From 180e509162a87e8171cb4d81dabe6d269907039f Mon Sep 17 00:00:00 2001 From: Anton Komarev Date: Thu, 12 Oct 2023 00:15:52 +0300 Subject: [PATCH] Code style fix --- src/Calculator/SvgFont.php | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/Calculator/SvgFont.php b/src/Calculator/SvgFont.php index ae266d5..963113f 100644 --- a/src/Calculator/SvgFont.php +++ b/src/Calculator/SvgFont.php @@ -34,8 +34,8 @@ public function __construct( int $glyphSpacingAdvX = 0, int $missingGlyphAdvX = 0 ) { - $this->glyphs = $glyphs; - $this->unitsPerEm = $unitsPerEm; + $this->glyphs = $glyphs; + $this->unitsPerEm = $unitsPerEm; $this->glyphSpacingAdvX = $glyphSpacingAdvX; $this->missingGlyphAdvX = $missingGlyphAdvX; } @@ -48,33 +48,29 @@ public function __construct( public static function fromFile( string $filePath ): self { - $xml = new XMLReader(); + $xml = new \XMLReader(); $xml->open($filePath); $glyphs = []; - $defaultHorizAdvX = 0; - $unitsPerEm = 0; - $glyphSpacingHorizAdvX = 0; - $missingGlyphHorizAdvX = 0; while ($xml->read()) { - if ($xml->nodeType !== XMLReader::ELEMENT) { + if (\XMLReader::ELEMENT !== $xml->nodeType) { continue; } - if ($xml->name === 'font') { - $defaultHorizAdvX = intval($xml->getAttribute('horiz-adv-x')); + if ('font' === $xml->name) { + $defaultHorizAdvX = (int) $xml->getAttribute('horiz-adv-x'); } - if ($xml->name === 'font-face') { - $unitsPerEm = intval($xml->getAttribute('units-per-em')); + if ('font-face' === $xml->name) { + $unitsPerEm = (int) $xml->getAttribute('units-per-em'); } - if ($xml->name === 'missing-glyph') { - $missingGlyphHorizAdvX = intval($xml->getAttribute('horiz-adv-x')); + if ('missing-glyph' === $xml->name) { + $missingGlyphHorizAdvX = (int) $xml->getAttribute('horiz-adv-x'); } - if ($xml->name === 'glyph') { + if ('glyph' === $xml->name) { $unicode = $xml->getAttribute('unicode'); if (isset($unicode)) { @@ -87,9 +83,9 @@ public static function fromFile( $glyphHorizAdvX = $xml->getAttribute('horiz-adv-x'); if (empty($glyphHorizAdvX)) { - $glyphs[$codePoint]->horizAdvX = $defaultHorizAdvX; + $glyphs[$codePoint]->horizAdvX = $defaultHorizAdvX ?? 0; } else { - $glyphs[$codePoint]->horizAdvX = intval($glyphHorizAdvX); + $glyphs[$codePoint]->horizAdvX = (int) $glyphHorizAdvX; } $glyphs[$codePoint]->d = $xml->getAttribute('d'); @@ -104,9 +100,9 @@ public static function fromFile( return new self( $glyphs, - $unitsPerEm, - $glyphSpacingHorizAdvX, - $missingGlyphHorizAdvX, + $unitsPerEm ?? 0, + $glyphSpacingHorizAdvX ?? 0, + $missingGlyphHorizAdvX ?? 0, ); } @@ -115,7 +111,7 @@ public function computeWidth( int $size, float $glyphSpacing = 0.0 ): float { - $size = $size / $this->unitsPerEm; + $size /= $this->unitsPerEm; $glyphAdvX = $this->getGlyphAdvX($codePoint);