[poppler] glib/poppler-action.cc poppler/FontInfo.cc poppler/Gfx.cc poppler/Object.cc poppler/PDFDoc.cc poppler/XRef.cc poppler/XRef.h utils/pdfunite.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Feb 10 15:59:22 UTC 2019


 glib/poppler-action.cc |    2 +-
 poppler/FontInfo.cc    |    4 ++--
 poppler/Gfx.cc         |    4 ++--
 poppler/Object.cc      |    4 ++--
 poppler/PDFDoc.cc      |   18 +++++++++---------
 poppler/XRef.cc        |    9 +++++++--
 poppler/XRef.h         |    3 ++-
 utils/pdfunite.cc      |    2 +-
 8 files changed, 26 insertions(+), 20 deletions(-)

New commits:
commit 4d0cbca6a9ebf92f4947522f56cf9361d4b5314e
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Feb 10 16:46:56 2019 +0100

    Add an XRef::fetch variant that takes a const Ref
    
    makes the code more compact and easier to understand

diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc
index 7e0bc031..1aa56a79 100644
--- a/glib/poppler-action.cc
+++ b/glib/poppler-action.cc
@@ -435,7 +435,7 @@ find_annot_movie_for_action (PopplerDocument *document,
   if (link->hasAnnotRef ()) {
     const Ref *ref = link->getAnnotRef ();
 
-    annotObj = xref->fetch (ref->num, ref->gen);
+    annotObj = xref->fetch (*ref);
   } else if (link->hasAnnotTitle ()) {
     const GooString *title = link->getAnnotTitle ();
     int i;
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index fe06d87f..cefacad7 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -3,7 +3,7 @@
 // FontInfo.cc
 //
 // Copyright (C) 2005, 2006 Kristian Høgsberg <krh at redhat.com>
-// Copyright (C) 2005-2008, 2010, 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005-2008, 2010, 2017-2019 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2005 Brad Hards <bradh at frogmouth.net>
 // Copyright (C) 2006 Kouhei Sutou <kou at cozmixng.org>
 // Copyright (C) 2009 Pino Toscano <pino at kde.org>
@@ -192,7 +192,7 @@ FontInfo::FontInfo(GfxFont *font, XRef *xref) {
 
   // look for a ToUnicode map
   hasToUnicode = false;
-  Object fontObj = xref->fetch(fontRef.num, fontRef.gen);
+  Object fontObj = xref->fetch(fontRef);
   if (fontObj.isDict()) {
     hasToUnicode = fontObj.dictLookup("ToUnicode").isStream();
   }
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 8dc2dc93..d9460f2f 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -14,7 +14,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2005 Jonathan Blandford <jrb at redhat.com>
-// Copyright (C) 2005-2013, 2015-2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005-2013, 2015-2019 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2006 Thorkild Stray <thorkild at ifi.uio.no>
 // Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
 // Copyright (C) 2006-2011 Carlos Garcia Campos <carlosgc at gnome.org>
@@ -505,7 +505,7 @@ Object GfxResources::lookupGState(const char *name) {
     return item->copy();
   }
 
-  auto *item = new Object{xref->fetch(ref.num, ref.gen)};
+  auto *item = new Object{xref->fetch(ref)};
   gStateCache.put(ref, item);
   return item->copy();
 }
diff --git a/poppler/Object.cc b/poppler/Object.cc
index 3ccf8f42..fca0e42e 100644
--- a/poppler/Object.cc
+++ b/poppler/Object.cc
@@ -13,7 +13,7 @@
 // All changes made under the Poppler project to this file are licensed
 // under GPL version 2 or later
 //
-// Copyright (C) 2008, 2010, 2012, 2017 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008, 2010, 2012, 2017, 2019 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
 //
@@ -89,7 +89,7 @@ Object Object::fetch(XRef *xref, int recursion) const {
   CHECK_NOT_DEAD;
 
   return (type == objRef && xref) ?
-         xref->fetch(ref.num, ref.gen, recursion) : copy();
+         xref->fetch(ref, recursion) : copy();
 }
 
 void Object::free() {
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 6f0dd0e1..822fe613 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -722,7 +722,7 @@ bool PDFDoc::checkLinearization() {
     }
 
     pageRef.gen = xref->getEntry(pageRef.num)->gen;
-    Object obj = xref->fetch(pageRef.num, pageRef.gen);
+    Object obj = xref->fetch(pageRef);
     if (!obj.isDict("Page")) {
       linearizationState = 2;
       return false;
@@ -896,7 +896,7 @@ int PDFDoc::savePageAs(const GooString *name, int pageNo)
     getCatalog()->getPage(pageNo)->getMediaBox(),
     cropBox);
   Ref *refPage = getCatalog()->getPageRef(pageNo);
-  Object page = getXRef()->fetch(refPage->num, refPage->gen);
+  Object page = getXRef()->fetch(*refPage);
 
   if (!(f = openFile(name->c_str(), "wb"))) {
     error(errIO, -1, "Couldn't open file '{0:t}'", name);
@@ -1125,7 +1125,7 @@ void PDFDoc::saveIncrementalUpdate (OutStream* outStr)
       ref.num = i;
       ref.gen = xref->getEntry(i)->type == xrefEntryCompressed ? 0 : xref->getEntry(i)->gen;
       if (xref->getEntry(i)->type != xrefEntryFree) {
-        Object obj1 = xref->fetch(ref.num, ref.gen, 1);
+        Object obj1 = xref->fetch(ref, 1 /* recursion */);
         Goffset offset = writeObjectHeader(&ref, outStr);
         writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen);
         writeObjectFooter(outStr);
@@ -1203,7 +1203,7 @@ void PDFDoc::saveCompleteRewrite (OutStream* outStr)
     } else if (type == xrefEntryUncompressed){ 
       ref.num = i;
       ref.gen = xref->getEntry(i)->gen;
-      Object obj1 = xref->fetch(ref.num, ref.gen, 1);
+      Object obj1 = xref->fetch(ref, 1 /* recursion */);
       Goffset offset = writeObjectHeader(&ref, outStr);
       // Write unencrypted objects in unencrypted form
       if (xref->getEntry(i)->getFlag(XRefEntry::Unencrypted)) {
@@ -1216,7 +1216,7 @@ void PDFDoc::saveCompleteRewrite (OutStream* outStr)
     } else if (type == xrefEntryCompressed) {
       ref.num = i;
       ref.gen = 0; //compressed entries have gen == 0
-      Object obj1 = xref->fetch(ref.num, ref.gen, 1);
+      Object obj1 = xref->fetch(ref, 1 /* recursion */);
       Goffset offset = writeObjectHeader(&ref, outStr);
       writeObject(&obj1, outStr, fileKey, encAlgorithm, keyLength, ref.num, ref.gen);
       writeObjectFooter(outStr);
@@ -1730,7 +1730,7 @@ void PDFDoc::markObject (Object* obj, XRef *xRef, XRef *countRef, unsigned int n
           if (entry->gen > 9)
             break;
         } 
-        Object obj1 = getXRef()->fetch(obj->getRef().num, obj->getRef().gen);
+        Object obj1 = getXRef()->fetch(obj->getRef());
         markObject(&obj1, xRef, countRef, numOffset, oldRefNum, newRefNum);
       }
       break;
@@ -1744,7 +1744,7 @@ void PDFDoc::replacePageDict(int pageNo, int rotate,
                              const PDFRectangle *cropBox)
 {
   Ref *refPage = getCatalog()->getPageRef(pageNo);
-  Object page = getXRef()->fetch(refPage->num, refPage->gen);
+  Object page = getXRef()->fetch(*refPage);
   Dict *pageDict = page.getDict();
   pageDict->remove("MediaBoxssdf");
   pageDict->remove("MediaBox");
@@ -1818,7 +1818,7 @@ bool PDFDoc::markAnnotations(Object *annotsObj, XRef *xRef, XRef *countRef, unsi
               } else if (obj2.getRef().num == newPageNum) {
                 continue;
               } else {
-                Object page  = getXRef()->fetch(obj2.getRef().num, obj2.getRef().gen);
+                Object page  = getXRef()->fetch(obj2.getRef());
                 if (page.isDict()) {
                   Dict *pageDict = page.getDict();
                   Object pagetype = pageDict->lookup("Type");
@@ -2093,7 +2093,7 @@ Page *PDFDoc::parsePage(int page)
   }
 
   pageRef.gen = xref->getEntry(pageRef.num)->gen;
-  Object obj = xref->fetch(pageRef.num, pageRef.gen);
+  Object obj = xref->fetch(pageRef);
   if (!obj.isDict("Page")) {
     error(errSyntaxWarning, -1, "Object ({0:d} {1:d}) is not a pageDict", pageRef.num, pageRef.gen);
     return nullptr;
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 2541d113..44e7ccac 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -1072,6 +1072,11 @@ Object XRef::getCatalog() {
   return catalog;
 }
 
+Object XRef::fetch(const Ref ref, int recursion)
+{
+    return fetch(ref.num, ref.gen, recursion);
+}
+
 Object XRef::fetch(int num, int gen, int recursion) {
   XRefEntry *e;
   Parser *parser;
@@ -1635,12 +1640,12 @@ void XRef::markUnencrypted(Object *obj) {
     }
     case objRef:
     {
-      Ref ref = obj->getRef();
+      const Ref ref = obj->getRef();
       XRefEntry *e = getEntry(ref.num);
       if (e->getFlag(XRefEntry::Unencrypted))
         return; // We've already been here: prevent infinite recursion
       e->setFlag(XRefEntry::Unencrypted, true);
-      obj1 = fetch(ref.num, ref.gen);
+      obj1 = fetch(ref);
       markUnencrypted(&obj1);
       break;
     }
diff --git a/poppler/XRef.h b/poppler/XRef.h
index 14b03089..eb8684d3 100644
--- a/poppler/XRef.h
+++ b/poppler/XRef.h
@@ -14,7 +14,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2005 Brad Hards <bradh at frogmouth.net>
-// Copyright (C) 2006, 2008, 2010-2013, 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2006, 2008, 2010-2013, 2017-2019 Albert Astals Cid <aacid at kde.org>
 // 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>
@@ -143,6 +143,7 @@ public:
   Object getCatalog();
 
   // Fetch an indirect reference.
+  Object fetch(const Ref ref, int recursion = 0);
   Object fetch(int num, int gen, int recursion = 0);
 
   // Return the document's Info dictionary (if any).
diff --git a/utils/pdfunite.cc b/utils/pdfunite.cc
index aa22592f..61613f60 100644
--- a/utils/pdfunite.cc
+++ b/utils/pdfunite.cc
@@ -287,7 +287,7 @@ int main (int argc, char *argv[])
 	    docs[i]->getCatalog()->getPage(j)->getRotate(),
 	    docs[i]->getCatalog()->getPage(j)->getMediaBox(), cropBox);
       Ref *refPage = docs[i]->getCatalog()->getPageRef(j);
-      Object page = docs[i]->getXRef()->fetch(refPage->num, refPage->gen);
+      Object page = docs[i]->getXRef()->fetch(*refPage);
       Dict *pageDict = page.getDict();
       Object *resDict = docs[i]->getCatalog()->getPage(j)->getResourceDictObject();
       if (resDict->isDict()) {


More information about the poppler mailing list