summaryrefslogtreecommitdiff
path: root/source/xps/xps-common.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-common.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-common.c')
-rw-r--r--source/xps/xps-common.c58
1 files changed, 29 insertions, 29 deletions
diff --git a/source/xps/xps-common.c b/source/xps/xps-common.c
index f2f9b93c..75baa2bf 100644
--- a/source/xps/xps-common.c
+++ b/source/xps/xps-common.c
@@ -33,7 +33,7 @@ xps_lookup_alternate_content(fz_context *ctx, xps_document *doc, fz_xml *node)
}
void
-xps_parse_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node)
+xps_parse_brush(fz_context *ctx, 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;
@@ -51,7 +51,7 @@ xps_parse_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const
}
void
-xps_parse_element(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node)
+xps_parse_element(fz_context *ctx, 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;
@@ -71,7 +71,7 @@ xps_parse_element(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, cons
}
void
-xps_begin_opacity(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
+xps_begin_opacity(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area,
char *base_uri, xps_resource *dict,
char *opacity_att, fz_xml *opacity_mask_tag)
{
@@ -109,7 +109,7 @@ xps_begin_opacity(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, cons
if (opacity_mask_tag)
{
- fz_begin_mask(ctx, dev, area, 0, NULL, NULL, NULL);
+ fz_begin_mask(ctx, dev, &area, 0, NULL, NULL, NULL);
xps_parse_brush(ctx, doc, ctm, area, base_uri, dict, opacity_mask_tag);
fz_end_mask(ctx, dev);
}
@@ -134,9 +134,10 @@ xps_end_opacity(fz_context *ctx, xps_document *doc, char *base_uri, xps_resource
}
}
-static void
-xps_parse_render_transform(fz_context *ctx, xps_document *doc, char *transform, fz_matrix *matrix)
+static fz_matrix
+xps_parse_render_transform(fz_context *ctx, xps_document *doc, char *transform)
{
+ fz_matrix matrix;
float args[6];
char *s = transform;
int i;
@@ -154,40 +155,38 @@ xps_parse_render_transform(fz_context *ctx, xps_document *doc, char *transform,
s++;
}
- matrix->a = args[0]; matrix->b = args[1];
- matrix->c = args[2]; matrix->d = args[3];
- matrix->e = args[4]; matrix->f = args[5];
+ matrix.a = args[0]; matrix.b = args[1];
+ matrix.c = args[2]; matrix.d = args[3];
+ matrix.e = args[4]; matrix.f = args[5];
+ return matrix;
}
-static void
-xps_parse_matrix_transform(fz_context *ctx, xps_document *doc, fz_xml *root, fz_matrix *matrix)
+static fz_matrix
+xps_parse_matrix_transform(fz_context *ctx, xps_document *doc, fz_xml *root)
{
- char *transform;
-
- *matrix = fz_identity;
-
if (fz_xml_is_tag(root, "MatrixTransform"))
{
- transform = fz_xml_att(root, "Matrix");
+ char *transform = fz_xml_att(root, "Matrix");
if (transform)
- xps_parse_render_transform(ctx, doc, transform, matrix);
+ return xps_parse_render_transform(ctx, doc, transform);
}
+ return fz_identity;
}
-void
-xps_parse_transform(fz_context *ctx, xps_document *doc, char *att, fz_xml *tag, fz_matrix *transform, const fz_matrix *ctm)
+fz_matrix
+xps_parse_transform(fz_context *ctx, xps_document *doc, char *att, fz_xml *tag, fz_matrix ctm)
{
- *transform = fz_identity;
if (att)
- xps_parse_render_transform(ctx, doc, att, transform);
+ return fz_concat(xps_parse_render_transform(ctx, doc, att), ctm);
if (tag)
- xps_parse_matrix_transform(ctx, doc, tag, transform);
- fz_concat(transform, transform, ctm);
+ return fz_concat(xps_parse_matrix_transform(ctx, doc, tag), ctm);
+ return ctm;
}
-void
-xps_parse_rectangle(fz_context *ctx, xps_document *doc, char *text, fz_rect *rect)
+fz_rect
+xps_parse_rectangle(fz_context *ctx, xps_document *doc, char *text)
{
+ fz_rect rect;
float args[4];
char *s = text;
int i;
@@ -204,10 +203,11 @@ xps_parse_rectangle(fz_context *ctx, xps_document *doc, char *text, fz_rect *rec
s++;
}
- rect->x0 = args[0];
- rect->y0 = args[1];
- rect->x1 = args[0] + args[2];
- rect->y1 = args[1] + args[3];
+ rect.x0 = args[0];
+ rect.y0 = args[1];
+ rect.x1 = args[0] + args[2];
+ rect.y1 = args[1] + args[3];
+ return rect;
}
static int count_commas(char *s)