[poppler] glib/poppler-document.cc poppler/Annot.cc poppler/Array.cc poppler/Array.h poppler/Catalog.cc poppler/Dict.h poppler/FontInfo.cc poppler/Form.cc poppler/Function.cc poppler/Gfx.cc poppler/GfxFont.cc poppler/GfxState.cc poppler/Link.cc poppler/Object.cc poppler/Object.h poppler/OptionalContent.cc poppler/Page.cc poppler/PDFDoc.cc poppler/PSOutputDev.cc poppler/StructElement.cc poppler/StructTreeRoot.cc poppler/XRef.cc qt5/src test/pdf-fullrewrite.cc utils/pdfunite.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Feb 27 13:18:12 UTC 2019
glib/poppler-document.cc | 4 ++--
poppler/Annot.cc | 6 +++---
poppler/Array.cc | 11 ++++++-----
poppler/Array.h | 4 ++--
poppler/Catalog.cc | 8 ++++----
poppler/Dict.h | 4 ++--
poppler/FontInfo.cc | 2 +-
poppler/Form.cc | 6 +++---
poppler/Function.cc | 2 +-
poppler/Gfx.cc | 4 ++--
poppler/GfxFont.cc | 6 +++---
poppler/GfxState.cc | 4 ++--
poppler/Link.cc | 8 ++++----
poppler/Object.cc | 4 ++--
poppler/Object.h | 8 ++++----
poppler/OptionalContent.cc | 24 ++++++++++++------------
poppler/PDFDoc.cc | 24 ++++++++++++------------
poppler/PSOutputDev.cc | 8 ++++----
poppler/Page.cc | 2 +-
poppler/StructElement.cc | 4 ++--
poppler/StructTreeRoot.cc | 8 ++++----
poppler/XRef.cc | 4 ++--
qt5/src/poppler-optcontent.cc | 6 +++---
test/pdf-fullrewrite.cc | 8 ++++----
utils/pdfunite.cc | 20 ++++++++++----------
25 files changed, 95 insertions(+), 94 deletions(-)
New commits:
commit 597e26e96d2a1449aea360e2cf6ffcbf4b8f5b1d
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 13:56:23 2019 +0100
Make Annot::getNF and Dict::getNF return const & instead of copy
Lots of users can deal with a const & directly, so it saves us some
copying. For the ones that can't move the copy to the caller side.
Some of copy() on the caller side can be easily removed, that will come
on next commits
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index ed37da4c..38699e2f 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -2845,7 +2845,7 @@ get_optional_content_rbgroups (OCGs *ocg)
for (j = 0; j < rb_array->getLength (); ++j) {
OptionalContentGroup *oc;
- Object ref = rb_array->getNF (j);
+ const Object &ref = rb_array->getNF (j);
if (!ref.isRef ()) {
continue;
}
@@ -2888,7 +2888,7 @@ get_optional_content_items_sorted (OCGs *ocg, Layer *parent, Array *order)
Object orderItem = order->get (i);
if (orderItem.isDict ()) {
- Object ref = order->getNF (i);
+ const Object &ref = order->getNF (i);
if (ref.isRef ()) {
OptionalContentGroup *oc = ocg->findOcgByRef (ref.getRef ());
Layer *layer = layer_new (oc);
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 294aa7b1..467836d1 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -938,7 +938,7 @@ bool AnnotAppearance::referencesStream(Object *stateObj, Ref refToStream) {
} else if (stateObj->isDict()) { // Test each value
const int size = stateObj->dictGetLength();
for (int i = 0; i < size; ++i) {
- Object obj1 = stateObj->dictGetValNF(i);
+ const Object &obj1 = stateObj->dictGetValNF(i);
if (obj1.isRef()) {
Ref r = obj1.getRef();
if (r.num == refToStream.num && r.gen == refToStream.gen) {
@@ -1001,7 +1001,7 @@ void AnnotAppearance::removeStateStreams(Object *obj1) {
} else if (obj1->isDict()) {
const int size = obj1->dictGetLength();
for (int i = 0; i < size; ++i) {
- Object obj2 = obj1->dictGetValNF(i);
+ const Object &obj2 = obj1->dictGetValNF(i);
if (obj2.isRef()) {
removeStream(obj2.getRef());
}
@@ -6646,7 +6646,7 @@ Annots::Annots(PDFDoc *docA, int page, Object *annotsObj) {
//form widget
Object obj1 = annotsObj->arrayGet(i);
if (obj1.isDict()) {
- Object obj2 = annotsObj->arrayGetNF(i);
+ const Object &obj2 = annotsObj->arrayGetNF(i);
annot = createAnnot (std::move(obj1), &obj2);
if (annot) {
if (annot->isOk()) {
diff --git a/poppler/Array.cc b/poppler/Array.cc
index ca4a03d5..83098a23 100644
--- a/poppler/Array.cc
+++ b/poppler/Array.cc
@@ -16,7 +16,7 @@
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
-// Copyright (C) 2013, 2017 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2013, 2017, 2019 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2017 Adrian Johnson <ajohnson at redneon.com>
// Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
//
@@ -77,16 +77,17 @@ Object Array::get(int i, int recursion) const {
return elems[i].fetch(xref, recursion);
}
-Object Array::getNF(int i) const {
+const Object &Array::getNF(int i) const {
if (i < 0 || std::size_t(i) >= elems.size()) {
- return Object(objNull);
+ static Object nullObj(objNull);
+ return nullObj;
}
- return elems[i].copy();
+ return elems[i];
}
bool Array::getString(int i, GooString *string) const
{
- Object obj = getNF(i);
+ const Object &obj = getNF(i);
if (obj.isString()) {
string->clear();
string->append(obj.getString());
diff --git a/poppler/Array.h b/poppler/Array.h
index dfe7c75e..b64503a5 100644
--- a/poppler/Array.h
+++ b/poppler/Array.h
@@ -16,7 +16,7 @@
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
-// Copyright (C) 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2017-2019 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2017 Adrian Johnson <ajohnson at redneon.com>
// Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
//
@@ -68,7 +68,7 @@ public:
// Accessors.
Object get(int i, int recursion = 0) const;
- Object getNF(int i) const;
+ const Object &getNF(int i) const;
bool getString(int i, GooString *string) const;
private:
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 894a8955..ed11145d 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
-// Copyright (C) 2005-2013, 2015, 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005-2013, 2015, 2017-2019 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2005 Jeff Muizelaar <jrmuizel at nit.ca>
// Copyright (C) 2005 Jonathan Blandford <jrb at redhat.com>
// Copyright (C) 2005 Marco Pesenti Gritti <mpg at redhat.com>
@@ -270,7 +270,7 @@ bool Catalog::cachePageTree(int page)
continue;
}
- Object kidRef = kids.arrayGetNF(kidsIdx);
+ const Object &kidRef = kids.arrayGetNF(kidsIdx);
if (!kidRef.isRef()) {
error(errSyntaxError, -1, "Kid object (page {0:uld}) is not an indirect reference ({1:s})",
pages.size()+1, kidRef.getTypeName());
@@ -558,7 +558,7 @@ NameTree::Entry::Entry(Array *array, int index) {
else
error(errSyntaxError, -1, "Invalid page tree");
}
- value = array->getNF(index + 1);
+ value = array->getNF(index + 1).copy();
}
NameTree::Entry::~Entry() {
@@ -615,7 +615,7 @@ void NameTree::parse(Object *tree, std::set<int> &seen) {
Object kids = tree->dictLookup("Kids");
if (kids.isArray()) {
for (int i = 0; i < kids.arrayGetLength(); ++i) {
- Object kidRef = kids.arrayGetNF(i);
+ const Object &kidRef = kids.arrayGetNF(i);
if (kidRef.isRef()) {
const int numObj = kidRef.getRef().num;
if (seen.find(numObj) != seen.end()) {
diff --git a/poppler/Dict.h b/poppler/Dict.h
index bdb08cd7..0747d40e 100644
--- a/poppler/Dict.h
+++ b/poppler/Dict.h
@@ -16,7 +16,7 @@
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk at gmail.com>
// Copyright (C) 2007-2008 Julien Rebetez <julienr at svn.gnome.org>
-// Copyright (C) 2010, 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2010, 2017-2019 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2010 Paweł Wiejacha <pawel.wiejacha at gmail.com>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
// Copyright (C) 2017 Adrian Johnson <ajohnson at redneon.com>
@@ -82,7 +82,7 @@ public:
// Iterative accessors.
const char *getKey(int i) const { return entries[i].first.c_str(); }
Object getVal(int i) const { return entries[i].second.fetch(xref); }
- Object getValNF(int i) const { return entries[i].second.copy(); }
+ const Object &getValNF(int i) const { return entries[i].second; }
// Set the xref pointer. This is only used in one special case: the
// trailer dictionary, which is read before the xref table is
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index cefacad7..9ce4ce3e 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) {
- obj1 = objDict.dictGetValNF(i);
+ obj1 = objDict.dictGetValNF(i).copy();
if (obj1.isRef()) {
// check for an already-seen object
const Ref r = obj1.getRef();
diff --git a/poppler/Form.cc b/poppler/Form.cc
index e37212ee..204bf4df 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -634,7 +634,7 @@ FormField::FormField(PDFDoc *docA, Object &&aobj, const Ref aref, FormField *par
if (obj1.isArray()) {
// Load children
for (int i = 0 ; i < obj1.arrayGetLength(); i++) {
- Object childRef = obj1.arrayGetNF(i);
+ const Object &childRef = obj1.arrayGetNF(i);
if (!childRef.isRef()) {
error (errSyntaxError, -1, "Invalid form field renference");
continue;
@@ -1817,7 +1817,7 @@ Form::Form(PDFDoc *docA, Object* acroFormA)
Array *array = obj1.getArray();
for(int i=0; i<array->getLength(); i++) {
Object obj2 = array->get(i);
- Object oref = array->getNF(i);
+ const Object &oref = array->getNF(i);
if (!oref.isRef()) {
error(errSyntaxWarning, -1, "Direct object in rootFields");
continue;
@@ -1846,7 +1846,7 @@ Form::Form(PDFDoc *docA, Object* acroFormA)
Array *array = obj1.getArray();
calculateOrder.reserve(array->getLength());
for(int i=0; i<array->getLength(); i++) {
- Object oref = array->getNF(i);
+ const Object &oref = array->getNF(i);
if (!oref.isRef()) {
error(errSyntaxWarning, -1, "Direct object in CO");
continue;
diff --git a/poppler/Function.cc b/poppler/Function.cc
index 2b882885..e0af1d15 100644
--- a/poppler/Function.cc
+++ b/poppler/Function.cc
@@ -690,7 +690,7 @@ 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);
+ Object obj2 = obj1.arrayGetNF(i).copy();
if (obj2.isRef()) {
const Ref ref = obj2.getRef();
if (usedParentsAux.find(ref.num) == usedParentsAux.end()) {
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index d9460f2f..c80786e7 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -1241,7 +1241,7 @@ void Gfx::opSetExtGState(Object args[], int numArgs) {
if (obj2.isArray()) {
GfxFont *font;
if (obj2.arrayGetLength() == 2) {
- Object fargs0 = obj2.arrayGetNF(0);
+ const Object &fargs0 = obj2.arrayGetNF(0);
Object fargs1 = obj2.arrayGet(1);
if (fargs0.isRef() && fargs1.isNum()) {
Object fobj = fargs0.fetch(xref);
@@ -1277,7 +1277,7 @@ void Gfx::opSetExtGState(Object args[], int numArgs) {
if (obj2.arrayGetLength() == 2) {
Object dargs[2];
- dargs[0] = obj2.arrayGetNF(0);
+ dargs[0] = obj2.arrayGetNF(0).copy();
dargs[1] = obj2.arrayGet(1);
if (dargs[0].isArray() && dargs[1].isInt()) {
opSetDash(dargs,2);
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 15604999..014e5caa 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -2388,7 +2388,7 @@ GfxFontDict::GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict) {
numFonts = fontDict->getLength();
fonts = (GfxFont **)gmallocn(numFonts, sizeof(GfxFont *));
for (i = 0; i < numFonts; ++i) {
- Object obj1 = fontDict->getValNF(i);
+ const Object &obj1 = fontDict->getValNF(i);
Object obj2 = obj1.fetch(xref);
if (obj2.isDict()) {
if (obj1.isRef()) {
@@ -2519,7 +2519,7 @@ void GfxFontDict::hashFontObject1(Object *obj, FNVHash *h) {
n = obj->arrayGetLength();
h->hash((char *)&n, sizeof(int));
for (i = 0; i < n; ++i) {
- obj2 = obj->arrayGetNF(i);
+ obj2 = obj->arrayGetNF(i).copy();
hashFontObject1(&obj2, h);
}
break;
@@ -2530,7 +2530,7 @@ void GfxFontDict::hashFontObject1(Object *obj, FNVHash *h) {
for (i = 0; i < n; ++i) {
p = obj->dictGetKey(i);
h->hash(p, (int)strlen(p));
- obj2 = obj->dictGetValNF(i);
+ obj2 = obj->dictGetValNF(i).copy();
hashFontObject1(&obj2, h);
}
break;
diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index 84f28c44..f0ea0257 100644
--- a/poppler/GfxState.cc
+++ b/poppler/GfxState.cc
@@ -16,7 +16,7 @@
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2006, 2007 Jeff Muizelaar <jeff at infidigm.net>
// Copyright (C) 2006, 2010 Carlos Garcia Campos <carlosgc at gnome.org>
-// Copyright (C) 2006-2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2006-2019 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2009, 2012 Koji Otani <sho at bbr.jp>
// Copyright (C) 2009, 2011-2016 Thomas Freitag <Thomas.Freitag at alfa.de>
// Copyright (C) 2009, 2019 Christian Persch <chpe at gnome.org>
@@ -1828,7 +1828,7 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, GfxState
error(errSyntaxError, -1, "Bad ICCBased color space");
return nullptr;
}
- obj1 = arr->getNF(1);
+ obj1 = arr->getNF(1).copy();
if (obj1.isRef()) {
iccProfileStreamA = obj1.getRef();
} else {
diff --git a/poppler/Link.cc b/poppler/Link.cc
index 33bcb82c..525c4423 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -16,7 +16,7 @@
// Copyright (C) 2006, 2008 Pino Toscano <pino at kde.org>
// Copyright (C) 2007, 2010, 2011 Carlos Garcia Campos <carlosgc at gnome.org>
// Copyright (C) 2008 Hugo Mercier <hmercier31 at gmail.com>
-// Copyright (C) 2008-2010, 2012-2014, 2016-2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008-2010, 2012-2014, 2016-2019 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
// Copyright (C) 2009 Ilya Gorenbein <igorenbein at finjan.com>
// Copyright (C) 2012 Tobias Koening <tobias.koenig at kdab.com>
@@ -188,7 +188,7 @@ LinkAction *LinkAction::parseAction(const Object *obj, const GooString *baseURI,
}
// Similar circle check as above.
- const Object obj3Ref = a->getNF(i);
+ const Object &obj3Ref = a->getNF(i);
if (obj3Ref.isRef()) {
const Ref ref = obj3Ref.getRef();
if (!seenNextActions->insert(ref.num).second) {
@@ -230,7 +230,7 @@ LinkDest::LinkDest(const Array *a) {
error(errSyntaxWarning, -1, "Annotation destination array is too short");
return;
}
- Object obj1 = a->getNF(0);
+ Object obj1 = a->getNF(0).copy();
if (obj1.isInt()) {
pageNum = obj1.getInt() + 1;
pageIsRef = false;
@@ -829,7 +829,7 @@ LinkOCGState::LinkOCGState(const Object *obj) {
StateList *stList = nullptr;
for (int i = 0; i < obj1.arrayGetLength(); ++i) {
- Object obj2 = obj1.arrayGetNF(i);
+ const Object &obj2 = obj1.arrayGetNF(i);
if (obj2.isName()) {
if (stList)
stateList->push_back(stList);
diff --git a/poppler/Object.cc b/poppler/Object.cc
index fca0e42e..be53947a 100644
--- a/poppler/Object.cc
+++ b/poppler/Object.cc
@@ -156,7 +156,7 @@ void Object::print(FILE *f) const {
for (i = 0; i < arrayGetLength(); ++i) {
if (i > 0)
fprintf(f, " ");
- obj = arrayGetNF(i);
+ obj = arrayGetNF(i).copy();
obj.print(f);
}
fprintf(f, "]");
@@ -165,7 +165,7 @@ void Object::print(FILE *f) const {
fprintf(f, "<<");
for (i = 0; i < dictGetLength(); ++i) {
fprintf(f, " /%s ", dictGetKey(i));
- obj = dictGetValNF(i);
+ obj = dictGetValNF(i).copy();
obj.print(f);
}
fprintf(f, " >>");
diff --git a/poppler/Object.h b/poppler/Object.h
index edc96f5b..4f07efa7 100644
--- a/poppler/Object.h
+++ b/poppler/Object.h
@@ -270,7 +270,7 @@ public:
void arrayAdd(Object &&elem);
void arrayRemove(int i);
Object arrayGet(int i, int recursion) const;
- Object arrayGetNF(int i) const;
+ const Object &arrayGetNF(int i) const;
// Dict accessors.
int dictGetLength() const;
@@ -283,7 +283,7 @@ public:
Object dictLookupNF(const char *key) const;
const char *dictGetKey(int i) const;
Object dictGetVal(int i) const;
- Object dictGetValNF(int i) const;
+ const Object &dictGetValNF(int i) const;
// Stream accessors.
bool streamIs(const char *dictType) const;
@@ -338,7 +338,7 @@ inline void Object::arrayRemove(int i)
inline Object Object::arrayGet(int i, int recursion = 0) const
{ OBJECT_TYPE_CHECK(objArray); return array->get(i, recursion); }
-inline Object Object::arrayGetNF(int i) const
+inline const Object &Object::arrayGetNF(int i) const
{ OBJECT_TYPE_CHECK(objArray); return array->getNF(i); }
//------------------------------------------------------------------------
@@ -377,7 +377,7 @@ inline const char *Object::dictGetKey(int i) const
inline Object Object::dictGetVal(int i) const
{ OBJECT_TYPE_CHECK(objDict); return dict->getVal(i); }
-inline Object Object::dictGetValNF(int i) const
+inline const Object &Object::dictGetValNF(int i) const
{ OBJECT_TYPE_CHECK(objDict); return dict->getValNF(i); }
//------------------------------------------------------------------------
diff --git a/poppler/OptionalContent.cc b/poppler/OptionalContent.cc
index 9f5bef83..75b93f4c 100644
--- a/poppler/OptionalContent.cc
+++ b/poppler/OptionalContent.cc
@@ -5,7 +5,7 @@
// Copyright 2007 Brad Hards <bradh at kde.org>
// Copyright 2008 Pino Toscano <pino at kde.org>
// Copyright 2008, 2010 Carlos Garcia Campos <carlosgc at gnome.org>
-// Copyright 2008, 2010, 2011, 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright 2008, 2010, 2011, 2017-2019 Albert Astals Cid <aacid at kde.org>
// Copyright 2008 Mark Kaplan <mkaplan at finjan.com>
// Copyright 2018 Adam Reichold <adam.reichold at t-online.de>
//
@@ -51,7 +51,7 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
break;
}
auto thisOptionalContentGroup = std::make_unique<OptionalContentGroup>(ocg.getDict());
- ocg = ocgList.arrayGetNF(i);
+ ocg = ocgList.arrayGetNF(i).copy();
if (!ocg.isRef()) {
break;
}
@@ -79,7 +79,7 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
if (on.isArray()) {
// ON is an optional element
for (int i = 0; i < on.arrayGetLength(); ++i) {
- Object reference = on.arrayGetNF(i);
+ const Object &reference = on.arrayGetNF(i);
if (!reference.isRef()) {
// there can be null entries
break;
@@ -97,7 +97,7 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
if (off.isArray()) {
// OFF is an optional element
for (int i = 0; i < off.arrayGetLength(); ++i) {
- Object reference = off.arrayGetNF(i);
+ const Object &reference = off.arrayGetNF(i);
if (!reference.isRef()) {
// there can be null entries
break;
@@ -217,7 +217,7 @@ bool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
Object op = expr2.arrayGet(0);
if (op.isName("Not")) {
if (expr2.arrayGetLength() == 2) {
- Object obj = expr2.arrayGetNF(1);
+ Object obj = expr2.arrayGetNF(1).copy();
ret = !evalOCVisibilityExpr(&obj, recursion + 1);
} else {
error(errSyntaxError, -1,
@@ -227,13 +227,13 @@ bool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
} else if (op.isName("And")) {
ret = true;
for (int i = 1; i < expr2.arrayGetLength() && ret; ++i) {
- Object obj = expr2.arrayGetNF(i);
+ Object obj = expr2.arrayGetNF(i).copy();
ret = evalOCVisibilityExpr(&obj, recursion + 1);
}
} else if (op.isName("Or")) {
ret = false;
for (int i = 1; i < expr2.arrayGetLength() && !ret; ++i) {
- Object obj = expr2.arrayGetNF(i);
+ Object obj = expr2.arrayGetNF(i).copy();
ret = evalOCVisibilityExpr(&obj, recursion + 1);
}
} else {
@@ -247,7 +247,7 @@ bool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
bool OCGs::allOn( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
- Object ocgItem = ocgArray->getNF(i);
+ const Object &ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::Off ) {
@@ -261,7 +261,7 @@ bool OCGs::allOn( Array *ocgArray )
bool OCGs::allOff( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
- Object ocgItem = ocgArray->getNF(i);
+ const Object &ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::On ) {
@@ -275,7 +275,7 @@ bool OCGs::allOff( Array *ocgArray )
bool OCGs::anyOn( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
- Object ocgItem = ocgArray->getNF(i);
+ const Object &ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::On ) {
@@ -289,7 +289,7 @@ bool OCGs::anyOn( Array *ocgArray )
bool OCGs::anyOff( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
- Object ocgItem = ocgArray->getNF(i);
+ const Object &ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::Off ) {
@@ -399,7 +399,7 @@ OCDisplayNode *OCDisplayNode::parse(Object *obj, OCGs *oc,
node = new OCDisplayNode();
}
for (; i < obj2.arrayGetLength(); ++i) {
- Object obj3 = obj2.arrayGetNF(i);
+ Object obj3 = obj2.arrayGetNF(i).copy();
if ((child = OCDisplayNode::parse(&obj3, oc, xref, recursion + 1))) {
if (!child->ocg && !child->name && node->getNumChildren() > 0) {
node->getChild(node->getNumChildren() - 1)->addChildren(child->takeChildren());
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 5cbeeb53..65267116 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -975,7 +975,7 @@ int PDFDoc::savePageAs(const GooString *name, int pageNo)
strcmp(key, "Pages") != 0)
{
if (j > 0) outStr->printf(" ");
- Object value = catDict->getValNF(j);
+ Object value = catDict->getValNF(j).copy();
outStr->printf("/%s ", key);
writeObject(&value, outStr, getXRef(), 0, nullptr, cryptRC4, 0, 0, 0);
}
@@ -998,7 +998,7 @@ int PDFDoc::savePageAs(const GooString *name, int pageNo)
for (int n = 0; n < pageDict->getLength(); n++) {
if (n > 0) outStr->printf(" ");
const char *key = pageDict->getKey(n);
- Object value = pageDict->getValNF(n);
+ Object value = pageDict->getValNF(n).copy();
if (strcmp(key, "Parent") == 0) {
outStr->printf("/Parent %d 0 R", rootNum + 1);
} else {
@@ -1253,7 +1253,7 @@ void PDFDoc::writeDictionnary (Dict* dict, OutStream* outStr, XRef *xRef, unsign
GooString *keyNameToPrint = keyName.sanitizedName(false /* non ps mode */);
outStr->printf("/%s ", keyNameToPrint->c_str());
delete keyNameToPrint;
- Object obj1 = dict->getValNF(i);
+ Object obj1 = dict->getValNF(i).copy();
writeObject(&obj1, outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen, alreadyWrittenDicts);
}
outStr->printf(">> ");
@@ -1403,7 +1403,7 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i
array = obj->getArray();
outStr->printf("[");
for (int i=0; i<array->getLength(); i++) {
- Object obj1 = array->getNF(i);
+ Object obj1 = array->getNF(i).copy();
writeObject(&obj1, outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen);
}
outStr->printf("] ");
@@ -1673,10 +1673,10 @@ void PDFDoc::markDictionnary (Dict* dict, XRef * xRef, XRef *countRef, unsigned
for (int i=0; i<dict->getLength(); i++) {
const char *key = dict->getKey(i);
if (strcmp(key, "Annots") != 0) {
- Object obj1 = dict->getValNF(i);
+ Object obj1 = dict->getValNF(i).copy();
markObject(&obj1, xRef, countRef, numOffset, oldRefNum, newRefNum, alreadyMarkedDicts);
} else {
- Object annotsObj = dict->getValNF(i);
+ Object annotsObj = dict->getValNF(i).copy();
if (!annotsObj.isNull()) {
markAnnotations(&annotsObj, xRef, countRef, 0, oldRefNum, newRefNum, alreadyMarkedDicts);
}
@@ -1696,7 +1696,7 @@ void PDFDoc::markObject (Object* obj, XRef *xRef, XRef *countRef, unsigned int n
case objArray:
array = obj->getArray();
for (int i=0; i<array->getLength(); i++) {
- Object obj1 = array->getNF(i);
+ Object obj1 = array->getNF(i).copy();
markObject(&obj1, xRef, countRef, numOffset, oldRefNum, newRefNum);
}
break;
@@ -1784,7 +1784,7 @@ void PDFDoc::markPageObjects(Dict *pageDict, XRef *xRef, XRef *countRef, unsigne
for (int n = 0; n < pageDict->getLength(); n++) {
const char *key = pageDict->getKey(n);
- Object value = pageDict->getValNF(n);
+ Object value = pageDict->getValNF(n).copy();
if (strcmp(key, "Parent") != 0 &&
strcmp(key, "Pages") != 0 &&
strcmp(key, "AcroForm") != 0 &&
@@ -1810,7 +1810,7 @@ bool PDFDoc::markAnnotations(Object *annotsObj, XRef *xRef, XRef *countRef, unsi
Object obj2 = dict->lookupNF("P");
if (obj2.isRef()) {
if (obj2.getRef().num == oldPageNum) {
- Object obj3 = array->getNF(i);
+ const Object &obj3 = array->getNF(i);
if (obj3.isRef()) {
Ref r;
r.num = newPageNum;
@@ -1837,7 +1837,7 @@ bool PDFDoc::markAnnotations(Object *annotsObj, XRef *xRef, XRef *countRef, unsi
}
markPageObjects(dict, xRef, countRef, numOffset, oldPageNum, newPageNum, alreadyMarkedDicts);
}
- obj1 = array->getNF(i);
+ obj1 = array->getNF(i).copy();
if (obj1.isRef()) {
if (obj1.getRef().num + (int) numOffset >= xRef->getNumObjects() || xRef->getEntry(obj1.getRef().num + numOffset)->type == xrefEntryFree) {
if (getXRef()->getEntry(obj1.getRef().num)->type == xrefEntryFree) {
@@ -1889,10 +1889,10 @@ void PDFDoc::markAcroForm(Object *afObj, XRef *xRef, XRef *countRef, unsigned in
Dict *dict = acroform.getDict();
for (int i=0; i < dict->getLength(); i++) {
if (strcmp(dict->getKey(i), "Fields") == 0) {
- Object fields = dict->getValNF(i);
+ Object fields = dict->getValNF(i).copy();
modified = markAnnotations(&fields, xRef, countRef, numOffset, oldRefNum, newRefNum);
} else {
- Object obj = dict->getValNF(i);
+ Object obj = dict->getValNF(i).copy();
markObject(&obj, xRef, countRef, numOffset, oldRefNum, newRefNum);
}
}
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 5f1db1f5..32f11fce 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -1791,7 +1791,7 @@ void PSOutputDev::setupResources(Dict *resDict) {
// avoid infinite recursion on XObjects
skip = false;
- Object xObjRef = xObjDict.dictGetValNF(i);
+ const Object &xObjRef = xObjDict.dictGetValNF(i);
if (xObjRef.isRef()) {
Ref ref0 = xObjRef.getRef();
if (resourceIDs.find(ref0.num) != resourceIDs.end()) {
@@ -1822,7 +1822,7 @@ void PSOutputDev::setupResources(Dict *resDict) {
// avoid infinite recursion on Patterns
skip = false;
- Object patRef = patDict.dictGetValNF(i);
+ const Object &patRef = patDict.dictGetValNF(i);
if (patRef.isRef()) {
Ref ref0 = patRef.getRef();
if (resourceIDs.find(ref0.num) != resourceIDs.end()) {
@@ -2893,7 +2893,7 @@ void PSOutputDev::setupImages(Dict *resDict) {
Object xObjDict = resDict->lookup("XObject");
if (xObjDict.isDict()) {
for (int i = 0; i < xObjDict.dictGetLength(); ++i) {
- Object xObjRef = xObjDict.dictGetValNF(i);
+ const Object &xObjRef = xObjDict.dictGetValNF(i);
Object xObj = xObjDict.dictGetVal(i);
if (xObj.isStream()) {
Object subtypeObj = xObj.streamGetDict()->lookup("Subtype");
@@ -3110,7 +3110,7 @@ void PSOutputDev::setupForms(Dict *resDict) {
Object xObjDict = resDict->lookup("XObject");
if (xObjDict.isDict()) {
for (int i = 0; i < xObjDict.dictGetLength(); ++i) {
- Object xObjRef = xObjDict.dictGetValNF(i);
+ const Object &xObjRef = xObjDict.dictGetValNF(i);
Object xObj = xObjDict.dictGetVal(i);
if (xObj.isStream()) {
Object subtypeObj = xObj.streamGetDict()->lookup("Subtype");
diff --git a/poppler/Page.cc b/poppler/Page.cc
index 775c1a51..33c624f0 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -423,7 +423,7 @@ void Page::removeAnnot(Annot *annot) {
int idx = -1;
// Get annotation position
for (int i = 0; idx == -1 && i < annArray.arrayGetLength(); ++i) {
- Object tmp = annArray.arrayGetNF(i);
+ const Object &tmp = annArray.arrayGetNF(i);
if (tmp.isRef()) {
Ref currAnnot = tmp.getRef();
if (currAnnot.num == annotRef.num && currAnnot.gen == annotRef.gen) {
diff --git a/poppler/StructElement.cc b/poppler/StructElement.cc
index d65abe74..250a1d38 100644
--- a/poppler/StructElement.cc
+++ b/poppler/StructElement.cc
@@ -6,7 +6,7 @@
//
// Copyright 2013, 2014 Igalia S.L.
// Copyright 2014 Luigi Scarso <luigi.scarso at gmail.com>
-// Copyright 2014, 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright 2014, 2017-2019 Albert Astals Cid <aacid at kde.org>
// Copyright 2015 Dmytro Morgun <lztoad at gmail.com>
// Copyright 2018 Adrian Johnson <ajohnson at redneon.com>
// Copyright 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
@@ -1255,7 +1255,7 @@ void StructElement::parseChildren(Dict *element, std::set<int> &seen)
if (kids.isArray()) {
for (int i = 0; i < kids.arrayGetLength(); i++) {
Object obj = kids.arrayGet(i);
- Object ref = kids.arrayGetNF(i);
+ Object ref = kids.arrayGetNF(i).copy();
parseChild(&ref, &obj, seen);
}
} else if (kids.isDict() || kids.isInt()) {
diff --git a/poppler/StructTreeRoot.cc b/poppler/StructTreeRoot.cc
index d23ad4d3..099bf62f 100644
--- a/poppler/StructTreeRoot.cc
+++ b/poppler/StructTreeRoot.cc
@@ -7,7 +7,7 @@
// Copyright 2013, 2014 Igalia S.L.
// Copyright 2014 Fabio D'Urso <fabiodurso at hotmail.it>
// Copyright 2017 Jan-Erik S <janerik234678 at gmail.com>
-// Copyright 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright 2017-2019 Albert Astals Cid <aacid at kde.org>
// Copyright 2017, 2018 Adrian Johnson <ajohnson at redneon.com>
// Copyright 2018, Adam Reichold <adam.reichold at t-online.de>
//
@@ -65,7 +65,7 @@ void StructTreeRoot::parse(Dict *root)
error(errSyntaxWarning, -1, "K in StructTreeRoot has more than one children in a tagged PDF");
}
for (int i = 0; i < kids.arrayGetLength(); i++) {
- Object ref = kids.arrayGetNF(i);
+ const Object &ref = kids.arrayGetNF(i);
if (ref.isRef()) {
seenElements.insert(ref.getRefNum());
}
@@ -145,7 +145,7 @@ void StructTreeRoot::parseNumberTreeNode(Dict *node)
if (value.isArray()) {
vec.resize(value.arrayGetLength());
for (int j = 0; j < value.arrayGetLength(); j++) {
- Object itemvalue = value.arrayGetNF(j);
+ const Object &itemvalue = value.arrayGetNF(j);
if (itemvalue.isRef()) {
Ref ref = itemvalue.getRef();
vec[j].ref = ref;
@@ -155,7 +155,7 @@ void StructTreeRoot::parseNumberTreeNode(Dict *node)
}
}
} else {
- value = nums.arrayGetNF(i + 1);
+ value = nums.arrayGetNF(i + 1).copy();
if (value.isRef()) {
Ref ref = value.getRef();
vec.resize(1);
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 44e7ccac..4679da96 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -1617,7 +1617,7 @@ void XRef::markUnencrypted(Object *obj) {
{
Array *array = obj->getArray();
for (int i = 0; i < array->getLength(); i++) {
- obj1 = array->getNF(i);
+ obj1 = array->getNF(i).copy();
markUnencrypted(&obj1);
}
break;
@@ -1633,7 +1633,7 @@ void XRef::markUnencrypted(Object *obj) {
dict = obj->getDict();
}
for (int i = 0; i < dict->getLength(); i++) {
- obj1 = dict->getValNF(i);
+ obj1 = dict->getValNF(i).copy();
markUnencrypted(&obj1);
}
break;
diff --git a/qt5/src/poppler-optcontent.cc b/qt5/src/poppler-optcontent.cc
index 9d8bf7cb..ac1c61fe 100644
--- a/qt5/src/poppler-optcontent.cc
+++ b/qt5/src/poppler-optcontent.cc
@@ -3,7 +3,7 @@
* Copyright (C) 2007, Brad Hards <bradh at kde.org>
* Copyright (C) 2008, 2014, Pino Toscano <pino at kde.org>
* Copyright (C) 2008, Carlos Garcia Campos <carlosgc at gnome.org>
- * Copyright (C) 2015-2018, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2015-2019, Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2017, Hubert Figuière <hub at figuiere.net>
* Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
* Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
@@ -43,7 +43,7 @@ namespace Poppler
{
itemsInGroup.reserve(rbarray->getLength());
for (int i = 0; i < rbarray->getLength(); ++i) {
- Object ref = rbarray->getNF( i );
+ const Object &ref = rbarray->getNF( i );
if ( ! ref.isRef() ) {
qDebug() << "expected ref, but got:" << ref.getType();
}
@@ -201,7 +201,7 @@ namespace Poppler
for (int i = 0; i < orderArray->getLength(); ++i) {
Object orderItem = orderArray->get(i);
if ( orderItem.isDict() ) {
- Object item = orderArray->getNF(i);
+ const Object &item = orderArray->getNF(i);
if (item.isRef() ) {
OptContentItem *ocItem = m_optContentItems.value(QString::number(item.getRefNum()));
if (ocItem) {
diff --git a/test/pdf-fullrewrite.cc b/test/pdf-fullrewrite.cc
index 94f39b3c..d9b8ac3e 100644
--- a/test/pdf-fullrewrite.cc
+++ b/test/pdf-fullrewrite.cc
@@ -125,8 +125,8 @@ static bool compareDictionaries(Dict *dictA, Dict *dictB)
* in dictB is also contained in dictA */
for (int i = 0; i < length; ++i) {
const char *key = dictA->getKey(i);
- Object valA = dictA->getValNF(i);
- Object valB = dictB->lookupNF(key);
+ Object valA = dictA->getValNF(i).copy();
+ Object valB = dictB->lookupNF(key).copy();
if (!compareObjects(&valA, &valB))
return false;
}
@@ -197,8 +197,8 @@ static bool compareObjects(Object *objA, Object *objB)
return false;
} else {
for (int i = 0; i < length; ++i) {
- Object elemA = arrayA->getNF(i);
- Object elemB = arrayB->getNF(i);
+ Object elemA = arrayA->getNF(i).copy();
+ Object elemB = arrayB->getNF(i).copy();
if (!compareObjects(&elemA, &elemB)) {
return false;
}
diff --git a/utils/pdfunite.cc b/utils/pdfunite.cc
index 73f416e3..4505f875 100644
--- a/utils/pdfunite.cc
+++ b/utils/pdfunite.cc
@@ -47,12 +47,12 @@ static void doMergeNameTree(PDFDoc *doc, XRef *srcXRef, XRef *countRef, int oldR
Array *newNameArray = new Array(srcXRef);
int j = 0;
for (int i = 0; i < srcNameArray.arrayGetLength() - 1; i += 2) {
- Object key = srcNameArray.arrayGetNF(i);
- Object value = srcNameArray.arrayGetNF(i + 1);
+ const Object &key = srcNameArray.arrayGetNF(i);
+ const Object &value = srcNameArray.arrayGetNF(i + 1);
if (key.isString() && value.isRef()) {
while (j < mergeNameArray.arrayGetLength() - 1) {
- Object mkey = mergeNameArray.arrayGetNF(j);
- Object mvalue = mergeNameArray.arrayGetNF(j + 1);
+ const Object &mkey = mergeNameArray.arrayGetNF(j);
+ const Object &mvalue = mergeNameArray.arrayGetNF(j + 1);
if (mkey.isString() && mvalue.isRef()) {
if (mkey.getString()->cmp(key.getString()) < 0) {
newNameArray->add(Object(new GooString(mkey.getString()->c_str())));
@@ -72,8 +72,8 @@ static void doMergeNameTree(PDFDoc *doc, XRef *srcXRef, XRef *countRef, int oldR
}
}
while (j < mergeNameArray.arrayGetLength() - 1) {
- Object mkey = mergeNameArray.arrayGetNF(j);
- Object mvalue = mergeNameArray.arrayGetNF(j + 1);
+ const Object &mkey = mergeNameArray.arrayGetNF(j);
+ const Object &mvalue = mergeNameArray.arrayGetNF(j + 1);
if (mkey.isString() && mvalue.isRef()) {
newNameArray->add(Object(new GooString(mkey.getString()->c_str())));
newNameArray->add(Object( { mvalue.getRef().num + numOffset, mvalue.getRef().gen } ));
@@ -85,8 +85,8 @@ static void doMergeNameTree(PDFDoc *doc, XRef *srcXRef, XRef *countRef, int oldR
} else if (srcNameArray.isNull() && mergeNameArray.isArray()) {
Array *newNameArray = new Array(srcXRef);
for (int i = 0; i < mergeNameArray.arrayGetLength() - 1; i += 2) {
- Object key = mergeNameArray.arrayGetNF(i);
- Object value = mergeNameArray.arrayGetNF(i + 1);
+ const Object &key = mergeNameArray.arrayGetNF(i);
+ const Object &value = mergeNameArray.arrayGetNF(i + 1);
if (key.isString() && value.isRef()) {
newNameArray->add(Object(new GooString(key.getString()->c_str())));
newNameArray->add(Object( { value.getRef().num + numOffset, value.getRef().gen } ));
@@ -117,7 +117,7 @@ static void doMergeFormDict(Dict *srcFormDict, Dict *mergeFormDict, int numOffse
Object mergeFields = mergeFormDict->lookup("Fields");
if (srcFields.isArray() && mergeFields.isArray()) {
for (int i = 0; i < mergeFields.arrayGetLength(); i++) {
- Object value = mergeFields.arrayGetNF(i);
+ const Object &value = mergeFields.arrayGetNF(i);
srcFields.arrayAdd(Object( { value.getRef().num + numOffset, value.getRef().gen } ));
}
}
@@ -372,7 +372,7 @@ int main (int argc, char *argv[])
if (j > 0)
outStr->printf(" ");
const char *key = pageDict->getKey(j);
- Object value = pageDict->getValNF(j);
+ Object value = pageDict->getValNF(j).copy();
if (strcmp(key, "Parent") == 0) {
outStr->printf("/Parent %d 0 R", rootNum + 1);
} else {
More information about the poppler
mailing list