From fc5bcdc79a12fb01b6cd07aa142c01ef11430b34 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 13 Dec 2013 16:54:29 +0000 Subject: 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. --- include/mupdf/fitz/device.h | 3 +++ include/mupdf/fitz/document.h | 3 +++ source/cbz/mucbz.c | 8 ++++++++ source/fitz/device.c | 10 ++++++++++ source/fitz/document.c | 7 +++++++ source/fitz/svg-device.c | 10 ++++++++++ source/img/muimage.c | 8 ++++++++ source/pdf/pdf-device.c | 9 +++++++++ source/pdf/pdf-xref.c | 8 ++++++++ source/xps/xps-zip.c | 9 +++++++++ 10 files changed, 75 insertions(+) diff --git a/include/mupdf/fitz/device.h b/include/mupdf/fitz/device.h index fe4a1dbd..a95a5ab1 100644 --- a/include/mupdf/fitz/device.h +++ b/include/mupdf/fitz/device.h @@ -103,6 +103,8 @@ struct fz_device_s void (*free_user)(fz_device *); fz_context *ctx; + void (*rebind)(fz_device *); + void (*begin_page)(fz_device *, const fz_rect *rect, const fz_matrix *ctm); void (*end_page)(fz_device *); @@ -141,6 +143,7 @@ struct fz_device_s fz_rect scissor_accumulator; }; +void fz_rebind_device(fz_device *dev, fz_context *ctx); void fz_begin_page(fz_device *dev, const fz_rect *rect, const fz_matrix *ctm); void fz_end_page(fz_device *dev); void fz_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha); diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index d1bbd75b..d185a31d 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -38,6 +38,7 @@ struct fz_document_s fz_annot *(*next_annot)(fz_document *doc, fz_annot *annot); fz_rect *(*bound_annot)(fz_document *doc, fz_annot *annot, fz_rect *rect); void (*write)(fz_document *doc, char *filename, fz_write_options *opts); + void (*rebind)(fz_document *doc, fz_context *ctx); }; /* @@ -226,4 +227,6 @@ void fz_free_page(fz_document *doc, fz_page *page); */ fz_transition *fz_page_presentation(fz_document *doc, fz_page *page, float *duration); +void fz_rebind_document(fz_document *doc, fz_context *ctx); + #endif 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 @@ -412,6 +412,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) { @@ -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 @@ -35,6 +35,16 @@ fz_disable_device_hints(fz_device *dev, int hints) dev->hints &= ~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) { 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 @@ -135,6 +135,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) { @@ -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 @@ -682,6 +682,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) { @@ -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; } -- cgit v1.2.3