Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Source/Text/SvgTextBase.Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ public override RectangleF Bounds
continue;
path.AddPath(elem.Path(null), false);
}
if (Transforms == null || Transforms.Count == 0)
var transforms = Transforms;
if (transforms is null)
{
// This is an SvgTextSpan which does not support the transform attribute, but parent transforms still apply.
transforms = Parents.FirstOrDefault(p => p.Transforms != null)?.Transforms;
}
if (transforms is null || transforms.Count == 0)
return path.GetBounds();

using (path = (GraphicsPath)path.Clone())
using (var matrix = Transforms.GetMatrix())
using (var matrix = transforms.GetMatrix())
{
path.Transform(matrix);
return path.GetBounds();
Expand Down
13 changes: 13 additions & 0 deletions Tests/Svg.UnitTests/SvgTextTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.Drawing;
using System.IO;
using System.Xml;

Expand Down Expand Up @@ -83,5 +84,17 @@ public void TestWritesCoordinatesForCollectionChange()
Assert.IsTrue(xml.Contains("dx=\"40\""));
Assert.IsTrue(xml.Contains("dy=\"50\""));
}

[Test]
public void TestParentTransformsRespected()
{
var span = new SvgTextSpan { Text = "abc" };
var b = span.Bounds;
Assert.AreNotEqual(new PointF(0f, 0f), b.Location);
var text = new SvgText { Transforms = new Transforms.SvgTransformCollection { new Transforms.SvgTranslate(10f, 20f) }, Children = { span } };
b.Offset(10f, 20f);
Assert.AreEqual(b, span.Bounds);
Assert.AreEqual(b, text.Bounds);
}
}
}