diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-10-14 17:41:03 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-10-14 18:25:20 +0100 |
commit | b26a8c54082337b9134bf3a51364f0442f15aa30 (patch) | |
tree | bfd4ab1aa2916b8012aaa4f29c9ba93f8f1db62f /source/pdf/pdf-device.c | |
parent | 06fd5ef29b26bba0f6d8e6fa1034756737e12ef5 (diff) | |
download | mupdf-b26a8c54082337b9134bf3a51364f0442f15aa30.tar.xz |
Create Contents entry in PDF write device if one doesn't exist already.
Avoids a SEGV on writing.
Diffstat (limited to 'source/pdf/pdf-device.c')
-rw-r--r-- | source/pdf/pdf-device.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c index 25c8afdc..4f2458fa 100644 --- a/source/pdf/pdf-device.c +++ b/source/pdf/pdf-device.c @@ -1333,14 +1333,34 @@ fz_device *pdf_new_pdf_device(pdf_document *doc, pdf_obj *contents, pdf_obj *res fz_device *pdf_page_write(pdf_document *doc, pdf_page *page) { + fz_context *ctx = doc->ctx; pdf_obj *resources = pdf_dict_gets(page->me, "Resources"); fz_matrix ctm; fz_pre_translate(fz_scale(&ctm, 1, -1), 0, page->mediabox.y0-page->mediabox.y1); + if (resources == NULL) { resources = pdf_new_dict(doc, 0); pdf_dict_puts_drop(page->me, "Resources", resources); } + if (page->contents == NULL) + { + pdf_obj *obj = pdf_new_dict(doc, 0); + fz_try(ctx) + { + page->contents = pdf_new_ref(doc, obj); + pdf_dict_puts(page->me, "Contents", obj); + } + fz_always(ctx) + { + pdf_drop_obj(obj); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } + } + return pdf_new_pdf_device(doc, page->contents, resources, &ctm); } |