[poppler] poppler/PDFDoc.cc poppler/XRef.cc poppler/XRef.h

Albert Astals Cid aacid at kemper.freedesktop.org
Wed Feb 1 10:19:48 PST 2012


 poppler/PDFDoc.cc |   63 +++++++++++++++++++++++++++++++++---------------------
 poppler/XRef.cc   |    9 ++++++-
 poppler/XRef.h    |    5 +++-
 3 files changed, 51 insertions(+), 26 deletions(-)

New commits:
commit 0089357de8ea96f3e394ea9cb37e8182ccf15ae2
Author: Thomas Freitag <Thomas.Freitag at kabelmail.de>
Date:   Wed Feb 1 19:17:38 2012 +0100

    pdfseparate: Produce PDF/X conformant pdf pages if the original PDF was PDF/X conformant.

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 1c85385..0932d84 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -603,22 +603,38 @@ int PDFDoc::savePageAs(GooString *name, int pageNo)
   }
   outStr = new FileOutStream(f,0);
 
-  yRef = new XRef();
+  yRef = new XRef(getXRef()->getTrailerDict());
   countRef = new XRef();
   yRef->add(0, 65535, 0, gFalse);
   writeHeader(outStr, getPDFMajorVersion(), getPDFMinorVersion());
 
-  // get and mark optional content groups
-  OCGs *ocgs = getCatalog()->getOptContentConfig();
-  if (ocgs != NULL) {
-    Object catDict, optContentProps;
-    getXRef()->getCatalog(&catDict);
-    catDict.dictLookup("OCProperties", &optContentProps);
-    Dict *pageDict = optContentProps.getDict();
-    markPageObjects(pageDict, yRef, countRef, 0);
-    catDict.free();
-    optContentProps.free();
+  // get and mark info dict
+  Object infoObj;
+  getXRef()->getDocInfo(&infoObj);
+  if (infoObj.isDict()) {
+    Dict *infoDict = infoObj.getDict();
+    markPageObjects(infoDict, yRef, countRef, 0);
+    Object *trailerObj = getXRef()->getTrailerDict();
+    if (trailerObj->isDict()) {
+      Dict *trailerDict = trailerObj->getDict();
+      Object ref;
+      trailerDict->lookupNF("Info", &ref);
+      if (ref.isRef()) {
+        yRef->add(ref.getRef().num, ref.getRef().gen, 0, gTrue);
+        if (getXRef()->getEntry(ref.getRef().num)->type == xrefEntryCompressed) {
+          yRef->getEntry(ref.getRef().num)->type = xrefEntryCompressed;
+        }
+      }
+      ref.free();
+    }
   }
+  infoObj.free();
+  
+  // get and mark output intents etc.
+  Object catObj;
+  getXRef()->getCatalog(&catObj);
+  Dict *catDict = catObj.getDict();
+  markPageObjects(catDict, yRef, countRef, 0);
 
   Dict *pageDict = page.getDict();
   markPageObjects(pageDict, yRef, countRef, 0);
@@ -627,24 +643,20 @@ int PDFDoc::savePageAs(GooString *name, int pageNo)
   yRef->add(rootNum,0,outStr->getPos(),gTrue);
   outStr->printf("%d 0 obj\n", rootNum);
   outStr->printf("<< /Type /Catalog /Pages %d 0 R", rootNum + 1); 
-  if (ocgs != NULL) {
-    Object catDict, optContentProps;
-    getXRef()->getCatalog(&catDict);
-    catDict.dictLookup("OCProperties", &optContentProps);
-    outStr->printf(" /OCProperties <<");
-    Dict *pageDict = optContentProps.getDict();
-    for (int n = 0; n < pageDict->getLength(); n++) {
-      if (n > 0) outStr->printf(" ");
-      const char *key = pageDict->getKey(n);
-      Object value; pageDict->getValNF(n, &value);
+  for (int j = 0; j < catDict->getLength(); j++) {
+    const char *key = catDict->getKey(j);
+    if (strcmp(key, "Type") != 0 &&
+      strcmp(key, "Catalog") != 0 &&
+      strcmp(key, "Pages") != 0) 
+    {
+      if (j > 0) outStr->printf(" ");
+      Object value; catDict->getValNF(j, &value);
       outStr->printf("/%s ", key);
       writeObject(&value, NULL, outStr, getXRef(), 0);
       value.free();
     }
-    outStr->printf(" >> ");
-    catDict.free();
-    optContentProps.free();
   }
+  catObj.free();
   outStr->printf(">>\nendobj\n");
   objectsCount++;
 
@@ -1293,6 +1305,9 @@ void PDFDoc::replacePageDict(int pageNo, int rotate,
     cropBoxObj->arrayAdd(cllx);
     cropBoxObj->arrayAdd(clly);
     pageDict->add(copyString("CropBox"), cropBoxObj);
+    pageDict->add(copyString("TrimBox"), cropBoxObj);
+  } else {
+    pageDict->add(copyString("TrimBox"), mediaBoxObj);
   }
   Object *rotateObj = new Object();
   rotateObj->initInt(rotate);
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 970a00b..300e59c 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -19,7 +19,8 @@
 // Copyright (C) 2007-2008 Julien Rebetez <julienr at svn.gnome.org>
 // Copyright (C) 2007 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2009, 2010 Ilya Gorenbein <igorenbein at finjan.com>
-// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
+// Copyright (C) 2012 Thomas Freitag <Thomas.Freitag at kabelmail.de>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -271,6 +272,12 @@ XRef::XRef() {
   init();
 }
 
+XRef::XRef(Object *trailerDictA) {
+  init();
+  if (trailerDictA->isDict())
+    trailerDict.initDict(trailerDictA->getDict());
+}
+
 XRef::XRef(BaseStream *strA, Guint pos, Guint mainXRefEntriesOffsetA, GBool *wasReconstructed, GBool reconstruct) {
   Object obj;
 
diff --git a/poppler/XRef.h b/poppler/XRef.h
index 8b77b6c..4687fe3 100644
--- a/poppler/XRef.h
+++ b/poppler/XRef.h
@@ -18,7 +18,8 @@
 // Copyright (C) 2007-2008 Julien Rebetez <julienr at svn.gnome.org>
 // Copyright (C) 2007 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2010 Ilya Gorenbein <igorenbein at finjan.com>
-// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
+// Copyright (C) 2012 Thomas Freitag <Thomas.Freitag at kabelmail.de>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -66,6 +67,8 @@ public:
 
   // Constructor, create an empty XRef, used for PDF writing
   XRef();
+  // Constructor, create an empty XRef but with info dict, used for PDF writing
+  XRef(Object *trailerDictA);
   // Constructor.  Read xref table from stream.
   XRef(BaseStream *strA, Guint pos, Guint mainXRefEntriesOffsetA = 0, GBool *wasReconstructed = NULL, GBool reconstruct = false);
 


More information about the poppler mailing list