diff options
Diffstat (limited to 'source/svg')
-rw-r--r-- | source/svg/svg-parse.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/source/svg/svg-parse.c b/source/svg/svg-parse.c index 56f2a1cf..00151dd4 100644 --- a/source/svg/svg-parse.c +++ b/source/svg/svg-parse.c @@ -142,7 +142,6 @@ svg_parse_transform(fz_context *ctx, svg_document *doc, char *str, fz_matrix *tr { if (*str == ',') str ++; - while (svg_is_whitespace(*str)) str ++; } @@ -152,22 +151,19 @@ svg_parse_transform(fz_context *ctx, svg_document *doc, char *str, fz_matrix *tr * Parse keyword and opening parenthesis. */ - if (!svg_is_alpha(*str)) - fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in transform attribute - expected keyword"); - keywordlen = 0; while (svg_is_alpha(*str) && keywordlen < sizeof(keyword) - 1) keyword[keywordlen++] = *str++; keyword[keywordlen] = 0; if (keywordlen == 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in transform attribute - no keyword"); + fz_throw(ctx, FZ_ERROR_SYNTAX, "expected keyword in transform attribute"); while (svg_is_whitespace(*str)) str ++; if (*str != '(') - fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in transform attribute - no open paren"); + fz_throw(ctx, FZ_ERROR_SYNTAX, "expected opening parenthesis in transform attribute"); str ++; /* @@ -177,33 +173,27 @@ svg_parse_transform(fz_context *ctx, svg_document *doc, char *str, fz_matrix *tr nargs = 0; while (*str && *str != ')' && nargs < 6) { - if (nargs > 0) - { - if (*str != ',') - fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in transform attribute - no comma between numbers"); + if (nargs > 0 && *str == ',') str ++; - } - while (svg_is_whitespace(*str)) str ++; - if (!svg_is_digit(*str)) - fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in transform attribute - number required"); - numberlen = 0; while (svg_is_digit(*str) && numberlen < sizeof(number) - 1) number[numberlen++] = *str++; number[numberlen] = 0; + + if (numberlen == 0) + fz_throw(ctx, FZ_ERROR_SYNTAX, "expected number in transform attribute"); + args[nargs++] = fz_atof(number); while (svg_is_whitespace(*str)) str ++; } - if (*str == 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in transform attribute - no close paren"); if (*str != ')') - fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in transform attribute - expected close paren"); + fz_throw(ctx, FZ_ERROR_SYNTAX, "expected closing parenthesis in transform attribute"); str ++; /* @@ -215,7 +205,7 @@ svg_parse_transform(fz_context *ctx, svg_document *doc, char *str, fz_matrix *tr fz_matrix m; if (nargs != 6) - fz_throw(ctx, FZ_ERROR_GENERIC, "wrong number of arguments to matrix(): %d", nargs); + fz_throw(ctx, FZ_ERROR_SYNTAX, "wrong number of arguments to matrix(): %d", nargs); m.a = args[0]; m.b = args[1]; @@ -230,7 +220,7 @@ svg_parse_transform(fz_context *ctx, svg_document *doc, char *str, fz_matrix *tr else if (!strcmp(keyword, "translate")) { if (nargs != 2) - fz_throw(ctx, FZ_ERROR_GENERIC, "wrong number of arguments to translate(): %d", nargs); + fz_throw(ctx, FZ_ERROR_SYNTAX, "wrong number of arguments to translate(): %d", nargs); fz_pre_translate(transform, args[0], args[1]); } @@ -242,13 +232,13 @@ svg_parse_transform(fz_context *ctx, svg_document *doc, char *str, fz_matrix *tr else if (nargs == 2) fz_pre_scale(transform, args[0], args[1]); else - fz_throw(ctx, FZ_ERROR_GENERIC, "wrong number of arguments to scale(): %d", nargs); + fz_throw(ctx, FZ_ERROR_SYNTAX, "wrong number of arguments to scale(): %d", nargs); } else if (!strcmp(keyword, "rotate")) { if (nargs != 1) - fz_throw(ctx, FZ_ERROR_GENERIC, "wrong number of arguments to rotate(): %d", nargs); + fz_throw(ctx, FZ_ERROR_SYNTAX, "wrong number of arguments to rotate(): %d", nargs); fz_pre_rotate(transform, args[0]); } @@ -257,7 +247,7 @@ svg_parse_transform(fz_context *ctx, svg_document *doc, char *str, fz_matrix *tr fz_matrix m; if (nargs != 1) - fz_throw(ctx, FZ_ERROR_GENERIC, "wrong number of arguments to skewX(): %d", nargs); + fz_throw(ctx, FZ_ERROR_SYNTAX, "wrong number of arguments to skewX(): %d", nargs); m.a = 1; m.b = 0; @@ -274,7 +264,7 @@ svg_parse_transform(fz_context *ctx, svg_document *doc, char *str, fz_matrix *tr fz_matrix m; if (nargs != 1) - fz_throw(ctx, FZ_ERROR_GENERIC, "wrong number of arguments to skewY(): %d", nargs); + fz_throw(ctx, FZ_ERROR_SYNTAX, "wrong number of arguments to skewY(): %d", nargs); m.a = 1; m.b = tanf(args[0] * 0.0174532925); @@ -288,7 +278,7 @@ svg_parse_transform(fz_context *ctx, svg_document *doc, char *str, fz_matrix *tr else { - fz_throw(ctx, FZ_ERROR_GENERIC, "unknown transform function: %s", keyword); + fz_throw(ctx, FZ_ERROR_SYNTAX, "unknown transform function: %s", keyword); } } } |