From 4a99615a609eec2b84bb2341d74fac46a5998137 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 25 Jun 2018 13:15:50 +0200 Subject: 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. --- source/pdf/pdf-run.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/pdf/pdf-run.c') diff --git a/source/pdf/pdf-run.c b/source/pdf/pdf-run.c index 2cc56edb..15339373 100644 --- a/source/pdf/pdf-run.c +++ b/source/pdf/pdf-run.c @@ -16,7 +16,7 @@ pdf_run_annot_with_usage(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf fz_set_default_colorspaces(ctx, dev, default_cs); pdf_page_transform(ctx, page, &mediabox, &page_ctm); - fz_concat(&local_ctm, &page_ctm, ctm); + local_ctm = fz_concat(page_ctm, *ctm); fz_try(ctx) { @@ -54,12 +54,12 @@ pdf_run_page_contents_with_usage(fz_context *ctx, pdf_document *doc, pdf_page *p fz_try(ctx) { pdf_page_transform(ctx, page, &mediabox, &page_ctm); - fz_concat(&local_ctm, &page_ctm, ctm); + local_ctm = fz_concat(page_ctm, *ctm); + mediabox = fz_transform_rect(mediabox, local_ctm); resources = pdf_page_resources(ctx, page); contents = pdf_page_contents(ctx, page); - if (page->transparency) { pdf_obj *group = pdf_page_group(ctx, page); @@ -78,7 +78,7 @@ pdf_run_page_contents_with_usage(fz_context *ctx, pdf_document *doc, pdf_page *p else colorspace = fz_keep_colorspace(ctx, fz_default_output_intent(ctx, default_cs)); - fz_begin_group(ctx, dev, fz_transform_rect(&mediabox, &local_ctm), colorspace, 1, 0, 0, 1); + fz_begin_group(ctx, dev, &mediabox, colorspace, 1, 0, 0, 1); fz_drop_colorspace(ctx, colorspace); colorspace = NULL; } -- cgit v1.2.3