diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2010-04-20 20:15:30 +0000 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2010-04-20 20:15:30 +0000 |
commit | 0ffe17b83c05efe7066e7bf4bd0ca1fa00389899 (patch) | |
tree | 3bead3a27105a41967cb1545ce17bbaf63c4d002 /xps | |
parent | aedcf47a54f382c1d510d0c07d644b450bf01ee5 (diff) | |
download | ghostpdl-0ffe17b83c05efe7066e7bf4bd0ca1fa00389899.tar.gz |
Reformat GhostXPS source to use 4 spaces for indentation rather than a mix of tabs and spaces.
git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@11090 a1074d23-0009-0410-80fe-cf8c14f379e6
Diffstat (limited to 'xps')
-rw-r--r-- | xps/ghostxps.h | 4 | ||||
-rw-r--r-- | xps/xpsanalyze.c | 282 | ||||
-rw-r--r-- | xps/xpscff.c | 640 | ||||
-rw-r--r-- | xps/xpscolor.c | 194 | ||||
-rw-r--r-- | xps/xpscommon.c | 42 | ||||
-rw-r--r-- | xps/xpsdoc.c | 398 | ||||
-rw-r--r-- | xps/xpsfont.c | 348 | ||||
-rw-r--r-- | xps/xpsglyphs.c | 434 | ||||
-rw-r--r-- | xps/xpsgradient.c | 638 | ||||
-rw-r--r-- | xps/xpshash.c | 97 | ||||
-rw-r--r-- | xps/xpsimage.c | 238 | ||||
-rw-r--r-- | xps/xpsmem.c | 88 | ||||
-rw-r--r-- | xps/xpsopacity.c | 48 | ||||
-rw-r--r-- | xps/xpspage.c | 198 | ||||
-rw-r--r-- | xps/xpspath.c | 920 | ||||
-rw-r--r-- | xps/xpspng.c | 6 | ||||
-rw-r--r-- | xps/xpsresource.c | 130 | ||||
-rw-r--r-- | xps/xpstiff.c | 38 | ||||
-rw-r--r-- | xps/xpstile.c | 223 | ||||
-rw-r--r-- | xps/xpstop.c | 158 | ||||
-rw-r--r-- | xps/xpsttf.c | 294 | ||||
-rw-r--r-- | xps/xpsutf.c | 42 | ||||
-rw-r--r-- | xps/xpsvisual.c | 6 | ||||
-rw-r--r-- | xps/xpsxml.c | 182 | ||||
-rw-r--r-- | xps/xpszip.c | 764 | ||||
-rw-r--r-- | xps/xpszipseek.c | 338 |
26 files changed, 3382 insertions, 3368 deletions
diff --git a/xps/ghostxps.h b/xps/ghostxps.h index 9c9322fc6..96e86e248 100644 --- a/xps/ghostxps.h +++ b/xps/ghostxps.h @@ -47,7 +47,7 @@ #include "gxpath.h" /* gsshade.h depends on it */ #include "gxfixed.h" /* gsshade.h depends on it */ -#include "gxmatrix.h" /* gxtype1.h depends on it */ +#include "gxmatrix.h" /* gxtype1.h depends on it */ #include "gsshade.h" #include "gsfunc.h" #include "gsfunc3.h" /* we use stitching and exponential interp */ @@ -412,7 +412,7 @@ int xps_parse_radial_gradient_brush(xps_context_t *ctx, char *base_uri, xps_reso void xps_free_image(xps_context_t *ctx, xps_image_t *image); int xps_parse_tiling_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_item_t *root, - int (*func)(xps_context_t*, char*, xps_resource_t*, xps_item_t*, void*), void *user); + int (*func)(xps_context_t*, char*, xps_resource_t*, xps_item_t*, void*), void *user); void xps_parse_matrix_transform(xps_context_t *ctx, xps_item_t *root, gs_matrix *matrix); void xps_parse_render_transform(xps_context_t *ctx, char *text, gs_matrix *matrix); diff --git a/xps/xpsanalyze.c b/xps/xpsanalyze.c index 7f0d3f0a9..4050ebf1e 100644 --- a/xps/xpsanalyze.c +++ b/xps/xpsanalyze.c @@ -33,11 +33,11 @@ xps_resource_dictionary_has_transparency(xps_context_t *ctx, char *base_uri, xps source = xps_att(root, "Source"); if (source) - return xps_remote_resource_dictionary_has_transparency(ctx, base_uri, source); + return xps_remote_resource_dictionary_has_transparency(ctx, base_uri, source); for (node = xps_down(root); node; node = xps_next(node)) { - // TODO: ... all kinds of stuff can be here, brushes, elements, whatnot + // TODO: ... all kinds of stuff can be here, brushes, elements, whatnot } return 1; @@ -53,19 +53,19 @@ xps_gradient_stops_have_transparency(xps_context_t *ctx, char *base_uri, xps_ite for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "GradientStop")) - { - color_att = xps_att(node, "Color"); - if (color_att) - { - xps_parse_color(ctx, base_uri, color_att, &colorspace, samples); - if (samples[0] < 1.0) - { - //dputs("page has transparency: GradientStop has alpha\n"); - return 1; - } - } - } + if (!strcmp(xps_tag(node), "GradientStop")) + { + color_att = xps_att(node, "Color"); + if (color_att) + { + xps_parse_color(ctx, base_uri, color_att, &colorspace, samples); + if (samples[0] < 1.0) + { + //dputs("page has transparency: GradientStop has alpha\n"); + return 1; + } + } + } } return 0; @@ -80,25 +80,25 @@ xps_gradient_brush_has_transparency(xps_context_t *ctx, char *base_uri, xps_item opacity_att = xps_att(root, "Opacity"); if (opacity_att) { - if (atof(opacity_att) < 1.0) - { - //dputs("page has transparency: GradientBrush Opacity\n"); - return 1; - } + if (atof(opacity_att) < 1.0) + { + //dputs("page has transparency: GradientBrush Opacity\n"); + return 1; + } } for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "RadialGradientBrush.GradientStops")) - { - if (xps_gradient_stops_have_transparency(ctx, base_uri, node)) - return 1; - } - if (!strcmp(xps_tag(node), "LinearGradientBrush.GradientStops")) - { - if (xps_gradient_stops_have_transparency(ctx, base_uri, node)) - return 1; - } + if (!strcmp(xps_tag(node), "RadialGradientBrush.GradientStops")) + { + if (xps_gradient_stops_have_transparency(ctx, base_uri, node)) + return 1; + } + if (!strcmp(xps_tag(node), "LinearGradientBrush.GradientStops")) + { + if (xps_gradient_stops_have_transparency(ctx, base_uri, node)) + return 1; + } } return 0; @@ -116,67 +116,67 @@ xps_brush_has_transparency(xps_context_t *ctx, char *base_uri, xps_item_t *root) if (!strcmp(xps_tag(root), "SolidColorBrush")) { - opacity_att = xps_att(root, "Opacity"); - if (opacity_att) - { - if (atof(opacity_att) < 1.0) - { - //dputs("page has transparency: SolidColorBrush Opacity\n"); - return 1; - } - } - - color_att = xps_att(root, "Color"); - if (color_att) - { - xps_parse_color(ctx, base_uri, color_att, &colorspace, samples); - if (samples[0] < 1.0) - { - //dputs("page has transparency: SolidColorBrush Color has alpha\n"); - return 1; - } - } + opacity_att = xps_att(root, "Opacity"); + if (opacity_att) + { + if (atof(opacity_att) < 1.0) + { + //dputs("page has transparency: SolidColorBrush Opacity\n"); + return 1; + } + } + + color_att = xps_att(root, "Color"); + if (color_att) + { + xps_parse_color(ctx, base_uri, color_att, &colorspace, samples); + if (samples[0] < 1.0) + { + //dputs("page has transparency: SolidColorBrush Color has alpha\n"); + return 1; + } + } } if (!strcmp(xps_tag(root), "VisualBrush")) { - char *opacity_att = xps_att(root, "Opacity"); - if (opacity_att) - { - if (atof(opacity_att) < 1.0) - { - //dputs("page has transparency: VisualBrush Opacity\n"); - return 1; - } - } - - for (node = xps_down(root); node; node = xps_next(node)) - { - if (!strcmp(xps_tag(node), "VisualBrush.Visual")) - { - if (xps_element_has_transparency(ctx, base_uri, xps_down(node))) - return 1; - } - } + char *opacity_att = xps_att(root, "Opacity"); + if (opacity_att) + { + if (atof(opacity_att) < 1.0) + { + //dputs("page has transparency: VisualBrush Opacity\n"); + return 1; + } + } + + for (node = xps_down(root); node; node = xps_next(node)) + { + if (!strcmp(xps_tag(node), "VisualBrush.Visual")) + { + if (xps_element_has_transparency(ctx, base_uri, xps_down(node))) + return 1; + } + } } if (!strcmp(xps_tag(root), "ImageBrush")) { - if (xps_image_brush_has_transparency(ctx, base_uri, root)) - return 1; + if (xps_image_brush_has_transparency(ctx, base_uri, root)) + return 1; } if (!strcmp(xps_tag(root), "LinearGradientBrush")) { - if (xps_gradient_brush_has_transparency(ctx, base_uri, root)) - return 1; + if (xps_gradient_brush_has_transparency(ctx, base_uri, root)) + return 1; } if (!strcmp(xps_tag(root), "RadialGradientBrush")) { - if (xps_gradient_brush_has_transparency(ctx, base_uri, root)) - return 1; + if (xps_gradient_brush_has_transparency(ctx, base_uri, root)) + return 1; } return 0; @@ -189,23 +189,23 @@ xps_path_has_transparency(xps_context_t *ctx, char *base_uri, xps_item_t *root) for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "Path.OpacityMask")) - { - //dputs("page has transparency: Path.OpacityMask\n"); - return 1; - } - - if (!strcmp(xps_tag(node), "Path.Stroke")) - { - if (xps_brush_has_transparency(ctx, base_uri, xps_down(node))) - return 1; - } - - if (!strcmp(xps_tag(node), "Path.Fill")) - { - if (xps_brush_has_transparency(ctx, base_uri, xps_down(node))) - return 1; - } + if (!strcmp(xps_tag(node), "Path.OpacityMask")) + { + //dputs("page has transparency: Path.OpacityMask\n"); + return 1; + } + + if (!strcmp(xps_tag(node), "Path.Stroke")) + { + if (xps_brush_has_transparency(ctx, base_uri, xps_down(node))) + return 1; + } + + if (!strcmp(xps_tag(node), "Path.Fill")) + { + if (xps_brush_has_transparency(ctx, base_uri, xps_down(node))) + return 1; + } } return 0; @@ -218,17 +218,17 @@ xps_glyphs_has_transparency(xps_context_t *ctx, char *base_uri, xps_item_t *root for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "Glyphs.OpacityMask")) - { - //dputs("page has transparency: Glyphs.OpacityMask\n"); - return 1; - } - - if (!strcmp(xps_tag(node), "Glyphs.Fill")) - { - if (xps_brush_has_transparency(ctx, base_uri, xps_down(node))) - return 1; - } + if (!strcmp(xps_tag(node), "Glyphs.OpacityMask")) + { + //dputs("page has transparency: Glyphs.OpacityMask\n"); + return 1; + } + + if (!strcmp(xps_tag(node), "Glyphs.Fill")) + { + if (xps_brush_has_transparency(ctx, base_uri, xps_down(node))) + return 1; + } } return 0; @@ -241,20 +241,20 @@ xps_canvas_has_transparency(xps_context_t *ctx, char *base_uri, xps_item_t *root for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "Canvas.Resources")) - { - if (xps_resource_dictionary_has_transparency(ctx, base_uri, xps_down(node))) - return 1; - } - - if (!strcmp(xps_tag(node), "Canvas.OpacityMask")) - { - //dputs("page has transparency: Canvas.OpacityMask\n"); - return 1; - } - - if (xps_element_has_transparency(ctx, base_uri, node)) - return 1; + if (!strcmp(xps_tag(node), "Canvas.Resources")) + { + if (xps_resource_dictionary_has_transparency(ctx, base_uri, xps_down(node))) + return 1; + } + + if (!strcmp(xps_tag(node), "Canvas.OpacityMask")) + { + //dputs("page has transparency: Canvas.OpacityMask\n"); + return 1; + } + + if (xps_element_has_transparency(ctx, base_uri, node)) + return 1; } return 0; @@ -273,50 +273,50 @@ xps_element_has_transparency(xps_context_t *ctx, char *base_uri, xps_item_t *nod stroke_att = xps_att(node, "Stroke"); if (stroke_att) { - xps_parse_color(ctx, base_uri, stroke_att, &colorspace, samples); - if (samples[0] < 1.0) - { - //dprintf1("page has transparency: Stroke alpha=%g\n", samples[0]); - return 1; - } + xps_parse_color(ctx, base_uri, stroke_att, &colorspace, samples); + if (samples[0] < 1.0) + { + //dprintf1("page has transparency: Stroke alpha=%g\n", samples[0]); + return 1; + } } fill_att = xps_att(node, "Fill"); if (fill_att) { - xps_parse_color(ctx, base_uri, fill_att, &colorspace, samples); - if (samples[0] < 1.0) - { - //dprintf1("page has transparency: Fill alpha=%g\n", samples[0]); - return 1; - } + xps_parse_color(ctx, base_uri, fill_att, &colorspace, samples); + if (samples[0] < 1.0) + { + //dprintf1("page has transparency: Fill alpha=%g\n", samples[0]); + return 1; + } } opacity_att = xps_att(node, "Opacity"); if (opacity_att) { - if (atof(opacity_att) < 1.0) - { - //dprintf1("page has transparency: Opacity=%g\n", atof(opacity_att)); - return 1; - } + if (atof(opacity_att) < 1.0) + { + //dprintf1("page has transparency: Opacity=%g\n", atof(opacity_att)); + return 1; + } } if (xps_att(node, "OpacityMask")) { - //dputs("page has transparency: OpacityMask\n"); - return 1; + //dputs("page has transparency: OpacityMask\n"); + return 1; } if (!strcmp(xps_tag(node), "Path")) - if (xps_path_has_transparency(ctx, base_uri, node)) - return 1; + if (xps_path_has_transparency(ctx, base_uri, node)) + return 1; if (!strcmp(xps_tag(node), "Glyphs")) - if (xps_glyphs_has_transparency(ctx, base_uri, node)) - return 1; + if (xps_glyphs_has_transparency(ctx, base_uri, node)) + return 1; if (!strcmp(xps_tag(node), "Canvas")) - if (xps_canvas_has_transparency(ctx, base_uri, node)) - return 1; + if (xps_canvas_has_transparency(ctx, base_uri, node)) + return 1; return 0; } diff --git a/xps/xpscff.c b/xps/xpscff.c index d4f932823..379f79842 100644 --- a/xps/xpscff.c +++ b/xps/xpscff.c @@ -76,25 +76,25 @@ xps_read_cff_real(byte *p, byte *e, float *val) while (txt < buf + (sizeof buf) - 3 && p < e) { - int b, n; - - b = *p++; - - n = (b >> 4) & 0xf; - if (n < 0xA) { *txt++ = n + '0'; } - else if (n == 0xA) { *txt++ = '.'; } - else if (n == 0xB) { *txt++ = 'E'; } - else if (n == 0xC) { *txt++ = 'E'; *txt++ = '-'; } - else if (n == 0xE) { *txt++ = '-'; } - else if (n == 0xF) { break; } - - n = b & 0xf; - if (n < 0xA) { *txt++ = n + '0'; } - else if (n == 0xA) { *txt++ = '.'; } - else if (n == 0xB) { *txt++ = 'E'; } - else if (n == 0xC) { *txt++ = 'E'; *txt++ = '-'; } - else if (n == 0xE) { *txt++ = '-'; } - else if (n == 0xF) { break; } + int b, n; + + b = *p++; + + n = (b >> 4) & 0xf; + if (n < 0xA) { *txt++ = n + '0'; } + else if (n == 0xA) { *txt++ = '.'; } + else if (n == 0xB) { *txt++ = 'E'; } + else if (n == 0xC) { *txt++ = 'E'; *txt++ = '-'; } + else if (n == 0xE) { *txt++ = '-'; } + else if (n == 0xF) { break; } + + n = b & 0xf; + if (n < 0xA) { *txt++ = n + '0'; } + else if (n == 0xA) { *txt++ = '.'; } + else if (n == 0xB) { *txt++ = 'E'; } + else if (n == 0xC) { *txt++ = 'E'; *txt++ = '-'; } + else if (n == 0xE) { *txt++ = '-'; } + else if (n == 0xF) { break; } } *txt = 0; @@ -111,55 +111,55 @@ xps_read_cff_integer(byte *p, byte *e, int b0, int *val) if (b0 == 28) { - if (p + 2 > e) - { - gs_throw(-1, "corrupt dictionary (integer)"); - return 0; - } - b1 = *p++; - b2 = *p++; - *val = (b1 << 8) | b2; + if (p + 2 > e) + { + gs_throw(-1, "corrupt dictionary (integer)"); + return 0; + } + b1 = *p++; + b2 = *p++; + *val = (b1 << 8) | b2; } else if (b0 == 29) { - if (p + 4 > e) - { - gs_throw(-1, "corrupt dictionary (integer)"); - return 0; - } - b1 = *p++; - b2 = *p++; - b3 = *p++; - b4 = *p++; - *val = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; + if (p + 4 > e) + { + gs_throw(-1, "corrupt dictionary (integer)"); + return 0; + } + b1 = *p++; + b2 = *p++; + b3 = *p++; + b4 = *p++; + *val = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; } else if (b0 < 247) { - *val = b0 - 139; + *val = b0 - 139; } else if (b0 < 251) { - if (p + 1 > e) - { - gs_throw(-1, "corrupt dictionary (integer)"); - return 0; - } - b1 = *p++; - *val = (b0 - 247) * 256 + b1 + 108; + if (p + 1 > e) + { + gs_throw(-1, "corrupt dictionary (integer)"); + return 0; + } + b1 = *p++; + *val = (b0 - 247) * 256 + b1 + 108; } else { - if (p + 1 > e) - { - gs_throw(-1, "corrupt dictionary (integer)"); - return 0; - } - b1 = *p++; - *val = -(b0 - 251) * 256 - b1 - 108; + if (p + 1 > e) + { + gs_throw(-1, "corrupt dictionary (integer)"); + return 0; + } + b1 = *p++; + *val = -(b0 - 251) * 256 - b1 - 108; } return p; @@ -180,193 +180,193 @@ xps_read_cff_dict(byte *p, byte *e, xps_font_t *font, gs_font_type1 *pt1) n = 0; while (p < e) { - b0 = *p++; - - if (b0 < 22) - { - if (b0 == 12) - { - if (p + 1 > e) - { - return gs_throw(-1, "corrupt dictionary (operator)"); - } - b0 = 0x100 | *p++; - } - - /* some CFF file offsets */ - - if (b0 == 17) - { - font->charstrings = font->cffdata + args[0].ival; - } - - if (b0 == 18) - { - privatelen = args[0].ival; - privateofs = args[1].ival; - } - - if (b0 == 19) - { - font->subrs = font->cffdata + offset + args[0].ival; - } - - if (b0 == (256 | 36)) - errprintf("warning: cid cff fonts not supported yet"); - if (b0 == (256 | 37)) - errprintf("warning: cid cff fonts not supported yet"); - - /* Type1 stuff that need to be set for the pt1 struct */ - - if (b0 == (256 | 6)) - { - if (args[0].ival == 1) - { - pt1->data.interpret = gs_type1_interpret; - pt1->data.lenIV = -1; // FIXME - } - } - - if (b0 == (256 | 7)) - { - pt1->FontMatrix.xx = args[0].fval; - pt1->FontMatrix.xy = args[1].fval; - pt1->FontMatrix.yx = args[2].fval; - pt1->FontMatrix.yy = args[3].fval; - pt1->FontMatrix.tx = args[4].fval; - pt1->FontMatrix.ty = args[5].fval; - } - - if (b0 == 5) - { - pt1->FontBBox.p.x = args[0].fval; - pt1->FontBBox.p.y = args[1].fval; - pt1->FontBBox.q.x = args[2].fval; - pt1->FontBBox.q.y = args[3].fval; - } - - if (b0 == 20) - pt1->data.defaultWidthX = float2fixed(args[0].fval); - - if (b0 == 21) - pt1->data.nominalWidthX = float2fixed(args[0].fval); - - if (b0 == (256 | 19)) - pt1->data.initialRandomSeed = args[0].ival; - - /* Monday morning blues */ + b0 = *p++; + + if (b0 < 22) + { + if (b0 == 12) + { + if (p + 1 > e) + { + return gs_throw(-1, "corrupt dictionary (operator)"); + } + b0 = 0x100 | *p++; + } + + /* some CFF file offsets */ + + if (b0 == 17) + { + font->charstrings = font->cffdata + args[0].ival; + } + + if (b0 == 18) + { + privatelen = args[0].ival; + privateofs = args[1].ival; + } + + if (b0 == 19) + { + font->subrs = font->cffdata + offset + args[0].ival; + } + + if (b0 == (256 | 36)) + errprintf("warning: cid cff fonts not supported yet"); + if (b0 == (256 | 37)) + errprintf("warning: cid cff fonts not supported yet"); + + /* Type1 stuff that need to be set for the pt1 struct */ + + if (b0 == (256 | 6)) + { + if (args[0].ival == 1) + { + pt1->data.interpret = gs_type1_interpret; + pt1->data.lenIV = -1; // FIXME + } + } + + if (b0 == (256 | 7)) + { + pt1->FontMatrix.xx = args[0].fval; + pt1->FontMatrix.xy = args[1].fval; + pt1->FontMatrix.yx = args[2].fval; + pt1->FontMatrix.yy = args[3].fval; + pt1->FontMatrix.tx = args[4].fval; + pt1->FontMatrix.ty = args[5].fval; + } + + if (b0 == 5) + { + pt1->FontBBox.p.x = args[0].fval; + pt1->FontBBox.p.y = args[1].fval; + pt1->FontBBox.q.x = args[2].fval; + pt1->FontBBox.q.y = args[3].fval; + } + + if (b0 == 20) + pt1->data.defaultWidthX = float2fixed(args[0].fval); + + if (b0 == 21) + pt1->data.nominalWidthX = float2fixed(args[0].fval); + + if (b0 == (256 | 19)) + pt1->data.initialRandomSeed = args[0].ival; + + /* Monday morning blues */ #if 0 - if (b0 == 6) - { - pt1->data.BlueValues.count = n / 2; - for (f = 0, i = 0; i < n; f += args[i].fval, i++) - pt1->data.BlueValues.values[i] = f; - } - - if (b0 == 7) - { - pt1->data.OtherBlues.count = n / 2; - for (f = 0, i = 0; i < n; f += args[i].fval, i++) - pt1->data.OtherBlues.values[i] = f; - } - - if (b0 == 8) - { - pt1->data.FamilyBlues.count = n / 2; - for (f = 0, i = 0; i < n; f += args[i].fval, i++) - pt1->data.FamilyBlues.values[i] = f; - } - - if (b0 == 9) - { - pt1->data.FamilyOtherBlues.count = n / 2; - for (f = 0, i = 0; i < n; f += args[i].fval, i++) - pt1->data.FamilyOtherBlues.values[i] = f; - } - - if (b0 == 10) - { - pt1->data.StdHW.count = 1; - pt1->data.StdHW.values[0] = args[0].fval; - } - - if (b0 == 11) - { - pt1->data.StdVW.count = 1; - pt1->data.StdVW.values[0] = args[0].fval; - } - - if (b0 == (256 | 9)) - pt1->data.BlueScale = args[0].fval; - - if (b0 == (256 | 10)) - pt1->data.BlueShift = args[0].fval; - - if (b0 == (256 | 11)) - pt1->data.BlueFuzz = args[0].fval; - - if (b0 == (256 | 12)) - { - pt1->data.StemSnapH.count = n; - for (f = 0, i = 0; i < n; f += args[i].fval, i++) - pt1->data.StemSnapH.values[i] = f; - } - - if (b0 == (256 | 13)) - { - pt1->data.StemSnapV.count = n; - for (f = 0, i = 0; i < n; f += args[i].fval, i++) - pt1->data.StemSnapV.values[i] = f; - } - - if (b0 == (256 | 14)) - pt1->data.ForceBold = args[0].ival; - - if (b0 == (256 | 17)) - pt1->data.LanguageGroup = args[0].ival; - - if (b0 == (256 | 18)) - pt1->data.ExpansionFactor = args[0].fval; + if (b0 == 6) + { + pt1->data.BlueValues.count = n / 2; + for (f = 0, i = 0; i < n; f += args[i].fval, i++) + pt1->data.BlueValues.values[i] = f; + } + + if (b0 == 7) + { + pt1->data.OtherBlues.count = n / 2; + for (f = 0, i = 0; i < n; f += args[i].fval, i++) + pt1->data.OtherBlues.values[i] = f; + } + + if (b0 == 8) + { + pt1->data.FamilyBlues.count = n / 2; + for (f = 0, i = 0; i < n; f += args[i].fval, i++) + pt1->data.FamilyBlues.values[i] = f; + } + + if (b0 == 9) + { + pt1->data.FamilyOtherBlues.count = n / 2; + for (f = 0, i = 0; i < n; f += args[i].fval, i++) + pt1->data.FamilyOtherBlues.values[i] = f; + } + + if (b0 == 10) + { + pt1->data.StdHW.count = 1; + pt1->data.StdHW.values[0] = args[0].fval; + } + + if (b0 == 11) + { + pt1->data.StdVW.count = 1; + pt1->data.StdVW.values[0] = args[0].fval; + } + + if (b0 == (256 | 9)) + pt1->data.BlueScale = args[0].fval; + + if (b0 == (256 | 10)) + pt1->data.BlueShift = args[0].fval; + + if (b0 == (256 | 11)) + pt1->data.BlueFuzz = args[0].fval; + + if (b0 == (256 | 12)) + { + pt1->data.StemSnapH.count = n; + for (f = 0, i = 0; i < n; f += args[i].fval, i++) + pt1->data.StemSnapH.values[i] = f; + } + + if (b0 == (256 | 13)) + { + pt1->data.StemSnapV.count = n; + for (f = 0, i = 0; i < n; f += args[i].fval, i++) + pt1->data.StemSnapV.values[i] = f; + } + + if (b0 == (256 | 14)) + pt1->data.ForceBold = args[0].ival; + + if (b0 == (256 | 17)) + pt1->data.LanguageGroup = args[0].ival; + + if (b0 == (256 | 18)) + pt1->data.ExpansionFactor = args[0].fval; #endif - n = 0; - } - - else - { - if (b0 == 30) - { - p = xps_read_cff_real(p, e, &args[n].fval); - if (!p) - return gs_throw(-1, "corrupt dictionary operand"); - args[n].ival = (int) args[n].fval; - n++; - } - else if (b0 == 28 || b0 == 29 || (b0 >= 32 && b0 <= 254)) - { - p = xps_read_cff_integer(p, e, b0, &args[n].ival); - if (!p) - return gs_throw(-1, "corrupt dictionary operand"); - args[n].fval = (float) args[n].ival; - n++; - } - else - { - return gs_throw1(-1, "corrupt dictionary operand (b0 = %d)", b0); - } - } + n = 0; + } + + else + { + if (b0 == 30) + { + p = xps_read_cff_real(p, e, &args[n].fval); + if (!p) + return gs_throw(-1, "corrupt dictionary operand"); + args[n].ival = (int) args[n].fval; + n++; + } + else if (b0 == 28 || b0 == 29 || (b0 >= 32 && b0 <= 254)) + { + p = xps_read_cff_integer(p, e, b0, &args[n].ival); + if (!p) + return gs_throw(-1, "corrupt dictionary operand"); + args[n].fval = (float) args[n].ival; + n++; + } + else + { + return gs_throw1(-1, "corrupt dictionary operand (b0 = %d)", b0); + } + } } /* recurse for the private dictionary */ if (privatelen) { - int code = xps_read_cff_dict( - font->cffdata + privateofs, - font->cffdata + privateofs + privatelen, - font, pt1); - if (code < 0) - return gs_rethrow(code, "cannot read private dictionary"); + int code = xps_read_cff_dict( + font->cffdata + privateofs, + font->cffdata + privateofs + privatelen, + font, pt1); + if (code < 0) + return gs_rethrow(code, "cannot read private dictionary"); } return 0; @@ -384,28 +384,28 @@ xps_count_cff_index(byte *p, byte *e, int *countp) if (p + 3 > e) { - gs_throw(-1, "not enough data for index header"); - return 0; + gs_throw(-1, "not enough data for index header"); + return 0; } count = u16(p); p += 2; *countp = count; if (count == 0) - return p; + return p; offsize = *p++; if (offsize < 1 || offsize > 4) { - gs_throw(-1, "corrupt index header"); - return 0; + gs_throw(-1, "corrupt index header"); + return 0; } if (p + count * offsize > e) { - gs_throw(-1, "not enough data for index offset table"); - return 0; + gs_throw(-1, "not enough data for index offset table"); + return 0; } p += count * offsize; @@ -415,8 +415,8 @@ xps_count_cff_index(byte *p, byte *e, int *countp) if (p + last > e) { - gs_throw(-1, "not enough data for index data"); - return 0; + gs_throw(-1, "not enough data for index data"); + return 0; } p += last; @@ -437,32 +437,32 @@ xps_find_cff_index(byte *p, byte *e, int idx, byte **pp, byte **ep) if (p + 3 > e) { - gs_throw(-1, "not enough data for index header"); - return 0; + gs_throw(-1, "not enough data for index header"); + return 0; } count = u16(p); p += 2; if (count == 0) - return 0; + return 0; offsize = *p++; if (offsize < 1 || offsize > 4) { - gs_throw(-1, "corrupt index header"); - return 0; + gs_throw(-1, "corrupt index header"); + return 0; } if (p + count * offsize > e) { - gs_throw(-1, "not enough data for index offset table"); - return 0; + gs_throw(-1, "not enough data for index offset table"); + return 0; } if (idx < 0 || idx >= count) { - gs_throw(-1, "tried to access non-existing index item"); - return 0; + gs_throw(-1, "tried to access non-existing index item"); + return 0; } sofs = uofs(p + idx * offsize, offsize); @@ -475,14 +475,14 @@ xps_find_cff_index(byte *p, byte *e, int idx, byte **pp, byte **ep) if (p + last > e) { - gs_throw(-1, "not enough data for index data"); - return 0; + gs_throw(-1, "not enough data for index data"); + return 0; } if (sofs < 0 || eofs < 0 || sofs > eofs || eofs > last) { - gs_throw(-1, "corrupt index offset table"); - return 0; + gs_throw(-1, "corrupt index offset table"); + return 0; } *pp = p + sofs; @@ -508,66 +508,66 @@ xps_read_cff_file(xps_font_t *font, gs_font_type1 *pt1) /* CFF header */ { - int major, minor, hdrsize, offsize; + int major, minor, hdrsize, offsize; - if (p + 4 > e) - return gs_throw(-1, "not enough data for header"); + if (p + 4 > e) + return gs_throw(-1, "not enough data for header"); - major = *p++; - minor = *p++; - hdrsize = *p++; - offsize = *p++; + major = *p++; + minor = *p++; + hdrsize = *p++; + offsize = *p++; - if (major != 1 || minor != 0) - return gs_throw(-1, "not a CFF 1.0 file"); + if (major != 1 || minor != 0) + return gs_throw(-1, "not a CFF 1.0 file"); - if (p + hdrsize - 4 > e) - return gs_throw(-1, "not enough data for extended header"); + if (p + hdrsize - 4 > e) + return gs_throw(-1, "not enough data for extended header"); } /* Name INDEX */ p = xps_count_cff_index(p, e, &count); if (!p) - return gs_throw(-1, "cannot read name index"); + return gs_throw(-1, "cannot read name index"); if (count != 1) - return gs_throw(-1, "file did not contain exactly one font"); + return gs_throw(-1, "file did not contain exactly one font"); /* Top Dict INDEX */ p = xps_find_cff_index(p, e, 0, &dictp, &dicte); if (!p) - return gs_throw(-1, "cannot read top dict index"); + return gs_throw(-1, "cannot read top dict index"); /* String index */ p = xps_count_cff_index(p, e, &count); if (!p) - return gs_throw(-1, "cannot read string index"); + return gs_throw(-1, "cannot read string index"); /* Global Subr INDEX */ font->gsubrs = p; p = xps_count_cff_index(p, e, &ngsubrs); if (!p) - return gs_throw(-1, "cannot read gsubr index"); + return gs_throw(-1, "cannot read gsubr index"); /* Read the top and private dictionaries */ code = xps_read_cff_dict(dictp, dicte, font, pt1); if (code < 0) - return gs_rethrow(code, "cannot read top dictionary"); + return gs_rethrow(code, "cannot read top dictionary"); /* Check the subrs index */ nsubrs = 0; if (font->subrs) { - p = xps_count_cff_index(font->subrs, e, &nsubrs); - if (!p) - return gs_rethrow(-1, "cannot read subrs index"); + p = xps_count_cff_index(font->subrs, e, &nsubrs); + if (!p) + return gs_rethrow(-1, "cannot read subrs index"); } /* Check the charstrings index */ if (font->charstrings) { - p = xps_count_cff_index(font->charstrings, e, &count); - if (!p) - return gs_rethrow(-1, "cannot read charstrings index"); + p = xps_count_cff_index(font->charstrings, e, &count); + if (!p) + return gs_rethrow(-1, "cannot read charstrings index"); } pt1->data.subroutineNumberBias = subrbias(nsubrs); @@ -589,7 +589,7 @@ xps_post_callback_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t spc) int value; value = xps_encode_font_char(xf, chr); if (value == 0) - return gs_no_glyph; + return gs_no_glyph; return value; } @@ -608,7 +608,7 @@ xps_post_callback_glyph_name(gs_font *pf, gs_glyph glyph, gs_const_string *pstr) static int xps_post_callback_glyph_info(gs_font *font, gs_glyph glyph, - const gs_matrix *pmat, int members, gs_glyph_info_t *info) + const gs_matrix *pmat, int members, gs_glyph_info_t *info) { dprintf1("asking for CFF glyph info %lu\n", (ulong)glyph); return -1; @@ -616,7 +616,7 @@ xps_post_callback_glyph_info(gs_font *font, gs_glyph glyph, static int xps_post_callback_glyph_outline(gs_font *font, int wmode, gs_glyph glyph, - const gs_matrix *pmat, gx_path *ppath, double sbw[4]) + const gs_matrix *pmat, gx_path *ppath, double sbw[4]) { dprintf1("asking for CFF glyph outline %lu\n", (ulong)glyph); return -1; @@ -647,7 +647,7 @@ xps_post_callback_glyph_data(gs_font_type1 * pfont, gs_glyph glyph, gs_glyph_dat p = xps_find_cff_index(font->charstrings, font->cffend, glyph, &s, &e); if (!p) - return gs_rethrow(gs_error_rangecheck, "cannot find charstring"); + return gs_rethrow(gs_error_rangecheck, "cannot find charstring"); gs_glyph_data_from_string(pgd, s, e - s, NULL); @@ -656,7 +656,7 @@ xps_post_callback_glyph_data(gs_font_type1 * pfont, gs_glyph glyph, gs_glyph_dat static int xps_post_callback_subr_data(gs_font_type1 * pfont, - int subr_num, bool global, gs_glyph_data_t *pgd) + int subr_num, bool global, gs_glyph_data_t *pgd) { xps_font_t *font = pfont->client_data; byte *s, *e; @@ -664,15 +664,15 @@ xps_post_callback_subr_data(gs_font_type1 * pfont, if (global) { - p = xps_find_cff_index(font->gsubrs, font->cffend, subr_num, &s, &e); - if (!p) - return gs_rethrow(gs_error_rangecheck, "cannot find gsubr"); + p = xps_find_cff_index(font->gsubrs, font->cffend, subr_num, &s, &e); + if (!p) + return gs_rethrow(gs_error_rangecheck, "cannot find gsubr"); } else { - p = xps_find_cff_index(font->subrs, font->cffend, subr_num, &s, &e); - if (!p) - return gs_rethrow(gs_error_rangecheck, "cannot find subr"); + p = xps_find_cff_index(font->subrs, font->cffend, subr_num, &s, &e); + if (!p) + return gs_rethrow(gs_error_rangecheck, "cannot find subr"); } gs_glyph_data_from_string(pgd, s, e - s, NULL); @@ -682,7 +682,7 @@ xps_post_callback_subr_data(gs_font_type1 * pfont, static int xps_post_callback_seac_data(gs_font_type1 * pfont, int ccode, gs_glyph * pglyph, - gs_const_string *gstr, gs_glyph_data_t *pgd) + gs_const_string *gstr, gs_glyph_data_t *pgd) { return gs_throw(-1, "seac is deprecated in CFF fonts"); } @@ -715,7 +715,7 @@ xps_cff_append(gs_state *pgs, gs_font_type1 *pt1, gs_glyph glyph, int donthint) /* get charstring data */ code = xps_post_callback_glyph_data(pt1, glyph, pgd); if (code < 0) - return gs_rethrow(code, "cannot get glyph data"); + return gs_rethrow(code, "cannot get glyph data"); mtx = ctm_only(pgs); gs_matrix_scale(&mtx, 0.001, 0.001, &mtx); @@ -726,7 +726,7 @@ xps_cff_append(gs_state *pgs, gs_font_type1 *pt1, gs_glyph glyph, int donthint) code = gs_type1_interp_init(&cxs.cis, pgis, pgs->path, NULL, NULL, donthint, 0, pt1); if (code < 0) - return gs_throw(code, "cannot init type1 interpreter"); + return gs_throw(code, "cannot init type1 interpreter"); gs_type1_set_callback_data(pcis, &cxs); @@ -738,27 +738,27 @@ xps_cff_append(gs_state *pgs, gs_font_type1 *pt1, gs_glyph glyph, int donthint) while (1) { - code = pt1->data.interpret(pcis, pgd, &value); - switch (code) - { - case type1_result_callothersubr: /* unknown OtherSubr */ - return_error(-15); /* can't handle it */ - case type1_result_sbw: /* [h]sbw, just continue */ - type1_cis_get_metrics(pcis, cxs.sbw); - type1_cis_get_metrics(pcis, sbw); - pgd = 0; - break; - case 0: /* all done */ - return 0; - default: /* code < 0, error */ - return gs_throw(code, "cannot interpret type1 data"); - } + code = pt1->data.interpret(pcis, pgd, &value); + switch (code) + { + case type1_result_callothersubr: /* unknown OtherSubr */ + return_error(-15); /* can't handle it */ + case type1_result_sbw: /* [h]sbw, just continue */ + type1_cis_get_metrics(pcis, cxs.sbw); + type1_cis_get_metrics(pcis, sbw); + pgd = 0; + break; + case 0: /* all done */ + return 0; + default: /* code < 0, error */ + return gs_throw(code, "cannot interpret type1 data"); + } } } static int xps_post_callback_build_char(gs_show_enum *penum, gs_state *pgs, - gs_font *pfont, gs_char chr, gs_glyph glyph) + gs_font *pfont, gs_char chr, gs_glyph glyph) { gs_font_type1 *pt1 = (gs_font_type1*)pfont; const gs_rect *pbbox; @@ -778,25 +778,25 @@ xps_post_callback_build_char(gs_show_enum *penum, gs_state *pgs, /* Expand the bbox when stroking */ if ( pfont->PaintType ) { - float expand = max(1.415, gs_currentmiterlimit(pgs)) * gs_currentlinewidth(pgs) / 2; - w2[2] -= expand, w2[3] -= expand; - w2[4] += expand, w2[5] += expand; + float expand = max(1.415, gs_currentmiterlimit(pgs)) * gs_currentlinewidth(pgs) / 2; + w2[2] -= expand, w2[3] -= expand; + w2[4] += expand, w2[5] += expand; } if ( (code = gs_moveto(pgs, 0.0, 0.0)) < 0 ) - return code; - + return code; + if ( (code = gs_setcachedevice(penum, pgs, w2)) < 0 ) - return code; + return code; code = xps_cff_append(pgs, pt1, glyph, - gs_show_in_charpath(penum) != cpm_show); + gs_show_in_charpath(penum) != cpm_show); if (code < 0) - return code; + return code; code = (pfont->PaintType ? gs_stroke(pgs) : gs_fill(pgs)); if (code < 0) - return code; + return code; return 0; } @@ -815,10 +815,10 @@ xps_init_postscript_font(xps_context_t *ctx, xps_font_t *font) cffofs = xps_find_sfnt_table(font, "CFF ", &cfflen); if (cffofs < 0) - return gs_throw(-1, "cannot find CFF table"); + return gs_throw(-1, "cannot find CFF table"); if (cfflen < 0 || cffofs + cfflen > font->length) - return gs_throw(-1, "corrupt CFF table location"); + return gs_throw(-1, "corrupt CFF table location"); font->cffdata = font->data + cffofs; font->cffend = font->data + cffofs + cfflen; @@ -829,7 +829,7 @@ xps_init_postscript_font(xps_context_t *ctx, xps_font_t *font) pt1 = (void*) gs_alloc_struct(ctx->memory, gs_font_type1, &st_gs_font_type1, "xps_font type1"); if (!pt1) - return gs_throw(-1, "out of memory"); + return gs_throw(-1, "out of memory"); font->font = (void*) pt1; @@ -863,7 +863,7 @@ xps_init_postscript_font(xps_context_t *ctx, xps_font_t *font) pt1->procs.make_font = gs_no_make_font; pt1->procs.font_info = gs_default_font_info; pt1->procs.same_font = gs_default_same_font; - pt1->procs.encode_char = xps_post_callback_encode_char; + pt1->procs.encode_char = xps_post_callback_encode_char; pt1->procs.decode_glyph = xps_post_callback_decode_glyph; pt1->procs.enumerate_glyph = gs_no_enumerate_glyph; pt1->procs.glyph_info = xps_post_callback_glyph_info; @@ -934,8 +934,8 @@ xps_init_postscript_font(xps_context_t *ctx, xps_font_t *font) code = xps_read_cff_file(font, pt1); if (code < 0) { - // TODO free pt1 here? - return gs_rethrow(code, "cannot read cff file structure"); + // TODO free pt1 here? + return gs_rethrow(code, "cannot read cff file structure"); } gs_definefont(ctx->fontdir, font->font); diff --git a/xps/xpscolor.c b/xps/xpscolor.c index 0bbf37a5e..234a5c863 100644 --- a/xps/xpscolor.c +++ b/xps/xpscolor.c @@ -25,19 +25,19 @@ xps_set_color(xps_context_t *ctx, gs_color_space *cs, float *samples) if (ctx->opacity_only) { - gs_setopacityalpha(ctx->pgs, 1.0); - gs_setgray(ctx->pgs, samples[0]); + gs_setopacityalpha(ctx->pgs, 1.0); + gs_setgray(ctx->pgs, samples[0]); } else { - n = cs_num_components(cs); - cc.pattern = 0; - for (i = 0; i < n; i++) - cc.paint.values[i] = samples[i + 1]; - - gs_setopacityalpha(ctx->pgs, samples[0]); - gs_setcolorspace(ctx->pgs, cs); - gs_setcolor(ctx->pgs, &cc); + n = cs_num_components(cs); + cc.pattern = 0; + for (i = 0; i < n; i++) + cc.paint.values[i] = samples[i + 1]; + + gs_setopacityalpha(ctx->pgs, samples[0]); + gs_setcolorspace(ctx->pgs, cs); + gs_setcolor(ctx->pgs, &cc); } return 0; @@ -54,9 +54,9 @@ static int count_commas(char *s) int n = 0; while (*s) { - if (*s == ',') - n ++; - s ++; + if (*s == ',') + n ++; + s ++; } return n; } @@ -80,105 +80,105 @@ xps_parse_color(xps_context_t *ctx, char *base_uri, char *string, gs_color_space if (string[0] == '#') { - if (strlen(string) == 9) - { - samples[0] = unhex(string[1]) * 16 + unhex(string[2]); - samples[1] = unhex(string[3]) * 16 + unhex(string[4]); - samples[2] = unhex(string[5]) * 16 + unhex(string[6]); - samples[3] = unhex(string[7]) * 16 + unhex(string[8]); - } - else - { - samples[0] = 255.0; - samples[1] = unhex(string[1]) * 16 + unhex(string[2]); - samples[2] = unhex(string[3]) * 16 + unhex(string[4]); - samples[3] = unhex(string[5]) * 16 + unhex(string[6]); - } - - samples[0] /= 255.0; - samples[1] /= 255.0; - samples[2] /= 255.0; - samples[3] /= 255.0; - - return 0; + if (strlen(string) == 9) + { + samples[0] = unhex(string[1]) * 16 + unhex(string[2]); + samples[1] = unhex(string[3]) * 16 + unhex(string[4]); + samples[2] = unhex(string[5]) * 16 + unhex(string[6]); + samples[3] = unhex(string[7]) * 16 + unhex(string[8]); + } + else + { + samples[0] = 255.0; + samples[1] = unhex(string[1]) * 16 + unhex(string[2]); + samples[2] = unhex(string[3]) * 16 + unhex(string[4]); + samples[3] = unhex(string[5]) * 16 + unhex(string[6]); + } + + samples[0] /= 255.0; + samples[1] /= 255.0; + samples[2] /= 255.0; + samples[3] /= 255.0; + + return 0; } else if (string[0] == 's' && string[1] == 'c' && string[2] == '#') { - if (count_commas(string) == 2) - sscanf(string, "sc#%g,%g,%g", samples + 1, samples + 2, samples + 3); - if (count_commas(string) == 3) - sscanf(string, "sc#%g,%g,%g,%g", samples, samples + 1, samples + 2, samples + 3); - return 0; + if (count_commas(string) == 2) + sscanf(string, "sc#%g,%g,%g", samples + 1, samples + 2, samples + 3); + if (count_commas(string) == 3) + sscanf(string, "sc#%g,%g,%g,%g", samples, samples + 1, samples + 2, samples + 3); + return 0; } else if (strstr(string, "ContextColor ") == string) { - /* Crack the string for profile name and sample values */ - strcpy(buf, string); - - profile = strchr(buf, ' '); - if (!profile) - return gs_throw1(-1, "cannot find icc profile uri in '%s'", string); - - *profile++ = 0; - p = strchr(profile, ' '); - if (!p) - return gs_throw1(-1, "cannot find component values in '%s'", profile); - - *p++ = 0; - n = count_commas(p) + 1; - i = 0; - while (i < n) - { - samples[i++] = atof(p); - p = strchr(p, ','); - if (!p) - break; - p ++; - if (*p == ' ') - p ++; - } - while (i < n) - { - samples[i++] = 0.0; - } - - /* Default fallbacks if the ICC stuff fails */ - - if (n == 2) /* alpha + tint */ - *csp = ctx->gray; - - if (n == 5) /* alpha + CMYK */ - *csp = ctx->cmyk; - - /* Find ICC colorspace part */ - - xps_absolute_path(partname, base_uri, profile); - part = xps_read_part(ctx, partname); - if (!part) - return gs_throw1(-1, "cannot find icc profile part '%s'", partname); + /* Crack the string for profile name and sample values */ + strcpy(buf, string); + + profile = strchr(buf, ' '); + if (!profile) + return gs_throw1(-1, "cannot find icc profile uri in '%s'", string); + + *profile++ = 0; + p = strchr(profile, ' '); + if (!p) + return gs_throw1(-1, "cannot find component values in '%s'", profile); + + *p++ = 0; + n = count_commas(p) + 1; + i = 0; + while (i < n) + { + samples[i++] = atof(p); + p = strchr(p, ','); + if (!p) + break; + p ++; + if (*p == ' ') + p ++; + } + while (i < n) + { + samples[i++] = 0.0; + } + + /* Default fallbacks if the ICC stuff fails */ + + if (n == 2) /* alpha + tint */ + *csp = ctx->gray; + + if (n == 5) /* alpha + CMYK */ + *csp = ctx->cmyk; + + /* Find ICC colorspace part */ + + xps_absolute_path(partname, base_uri, profile); + part = xps_read_part(ctx, partname); + if (!part) + return gs_throw1(-1, "cannot find icc profile part '%s'", partname); #if 0 /* disable ICC profiles until gsicc_manager is available */ - if (!part->icc) - { - code = xps_parse_icc_profile(ctx, &part->icc, (byte*)part->data, part->size, n - 1); - if (code < 0) - return gs_rethrow1(code, "cannot parse icc profile part '%s'", partname); - } + if (!part->icc) + { + code = xps_parse_icc_profile(ctx, &part->icc, (byte*)part->data, part->size, n - 1); + if (code < 0) + return gs_rethrow1(code, "cannot parse icc profile part '%s'", partname); + } - *csp = part->icc; + *csp = part->icc; #endif - xps_release_part(ctx, part); + xps_release_part(ctx, part); - return 0; + return 0; } else { - return gs_throw1(-1, "cannot parse color (%s)", string); + return gs_throw1(-1, "cannot parse color (%s)", string); } } @@ -190,8 +190,8 @@ xps_stream_from_buffer(xps_context_t *ctx, byte *data, int length) stm = xps_alloc(ctx, sizeof(struct stream_s)); if (!stm) { - gs_throw(-1, "out of memory: stream struct"); - return NULL; + gs_throw(-1, "out of memory: stream struct"); + return NULL; } sread_string(stm, data, length); @@ -225,10 +225,10 @@ xps_parse_solid_color_brush(xps_context_t *ctx, char *base_uri, xps_resource_t * samples[3] = 0.0; if (color_att) - xps_parse_color(ctx, base_uri, color_att, &colorspace, samples); + xps_parse_color(ctx, base_uri, color_att, &colorspace, samples); if (opacity_att) - samples[0] = atof(opacity_att); + samples[0] = atof(opacity_att); xps_set_color(ctx, colorspace, samples); diff --git a/xps/xpscommon.c b/xps/xpscommon.c index 075a58095..524d0ba15 100644 --- a/xps/xpscommon.c +++ b/xps/xpscommon.c @@ -19,15 +19,15 @@ int xps_parse_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_item_t *node) { if (!strcmp(xps_tag(node), "SolidColorBrush")) - return xps_parse_solid_color_brush(ctx, base_uri, dict, node); + return xps_parse_solid_color_brush(ctx, base_uri, dict, node); if (!strcmp(xps_tag(node), "ImageBrush")) - return xps_parse_image_brush(ctx, base_uri, dict, node); + return xps_parse_image_brush(ctx, base_uri, dict, node); if (!strcmp(xps_tag(node), "VisualBrush")) - return xps_parse_visual_brush(ctx, base_uri, dict, node); + return xps_parse_visual_brush(ctx, base_uri, dict, node); if (!strcmp(xps_tag(node), "LinearGradientBrush")) - return xps_parse_linear_gradient_brush(ctx, base_uri, dict, node); + return xps_parse_linear_gradient_brush(ctx, base_uri, dict, node); if (!strcmp(xps_tag(node), "RadialGradientBrush")) - return xps_parse_radial_gradient_brush(ctx, base_uri, dict, node); + return xps_parse_radial_gradient_brush(ctx, base_uri, dict, node); return gs_throw1(-1, "unknown brush tag: %s", xps_tag(node)); } @@ -35,11 +35,11 @@ int xps_parse_element(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_item_t *node) { if (!strcmp(xps_tag(node), "Path")) - return xps_parse_path(ctx, base_uri, dict, node); + return xps_parse_path(ctx, base_uri, dict, node); if (!strcmp(xps_tag(node), "Glyphs")) - return xps_parse_glyphs(ctx, base_uri, dict, node); + return xps_parse_glyphs(ctx, base_uri, dict, node); if (!strcmp(xps_tag(node), "Canvas")) - return xps_parse_canvas(ctx, base_uri, dict, node); + return xps_parse_canvas(ctx, base_uri, dict, node); /* skip unknown tags (like Foo.Resources and similar) */ return 0; } @@ -57,11 +57,11 @@ xps_parse_render_transform(xps_context_t *ctx, char *transform, gs_matrix *matri for (i = 0; i < 6 && *s; i++) { - args[i] = atof(s); - while (*s && *s != ',') - s++; - if (*s == ',') - s++; + args[i] = atof(s); + while (*s && *s != ',') + s++; + if (*s == ',') + s++; } matrix->xx = args[0]; matrix->xy = args[1]; @@ -78,9 +78,9 @@ xps_parse_matrix_transform(xps_context_t *ctx, xps_item_t *root, gs_matrix *matr if (!strcmp(xps_tag(root), "MatrixTransform")) { - transform = xps_att(root, "Matrix"); - if (transform) - xps_parse_render_transform(ctx, transform, matrix); + transform = xps_att(root, "Matrix"); + if (transform) + xps_parse_render_transform(ctx, transform, matrix); } } @@ -96,11 +96,11 @@ xps_parse_rectangle(xps_context_t *ctx, char *text, gs_rect *rect) for (i = 0; i < 4 && *s; i++) { - args[i] = atof(s); - while (*s && *s != ',') - s++; - if (*s == ',') - s++; + args[i] = atof(s); + while (*s && *s != ',') + s++; + if (*s == ',') + s++; } rect->p.x = args[0]; diff --git a/xps/xpsdoc.c b/xps/xpsdoc.c index a4c61c244..8bb0cda1e 100644 --- a/xps/xpsdoc.c +++ b/xps/xpsdoc.c @@ -30,10 +30,10 @@ void xps_debug_parts(xps_context_t *ctx) xps_relation_t *rel; while (part) { - dprintf2("part '%s' size=%d\n", part->name, part->size); - for (rel = part->relations; rel; rel = rel->next) - dprintf2(" target=%s type=%s\n", rel->target, rel->type); - part = part->next; + dprintf2("part '%s' size=%d\n", part->name, part->size); + for (rel = part->relations; rel; rel = rel->next) + dprintf2(" target=%s type=%s\n", rel->target, rel->type); + part = part->next; } } @@ -44,7 +44,7 @@ xps_new_part(xps_context_t *ctx, char *name, int capacity) part = xps_alloc(ctx, sizeof(xps_part_t)); if (!part) - return NULL; + return NULL; part->name = NULL; part->size = 0; @@ -63,21 +63,21 @@ xps_new_part(xps_context_t *ctx, char *name, int capacity) part->name = xps_strdup(ctx, name); if (!part->name) { - xps_free(ctx, part); - return NULL; + xps_free(ctx, part); + return NULL; } if (capacity == 0) - capacity = 1024; + capacity = 1024; part->size = 0; part->capacity = capacity; part->data = xps_alloc(ctx, part->capacity); if (!part->data) { - xps_free(ctx, part->name); - xps_free(ctx, part); - return NULL; + xps_free(ctx, part->name); + xps_free(ctx, part); + return NULL; } part->next = NULL; @@ -96,7 +96,7 @@ void xps_free_part_data(xps_context_t *ctx, xps_part_t *part) { if (part->data) - xps_free(ctx, part->data); + xps_free(ctx, part->data); part->data = NULL; part->size = 0; part->capacity = 0; @@ -110,12 +110,12 @@ xps_release_part(xps_context_t *ctx, xps_part_t *part) /* since fonts and colorspaces need to live for the duration of the job there's no point in freeing those parts */ if (part->font || part->icc) - return; + return; /* never free the part data if we're in feed mode, since we may need it later */ if (ctx->file) - xps_free_part_data(ctx, part); + xps_free_part_data(ctx, part); } void @@ -124,10 +124,10 @@ xps_free_part(xps_context_t *ctx, xps_part_t *part) xps_free_part_data(ctx, part); if (part->font) - xps_free_font(ctx, part->font); + xps_free_font(ctx, part->font); if (part->name) - xps_free(ctx, part->name); + xps_free(ctx, part->name); part->name = NULL; xps_free_relations(ctx, part->relations); @@ -157,11 +157,11 @@ xps_read_part(xps_context_t *ctx, char *name) part = xps_hash_lookup(ctx->part_table, name); if (ctx->file) { - if (!part) - part = xps_read_zip_part(ctx, name); - if (part && !part->complete) - part = xps_read_zip_part(ctx, name); - return part; + if (!part) + part = xps_read_zip_part(ctx, name); + if (part && !part->complete) + part = xps_read_zip_part(ctx, name); + return part; } return part; } @@ -180,13 +180,13 @@ xps_part_name_from_relation_part_name(char *output, char *name) q = strstr(name, "_rels/"); if (p) { - *p = 0; - strcat(output, q + 6); + *p = 0; + strcat(output, q + 6); } p = strstr(output, ".rels"); if (p) { - *p = 0; + *p = 0; } } @@ -201,28 +201,28 @@ xps_add_relation(xps_context_t *ctx, char *source, char *target, char *type) /* No existing part found. Create a blank part and hook it in. */ if (part == NULL) { - part = xps_new_part(ctx, source, 0); - if (!part) - return gs_rethrow(-1, "cannot create new part"); + part = xps_new_part(ctx, source, 0); + if (!part) + return gs_rethrow(-1, "cannot create new part"); } /* Check for duplicates. */ for (node = part->relations; node; node = node->next) - if (!strcmp(node->target, target)) - return 0; + if (!strcmp(node->target, target)) + return 0; node = xps_alloc(ctx, sizeof(xps_relation_t)); if (!node) - return gs_rethrow(-1, "cannot create new relation"); + return gs_rethrow(-1, "cannot create new relation"); node->target = xps_strdup(ctx, target); node->type = xps_strdup(ctx, type); if (!node->target || !node->type) { - if (node->target) xps_free(ctx, node->target); - if (node->type) xps_free(ctx, node->type); - xps_free(ctx, node); - return gs_rethrow(-1, "cannot copy relation strings"); + if (node->target) xps_free(ctx, node->target); + if (node->type) xps_free(ctx, node->type); + xps_free(ctx, node); + return gs_rethrow(-1, "cannot copy relation strings"); } node->next = part->relations; @@ -230,7 +230,7 @@ xps_add_relation(xps_context_t *ctx, char *source, char *target, char *type) if (xps_doc_trace) { - dprintf2(" relation %s -> %s\n", source, target); + dprintf2(" relation %s -> %s\n", source, target); } return 0; @@ -242,11 +242,11 @@ xps_free_relations(xps_context_t *ctx, xps_relation_t *node) xps_relation_t *next; while (node) { - next = node->next; - xps_free(ctx, node->target); - xps_free(ctx, node->type); - xps_free(ctx, node); - node = next; + next = node->next; + xps_free(ctx, node->target); + xps_free(ctx, node->type); + xps_free(ctx, node); + node = next; } } @@ -261,18 +261,18 @@ void xps_debug_fixdocseq(xps_context_t *ctx) xps_page_t *page = ctx->first_page; if (ctx->start_part) - dprintf1("start part %s\n", ctx->start_part); + dprintf1("start part %s\n", ctx->start_part); while (fixdoc) { - dprintf1("fixdoc %s\n", fixdoc->name); - fixdoc = fixdoc->next; + dprintf1("fixdoc %s\n", fixdoc->name); + fixdoc = fixdoc->next; } while (page) { - dprintf3("page %s w=%d h=%d\n", page->name, page->width, page->height); - page = page->next; + dprintf3("page %s w=%d h=%d\n", page->name, page->width, page->height); + page = page->next; } } @@ -283,34 +283,34 @@ xps_add_fixed_document(xps_context_t *ctx, char *name) /* Check for duplicates first */ for (fixdoc = ctx->first_fixdoc; fixdoc; fixdoc = fixdoc->next) - if (!strcmp(fixdoc->name, name)) - return 0; + if (!strcmp(fixdoc->name, name)) + return 0; if (xps_doc_trace) - dprintf1("doc: adding fixdoc %s\n", name); + dprintf1("doc: adding fixdoc %s\n", name); fixdoc = xps_alloc(ctx, sizeof(xps_document_t)); if (!fixdoc) - return -1; + return -1; fixdoc->name = xps_strdup(ctx, name); if (!fixdoc->name) { - xps_free(ctx, fixdoc); - return -1; + xps_free(ctx, fixdoc); + return -1; } fixdoc->next = NULL; if (!ctx->first_fixdoc) { - ctx->first_fixdoc = fixdoc; - ctx->last_fixdoc = fixdoc; + ctx->first_fixdoc = fixdoc; + ctx->last_fixdoc = fixdoc; } else { - ctx->last_fixdoc->next = fixdoc; - ctx->last_fixdoc = fixdoc; + ctx->last_fixdoc->next = fixdoc; + ctx->last_fixdoc = fixdoc; } return 0; @@ -322,10 +322,10 @@ xps_free_fixed_documents(xps_context_t *ctx) xps_document_t *node = ctx->first_fixdoc; while (node) { - xps_document_t *next = node->next; - xps_free(ctx, node->name); - xps_free(ctx, node); - node = next; + xps_document_t *next = node->next; + xps_free(ctx, node->name); + xps_free(ctx, node); + node = next; } ctx->first_fixdoc = NULL; ctx->last_fixdoc = NULL; @@ -338,21 +338,21 @@ xps_add_fixed_page(xps_context_t *ctx, char *name, int width, int height) /* Check for duplicates first */ for (page = ctx->first_page; page; page = page->next) - if (!strcmp(page->name, name)) - return 0; + if (!strcmp(page->name, name)) + return 0; if (xps_doc_trace) - dprintf1("doc: adding page %s\n", name); + dprintf1("doc: adding page %s\n", name); page = xps_alloc(ctx, sizeof(xps_page_t)); if (!page) - return -1; + return -1; page->name = xps_strdup(ctx, name); if (!page->name) { - xps_free(ctx, page); - return -1; + xps_free(ctx, page); + return -1; } page->width = width; @@ -361,18 +361,18 @@ xps_add_fixed_page(xps_context_t *ctx, char *name, int width, int height) if (!ctx->first_page) { - ctx->first_page = page; - ctx->last_page = page; + ctx->first_page = page; + ctx->last_page = page; } else { - ctx->last_page->next = page; - ctx->last_page = page; + ctx->last_page->next = page; + ctx->last_page = page; } /* first page, or we processed all the previous pages */ if (ctx->next_page == NULL) - ctx->next_page = page; + ctx->next_page = page; return 0; } @@ -383,10 +383,10 @@ xps_free_fixed_pages(xps_context_t *ctx) xps_page_t *node = ctx->first_page; while (node) { - xps_page_t *next = node->next; - xps_free(ctx, node->name); - xps_free(ctx, node); - node = next; + xps_page_t *next = node->next; + xps_free(ctx, node->name); + xps_free(ctx, node); + node = next; } ctx->first_page = NULL; ctx->last_page = NULL; @@ -417,67 +417,67 @@ xps_parse_metadata_imp(void *zp, char *name, char **atts) if (!strcmp(name, "Relationship")) { - char realpart[1024]; - char tgtbuf[1024]; - char *target = NULL; - char *type = NULL; - - for (i = 0; atts[i]; i += 2) - { - if (!strcmp(atts[i], "Target")) - target = atts[i + 1]; - if (!strcmp(atts[i], "Type")) - type = atts[i + 1]; - } - - if (target && type) - { - xps_part_name_from_relation_part_name(realpart, ctx->part_uri); - xps_absolute_path(tgtbuf, ctx->base_uri, target); - xps_add_relation(ctx, realpart, tgtbuf, type); - } + char realpart[1024]; + char tgtbuf[1024]; + char *target = NULL; + char *type = NULL; + + for (i = 0; atts[i]; i += 2) + { + if (!strcmp(atts[i], "Target")) + target = atts[i + 1]; + if (!strcmp(atts[i], "Type")) + type = atts[i + 1]; + } + + if (target && type) + { + xps_part_name_from_relation_part_name(realpart, ctx->part_uri); + xps_absolute_path(tgtbuf, ctx->base_uri, target); + xps_add_relation(ctx, realpart, tgtbuf, type); + } } if (!strcmp(name, "DocumentReference")) { - char *source = NULL; - char srcbuf[1024]; - - for (i = 0; atts[i]; i += 2) - { - if (!strcmp(atts[i], "Source")) - source = atts[i + 1]; - } - - if (source) - { - xps_absolute_path(srcbuf, ctx->base_uri, source); - xps_add_fixed_document(ctx, srcbuf); - } + char *source = NULL; + char srcbuf[1024]; + + for (i = 0; atts[i]; i += 2) + { + if (!strcmp(atts[i], "Source")) + source = atts[i + 1]; + } + + if (source) + { + xps_absolute_path(srcbuf, ctx->base_uri, source); + xps_add_fixed_document(ctx, srcbuf); + } } if (!strcmp(name, "PageContent")) { - char *source = NULL; - char srcbuf[1024]; - int width = 0; - int height = 0; - - for (i = 0; atts[i]; i += 2) - { - if (!strcmp(atts[i], "Source")) - source = atts[i + 1]; - if (!strcmp(atts[i], "Width")) - width = atoi(atts[i + 1]); - if (!strcmp(atts[i], "Height")) - height = atoi(atts[i + 1]); - } - - if (source) - { - xps_absolute_path(srcbuf, ctx->base_uri, source); - xps_add_fixed_page(ctx, srcbuf, width, height); - } + char *source = NULL; + char srcbuf[1024]; + int width = 0; + int height = 0; + + for (i = 0; atts[i]; i += 2) + { + if (!strcmp(atts[i], "Source")) + source = atts[i + 1]; + if (!strcmp(atts[i], "Width")) + width = atoi(atts[i + 1]); + if (!strcmp(atts[i], "Height")) + height = atoi(atts[i + 1]); + } + + if (source) + { + xps_absolute_path(srcbuf, ctx->base_uri, source); + xps_add_fixed_page(ctx, srcbuf, width, height); + } } } @@ -492,7 +492,7 @@ xps_parse_metadata(xps_context_t *ctx, xps_part_t *part) strcpy(buf, part->name); s = strrchr(buf, '/'); if (s) - s[0] = 0; + s[0] = 0; /* _rels parts are voodoo: their URI references are from * the part they are associated with, not the actual _rels @@ -500,14 +500,14 @@ xps_parse_metadata(xps_context_t *ctx, xps_part_t *part) */ s = strstr(buf, "/_rels"); if (s) - *s = 0; + *s = 0; ctx->base_uri = buf; ctx->part_uri = part->name; xp = XML_ParserCreate(NULL); if (!xp) - return -1; + return -1; XML_SetUserData(xp, ctx); XML_SetParamEntityParsing(xp, XML_PARAM_ENTITY_PARSING_NEVER); @@ -539,7 +539,7 @@ xps_trim_url(char *path) { char *p = strrchr(path, '#'); if (p) - *p = 0; + *p = 0; } static void @@ -555,15 +555,15 @@ xps_parse_color_relation(xps_context_t *ctx, char *string) sp = strchr(buf, ' '); if (sp) { - sp ++; - ep = strchr(sp, ' '); - if (ep) - { - *ep = 0; - xps_absolute_path(path, ctx->base_uri, sp); - xps_trim_url(path); - xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); - } + sp ++; + ep = strchr(sp, ' '); + if (ep) + { + *ep = 0; + xps_absolute_path(path, ctx->base_uri, sp); + xps_trim_url(path); + xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); + } } } @@ -578,36 +578,36 @@ xps_parse_image_relation(xps_context_t *ctx, char *string) if (strstr(string, "{ColorConvertedBitmap") == string) { - strcpy(buf, string); - sp = strchr(buf, ' '); - if (sp) - { - sp ++; - ep = strchr(sp, ' '); - if (ep) - { - *ep = 0; - xps_absolute_path(path, ctx->base_uri, sp); - xps_trim_url(path); - xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); - - sp = ep + 1; - ep = strchr(sp, '}'); - if (ep) - { - *ep = 0; - xps_absolute_path(path, ctx->base_uri, sp); - xps_trim_url(path); - xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); - } - } - } + strcpy(buf, string); + sp = strchr(buf, ' '); + if (sp) + { + sp ++; + ep = strchr(sp, ' '); + if (ep) + { + *ep = 0; + xps_absolute_path(path, ctx->base_uri, sp); + xps_trim_url(path); + xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); + + sp = ep + 1; + ep = strchr(sp, '}'); + if (ep) + { + *ep = 0; + xps_absolute_path(path, ctx->base_uri, sp); + xps_trim_url(path); + xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); + } + } + } } else { - xps_absolute_path(path, ctx->base_uri, string); - xps_trim_url(path); - xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); + xps_absolute_path(path, ctx->base_uri, string); + xps_trim_url(path); + xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); } } @@ -621,55 +621,55 @@ xps_parse_content_relations_imp(void *zp, char *ns_name, char **atts) name = strchr(ns_name, ' '); if (name) - name ++; + name ++; else - name = ns_name; + name = ns_name; if (!strcmp(name, "Glyphs")) { - for (i = 0; atts[i]; i += 2) - { - if (!strcmp(atts[i], "FontUri")) - { - xps_absolute_path(path, ctx->base_uri, atts[i+1]); - xps_trim_url(path); - xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); - } - } + for (i = 0; atts[i]; i += 2) + { + if (!strcmp(atts[i], "FontUri")) + { + xps_absolute_path(path, ctx->base_uri, atts[i+1]); + xps_trim_url(path); + xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE); + } + } } if (!strcmp(name, "ImageBrush")) { - for (i = 0; atts[i]; i += 2) - if (!strcmp(atts[i], "ImageSource")) - xps_parse_image_relation(ctx, atts[i + 1]); + for (i = 0; atts[i]; i += 2) + if (!strcmp(atts[i], "ImageSource")) + xps_parse_image_relation(ctx, atts[i + 1]); } if (!strcmp(name, "ResourceDictionary")) { - for (i = 0; atts[i]; i += 2) - { - if (!strcmp(atts[i], "Source")) - { - xps_absolute_path(path, ctx->base_uri, atts[i+1]); - xps_trim_url(path); - xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE_RECURSIVE); - } - } + for (i = 0; atts[i]; i += 2) + { + if (!strcmp(atts[i], "Source")) + { + xps_absolute_path(path, ctx->base_uri, atts[i+1]); + xps_trim_url(path); + xps_add_relation(ctx, ctx->part_uri, path, REL_REQUIRED_RESOURCE_RECURSIVE); + } + } } if (!strcmp(name, "SolidColorBrush") || !strcmp(name, "GradientStop")) { - for (i = 0; atts[i]; i += 2) - if (!strcmp(atts[i], "Color")) - xps_parse_color_relation(ctx, atts[i + 1]); + for (i = 0; atts[i]; i += 2) + if (!strcmp(atts[i], "Color")) + xps_parse_color_relation(ctx, atts[i + 1]); } if (!strcmp(name, "Glyphs") || !strcmp(name, "Path")) { - for (i = 0; atts[i]; i += 2) - if (!strcmp(atts[i], "Fill") || !strcmp(atts[i], "Stroke")) - xps_parse_color_relation(ctx, atts[i + 1]); + for (i = 0; atts[i]; i += 2) + if (!strcmp(atts[i], "Fill") || !strcmp(atts[i], "Stroke")) + xps_parse_color_relation(ctx, atts[i + 1]); } } @@ -684,17 +684,17 @@ xps_parse_content_relations(xps_context_t *ctx, xps_part_t *part) strcpy(buf, part->name); s = strrchr(buf, '/'); if (s) - s[0] = 0; + s[0] = 0; ctx->part_uri = part->name; ctx->base_uri = buf; if (xps_doc_trace) - dprintf1("doc: parsing relations from content (%s)\n", part->name); + dprintf1("doc: parsing relations from content (%s)\n", part->name); xp = XML_ParserCreateNS(NULL, ' '); if (!xp) - return -1; + return -1; XML_SetUserData(xp, ctx); XML_SetParamEntityParsing(xp, XML_PARAM_ENTITY_PARSING_NEVER); diff --git a/xps/xpsfont.c b/xps/xpsfont.c index 0ddb6b265..e2d375bac 100644 --- a/xps/xpsfont.c +++ b/xps/xpsfont.c @@ -44,7 +44,7 @@ int xps_init_font_cache(xps_context_t *ctx) { ctx->fontdir = gs_font_dir_alloc(ctx->memory); if (!ctx->fontdir) - return gs_throw(-1, "cannot gs_font_dir_alloc()"); + return gs_throw(-1, "cannot gs_font_dir_alloc()"); gs_setaligntopixels(ctx->fontdir, 1); /* no subpixels */ gs_setgridfittt(ctx->fontdir, 1); /* see gx_ttf_outline in gxttfn.c for values */ @@ -61,8 +61,8 @@ xps_new_font(xps_context_t *ctx, byte *buf, int buflen, int index) font = xps_alloc(ctx, sizeof(xps_font_t)); if (!font) { - gs_throw(-1, "out of memory"); - return NULL; + gs_throw(-1, "out of memory"); + return NULL; } font->data = buf; @@ -82,31 +82,31 @@ xps_new_font(xps_context_t *ctx, byte *buf, int buflen, int index) font->charstrings = 0; if (memcmp(font->data, "OTTO", 4) == 0) - code = xps_init_postscript_font(ctx, font); + code = xps_init_postscript_font(ctx, font); else if (memcmp(font->data, "\0\1\0\0", 4) == 0) - code = xps_init_truetype_font(ctx, font); + code = xps_init_truetype_font(ctx, font); else if (memcmp(font->data, "true", 4) == 0) - code = xps_init_truetype_font(ctx, font); + code = xps_init_truetype_font(ctx, font); else if (memcmp(font->data, "ttcf", 4) == 0) - code = xps_init_truetype_font(ctx, font); + code = xps_init_truetype_font(ctx, font); else { - xps_free_font(ctx, font); - gs_throw(-1, "not an opentype font"); - return NULL; + xps_free_font(ctx, font); + gs_throw(-1, "not an opentype font"); + return NULL; } if (code < 0) { - xps_free_font(ctx, font); - gs_rethrow(-1, "cannot init font"); - return NULL; + xps_free_font(ctx, font); + gs_rethrow(-1, "cannot init font"); + return NULL; } code = xps_load_sfnt_cmap(font); if (code < 0) { - errprintf("warning: no cmap table found in font\n"); + errprintf("warning: no cmap table found in font\n"); } return font; @@ -117,8 +117,8 @@ xps_free_font(xps_context_t *ctx, xps_font_t *font) { if (font->font) { - gs_font_finalize(font->font); - gs_free_object(ctx->memory, font->font, "font object"); + gs_font_finalize(font->font); + gs_free_object(ctx->memory, font->font, "font object"); } xps_free(ctx, font); } @@ -137,33 +137,33 @@ xps_find_sfnt_table(xps_font_t *font, char *name, int *lengthp) int i; if (font->length < 12) - return -1; + return -1; if (!memcmp(font->data, "ttcf", 4)) { - int nfonts = u32(font->data + 8); - if (font->subfontid < 0 || font->subfontid >= nfonts) - return gs_throw(-1, "Invalid subfont ID"); - offset = u32(font->data + 12 + font->subfontid * 4); + int nfonts = u32(font->data + 8); + if (font->subfontid < 0 || font->subfontid >= nfonts) + return gs_throw(-1, "Invalid subfont ID"); + offset = u32(font->data + 12 + font->subfontid * 4); } else { - offset = 0; + offset = 0; } ntables = u16(font->data + offset + 4); if (font->length < offset + 12 + ntables * 16) - return -1; + return -1; for (i = 0; i < ntables; i++) { - byte *entry = font->data + offset + 12 + i * 16; - if (!memcmp(entry, name, 4)) - { - if (lengthp) - *lengthp = u32(entry + 12); - return u32(entry + 8); - } + byte *entry = font->data + offset + 12 + i * 16; + if (!memcmp(entry, name, 4)) + { + if (lengthp) + *lengthp = u32(entry + 12); + return u32(entry + 8); + } } return -1; @@ -183,9 +183,9 @@ int xps_load_sfnt_name(xps_font_t *font, char *namep) offset = xps_find_sfnt_table(font, "name", &length); if (offset < 0) - return -1; + return -1; if (length < 6) - return -1; + return -1; namedata = font->data + offset; @@ -195,24 +195,24 @@ int xps_load_sfnt_name(xps_font_t *font, char *namep) for (i = 0; i < count; i++) { - byte *record = namedata + 6 + i * 12; - int pid = u16(record + 0); - int eid = u16(record + 2); - int langid = u16(record + 4); - int nameid = u16(record + 6); - length = u16(record + 8); - offset = u16(record + 10); - - /* Mac Roman English */ - if (pid == 1 && eid == 0 && langid == 0) - { - /* Full font name or postscript name */ - if (nameid == 4 || nameid == 6) - { - memcpy(namep, namedata + stringoffset + offset, length); - namep[length] = 0; - } - } + byte *record = namedata + 6 + i * 12; + int pid = u16(record + 0); + int eid = u16(record + 2); + int langid = u16(record + 4); + int nameid = u16(record + 6); + length = u16(record + 8); + offset = u16(record + 10); + + /* Mac Roman English */ + if (pid == 1 && eid == 0 && langid == 0) + { + /* Full font name or postscript name */ + if (nameid == 4 || nameid == 6) + { + memcpy(namep, namedata + stringoffset + offset, length); + namep[length] = 0; + } + } } return 0; @@ -231,18 +231,18 @@ xps_load_sfnt_cmap(xps_font_t *font) offset = xps_find_sfnt_table(font, "cmap", &length); if (offset < 0) - return -1; + return -1; if (length < 4) - return -1; + return -1; cmapdata = font->data + offset; nsubtables = u16(cmapdata + 2); if (nsubtables < 0) - return -1; + return -1; if (length < 4 + nsubtables * 8) - return -1; + return -1; font->cmaptable = offset; font->cmapsubcount = nsubtables; @@ -270,7 +270,7 @@ xps_identify_font_encoding(xps_font_t *font, int idx, int *pid, int *eid) { byte *cmapdata, *entry; if (idx < 0 || idx >= font->cmapsubcount) - return -1; + return -1; cmapdata = font->data + font->cmaptable; entry = cmapdata + 4 + idx * 8; *pid = u16(entry + 0); @@ -288,7 +288,7 @@ xps_select_font_encoding(xps_font_t *font, int idx) byte *cmapdata, *entry; int pid, eid; if (idx < 0 || idx >= font->cmapsubcount) - return -1; + return -1; cmapdata = font->data + font->cmaptable; entry = cmapdata + 4 + idx * 8; pid = u16(entry + 0); @@ -311,97 +311,97 @@ xps_encode_font_char_int(xps_font_t *font, int code) /* no cmap selected: return identity */ if (font->cmapsubtable <= 0) - return code; + return code; table = font->data + font->cmapsubtable; switch (u16(table)) { case 0: /* Apple standard 1-to-1 mapping. */ - return table[code + 6]; + return table[code + 6]; case 4: /* Microsoft/Adobe segmented mapping. */ - { - int segCount2 = u16(table + 6); - byte *endCount = table + 14; - byte *startCount = endCount + segCount2 + 2; - byte *idDelta = startCount + segCount2; - byte *idRangeOffset = idDelta + segCount2; - int i2; - - for (i2 = 0; i2 < segCount2 - 3; i2 += 2) - { - int delta, roff; - int start = u16(startCount + i2); - int glyph; - - if ( code < start ) - return 0; - if ( code > u16(endCount + i2) ) - continue; - delta = s16(idDelta + i2); - roff = s16(idRangeOffset + i2); - if ( roff == 0 ) - { - return ( code + delta ) & 0xffff; /* mod 65536 */ - return 0; - } - glyph = u16(idRangeOffset + i2 + roff + ((code - start) << 1)); - return (glyph == 0 ? 0 : glyph + delta); - } - - /* - * The TrueType documentation says that the last range is - * always supposed to end with 0xffff, so this shouldn't - * happen; however, in some real fonts, it does. - */ - return 0; - } + { + int segCount2 = u16(table + 6); + byte *endCount = table + 14; + byte *startCount = endCount + segCount2 + 2; + byte *idDelta = startCount + segCount2; + byte *idRangeOffset = idDelta + segCount2; + int i2; + + for (i2 = 0; i2 < segCount2 - 3; i2 += 2) + { + int delta, roff; + int start = u16(startCount + i2); + int glyph; + + if ( code < start ) + return 0; + if ( code > u16(endCount + i2) ) + continue; + delta = s16(idDelta + i2); + roff = s16(idRangeOffset + i2); + if ( roff == 0 ) + { + return ( code + delta ) & 0xffff; /* mod 65536 */ + return 0; + } + glyph = u16(idRangeOffset + i2 + roff + ((code - start) << 1)); + return (glyph == 0 ? 0 : glyph + delta); + } + + /* + * The TrueType documentation says that the last range is + * always supposed to end with 0xffff, so this shouldn't + * happen; however, in some real fonts, it does. + */ + return 0; + } case 6: /* Single interval lookup. */ - { - int firstCode = u16(table + 6); - int entryCount = u16(table + 8); - if ( code < firstCode || code >= firstCode + entryCount ) - return 0; - return u16(table + 10 + ((code - firstCode) << 1)); - } + { + int firstCode = u16(table + 6); + int entryCount = u16(table + 8); + if ( code < firstCode || code >= firstCode + entryCount ) + return 0; + return u16(table + 10 + ((code - firstCode) << 1)); + } case 10: /* Trimmed array (like 6) */ - { - int startCharCode = u32(table + 12); - int numChars = u32(table + 16); - if ( code < startCharCode || code >= startCharCode + numChars ) - return 0; - return u32(table + 20 + (code - startCharCode) * 4); - } + { + int startCharCode = u32(table + 12); + int numChars = u32(table + 16); + if ( code < startCharCode || code >= startCharCode + numChars ) + return 0; + return u32(table + 20 + (code - startCharCode) * 4); + } case 12: /* Segmented coverage. (like 4) */ - { - int nGroups = u32(table + 12); - byte *group = table + 16; - int i; - - for (i = 0; i < nGroups; i++) - { - int startCharCode = u32(group + 0); - int endCharCode = u32(group + 4); - int startGlyphID = u32(group + 8); - if ( code < startCharCode ) - return 0; - if ( code <= endCharCode ) - return startGlyphID + (code - startCharCode); - group += 12; - } - - return 0; - } + { + int nGroups = u32(table + 12); + byte *group = table + 16; + int i; + + for (i = 0; i < nGroups; i++) + { + int startCharCode = u32(group + 0); + int endCharCode = u32(group + 4); + int startGlyphID = u32(group + 8); + if ( code < startCharCode ) + return 0; + if ( code <= endCharCode ) + return startGlyphID + (code - startCharCode); + group += 12; + } + + return 0; + } case 2: /* High-byte mapping through table. */ case 8: /* Mixed 16-bit and 32-bit coverage (like 2) */ default: - errprintf("error: unknown cmap format: %d\n", u16(table)); - return 0; + errprintf("error: unknown cmap format: %d\n", u16(table)); + return 0; } return 0; @@ -412,7 +412,7 @@ xps_encode_font_char(xps_font_t *font, int code) { int gid = xps_encode_font_char_int(font, code); if (gid == 0 && font->usepua) - gid = xps_encode_font_char_int(font, 0xF000 | code); + gid = xps_encode_font_char_int(font, 0xF000 | code); return gid; } @@ -445,24 +445,24 @@ int xps_measure_font_glyph(xps_context_t *ctx, xps_font_t *font, int gid, xps_gl ofs = xps_find_sfnt_table(font, "hhea", &len); if (ofs < 0) - return gs_throw(-1, "cannot find hhea table"); + return gs_throw(-1, "cannot find hhea table"); if (len < 2 * 18) - return gs_throw(-1, "hhea table is too short"); + return gs_throw(-1, "hhea table is too short"); vorg = s16(font->data + ofs + 4); /* ascender is default vorg */ desc = s16(font->data + ofs + 6); /* descender */ if (desc < 0) - desc = -desc; + desc = -desc; n = u16(font->data + ofs + 17 * 2); ofs = xps_find_sfnt_table(font, "hmtx", &len); if (ofs < 0) - return gs_throw(-1, "cannot find hmtx table"); + return gs_throw(-1, "cannot find hmtx table"); idx = gid; if (idx > n - 1) - idx = n - 1; + idx = n - 1; hadv = u16(font->data + ofs + idx * 4); vadv = 0; @@ -474,71 +474,71 @@ int xps_measure_font_glyph(xps_context_t *ctx, xps_font_t *font, int gid, xps_gl head = xps_find_sfnt_table(font, "head", &len); if (head > 0) { - scale = u16(font->data + head + 18); /* units per em */ + scale = u16(font->data + head + 18); /* units per em */ } ofs = xps_find_sfnt_table(font, "OS/2", &len); if (ofs > 0 && len > 70) { - vorg = s16(font->data + ofs + 68); /* sTypoAscender */ - desc = s16(font->data + ofs + 70); /* sTypoDescender */ - if (desc < 0) - desc = -desc; + vorg = s16(font->data + ofs + 68); /* sTypoAscender */ + desc = s16(font->data + ofs + 70); /* sTypoDescender */ + if (desc < 0) + desc = -desc; } ofs = xps_find_sfnt_table(font, "vhea", &len); if (ofs > 0) { - if (len < 2 * 18) - return gs_throw(-1, "vhea table is too short"); + if (len < 2 * 18) + return gs_throw(-1, "vhea table is too short"); - n = u16(font->data + ofs + 17 * 2); + n = u16(font->data + ofs + 17 * 2); - ofs = xps_find_sfnt_table(font, "vmtx", &len); - if (ofs < 0) - return gs_throw(-1, "cannot find vmtx table"); + ofs = xps_find_sfnt_table(font, "vmtx", &len); + if (ofs < 0) + return gs_throw(-1, "cannot find vmtx table"); - idx = gid; - if (idx > n - 1) - idx = n - 1; + idx = gid; + if (idx > n - 1) + idx = n - 1; - vadv = u16(font->data + ofs + idx * 4); - vtop = u16(font->data + ofs + idx * 4 + 2); + vadv = u16(font->data + ofs + idx * 4); + vtop = u16(font->data + ofs + idx * 4 + 2); - glyf = xps_find_sfnt_table(font, "glyf", &len); - loca = xps_find_sfnt_table(font, "loca", &len); - if (head > 0 && glyf > 0 && loca > 0) - { - format = u16(font->data + head + 50); /* indexToLocaFormat */ + glyf = xps_find_sfnt_table(font, "glyf", &len); + loca = xps_find_sfnt_table(font, "loca", &len); + if (head > 0 && glyf > 0 && loca > 0) + { + format = u16(font->data + head + 50); /* indexToLocaFormat */ - if (format == 0) - ofs = u16(font->data + loca + gid * 2) * 2; - else - ofs = u32(font->data + loca + gid * 4); + if (format == 0) + ofs = u16(font->data + loca + gid * 2) * 2; + else + ofs = u32(font->data + loca + gid * 4); - ymax = u16(font->data + glyf + ofs + 8); /* yMax */ + ymax = u16(font->data + glyf + ofs + 8); /* yMax */ - vorg = ymax + vtop; - } + vorg = ymax + vtop; + } } ofs = xps_find_sfnt_table(font, "VORG", &len); if (ofs > 0) { - vorg = u16(font->data + ofs + 6); - n = u16(font->data + ofs + 6); - for (i = 0; i < n; i++) - { - if (u16(font->data + ofs + 8 + 4 * i) == gid) - { - vorg = s16(font->data + ofs + 8 + 4 * i + 2); - break; - } - } + vorg = u16(font->data + ofs + 6); + n = u16(font->data + ofs + 6); + for (i = 0; i < n; i++) + { + if (u16(font->data + ofs + 8 + 4 * i) == gid) + { + vorg = s16(font->data + ofs + 8 + 4 * i + 2); + break; + } + } } if (vadv == 0) - vadv = vorg + desc; + vadv = vorg + desc; mtx->hadv = hadv / (float) scale; mtx->vadv = vadv / (float) scale; diff --git a/xps/xpsglyphs.c b/xps/xpsglyphs.c index 9b2b027fb..e353faa31 100644 --- a/xps/xpsglyphs.c +++ b/xps/xpsglyphs.c @@ -32,7 +32,7 @@ struct xps_text_buffer_s static inline int unhex(int i) { if (isdigit(i)) - return i - '0'; + return i - '0'; return tolower(i) - 'a' + 10; } @@ -47,21 +47,21 @@ void xps_debug_path(xps_context_t *ctx) switch (seg->type) { case s_start: - dprintf2("%g %g moveto\n", + dprintf2("%g %g moveto\n", fixed2float(seg->pt.x) * 0.001, fixed2float(seg->pt.y) * 0.001); break; case s_line: - dprintf2("%g %g lineto\n", + dprintf2("%g %g lineto\n", fixed2float(seg->pt.x) * 0.001, fixed2float(seg->pt.y) * 0.001); break; case s_line_close: - dputs("closepath\n"); + dputs("closepath\n"); break; case s_curve: cseg = (curve_segment*)seg; - dprintf6("%g %g %g %g %g %g curveto\n", + dprintf6("%g %g %g %g %g %g curveto\n", fixed2float(cseg->p1.x) * 0.001, fixed2float(cseg->p1.y) * 0.001, fixed2float(cseg->p2.x) * 0.001, @@ -88,25 +88,25 @@ xps_deobfuscate_font_resource(xps_context_t *ctx, xps_part_t *part) p = strrchr(part->name, '/'); if (!p) - p = part->name; + p = part->name; for (i = 0; i < 32 && *p; p++) { - if (isxdigit(*p)) - buf[i++] = *p; + if (isxdigit(*p)) + buf[i++] = *p; } buf[i] = 0; if (i != 32) - return gs_throw(-1, "cannot extract GUID from part name"); + return gs_throw(-1, "cannot extract GUID from part name"); for (i = 0; i < 16; i++) - key[i] = unhex(buf[i*2+0]) * 16 + unhex(buf[i*2+1]); + key[i] = unhex(buf[i*2+0]) * 16 + unhex(buf[i*2+1]); for (i = 0; i < 16; i++) { - part->data[i] ^= key[15-i]; - part->data[i+16] ^= key[15-i]; + part->data[i] ^= key[15-i]; + part->data[i+16] ^= key[15-i]; } return 0; @@ -117,16 +117,16 @@ xps_select_best_font_encoding(xps_font_t *font) { static struct { int pid, eid; } xps_cmap_list[] = { - { 3, 10 }, /* Unicode with surrogates */ - { 3, 1 }, /* Unicode without surrogates */ - { 3, 5 }, /* Wansung */ - { 3, 4 }, /* Big5 */ - { 3, 3 }, /* Prc */ - { 3, 2 }, /* ShiftJis */ - { 3, 0 }, /* Symbol */ - // { 0, * }, -- Unicode (deprecated) - { 1, 0 }, - { -1, -1 }, + { 3, 10 }, /* Unicode with surrogates */ + { 3, 1 }, /* Unicode without surrogates */ + { 3, 5 }, /* Wansung */ + { 3, 4 }, /* Big5 */ + { 3, 3 }, /* Prc */ + { 3, 2 }, /* ShiftJis */ + { 3, 0 }, /* Symbol */ + // { 0, * }, -- Unicode (deprecated) + { 1, 0 }, + { -1, -1 }, }; int i, k, n, pid, eid; @@ -134,15 +134,15 @@ xps_select_best_font_encoding(xps_font_t *font) n = xps_count_font_encodings(font); for (k = 0; xps_cmap_list[k].pid != -1; k++) { - for (i = 0; i < n; i++) - { - xps_identify_font_encoding(font, i, &pid, &eid); - if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid) - { - xps_select_font_encoding(font, i); - return 0; - } - } + for (i = 0; i < n; i++) + { + xps_identify_font_encoding(font, i, &pid, &eid); + if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid) + { + xps_select_font_encoding(font, i); + return 0; + } + } } return gs_throw(-1, "could not find a suitable cmap"); @@ -154,7 +154,7 @@ xps_select_best_font_encoding(xps_font_t *font) static int xps_flush_text_buffer(xps_context_t *ctx, xps_font_t *font, - xps_text_buffer_t *buf, int is_charpath) + xps_text_buffer_t *buf, int is_charpath) { gs_text_params_t params; gs_text_enum_t *textenum; @@ -169,25 +169,25 @@ xps_flush_text_buffer(xps_context_t *ctx, xps_font_t *font, for (i = 0; i < buf->count; i++) { - gs_moveto(ctx->pgs, buf->x[i], buf->y[i]); + gs_moveto(ctx->pgs, buf->x[i], buf->y[i]); - params.operation = TEXT_FROM_SINGLE_GLYPH; - if (is_charpath) - params.operation |= TEXT_DO_FALSE_CHARPATH; - else - params.operation |= TEXT_DO_DRAW; - params.data.d_glyph = buf->g[i]; - params.size = 1; + params.operation = TEXT_FROM_SINGLE_GLYPH; + if (is_charpath) + params.operation |= TEXT_DO_FALSE_CHARPATH; + else + params.operation |= TEXT_DO_DRAW; + params.data.d_glyph = buf->g[i]; + params.size = 1; - code = gs_text_begin(ctx->pgs, ¶ms, ctx->memory, &textenum); - if (code != 0) - return gs_throw1(-1, "cannot gs_text_begin() (%d)", code); + code = gs_text_begin(ctx->pgs, ¶ms, ctx->memory, &textenum); + if (code != 0) + return gs_throw1(-1, "cannot gs_text_begin() (%d)", code); - code = gs_text_process(textenum); - if (code != 0) - return gs_throw1(-1, "cannot gs_text_process() (%d)", code); + code = gs_text_process(textenum); + if (code != 0) + return gs_throw1(-1, "cannot gs_text_process() (%d)", code); - gs_text_release(textenum, "gslt font render"); + gs_text_release(textenum, "gslt font render"); } #else @@ -196,9 +196,9 @@ xps_flush_text_buffer(xps_context_t *ctx, xps_font_t *font, params.operation = TEXT_FROM_GLYPHS | TEXT_REPLACE_WIDTHS; if (is_charpath) - params.operation |= TEXT_DO_FALSE_CHARPATH; + params.operation |= TEXT_DO_FALSE_CHARPATH; else - params.operation |= TEXT_DO_DRAW; + params.operation |= TEXT_DO_DRAW; params.data.glyphs = buf->g; params.size = buf->count; params.x_widths = buf->x + 1; @@ -207,23 +207,23 @@ xps_flush_text_buffer(xps_context_t *ctx, xps_font_t *font, for (i = 0; i < buf->count; i++) { - buf->x[i] = buf->x[i] - x; - buf->y[i] = buf->y[i] - y; - x += buf->x[i]; - y += buf->y[i]; + buf->x[i] = buf->x[i] - x; + buf->y[i] = buf->y[i] - y; + x += buf->x[i]; + y += buf->y[i]; } buf->x[buf->count] = 0; buf->y[buf->count] = 0; code = gs_text_begin(ctx->pgs, ¶ms, ctx->memory, &textenum); if (code != 0) - return gs_throw1(-1, "cannot gs_text_begin() (%d)", code); + return gs_throw1(-1, "cannot gs_text_begin() (%d)", code); code = gs_text_process(textenum); gs_text_release(textenum, "gslt font render"); if (code != 0) - return gs_throw1(-1, "cannot gs_text_process() (%d)", code); + return gs_throw1(-1, "cannot gs_text_process() (%d)", code); #endif @@ -258,8 +258,8 @@ xps_parse_digits(char *s, int *digit) *digit = 0; while (*s >= '0' && *s <= '9') { - *digit = *digit * 10 + (*s - '0'); - s ++; + *digit = *digit * 10 + (*s - '0'); + s ++; } return s; } @@ -275,10 +275,10 @@ xps_parse_real_num(char *s, float *number) char buf[64]; char *p = buf; while (is_real_num_char(*s)) - *p++ = *s++; + *p++ = *s++; *p = 0; if (buf[0]) - *number = atof(buf); + *number = atof(buf); return s; } @@ -286,11 +286,11 @@ static char * xps_parse_cluster_mapping(char *s, int *code_count, int *glyph_count) { if (*s == '(') - s = xps_parse_digits(s + 1, code_count); + s = xps_parse_digits(s + 1, code_count); if (*s == ':') - s = xps_parse_digits(s + 1, glyph_count); + s = xps_parse_digits(s + 1, glyph_count); if (*s == ')') - s ++; + s ++; return s; } @@ -298,7 +298,7 @@ static char * xps_parse_glyph_index(char *s, int *glyph_index) { if (*s >= '0' && *s <= '9') - s = xps_parse_digits(s, glyph_index); + s = xps_parse_digits(s, glyph_index); return s; } @@ -306,18 +306,18 @@ static char * xps_parse_glyph_metrics(char *s, float *advance, float *uofs, float *vofs) { if (*s == ',') - s = xps_parse_real_num(s + 1, advance); + s = xps_parse_real_num(s + 1, advance); if (*s == ',') - s = xps_parse_real_num(s + 1, uofs); + s = xps_parse_real_num(s + 1, uofs); if (*s == ',') - s = xps_parse_real_num(s + 1, vofs); + s = xps_parse_real_num(s + 1, vofs); return s; } static int xps_parse_glyphs_imp(xps_context_t *ctx, xps_font_t *font, float size, - float originx, float originy, int is_sideways, int bidi_level, - char *indices, char *unicode, int is_charpath) + float originx, float originy, int is_sideways, int bidi_level, + char *indices, char *unicode, int is_charpath) { // parse unicode and indices strings and encode glyphs // and calculate metrics for positioning @@ -336,114 +336,114 @@ xps_parse_glyphs_imp(xps_context_t *ctx, xps_font_t *font, float size, buf.count = 0; if (!unicode && !indices) - return gs_throw(-1, "no text in glyphs element"); + return gs_throw(-1, "no text in glyphs element"); if (us) { - if (us[0] == '{' && us[1] == '}') - us = us + 2; - un = strlen(us); + if (us[0] == '{' && us[1] == '}') + us = us + 2; + un = strlen(us); } while ((us && un > 0) || (is && *is)) { - int code_count = 1; - int glyph_count = 1; - - if (is && *is) - { - is = xps_parse_cluster_mapping(is, &code_count, &glyph_count); - } - - if (code_count < 1) - code_count = 1; - if (glyph_count < 1) - glyph_count = 1; - - while (code_count > 0 || glyph_count > 0) - { - int char_code = '?'; - int glyph_index = -1; - float u_offset = 0.0; - float v_offset = 0.0; - float advance; - - if (glyph_count) - { - if (is && *is) - is = xps_parse_glyph_index(is, &glyph_index); - glyph_count --; - } - - if (code_count) - { - if (us && un > 0) - { - int t = xps_utf8_to_ucs(&char_code, us, un); - if (t < 0) - return gs_rethrow(-1, "error decoding UTF-8 string"); - us += t; un -= t; - } - code_count --; - } - - if (glyph_index == -1) - glyph_index = xps_encode_font_char(font, char_code); - - xps_measure_font_glyph(ctx, font, glyph_index, &mtx); - if (is_sideways) - advance = mtx.vadv * 100.0; - else if (bidi_level & 1) - advance = -mtx.hadv * 100.0; - else - advance = mtx.hadv * 100.0; - - if (is && *is) - { - is = xps_parse_glyph_metrics(is, &advance, &u_offset, &v_offset); - if (*is == ';') - is ++; - } + int code_count = 1; + int glyph_count = 1; + + if (is && *is) + { + is = xps_parse_cluster_mapping(is, &code_count, &glyph_count); + } + + if (code_count < 1) + code_count = 1; + if (glyph_count < 1) + glyph_count = 1; + + while (code_count > 0 || glyph_count > 0) + { + int char_code = '?'; + int glyph_index = -1; + float u_offset = 0.0; + float v_offset = 0.0; + float advance; + + if (glyph_count) + { + if (is && *is) + is = xps_parse_glyph_index(is, &glyph_index); + glyph_count --; + } + + if (code_count) + { + if (us && un > 0) + { + int t = xps_utf8_to_ucs(&char_code, us, un); + if (t < 0) + return gs_rethrow(-1, "error decoding UTF-8 string"); + us += t; un -= t; + } + code_count --; + } + + if (glyph_index == -1) + glyph_index = xps_encode_font_char(font, char_code); + + xps_measure_font_glyph(ctx, font, glyph_index, &mtx); + if (is_sideways) + advance = mtx.vadv * 100.0; + else if (bidi_level & 1) + advance = -mtx.hadv * 100.0; + else + advance = mtx.hadv * 100.0; + + if (is && *is) + { + is = xps_parse_glyph_metrics(is, &advance, &u_offset, &v_offset); + if (*is == ';') + is ++; + } #if 0 - dprintf6("glyph mapping (%d:%d)%d,%g,%g,%g\n", - code_count, glyph_count, glyph_index, - advance, u_offset, v_offset); + dprintf6("glyph mapping (%d:%d)%d,%g,%g,%g\n", + code_count, glyph_count, glyph_index, + advance, u_offset, v_offset); #endif - if (bidi_level & 1) - u_offset = -mtx.hadv * 100 - u_offset; - - u_offset = u_offset * 0.01 * size; - v_offset = v_offset * 0.01 * size; - - if (buf.count < XPS_TEXT_BUFFER_SIZE) - { - if (is_sideways) - { - buf.x[buf.count] = x + u_offset + (mtx.vorg * size); - buf.y[buf.count] = y - v_offset + (mtx.hadv * 0.5 * size); - } - else - { - buf.x[buf.count] = x + u_offset; - buf.y[buf.count] = y - v_offset; - } - buf.g[buf.count] = glyph_index; - buf.count ++; - } - else - { - xps_flush_text_buffer(ctx, font, &buf, is_charpath); - } - - x += advance * 0.01 * size; - } + if (bidi_level & 1) + u_offset = -mtx.hadv * 100 - u_offset; + + u_offset = u_offset * 0.01 * size; + v_offset = v_offset * 0.01 * size; + + if (buf.count < XPS_TEXT_BUFFER_SIZE) + { + if (is_sideways) + { + buf.x[buf.count] = x + u_offset + (mtx.vorg * size); + buf.y[buf.count] = y - v_offset + (mtx.hadv * 0.5 * size); + } + else + { + buf.x[buf.count] = x + u_offset; + buf.y[buf.count] = y - v_offset; + } + buf.g[buf.count] = glyph_index; + buf.count ++; + } + else + { + xps_flush_text_buffer(ctx, font, &buf, is_charpath); + } + + x += advance * 0.01 * size; + } } if (buf.count > 0) { - xps_flush_text_buffer(ctx, font, &buf, is_charpath); + xps_flush_text_buffer(ctx, font, &buf, is_charpath); } return 0; @@ -451,7 +451,7 @@ xps_parse_glyphs_imp(xps_context_t *ctx, xps_font_t *font, float size, int xps_parse_glyphs(xps_context_t *ctx, - char *base_uri, xps_resource_t *dict, xps_item_t *root) + char *base_uri, xps_resource_t *dict, xps_item_t *root) { xps_item_t *node; @@ -517,17 +517,17 @@ xps_parse_glyphs(xps_context_t *ctx, for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "Glyphs.RenderTransform")) - transform_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Glyphs.RenderTransform")) + transform_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Glyphs.OpacityMask")) - opacity_mask_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Glyphs.OpacityMask")) + opacity_mask_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Glyphs.Clip")) - clip_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Glyphs.Clip")) + clip_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Glyphs.Fill")) - fill_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Glyphs.Fill")) + fill_tag = xps_down(node); } fill_uri = base_uri; @@ -543,16 +543,16 @@ xps_parse_glyphs(xps_context_t *ctx, */ if (!font_size_att || !font_uri_att || !origin_x_att || !origin_y_att) - return gs_throw(-1, "missing attributes in glyphs element"); + return gs_throw(-1, "missing attributes in glyphs element"); if (!indices_att && !unicode_att) - return 0; /* nothing to draw */ + return 0; /* nothing to draw */ if (is_sideways_att) - is_sideways = !strcmp(is_sideways_att, "true"); + is_sideways = !strcmp(is_sideways_att, "true"); if (bidi_level_att) - bidi_level = atoi(bidi_level_att); + bidi_level = atoi(bidi_level_att); /* * Find and load the font resource @@ -562,30 +562,30 @@ xps_parse_glyphs(xps_context_t *ctx, subfont = strrchr(partname, '#'); if (subfont) { - subfontid = atoi(subfont + 1); - *subfont = 0; + subfontid = atoi(subfont + 1); + *subfont = 0; } part = xps_read_part(ctx, partname); if (!part) - return gs_throw1(-1, "cannot find font resource part '%s'", partname); + return gs_throw1(-1, "cannot find font resource part '%s'", partname); /* deobfuscate if necessary */ if (!part->deobfuscated) { - if (strstr(part->name, ".odttf")) - xps_deobfuscate_font_resource(ctx, part); - if (strstr(part->name, ".ODTTF")) - xps_deobfuscate_font_resource(ctx, part); - part->deobfuscated = 1; + if (strstr(part->name, ".odttf")) + xps_deobfuscate_font_resource(ctx, part); + if (strstr(part->name, ".ODTTF")) + xps_deobfuscate_font_resource(ctx, part); + part->deobfuscated = 1; } if (!part->font) { - part->font = xps_new_font(ctx, part->data, part->size, subfontid); - if (!part->font) - return gs_rethrow1(-1, "cannot load font resource '%s'", partname); + part->font = xps_new_font(ctx, part->data, part->size, subfontid); + if (!part->font) + return gs_rethrow1(-1, "cannot load font resource '%s'", partname); - xps_select_best_font_encoding(part->font); + xps_select_best_font_encoding(part->font); } font = part->font; @@ -598,24 +598,24 @@ xps_parse_glyphs(xps_context_t *ctx, if (transform_att || transform_tag) { - gs_matrix transform; + gs_matrix transform; - if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); - if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + if (transform_att) + xps_parse_render_transform(ctx, transform_att, &transform); + if (transform_tag) + xps_parse_matrix_transform(ctx, transform_tag, &transform); - gs_concat(ctx->pgs, &transform); + gs_concat(ctx->pgs, &transform); } if (clip_att || clip_tag) { - if (clip_att) - xps_parse_abbreviated_geometry(ctx, clip_att); - if (clip_tag) - xps_parse_path_geometry(ctx, dict, clip_tag, 0); + if (clip_att) + xps_parse_abbreviated_geometry(ctx, clip_att); + if (clip_tag) + xps_parse_path_geometry(ctx, dict, clip_tag, 0); - xps_clip(ctx, &saved_bounds); + xps_clip(ctx, &saved_bounds); } font_size = atof(font_size_att); @@ -623,7 +623,7 @@ xps_parse_glyphs(xps_context_t *ctx, gs_setfont(ctx->pgs, font->font); gs_make_scaling(font_size, -font_size, &matrix); if (is_sideways) - gs_matrix_rotate(&matrix, 90.0, &matrix); + gs_matrix_rotate(&matrix, 90.0, &matrix); gs_setcharmatrix(ctx->pgs, &matrix); @@ -638,23 +638,23 @@ xps_parse_glyphs(xps_context_t *ctx, if (fill_tag && !strcmp(xps_tag(fill_tag), "SolidColorBrush")) { - fill_opacity_att = xps_att(fill_tag, "Opacity"); - fill_att = xps_att(fill_tag, "Color"); - fill_tag = NULL; + fill_opacity_att = xps_att(fill_tag, "Opacity"); + fill_att = xps_att(fill_tag, "Color"); + fill_tag = NULL; } if (fill_att) { - float samples[32]; - gs_color_space *colorspace; - xps_parse_color(ctx, base_uri, fill_att, &colorspace, samples); - if (fill_opacity_att) - samples[0] = atof(fill_opacity_att); - xps_set_color(ctx, colorspace, samples); - xps_parse_glyphs_imp(ctx, font, font_size, - atof(origin_x_att), atof(origin_y_att), - is_sideways, bidi_level, - indices_att, unicode_att, 0); + float samples[32]; + gs_color_space *colorspace; + xps_parse_color(ctx, base_uri, fill_att, &colorspace, samples); + if (fill_opacity_att) + samples[0] = atof(fill_opacity_att); + xps_set_color(ctx, colorspace, samples); + xps_parse_glyphs_imp(ctx, font, font_size, + atof(origin_x_att), atof(origin_y_att), + is_sideways, bidi_level, + indices_att, unicode_att, 0); } /* @@ -663,11 +663,11 @@ xps_parse_glyphs(xps_context_t *ctx, if (fill_tag) { - ctx->fill_rule = 1; /* always use non-zero winding rule for char paths */ - xps_parse_glyphs_imp(ctx, font, font_size, - atof(origin_x_att), atof(origin_y_att), - is_sideways, bidi_level, indices_att, unicode_att, 1); - xps_parse_brush(ctx, fill_uri, dict, fill_tag); + ctx->fill_rule = 1; /* always use non-zero winding rule for char paths */ + xps_parse_glyphs_imp(ctx, font, font_size, + atof(origin_x_att), atof(origin_y_att), + is_sideways, bidi_level, indices_att, unicode_att, 1); + xps_parse_brush(ctx, fill_uri, dict, fill_tag); } xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); @@ -676,7 +676,7 @@ xps_parse_glyphs(xps_context_t *ctx, if (clip_att || clip_tag) { - xps_restore_bounds(ctx, &saved_bounds); + xps_restore_bounds(ctx, &saved_bounds); } xps_release_part(ctx, part); diff --git a/xps/xpsgradient.c b/xps/xpsgradient.c index 30dee6304..3a7205b08 100644 --- a/xps/xpsgradient.c +++ b/xps/xpsgradient.c @@ -27,7 +27,7 @@ enum { SPREAD_PAD, SPREAD_REPEAT, SPREAD_REFLECT }; static int xps_parse_gradient_stops(xps_context_t *ctx, char *base_uri, xps_item_t *node, - float *offsets, float *colors, int maxcount) + float *offsets, float *colors, int maxcount) { int count = 0; gs_color_space *colorspace; @@ -36,52 +36,52 @@ xps_parse_gradient_stops(xps_context_t *ctx, char *base_uri, xps_item_t *node, while (node && count < maxcount) { - if (!strcmp(xps_tag(node), "GradientStop")) - { - char *offset = xps_att(node, "Offset"); - char *color = xps_att(node, "Color"); - if (offset && color) - { - offsets[count] = atof(offset); - - xps_parse_color(ctx, base_uri, color, &colorspace, sample); - - /* TODO: Convert colors to sRGB using icc_work branch */ - - colors[count * 4 + 0] = sample[0]; - colors[count * 4 + 1] = sample[1]; - colors[count * 4 + 2] = sample[2]; - colors[count * 4 + 3] = sample[3]; - count ++; - } - } - - node = xps_next(node); + if (!strcmp(xps_tag(node), "GradientStop")) + { + char *offset = xps_att(node, "Offset"); + char *color = xps_att(node, "Color"); + if (offset && color) + { + offsets[count] = atof(offset); + + xps_parse_color(ctx, base_uri, color, &colorspace, sample); + + /* TODO: Convert colors to sRGB using icc_work branch */ + + colors[count * 4 + 0] = sample[0]; + colors[count * 4 + 1] = sample[1]; + colors[count * 4 + 2] = sample[2]; + colors[count * 4 + 3] = sample[3]; + count ++; + } + } + + node = xps_next(node); } if (count == maxcount) - dputs("gradient brush exceeded maximum number of gradient stops\n"); + dputs("gradient brush exceeded maximum number of gradient stops\n"); /* Sort the gradient stops by offset */ done = 0; while (!done) { - done = 1; - for (i = 1; i < count; i++) - { - if (offsets[i - 1] > offsets[i]) - { - f = offsets[i - 1]; - offsets[i - 1] = offsets[i]; - offsets[i] = f; - - memcpy(sample, colors + (i - 1) * 4, sizeof(float) * 4); - memcpy(colors + (i - 1) * 4, colors + i * 4, sizeof(float) * 4); - memcpy(colors + i * 4, sample, sizeof(float) * 4); - - done = 0; - } - } + done = 1; + for (i = 1; i < count; i++) + { + if (offsets[i - 1] > offsets[i]) + { + f = offsets[i - 1]; + offsets[i - 1] = offsets[i]; + offsets[i] = f; + + memcpy(sample, colors + (i - 1) * 4, sizeof(float) * 4); + memcpy(colors + (i - 1) * 4, colors + i * 4, sizeof(float) * 4); + memcpy(colors + i * 4, sample, sizeof(float) * 4); + + done = 0; + } + } } return count; @@ -92,8 +92,8 @@ xps_gradient_has_transparent_colors(float *offsets, float *colors, int count) { int i; for (i = 0; i < count; i++) - if (colors[i * 4 + 0] < 0.999) - return 1; + if (colors[i * 4 + 0] < 0.999) + return 1; return 0; } @@ -108,7 +108,7 @@ xps_gradient_has_transparent_colors(float *offsets, float *colors, int count) static gs_function_t * xps_create_gradient_stop_function(xps_context_t *ctx, - float *offsets, float *colors, int count, int opacity_only) + float *offsets, float *colors, int count, int opacity_only) { gs_function_1ItSg_params_t sparams; gs_function_ElIn_params_t lparams; @@ -151,72 +151,72 @@ xps_create_gradient_stop_function(xps_context_t *ctx, for (i = 0; i < k; i++) { - domain = xps_alloc(ctx, 2 * sizeof(float)); - domain[0] = 0.0; - domain[1] = 1.0; - lparams.m = 1; - lparams.Domain = domain; - - range = xps_alloc(ctx, 6 * sizeof(float)); - range[0] = 0.0; - range[1] = 1.0; - range[2] = 0.0; - range[3] = 1.0; - range[4] = 0.0; - range[5] = 1.0; - lparams.n = 3; - lparams.Range = range; - - c0 = xps_alloc(ctx, 3 * sizeof(float)); - lparams.C0 = c0; - - c1 = xps_alloc(ctx, 3 * sizeof(float)); - lparams.C1 = c1; - - if (opacity_only) - { - c0[0] = colors[(i + 0) * 4 + 0]; - c0[1] = colors[(i + 0) * 4 + 0]; - c0[2] = colors[(i + 0) * 4 + 0]; - - c1[0] = colors[(i + 1) * 4 + 0]; - c1[1] = colors[(i + 1) * 4 + 0]; - c1[2] = colors[(i + 1) * 4 + 0]; - } - else - { - c0[0] = colors[(i + 0) * 4 + 1]; - c0[1] = colors[(i + 0) * 4 + 2]; - c0[2] = colors[(i + 0) * 4 + 3]; - - c1[0] = colors[(i + 1) * 4 + 1]; - c1[1] = colors[(i + 1) * 4 + 2]; - c1[2] = colors[(i + 1) * 4 + 3]; - } - - lparams.N = 1; - - code = gs_function_ElIn_init(&lfunc, &lparams, ctx->memory); - if (code < 0) - { - gs_rethrow(code, "gs_function_ElIn_init failed"); - return NULL; - } - - functions[i] = lfunc; - - if (i > 0) - bounds[i - 1] = offsets[(i + 0) + 0]; - - encode[i * 2 + 0] = 0.0; - encode[i * 2 + 1] = 1.0; + domain = xps_alloc(ctx, 2 * sizeof(float)); + domain[0] = 0.0; + domain[1] = 1.0; + lparams.m = 1; + lparams.Domain = domain; + + range = xps_alloc(ctx, 6 * sizeof(float)); + range[0] = 0.0; + range[1] = 1.0; + range[2] = 0.0; + range[3] = 1.0; + range[4] = 0.0; + range[5] = 1.0; + lparams.n = 3; + lparams.Range = range; + + c0 = xps_alloc(ctx, 3 * sizeof(float)); + lparams.C0 = c0; + + c1 = xps_alloc(ctx, 3 * sizeof(float)); + lparams.C1 = c1; + + if (opacity_only) + { + c0[0] = colors[(i + 0) * 4 + 0]; + c0[1] = colors[(i + 0) * 4 + 0]; + c0[2] = colors[(i + 0) * 4 + 0]; + + c1[0] = colors[(i + 1) * 4 + 0]; + c1[1] = colors[(i + 1) * 4 + 0]; + c1[2] = colors[(i + 1) * 4 + 0]; + } + else + { + c0[0] = colors[(i + 0) * 4 + 1]; + c0[1] = colors[(i + 0) * 4 + 2]; + c0[2] = colors[(i + 0) * 4 + 3]; + + c1[0] = colors[(i + 1) * 4 + 1]; + c1[1] = colors[(i + 1) * 4 + 2]; + c1[2] = colors[(i + 1) * 4 + 3]; + } + + lparams.N = 1; + + code = gs_function_ElIn_init(&lfunc, &lparams, ctx->memory); + if (code < 0) + { + gs_rethrow(code, "gs_function_ElIn_init failed"); + return NULL; + } + + functions[i] = lfunc; + + if (i > 0) + bounds[i - 1] = offsets[(i + 0) + 0]; + + encode[i * 2 + 0] = 0.0; + encode[i * 2 + 1] = 1.0; } code = gs_function_1ItSg_init(&sfunc, &sparams, ctx->memory); if (code < 0) { - gs_rethrow(code, "gs_function_1ItSg_init failed"); - return NULL; + gs_rethrow(code, "gs_function_1ItSg_init failed"); + return NULL; } return sfunc; @@ -243,13 +243,13 @@ xps_free_gradient_stop_function(xps_context_t *ctx, gs_function_t *func) for (i = 0; i < sparams->k; i++) { - lfunc = (gs_function_t*) sparams->Functions[i]; /* discard const */ - lparams = (gs_function_ElIn_params_t*) &lfunc->params; - xps_free(ctx, (void*)lparams->Domain); - xps_free(ctx, (void*)lparams->Range); - xps_free(ctx, (void*)lparams->C0); - xps_free(ctx, (void*)lparams->C1); - xps_free(ctx, lfunc); + lfunc = (gs_function_t*) sparams->Functions[i]; /* discard const */ + lparams = (gs_function_ElIn_params_t*) &lfunc->params; + xps_free(ctx, (void*)lparams->Domain); + xps_free(ctx, (void*)lparams->Range); + xps_free(ctx, (void*)lparams->C0); + xps_free(ctx, (void*)lparams->C1); + xps_free(ctx, lfunc); } xps_free(ctx, (void*)sparams->Bounds); @@ -304,8 +304,8 @@ xps_reverse_function(xps_context_t *ctx, gs_function_t *func, float *fary, void code = gs_function_1ItSg_init(&sfunc, &sparams, ctx->memory); if (code < 0) { - gs_rethrow(code, "gs_function_1ItSg_init failed"); - return NULL; + gs_rethrow(code, "gs_function_1ItSg_init failed"); + return NULL; } return sfunc; @@ -320,9 +320,9 @@ xps_reverse_function(xps_context_t *ctx, gs_function_t *func, float *fary, void static int xps_draw_one_radial_gradient(xps_context_t *ctx, - gs_function_t *func, int extend, - float x0, float y0, float r0, - float x1, float y1, float r1) + gs_function_t *func, int extend, + float x0, float y0, float r0, + float x1, float y1, float r1) { gs_memory_t *mem = ctx->memory; gs_shading_t *shading; @@ -331,32 +331,32 @@ xps_draw_one_radial_gradient(xps_context_t *ctx, gs_shading_R_params_init(¶ms); { - params.ColorSpace = ctx->srgb; + params.ColorSpace = ctx->srgb; - params.Coords[0] = x0; - params.Coords[1] = y0; - params.Coords[2] = r0; - params.Coords[3] = x1; - params.Coords[4] = y1; - params.Coords[5] = r1; + params.Coords[0] = x0; + params.Coords[1] = y0; + params.Coords[2] = r0; + params.Coords[3] = x1; + params.Coords[4] = y1; + params.Coords[5] = r1; - params.Extend[0] = extend; - params.Extend[1] = extend; + params.Extend[0] = extend; + params.Extend[1] = extend; - params.Function = func; + params.Function = func; } code = gs_shading_R_init(&shading, ¶ms, mem); if (code < 0) - return gs_rethrow(code, "gs_shading_R_init failed"); + return gs_rethrow(code, "gs_shading_R_init failed"); gs_setsmoothness(ctx->pgs, 0.02); code = gs_shfill(ctx->pgs, shading); if (code < 0) { - gs_free_object(mem, shading, "gs_shading_R"); - return gs_rethrow(code, "gs_shfill failed"); + gs_free_object(mem, shading, "gs_shading_R"); + return gs_rethrow(code, "gs_shfill failed"); } gs_free_object(mem, shading, "gs_shading_R"); @@ -370,8 +370,8 @@ xps_draw_one_radial_gradient(xps_context_t *ctx, static int xps_draw_one_linear_gradient(xps_context_t *ctx, - gs_function_t *func, int extend, - float x0, float y0, float x1, float y1) + gs_function_t *func, int extend, + float x0, float y0, float x1, float y1) { gs_memory_t *mem = ctx->memory; gs_shading_t *shading; @@ -380,30 +380,30 @@ xps_draw_one_linear_gradient(xps_context_t *ctx, gs_shading_A_params_init(¶ms); { - params.ColorSpace = ctx->srgb; + params.ColorSpace = ctx->srgb; - params.Coords[0] = x0; - params.Coords[1] = y0; - params.Coords[2] = x1; - params.Coords[3] = y1; + params.Coords[0] = x0; + params.Coords[1] = y0; + params.Coords[2] = x1; + params.Coords[3] = y1; - params.Extend[0] = extend; - params.Extend[1] = extend; + params.Extend[0] = extend; + params.Extend[1] = extend; - params.Function = func; + params.Function = func; } code = gs_shading_A_init(&shading, ¶ms, mem); if (code < 0) - return gs_rethrow(code, "gs_shading_A_init failed"); + return gs_rethrow(code, "gs_shading_A_init failed"); gs_setsmoothness(ctx->pgs, 0.02); code = gs_shfill(ctx->pgs, shading); if (code < 0) { - gs_free_object(mem, shading, "gs_shading_A"); - return gs_rethrow(code, "gs_shfill failed"); + gs_free_object(mem, shading, "gs_shading_A"); + return gs_rethrow(code, "gs_shfill failed"); } gs_free_object(mem, shading, "gs_shading_A"); @@ -446,13 +446,13 @@ xps_draw_radial_gradient(xps_context_t *ctx, xps_item_t *root, int spread, gs_fu char *radius_y_att = xps_att(root, "RadiusY"); if (origin_att) - sscanf(origin_att, "%g,%g", &x0, &y0); + sscanf(origin_att, "%g,%g", &x0, &y0); if (center_att) - sscanf(center_att, "%g,%g", &x1, &y1); + sscanf(center_att, "%g,%g", &x1, &y1); if (radius_x_att) - xrad = atof(radius_x_att); + xrad = atof(radius_x_att); if (radius_y_att) - yrad = atof(radius_y_att); + yrad = atof(radius_y_att); /* scale the ctm to make ellipses */ gs_gsave(ctx->pgs); @@ -472,92 +472,92 @@ xps_draw_radial_gradient(xps_context_t *ctx, xps_item_t *root, int spread, gs_fu if (spread == SPREAD_PAD) { - if (!point_inside_circle(x0, y0, x1, y1, r1)) - { - gs_function_t *reverse; - float in[1]; - float out[4]; - float fary[10]; - void *vary[1]; - - /* PDF shadings with extend doesn't work the same way as XPS - * gradients when the radial shading is a cone. In this case - * we fill the background ourselves. - */ - - in[0] = 1.0; - out[0] = 1.0; - out[1] = 0.0; - out[2] = 0.0; - out[3] = 0.0; - if (ctx->opacity_only) - gs_function_evaluate(func, in, out); - else - gs_function_evaluate(func, in, out + 1); - - xps_set_color(ctx, ctx->srgb, out); - - gs_moveto(ctx->pgs, bbox.p.x, bbox.p.y); - gs_lineto(ctx->pgs, bbox.q.x, bbox.p.y); - gs_lineto(ctx->pgs, bbox.q.x, bbox.q.y); - gs_lineto(ctx->pgs, bbox.p.x, bbox.q.y); - gs_closepath(ctx->pgs); - gs_fill(ctx->pgs); - - /* We also have to reverse the direction so the bigger circle - * comes first or the graphical results do not match. We also - * have to reverse the direction of the function to compensate. - */ - - reverse = xps_reverse_function(ctx, func, fary, vary); - code = xps_draw_one_radial_gradient(ctx, reverse, 1, x1, y1, r1, x0, y0, r0); - if (code < 0) - return gs_rethrow(code, "could not draw radial gradient"); - xps_free(ctx, reverse); - } - else - { - code = xps_draw_one_radial_gradient(ctx, func, 1, x0, y0, r0, x1, y1, r1); - if (code < 0) - return gs_rethrow(code, "could not draw radial gradient"); - } + if (!point_inside_circle(x0, y0, x1, y1, r1)) + { + gs_function_t *reverse; + float in[1]; + float out[4]; + float fary[10]; + void *vary[1]; + + /* PDF shadings with extend doesn't work the same way as XPS + * gradients when the radial shading is a cone. In this case + * we fill the background ourselves. + */ + + in[0] = 1.0; + out[0] = 1.0; + out[1] = 0.0; + out[2] = 0.0; + out[3] = 0.0; + if (ctx->opacity_only) + gs_function_evaluate(func, in, out); + else + gs_function_evaluate(func, in, out + 1); + + xps_set_color(ctx, ctx->srgb, out); + + gs_moveto(ctx->pgs, bbox.p.x, bbox.p.y); + gs_lineto(ctx->pgs, bbox.q.x, bbox.p.y); + gs_lineto(ctx->pgs, bbox.q.x, bbox.q.y); + gs_lineto(ctx->pgs, bbox.p.x, bbox.q.y); + gs_closepath(ctx->pgs); + gs_fill(ctx->pgs); + + /* We also have to reverse the direction so the bigger circle + * comes first or the graphical results do not match. We also + * have to reverse the direction of the function to compensate. + */ + + reverse = xps_reverse_function(ctx, func, fary, vary); + code = xps_draw_one_radial_gradient(ctx, reverse, 1, x1, y1, r1, x0, y0, r0); + if (code < 0) + return gs_rethrow(code, "could not draw radial gradient"); + xps_free(ctx, reverse); + } + else + { + code = xps_draw_one_radial_gradient(ctx, func, 1, x0, y0, r0, x1, y1, r1); + if (code < 0) + return gs_rethrow(code, "could not draw radial gradient"); + } } else { - for (i = 0; i < 100; i++) - { - /* Draw current circle */ - - if (!point_inside_circle(x0, y0, x1, y1, r1)) - dputs("xps: we should reverse gradient here too\n"); - - if (spread == SPREAD_REFLECT && (i & 1)) - code = xps_draw_one_radial_gradient(ctx, func, 0, x1, y1, r1, x0, y0, r0); - else - code = xps_draw_one_radial_gradient(ctx, func, 0, x0, y0, r0, x1, y1, r1); - if (code < 0) - return gs_rethrow(code, "could not draw axial gradient"); - - /* Check if circle encompassed the entire bounding box (break loop if we do) */ - - done = 1; - if (!point_inside_circle(bbox.p.x, bbox.p.y, x1, y1, r1)) done = 0; - if (!point_inside_circle(bbox.p.x, bbox.q.y, x1, y1, r1)) done = 0; - if (!point_inside_circle(bbox.q.x, bbox.q.y, x1, y1, r1)) done = 0; - if (!point_inside_circle(bbox.q.x, bbox.p.y, x1, y1, r1)) done = 0; - if (done) - break; - - /* Prepare next circle */ - - r0 = r1; - r1 += xrad; - - x0 += dx; - y0 += dy; - x1 += dx; - y1 += dy; - } + for (i = 0; i < 100; i++) + { + /* Draw current circle */ + + if (!point_inside_circle(x0, y0, x1, y1, r1)) + dputs("xps: we should reverse gradient here too\n"); + + if (spread == SPREAD_REFLECT && (i & 1)) + code = xps_draw_one_radial_gradient(ctx, func, 0, x1, y1, r1, x0, y0, r0); + else + code = xps_draw_one_radial_gradient(ctx, func, 0, x0, y0, r0, x1, y1, r1); + if (code < 0) + return gs_rethrow(code, "could not draw axial gradient"); + + /* Check if circle encompassed the entire bounding box (break loop if we do) */ + + done = 1; + if (!point_inside_circle(bbox.p.x, bbox.p.y, x1, y1, r1)) done = 0; + if (!point_inside_circle(bbox.p.x, bbox.q.y, x1, y1, r1)) done = 0; + if (!point_inside_circle(bbox.q.x, bbox.q.y, x1, y1, r1)) done = 0; + if (!point_inside_circle(bbox.q.x, bbox.p.y, x1, y1, r1)) done = 0; + if (done) + break; + + /* Prepare next circle */ + + r0 = r1; + r1 += xrad; + + x0 += dx; + y0 += dy; + x1 += dx; + y1 += dy; + } } gs_grestore(ctx->pgs); @@ -588,9 +588,9 @@ xps_draw_linear_gradient(xps_context_t *ctx, xps_item_t *root, int spread, gs_fu y1 = 1; if (start_point_att) - sscanf(start_point_att, "%g,%g", &x0, &y0); + sscanf(start_point_att, "%g,%g", &x0, &y0); if (end_point_att) - sscanf(end_point_att, "%g,%g", &x1, &y1); + sscanf(end_point_att, "%g,%g", &x1, &y1); dx = x1 - x0; dy = y1 - y0; @@ -599,55 +599,55 @@ xps_draw_linear_gradient(xps_context_t *ctx, xps_item_t *root, int spread, gs_fu if (spread == SPREAD_PAD) { - code = xps_draw_one_linear_gradient(ctx, func, 1, x0, y0, x1, y1); - if (code < 0) - return gs_rethrow(code, "could not draw axial gradient"); + code = xps_draw_one_linear_gradient(ctx, func, 1, x0, y0, x1, y1); + if (code < 0) + return gs_rethrow(code, "could not draw axial gradient"); } else { - float len; - float a, b; - float dist[4]; - float d0, d1; - int i0, i1; - - len = sqrt(dx * dx + dy * dy); - a = dx / len; - b = dy / len; - - dist[0] = a * (bbox.p.x - x0) + b * (bbox.p.y - y0); - dist[1] = a * (bbox.p.x - x0) + b * (bbox.q.y - y0); - dist[2] = a * (bbox.q.x - x0) + b * (bbox.q.y - y0); - dist[3] = a * (bbox.q.x - x0) + b * (bbox.p.y - y0); - - d0 = dist[0]; - d1 = dist[0]; - for (i = 1; i < 4; i++) - { - if (dist[i] < d0) d0 = dist[i]; - if (dist[i] > d1) d1 = dist[i]; - } - - i0 = floor(d0 / len); - i1 = ceil(d1 / len); - - for (i = i0; i < i1; i++) - { - if (spread == SPREAD_REFLECT && (i & 1)) - { - code = xps_draw_one_linear_gradient(ctx, func, 0, - x1 + dx * i, y1 + dy * i, - x0 + dx * i, y0 + dy * i); - } - else - { - code = xps_draw_one_linear_gradient(ctx, func, 0, - x0 + dx * i, y0 + dy * i, - x1 + dx * i, y1 + dy * i); - } - if (code < 0) - return gs_rethrow(code, "could not draw axial gradient"); - } + float len; + float a, b; + float dist[4]; + float d0, d1; + int i0, i1; + + len = sqrt(dx * dx + dy * dy); + a = dx / len; + b = dy / len; + + dist[0] = a * (bbox.p.x - x0) + b * (bbox.p.y - y0); + dist[1] = a * (bbox.p.x - x0) + b * (bbox.q.y - y0); + dist[2] = a * (bbox.q.x - x0) + b * (bbox.q.y - y0); + dist[3] = a * (bbox.q.x - x0) + b * (bbox.p.y - y0); + + d0 = dist[0]; + d1 = dist[0]; + for (i = 1; i < 4; i++) + { + if (dist[i] < d0) d0 = dist[i]; + if (dist[i] > d1) d1 = dist[i]; + } + + i0 = floor(d0 / len); + i1 = ceil(d1 / len); + + for (i = i0; i < i1; i++) + { + if (spread == SPREAD_REFLECT && (i & 1)) + { + code = xps_draw_one_linear_gradient(ctx, func, 0, + x1 + dx * i, y1 + dy * i, + x0 + dx * i, y0 + dy * i); + } + else + { + code = xps_draw_one_linear_gradient(ctx, func, 0, + x0 + dx * i, y0 + dy * i, + x1 + dx * i, y1 + dy * i); + } + if (code < 0) + return gs_rethrow(code, "could not draw axial gradient"); + } } return 0; @@ -660,7 +660,7 @@ xps_draw_linear_gradient(xps_context_t *ctx, xps_item_t *root, int spread, gs_fu static int xps_parse_gradient_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_item_t *root, - int (*draw)(xps_context_t *, xps_item_t *, int, gs_function_t *)) + int (*draw)(xps_context_t *, xps_item_t *, int, gs_function_t *)) { xps_item_t *node; @@ -694,14 +694,14 @@ xps_parse_gradient_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dic for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "LinearGradientBrush.Transform")) - transform_tag = xps_down(node); - if (!strcmp(xps_tag(node), "RadialGradientBrush.Transform")) - transform_tag = xps_down(node); - if (!strcmp(xps_tag(node), "LinearGradientBrush.GradientStops")) - stop_tag = xps_down(node); - if (!strcmp(xps_tag(node), "RadialGradientBrush.GradientStops")) - stop_tag = xps_down(node); + if (!strcmp(xps_tag(node), "LinearGradientBrush.Transform")) + transform_tag = xps_down(node); + if (!strcmp(xps_tag(node), "RadialGradientBrush.Transform")) + transform_tag = xps_down(node); + if (!strcmp(xps_tag(node), "LinearGradientBrush.GradientStops")) + stop_tag = xps_down(node); + if (!strcmp(xps_tag(node), "RadialGradientBrush.GradientStops")) + stop_tag = xps_down(node); } xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL); @@ -709,34 +709,34 @@ xps_parse_gradient_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dic spread_method = SPREAD_PAD; if (spread_att) { - if (!strcmp(spread_att, "Pad")) - spread_method = SPREAD_PAD; - if (!strcmp(spread_att, "Reflect")) - spread_method = SPREAD_REFLECT; - if (!strcmp(spread_att, "Repeat")) - spread_method = SPREAD_REPEAT; + if (!strcmp(spread_att, "Pad")) + spread_method = SPREAD_PAD; + if (!strcmp(spread_att, "Reflect")) + spread_method = SPREAD_REFLECT; + if (!strcmp(spread_att, "Repeat")) + spread_method = SPREAD_REPEAT; } gs_make_identity(&transform); if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); + xps_parse_render_transform(ctx, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + xps_parse_matrix_transform(ctx, transform_tag, &transform); if (!stop_tag) - return gs_throw(-1, "missing gradient stops tag"); + return gs_throw(-1, "missing gradient stops tag"); stop_count = xps_parse_gradient_stops(ctx, base_uri, stop_tag, stop_offsets, stop_colors, MAX_STOPS); if (stop_count == 0) - return gs_throw(-1, "no gradient stops found"); + return gs_throw(-1, "no gradient stops found"); color_func = xps_create_gradient_stop_function(ctx, stop_offsets, stop_colors, stop_count, 0); if (!color_func) - return gs_rethrow(-1, "could not create color gradient function"); + return gs_rethrow(-1, "could not create color gradient function"); opacity_func = xps_create_gradient_stop_function(ctx, stop_offsets, stop_colors, stop_count, 1); if (!opacity_func) - return gs_rethrow(-1, "could not create opacity gradient function"); + return gs_rethrow(-1, "could not create opacity gradient function"); has_opacity = xps_gradient_has_transparent_colors(stop_offsets, stop_colors, stop_count); @@ -752,29 +752,29 @@ xps_parse_gradient_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dic if (ctx->opacity_only) { - draw(ctx, root, spread_method, opacity_func); + draw(ctx, root, spread_method, opacity_func); } else { - if (has_opacity) - { - gs_transparency_mask_params_t params; - gs_transparency_group_params_t tgp; - - gs_trans_mask_params_init(¶ms, TRANSPARENCY_MASK_Luminosity); - gs_begin_transparency_mask(ctx->pgs, ¶ms, &bbox, 0); - draw(ctx, root, spread_method, opacity_func); - gs_end_transparency_mask(ctx->pgs, TRANSPARENCY_CHANNEL_Opacity); - - gs_trans_group_params_init(&tgp); - gs_begin_transparency_group(ctx->pgs, &tgp, &bbox); - draw(ctx, root, spread_method, color_func); - gs_end_transparency_group(ctx->pgs); - } - else - { - draw(ctx, root, spread_method, color_func); - } + if (has_opacity) + { + gs_transparency_mask_params_t params; + gs_transparency_group_params_t tgp; + + gs_trans_mask_params_init(¶ms, TRANSPARENCY_MASK_Luminosity); + gs_begin_transparency_mask(ctx->pgs, ¶ms, &bbox, 0); + draw(ctx, root, spread_method, opacity_func); + gs_end_transparency_mask(ctx->pgs, TRANSPARENCY_CHANNEL_Opacity); + + gs_trans_group_params_init(&tgp); + gs_begin_transparency_group(ctx->pgs, &tgp, &bbox); + draw(ctx, root, spread_method, color_func); + gs_end_transparency_group(ctx->pgs); + } + else + { + draw(ctx, root, spread_method, color_func); + } } xps_end_opacity(ctx, base_uri, dict, opacity_att, NULL); @@ -795,7 +795,7 @@ xps_parse_linear_gradient_brush(xps_context_t *ctx, char *base_uri, xps_resource int code; code = xps_parse_gradient_brush(ctx, base_uri, dict, root, xps_draw_linear_gradient); if (code < 0) - return gs_rethrow(code, "cannot parse linear gradient brush"); + return gs_rethrow(code, "cannot parse linear gradient brush"); return gs_okay; } @@ -805,7 +805,7 @@ xps_parse_radial_gradient_brush(xps_context_t *ctx, char *base_uri, xps_resource int code; code = xps_parse_gradient_brush(ctx, base_uri, dict, root, xps_draw_radial_gradient); if (code < 0) - return gs_rethrow(code, "cannot parse radial gradient brush"); + return gs_rethrow(code, "cannot parse radial gradient brush"); return gs_okay; } diff --git a/xps/xpshash.c b/xps/xpshash.c index f4445db0d..6ce573f3b 100644 --- a/xps/xpshash.c +++ b/xps/xpshash.c @@ -1,9 +1,22 @@ +/* Copyright (C) 2006-2008 Artifex Software, Inc. + All Rights Reserved. + + This software is provided AS-IS with no warranty, either express or + implied. + + This software is distributed under license and may not be copied, modified + or distributed except as expressly authorized under the terms of that + license. Refer to licensing information at http://www.artifex.com/ + or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, + San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information. +*/ + /* Linear probe hash table. * * Simple hashtable with open adressing linear probe. * Does not manage memory of key/value pointers. * Does not support deleting entries. - */ + */ #include "ghostxps.h" @@ -32,7 +45,7 @@ struct xps_hash_table_s static inline int xps_tolower(int c) { if (c >= 'A' && c <= 'Z') - return c + 32; + return c + 32; return c; } @@ -40,7 +53,7 @@ static unsigned int xps_hash(char *s) { unsigned int h = 0; while (*s) - h = xps_tolower(*s++) + (h << 6) + (h << 16) - h; + h = xps_tolower(*s++) + (h << 6) + (h << 16) - h; return h; } @@ -51,8 +64,8 @@ xps_hash_table_t *xps_hash_new(xps_context_t *ctx) table = xps_alloc(ctx, sizeof(xps_hash_table_t)); if (!table) { - gs_throw(-1, "out of memory: hash table struct"); - return NULL; + gs_throw(-1, "out of memory: hash table struct"); + return NULL; } table->size = primes[0]; @@ -61,9 +74,9 @@ xps_hash_table_t *xps_hash_new(xps_context_t *ctx) table->entries = xps_alloc(ctx, sizeof(xps_hash_entry_t) * table->size); if (!table->entries) { - xps_free(ctx, table); - gs_throw(-1, "out of memory: hash table entries array"); - return NULL; + xps_free(ctx, table); + gs_throw(-1, "out of memory: hash table entries array"); + return NULL; } memset(table->entries, 0, sizeof(xps_hash_entry_t) * table->size); @@ -81,17 +94,17 @@ static int xps_hash_double(xps_context_t *ctx, xps_hash_table_t *table) for (i = 0; primes[i] != 0; i++) { - if (primes[i] > old_size) - { - new_size = primes[i]; - break; - } + if (primes[i] > old_size) + { + new_size = primes[i]; + break; + } } old_entries = table->entries; new_entries = xps_alloc(ctx, sizeof(xps_hash_entry_t) * new_size); if (!new_entries) - return gs_throw(-1, "out of memory: hash table entries array"); + return gs_throw(-1, "out of memory: hash table entries array"); table->size = new_size; table->entries = new_entries; @@ -100,8 +113,8 @@ static int xps_hash_double(xps_context_t *ctx, xps_hash_table_t *table) memset(table->entries, 0, sizeof(xps_hash_entry_t) * table->size); for (i = 0; i < old_size; i++) - if (old_entries[i].value) - xps_hash_insert(ctx, table, old_entries[i].key, old_entries[i].value); + if (old_entries[i].value) + xps_hash_insert(ctx, table, old_entries[i].key, old_entries[i].value); xps_free(ctx, old_entries); @@ -122,13 +135,13 @@ void *xps_hash_lookup(xps_hash_table_t *table, char *key) while (1) { - if (!entries[pos].value) - return NULL; + if (!entries[pos].value) + return NULL; - if (xps_strcasecmp(key, entries[pos].key) == 0) - return entries[pos].value; + if (xps_strcasecmp(key, entries[pos].key) == 0) + return entries[pos].value; - pos = (pos + 1) % size; + pos = (pos + 1) % size; } } @@ -140,8 +153,8 @@ int xps_hash_insert(xps_context_t *ctx, xps_hash_table_t *table, char *key, void /* Grow the table at 80% load */ if (table->load > table->size * 8 / 10) { - if (xps_hash_double(ctx, table) < 0) - return gs_rethrow(-1, "cannot grow hash table"); + if (xps_hash_double(ctx, table) < 0) + return gs_rethrow(-1, "cannot grow hash table"); } entries = table->entries; @@ -150,20 +163,20 @@ int xps_hash_insert(xps_context_t *ctx, xps_hash_table_t *table, char *key, void while (1) { - if (!entries[pos].value) - { - entries[pos].key = key; - entries[pos].value = value; - table->load ++; - return 0; - } - - if (xps_strcasecmp(key, entries[pos].key) == 0) - { - return 0; - } - - pos = (pos + 1) % size; + if (!entries[pos].value) + { + entries[pos].key = key; + entries[pos].value = value; + table->load ++; + return 0; + } + + if (xps_strcasecmp(key, entries[pos].key) == 0) + { + return 0; + } + + pos = (pos + 1) % size; } } @@ -175,11 +188,11 @@ void xps_hash_debug(xps_hash_table_t *table) for (i = 0; i < table->size; i++) { - if (!table->entries[i].value) - printf("table % 4d: empty\n", i); - else - printf("table % 4d: key=%s value=%p\n", i, - table->entries[i].key, table->entries[i].value); + if (!table->entries[i].value) + printf("table % 4d: empty\n", i); + else + printf("table % 4d: key=%s value=%p\n", i, + table->entries[i].key, table->entries[i].value); } } diff --git a/xps/xpsimage.c b/xps/xpsimage.c index 00cc8290c..ef3743c60 100644 --- a/xps/xpsimage.c +++ b/xps/xpsimage.c @@ -32,33 +32,33 @@ xps_isolate_alpha_channel_8(xps_context_t *ctx, xps_image_t *image) byte *sp, *dp, *ap; if ((image->colorspace != XPS_GRAY_A) && - (image->colorspace != XPS_RGB_A) && - (image->colorspace != XPS_CMYK_A)) - return 0; + (image->colorspace != XPS_RGB_A) && + (image->colorspace != XPS_CMYK_A)) + return 0; image->alpha = xps_alloc(ctx, image->width * image->height); if (!image->alpha) - return gs_throw(-1, "cannot allocate image alpha plane"); + return gs_throw(-1, "cannot allocate image alpha plane"); for (y = 0; y < image->height; y++) { - sp = image->samples + image->width * n * y; - dp = image->samples + image->width * (n - 1) * y; - ap = image->alpha + image->width * y; - for (x = 0; x < image->width; x++) - { - for (k = 0; k < n - 1; k++) - *dp++ = *sp++; - *ap++ = *sp++; - } + sp = image->samples + image->width * n * y; + dp = image->samples + image->width * (n - 1) * y; + ap = image->alpha + image->width * y; + for (x = 0; x < image->width; x++) + { + for (k = 0; k < n - 1; k++) + *dp++ = *sp++; + *ap++ = *sp++; + } } if (image->colorspace == XPS_GRAY_A) - image->colorspace = XPS_GRAY; + image->colorspace = XPS_GRAY; if (image->colorspace == XPS_RGB_A) - image->colorspace = XPS_RGB; + image->colorspace = XPS_RGB; if (image->colorspace == XPS_CMYK_A) - image->colorspace = XPS_CMYK; + image->colorspace = XPS_CMYK; image->comps --; image->stride = image->width * image->comps; @@ -74,33 +74,33 @@ xps_isolate_alpha_channel_16(xps_context_t *ctx, xps_image_t *image) unsigned short *sp, *dp, *ap; if ((image->colorspace != XPS_GRAY_A) && - (image->colorspace != XPS_RGB_A) && - (image->colorspace != XPS_CMYK_A)) - return 0; + (image->colorspace != XPS_RGB_A) && + (image->colorspace != XPS_CMYK_A)) + return 0; image->alpha = xps_alloc(ctx, image->width * image->height * 2); if (!image->alpha) - return gs_throw(-1, "cannot allocate image alpha plane"); + return gs_throw(-1, "cannot allocate image alpha plane"); for (y = 0; y < image->height; y++) { - sp = ((unsigned short*)image->samples) + (image->width * n * y); - dp = ((unsigned short*)image->samples) + (image->width * (n - 1) * y); - ap = ((unsigned short*)image->alpha) + (image->width * y); - for (x = 0; x < image->width; x++) - { - for (k = 0; k < n - 1; k++) - *dp++ = *sp++; - *ap++ = *sp++; - } + sp = ((unsigned short*)image->samples) + (image->width * n * y); + dp = ((unsigned short*)image->samples) + (image->width * (n - 1) * y); + ap = ((unsigned short*)image->alpha) + (image->width * y); + for (x = 0; x < image->width; x++) + { + for (k = 0; k < n - 1; k++) + *dp++ = *sp++; + *ap++ = *sp++; + } } if (image->colorspace == XPS_GRAY_A) - image->colorspace = XPS_GRAY; + image->colorspace = XPS_GRAY; if (image->colorspace == XPS_RGB_A) - image->colorspace = XPS_RGB; + image->colorspace = XPS_RGB; if (image->colorspace == XPS_CMYK_A) - image->colorspace = XPS_CMYK; + image->colorspace = XPS_CMYK; image->comps --; image->stride = image->width * image->comps * 2; @@ -116,38 +116,38 @@ xps_decode_image(xps_context_t *ctx, xps_part_t *part, xps_image_t *image) int error; if (len < 2) - error = gs_throw(-1, "unknown image file format"); + error = gs_throw(-1, "unknown image file format"); memset(image, 0, sizeof(xps_image_t)); image->samples = NULL; image->alpha = NULL; if (buf[0] == 0xff && buf[1] == 0xd8) - error = xps_decode_jpeg(ctx->memory, buf, len, image); + error = xps_decode_jpeg(ctx->memory, buf, len, image); else if (memcmp(buf, "\211PNG\r\n\032\n", 8) == 0) - error = xps_decode_png(ctx->memory, buf, len, image); + error = xps_decode_png(ctx->memory, buf, len, image); else if (memcmp(buf, "II", 2) == 0 && buf[2] == 0xBC) - error = xps_decode_hdphoto(ctx->memory, buf, len, image); + error = xps_decode_hdphoto(ctx->memory, buf, len, image); else if (memcmp(buf, "MM", 2) == 0) - error = xps_decode_tiff(ctx->memory, buf, len, image); + error = xps_decode_tiff(ctx->memory, buf, len, image); else if (memcmp(buf, "II", 2) == 0) - error = xps_decode_tiff(ctx->memory, buf, len, image); + error = xps_decode_tiff(ctx->memory, buf, len, image); else - error = gs_throw(-1, "unknown image file format"); + error = gs_throw(-1, "unknown image file format"); if (error) - return gs_rethrow(error, "could not decode image"); + return gs_rethrow(error, "could not decode image"); if (image->colorspace == XPS_GRAY_A || - image->colorspace == XPS_RGB_A || - image->colorspace == XPS_CMYK_A) + image->colorspace == XPS_RGB_A || + image->colorspace == XPS_CMYK_A) { - if (image->bits < 8) - dprintf1("cannot isolate alpha channel in %d bpc images\n", image->bits); - if (image->bits == 8) - xps_isolate_alpha_channel_8(ctx, image); - if (image->bits == 16) - xps_isolate_alpha_channel_16(ctx, image); + if (image->bits < 8) + dprintf1("cannot isolate alpha channel in %d bpc images\n", image->bits); + if (image->bits == 8) + xps_isolate_alpha_channel_8(ctx, image); + if (image->bits == 16) + xps_isolate_alpha_channel_16(ctx, image); } return gs_okay; @@ -167,24 +167,24 @@ xps_paint_image_brush_imp(xps_context_t *ctx, xps_image_t *image, int alpha) if (alpha) { - colorspace = ctx->gray; - samples = image->alpha; - count = (image->width * image->bits + 7) / 8 * image->height; - used = 0; + colorspace = ctx->gray; + samples = image->alpha; + count = (image->width * image->bits + 7) / 8 * image->height; + used = 0; } else { - switch (image->colorspace) - { - case XPS_GRAY: colorspace = ctx->gray; break; - case XPS_RGB: colorspace = ctx->srgb; break; - case XPS_CMYK: colorspace = ctx->cmyk; break; - default: - return gs_throw(-1, "cannot draw images with interleaved alpha"); - } - samples = image->samples; - count = image->stride * image->height; - used = 0; + switch (image->colorspace) + { + case XPS_GRAY: colorspace = ctx->gray; break; + case XPS_RGB: colorspace = ctx->srgb; break; + case XPS_CMYK: colorspace = ctx->cmyk; break; + default: + return gs_throw(-1, "cannot draw images with interleaved alpha"); + } + samples = image->samples; + count = image->stride * image->height; + used = 0; } memset(&gsimage, 0, sizeof(gsimage)); @@ -201,19 +201,19 @@ xps_paint_image_brush_imp(xps_context_t *ctx, xps_image_t *image, int alpha) penum = gs_image_enum_alloc(ctx->memory, "xps_parse_image_brush (gs_image_enum_alloc)"); if (!penum) - return gs_throw(-1, "gs_enum_allocate failed"); + return gs_throw(-1, "gs_enum_allocate failed"); if ((code = gs_image_init(penum, &gsimage, false, ctx->pgs)) < 0) - return gs_throw(code, "gs_image_init failed"); + return gs_throw(code, "gs_image_init failed"); if ((code = gs_image_next(penum, samples, count, &used)) < 0) - return gs_throw(code, "gs_image_next failed"); + return gs_throw(code, "gs_image_next failed"); if (count < used) - return gs_throw2(-1, "not enough image data (image=%d used=%d)", count, used); + return gs_throw2(-1, "not enough image data (image=%d used=%d)", count, used); if (count > used) - return gs_throw2(0, "too much image data (image=%d used=%d)", count, used); + return gs_throw2(0, "too much image data (image=%d used=%d)", count, used); gs_image_cleanup_and_free_enum(penum, ctx->pgs); @@ -227,34 +227,34 @@ xps_paint_image_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, if (ctx->opacity_only) { - if (image->alpha) - { - xps_paint_image_brush_imp(ctx, image, 1); - } - return 0; + if (image->alpha) + { + xps_paint_image_brush_imp(ctx, image, 1); + } + return 0; } if (image->alpha) { - gs_transparency_mask_params_t params; - gs_transparency_group_params_t tgp; - gs_rect bbox; + gs_transparency_mask_params_t params; + gs_transparency_group_params_t tgp; + gs_rect bbox; - xps_bounds_in_user_space(ctx, &bbox); + xps_bounds_in_user_space(ctx, &bbox); - gs_trans_mask_params_init(¶ms, TRANSPARENCY_MASK_Luminosity); - gs_begin_transparency_mask(ctx->pgs, ¶ms, &bbox, 0); - xps_paint_image_brush_imp(ctx, image, 1); - gs_end_transparency_mask(ctx->pgs, TRANSPARENCY_CHANNEL_Opacity); + gs_trans_mask_params_init(¶ms, TRANSPARENCY_MASK_Luminosity); + gs_begin_transparency_mask(ctx->pgs, ¶ms, &bbox, 0); + xps_paint_image_brush_imp(ctx, image, 1); + gs_end_transparency_mask(ctx->pgs, TRANSPARENCY_CHANNEL_Opacity); - gs_trans_group_params_init(&tgp); - gs_begin_transparency_group(ctx->pgs, &tgp, &bbox); - xps_paint_image_brush_imp(ctx, image, 0); - gs_end_transparency_group(ctx->pgs); + gs_trans_group_params_init(&tgp); + gs_begin_transparency_group(ctx->pgs, &tgp, &bbox); + xps_paint_image_brush_imp(ctx, image, 0); + gs_end_transparency_group(ctx->pgs); } else { - xps_paint_image_brush_imp(ctx, image, 0); + xps_paint_image_brush_imp(ctx, image, 0); } return 0; } @@ -272,47 +272,47 @@ xps_find_image_brush_source_part(xps_context_t *ctx, char *base_uri, xps_item_t image_source_att = xps_att(root, "ImageSource"); if (!image_source_att) - return gs_throw(-1, "missing ImageSource attribute"); + return gs_throw(-1, "missing ImageSource attribute"); /* "{ColorConvertedBitmap /Resources/Image.tiff /Resources/Profile.icc}" */ if (strstr(image_source_att, "{ColorConvertedBitmap") == image_source_att) { - image_name = NULL; - profile_name = NULL; - - strcpy(buf, image_source_att); - p = strchr(buf, ' '); - if (p) - { - image_name = p + 1; - p = strchr(p + 1, ' '); - if (p) - { - *p = 0; - profile_name = p + 1; - p = strchr(p + 1, '}'); - if (p) - *p = 0; - } - } + image_name = NULL; + profile_name = NULL; + + strcpy(buf, image_source_att); + p = strchr(buf, ' '); + if (p) + { + image_name = p + 1; + p = strchr(p + 1, ' '); + if (p) + { + *p = 0; + profile_name = p + 1; + p = strchr(p + 1, '}'); + if (p) + *p = 0; + } + } } else { - image_name = image_source_att; - profile_name = NULL; + image_name = image_source_att; + profile_name = NULL; } if (!image_name) - return gs_throw1(-1, "cannot parse image resource name '%s'", image_source_att); + return gs_throw1(-1, "cannot parse image resource name '%s'", image_source_att); if (profile_name) - dprintf2("warning: ignoring color profile '%s' associated with image '%s'\n", - profile_name, image_name); + dprintf2("warning: ignoring color profile '%s' associated with image '%s'\n", + profile_name, image_name); xps_absolute_path(partname, base_uri, image_name); part = xps_read_part(ctx, partname); if (!part) - return gs_throw1(-1, "cannot find image resource part '%s'", partname); + return gs_throw1(-1, "cannot find image resource part '%s'", partname); *partp = part; return 0; @@ -327,15 +327,15 @@ xps_parse_image_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, code = xps_find_image_brush_source_part(ctx, base_uri, root, &part); if (code < 0) - return gs_rethrow(code, "cannot find image source"); + return gs_rethrow(code, "cannot find image source"); image = xps_alloc(ctx, sizeof(xps_image_t)); if (!image) - return gs_throw(-1, "out of memory: image struct"); + return gs_throw(-1, "out of memory: image struct"); code = xps_decode_image(ctx, part, image); if (code < 0) - return gs_rethrow(-1, "cannot decode image resource"); + return gs_rethrow(-1, "cannot decode image resource"); xps_parse_tiling_brush(ctx, base_uri, dict, root, xps_paint_image_brush, image); @@ -356,17 +356,17 @@ xps_image_brush_has_transparency(xps_context_t *ctx, char *base_uri, xps_item_t code = xps_find_image_brush_source_part(ctx, base_uri, root, &part); if (code < 0) - return gs_rethrow(code, "cannot find image source"); + return gs_rethrow(code, "cannot find image source"); /* Hmm, we should be smarter here and only look at the image header */ image = xps_alloc(ctx, sizeof(xps_image_t)); if (!image) - return gs_throw(-1, "out of memory: image struct"); + return gs_throw(-1, "out of memory: image struct"); code = xps_decode_image(ctx, part, image); if (code < 0) - return gs_rethrow(-1, "cannot decode image resource"); + return gs_rethrow(-1, "cannot decode image resource"); has_alpha = image->alpha != NULL; @@ -379,9 +379,9 @@ void xps_free_image(xps_context_t *ctx, xps_image_t *image) { if (image->samples) - xps_free(ctx, image->samples); + xps_free(ctx, image->samples); if (image->alpha) - xps_free(ctx, image->alpha); + xps_free(ctx, image->alpha); xps_free(ctx, image); } diff --git a/xps/xpsmem.c b/xps/xpsmem.c index 9901230d8..525706ba5 100644 --- a/xps/xpsmem.c +++ b/xps/xpsmem.c @@ -19,7 +19,7 @@ void * xps_realloc_imp(xps_context_t *ctx, void *ptr, int size, const char *func) { if (!ptr) - return gs_alloc_bytes(ctx->memory, size, func); + return gs_alloc_bytes(ctx->memory, size, func); return gs_resize_object(ctx->memory, ptr, size, func); } @@ -27,20 +27,20 @@ static inline int xps_tolower(int c) { if (c >= 'A' && c <= 'Z') - return c + 32; + return c + 32; return c; } int xps_strcasecmp(char *a, char *b) { - while (xps_tolower(*a) == xps_tolower(*b)) - { - if (*a++ == 0) - return 0; - b++; - } - return xps_tolower(*a) - xps_tolower(*b); + while (xps_tolower(*a) == xps_tolower(*b)) + { + if (*a++ == 0) + return 0; + b++; + } + return xps_tolower(*a) - xps_tolower(*b); } char * @@ -48,9 +48,9 @@ xps_strdup_imp(xps_context_t *ctx, const char *str, const char *cname) { char *cpy = NULL; if (str) - cpy = (char*) gs_alloc_bytes(ctx->memory, strlen(str) + 1, cname); + cpy = (char*) gs_alloc_bytes(ctx->memory, strlen(str) + 1, cname); if (cpy) - strcpy(cpy, str); + strcpy(cpy, str); return cpy; } @@ -74,38 +74,38 @@ xps_clean_path(char *name) p = q = dotdot = name + rooted; while (*p) { - if(p[0] == '/') /* null element */ - p++; - else if (p[0] == '.' && SEP(p[1])) - p += 1; /* don't count the separator in case it is nul */ - else if (p[0] == '.' && p[1] == '.' && SEP(p[2])) - { - p += 2; - if (q > dotdot) /* can backtrack */ - { - while(--q > dotdot && *q != '/') - ; - } - else if (!rooted) /* /.. is / but ./../ is .. */ - { - if (q != name) - *q++ = '/'; - *q++ = '.'; - *q++ = '.'; - dotdot = q; - } - } - else /* real path element */ - { - if (q != name+rooted) - *q++ = '/'; - while ((*q = *p) != '/' && *q != 0) - p++, q++; - } + if(p[0] == '/') /* null element */ + p++; + else if (p[0] == '.' && SEP(p[1])) + p += 1; /* don't count the separator in case it is nul */ + else if (p[0] == '.' && p[1] == '.' && SEP(p[2])) + { + p += 2; + if (q > dotdot) /* can backtrack */ + { + while(--q > dotdot && *q != '/') + ; + } + else if (!rooted) /* /.. is / but ./../ is .. */ + { + if (q != name) + *q++ = '/'; + *q++ = '.'; + *q++ = '.'; + dotdot = q; + } + } + else /* real path element */ + { + if (q != name+rooted) + *q++ = '/'; + while ((*q = *p) != '/' && *q != 0) + p++, q++; + } } if (q == name) /* empty string is really "." */ - *q++ = '.'; + *q++ = '.'; *q = '\0'; return name; @@ -116,13 +116,13 @@ xps_absolute_path(char *output, char *base_uri, char *path) { if (path[0] == '/') { - strcpy(output, path); + strcpy(output, path); } else { - strcpy(output, base_uri); - strcat(output, "/"); - strcat(output, path); + strcpy(output, base_uri); + strcat(output, "/"); + strcat(output, path); } xps_clean_path(output); } diff --git a/xps/xpsopacity.c b/xps/xpsopacity.c index 6390a034b..1156320f9 100644 --- a/xps/xpsopacity.c +++ b/xps/xpsopacity.c @@ -17,7 +17,7 @@ int xps_begin_opacity(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, - char *opacity_att, xps_item_t *opacity_mask_tag) + char *opacity_att, xps_item_t *opacity_mask_tag) { gs_transparency_group_params_t tgp; gs_transparency_mask_params_t tmp; @@ -26,44 +26,44 @@ xps_begin_opacity(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, int save; if (!opacity_att && !opacity_mask_tag) - return 0; + return 0; opacity = 1.0; if (opacity_att) - opacity = atof(opacity_att); + opacity = atof(opacity_att); gs_setopacityalpha(ctx->pgs, opacity); xps_bounds_in_user_space(ctx, &bbox); if (opacity_mask_tag) { - gs_trans_mask_params_init(&tmp, TRANSPARENCY_MASK_Luminosity); - gs_begin_transparency_mask(ctx->pgs, &tmp, &bbox, 0); + gs_trans_mask_params_init(&tmp, TRANSPARENCY_MASK_Luminosity); + gs_begin_transparency_mask(ctx->pgs, &tmp, &bbox, 0); - gs_gsave(ctx->pgs); + gs_gsave(ctx->pgs); - /* Need a path to fill/clip for the brush */ - gs_moveto(ctx->pgs, bbox.p.x, bbox.p.y); - gs_lineto(ctx->pgs, bbox.p.x, bbox.q.y); - gs_lineto(ctx->pgs, bbox.q.x, bbox.q.y); - gs_lineto(ctx->pgs, bbox.q.x, bbox.p.y); - gs_closepath(ctx->pgs); + /* Need a path to fill/clip for the brush */ + gs_moveto(ctx->pgs, bbox.p.x, bbox.p.y); + gs_lineto(ctx->pgs, bbox.p.x, bbox.q.y); + gs_lineto(ctx->pgs, bbox.q.x, bbox.q.y); + gs_lineto(ctx->pgs, bbox.q.x, bbox.p.y); + gs_closepath(ctx->pgs); - // gs_setopacityalpha(ctx->pgs, 0.5); - // gs_setrgbcolor(ctx->pgs, 1, 1, 1); - // gs_fill(ctx->pgs); + // gs_setopacityalpha(ctx->pgs, 0.5); + // gs_setrgbcolor(ctx->pgs, 1, 1, 1); + // gs_fill(ctx->pgs); - /* opacity-only mode: use alpha value as gray color to create luminosity mask */ - save = ctx->opacity_only; - ctx->opacity_only = 1; + /* opacity-only mode: use alpha value as gray color to create luminosity mask */ + save = ctx->opacity_only; + ctx->opacity_only = 1; - xps_parse_brush(ctx, base_uri, dict, opacity_mask_tag); + xps_parse_brush(ctx, base_uri, dict, opacity_mask_tag); - gs_grestore(ctx->pgs); + gs_grestore(ctx->pgs); - ctx->opacity_only = save; + ctx->opacity_only = save; - gs_end_transparency_mask(ctx->pgs, TRANSPARENCY_CHANNEL_Opacity); + gs_end_transparency_mask(ctx->pgs, TRANSPARENCY_CHANNEL_Opacity); } gs_trans_group_params_init(&tgp); @@ -75,10 +75,10 @@ xps_begin_opacity(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, int xps_end_opacity(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, - char *opacity_att, xps_item_t *opacity_mask_tag) + char *opacity_att, xps_item_t *opacity_mask_tag) { if (!opacity_att && !opacity_mask_tag) - return 0; + return 0; gs_end_transparency_group(ctx->pgs); diff --git a/xps/xpspage.c b/xps/xpspage.c index 87f863e65..02b066ca0 100644 --- a/xps/xpspage.c +++ b/xps/xpspage.c @@ -41,22 +41,22 @@ int xps_parse_canvas(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, x for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "Canvas.Resources") && xps_down(node)) - { - new_dict = xps_parse_resource_dictionary(ctx, base_uri, xps_down(node)); - if (new_dict) - { - new_dict->parent = dict; - dict = new_dict; - } - } - - if (!strcmp(xps_tag(node), "Canvas.RenderTransform")) - transform_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Canvas.Clip")) - clip_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Canvas.OpacityMask")) - opacity_mask_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Canvas.Resources") && xps_down(node)) + { + new_dict = xps_parse_resource_dictionary(ctx, base_uri, xps_down(node)); + if (new_dict) + { + new_dict->parent = dict; + dict = new_dict; + } + } + + if (!strcmp(xps_tag(node), "Canvas.RenderTransform")) + transform_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Canvas.Clip")) + clip_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Canvas.OpacityMask")) + opacity_mask_tag = xps_down(node); } opacity_mask_uri = base_uri; @@ -68,30 +68,30 @@ int xps_parse_canvas(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, x gs_make_identity(&transform); if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); + xps_parse_render_transform(ctx, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + xps_parse_matrix_transform(ctx, transform_tag, &transform); gs_concat(ctx->pgs, &transform); if (clip_att || clip_tag) { - if (clip_att) - xps_parse_abbreviated_geometry(ctx, clip_att); - if (clip_tag) - xps_parse_path_geometry(ctx, dict, clip_tag, 0); - xps_clip(ctx, &saved_bounds); + if (clip_att) + xps_parse_abbreviated_geometry(ctx, clip_att); + if (clip_tag) + xps_parse_path_geometry(ctx, dict, clip_tag, 0); + xps_clip(ctx, &saved_bounds); } xps_begin_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); for (node = xps_down(root); node; node = xps_next(node)) { - xps_parse_element(ctx, base_uri, dict, node); + xps_parse_element(ctx, base_uri, dict, node); } if (clip_att || clip_tag) { - xps_restore_bounds(ctx, &saved_bounds); + xps_restore_bounds(ctx, &saved_bounds); } xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); @@ -100,7 +100,7 @@ int xps_parse_canvas(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, x if (new_dict) { - xps_free_resource_dictionary(ctx, new_dict); + xps_free_resource_dictionary(ctx, new_dict); } return 0; @@ -121,81 +121,81 @@ xps_parse_fixed_page(xps_context_t *ctx, xps_part_t *part) char *s; if (xps_doc_trace) - dprintf1("doc: parsing page %s\n", part->name); + dprintf1("doc: parsing page %s\n", part->name); strcpy(base_uri, part->name); s = strrchr(base_uri, '/'); if (s) - s[1] = 0; + s[1] = 0; root = xps_parse_xml(ctx, part->data, part->size); if (!root) - return gs_rethrow(-1, "cannot parse xml"); + return gs_rethrow(-1, "cannot parse xml"); if (strcmp(xps_tag(root), "FixedPage")) - return gs_throw1(-1, "expected FixedPage element (found %s)", xps_tag(root)); + return gs_throw1(-1, "expected FixedPage element (found %s)", xps_tag(root)); width_att = xps_att(root, "Width"); height_att = xps_att(root, "Height"); if (!width_att) - return gs_throw(-1, "FixedPage missing required attribute: Width"); + return gs_throw(-1, "FixedPage missing required attribute: Width"); if (!height_att) - return gs_throw(-1, "FixedPage missing required attribute: Height"); + return gs_throw(-1, "FixedPage missing required attribute: Height"); dict = NULL; /* Setup new page */ { - gs_memory_t *mem = ctx->memory; - gs_state *pgs = ctx->pgs; - gx_device *dev = gs_currentdevice(pgs); - gs_param_float_array fa; - float fv[2]; - gs_c_param_list list; - - gs_c_param_list_write(&list, mem); - - fv[0] = atoi(width_att) / 96.0 * 72.0; - fv[1] = atoi(height_att) / 96.0 * 72.0; - fa.persistent = false; - fa.data = fv; - fa.size = 2; - - code = param_write_float_array((gs_param_list *)&list, ".MediaSize", &fa); - if ( code >= 0 ) - { - gs_c_param_list_read(&list); - code = gs_putdeviceparams(dev, (gs_param_list *)&list); - } - gs_c_param_list_release(&list); - - /* nb this is for the demo it is wrong and should be removed */ - gs_initgraphics(pgs); - - /* 96 dpi default - and put the origin at the top of the page */ - - gs_initmatrix(pgs); - - code = gs_scale(pgs, 72.0/96.0, -72.0/96.0); - if (code < 0) - return gs_rethrow(code, "cannot set page transform"); - - code = gs_translate(pgs, 0.0, -atoi(height_att)); - if (code < 0) - return gs_rethrow(code, "cannot set page transform"); - - code = gs_erasepage(pgs); - if (code < 0) - return gs_rethrow(code, "cannot clear page"); - - /* set initial bounds to cover the page */ - gs_currentmatrix(pgs, &ctm); - gs_point_transform(0.0, 0.0, &ctm, &rc.p); - gs_point_transform(atoi(width_att), atoi(height_att), &ctm, &rc.q); - if (rc.p.x > rc.q.x) { float t = rc.p.x; rc.p.x = rc.q.x; rc.q.x = t; } - if (rc.p.y > rc.q.y) { float t = rc.p.y; rc.p.y = rc.q.y; rc.q.y = t; } - ctx->bounds = rc; + gs_memory_t *mem = ctx->memory; + gs_state *pgs = ctx->pgs; + gx_device *dev = gs_currentdevice(pgs); + gs_param_float_array fa; + float fv[2]; + gs_c_param_list list; + + gs_c_param_list_write(&list, mem); + + fv[0] = atoi(width_att) / 96.0 * 72.0; + fv[1] = atoi(height_att) / 96.0 * 72.0; + fa.persistent = false; + fa.data = fv; + fa.size = 2; + + code = param_write_float_array((gs_param_list *)&list, ".MediaSize", &fa); + if ( code >= 0 ) + { + gs_c_param_list_read(&list); + code = gs_putdeviceparams(dev, (gs_param_list *)&list); + } + gs_c_param_list_release(&list); + + /* nb this is for the demo it is wrong and should be removed */ + gs_initgraphics(pgs); + + /* 96 dpi default - and put the origin at the top of the page */ + + gs_initmatrix(pgs); + + code = gs_scale(pgs, 72.0/96.0, -72.0/96.0); + if (code < 0) + return gs_rethrow(code, "cannot set page transform"); + + code = gs_translate(pgs, 0.0, -atoi(height_att)); + if (code < 0) + return gs_rethrow(code, "cannot set page transform"); + + code = gs_erasepage(pgs); + if (code < 0) + return gs_rethrow(code, "cannot clear page"); + + /* set initial bounds to cover the page */ + gs_currentmatrix(pgs, &ctm); + gs_point_transform(0.0, 0.0, &ctm, &rc.p); + gs_point_transform(atoi(width_att), atoi(height_att), &ctm, &rc.q); + if (rc.p.x > rc.q.x) { float t = rc.p.x; rc.p.x = rc.q.x; rc.q.x = t; } + if (rc.p.y > rc.q.y) { float t = rc.p.y; rc.p.y = rc.q.y; rc.q.y = t; } + ctx->bounds = rc; } /* Pre-parse looking for transparency */ @@ -204,11 +204,11 @@ xps_parse_fixed_page(xps_context_t *ctx, xps_part_t *part) for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "FixedPage.Resources") && xps_down(node)) - if (xps_resource_dictionary_has_transparency(ctx, base_uri, xps_down(node))) - has_transparency = 1; - if (xps_element_has_transparency(ctx, base_uri, node)) - has_transparency = 1; + if (!strcmp(xps_tag(node), "FixedPage.Resources") && xps_down(node)) + if (xps_resource_dictionary_has_transparency(ctx, base_uri, xps_down(node))) + has_transparency = 1; + if (xps_element_has_transparency(ctx, base_uri, node)) + has_transparency = 1; } /* save the state with the original device before we push */ @@ -216,32 +216,32 @@ xps_parse_fixed_page(xps_context_t *ctx, xps_part_t *part) if (ctx->use_transparency && has_transparency) { - code = gs_push_pdf14trans_device(ctx->pgs); - if (code < 0) - return gs_rethrow(code, "cannot install transparency device"); + code = gs_push_pdf14trans_device(ctx->pgs); + if (code < 0) + return gs_rethrow(code, "cannot install transparency device"); } /* Draw contents */ for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "FixedPage.Resources") && xps_down(node)) - dict = xps_parse_resource_dictionary(ctx, base_uri, xps_down(node)); - xps_parse_element(ctx, base_uri, dict, node); + if (!strcmp(xps_tag(node), "FixedPage.Resources") && xps_down(node)) + dict = xps_parse_resource_dictionary(ctx, base_uri, xps_down(node)); + xps_parse_element(ctx, base_uri, dict, node); } if (ctx->use_transparency && has_transparency) { - code = gs_pop_pdf14trans_device(ctx->pgs); - if (code < 0) - return gs_rethrow(code, "cannot uninstall transparency device"); + code = gs_pop_pdf14trans_device(ctx->pgs); + if (code < 0) + return gs_rethrow(code, "cannot uninstall transparency device"); } /* Flush page */ { - code = xps_show_page(ctx, 1, true); /* copies, flush */ - if (code < 0) - return gs_rethrow(code, "cannot flush page"); + code = xps_show_page(ctx, 1, true); /* copies, flush */ + if (code < 0) + return gs_rethrow(code, "cannot flush page"); } /* restore the original device, discarding the pdf14 compositor */ @@ -249,7 +249,7 @@ xps_parse_fixed_page(xps_context_t *ctx, xps_part_t *part) if (dict) { - xps_free_resource_dictionary(ctx, dict); + xps_free_resource_dictionary(ctx, dict); } xps_free_item(ctx, root); diff --git a/xps/xpspath.c b/xps/xpspath.c index 073433d72..4ce974f54 100644 --- a/xps/xpspath.c +++ b/xps/xpspath.c @@ -34,7 +34,7 @@ xps_bounds_in_user_space(xps_context_t *ctx, gs_rect *user) gs_currentmatrix(ctx->pgs, &ctm); gs_matrix_invert(&ctm, &inv); - + bbox = ctx->bounds; gs_point_transform(bbox.p.x, bbox.p.y, &inv, &a); gs_point_transform(bbox.p.x, bbox.q.y, &inv, &b); @@ -62,40 +62,40 @@ xps_update_bounds(xps_context_t *ctx, gs_rect *save) /* get bounds of current path (that is about to be clipped) */ /* the coordinates of the path segments are already in device space (yay!) */ if (!ctx->pgs->path) - return; + return; seg = (segment*)ctx->pgs->path->first_subpath; if (seg) { - rc.p.x = rc.q.x = fixed2float(seg->pt.x); - rc.p.y = rc.q.y = fixed2float(seg->pt.y); + rc.p.x = rc.q.x = fixed2float(seg->pt.x); + rc.p.y = rc.q.y = fixed2float(seg->pt.y); } else { - rc.p.x = rc.q.x = 0.0; - rc.p.y = rc.q.y = 0.0; + rc.p.x = rc.q.x = 0.0; + rc.p.y = rc.q.y = 0.0; } while (seg) { - switch (seg->type) - { - case s_start: - xps_grow_rect(&rc, fixed2float(seg->pt.x), fixed2float(seg->pt.y)); - break; - case s_line: - xps_grow_rect(&rc, fixed2float(seg->pt.x), fixed2float(seg->pt.y)); - break; - case s_line_close: - break; - case s_curve: - cseg = (curve_segment*)seg; - xps_grow_rect(&rc, fixed2float(cseg->p1.x), fixed2float(cseg->p1.y)); - xps_grow_rect(&rc, fixed2float(cseg->p2.x), fixed2float(cseg->p2.y)); - xps_grow_rect(&rc, fixed2float(seg->pt.x), fixed2float(seg->pt.y)); - break; - } - seg = seg->next; + switch (seg->type) + { + case s_start: + xps_grow_rect(&rc, fixed2float(seg->pt.x), fixed2float(seg->pt.y)); + break; + case s_line: + xps_grow_rect(&rc, fixed2float(seg->pt.x), fixed2float(seg->pt.y)); + break; + case s_line_close: + break; + case s_curve: + cseg = (curve_segment*)seg; + xps_grow_rect(&rc, fixed2float(cseg->p1.x), fixed2float(cseg->p1.y)); + xps_grow_rect(&rc, fixed2float(cseg->p2.x), fixed2float(cseg->p2.y)); + xps_grow_rect(&rc, fixed2float(seg->pt.x), fixed2float(seg->pt.y)); + break; + } + seg = seg->next; } /* intersect with old bounds, and fix degenerate case */ @@ -103,9 +103,9 @@ xps_update_bounds(xps_context_t *ctx, gs_rect *save) rect_intersect(ctx->bounds, rc); if (ctx->bounds.q.x < ctx->bounds.p.x) - ctx->bounds.q.x = ctx->bounds.p.x; + ctx->bounds.q.x = ctx->bounds.p.x; if (ctx->bounds.q.y < ctx->bounds.p.y) - ctx->bounds.q.y = ctx->bounds.p.y; + ctx->bounds.q.y = ctx->bounds.p.y; } void @@ -126,10 +126,10 @@ xps_debug_bounds(xps_context_t *ctx) gs_gsave(ctx->pgs); dprintf6("bounds: debug [%g %g %g %g] w=%g h=%g\n", - ctx->bounds.p.x, ctx->bounds.p.y, - ctx->bounds.q.x, ctx->bounds.q.y, - ctx->bounds.q.x - ctx->bounds.p.x, - ctx->bounds.q.y - ctx->bounds.p.y); + ctx->bounds.p.x, ctx->bounds.p.y, + ctx->bounds.q.x, ctx->bounds.q.y, + ctx->bounds.q.x - ctx->bounds.p.x, + ctx->bounds.q.y - ctx->bounds.p.y); gs_make_identity(&mat); gs_setmatrix(ctx->pgs, &mat); @@ -158,9 +158,9 @@ xps_clip(xps_context_t *ctx, gs_rect *saved_bounds) xps_update_bounds(ctx, saved_bounds); if (ctx->fill_rule == 0) - gs_eoclip(ctx->pgs); + gs_eoclip(ctx->pgs); else - gs_clip(ctx->pgs); + gs_clip(ctx->pgs); gs_newpath(ctx->pgs); } @@ -169,11 +169,11 @@ void xps_fill(xps_context_t *ctx) { if (gs_currentopacityalpha(ctx->pgs) < 0.001) - gs_newpath(ctx->pgs); + gs_newpath(ctx->pgs); else if (ctx->fill_rule == 0) - gs_eofill(ctx->pgs); + gs_eofill(ctx->pgs); else - gs_fill(ctx->pgs); + gs_fill(ctx->pgs); } @@ -189,34 +189,34 @@ xps_draw_arc_segment(xps_context_t *ctx, gs_matrix *mtx, float th0, float th1, i gs_point p; while (th1 < th0) - th1 += M_PI * 2.0; + th1 += M_PI * 2.0; d = 1 * (M_PI / 180.0); /* 1-degree precision */ if (iscw) { - gs_point_transform(cos(th0), sin(th0), mtx, &p); - gs_lineto(ctx->pgs, p.x, p.y); - for (t = th0; t < th1; t += d) - { - gs_point_transform(cos(t), sin(t), mtx, &p); - gs_lineto(ctx->pgs, p.x, p.y); - } - gs_point_transform(cos(th1), sin(th1), mtx, &p); - gs_lineto(ctx->pgs, p.x, p.y); + gs_point_transform(cos(th0), sin(th0), mtx, &p); + gs_lineto(ctx->pgs, p.x, p.y); + for (t = th0; t < th1; t += d) + { + gs_point_transform(cos(t), sin(t), mtx, &p); + gs_lineto(ctx->pgs, p.x, p.y); + } + gs_point_transform(cos(th1), sin(th1), mtx, &p); + gs_lineto(ctx->pgs, p.x, p.y); } else { - th0 += M_PI * 2; - gs_point_transform(cos(th0), sin(th0), mtx, &p); - gs_lineto(ctx->pgs, p.x, p.y); - for (t = th0; t > th1; t -= d) - { - gs_point_transform(cos(t), sin(t), mtx, &p); - gs_lineto(ctx->pgs, p.x, p.y); - } - gs_point_transform(cos(th1), sin(th1), mtx, &p); - gs_lineto(ctx->pgs, p.x, p.y); + th0 += M_PI * 2; + gs_point_transform(cos(th0), sin(th0), mtx, &p); + gs_lineto(ctx->pgs, p.x, p.y); + for (t = th0; t > th1; t -= d) + { + gs_point_transform(cos(t), sin(t), mtx, &p); + gs_lineto(ctx->pgs, p.x, p.y); + } + gs_point_transform(cos(th1), sin(th1), mtx, &p); + gs_lineto(ctx->pgs, p.x, p.y); } } @@ -238,9 +238,9 @@ angle_between(const gs_point u, const gs_point v) static int xps_draw_arc(xps_context_t *ctx, - float size_x, float size_y, float rotation_angle, - int is_large_arc, int is_clockwise, - float point_x, float point_y) + float size_x, float size_y, float rotation_angle, + int is_large_arc, int is_clockwise, + float point_x, float point_y) { gs_matrix rotmat, revmat; gs_matrix mtx; @@ -262,9 +262,9 @@ xps_draw_arc(xps_context_t *ctx, ry = size_y; if (is_clockwise != is_large_arc) - sign = 1; + sign = 1; else - sign = -1; + sign = -1; gs_make_rotation(rotation_angle, &rotmat); gs_make_rotation(-rotation_angle, &revmat); @@ -277,8 +277,8 @@ xps_draw_arc(xps_context_t *ctx, ry = fabs(ry); if (rx < 0.001 || ry < 0.001) { - gs_lineto(ctx->pgs, x2, y2); - return 0; + gs_lineto(ctx->pgs, x2, y2); + return 0; } /* F.6.5.1 */ @@ -290,8 +290,8 @@ xps_draw_arc(xps_context_t *ctx, t1 = (x1t * x1t) / (rx * rx) + (y1t * y1t) / (ry * ry); if (t1 > 1.0) { - rx = rx * sqrt(t1); - ry = ry * sqrt(t1); + rx = rx * sqrt(t1); + ry = ry * sqrt(t1); } /* F.6.5.2 */ @@ -312,21 +312,21 @@ xps_draw_arc(xps_context_t *ctx, /* F.6.5.4 */ { - gs_point coord1, coord2, coord3, coord4; - coord1.x = 1; - coord1.y = 0; - coord2.x = (x1t - cxt) / rx; - coord2.y = (y1t - cyt) / ry; - coord3.x = (x1t - cxt) / rx; - coord3.y = (y1t - cyt) / ry; - coord4.x = (-x1t - cxt) / rx; - coord4.y = (-y1t - cyt) / ry; - th1 = angle_between(coord1, coord2); - dth = angle_between(coord3, coord4); - if (dth < 0 && !is_clockwise) - dth += (degrees_to_radians * 360); - if (dth > 0 && is_clockwise) - dth -= (degrees_to_radians * 360); + gs_point coord1, coord2, coord3, coord4; + coord1.x = 1; + coord1.y = 0; + coord2.x = (x1t - cxt) / rx; + coord2.y = (y1t - cyt) / ry; + coord3.x = (x1t - cxt) / rx; + coord3.y = (y1t - cyt) / ry; + coord4.x = (-x1t - cxt) / rx; + coord4.y = (-y1t - cyt) / ry; + th1 = angle_between(coord1, coord2); + dth = angle_between(coord3, coord4); + if (dth < 0 && !is_clockwise) + dth += (degrees_to_radians * 360); + if (dth > 0 && is_clockwise) + dth -= (degrees_to_radians * 360); } gs_make_identity(&mtx); @@ -368,20 +368,20 @@ xps_parse_abbreviated_geometry(xps_context_t *ctx, char *geom) while (*s) { - if ((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z')) - { - *pargs++ = s++; - } - else if ((*s >= '0' && *s <= '9') || *s == '.' || *s == '+' || *s == '-' || *s == 'e' || *s == 'E') - { - *pargs++ = s; - while ((*s >= '0' && *s <= '9') || *s == '.' || *s == '+' || *s == '-' || *s == 'e' || *s == 'E') - s ++; - } - else - { - s++; - } + if ((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z')) + { + *pargs++ = s++; + } + else if ((*s >= '0' && *s <= '9') || *s == '.' || *s == '+' || *s == '-' || *s == 'e' || *s == 'E') + { + *pargs++ = s; + while ((*s >= '0' && *s <= '9') || *s == '.' || *s == '+' || *s == '-' || *s == 'e' || *s == 'E') + s ++; + } + else + { + s++; + } } pargs[0] = s; @@ -398,185 +398,185 @@ xps_parse_abbreviated_geometry(xps_context_t *ctx, char *geom) while (i < n) { - cmd = args[i][0]; - if (cmd == '+' || cmd == '.' || cmd == '-' || (cmd >= '0' && cmd <= '9')) - cmd = old; /* it's a number, repeat old command */ - else - i ++; - - if (reset_smooth) - { - smooth_x = 0.0; - smooth_y = 0.0; - } - - reset_smooth = 1; - - switch (cmd) - { - case 'F': - ctx->fill_rule = atoi(args[i]); - i ++; - break; - - case 'M': - gs_moveto(ctx->pgs, atof(args[i]), atof(args[i+1])); - //dprintf2("moveto %g %g\n", atof(args[i]), atof(args[i+1])); - i += 2; - break; - case 'm': - gs_rmoveto(ctx->pgs, atof(args[i]), atof(args[i+1])); - //dprintf2("rmoveto %g %g\n", atof(args[i]), atof(args[i+1])); - i += 2; - break; - - case 'L': - gs_lineto(ctx->pgs, atof(args[i]), atof(args[i+1])); - //dprintf2("lineto %g %g\n", atof(args[i]), atof(args[i+1])); - i += 2; - break; - case 'l': - gs_rlineto(ctx->pgs, atof(args[i]), atof(args[i+1])); - //dprintf2("rlineto %g %g\n", atof(args[i]), atof(args[i+1])); - i += 2; - break; - - case 'H': - gs_currentpoint(ctx->pgs, &pt); - gs_lineto(ctx->pgs, atof(args[i]), pt.y); - //dprintf1("hlineto %g\n", atof(args[i])); - i += 1; - break; - case 'h': - gs_rlineto(ctx->pgs, atof(args[i]), 0.0); - //dprintf1("rhlineto %g\n", atof(args[i])); - i += 1; - break; - - case 'V': - gs_currentpoint(ctx->pgs, &pt); - gs_lineto(ctx->pgs, pt.x, atof(args[i])); - //dprintf1("vlineto %g\n", atof(args[i])); - i += 1; - break; - case 'v': - gs_rlineto(ctx->pgs, 0.0, atof(args[i])); - //dprintf1("rvlineto %g\n", atof(args[i])); - i += 1; - break; - - case 'C': - x1 = atof(args[i+0]); - y1 = atof(args[i+1]); - x2 = atof(args[i+2]); - y2 = atof(args[i+3]); - x3 = atof(args[i+4]); - y3 = atof(args[i+5]); - gs_curveto(ctx->pgs, x1, y1, x2, y2, x3, y3); - i += 6; - reset_smooth = 0; - smooth_x = x3 - x2; - smooth_y = y3 - y2; - break; - - case 'c': - gs_currentpoint(ctx->pgs, &pt); - x1 = atof(args[i+0]) + pt.x; - y1 = atof(args[i+1]) + pt.y; - x2 = atof(args[i+2]) + pt.x; - y2 = atof(args[i+3]) + pt.y; - x3 = atof(args[i+4]) + pt.x; - y3 = atof(args[i+5]) + pt.y; - gs_curveto(ctx->pgs, x1, y1, x2, y2, x3, y3); - i += 6; - reset_smooth = 0; - smooth_x = x3 - x2; - smooth_y = y3 - y2; - break; - - case 'S': - gs_currentpoint(ctx->pgs, &pt); - x1 = atof(args[i+0]); - y1 = atof(args[i+1]); - x2 = atof(args[i+2]); - y2 = atof(args[i+3]); - //dprintf2("smooth %g %g\n", smooth_x, smooth_y); - gs_curveto(ctx->pgs, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2); - i += 4; - reset_smooth = 0; - smooth_x = x2 - x1; - smooth_y = y2 - y1; - break; - - case 's': - gs_currentpoint(ctx->pgs, &pt); - x1 = atof(args[i+0]) + pt.x; - y1 = atof(args[i+1]) + pt.y; - x2 = atof(args[i+2]) + pt.x; - y2 = atof(args[i+3]) + pt.y; - //dprintf2("smooth %g %g\n", smooth_x, smooth_y); - gs_curveto(ctx->pgs, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2); - i += 4; - reset_smooth = 0; - smooth_x = x2 - x1; - smooth_y = y2 - y1; - break; - - case 'Q': - gs_currentpoint(ctx->pgs, &pt); - x1 = atof(args[i+0]); - y1 = atof(args[i+1]); - x2 = atof(args[i+2]); - y2 = atof(args[i+3]); - //dprintf4("conicto %g %g %g %g\n", x1, y1, x2, y2); - gs_curveto(ctx->pgs, - (pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3, - (x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3, - x2, y2); - i += 4; - break; - case 'q': - gs_currentpoint(ctx->pgs, &pt); - x1 = atof(args[i+0]) + pt.x; - y1 = atof(args[i+1]) + pt.y; - x2 = atof(args[i+2]) + pt.x; - y2 = atof(args[i+3]) + pt.y; - //dprintf4("conicto %g %g %g %g\n", x1, y1, x2, y2); - gs_curveto(ctx->pgs, - (pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3, - (x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3, - x2, y2); - i += 4; - break; - - case 'A': - xps_draw_arc(ctx, - atof(args[i+0]), atof(args[i+1]), atof(args[i+2]), - atoi(args[i+3]), atoi(args[i+4]), - atof(args[i+5]), atof(args[i+6])); - i += 7; - break; - case 'a': - gs_currentpoint(ctx->pgs, &pt); - xps_draw_arc(ctx, - atof(args[i+0]), atof(args[i+1]), atof(args[i+2]), - atoi(args[i+3]), atoi(args[i+4]), - atof(args[i+5]) + pt.x, atof(args[i+6]) + pt.y); - i += 7; - break; - - case 'Z': - case 'z': - gs_closepath(ctx->pgs); - //dputs("closepath\n"); - break; - - default: - /* eek */ - break; - } - - old = cmd; + cmd = args[i][0]; + if (cmd == '+' || cmd == '.' || cmd == '-' || (cmd >= '0' && cmd <= '9')) + cmd = old; /* it's a number, repeat old command */ + else + i ++; + + if (reset_smooth) + { + smooth_x = 0.0; + smooth_y = 0.0; + } + + reset_smooth = 1; + + switch (cmd) + { + case 'F': + ctx->fill_rule = atoi(args[i]); + i ++; + break; + + case 'M': + gs_moveto(ctx->pgs, atof(args[i]), atof(args[i+1])); + //dprintf2("moveto %g %g\n", atof(args[i]), atof(args[i+1])); + i += 2; + break; + case 'm': + gs_rmoveto(ctx->pgs, atof(args[i]), atof(args[i+1])); + //dprintf2("rmoveto %g %g\n", atof(args[i]), atof(args[i+1])); + i += 2; + break; + + case 'L': + gs_lineto(ctx->pgs, atof(args[i]), atof(args[i+1])); + //dprintf2("lineto %g %g\n", atof(args[i]), atof(args[i+1])); + i += 2; + break; + case 'l': + gs_rlineto(ctx->pgs, atof(args[i]), atof(args[i+1])); + //dprintf2("rlineto %g %g\n", atof(args[i]), atof(args[i+1])); + i += 2; + break; + + case 'H': + gs_currentpoint(ctx->pgs, &pt); + gs_lineto(ctx->pgs, atof(args[i]), pt.y); + //dprintf1("hlineto %g\n", atof(args[i])); + i += 1; + break; + case 'h': + gs_rlineto(ctx->pgs, atof(args[i]), 0.0); + //dprintf1("rhlineto %g\n", atof(args[i])); + i += 1; + break; + + case 'V': + gs_currentpoint(ctx->pgs, &pt); + gs_lineto(ctx->pgs, pt.x, atof(args[i])); + //dprintf1("vlineto %g\n", atof(args[i])); + i += 1; + break; + case 'v': + gs_rlineto(ctx->pgs, 0.0, atof(args[i])); + //dprintf1("rvlineto %g\n", atof(args[i])); + i += 1; + break; + + case 'C': + x1 = atof(args[i+0]); + y1 = atof(args[i+1]); + x2 = atof(args[i+2]); + y2 = atof(args[i+3]); + x3 = atof(args[i+4]); + y3 = atof(args[i+5]); + gs_curveto(ctx->pgs, x1, y1, x2, y2, x3, y3); + i += 6; + reset_smooth = 0; + smooth_x = x3 - x2; + smooth_y = y3 - y2; + break; + + case 'c': + gs_currentpoint(ctx->pgs, &pt); + x1 = atof(args[i+0]) + pt.x; + y1 = atof(args[i+1]) + pt.y; + x2 = atof(args[i+2]) + pt.x; + y2 = atof(args[i+3]) + pt.y; + x3 = atof(args[i+4]) + pt.x; + y3 = atof(args[i+5]) + pt.y; + gs_curveto(ctx->pgs, x1, y1, x2, y2, x3, y3); + i += 6; + reset_smooth = 0; + smooth_x = x3 - x2; + smooth_y = y3 - y2; + break; + + case 'S': + gs_currentpoint(ctx->pgs, &pt); + x1 = atof(args[i+0]); + y1 = atof(args[i+1]); + x2 = atof(args[i+2]); + y2 = atof(args[i+3]); + //dprintf2("smooth %g %g\n", smooth_x, smooth_y); + gs_curveto(ctx->pgs, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2); + i += 4; + reset_smooth = 0; + smooth_x = x2 - x1; + smooth_y = y2 - y1; + break; + + case 's': + gs_currentpoint(ctx->pgs, &pt); + x1 = atof(args[i+0]) + pt.x; + y1 = atof(args[i+1]) + pt.y; + x2 = atof(args[i+2]) + pt.x; + y2 = atof(args[i+3]) + pt.y; + //dprintf2("smooth %g %g\n", smooth_x, smooth_y); + gs_curveto(ctx->pgs, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2); + i += 4; + reset_smooth = 0; + smooth_x = x2 - x1; + smooth_y = y2 - y1; + break; + + case 'Q': + gs_currentpoint(ctx->pgs, &pt); + x1 = atof(args[i+0]); + y1 = atof(args[i+1]); + x2 = atof(args[i+2]); + y2 = atof(args[i+3]); + //dprintf4("conicto %g %g %g %g\n", x1, y1, x2, y2); + gs_curveto(ctx->pgs, + (pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3, + (x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3, + x2, y2); + i += 4; + break; + case 'q': + gs_currentpoint(ctx->pgs, &pt); + x1 = atof(args[i+0]) + pt.x; + y1 = atof(args[i+1]) + pt.y; + x2 = atof(args[i+2]) + pt.x; + y2 = atof(args[i+3]) + pt.y; + //dprintf4("conicto %g %g %g %g\n", x1, y1, x2, y2); + gs_curveto(ctx->pgs, + (pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3, + (x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3, + x2, y2); + i += 4; + break; + + case 'A': + xps_draw_arc(ctx, + atof(args[i+0]), atof(args[i+1]), atof(args[i+2]), + atoi(args[i+3]), atoi(args[i+4]), + atof(args[i+5]), atof(args[i+6])); + i += 7; + break; + case 'a': + gs_currentpoint(ctx->pgs, &pt); + xps_draw_arc(ctx, + atof(args[i+0]), atof(args[i+1]), atof(args[i+2]), + atoi(args[i+3]), atoi(args[i+4]), + atof(args[i+5]) + pt.x, atof(args[i+6]) + pt.y); + i += 7; + break; + + case 'Z': + case 'z': + gs_closepath(ctx->pgs); + //dputs("closepath\n"); + break; + + default: + /* eek */ + break; + } + + old = cmd; } xps_free(ctx, args); @@ -607,13 +607,13 @@ xps_parse_arc_segment(xps_context_t *ctx, xps_item_t *root, int stroking, int *s char *is_stroked_att = xps_att(root, "IsStroked"); if (!point_att || !size_att || !rotation_angle_att || !is_large_arc_att || !sweep_direction_att) - return gs_throw(-1, "ArcSegment element is missing attributes"); + return gs_throw(-1, "ArcSegment element is missing attributes"); is_stroked = 1; if (is_stroked_att && !strcmp(is_stroked_att, "false")) - is_stroked = 0; + is_stroked = 0; if (!is_stroked) - *skipped_stroke = 1; + *skipped_stroke = 1; sscanf(point_att, "%g,%g", &point_x, &point_y); sscanf(size_att, "%g,%g", &size_x, &size_y); @@ -623,12 +623,12 @@ xps_parse_arc_segment(xps_context_t *ctx, xps_item_t *root, int stroking, int *s if (stroking && !is_stroked) { - gs_moveto(ctx->pgs, point_x, point_y); - return 0; + gs_moveto(ctx->pgs, point_x, point_y); + return 0; } return xps_draw_arc(ctx, size_x, size_y, rotation_angle, - is_large_arc, is_clockwise, point_x, point_y); + is_large_arc, is_clockwise, point_x, point_y); } static int @@ -643,38 +643,38 @@ xps_parse_poly_quadratic_bezier_segment(xps_context_t *ctx, xps_item_t *root, in int n; if (!points_att) - return gs_throw(-1, "PolyQuadraticBezierSegment element has no points"); + return gs_throw(-1, "PolyQuadraticBezierSegment element has no points"); is_stroked = 1; if (is_stroked_att && !strcmp(is_stroked_att, "false")) - is_stroked = 0; + is_stroked = 0; if (!is_stroked) - *skipped_stroke = 1; + *skipped_stroke = 1; s = points_att; n = 0; while (*s != 0) { - while (*s == ' ') s++; - sscanf(s, "%g,%g", &x[n], &y[n]); - while (*s != ' ' && *s != 0) s++; - n ++; - if (n == 2) - { - if (stroking && !is_stroked) - { - gs_moveto(ctx->pgs, x[1], y[1]); - } - else - { - gs_currentpoint(ctx->pgs, &pt); - gs_curveto(ctx->pgs, - (pt.x + 2 * x[0]) / 3, (pt.y + 2 * y[0]) / 3, - (x[1] + 2 * x[0]) / 3, (y[1] + 2 * y[0]) / 3, - x[1], y[1]); - } - n = 0; - } + while (*s == ' ') s++; + sscanf(s, "%g,%g", &x[n], &y[n]); + while (*s != ' ' && *s != 0) s++; + n ++; + if (n == 2) + { + if (stroking && !is_stroked) + { + gs_moveto(ctx->pgs, x[1], y[1]); + } + else + { + gs_currentpoint(ctx->pgs, &pt); + gs_curveto(ctx->pgs, + (pt.x + 2 * x[0]) / 3, (pt.y + 2 * y[0]) / 3, + (x[1] + 2 * x[0]) / 3, (y[1] + 2 * y[0]) / 3, + x[1], y[1]); + } + n = 0; + } } return 0; @@ -691,30 +691,30 @@ xps_parse_poly_bezier_segment(xps_context_t *ctx, xps_item_t *root, int stroking int n; if (!points_att) - return gs_throw(-1, "PolyBezierSegment element has no points"); + return gs_throw(-1, "PolyBezierSegment element has no points"); is_stroked = 1; if (is_stroked_att && !strcmp(is_stroked_att, "false")) - is_stroked = 0; + is_stroked = 0; if (!is_stroked) - *skipped_stroke = 1; + *skipped_stroke = 1; s = points_att; n = 0; while (*s != 0) { - while (*s == ' ') s++; - sscanf(s, "%g,%g", &x[n], &y[n]); - while (*s != ' ' && *s != 0) s++; - n ++; - if (n == 3) - { - if (stroking && !is_stroked) - gs_moveto(ctx->pgs, x[2], y[2]); - else - gs_curveto(ctx->pgs, x[0], y[0], x[1], y[1], x[2], y[2]); - n = 0; - } + while (*s == ' ') s++; + sscanf(s, "%g,%g", &x[n], &y[n]); + while (*s != ' ' && *s != 0) s++; + n ++; + if (n == 3) + { + if (stroking && !is_stroked) + gs_moveto(ctx->pgs, x[2], y[2]); + else + gs_curveto(ctx->pgs, x[0], y[0], x[1], y[1], x[2], y[2]); + n = 0; + } } return 0; @@ -730,24 +730,24 @@ xps_parse_poly_line_segment(xps_context_t *ctx, xps_item_t *root, int stroking, char *s; if (!points_att) - return gs_throw(-1, "PolyLineSegment element has no points"); + return gs_throw(-1, "PolyLineSegment element has no points"); is_stroked = 1; if (is_stroked_att && !strcmp(is_stroked_att, "false")) - is_stroked = 0; + is_stroked = 0; if (!is_stroked) - *skipped_stroke = 1; + *skipped_stroke = 1; s = points_att; while (*s != 0) { - while (*s == ' ') s++; - sscanf(s, "%g,%g", &x, &y); - if (stroking && !is_stroked) - gs_moveto(ctx->pgs, x, y); - else - gs_lineto(ctx->pgs, x, y); - while (*s != ' ' && *s != 0) s++; + while (*s == ' ') s++; + sscanf(s, "%g,%g", &x, &y); + if (stroking && !is_stroked) + gs_moveto(ctx->pgs, x, y); + else + gs_lineto(ctx->pgs, x, y); + while (*s != ' ' && *s != 0) s++; } return 0; @@ -774,35 +774,35 @@ xps_parse_path_figure(xps_context_t *ctx, xps_item_t *root, int stroking) is_filled_att = xps_att(root, "IsFilled"); if (is_closed_att) - is_closed = !strcmp(is_closed_att, "true"); + is_closed = !strcmp(is_closed_att, "true"); if (is_filled_att) - is_filled = !strcmp(is_filled_att, "true"); + is_filled = !strcmp(is_filled_att, "true"); if (start_point_att) - sscanf(start_point_att, "%g,%g", &start_x, &start_y); + sscanf(start_point_att, "%g,%g", &start_x, &start_y); if (!stroking && !is_filled) /* not filled, when filling */ - return 0; + return 0; gs_moveto(ctx->pgs, start_x, start_y); for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "ArcSegment")) - xps_parse_arc_segment(ctx, node, stroking, &skipped_stroke); - if (!strcmp(xps_tag(node), "PolyBezierSegment")) - xps_parse_poly_bezier_segment(ctx, node, stroking, &skipped_stroke); - if (!strcmp(xps_tag(node), "PolyLineSegment")) - xps_parse_poly_line_segment(ctx, node, stroking, &skipped_stroke); - if (!strcmp(xps_tag(node), "PolyQuadraticBezierSegment")) - xps_parse_poly_quadratic_bezier_segment(ctx, node, stroking, &skipped_stroke); + if (!strcmp(xps_tag(node), "ArcSegment")) + xps_parse_arc_segment(ctx, node, stroking, &skipped_stroke); + if (!strcmp(xps_tag(node), "PolyBezierSegment")) + xps_parse_poly_bezier_segment(ctx, node, stroking, &skipped_stroke); + if (!strcmp(xps_tag(node), "PolyLineSegment")) + xps_parse_poly_line_segment(ctx, node, stroking, &skipped_stroke); + if (!strcmp(xps_tag(node), "PolyQuadraticBezierSegment")) + xps_parse_poly_quadratic_bezier_segment(ctx, node, stroking, &skipped_stroke); } if (is_closed) { - if (stroking && skipped_stroke) - gs_lineto(ctx->pgs, start_x, start_y); /* we've skipped using gs_moveto... */ - else - gs_closepath(ctx->pgs); /* no skipped segments, safe to closepath properly */ + if (stroking && skipped_stroke) + gs_lineto(ctx->pgs, start_x, start_y); /* we've skipped using gs_moveto... */ + else + gs_closepath(ctx->pgs); /* no skipped segments, safe to closepath properly */ } return 0; @@ -831,8 +831,8 @@ xps_parse_path_geometry(xps_context_t *ctx, xps_resource_t *dict, xps_item_t *ro for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "PathGeometry.Transform")) - transform_tag = xps_down(node); + if (!strcmp(xps_tag(node), "PathGeometry.Transform")) + transform_tag = xps_down(node); } xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL); @@ -840,19 +840,19 @@ xps_parse_path_geometry(xps_context_t *ctx, xps_resource_t *dict, xps_item_t *ro if (fill_rule_att) { - if (!strcmp(fill_rule_att, "NonZero")) - ctx->fill_rule = 1; - if (!strcmp(fill_rule_att, "EvenOdd")) - ctx->fill_rule = 0; + if (!strcmp(fill_rule_att, "NonZero")) + ctx->fill_rule = 1; + if (!strcmp(fill_rule_att, "EvenOdd")) + ctx->fill_rule = 0; } gs_make_identity(&transform); if (transform_att || transform_tag) { - if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); - if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + if (transform_att) + xps_parse_render_transform(ctx, transform_att, &transform); + if (transform_tag) + xps_parse_matrix_transform(ctx, transform_tag, &transform); } gs_currentmatrix(ctx->pgs, &saved_transform); @@ -860,18 +860,18 @@ xps_parse_path_geometry(xps_context_t *ctx, xps_resource_t *dict, xps_item_t *ro if (figures_att) { - xps_parse_abbreviated_geometry(ctx, figures_att); + xps_parse_abbreviated_geometry(ctx, figures_att); } if (figures_tag) { - xps_parse_path_figure(ctx, figures_tag, stroking); + xps_parse_path_figure(ctx, figures_tag, stroking); } for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "PathFigure")) - xps_parse_path_figure(ctx, node, stroking); + if (!strcmp(xps_tag(node), "PathFigure")) + xps_parse_path_figure(ctx, node, stroking); } gs_setmatrix(ctx->pgs, &saved_transform); @@ -884,10 +884,10 @@ xps_parse_line_cap(char *attr) { if (attr) { - if (!strcmp(attr, "Flat")) return gs_cap_butt; - if (!strcmp(attr, "Square")) return gs_cap_square; - if (!strcmp(attr, "Round")) return gs_cap_round; - if (!strcmp(attr, "Triangle")) return gs_cap_triangle; + if (!strcmp(attr, "Flat")) return gs_cap_butt; + if (!strcmp(attr, "Square")) return gs_cap_square; + if (!strcmp(attr, "Round")) return gs_cap_round; + if (!strcmp(attr, "Triangle")) return gs_cap_triangle; } return gs_cap_butt; } @@ -970,23 +970,23 @@ xps_parse_path(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_ite for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "Path.RenderTransform")) - transform_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Path.RenderTransform")) + transform_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Path.OpacityMask")) - opacity_mask_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Path.OpacityMask")) + opacity_mask_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Path.Clip")) - clip_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Path.Clip")) + clip_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Path.Fill")) - fill_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Path.Fill")) + fill_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Path.Stroke")) - stroke_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Path.Stroke")) + stroke_tag = xps_down(node); - if (!strcmp(xps_tag(node), "Path.Data")) - data_tag = xps_down(node); + if (!strcmp(xps_tag(node), "Path.Data")) + data_tag = xps_down(node); } fill_uri = base_uri; @@ -1006,16 +1006,16 @@ xps_parse_path(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_ite if (fill_tag && !strcmp(xps_tag(fill_tag), "SolidColorBrush")) { - fill_opacity_att = xps_att(fill_tag, "Opacity"); - fill_att = xps_att(fill_tag, "Color"); - fill_tag = NULL; + fill_opacity_att = xps_att(fill_tag, "Opacity"); + fill_att = xps_att(fill_tag, "Color"); + fill_tag = NULL; } if (stroke_tag && !strcmp(xps_tag(stroke_tag), "SolidColorBrush")) { - stroke_opacity_att = xps_att(stroke_tag, "Opacity"); - stroke_att = xps_att(stroke_tag, "Color"); - stroke_tag = NULL; + stroke_opacity_att = xps_att(stroke_tag, "Opacity"); + stroke_att = xps_att(stroke_tag, "Color"); + stroke_tag = NULL; } gs_setlinestartcap(ctx->pgs, xps_parse_line_cap(stroke_start_line_cap_att)); @@ -1025,152 +1025,152 @@ xps_parse_path(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_ite linejoin = gs_join_miter; if (stroke_line_join_att) { - if (!strcmp(stroke_line_join_att, "Miter")) linejoin = gs_join_miter; - if (!strcmp(stroke_line_join_att, "Bevel")) linejoin = gs_join_bevel; - if (!strcmp(stroke_line_join_att, "Round")) linejoin = gs_join_round; + if (!strcmp(stroke_line_join_att, "Miter")) linejoin = gs_join_miter; + if (!strcmp(stroke_line_join_att, "Bevel")) linejoin = gs_join_bevel; + if (!strcmp(stroke_line_join_att, "Round")) linejoin = gs_join_round; } gs_setlinejoin(ctx->pgs, linejoin); miterlimit = 10.0; if (stroke_miter_limit_att) - miterlimit = atof(stroke_miter_limit_att); + miterlimit = atof(stroke_miter_limit_att); gs_setmiterlimit(ctx->pgs, miterlimit); linewidth = 1.0; if (stroke_thickness_att) - linewidth = atof(stroke_thickness_att); + linewidth = atof(stroke_thickness_att); gs_setlinewidth(ctx->pgs, linewidth); if (stroke_dash_array_att) { - char *s = stroke_dash_array_att; - float dash_array[100]; - float dash_offset = 0.0; - int dash_count = 0; - - if (stroke_dash_offset_att) - dash_offset = atof(stroke_dash_offset_att) * linewidth; - - while (*s) - { - while (*s == ' ') - s++; - dash_array[dash_count++] = atof(s) * linewidth; - while (*s && *s != ' ') - s++; - } - - gs_setdash(ctx->pgs, dash_array, dash_count, dash_offset); + char *s = stroke_dash_array_att; + float dash_array[100]; + float dash_offset = 0.0; + int dash_count = 0; + + if (stroke_dash_offset_att) + dash_offset = atof(stroke_dash_offset_att) * linewidth; + + while (*s) + { + while (*s == ' ') + s++; + dash_array[dash_count++] = atof(s) * linewidth; + while (*s && *s != ' ') + s++; + } + + gs_setdash(ctx->pgs, dash_array, dash_count, dash_offset); } else { - gs_setdash(ctx->pgs, NULL, 0, 0.0); + gs_setdash(ctx->pgs, NULL, 0, 0.0); } if (transform_att || transform_tag) { - gs_matrix transform; + gs_matrix transform; - if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); - if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + if (transform_att) + xps_parse_render_transform(ctx, transform_att, &transform); + if (transform_tag) + xps_parse_matrix_transform(ctx, transform_tag, &transform); - gs_concat(ctx->pgs, &transform); + gs_concat(ctx->pgs, &transform); } if (clip_att || clip_tag) { - if (clip_att) - xps_parse_abbreviated_geometry(ctx, clip_att); - if (clip_tag) - xps_parse_path_geometry(ctx, dict, clip_tag, 0); + if (clip_att) + xps_parse_abbreviated_geometry(ctx, clip_att); + if (clip_tag) + xps_parse_path_geometry(ctx, dict, clip_tag, 0); - xps_clip(ctx, &saved_bounds_clip); + xps_clip(ctx, &saved_bounds_clip); } if (opacity_att || opacity_mask_tag) { - /* clip the bounds with the actual path */ - if (data_att) - xps_parse_abbreviated_geometry(ctx, data_att); - if (data_tag) - xps_parse_path_geometry(ctx, dict, data_tag, 0); - xps_update_bounds(ctx, &saved_bounds_opacity); - gs_newpath(ctx->pgs); - - xps_begin_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); + /* clip the bounds with the actual path */ + if (data_att) + xps_parse_abbreviated_geometry(ctx, data_att); + if (data_tag) + xps_parse_path_geometry(ctx, dict, data_tag, 0); + xps_update_bounds(ctx, &saved_bounds_opacity); + gs_newpath(ctx->pgs); + + xps_begin_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); } if (fill_att) { - xps_parse_color(ctx, base_uri, fill_att, &colorspace, samples); - if (fill_opacity_att) - samples[0] = atof(fill_opacity_att); - xps_set_color(ctx, colorspace, samples); + xps_parse_color(ctx, base_uri, fill_att, &colorspace, samples); + if (fill_opacity_att) + samples[0] = atof(fill_opacity_att); + xps_set_color(ctx, colorspace, samples); - if (data_att) - xps_parse_abbreviated_geometry(ctx, data_att); - if (data_tag) - xps_parse_path_geometry(ctx, dict, data_tag, 0); + if (data_att) + xps_parse_abbreviated_geometry(ctx, data_att); + if (data_tag) + xps_parse_path_geometry(ctx, dict, data_tag, 0); - xps_fill(ctx); + xps_fill(ctx); } if (fill_tag) { - if (data_att) - xps_parse_abbreviated_geometry(ctx, data_att); - if (data_tag) - xps_parse_path_geometry(ctx, dict, data_tag, 0); - - code = xps_parse_brush(ctx, fill_uri, dict, fill_tag); - if (code < 0) - gs_catch(code, "cannot parse fill brush. ignoring error."); + if (data_att) + xps_parse_abbreviated_geometry(ctx, data_att); + if (data_tag) + xps_parse_path_geometry(ctx, dict, data_tag, 0); + + code = xps_parse_brush(ctx, fill_uri, dict, fill_tag); + if (code < 0) + gs_catch(code, "cannot parse fill brush. ignoring error."); } if (stroke_att) { - xps_parse_color(ctx, base_uri, stroke_att, &colorspace, samples); - if (stroke_opacity_att) - samples[0] = atof(stroke_opacity_att); - xps_set_color(ctx, colorspace, samples); + xps_parse_color(ctx, base_uri, stroke_att, &colorspace, samples); + if (stroke_opacity_att) + samples[0] = atof(stroke_opacity_att); + xps_set_color(ctx, colorspace, samples); - if (data_att) - xps_parse_abbreviated_geometry(ctx, data_att); - if (data_tag) - xps_parse_path_geometry(ctx, dict, data_tag, 1); + if (data_att) + xps_parse_abbreviated_geometry(ctx, data_att); + if (data_tag) + xps_parse_path_geometry(ctx, dict, data_tag, 1); - gs_stroke(ctx->pgs); + gs_stroke(ctx->pgs); } if (stroke_tag) { - if (data_att) - xps_parse_abbreviated_geometry(ctx, data_att); - if (data_tag) - xps_parse_path_geometry(ctx, dict, data_tag, 1); + if (data_att) + xps_parse_abbreviated_geometry(ctx, data_att); + if (data_tag) + xps_parse_path_geometry(ctx, dict, data_tag, 1); - ctx->fill_rule = 1; /* over-ride fill rule when converting outline to stroked */ - gs_strokepath2(ctx->pgs); + ctx->fill_rule = 1; /* over-ride fill rule when converting outline to stroked */ + gs_strokepath2(ctx->pgs); - code = xps_parse_brush(ctx, stroke_uri, dict, stroke_tag); - if (code < 0) - gs_catch(code, "cannot parse stroke brush. ignoring error."); + code = xps_parse_brush(ctx, stroke_uri, dict, stroke_tag); + if (code < 0) + gs_catch(code, "cannot parse stroke brush. ignoring error."); } if (opacity_att || opacity_mask_tag) { - xps_restore_bounds(ctx, &saved_bounds_opacity); + xps_restore_bounds(ctx, &saved_bounds_opacity); - xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); + xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); } gs_grestore(ctx->pgs); if (clip_att || clip_tag) { - xps_restore_bounds(ctx, &saved_bounds_clip); + xps_restore_bounds(ctx, &saved_bounds_clip); } return 0; diff --git a/xps/xpspng.c b/xps/xpspng.c index 0529f0360..94aef0d30 100644 --- a/xps/xpspng.c +++ b/xps/xpspng.c @@ -112,13 +112,13 @@ int xps_decode_png(gs_memory_t *mem, byte *rbuf, int rlen, xps_image_t *image) if (png_get_color_type(png, info) == PNG_COLOR_TYPE_PALETTE) { - png_set_palette_to_rgb(png); + png_set_palette_to_rgb(png); } if (png_get_valid(png, info, PNG_INFO_tRNS)) { - /* this will also expand the depth to 8-bits */ - png_set_tRNS_to_alpha(png); + /* this will also expand the depth to 8-bits */ + png_set_tRNS_to_alpha(png); } png_read_update_info(png, info); diff --git a/xps/xpsresource.c b/xps/xpsresource.c index 21151f20d..9fe879268 100644 --- a/xps/xpsresource.c +++ b/xps/xpsresource.c @@ -21,15 +21,15 @@ xps_find_resource(xps_context_t *ctx, xps_resource_t *dict, char *name, char **u xps_resource_t *head, *node; for (head = dict; head; head = head->parent) { - for (node = head; node; node = node->next) - { - if (!strcmp(node->name, name)) - { - if (urip && head->base_uri) - *urip = head->base_uri; - return node->data; - } - } + for (node = head; node; node = node->next) + { + if (!strcmp(node->name, name)) + { + if (urip && head->base_uri) + *urip = head->base_uri; + return node->data; + } + } } return NULL; } @@ -41,28 +41,28 @@ xps_parse_resource_reference(xps_context_t *ctx, xps_resource_t *dict, char *att char *s; if (strstr(att, "{StaticResource ") != att) - return NULL; + return NULL; strcpy(name, att + 16); s = strrchr(name, '}'); if (s) - *s = 0; + *s = 0; return xps_find_resource(ctx, dict, name, urip); } int xps_resolve_resource_reference(xps_context_t *ctx, xps_resource_t *dict, - char **attp, xps_item_t **tagp, char **urip) + char **attp, xps_item_t **tagp, char **urip) { if (*attp) { - xps_item_t *rsrc = xps_parse_resource_reference(ctx, dict, *attp, urip); - if (rsrc) - { - *attp = NULL; - *tagp = rsrc; - } + xps_item_t *rsrc = xps_parse_resource_reference(ctx, dict, *attp, urip); + if (rsrc) + { + *attp = NULL; + *tagp = rsrc; + } } return 0; } @@ -82,33 +82,33 @@ xps_parse_remote_resource_dictionary(xps_context_t *ctx, char *base_uri, char *s part = xps_read_part(ctx, part_name); if (!part) { - gs_throw1(-1, "cannot find remote resource part '%s'", part_name); - return NULL; + gs_throw1(-1, "cannot find remote resource part '%s'", part_name); + return NULL; } xml = xps_parse_xml(ctx, part->data, part->size); if (!xml) { - gs_rethrow(-1, "cannot parse xml"); - return NULL; + gs_rethrow(-1, "cannot parse xml"); + return NULL; } if (strcmp(xps_tag(xml), "ResourceDictionary")) { - gs_throw1(-1, "expected ResourceDictionary element (found %s)", xps_tag(xml)); - return NULL; + gs_throw1(-1, "expected ResourceDictionary element (found %s)", xps_tag(xml)); + return NULL; } strcpy(part_uri, part_name); s = strrchr(part_uri, '/'); if (s) - s[1] = 0; + s[1] = 0; dict = xps_parse_resource_dictionary(ctx, part_uri, xml); if (!dict) { - gs_rethrow1(-1, "cannot parse remote resource dictionary %s", part_uri); - return NULL; + gs_rethrow1(-1, "cannot parse remote resource dictionary %s", part_uri); + return NULL; } dict->base_xml = xml; /* pass on ownership */ @@ -129,36 +129,36 @@ xps_parse_resource_dictionary(xps_context_t *ctx, char *base_uri, xps_item_t *ro source = xps_att(root, "Source"); if (source) - return xps_parse_remote_resource_dictionary(ctx, base_uri, source); + return xps_parse_remote_resource_dictionary(ctx, base_uri, source); head = NULL; for (node = xps_down(root); node; node = xps_next(node)) { - /* Usually "x:Key"; we have already processed and stripped namespace */ - key = xps_att(node, "Key"); - if (key) - { - entry = xps_alloc(ctx, sizeof(xps_resource_t)); - if (!entry) - { - gs_throw(-1, "cannot allocate resource entry"); - return head; - } - entry->name = key; - entry->base_uri = NULL; - entry->base_xml = NULL; - entry->data = node; - entry->next = head; - entry->parent = NULL; - head = entry; - } + /* Usually "x:Key"; we have already processed and stripped namespace */ + key = xps_att(node, "Key"); + if (key) + { + entry = xps_alloc(ctx, sizeof(xps_resource_t)); + if (!entry) + { + gs_throw(-1, "cannot allocate resource entry"); + return head; + } + entry->name = key; + entry->base_uri = NULL; + entry->base_xml = NULL; + entry->data = node; + entry->next = head; + entry->parent = NULL; + head = entry; + } } if (head) { - head->base_uri = xps_alloc(ctx, strlen(base_uri) + 1); - strcpy(head->base_uri, base_uri); + head->base_uri = xps_alloc(ctx, strlen(base_uri) + 1); + strcpy(head->base_uri, base_uri); } return head; @@ -170,13 +170,13 @@ xps_free_resource_dictionary(xps_context_t *ctx, xps_resource_t *dict) xps_resource_t *next; while (dict) { - next = dict->next; - if (dict->base_xml) - xps_free_item(ctx, dict->base_xml); - if (dict->base_uri) - xps_free(ctx, dict->base_uri); - xps_free(ctx, dict); - dict = next; + next = dict->next; + if (dict->base_xml) + xps_free_item(ctx, dict->base_xml); + if (dict->base_uri) + xps_free(ctx, dict->base_uri); + xps_free(ctx, dict); + dict = next; } } @@ -185,16 +185,16 @@ xps_debug_resource_dictionary(xps_resource_t *dict) { while (dict) { - if (dict->base_uri) - dprintf1("URI = '%s'\n", dict->base_uri); - dprintf2("KEY = '%s' VAL = %p\n", dict->name, dict->data); - if (dict->parent) - { - dputs("PARENT = {\n"); - xps_debug_resource_dictionary(dict->parent); - dputs("}\n"); - } - dict = dict->next; + if (dict->base_uri) + dprintf1("URI = '%s'\n", dict->base_uri); + dprintf2("KEY = '%s' VAL = %p\n", dict->name, dict->data); + if (dict->parent) + { + dputs("PARENT = {\n"); + xps_debug_resource_dictionary(dict->parent); + dputs("}\n"); + } + dict = dict->next; } } diff --git a/xps/xpstiff.c b/xps/xpstiff.c index 3ed9ed4c2..e0a85b1eb 100644 --- a/xps/xpstiff.c +++ b/xps/xpstiff.c @@ -512,8 +512,8 @@ xps_invert_tiff(byte *line, int width, int comps, int bits, int alpha) for (k = 0; k < comps; k++) { v = getcomp(line, i * comps + k, bits); - if (!alpha || k < comps - 1) - v = m - v; + if (!alpha || k < comps - 1) + v = m - v; putcomp(line, i * comps + k, bits, v); } } @@ -640,15 +640,15 @@ xps_decode_tiff_strips(gs_memory_t *mem, xps_tiff_t *tiff, xps_image_t *image) case 2: image->xres = tiff->xresolution; image->yres = tiff->yresolution; - break; + break; case 3: image->xres = tiff->xresolution * 2.54 + 0.5; image->yres = tiff->yresolution * 2.54 + 0.5; - break; + break; default: image->xres = 96; image->yres = 96; - break; + break; } image->samples = gs_alloc_bytes(mem, image->stride * image->height, "samples"); @@ -681,31 +681,31 @@ xps_decode_tiff_strips(gs_memory_t *mem, xps_tiff_t *tiff, xps_image_t *image) switch (tiff->compression) { case 1: - error = xps_decode_tiff_uncompressed(mem, tiff, rp, rp + rlen, wp, wp + wlen); + error = xps_decode_tiff_uncompressed(mem, tiff, rp, rp + rlen, wp, wp + wlen); break; case 2: - error = xps_decode_tiff_fax(mem, tiff, 2, rp, rp + rlen, wp, wp + wlen); + error = xps_decode_tiff_fax(mem, tiff, 2, rp, rp + rlen, wp, wp + wlen); break; case 3: - error = xps_decode_tiff_fax(mem, tiff, 3, rp, rp + rlen, wp, wp + wlen); + error = xps_decode_tiff_fax(mem, tiff, 3, rp, rp + rlen, wp, wp + wlen); break; case 4: - error = xps_decode_tiff_fax(mem, tiff, 4, rp, rp + rlen, wp, wp + wlen); + error = xps_decode_tiff_fax(mem, tiff, 4, rp, rp + rlen, wp, wp + wlen); break; case 5: - error = xps_decode_tiff_lzw(mem, tiff, rp, rp + rlen, wp, wp + wlen); + error = xps_decode_tiff_lzw(mem, tiff, rp, rp + rlen, wp, wp + wlen); break; case 6: - error = gs_throw(-1, "deprecated JPEG in TIFF compression not supported"); + error = gs_throw(-1, "deprecated JPEG in TIFF compression not supported"); break; case 7: - error = xps_decode_tiff_jpeg(mem, tiff, rp, rp + rlen, wp, wp + wlen); + error = xps_decode_tiff_jpeg(mem, tiff, rp, rp + rlen, wp, wp + wlen); break; case 8: - error = xps_decode_tiff_flate(mem, tiff, rp, rp + rlen, wp, wp + wlen); + error = xps_decode_tiff_flate(mem, tiff, rp, rp + rlen, wp, wp + wlen); break; case 32773: - error = xps_decode_tiff_packbits(mem, tiff, rp, rp + rlen, wp, wp + wlen); + error = xps_decode_tiff_packbits(mem, tiff, rp, rp + rlen, wp, wp + wlen); break; default: error = gs_throw1(-1, "unknown TIFF compression: %d", tiff->compression); @@ -918,9 +918,9 @@ xps_swap_byte_order(byte *buf, int n) int i, t; for (i = 0; i < n; i++) { - t = buf[i * 2 + 0]; - buf[i * 2 + 0] = buf[i * 2 + 1]; - buf[i * 2 + 1] = t; + t = buf[i * 2 + 0]; + buf[i * 2 + 0] = buf[i * 2 + 1]; + buf[i * 2 + 1] = t; } } @@ -1016,8 +1016,8 @@ xps_decode_tiff(gs_memory_t *mem, byte *buf, int len, xps_image_t *image) */ if (image->bits == 16) { - if (tiff->order == TII) - xps_swap_byte_order(image->samples, image->width * image->height * image->comps); + if (tiff->order == TII) + xps_swap_byte_order(image->samples, image->width * image->height * image->comps); } return gs_okay; diff --git a/xps/xpstile.c b/xps/xpstile.c index ec9074310..35207765c 100644 --- a/xps/xpstile.c +++ b/xps/xpstile.c @@ -84,29 +84,29 @@ xps_paint_tiling_brush(const gs_client_color *pcc, gs_state *pgs) if (c->tile_mode == TILE_FLIP_X || c->tile_mode == TILE_FLIP_X_Y) { - gs_gsave(ctx->pgs); - gs_translate(ctx->pgs, c->viewbox.q.x * 2, 0.0); - gs_scale(ctx->pgs, -1.0, 1.0); - xps_paint_tiling_brush_clipped(c); - gs_grestore(ctx->pgs); + gs_gsave(ctx->pgs); + gs_translate(ctx->pgs, c->viewbox.q.x * 2, 0.0); + gs_scale(ctx->pgs, -1.0, 1.0); + xps_paint_tiling_brush_clipped(c); + gs_grestore(ctx->pgs); } if (c->tile_mode == TILE_FLIP_Y || c->tile_mode == TILE_FLIP_X_Y) { - gs_gsave(ctx->pgs); - gs_translate(ctx->pgs, 0.0, c->viewbox.q.y * 2); - gs_scale(ctx->pgs, 1.0, -1.0); - xps_paint_tiling_brush_clipped(c); - gs_grestore(ctx->pgs); + gs_gsave(ctx->pgs); + gs_translate(ctx->pgs, 0.0, c->viewbox.q.y * 2); + gs_scale(ctx->pgs, 1.0, -1.0); + xps_paint_tiling_brush_clipped(c); + gs_grestore(ctx->pgs); } if (c->tile_mode == TILE_FLIP_X_Y) { - gs_gsave(ctx->pgs); - gs_translate(ctx->pgs, c->viewbox.q.x * 2, c->viewbox.q.y * 2); - gs_scale(ctx->pgs, -1.0, -1.0); - xps_paint_tiling_brush_clipped(c); - gs_grestore(ctx->pgs); + gs_gsave(ctx->pgs); + gs_translate(ctx->pgs, c->viewbox.q.x * 2, c->viewbox.q.y * 2); + gs_scale(ctx->pgs, -1.0, -1.0); + xps_paint_tiling_brush_clipped(c); + gs_grestore(ctx->pgs); } ctx->pgs = saved_pgs; @@ -116,7 +116,7 @@ xps_paint_tiling_brush(const gs_client_color *pcc, gs_state *pgs) int xps_parse_tiling_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_item_t *root, - int (*func)(xps_context_t*, char*, xps_resource_t*, xps_item_t*, void*), void *user) + int (*func)(xps_context_t*, char*, xps_resource_t*, xps_item_t*, void*), void *user) { xps_item_t *node; @@ -146,29 +146,29 @@ xps_parse_tiling_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "ImageBrush.Transform")) - transform_tag = xps_down(node); - if (!strcmp(xps_tag(node), "VisualBrush.Transform")) - transform_tag = xps_down(node); + if (!strcmp(xps_tag(node), "ImageBrush.Transform")) + transform_tag = xps_down(node); + if (!strcmp(xps_tag(node), "VisualBrush.Transform")) + transform_tag = xps_down(node); } xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL); gs_make_identity(&transform); if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); + xps_parse_render_transform(ctx, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + xps_parse_matrix_transform(ctx, transform_tag, &transform); viewbox.p.x = 0.0; viewbox.p.y = 0.0; viewbox.q.x = 1.0; viewbox.q.y = 1.0; if (viewbox_att) - xps_parse_rectangle(ctx, viewbox_att, &viewbox); + xps_parse_rectangle(ctx, viewbox_att, &viewbox); viewport.p.x = 0.0; viewport.p.y = 0.0; viewport.q.x = 1.0; viewport.q.y = 1.0; if (viewport_att) - xps_parse_rectangle(ctx, viewport_att, &viewport); + xps_parse_rectangle(ctx, viewport_att, &viewport); /* some sanity checks on the viewport/viewbox size */ if (fabs(viewport.q.x - viewport.p.x) < 0.01) return 0; @@ -182,111 +182,112 @@ xps_parse_tiling_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, tile_mode = TILE_NONE; if (tile_mode_att) { - if (!strcmp(tile_mode_att, "None")) - tile_mode = TILE_NONE; - if (!strcmp(tile_mode_att, "Tile")) - tile_mode = TILE_TILE; - if (!strcmp(tile_mode_att, "FlipX")) - tile_mode = TILE_FLIP_X; - if (!strcmp(tile_mode_att, "FlipY")) - tile_mode = TILE_FLIP_Y; - if (!strcmp(tile_mode_att, "FlipXY")) - tile_mode = TILE_FLIP_X_Y; + if (!strcmp(tile_mode_att, "None")) + tile_mode = TILE_NONE; + if (!strcmp(tile_mode_att, "Tile")) + tile_mode = TILE_TILE; + if (!strcmp(tile_mode_att, "FlipX")) + tile_mode = TILE_FLIP_X; + if (!strcmp(tile_mode_att, "FlipY")) + tile_mode = TILE_FLIP_Y; + if (!strcmp(tile_mode_att, "FlipXY")) + tile_mode = TILE_FLIP_X_Y; } gs_gsave(ctx->pgs); xps_begin_opacity(ctx, base_uri, dict, opacity_att, NULL); - + /* TODO(tor): check viewport and tiling to see if we can set it to TILE_NONE */ if (tile_mode != TILE_NONE) { - struct tile_closure_s closure; - - gs_client_pattern gspat; - gs_client_color gscolor; - gs_color_space *cs; - - closure.ctx = ctx; - closure.base_uri = base_uri; - closure.dict = dict; - closure.tag = root; - closure.tile_mode = tile_mode; - closure.user = user; - closure.func = func; - - closure.viewbox.p.x = viewbox.p.x; - closure.viewbox.p.y = viewbox.p.y; - closure.viewbox.q.x = viewbox.q.x; - closure.viewbox.q.y = viewbox.q.y; - - gs_pattern1_init(&gspat); - uid_set_UniqueID(&gspat.uid, gs_next_ids(ctx->memory, 1)); - gspat.PaintType = 1; - gspat.TilingType = 1; - gspat.PaintProc = xps_paint_tiling_brush; - gspat.client_data = &closure; - - gspat.XStep = viewbox.q.x - viewbox.p.x; - gspat.YStep = viewbox.q.y - viewbox.p.y; - gspat.BBox.p.x = viewbox.p.x; - gspat.BBox.p.y = viewbox.p.y; - gspat.BBox.q.x = viewbox.q.x; - gspat.BBox.q.y = viewbox.q.y; - - if (tile_mode == TILE_FLIP_X || tile_mode == TILE_FLIP_X_Y) - { - gspat.BBox.q.x += gspat.XStep; - gspat.XStep *= 2; - } - - if (tile_mode == TILE_FLIP_Y || tile_mode == TILE_FLIP_X_Y) - { - gspat.BBox.q.y += gspat.YStep; - gspat.YStep *= 2; - } - - gs_matrix_translate(&transform, viewport.p.x, viewport.p.y, &transform); - gs_matrix_scale(&transform, scalex, scaley, &transform); - gs_matrix_translate(&transform, -viewbox.p.x, -viewbox.p.y, &transform); - - cs = ctx->srgb; - gs_setcolorspace(ctx->pgs, cs); - gs_makepattern(&gscolor, &gspat, &transform, ctx->pgs, NULL); - gs_setpattern(ctx->pgs, &gscolor); - - xps_fill(ctx); - - /* gs_makepattern increments the pattern count stored in the color - * structure. We will discard the color struct (its on the stack) so we need to - * decrement the reference before we throw away the structure. - */ - gs_pattern_reference(&gscolor, -1); + struct tile_closure_s closure; + + gs_client_pattern gspat; + gs_client_color gscolor; + gs_color_space *cs; + + closure.ctx = ctx; + closure.base_uri = base_uri; + closure.dict = dict; + closure.tag = root; + closure.tile_mode = tile_mode; + closure.user = user; + closure.func = func; + + closure.viewbox.p.x = viewbox.p.x; + closure.viewbox.p.y = viewbox.p.y; + closure.viewbox.q.x = viewbox.q.x; + closure.viewbox.q.y = viewbox.q.y; + + gs_pattern1_init(&gspat); + uid_set_UniqueID(&gspat.uid, gs_next_ids(ctx->memory, 1)); + gspat.PaintType = 1; + gspat.TilingType = 1; + gspat.PaintProc = xps_paint_tiling_brush; + gspat.client_data = &closure; + + gspat.XStep = viewbox.q.x - viewbox.p.x; + gspat.YStep = viewbox.q.y - viewbox.p.y; + gspat.BBox.p.x = viewbox.p.x; + gspat.BBox.p.y = viewbox.p.y; + gspat.BBox.q.x = viewbox.q.x; + gspat.BBox.q.y = viewbox.q.y; + + if (tile_mode == TILE_FLIP_X || tile_mode == TILE_FLIP_X_Y) + { + gspat.BBox.q.x += gspat.XStep; + gspat.XStep *= 2; + } + + if (tile_mode == TILE_FLIP_Y || tile_mode == TILE_FLIP_X_Y) + { + gspat.BBox.q.y += gspat.YStep; + gspat.YStep *= 2; + } + + gs_matrix_translate(&transform, viewport.p.x, viewport.p.y, &transform); + gs_matrix_scale(&transform, scalex, scaley, &transform); + gs_matrix_translate(&transform, -viewbox.p.x, -viewbox.p.y, &transform); + + cs = ctx->srgb; + gs_setcolorspace(ctx->pgs, cs); + gs_makepattern(&gscolor, &gspat, &transform, ctx->pgs, NULL); + gs_setpattern(ctx->pgs, &gscolor); + + xps_fill(ctx); + + /* gs_makepattern increments the pattern count stored in the color + * structure. We will discard the color struct (its on the stack) + * so we need to decrement the reference before we throw away + * the structure. + */ + gs_pattern_reference(&gscolor, -1); } else { - gs_rect saved_bounds; + gs_rect saved_bounds; - xps_clip(ctx, &saved_bounds); + xps_clip(ctx, &saved_bounds); - gs_concat(ctx->pgs, &transform); + gs_concat(ctx->pgs, &transform); - gs_translate(ctx->pgs, viewport.p.x, viewport.p.y); - gs_scale(ctx->pgs, scalex, scaley); - gs_translate(ctx->pgs, -viewbox.p.x, -viewbox.p.y); + gs_translate(ctx->pgs, viewport.p.x, viewport.p.y); + gs_scale(ctx->pgs, scalex, scaley); + gs_translate(ctx->pgs, -viewbox.p.x, -viewbox.p.y); - gs_moveto(ctx->pgs, viewbox.p.x, viewbox.p.y); - gs_lineto(ctx->pgs, viewbox.p.x, viewbox.q.y); - gs_lineto(ctx->pgs, viewbox.q.x, viewbox.q.y); - gs_lineto(ctx->pgs, viewbox.q.x, viewbox.p.y); - gs_closepath(ctx->pgs); - gs_clip(ctx->pgs); - gs_newpath(ctx->pgs); + gs_moveto(ctx->pgs, viewbox.p.x, viewbox.p.y); + gs_lineto(ctx->pgs, viewbox.p.x, viewbox.q.y); + gs_lineto(ctx->pgs, viewbox.q.x, viewbox.q.y); + gs_lineto(ctx->pgs, viewbox.q.x, viewbox.p.y); + gs_closepath(ctx->pgs); + gs_clip(ctx->pgs); + gs_newpath(ctx->pgs); - func(ctx, base_uri, dict, root, user); + func(ctx, base_uri, dict, root, user); - xps_restore_bounds(ctx, &saved_bounds); + xps_restore_bounds(ctx, &saved_bounds); } xps_end_opacity(ctx, base_uri, dict, opacity_att, NULL); diff --git a/xps/xpstop.c b/xps/xpstop.c index 1b0524ad3..2068fa04f 100644 --- a/xps/xpstop.c +++ b/xps/xpstop.c @@ -40,12 +40,12 @@ typedef struct xps_interp_instance_s xps_interp_instance_t; struct xps_interp_instance_s { - pl_interp_instance_t pl; /* common part: must be first */ + pl_interp_instance_t pl; /* common part: must be first */ pl_page_action_t pre_page_action; /* action before page out */ - void *pre_page_closure; /* closure to call pre_page_action with */ + void *pre_page_closure; /* closure to call pre_page_action with */ pl_page_action_t post_page_action; /* action before page out */ - void *post_page_closure; /* closure to call post_page_action with */ + void *post_page_closure; /* closure to call post_page_action with */ xps_context_t *ctx; }; @@ -59,20 +59,20 @@ xps_imp_characteristics(const pl_interp_implementation_t *pimpl) { static pl_interp_characteristics_t xps_characteristics = { - "XPS", - "PK", /* string to recognize XPS files */ - "Artifex", - XPS_VERSION, - XPS_BUILD_DATE, - XPS_PARSER_MIN_INPUT_SIZE, /* Minimum input size */ + "XPS", + "PK", /* string to recognize XPS files */ + "Artifex", + XPS_VERSION, + XPS_BUILD_DATE, + XPS_PARSER_MIN_INPUT_SIZE, /* Minimum input size */ }; return &xps_characteristics; } static int xps_imp_allocate_interp(pl_interp_t **ppinterp, - const pl_interp_implementation_t *pimpl, - gs_memory_t *pmem) + const pl_interp_implementation_t *pimpl, + gs_memory_t *pmem) { static pl_interp_t interp; /* there's only one interpreter */ *ppinterp = &interp; @@ -82,18 +82,18 @@ xps_imp_allocate_interp(pl_interp_t **ppinterp, /* Do per-instance interpreter allocation/init. No device is set yet */ static int xps_imp_allocate_interp_instance(pl_interp_instance_t **ppinstance, - pl_interp_t *pinterp, - gs_memory_t *pmem) + pl_interp_t *pinterp, + gs_memory_t *pmem) { xps_interp_instance_t *instance; xps_context_t *ctx; gs_state *pgs; instance = (xps_interp_instance_t *) gs_alloc_bytes(pmem, - sizeof(xps_interp_instance_t), "xps_imp_allocate_interp_instance"); + sizeof(xps_interp_instance_t), "xps_imp_allocate_interp_instance"); ctx = (xps_context_t *) gs_alloc_bytes(pmem, - sizeof(xps_context_t), "xps_imp_allocate_interp_instance"); + sizeof(xps_context_t), "xps_imp_allocate_interp_instance"); pgs = gs_state_alloc(pmem); #ifdef ICCBRANCH @@ -103,7 +103,7 @@ xps_imp_allocate_interp_instance(pl_interp_instance_t **ppinstance, if (!instance || !ctx || !pgs) { - if (instance) + if (instance) gs_free_object(pmem, instance, "xps_imp_allocate_interp_instance"); if (ctx) gs_free_object(pmem, ctx, "xps_imp_allocate_interp_instance"); @@ -143,8 +143,8 @@ xps_imp_allocate_interp_instance(pl_interp_instance_t **ppinstance, /* Set a client language into an interperter instance */ static int xps_imp_set_client_instance(pl_interp_instance_t *pinstance, - pl_interp_instance_t *pclient, - pl_interp_instance_clients_t which_client) + pl_interp_instance_t *pclient, + pl_interp_instance_clients_t which_client) { /* ignore */ return 0; @@ -152,7 +152,7 @@ xps_imp_set_client_instance(pl_interp_instance_t *pinstance, static int xps_imp_set_pre_page_action(pl_interp_instance_t *pinstance, - pl_page_action_t action, void *closure) + pl_page_action_t action, void *closure) { xps_interp_instance_t *instance = (xps_interp_instance_t *)pinstance; instance->pre_page_action = action; @@ -162,7 +162,7 @@ xps_imp_set_pre_page_action(pl_interp_instance_t *pinstance, static int xps_imp_set_post_page_action(pl_interp_instance_t *pinstance, - pl_page_action_t action, void *closure) + pl_page_action_t action, void *closure) { xps_interp_instance_t *instance = (xps_interp_instance_t *)pinstance; instance->post_page_action = action; @@ -178,7 +178,7 @@ xps_imp_set_device(pl_interp_instance_t *pinstance, gx_device *pdevice) int code; gs_opendevice(pdevice); - + #ifdef ICCBRANCH code = gsicc_init_device_profile(ctx->pgs, pdevice); if (code < 0) @@ -187,7 +187,7 @@ xps_imp_set_device(pl_interp_instance_t *pinstance, gx_device *pdevice) code = gs_setdevice_no_erase(ctx->pgs, pdevice); if (code < 0) - goto cleanup_setdevice; + goto cleanup_setdevice; gs_setaccuratecurves(ctx->pgs, true); /* NB not sure */ gs_setfilladjust(ctx->pgs, 0, 0); @@ -197,15 +197,15 @@ xps_imp_set_device(pl_interp_instance_t *pinstance, gx_device *pdevice) /* Ensure that now. */ code = gs_gsave(ctx->pgs); if (code < 0) - goto cleanup_gsave; + goto cleanup_gsave; code = gs_erasepage(ctx->pgs); if (code < 0) - goto cleanup_erase; + goto cleanup_erase; code = xps_install_halftone(ctx, pdevice); if (code < 0) - goto cleanup_halftone; + goto cleanup_halftone; return 0; @@ -241,11 +241,11 @@ xps_imp_process_file(pl_interp_instance_t *pinstance, char *filename) file = fopen(filename, "rb"); if (!file) - return gs_error_ioerror; + return gs_error_ioerror; code = xps_process_file(ctx, file); if (code) - gs_catch1(code, "cannot process xps file (%s)", filename); + gs_catch1(code, "cannot process xps file (%s)", filename); fclose(file); @@ -263,13 +263,13 @@ xps_imp_process(pl_interp_instance_t *pinstance, stream_cursor_read *pcursor) code = xps_process_data(ctx, pcursor); if (code == 1) { - code = xps_process_end_of_data(ctx); - if (code < 0) - gs_catch(code, "cannot process xps data"); - return e_ExitLanguage; + code = xps_process_end_of_data(ctx); + if (code < 0) + gs_catch(code, "cannot process xps data"); + return e_ExitLanguage; } else if (code < 0) - gs_catch(code, "cannot process xps data"); + gs_catch(code, "cannot process xps data"); return code; } @@ -294,7 +294,7 @@ xps_imp_process_eof(pl_interp_instance_t *pinstance) code = xps_process_end_of_data(ctx); if (code) - gs_catch(code, "cannot process xps file"); + gs_catch(code, "cannot process xps file"); return 0; } @@ -302,10 +302,10 @@ xps_imp_process_eof(pl_interp_instance_t *pinstance) /* Report any errors after running a job */ static int xps_imp_report_errors(pl_interp_instance_t *pinstance, - int code, /* prev termination status */ - long file_position, /* file position of error, -1 if unknown */ - bool force_to_cout /* force errors to cout */ - ) + int code, /* prev termination status */ + long file_position, /* file position of error, -1 if unknown */ + bool force_to_cout /* force errors to cout */ + ) { return 0; } @@ -318,9 +318,9 @@ xps_imp_init_job(pl_interp_instance_t *pinstance) xps_context_t *ctx = instance->ctx; if (gs_debug_c('|')) - xps_zip_trace = 1; + xps_zip_trace = 1; if (gs_debug_c('|')) - xps_doc_trace = 1; + xps_doc_trace = 1; ctx->part_table = xps_hash_new(ctx); ctx->part_list = NULL; @@ -332,7 +332,7 @@ xps_imp_init_job(pl_interp_instance_t *pinstance) ctx->use_transparency = 1; if (getenv("XPS_DISABLE_TRANSPARENCY")) - ctx->use_transparency = 0; + ctx->use_transparency = 0; ctx->opacity_only = 0; ctx->fill_rule = 0; @@ -349,31 +349,31 @@ xps_imp_dnit_job(pl_interp_instance_t *pinstance) int i; if (gs_debug_c('|')) - xps_debug_parts(ctx); + xps_debug_parts(ctx); if (gs_debug_c('|')) - xps_debug_fixdocseq(ctx); + xps_debug_fixdocseq(ctx); /* Free XPS parsing stuff */ { - xps_part_t *part = ctx->part_list; - while (part) - { - xps_part_t *next = part->next; - xps_free_part(ctx, part); - part = next; - } - - for (i = 0; i < ctx->zip_count; i++) - xps_free(ctx, ctx->zip_table[i].name); - xps_free(ctx, ctx->zip_table); - - xps_hash_free(ctx, ctx->part_table); - ctx->part_table = NULL; - ctx->part_list = NULL; - ctx->current_part = NULL; - - xps_free_fixed_pages(ctx); - xps_free_fixed_documents(ctx); + xps_part_t *part = ctx->part_list; + while (part) + { + xps_part_t *next = part->next; + xps_free_part(ctx, part); + part = next; + } + + for (i = 0; i < ctx->zip_count; i++) + xps_free(ctx, ctx->zip_table[i].name); + xps_free(ctx, ctx->zip_table); + + xps_hash_free(ctx, ctx->part_table); + ctx->part_table = NULL; + ctx->part_list = NULL; + ctx->current_part = NULL; + + xps_free_fixed_pages(ctx); + xps_free_fixed_documents(ctx); } return 0; @@ -478,7 +478,7 @@ xps_show_page(xps_context_t *ctx, int num_copies, int flush) /* do post-page action */ if (instance->post_page_action) { - code = instance->post_page_action(pinstance, instance->post_page_closure); + code = instance->post_page_action(pinstance, instance->post_page_closure); if (code < 0) return code; } @@ -535,23 +535,23 @@ xps_install_halftone(xps_context_t *ctx, gx_device *pdevice) if (gx_device_must_halftone(pdevice)) { - ht.type = ht_type_threshold; - ht.params.threshold.width = width; - ht.params.threshold.height = height; - ht.params.threshold.thresholds.data = thresh.data; - ht.params.threshold.thresholds.size = thresh.size; - ht.params.threshold.transfer = 0; - ht.params.threshold.transfer_closure.proc = 0; - - gs_settransfer(ctx->pgs, identity_transfer); - - code = gs_sethalftone(ctx->pgs, &ht); - if (code < 0) - return gs_throw(code, "could not install halftone"); - - code = gs_sethalftonephase(ctx->pgs, 0, 0); - if (code < 0) - return gs_throw(code, "could not set halftone phase"); + ht.type = ht_type_threshold; + ht.params.threshold.width = width; + ht.params.threshold.height = height; + ht.params.threshold.thresholds.data = thresh.data; + ht.params.threshold.thresholds.size = thresh.size; + ht.params.threshold.transfer = 0; + ht.params.threshold.transfer_closure.proc = 0; + + gs_settransfer(ctx->pgs, identity_transfer); + + code = gs_sethalftone(ctx->pgs, &ht); + if (code < 0) + return gs_throw(code, "could not install halftone"); + + code = gs_sethalftonephase(ctx->pgs, 0, 0); + if (code < 0) + return gs_throw(code, "could not set halftone phase"); } return 0; diff --git a/xps/xpsttf.c b/xps/xpsttf.c index fd92b1c70..e6534a0e9 100644 --- a/xps/xpsttf.c +++ b/xps/xpsttf.c @@ -91,8 +91,8 @@ xps_true_callback_string_proc(gs_font_type42 *p42, ulong offset, uint length, co xps_font_t *font = p42->client_data; if (offset < 0 || offset + length > font->length) { - *pdata = NULL; - return gs_throw2(-1, "font data access out of bounds (offset=%lu size=%u)", offset, length); + *pdata = NULL; + return gs_throw2(-1, "font data access out of bounds (offset=%lu size=%u)", offset, length); } *pdata = font->data + offset; return 0; @@ -108,7 +108,7 @@ xps_true_callback_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t spc) xps_last_char = chr; /* save the char we're encoding for the decode_glyph hack */ value = xps_encode_font_char(font, chr); if (value == 0) - return gs_no_glyph; + return gs_no_glyph; return value; } @@ -138,31 +138,31 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps /* guess if the font type is not truetype */ if ( pfont->FontType != ft_TrueType ) { - glyph -= 29; - if ( glyph >= 0 && glyph < 258 ) - { - pstr->data = (byte*) pl_mac_names[glyph]; - pstr->size = strlen((char*)pstr->data); - return 0; - } - else - { - return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph); - } + glyph -= 29; + if ( glyph >= 0 && glyph < 258 ) + { + pstr->data = (byte*) pl_mac_names[glyph]; + pstr->size = strlen((char*)pstr->data); + return 0; + } + else + { + return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph); + } } table_offset = xps_find_sfnt_table((xps_font_t*)pfont->client_data, "post", &table_length); /* no post table */ if (table_offset < 0) - return gs_throw(-1, "no post table"); + return gs_throw(-1, "no post table"); /* this shoudn't happen but... */ if ( table_length == 0 ) - return gs_throw(-1, "zero-size post table"); + return gs_throw(-1, "zero-size post table"); ((gs_font_type42 *)pfont)->data.string_proc((gs_font_type42 *)pfont, - table_offset, table_length, &postp); + table_offset, table_length, &postp); format = u32(postp); /* Format 1.0 (mac encoding) is a simple table see the TT spec. @@ -174,19 +174,19 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps */ if ( format != 0x20000 ) { - /* Invent a name if we don't know the table format. */ - char buf[16]; - sprintf(buf, "glyph%d", (int)glyph); - pstr->data = (byte*)buf; - pstr->size = strlen((char*)pstr->data); - return 0; + /* Invent a name if we don't know the table format. */ + char buf[16]; + sprintf(buf, "glyph%d", (int)glyph); + pstr->data = (byte*)buf; + pstr->size = strlen((char*)pstr->data); + return 0; } /* skip over the post header */ numGlyphs = u16(postp + 32); if ( glyph < 0 || glyph > numGlyphs - 1) { - return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph); + return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph); } /* glyph name index starts at post + 34 each entry is 2 bytes */ @@ -194,65 +194,65 @@ xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *ps /* this shouldn't happen */ if ( glyph_name_index < 0 && glyph_name_index > 0x7fff ) - return gs_throw(-1, "post table format error"); + return gs_throw(-1, "post table format error"); /* mac easy */ if ( glyph_name_index < 258 ) { - // dprintf2("glyph name (mac) %d = %s\n", glyph, pl_mac_names[glyph_name_index]); - pstr->data = (byte*) pl_mac_names[glyph_name_index]; - pstr->size = strlen((char*)pstr->data); - return 0; + // dprintf2("glyph name (mac) %d = %s\n", glyph, pl_mac_names[glyph_name_index]); + pstr->data = (byte*) pl_mac_names[glyph_name_index]; + pstr->size = strlen((char*)pstr->data); + return 0; } /* not mac */ else { - byte *mydata; + byte *mydata; - /* and here's the tricky part */ - const byte *pascal_stringp = postp + 34 + (numGlyphs * 2); + /* and here's the tricky part */ + const byte *pascal_stringp = postp + 34 + (numGlyphs * 2); - /* 0 - 257 lives in the mac table above */ - glyph_name_index -= 258; + /* 0 - 257 lives in the mac table above */ + glyph_name_index -= 258; - /* The string we want is the index'th pascal string, - so we "hop" to each length byte "index" times. */ - while (glyph_name_index > 0) - { - pascal_stringp += ((int)(*pascal_stringp)+1); - glyph_name_index--; - } + /* The string we want is the index'th pascal string, + so we "hop" to each length byte "index" times. */ + while (glyph_name_index > 0) + { + pascal_stringp += ((int)(*pascal_stringp)+1); + glyph_name_index--; + } - /* length byte */ - pstr->size = (int)(*pascal_stringp); + /* length byte */ + pstr->size = (int)(*pascal_stringp); - /* + 1 is for the length byte */ - pstr->data = pascal_stringp + 1; + /* + 1 is for the length byte */ + pstr->data = pascal_stringp + 1; - /* sanity check */ - if ( pstr->data + pstr->size > postp + table_length || pstr->data - 1 < postp) - return gs_throw(-1, "data out of range"); + /* sanity check */ + if ( pstr->data + pstr->size > postp + table_length || pstr->data - 1 < postp) + return gs_throw(-1, "data out of range"); - /* sigh - we have to allocate a copy of the data - by the - time a high level device makes use of it the font data - may be freed. This is a necessary leak. */ - mydata = gs_alloc_bytes(pfont->memory, pstr->size + 1, "glyph to name"); - if ( mydata == 0 ) - return -1; - memcpy(mydata, pascal_stringp + 1, pstr->size); - pstr->data = mydata; + /* sigh - we have to allocate a copy of the data - by the + time a high level device makes use of it the font data + may be freed. This is a necessary leak. */ + mydata = gs_alloc_bytes(pfont->memory, pstr->size + 1, "glyph to name"); + if ( mydata == 0 ) + return -1; + memcpy(mydata, pascal_stringp + 1, pstr->size); + pstr->data = mydata; - mydata[pstr->size] = 0; - // dprintf2("glyph name (tbl) %d = %s\n", glyph, pstr->data); + mydata[pstr->size] = 0; + // dprintf2("glyph name (tbl) %d = %s\n", glyph, pstr->data); - return 0; + return 0; } } static int xps_true_callback_build_char(gs_show_enum *penum, gs_state *pgs, gs_font *pfont, - gs_char chr, gs_glyph glyph) + gs_char chr, gs_glyph glyph) { gs_font_type42 *p42 = (gs_font_type42*)pfont; const gs_rect *pbbox; @@ -264,7 +264,7 @@ xps_true_callback_build_char(gs_show_enum *penum, gs_state *pgs, gs_font *pfont, code = gs_type42_get_metrics(p42, glyph, sbw); if (code < 0) - return code; + return code; w2[0] = sbw[2]; w2[1] = sbw[3]; @@ -278,33 +278,33 @@ xps_true_callback_build_char(gs_show_enum *penum, gs_state *pgs, gs_font *pfont, /* Expand the bbox when stroking */ if ( pfont->PaintType ) { - float expand = max(1.415, gs_currentmiterlimit(pgs)) * gs_currentlinewidth(pgs) / 2; - w2[2] -= expand, w2[3] -= expand; - w2[4] += expand, w2[5] += expand; + float expand = max(1.415, gs_currentmiterlimit(pgs)) * gs_currentlinewidth(pgs) / 2; + w2[2] -= expand, w2[3] -= expand; + w2[4] += expand, w2[5] += expand; } if ( (code = gs_moveto(pgs, 0.0, 0.0)) < 0 ) - return code; + return code; if ( (code = gs_setcachedevice(penum, pgs, w2)) < 0 ) - return code; + return code; code = gs_type42_append(glyph, pgs, - gx_current_path(pgs), - (gs_text_enum_t*)penum, (gs_font*)p42, - gs_show_in_charpath(penum) != cpm_show); + gx_current_path(pgs), + (gs_text_enum_t*)penum, (gs_font*)p42, + gs_show_in_charpath(penum) != cpm_show); if (code < 0) - return code; + return code; /* Indicate that dropout prevention should be enabled by setting - fill_adjust to the special value -1. */ + fill_adjust to the special value -1. */ saved_adjust = pgs->fill_adjust; pgs->fill_adjust.x = -1; pgs->fill_adjust.y = -1; code = (pfont->PaintType ? gs_stroke(pgs) : gs_fill(pgs)); if (code < 0) - return code; + return code; pgs->fill_adjust = saved_adjust; @@ -320,84 +320,84 @@ int xps_init_truetype_font(xps_context_t *ctx, xps_font_t *font) { font->font = (void*) gs_alloc_struct(ctx->memory, gs_font_type42, &st_gs_font_type42, "xps_font type42"); if (!font->font) - return gs_throw(-1, "out of memory"); + return gs_throw(-1, "out of memory"); /* no shortage of things to initialize */ { - gs_font_type42 *p42 = (gs_font_type42*) font->font; - - /* Common to all fonts: */ - - p42->next = 0; - p42->prev = 0; - p42->memory = ctx->memory; - - p42->dir = ctx->fontdir; /* NB also set by gs_definefont later */ - p42->base = font->font; /* NB also set by gs_definefont later */ - p42->is_resource = false; - gs_notify_init(&p42->notify_list, gs_memory_stable(ctx->memory)); - p42->id = gs_next_ids(ctx->memory, 1); - - p42->client_data = font; /* that's us */ - - /* this is overwritten in grid_fit() */ - gs_make_identity(&p42->FontMatrix); - gs_make_identity(&p42->orig_FontMatrix); /* NB ... original or zeroes? */ - - p42->FontType = ft_TrueType; - p42->BitmapWidths = false; - p42->ExactSize = fbit_use_outlines; - p42->InBetweenSize = fbit_use_outlines; - p42->TransformedChar = fbit_use_outlines; - p42->WMode = 0; - p42->PaintType = 0; - p42->StrokeWidth = 0; - p42->is_cached = 0; - - p42->procs.define_font = gs_no_define_font; - p42->procs.make_font = gs_no_make_font; - p42->procs.font_info = gs_type42_font_info; - p42->procs.same_font = gs_default_same_font; - p42->procs.encode_char = xps_true_callback_encode_char; - p42->procs.decode_glyph = xps_true_callback_decode_glyph; - p42->procs.enumerate_glyph = gs_type42_enumerate_glyph; - p42->procs.glyph_info = gs_type42_glyph_info; - p42->procs.glyph_outline = gs_type42_glyph_outline; - p42->procs.glyph_name = xps_true_callback_glyph_name; - p42->procs.init_fstack = gs_default_init_fstack; - p42->procs.next_char_glyph = gs_default_next_char_glyph; - p42->procs.build_char = xps_true_callback_build_char; - - memset(p42->font_name.chars, 0, sizeof(p42->font_name.chars)); - xps_load_sfnt_name(font, (char*)p42->font_name.chars); - p42->font_name.size = strlen((char*)p42->font_name.chars); - - memset(p42->key_name.chars, 0, sizeof(p42->key_name.chars)); - strcpy((char*)p42->key_name.chars, (char*)p42->font_name.chars); - p42->key_name.size = strlen((char*)p42->key_name.chars); - - /* Base font specific: */ - - p42->FontBBox.p.x = 0; - p42->FontBBox.p.y = 0; - p42->FontBBox.q.x = 0; - p42->FontBBox.q.y = 0; - - uid_set_UniqueID(&p42->UID, p42->id); - - p42->encoding_index = ENCODING_INDEX_UNKNOWN; - p42->nearest_encoding_index = ENCODING_INDEX_ISOLATIN1; - - p42->FAPI = 0; - p42->FAPI_font_data = 0; - - /* Type 42 specific: */ - - p42->data.string_proc = xps_true_callback_string_proc; - p42->data.proc_data = font; - - gs_type42_font_init(p42, font->subfontid); - p42->data.get_glyph_index = xps_true_get_glyph_index; + gs_font_type42 *p42 = (gs_font_type42*) font->font; + + /* Common to all fonts: */ + + p42->next = 0; + p42->prev = 0; + p42->memory = ctx->memory; + + p42->dir = ctx->fontdir; /* NB also set by gs_definefont later */ + p42->base = font->font; /* NB also set by gs_definefont later */ + p42->is_resource = false; + gs_notify_init(&p42->notify_list, gs_memory_stable(ctx->memory)); + p42->id = gs_next_ids(ctx->memory, 1); + + p42->client_data = font; /* that's us */ + + /* this is overwritten in grid_fit() */ + gs_make_identity(&p42->FontMatrix); + gs_make_identity(&p42->orig_FontMatrix); /* NB ... original or zeroes? */ + + p42->FontType = ft_TrueType; + p42->BitmapWidths = false; + p42->ExactSize = fbit_use_outlines; + p42->InBetweenSize = fbit_use_outlines; + p42->TransformedChar = fbit_use_outlines; + p42->WMode = 0; + p42->PaintType = 0; + p42->StrokeWidth = 0; + p42->is_cached = 0; + + p42->procs.define_font = gs_no_define_font; + p42->procs.make_font = gs_no_make_font; + p42->procs.font_info = gs_type42_font_info; + p42->procs.same_font = gs_default_same_font; + p42->procs.encode_char = xps_true_callback_encode_char; + p42->procs.decode_glyph = xps_true_callback_decode_glyph; + p42->procs.enumerate_glyph = gs_type42_enumerate_glyph; + p42->procs.glyph_info = gs_type42_glyph_info; + p42->procs.glyph_outline = gs_type42_glyph_outline; + p42->procs.glyph_name = xps_true_callback_glyph_name; + p42->procs.init_fstack = gs_default_init_fstack; + p42->procs.next_char_glyph = gs_default_next_char_glyph; + p42->procs.build_char = xps_true_callback_build_char; + + memset(p42->font_name.chars, 0, sizeof(p42->font_name.chars)); + xps_load_sfnt_name(font, (char*)p42->font_name.chars); + p42->font_name.size = strlen((char*)p42->font_name.chars); + + memset(p42->key_name.chars, 0, sizeof(p42->key_name.chars)); + strcpy((char*)p42->key_name.chars, (char*)p42->font_name.chars); + p42->key_name.size = strlen((char*)p42->key_name.chars); + + /* Base font specific: */ + + p42->FontBBox.p.x = 0; + p42->FontBBox.p.y = 0; + p42->FontBBox.q.x = 0; + p42->FontBBox.q.y = 0; + + uid_set_UniqueID(&p42->UID, p42->id); + + p42->encoding_index = ENCODING_INDEX_UNKNOWN; + p42->nearest_encoding_index = ENCODING_INDEX_ISOLATIN1; + + p42->FAPI = 0; + p42->FAPI_font_data = 0; + + /* Type 42 specific: */ + + p42->data.string_proc = xps_true_callback_string_proc; + p42->data.proc_data = font; + + gs_type42_font_init(p42, font->subfontid); + p42->data.get_glyph_index = xps_true_get_glyph_index; } gs_definefont(ctx->fontdir, font->font); diff --git a/xps/xpsutf.c b/xps/xpsutf.c index 76af7a653..d20fd391a 100644 --- a/xps/xpsutf.c +++ b/xps/xpsutf.c @@ -24,42 +24,42 @@ int xps_utf8_to_ucs(int *p, const char *ss, int n) unsigned char *s = (unsigned char *)ss; if (s == NULL) - goto bad; + goto bad; if ((s[0] & 0x80) == 0) { - *p = (s[0] & 0x7f); - return 1; + *p = (s[0] & 0x7f); + return 1; } if ((s[0] & 0xe0) == 0xc0) { - if (n < 2 || s[1] < 0x80) - goto bad; - *p = (s[0] & 0x1f) << 6; - *p |= (s[1] & 0x3f); - return 2; + if (n < 2 || s[1] < 0x80) + goto bad; + *p = (s[0] & 0x1f) << 6; + *p |= (s[1] & 0x3f); + return 2; } if ((s[0] & 0xf0) == 0xe0) { - if (n < 3 || s[1] < 0x80 || s[2] < 0x80) - goto bad; - *p = (s[0] & 0x0f) << 12; - *p |= (s[1] & 0x3f) << 6; - *p |= (s[2] & 0x3f); - return 3; + if (n < 3 || s[1] < 0x80 || s[2] < 0x80) + goto bad; + *p = (s[0] & 0x0f) << 12; + *p |= (s[1] & 0x3f) << 6; + *p |= (s[2] & 0x3f); + return 3; } if ((s[0] & 0xf8) == 0xf0) { - if (n < 4 || s[1] < 0x80 || s[2] < 0x80 || s[3] < 0x80) - goto bad; - *p = (s[0] & 0x07) << 18; - *p |= (s[1] & 0x3f) << 12; - *p |= (s[2] & 0x3f) << 6; - *p |= (s[3] & 0x3f); - return 4; + if (n < 4 || s[1] < 0x80 || s[2] < 0x80 || s[3] < 0x80) + goto bad; + *p = (s[0] & 0x07) << 18; + *p |= (s[1] & 0x3f) << 12; + *p |= (s[2] & 0x3f) << 6; + *p |= (s[3] & 0x3f); + return 4; } bad: diff --git a/xps/xpsvisual.c b/xps/xpsvisual.c index 5f73628eb..727e60d1c 100644 --- a/xps/xpsvisual.c +++ b/xps/xpsvisual.c @@ -43,8 +43,8 @@ xps_parse_visual_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, for (node = xps_down(root); node; node = xps_next(node)) { - if (!strcmp(xps_tag(node), "VisualBrush.Visual")) - visual_tag = xps_down(node); + if (!strcmp(xps_tag(node), "VisualBrush.Visual")) + visual_tag = xps_down(node); } visual_uri = base_uri; @@ -52,7 +52,7 @@ xps_parse_visual_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, if (visual_tag) { - xps_parse_tiling_brush(ctx, visual_uri, dict, root, xps_paint_visual_brush, visual_tag); + xps_parse_tiling_brush(ctx, visual_uri, dict, root, xps_paint_visual_brush, visual_tag); } return 0; diff --git a/xps/xpsxml.c b/xps/xpsxml.c index 956066018..4f23870c8 100644 --- a/xps/xpsxml.c +++ b/xps/xpsxml.c @@ -47,7 +47,7 @@ static char *skip_namespace(char *s) { char *p = strchr(s, ' '); if (p) - return p + 1; + return p + 1; return s; } @@ -64,7 +64,7 @@ static void on_open_tag(void *zp, char *ns_name, char **atts) int i; if (parser->error) - return; + return; /* check namespace */ @@ -73,20 +73,20 @@ static void on_open_tag(void *zp, char *ns_name, char **atts) p = strstr(ns_name, NS_XPS); if (p == ns_name) { - name = strchr(ns_name, ' ') + 1; + name = strchr(ns_name, ' ') + 1; } p = strstr(ns_name, NS_MC); if (p == ns_name) { - name = strchr(ns_name, ' ') + 1; - parser->compat = 1; + name = strchr(ns_name, ' ') + 1; + parser->compat = 1; } if (!name) { - dprintf1("unknown namespace: %s\n", ns_name); - name = ns_name; + dprintf1("unknown namespace: %s\n", ns_name); + name = ns_name; } /* count size to alloc */ @@ -96,17 +96,17 @@ static void on_open_tag(void *zp, char *ns_name, char **atts) textlen = 0; for (i = 0; atts[i]; i++) { - attslen += sizeof(char*); - if ((i & 1) == 0) - textlen += strlen(skip_namespace(atts[i])) + 1; - else - textlen += strlen(atts[i]) + 1; + attslen += sizeof(char*); + if ((i & 1) == 0) + textlen += strlen(skip_namespace(atts[i])) + 1; + else + textlen += strlen(atts[i]) + 1; } item = xps_alloc(ctx, sizeof(xps_item_t) + attslen + namelen + textlen); if (!item) { - parser->error = "out of memory"; + parser->error = "out of memory"; } /* copy strings to new memory */ @@ -118,12 +118,12 @@ static void on_open_tag(void *zp, char *ns_name, char **atts) strcpy(item->name, name); for (i = 0; atts[i]; i++) { - item->atts[i] = p; - if ((i & 1) == 0) - strcpy(item->atts[i], skip_namespace(atts[i])); - else - strcpy(item->atts[i], atts[i]); - p += strlen(p) + 1; + item->atts[i] = p; + if ((i & 1) == 0) + strcpy(item->atts[i], skip_namespace(atts[i])); + else + strcpy(item->atts[i], atts[i]); + p += strlen(p) + 1; } item->atts[i] = 0; @@ -136,21 +136,21 @@ static void on_open_tag(void *zp, char *ns_name, char **atts) if (!parser->head) { - parser->root = item; - parser->head = item; - return; + parser->root = item; + parser->head = item; + return; } if (!parser->head->down) { - parser->head->down = item; - parser->head = item; - return; + parser->head->down = item; + parser->head = item; + return; } tail = parser->head->down; while (tail->next) - tail = tail->next; + tail = tail->next; tail->next = item; parser->head = item; } @@ -160,10 +160,10 @@ static void on_close_tag(void *zp, char *name) xps_parser_t *parser = zp; if (parser->error) - return; + return; if (parser->head) - parser->head = parser->head->up; + parser->head = parser->head->up; } static inline int is_xml_space(int c) @@ -179,30 +179,30 @@ static void on_text(void *zp, char *buf, int len) int i; if (parser->error) - return; + return; for (i = 0; i < len; i++) { - if (!is_xml_space(buf[i])) - { - char *tmp = xps_alloc(ctx, len + 1); - if (!tmp) - { - parser->error = "out of memory"; - return; - } - - atts[0] = ""; - atts[1] = tmp; - atts[2] = NULL; - - memcpy(tmp, buf, len); - tmp[len] = 0; - on_open_tag(zp, "", atts); - on_close_tag(zp, ""); - xps_free(ctx, tmp); - return; - } + if (!is_xml_space(buf[i])) + { + char *tmp = xps_alloc(ctx, len + 1); + if (!tmp) + { + parser->error = "out of memory"; + return; + } + + atts[0] = ""; + atts[1] = tmp; + atts[2] = NULL; + + memcpy(tmp, buf, len); + tmp[len] = 0; + on_open_tag(zp, "", atts); + on_close_tag(zp, ""); + xps_free(ctx, tmp); + return; + } } } @@ -229,8 +229,8 @@ xps_parse_xml(xps_context_t *ctx, byte *buf, int len) xp = XML_ParserCreateNS(NULL, ' '); if (!xp) { - gs_throw(-1, "xml error: could not create expat parser"); - return NULL; + gs_throw(-1, "xml error: could not create expat parser"); + return NULL; } XML_SetUserData(xp, &parser); @@ -242,17 +242,17 @@ xps_parse_xml(xps_context_t *ctx, byte *buf, int len) code = XML_Parse(xp, (char*)buf, len, 1); if (code == 0) { - if (parser.root) - xps_free_item(ctx, parser.root); - XML_ParserFree(xp); - gs_throw1(-1, "xml error: %s", XML_ErrorString(XML_GetErrorCode(xp))); - return NULL; + if (parser.root) + xps_free_item(ctx, parser.root); + XML_ParserFree(xp); + gs_throw1(-1, "xml error: %s", XML_ErrorString(XML_GetErrorCode(xp))); + return NULL; } XML_ParserFree(xp); if (parser.compat) - xps_process_compatibility(ctx, parser.root); + xps_process_compatibility(ctx, parser.root); return parser.root; } @@ -280,8 +280,8 @@ xps_att(xps_item_t *item, char *att) { int i; for (i = 0; item->atts[i]; i += 2) - if (!strcmp(item->atts[i], att)) - return item->atts[i + 1]; + if (!strcmp(item->atts[i], att)) + return item->atts[i + 1]; return NULL; } @@ -291,18 +291,18 @@ xps_free_item(xps_context_t *ctx, xps_item_t *item) xps_item_t *next; while (item) { - next = item->next; - if (item->down) - xps_free_item(ctx, item->down); - xps_free(ctx, item); - item = next; + next = item->next; + if (item->down) + xps_free_item(ctx, item->down); + xps_free(ctx, item); + item = next; } } static void indent(int n) { while (n--) - printf(" "); + printf(" "); } /* forward prototype for recursion */ @@ -315,32 +315,32 @@ xps_debug_item_imp(xps_item_t *item, int level, int loop) while (item) { - indent(level); - - if (strlen(item->name) == 0) - printf("%s\n", item->atts[1]); - else - { - printf("<%s", item->name); - - for (i = 0; item->atts[i]; i += 2) - printf(" %s=\"%s\"", item->atts[i], item->atts[i+1]); - - if (item->down) - { - printf(">\n"); - xps_debug_item_imp(item->down, level + 1, 1); - indent(level); - printf("</%s>\n", item->name); - } - else - printf(" />\n"); - } - - item = item->next; - - if (!loop) - return; + indent(level); + + if (strlen(item->name) == 0) + printf("%s\n", item->atts[1]); + else + { + printf("<%s", item->name); + + for (i = 0; item->atts[i]; i += 2) + printf(" %s=\"%s\"", item->atts[i], item->atts[i+1]); + + if (item->down) + { + printf(">\n"); + xps_debug_item_imp(item->down, level + 1, 1); + indent(level); + printf("</%s>\n", item->name); + } + else + printf(" />\n"); + } + + item = item->next; + + if (!loop) + return; } } diff --git a/xps/xpszip.c b/xps/xpszip.c index a61c9d13a..1c9970dce 100644 --- a/xps/xpszip.c +++ b/xps/xpszip.c @@ -35,7 +35,7 @@ static inline int read1(xps_context_t *ctx, stream_cursor_read *buf) { if (buf->ptr >= buf->limit) - return -1; + return -1; buf->ptr++; return *buf->ptr; } @@ -70,7 +70,7 @@ static inline void readall(xps_context_t *ctx, stream_cursor_read *buf, byte *str, int n) { while (n--) - *str++ = read1(ctx, buf); + *str++ = read1(ctx, buf); } static void * @@ -98,26 +98,26 @@ xps_validate_resources(xps_context_t *ctx, xps_part_t *part) for (rel = part->relations; rel; rel = rel->next) { - if (!strcmp(rel->type, REL_REQUIRED_RESOURCE_RECURSIVE)) - { - subpart = xps_find_part(ctx, rel->target); - if (!subpart || !subpart->complete) - return 0; - if (!subpart->relations_complete) - { - xps_parse_content_relations(ctx, subpart); - subpart->relations_complete = 1; - } - if (!xps_validate_resources(ctx, subpart)) - return 0; - } - - if (!strcmp(rel->type, REL_REQUIRED_RESOURCE)) - { - subpart = xps_find_part(ctx, rel->target); - if (!subpart || !subpart->complete) - return 0; - } + if (!strcmp(rel->type, REL_REQUIRED_RESOURCE_RECURSIVE)) + { + subpart = xps_find_part(ctx, rel->target); + if (!subpart || !subpart->complete) + return 0; + if (!subpart->relations_complete) + { + xps_parse_content_relations(ctx, subpart); + subpart->relations_complete = 1; + } + if (!xps_validate_resources(ctx, subpart)) + return 0; + } + + if (!strcmp(rel->type, REL_REQUIRED_RESOURCE)) + { + subpart = xps_find_part(ctx, rel->target); + if (!subpart || !subpart->complete) + return 0; + } } return 1; @@ -151,7 +151,7 @@ xps_process_part(xps_context_t *ctx, xps_part_t *part) xps_document_t *fixdoc; if (xps_doc_trace && part->complete) - dprintf2("doc: found part %s %s\n", part->name, part->complete ? "" : "(piece)"); + dprintf2("doc: found part %s %s\n", part->name, part->complete ? "" : "(piece)"); /* * This is a magic Open Packaging Convention name. @@ -159,19 +159,19 @@ xps_process_part(xps_context_t *ctx, xps_part_t *part) if (strstr(part->name, "_rels/")) { - xps_parse_metadata(ctx, part); - - if (part->complete) - { - char realname[1024]; - xps_part_t *realpart; - xps_part_name_from_relation_part_name(realname, part->name); - realpart = xps_find_part(ctx, realname); - if (realpart) - { - realpart->relations_complete = 1; - } - } + xps_parse_metadata(ctx, part); + + if (part->complete) + { + char realname[1024]; + xps_part_t *realpart; + xps_part_name_from_relation_part_name(realname, part->name); + realpart = xps_find_part(ctx, realname); + if (realpart) + { + realpart->relations_complete = 1; + } + } } /* TODO: DiscardControl parts. @@ -188,28 +188,28 @@ xps_process_part(xps_context_t *ctx, xps_part_t *part) if (!ctx->start_part) { - xps_part_t *rootpart; - rootpart = xps_find_part(ctx, "/"); - if (rootpart) - { - xps_relation_t *rel; - for (rel = rootpart->relations; rel; rel = rel->next) - { - if (!strcmp(rel->type, REL_START_PART)) - { - xps_part_t *startpart; - - ctx->start_part = rel->target; - - if (xps_doc_trace) - dprintf1("doc: adding fixdocseq %s\n", ctx->start_part); - - startpart = xps_find_part(ctx, rel->target); - if (startpart) - xps_parse_metadata(ctx, startpart); - } - } - } + xps_part_t *rootpart; + rootpart = xps_find_part(ctx, "/"); + if (rootpart) + { + xps_relation_t *rel; + for (rel = rootpart->relations; rel; rel = rel->next) + { + if (!strcmp(rel->type, REL_START_PART)) + { + xps_part_t *startpart; + + ctx->start_part = rel->target; + + if (xps_doc_trace) + dprintf1("doc: adding fixdocseq %s\n", ctx->start_part); + + startpart = xps_find_part(ctx, rel->target); + if (startpart) + xps_parse_metadata(ctx, startpart); + } + } + } } /* @@ -219,10 +219,10 @@ xps_process_part(xps_context_t *ctx, xps_part_t *part) if (ctx->start_part) { - if (!strcmp(part->name, ctx->start_part)) - { - xps_parse_metadata(ctx, part); - } + if (!strcmp(part->name, ctx->start_part)) + { + xps_parse_metadata(ctx, part); + } } /* @@ -232,13 +232,13 @@ xps_process_part(xps_context_t *ctx, xps_part_t *part) for (fixdoc = ctx->first_fixdoc; fixdoc; fixdoc = fixdoc->next) { - xps_part_t *fixdocpart = xps_find_part(ctx, fixdoc->name); - if (fixdocpart) - { - xps_parse_metadata(ctx, fixdocpart); - if (!fixdocpart->complete) - break; /* incomplete fixdocpart, try parsing more later */ - } + xps_part_t *fixdocpart = xps_find_part(ctx, fixdoc->name); + if (fixdocpart) + { + xps_parse_metadata(ctx, fixdocpart); + if (!fixdocpart->complete) + break; /* incomplete fixdocpart, try parsing more later */ + } } /* @@ -249,30 +249,30 @@ xps_process_part(xps_context_t *ctx, xps_part_t *part) while (ctx->next_page) { - xps_part_t *pagepart = xps_find_part(ctx, ctx->next_page->name); - if (pagepart && pagepart->complete) - { - if (!pagepart->relations_complete) - { - xps_parse_content_relations(ctx, pagepart); - pagepart->relations_complete = 1; - } - - if (xps_validate_resources(ctx, pagepart)) - { - int code = xps_parse_fixed_page(ctx, pagepart); - if (code < 0) - return code; - - ctx->next_page = ctx->next_page->next; - - xps_free_used_parts(ctx); - - continue; - } - } - - break; + xps_part_t *pagepart = xps_find_part(ctx, ctx->next_page->name); + if (pagepart && pagepart->complete) + { + if (!pagepart->relations_complete) + { + xps_parse_content_relations(ctx, pagepart); + pagepart->relations_complete = 1; + } + + if (xps_validate_resources(ctx, pagepart)) + { + int code = xps_parse_fixed_page(ctx, pagepart); + if (code < 0) + return code; + + ctx->next_page = ctx->next_page->next; + + xps_free_used_parts(ctx); + + continue; + } + } + + break; } return 0; @@ -294,47 +294,47 @@ xps_prepare_part(xps_context_t *ctx) if (strstr(ctx->zip_file_name, ".piece")) { - piece = 1; - if (strstr(ctx->zip_file_name, ".last.piece")) - last_piece = 1; - else - last_piece = 0; + piece = 1; + if (strstr(ctx->zip_file_name, ".last.piece")) + last_piece = 1; + else + last_piece = 0; } else { - piece = 0; - last_piece = 1; + piece = 0; + last_piece = 1; } if (piece) { - char *p = strrchr(ctx->zip_file_name, '/'); - if (p) - *p = 0; + char *p = strrchr(ctx->zip_file_name, '/'); + if (p) + *p = 0; } part = xps_find_part(ctx, ctx->zip_file_name); if (!part) { - part = xps_new_part(ctx, ctx->zip_file_name, ctx->zip_uncompressed_size); - if (!part) - return gs_rethrow(-1, "cannot create part buffer"); + part = xps_new_part(ctx, ctx->zip_file_name, ctx->zip_uncompressed_size); + if (!part) + return gs_rethrow(-1, "cannot create part buffer"); - ctx->current_part = part; /* make it the current part */ + ctx->current_part = part; /* make it the current part */ } else { - part->interleave = part->size; /* save where this interleaved part starts for checksums */ + part->interleave = part->size; /* save where this interleaved part starts for checksums */ - if (ctx->zip_uncompressed_size != 0) - { - part->capacity = part->size + ctx->zip_uncompressed_size; /* grow to exact size */ - part->data = xps_realloc(ctx, part->data, part->capacity); - if (!part->data) - return gs_throw(-1, "cannot extend part buffer"); - } + if (ctx->zip_uncompressed_size != 0) + { + part->capacity = part->size + ctx->zip_uncompressed_size; /* grow to exact size */ + part->data = xps_realloc(ctx, part->data, part->capacity); + if (!part->data) + return gs_throw(-1, "cannot extend part buffer"); + } - ctx->current_part = part; + ctx->current_part = part; } ctx->current_part->complete = last_piece; @@ -342,32 +342,32 @@ xps_prepare_part(xps_context_t *ctx) /* init decompression */ if (ctx->zip_method == 8) { - memset(&ctx->zip_stream, 0, sizeof(z_stream)); - ctx->zip_stream.zalloc = (alloc_func)xps_zip_alloc_items; - ctx->zip_stream.zfree = (free_func)xps_zip_free; - ctx->zip_stream.opaque = ctx; - - code = inflateInit2(&ctx->zip_stream, -15); - if (code != Z_OK) - return gs_throw1(-1, "cannot inflateInit2(): %d", code); - return 0; + memset(&ctx->zip_stream, 0, sizeof(z_stream)); + ctx->zip_stream.zalloc = (alloc_func)xps_zip_alloc_items; + ctx->zip_stream.zfree = (free_func)xps_zip_free; + ctx->zip_stream.opaque = ctx; + + code = inflateInit2(&ctx->zip_stream, -15); + if (code != Z_OK) + return gs_throw1(-1, "cannot inflateInit2(): %d", code); + return 0; } else if (ctx->zip_method == 0) { - return 0; + return 0; } else { - return gs_throw(-1, "unknown compression method"); + return gs_throw(-1, "unknown compression method"); } } /* * Call zlib to decompress the ZIP entry data. * Return values: - * -1 = fail - * 0 = need more data - * 1 = finished + * -1 = fail + * 0 = need more data + * 1 = finished */ static int @@ -382,119 +382,119 @@ xps_process_part_data(xps_context_t *ctx, stream_cursor_read *buf) if (ctx->zip_method == 8) { - if (part->size >= part->capacity) - { - /* dprintf2("growing buffer (%d/%d)\n", part->size, part->capacity); */ - part->capacity += 8192; - part->data = xps_realloc(ctx, part->data, part->capacity); - if (!part->data) - return gs_throw(-1, "out of memory"); - } - - ctx->zip_stream.next_in = (byte*) buf->ptr + 1; /* discard const */ - ctx->zip_stream.avail_in = buf->limit - buf->ptr; - ctx->zip_stream.next_out = part->data + part->size; - ctx->zip_stream.avail_out = part->capacity - part->size; - - code = inflate(&ctx->zip_stream, Z_NO_FLUSH); - buf->ptr = ctx->zip_stream.next_in - 1; - part->size = part->capacity - ctx->zip_stream.avail_out; - - if (code == Z_STREAM_END) - { - inflateEnd(&ctx->zip_stream); - return 1; - } - else if (code == Z_OK || code == Z_BUF_ERROR) - { - return 0; - } - else - { - inflateEnd(&ctx->zip_stream); - return gs_throw2(-1, "inflate returned %d (%s)", code, - ctx->zip_stream.msg ? ctx->zip_stream.msg : "no error message"); - } + if (part->size >= part->capacity) + { + /* dprintf2("growing buffer (%d/%d)\n", part->size, part->capacity); */ + part->capacity += 8192; + part->data = xps_realloc(ctx, part->data, part->capacity); + if (!part->data) + return gs_throw(-1, "out of memory"); + } + + ctx->zip_stream.next_in = (byte*) buf->ptr + 1; /* discard const */ + ctx->zip_stream.avail_in = buf->limit - buf->ptr; + ctx->zip_stream.next_out = part->data + part->size; + ctx->zip_stream.avail_out = part->capacity - part->size; + + code = inflate(&ctx->zip_stream, Z_NO_FLUSH); + buf->ptr = ctx->zip_stream.next_in - 1; + part->size = part->capacity - ctx->zip_stream.avail_out; + + if (code == Z_STREAM_END) + { + inflateEnd(&ctx->zip_stream); + return 1; + } + else if (code == Z_OK || code == Z_BUF_ERROR) + { + return 0; + } + else + { + inflateEnd(&ctx->zip_stream); + return gs_throw2(-1, "inflate returned %d (%s)", code, + ctx->zip_stream.msg ? ctx->zip_stream.msg : "no error message"); + } } if (ctx->zip_method == 0 && (ctx->zip_general & 8)) { - /* A stored part with an unknown size. This is a brain damaged file - * allowed by a brain damaged spec and written by a brain damaged company. - */ - - sixteen = ctx->zip_version < 45 ? 16 : 24; - - while (1) - { - if (part->size >= part->capacity) - { - /* dprintf2("growing buffer (%d/%d)\n", part->size, part->capacity); */ - part->capacity += 8192; - part->data = xps_realloc(ctx, part->data, part->capacity); - if (!part->data) - return gs_throw(-1, "out of memory"); - } - - /* A workaround to handle this case is to look for signatures. - * Check the crc32 just to be on the safe side. - */ - - if (part->size >= sixteen) - { - if (scan4(part->data + part->size - sixteen) == ZIP_DATA_DESC_SIG) - { - if (ctx->zip_version < 45) - { - crc32 = scan4(part->data + part->size - 12); - csize = scan4(part->data + part->size - 8); - usize = scan4(part->data + part->size - 4); - } - else - { - crc32 = scan4(part->data + part->size - 20); - csize = scan4(part->data + part->size - 16); - usize = scan4(part->data + part->size - 8); - } - - if (csize == usize && usize == part->size - part->interleave - sixteen) - { - if (crc32 == xps_crc32(0, part->data + part->interleave, - part->size - part->interleave - sixteen)) - { - part->size -= sixteen; - return 1; - } - } - } - } - - code = read1(ctx, buf); - if (code < 0) - return 0; - - part->data[part->size++] = code; - } + /* A stored part with an unknown size. This is a brain damaged file + * allowed by a brain damaged spec and written by a brain damaged company. + */ + + sixteen = ctx->zip_version < 45 ? 16 : 24; + + while (1) + { + if (part->size >= part->capacity) + { + /* dprintf2("growing buffer (%d/%d)\n", part->size, part->capacity); */ + part->capacity += 8192; + part->data = xps_realloc(ctx, part->data, part->capacity); + if (!part->data) + return gs_throw(-1, "out of memory"); + } + + /* A workaround to handle this case is to look for signatures. + * Check the crc32 just to be on the safe side. + */ + + if (part->size >= sixteen) + { + if (scan4(part->data + part->size - sixteen) == ZIP_DATA_DESC_SIG) + { + if (ctx->zip_version < 45) + { + crc32 = scan4(part->data + part->size - 12); + csize = scan4(part->data + part->size - 8); + usize = scan4(part->data + part->size - 4); + } + else + { + crc32 = scan4(part->data + part->size - 20); + csize = scan4(part->data + part->size - 16); + usize = scan4(part->data + part->size - 8); + } + + if (csize == usize && usize == part->size - part->interleave - sixteen) + { + if (crc32 == xps_crc32(0, part->data + part->interleave, + part->size - part->interleave - sixteen)) + { + part->size -= sixteen; + return 1; + } + } + } + } + + code = read1(ctx, buf); + if (code < 0) + return 0; + + part->data[part->size++] = code; + } } else { - /* For stored parts we usually know the size, - * and then capacity is set to the actual size of the data. - */ - - if (ctx->zip_uncompressed_size == 0) - return 1; - - while (part->size < part->capacity) - { - int c = read1(ctx, buf); - if (c < 0) - return 0; - part->data[part->size++] = c; - } - - return 1; + /* For stored parts we usually know the size, + * and then capacity is set to the actual size of the data. + */ + + if (ctx->zip_uncompressed_size == 0) + return 1; + + while (part->size < part->capacity) + { + int c = read1(ctx, buf); + if (c < 0) + return 0; + part->data[part->size++] = c; + } + + return 1; } } @@ -513,134 +513,134 @@ xps_process_data(xps_context_t *ctx, stream_cursor_read *buf) while (1) { - switch (ctx->zip_state) - { - case -1: - /* at the end, or error condition. toss data. */ - buf->ptr = buf->limit; - return 1; - - case 0: /* between parts looking for a signature */ - do - { - if (buf->limit - buf->ptr < 4 + 12) - return 0; - - signature = read4(ctx, buf); - if (signature == ZIP_LOCAL_FILE_SIG) - { - /* do nothing */ - } - else if (signature == ZIP_DATA_DESC_SIG) - { - if (ctx->zip_version >= 45) - { - (void) read4(ctx, buf); /* crc32 */ - (void) read8(ctx, buf); /* csize */ - (void) read8(ctx, buf); /* usize */ - } - else - { - (void) read4(ctx, buf); /* crc32 */ - (void) read4(ctx, buf); /* csize */ - (void) read4(ctx, buf); /* usize */ - } - } - else if (signature == ZIP_CENTRAL_DIRECTORY_SIG) - { - if (xps_zip_trace) - dputs("zip: central directory signature\n"); - ctx->zip_state = -1; - return 0; - } - else - { - if (xps_zip_trace) - dprintf1("zip: unknown signature 0x%x\n", signature); - ctx->zip_state = -1; - return 0; - } - } - while (signature != ZIP_LOCAL_FILE_SIG); - - ctx->zip_state ++; - - case 1: /* local file header */ - { - if (buf->limit - buf->ptr < 26) - return 0; - - ctx->zip_version = read2(ctx, buf); - ctx->zip_general = read2(ctx, buf); - ctx->zip_method = read2(ctx, buf); - (void) read2(ctx, buf); /* file time */ - (void) read2(ctx, buf); /* file date */ - (void) read4(ctx, buf); /* crc32 */ - ctx->zip_compressed_size = read4(ctx, buf); - ctx->zip_uncompressed_size = read4(ctx, buf); - ctx->zip_name_length = read2(ctx, buf); - ctx->zip_extra_length = read2(ctx, buf); - } - ctx->zip_state ++; - - case 2: /* file name */ - { - if (buf->limit - buf->ptr < ctx->zip_name_length) - return 0; - if (ctx->zip_name_length >= sizeof(ctx->zip_file_name) + 2) - return gs_throw(-1, "part name too long"); - ctx->zip_file_name[0] = '/'; - readall(ctx, buf, (byte*)ctx->zip_file_name + 1, ctx->zip_name_length); - ctx->zip_file_name[ctx->zip_name_length + 1] = 0; - - if (xps_zip_trace) - dprintf1("zip: inflating '%s'\n", ctx->zip_file_name + 1); - } - ctx->zip_state ++; - - case 3: /* extra field */ - - /* work around for the fixed size cursor buffer */ - if (ctx->zip_extra_length > buf->limit - buf->ptr) - { - ctx->zip_extra_length -= buf->limit - buf->ptr; - buf->limit = buf->ptr; - } - - if (buf->limit - buf->ptr < ctx->zip_extra_length) - return 0; - buf->ptr += ctx->zip_extra_length; - ctx->zip_state ++; - - /* prepare the correct part for receiving data */ - code = xps_prepare_part(ctx); - if (code < 0) - return gs_throw(-1, "cannot create part"); - - case 4: /* file data */ - - while (ctx->zip_state == 4) - { - code = xps_process_part_data(ctx, buf); - if (code < 0) - return gs_throw(-1, "cannot read part"); - if (code == 0) - return 0; - if (code == 1) - ctx->zip_state ++; - } - - case 5: /* end of part (data descriptor) */ - - ctx->zip_state = 0; - - /* Process contents of part. - * This is the entrance to the real parser. - */ - code = xps_process_part(ctx, ctx->current_part); - if (code < 0) - return gs_rethrow(code, "cannot handle part"); - } + switch (ctx->zip_state) + { + case -1: + /* at the end, or error condition. toss data. */ + buf->ptr = buf->limit; + return 1; + + case 0: /* between parts looking for a signature */ + do + { + if (buf->limit - buf->ptr < 4 + 12) + return 0; + + signature = read4(ctx, buf); + if (signature == ZIP_LOCAL_FILE_SIG) + { + /* do nothing */ + } + else if (signature == ZIP_DATA_DESC_SIG) + { + if (ctx->zip_version >= 45) + { + (void) read4(ctx, buf); /* crc32 */ + (void) read8(ctx, buf); /* csize */ + (void) read8(ctx, buf); /* usize */ + } + else + { + (void) read4(ctx, buf); /* crc32 */ + (void) read4(ctx, buf); /* csize */ + (void) read4(ctx, buf); /* usize */ + } + } + else if (signature == ZIP_CENTRAL_DIRECTORY_SIG) + { + if (xps_zip_trace) + dputs("zip: central directory signature\n"); + ctx->zip_state = -1; + return 0; + } + else + { + if (xps_zip_trace) + dprintf1("zip: unknown signature 0x%x\n", signature); + ctx->zip_state = -1; + return 0; + } + } + while (signature != ZIP_LOCAL_FILE_SIG); + + ctx->zip_state ++; + + case 1: /* local file header */ + { + if (buf->limit - buf->ptr < 26) + return 0; + + ctx->zip_version = read2(ctx, buf); + ctx->zip_general = read2(ctx, buf); + ctx->zip_method = read2(ctx, buf); + (void) read2(ctx, buf); /* file time */ + (void) read2(ctx, buf); /* file date */ + (void) read4(ctx, buf); /* crc32 */ + ctx->zip_compressed_size = read4(ctx, buf); + ctx->zip_uncompressed_size = read4(ctx, buf); + ctx->zip_name_length = read2(ctx, buf); + ctx->zip_extra_length = read2(ctx, buf); + } + ctx->zip_state ++; + + case 2: /* file name */ + { + if (buf->limit - buf->ptr < ctx->zip_name_length) + return 0; + if (ctx->zip_name_length >= sizeof(ctx->zip_file_name) + 2) + return gs_throw(-1, "part name too long"); + ctx->zip_file_name[0] = '/'; + readall(ctx, buf, (byte*)ctx->zip_file_name + 1, ctx->zip_name_length); + ctx->zip_file_name[ctx->zip_name_length + 1] = 0; + + if (xps_zip_trace) + dprintf1("zip: inflating '%s'\n", ctx->zip_file_name + 1); + } + ctx->zip_state ++; + + case 3: /* extra field */ + + /* work around for the fixed size cursor buffer */ + if (ctx->zip_extra_length > buf->limit - buf->ptr) + { + ctx->zip_extra_length -= buf->limit - buf->ptr; + buf->limit = buf->ptr; + } + + if (buf->limit - buf->ptr < ctx->zip_extra_length) + return 0; + buf->ptr += ctx->zip_extra_length; + ctx->zip_state ++; + + /* prepare the correct part for receiving data */ + code = xps_prepare_part(ctx); + if (code < 0) + return gs_throw(-1, "cannot create part"); + + case 4: /* file data */ + + while (ctx->zip_state == 4) + { + code = xps_process_part_data(ctx, buf); + if (code < 0) + return gs_throw(-1, "cannot read part"); + if (code == 0) + return 0; + if (code == 1) + ctx->zip_state ++; + } + + case 5: /* end of part (data descriptor) */ + + ctx->zip_state = 0; + + /* Process contents of part. + * This is the entrance to the real parser. + */ + code = xps_process_part(ctx, ctx->current_part); + if (code < 0) + return gs_rethrow(code, "cannot handle part"); + } } return 0; @@ -650,29 +650,29 @@ int xps_process_end_of_data(xps_context_t *ctx) { if (xps_doc_trace) - dputs("doc: reached end of file; parsing remaining pages\n"); + dputs("doc: reached end of file; parsing remaining pages\n"); while (ctx->next_page) { xps_part_t *pagepart; - pagepart = xps_find_part(ctx, ctx->next_page->name); - if (!pagepart) - dputs(" page part missing\n"); - else if (!pagepart->complete) - dputs(" page part incomplete\n"); - else - { - xps_relation_t *rel; - for (rel = pagepart->relations; rel; rel = rel->next) - { - xps_part_t *subpart = xps_find_part(ctx, rel->target); - if (!subpart) - dprintf1(" resource '%s' missing\n", rel->target); - else if (!subpart->complete) - dprintf1(" resource '%s' incomplete\n", rel->target); - // TODO: recursive resource check... - } - } + pagepart = xps_find_part(ctx, ctx->next_page->name); + if (!pagepart) + dputs(" page part missing\n"); + else if (!pagepart->complete) + dputs(" page part incomplete\n"); + else + { + xps_relation_t *rel; + for (rel = pagepart->relations; rel; rel = rel->next) + { + xps_part_t *subpart = xps_find_part(ctx, rel->target); + if (!subpart) + dprintf1(" resource '%s' missing\n", rel->target); + else if (!subpart->complete) + dprintf1(" resource '%s' incomplete\n", rel->target); + // TODO: recursive resource check... + } + } ctx->next_page = ctx->next_page->next; } diff --git a/xps/xpszipseek.c b/xps/xpszipseek.c index 967724975..2d1be030b 100644 --- a/xps/xpszipseek.c +++ b/xps/xpszipseek.c @@ -58,14 +58,14 @@ xps_find_zip_entry(xps_context_t *ctx, char *name) int r = ctx->zip_count - 1; while (l <= r) { - int m = (l + r) >> 1; - int c = xps_strcasecmp(name, ctx->zip_table[m].name); - if (c < 0) - r = m - 1; - else if (c > 0) - l = m + 1; - else - return &ctx->zip_table[m]; + int m = (l + r) >> 1; + int c = xps_strcasecmp(name, ctx->zip_table[m].name); + if (c < 0) + r = m - 1; + else if (c > 0) + l = m + 1; + else + return &ctx->zip_table[m]; } return NULL; } @@ -81,13 +81,13 @@ xps_inflate_zip_entry(xps_context_t *ctx, xps_entry_t *ent, unsigned char *outbu int code; if (xps_zip_trace) - dprintf1("zip: inflating entry '%s'\n", ent->name); + dprintf1("zip: inflating entry '%s'\n", ent->name); fseek(ctx->file, ent->offset, 0); sig = getlong(ctx->file); if (sig != ZIP_LOCAL_FILE_SIG) - return gs_throw1(-1, "wrong zip local file signature (0x%x)", sig); + return gs_throw1(-1, "wrong zip local file signature (0x%x)", sig); version = getshort(ctx->file); general = getshort(ctx->file); @@ -104,41 +104,41 @@ xps_inflate_zip_entry(xps_context_t *ctx, xps_entry_t *ent, unsigned char *outbu if (method == 0) { - fread(outbuf, 1, ent->usize, ctx->file); + fread(outbuf, 1, ent->usize, ctx->file); } else if (method == 8) { - inbuf = xps_alloc(ctx, ent->csize); - - fread(inbuf, 1, ent->csize, ctx->file); - - memset(&stream, 0, sizeof(z_stream)); - stream.zalloc = (alloc_func) xps_zip_alloc_items; - stream.zfree = (free_func) xps_zip_free; - stream.opaque = ctx; - stream.next_in = inbuf; - stream.avail_in = ent->csize; - stream.next_out = outbuf; - stream.avail_out = ent->usize; - - code = inflateInit2(&stream, -15); - if (code != Z_OK) - return gs_throw1(-1, "zlib inflateInit2 error: %s", stream.msg); - code = inflate(&stream, Z_FINISH); - if (code != Z_STREAM_END) - { - inflateEnd(&stream); - return gs_throw1(-1, "zlib inflate error: %s", stream.msg); - } - code = inflateEnd(&stream); - if (code != Z_OK) - return gs_throw1(-1, "zlib inflateEnd error: %s", stream.msg); - - xps_free(ctx, inbuf); + inbuf = xps_alloc(ctx, ent->csize); + + fread(inbuf, 1, ent->csize, ctx->file); + + memset(&stream, 0, sizeof(z_stream)); + stream.zalloc = (alloc_func) xps_zip_alloc_items; + stream.zfree = (free_func) xps_zip_free; + stream.opaque = ctx; + stream.next_in = inbuf; + stream.avail_in = ent->csize; + stream.next_out = outbuf; + stream.avail_out = ent->usize; + + code = inflateInit2(&stream, -15); + if (code != Z_OK) + return gs_throw1(-1, "zlib inflateInit2 error: %s", stream.msg); + code = inflate(&stream, Z_FINISH); + if (code != Z_STREAM_END) + { + inflateEnd(&stream); + return gs_throw1(-1, "zlib inflate error: %s", stream.msg); + } + code = inflateEnd(&stream); + if (code != Z_OK) + return gs_throw1(-1, "zlib inflateEnd error: %s", stream.msg); + + xps_free(ctx, inbuf); } else { - return gs_throw1(-1, "unknown compression method (%d)", method); + return gs_throw1(-1, "unknown compression method (%d)", method); } return gs_okay; @@ -157,29 +157,29 @@ xps_read_zip_entry(xps_context_t *ctx, char *name, xps_entry_t *ent) part = xps_find_part(ctx, buf); if (!part) { - part = xps_new_part(ctx, buf, ent->usize); - if (!part) - { - gs_rethrow1(-1, "cannot create part for zip entry '%s'", name); - return NULL; - } + part = xps_new_part(ctx, buf, ent->usize); + if (!part) + { + gs_rethrow1(-1, "cannot create part for zip entry '%s'", name); + return NULL; + } } if (part->capacity < ent->usize) { - part->data = xps_realloc(ctx, part->data, ent->usize); - if (!part->data) - { - gs_throw(-1, "cannot extend part buffer"); - return NULL; - } + part->data = xps_realloc(ctx, part->data, ent->usize); + if (!part->data) + { + gs_throw(-1, "cannot extend part buffer"); + return NULL; + } } code = xps_inflate_zip_entry(ctx, ent, part->data); if (code) { - gs_rethrow1(code, "cannot inflate zip entry '%s'", name); - return NULL; + gs_rethrow1(code, "cannot inflate zip entry '%s'", name); + return NULL; } part->size = ent->usize; @@ -201,51 +201,51 @@ xps_read_zip_interleaved_entries(xps_context_t *ctx, char *name, int count, int strcat(buf, name); if (xps_zip_trace) - dprintf3("zip: interleaved part '%s' pieces=%d size=%d\n", buf, count, size); + dprintf3("zip: interleaved part '%s' pieces=%d size=%d\n", buf, count, size); part = xps_find_part(ctx, buf); if (!part) { - part = xps_new_part(ctx, buf, size); - if (!part) - { - gs_rethrow1(-1, "cannot create part for zip entry '%s'", buf); - return NULL; - } + part = xps_new_part(ctx, buf, size); + if (!part) + { + gs_rethrow1(-1, "cannot create part for zip entry '%s'", buf); + return NULL; + } } if (part->capacity < size) { - part->data = xps_realloc(ctx, part->data, size); - if (!part->data) - { - gs_throw(-1, "cannot extend part buffer"); - return NULL; - } + part->data = xps_realloc(ctx, part->data, size); + if (!part->data) + { + gs_throw(-1, "cannot extend part buffer"); + return NULL; + } } for (i = 0; i < count; i++) { - if (i == count - 1) - sprintf(buf, "%s/[%d].last.piece", name, i); - else - sprintf(buf, "%s/[%d].piece", name, i); - - ent = xps_find_zip_entry(ctx, buf); - if (!ent) - { - gs_throw1(-1, "cannot find zip entry '%s'", buf); - return NULL; - } - - code = xps_inflate_zip_entry(ctx, ent, part->data + part->size); - if (code) - { - gs_rethrow1(code, "cannot inflate zip entry '%s'", buf); - return NULL; - } - - part->size += ent->usize; + if (i == count - 1) + sprintf(buf, "%s/[%d].last.piece", name, i); + else + sprintf(buf, "%s/[%d].piece", name, i); + + ent = xps_find_zip_entry(ctx, buf); + if (!ent) + { + gs_throw1(-1, "cannot find zip entry '%s'", buf); + return NULL; + } + + code = xps_inflate_zip_entry(ctx, ent, part->data + part->size); + if (code) + { + gs_rethrow1(code, "cannot inflate zip entry '%s'", buf); + return NULL; + } + + part->size += ent->usize; } part->complete = 1; @@ -266,32 +266,32 @@ xps_read_zip_part(xps_context_t *ctx, char *name) /* skip leading '/' */ if (name[0] == '/') - name ++; + name ++; ent = xps_find_zip_entry(ctx, name); if (ent) - return xps_read_zip_entry(ctx, name, ent); + return xps_read_zip_entry(ctx, name, ent); count = 0; size = 0; do { - sprintf(buf, "%s/[%d].piece", name, count); - ent = xps_find_zip_entry(ctx, buf); - if (!ent) - { - sprintf(buf, "%s/[%d].last.piece", name, count); - ent = xps_find_zip_entry(ctx, buf); - } - if (ent) - { - count ++; - size += ent->usize; - } + sprintf(buf, "%s/[%d].piece", name, count); + ent = xps_find_zip_entry(ctx, buf); + if (!ent) + { + sprintf(buf, "%s/[%d].last.piece", name, count); + ent = xps_find_zip_entry(ctx, buf); + } + if (ent) + { + count ++; + size += ent->usize; + } } while (ent); if (count) { - return xps_read_zip_interleaved_entries(ctx, name, count, size); + return xps_read_zip_interleaved_entries(ctx, name, count, size); } return NULL; @@ -308,49 +308,49 @@ xps_read_zip_dir(xps_context_t *ctx, int offset, int count) for (i = 0; i < count; i++) { - sig = getlong(ctx->file); - if (sig != ZIP_CENTRAL_DIRECTORY_SIG) - return gs_throw1(-1, "wrong zip central directory signature (0x%x)", sig); - - (void) getshort(ctx->file); /* version made by */ - (void) getshort(ctx->file); /* version to extract */ - (void) getshort(ctx->file); /* general */ - (void) getshort(ctx->file); /* method */ - (void) getshort(ctx->file); /* last mod file time */ - (void) getshort(ctx->file); /* last mod file date */ - (void) getlong(ctx->file); /* crc-32 */ - ctx->zip_table[i].csize = getlong(ctx->file); - ctx->zip_table[i].usize = getlong(ctx->file); - namesize = getshort(ctx->file); - metasize = getshort(ctx->file); - commentsize = getshort(ctx->file); - (void) getshort(ctx->file); /* disk number start */ - (void) getshort(ctx->file); /* int file atts */ - (void) getlong(ctx->file); /* ext file atts */ - ctx->zip_table[i].offset = getlong(ctx->file); - - ctx->zip_table[i].name = xps_alloc(ctx, namesize + 1); - if (!ctx->zip_table[i].name) - return gs_throw(-1, "cannot allocate zip entry name"); - - fread(ctx->zip_table[i].name, 1, namesize, ctx->file); - ctx->zip_table[i].name[namesize] = 0; - - fseek(ctx->file, metasize, 1); - fseek(ctx->file, commentsize, 1); + sig = getlong(ctx->file); + if (sig != ZIP_CENTRAL_DIRECTORY_SIG) + return gs_throw1(-1, "wrong zip central directory signature (0x%x)", sig); + + (void) getshort(ctx->file); /* version made by */ + (void) getshort(ctx->file); /* version to extract */ + (void) getshort(ctx->file); /* general */ + (void) getshort(ctx->file); /* method */ + (void) getshort(ctx->file); /* last mod file time */ + (void) getshort(ctx->file); /* last mod file date */ + (void) getlong(ctx->file); /* crc-32 */ + ctx->zip_table[i].csize = getlong(ctx->file); + ctx->zip_table[i].usize = getlong(ctx->file); + namesize = getshort(ctx->file); + metasize = getshort(ctx->file); + commentsize = getshort(ctx->file); + (void) getshort(ctx->file); /* disk number start */ + (void) getshort(ctx->file); /* int file atts */ + (void) getlong(ctx->file); /* ext file atts */ + ctx->zip_table[i].offset = getlong(ctx->file); + + ctx->zip_table[i].name = xps_alloc(ctx, namesize + 1); + if (!ctx->zip_table[i].name) + return gs_throw(-1, "cannot allocate zip entry name"); + + fread(ctx->zip_table[i].name, 1, namesize, ctx->file); + ctx->zip_table[i].name[namesize] = 0; + + fseek(ctx->file, metasize, 1); + fseek(ctx->file, commentsize, 1); } qsort(ctx->zip_table, count, sizeof(xps_entry_t), xps_compare_entries); if (xps_zip_trace) { - for (i = 0; i < ctx->zip_count; i++) - { - dprintf3("zip entry '%s' csize=%d usize=%d\n", - ctx->zip_table[i].name, - ctx->zip_table[i].csize, - ctx->zip_table[i].usize); - } + for (i = 0; i < ctx->zip_count; i++) + { + dprintf3("zip entry '%s' csize=%d usize=%d\n", + ctx->zip_table[i].name, + ctx->zip_table[i].csize, + ctx->zip_table[i].usize); + } } return gs_okay; @@ -367,7 +367,7 @@ xps_read_zip_end_of_dir(xps_context_t *ctx, int start_offset) sig = getlong(ctx->file); if (sig != ZIP_END_OF_CENTRAL_DIRECTORY_SIG) - return gs_throw1(-1, "wrong zip end of central directory signature (0x%x)", sig); + return gs_throw1(-1, "wrong zip end of central directory signature (0x%x)", sig); (void) getshort(ctx->file); /* this disk */ (void) getshort(ctx->file); /* start disk */ @@ -379,7 +379,7 @@ xps_read_zip_end_of_dir(xps_context_t *ctx, int start_offset) ctx->zip_count = count; ctx->zip_table = xps_alloc(ctx, sizeof(xps_entry_t) * count); if (!ctx->zip_table) - return gs_throw(-1, "cannot allocate zip entry table"); + return gs_throw(-1, "cannot allocate zip entry table"); memset(ctx->zip_table, 0, sizeof(xps_entry_t) * count); @@ -401,17 +401,17 @@ xps_find_zip_end_of_dir(xps_context_t *ctx) while (back < maxback) { - fseek(ctx->file, filesize - back, 0); + fseek(ctx->file, filesize - back, 0); - n = fread(buf, 1, sizeof buf, ctx->file); - if (n < 0) - return gs_throw(-1, "cannot read end of central directory"); + n = fread(buf, 1, sizeof buf, ctx->file); + if (n < 0) + return gs_throw(-1, "cannot read end of central directory"); - for (i = n - 4; i > 0; i--) - if (!memcmp(buf + i, "PK\5\6", 4)) - return xps_read_zip_end_of_dir(ctx, filesize - back + i); + for (i = n - 4; i > 0; i--) + if (!memcmp(buf + i, "PK\5\6", 4)) + return xps_read_zip_end_of_dir(ctx, filesize - back + i); - back += sizeof buf - 4; + back += sizeof buf - 4; } return gs_throw(-1, "cannot find end of central directory"); @@ -425,11 +425,11 @@ xps_read_and_process_metadata_part(xps_context_t *ctx, char *name) part = xps_read_zip_part(ctx, name); if (!part) - return gs_rethrow1(-1, "cannot read zip part '%s'", name); + return gs_rethrow1(-1, "cannot read zip part '%s'", name); code = xps_parse_metadata(ctx, part); if (code) - return gs_rethrow1(code, "cannot process metadata part '%s'", name); + return gs_rethrow1(code, "cannot process metadata part '%s'", name); xps_release_part(ctx, part); @@ -444,11 +444,11 @@ xps_read_and_process_page_part(xps_context_t *ctx, char *name) part = xps_read_zip_part(ctx, name); if (!part) - return gs_rethrow1(-1, "cannot read zip part '%s'", name); + return gs_rethrow1(-1, "cannot read zip part '%s'", name); code = xps_parse_fixed_page(ctx, part); if (code) - return gs_rethrow1(code, "cannot parse fixed page part '%s'", name); + return gs_rethrow1(code, "cannot parse fixed page part '%s'", name); xps_release_part(ctx, part); @@ -468,45 +468,45 @@ xps_process_file(xps_context_t *ctx, FILE *file) code = xps_find_zip_end_of_dir(ctx); if (code < 0) - return gs_rethrow(code, "cannot read zip central directory"); + return gs_rethrow(code, "cannot read zip central directory"); code = xps_read_and_process_metadata_part(ctx, "/_rels/.rels"); if (code) - return gs_rethrow(code, "cannot process root relationship part"); + return gs_rethrow(code, "cannot process root relationship part"); part = xps_find_part(ctx, "/"); if (!part) - return gs_rethrow(code, "cannot find root part"); + return gs_rethrow(code, "cannot find root part"); for (rel = part->relations; rel; rel = rel->next) { - if (!strcmp(rel->type, REL_START_PART)) - { - ctx->start_part = rel->target; - if (xps_doc_trace) - dprintf1("doc: adding fixdocseq %s\n", ctx->start_part); - } + if (!strcmp(rel->type, REL_START_PART)) + { + ctx->start_part = rel->target; + if (xps_doc_trace) + dprintf1("doc: adding fixdocseq %s\n", ctx->start_part); + } } if (!ctx->start_part) - return gs_throw(-1, "cannot find fixed document sequence relationship"); + return gs_throw(-1, "cannot find fixed document sequence relationship"); code = xps_read_and_process_metadata_part(ctx, ctx->start_part); if (code) - return gs_rethrow(code, "cannot process FixedDocumentSequence part"); + return gs_rethrow(code, "cannot process FixedDocumentSequence part"); for (doc = ctx->first_fixdoc; doc; doc = doc->next) { - code = xps_read_and_process_metadata_part(ctx, doc->name); - if (code) - return gs_rethrow(code, "cannot process FixedDocument part"); + code = xps_read_and_process_metadata_part(ctx, doc->name); + if (code) + return gs_rethrow(code, "cannot process FixedDocument part"); } for (page = ctx->first_page; page; page = page->next) { - code = xps_read_and_process_page_part(ctx, page->name); - if (code) - return gs_rethrow(code, "cannot process FixedPage part"); + code = xps_read_and_process_page_part(ctx, page->name); + if (code) + return gs_rethrow(code, "cannot process FixedPage part"); } return gs_okay; |