summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/pdf/output-pdf.h4
-rw-r--r--include/mupdf/pdf/page.h2
-rw-r--r--source/pdf/pdf-device.c33
-rw-r--r--source/pdf/pdf-page.c5
4 files changed, 29 insertions, 15 deletions
diff --git a/include/mupdf/pdf/output-pdf.h b/include/mupdf/pdf/output-pdf.h
index 1e783201..617d32fc 100644
--- a/include/mupdf/pdf/output-pdf.h
+++ b/include/mupdf/pdf/output-pdf.h
@@ -5,6 +5,10 @@
pdf_new_pdf_device: Create a pdf device. Rendering to the device creates
new pdf content. WARNING: this device is work in progress. It doesn't
currently support all rendering cases.
+
+ Note that contents must be a stream (dictionary) to be updated (or
+ a reference to a stream). Callers should take care to ensure that it
+ is not an array, and that is it not shared with other objects/pages.
*/
fz_device *pdf_new_pdf_device(fz_context *ctx, pdf_document *doc, pdf_obj *contents, pdf_obj *resources, const fz_matrix *ctm, fz_buffer *buf);
diff --git a/include/mupdf/pdf/page.h b/include/mupdf/pdf/page.h
index 2a323ddb..79b7659e 100644
--- a/include/mupdf/pdf/page.h
+++ b/include/mupdf/pdf/page.h
@@ -17,6 +17,8 @@ pdf_obj *pdf_lookup_page_obj(fz_context *ctx, pdf_document *doc, int needle);
*/
pdf_page *pdf_load_page(fz_context *ctx, pdf_document *doc, int number);
+void pdf_drop_page(fz_context *ctx, pdf_page *page);
+
fz_link *pdf_load_links(fz_context *ctx, pdf_page *page);
/*
diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c
index e3b63dc5..8b99c4f0 100644
--- a/source/pdf/pdf-device.c
+++ b/source/pdf/pdf-device.c
@@ -1350,6 +1350,8 @@ fz_device *pdf_page_write(fz_context *ctx, pdf_document *doc, pdf_page *page)
{
pdf_obj *resources = pdf_dict_get(ctx, page->me, PDF_NAME_Resources);
fz_matrix ctm;
+ pdf_obj *obj;
+
fz_pre_translate(fz_scale(&ctm, 1, -1), 0, page->mediabox.y0-page->mediabox.y1);
if (resources == NULL)
@@ -1358,22 +1360,23 @@ fz_device *pdf_page_write(fz_context *ctx, pdf_document *doc, pdf_page *page)
pdf_dict_put_drop(ctx, page->me, PDF_NAME_Resources, resources);
}
- if (page->contents == NULL)
+ /* We always make a new object for page->contents here, in case
+ * the existing one is an array, or is shared. */
+ obj = pdf_new_dict(ctx, doc, 0);
+ fz_try(ctx)
{
- pdf_obj *obj = pdf_new_dict(ctx, doc, 0);
- fz_try(ctx)
- {
- page->contents = pdf_new_ref(ctx, doc, obj);
- pdf_dict_put(ctx, page->me, PDF_NAME_Contents, page->contents);
- }
- fz_always(ctx)
- {
- pdf_drop_obj(ctx, obj);
- }
- fz_catch(ctx)
- {
- fz_rethrow(ctx);
- }
+ pdf_obj *new_contents = pdf_new_ref(ctx, doc, obj);
+ pdf_dict_put(ctx, page->me, PDF_NAME_Contents, new_contents);
+ pdf_drop_obj(ctx, page->contents);
+ page->contents = new_contents;
+ }
+ fz_always(ctx)
+ {
+ pdf_drop_obj(ctx, obj);
+ }
+ fz_catch(ctx)
+ {
+ fz_rethrow(ctx);
}
return pdf_new_pdf_device(ctx, doc, page->contents, resources, &ctm, NULL);
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c
index 588ba093..9d5eb863 100644
--- a/source/pdf/pdf-page.c
+++ b/source/pdf/pdf-page.c
@@ -420,6 +420,11 @@ pdf_drop_page_imp(fz_context *ctx, pdf_page *page)
fz_drop_document(ctx, &page->doc->super);
}
+void pdf_drop_page(fz_context *ctx, pdf_page *page)
+{
+ fz_drop_page(ctx, &page->super);
+}
+
pdf_page *
pdf_load_page(fz_context *ctx, pdf_document *doc, int number)
{