From d5394cbcf3a98dcabc49264172d4ce6618535d91 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 28 Dec 2015 15:18:21 +0100 Subject: Remove fz_page argument from fz_annot function calls. --- source/fitz/document.c | 32 ++++++++++++++++++++------------ source/fitz/util.c | 6 +++--- source/pdf/pdf-annot.c | 13 +++++++++---- source/pdf/pdf-page.c | 3 --- source/pdf/pdf-run.c | 3 ++- 5 files changed, 34 insertions(+), 23 deletions(-) (limited to 'source') diff --git a/source/fitz/document.c b/source/fitz/document.c index 61d3091e..abcbfd9c 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -275,18 +275,18 @@ fz_first_annot(fz_context *ctx, fz_page *page) } fz_annot * -fz_next_annot(fz_context *ctx, fz_page *page, fz_annot *annot) +fz_next_annot(fz_context *ctx, fz_annot *annot) { - if (page && page->next_annot && annot) - return page->next_annot(ctx, page, annot); + if (annot && annot->next_annot) + return annot->next_annot(ctx, annot); return NULL; } fz_rect * -fz_bound_annot(fz_context *ctx, fz_page *page, fz_annot *annot, fz_rect *rect) +fz_bound_annot(fz_context *ctx, fz_annot *annot, fz_rect *rect) { - if (page && page->bound_annot && annot && rect) - return page->bound_annot(ctx, page, annot, rect); + if (annot && annot->bound_annot && rect) + return annot->bound_annot(ctx, annot, rect); if (rect) *rect = fz_empty_rect; return rect; @@ -310,13 +310,13 @@ fz_run_page_contents(fz_context *ctx, fz_page *page, fz_device *dev, const fz_ma } void -fz_run_annot(fz_context *ctx, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) +fz_run_annot(fz_context *ctx, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) { - if (page && page->run_annot && page && annot) + if (annot && annot->run_annot) { fz_try(ctx) { - page->run_annot(ctx, page, annot, dev, transform, cookie); + annot->run_annot(ctx, annot, dev, transform, cookie); } fz_catch(ctx) { @@ -340,12 +340,12 @@ fz_run_page(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *tra if (cookie && cookie->progress_max != -1) { int count = 1; - for (annot = fz_first_annot(ctx, page); annot; annot = fz_next_annot(ctx, page, annot)) + for (annot = fz_first_annot(ctx, page); annot; annot = fz_next_annot(ctx, annot)) count++; cookie->progress_max += count; } - for (annot = fz_first_annot(ctx, page); annot; annot = fz_next_annot(ctx, page, annot)) + for (annot = fz_first_annot(ctx, page); annot; annot = fz_next_annot(ctx, annot)) { /* Check the cookie for aborting */ if (cookie) @@ -355,12 +355,20 @@ fz_run_page(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *tra cookie->progress++; } - fz_run_annot(ctx, page, annot, dev, transform, cookie); + fz_run_annot(ctx, annot, dev, transform, cookie); } fz_end_page(ctx, dev); } +void * +fz_new_annot(fz_context *ctx, int size) +{ + fz_page *page = Memento_label(fz_calloc(ctx, 1, size), "fz_annot"); + page->refs = 1; + return page; +} + void * fz_new_page(fz_context *ctx, int size) { diff --git a/source/fitz/util.c b/source/fitz/util.c index 54e5754d..0d782ba8 100644 --- a/source/fitz/util.c +++ b/source/fitz/util.c @@ -112,14 +112,14 @@ fz_new_pixmap_from_page_contents(fz_context *ctx, fz_page *page, const fz_matrix } fz_pixmap * -fz_new_pixmap_from_annot(fz_context *ctx, fz_page *page, fz_annot *annot, const fz_matrix *ctm, fz_colorspace *cs) +fz_new_pixmap_from_annot(fz_context *ctx, fz_annot *annot, const fz_matrix *ctm, fz_colorspace *cs) { fz_rect rect; fz_irect irect; fz_pixmap *pix; fz_device *dev; - fz_bound_annot(ctx, page, annot, &rect); + fz_bound_annot(ctx, annot, &rect); fz_transform_rect(&rect, ctm); fz_round_rect(&irect, &rect); @@ -129,7 +129,7 @@ fz_new_pixmap_from_annot(fz_context *ctx, fz_page *page, fz_annot *annot, const fz_try(ctx) { dev = fz_new_draw_device(ctx, pix); - fz_run_annot(ctx, page, annot, dev, ctm, NULL); + fz_run_annot(ctx, annot, dev, ctm, NULL); } fz_always(ctx) { diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c index 3718c20a..bfdfe306 100644 --- a/source/pdf/pdf-annot.c +++ b/source/pdf/pdf-annot.c @@ -503,9 +503,14 @@ pdf_load_annots(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_obj *ann for (i = 0; i < len; i++) { obj = pdf_array_get(ctx, annots, i); - annot = fz_malloc_struct(ctx, pdf_annot); - annot->obj = pdf_keep_obj(ctx, obj); + + annot = fz_new_annot(ctx, sizeof(pdf_annot)); + annot->super.bound_annot = (fz_annot_bound_fn*)pdf_bound_annot; + annot->super.run_annot = (fz_annot_run_fn*)pdf_run_annot; + annot->super.next_annot = (fz_annot_next_fn*)pdf_next_annot; + annot->page = page; + annot->obj = pdf_keep_obj(ctx, obj); annot->next = NULL; *itr = annot; @@ -613,13 +618,13 @@ pdf_first_annot(fz_context *ctx, pdf_page *page) } pdf_annot * -pdf_next_annot(fz_context *ctx, pdf_page *page, pdf_annot *annot) +pdf_next_annot(fz_context *ctx, pdf_annot *annot) { return annot ? annot->next : NULL; } fz_rect * -pdf_bound_annot(fz_context *ctx, pdf_page *page, pdf_annot *annot, fz_rect *rect) +pdf_bound_annot(fz_context *ctx, pdf_annot *annot, fz_rect *rect) { if (rect == NULL) return NULL; diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index c7ef3422..d763b8c8 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -436,10 +436,7 @@ pdf_new_page(fz_context *ctx, pdf_document *doc) page->super.load_links = (fz_page_load_links_fn *)pdf_load_links; page->super.bound_page = (fz_page_bound_page_fn *)pdf_bound_page; page->super.first_annot = (fz_page_first_annot_fn *)pdf_first_annot; - page->super.next_annot = (fz_page_next_annot_fn *)pdf_next_annot; - page->super.bound_annot = (fz_page_bound_annot_fn *)pdf_bound_annot; page->super.run_page_contents = (fz_page_run_page_contents_fn *)pdf_run_page_contents; - page->super.run_annot = (fz_page_run_annot_fn *)pdf_run_annot; page->super.page_presentation = (fz_page_page_presentation_fn *)pdf_page_presentation; page->resources = NULL; diff --git a/source/pdf/pdf-run.c b/source/pdf/pdf-run.c index 65460e2a..e84604fb 100644 --- a/source/pdf/pdf-run.c +++ b/source/pdf/pdf-run.c @@ -69,8 +69,9 @@ void pdf_run_page_contents(fz_context *ctx, pdf_page *page, fz_device *dev, cons fz_throw(ctx, FZ_ERROR_TRYLATER, "incomplete rendering"); } -void pdf_run_annot(fz_context *ctx, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) +void pdf_run_annot(fz_context *ctx, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) { + pdf_page *page = annot->page; pdf_document *doc = page->doc; int nocache; -- cgit v1.2.3