Skip to content

Commit

Permalink
Better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed Dec 11, 2023
1 parent df79793 commit e782d35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ final class Font
private const UNICODE_CODE_POINT_LINE_FEED = 10;

/**
* @param array<int, Glyph> $glyphs
* @param array<int, Glyph> $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(
Expand Down Expand Up @@ -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;
}
}
14 changes: 7 additions & 7 deletions src/Parser/SimpleXmlSvgFontFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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
}
Expand All @@ -97,7 +97,7 @@ private function initFont(
$defaultHorizontalAdvance,
$fontFace,
$missingGlyph,
$glyphs,
$glyphMap,
);
}

Expand Down Expand Up @@ -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,
);
}

Expand Down

0 comments on commit e782d35

Please sign in to comment.