Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 42e6cba

Browse files
committed
[[ libgraphics ]] Handle Skia path close verb when iterating.
[[ Canvas ]] Fix some svg path data parsing issues - relative moveto command not relative. close command not setting the current point for relative commands.
1 parent 42da855 commit 42e6cba

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

engine/src/module-canvas.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,6 +2965,7 @@ void MCCanvasPathMakeEmpty(MCCanvasPathRef &r_path)
29652965
struct MCCanvasPathSVGParseContext
29662966
{
29672967
MCGPathRef path;
2968+
MCGPoint first_point;
29682969
MCGPoint last_point;
29692970
MCGPoint last_control;
29702971
MCSVGPathCommand last_command;
@@ -2982,14 +2983,17 @@ bool MCCanvasPathSVGParseCallback(void *p_context, MCSVGPathCommand p_command, f
29822983
{
29832984
MCGPoint t_point;
29842985
t_point = MCGPointMake(p_params[0], p_params[1]);
2986+
if (p_command == kMCSVGPathRelativeMoveTo)
2987+
t_point = MCGPointRelativeToAbsolute(t_context->last_point, t_point);
29852988
MCGPathMoveTo(t_context->path, t_point);
2986-
t_context->last_point = t_point;
2989+
t_context->last_point = t_context->first_point = t_point;
29872990
break;
29882991
}
29892992

29902993
case kMCSVGPathClose:
29912994
case kMCSVGPathRelativeClose:
29922995
MCGPathCloseSubpath(t_context->path);
2996+
t_context->last_point = t_context->first_point;
29932997
break;
29942998

29952999
case kMCSVGPathLineTo:
@@ -3131,8 +3135,8 @@ bool MCCanvasPathSVGParseCallback(void *p_context, MCSVGPathCommand p_command, f
31313135
}
31323136

31333137
default:
3134-
MCAssert(false);
3135-
3138+
MCUnreachable();
3139+
break;
31363140
}
31373141

31383142
t_context->last_command = p_command;

libgraphics/src/path.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -694,17 +694,13 @@ bool MCGPathIterate(MCGPathRef self, MCGPathIterateCallback p_callback, void *p_
694694
break;
695695

696696
case SkPath::kLine_Verb:
697+
// Don't call callback for implicit lineto from close command
697698
if (t_iter.isCloseLine())
698-
{
699-
t_command = kMCGPathCommandCloseSubpath;
700-
t_point_count = 0;
701-
}
702-
else
703-
{
704-
t_command = kMCGPathCommandLineTo;
705-
t_points[0] = MCGPointFromSkPoint(t_sk_points[0]);
706-
t_point_count = 1;
707-
}
699+
continue;
700+
701+
t_command = kMCGPathCommandLineTo;
702+
t_points[0] = MCGPointFromSkPoint(t_sk_points[0]);
703+
t_point_count = 1;
708704
break;
709705

710706
case SkPath::kQuad_Verb:
@@ -722,6 +718,11 @@ bool MCGPathIterate(MCGPathRef self, MCGPathIterateCallback p_callback, void *p_
722718
t_point_count = 3;
723719
break;
724720

721+
case SkPath::kClose_Verb:
722+
t_command = kMCGPathCommandCloseSubpath;
723+
t_point_count = 0;
724+
break;
725+
725726
default:
726727
// Unknown path instruction
727728
t_success = false;

0 commit comments

Comments
 (0)