Skip to content

Commit

Permalink
fix: parse floating point values in svg path
Browse files Browse the repository at this point in the history
  • Loading branch information
spouliot committed Nov 14, 2024
1 parent f20b0b8 commit ab73de5
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/Uno.UI.Runtime.Skia.MacOS/UnoNativeMac/UnoNativeMac/UNOWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -665,20 +665,10 @@ CGFloat readNextCoord(const char *svg, int *position, long length)
#endif
return result;
}
for (int i=*position; i < length; i++) {
if (isdigit(svg[i])) {
if (isnan(result)) {
result = svg[i] - '0';
} else {
result *= 10;
result += svg[i] - '0';
}
*position = i;
} else if (!isnan(result)) {
*position = i - 1;
break;
}
}
const char* start = svg + *position;
char* end;
result = strtod(start, &end);
*position += (int)(end - start);
return result;
}

Expand All @@ -697,11 +687,12 @@ void uno_window_clip_svg(UNOWindow* window, const char* svg)
CGMutablePathRef path = CGPathCreateMutable();
// small subset of an SVG path parser handling trusted input of integer-based points
long length = strlen(svg);
for (int i=0; i < length; i++) {
for (int i=0; i < length;) {
CGFloat x, y;
char op = svg[i];
switch (op) {
case 'M':
i++; // skip M
x = readNextCoord(svg, &i, length);
i++; // skip separator
y = readNextCoord(svg, &i, length);
Expand All @@ -714,6 +705,7 @@ void uno_window_clip_svg(UNOWindow* window, const char* svg)
CGPathMoveToPoint(path, nil, x, y);
break;
case 'L':
i++; // skip L
x = readNextCoord(svg, &i, length);
i++; // skip separator
y = readNextCoord(svg, &i, length);
Expand All @@ -726,6 +718,7 @@ void uno_window_clip_svg(UNOWindow* window, const char* svg)
CGPathAddLineToPoint(path, nil, x, y);
break;
case 'Z':
i++; // skip Z
#if DEBUG_PARSER
NSLog(@"uno_window_clip_svg parsing CGPathCloseSubpath - position %d", i);
#endif
Expand All @@ -734,8 +727,9 @@ void uno_window_clip_svg(UNOWindow* window, const char* svg)
#if DEBUG
default:
if (op != ' ') {
NSLog(@"uno_window_clip_svg parsing unknown op %c at position %d", op, i - 1);
NSLog(@"uno_window_clip_svg parsing unknown op %c at position %d", op, i);
}
i++; // skip unknown op
break;
#endif
}
Expand Down

0 comments on commit ab73de5

Please sign in to comment.