diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2012-10-25 16:44:24 +0100 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2012-10-25 16:44:24 +0100 |
commit | d8266814d24f5bdf95b81e66e9b06a5d188b5edd (patch) | |
tree | 03282b583686917c348492d8584b0a134c01e753 /pdf | |
parent | c2a526b73e6654b99c66747a379a9218ab8683f4 (diff) | |
download | mupdf-d8266814d24f5bdf95b81e66e9b06a5d188b5edd.tar.xz |
Support separate rendering of the main page contents and the annotations
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/mupdf.h | 27 | ||||
-rw-r--r-- | pdf/pdf_interpret.c | 96 | ||||
-rw-r--r-- | pdf/pdf_xref.c | 3 | ||||
-rw-r--r-- | pdf/pdf_xref_aux.c | 15 |
4 files changed, 103 insertions, 38 deletions
diff --git a/pdf/mupdf.h b/pdf/mupdf.h index 1149d99a..5daba8da 100644 --- a/pdf/mupdf.h +++ b/pdf/mupdf.h @@ -274,6 +274,33 @@ void pdf_run_page(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix c void pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie); /* + pdf_run_page_contents: Interpret a loaded page and render it on a device. + Just the main page contents without the annotations + + page: A page loaded by pdf_load_page. + + dev: Device used for rendering, obtained from fz_new_*_device. + + ctm: A transformation matrix applied to the objects on the page, + e.g. to scale or rotate the page contents as desired. +*/ +void pdf_run_page_contents(pdf_document *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie); + +/* + pdf_run_annot: Interpret an annotation and render it on a device. + + page: A page loaded by pdf_load_page. + + annot: an annotation. + + dev: Device used for rendering, obtained from fz_new_*_device. + + ctm: A transformation matrix applied to the objects on the page, + e.g. to scale or rotate the page contents as desired. +*/ +void pdf_run_annot(pdf_document *xref, pdf_page *page, pdf_annot *annot, fz_device *dev, fz_matrix ctm, fz_cookie *cookie); + +/* Metadata interface. */ int pdf_meta(pdf_document *doc, int key, void *ptr, int size); diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index 7f99f5c0..9304d5b6 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -2788,13 +2788,10 @@ pdf_run_contents_buffer(pdf_csi *csi, pdf_obj *rdb, fz_buffer *contents) } } -void -pdf_run_page_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie) +static void pdf_run_page_contents_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie) { fz_context *ctx = dev->ctx; pdf_csi *csi; - pdf_annot *annot; - int flags; ctm = fz_concat(page->ctm, ctm); @@ -2815,6 +2812,61 @@ pdf_run_page_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, fz_m fz_throw(ctx, "cannot parse page content stream"); } + if (page->transparency) + fz_end_group(dev); +} + +void pdf_run_page_contents(pdf_document *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie) +{ + pdf_run_page_contents_with_usage(xref, page, dev, ctm, "View", cookie); +} + +static void pdf_run_annot_with_usage(pdf_document *xref, pdf_page *page, pdf_annot *annot, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie) +{ + fz_context *ctx = dev->ctx; + pdf_csi *csi; + int flags; + + ctm = fz_concat(page->ctm, ctm); + + flags = pdf_to_int(pdf_dict_gets(annot->obj, "F")); + + /* TODO: NoZoom and NoRotate */ + if (flags & (1 << 0)) /* Invisible */ + return; + if (flags & (1 << 1)) /* Hidden */ + return; + if (!strcmp(event, "Print") && !(flags & (1 << 2))) /* Print */ + return; + if (!strcmp(event, "View") && (flags & (1 << 5))) /* NoView */ + return; + + csi = pdf_new_csi(xref, dev, ctm, event, cookie, NULL); + if (!pdf_is_hidden_ocg(pdf_dict_gets(annot->obj, "OC"), csi, page->resources)) + { + fz_try(ctx) + { + pdf_update_annot(xref, annot); + pdf_run_xobject(csi, page->resources, annot->ap, annot->matrix); + } + fz_catch(ctx) + { + pdf_free_csi(csi); + fz_throw(ctx, "cannot parse annotation appearance stream"); + } + } + pdf_free_csi(csi); +} + +void pdf_run_annot(pdf_document *xref, pdf_page *page, pdf_annot *annot, fz_device *dev, fz_matrix ctm, fz_cookie *cookie) +{ + pdf_run_annot_with_usage(xref, page, annot, dev, ctm, "View", cookie); +} + +static void pdf_run_page_annots_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie) +{ + pdf_annot *annot; + if (cookie && cookie->progress_max != -1) { int count = 1; @@ -2833,37 +2885,15 @@ pdf_run_page_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, fz_m cookie->progress++; } - flags = pdf_to_int(pdf_dict_gets(annot->obj, "F")); - - /* TODO: NoZoom and NoRotate */ - if (flags & (1 << 0)) /* Invisible */ - continue; - if (flags & (1 << 1)) /* Hidden */ - continue; - if (!strcmp(event, "Print") && !(flags & (1 << 2))) /* Print */ - continue; - if (!strcmp(event, "View") && (flags & (1 << 5))) /* NoView */ - continue; - - csi = pdf_new_csi(xref, dev, ctm, event, cookie, NULL); - if (!pdf_is_hidden_ocg(pdf_dict_gets(annot->obj, "OC"), csi, page->resources)) - { - fz_try(ctx) - { - pdf_update_annot(xref, annot); - pdf_run_xobject(csi, page->resources, annot->ap, annot->matrix); - } - fz_catch(ctx) - { - pdf_free_csi(csi); - fz_throw(ctx, "cannot parse annotation appearance stream"); - } - } - pdf_free_csi(csi); + pdf_run_annot_with_usage(xref, page, annot, dev, ctm, event, cookie); } +} - if (page->transparency) - fz_end_group(dev); +void +pdf_run_page_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie) +{ + pdf_run_page_contents_with_usage(xref, page, dev, ctm, event, cookie); + pdf_run_page_annots_with_usage(xref, page, dev, ctm, event, cookie); } void diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index c78a9ec7..5182a263 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -1294,7 +1294,8 @@ pdf_new_document(fz_context *ctx, fz_stream *file) doc->super.first_annot = (void*)pdf_first_annot; doc->super.next_annot = (void*)pdf_next_annot; doc->super.bound_annot = (void*)pdf_bound_annot; - doc->super.run_page = NULL; /* see pdf_xref_aux.c */ + doc->super.run_page_contents = NULL; /* see pdf_xref_aux.c */ + doc->super.run_annot = NULL; /* see pdf_xref_aux.c */ doc->super.free_page = (void*)pdf_free_page; doc->super.meta = (void*)pdf_meta; doc->super.page_presentation = (void*)pdf_page_presentation; diff --git a/pdf/pdf_xref_aux.c b/pdf/pdf_xref_aux.c index bf2fe19b..22f21b1f 100644 --- a/pdf/pdf_xref_aux.c +++ b/pdf/pdf_xref_aux.c @@ -9,16 +9,22 @@ resulting executables. */ -static void pdf_run_page_shim(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie) +static void pdf_run_page_contents_shim(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie) { - pdf_run_page((pdf_document*)doc, (pdf_page*)page, dev, transform, cookie); + pdf_run_page_contents((pdf_document*)doc, (pdf_page*)page, dev, transform, cookie); +} + +static void pdf_run_annot_shim(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, fz_matrix transform, fz_cookie *cookie) +{ + pdf_run_annot((pdf_document*)doc, (pdf_page*)page, (pdf_annot *)annot, dev, transform, cookie); } pdf_document * pdf_open_document_with_stream(fz_context *ctx, fz_stream *file) { pdf_document *doc = pdf_open_document_no_run_with_stream(ctx, file); - doc->super.run_page = pdf_run_page_shim; + doc->super.run_page_contents = pdf_run_page_contents_shim; + doc->super.run_annot = pdf_run_annot_shim; return doc; } @@ -26,6 +32,7 @@ pdf_document * pdf_open_document(fz_context *ctx, const char *filename) { pdf_document *doc = pdf_open_document_no_run(ctx, filename); - doc->super.run_page = pdf_run_page_shim; + doc->super.run_page_contents = pdf_run_page_contents_shim; + doc->super.run_annot = pdf_run_annot_shim; return doc; } |