From b15da4f28e27ee8133481c8a0c1f8b90d2d9ba88 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 6 Dec 2023 12:34:22 +0100 Subject: [PATCH] some cleanup in EasySVG just minimal formatting adjustments --- EasySVG.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/EasySVG.php b/EasySVG.php index 2517134..6604a3e 100644 --- a/EasySVG.php +++ b/EasySVG.php @@ -42,7 +42,7 @@ public function clearSVG() * @param string $str * @return string */ - private function _utf8ToUnicode($str) + private function utf8ToUnicode($str) { $unicode = []; $values = []; @@ -154,7 +154,7 @@ public function setFontSVG($filepath) if ($name == 'glyph') { $unicode = $z->getAttribute('unicode'); - $unicode = $this->_utf8ToUnicode($unicode); + $unicode = $this->utf8ToUnicode($unicode); if (isset($unicode[0])) { $unicode = $unicode[0]; @@ -227,7 +227,7 @@ public function textDef($text) $horizAdvX = 0; $horizAdvY = $this->font->ascent + $this->font->descent; $fontSize = (float) $this->font->size / $this->font->unitsPerEm; - $text = $this->_utf8ToUnicode($text); + $text = $this->utf8ToUnicode($text); $counter = count($text); for ($i = 0; $i < $counter; $i++) { @@ -250,7 +250,8 @@ public function textDef($text) $def[] = $d; // next letter's position - $horizAdvX += $this->font->glyphs[$letter]->horizAdvX * $fontSize + $this->font->em * $this->font->letterSpacing * $fontSize; + $horizAdvX += $this->font->glyphs[$letter]->horizAdvX * $fontSize + + $this->font->em * $this->font->letterSpacing * $fontSize; } return implode(' ', $def); } @@ -263,7 +264,7 @@ public function textDef($text) public function textDimensions($text) { $fontSize = (float) $this->font->size / $this->font->unitsPerEm; - $text = $this->_utf8ToUnicode($text); + $text = $this->utf8ToUnicode($text); $lineWidth = 0; $lineHeight = ($this->font->ascent + $this->font->descent) * $fontSize * 2; @@ -283,7 +284,8 @@ public function textDimensions($text) continue; } - $lineWidth += $this->font->glyphs[$letter]->horizAdvX * $fontSize + $this->font->em * $this->font->letterSpacing * $fontSize; + $lineWidth += $this->font->glyphs[$letter]->horizAdvX * $fontSize + + $this->font->em * $this->font->letterSpacing * $fontSize; } // only keep the widest line's width @@ -324,7 +326,7 @@ public function characterWidth($char, $is_unicode = false) if ($is_unicode) { $letter = hexdec($char); } else { - $letter = $this->_utf8ToUnicode($char); + $letter = $this->utf8ToUnicode($char); } if (!isset($this->font->glyphs[$letter])) { @@ -431,8 +433,8 @@ public function defApplyMatrix($def, $matrix) // add new point's coordinates $current_point = [$a * $x + $e, $b * $x + $f]; $new_coords = [...$new_coords, ...$current_point]; - } // convert vertical lineto (relative) - elseif ($i == 'v') { + } elseif ($i == 'v') { + // convert vertical lineto (relative) $i = 'l'; $x = 0; $y = (float) array_shift($coords); @@ -440,8 +442,8 @@ public function defApplyMatrix($def, $matrix) // add new point's coordinates $current_point = [$c * $y + $e, $d * $y + $f]; $new_coords = [...$new_coords, ...$current_point]; - } // convert quadratic bezier curve (relative) - elseif ($i == 'q') { + } elseif ($i == 'q') { + // convert quadratic bezier curve (relative) $x = (float) array_shift($coords); $y = (float) array_shift($coords); @@ -456,12 +458,11 @@ public function defApplyMatrix($def, $matrix) // add new point's coordinates $current_point = [$a * $x + $c * $y + $e, $b * $x + $d * $y + $f]; $new_coords = array_merge($new_coords, $current_point); - } + } else { + // every other commands + // @TODO: handle 'a,c,s' (elliptic arc curve) commands + // cf. http://www.w3.org/TR/SVG/paths.html#PathDataCurveCommands - // every other commands - // @TODO: handle 'a,c,s' (elliptic arc curve) commands - // cf. http://www.w3.org/TR/SVG/paths.html#PathDataCurveCommands - else { $x = (float) array_shift($coords); $y = (float) array_shift($coords);