diff --git a/src/Font.php b/src/Font.php index ff0dc37..5321796 100644 --- a/src/Font.php +++ b/src/Font.php @@ -12,14 +12,14 @@ final class Font private const UNICODE_CODE_POINT_LINE_FEED = 10; /** - * @param array $glyphs + * @param array $glyphMap */ public function __construct( public readonly string $id, private readonly int $horizontalAdvance, private readonly FontFace $fontFace, private readonly MissingGlyph $missingGlyph, - private readonly array $glyphs = [], + private readonly array $glyphMap = [], ) { if ($horizontalAdvance < 0) { throw new \InvalidArgumentException( @@ -68,8 +68,8 @@ private function computeCharacterWidth( private function resolveGlyphHorizontalAdvance( Character $character, ): int { - return isset($this->glyphs[strval($character)]) - ? $this->glyphs[strval($character)]->horizontalAdvance ?? $this->horizontalAdvance + return isset($this->glyphMap[strval($character)]) + ? $this->glyphMap[strval($character)]->horizontalAdvance ?? $this->horizontalAdvance : $this->missingGlyph->horizontalAdvance ?? $this->horizontalAdvance; } } diff --git a/src/Parser/SimpleXmlSvgFontFileParser.php b/src/Parser/SimpleXmlSvgFontFileParser.php index bc08c62..c8aeb3b 100644 --- a/src/Parser/SimpleXmlSvgFontFileParser.php +++ b/src/Parser/SimpleXmlSvgFontFileParser.php @@ -55,7 +55,7 @@ private function initFont( ): Font { $fontId = strval($fontElement[self::ATTRIBUTE_ID]); $defaultHorizontalAdvance = intval($fontElement[self::ATTRIBUTE_HORIZ_ADV_X]); - $glyphs = []; + $glyphMap = []; foreach ($fontElement as $fontChildElement) { switch ($fontChildElement->getName()) { @@ -71,7 +71,7 @@ private function initFont( if ($unicode !== '') { try { $character = Character::of($unicode); - $glyphs[$unicode] = $this->initGlyph($fontChildElement, $character); + $glyphMap[$unicode] = $this->initGlyph($fontChildElement, $character); } catch (\Exception $exception) { // TODO: Add multiple character support } @@ -97,7 +97,7 @@ private function initFont( $defaultHorizontalAdvance, $fontFace, $missingGlyph, - $glyphs, + $glyphMap, ); } @@ -125,16 +125,16 @@ private function initGlyph( $name = null; } - $glyphHorizontalAdvance = intval($glyphElement[self::ATTRIBUTE_HORIZ_ADV_X]); + $horizontalAdvance = intval($glyphElement[self::ATTRIBUTE_HORIZ_ADV_X]); - if ($glyphHorizontalAdvance === 0) { - $glyphHorizontalAdvance = null; + if ($horizontalAdvance === 0) { + $horizontalAdvance = null; } return new Glyph( $character, $name, - $glyphHorizontalAdvance, + $horizontalAdvance, ); }