Skip to content

Commit

Permalink
tools/svg2tvgt: save/restore co-ordinates when starting/closing paths
Browse files Browse the repository at this point in the history
This ensures that the current co-ordinates in the parser are saved when
starting and closing paths. This is necessary to ensure that relative
moves in a path function correctly after the first move.
  • Loading branch information
vancluever authored and ikskuh committed Jan 5, 2024
1 parent b8e82bc commit 24abddf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/tools/svg2tvgt/svg2tvgt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,7 @@ public static void Parse(string str, IPathRenderer renderer)
int char_offset = 0;

PointF current_position = new PointF(0, 0);
PointF? path_start = null;
PointF? stored_control_point = null;

private SvgPathParser(string str, IPathRenderer renderer)
Expand Down Expand Up @@ -1836,6 +1837,9 @@ void ParseDrawToCommand()
void ParseClosePath()
{
AcceptChar('Z', 'z');
if (path_start == null) throw new InvalidOperationException("ClosePath detected without MoveTo");
current_position = (PointF)path_start;
path_start = null;
renderer.ClosePath();
SkipWhitespace();
}
Expand All @@ -1852,6 +1856,8 @@ void ParseMoveTo()
var p = MoveCursor(pair, relative);
if (first)
{
if (path_start != null) throw new InvalidOperationException("New MoveTo detected without ClosePath");
path_start = current_position;
renderer.MoveTo(p);
}
else
Expand Down

0 comments on commit 24abddf

Please sign in to comment.