Skip to content

Commit

Permalink
Tweak code
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed Oct 12, 2023
1 parent 95edf63 commit 1252cc6
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/Calculator/SvgFont.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@
*/
class SvgFont
{
private const UNICODE_CODE_POINT_M_LOWERCASE = 109;
private const DEFAULT_UNITS_PER_EM = 1000;

private array $glyphs;

private int $unitsPerEm;

private int $glyphSpacingAdvX;

private int $missingGlyphAdvX;

public function __construct(
array $glyphs = [],
int $unitsPerEm = 0,
int $glyphSpacingAdvX = 0,
int $unitsPerEm = self::DEFAULT_UNITS_PER_EM,
int $missingGlyphAdvX = 0
) {
$this->glyphs = $glyphs;
$this->unitsPerEm = $unitsPerEm;
$this->glyphSpacingAdvX = $glyphSpacingAdvX;
$this->missingGlyphAdvX = $missingGlyphAdvX;
}

Expand Down Expand Up @@ -88,19 +84,14 @@ public static function fromFile(
}

$glyphs[$codePoint]->d = $xml->getAttribute('d');

if (self::UNICODE_CODE_POINT_M_LOWERCASE === $codePoint) {
$glyphSpacingHorizAdvX = $glyphs[$codePoint]->horizAdvX;
}
}
}
}
}

return new self(
$glyphs,
$unitsPerEm ?? 0,
$glyphSpacingHorizAdvX ?? 0,
$unitsPerEm ?? self::DEFAULT_UNITS_PER_EM,
$missingGlyphHorizAdvX ?? 0,
);
}
Expand All @@ -115,7 +106,7 @@ public function computeWidth(
$glyphAdvX = $this->getGlyphAdvX($codePoint);

$glyphWidth = $glyphAdvX * $size;
$glyphSpacingWidth = $this->glyphSpacingAdvX * $glyphSpacing * $size;
$glyphSpacingWidth = $this->unitsPerEm * $glyphSpacing * $size;

return $glyphWidth + $glyphSpacingWidth;
}
Expand Down

0 comments on commit 1252cc6

Please sign in to comment.