From e78fbdbb172dfce61878a97190a1ee380b2c65a7 Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Tue, 26 Dec 2023 10:55:07 -0800 Subject: [PATCH] tools/svg2tvgt: save/restore co-ordinates when starting/closing paths 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. --- src/tools/svg2tvgt/svg2tvgt.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/svg2tvgt/svg2tvgt.cs b/src/tools/svg2tvgt/svg2tvgt.cs index 0228c81..fc55c40 100644 --- a/src/tools/svg2tvgt/svg2tvgt.cs +++ b/src/tools/svg2tvgt/svg2tvgt.cs @@ -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) @@ -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(); } @@ -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