Skip to content
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

Values of SvgPathSegment became relative (not absolute as earlier) when iterating through the SvgPathSegmentList #1159

Open
hubaksis opened this issue May 29, 2024 · 3 comments

Comments

@hubaksis
Copy link

Description

Somewhere between versions 3.0.84 and 3.4.7 the default behaviour of iterating through SvgPathSegmentList changed.
In the 3.0.84 version iterating through the SvgPathSegmentList returns SvgPathSegment result as absolute coordinates of the point.
In the 3.4.7 version the object SvgPathSegment has relative coordinates with an additional property 'IsRelative' set to 'true'

Example data

<path d="M2639.9,1960.88l1.26,1.11l-0.36,1.79l-1.79,1.58 .....

Was the change intentional? I did not find any breaking changes in the release notes.

Is there a flag or a setting I can use to return the default behavior to absolute coordinates without the need to calculate them manually?

Thank you.

@hubaksis hubaksis changed the title Relative and absolute values of SvgPathSegment when iterating through the SvgPathSegmentList Values of SvgPathSegment became relative (not absolute as earlier) when iterating through the SvgPathSegmentList May 29, 2024
@hubaksis
Copy link
Author

Workaround that I've currently implemented in my project:

PointF absolutePoint = new PointF(0, 0);
foreach (var point in path.PathData)
{
     absolutePoint = ToAbsolute(point.End, point.IsRelative, absolutePoint);
     ... do what you need to do with the absolutePoint
}

Where ToAbsolute I took from the abstract class SvgPathSegment

 protected static PointF ToAbsolute(PointF point, bool isRelative, PointF start)
 {
     if (float.IsNaN(point.X))
         point.X = start.X;
     else if (isRelative)
         point.X += start.X;

     if (float.IsNaN(point.Y))
         point.Y = start.Y;
     else if (isRelative)
         point.Y += start.Y;

     return point;
 }

@mrbean-bremen
Copy link
Member

Was the change intentional? I did not find any breaking changes in the release notes.

Yes, see #925. And yes, the release notes for this are not really helpful in that respect.

Is there a flag or a setting I can use to return the default behavior to absolute coordinates without the need to calculate them manually?

Not that I know of, though @H1Gdev might know more.

@H1Gdev
Copy link
Contributor

H1Gdev commented Jun 5, 2024

@hubaksis

In the previous version, relative information was lost when read SVG into DOM.
(SVG(relative) -> SvgDocument(absolute) -> SVG(absolute))

We supported relatives with PR #925.

For conversion, I think you should use ToAbsolute logic. You can calculate each point in this method sequentially.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants