Improved optional command handling in SkParsePath::FromSVGString()

Repeating command letters are optional in SVG path data strings:
https://www.w3.org/TR/SVG/paths.html#PathData

FromSVGString() already supports this feature, but only checks for
scalars prefixes == (digit | '-' | '+').

A decimal point is also a valid scalar prefix though, so it should be
included in the test.

R=caryclark@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2339813003

Review-Url: https://codereview.chromium.org/2339813003
This commit is contained in:
fmalita 2016-09-14 10:14:08 -07:00 committed by Commit bot
parent f605c16a03
commit a17411f056
2 changed files with 41 additions and 1 deletions

View File

@ -91,7 +91,7 @@ bool SkParsePath::FromSVGString(const char data[], SkPath* result) {
break;
}
char ch = data[0];
if (is_digit(ch) || ch == '-' || ch == '+') {
if (is_digit(ch) || ch == '-' || ch == '+' || ch == '.') {
if (op == '\0') {
return false;
}

View File

@ -88,3 +88,43 @@ DEF_TEST(ParsePathRandom, r) {
REPORTER_ASSERT(r, success);
}
}
DEF_TEST(ParsePathOptionalCommand, r) {
struct {
const char* fStr;
int fVerbs;
int fPoints;
} gTests[] = {
{ "", 0, 0 },
{ "H100 200 ", 3, 3 },
{ "H-100-200", 3, 3 },
{ "H+100+200", 3, 3 },
{ "H.10.20" , 3, 3 },
{ "H-.10-.20", 3, 3 },
{ "H+.10+.20", 3, 3 },
{ "L100 100 200 200" , 3, 3 },
{ "L-100-100-200-200", 3, 3 },
{ "L+100+100+200+200", 3, 3 },
{ "L.10.10.20.20" , 3, 3 },
{ "L-.10-.10-.20-.20", 3, 3 },
{ "L+.10+.10+.20+.20", 3, 3 },
{ "C100 100 200 200 300 300 400 400 500 500 600 600" , 3, 7 },
{ "C100-100-200-200-300-300-400-400-500-500-600-600" , 3, 7 },
{ "C100+100+200+200+300+300+400+400+500+500+600+600" , 3, 7 },
{ "C.10.10.20.20.30.30.40.40.50.50.60.60" , 3, 7 },
{ "C-.10-.10-.20-.20-.30-.30-.40-.40-.50-.50-.60-.60", 3, 7 },
{ "C+.10+.10+.20+.20+.30+.30+.40+.40+.50+.50+.60+.60", 3, 7 },
{ "c-1.49.71-2.12 2.5-1.4 4 .71 1.49 2.5 2.12 4 1.4z", 4, 7 },
};
SkPath path;
for (size_t i = 0; i < SK_ARRAY_COUNT(gTests); ++i) {
REPORTER_ASSERT(r, SkParsePath::FromSVGString(gTests[i].fStr, &path));
REPORTER_ASSERT(r, path.countVerbs() == gTests[i].fVerbs);
REPORTER_ASSERT(r, path.countPoints() == gTests[i].fPoints);
}
}