Skip to content

Commit

Permalink
some cleanup in EasySVG
Browse files Browse the repository at this point in the history
just minimal formatting adjustments
  • Loading branch information
splitbrain committed Dec 6, 2023
1 parent 5e79b2e commit b15da4f
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions EasySVG.php
Expand Up @@ -42,7 +42,7 @@ public function clearSVG()
* @param string $str
* @return string
*/
private function _utf8ToUnicode($str)
private function utf8ToUnicode($str)
{
$unicode = [];
$values = [];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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++) {
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -431,17 +433,17 @@ 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);

// 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);

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

Expand Down

0 comments on commit b15da4f

Please sign in to comment.