summaryrefslogtreecommitdiff
path: root/source/tools
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/tools
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/tools')
-rw-r--r--source/tools/muconvert.c2
-rw-r--r--source/tools/mudraw.c41
-rw-r--r--source/tools/murun.c22
-rw-r--r--source/tools/mutrace.c2
-rw-r--r--source/tools/pdfcreate.c2
-rw-r--r--source/tools/pdfinfo.c2
-rw-r--r--source/tools/pdfpages.c2
-rw-r--r--source/tools/pdfportfolio.c2
8 files changed, 36 insertions, 39 deletions
diff --git a/source/tools/muconvert.c b/source/tools/muconvert.c
index e2a51c6e..ed4b4615 100644
--- a/source/tools/muconvert.c
+++ b/source/tools/muconvert.c
@@ -75,7 +75,7 @@ static void runpage(int number)
fz_try(ctx)
{
- fz_bound_page(ctx, page, &mediabox);
+ mediabox = fz_bound_page(ctx, page);
dev = fz_begin_page(ctx, out, &mediabox);
fz_run_page(ctx, page, dev, &fz_identity, NULL);
}
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index 0649bae0..2e1e759d 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -517,9 +517,9 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
fz_try(ctx)
{
if (list)
- fz_bound_display_list(ctx, list, &mediabox);
+ mediabox = fz_bound_display_list(ctx, list);
else
- fz_bound_page(ctx, page, &mediabox);
+ mediabox = fz_bound_page(ctx, page);
}
fz_catch(ctx)
{
@@ -564,7 +564,7 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
fz_matrix ctm;
zoom = resolution / 72;
- fz_pre_scale(fz_rotate(&ctm, rotation), zoom, zoom);
+ ctm = fz_pre_scale(fz_rotate(rotation), zoom, zoom);
fz_var(text);
@@ -573,7 +573,7 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
fz_stext_options stext_options;
stext_options.flags = (output_format == OUT_HTML || output_format == OUT_XHTML) ? FZ_STEXT_PRESERVE_IMAGES : 0;
- text = fz_new_stext_page(ctx, &mediabox);
+ text = fz_new_stext_page(ctx, mediabox);
dev = fz_new_stext_device(ctx, text, &stext_options);
if (lowmemory)
fz_enable_device_hints(ctx, dev, FZ_NO_CACHE);
@@ -638,7 +638,7 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
fz_drop_device(ctx, dev);
dev = NULL;
- page_obj = pdf_add_page(ctx, pdfout, &mediabox, rotation, resources, contents);
+ page_obj = pdf_add_page(ctx, pdfout, mediabox, rotation, resources, contents);
pdf_insert_page(ctx, pdfout, -1, page_obj);
pdf_drop_obj(ctx, page_obj);
}
@@ -669,9 +669,8 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
fz_var(out);
zoom = resolution / 72;
- fz_pre_rotate(fz_scale(&ctm, zoom, zoom), rotation);
- tbounds = mediabox;
- fz_transform_rect(&tbounds, &ctm);
+ ctm = fz_pre_rotate(fz_scale(zoom, zoom), rotation);
+ tbounds = fz_transform_rect(mediabox, ctm);
fz_try(ctx)
{
@@ -721,15 +720,15 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
fz_var(bit);
zoom = resolution / 72;
- fz_pre_scale(fz_rotate(&ctm, rotation), zoom, zoom);
+ ctm = fz_pre_scale(fz_rotate(rotation), zoom, zoom);
if (output_format == OUT_TGA)
{
- fz_pre_scale(fz_pre_translate(&ctm, 0, -height), 1, -1);
+ ctm = fz_pre_scale(fz_pre_translate(ctm, 0, -height), 1, -1);
}
- tbounds = mediabox;
- fz_round_rect(&ibounds, fz_transform_rect(&tbounds, &ctm));
+ tbounds = fz_transform_rect(mediabox, ctm);
+ ibounds = fz_round_rect(tbounds);
/* Make local copies of our width/height */
w = width;
@@ -776,13 +775,12 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
else
scaley = scalex;
}
- fz_scale(&scale_mat, scalex, scaley);
- fz_concat(&ctm, &ctm, &scale_mat);
- tbounds = mediabox;
- fz_transform_rect(&tbounds, &ctm);
+ scale_mat = fz_scale(scalex, scaley);
+ ctm = fz_concat(ctm, scale_mat);
+ tbounds = fz_transform_rect(mediabox, ctm);
}
- fz_round_rect(&ibounds, &tbounds);
- fz_rect_from_irect(&tbounds, &ibounds);
+ ibounds = fz_round_rect(tbounds);
+ tbounds = fz_rect_from_irect(ibounds);
fz_try(ctx)
{
@@ -812,7 +810,7 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
workers[band].tbounds = tbounds;
memset(&workers[band].cookie, 0, sizeof(fz_cookie));
workers[band].list = list;
- workers[band].pix = fz_new_pixmap_with_bbox(ctx, colorspace, &band_ibounds, seps, alpha);
+ workers[band].pix = fz_new_pixmap_with_bbox(ctx, colorspace, band_ibounds, seps, alpha);
fz_set_pixmap_resolution(ctx, workers[band].pix, resolution, resolution);
#ifndef DISABLE_MUTHREADS
DEBUG_THREADS(("Worker %d, Pre-triggering band %d\n", band, band));
@@ -824,7 +822,7 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
}
else
{
- pix = fz_new_pixmap_with_bbox(ctx, colorspace, &band_ibounds, seps, alpha);
+ pix = fz_new_pixmap_with_bbox(ctx, colorspace, band_ibounds, seps, alpha);
fz_set_pixmap_resolution(ctx, pix, resolution, resolution);
}
@@ -1030,7 +1028,6 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
fz_device *dev = NULL;
int start;
fz_cookie cookie = { 0 };
- fz_rect bounds;
fz_separations *seps = NULL;
fz_var(list);
@@ -1082,7 +1079,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
{
fz_try(ctx)
{
- list = fz_new_display_list(ctx, fz_bound_page(ctx, page, &bounds));
+ list = fz_new_display_list(ctx, fz_bound_page(ctx, page));
dev = fz_new_list_device(ctx, list);
if (lowmemory)
fz_enable_device_hints(ctx, dev, FZ_NO_CACHE);
diff --git a/source/tools/murun.c b/source/tools/murun.c
index 10d76e8b..a4e88ea2 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -1829,7 +1829,7 @@ static void ffi_Page_bound(js_State *J)
fz_rect bounds;
fz_try(ctx)
- fz_bound_page(ctx, page, &bounds);
+ bounds = fz_bound_page(ctx, page);
fz_catch(ctx)
rethrow(J);
@@ -2017,7 +2017,7 @@ static void ffi_Annotation_bound(js_State *J)
fz_rect bounds;
fz_try(ctx)
- fz_bound_annot(ctx, annot, &bounds);
+ bounds = fz_bound_annot(ctx, annot);
fz_catch(ctx)
rethrow(J);
@@ -2107,7 +2107,7 @@ static void ffi_new_Pixmap(js_State *J)
fz_pixmap *pixmap = NULL;
fz_try(ctx)
- pixmap = fz_new_pixmap_with_bbox(ctx, colorspace, &bounds, 0, alpha);
+ pixmap = fz_new_pixmap_with_bbox(ctx, colorspace, bounds, 0, alpha);
fz_catch(ctx)
rethrow(J);
@@ -2339,7 +2339,7 @@ static void ffi_Shade_bound(js_State *J)
fz_rect bounds;
fz_try(ctx)
- fz_bound_shade(ctx, shade, &ctm, &bounds);
+ bounds = fz_bound_shade(ctx, shade, ctm);
fz_catch(ctx)
rethrow(J);
@@ -2459,7 +2459,7 @@ static void ffi_Text_showGlyph(js_State *J)
int wmode = js_isdefined(J, 5) ? js_toboolean(J, 5) : 0;
fz_try(ctx)
- fz_show_glyph(ctx, text, font, &trm, glyph, unicode, wmode, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET);
+ fz_show_glyph(ctx, text, font, trm, glyph, unicode, wmode, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET);
fz_catch(ctx)
rethrow(J);
}
@@ -2687,7 +2687,7 @@ static void ffi_Path_bound(js_State *J)
fz_rect bounds;
fz_try(ctx)
- fz_bound_path(ctx, path, &stroke, &ctm, &bounds);
+ bounds = fz_bound_path(ctx, path, &stroke, ctm);
fz_catch(ctx)
rethrow(J);
@@ -2701,7 +2701,7 @@ static void ffi_Path_transform(js_State *J)
fz_matrix ctm = ffi_tomatrix(J, 1);
fz_try(ctx)
- fz_transform_path(ctx, path, &ctm);
+ fz_transform_path(ctx, path, ctm);
fz_catch(ctx)
rethrow(J);
}
@@ -2713,7 +2713,7 @@ static void ffi_new_DisplayList(js_State *J)
fz_display_list *list = NULL;
fz_try(ctx)
- list = fz_new_display_list(ctx, &mediabox);
+ list = fz_new_display_list(ctx, mediabox);
fz_catch(ctx)
rethrow(J);
@@ -3354,7 +3354,7 @@ static void ffi_PDFDocument_addPage(js_State *J)
pdf_obj *ind = NULL;
fz_try(ctx)
- ind = pdf_add_page(ctx, pdf, &mediabox, rotate, resources, contents);
+ ind = pdf_add_page(ctx, pdf, mediabox, rotate, resources, contents);
fz_always(ctx) {
fz_drop_buffer(ctx, contents);
pdf_drop_obj(ctx, resources);
@@ -4110,7 +4110,7 @@ static void ffi_PDFAnnotation_getRect(js_State *J)
pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
fz_rect rect;
fz_try(ctx)
- pdf_annot_rect(ctx, annot, &rect);
+ rect = pdf_annot_rect(ctx, annot);
fz_catch(ctx)
rethrow(J);
ffi_pushrect(J, rect);
@@ -4122,7 +4122,7 @@ static void ffi_PDFAnnotation_setRect(js_State *J)
pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
fz_rect rect = ffi_torect(J, 1);
fz_try(ctx)
- pdf_set_annot_rect(ctx, annot, &rect);
+ pdf_set_annot_rect(ctx, annot, rect);
fz_catch(ctx)
rethrow(J);
}
diff --git a/source/tools/mutrace.c b/source/tools/mutrace.c
index 2baef7d1..350de919 100644
--- a/source/tools/mutrace.c
+++ b/source/tools/mutrace.c
@@ -44,7 +44,7 @@ static void runpage(fz_context *ctx, fz_document *doc, int number)
fz_try(ctx)
{
page = fz_load_page(ctx, doc, number - 1);
- fz_bound_page(ctx, page, &mediabox);
+ mediabox = fz_bound_page(ctx, page);
printf("<page number=\"%d\" mediabox=\"%g %g %g %g\">\n",
number, mediabox.x0, mediabox.y0, mediabox.x1, mediabox.y1);
dev = fz_new_trace_device(ctx, fz_stdout(ctx));
diff --git a/source/tools/pdfcreate.c b/source/tools/pdfcreate.c
index a8502fdc..52d16dbe 100644
--- a/source/tools/pdfcreate.c
+++ b/source/tools/pdfcreate.c
@@ -207,7 +207,7 @@ static void create_page(char *input)
}
fz_drop_stream(ctx, stm);
- page = pdf_add_page(ctx, doc, &mediabox, rotate, resources, contents);
+ page = pdf_add_page(ctx, doc, mediabox, rotate, resources, contents);
pdf_insert_page(ctx, doc, -1, page);
pdf_drop_obj(ctx, page);
diff --git a/source/tools/pdfinfo.c b/source/tools/pdfinfo.c
index 65178561..4a726bfe 100644
--- a/source/tools/pdfinfo.c
+++ b/source/tools/pdfinfo.c
@@ -213,7 +213,7 @@ gatherdimensions(fz_context *ctx, globals *glo, int page, pdf_obj *pageref)
if (!pdf_is_array(ctx, obj))
return;
- pdf_to_rect(ctx, obj, &bbox);
+ bbox = pdf_to_rect(ctx, obj);
obj = pdf_dict_get(ctx, pageref, PDF_NAME(UserUnit));
if (pdf_is_real(ctx, obj))
diff --git a/source/tools/pdfpages.c b/source/tools/pdfpages.c
index cf5a8bf2..fa13e91e 100644
--- a/source/tools/pdfpages.c
+++ b/source/tools/pdfpages.c
@@ -33,7 +33,7 @@ showbox(fz_context *ctx, fz_output *out, pdf_obj *page, char *text, pdf_obj *nam
if (!pdf_is_array(ctx, obj))
break;
- pdf_to_rect(ctx, obj, &bbox);
+ bbox = pdf_to_rect(ctx, obj);
fz_write_printf(ctx, out, "<%s l=\"%g\" b=\"%g\" r=\"%g\" t=\"%g\" />\n", text, bbox.x0, bbox.y0, bbox.x1, bbox.y1);
}
diff --git a/source/tools/pdfportfolio.c b/source/tools/pdfportfolio.c
index a5830149..beeeaf23 100644
--- a/source/tools/pdfportfolio.c
+++ b/source/tools/pdfportfolio.c
@@ -263,7 +263,7 @@ int pdfportfolio_main(int argc, char **argv)
contents = fz_new_buffer_from_shared_data(ctx, (const unsigned char *)template, strlen(template));
- page_obj = pdf_add_page(ctx, doc, &mediabox, 0, resources, contents);
+ page_obj = pdf_add_page(ctx, doc, mediabox, 0, resources, contents);
pdf_insert_page(ctx, doc, -1, page_obj);
pdf_drop_obj(ctx, page_obj);
pdf_drop_obj(ctx, resources);