summaryrefslogtreecommitdiff
path: root/source/xps/xps-glyphs.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-glyphs.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-glyphs.c')
-rw-r--r--source/xps/xps-glyphs.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/source/xps/xps-glyphs.c b/source/xps/xps-glyphs.c
index 31da84fd..1effccc2 100644
--- a/source/xps/xps-glyphs.c
+++ b/source/xps/xps-glyphs.c
@@ -344,7 +344,7 @@ xps_parse_glyph_metrics(char *s, float *advance, float *uofs, float *vofs, int b
* Calculate metrics for positioning.
*/
fz_text *
-xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
+xps_parse_glyphs_imp(fz_context *ctx, 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)
@@ -369,11 +369,9 @@ xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
}
if (is_sideways)
- {
- fz_pre_scale(fz_rotate(&tm, 90), -size, size);
- }
+ tm = fz_pre_scale(fz_rotate(90), -size, size);
else
- fz_scale(&tm, size, -size);
+ tm = fz_scale(size, -size);
text = fz_new_text(ctx);
@@ -454,7 +452,7 @@ xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
}
dir = bidi_level & 1 ? FZ_BIDI_RTL : FZ_BIDI_LTR;
- fz_show_glyph(ctx, text, font, &tm, glyph_index, char_code, is_sideways, bidi_level, dir, FZ_LANG_UNSET);
+ fz_show_glyph(ctx, text, font, tm, glyph_index, char_code, is_sideways, bidi_level, dir, FZ_LANG_UNSET);
x += advance * 0.01f * size;
}
@@ -464,7 +462,7 @@ xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
}
void
-xps_parse_glyphs(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
+xps_parse_glyphs(fz_context *ctx, xps_document *doc, fz_matrix ctm,
char *base_uri, xps_resource *dict, fz_xml *root)
{
fz_device *dev = doc->dev;
@@ -505,8 +503,6 @@ xps_parse_glyphs(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
fz_text *text;
fz_rect area;
- fz_matrix local_ctm;
-
/*
* Extract attributes and extended attributes.
*/
@@ -576,20 +572,20 @@ xps_parse_glyphs(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
* Set up graphics state.
*/
- xps_parse_transform(ctx, doc, transform_att, transform_tag, &local_ctm, ctm);
+ ctm = xps_parse_transform(ctx, doc, transform_att, transform_tag, ctm);
if (clip_att || clip_tag)
- xps_clip(ctx, doc, &local_ctm, dict, clip_att, clip_tag);
+ xps_clip(ctx, doc, ctm, dict, clip_att, clip_tag);
font_size = fz_atof(font_size_att);
- text = xps_parse_glyphs_imp(ctx, doc, &local_ctm, font, font_size,
+ text = xps_parse_glyphs_imp(ctx, doc, ctm, font, font_size,
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);
- xps_begin_opacity(ctx, doc, &local_ctm, &area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag);
+ xps_begin_opacity(ctx, 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 */
@@ -610,7 +606,7 @@ xps_parse_glyphs(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
samples[0] *= fz_atof(fill_opacity_att);
xps_set_color(ctx, doc, colorspace, samples);
- fz_fill_text(ctx, dev, text, &local_ctm,
+ fz_fill_text(ctx, dev, text, &ctm,
doc->colorspace, doc->color, doc->alpha, NULL);
}
@@ -618,8 +614,8 @@ xps_parse_glyphs(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
if (fill_tag)
{
- fz_clip_text(ctx, dev, text, &local_ctm, &area);
- xps_parse_brush(ctx, doc, &local_ctm, &area, fill_uri, dict, fill_tag);
+ fz_clip_text(ctx, dev, text, &ctm, &area);
+ xps_parse_brush(ctx, doc, ctm, area, fill_uri, dict, fill_tag);
fz_pop_clip(ctx, dev);
}