summaryrefslogtreecommitdiff
path: root/xps/xps_path.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-01-26 16:22:29 +0000
committerRobin Watts <robin.watts@artifex.com>2012-01-26 19:24:12 +0000
commit4a61e49b6eda6c9f74c8010548f529385a5ade5e (patch)
tree9d9fd82495c8d3b1a00ff3ef0dcd01f0f7147b21 /xps/xps_path.c
parent50dbc1a356577f3df15a876f6adb716dea29bdc5 (diff)
downloadmupdf-4a61e49b6eda6c9f74c8010548f529385a5ade5e.tar.xz
Pull in XPS commits from GhostXPS to MuXPS
This brings MuXPS up to date with GhostXPS as of today. The commits pulled in are: 856ecdc Whitespace fixes for parsing dashed line attributes 91dc749 Whitespace fixes while parsing points. This commit is tweaked from the original, and the changes will be pushed back into GhostXPS shortly. a298a05 Tiff premultiplied/non-premultiped alpha differences. No changes required for this, as we hold images premultiplied already (and already cope with premultiplying where required). Some changes to comments and cleanup code to avoid leaks though.
Diffstat (limited to 'xps/xps_path.c')
-rw-r--r--xps/xps_path.c53
1 files changed, 43 insertions, 10 deletions
diff --git a/xps/xps_path.c b/xps/xps_path.c
index 8b66e1ff..e3dff868 100644
--- a/xps/xps_path.c
+++ b/xps/xps_path.c
@@ -1,6 +1,41 @@
#include "fitz.h"
#include "muxps.h"
+char *
+xps_get_real_params(char *s, int num, float *x)
+{
+ int k = 0;
+
+ if (s == NULL || *s == 0)
+ return NULL;
+
+ while (*s)
+ {
+ while (*s == 0x0d || *s == '\t' || *s == ' ' || *s == 0x0a)
+ s++;
+ x[k] = (float)strtod(s, &s);
+ while (*s == 0x0d || *s == '\t' || *s == ' ' || *s == 0x0a)
+ s++;
+ if (*s == ',')
+ s++;
+ if (++k == num)
+ break;
+ }
+ return s;
+}
+
+char *
+xps_get_point(char *s_in, float *x, float *y)
+{
+ char *s_out = s_in;
+ float xy[2];
+
+ s_out = xps_get_real_params(s_out, 2, &xy[0]);
+ *x = xy[0];
+ *y = xy[1];
+ return s_out;
+}
+
static fz_point
fz_currentpoint(fz_path *path)
{
@@ -475,8 +510,8 @@ xps_parse_arc_segment(fz_context *doc, fz_path *path, xml_element *root, int str
if (!is_stroked)
*skipped_stroke = 1;
- sscanf(point_att, "%g,%g", &point_x, &point_y);
- sscanf(size_att, "%g,%g", &size_x, &size_y);
+ xps_get_point(point_att, &point_x, &point_y);
+ xps_get_point(size_att, &size_x, &size_y);
rotation_angle = fz_atof(rotation_angle_att);
is_large_arc = !strcmp(is_large_arc_att, "true");
is_clockwise = !strcmp(sweep_direction_att, "Clockwise");
@@ -518,8 +553,7 @@ xps_parse_poly_quadratic_bezier_segment(fz_context *doc, fz_path *path, xml_elem
while (*s != 0)
{
while (*s == ' ') s++;
- sscanf(s, "%g,%g", &x[n], &y[n]);
- while (*s != ' ' && *s != 0) s++;
+ s = xps_get_point(s, &x[n], &y[n]);
n ++;
if (n == 2)
{
@@ -567,8 +601,7 @@ xps_parse_poly_bezier_segment(fz_context *doc, fz_path *path, xml_element *root,
while (*s != 0)
{
while (*s == ' ') s++;
- sscanf(s, "%g,%g", &x[n], &y[n]);
- while (*s != ' ' && *s != 0) s++;
+ s = xps_get_point(s, &x[n], &y[n]);
n ++;
if (n == 3)
{
@@ -606,12 +639,11 @@ xps_parse_poly_line_segment(fz_context *doc, fz_path *path, xml_element *root, i
while (*s != 0)
{
while (*s == ' ') s++;
- sscanf(s, "%g,%g", &x, &y);
+ s = xps_get_point(s, &x, &y);
if (stroking && !is_stroked)
fz_moveto(doc, path, x, y);
else
fz_lineto(doc, path, x, y);
- while (*s != ' ' && *s != 0) s++;
}
}
@@ -640,7 +672,7 @@ xps_parse_path_figure(fz_context *doc, fz_path *path, xml_element *root, int str
if (is_filled_att)
is_filled = !strcmp(is_filled_att, "true");
if (start_point_att)
- sscanf(start_point_att, "%g,%g", &start_x, &start_y);
+ xps_get_point(start_point_att, &start_x, &start_y);
if (!stroking && !is_filled) /* not filled, when filling */
return;
@@ -910,7 +942,8 @@ xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *d
{
while (*s == ' ')
s++;
- stroke.dash_list[stroke.dash_len++] = fz_atof(s) * stroke.linewidth;
+ if (*s) /* needed in case of a space before the last quote */
+ stroke.dash_list[stroke.dash_len++] = fz_atof(s) * stroke.linewidth;
while (*s && *s != ' ')
s++;
}