diff options
-rw-r--r-- | cbz/mucbz.c | 2 | ||||
-rw-r--r-- | fitz/doc_document.c | 40 | ||||
-rw-r--r-- | fitz/fitz-internal.h | 3 | ||||
-rw-r--r-- | fitz/fitz.h | 45 | ||||
-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 | ||||
-rw-r--r-- | xps/xps_zip.c | 2 |
9 files changed, 190 insertions, 43 deletions
diff --git a/cbz/mucbz.c b/cbz/mucbz.c index 83737833..1fc2fbe6 100644 --- a/cbz/mucbz.c +++ b/cbz/mucbz.c @@ -477,7 +477,7 @@ cbz_init_document(cbz_document *doc) doc->super.count_pages = (void*)cbz_count_pages; doc->super.load_page = (void*)cbz_load_page; doc->super.bound_page = (void*)cbz_bound_page; - doc->super.run_page = (void*)cbz_run_page; + doc->super.run_page_contents = (void*)cbz_run_page; doc->super.free_page = (void*)cbz_free_page; doc->super.meta = (void*)cbz_meta; } diff --git a/fitz/doc_document.c b/fitz/doc_document.c index fe89a061..47157156 100644 --- a/fitz/doc_document.c +++ b/fitz/doc_document.c @@ -162,10 +162,46 @@ fz_bound_annot(fz_document *doc, fz_annot *annot) } void +fz_run_page_contents(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie) +{ + if (doc && doc->run_page_contents && page) + doc->run_page_contents(doc, page, dev, transform, cookie); +} + +void +fz_run_annot(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, fz_matrix transform, fz_cookie *cookie) +{ + if (doc && doc->run_annot && page && annot) + doc->run_annot(doc, page, annot, dev, transform, cookie); +} + +void fz_run_page(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie) { - if (doc && doc->run_page && page) - doc->run_page(doc, page, dev, transform, cookie); + fz_annot *annot; + + fz_run_page_contents(doc, page, dev, transform, cookie); + + if (cookie && cookie->progress_max != -1) + { + int count = 1; + for (annot = fz_first_annot(doc, page); annot; annot = fz_next_annot(doc, annot)) + count++; + cookie->progress_max += count; + } + + for (annot = fz_first_annot(doc, page); annot; annot = fz_next_annot(doc, annot)) + { + /* Check the cookie for aborting */ + if (cookie) + { + if (cookie->abort) + break; + cookie->progress++; + } + + fz_run_annot(doc, page, annot, dev, transform, cookie); + } } void diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index 2023f99b..9726dbf7 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -1434,7 +1434,8 @@ struct fz_document_s fz_page *(*load_page)(fz_document *doc, int number); fz_link *(*load_links)(fz_document *doc, fz_page *page); fz_rect (*bound_page)(fz_document *doc, fz_page *page); - void (*run_page)(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie); + void (*run_page_contents)(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie); + void (*run_annot)(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, fz_matrix transform, fz_cookie *cookie); void (*free_page)(fz_document *doc, fz_page *page); int (*meta)(fz_document *doc, int key, void *ptr, int size); fz_transition *(*page_presentation)(fz_document *doc, fz_page *page, float *duration); diff --git a/fitz/fitz.h b/fitz/fitz.h index 67d9c97c..590bcd45 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -2322,6 +2322,51 @@ fz_rect fz_bound_annot(fz_document *doc, fz_annot *annot); void fz_run_page(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie); /* + fz_run_page_contents: Run a page through a device. Just the main + page content, without the annotations, if any. + + page: Page obtained from fz_load_page. + + dev: Device obtained from fz_new_*_device. + + transform: Transform to apply to page. May include for example + scaling and rotation, see fz_scale, fz_rotate and fz_concat. + Set to fz_identity if no transformation is desired. + + cookie: Communication mechanism between caller and library + rendering the page. Intended for multi-threaded applications, + while single-threaded applications set cookie to NULL. The + caller may abort an ongoing rendering of a page. Cookie also + communicates progress information back to the caller. The + fields inside cookie are continually updated while the page is + rendering. +*/ +void fz_run_page_contents(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie); + +/* + fz_run_annot: Run an annotation through a device. + + page: Page obtained from fz_load_page. + + annot: an annotation. + + dev: Device obtained from fz_new_*_device. + + transform: Transform to apply to page. May include for example + scaling and rotation, see fz_scale, fz_rotate and fz_concat. + Set to fz_identity if no transformation is desired. + + cookie: Communication mechanism between caller and library + rendering the page. Intended for multi-threaded applications, + while single-threaded applications set cookie to NULL. The + caller may abort an ongoing rendering of a page. Cookie also + communicates progress information back to the caller. The + fields inside cookie are continually updated while the page is + rendering. +*/ +void fz_run_annot(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, fz_matrix transform, fz_cookie *cookie); + +/* fz_free_page: Free a loaded page. Does not throw exceptions. 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; } diff --git a/xps/xps_zip.c b/xps/xps_zip.c index 762fe2ba..fa52dec1 100644 --- a/xps/xps_zip.c +++ b/xps/xps_zip.c @@ -691,7 +691,7 @@ xps_init_document(xps_document *doc) doc->super.load_page = (void*)xps_load_page; doc->super.load_links = (void*)xps_load_links; doc->super.bound_page = (void*)xps_bound_page; - doc->super.run_page = (void*)xps_run_page; + doc->super.run_page_contents = (void*)xps_run_page; doc->super.free_page = (void*)xps_free_page; doc->super.meta = (void*)xps_meta; } |