summaryrefslogtreecommitdiff
path: root/source/xps/xps-link.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-06-25 13:15:50 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-07-05 15:32:34 +0200
commit4a99615a609eec2b84bb2341d74fac46a5998137 (patch)
tree486eacff07448e4c655df1fa1bcb20df709dd8df /source/xps/xps-link.c
parent2aa62902447760764e7a763dea322145d9c4808c (diff)
downloadmupdf-4a99615a609eec2b84bb2341d74fac46a5998137.tar.xz
Pass rect and matrix by value in geometry functions.
Several things irk me about passing values as const pointers: * They can be NULL, which is not a valid value. * They require explicit temporary variables for storage. * They don't compose easily in a legible manner, requiring weird pointer passing semantics where the variable being assigned is hidden as an argument in the innermost function call. * We can't change the value through the pointer, requiring yet more local variables to hold copies of the input value. In the device interface where we pass a matrix to a function, we often find ourselves making a local copy of the matrix so we can concatenate other transforms to it. This copying is a lot of unnecessary busywork that I hope to eventually avoid by laying the groundwork with this commit. This is a rather large API change, so I apologize for the inconvenience, but I hope the end result and gain in legibility will be worth the pain.
Diffstat (limited to 'source/xps/xps-link.c')
-rw-r--r--source/xps/xps-link.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/source/xps/xps-link.c b/source/xps/xps-link.c
index 59b4d1a5..9da2e5e2 100644
--- a/source/xps/xps-link.c
+++ b/source/xps/xps-link.c
@@ -7,11 +7,11 @@
/* Quick parsing of document to find links. */
static void
-xps_load_links_in_element(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
+xps_load_links_in_element(fz_context *ctx, xps_document *doc, fz_matrix ctm,
char *base_uri, xps_resource *dict, fz_xml *node, fz_link **link);
static void
-xps_add_link(fz_context *ctx, xps_document *doc, const fz_rect *area, char *base_uri, char *target_uri, fz_link **head)
+xps_add_link(fz_context *ctx, xps_document *doc, fz_rect area, char *base_uri, char *target_uri, fz_link **head)
{
fz_link *link = fz_new_link(ctx, area, doc, target_uri);
link->next = *head;
@@ -19,7 +19,7 @@ xps_add_link(fz_context *ctx, xps_document *doc, const fz_rect *area, char *base
}
static void
-xps_load_links_in_path(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
+xps_load_links_in_path(fz_context *ctx, xps_document *doc, fz_matrix ctm,
char *base_uri, xps_resource *dict, fz_xml *root, fz_link **link)
{
char *navigate_uri_att = fz_xml_att(root, "FixedPage.NavigateUri");
@@ -33,13 +33,12 @@ xps_load_links_in_path(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
fz_path *path = NULL;
int fill_rule;
- fz_matrix local_ctm;
fz_rect area;
xps_resolve_resource_reference(ctx, doc, dict, &data_att, &data_tag, NULL);
xps_resolve_resource_reference(ctx, doc, dict, &transform_att, &transform_tag, NULL);
- xps_parse_transform(ctx, doc, transform_att, transform_tag, &local_ctm, ctm);
+ ctm = xps_parse_transform(ctx, doc, transform_att, transform_tag, ctm);
if (data_att)
path = xps_parse_abbreviated_geometry(ctx, doc, data_att, &fill_rule);
@@ -47,15 +46,15 @@ xps_load_links_in_path(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
path = xps_parse_path_geometry(ctx, doc, dict, data_tag, 0, &fill_rule);
if (path)
{
- fz_bound_path(ctx, path, NULL, &local_ctm, &area);
+ area = fz_bound_path(ctx, path, NULL, ctm);
fz_drop_path(ctx, path);
- xps_add_link(ctx, doc, &area, base_uri, navigate_uri_att, link);
+ xps_add_link(ctx, doc, area, base_uri, navigate_uri_att, link);
}
}
}
static void
-xps_load_links_in_glyphs(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
+xps_load_links_in_glyphs(fz_context *ctx, xps_document *doc, fz_matrix ctm,
char *base_uri, xps_resource *dict, fz_xml *root, fz_link **link)
{
char *navigate_uri_att = fz_xml_att(root, "FixedPage.NavigateUri");
@@ -76,14 +75,13 @@ xps_load_links_in_glyphs(fz_context *ctx, xps_document *doc, const fz_matrix *ct
int is_sideways = 0;
int bidi_level = 0;
- fz_matrix local_ctm;
fz_font *font;
fz_text *text;
fz_rect area;
xps_resolve_resource_reference(ctx, doc, dict, &transform_att, &transform_tag, NULL);
- xps_parse_transform(ctx, doc, transform_att, transform_tag, &local_ctm, ctm);
+ ctm = xps_parse_transform(ctx, doc, transform_att, transform_tag, ctm);
if (is_sideways_att)
is_sideways = !strcmp(is_sideways_att, "true");
@@ -93,23 +91,22 @@ xps_load_links_in_glyphs(fz_context *ctx, xps_document *doc, const fz_matrix *ct
font = xps_lookup_font(ctx, doc, base_uri, font_uri_att, style_att);
if (!font)
return;
- text = xps_parse_glyphs_imp(ctx, doc, &local_ctm, font, fz_atof(font_size_att),
+ text = xps_parse_glyphs_imp(ctx, doc, ctm, font, fz_atof(font_size_att),
fz_atof(origin_x_att), fz_atof(origin_y_att),
is_sideways, bidi_level, indices_att, unicode_att);
- fz_bound_text(ctx, text, NULL, &local_ctm, &area);
+ area = fz_bound_text(ctx, text, NULL, ctm);
fz_drop_text(ctx, text);
fz_drop_font(ctx, font);
- xps_add_link(ctx, doc, &area, base_uri, navigate_uri_att, link);
+ xps_add_link(ctx, doc, area, base_uri, navigate_uri_att, link);
}
}
static void
-xps_load_links_in_canvas(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
+xps_load_links_in_canvas(fz_context *ctx, xps_document *doc, 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");
@@ -129,20 +126,20 @@ xps_load_links_in_canvas(fz_context *ctx, xps_document *doc, const fz_matrix *ct
xps_resolve_resource_reference(ctx, doc, dict, &transform_att, &transform_tag, NULL);
- xps_parse_transform(ctx, doc, transform_att, transform_tag, &local_ctm, ctm);
+ ctm = xps_parse_transform(ctx, doc, transform_att, transform_tag, 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);
+ xps_load_links_in_element(ctx, doc, ctm, base_uri, dict, node, link);
if (new_dict)
xps_drop_resource_dictionary(ctx, doc, new_dict);
}
static void
-xps_load_links_in_element(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_resource *dict, fz_xml *node, fz_link **link)
+xps_load_links_in_element(fz_context *ctx, xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node, fz_link **link)
{
if (fz_xml_is_tag(node, "Path"))
xps_load_links_in_path(ctx, doc, ctm, base_uri, dict, node, link);
@@ -159,7 +156,7 @@ xps_load_links_in_element(fz_context *ctx, xps_document *doc, const fz_matrix *c
}
static void
-xps_load_links_in_fixed_page(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, xps_page *page, fz_link **link)
+xps_load_links_in_fixed_page(fz_context *ctx, xps_document *doc, fz_matrix ctm, xps_page *page, fz_link **link)
{
fz_xml *root, *node, *resource_tag;
xps_resource *dict = NULL;
@@ -193,7 +190,7 @@ xps_load_links(fz_context *ctx, fz_page *page_)
xps_page *page = (xps_page*)page_;
fz_matrix ctm;
fz_link *link = NULL;
- fz_scale(&ctm, 72.0f / 96.0f, 72.0f / 96.0f);
- xps_load_links_in_fixed_page(ctx, page->doc, &ctm, page, &link);
+ ctm = fz_scale(72.0f / 96.0f, 72.0f / 96.0f);
+ xps_load_links_in_fixed_page(ctx, page->doc, ctm, page, &link);
return link;
}