Skip to content

Commit

Permalink
Code style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Komarev committed Oct 11, 2023
1 parent 5bd41df commit 180e509
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/Calculator/SvgFont.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)) {
Expand All @@ -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');
Expand All @@ -104,9 +100,9 @@ public static function fromFile(

return new self(
$glyphs,
$unitsPerEm,
$glyphSpacingHorizAdvX,
$missingGlyphHorizAdvX,
$unitsPerEm ?? 0,
$glyphSpacingHorizAdvX ?? 0,
$missingGlyphHorizAdvX ?? 0,
);
}

Expand All @@ -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);

Expand Down

0 comments on commit 180e509

Please sign in to comment.