static void xps_load_links_in_fixed_page(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, xps_page *page, fz_link **link) { fz_xml *node, *resource_tag; xps_resource *dict = NULL; char base_uri[1024]; char *s; if (!page->root) return; fz_strlcpy(base_uri, page->fix->name, sizeof base_uri); s = strrchr(base_uri, '/'); if (s) s[1] = 0; resource_tag = fz_xml_down(fz_xml_find_down(page->root, "FixedPage.Resources")); if (resource_tag) dict = xps_parse_resource_dictionary(ctx, doc, base_uri, resource_tag); for (node = fz_xml_down(page->root); node; node = fz_xml_next(node)) xps_load_links_in_element(ctx, doc, ctm, base_uri, dict, node, link); if (dict) xps_drop_resource_dictionary(ctx, doc, dict); }
void xps_parse_fixed_page(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, xps_page *page) { fz_xml *root, *node; xps_resource *dict; char base_uri[1024]; fz_rect area; char *s; fz_matrix scm; fz_strlcpy(base_uri, page->fix->name, sizeof base_uri); s = strrchr(base_uri, '/'); if (s) s[1] = 0; dict = NULL; doc->opacity_top = 0; doc->opacity[0] = 1; root = fz_xml_root(page->xml); if (!root) return; area = fz_unit_rect; fz_transform_rect(&area, fz_scale(&scm, page->fix->width, page->fix->height)); fz_try(ctx) { for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { if (fz_xml_is_tag(node, "FixedPage.Resources") && fz_xml_down(node)) { if (dict) fz_warn(ctx, "ignoring follow-up resource dictionaries"); else dict = xps_parse_resource_dictionary(ctx, doc, base_uri, fz_xml_down(node)); } xps_parse_element(ctx, doc, ctm, &area, base_uri, dict, node); } } fz_always(ctx) xps_drop_resource_dictionary(ctx, doc, dict); fz_catch(ctx) fz_rethrow(ctx); }
static void xps_load_links_in_canvas(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_resource *dict, fz_xml *root, fz_link **link) { xps_resource *new_dict = NULL; fz_matrix local_ctm; fz_xml *node; char *navigate_uri_att = fz_xml_att(root, "FixedPage.NavigateUri"); char *transform_att = fz_xml_att(root, "RenderTransform"); fz_xml *transform_tag = fz_xml_down(fz_xml_find_down(root, "Canvas.RenderTransform")); fz_xml *resource_tag = fz_xml_down(fz_xml_find_down(root, "Canvas.Resources")); if (resource_tag) { new_dict = xps_parse_resource_dictionary(ctx, doc, base_uri, resource_tag); if (new_dict) { new_dict->parent = dict; dict = new_dict; } } xps_resolve_resource_reference(ctx, doc, dict, &transform_att, &transform_tag, NULL); xps_parse_transform(ctx, doc, transform_att, transform_tag, &local_ctm, ctm); if (navigate_uri_att) fz_warn(ctx, "FixedPage.NavigateUri attribute on Canvas element"); for (node = fz_xml_down(root); node; node = fz_xml_next(node)) xps_load_links_in_element(ctx, doc, &local_ctm, base_uri, dict, node, link); if (new_dict) xps_drop_resource_dictionary(ctx, doc, new_dict); }
void xps_parse_canvas(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *root) { fz_device *dev = doc->dev; xps_resource *new_dict = NULL; fz_xml *node; char *opacity_mask_uri; char *transform_att; char *clip_att; char *opacity_att; char *opacity_mask_att; char *navigate_uri_att; fz_xml *transform_tag = NULL; fz_xml *clip_tag = NULL; fz_xml *opacity_mask_tag = NULL; fz_matrix transform; 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 (fz_xml_is_tag(node, "Canvas.Resources") && fz_xml_down(node)) { if (new_dict) { fz_warn(ctx, "ignoring follow-up resource dictionaries"); } else { new_dict = xps_parse_resource_dictionary(ctx, doc, base_uri, fz_xml_down(node)); if (new_dict) { new_dict->parent = dict; dict = new_dict; } } } if (fz_xml_is_tag(node, "Canvas.RenderTransform")) transform_tag = fz_xml_down(node); if (fz_xml_is_tag(node, "Canvas.Clip")) clip_tag = fz_xml_down(node); if (fz_xml_is_tag(node, "Canvas.OpacityMask")) opacity_mask_tag = fz_xml_down(node); } opacity_mask_uri = base_uri; xps_resolve_resource_reference(ctx, doc, dict, &transform_att, &transform_tag, NULL); xps_resolve_resource_reference(ctx, doc, dict, &clip_att, &clip_tag, NULL); xps_resolve_resource_reference(ctx, doc, dict, &opacity_mask_att, &opacity_mask_tag, &opacity_mask_uri); transform = fz_identity; if (transform_att) xps_parse_render_transform(ctx, doc, transform_att, &transform); if (transform_tag) xps_parse_matrix_transform(ctx, doc, transform_tag, &transform); fz_concat(&transform, &transform, ctm); if (navigate_uri_att) xps_add_link(ctx, doc, area, base_uri, navigate_uri_att); if (clip_att || clip_tag) xps_clip(ctx, doc, &transform, dict, clip_att, clip_tag); xps_begin_opacity(ctx, doc, &transform, area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); for (node = fz_xml_down(root); node; node = fz_xml_next(node)) { xps_parse_element(ctx, doc, &transform, area, base_uri, dict, node); } xps_end_opacity(ctx, doc, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); if (clip_att || clip_tag) fz_pop_clip(ctx, dev); if (new_dict) xps_drop_resource_dictionary(ctx, doc, new_dict); }