poppler/Annot.cc | 52 +++++++++++++++++++-------------------------- poppler/Annot.h | 6 ++--- poppler/Array.cc | 14 ++++++++++++ poppler/Array.h | 1 poppler/FileSpec.h | 2 - poppler/FontInfo.cc | 2 - poppler/Form.cc | 6 ++--- poppler/Function.cc | 7 ++---- poppler/Gfx.cc | 11 ++++----- poppler/Link.cc | 17 ++++++++------ poppler/Link.h | 8 +++--- poppler/OptionalContent.cc | 2 - poppler/OptionalContent.h | 2 - poppler/Stream.h | 2 - poppler/StructElement.cc | 5 ++-- poppler/StructElement.h | 4 +-- 16 files changed, 75 insertions(+), 66 deletions(-)
New commits: commit 679339e0384a630052902cfbad1b278440857046 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 17:42:20 2019 +0100 Function: use new Array::get function Makes code simple and saves getting twice if it's a ref diff --git a/poppler/Function.cc b/poppler/Function.cc index e0af1d15..873c2c0a 100644 --- a/poppler/Function.cc +++ b/poppler/Function.cc @@ -690,12 +690,11 @@ StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict, std::set<int> } for (i = 0; i < k; ++i) { std::set<int> usedParentsAux = *usedParents; - Object obj2 = obj1.arrayGetNF(i).copy(); - if (obj2.isRef()) { - const Ref ref = obj2.getRef(); + Ref ref; + Object obj2 = obj1.getArray()->get(i, &ref); + if (ref.num != 0) { if (usedParentsAux.find(ref.num) == usedParentsAux.end()) { usedParentsAux.insert(ref.num); - obj2 = obj1.arrayGet(i); } else { return; } commit ef6d9e341c98aaf727a27bd858eda7c52b4bed21 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 17:40:44 2019 +0100 Array: introduce get variant that returns also the Ref it is one Similar to the new one in Dict diff --git a/poppler/Array.cc b/poppler/Array.cc index 83098a23..cc7dd0c1 100644 --- a/poppler/Array.cc +++ b/poppler/Array.cc @@ -77,6 +77,20 @@ Object Array::get(int i, int recursion) const { return elems[i].fetch(xref, recursion); } +Object Array::get(int i, Ref *returnRef, int recursion) const +{ + if (i < 0 || std::size_t(i) >= elems.size()) { + *returnRef = { 0, 0 }; + return Object(objNull); + } + if (elems[i].getType() == objRef) { + *returnRef = elems[i].getRef(); + } else { + *returnRef = { 0, 0 }; + } + return elems[i].fetch(xref, recursion); +} + const Object &Array::getNF(int i) const { if (i < 0 || std::size_t(i) >= elems.size()) { static Object nullObj(objNull); diff --git a/poppler/Array.h b/poppler/Array.h index b64503a5..1d03cbc9 100644 --- a/poppler/Array.h +++ b/poppler/Array.h @@ -68,6 +68,7 @@ public: // Accessors. Object get(int i, int recursion = 0) const; + Object get(int i, Ref *returnRef, int recursion = 0) const; const Object &getNF(int i) const; bool getString(int i, GooString *string) const; commit 11d6103d45521d0cfec2a5e49a8214bf85843c7f Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 17:26:47 2019 +0100 Annot: Use the new Dict::lookup function Simplifies the code diff --git a/poppler/Annot.cc b/poppler/Annot.cc index bcd72805..412f1e1d 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -2823,14 +2823,8 @@ void AnnotFreeText::generateFreeTextAppearance() error(errSyntaxWarning, -1, "Font subdictionary is not a dictionary"); } else { // Get the font dictionary for the actual requested font - Object fontDictionary = fontResources.getDict()->lookupNF(da.getFontName().getName()).copy(); - - // Resolve reference, if necessary - Ref fontReference = {-1, -1}; - if (fontDictionary.isRef()) { - fontReference = fontDictionary.getRef(); - fontDictionary = fontDictionary.fetch(xref); - } + Ref fontReference; + Object fontDictionary = fontResources.getDict()->lookup(da.getFontName().getName(), &fontReference); if (fontDictionary.isDict()) { font = GfxFont::makeFont(xref, da.getFontName().getName(), fontReference, fontDictionary.getDict()); commit 56dc35f28a3f878e57ad7eb2b0ca63f325882f12 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 17:05:43 2019 +0100 Annot: Remove unneeded copy() calls diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 0ebde310..bcd72805 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -1224,9 +1224,9 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) { } // Note: This value is overwritten by Annots ctor - obj1 = dict->lookupNF("P").copy(); - if (obj1.isRef()) { - Ref ref = obj1.getRef(); + const Object &pObj = dict->lookupNF("P"); + if (pObj.isRef()) { + Ref ref = pObj.getRef(); page = doc->getCatalog()->findPage (ref.num, ref.gen); } else { @@ -1928,9 +1928,9 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict) { date.reset(obj1.getString()->copy()); } - obj1 = dict->lookupNF("IRT").copy(); - if (obj1.isRef()) { - inReplyTo = obj1.getRef(); + const Object &irtObj = dict->lookupNF("IRT"); + if (irtObj.isRef()) { + inReplyTo = irtObj.getRef(); } else { inReplyTo.num = 0; inReplyTo.gen = 0; commit ff77c618d2d71ff7b9e473b5735b027ec9ba55bd Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 17:02:42 2019 +0100 Link: Remove unneeded copy() calls diff --git a/poppler/Link.cc b/poppler/Link.cc index 428e8b6f..4ee8b78a 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -637,12 +637,12 @@ LinkMovie::LinkMovie(const Object *obj) { annotRef.num = -1; annotTitle = nullptr; - Object tmp = obj->dictLookupNF("Annotation").copy(); - if (tmp.isRef()) { - annotRef = tmp.getRef(); + const Object &annotationObj = obj->dictLookupNF("Annotation"); + if (annotationObj.isRef()) { + annotRef = annotationObj.getRef(); } - tmp = obj->dictLookup("T"); + Object tmp = obj->dictLookup("T"); if (tmp.isString()) { annotTitle = tmp.getString()->copy(); } @@ -729,6 +729,8 @@ LinkRendition::LinkRendition(const Object *obj) { js = nullptr; int operationCode = -1; + screenRef.num = -1; + if (obj->isDict()) { Object tmp = obj->dictLookup("JS"); if (!tmp.isNull()) { @@ -758,10 +760,11 @@ LinkRendition::LinkRendition(const Object *obj) { renditionObj.setToNull(); } - screenRef = obj->dictLookupNF("AN").copy(); - if (!screenRef.isRef() && operation >= 0 && operation <= 4) { + const Object &anObj = obj->dictLookupNF("AN"); + if (anObj.isRef()) { + screenRef = anObj.getRef(); + } else if (operation >= 0 && operation <= 4) { error(errSyntaxWarning, -1, "Invalid Rendition Action: no AN field with op = {0:d}", operationCode); - screenRef.setToNull(); } } diff --git a/poppler/Link.h b/poppler/Link.h index d0e3cc39..5fea9a60 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -17,7 +17,7 @@ // Copyright (C) 2008 Hugo Mercier <[email protected]> // Copyright (C) 2010, 2011 Carlos Garcia Campos <[email protected]> // Copyright (C) 2012 Tobias Koening <[email protected]> -// Copyright (C) 2018 Albert Astals Cid <[email protected]> +// Copyright (C) 2018, 2019 Albert Astals Cid <[email protected]> // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2018 Intevation GmbH <[email protected]> // @@ -360,8 +360,8 @@ public: bool hasRenditionObject() const { return renditionObj.isDict(); } const Object* getRenditionObject() const { return &renditionObj; } - bool hasScreenAnnot() const { return screenRef.isRef(); } - Ref getScreenAnnot() const { return screenRef.getRef(); } + bool hasScreenAnnot() const { return screenRef.num != -1; } + Ref getScreenAnnot() const { return screenRef; } RenditionOperation getOperation() const { return operation; } @@ -371,7 +371,7 @@ public: private: - Object screenRef; + Ref screenRef; Object renditionObj; RenditionOperation operation; commit d57ceff195f5d02504d7adf7396defc915272b67 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 16:52:58 2019 +0100 Gfx: Save unneeded copy() calls diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc index 4da19c14..9244b044 100644 --- a/poppler/Gfx.cc +++ b/poppler/Gfx.cc @@ -4214,7 +4214,6 @@ void Gfx::doImage(Object *ref, Stream *str, bool inlineImg) { bool maskInvert; bool maskInterpolate; Stream *maskStr; - Object obj1; int i, n; // get info from the stream @@ -4227,14 +4226,14 @@ void Gfx::doImage(Object *ref, Stream *str, bool inlineImg) { // check for optional content key if (ref) { - obj1 = dict->lookupNF("OC").copy(); - if (catalog->getOptContentConfig() && !catalog->getOptContentConfig()->optContentIsVisible(&obj1)) { + const Object &objOC = dict->lookupNF("OC"); + if (catalog->getOptContentConfig() && !catalog->getOptContentConfig()->optContentIsVisible(&objOC)) { return; } } // get size - obj1 = dict->lookup("Width"); + Object obj1 = dict->lookup("Width"); if (obj1.isNull()) { obj1 = dict->lookup("W"); } @@ -4691,8 +4690,8 @@ void Gfx::doForm(Object *str) { // check for optional content key ocSaved = ocState; - obj1 = dict->lookupNF("OC").copy(); - if (catalog->getOptContentConfig() && !catalog->getOptContentConfig()->optContentIsVisible(&obj1)) { + const Object &objOC = dict->lookupNF("OC"); + if (catalog->getOptContentConfig() && !catalog->getOptContentConfig()->optContentIsVisible(&objOC)) { if (out->needCharCount()) { ocState = false; } else { commit 008431647c573d342f07f2e05123bdce938802a3 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 16:52:33 2019 +0100 StructElement: save unneeded copy() calls diff --git a/poppler/StructElement.cc b/poppler/StructElement.cc index 41491161..e1142772 100644 --- a/poppler/StructElement.cc +++ b/poppler/StructElement.cc @@ -1045,11 +1045,12 @@ void StructElement::parse(Dict *element) } // Parent object reference (required). - s->parentRef = element->lookupNF("P").copy(); - if (!s->parentRef.isRef()) { + const Object &objP = element->lookupNF("P"); + if (!objP.isRef()) { error(errSyntaxError, -1, "P object is wrong type ({0:s})", obj.getTypeName()); return; } + s->parentRef = objP.getRef(); // Check whether the S-type is valid for the top level // element and create a node of the appropriate type. diff --git a/poppler/StructElement.h b/poppler/StructElement.h index b654366d..9030fb3d 100644 --- a/poppler/StructElement.h +++ b/poppler/StructElement.h @@ -159,7 +159,7 @@ public: int getMCID() const { return c->mcid; } Ref getObjectRef() const { return c->ref; } - Ref getParentRef() { return isContent() ? parent->getParentRef() : s->parentRef.getRef(); } + Ref getParentRef() { return isContent() ? parent->getParentRef() : s->parentRef; } bool hasPageRef() const; bool getPageRef(Ref& ref) const; StructTreeRoot *getStructTreeRoot() { return treeRoot; } @@ -253,7 +253,7 @@ private: typedef std::vector<StructElement*> ElemPtrArray; struct StructData { - Object parentRef; + Ref parentRef; GooString *altText; GooString *actualText; GooString *id; commit 38422a432c4f49e31467e5eae447e244eade3218 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 16:51:57 2019 +0100 OptionalContent: constify diff --git a/poppler/OptionalContent.cc b/poppler/OptionalContent.cc index 23acd019..846a2ae6 100644 --- a/poppler/OptionalContent.cc +++ b/poppler/OptionalContent.cc @@ -137,7 +137,7 @@ OCDisplayNode *OCGs::getDisplayRoot() return display.get(); } -bool OCGs::optContentIsVisible( Object *dictRef ) +bool OCGs::optContentIsVisible( const Object *dictRef ) { Dict *dict; bool result = true; diff --git a/poppler/OptionalContent.h b/poppler/OptionalContent.h index e4144e64..309d1e65 100644 --- a/poppler/OptionalContent.h +++ b/poppler/OptionalContent.h @@ -53,7 +53,7 @@ public: Array* getRBGroupsArray() { return (rbgroups.isArray() && rbgroups.arrayGetLength()) ? rbgroups.getArray() : nullptr; } - bool optContentIsVisible( Object *dictRef ); + bool optContentIsVisible( const Object *dictRef ); private: bool ok; commit d2ccd7f9cd26a877492bc5dd02094defa9be0592 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 16:51:25 2019 +0100 Form: Save unneeded copy() calls diff --git a/poppler/Form.cc b/poppler/Form.cc index 905e5c3e..6d167c6a 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -648,9 +648,9 @@ FormField::FormField(PDFDoc *docA, Object &&aobj, const Ref aref, FormField *par const Ref ref = childRef.getRef(); if (usedParents->find(ref.num) == usedParents->end()) { // Field child: it could be a form field or a widget or composed dict - Object obj2 = childObj.dictLookupNF("Parent").copy(); + const Object &objParent = childObj.dictLookupNF("Parent"); Object obj3 = childObj.dictLookup("Parent"); - if (obj2.isRef() || obj3.isDict()) { + if (objParent.isRef() || obj3.isDict()) { // Child is a form field or composed dict // We create the field, if it's composed // it will create the widget as a child @@ -666,7 +666,7 @@ FormField::FormField(PDFDoc *docA, Object &&aobj, const Ref aref, FormField *par children = (FormField**)greallocn(children, numChildren, sizeof(FormField*)); children[numChildren - 1] = Form::createFieldFromDict(std::move(childObj), doc, ref, this, &usedParentsAux); } else { - obj2 = childObj.dictLookup("Subtype"); + Object obj2 = childObj.dictLookup("Subtype"); if (obj2.isName("Widget")) { // Child is a widget annotation if (!terminal && numChildren > 0) { commit c4c8b5be381c925328ecace0753ce4d0c1305bf8 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 16:50:36 2019 +0100 FontInfo: Save unneeded copy() call diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc index 161e5978..a6dd5a74 100644 --- a/poppler/FontInfo.cc +++ b/poppler/FontInfo.cc @@ -131,7 +131,7 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, GooList *fontsList) Object objDict = resDict->lookup(resTypes[resType]); if (objDict.isDict()) { for (int i = 0; i < objDict.dictGetLength(); ++i) { - const Object &resObj = objDict.dictGetValNF(i).copy(); + const Object &resObj = objDict.dictGetValNF(i); if (resObj.isRef()) { // check for an already-seen object const Ref r = resObj.getRef(); commit a1b7baeab913931b06e53d2d271481f711eeab81 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 16:50:19 2019 +0100 Annot: save some unneeded copy() calls diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 80e3a99b..0ebde310 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -929,7 +929,7 @@ int AnnotAppearance::getNumStates() { } // Test if stateObj (a Ref or a Dict) points to the specified stream -bool AnnotAppearance::referencesStream(Object *stateObj, Ref refToStream) { +bool AnnotAppearance::referencesStream(const Object *stateObj, Ref refToStream) { if (stateObj->isRef()) { Ref r = stateObj->getRef(); if (r.num == refToStream.num && r.gen == refToStream.gen) { @@ -952,22 +952,21 @@ bool AnnotAppearance::referencesStream(Object *stateObj, Ref refToStream) { // Test if this AnnotAppearance references the specified stream bool AnnotAppearance::referencesStream(Ref refToStream) { - Object obj1; bool found; // Scan each state's ref/subdictionary - obj1 = appearDict.dictLookupNF("N").copy(); - found = referencesStream(&obj1, refToStream); + const Object &objN = appearDict.dictLookupNF("N"); + found = referencesStream(&objN, refToStream); if (found) return true; - obj1 = appearDict.dictLookupNF("R").copy(); - found = referencesStream(&obj1, refToStream); + const Object &objR = appearDict.dictLookupNF("R"); + found = referencesStream(&objR, refToStream); if (found) return true; - obj1 = appearDict.dictLookupNF("D").copy(); - found = referencesStream(&obj1, refToStream); + const Object &objD = appearDict.dictLookupNF("D"); + found = referencesStream(&objD, refToStream); return found; } @@ -995,7 +994,7 @@ void AnnotAppearance::removeStream(Ref refToStream) { } // Removes stream if obj is a Ref, or removes pointed streams if obj is a Dict -void AnnotAppearance::removeStateStreams(Object *obj1) { +void AnnotAppearance::removeStateStreams(const Object *obj1) { if (obj1->isRef()) { removeStream(obj1->getRef()); } else if (obj1->isDict()) { @@ -1010,13 +1009,12 @@ void AnnotAppearance::removeStateStreams(Object *obj1) { } void AnnotAppearance::removeAllStreams() { - Object obj1; - obj1 = appearDict.dictLookupNF("N").copy(); - removeStateStreams(&obj1); - obj1 = appearDict.dictLookupNF("R").copy(); - removeStateStreams(&obj1); - obj1 = appearDict.dictLookupNF("D").copy(); - removeStateStreams(&obj1); + const Object &objN = appearDict.dictLookupNF("N"); + removeStateStreams(&objN); + const Object &objR = appearDict.dictLookupNF("R"); + removeStateStreams(&objR); + const Object &objD = appearDict.dictLookupNF("D"); + removeStateStreams(&objD); } //------------------------------------------------------------------------ diff --git a/poppler/Annot.h b/poppler/Annot.h index 4fbdcda4..09169865 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -21,7 +21,7 @@ // Copyright (C) 2008 Hugo Mercier <[email protected]> // Copyright (C) 2008 Pino Toscano <[email protected]> // Copyright (C) 2008 Tomas Are Haavet <[email protected]> -// Copyright (C) 2009-2011, 2013, 2016-2018 Albert Astals Cid <[email protected]> +// Copyright (C) 2009-2011, 2013, 2016-2019 Albert Astals Cid <[email protected]> // Copyright (C) 2012, 2013 Fabio D'Urso <[email protected]> // Copyright (C) 2012, 2015 Tobias Koenig <[email protected]> // Copyright (C) 2013 Thomas Freitag <[email protected]> @@ -446,9 +446,9 @@ public: bool referencesStream(Ref targetStreamRef); private: - static bool referencesStream(Object *stateObj, Ref targetStreamRef); + static bool referencesStream(const Object *stateObj, Ref targetStreamRef); void removeStream(Ref refToStream); - void removeStateStreams(Object *state); + void removeStateStreams(const Object *state); protected: PDFDoc *doc; commit c33a0e82f8df11f7a5a0f7d0e0020c485b9142f0 Author: Albert Astals Cid <[email protected]> Date: Thu Feb 28 17:33:40 2019 +0100 Update (C) of previous commit diff --git a/poppler/FileSpec.h b/poppler/FileSpec.h index f205ac32..8d22e02c 100644 --- a/poppler/FileSpec.h +++ b/poppler/FileSpec.h @@ -6,7 +6,7 @@ // under GPL version 2 or later // // Copyright (C) 2008 Carlos Garcia Campos <[email protected]> -// Copyright (C) 2017, 2018 Albert Astals Cid <[email protected]> +// Copyright (C) 2017-2019 Albert Astals Cid <[email protected]> // // 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 diff --git a/poppler/Stream.h b/poppler/Stream.h index 851d2fe3..32987c48 100644 --- a/poppler/Stream.h +++ b/poppler/Stream.h @@ -15,7 +15,7 @@ // // Copyright (C) 2005 Jeff Muizelaar <[email protected]> // Copyright (C) 2008 Julien Rebetez <[email protected]> -// Copyright (C) 2008, 2010, 2011, 2016-2018 Albert Astals Cid <[email protected]> +// Copyright (C) 2008, 2010, 2011, 2016-2019 Albert Astals Cid <[email protected]> // Copyright (C) 2009 Carlos Garcia Campos <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> // Copyright (C) 2010 Hib Eris <[email protected]> _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
