diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-09-21 17:39:55 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-09-21 17:39:55 +0200 |
commit | ba46cad4b09bb957085900a203206c8fa5868cd4 (patch) | |
tree | e97bd846e63c0f496b6aff983ff9c4d14cef82c9 | |
parent | f783c31203be2dbd7a28c89557014f97a367bec9 (diff) | |
download | mupdf-ba46cad4b09bb957085900a203206c8fa5868cd4.tar.xz |
Rename xps_context to xps_document.
-rw-r--r-- | apps/pdfapp.h | 2 | ||||
-rw-r--r-- | apps/xpsdraw.c | 66 | ||||
-rw-r--r-- | xps/muxps.h | 98 | ||||
-rw-r--r-- | xps/xps_common.c | 66 | ||||
-rw-r--r-- | xps/xps_doc.c | 162 | ||||
-rw-r--r-- | xps/xps_glyphs.c | 100 | ||||
-rw-r--r-- | xps/xps_gradient.c | 68 | ||||
-rw-r--r-- | xps/xps_image.c | 32 | ||||
-rw-r--r-- | xps/xps_jpeg.c | 10 | ||||
-rw-r--r-- | xps/xps_path.c | 202 | ||||
-rw-r--r-- | xps/xps_png.c | 28 | ||||
-rw-r--r-- | xps/xps_resource.c | 46 | ||||
-rw-r--r-- | xps/xps_tiff.c | 60 | ||||
-rw-r--r-- | xps/xps_tile.c | 110 | ||||
-rw-r--r-- | xps/xps_xml.c | 38 | ||||
-rw-r--r-- | xps/xps_zip.c | 272 |
16 files changed, 680 insertions, 680 deletions
diff --git a/apps/pdfapp.h b/apps/pdfapp.h index 1a161d93..6bafbbf8 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -32,7 +32,7 @@ struct pdfapp_s char *doctitle; pdf_xref *xref; pdf_outline *outline; - xps_context *xps; + xps_document *xps; int pagecount; fz_glyph_cache *cache; diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c index 2ec54322..4544d09c 100644 --- a/apps/xpsdraw.c +++ b/apps/xpsdraw.c @@ -78,14 +78,14 @@ static int isrange(char *s) } static void -xps_run_page(xps_context *ctx, xps_page *page, fz_device *dev, fz_matrix ctm) +xps_run_page(xps_document *doc, xps_page *page, fz_device *dev, fz_matrix ctm) { - ctx->dev = dev; - xps_parse_fixed_page(ctx, ctm, page); - ctx->dev = NULL; + doc->dev = dev; + xps_parse_fixed_page(doc, ctm, page); + doc->dev = NULL; } -static void drawpage(xps_context *ctx, int pagenum) +static void drawpage(xps_document *doc, int pagenum) { xps_page *page; fz_display_list *list; @@ -98,7 +98,7 @@ static void drawpage(xps_context *ctx, int pagenum) start = gettime(); } - code = xps_load_page(&page, ctx, pagenum - 1); + code = xps_load_page(&page, doc, pagenum - 1); if (code) die(fz_error_note(code, "cannot load page %d in file '%s'", pagenum, filename)); @@ -106,32 +106,32 @@ static void drawpage(xps_context *ctx, int pagenum) if (uselist) { - list = fz_new_display_list(ctx->ctx); - dev = fz_new_list_device(ctx->ctx, list); - xps_run_page(ctx, page, dev, fz_identity); + list = fz_new_display_list(doc->ctx); + dev = fz_new_list_device(doc->ctx, list); + xps_run_page(doc, page, dev, fz_identity); fz_free_device(dev); } if (showxml) { - dev = fz_new_trace_device(ctx->ctx); + dev = fz_new_trace_device(doc->ctx); printf("<page number=\"%d\">\n", pagenum); if (list) fz_execute_display_list(list, dev, fz_identity, fz_infinite_bbox); else - xps_run_page(ctx, page, dev, fz_identity); + xps_run_page(doc, page, dev, fz_identity); printf("</page>\n"); fz_free_device(dev); } if (showtext) { - fz_text_span *text = fz_new_text_span(ctx->ctx); - dev = fz_new_text_device(ctx->ctx, text); + fz_text_span *text = fz_new_text_span(doc->ctx); + dev = fz_new_text_device(doc->ctx, text); if (list) fz_execute_display_list(list, dev, fz_identity, fz_infinite_bbox); else - xps_run_page(ctx, page, dev, fz_identity); + xps_run_page(doc, page, dev, fz_identity); fz_free_device(dev); printf("[Page %d]\n", pagenum); if (showtext > 1) @@ -139,7 +139,7 @@ static void drawpage(xps_context *ctx, int pagenum) else fz_debug_text_span(text); printf("\n"); - fz_free_text_span(ctx->ctx, text); + fz_free_text_span(doc->ctx, text); } if (showmd5 || showtime) @@ -164,18 +164,18 @@ static void drawpage(xps_context *ctx, int pagenum) /* TODO: banded rendering and multi-page ppm */ - pix = fz_new_pixmap_with_rect(ctx->ctx, colorspace, bbox); + pix = fz_new_pixmap_with_rect(doc->ctx, colorspace, bbox); if (savealpha) fz_clear_pixmap(pix); else fz_clear_pixmap_with_color(pix, 255); - dev = fz_new_draw_device(ctx->ctx, glyphcache, pix); + dev = fz_new_draw_device(doc->ctx, glyphcache, pix); if (list) fz_execute_display_list(list, dev, ctm, bbox); else - xps_run_page(ctx, page, dev, ctm); + xps_run_page(doc, page, dev, ctm); fz_free_device(dev); if (output) @@ -187,7 +187,7 @@ static void drawpage(xps_context *ctx, int pagenum) else if (strstr(output, ".pam")) fz_write_pam(pix, buf, savealpha); else if (strstr(output, ".png")) - fz_write_png(ctx->ctx, pix, buf, savealpha); + fz_write_png(doc->ctx, pix, buf, savealpha); } if (showmd5) @@ -205,11 +205,11 @@ static void drawpage(xps_context *ctx, int pagenum) printf("%02x", digest[i]); } - fz_drop_pixmap(ctx->ctx, pix); + fz_drop_pixmap(doc->ctx, pix); } if (list) - fz_free_display_list(ctx->ctx, list); + fz_free_display_list(doc->ctx, list); if (showtime) { @@ -236,7 +236,7 @@ static void drawpage(xps_context *ctx, int pagenum) printf("\n"); } -static void drawrange(xps_context *ctx, char *range) +static void drawrange(xps_document *doc, char *range) { int page, spage, epage; char *spec, *dash; @@ -247,7 +247,7 @@ static void drawrange(xps_context *ctx, char *range) dash = strchr(spec, '-'); if (dash == spec) - spage = epage = xps_count_pages(ctx); + spage = epage = xps_count_pages(doc); else spage = epage = atoi(spec); @@ -256,18 +256,18 @@ static void drawrange(xps_context *ctx, char *range) if (strlen(dash) > 1) epage = atoi(dash + 1); else - epage = xps_count_pages(ctx); + epage = xps_count_pages(doc); } - spage = CLAMP(spage, 1, xps_count_pages(ctx)); - epage = CLAMP(epage, 1, xps_count_pages(ctx)); + spage = CLAMP(spage, 1, xps_count_pages(doc)); + epage = CLAMP(epage, 1, xps_count_pages(doc)); if (spage < epage) for (page = spage; page <= epage; page++) - drawpage(ctx, page); + drawpage(doc, page); else for (page = spage; page >= epage; page--) - drawpage(ctx, page); + drawpage(doc, page); spec = fz_strsep(&range, ","); } @@ -277,7 +277,7 @@ int main(int argc, char **argv) { int grayscale = 0; int accelerate = 1; - xps_context *ctx; + xps_document *doc; int code; int c; @@ -342,7 +342,7 @@ int main(int argc, char **argv) { filename = argv[fz_optind++]; - code = xps_open_file(fzctx, &ctx, filename); + code = xps_open_file(fzctx, &doc, filename); if (code) die(fz_error_note(code, "cannot open document: %s", filename)); @@ -350,14 +350,14 @@ int main(int argc, char **argv) printf("<document name=\"%s\">\n", filename); if (fz_optind == argc || !isrange(argv[fz_optind])) - drawrange(ctx, "1-"); + drawrange(doc, "1-"); if (fz_optind < argc && isrange(argv[fz_optind])) - drawrange(ctx, argv[fz_optind++]); + drawrange(doc, argv[fz_optind++]); if (showxml) printf("</document>\n"); - xps_free_context(ctx); + xps_free_context(doc); } if (showtime) diff --git a/xps/muxps.h b/xps/muxps.h index bdae3eea..36635331 100644 --- a/xps/muxps.h +++ b/xps/muxps.h @@ -11,7 +11,7 @@ typedef unsigned char byte; * XPS and ZIP constants. */ -typedef struct xps_context_s xps_context; +typedef struct xps_document_s xps_document; #define REL_START_PART \ "http://schemas.microsoft.com/xps/2005/06/fixedrepresentation" @@ -38,12 +38,12 @@ void xps_absolute_path(char *output, char *base_uri, char *path, int output_size typedef struct element xml_element; -xml_element *xml_parse_document(fz_context *ctx, byte *buf, int len); +xml_element *xml_parse_document(fz_context *doc, byte *buf, int len); xml_element *xml_next(xml_element *item); xml_element *xml_down(xml_element *item); char *xml_tag(xml_element *item); char *xml_att(xml_element *item, const char *att); -void xml_free_element(fz_context *ctx, xml_element *item); +void xml_free_element(fz_context *doc, xml_element *item); void xml_print_element(xml_element *item, int level); /* @@ -60,21 +60,21 @@ struct xps_part_s byte *data; }; -xps_part *xps_new_part(xps_context *ctx, char *name, int size); -xps_part *xps_read_part(xps_context *ctx, char *partname); -void xps_free_part(xps_context *ctx, xps_part *part); +xps_part *xps_new_part(xps_document *doc, char *name, int size); +xps_part *xps_read_part(xps_document *doc, char *partname); +void xps_free_part(xps_document *doc, xps_part *part); /* * Document structure. */ -typedef struct xps_document_s xps_document; +typedef struct xps_fixdoc_s xps_fixdoc; typedef struct xps_page_s xps_page; -struct xps_document_s +struct xps_fixdoc_s { char *name; - xps_document *next; + xps_fixdoc *next; }; struct xps_page_s @@ -86,21 +86,21 @@ struct xps_page_s xps_page *next; }; -int xps_read_page_list(xps_context *ctx); -void xps_debug_page_list(xps_context *ctx); -void xps_free_page_list(xps_context *ctx); +int xps_read_page_list(xps_document *doc); +void xps_debug_page_list(xps_document *doc); +void xps_free_page_list(xps_document *doc); -int xps_count_pages(xps_context *ctx); -int xps_load_page(xps_page **page, xps_context *ctx, int number); -void xps_free_page(xps_context *ctx, xps_page *page); +int xps_count_pages(xps_document *doc); +int xps_load_page(xps_page **page, xps_document *doc, int number); +void xps_free_page(xps_document *doc, xps_page *page); /* * Images, fonts, and colorspaces. */ -int xps_decode_jpeg(fz_context *ctx, fz_pixmap **imagep, byte *rbuf, int rlen); -int xps_decode_png(fz_context *ctx, fz_pixmap **imagep, byte *rbuf, int rlen); -int xps_decode_tiff(fz_context *ctx, fz_pixmap **imagep, byte *rbuf, int rlen); +int xps_decode_jpeg(fz_context *doc, fz_pixmap **imagep, byte *rbuf, int rlen); +int xps_decode_png(fz_context *doc, fz_pixmap **imagep, byte *rbuf, int rlen); +int xps_decode_tiff(fz_context *doc, fz_pixmap **imagep, byte *rbuf, int rlen); typedef struct xps_font_cache_s xps_font_cache; @@ -123,12 +123,12 @@ void xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid); void xps_select_font_encoding(fz_font *font, int idx); int xps_encode_font_char(fz_font *font, int key); -void xps_measure_font_glyph(xps_context *ctx, fz_font *font, int gid, xps_glyph_metrics *mtx); +void xps_measure_font_glyph(xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx); -void xps_debug_path(xps_context *ctx); +void xps_debug_path(xps_document *doc); -void xps_parse_color(xps_context *ctx, char *base_uri, char *hexstring, fz_colorspace **csp, float *samples); -void xps_set_color(xps_context *ctx, fz_colorspace *colorspace, float *samples); +void xps_parse_color(xps_document *doc, char *base_uri, char *hexstring, fz_colorspace **csp, float *samples); +void xps_set_color(xps_document *doc, fz_colorspace *colorspace, float *samples); /* * Resource dictionaries. @@ -146,9 +146,9 @@ struct xps_resource_s xps_resource *parent; /* up to the previous dict in the stack */ }; -int xps_parse_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base_uri, xml_element *root); -void xps_free_resource_dictionary(xps_context *ctx, xps_resource *dict); -void xps_resolve_resource_reference(xps_context *ctx, xps_resource *dict, char **attp, xml_element **tagp, char **urip); +int xps_parse_resource_dictionary(xps_document *doc, xps_resource **dictp, char *base_uri, xml_element *root); +void xps_free_resource_dictionary(xps_document *doc, xps_resource *dict); +void xps_resolve_resource_reference(xps_document *doc, xps_resource *dict, char **attp, xml_element **tagp, char **urip); void xps_debug_resource_dictionary(xps_resource *dict); @@ -156,29 +156,29 @@ void xps_debug_resource_dictionary(xps_resource *dict); * Fixed page/graphics parsing. */ -void xps_parse_fixed_page(xps_context *ctx, fz_matrix ctm, xps_page *page); -void xps_parse_canvas(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_path(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_glyphs(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_solid_color_brush(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_image_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_visual_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_linear_gradient_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_radial_gradient_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_fixed_page(xps_document *doc, fz_matrix ctm, xps_page *page); +void xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_glyphs(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_solid_color_brush(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_visual_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_linear_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_radial_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root, void(*func)(xps_context*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*), void *user); +void xps_parse_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root, void(*func)(xps_document*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*), void *user); -void xps_parse_matrix_transform(xps_context *ctx, xml_element *root, fz_matrix *matrix); -void xps_parse_render_transform(xps_context *ctx, char *text, fz_matrix *matrix); -void xps_parse_rectangle(xps_context *ctx, char *text, fz_rect *rect); +void xps_parse_matrix_transform(xps_document *doc, xml_element *root, fz_matrix *matrix); +void xps_parse_render_transform(xps_document *doc, char *text, fz_matrix *matrix); +void xps_parse_rectangle(xps_document *doc, char *text, fz_rect *rect); -void xps_begin_opacity(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag); -void xps_end_opacity(xps_context *ctx, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag); +void xps_begin_opacity(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag); +void xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag); -void xps_parse_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_element(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_element(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_clip(xps_context *ctx, fz_matrix ctm, xps_resource *dict, char *clip_att, xml_element *clip_tag); +void xps_clip(xps_document *doc, fz_matrix ctm, xps_resource *dict, char *clip_att, xml_element *clip_tag); /* * The interpreter context. @@ -194,7 +194,7 @@ struct xps_entry_s int usize; }; -struct xps_context_s +struct xps_document_s { fz_context *ctx; char *directory; @@ -203,8 +203,8 @@ struct xps_context_s xps_entry *zip_table; char *start_part; /* fixed document sequence */ - xps_document *first_fixdoc; /* first fixed document */ - xps_document *last_fixdoc; /* last fixed document */ + xps_fixdoc *first_fixdoc; /* first fixed document */ + xps_fixdoc *last_fixdoc; /* last fixed document */ xps_page *first_page; /* first page of document */ xps_page *last_page; /* last page of document */ @@ -227,8 +227,8 @@ struct xps_context_s fz_device *dev; }; -int xps_open_file(fz_context *ctx, xps_context **ctxp, char *filename); -int xps_open_stream(xps_context **ctxp, fz_stream *file); -void xps_free_context(xps_context *ctx); +int xps_open_file(fz_context *doc, xps_document **ctxp, char *filename); +int xps_open_stream(xps_document **ctxp, fz_stream *file); +void xps_free_context(xps_document *doc); #endif diff --git a/xps/xps_common.c b/xps/xps_common.c index 5fb1db31..745d1be1 100644 --- a/xps/xps_common.c +++ b/xps/xps_common.c @@ -10,35 +10,35 @@ static inline int unhex(int a) } void -xps_parse_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node) +xps_parse_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node) { /* SolidColorBrushes are handled in a special case and will never show up here */ if (!strcmp(xml_tag(node), "ImageBrush")) - xps_parse_image_brush(ctx, ctm, area, base_uri, dict, node); + xps_parse_image_brush(doc, ctm, area, base_uri, dict, node); else if (!strcmp(xml_tag(node), "VisualBrush")) - xps_parse_visual_brush(ctx, ctm, area, base_uri, dict, node); + xps_parse_visual_brush(doc, ctm, area, base_uri, dict, node); else if (!strcmp(xml_tag(node), "LinearGradientBrush")) - xps_parse_linear_gradient_brush(ctx, ctm, area, base_uri, dict, node); + xps_parse_linear_gradient_brush(doc, ctm, area, base_uri, dict, node); else if (!strcmp(xml_tag(node), "RadialGradientBrush")) - xps_parse_radial_gradient_brush(ctx, ctm, area, base_uri, dict, node); + xps_parse_radial_gradient_brush(doc, ctm, area, base_uri, dict, node); else - fz_warn(ctx->ctx, "unknown brush tag: %s", xml_tag(node)); + fz_warn(doc->ctx, "unknown brush tag: %s", xml_tag(node)); } void -xps_parse_element(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node) +xps_parse_element(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node) { if (!strcmp(xml_tag(node), "Path")) - xps_parse_path(ctx, ctm, base_uri, dict, node); + xps_parse_path(doc, ctm, base_uri, dict, node); if (!strcmp(xml_tag(node), "Glyphs")) - xps_parse_glyphs(ctx, ctm, base_uri, dict, node); + xps_parse_glyphs(doc, ctm, base_uri, dict, node); if (!strcmp(xml_tag(node), "Canvas")) - xps_parse_canvas(ctx, ctm, area, base_uri, dict, node); + xps_parse_canvas(doc, ctm, area, base_uri, dict, node); /* skip unknown tags (like Foo.Resources and similar) */ } void -xps_begin_opacity(xps_context *ctx, fz_matrix ctm, fz_rect area, +xps_begin_opacity(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag) { @@ -61,45 +61,45 @@ xps_begin_opacity(xps_context *ctx, fz_matrix ctm, fz_rect area, { fz_colorspace *colorspace; float samples[32]; - xps_parse_color(ctx, base_uri, scb_color_att, &colorspace, samples); + xps_parse_color(doc, base_uri, scb_color_att, &colorspace, samples); opacity = opacity * samples[0]; } opacity_mask_tag = NULL; } - if (ctx->opacity_top + 1 < nelem(ctx->opacity)) + if (doc->opacity_top + 1 < nelem(doc->opacity)) { - ctx->opacity[ctx->opacity_top + 1] = ctx->opacity[ctx->opacity_top] * opacity; - ctx->opacity_top++; + doc->opacity[doc->opacity_top + 1] = doc->opacity[doc->opacity_top] * opacity; + doc->opacity_top++; } if (opacity_mask_tag) { - fz_begin_mask(ctx->dev, area, 0, NULL, NULL); - xps_parse_brush(ctx, ctm, area, base_uri, dict, opacity_mask_tag); - fz_end_mask(ctx->dev); + fz_begin_mask(doc->dev, area, 0, NULL, NULL); + xps_parse_brush(doc, ctm, area, base_uri, dict, opacity_mask_tag); + fz_end_mask(doc->dev); } } void -xps_end_opacity(xps_context *ctx, char *base_uri, xps_resource *dict, +xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag) { if (!opacity_att && !opacity_mask_tag) return; - if (ctx->opacity_top > 0) - ctx->opacity_top--; + if (doc->opacity_top > 0) + doc->opacity_top--; if (opacity_mask_tag) { if (strcmp(xml_tag(opacity_mask_tag), "SolidColorBrush")) - fz_pop_clip(ctx->dev); + fz_pop_clip(doc->dev); } } void -xps_parse_render_transform(xps_context *ctx, char *transform, fz_matrix *matrix) +xps_parse_render_transform(xps_document *doc, char *transform, fz_matrix *matrix) { float args[6]; char *s = transform; @@ -124,7 +124,7 @@ xps_parse_render_transform(xps_context *ctx, char *transform, fz_matrix *matrix) } void -xps_parse_matrix_transform(xps_context *ctx, xml_element *root, fz_matrix *matrix) +xps_parse_matrix_transform(xps_document *doc, xml_element *root, fz_matrix *matrix) { char *transform; @@ -134,12 +134,12 @@ xps_parse_matrix_transform(xps_context *ctx, xml_element *root, fz_matrix *matri { transform = xml_att(root, "Matrix"); if (transform) - xps_parse_render_transform(ctx, transform, matrix); + xps_parse_render_transform(doc, transform, matrix); } } void -xps_parse_rectangle(xps_context *ctx, char *text, fz_rect *rect) +xps_parse_rectangle(xps_document *doc, char *text, fz_rect *rect) { float args[4]; char *s = text; @@ -176,7 +176,7 @@ static int count_commas(char *s) } void -xps_parse_color(xps_context *ctx, char *base_uri, char *string, +xps_parse_color(xps_document *doc, char *base_uri, char *string, fz_colorspace **csp, float *samples) { char *p; @@ -230,7 +230,7 @@ xps_parse_color(xps_context *ctx, char *base_uri, char *string, profile = strchr(buf, ' '); if (!profile) { - fz_warn(ctx->ctx, "cannot find icc profile uri in '%s'", string); + fz_warn(doc->ctx, "cannot find icc profile uri in '%s'", string); return; } @@ -238,7 +238,7 @@ xps_parse_color(xps_context *ctx, char *base_uri, char *string, p = strchr(profile, ' '); if (!p) { - fz_warn(ctx->ctx, "cannot find component values in '%s'", profile); + fz_warn(doc->ctx, "cannot find component values in '%s'", profile); return; } @@ -272,11 +272,11 @@ xps_parse_color(xps_context *ctx, char *base_uri, char *string, } void -xps_set_color(xps_context *ctx, fz_colorspace *colorspace, float *samples) +xps_set_color(xps_document *doc, fz_colorspace *colorspace, float *samples) { int i; - ctx->colorspace = colorspace; + doc->colorspace = colorspace; for (i = 0; i < colorspace->n; i++) - ctx->color[i] = samples[i + 1]; - ctx->alpha = samples[0] * ctx->opacity[ctx->opacity_top]; + doc->color[i] = samples[i + 1]; + doc->alpha = samples[0] * doc->opacity[doc->opacity_top]; } diff --git a/xps/xps_doc.c b/xps/xps_doc.c index e6d4dca3..378006e3 100644 --- a/xps/xps_doc.c +++ b/xps/xps_doc.c @@ -7,13 +7,13 @@ */ void -xps_debug_page_list(xps_context *ctx) +xps_debug_page_list(xps_document *doc) { - xps_document *fixdoc = ctx->first_fixdoc; - xps_page *page = ctx->first_page; + xps_fixdoc *fixdoc = doc->first_fixdoc; + xps_page *page = doc->first_page; - if (ctx->start_part) - printf("start part %s\n", ctx->start_part); + if (doc->start_part) + printf("start part %s\n", doc->start_part); while (fixdoc) { @@ -29,96 +29,96 @@ xps_debug_page_list(xps_context *ctx) } static void -xps_add_fixed_document(xps_context *ctx, char *name) +xps_add_fixed_document(xps_document *doc, char *name) { - xps_document *fixdoc; + xps_fixdoc *fixdoc; /* Check for duplicates first */ - for (fixdoc = ctx->first_fixdoc; fixdoc; fixdoc = fixdoc->next) + for (fixdoc = doc->first_fixdoc; fixdoc; fixdoc = fixdoc->next) if (!strcmp(fixdoc->name, name)) return; - fixdoc = fz_malloc(ctx->ctx, sizeof(xps_document)); - fixdoc->name = fz_strdup(ctx->ctx, name); + fixdoc = fz_malloc(doc->ctx, sizeof(xps_fixdoc)); + fixdoc->name = fz_strdup(doc->ctx, name); fixdoc->next = NULL; - if (!ctx->first_fixdoc) + if (!doc->first_fixdoc) { - ctx->first_fixdoc = fixdoc; - ctx->last_fixdoc = fixdoc; + doc->first_fixdoc = fixdoc; + doc->last_fixdoc = fixdoc; } else { - ctx->last_fixdoc->next = fixdoc; - ctx->last_fixdoc = fixdoc; + doc->last_fixdoc->next = fixdoc; + doc->last_fixdoc = fixdoc; } } static void -xps_add_fixed_page(xps_context *ctx, char *name, int width, int height) +xps_add_fixed_page(xps_document *doc, char *name, int width, int height) { xps_page *page; /* Check for duplicates first */ - for (page = ctx->first_page; page; page = page->next) + for (page = doc->first_page; page; page = page->next) if (!strcmp(page->name, name)) return; - page = fz_malloc(ctx->ctx, sizeof(xps_page)); - page->name = fz_strdup(ctx->ctx, name); + page = fz_malloc(doc->ctx, sizeof(xps_page)); + page->name = fz_strdup(doc->ctx, name); page->width = width; page->height = height; page->root = NULL; page->next = NULL; - if (!ctx->first_page) + if (!doc->first_page) { - ctx->first_page = page; - ctx->last_page = page; + doc->first_page = page; + doc->last_page = page; } else { - ctx->last_page->next = page; - ctx->last_page = page; + doc->last_page->next = page; + doc->last_page = page; } } static void -xps_free_fixed_pages(xps_context *ctx) +xps_free_fixed_pages(xps_document *doc) { - xps_page *page = ctx->first_page; + xps_page *page = doc->first_page; while (page) { xps_page *next = page->next; - xps_free_page(ctx, page); - fz_free(ctx->ctx, page->name); - fz_free(ctx->ctx, page); + xps_free_page(doc, page); + fz_free(doc->ctx, page->name); + fz_free(doc->ctx, page); page = next; } - ctx->first_page = NULL; - ctx->last_page = NULL; + doc->first_page = NULL; + doc->last_page = NULL; } static void -xps_free_fixed_documents(xps_context *ctx) +xps_free_fixed_documents(xps_document *doc) { - xps_document *doc = ctx->first_fixdoc; - while (doc) + xps_fixdoc *fixdoc = doc->first_fixdoc; + while (fixdoc) { - xps_document *next = doc->next; - fz_free(ctx->ctx, doc->name); - fz_free(ctx->ctx, doc); - doc = next; + xps_fixdoc *next = fixdoc->next; + fz_free(doc->ctx, fixdoc->name); + fz_free(doc->ctx, fixdoc); + fixdoc = next; } - ctx->first_fixdoc = NULL; - ctx->last_fixdoc = NULL; + doc->first_fixdoc = NULL; + doc->last_fixdoc = NULL; } void -xps_free_page_list(xps_context *ctx) +xps_free_page_list(xps_document *doc) { - xps_free_fixed_documents(ctx); - xps_free_fixed_pages(ctx); + xps_free_fixed_documents(doc); + xps_free_fixed_pages(doc); } /* @@ -126,11 +126,11 @@ xps_free_page_list(xps_context *ctx) */ static void -xps_parse_metadata_imp(xps_context *ctx, xml_element *item) +xps_parse_metadata_imp(xps_document *doc, xml_element *item) { while (item) { - xps_parse_metadata_imp(ctx, xml_down(item)); + xps_parse_metadata_imp(doc, xml_down(item)); if (!strcmp(xml_tag(item), "Relationship")) { @@ -139,9 +139,9 @@ xps_parse_metadata_imp(xps_context *ctx, xml_element *item) if (target && type) { char tgtbuf[1024]; - xps_absolute_path(tgtbuf, ctx->base_uri, target, sizeof tgtbuf); + xps_absolute_path(tgtbuf, doc->base_uri, target, sizeof tgtbuf); if (!strcmp(type, REL_START_PART)) - ctx->start_part = fz_strdup(ctx->ctx, tgtbuf); + doc->start_part = fz_strdup(doc->ctx, tgtbuf); } } @@ -151,8 +151,8 @@ xps_parse_metadata_imp(xps_context *ctx, xml_element *item) if (source) { char srcbuf[1024]; - xps_absolute_path(srcbuf, ctx->base_uri, source, sizeof srcbuf); - xps_add_fixed_document(ctx, srcbuf); + xps_absolute_path(srcbuf, doc->base_uri, source, sizeof srcbuf); + xps_add_fixed_document(doc, srcbuf); } } @@ -166,8 +166,8 @@ xps_parse_metadata_imp(xps_context *ctx, xml_element *item) if (source) { char srcbuf[1024]; - xps_absolute_path(srcbuf, ctx->base_uri, source, sizeof srcbuf); - xps_add_fixed_page(ctx, srcbuf, width, height); + xps_absolute_path(srcbuf, doc->base_uri, source, sizeof srcbuf); + xps_add_fixed_page(doc, srcbuf, width, height); } } @@ -176,7 +176,7 @@ xps_parse_metadata_imp(xps_context *ctx, xml_element *item) } static int -xps_parse_metadata(xps_context *ctx, xps_part *part) +xps_parse_metadata(xps_document *doc, xps_part *part) { xml_element *root; char buf[1024]; @@ -196,62 +196,62 @@ xps_parse_metadata(xps_context *ctx, xps_part *part) if (s) *s = 0; - ctx->base_uri = buf; - ctx->part_uri = part->name; + doc->base_uri = buf; + doc->part_uri = part->name; - root = xml_parse_document(ctx->ctx, part->data, part->size); + root = xml_parse_document(doc->ctx, part->data, part->size); if (!root) return fz_error_note(-1, "cannot parse metadata part '%s'", part->name); - xps_parse_metadata_imp(ctx, root); + xps_parse_metadata_imp(doc, root); - xml_free_element(ctx->ctx, root); + xml_free_element(doc->ctx, root); - ctx->base_uri = NULL; - ctx->part_uri = NULL; + doc->base_uri = NULL; + doc->part_uri = NULL; return fz_okay; } static int -xps_read_and_process_metadata_part(xps_context *ctx, char *name) +xps_read_and_process_metadata_part(xps_document *doc, char *name) { xps_part *part; int code; - part = xps_read_part(ctx, name); + part = xps_read_part(doc, name); if (!part) return fz_error_note(-1, "cannot read zip part '%s'", name); - code = xps_parse_metadata(ctx, part); + code = xps_parse_metadata(doc, part); if (code) return fz_error_note(code, "cannot process metadata part '%s'", name); - xps_free_part(ctx, part); + xps_free_part(doc, part); return fz_okay; } int -xps_read_page_list(xps_context *ctx) +xps_read_page_list(xps_document *doc) { - xps_document *doc; + xps_fixdoc *fixdoc; int code; - code = xps_read_and_process_metadata_part(ctx, "/_rels/.rels"); + code = xps_read_and_process_metadata_part(doc, "/_rels/.rels"); if (code) return fz_error_note(code, "cannot process root relationship part"); - if (!ctx->start_part) + if (!doc->start_part) return fz_error_make("cannot find fixed document sequence start part"); - code = xps_read_and_process_metadata_part(ctx, ctx->start_part); + code = xps_read_and_process_metadata_part(doc, doc->start_part); if (code) return fz_error_note(code, "cannot process FixedDocumentSequence part"); - for (doc = ctx->first_fixdoc; doc; doc = doc->next) + for (fixdoc = doc->first_fixdoc; fixdoc; fixdoc = fixdoc->next) { - code = xps_read_and_process_metadata_part(ctx, doc->name); + code = xps_read_and_process_metadata_part(doc, fixdoc->name); if (code) return fz_error_note(code, "cannot process FixedDocument part"); } @@ -260,32 +260,32 @@ xps_read_page_list(xps_context *ctx) } int -xps_count_pages(xps_context *ctx) +xps_count_pages(xps_document *doc) { xps_page *page; int n = 0; - for (page = ctx->first_page; page; page = page->next) + for (page = doc->first_page; page; page = page->next) n ++; return n; } static int -xps_load_fixed_page(xps_context *ctx, xps_page *page) +xps_load_fixed_page(xps_document *doc, xps_page *page) { xps_part *part; xml_element *root; char *width_att; char *height_att; - part = xps_read_part(ctx, page->name); + part = xps_read_part(doc, page->name); if (!part) return fz_error_note(-1, "cannot read zip part '%s'", page->name); - root = xml_parse_document(ctx->ctx, part->data, part->size); + root = xml_parse_document(doc->ctx, part->data, part->size); if (!root) return fz_error_note(-1, "cannot parse xml part '%s'", page->name); - xps_free_part(ctx, part); + xps_free_part(doc, part); if (strcmp(xml_tag(root), "FixedPage")) return fz_error_make("expected FixedPage element (found %s)", xml_tag(root)); @@ -306,19 +306,19 @@ xps_load_fixed_page(xps_context *ctx, xps_page *page) } int -xps_load_page(xps_page **pagep, xps_context *ctx, int number) +xps_load_page(xps_page **pagep, xps_document *doc, int number) { xps_page *page; int code; int n = 0; - for (page = ctx->first_page; page; page = page->next) + for (page = doc->first_page; page; page = page->next) { if (n == number) { if (!page->root) { - code = xps_load_fixed_page(ctx, page); + code = xps_load_fixed_page(doc, page); if (code) return fz_error_note(code, "cannot load page %d", number + 1); } @@ -332,10 +332,10 @@ xps_load_page(xps_page **pagep, xps_context *ctx, int number) } void -xps_free_page(xps_context *ctx, xps_page *page) +xps_free_page(xps_document *doc, xps_page *page) { /* only free the XML contents */ if (page->root) - xml_free_element(ctx->ctx, page->root); + xml_free_element(doc->ctx, page->root); page->root = NULL; } diff --git a/xps/xps_glyphs.c b/xps/xps_glyphs.c index 9dfd165e..bcab9b39 100644 --- a/xps/xps_glyphs.c +++ b/xps/xps_glyphs.c @@ -53,7 +53,7 @@ xps_encode_font_char(fz_font *font, int code) } void -xps_measure_font_glyph(xps_context *ctx, fz_font *font, int gid, xps_glyph_metrics *mtx) +xps_measure_font_glyph(xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx) { int mask = FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING | FT_LOAD_IGNORE_TRANSFORM; FT_Face face = font->ft_face; @@ -69,23 +69,23 @@ xps_measure_font_glyph(xps_context *ctx, fz_font *font, int gid, xps_glyph_metri } static fz_font * -xps_lookup_font(xps_context *ctx, char *name) +xps_lookup_font(xps_document *doc, char *name) { xps_font_cache *cache; - for (cache = ctx->font_table; cache; cache = cache->next) + for (cache = doc->font_table; cache; cache = cache->next) if (!xps_strcasecmp(cache->name, name)) return fz_keep_font(cache->font); return NULL; } static void -xps_insert_font(xps_context *ctx, char *name, fz_font *font) +xps_insert_font(xps_document *doc, char *name, fz_font *font) { - xps_font_cache *cache = fz_malloc(ctx->ctx, sizeof(xps_font_cache)); - cache->name = fz_strdup(ctx->ctx, name); + xps_font_cache *cache = fz_malloc(doc->ctx, sizeof(xps_font_cache)); + cache->name = fz_strdup(doc->ctx, name); cache->font = fz_keep_font(font); - cache->next = ctx->font_table; - ctx->font_table = cache; + cache->next = doc->font_table; + doc->font_table = cache; } /* @@ -93,7 +93,7 @@ xps_insert_font(xps_context *ctx, char *name, fz_font *font) * data with the GUID in the fontname. */ static void -xps_deobfuscate_font_resource(xps_context *ctx, xps_part *part) +xps_deobfuscate_font_resource(xps_document *doc, xps_part *part) { byte buf[33]; byte key[16]; @@ -113,7 +113,7 @@ xps_deobfuscate_font_resource(xps_context *ctx, xps_part *part) if (i != 32) { - fz_warn(ctx->ctx, "cannot extract GUID from obfuscated font part name"); + fz_warn(doc->ctx, "cannot extract GUID from obfuscated font part name"); return; } @@ -128,7 +128,7 @@ xps_deobfuscate_font_resource(xps_context *ctx, xps_part *part) } static void -xps_select_best_font_encoding(xps_context *ctx, fz_font *font) +xps_select_best_font_encoding(xps_document *doc, fz_font *font) { static struct { int pid, eid; } xps_cmap_list[] = { @@ -160,7 +160,7 @@ xps_select_best_font_encoding(xps_context *ctx, fz_font *font) } } - fz_warn(ctx->ctx, "cannot find a suitable cmap"); + fz_warn(doc->ctx, "cannot find a suitable cmap"); } /* @@ -251,7 +251,7 @@ xps_parse_glyph_metrics(char *s, float *advance, float *uofs, float *vofs) * Calculate metrics for positioning. */ static fz_text * -xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, +xps_parse_glyphs_imp(xps_document *doc, fz_matrix ctm, fz_font *font, float size, float originx, float originy, int is_sideways, int bidi_level, char *indices, char *unicode) @@ -267,7 +267,7 @@ xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, int un = 0; if (!unicode && !indices) - fz_warn(ctx->ctx, "glyphs element with neither characters nor indices"); + fz_warn(doc->ctx, "glyphs element with neither characters nor indices"); if (us) { @@ -281,7 +281,7 @@ xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, else tm = fz_scale(size, -size); - text = fz_new_text(ctx->ctx, font, tm, is_sideways); + text = fz_new_text(doc->ctx, font, tm, is_sideways); while ((us && un > 0) || (is && *is)) { @@ -323,7 +323,7 @@ xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, if (glyph_index == -1) glyph_index = xps_encode_font_char(font, char_code); - xps_measure_font_glyph(ctx, font, glyph_index, &mtx); + xps_measure_font_glyph(doc, font, glyph_index, &mtx); if (is_sideways) advance = mtx.vadv * 100; else if (bidi_level & 1) @@ -355,7 +355,7 @@ xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, f = y - v_offset; } - fz_add_text(ctx->ctx, text, glyph_index, char_code, e, f); + fz_add_text(doc->ctx, text, glyph_index, char_code, e, f); x += advance * 0.01f * size; } @@ -365,7 +365,7 @@ xps_parse_glyphs_imp(xps_context *ctx, fz_matrix ctm, } void -xps_parse_glyphs(xps_context *ctx, fz_matrix ctm, +xps_parse_glyphs(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *root) { xml_element *node; @@ -446,17 +446,17 @@ xps_parse_glyphs(xps_context *ctx, fz_matrix ctm, fill_uri = base_uri; opacity_mask_uri = base_uri; - xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL); - xps_resolve_resource_reference(ctx, dict, &clip_att, &clip_tag, NULL); - xps_resolve_resource_reference(ctx, dict, &fill_att, &fill_tag, &fill_uri); - xps_resolve_resource_reference(ctx, dict, &opacity_mask_att, &opacity_mask_tag, &opacity_mask_uri); + xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); + xps_resolve_resource_reference(doc, dict, &clip_att, &clip_tag, NULL); + xps_resolve_resource_reference(doc, dict, &fill_att, &fill_tag, &fill_uri); + xps_resolve_resource_reference(doc, dict, &opacity_mask_att, &opacity_mask_tag, &opacity_mask_uri); /* * Check that we have all the necessary information. */ if (!font_size_att || !font_uri_att || !origin_x_att || !origin_y_att) { - fz_warn(ctx->ctx, "missing attributes in glyphs element"); + fz_warn(doc->ctx, "missing attributes in glyphs element"); return; } @@ -481,37 +481,37 @@ xps_parse_glyphs(xps_context *ctx, fz_matrix ctm, *subfont = 0; } - font = xps_lookup_font(ctx, partname); + font = xps_lookup_font(doc, partname); if (!font) { - part = xps_read_part(ctx, partname); + part = xps_read_part(doc, partname); if (!part) { - fz_warn(ctx->ctx, "cannot find font resource part '%s'", partname); + fz_warn(doc->ctx, "cannot find font resource part '%s'", partname); return; } /* deobfuscate if necessary */ if (strstr(part->name, ".odttf")) - xps_deobfuscate_font_resource(ctx, part); + xps_deobfuscate_font_resource(doc, part); if (strstr(part->name, ".ODTTF")) - xps_deobfuscate_font_resource(ctx, part); + xps_deobfuscate_font_resource(doc, part); - code = fz_new_font_from_memory(ctx->ctx, &font, part->data, part->size, subfontid); + code = fz_new_font_from_memory(doc->ctx, &font, part->data, part->size, subfontid); if (code) { fz_error_handle(code, "cannot load font resource '%s'", partname); - xps_free_part(ctx, part); + xps_free_part(doc, part); return; } - xps_select_best_font_encoding(ctx, font); + xps_select_best_font_encoding(doc, font); - xps_insert_font(ctx, part->name, font); + xps_insert_font(doc, part->name, font); /* NOTE: we keep part->data in the font */ font->ft_data = part->data; font->ft_size = part->size; - fz_free(ctx->ctx, part->name); - fz_free(ctx->ctx, part); + fz_free(doc->ctx, part->name); + fz_free(doc->ctx, part); } /* @@ -522,24 +522,24 @@ xps_parse_glyphs(xps_context *ctx, fz_matrix ctm, { fz_matrix transform; if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); + xps_parse_render_transform(doc, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + xps_parse_matrix_transform(doc, transform_tag, &transform); ctm = fz_concat(transform, ctm); } if (clip_att || clip_tag) - xps_clip(ctx, ctm, dict, clip_att, clip_tag); + xps_clip(doc, ctm, dict, clip_att, clip_tag); font_size = fz_atof(font_size_att); - text = xps_parse_glyphs_imp(ctx, ctm, font, font_size, + text = xps_parse_glyphs_imp(doc, ctm, font, font_size, fz_atof(origin_x_att), fz_atof(origin_y_att), is_sideways, bidi_level, indices_att, unicode_att); area = fz_bound_text(text, ctm); - xps_begin_opacity(ctx, ctm, area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); + xps_begin_opacity(doc, ctm, area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); /* If it's a solid color brush fill/stroke do a simple fill */ @@ -555,30 +555,30 @@ xps_parse_glyphs(xps_context *ctx, fz_matrix ctm, float samples[32]; fz_colorspace *colorspace; - xps_parse_color(ctx, base_uri, fill_att, &colorspace, samples); + xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); if (fill_opacity_att) samples[0] = fz_atof(fill_opacity_att); - xps_set_color(ctx, colorspace, samples); + xps_set_color(doc, colorspace, samples); - fz_fill_text(ctx->dev, text, ctm, - ctx->colorspace, ctx->color, ctx->alpha); + fz_fill_text(doc->dev, text, ctm, + doc->colorspace, doc->color, doc->alpha); } /* If it's a complex brush, use the charpath as a clip mask */ if (fill_tag) { - fz_clip_text(ctx->dev, text, ctm, 0); - xps_parse_brush(ctx, ctm, area, fill_uri, dict, fill_tag); - fz_pop_clip(ctx->dev); + fz_clip_text(doc->dev, text, ctm, 0); + xps_parse_brush(doc, ctm, area, fill_uri, dict, fill_tag); + fz_pop_clip(doc->dev); } - xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); + xps_end_opacity(doc, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); - fz_free_text(ctx->ctx, text); + fz_free_text(doc->ctx, text); if (clip_att || clip_tag) - fz_pop_clip(ctx->dev); + fz_pop_clip(doc->dev); - fz_drop_font(ctx->ctx, font); + fz_drop_font(doc->ctx, font); } diff --git a/xps/xps_gradient.c b/xps/xps_gradient.c index 19424f9b..b13d14ef 100644 --- a/xps/xps_gradient.c +++ b/xps/xps_gradient.c @@ -35,7 +35,7 @@ static inline float lerp(float a, float b, float x) } static int -xps_parse_gradient_stops(xps_context *ctx, char *base_uri, xml_element *node, +xps_parse_gradient_stops(xps_document *doc, char *base_uri, xml_element *node, struct stop *stops, int maxcount) { fz_colorspace *colorspace; @@ -59,9 +59,9 @@ xps_parse_gradient_stops(xps_context *ctx, char *base_uri, xml_element *node, { stops[count].offset = fz_atof(offset); - xps_parse_color(ctx, base_uri, color, &colorspace, sample); + xps_parse_color(doc, base_uri, color, &colorspace, sample); - fz_convert_color(ctx->ctx, colorspace, sample + 1, fz_device_rgb, rgb); + fz_convert_color(doc->ctx, colorspace, sample + 1, fz_device_rgb, rgb); stops[count].r = rgb[0]; stops[count].g = rgb[1]; @@ -76,7 +76,7 @@ xps_parse_gradient_stops(xps_context *ctx, char *base_uri, xml_element *node, if (count == 0) { - fz_warn(ctx->ctx, "gradient brush has no gradient stops"); + fz_warn(doc->ctx, "gradient brush has no gradient stops"); stops[0].offset = 0; stops[0].r = 0; stops[0].g = 0; @@ -91,7 +91,7 @@ xps_parse_gradient_stops(xps_context *ctx, char *base_uri, xml_element *node, } if (count == maxcount) - fz_warn(ctx->ctx, "gradient brush exceeded maximum number of gradient stops"); + fz_warn(doc->ctx, "gradient brush exceeded maximum number of gradient stops"); /* Postprocess to make sure the range of offsets is 0.0 to 1.0 */ @@ -203,7 +203,7 @@ xps_sample_gradient_stops(fz_shade *shade, struct stop *stops, int count) */ static void -xps_draw_one_radial_gradient(xps_context *ctx, fz_matrix ctm, +xps_draw_one_radial_gradient(xps_document *doc, fz_matrix ctm, struct stop *stops, int count, int extend, float x0, float y0, float r0, @@ -212,7 +212,7 @@ xps_draw_one_radial_gradient(xps_context *ctx, fz_matrix ctm, fz_shade *shade; /* TODO: this (and the stuff in pdf_shade) should move to res_shade.c */ - shade = fz_malloc(ctx->ctx, sizeof(fz_shade)); + shade = fz_malloc(doc->ctx, sizeof(fz_shade)); shade->refs = 1; shade->colorspace = fz_device_rgb; shade->bbox = fz_infinite_rect; @@ -227,7 +227,7 @@ xps_draw_one_radial_gradient(xps_context *ctx, fz_matrix ctm, shade->mesh_len = 6; shade->mesh_cap = 6; - shade->mesh = fz_malloc_array(ctx->ctx, shade->mesh_cap, sizeof(float)); + shade->mesh = fz_malloc_array(doc->ctx, shade->mesh_cap, sizeof(float)); shade->mesh[0] = x0; shade->mesh[1] = y0; shade->mesh[2] = r0; @@ -235,9 +235,9 @@ xps_draw_one_radial_gradient(xps_context *ctx, fz_matrix ctm, shade->mesh[4] = y1; shade->mesh[5] = r1; - fz_fill_shade(ctx->dev, shade, ctm, 1); + fz_fill_shade(doc->dev, shade, ctm, 1); - fz_drop_shade(ctx->ctx, shade); + fz_drop_shade(doc->ctx, shade); } /* @@ -245,7 +245,7 @@ xps_draw_one_radial_gradient(xps_context *ctx, fz_matrix ctm, */ static void -xps_draw_one_linear_gradient(xps_context *ctx, fz_matrix ctm, +xps_draw_one_linear_gradient(xps_document *doc, fz_matrix ctm, struct stop *stops, int count, int extend, float x0, float y0, float x1, float y1) @@ -253,7 +253,7 @@ xps_draw_one_linear_gradient(xps_context *ctx, fz_matrix ctm, fz_shade *shade; /* TODO: this (and the stuff in pdf_shade) should move to res_shade.c */ - shade = fz_malloc(ctx->ctx, sizeof(fz_shade)); + shade = fz_malloc(doc->ctx, sizeof(fz_shade)); shade->refs = 1; shade->colorspace = fz_device_rgb; shade->bbox = fz_infinite_rect; @@ -268,7 +268,7 @@ xps_draw_one_linear_gradient(xps_context *ctx, fz_matrix ctm, shade->mesh_len = 6; shade->mesh_cap = 6; - shade->mesh = fz_malloc_array(ctx->ctx, shade->mesh_cap, sizeof(float)); + shade->mesh = fz_malloc_array(doc->ctx, shade->mesh_cap, sizeof(float)); shade->mesh[0] = x0; shade->mesh[1] = y0; shade->mesh[2] = 0; @@ -276,9 +276,9 @@ xps_draw_one_linear_gradient(xps_context *ctx, fz_matrix ctm, shade->mesh[4] = y1; shade->mesh[5] = 0; - fz_fill_shade(ctx->dev, shade, ctm, 1); + fz_fill_shade(doc->dev, shade, ctm, 1); - fz_drop_shade(ctx->ctx, shade); + fz_drop_shade(doc->ctx, shade); } /* @@ -297,7 +297,7 @@ static inline float point_inside_circle(float px, float py, float x, float y, fl } static void -xps_draw_radial_gradient(xps_context *ctx, fz_matrix ctm, +xps_draw_radial_gradient(xps_document *doc, fz_matrix ctm, struct stop *stops, int count, xml_element *root, int spread) { @@ -331,7 +331,7 @@ xps_draw_radial_gradient(xps_context *ctx, fz_matrix ctm, r0 = 0; r1 = xrad; - xps_draw_one_radial_gradient(ctx, ctm, stops, count, 1, x0, y0, r0, x1, y1, r1); + xps_draw_one_radial_gradient(doc, ctm, stops, count, 1, x0, y0, r0, x1, y1, r1); } /* @@ -340,7 +340,7 @@ xps_draw_radial_gradient(xps_context *ctx, fz_matrix ctm, */ static void -xps_draw_linear_gradient(xps_context *ctx, fz_matrix ctm, +xps_draw_linear_gradient(xps_document *doc, fz_matrix ctm, struct stop *stops, int count, xml_element *root, int spread) { @@ -357,7 +357,7 @@ xps_draw_linear_gradient(xps_context *ctx, fz_matrix ctm, if (end_point_att) sscanf(end_point_att, "%g,%g", &x1, &y1); - xps_draw_one_linear_gradient(ctx, ctm, stops, count, 1, x0, y0, x1, y1); + xps_draw_one_linear_gradient(doc, ctm, stops, count, 1, x0, y0, x1, y1); } /* @@ -366,9 +366,9 @@ xps_draw_linear_gradient(xps_context *ctx, fz_matrix ctm, */ static void -xps_parse_gradient_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, +xps_parse_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root, - void (*draw)(xps_context *, fz_matrix, struct stop *, int, xml_element *, int)) + void (*draw)(xps_document *, fz_matrix, struct stop *, int, xml_element *, int)) { xml_element *node; @@ -404,7 +404,7 @@ xps_parse_gradient_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, stop_tag = xml_down(node); } - xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL); + xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); spread_method = SPREAD_PAD; if (spread_att) @@ -419,40 +419,40 @@ xps_parse_gradient_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, transform = fz_identity; if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); + xps_parse_render_transform(doc, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + xps_parse_matrix_transform(doc, transform_tag, &transform); ctm = fz_concat(transform, ctm); if (!stop_tag) { - fz_warn(ctx->ctx, "missing gradient stops tag"); + fz_warn(doc->ctx, "missing gradient stops tag"); return; } - stop_count = xps_parse_gradient_stops(ctx, base_uri, stop_tag, stop_list, MAX_STOPS); + stop_count = xps_parse_gradient_stops(doc, base_uri, stop_tag, stop_list, MAX_STOPS); if (stop_count == 0) { - fz_warn(ctx->ctx, "no gradient stops found"); + fz_warn(doc->ctx, "no gradient stops found"); return; } - xps_begin_opacity(ctx, ctm, area, base_uri, dict, opacity_att, NULL); + xps_begin_opacity(doc, ctm, area, base_uri, dict, opacity_att, NULL); - draw(ctx, ctm, stop_list, stop_count, root, spread_method); + draw(doc, ctm, stop_list, stop_count, root, spread_method); - xps_end_opacity(ctx, base_uri, dict, opacity_att, NULL); + xps_end_opacity(doc, base_uri, dict, opacity_att, NULL); } void -xps_parse_linear_gradient_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, +xps_parse_linear_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root) { - xps_parse_gradient_brush(ctx, ctm, area, base_uri, dict, root, xps_draw_linear_gradient); + xps_parse_gradient_brush(doc, ctm, area, base_uri, dict, root, xps_draw_linear_gradient); } void -xps_parse_radial_gradient_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, +xps_parse_radial_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root) { - xps_parse_gradient_brush(ctx, ctm, area, base_uri, dict, root, xps_draw_radial_gradient); + xps_parse_gradient_brush(doc, ctm, area, base_uri, dict, root, xps_draw_radial_gradient); } diff --git a/xps/xps_image.c b/xps/xps_image.c index 28cadecf..dfe0dd91 100644 --- a/xps/xps_image.c +++ b/xps/xps_image.c @@ -2,7 +2,7 @@ #include "muxps.h" static int -xps_decode_image(fz_context *ctx, fz_pixmap **imagep, byte *buf, int len) +xps_decode_image(fz_context *doc, fz_pixmap **imagep, byte *buf, int len) { int error; @@ -11,13 +11,13 @@ xps_decode_image(fz_context *ctx, fz_pixmap **imagep, byte *buf, int len) if (buf[0] == 0xff && buf[1] == 0xd8) { - error = xps_decode_jpeg(ctx, imagep, buf, len); + error = xps_decode_jpeg(doc, imagep, buf, len); if (error) return fz_error_note(error, "cannot decode jpeg image"); } else if (memcmp(buf, "\211PNG\r\n\032\n", 8) == 0) { - error = xps_decode_png(ctx, imagep, buf, len); + error = xps_decode_png(doc, imagep, buf, len); if (error) return fz_error_note(error, "cannot decode png image"); } @@ -27,7 +27,7 @@ xps_decode_image(fz_context *ctx, fz_pixmap **imagep, byte *buf, int len) } else if (memcmp(buf, "MM", 2) == 0 || memcmp(buf, "II", 2) == 0) { - error = xps_decode_tiff(ctx, imagep, buf, len); + error = xps_decode_tiff(doc, imagep, buf, len); if (error) return fz_error_note(error, "cannot decode TIFF image"); } @@ -38,7 +38,7 @@ xps_decode_image(fz_context *ctx, fz_pixmap **imagep, byte *buf, int len) } static void -xps_paint_image_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, +xps_paint_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root, void *vimage) { fz_pixmap *pixmap = vimage; @@ -47,11 +47,11 @@ xps_paint_image_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_ fz_matrix im = fz_scale(xs, -ys); im.f = ys; ctm = fz_concat(im, ctm); - fz_fill_image(ctx->dev, pixmap, ctm, ctx->opacity[ctx->opacity_top]); + fz_fill_image(doc->dev, pixmap, ctm, doc->opacity[doc->opacity_top]); } static xps_part * -xps_find_image_brush_source_part(xps_context *ctx, char *base_uri, xml_element *root) +xps_find_image_brush_source_part(xps_document *doc, char *base_uri, xml_element *root) { char *image_source_att; char buf[1024]; @@ -97,32 +97,32 @@ xps_find_image_brush_source_part(xps_context *ctx, char *base_uri, xml_element * xps_absolute_path(partname, base_uri, image_name, sizeof partname); - return xps_read_part(ctx, partname); + return xps_read_part(doc, partname); } void -xps_parse_image_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, +xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root) { xps_part *part; fz_pixmap *image; int code; - part = xps_find_image_brush_source_part(ctx, base_uri, root); + part = xps_find_image_brush_source_part(doc, base_uri, root); if (!part) { - fz_warn(ctx, "cannot find image source"); + fz_warn(doc->ctx, "cannot find image source"); return; } - code = xps_decode_image(ctx->ctx, &image, part->data, part->size); + code = xps_decode_image(doc->ctx, &image, part->data, part->size); if (code < 0) { - xps_free_part(ctx, part); + xps_free_part(doc, part); fz_error_handle(-1, "cannot decode image resource"); return; } - xps_parse_tiling_brush(ctx, ctm, area, base_uri, dict, root, xps_paint_image_brush, image); + xps_parse_tiling_brush(doc, ctm, area, base_uri, dict, root, xps_paint_image_brush, image); - fz_drop_pixmap(ctx->ctx, image); - xps_free_part(ctx, part); + fz_drop_pixmap(doc->ctx, image); + xps_free_part(doc, part); } diff --git a/xps/xps_jpeg.c b/xps/xps_jpeg.c index 368f1d73..e96bcd8c 100644 --- a/xps/xps_jpeg.c +++ b/xps/xps_jpeg.c @@ -48,7 +48,7 @@ static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) } int -xps_decode_jpeg(fz_context *ctx, fz_pixmap **imagep, byte *rbuf, int rlen) +xps_decode_jpeg(fz_context *doc, fz_pixmap **imagep, byte *rbuf, int rlen) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr_jmp err; @@ -63,7 +63,7 @@ xps_decode_jpeg(fz_context *ctx, fz_pixmap **imagep, byte *rbuf, int rlen) if (setjmp(err.env)) { if (image) - fz_drop_pixmap(ctx, image); + fz_drop_pixmap(doc, image); return fz_error_make("jpeg error: %s", err.msg); } @@ -94,7 +94,7 @@ xps_decode_jpeg(fz_context *ctx, fz_pixmap **imagep, byte *rbuf, int rlen) else return fz_error_make("bad number of components in jpeg: %d", cinfo.output_components); - image = fz_new_pixmap_with_limit(ctx, colorspace, cinfo.output_width, cinfo.output_height); + image = fz_new_pixmap_with_limit(doc, colorspace, cinfo.output_width, cinfo.output_height); if (!image) { jpeg_finish_decompress(&cinfo); @@ -115,7 +115,7 @@ xps_decode_jpeg(fz_context *ctx, fz_pixmap **imagep, byte *rbuf, int rlen) fz_clear_pixmap(image); - row[0] = fz_malloc(ctx, cinfo.output_components * cinfo.output_width); + row[0] = fz_malloc(doc, cinfo.output_components * cinfo.output_width); dp = image->samples; while (cinfo.output_scanline < cinfo.output_height) { @@ -128,7 +128,7 @@ xps_decode_jpeg(fz_context *ctx, fz_pixmap **imagep, byte *rbuf, int rlen) *dp++ = 255; } } - fz_free(ctx, row[0]); + fz_free(doc, row[0]); jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); diff --git a/xps/xps_path.c b/xps/xps_path.c index fcc6f571..ead2c7fa 100644 --- a/xps/xps_path.c +++ b/xps/xps_path.c @@ -41,7 +41,7 @@ fz_currentpoint(fz_path *path) * without transforming the line width. */ static void -xps_draw_arc_segment(fz_context *ctx, fz_path *path, fz_matrix mtx, float th0, float th1, int iscw) +xps_draw_arc_segment(fz_context *doc, fz_path *path, fz_matrix mtx, float th0, float th1, int iscw) { float t, d; fz_point p; @@ -56,18 +56,18 @@ xps_draw_arc_segment(fz_context *ctx, fz_path *path, fz_matrix mtx, float th0, f p.x = cosf(th0); p.y = sinf(th0); p = fz_transform_point(mtx, p); - fz_lineto(ctx, path, p.x, p.y); + fz_lineto(doc, path, p.x, p.y); for (t = th0; t < th1; t += d) { p.x = cosf(t); p.y = sinf(t); p = fz_transform_point(mtx, p); - fz_lineto(ctx, path, p.x, p.y); + fz_lineto(doc, path, p.x, p.y); } p.x = cosf(th1); p.y = sinf(th1); p = fz_transform_point(mtx, p); - fz_lineto(ctx, path, p.x, p.y); + fz_lineto(doc, path, p.x, p.y); } else { @@ -75,18 +75,18 @@ xps_draw_arc_segment(fz_context *ctx, fz_path *path, fz_matrix mtx, float th0, f p.x = cosf(th0); p.y = sinf(th0); p = fz_transform_point(mtx, p); - fz_lineto(ctx, path, p.x, p.y); + fz_lineto(doc, path, p.x, p.y); for (t = th0; t > th1; t -= d) { p.x = cosf(t); p.y = sinf(t); p = fz_transform_point(mtx, p); - fz_lineto(ctx, path, p.x, p.y); + fz_lineto(doc, path, p.x, p.y); } p.x = cosf(th1); p.y = sinf(th1); p = fz_transform_point(mtx, p); - fz_lineto(ctx, path, p.x, p.y); + fz_lineto(doc, path, p.x, p.y); } } @@ -107,7 +107,7 @@ angle_between(const fz_point u, const fz_point v) } static void -xps_draw_arc(fz_context *ctx, fz_path *path, +xps_draw_arc(fz_context *doc, fz_path *path, float size_x, float size_y, float rotation_angle, int is_large_arc, int is_clockwise, float point_x, float point_y) @@ -147,7 +147,7 @@ xps_draw_arc(fz_context *ctx, fz_path *path, ry = fabsf(ry); if (rx < 0.001f || ry < 0.001f) { - fz_lineto(ctx, path, x2, y2); + fz_lineto(doc, path, x2, y2); return; } @@ -207,9 +207,9 @@ xps_draw_arc(fz_context *ctx, fz_path *path, mtx = fz_concat(fz_translate(cx, cy), mtx); mtx = fz_concat(fz_rotate(rotation_angle), mtx); mtx = fz_concat(fz_scale(rx, ry), mtx); - xps_draw_arc_segment(ctx, path, mtx, th1, th1 + dth, is_clockwise); + xps_draw_arc_segment(doc, path, mtx, th1, th1 + dth, is_clockwise); - fz_lineto(ctx, path, point_x, point_y); + fz_lineto(doc, path, point_x, point_y); } /* @@ -219,7 +219,7 @@ xps_draw_arc(fz_context *ctx, fz_path *path, */ static fz_path * -xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) +xps_parse_abbreviated_geometry(xps_document *doc, char *geom, int *fill_rule) { fz_path *path; char **args; @@ -232,9 +232,9 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) float smooth_x, smooth_y; /* saved cubic bezier control point for smooth curves */ int reset_smooth; - path = fz_new_path(ctx->ctx); + path = fz_new_path(doc->ctx); - args = fz_malloc_array(ctx->ctx, strlen(geom) + 1, sizeof(char*)); + args = fz_malloc_array(doc->ctx, strlen(geom) + 1, sizeof(char*)); pargs = args; while (*s) @@ -291,44 +291,44 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) break; case 'M': - fz_moveto(ctx->ctx, path, fz_atof(args[i]), fz_atof(args[i+1])); + fz_moveto(doc->ctx, path, fz_atof(args[i]), fz_atof(args[i+1])); i += 2; break; case 'm': pt = fz_currentpoint(path); - fz_moveto(ctx->ctx, path, pt.x + fz_atof(args[i]), pt.y + fz_atof(args[i+1])); + fz_moveto(doc->ctx, path, pt.x + fz_atof(args[i]), pt.y + fz_atof(args[i+1])); i += 2; break; case 'L': - fz_lineto(ctx->ctx, path, fz_atof(args[i]), fz_atof(args[i+1])); + fz_lineto(doc->ctx, path, fz_atof(args[i]), fz_atof(args[i+1])); i += 2; break; case 'l': pt = fz_currentpoint(path); - fz_lineto(ctx->ctx, path, pt.x + fz_atof(args[i]), pt.y + fz_atof(args[i+1])); + fz_lineto(doc->ctx, path, pt.x + fz_atof(args[i]), pt.y + fz_atof(args[i+1])); i += 2; break; case 'H': pt = fz_currentpoint(path); - fz_lineto(ctx->ctx, path, fz_atof(args[i]), pt.y); + fz_lineto(doc->ctx, path, fz_atof(args[i]), pt.y); i += 1; break; case 'h': pt = fz_currentpoint(path); - fz_lineto(ctx->ctx, path, pt.x + fz_atof(args[i]), pt.y); + fz_lineto(doc->ctx, path, pt.x + fz_atof(args[i]), pt.y); i += 1; break; case 'V': pt = fz_currentpoint(path); - fz_lineto(ctx->ctx, path, pt.x, fz_atof(args[i])); + fz_lineto(doc->ctx, path, pt.x, fz_atof(args[i])); i += 1; break; case 'v': pt = fz_currentpoint(path); - fz_lineto(ctx->ctx, path, pt.x, pt.y + fz_atof(args[i])); + fz_lineto(doc->ctx, path, pt.x, pt.y + fz_atof(args[i])); i += 1; break; @@ -339,7 +339,7 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) y2 = fz_atof(args[i+3]); x3 = fz_atof(args[i+4]); y3 = fz_atof(args[i+5]); - fz_curveto(ctx->ctx, path, x1, y1, x2, y2, x3, y3); + fz_curveto(doc->ctx, path, x1, y1, x2, y2, x3, y3); i += 6; reset_smooth = 0; smooth_x = x3 - x2; @@ -354,7 +354,7 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) y2 = fz_atof(args[i+3]) + pt.y; x3 = fz_atof(args[i+4]) + pt.x; y3 = fz_atof(args[i+5]) + pt.y; - fz_curveto(ctx->ctx, path, x1, y1, x2, y2, x3, y3); + fz_curveto(doc->ctx, path, x1, y1, x2, y2, x3, y3); i += 6; reset_smooth = 0; smooth_x = x3 - x2; @@ -367,7 +367,7 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) y1 = fz_atof(args[i+1]); x2 = fz_atof(args[i+2]); y2 = fz_atof(args[i+3]); - fz_curveto(ctx->ctx, path, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2); + fz_curveto(doc->ctx, path, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2); i += 4; reset_smooth = 0; smooth_x = x2 - x1; @@ -380,7 +380,7 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) y1 = fz_atof(args[i+1]) + pt.y; x2 = fz_atof(args[i+2]) + pt.x; y2 = fz_atof(args[i+3]) + pt.y; - fz_curveto(ctx->ctx, path, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2); + fz_curveto(doc->ctx, path, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2); i += 4; reset_smooth = 0; smooth_x = x2 - x1; @@ -393,7 +393,7 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) y1 = fz_atof(args[i+1]); x2 = fz_atof(args[i+2]); y2 = fz_atof(args[i+3]); - fz_curveto(ctx->ctx, path, + fz_curveto(doc->ctx, path, (pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3, (x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3, x2, y2); @@ -405,7 +405,7 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) y1 = fz_atof(args[i+1]) + pt.y; x2 = fz_atof(args[i+2]) + pt.x; y2 = fz_atof(args[i+3]) + pt.y; - fz_curveto(ctx->ctx, path, + fz_curveto(doc->ctx, path, (pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3, (x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3, x2, y2); @@ -413,7 +413,7 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) break; case 'A': - xps_draw_arc(ctx->ctx, path, + xps_draw_arc(doc->ctx, path, fz_atof(args[i+0]), fz_atof(args[i+1]), fz_atof(args[i+2]), atoi(args[i+3]), atoi(args[i+4]), fz_atof(args[i+5]), fz_atof(args[i+6])); @@ -421,7 +421,7 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) break; case 'a': pt = fz_currentpoint(path); - xps_draw_arc(ctx->ctx, path, + xps_draw_arc(doc->ctx, path, fz_atof(args[i+0]), fz_atof(args[i+1]), fz_atof(args[i+2]), atoi(args[i+3]), atoi(args[i+4]), fz_atof(args[i+5]) + pt.x, fz_atof(args[i+6]) + pt.y); @@ -430,7 +430,7 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) case 'Z': case 'z': - fz_closepath(ctx->ctx, path); + fz_closepath(doc->ctx, path); break; default: @@ -441,12 +441,12 @@ xps_parse_abbreviated_geometry(xps_context *ctx, char *geom, int *fill_rule) old = cmd; } - fz_free(ctx->ctx, args); + fz_free(doc->ctx, args); return path; } static void -xps_parse_arc_segment(fz_context *ctx, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) +xps_parse_arc_segment(fz_context *doc, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) { /* ArcSegment pretty much follows the SVG algorithm for converting an * arc in endpoint representation to an arc in centerpoint @@ -468,7 +468,7 @@ xps_parse_arc_segment(fz_context *ctx, fz_path *path, xml_element *root, int str if (!point_att || !size_att || !rotation_angle_att || !is_large_arc_att || !sweep_direction_att) { - fz_warn(ctx, "ArcSegment element is missing attributes"); + fz_warn(doc, "ArcSegment element is missing attributes"); return; } @@ -486,15 +486,15 @@ xps_parse_arc_segment(fz_context *ctx, fz_path *path, xml_element *root, int str if (stroking && !is_stroked) { - fz_moveto(ctx, path, point_x, point_y); + fz_moveto(doc, path, point_x, point_y); return; } - xps_draw_arc(ctx, path, size_x, size_y, rotation_angle, is_large_arc, is_clockwise, point_x, point_y); + xps_draw_arc(doc, path, size_x, size_y, rotation_angle, is_large_arc, is_clockwise, point_x, point_y); } static void -xps_parse_poly_quadratic_bezier_segment(fz_context *ctx, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) +xps_parse_poly_quadratic_bezier_segment(fz_context *doc, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) { char *points_att = xml_att(root, "Points"); char *is_stroked_att = xml_att(root, "IsStroked"); @@ -506,7 +506,7 @@ xps_parse_poly_quadratic_bezier_segment(fz_context *ctx, fz_path *path, xml_elem if (!points_att) { - fz_warn(ctx, "PolyQuadraticBezierSegment element has no points"); + fz_warn(doc, "PolyQuadraticBezierSegment element has no points"); return; } @@ -528,12 +528,12 @@ xps_parse_poly_quadratic_bezier_segment(fz_context *ctx, fz_path *path, xml_elem { if (stroking && !is_stroked) { - fz_moveto(ctx, path, x[1], y[1]); + fz_moveto(doc, path, x[1], y[1]); } else { pt = fz_currentpoint(path); - fz_curveto(ctx, path, + fz_curveto(doc, path, (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]); @@ -544,7 +544,7 @@ xps_parse_poly_quadratic_bezier_segment(fz_context *ctx, fz_path *path, xml_elem } static void -xps_parse_poly_bezier_segment(fz_context *ctx, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) +xps_parse_poly_bezier_segment(fz_context *doc, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) { char *points_att = xml_att(root, "Points"); char *is_stroked_att = xml_att(root, "IsStroked"); @@ -555,7 +555,7 @@ xps_parse_poly_bezier_segment(fz_context *ctx, fz_path *path, xml_element *root, if (!points_att) { - fz_warn(ctx, "PolyBezierSegment element has no points"); + fz_warn(doc, "PolyBezierSegment element has no points"); return; } @@ -576,16 +576,16 @@ xps_parse_poly_bezier_segment(fz_context *ctx, fz_path *path, xml_element *root, if (n == 3) { if (stroking && !is_stroked) - fz_moveto(ctx, path, x[2], y[2]); + fz_moveto(doc, path, x[2], y[2]); else - fz_curveto(ctx, path, x[0], y[0], x[1], y[1], x[2], y[2]); + fz_curveto(doc, path, x[0], y[0], x[1], y[1], x[2], y[2]); n = 0; } } } static void -xps_parse_poly_line_segment(fz_context *ctx, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) +xps_parse_poly_line_segment(fz_context *doc, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) { char *points_att = xml_att(root, "Points"); char *is_stroked_att = xml_att(root, "IsStroked"); @@ -595,7 +595,7 @@ xps_parse_poly_line_segment(fz_context *ctx, fz_path *path, xml_element *root, i if (!points_att) { - fz_warn(ctx, "PolyLineSegment element has no points"); + fz_warn(doc, "PolyLineSegment element has no points"); return; } @@ -611,15 +611,15 @@ xps_parse_poly_line_segment(fz_context *ctx, fz_path *path, xml_element *root, i while (*s == ' ') s++; sscanf(s, "%g,%g", &x, &y); if (stroking && !is_stroked) - fz_moveto(ctx, path, x, y); + fz_moveto(doc, path, x, y); else - fz_lineto(ctx, path, x, y); + fz_lineto(doc, path, x, y); while (*s != ' ' && *s != 0) s++; } } static void -xps_parse_path_figure(fz_context *ctx, fz_path *path, xml_element *root, int stroking) +xps_parse_path_figure(fz_context *doc, fz_path *path, xml_element *root, int stroking) { xml_element *node; @@ -648,31 +648,31 @@ xps_parse_path_figure(fz_context *ctx, fz_path *path, xml_element *root, int str if (!stroking && !is_filled) /* not filled, when filling */ return; - fz_moveto(ctx, path, start_x, start_y); + fz_moveto(doc, path, start_x, start_y); for (node = xml_down(root); node; node = xml_next(node)) { if (!strcmp(xml_tag(node), "ArcSegment")) - xps_parse_arc_segment(ctx, path, node, stroking, &skipped_stroke); + xps_parse_arc_segment(doc, path, node, stroking, &skipped_stroke); if (!strcmp(xml_tag(node), "PolyBezierSegment")) - xps_parse_poly_bezier_segment(ctx, path, node, stroking, &skipped_stroke); + xps_parse_poly_bezier_segment(doc, path, node, stroking, &skipped_stroke); if (!strcmp(xml_tag(node), "PolyLineSegment")) - xps_parse_poly_line_segment(ctx, path, node, stroking, &skipped_stroke); + xps_parse_poly_line_segment(doc, path, node, stroking, &skipped_stroke); if (!strcmp(xml_tag(node), "PolyQuadraticBezierSegment")) - xps_parse_poly_quadratic_bezier_segment(ctx, path, node, stroking, &skipped_stroke); + xps_parse_poly_quadratic_bezier_segment(doc, path, node, stroking, &skipped_stroke); } if (is_closed) { if (stroking && skipped_stroke) - fz_lineto(ctx, path, start_x, start_y); /* we've skipped using fz_moveto... */ + fz_lineto(doc, path, start_x, start_y); /* we've skipped using fz_moveto... */ else - fz_closepath(ctx, path); /* no skipped segments, safe to closepath properly */ + fz_closepath(doc, path); /* no skipped segments, safe to closepath properly */ } } fz_path * -xps_parse_path_geometry(xps_context *ctx, xps_resource *dict, xml_element *root, int stroking, int *fill_rule) +xps_parse_path_geometry(xps_document *doc, xps_resource *dict, xml_element *root, int stroking, int *fill_rule) { xml_element *node; @@ -696,8 +696,8 @@ xps_parse_path_geometry(xps_context *ctx, xps_resource *dict, xml_element *root, transform_tag = xml_down(node); } - xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL); - xps_resolve_resource_reference(ctx, dict, &figures_att, &figures_tag, NULL); + xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); + xps_resolve_resource_reference(doc, dict, &figures_att, &figures_tag, NULL); if (fill_rule_att) { @@ -709,22 +709,22 @@ xps_parse_path_geometry(xps_context *ctx, xps_resource *dict, xml_element *root, transform = fz_identity; if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); + xps_parse_render_transform(doc, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + xps_parse_matrix_transform(doc, transform_tag, &transform); if (figures_att) - path = xps_parse_abbreviated_geometry(ctx, figures_att, fill_rule); + path = xps_parse_abbreviated_geometry(doc, figures_att, fill_rule); else - path = fz_new_path(ctx->ctx); + path = fz_new_path(doc->ctx); if (figures_tag) - xps_parse_path_figure(ctx->ctx, path, figures_tag, stroking); + xps_parse_path_figure(doc->ctx, path, figures_tag, stroking); for (node = xml_down(root); node; node = xml_next(node)) { if (!strcmp(xml_tag(node), "PathFigure")) - xps_parse_path_figure(ctx->ctx, path, node, stroking); + xps_parse_path_figure(doc->ctx, path, node, stroking); } if (transform_att || transform_tag) @@ -747,19 +747,19 @@ xps_parse_line_cap(char *attr) } void -xps_clip(xps_context *ctx, fz_matrix ctm, xps_resource *dict, char *clip_att, xml_element *clip_tag) +xps_clip(xps_document *doc, fz_matrix ctm, xps_resource *dict, char *clip_att, xml_element *clip_tag) { fz_path *path; int fill_rule = 0; if (clip_att) - path = xps_parse_abbreviated_geometry(ctx, clip_att, &fill_rule); + path = xps_parse_abbreviated_geometry(doc, clip_att, &fill_rule); else if (clip_tag) - path = xps_parse_path_geometry(ctx, dict, clip_tag, 0, &fill_rule); + path = xps_parse_path_geometry(doc, dict, clip_tag, 0, &fill_rule); else - path = fz_new_path(ctx->ctx); - fz_clip_path(ctx->dev, path, NULL, fill_rule == 0, ctm); - fz_free_path(ctx->ctx, path); + path = fz_new_path(doc->ctx); + fz_clip_path(doc->dev, path, NULL, fill_rule == 0, ctm); + fz_free_path(doc->ctx, path); } /* @@ -768,7 +768,7 @@ xps_clip(xps_context *ctx, fz_matrix ctm, xps_resource *dict, char *clip_att, xm */ void -xps_parse_path(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *root) +xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *root) { xml_element *node; @@ -852,12 +852,12 @@ xps_parse_path(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *di stroke_uri = base_uri; opacity_mask_uri = base_uri; - xps_resolve_resource_reference(ctx, dict, &data_att, &data_tag, NULL); - xps_resolve_resource_reference(ctx, dict, &clip_att, &clip_tag, NULL); - xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL); - xps_resolve_resource_reference(ctx, dict, &fill_att, &fill_tag, &fill_uri); - xps_resolve_resource_reference(ctx, dict, &stroke_att, &stroke_tag, &stroke_uri); - xps_resolve_resource_reference(ctx, dict, &opacity_mask_att, &opacity_mask_tag, &opacity_mask_uri); + xps_resolve_resource_reference(doc, dict, &data_att, &data_tag, NULL); + xps_resolve_resource_reference(doc, dict, &clip_att, &clip_tag, NULL); + xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); + xps_resolve_resource_reference(doc, dict, &fill_att, &fill_tag, &fill_uri); + xps_resolve_resource_reference(doc, dict, &stroke_att, &stroke_tag, &stroke_uri); + xps_resolve_resource_reference(doc, dict, &opacity_mask_att, &opacity_mask_tag, &opacity_mask_uri); /* * Act on the information we have gathered: @@ -921,70 +921,70 @@ xps_parse_path(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *di transform = fz_identity; if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); + xps_parse_render_transform(doc, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + xps_parse_matrix_transform(doc, transform_tag, &transform); ctm = fz_concat(transform, ctm); if (clip_att || clip_tag) - xps_clip(ctx, ctm, dict, clip_att, clip_tag); + xps_clip(doc, ctm, dict, clip_att, clip_tag); fill_rule = 0; if (data_att) - path = xps_parse_abbreviated_geometry(ctx, data_att, &fill_rule); + path = xps_parse_abbreviated_geometry(doc, data_att, &fill_rule); else if (data_tag) - path = xps_parse_path_geometry(ctx, dict, data_tag, 0, &fill_rule); + path = xps_parse_path_geometry(doc, dict, data_tag, 0, &fill_rule); if (stroke_att || stroke_tag) area = fz_bound_path(path, &stroke, ctm); else area = fz_bound_path(path, NULL, ctm); - xps_begin_opacity(ctx, ctm, area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); + xps_begin_opacity(doc, ctm, area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); if (fill_att) { - xps_parse_color(ctx, base_uri, fill_att, &colorspace, samples); + xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); if (fill_opacity_att) samples[0] = fz_atof(fill_opacity_att); - xps_set_color(ctx, colorspace, samples); + xps_set_color(doc, colorspace, samples); - fz_fill_path(ctx->dev, path, fill_rule == 0, ctm, - ctx->colorspace, ctx->color, ctx->alpha); + fz_fill_path(doc->dev, path, fill_rule == 0, ctm, + doc->colorspace, doc->color, doc->alpha); } if (fill_tag) { area = fz_bound_path(path, NULL, ctm); - fz_clip_path(ctx->dev, path, NULL, fill_rule == 0, ctm); - xps_parse_brush(ctx, ctm, area, fill_uri, dict, fill_tag); - fz_pop_clip(ctx->dev); + fz_clip_path(doc->dev, path, NULL, fill_rule == 0, ctm); + xps_parse_brush(doc, ctm, area, fill_uri, dict, fill_tag); + fz_pop_clip(doc->dev); } if (stroke_att) { - xps_parse_color(ctx, base_uri, stroke_att, &colorspace, samples); + xps_parse_color(doc, base_uri, stroke_att, &colorspace, samples); if (stroke_opacity_att) samples[0] = fz_atof(stroke_opacity_att); - xps_set_color(ctx, colorspace, samples); + xps_set_color(doc, colorspace, samples); - fz_stroke_path(ctx->dev, path, &stroke, ctm, - ctx->colorspace, ctx->color, ctx->alpha); + fz_stroke_path(doc->dev, path, &stroke, ctm, + doc->colorspace, doc->color, doc->alpha); } if (stroke_tag) { - fz_clip_stroke_path(ctx->dev, path, NULL, &stroke, ctm); - xps_parse_brush(ctx, ctm, area, stroke_uri, dict, stroke_tag); - fz_pop_clip(ctx->dev); + fz_clip_stroke_path(doc->dev, path, NULL, &stroke, ctm); + xps_parse_brush(doc, ctm, area, stroke_uri, dict, stroke_tag); + fz_pop_clip(doc->dev); } - xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); + xps_end_opacity(doc, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); - fz_free_path(ctx->ctx, path); + fz_free_path(doc->ctx, path); path = NULL; if (clip_att || clip_tag) - fz_pop_clip(ctx->dev); + fz_pop_clip(doc->dev); } diff --git a/xps/xps_png.c b/xps/xps_png.c index 4c8b5150..203f9676 100644 --- a/xps/xps_png.c +++ b/xps/xps_png.c @@ -5,7 +5,7 @@ struct info { - fz_context *ctx; + fz_context *doc; int width, height, depth, n; int interlace, indexed; int size; @@ -189,7 +189,7 @@ png_deinterlace(struct info *info, int *passw, int *passh, int *passofs) unsigned char *output; int p, x, y, k; - output = fz_malloc_array(info->ctx, info->height, stride); + output = fz_malloc_array(info->doc, info->height, stride); for (p = 0; p < 7; p++) { @@ -215,7 +215,7 @@ png_deinterlace(struct info *info, int *passw, int *passh, int *passofs) } } - fz_free(info->ctx, info->samples); + fz_free(info->doc, info->samples); info->samples = output; } @@ -409,11 +409,11 @@ png_read_image(struct info *info, unsigned char *p, int total) info->size = passofs[7]; } - info->samples = fz_malloc(info->ctx, info->size); + info->samples = fz_malloc(info->doc, info->size); stm.zalloc = zalloc; stm.zfree = zfree; - stm.opaque = info->ctx; + stm.opaque = info->doc; stm.next_out = info->samples; stm.avail_out = info->size; @@ -481,9 +481,9 @@ png_read_image(struct info *info, unsigned char *p, int total) } static fz_pixmap * -png_expand_palette(fz_context *ctx, struct info *info, fz_pixmap *src) +png_expand_palette(fz_context *doc, struct info *info, fz_pixmap *src) { - fz_pixmap *dst = fz_new_pixmap(ctx, fz_device_rgb, src->w, src->h); + fz_pixmap *dst = fz_new_pixmap(doc, fz_device_rgb, src->w, src->h); unsigned char *sp = src->samples; unsigned char *dp = dst->samples; int x, y; @@ -504,7 +504,7 @@ png_expand_palette(fz_context *ctx, struct info *info, fz_pixmap *src) } } - fz_drop_pixmap(info->ctx, src); + fz_drop_pixmap(info->doc, src); return dst; } @@ -533,7 +533,7 @@ png_mask_transparency(struct info *info, fz_pixmap *dst) } int -xps_decode_png(fz_context *ctx, fz_pixmap **imagep, byte *p, int total) +xps_decode_png(fz_context *doc, fz_pixmap **imagep, byte *p, int total) { fz_pixmap *image; fz_colorspace *colorspace; @@ -541,7 +541,7 @@ xps_decode_png(fz_context *ctx, fz_pixmap **imagep, byte *p, int total) int code; int stride; - png.ctx = ctx; + png.doc = doc; code = png_read_image(&png, p, total); if (code) return fz_error_note(code, "cannot read png image"); @@ -553,10 +553,10 @@ xps_decode_png(fz_context *ctx, fz_pixmap **imagep, byte *p, int total) stride = (png.width * png.n * png.depth + 7) / 8; - image = fz_new_pixmap_with_limit(ctx, colorspace, png.width, png.height); + image = fz_new_pixmap_with_limit(doc, colorspace, png.width, png.height); if (!image) { - fz_free(png.ctx, png.samples); + fz_free(png.doc, png.samples); return fz_error_make("out of memory"); } @@ -566,14 +566,14 @@ xps_decode_png(fz_context *ctx, fz_pixmap **imagep, byte *p, int total) fz_unpack_tile(image, png.samples, png.n, png.depth, stride, png.indexed); if (png.indexed) - image = png_expand_palette(ctx, &png, image); + image = png_expand_palette(doc, &png, image); else if (png.transparency) png_mask_transparency(&png, image); if (png.transparency || png.n == 2 || png.n == 4) fz_premultiply_pixmap(image); - fz_free(png.ctx, png.samples); + fz_free(png.doc, png.samples); *imagep = image; return fz_okay; diff --git a/xps/xps_resource.c b/xps/xps_resource.c index 176afd77..4a084b29 100644 --- a/xps/xps_resource.c +++ b/xps/xps_resource.c @@ -2,7 +2,7 @@ #include "muxps.h" static xml_element * -xps_find_resource(xps_context *ctx, xps_resource *dict, char *name, char **urip) +xps_find_resource(xps_document *doc, xps_resource *dict, char *name, char **urip) { xps_resource *head, *node; for (head = dict; head; head = head->parent) @@ -21,7 +21,7 @@ xps_find_resource(xps_context *ctx, xps_resource *dict, char *name, char **urip) } static xml_element * -xps_parse_resource_reference(xps_context *ctx, xps_resource *dict, char *att, char **urip) +xps_parse_resource_reference(xps_document *doc, xps_resource *dict, char *att, char **urip) { char name[1024]; char *s; @@ -34,16 +34,16 @@ xps_parse_resource_reference(xps_context *ctx, xps_resource *dict, char *att, ch if (s) *s = 0; - return xps_find_resource(ctx, dict, name, urip); + return xps_find_resource(doc, dict, name, urip); } void -xps_resolve_resource_reference(xps_context *ctx, xps_resource *dict, +xps_resolve_resource_reference(xps_document *doc, xps_resource *dict, char **attp, xml_element **tagp, char **urip) { if (*attp) { - xml_element *rsrc = xps_parse_resource_reference(ctx, dict, *attp, urip); + xml_element *rsrc = xps_parse_resource_reference(doc, dict, *attp, urip); if (rsrc) { *attp = NULL; @@ -53,7 +53,7 @@ xps_resolve_resource_reference(xps_context *ctx, xps_resource *dict, } static int -xps_parse_remote_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base_uri, char *source_att) +xps_parse_remote_resource_dictionary(xps_document *doc, xps_resource **dictp, char *base_uri, char *source_att) { char part_name[1024]; char part_uri[1024]; @@ -65,23 +65,23 @@ xps_parse_remote_resource_dictionary(xps_context *ctx, xps_resource **dictp, cha /* External resource dictionaries MUST NOT reference other resource dictionaries */ xps_absolute_path(part_name, base_uri, source_att, sizeof part_name); - part = xps_read_part(ctx, part_name); + part = xps_read_part(doc, part_name); if (!part) { return fz_error_make("cannot find remote resource part '%s'", part_name); } - xml = xml_parse_document(ctx->ctx, part->data, part->size); + xml = xml_parse_document(doc->ctx, part->data, part->size); if (!xml) { - xps_free_part(ctx, part); + xps_free_part(doc, part); return fz_error_note(-1, "cannot parse xml"); } if (strcmp(xml_tag(xml), "ResourceDictionary")) { - xml_free_element(ctx->ctx, xml); - xps_free_part(ctx, part); + xml_free_element(doc->ctx, xml); + xps_free_part(doc, part); return fz_error_make("expected ResourceDictionary element (found %s)", xml_tag(xml)); } @@ -90,24 +90,24 @@ xps_parse_remote_resource_dictionary(xps_context *ctx, xps_resource **dictp, cha if (s) s[1] = 0; - code = xps_parse_resource_dictionary(ctx, &dict, part_uri, xml); + code = xps_parse_resource_dictionary(doc, &dict, part_uri, xml); if (code) { - xml_free_element(ctx->ctx, xml); - xps_free_part(ctx, part); + xml_free_element(doc->ctx, xml); + xps_free_part(doc, part); return fz_error_note(code, "cannot parse remote resource dictionary: %s", part_uri); } dict->base_xml = xml; /* pass on ownership */ - xps_free_part(ctx, part); + xps_free_part(doc, part); *dictp = dict; return fz_okay; } int -xps_parse_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base_uri, xml_element *root) +xps_parse_resource_dictionary(xps_document *doc, xps_resource **dictp, char *base_uri, xml_element *root) { xps_resource *head; xps_resource *entry; @@ -119,7 +119,7 @@ xps_parse_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base source = xml_att(root, "Source"); if (source) { - code = xps_parse_remote_resource_dictionary(ctx, dictp, base_uri, source); + code = xps_parse_remote_resource_dictionary(doc, dictp, base_uri, source); if (code) return fz_error_note(code, "cannot parse remote resource dictionary"); return fz_okay; @@ -132,7 +132,7 @@ xps_parse_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base key = xml_att(node, "x:Key"); if (key) { - entry = fz_malloc(ctx->ctx, sizeof(xps_resource)); + entry = fz_malloc(doc->ctx, sizeof(xps_resource)); entry->name = key; entry->base_uri = NULL; entry->base_xml = NULL; @@ -144,7 +144,7 @@ xps_parse_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base } if (head) - head->base_uri = fz_strdup(ctx->ctx, base_uri); + head->base_uri = fz_strdup(doc->ctx, base_uri); else return fz_error_make("empty resource dictionary"); @@ -153,17 +153,17 @@ xps_parse_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base } void -xps_free_resource_dictionary(xps_context *ctx, xps_resource *dict) +xps_free_resource_dictionary(xps_document *doc, xps_resource *dict) { xps_resource *next; while (dict) { next = dict->next; if (dict->base_xml) - xml_free_element(ctx->ctx, dict->base_xml); + xml_free_element(doc->ctx, dict->base_xml); if (dict->base_uri) - fz_free(ctx->ctx, dict->base_uri); - fz_free(ctx->ctx, dict); + fz_free(doc->ctx, dict->base_uri); + fz_free(doc->ctx, dict); dict = next; } } diff --git a/xps/xps_tiff.c b/xps/xps_tiff.c index f970f153..7496cb56 100644 --- a/xps/xps_tiff.c +++ b/xps/xps_tiff.c @@ -56,7 +56,7 @@ struct tiff fz_colorspace *colorspace; byte *samples; int stride; - fz_context *ctx; + fz_context *doc; }; enum @@ -183,15 +183,15 @@ xps_decode_tiff_fax(struct tiff *tiff, int comp, fz_stream *chain, byte *wp, int fz_obj *params; fz_obj *columns, *rows, *black_is_1, *k, *encoded_byte_align; int n; - fz_context *ctx = tiff->ctx; + fz_context *doc = tiff->doc; - columns = fz_new_int(ctx, tiff->imagewidth); - rows = fz_new_int(ctx, tiff->imagelength); - black_is_1 = fz_new_bool(ctx, tiff->photometric == 0); - k = fz_new_int(ctx, comp == 4 ? -1 : 0); - encoded_byte_align = fz_new_bool(ctx, comp == 2); + columns = fz_new_int(doc, tiff->imagewidth); + rows = fz_new_int(doc, tiff->imagelength); + black_is_1 = fz_new_bool(doc, tiff->photometric == 0); + k = fz_new_int(doc, comp == 4 ? -1 : 0); + encoded_byte_align = fz_new_bool(doc, comp == 2); - params = fz_new_dict(ctx, 5); + params = fz_new_dict(doc, 5); fz_dict_puts(params, "Columns", columns); fz_dict_puts(params, "Rows", rows); fz_dict_puts(params, "BlackIs1", black_is_1); @@ -320,7 +320,7 @@ xps_expand_tiff_colormap(struct tiff *tiff) stride = tiff->imagewidth * (tiff->samplesperpixel + 2); - samples = fz_malloc(tiff->ctx, stride * tiff->imagelength); + samples = fz_malloc(tiff->doc, stride * tiff->imagelength); for (y = 0; y < tiff->imagelength; y++) { @@ -430,7 +430,7 @@ xps_decode_tiff_strips(struct tiff *tiff) tiff->yresolution = 96; } - tiff->samples = fz_malloc_array(tiff->ctx, tiff->imagelength, tiff->stride); + tiff->samples = fz_malloc_array(tiff->doc, tiff->imagelength, tiff->stride); memset(tiff->samples, 0x55, tiff->imagelength * tiff->stride); wp = tiff->samples; @@ -454,7 +454,7 @@ xps_decode_tiff_strips(struct tiff *tiff) rp[i] = bitrev[rp[i]]; /* the strip decoders will close this */ - stm = fz_open_memory(tiff->ctx, rp, rlen); + stm = fz_open_memory(tiff->doc, rp, rlen); switch (tiff->compression) { @@ -675,7 +675,7 @@ xps_read_tiff_tag(struct tiff *tiff, unsigned offset) break; case ICCProfile: - tiff->profile = fz_malloc(tiff->ctx, count); + tiff->profile = fz_malloc(tiff->doc, count); /* ICC profile data type is set to UNDEFINED. * TBYTE reading not correct in xps_read_tiff_tag_value */ xps_read_tiff_bytes(tiff->profile, tiff, value, count); @@ -683,23 +683,23 @@ xps_read_tiff_tag(struct tiff *tiff, unsigned offset) break; case JPEGTables: - fz_warn(tiff->ctx, "jpeg tables in tiff not implemented"); + fz_warn(tiff->doc, "jpeg tables in tiff not implemented"); tiff->jpegtables = tiff->bp + value; tiff->jpegtableslen = count; break; case StripOffsets: - tiff->stripoffsets = fz_malloc_array(tiff->ctx, count, sizeof(unsigned)); + tiff->stripoffsets = fz_malloc_array(tiff->doc, count, sizeof(unsigned)); xps_read_tiff_tag_value(tiff->stripoffsets, tiff, type, value, count); break; case StripByteCounts: - tiff->stripbytecounts = fz_malloc_array(tiff->ctx, count, sizeof(unsigned)); + tiff->stripbytecounts = fz_malloc_array(tiff->doc, count, sizeof(unsigned)); xps_read_tiff_tag_value(tiff->stripbytecounts, tiff, type, value, count); break; case ColorMap: - tiff->colormap = fz_malloc_array(tiff->ctx, count, sizeof(unsigned)); + tiff->colormap = fz_malloc_array(tiff->doc, count, sizeof(unsigned)); xps_read_tiff_tag_value(tiff->colormap, tiff, type, value, count); break; @@ -796,13 +796,13 @@ xps_decode_tiff_header(struct tiff *tiff, byte *buf, int len) } int -xps_decode_tiff(fz_context *ctx, fz_pixmap **imagep, byte *buf, int len) +xps_decode_tiff(fz_context *doc, fz_pixmap **imagep, byte *buf, int len) { int error; fz_pixmap *image; struct tiff tiff; - tiff.ctx = ctx; + tiff.doc = doc; error = xps_decode_tiff_header(&tiff, buf, len); if (error) return fz_error_note(error, "cannot decode tiff header"); @@ -825,13 +825,13 @@ xps_decode_tiff(fz_context *ctx, fz_pixmap **imagep, byte *buf, int len) /* Expand into fz_pixmap struct */ - image = fz_new_pixmap_with_limit(tiff.ctx, tiff.colorspace, tiff.imagewidth, tiff.imagelength); + image = fz_new_pixmap_with_limit(tiff.doc, tiff.colorspace, tiff.imagewidth, tiff.imagelength); if (!image) { - if (tiff.colormap) fz_free(ctx, tiff.colormap); - if (tiff.stripoffsets) fz_free(ctx, tiff.stripoffsets); - if (tiff.stripbytecounts) fz_free(ctx, tiff.stripbytecounts); - if (tiff.samples) fz_free(ctx, tiff.samples); + if (tiff.colormap) fz_free(doc, tiff.colormap); + if (tiff.stripoffsets) fz_free(doc, tiff.stripoffsets); + if (tiff.stripbytecounts) fz_free(doc, tiff.stripbytecounts); + if (tiff.samples) fz_free(doc, tiff.samples); return fz_error_make("out of memory"); } @@ -846,11 +846,11 @@ xps_decode_tiff(fz_context *ctx, fz_pixmap **imagep, byte *buf, int len) /* CMYK is a subtractive colorspace, we want additive for premul alpha */ if (image->n == 5) { - fz_pixmap *rgb = fz_new_pixmap(tiff.ctx, fz_device_rgb, image->w, image->h); - fz_convert_pixmap(tiff.ctx, image, rgb); + fz_pixmap *rgb = fz_new_pixmap(tiff.doc, fz_device_rgb, image->w, image->h); + fz_convert_pixmap(tiff.doc, image, rgb); rgb->xres = image->xres; rgb->yres = image->yres; - fz_drop_pixmap(ctx, image); + fz_drop_pixmap(doc, image); image = rgb; } fz_premultiply_pixmap(image); @@ -858,10 +858,10 @@ xps_decode_tiff(fz_context *ctx, fz_pixmap **imagep, byte *buf, int len) /* Clean up scratch memory */ - if (tiff.colormap) fz_free(ctx, tiff.colormap); - if (tiff.stripoffsets) fz_free(ctx, tiff.stripoffsets); - if (tiff.stripbytecounts) fz_free(ctx, tiff.stripbytecounts); - if (tiff.samples) fz_free(ctx, tiff.samples); + if (tiff.colormap) fz_free(doc, tiff.colormap); + if (tiff.stripoffsets) fz_free(doc, tiff.stripoffsets); + if (tiff.stripbytecounts) fz_free(doc, tiff.stripbytecounts); + if (tiff.samples) fz_free(doc, tiff.samples); *imagep = image; return fz_okay; diff --git a/xps/xps_tile.c b/xps/xps_tile.c index 7a0a4f66..f6a2143f 100644 --- a/xps/xps_tile.c +++ b/xps/xps_tile.c @@ -16,57 +16,57 @@ struct closure xps_resource *dict; xml_element *root; void *user; - void (*func)(xps_context*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*); + void (*func)(xps_document*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*); }; static void -xps_paint_tiling_brush_clipped(xps_context *ctx, fz_matrix ctm, fz_rect viewbox, struct closure *c) +xps_paint_tiling_brush_clipped(xps_document *doc, fz_matrix ctm, fz_rect viewbox, struct closure *c) { - fz_path *path = fz_new_path(ctx->ctx); - fz_moveto(ctx->ctx, path, viewbox.x0, viewbox.y0); - fz_lineto(ctx->ctx, path, viewbox.x0, viewbox.y1); - fz_lineto(ctx->ctx, path, viewbox.x1, viewbox.y1); - fz_lineto(ctx->ctx, path, viewbox.x1, viewbox.y0); - fz_closepath(ctx->ctx, path); - fz_clip_path(ctx->dev, path, NULL, 0, ctm); - fz_free_path(ctx->ctx, path); - c->func(ctx, ctm, viewbox, c->base_uri, c->dict, c->root, c->user); - fz_pop_clip(ctx->dev); + fz_path *path = fz_new_path(doc->ctx); + fz_moveto(doc->ctx, path, viewbox.x0, viewbox.y0); + fz_lineto(doc->ctx, path, viewbox.x0, viewbox.y1); + fz_lineto(doc->ctx, path, viewbox.x1, viewbox.y1); + fz_lineto(doc->ctx, path, viewbox.x1, viewbox.y0); + fz_closepath(doc->ctx, path); + fz_clip_path(doc->dev, path, NULL, 0, ctm); + fz_free_path(doc->ctx, path); + c->func(doc, ctm, viewbox, c->base_uri, c->dict, c->root, c->user); + fz_pop_clip(doc->dev); } static void -xps_paint_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect viewbox, int tile_mode, struct closure *c) +xps_paint_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect viewbox, int tile_mode, struct closure *c) { fz_matrix ttm; - xps_paint_tiling_brush_clipped(ctx, ctm, viewbox, c); + xps_paint_tiling_brush_clipped(doc, ctm, viewbox, c); if (tile_mode == TILE_FLIP_X || tile_mode == TILE_FLIP_X_Y) { ttm = fz_concat(fz_translate(viewbox.x1 * 2, 0), ctm); ttm = fz_concat(fz_scale(-1, 1), ttm); - xps_paint_tiling_brush_clipped(ctx, ttm, viewbox, c); + xps_paint_tiling_brush_clipped(doc, ttm, viewbox, c); } if (tile_mode == TILE_FLIP_Y || tile_mode == TILE_FLIP_X_Y) { ttm = fz_concat(fz_translate(0, viewbox.y1 * 2), ctm); ttm = fz_concat(fz_scale(1, -1), ttm); - xps_paint_tiling_brush_clipped(ctx, ttm, viewbox, c); + xps_paint_tiling_brush_clipped(doc, ttm, viewbox, c); } if (tile_mode == TILE_FLIP_X_Y) { ttm = fz_concat(fz_translate(viewbox.x1 * 2, viewbox.y1 * 2), ctm); ttm = fz_concat(fz_scale(-1, -1), ttm); - xps_paint_tiling_brush_clipped(ctx, ttm, viewbox, c); + xps_paint_tiling_brush_clipped(doc, ttm, viewbox, c); } } void -xps_parse_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, +xps_parse_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root, - void (*func)(xps_context*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*), void *user) + void (*func)(xps_document*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*), void *user) { xml_element *node; struct closure c; @@ -110,22 +110,22 @@ xps_parse_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, transform_tag = xml_down(node); } - xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL); + xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); transform = fz_identity; if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); + xps_parse_render_transform(doc, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + xps_parse_matrix_transform(doc, transform_tag, &transform); ctm = fz_concat(transform, ctm); viewbox = fz_unit_rect; if (viewbox_att) - xps_parse_rectangle(ctx, viewbox_att, &viewbox); + xps_parse_rectangle(doc, viewbox_att, &viewbox); viewport = fz_unit_rect; if (viewport_att) - xps_parse_rectangle(ctx, viewport_att, &viewport); + xps_parse_rectangle(doc, viewport_att, &viewport); /* some sanity checks on the viewport/viewbox size */ if (fabsf(viewport.x1 - viewport.x0) < 0.01f) return; @@ -159,7 +159,7 @@ xps_parse_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, if (tile_mode == TILE_FLIP_Y || tile_mode == TILE_FLIP_X_Y) ystep *= 2; - xps_begin_opacity(ctx, ctm, area, base_uri, dict, opacity_att, NULL); + xps_begin_opacity(doc, ctm, area, base_uri, dict, opacity_att, NULL); ctm = fz_concat(fz_translate(viewport.x0, viewport.y0), ctm); ctm = fz_concat(fz_scale(xscale, yscale), ctm); @@ -184,9 +184,9 @@ xps_parse_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, fz_rect bigview = viewbox; bigview.x1 = bigview.x0 + xstep; bigview.y1 = bigview.y0 + ystep; - fz_begin_tile(ctx->dev, area, bigview, xstep, ystep, ctm); - xps_paint_tiling_brush(ctx, ctm, viewbox, tile_mode, &c); - fz_end_tile(ctx->dev); + fz_begin_tile(doc->dev, area, bigview, xstep, ystep, ctm); + xps_paint_tiling_brush(doc, ctm, viewbox, tile_mode, &c); + fz_end_tile(doc->dev); } else { @@ -196,28 +196,28 @@ xps_parse_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, for (x = x0; x < x1; x++) { fz_matrix ttm = fz_concat(fz_translate(xstep * x, ystep * y), ctm); - xps_paint_tiling_brush(ctx, ttm, viewbox, tile_mode, &c); + xps_paint_tiling_brush(doc, ttm, viewbox, tile_mode, &c); } } } } else { - xps_paint_tiling_brush(ctx, ctm, viewbox, tile_mode, &c); + xps_paint_tiling_brush(doc, ctm, viewbox, tile_mode, &c); } - xps_end_opacity(ctx, base_uri, dict, opacity_att, NULL); + xps_end_opacity(doc, base_uri, dict, opacity_att, NULL); } static void -xps_paint_visual_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, +xps_paint_visual_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root, void *visual_tag) { - xps_parse_element(ctx, ctm, area, base_uri, dict, (xml_element *)visual_tag); + xps_parse_element(doc, ctm, area, base_uri, dict, (xml_element *)visual_tag); } void -xps_parse_visual_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, +xps_parse_visual_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root) { xml_element *node; @@ -235,17 +235,17 @@ xps_parse_visual_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, } visual_uri = base_uri; - xps_resolve_resource_reference(ctx, dict, &visual_att, &visual_tag, &visual_uri); + xps_resolve_resource_reference(doc, dict, &visual_att, &visual_tag, &visual_uri); if (visual_tag) { - xps_parse_tiling_brush(ctx, ctm, area, + xps_parse_tiling_brush(doc, ctm, area, visual_uri, dict, root, xps_paint_visual_brush, visual_tag); } } void -xps_parse_canvas(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root) +xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root) { xps_resource *new_dict = NULL; xml_element *node; @@ -272,7 +272,7 @@ xps_parse_canvas(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, { if (!strcmp(xml_tag(node), "Canvas.Resources") && xml_down(node)) { - code = xps_parse_resource_dictionary(ctx, &new_dict, base_uri, xml_down(node)); + code = xps_parse_resource_dictionary(doc, &new_dict, base_uri, xml_down(node)); if (code) fz_error_handle(code, "cannot load Canvas.Resources"); else @@ -291,38 +291,38 @@ xps_parse_canvas(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, } opacity_mask_uri = base_uri; - xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL); - xps_resolve_resource_reference(ctx, dict, &clip_att, &clip_tag, NULL); - xps_resolve_resource_reference(ctx, dict, &opacity_mask_att, &opacity_mask_tag, &opacity_mask_uri); + xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); + xps_resolve_resource_reference(doc, dict, &clip_att, &clip_tag, NULL); + xps_resolve_resource_reference(doc, dict, &opacity_mask_att, &opacity_mask_tag, &opacity_mask_uri); transform = fz_identity; if (transform_att) - xps_parse_render_transform(ctx, transform_att, &transform); + xps_parse_render_transform(doc, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(ctx, transform_tag, &transform); + xps_parse_matrix_transform(doc, transform_tag, &transform); ctm = fz_concat(transform, ctm); if (clip_att || clip_tag) - xps_clip(ctx, ctm, dict, clip_att, clip_tag); + xps_clip(doc, ctm, dict, clip_att, clip_tag); - xps_begin_opacity(ctx, ctm, area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); + xps_begin_opacity(doc, ctm, area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); for (node = xml_down(root); node; node = xml_next(node)) { - xps_parse_element(ctx, ctm, area, base_uri, dict, node); + xps_parse_element(doc, ctm, area, base_uri, dict, node); } - xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); + xps_end_opacity(doc, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); if (clip_att || clip_tag) - fz_pop_clip(ctx->dev); + fz_pop_clip(doc->dev); if (new_dict) - xps_free_resource_dictionary(ctx, new_dict); + xps_free_resource_dictionary(doc, new_dict); } void -xps_parse_fixed_page(xps_context *ctx, fz_matrix ctm, xps_page *page) +xps_parse_fixed_page(xps_document *doc, fz_matrix ctm, xps_page *page) { xml_element *node; xps_resource *dict; @@ -338,8 +338,8 @@ xps_parse_fixed_page(xps_context *ctx, fz_matrix ctm, xps_page *page) dict = NULL; - ctx->opacity_top = 0; - ctx->opacity[0] = 1; + doc->opacity_top = 0; + doc->opacity[0] = 1; if (!page->root) return; @@ -350,15 +350,15 @@ xps_parse_fixed_page(xps_context *ctx, fz_matrix ctm, xps_page *page) { if (!strcmp(xml_tag(node), "FixedPage.Resources") && xml_down(node)) { - code = xps_parse_resource_dictionary(ctx, &dict, base_uri, xml_down(node)); + code = xps_parse_resource_dictionary(doc, &dict, base_uri, xml_down(node)); if (code) fz_error_handle(code, "cannot load FixedPage.Resources"); } - xps_parse_element(ctx, ctm, area, base_uri, dict, node); + xps_parse_element(doc, ctm, area, base_uri, dict, node); } if (dict) { - xps_free_resource_dictionary(ctx, dict); + xps_free_resource_dictionary(doc, dict); } } diff --git a/xps/xps_xml.c b/xps/xps_xml.c index 47e1728b..0c3f591b 100644 --- a/xps/xps_xml.c +++ b/xps/xps_xml.c @@ -18,7 +18,7 @@ struct element struct parser { struct element *head; - fz_context *ctx; + fz_context *doc; }; static inline void indent(int n) @@ -71,26 +71,26 @@ char *xml_att(struct element *item, const char *name) return NULL; } -static void xml_free_attribute(fz_context *ctx, struct attribute *att) +static void xml_free_attribute(fz_context *doc, struct attribute *att) { while (att) { struct attribute *next = att->next; if (att->value) - fz_free(ctx, att->value); - fz_free(ctx, att); + fz_free(doc, att->value); + fz_free(doc, att); att = next; } } -void xml_free_element(fz_context *ctx, struct element *item) +void xml_free_element(fz_context *doc, struct element *item) { while (item) { struct element *next = item->next; if (item->atts) - xml_free_attribute(ctx, item->atts); + xml_free_attribute(doc, item->atts); if (item->down) - xml_free_element(ctx, item->down); - fz_free(ctx, item); + xml_free_element(doc, item->down); + fz_free(doc, item); item = next; } } @@ -134,7 +134,7 @@ static void xml_emit_open_tag(struct parser *parser, char *a, char *b) { struct element *head, *tail; - head = fz_malloc(parser->ctx, sizeof(struct element)); + head = fz_malloc(parser->doc, sizeof(struct element)); if (b - a > sizeof(head->name)) b = a + sizeof(head->name); memcpy(head->name, a, b - a); @@ -163,7 +163,7 @@ static void xml_emit_att_name(struct parser *parser, char *a, char *b) struct element *head = parser->head; struct attribute *att; - att = fz_malloc(parser->ctx, sizeof(struct attribute)); + att = fz_malloc(parser->doc, sizeof(struct attribute)); if (b - a > sizeof(att->name)) b = a + sizeof(att->name); memcpy(att->name, a, b - a); @@ -181,7 +181,7 @@ static void xml_emit_att_value(struct parser *parser, char *a, char *b) int c; /* entities are all longer than UTFmax so runetochar is safe */ - s = att->value = fz_malloc(parser->ctx, b - a + 1); + s = att->value = fz_malloc(parser->doc, b - a + 1); while (a < b) { if (*a == '&') { a += xml_parse_entity(&c, a); @@ -330,14 +330,14 @@ parse_attribute_value: return "end of data in attribute value"; } -static char *convert_to_utf8(fz_context *ctx, unsigned char *s, int n) +static char *convert_to_utf8(fz_context *doc, unsigned char *s, int n) { unsigned char *e = s + n; char *dst, *d; int c; if (s[0] == 0xFE && s[1] == 0xFF) { - dst = d = fz_malloc(ctx, n * 2); + dst = d = fz_malloc(doc, n * 2); while (s + 1 < e) { c = s[0] << 8 | s[1]; d += runetochar(d, &c); @@ -348,7 +348,7 @@ static char *convert_to_utf8(fz_context *ctx, unsigned char *s, int n) } if (s[0] == 0xFF && s[1] == 0xFE) { - dst = d = fz_malloc(ctx, n * 2); + dst = d = fz_malloc(doc, n * 2); while (s + 1 < e) { c = s[0] | s[1] << 8; d += runetochar(d, &c); @@ -362,7 +362,7 @@ static char *convert_to_utf8(fz_context *ctx, unsigned char *s, int n) } struct element * -xml_parse_document(fz_context *ctx, unsigned char *s, int n) +xml_parse_document(fz_context *doc, unsigned char *s, int n) { struct parser parser; struct element root; @@ -372,18 +372,18 @@ xml_parse_document(fz_context *ctx, unsigned char *s, int n) memset(&root, 0, sizeof(root)); parser.head = &root; - parser.ctx = ctx; + parser.doc = doc; - p = convert_to_utf8(ctx, s, n); + p = convert_to_utf8(doc, s, n); error = xml_parse_document_imp(&parser, p); if (error) { - fz_error_make(error, ""); + fz_error_handle(-1, error); return NULL; } if (p != (char*)s) - fz_free(ctx, p); + fz_free(doc, p); return root.down; } diff --git a/xps/xps_zip.c b/xps/xps_zip.c index 880db0d4..954a8a00 100644 --- a/xps/xps_zip.c +++ b/xps/xps_zip.c @@ -4,25 +4,25 @@ #include <zlib.h> xps_part * -xps_new_part(xps_context *ctx, char *name, int size) +xps_new_part(xps_document *doc, char *name, int size) { xps_part *part; - part = fz_malloc(ctx->ctx, sizeof(xps_part)); - part->name = fz_strdup(ctx->ctx, name); + part = fz_malloc(doc->ctx, sizeof(xps_part)); + part->name = fz_strdup(doc->ctx, name); part->size = size; - part->data = fz_malloc(ctx->ctx, size + 1); + part->data = fz_malloc(doc->ctx, size + 1); part->data[size] = 0; /* null-terminate for xml parser */ return part; } void -xps_free_part(xps_context *ctx, xps_part *part) +xps_free_part(xps_document *doc, xps_part *part) { - fz_free(ctx->ctx, part->name); - fz_free(ctx->ctx, part->data); - fz_free(ctx->ctx, part); + fz_free(doc->ctx, part->name); + fz_free(doc->ctx, part->data); + fz_free(doc->ctx, part); } static inline int getshort(fz_stream *file) @@ -42,15 +42,15 @@ static inline int getlong(fz_stream *file) } static void * -xps_zip_alloc_items(xps_context *ctx, int items, int size) +xps_zip_alloc_items(xps_document *doc, int items, int size) { - return fz_malloc_array(ctx->ctx, items, size); + return fz_malloc_array(doc->ctx, items, size); } static void -xps_zip_free(xps_context *ctx, void *ptr) +xps_zip_free(xps_document *doc, void *ptr) { - fz_free(ctx->ctx, ptr); + fz_free(doc->ctx, ptr); } static int @@ -62,26 +62,26 @@ xps_compare_entries(const void *a0, const void *b0) } static xps_entry * -xps_find_zip_entry(xps_context *ctx, char *name) +xps_find_zip_entry(xps_document *doc, char *name) { int l = 0; - int r = ctx->zip_count - 1; + int r = doc->zip_count - 1; while (l <= r) { int m = (l + r) >> 1; - int c = xps_strcasecmp(name, ctx->zip_table[m].name); + int c = xps_strcasecmp(name, doc->zip_table[m].name); if (c < 0) r = m - 1; else if (c > 0) l = m + 1; else - return &ctx->zip_table[m]; + return &doc->zip_table[m]; } return NULL; } static int -xps_read_zip_entry(xps_context *ctx, xps_entry *ent, unsigned char *outbuf) +xps_read_zip_entry(xps_document *doc, xps_entry *ent, unsigned char *outbuf) { z_stream stream; unsigned char *inbuf; @@ -90,39 +90,39 @@ xps_read_zip_entry(xps_context *ctx, xps_entry *ent, unsigned char *outbuf) int namelength, extralength; int code; - fz_seek(ctx->file, ent->offset, 0); + fz_seek(doc->file, ent->offset, 0); - sig = getlong(ctx->file); + sig = getlong(doc->file); if (sig != ZIP_LOCAL_FILE_SIG) return fz_error_make("wrong zip local file signature (0x%x)", sig); - version = getshort(ctx->file); - general = getshort(ctx->file); - method = getshort(ctx->file); - (void) getshort(ctx->file); /* file time */ - (void) getshort(ctx->file); /* file date */ - (void) getlong(ctx->file); /* crc-32 */ - (void) getlong(ctx->file); /* csize */ - (void) getlong(ctx->file); /* usize */ - namelength = getshort(ctx->file); - extralength = getshort(ctx->file); + version = getshort(doc->file); + general = getshort(doc->file); + method = getshort(doc->file); + (void) getshort(doc->file); /* file time */ + (void) getshort(doc->file); /* file date */ + (void) getlong(doc->file); /* crc-32 */ + (void) getlong(doc->file); /* csize */ + (void) getlong(doc->file); /* usize */ + namelength = getshort(doc->file); + extralength = getshort(doc->file); - fz_seek(ctx->file, namelength + extralength, 1); + fz_seek(doc->file, namelength + extralength, 1); if (method == 0) { - fz_read(ctx->file, outbuf, ent->usize); + fz_read(doc->file, outbuf, ent->usize); } else if (method == 8) { - inbuf = fz_malloc(ctx->ctx, ent->csize); + inbuf = fz_malloc(doc->ctx, ent->csize); - fz_read(ctx->file, inbuf, ent->csize); + fz_read(doc->file, inbuf, ent->csize); 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.opaque = doc; stream.next_in = inbuf; stream.avail_in = ent->csize; stream.next_out = outbuf; @@ -141,7 +141,7 @@ xps_read_zip_entry(xps_context *ctx, xps_entry *ent, unsigned char *outbuf) if (code != Z_OK) return fz_error_make("zlib inflateEnd error: %s", stream.msg); - fz_free(ctx->ctx, inbuf); + fz_free(doc->ctx, inbuf); } else { @@ -156,91 +156,91 @@ xps_read_zip_entry(xps_context *ctx, xps_entry *ent, unsigned char *outbuf) */ static int -xps_read_zip_dir(xps_context *ctx, int start_offset) +xps_read_zip_dir(xps_document *doc, int start_offset) { int sig; int offset, count; int namesize, metasize, commentsize; int i; - fz_seek(ctx->file, start_offset, 0); + fz_seek(doc->file, start_offset, 0); - sig = getlong(ctx->file); + sig = getlong(doc->file); if (sig != ZIP_END_OF_CENTRAL_DIRECTORY_SIG) return fz_error_make("wrong zip end of central directory signature (0x%x)", sig); - (void) getshort(ctx->file); /* this disk */ - (void) getshort(ctx->file); /* start disk */ - (void) getshort(ctx->file); /* entries in this disk */ - count = getshort(ctx->file); /* entries in central directory disk */ - (void) getlong(ctx->file); /* size of central directory */ - offset = getlong(ctx->file); /* offset to central directory */ + (void) getshort(doc->file); /* this disk */ + (void) getshort(doc->file); /* start disk */ + (void) getshort(doc->file); /* entries in this disk */ + count = getshort(doc->file); /* entries in central directory disk */ + (void) getlong(doc->file); /* size of central directory */ + offset = getlong(doc->file); /* offset to central directory */ - ctx->zip_count = count; - ctx->zip_table = fz_malloc_array(ctx->ctx, count, sizeof(xps_entry)); + doc->zip_count = count; + doc->zip_table = fz_malloc_array(doc->ctx, count, sizeof(xps_entry)); - fz_seek(ctx->file, offset, 0); + fz_seek(doc->file, offset, 0); for (i = 0; i < count; i++) { - sig = getlong(ctx->file); + sig = getlong(doc->file); if (sig != ZIP_CENTRAL_DIRECTORY_SIG) return fz_error_make("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 = fz_malloc(ctx->ctx, namesize + 1); - fz_read(ctx->file, (unsigned char*)ctx->zip_table[i].name, namesize); - ctx->zip_table[i].name[namesize] = 0; - - fz_seek(ctx->file, metasize, 1); - fz_seek(ctx->file, commentsize, 1); + (void) getshort(doc->file); /* version made by */ + (void) getshort(doc->file); /* version to extract */ + (void) getshort(doc->file); /* general */ + (void) getshort(doc->file); /* method */ + (void) getshort(doc->file); /* last mod file time */ + (void) getshort(doc->file); /* last mod file date */ + (void) getlong(doc->file); /* crc-32 */ + doc->zip_table[i].csize = getlong(doc->file); + doc->zip_table[i].usize = getlong(doc->file); + namesize = getshort(doc->file); + metasize = getshort(doc->file); + commentsize = getshort(doc->file); + (void) getshort(doc->file); /* disk number start */ + (void) getshort(doc->file); /* int file atts */ + (void) getlong(doc->file); /* ext file atts */ + doc->zip_table[i].offset = getlong(doc->file); + + doc->zip_table[i].name = fz_malloc(doc->ctx, namesize + 1); + fz_read(doc->file, (unsigned char*)doc->zip_table[i].name, namesize); + doc->zip_table[i].name[namesize] = 0; + + fz_seek(doc->file, metasize, 1); + fz_seek(doc->file, commentsize, 1); } - qsort(ctx->zip_table, count, sizeof(xps_entry), xps_compare_entries); + qsort(doc->zip_table, count, sizeof(xps_entry), xps_compare_entries); return fz_okay; } static int -xps_find_and_read_zip_dir(xps_context *ctx) +xps_find_and_read_zip_dir(xps_document *doc) { unsigned char buf[512]; int file_size, back, maxback; int i, n; - fz_seek(ctx->file, 0, SEEK_END); - file_size = fz_tell(ctx->file); + fz_seek(doc->file, 0, SEEK_END); + file_size = fz_tell(doc->file); maxback = MIN(file_size, 0xFFFF + sizeof buf); back = MIN(maxback, sizeof buf); while (back < maxback) { - fz_seek(ctx->file, file_size - back, 0); + fz_seek(doc->file, file_size - back, 0); - n = fz_read(ctx->file, buf, sizeof buf); + n = fz_read(doc->file, buf, sizeof buf); if (n < 0) return fz_error_make("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_dir(ctx, file_size - back + i); + return xps_read_zip_dir(doc, file_size - back + i); back += sizeof buf - 4; } @@ -252,7 +252,7 @@ xps_find_and_read_zip_dir(xps_context *ctx) * Read and interleave split parts from a ZIP file. */ static xps_part * -xps_read_zip_part(xps_context *ctx, char *partname) +xps_read_zip_part(xps_document *doc, char *partname) { char buf[2048]; xps_entry *ent; @@ -265,11 +265,11 @@ xps_read_zip_part(xps_context *ctx, char *partname) name ++; /* All in one piece */ - ent = xps_find_zip_entry(ctx, name); + ent = xps_find_zip_entry(doc, name); if (ent) { - part = xps_new_part(ctx, partname, ent->usize); - xps_read_zip_entry(ctx, ent, part->data); + part = xps_new_part(doc, partname, ent->usize); + xps_read_zip_entry(doc, ent, part->data); return part; } @@ -279,11 +279,11 @@ xps_read_zip_part(xps_context *ctx, char *partname) while (1) { sprintf(buf, "%s/[%d].piece", name, count); - ent = xps_find_zip_entry(ctx, buf); + ent = xps_find_zip_entry(doc, buf); if (!ent) { sprintf(buf, "%s/[%d].last.piece", name, count); - ent = xps_find_zip_entry(ctx, buf); + ent = xps_find_zip_entry(doc, buf); } if (!ent) break; @@ -294,7 +294,7 @@ xps_read_zip_part(xps_context *ctx, char *partname) /* Inflate the pieces */ if (count) { - part = xps_new_part(ctx, partname, size); + part = xps_new_part(doc, partname, size); offset = 0; for (i = 0; i < count; i++) { @@ -302,8 +302,8 @@ xps_read_zip_part(xps_context *ctx, char *partname) sprintf(buf, "%s/[%d].piece", name, i); else sprintf(buf, "%s/[%d].last.piece", name, i); - ent = xps_find_zip_entry(ctx, buf); - xps_read_zip_entry(ctx, ent, part->data + offset); + ent = xps_find_zip_entry(doc, buf); + xps_read_zip_entry(doc, ent, part->data + offset); offset += ent->usize; } return part; @@ -316,14 +316,14 @@ xps_read_zip_part(xps_context *ctx, char *partname) * Read and interleave split parts from files in the directory. */ static xps_part * -xps_read_dir_part(xps_context *ctx, char *name) +xps_read_dir_part(xps_document *doc, char *name) { char buf[2048]; xps_part *part; FILE *file; int count, size, offset, i, n; - fz_strlcpy(buf, ctx->directory, sizeof buf); + fz_strlcpy(buf, doc->directory, sizeof buf); fz_strlcat(buf, name, sizeof buf); /* All in one piece */ @@ -333,7 +333,7 @@ xps_read_dir_part(xps_context *ctx, char *name) fseek(file, 0, SEEK_END); size = ftell(file); fseek(file, 0, SEEK_SET); - part = xps_new_part(ctx, name, size); + part = xps_new_part(doc, name, size); fread(part->data, 1, size, file); fclose(file); return part; @@ -344,11 +344,11 @@ xps_read_dir_part(xps_context *ctx, char *name) size = 0; while (1) { - sprintf(buf, "%s%s/[%d].piece", ctx->directory, name, count); + sprintf(buf, "%s%s/[%d].piece", doc->directory, name, count); file = fopen(buf, "rb"); if (!file) { - sprintf(buf, "%s%s/[%d].last.piece", ctx->directory, name, count); + sprintf(buf, "%s%s/[%d].last.piece", doc->directory, name, count); file = fopen(buf, "rb"); } if (!file) @@ -362,14 +362,14 @@ xps_read_dir_part(xps_context *ctx, char *name) /* Inflate the pieces */ if (count) { - part = xps_new_part(ctx, name, size); + part = xps_new_part(doc, name, size); offset = 0; for (i = 0; i < count; i++) { if (i < count - 1) - sprintf(buf, "%s%s/[%d].piece", ctx->directory, name, i); + sprintf(buf, "%s%s/[%d].piece", doc->directory, name, i); else - sprintf(buf, "%s%s/[%d].last.piece", ctx->directory, name, i); + sprintf(buf, "%s%s/[%d].last.piece", doc->directory, name, i); file = fopen(buf, "rb"); n = fread(part->data + offset, 1, size - offset, file); offset += n; @@ -382,68 +382,68 @@ xps_read_dir_part(xps_context *ctx, char *name) } xps_part * -xps_read_part(xps_context *ctx, char *partname) +xps_read_part(xps_document *doc, char *partname) { - if (ctx->directory) - return xps_read_dir_part(ctx, partname); - return xps_read_zip_part(ctx, partname); + if (doc->directory) + return xps_read_dir_part(doc, partname); + return xps_read_zip_part(doc, partname); } static int -xps_open_directory(fz_context *fctx, xps_context **ctxp, char *directory) +xps_open_directory(fz_context *fctx, xps_document **ctxp, char *directory) { - xps_context *ctx; + xps_document *doc; int code; - ctx = fz_malloc(fctx, sizeof(xps_context)); - memset(ctx, 0, sizeof *ctx); + doc = fz_malloc(fctx, sizeof(xps_document)); + memset(doc, 0, sizeof *doc); - ctx->directory = fz_strdup(fctx, directory); - ctx->ctx = fctx; + doc->directory = fz_strdup(fctx, directory); + doc->ctx = fctx; - code = xps_read_page_list(ctx); + code = xps_read_page_list(doc); if (code) { - xps_free_context(ctx); + xps_free_context(doc); return fz_error_note(code, "cannot read page list"); } - *ctxp = ctx; + *ctxp = doc; return fz_okay; } int -xps_open_stream(xps_context **ctxp, fz_stream *file) +xps_open_stream(xps_document **ctxp, fz_stream *file) { - xps_context *ctx; + xps_document *doc; int code; - ctx = fz_malloc(file->ctx, sizeof(xps_context)); - memset(ctx, 0, sizeof *ctx); + doc = fz_malloc(file->ctx, sizeof(xps_document)); + memset(doc, 0, sizeof *doc); - ctx->ctx = file->ctx; - ctx->file = fz_keep_stream(file); + doc->ctx = file->ctx; + doc->file = fz_keep_stream(file); - code = xps_find_and_read_zip_dir(ctx); + code = xps_find_and_read_zip_dir(doc); if (code < 0) { - xps_free_context(ctx); + xps_free_context(doc); return fz_error_note(code, "cannot read zip central directory"); } - code = xps_read_page_list(ctx); + code = xps_read_page_list(doc); if (code) { - xps_free_context(ctx); + xps_free_context(doc); return fz_error_note(code, "cannot read page list"); } - *ctxp = ctx; + *ctxp = doc; return fz_okay; } int -xps_open_file(fz_context *ctx, xps_context **ctxp, char *filename) +xps_open_file(fz_context *doc, xps_document **ctxp, char *filename) { char buf[2048]; fz_stream *file; @@ -457,10 +457,10 @@ xps_open_file(fz_context *ctx, xps_context **ctxp, char *filename) if (!p) p = strstr(buf, "\\_rels\\.rels"); *p = 0; - return xps_open_directory(ctx, ctxp, buf); + return xps_open_directory(doc, ctxp, buf); } - file = fz_open_file(ctx, filename); + file = fz_open_file(doc, filename); if (!file) return fz_error_make("cannot open file '%s': %s", filename, strerror(errno)); @@ -472,31 +472,31 @@ xps_open_file(fz_context *ctx, xps_context **ctxp, char *filename) } void -xps_free_context(xps_context *ctx) +xps_free_context(xps_document *doc) { xps_font_cache *font, *next; int i; - if (ctx->file) - fz_close(ctx->file); + if (doc->file) + fz_close(doc->file); - for (i = 0; i < ctx->zip_count; i++) - fz_free(ctx->ctx, ctx->zip_table[i].name); - fz_free(ctx->ctx, ctx->zip_table); + for (i = 0; i < doc->zip_count; i++) + fz_free(doc->ctx, doc->zip_table[i].name); + fz_free(doc->ctx, doc->zip_table); - font = ctx->font_table; + font = doc->font_table; while (font) { next = font->next; - fz_drop_font(ctx->ctx, font->font); - fz_free(ctx->ctx, font->name); - fz_free(ctx->ctx, font); + fz_drop_font(doc->ctx, font->font); + fz_free(doc->ctx, font->name); + fz_free(doc->ctx, font); font = next; } - xps_free_page_list(ctx); + xps_free_page_list(doc); - fz_free(ctx->ctx, ctx->start_part); - fz_free(ctx->ctx, ctx->directory); - fz_free(ctx->ctx, ctx); + fz_free(doc->ctx, doc->start_part); + fz_free(doc->ctx, doc->directory); + fz_free(doc->ctx, doc); } |