diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2012-11-24 15:34:00 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-11-26 12:49:49 +0000 |
commit | 11032ab74abc9f74161a7c2d138e894c7a7854da (patch) | |
tree | edb49e82ec5a23a301f8c28a38fd613818b763d0 | |
parent | f132f5df437b0fbdef73899943da56ae810f9f1f (diff) | |
download | mupdf-11032ab74abc9f74161a7c2d138e894c7a7854da.tar.xz |
xps: Move XML parser into fitz namespace.
-rw-r--r-- | scripts/rename4.sed | 11 | ||||
-rw-r--r-- | xps/muxps-internal.h | 46 | ||||
-rw-r--r-- | xps/muxps.h | 22 | ||||
-rw-r--r-- | xps/xps_common.c | 56 | ||||
-rw-r--r-- | xps/xps_doc.c | 64 | ||||
-rw-r--r-- | xps/xps_glyphs.c | 70 | ||||
-rw-r--r-- | xps/xps_gradient.c | 68 | ||||
-rw-r--r-- | xps/xps_image.c | 8 | ||||
-rw-r--r-- | xps/xps_outline.c | 34 | ||||
-rw-r--r-- | xps/xps_path.c | 168 | ||||
-rw-r--r-- | xps/xps_resource.c | 28 | ||||
-rw-r--r-- | xps/xps_tile.c | 102 | ||||
-rw-r--r-- | xps/xps_xml.c | 56 |
13 files changed, 372 insertions, 361 deletions
diff --git a/scripts/rename4.sed b/scripts/rename4.sed new file mode 100644 index 00000000..cb27df85 --- /dev/null +++ b/scripts/rename4.sed @@ -0,0 +1,11 @@ +s/\<xml_element\>/fz_xml/g +s/\<xml_element\>/fz_xml/g +s/\<xml_parse_document\>/fz_parse_xml/g +s/\<xml_next\>/fz_xml_next/g +s/\<xml_down\>/fz_xml_down/g +s/\<xml_tag\>/fz_xml_tag/g +s/\<xml_att\>/fz_xml_att/g +s/\<xml_text\>/fz_xml_text/g +s/\<xml_free_element\>/fz_free_xml/g +s/\<xml_print_element\>/fz_print_xml/g +s/\<xml_detach\>/fz_detach_xml/g diff --git a/xps/muxps-internal.h b/xps/muxps-internal.h index 5a354555..fab90963 100644 --- a/xps/muxps-internal.h +++ b/xps/muxps-internal.h @@ -54,7 +54,7 @@ struct xps_page_s int number; int width; int height; - xml_element *root; + fz_xml *root; int links_resolved; fz_link *links; xps_page *next; @@ -123,15 +123,15 @@ struct xps_resource_s { char *name; char *base_uri; /* only used in the head nodes */ - xml_element *base_xml; /* only used in the head nodes, to free the xml document */ - xml_element *data; + fz_xml *base_xml; /* only used in the head nodes, to free the xml document */ + fz_xml *data; xps_resource *next; xps_resource *parent; /* up to the previous dict in the stack */ }; -xps_resource * xps_parse_resource_dictionary(xps_document *doc, char *base_uri, xml_element *root); +xps_resource * xps_parse_resource_dictionary(xps_document *doc, char *base_uri, fz_xml *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_resolve_resource_reference(xps_document *doc, xps_resource *dict, char **attp, fz_xml **tagp, char **urip); void xps_print_resource_dictionary(xps_resource *dict); @@ -142,30 +142,30 @@ void xps_print_resource_dictionary(xps_resource *dict); void xps_run_page(xps_document *doc, xps_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie); 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_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_document *doc, xml_element *root, fz_matrix *matrix); +void xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node); +void xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node); +void xps_parse_glyphs(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node); +void xps_parse_solid_color_brush(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node); +void xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node); +void xps_parse_visual_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node); +void xps_parse_linear_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node); +void xps_parse_radial_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node); + +void xps_parse_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *root, void(*func)(xps_document*, fz_matrix, fz_rect, char*, xps_resource*, fz_xml*, void*), void *user); + +void xps_parse_matrix_transform(xps_document *doc, fz_xml *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_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_begin_opacity(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, char *opacity_att, fz_xml *opacity_mask_tag); +void xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict, char *opacity_att, fz_xml *opacity_mask_tag); -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_parse_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node); +void xps_parse_element(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node); -void xps_clip(xps_document *doc, 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, fz_xml *clip_tag); -xml_element *xps_lookup_alternate_content(xml_element *node); +fz_xml *xps_lookup_alternate_content(fz_xml *node); /* * The interpreter context. diff --git a/xps/muxps.h b/xps/muxps.h index f342283e..c784a01a 100644 --- a/xps/muxps.h +++ b/xps/muxps.h @@ -10,17 +10,17 @@ typedef struct xps_page_s xps_page; * XML document model */ -typedef struct element xml_element; - -xml_element *xml_parse_document(fz_context *doc, unsigned char *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); -char *xml_text(xml_element *item); -void xml_free_element(fz_context *doc, xml_element *item); -void xml_print_element(xml_element *item, int level); -void xml_detach(xml_element *node); +typedef struct fz_xml_s fz_xml; + +fz_xml *fz_parse_xml(fz_context *doc, unsigned char *buf, int len); +fz_xml *fz_xml_next(fz_xml *item); +fz_xml *fz_xml_down(fz_xml *item); +char *fz_xml_tag(fz_xml *item); +char *fz_xml_att(fz_xml *item, const char *att); +char *fz_xml_text(fz_xml *item); +void fz_free_xml(fz_context *doc, fz_xml *item); +void fz_print_xml(fz_xml *item, int level); +void fz_detach_xml(fz_xml *node); /* xps_open_document: Open a document. diff --git a/xps/xps_common.c b/xps/xps_common.c index eddef1b0..ef254f36 100644 --- a/xps/xps_common.c +++ b/xps/xps_common.c @@ -8,56 +8,56 @@ static inline int unhex(int a) return 0; } -xml_element * -xps_lookup_alternate_content(xml_element *node) +fz_xml * +xps_lookup_alternate_content(fz_xml *node) { - for (node = xml_down(node); node; node = xml_next(node)) + for (node = fz_xml_down(node); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "mc:Choice") && xml_att(node, "Requires")) + if (!strcmp(fz_xml_tag(node), "mc:Choice") && fz_xml_att(node, "Requires")) { char list[64]; char *next = list, *item; - fz_strlcpy(list, xml_att(node, "Requires"), sizeof(list)); + fz_strlcpy(list, fz_xml_att(node, "Requires"), sizeof(list)); while ((item = fz_strsep(&next, " \t\r\n")) && (!*item || !strcmp(item, "xps"))); if (!item) - return xml_down(node); + return fz_xml_down(node); } - else if (!strcmp(xml_tag(node), "mc:Fallback")) - return xml_down(node); + else if (!strcmp(fz_xml_tag(node), "mc:Fallback")) + return fz_xml_down(node); } return NULL; } void -xps_parse_brush(xps_document *doc, 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, fz_xml *node) { if (doc->cookie && doc->cookie->abort) return; /* SolidColorBrushes are handled in a special case and will never show up here */ - if (!strcmp(xml_tag(node), "ImageBrush")) + if (!strcmp(fz_xml_tag(node), "ImageBrush")) xps_parse_image_brush(doc, ctm, area, base_uri, dict, node); - else if (!strcmp(xml_tag(node), "VisualBrush")) + else if (!strcmp(fz_xml_tag(node), "VisualBrush")) xps_parse_visual_brush(doc, ctm, area, base_uri, dict, node); - else if (!strcmp(xml_tag(node), "LinearGradientBrush")) + else if (!strcmp(fz_xml_tag(node), "LinearGradientBrush")) xps_parse_linear_gradient_brush(doc, ctm, area, base_uri, dict, node); - else if (!strcmp(xml_tag(node), "RadialGradientBrush")) + else if (!strcmp(fz_xml_tag(node), "RadialGradientBrush")) xps_parse_radial_gradient_brush(doc, ctm, area, base_uri, dict, node); else - fz_warn(doc->ctx, "unknown brush tag: %s", xml_tag(node)); + fz_warn(doc->ctx, "unknown brush tag: %s", fz_xml_tag(node)); } void -xps_parse_element(xps_document *doc, 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, fz_xml *node) { if (doc->cookie && doc->cookie->abort) return; - if (!strcmp(xml_tag(node), "Path")) + if (!strcmp(fz_xml_tag(node), "Path")) xps_parse_path(doc, ctm, base_uri, dict, node); - if (!strcmp(xml_tag(node), "Glyphs")) + if (!strcmp(fz_xml_tag(node), "Glyphs")) xps_parse_glyphs(doc, ctm, base_uri, dict, node); - if (!strcmp(xml_tag(node), "Canvas")) + if (!strcmp(fz_xml_tag(node), "Canvas")) xps_parse_canvas(doc, ctm, area, base_uri, dict, node); - if (!strcmp(xml_tag(node), "mc:AlternateContent")) + if (!strcmp(fz_xml_tag(node), "mc:AlternateContent")) { node = xps_lookup_alternate_content(node); if (node) @@ -69,7 +69,7 @@ xps_parse_element(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri 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) + char *opacity_att, fz_xml *opacity_mask_tag) { float opacity; @@ -80,10 +80,10 @@ xps_begin_opacity(xps_document *doc, fz_matrix ctm, fz_rect area, if (opacity_att) opacity = fz_atof(opacity_att); - if (opacity_mask_tag && !strcmp(xml_tag(opacity_mask_tag), "SolidColorBrush")) + if (opacity_mask_tag && !strcmp(fz_xml_tag(opacity_mask_tag), "SolidColorBrush")) { - char *scb_opacity_att = xml_att(opacity_mask_tag, "Opacity"); - char *scb_color_att = xml_att(opacity_mask_tag, "Color"); + char *scb_opacity_att = fz_xml_att(opacity_mask_tag, "Opacity"); + char *scb_color_att = fz_xml_att(opacity_mask_tag, "Color"); if (scb_opacity_att) opacity = opacity * fz_atof(scb_opacity_att); if (scb_color_att) @@ -112,7 +112,7 @@ xps_begin_opacity(xps_document *doc, fz_matrix ctm, fz_rect area, void xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict, - char *opacity_att, xml_element *opacity_mask_tag) + char *opacity_att, fz_xml *opacity_mask_tag) { if (!opacity_att && !opacity_mask_tag) return; @@ -122,7 +122,7 @@ xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict, if (opacity_mask_tag) { - if (strcmp(xml_tag(opacity_mask_tag), "SolidColorBrush")) + if (strcmp(fz_xml_tag(opacity_mask_tag), "SolidColorBrush")) fz_pop_clip(doc->dev); } } @@ -153,15 +153,15 @@ xps_parse_render_transform(xps_document *doc, char *transform, fz_matrix *matrix } void -xps_parse_matrix_transform(xps_document *doc, xml_element *root, fz_matrix *matrix) +xps_parse_matrix_transform(xps_document *doc, fz_xml *root, fz_matrix *matrix) { char *transform; *matrix = fz_identity; - if (!strcmp(xml_tag(root), "MatrixTransform")) + if (!strcmp(fz_xml_tag(root), "MatrixTransform")) { - transform = xml_att(root, "Matrix"); + transform = fz_xml_att(root, "Matrix"); if (transform) xps_parse_render_transform(doc, transform, matrix); } diff --git a/xps/xps_doc.c b/xps/xps_doc.c index 54e90186..8c86fd59 100644 --- a/xps/xps_doc.c +++ b/xps/xps_doc.c @@ -271,14 +271,14 @@ xps_free_page_list(xps_document *doc) */ static void -xps_parse_metadata_imp(xps_document *doc, xml_element *item, xps_fixdoc *fixdoc) +xps_parse_metadata_imp(xps_document *doc, fz_xml *item, xps_fixdoc *fixdoc) { while (item) { - if (!strcmp(xml_tag(item), "Relationship")) + if (!strcmp(fz_xml_tag(item), "Relationship")) { - char *target = xml_att(item, "Target"); - char *type = xml_att(item, "Type"); + char *target = fz_xml_att(item, "Target"); + char *type = fz_xml_att(item, "Type"); if (target && type) { char tgtbuf[1024]; @@ -287,14 +287,14 @@ xps_parse_metadata_imp(xps_document *doc, xml_element *item, xps_fixdoc *fixdoc) doc->start_part = fz_strdup(doc->ctx, tgtbuf); if (!strcmp(type, REL_DOC_STRUCTURE) && fixdoc) fixdoc->outline = fz_strdup(doc->ctx, tgtbuf); - if (!xml_att(item, "Id")) + if (!fz_xml_att(item, "Id")) fz_warn(doc->ctx, "missing relationship id for %s", target); } } - if (!strcmp(xml_tag(item), "DocumentReference")) + if (!strcmp(fz_xml_tag(item), "DocumentReference")) { - char *source = xml_att(item, "Source"); + char *source = fz_xml_att(item, "Source"); if (source) { char srcbuf[1024]; @@ -303,11 +303,11 @@ xps_parse_metadata_imp(xps_document *doc, xml_element *item, xps_fixdoc *fixdoc) } } - if (!strcmp(xml_tag(item), "PageContent")) + if (!strcmp(fz_xml_tag(item), "PageContent")) { - char *source = xml_att(item, "Source"); - char *width_att = xml_att(item, "Width"); - char *height_att = xml_att(item, "Height"); + char *source = fz_xml_att(item, "Source"); + char *width_att = fz_xml_att(item, "Width"); + char *height_att = fz_xml_att(item, "Height"); int width = width_att ? atoi(width_att) : 0; int height = height_att ? atoi(height_att) : 0; if (source) @@ -318,23 +318,23 @@ xps_parse_metadata_imp(xps_document *doc, xml_element *item, xps_fixdoc *fixdoc) } } - if (!strcmp(xml_tag(item), "LinkTarget")) + if (!strcmp(fz_xml_tag(item), "LinkTarget")) { - char *name = xml_att(item, "Name"); + char *name = fz_xml_att(item, "Name"); if (name) xps_add_link_target(doc, name); } - xps_parse_metadata_imp(doc, xml_down(item), fixdoc); + xps_parse_metadata_imp(doc, fz_xml_down(item), fixdoc); - item = xml_next(item); + item = fz_xml_next(item); } } static void xps_parse_metadata(xps_document *doc, xps_part *part, xps_fixdoc *fixdoc) { - xml_element *root; + fz_xml *root; char buf[1024]; char *s; @@ -355,9 +355,9 @@ xps_parse_metadata(xps_document *doc, xps_part *part, xps_fixdoc *fixdoc) doc->base_uri = buf; doc->part_uri = part->name; - root = xml_parse_document(doc->ctx, part->data, part->size); + root = fz_parse_xml(doc->ctx, part->data, part->size); xps_parse_metadata_imp(doc, root, fixdoc); - xml_free_element(doc->ctx, root); + fz_free_xml(doc->ctx, root); doc->base_uri = NULL; doc->part_uri = NULL; @@ -412,46 +412,46 @@ static void xps_load_fixed_page(xps_document *doc, xps_page *page) { xps_part *part; - xml_element *root; + fz_xml *root; char *width_att; char *height_att; part = xps_read_part(doc, page->name); - root = xml_parse_document(doc->ctx, part->data, part->size); + root = fz_parse_xml(doc->ctx, part->data, part->size); xps_free_part(doc, part); if (!root) fz_throw(doc->ctx, "FixedPage missing root element"); - if (!strcmp(xml_tag(root), "mc:AlternateContent")) + if (!strcmp(fz_xml_tag(root), "mc:AlternateContent")) { - xml_element *node = xps_lookup_alternate_content(root); + fz_xml *node = xps_lookup_alternate_content(root); if (!node) { - xml_free_element(doc->ctx, root); + fz_free_xml(doc->ctx, root); fz_throw(doc->ctx, "FixedPage missing alternate root element"); } - xml_detach(node); - xml_free_element(doc->ctx, root); + fz_detach_xml(node); + fz_free_xml(doc->ctx, root); root = node; } - if (strcmp(xml_tag(root), "FixedPage")) + if (strcmp(fz_xml_tag(root), "FixedPage")) { - xml_free_element(doc->ctx, root); + fz_free_xml(doc->ctx, root); fz_throw(doc->ctx, "expected FixedPage element"); } - width_att = xml_att(root, "Width"); + width_att = fz_xml_att(root, "Width"); if (!width_att) { - xml_free_element(doc->ctx, root); + fz_free_xml(doc->ctx, root); fz_throw(doc->ctx, "FixedPage missing required attribute: Width"); } - height_att = xml_att(root, "Height"); + height_att = fz_xml_att(root, "Height"); if (!height_att) { - xml_free_element(doc->ctx, root); + fz_free_xml(doc->ctx, root); fz_throw(doc->ctx, "FixedPage missing required attribute: Height"); } @@ -497,6 +497,6 @@ xps_free_page(xps_document *doc, xps_page *page) { /* only free the XML contents */ if (page->root) - xml_free_element(doc->ctx, page->root); + fz_free_xml(doc->ctx, page->root); page->root = NULL; } diff --git a/xps/xps_glyphs.c b/xps/xps_glyphs.c index 6b262016..cdc7b159 100644 --- a/xps/xps_glyphs.c +++ b/xps/xps_glyphs.c @@ -370,9 +370,9 @@ xps_parse_glyphs_imp(xps_document *doc, fz_matrix ctm, void xps_parse_glyphs(xps_document *doc, fz_matrix ctm, - char *base_uri, xps_resource *dict, xml_element *root) + char *base_uri, xps_resource *dict, fz_xml *root) { - xml_element *node; + fz_xml *node; char *fill_uri; char *opacity_mask_uri; @@ -394,10 +394,10 @@ xps_parse_glyphs(xps_document *doc, fz_matrix ctm, char *opacity_mask_att; char *navigate_uri_att; - xml_element *transform_tag = NULL; - xml_element *clip_tag = NULL; - xml_element *fill_tag = NULL; - xml_element *opacity_mask_tag = NULL; + fz_xml *transform_tag = NULL; + fz_xml *clip_tag = NULL; + fz_xml *fill_tag = NULL; + fz_xml *opacity_mask_tag = NULL; char *fill_opacity_att = NULL; @@ -420,33 +420,33 @@ xps_parse_glyphs(xps_document *doc, fz_matrix ctm, * Extract attributes and extended attributes. */ - bidi_level_att = xml_att(root, "BidiLevel"); - caret_stops_att = xml_att(root, "CaretStops"); - fill_att = xml_att(root, "Fill"); - font_size_att = xml_att(root, "FontRenderingEmSize"); - font_uri_att = xml_att(root, "FontUri"); - origin_x_att = xml_att(root, "OriginX"); - origin_y_att = xml_att(root, "OriginY"); - is_sideways_att = xml_att(root, "IsSideways"); - indices_att = xml_att(root, "Indices"); - unicode_att = xml_att(root, "UnicodeString"); - style_att = xml_att(root, "StyleSimulations"); - transform_att = xml_att(root, "RenderTransform"); - clip_att = xml_att(root, "Clip"); - opacity_att = xml_att(root, "Opacity"); - opacity_mask_att = xml_att(root, "OpacityMask"); - navigate_uri_att = xml_att(root, "FixedPage.NavigateUri"); - - for (node = xml_down(root); node; node = xml_next(node)) + bidi_level_att = fz_xml_att(root, "BidiLevel"); + caret_stops_att = fz_xml_att(root, "CaretStops"); + fill_att = fz_xml_att(root, "Fill"); + font_size_att = fz_xml_att(root, "FontRenderingEmSize"); + font_uri_att = fz_xml_att(root, "FontUri"); + origin_x_att = fz_xml_att(root, "OriginX"); + origin_y_att = fz_xml_att(root, "OriginY"); + is_sideways_att = fz_xml_att(root, "IsSideways"); + indices_att = fz_xml_att(root, "Indices"); + unicode_att = fz_xml_att(root, "UnicodeString"); + style_att = fz_xml_att(root, "StyleSimulations"); + transform_att = fz_xml_att(root, "RenderTransform"); + clip_att = fz_xml_att(root, "Clip"); + opacity_att = fz_xml_att(root, "Opacity"); + opacity_mask_att = fz_xml_att(root, "OpacityMask"); + navigate_uri_att = fz_xml_att(root, "FixedPage.NavigateUri"); + + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "Glyphs.RenderTransform")) - transform_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Glyphs.OpacityMask")) - opacity_mask_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Glyphs.Clip")) - clip_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Glyphs.Fill")) - fill_tag = xml_down(node); + if (!strcmp(fz_xml_tag(node), "Glyphs.RenderTransform")) + transform_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Glyphs.OpacityMask")) + opacity_mask_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Glyphs.Clip")) + clip_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Glyphs.Fill")) + fill_tag = fz_xml_down(node); } fill_uri = base_uri; @@ -578,10 +578,10 @@ xps_parse_glyphs(xps_document *doc, fz_matrix ctm, /* If it's a solid color brush fill/stroke do a simple fill */ - if (fill_tag && !strcmp(xml_tag(fill_tag), "SolidColorBrush")) + if (fill_tag && !strcmp(fz_xml_tag(fill_tag), "SolidColorBrush")) { - fill_opacity_att = xml_att(fill_tag, "Opacity"); - fill_att = xml_att(fill_tag, "Color"); + fill_opacity_att = fz_xml_att(fill_tag, "Opacity"); + fill_att = fz_xml_att(fill_tag, "Color"); fill_tag = NULL; } diff --git a/xps/xps_gradient.c b/xps/xps_gradient.c index 6972a79f..77d9c56f 100644 --- a/xps/xps_gradient.c +++ b/xps/xps_gradient.c @@ -34,7 +34,7 @@ static inline float lerp(float a, float b, float x) } static int -xps_parse_gradient_stops(xps_document *doc, char *base_uri, xml_element *node, +xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node, struct stop *stops, int maxcount) { fz_colorspace *colorspace; @@ -50,10 +50,10 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, xml_element *node, count = 0; while (node && count < maxcount) { - if (!strcmp(xml_tag(node), "GradientStop")) + if (!strcmp(fz_xml_tag(node), "GradientStop")) { - char *offset = xml_att(node, "Offset"); - char *color = xml_att(node, "Color"); + char *offset = fz_xml_att(node, "Offset"); + char *color = fz_xml_att(node, "Color"); if (offset && color) { stops[count].offset = fz_atof(offset); @@ -70,7 +70,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, xml_element *node, count ++; } } - node = xml_next(node); + node = fz_xml_next(node); } if (count == 0) @@ -292,7 +292,7 @@ static inline float point_inside_circle(float px, float py, float x, float y, fl static void xps_draw_radial_gradient(xps_document *doc, fz_matrix ctm, fz_rect area, struct stop *stops, int count, - xml_element *root, int spread) + fz_xml *root, int spread) { float x0, y0, r0; float x1, y1, r1; @@ -301,10 +301,10 @@ xps_draw_radial_gradient(xps_document *doc, fz_matrix ctm, fz_rect area, float invscale; int i, ma = 1; - char *center_att = xml_att(root, "Center"); - char *origin_att = xml_att(root, "GradientOrigin"); - char *radius_x_att = xml_att(root, "RadiusX"); - char *radius_y_att = xml_att(root, "RadiusY"); + char *center_att = fz_xml_att(root, "Center"); + char *origin_att = fz_xml_att(root, "GradientOrigin"); + char *radius_x_att = fz_xml_att(root, "RadiusX"); + char *radius_y_att = fz_xml_att(root, "RadiusY"); x0 = y0 = 0.0; x1 = y1 = 1.0; @@ -372,15 +372,15 @@ xps_draw_radial_gradient(xps_document *doc, fz_matrix ctm, fz_rect area, static void xps_draw_linear_gradient(xps_document *doc, fz_matrix ctm, fz_rect area, struct stop *stops, int count, - xml_element *root, int spread) + fz_xml *root, int spread) { float x0, y0, x1, y1; int i, mi, ma; float dx, dy, x, y, k; fz_point p1, p2; - char *start_point_att = xml_att(root, "StartPoint"); - char *end_point_att = xml_att(root, "EndPoint"); + char *start_point_att = fz_xml_att(root, "StartPoint"); + char *end_point_att = fz_xml_att(root, "EndPoint"); x0 = y0 = 0; x1 = y1 = 1; @@ -431,10 +431,10 @@ xps_draw_linear_gradient(xps_document *doc, fz_matrix ctm, fz_rect area, static void 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_document *, fz_matrix, fz_rect, struct stop *, int, xml_element *, int)) + char *base_uri, xps_resource *dict, fz_xml *root, + void (*draw)(xps_document *, fz_matrix, fz_rect, struct stop *, int, fz_xml *, int)) { - xml_element *node; + fz_xml *node; char *opacity_att; char *interpolation_att; @@ -442,30 +442,30 @@ xps_parse_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *mapping_att; char *transform_att; - xml_element *transform_tag = NULL; - xml_element *stop_tag = NULL; + fz_xml *transform_tag = NULL; + fz_xml *stop_tag = NULL; struct stop stop_list[MAX_STOPS]; int stop_count; fz_matrix transform; int spread_method; - opacity_att = xml_att(root, "Opacity"); - interpolation_att = xml_att(root, "ColorInterpolationMode"); - spread_att = xml_att(root, "SpreadMethod"); - mapping_att = xml_att(root, "MappingMode"); - transform_att = xml_att(root, "Transform"); + opacity_att = fz_xml_att(root, "Opacity"); + interpolation_att = fz_xml_att(root, "ColorInterpolationMode"); + spread_att = fz_xml_att(root, "SpreadMethod"); + mapping_att = fz_xml_att(root, "MappingMode"); + transform_att = fz_xml_att(root, "Transform"); - for (node = xml_down(root); node; node = xml_next(node)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "LinearGradientBrush.Transform")) - transform_tag = xml_down(node); - if (!strcmp(xml_tag(node), "RadialGradientBrush.Transform")) - transform_tag = xml_down(node); - if (!strcmp(xml_tag(node), "LinearGradientBrush.GradientStops")) - stop_tag = xml_down(node); - if (!strcmp(xml_tag(node), "RadialGradientBrush.GradientStops")) - stop_tag = xml_down(node); + if (!strcmp(fz_xml_tag(node), "LinearGradientBrush.Transform")) + transform_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "RadialGradientBrush.Transform")) + transform_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "LinearGradientBrush.GradientStops")) + stop_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "RadialGradientBrush.GradientStops")) + stop_tag = fz_xml_down(node); } xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); @@ -509,14 +509,14 @@ xps_parse_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, void xps_parse_linear_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, - char *base_uri, xps_resource *dict, xml_element *root) + char *base_uri, xps_resource *dict, fz_xml *root) { xps_parse_gradient_brush(doc, ctm, area, base_uri, dict, root, xps_draw_linear_gradient); } void xps_parse_radial_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, - char *base_uri, xps_resource *dict, xml_element *root) + char *base_uri, xps_resource *dict, fz_xml *root) { 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 1a6a8573..ee20543d 100644 --- a/xps/xps_image.c +++ b/xps/xps_image.c @@ -76,7 +76,7 @@ xps_load_image(fz_context *ctx, byte *buf, int len) static void 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_xml *root, void *vimage) { xps_image *image = vimage; float xs, ys; @@ -90,7 +90,7 @@ xps_paint_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base } static xps_part * -xps_find_image_brush_source_part(xps_document *doc, char *base_uri, xml_element *root) +xps_find_image_brush_source_part(xps_document *doc, char *base_uri, fz_xml *root) { char *image_source_att; char buf[1024]; @@ -99,7 +99,7 @@ xps_find_image_brush_source_part(xps_document *doc, char *base_uri, xml_element char *profile_name; char *p; - image_source_att = xml_att(root, "ImageSource"); + image_source_att = fz_xml_att(root, "ImageSource"); if (!image_source_att) fz_throw(doc->ctx, "cannot find image source attribute"); @@ -141,7 +141,7 @@ xps_find_image_brush_source_part(xps_document *doc, char *base_uri, xml_element void xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, - char *base_uri, xps_resource *dict, xml_element *root) + char *base_uri, xps_resource *dict, fz_xml *root) { xps_part *part; fz_image *image; diff --git a/xps/xps_outline.c b/xps/xps_outline.c index 21dc0710..5c5bdbc6 100644 --- a/xps/xps_outline.c +++ b/xps/xps_outline.c @@ -15,18 +15,18 @@ xps_find_last_outline_at_level(fz_outline *node, int level, int target_level) } static fz_outline * -xps_parse_document_outline(xps_document *doc, xml_element *root) +xps_parse_document_outline(xps_document *doc, fz_xml *root) { - xml_element *node; + fz_xml *node; fz_outline *head = NULL, *entry, *tail; int last_level = 1, this_level; - for (node = xml_down(root); node; node = xml_next(node)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "OutlineEntry")) + if (!strcmp(fz_xml_tag(node), "OutlineEntry")) { - char *level = xml_att(node, "OutlineLevel"); - char *target = xml_att(node, "OutlineTarget"); - char *description = xml_att(node, "Description"); + char *level = fz_xml_att(node, "OutlineLevel"); + char *target = fz_xml_att(node, "OutlineTarget"); + char *description = fz_xml_att(node, "Description"); if (!target || !description) continue; @@ -60,16 +60,16 @@ xps_parse_document_outline(xps_document *doc, xml_element *root) } static fz_outline * -xps_parse_document_structure(xps_document *doc, xml_element *root) +xps_parse_document_structure(xps_document *doc, fz_xml *root) { - xml_element *node; - if (!strcmp(xml_tag(root), "DocumentStructure")) + fz_xml *node; + if (!strcmp(fz_xml_tag(root), "DocumentStructure")) { - node = xml_down(root); - if (!strcmp(xml_tag(node), "DocumentStructure.Outline")) + node = fz_xml_down(root); + if (!strcmp(fz_xml_tag(node), "DocumentStructure.Outline")) { - node = xml_down(node); - if (!strcmp(xml_tag(node), "DocumentOutline")) + node = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "DocumentOutline")) return xps_parse_document_outline(doc, node); } } @@ -80,13 +80,13 @@ static fz_outline * xps_load_document_structure(xps_document *doc, xps_fixdoc *fixdoc) { xps_part *part; - xml_element *root; + fz_xml *root; fz_outline *outline; part = xps_read_part(doc, fixdoc->outline); fz_try(doc->ctx) { - root = xml_parse_document(doc->ctx, part->data, part->size); + root = fz_parse_xml(doc->ctx, part->data, part->size); } fz_always(doc->ctx) { @@ -105,7 +105,7 @@ xps_load_document_structure(xps_document *doc, xps_fixdoc *fixdoc) } fz_always(doc->ctx) { - xml_free_element(doc->ctx, root); + fz_free_xml(doc->ctx, root); } fz_catch(doc->ctx) { diff --git a/xps/xps_path.c b/xps/xps_path.c index 8650fbb8..3bc92ff3 100644 --- a/xps/xps_path.c +++ b/xps/xps_path.c @@ -465,7 +465,7 @@ xps_parse_abbreviated_geometry(xps_document *doc, char *geom, int *fill_rule) } static void -xps_parse_arc_segment(fz_context *doc, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) +xps_parse_arc_segment(fz_context *doc, fz_path *path, fz_xml *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 @@ -478,12 +478,12 @@ xps_parse_arc_segment(fz_context *doc, fz_path *path, xml_element *root, int str float size_x, size_y; int is_stroked; - char *point_att = xml_att(root, "Point"); - char *size_att = xml_att(root, "Size"); - char *rotation_angle_att = xml_att(root, "RotationAngle"); - char *is_large_arc_att = xml_att(root, "IsLargeArc"); - char *sweep_direction_att = xml_att(root, "SweepDirection"); - char *is_stroked_att = xml_att(root, "IsStroked"); + char *point_att = fz_xml_att(root, "Point"); + char *size_att = fz_xml_att(root, "Size"); + char *rotation_angle_att = fz_xml_att(root, "RotationAngle"); + char *is_large_arc_att = fz_xml_att(root, "IsLargeArc"); + char *sweep_direction_att = fz_xml_att(root, "SweepDirection"); + char *is_stroked_att = fz_xml_att(root, "IsStroked"); if (!point_att || !size_att || !rotation_angle_att || !is_large_arc_att || !sweep_direction_att) { @@ -516,10 +516,10 @@ xps_parse_arc_segment(fz_context *doc, fz_path *path, xml_element *root, int str } static void -xps_parse_poly_quadratic_bezier_segment(fz_context *doc, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) +xps_parse_poly_quadratic_bezier_segment(fz_context *doc, fz_path *path, fz_xml *root, int stroking, int *skipped_stroke) { - char *points_att = xml_att(root, "Points"); - char *is_stroked_att = xml_att(root, "IsStroked"); + char *points_att = fz_xml_att(root, "Points"); + char *is_stroked_att = fz_xml_att(root, "IsStroked"); float x[2], y[2]; int is_stroked; fz_point pt; @@ -565,10 +565,10 @@ xps_parse_poly_quadratic_bezier_segment(fz_context *doc, fz_path *path, xml_elem } static void -xps_parse_poly_bezier_segment(fz_context *doc, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) +xps_parse_poly_bezier_segment(fz_context *doc, fz_path *path, fz_xml *root, int stroking, int *skipped_stroke) { - char *points_att = xml_att(root, "Points"); - char *is_stroked_att = xml_att(root, "IsStroked"); + char *points_att = fz_xml_att(root, "Points"); + char *is_stroked_att = fz_xml_att(root, "IsStroked"); float x[3], y[3]; int is_stroked; char *s; @@ -605,10 +605,10 @@ xps_parse_poly_bezier_segment(fz_context *doc, fz_path *path, xml_element *root, } static void -xps_parse_poly_line_segment(fz_context *doc, fz_path *path, xml_element *root, int stroking, int *skipped_stroke) +xps_parse_poly_line_segment(fz_context *doc, fz_path *path, fz_xml *root, int stroking, int *skipped_stroke) { - char *points_att = xml_att(root, "Points"); - char *is_stroked_att = xml_att(root, "IsStroked"); + char *points_att = fz_xml_att(root, "Points"); + char *is_stroked_att = fz_xml_att(root, "IsStroked"); int is_stroked; float x, y; char *s; @@ -638,9 +638,9 @@ xps_parse_poly_line_segment(fz_context *doc, fz_path *path, xml_element *root, i } static void -xps_parse_path_figure(fz_context *doc, fz_path *path, xml_element *root, int stroking) +xps_parse_path_figure(fz_context *doc, fz_path *path, fz_xml *root, int stroking) { - xml_element *node; + fz_xml *node; char *is_closed_att; char *start_point_att; @@ -653,9 +653,9 @@ xps_parse_path_figure(fz_context *doc, fz_path *path, xml_element *root, int str int skipped_stroke = 0; - is_closed_att = xml_att(root, "IsClosed"); - start_point_att = xml_att(root, "StartPoint"); - is_filled_att = xml_att(root, "IsFilled"); + is_closed_att = fz_xml_att(root, "IsClosed"); + start_point_att = fz_xml_att(root, "StartPoint"); + is_filled_att = fz_xml_att(root, "IsFilled"); if (is_closed_att) is_closed = !strcmp(is_closed_att, "true"); @@ -669,15 +669,15 @@ xps_parse_path_figure(fz_context *doc, fz_path *path, xml_element *root, int str fz_moveto(doc, path, start_x, start_y); - for (node = xml_down(root); node; node = xml_next(node)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "ArcSegment")) + if (!strcmp(fz_xml_tag(node), "ArcSegment")) xps_parse_arc_segment(doc, path, node, stroking, &skipped_stroke); - if (!strcmp(xml_tag(node), "PolyBezierSegment")) + if (!strcmp(fz_xml_tag(node), "PolyBezierSegment")) xps_parse_poly_bezier_segment(doc, path, node, stroking, &skipped_stroke); - if (!strcmp(xml_tag(node), "PolyLineSegment")) + if (!strcmp(fz_xml_tag(node), "PolyLineSegment")) xps_parse_poly_line_segment(doc, path, node, stroking, &skipped_stroke); - if (!strcmp(xml_tag(node), "PolyQuadraticBezierSegment")) + if (!strcmp(fz_xml_tag(node), "PolyQuadraticBezierSegment")) xps_parse_poly_quadratic_bezier_segment(doc, path, node, stroking, &skipped_stroke); } @@ -691,28 +691,28 @@ xps_parse_path_figure(fz_context *doc, fz_path *path, xml_element *root, int str } fz_path * -xps_parse_path_geometry(xps_document *doc, xps_resource *dict, xml_element *root, int stroking, int *fill_rule) +xps_parse_path_geometry(xps_document *doc, xps_resource *dict, fz_xml *root, int stroking, int *fill_rule) { - xml_element *node; + fz_xml *node; char *figures_att; char *fill_rule_att; char *transform_att; - xml_element *transform_tag = NULL; - xml_element *figures_tag = NULL; /* only used by resource */ + fz_xml *transform_tag = NULL; + fz_xml *figures_tag = NULL; /* only used by resource */ fz_matrix transform; fz_path *path; - figures_att = xml_att(root, "Figures"); - fill_rule_att = xml_att(root, "FillRule"); - transform_att = xml_att(root, "Transform"); + figures_att = fz_xml_att(root, "Figures"); + fill_rule_att = fz_xml_att(root, "FillRule"); + transform_att = fz_xml_att(root, "Transform"); - for (node = xml_down(root); node; node = xml_next(node)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "PathGeometry.Transform")) - transform_tag = xml_down(node); + if (!strcmp(fz_xml_tag(node), "PathGeometry.Transform")) + transform_tag = fz_xml_down(node); } xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); @@ -740,9 +740,9 @@ xps_parse_path_geometry(xps_document *doc, xps_resource *dict, xml_element *root if (figures_tag) xps_parse_path_figure(doc->ctx, path, figures_tag, stroking); - for (node = xml_down(root); node; node = xml_next(node)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "PathFigure")) + if (!strcmp(fz_xml_tag(node), "PathFigure")) xps_parse_path_figure(doc->ctx, path, node, stroking); } @@ -766,7 +766,7 @@ xps_parse_line_cap(char *attr) } void -xps_clip(xps_document *doc, 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, fz_xml *clip_tag) { fz_path *path; int fill_rule = 0; @@ -787,9 +787,9 @@ xps_clip(xps_document *doc, fz_matrix ctm, xps_resource *dict, char *clip_att, x */ void -xps_parse_path(xps_document *doc, 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, fz_xml *root) { - xml_element *node; + fz_xml *node; char *fill_uri; char *stroke_uri; @@ -803,12 +803,12 @@ xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *d char *opacity_att; char *opacity_mask_att; - xml_element *transform_tag = NULL; - xml_element *clip_tag = NULL; - xml_element *data_tag = NULL; - xml_element *fill_tag = NULL; - xml_element *stroke_tag = NULL; - xml_element *opacity_mask_tag = NULL; + fz_xml *transform_tag = NULL; + fz_xml *clip_tag = NULL; + fz_xml *data_tag = NULL; + fz_xml *fill_tag = NULL; + fz_xml *stroke_tag = NULL; + fz_xml *opacity_mask_tag = NULL; char *fill_opacity_att = NULL; char *stroke_opacity_att = NULL; @@ -837,38 +837,38 @@ xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *d * Extract attributes and extended attributes. */ - transform_att = xml_att(root, "RenderTransform"); - clip_att = xml_att(root, "Clip"); - data_att = xml_att(root, "Data"); - fill_att = xml_att(root, "Fill"); - stroke_att = xml_att(root, "Stroke"); - opacity_att = xml_att(root, "Opacity"); - opacity_mask_att = xml_att(root, "OpacityMask"); - - stroke_dash_array_att = xml_att(root, "StrokeDashArray"); - stroke_dash_cap_att = xml_att(root, "StrokeDashCap"); - stroke_dash_offset_att = xml_att(root, "StrokeDashOffset"); - stroke_end_line_cap_att = xml_att(root, "StrokeEndLineCap"); - stroke_start_line_cap_att = xml_att(root, "StrokeStartLineCap"); - stroke_line_join_att = xml_att(root, "StrokeLineJoin"); - stroke_miter_limit_att = xml_att(root, "StrokeMiterLimit"); - stroke_thickness_att = xml_att(root, "StrokeThickness"); - navigate_uri_att = xml_att(root, "FixedPage.NavigateUri"); - - for (node = xml_down(root); node; node = xml_next(node)) + transform_att = fz_xml_att(root, "RenderTransform"); + clip_att = fz_xml_att(root, "Clip"); + data_att = fz_xml_att(root, "Data"); + fill_att = fz_xml_att(root, "Fill"); + stroke_att = fz_xml_att(root, "Stroke"); + opacity_att = fz_xml_att(root, "Opacity"); + opacity_mask_att = fz_xml_att(root, "OpacityMask"); + + stroke_dash_array_att = fz_xml_att(root, "StrokeDashArray"); + stroke_dash_cap_att = fz_xml_att(root, "StrokeDashCap"); + stroke_dash_offset_att = fz_xml_att(root, "StrokeDashOffset"); + stroke_end_line_cap_att = fz_xml_att(root, "StrokeEndLineCap"); + stroke_start_line_cap_att = fz_xml_att(root, "StrokeStartLineCap"); + stroke_line_join_att = fz_xml_att(root, "StrokeLineJoin"); + stroke_miter_limit_att = fz_xml_att(root, "StrokeMiterLimit"); + stroke_thickness_att = fz_xml_att(root, "StrokeThickness"); + navigate_uri_att = fz_xml_att(root, "FixedPage.NavigateUri"); + + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "Path.RenderTransform")) - transform_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Path.OpacityMask")) - opacity_mask_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Path.Clip")) - clip_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Path.Fill")) - fill_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Path.Stroke")) - stroke_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Path.Data")) - data_tag = xml_down(node); + if (!strcmp(fz_xml_tag(node), "Path.RenderTransform")) + transform_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Path.OpacityMask")) + opacity_mask_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Path.Clip")) + clip_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Path.Fill")) + fill_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Path.Stroke")) + stroke_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Path.Data")) + data_tag = fz_xml_down(node); } fill_uri = base_uri; @@ -889,17 +889,17 @@ xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *d if (!data_att && !data_tag) return; - if (fill_tag && !strcmp(xml_tag(fill_tag), "SolidColorBrush")) + if (fill_tag && !strcmp(fz_xml_tag(fill_tag), "SolidColorBrush")) { - fill_opacity_att = xml_att(fill_tag, "Opacity"); - fill_att = xml_att(fill_tag, "Color"); + fill_opacity_att = fz_xml_att(fill_tag, "Opacity"); + fill_att = fz_xml_att(fill_tag, "Color"); fill_tag = NULL; } - if (stroke_tag && !strcmp(xml_tag(stroke_tag), "SolidColorBrush")) + if (stroke_tag && !strcmp(fz_xml_tag(stroke_tag), "SolidColorBrush")) { - stroke_opacity_att = xml_att(stroke_tag, "Opacity"); - stroke_att = xml_att(stroke_tag, "Color"); + stroke_opacity_att = fz_xml_att(stroke_tag, "Opacity"); + stroke_att = fz_xml_att(stroke_tag, "Color"); stroke_tag = NULL; } diff --git a/xps/xps_resource.c b/xps/xps_resource.c index 73372801..ffbce2d3 100644 --- a/xps/xps_resource.c +++ b/xps/xps_resource.c @@ -1,6 +1,6 @@ #include "muxps-internal.h" -static xml_element * +static fz_xml * xps_find_resource(xps_document *doc, xps_resource *dict, char *name, char **urip) { xps_resource *head, *node; @@ -19,7 +19,7 @@ xps_find_resource(xps_document *doc, xps_resource *dict, char *name, char **urip return NULL; } -static xml_element * +static fz_xml * xps_parse_resource_reference(xps_document *doc, xps_resource *dict, char *att, char **urip) { char name[1024]; @@ -38,11 +38,11 @@ xps_parse_resource_reference(xps_document *doc, xps_resource *dict, char *att, c void xps_resolve_resource_reference(xps_document *doc, xps_resource *dict, - char **attp, xml_element **tagp, char **urip) + char **attp, fz_xml **tagp, char **urip) { if (*attp) { - xml_element *rsrc = xps_parse_resource_reference(doc, dict, *attp, urip); + fz_xml *rsrc = xps_parse_resource_reference(doc, dict, *attp, urip); if (rsrc) { *attp = NULL; @@ -58,21 +58,21 @@ xps_parse_remote_resource_dictionary(xps_document *doc, char *base_uri, char *so char part_uri[1024]; xps_resource *dict; xps_part *part; - xml_element *xml; + fz_xml *xml; char *s; /* External resource dictionaries MUST NOT reference other resource dictionaries */ xps_resolve_url(part_name, base_uri, source_att, sizeof part_name); part = xps_read_part(doc, part_name); - xml = xml_parse_document(doc->ctx, part->data, part->size); + xml = fz_parse_xml(doc->ctx, part->data, part->size); xps_free_part(doc, part); if (!xml) return NULL; - if (strcmp(xml_tag(xml), "ResourceDictionary")) + if (strcmp(fz_xml_tag(xml), "ResourceDictionary")) { - xml_free_element(doc->ctx, xml); + fz_free_xml(doc->ctx, xml); fz_throw(doc->ctx, "expected ResourceDictionary element"); } @@ -89,23 +89,23 @@ xps_parse_remote_resource_dictionary(xps_document *doc, char *base_uri, char *so } xps_resource * -xps_parse_resource_dictionary(xps_document *doc, char *base_uri, xml_element *root) +xps_parse_resource_dictionary(xps_document *doc, char *base_uri, fz_xml *root) { xps_resource *head; xps_resource *entry; - xml_element *node; + fz_xml *node; char *source; char *key; - source = xml_att(root, "Source"); + source = fz_xml_att(root, "Source"); if (source) return xps_parse_remote_resource_dictionary(doc, base_uri, source); head = NULL; - for (node = xml_down(root); node; node = xml_next(node)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - key = xml_att(node, "x:Key"); + key = fz_xml_att(node, "x:Key"); if (key) { entry = fz_malloc_struct(doc->ctx, xps_resource); @@ -133,7 +133,7 @@ xps_free_resource_dictionary(xps_document *doc, xps_resource *dict) { next = dict->next; if (dict->base_xml) - xml_free_element(doc->ctx, dict->base_xml); + fz_free_xml(doc->ctx, dict->base_xml); if (dict->base_uri) fz_free(doc->ctx, dict->base_uri); fz_free(doc->ctx, dict); diff --git a/xps/xps_tile.c b/xps/xps_tile.c index fcac57d8..7c1ed933 100644 --- a/xps/xps_tile.c +++ b/xps/xps_tile.c @@ -13,9 +13,9 @@ struct closure { char *base_uri; xps_resource *dict; - xml_element *root; + fz_xml *root; void *user; - void (*func)(xps_document*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*); + void (*func)(xps_document*, fz_matrix, fz_rect, char*, xps_resource*, fz_xml*, void*); }; static void @@ -64,10 +64,10 @@ xps_paint_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect viewbox, int ti 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) + char *base_uri, xps_resource *dict, fz_xml *root, + void (*func)(xps_document*, fz_matrix, fz_rect, char*, xps_resource*, fz_xml*, void*), void *user) { - xml_element *node; + fz_xml *node; struct closure c; char *opacity_att; @@ -78,7 +78,7 @@ xps_parse_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *viewbox_units_att; char *viewport_units_att; - xml_element *transform_tag = NULL; + fz_xml *transform_tag = NULL; fz_matrix transform; fz_rect viewbox; @@ -87,13 +87,13 @@ xps_parse_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect area, float xscale, yscale; int tile_mode; - opacity_att = xml_att(root, "Opacity"); - transform_att = xml_att(root, "Transform"); - viewbox_att = xml_att(root, "Viewbox"); - viewport_att = xml_att(root, "Viewport"); - tile_mode_att = xml_att(root, "TileMode"); - viewbox_units_att = xml_att(root, "ViewboxUnits"); - viewport_units_att = xml_att(root, "ViewportUnits"); + opacity_att = fz_xml_att(root, "Opacity"); + transform_att = fz_xml_att(root, "Transform"); + viewbox_att = fz_xml_att(root, "Viewbox"); + viewport_att = fz_xml_att(root, "Viewport"); + tile_mode_att = fz_xml_att(root, "TileMode"); + viewbox_units_att = fz_xml_att(root, "ViewboxUnits"); + viewport_units_att = fz_xml_att(root, "ViewportUnits"); c.base_uri = base_uri; c.dict = dict; @@ -101,12 +101,12 @@ xps_parse_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect area, c.user = user; c.func = func; - for (node = xml_down(root); node; node = xml_next(node)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "ImageBrush.Transform")) - transform_tag = xml_down(node); - if (!strcmp(xml_tag(node), "VisualBrush.Transform")) - transform_tag = xml_down(node); + if (!strcmp(fz_xml_tag(node), "ImageBrush.Transform")) + transform_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "VisualBrush.Transform")) + transform_tag = fz_xml_down(node); } xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); @@ -215,27 +215,27 @@ xps_parse_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect area, static void 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) + char *base_uri, xps_resource *dict, fz_xml *root, void *visual_tag) { - xps_parse_element(doc, ctm, area, base_uri, dict, (xml_element *)visual_tag); + xps_parse_element(doc, ctm, area, base_uri, dict, (fz_xml *)visual_tag); } void xps_parse_visual_brush(xps_document *doc, fz_matrix ctm, fz_rect area, - char *base_uri, xps_resource *dict, xml_element *root) + char *base_uri, xps_resource *dict, fz_xml *root) { - xml_element *node; + fz_xml *node; char *visual_uri; char *visual_att; - xml_element *visual_tag = NULL; + fz_xml *visual_tag = NULL; - visual_att = xml_att(root, "Visual"); + visual_att = fz_xml_att(root, "Visual"); - for (node = xml_down(root); node; node = xml_next(node)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "VisualBrush.Visual")) - visual_tag = xml_down(node); + if (!strcmp(fz_xml_tag(node), "VisualBrush.Visual")) + visual_tag = fz_xml_down(node); } visual_uri = base_uri; @@ -249,10 +249,10 @@ xps_parse_visual_brush(xps_document *doc, fz_matrix ctm, fz_rect area, } void -xps_parse_canvas(xps_document *doc, 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, fz_xml *root) { xps_resource *new_dict = NULL; - xml_element *node; + fz_xml *node; char *opacity_mask_uri; char *transform_att; @@ -261,21 +261,21 @@ xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, char *opacity_mask_att; char *navigate_uri_att; - xml_element *transform_tag = NULL; - xml_element *clip_tag = NULL; - xml_element *opacity_mask_tag = NULL; + fz_xml *transform_tag = NULL; + fz_xml *clip_tag = NULL; + fz_xml *opacity_mask_tag = NULL; fz_matrix transform; - transform_att = xml_att(root, "RenderTransform"); - clip_att = xml_att(root, "Clip"); - opacity_att = xml_att(root, "Opacity"); - opacity_mask_att = xml_att(root, "OpacityMask"); - navigate_uri_att = xml_att(root, "FixedPage.NavigateUri"); + transform_att = fz_xml_att(root, "RenderTransform"); + clip_att = fz_xml_att(root, "Clip"); + opacity_att = fz_xml_att(root, "Opacity"); + opacity_mask_att = fz_xml_att(root, "OpacityMask"); + navigate_uri_att = fz_xml_att(root, "FixedPage.NavigateUri"); - for (node = xml_down(root); node; node = xml_next(node)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "Canvas.Resources") && xml_down(node)) + if (!strcmp(fz_xml_tag(node), "Canvas.Resources") && fz_xml_down(node)) { if (new_dict) { @@ -283,7 +283,7 @@ xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, } else { - new_dict = xps_parse_resource_dictionary(doc, base_uri, xml_down(node)); + new_dict = xps_parse_resource_dictionary(doc, base_uri, fz_xml_down(node)); if (new_dict) { new_dict->parent = dict; @@ -292,12 +292,12 @@ xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, } } - if (!strcmp(xml_tag(node), "Canvas.RenderTransform")) - transform_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Canvas.Clip")) - clip_tag = xml_down(node); - if (!strcmp(xml_tag(node), "Canvas.OpacityMask")) - opacity_mask_tag = xml_down(node); + if (!strcmp(fz_xml_tag(node), "Canvas.RenderTransform")) + transform_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Canvas.Clip")) + clip_tag = fz_xml_down(node); + if (!strcmp(fz_xml_tag(node), "Canvas.OpacityMask")) + opacity_mask_tag = fz_xml_down(node); } opacity_mask_uri = base_uri; @@ -320,7 +320,7 @@ xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, 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)) + for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { xps_parse_element(doc, ctm, area, base_uri, dict, node); } @@ -337,7 +337,7 @@ xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, void xps_parse_fixed_page(xps_document *doc, fz_matrix ctm, xps_page *page) { - xml_element *node; + fz_xml *node; xps_resource *dict; char base_uri[1024]; fz_rect area; @@ -358,14 +358,14 @@ xps_parse_fixed_page(xps_document *doc, fz_matrix ctm, xps_page *page) area = fz_transform_rect(fz_scale(page->width, page->height), fz_unit_rect); - for (node = xml_down(page->root); node; node = xml_next(node)) + for (node = fz_xml_down(page->root); node; node = fz_xml_next(node)) { - if (!strcmp(xml_tag(node), "FixedPage.Resources") && xml_down(node)) + if (!strcmp(fz_xml_tag(node), "FixedPage.Resources") && fz_xml_down(node)) { if (dict) fz_warn(doc->ctx, "ignoring follow-up resource dictionaries"); else - dict = xps_parse_resource_dictionary(doc, base_uri, xml_down(node)); + dict = xps_parse_resource_dictionary(doc, base_uri, fz_xml_down(node)); } xps_parse_element(doc, ctm, area, base_uri, dict, node); } diff --git a/xps/xps_xml.c b/xps/xps_xml.c index fd7f6805..739c00ec 100644 --- a/xps/xps_xml.c +++ b/xps/xps_xml.c @@ -1,4 +1,10 @@ -#include "muxps-internal.h" +#include "muxps.h" + +struct parser +{ + fz_xml *head; + fz_context *ctx; +}; struct attribute { @@ -7,18 +13,12 @@ struct attribute struct attribute *next; }; -struct element +struct fz_xml_s { char name[40]; char *text; struct attribute *atts; - struct element *up, *down, *next; -}; - -struct parser -{ - struct element *head; - fz_context *ctx; + fz_xml *up, *down, *next; }; static inline void indent(int n) @@ -26,7 +26,7 @@ static inline void indent(int n) while (n--) putchar(' '); } -void xml_print_element(struct element *item, int level) +void fz_print_xml(fz_xml *item, int level) { while (item) { if (item->text) { @@ -39,7 +39,7 @@ void xml_print_element(struct element *item, int level) printf(" %s=\"%s\"", att->name, att->value); if (item->down) { printf(">\n"); - xml_print_element(item->down, level + 1); + fz_print_xml(item->down, level + 1); indent(level); printf("</%s>\n", item->name); } @@ -51,27 +51,27 @@ void xml_print_element(struct element *item, int level) } } -struct element *xml_next(struct element *item) +fz_xml *fz_xml_next(fz_xml *item) { return item->next; } -struct element *xml_down(struct element *item) +fz_xml *fz_xml_down(fz_xml *item) { return item->down; } -char *xml_text(struct element *item) +char *fz_xml_text(fz_xml *item) { return item->text; } -char *xml_tag(struct element *item) +char *fz_xml_tag(fz_xml *item) { return item->name; } -char *xml_att(struct element *item, const char *name) +char *fz_xml_att(fz_xml *item, const char *name) { struct attribute *att; for (att = item->atts; att; att = att->next) @@ -91,22 +91,22 @@ static void xml_free_attribute(fz_context *ctx, struct attribute *att) } } -void xml_free_element(fz_context *ctx, struct element *item) +void fz_free_xml(fz_context *ctx, fz_xml *item) { while (item) { - struct element *next = item->next; + fz_xml *next = item->next; if (item->text) fz_free(ctx, item->text); if (item->atts) xml_free_attribute(ctx, item->atts); if (item->down) - xml_free_element(ctx, item->down); + fz_free_xml(ctx, item->down); fz_free(ctx, item); item = next; } } -void xml_detach(xml_element *node) +void fz_detach_xml(fz_xml *node) { if (node->up) node->up->down = NULL; @@ -162,9 +162,9 @@ static inline int iswhite(int c) static void xml_emit_open_tag(struct parser *parser, char *a, char *b) { - struct element *head, *tail; + fz_xml *head, *tail; - head = fz_malloc_struct(parser->ctx, struct element); + head = fz_malloc_struct(parser->ctx, fz_xml); if (b - a > sizeof(head->name) - 1) b = a + sizeof(head->name) - 1; memcpy(head->name, a, b - a); @@ -191,7 +191,7 @@ static void xml_emit_open_tag(struct parser *parser, char *a, char *b) static void xml_emit_att_name(struct parser *parser, char *a, char *b) { - struct element *head = parser->head; + fz_xml *head = parser->head; struct attribute *att; att = fz_malloc_struct(parser->ctx, struct attribute); @@ -206,7 +206,7 @@ static void xml_emit_att_name(struct parser *parser, char *a, char *b) static void xml_emit_att_value(struct parser *parser, char *a, char *b) { - struct element *head = parser->head; + fz_xml *head = parser->head; struct attribute *att = head->atts; char *s; int c; @@ -234,7 +234,7 @@ static void xml_emit_close_tag(struct parser *parser) static void xml_emit_text(struct parser *parser, char *a, char *b) { static char *empty = ""; - struct element *head; + fz_xml *head; char *s; int c; @@ -413,11 +413,11 @@ static char *convert_to_utf8(fz_context *doc, unsigned char *s, int n) return (char*)s; } -struct element * -xml_parse_document(fz_context *ctx, unsigned char *s, int n) +fz_xml * +fz_parse_xml(fz_context *ctx, unsigned char *s, int n) { struct parser parser; - struct element root; + fz_xml root; char *p, *error; /* s is already null-terminated (see xps_new_part) */ |