-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bounds not correctly computed for texts and groups #1144
Comments
@Moggel12 It will help a lot if you provide a sample. |
Sure, something like this? @paulushub using Svg;
var document = new SvgDocument()
{
Width = new SvgUnit(SvgUnitType.Inch, 10),
Height = new SvgUnit(SvgUnitType.Inch, 10),
FontSize = 15,
FontFamily = "Sans-Serif",
};
var svgGroup = new SvgGroup();
float x = 100, y = 100;
var xLocation = new SvgUnitCollection();
var yLocation = new SvgUnitCollection();
xLocation.Add(x);
yLocation.Add(y);
var textBox = new SvgText
{
X = xLocation,
Y = yLocation
};
var lines = new List<string>()
{
"This is",
"a multiline",
"test"
};
float offset = 0;
foreach (var line in lines)
{
var unit = new SvgUnit(SvgUnitType.Em, offset);
var yOffset = new SvgUnitCollection
{
unit
};
var textSpan = new SvgTextSpan
{
Text = line,
Dy = yOffset,
X = xLocation,
};
textBox.Children.Add(textSpan);
offset += 1F;
}
textBox.AddStyle("fill", "black", 0);
textBox.AddStyle("font-size", "inherit", 0);
svgGroup.Children.Add(textBox);
var boundingBox = new SvgRectangle
{
X = textBox.Bounds.X,
Y = textBox.Bounds.Y,
Width = textBox.Bounds.Width,
Height = textBox.Bounds.Height
};
boundingBox.AddStyle("fill", "none", 0);
boundingBox.AddStyle("stroke", "black", 0);
svgGroup.Children.Add(boundingBox);
document.Children.Add(svgGroup);
var completePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "test.svg");
document.Write(completePath, false); |
Alright, just spotted that the problem only occurs when elements are added to a group prior to being added to an SvgDocument. I edited the previous comment so that the problem actually occurs. Sorry! |
It may be an extension to it, but I don't believe it to be the same. In my case, no transformations have been added to the group. However, it does look like #946 adds elements to the group first and then adds the group to the document, so maybe the same root cause? |
Both
text
elements with multiple childtspan
elements, andgroup
elements, incorrectly compute the bounding box. Have not tested other elements.Example: creating a
text
element with threetspan
s internally (using thedy
property to simulate newlines) and calling.Bounds
will return a box that does not fit the entire text nor is positioned correctly. Putting the text element inside a group will act likewise. Atleast this is the case when trying to render the box via arect
element in an SVG file.In my case font-size is set to 15 with Sans-Serif font family. Using
text-anchor
ordominant-baseline
does not seem to help either.Using SVG v3.4.6 and .NET 7.
The text was updated successfully, but these errors were encountered: