From d37006564909041ef0a19a99d82c350edcbbdf25 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 1 Apr 2018 16:35:31 +0200 Subject: [PATCH] Store duplicate pages only once --- TODO | 1 + jam.h | 1 + paperjam.cc | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 29db5d5..65580b0 100644 --- a/TODO +++ b/TODO @@ -2,3 +2,4 @@ - What if an input page specifies /Rotate? - Better error messages from instantiation - Select should work without commands in the pipeline +- page->index: use or remove diff --git a/jam.h b/jam.h index f4235dd..b3f08d7 100644 --- a/jam.h +++ b/jam.h @@ -43,6 +43,7 @@ struct page_out { string contents; int res_cnt; string new_resource(const string type); + page_out() { res_cnt = 0; } }; struct page { diff --git a/paperjam.cc b/paperjam.cc index 07ae6b4..f388734 100644 --- a/paperjam.cc +++ b/paperjam.cc @@ -17,6 +17,7 @@ string page_out::new_resource(const string type) class in_page : public page { QPDFObjectHandle pdf_page; + QPDFObjectHandle xobject; public: BBox media_box; void render(page_out *out, pdf_matrix xform); @@ -26,6 +27,7 @@ public: in_page::in_page(QPDFObjectHandle inpg, int idx) { pdf_page = inpg; + xobject = QPDFObjectHandle::newNull(); index = idx; media_box = BBox(inpg.getKey("/MediaBox")); width = media_box.width(); @@ -35,9 +37,10 @@ in_page::in_page(QPDFObjectHandle inpg, int idx) void in_page::render(page_out *out, pdf_matrix xform) { // Convert page to xobject - QPDFObjectHandle page_copy = page_to_xobject(&out_pdf, out_pdf.copyForeignObject(pdf_page)); + if (xobject.isNull()) + xobject = out_pdf.makeIndirectObject( page_to_xobject(&out_pdf, out_pdf.copyForeignObject(pdf_page)) ); string xobj_res = out->new_resource("XO"); - out->xobjects.replaceKey(xobj_res, out_pdf.makeIndirectObject(page_copy)); + out->xobjects.replaceKey(xobj_res, xobject); pdf_matrix m; m.shift(-media_box.x_min, -media_box.y_min); -- 2.39.2