diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-06-25 13:15:50 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-07-05 15:32:34 +0200 |
commit | 4a99615a609eec2b84bb2341d74fac46a5998137 (patch) | |
tree | 486eacff07448e4c655df1fa1bcb20df709dd8df /source/html/epub-doc.c | |
parent | 2aa62902447760764e7a763dea322145d9c4808c (diff) | |
download | mupdf-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/html/epub-doc.c')
-rw-r--r-- | source/html/epub-doc.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index deb45f92..5325c316 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -121,31 +121,31 @@ epub_drop_page(fz_context *ctx, fz_page *page_) { } -static fz_rect * -epub_bound_page(fz_context *ctx, fz_page *page_, fz_rect *bbox) +static fz_rect +epub_bound_page(fz_context *ctx, fz_page *page_) { epub_page *page = (epub_page*)page_; epub_document *doc = page->doc; epub_chapter *ch; int n = page->number; int count = 0; + fz_rect bbox; for (ch = doc->spine; ch; ch = ch->next) { int cn = count_chapter_pages(ch); if (n < count + cn) { - bbox->x0 = 0; - bbox->y0 = 0; - bbox->x1 = ch->html->page_w + ch->html->page_margin[L] + ch->html->page_margin[R]; - bbox->y1 = ch->html->page_h + ch->html->page_margin[T] + ch->html->page_margin[B]; + bbox.x0 = 0; + bbox.y0 = 0; + bbox.x1 = ch->html->page_w + ch->html->page_margin[L] + ch->html->page_margin[R]; + bbox.y1 = ch->html->page_h + ch->html->page_margin[T] + ch->html->page_margin[B]; return bbox; } count += cn; } - *bbox = fz_unit_rect; - return bbox; + return fz_unit_rect; } static void @@ -162,7 +162,7 @@ epub_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix * int cn = count_chapter_pages(ch); if (n < count + cn) { - fz_draw_html(ctx, dev, ctm, ch->html, n-count); + fz_draw_html(ctx, dev, *ctm, ch->html, n-count); break; } count += cn; |