diff --git a/src/Calculator/SvgFont.php b/src/Calculator/SvgFont.php index 662bd8d..8e5044c 100644 --- a/src/Calculator/SvgFont.php +++ b/src/Calculator/SvgFont.php @@ -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; } @@ -88,10 +84,6 @@ public static function fromFile( } $glyphs[$codePoint]->d = $xml->getAttribute('d'); - - if (self::UNICODE_CODE_POINT_M_LOWERCASE === $codePoint) { - $glyphSpacingHorizAdvX = $glyphs[$codePoint]->horizAdvX; - } } } } @@ -99,8 +91,7 @@ public static function fromFile( return new self( $glyphs, - $unitsPerEm ?? 0, - $glyphSpacingHorizAdvX ?? 0, + $unitsPerEm ?? self::DEFAULT_UNITS_PER_EM, $missingGlyphHorizAdvX ?? 0, ); } @@ -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; }