diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-12-13 16:54:29 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2014-01-02 20:04:44 +0000 |
commit | fc5bcdc79a12fb01b6cd07aa142c01ef11430b34 (patch) | |
tree | 547ed060a16453df001ffcb34657de46418872ff /source | |
parent | 651f13408c67a8392ad93adda079c096d8a6118c (diff) | |
download | mupdf-fc5bcdc79a12fb01b6cd07aa142c01ef11430b34.tar.xz |
Add rebinding for fz_devices and fz_documents
The SVG device needs rebinding as it holds a file. The PDF device needs
to rebind the underlying pdf document.
All documents need to rebind their underlying streams.
Diffstat (limited to 'source')
-rw-r--r-- | source/cbz/mucbz.c | 8 | ||||
-rw-r--r-- | source/fitz/device.c | 10 | ||||
-rw-r--r-- | source/fitz/document.c | 7 | ||||
-rw-r--r-- | source/fitz/svg-device.c | 10 | ||||
-rw-r--r-- | source/img/muimage.c | 8 | ||||
-rw-r--r-- | source/pdf/pdf-device.c | 9 | ||||
-rw-r--r-- | source/pdf/pdf-xref.c | 8 | ||||
-rw-r--r-- | source/xps/xps-zip.c | 9 |
8 files changed, 69 insertions, 0 deletions
diff --git a/source/cbz/mucbz.c b/source/cbz/mucbz.c index 5247a4ee..4ebb623a 100644 --- a/source/cbz/mucbz.c +++ b/source/cbz/mucbz.c @@ -413,6 +413,13 @@ cbz_meta(cbz_document *doc, int key, void *ptr, int size) } static void +cbz_rebind(cbz_document *doc, fz_context *ctx) +{ + doc->ctx = ctx; + fz_rebind_stream(doc->file, ctx); +} + +static void cbz_init_document(cbz_document *doc) { doc->super.close = (void*)cbz_close_document; @@ -422,4 +429,5 @@ cbz_init_document(cbz_document *doc) doc->super.run_page_contents = (void*)cbz_run_page; doc->super.free_page = (void*)cbz_free_page; doc->super.meta = (void*)cbz_meta; + doc->super.rebind = (void *)cbz_rebind; } diff --git a/source/fitz/device.c b/source/fitz/device.c index fa428764..d9249732 100644 --- a/source/fitz/device.c +++ b/source/fitz/device.c @@ -36,6 +36,16 @@ fz_disable_device_hints(fz_device *dev, int hints) } void +fz_rebind_device(fz_device *dev, fz_context *ctx) +{ + if (dev == NULL) + return; + dev->ctx = ctx; + if (dev->rebind) + dev->rebind(dev); +} + +void fz_begin_page(fz_device *dev, const fz_rect *rect, const fz_matrix *ctm) { if (dev->begin_page) diff --git a/source/fitz/document.c b/source/fitz/document.c index 3926255b..a86c2f6e 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -102,6 +102,13 @@ fz_close_document(fz_document *doc) doc->close(doc); } +void +fz_rebind_document(fz_document *doc, fz_context *ctx) +{ + if (doc != NULL && doc->rebind != NULL) + doc->rebind(doc, ctx); +} + int fz_needs_password(fz_document *doc) { diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c index dd5a2e19..dc248f88 100644 --- a/source/fitz/svg-device.c +++ b/source/fitz/svg-device.c @@ -1027,6 +1027,15 @@ svg_dev_free_user(fz_device *dev) fz_free(ctx, sdev); } +void svg_rebind(fz_device *dev) +{ + svg_device *sdev = dev->user; + + sdev->ctx = dev->ctx; + fz_rebind_output(sdev->out, sdev->ctx); + fz_rebind_output(sdev->out_store, sdev->ctx); +} + fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, float page_height) { svg_device *sdev = fz_malloc_struct(ctx, svg_device); @@ -1047,6 +1056,7 @@ fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, fz_rethrow(ctx); } + dev->rebind = svg_rebind; dev->free_user = svg_dev_free_user; dev->fill_path = svg_dev_fill_path; diff --git a/source/img/muimage.c b/source/img/muimage.c index 759653a7..7a6dfc3a 100644 --- a/source/img/muimage.c +++ b/source/img/muimage.c @@ -136,6 +136,13 @@ image_meta(image_document *doc, int key, void *ptr, int size) } static void +image_rebind(image_document *doc, fz_context *ctx) +{ + doc->ctx = ctx; + fz_rebind_stream(doc->file, ctx); +} + +static void image_init_document(image_document *doc) { doc->super.close = (void*)image_close_document; @@ -145,4 +152,5 @@ image_init_document(image_document *doc) doc->super.run_page_contents = (void*)image_run_page; doc->super.free_page = (void*)image_free_page; doc->super.meta = (void*)image_meta; + doc->super.rebind = (void*)image_rebind; } diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c index 39c19627..633d9975 100644 --- a/source/pdf/pdf-device.c +++ b/source/pdf/pdf-device.c @@ -1277,6 +1277,14 @@ pdf_dev_free_user(fz_device *dev) fz_free(ctx, pdev); } +static void +pdf_dev_rebind(fz_device *dev) +{ + pdf_device *pdev = dev->user; + + fz_rebind_document((fz_document *)pdev->doc, dev->ctx); +} + fz_device *pdf_new_pdf_device(pdf_document *doc, pdf_obj *contents, pdf_obj *resources, const fz_matrix *ctm) { fz_context *ctx = doc->ctx; @@ -1313,6 +1321,7 @@ fz_device *pdf_new_pdf_device(pdf_document *doc, pdf_obj *contents, pdf_obj *res fz_rethrow(ctx); } + dev->rebind = pdf_dev_rebind; dev->free_user = pdf_dev_free_user; dev->fill_path = pdf_dev_fill_path; diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index a71dc1cf..523dd1f3 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -1941,6 +1941,13 @@ pdf_page_presentation(pdf_document *doc, pdf_page *page, float *duration) return &page->transition; } +static void +pdf_rebind(pdf_document *doc, fz_context *ctx) +{ + doc->ctx = ctx; + fz_rebind_stream(doc->file, ctx); +} + /* Initializers for the fz_document interface. @@ -1973,6 +1980,7 @@ pdf_new_document(fz_context *ctx, fz_stream *file) doc->super.meta = (void*)pdf_meta; doc->super.page_presentation = (void*)pdf_page_presentation; doc->super.write = (void*)pdf_write_document; + doc->super.rebind = (void*)pdf_rebind; pdf_lexbuf_init(ctx, &doc->lexbuf.base, PDF_LEXBUF_LARGE); doc->file = fz_keep_stream(file); diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c index 70b643af..c9dc9840 100644 --- a/source/xps/xps-zip.c +++ b/source/xps/xps-zip.c @@ -683,6 +683,14 @@ xps_meta(xps_document *doc, int key, void *ptr, int size) } static void +xps_rebind(xps_document *doc, fz_context *ctx) +{ + doc->ctx = ctx; + fz_rebind_stream(doc->file, ctx); + fz_rebind_device(doc->dev, ctx); +} + +static void xps_init_document(xps_document *doc) { doc->super.close = (void*)xps_close_document; @@ -694,4 +702,5 @@ xps_init_document(xps_document *doc) doc->super.run_page_contents = (void*)xps_run_page; doc->super.free_page = (void*)xps_free_page; doc->super.meta = (void*)xps_meta; + doc->super.rebind = (void*)xps_rebind; } |