diff --git a/src/Svg.Model/Services/SvgService.cs b/src/Svg.Model/Services/SvgService.cs
index 462b7c0679..e3e98cf421 100644
--- a/src/Svg.Model/Services/SvgService.cs
+++ b/src/Svg.Model/Services/SvgService.cs
@@ -730,7 +730,7 @@ public static SKSize GetDimensions(SvgFragment svgFragment, SKRect skViewport =
if (isWidthperc && svgFragment is SvgDocument)
{
var bounds = percentViewport;
- w = (bounds.Width + bounds.Left) * (svgFragment.Width.Value * 0.01f);
+ w = bounds.Width * (svgFragment.Width.Value * 0.01f);
}
else
{
@@ -740,7 +740,7 @@ public static SKSize GetDimensions(SvgFragment svgFragment, SKRect skViewport =
if (isHeightperc && svgFragment is SvgDocument)
{
var bounds = percentViewport;
- h = (bounds.Height + bounds.Top) * (svgFragment.Height.Value * 0.01f);
+ h = bounds.Height * (svgFragment.Height.Value * 0.01f);
}
else
{
diff --git a/tests/Svg.Skia.UnitTests/SKSvgTests.cs b/tests/Svg.Skia.UnitTests/SKSvgTests.cs
index e254dd4bb9..734c9b2afd 100644
--- a/tests/Svg.Skia.UnitTests/SKSvgTests.cs
+++ b/tests/Svg.Skia.UnitTests/SKSvgTests.cs
@@ -107,6 +107,35 @@ public void Save_StandaloneDocumentWithExplicitPercentSize_UsesViewBoxWithoutCon
Assert.Equal(100, image.Height);
}
+ [Fact]
+ public void Save_StandaloneDocumentWithNegativeViewBoxOrigin_UsesViewBoxSize()
+ {
+ const string svgMarkup = """
+
+ """;
+
+ var document = SvgService.FromSvg(svgMarkup);
+ Assert.NotNull(document);
+
+ var size = SvgService.GetDimensions(document);
+ Assert.Equal(120f, size.Width);
+ Assert.Equal(80f, size.Height);
+
+ var svg = new SKSvg();
+ using var input = new MemoryStream(Encoding.UTF8.GetBytes(svgMarkup));
+ using var _ = svg.Load(input);
+ using var output = new MemoryStream();
+
+ Assert.True(svg.Save(output, SkiaSharp.SKColors.Transparent));
+
+ output.Position = 0;
+ using var image = Image.Load(output);
+ Assert.Equal(120, image.Width);
+ Assert.Equal(80, image.Height);
+ }
+
[Fact]
public void Save_StandaloneDocumentWithExplicitPercentSize_UsesConfiguredStandaloneViewport()
{
diff --git a/tests/Svg.Skia.UnitTests/SvgAnimationControllerTests.cs b/tests/Svg.Skia.UnitTests/SvgAnimationControllerTests.cs
index e5fe63cb49..2cf8b0b377 100644
--- a/tests/Svg.Skia.UnitTests/SvgAnimationControllerTests.cs
+++ b/tests/Svg.Skia.UnitTests/SvgAnimationControllerTests.cs
@@ -330,7 +330,7 @@ public void SetAnimationTime_RebuildsRootViewBoxAnimations()
Assert.Equal(50f, renderedDocument.ViewBox.Width, 3);
Assert.Equal(50f, renderedDocument.ViewBox.Height, 3);
Assert.Null(svg.HitTestTopmostElement(new SKPoint(65, 65)));
- Assert.Equal("target", svg.HitTestTopmostElement(new SKPoint(25, 25))?.ID);
+ Assert.Equal("target", svg.HitTestTopmostElement(new SKPoint(15, 15))?.ID);
}
[Fact]