summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-xobject.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/pdf/pdf-xobject.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/pdf/pdf-xobject.c')
-rw-r--r--source/pdf/pdf-xobject.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/source/pdf/pdf-xobject.c b/source/pdf/pdf-xobject.c
index 871f001a..2cfe1f8f 100644
--- a/source/pdf/pdf-xobject.c
+++ b/source/pdf/pdf-xobject.c
@@ -7,16 +7,16 @@ pdf_xobject_resources(fz_context *ctx, pdf_obj *xobj)
return pdf_dict_get(ctx, xobj, PDF_NAME(Resources));
}
-fz_rect *
-pdf_xobject_bbox(fz_context *ctx, pdf_obj *xobj, fz_rect *bbox)
+fz_rect
+pdf_xobject_bbox(fz_context *ctx, pdf_obj *xobj)
{
- return pdf_to_rect(ctx, pdf_dict_get(ctx, xobj, PDF_NAME(BBox)), bbox);
+ return pdf_to_rect(ctx, pdf_dict_get(ctx, xobj, PDF_NAME(BBox)));
}
-fz_matrix *
-pdf_xobject_matrix(fz_context *ctx, pdf_obj *xobj, fz_matrix *matrix)
+fz_matrix
+pdf_xobject_matrix(fz_context *ctx, pdf_obj *xobj)
{
- return pdf_to_matrix(ctx, pdf_dict_get(ctx, xobj, PDF_NAME(Matrix)), matrix);
+ return pdf_to_matrix(ctx, pdf_dict_get(ctx, xobj, PDF_NAME(Matrix)));
}
int pdf_xobject_isolated(fz_context *ctx, pdf_obj *xobj)
@@ -65,7 +65,7 @@ pdf_xobject_colorspace(fz_context *ctx, pdf_obj *xobj)
}
pdf_obj *
-pdf_new_xobject(fz_context *ctx, pdf_document *doc, const fz_rect *bbox, const fz_matrix *mat, pdf_obj *res, fz_buffer *contents)
+pdf_new_xobject(fz_context *ctx, pdf_document *doc, fz_rect bbox, fz_matrix matrix, pdf_obj *res, fz_buffer *contents)
{
pdf_obj *ind = NULL;
pdf_obj *form = pdf_new_dict(ctx, doc, 5);
@@ -74,8 +74,7 @@ pdf_new_xobject(fz_context *ctx, pdf_document *doc, const fz_rect *bbox, const f
pdf_dict_put(ctx, form, PDF_NAME(Type), PDF_NAME(XObject));
pdf_dict_put(ctx, form, PDF_NAME(Subtype), PDF_NAME(Form));
pdf_dict_put_rect(ctx, form, PDF_NAME(BBox), bbox);
- if (mat)
- pdf_dict_put_matrix(ctx, form, PDF_NAME(Matrix), mat);
+ pdf_dict_put_matrix(ctx, form, PDF_NAME(Matrix), matrix);
if (res)
pdf_dict_put(ctx, form, PDF_NAME(Resources), res);
ind = pdf_add_stream(ctx, doc, contents, form, 0);
@@ -88,13 +87,10 @@ pdf_new_xobject(fz_context *ctx, pdf_document *doc, const fz_rect *bbox, const f
}
void
-pdf_update_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *form, const fz_rect *bbox, const fz_matrix *mat, pdf_obj *res, fz_buffer *contents)
+pdf_update_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *form, fz_rect bbox, fz_matrix matrix, pdf_obj *res, fz_buffer *contents)
{
pdf_dict_put_rect(ctx, form, PDF_NAME(BBox), bbox);
- if (mat)
- pdf_dict_put_matrix(ctx, form, PDF_NAME(Matrix), mat);
- else
- pdf_dict_del(ctx, form, PDF_NAME(Matrix));
+ pdf_dict_put_matrix(ctx, form, PDF_NAME(Matrix), matrix);
if (res)
pdf_dict_put(ctx, form, PDF_NAME(Resources), res);
else