]> mj.ucw.cz Git - paperjam.git/commitdiff
Store duplicate pages only once
authorMartin Mares <mj@ucw.cz>
Sun, 1 Apr 2018 14:35:31 +0000 (16:35 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 1 Apr 2018 14:35:31 +0000 (16:35 +0200)
TODO
jam.h
paperjam.cc

diff --git a/TODO b/TODO
index 29db5d501a2da8a2c34b59a2078b607d19ca0517..65580b06f56cd5db5ff637082c05ef0c55f7fe67 100644 (file)
--- 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 f4235dd332e1dc0084cf9c907a1b08f7fa7b00c6..b3f08d78fa3a999dcea5174a8f86566366b8b8a1 100644 (file)
--- 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 {
index 07ae6b4289d40f460bc054373c7bcd3c9d11ac7a..f388734bcd9583100f81c7beb9a19a1d738a0c22 100644 (file)
@@ -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);