From 358c38d168499e85242ac648ff18f5c199071dea Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Fri, 2 Oct 2026 03:02:16 +0800 Subject: [PATCH 1/2] Fix SVG viewport and path geometry --- src/Svg/Tag/AbstractTag.php | 8 ++++---- src/Svg/Tag/Path.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Svg/Tag/AbstractTag.php b/src/Svg/Tag/AbstractTag.php index 872d971..29eb444 100644 --- a/src/Svg/Tag/AbstractTag.php +++ b/src/Svg/Tag/AbstractTag.php @@ -229,7 +229,7 @@ protected function applyViewbox($attributes) { $align = $preserveAspectRatio[0]; // 4. Let meetOrSlice be the meetOrSlice value of preserveAspectRatio, or 'meet' if preserveAspectRatio is not defined or if meetOrSlice is missing from this value. - $meetOrSlice = $meetOrSlice ?? "meet"; + $meetOrSlice = $preserveAspectRatio[1] ?? "meet"; // 5. Initialize scale-x to e-width/vb-width. $scaleX = $vbWidth == 0 ? 0 : ($eWidth / $vbWidth); @@ -267,12 +267,12 @@ protected function applyViewbox($attributes) { // 13. If align contains 'yMid', add (e-height - vb-height * scale-y) / 2 to translate-y. if (strpos($align, "yMid") !== false) { - $translateX += ($eHeight - $vbHeight * $scaleY) / 2; + $translateY += ($eHeight - $vbHeight * $scaleY) / 2; } // 14. If align contains 'yMax', add (e-height - vb-height * scale-y) to translate-y. - if (strpos($align, "yMid") !== false) { - $translateX += ($eHeight - $vbHeight * $scaleY); + if (strpos($align, "yMax") !== false) { + $translateY += ($eHeight - $vbHeight * $scaleY); } $surface->translate($translateX, $translateY); diff --git a/src/Svg/Tag/Path.php b/src/Svg/Tag/Path.php index b792b3a..ba7bf74 100644 --- a/src/Svg/Tag/Path.php +++ b/src/Svg/Tag/Path.php @@ -90,7 +90,7 @@ public static function parse(string $commandSequence): array $command = $c[1]; for ($k = 0, $klen = count($item); $k < $klen; $k += $commandLength) { - $_item = array_slice($item, $k, $k + $commandLength); + $_item = array_slice($item, $k, $commandLength); array_unshift($_item, $command); $path[] = $_item; @@ -448,7 +448,7 @@ function drawArc(SurfaceInterface $surface, $fx, $fy, $coords) $toX = $tx - $fx; $toY = $ty - $fy; - if ((float)($toX + $toY) === 0.0) { + if ((float)$toX === 0.0 && (float)$toY === 0.0) { return; } From 6dd4d014224705824af65ba371d92cf3f2b4598c Mon Sep 17 00:00:00 2001 From: dajiaohuang <108231307+dajiaohuang@users.noreply.github.com> Date: Sun, 18 Oct 2026 19:54:01 +0800 Subject: [PATCH 2/2] Fix SVG viewport alignment --- src/Svg/Tag/AbstractTag.php | 10 +++++----- src/Svg/Tag/Path.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Svg/Tag/AbstractTag.php b/src/Svg/Tag/AbstractTag.php index 29eb444..0dc06a9 100644 --- a/src/Svg/Tag/AbstractTag.php +++ b/src/Svg/Tag/AbstractTag.php @@ -225,7 +225,7 @@ protected function applyViewbox($attributes) { $eHeight = $attributes["height"] ?? $this->document->getHeight(); // 3. Let align be the align value of preserveAspectRatio, or 'xMidYMid' if preserveAspectRatio is not defined. - $preserveAspectRatio = explode(" ", $attributes["preserveAspectRatio"] ?? "xMidYMid meet"); + $preserveAspectRatio = explode(" ", $attributes["preserveaspectratio"] ?? "xMidYMid meet"); $align = $preserveAspectRatio[0]; // 4. Let meetOrSlice be the meetOrSlice value of preserveAspectRatio, or 'meet' if preserveAspectRatio is not defined or if meetOrSlice is missing from this value. @@ -265,13 +265,13 @@ protected function applyViewbox($attributes) { $translateX += ($eWidth - $vbWidth * $scaleX); } - // 13. If align contains 'yMid', add (e-height - vb-height * scale-y) / 2 to translate-y. - if (strpos($align, "yMid") !== false) { + // 13. If align contains 'YMid', add (e-height - vb-height * scale-y) / 2 to translate-y. + if (strpos($align, "YMid") !== false) { $translateY += ($eHeight - $vbHeight * $scaleY) / 2; } - // 14. If align contains 'yMax', add (e-height - vb-height * scale-y) to translate-y. - if (strpos($align, "yMax") !== false) { + // 14. If align contains 'YMax', add (e-height - vb-height * scale-y) to translate-y. + if (strpos($align, "YMax") !== false) { $translateY += ($eHeight - $vbHeight * $scaleY); } diff --git a/src/Svg/Tag/Path.php b/src/Svg/Tag/Path.php index ba7bf74..c3dd75f 100644 --- a/src/Svg/Tag/Path.php +++ b/src/Svg/Tag/Path.php @@ -90,7 +90,7 @@ public static function parse(string $commandSequence): array $command = $c[1]; for ($k = 0, $klen = count($item); $k < $klen; $k += $commandLength) { - $_item = array_slice($item, $k, $commandLength); + $_item = array_slice($item, $k, $k + $commandLength); array_unshift($_item, $command); $path[] = $_item;