Commit 49ecbd59 authored by Albert Astals Cid's avatar Albert Astals Cid

Change Dict::lookupNF return a const &

Saves some copy()
parent 099a09c5
......@@ -891,22 +891,22 @@ Object AnnotAppearance::getAppearanceStream(AnnotAppearanceType type, const char
// Obtain dictionary or stream associated to appearance type
switch (type) {
case appearRollover:
apData = appearDict.dictLookupNF("R");
apData = appearDict.dictLookupNF("R").copy();
if (apData.isNull())
apData = appearDict.dictLookupNF("N");
apData = appearDict.dictLookupNF("N").copy();
break;
case appearDown:
apData = appearDict.dictLookupNF("D");
apData = appearDict.dictLookupNF("D").copy();
if (apData.isNull())
apData = appearDict.dictLookupNF("N");
apData = appearDict.dictLookupNF("N").copy();
break;
case appearNormal:
apData = appearDict.dictLookupNF("N");
apData = appearDict.dictLookupNF("N").copy();
break;
}
if (apData.isDict() && state)
return apData.dictLookupNF(state);
return apData.dictLookupNF(state).copy();
else if (apData.isRef())
return apData;
......@@ -914,7 +914,7 @@ Object AnnotAppearance::getAppearanceStream(AnnotAppearanceType type, const char
}
std::unique_ptr<GooString> AnnotAppearance::getStateKey(int i) {
Object obj1 = appearDict.dictLookupNF("N");
const Object &obj1 = appearDict.dictLookupNF("N");
if (obj1.isDict())
return std::make_unique<GooString>(obj1.dictGetKey(i));
return nullptr;
......@@ -922,7 +922,7 @@ std::unique_ptr<GooString> AnnotAppearance::getStateKey(int i) {
int AnnotAppearance::getNumStates() {
int res = 0;
Object obj1 = appearDict.dictLookupNF("N");
const Object &obj1 = appearDict.dictLookupNF("N");
if (obj1.isDict())
res = obj1.dictGetLength();
return res;
......@@ -956,17 +956,17 @@ bool AnnotAppearance::referencesStream(Ref refToStream) {
bool found;
// Scan each state's ref/subdictionary
obj1 = appearDict.dictLookupNF("N");
obj1 = appearDict.dictLookupNF("N").copy();
found = referencesStream(&obj1, refToStream);
if (found)
return true;
obj1 = appearDict.dictLookupNF("R");
obj1 = appearDict.dictLookupNF("R").copy();
found = referencesStream(&obj1, refToStream);
if (found)
return true;
obj1 = appearDict.dictLookupNF("D");
obj1 = appearDict.dictLookupNF("D").copy();
found = referencesStream(&obj1, refToStream);
return found;
}
......@@ -1011,11 +1011,11 @@ void AnnotAppearance::removeStateStreams(Object *obj1) {
void AnnotAppearance::removeAllStreams() {
Object obj1;
obj1 = appearDict.dictLookupNF("N");
obj1 = appearDict.dictLookupNF("N").copy();
removeStateStreams(&obj1);
obj1 = appearDict.dictLookupNF("R");
obj1 = appearDict.dictLookupNF("R").copy();
removeStateStreams(&obj1);
obj1 = appearDict.dictLookupNF("D");
obj1 = appearDict.dictLookupNF("D").copy();
removeStateStreams(&obj1);
}
......@@ -1226,7 +1226,7 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
}
// Note: This value is overwritten by Annots ctor
obj1 = dict->lookupNF("P");
obj1 = dict->lookupNF("P").copy();
if (obj1.isRef()) {
Ref ref = obj1.getRef();
......@@ -1303,7 +1303,7 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
treeKey = 0;
}
oc = dict->lookupNF("OC");
oc = dict->lookupNF("OC").copy();
}
void Annot::getRect(double *x1, double *y1, double *x2, double *y2) const {
......@@ -1866,7 +1866,7 @@ AnnotPopup::~AnnotPopup() {
}
void AnnotPopup::initialize(PDFDoc *docA, Dict *dict) {
parent = dict->lookupNF("Parent");
parent = dict->lookupNF("Parent").copy();
if (!parent.isRef()) {
parent.setToNull();
}
......@@ -1905,7 +1905,7 @@ AnnotMarkup::AnnotMarkup(PDFDoc *docA, Object &&dictObject, const Object *obj) :
AnnotMarkup::~AnnotMarkup() = default;
void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict) {
Object obj1, obj2;
Object obj1;
obj1 = dict->lookup("T");
if (obj1.isString()) {
......@@ -1913,7 +1913,7 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict) {
}
Object popupObj = dict->lookup("Popup");
obj2 = dict->lookupNF("Popup");
const Object &obj2 = dict->lookupNF("Popup");
if (popupObj.isDict() && obj2.isRef()) {
popup = std::make_unique<AnnotPopup>(docA, std::move(popupObj), &obj2);
}
......@@ -1930,7 +1930,7 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict) {
date.reset(obj1.getString()->copy());
}
obj1 = dict->lookupNF("IRT");
obj1 = dict->lookupNF("IRT").copy();
if (obj1.isRef()) {
inReplyTo = obj1.getRef();
} else {
......@@ -2825,7 +2825,7 @@ 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());
Object fontDictionary = fontResources.getDict()->lookupNF(da.getFontName().getName()).copy();
// Resolve reference, if necessary
Ref fontReference = {-1, -1};
......@@ -3760,7 +3760,7 @@ void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) {
action.reset(LinkAction::parseAction(&obj1, doc->getCatalog()->getBaseURI()));
}
additionalActions = dict->lookupNF("AA");
additionalActions = dict->lookupNF("AA").copy();
obj1 = dict->lookup("Parent");
if (obj1.isDict()) {
......@@ -5132,7 +5132,7 @@ void AnnotScreen::initialize(PDFDoc *docA, Dict* dict) {
}
}
additionalActions = dict->lookupNF("AA");
additionalActions = dict->lookupNF("AA").copy();
obj1 = dict->lookup("MK");
if (obj1.isDict()) {
......
......@@ -120,7 +120,7 @@ Catalog::Catalog(PDFDoc *docA) {
}
// actions
additionalActions = catDict.dictLookupNF("AA");
additionalActions = catDict.dictLookupNF("AA").copy();
// get the ViewerPreferences dictionary
viewerPreferences = catDict.dictLookup("ViewerPreferences");
......@@ -213,7 +213,7 @@ bool Catalog::cachePageTree(int page)
Object catDict = xref->getCatalog();
if (catDict.isDict()) {
Object pagesDictRef = catDict.dictLookupNF("Pages");
const Object &pagesDictRef = catDict.dictLookupNF("Pages");
if (pagesDictRef.isRef() &&
pagesDictRef.getRefNum() >= 0 &&
pagesDictRef.getRefNum() < xref->getNumObjects()) {
......@@ -732,7 +732,7 @@ int Catalog::getNumPages()
// some PDF files actually use real numbers here ("/Count 9.0")
if (!obj.isNum()) {
if (pagesDict.dictIs("Page")) {
Object pageRootRef = catDict.dictLookupNF("Pages");
const Object &pageRootRef = catDict.dictLookupNF("Pages");
error(errSyntaxError, -1, "Pages top-level is a single Page. The document is malformed, trying to recover...");
......
......@@ -16,7 +16,7 @@
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
// Copyright (C) 2007-2008 Julien Rebetez <julienr@svn.gnome.org>
// Copyright (C) 2008, 2010, 2013, 2014, 2017 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2008, 2010, 2013, 2014, 2017, 2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Paweł Wiejacha <pawel.wiejacha@gmail.com>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
......@@ -168,11 +168,12 @@ Object Dict::lookup(const char *key, int recursion) const {
return Object(objNull);
}
Object Dict::lookupNF(const char *key) const {
const Object &Dict::lookupNF(const char *key) const {
if (const auto *entry = find(key)) {
return entry->second.copy();
return entry->second;
}
return Object(objNull);
static Object nullObj(objNull);
return nullObj;
}
bool Dict::lookupInt(const char *key, const char *alt_key, int *value) const
......
......@@ -76,7 +76,7 @@ public:
// Look up an entry and return the value. Returns a null object
// if <key> is not in the dictionary.
Object lookup(const char *key, int recursion = 0) const;
Object lookupNF(const char *key) const;
const Object &lookupNF(const char *key) const;
bool lookupInt(const char *key, const char *alt_key, int *value) const;
// Iterative accessors.
......
......@@ -7,7 +7,7 @@
//
// Copyright (C) 2008-2009 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net>
// Copyright (C) 2012, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2012, 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2012 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
......@@ -127,7 +127,7 @@ FileSpec::FileSpec(const Object *fileSpecA)
if (fileSpec.isDict()) {
obj1 = fileSpec.dictLookup("EF");
if (obj1.isDict()) {
fileStream = obj1.dictLookupNF("F");
fileStream = obj1.dictLookupNF("F").copy();
if (!fileStream.isRef()) {
ok = false;
fileStream.setToNull();
......
......@@ -99,7 +99,7 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, GooList *fontsList)
// scan the fonts in this resource dictionary
gfxFontDict = nullptr;
Object fontObj = resDict->lookupNF("Font");
const Object &fontObj = resDict->lookupNF("Font");
if (fontObj.isRef()) {
Object obj2 = fontObj.fetch(xrefA);
if (obj2.isDict()) {
......
......@@ -648,7 +648,7 @@ 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");
Object obj2 = childObj.dictLookupNF("Parent").copy();
Object obj3 = childObj.dictLookup("Parent");
if (obj2.isRef() || obj3.isDict()) {
// Child is a form field or composed dict
......@@ -1875,7 +1875,7 @@ static Object fieldLookup(Dict *field, const char *key, std::set<int> *usedParen
if (!obj.isNull()) {
return obj;
}
Object parent = dict->lookupNF("Parent");
const Object &parent = dict->lookupNF("Parent");
if (parent.isRef()) {
const Ref ref = parent.getRef();
if (usedParents->find(ref.num) == usedParents->end()) {
......
......@@ -317,7 +317,6 @@ static inline bool isSameGfxColor(const GfxColor &colorA, const GfxColor &colorB
GfxResources::GfxResources(XRef *xrefA, Dict *resDictA, GfxResources *nextA) :
gStateCache(2), xref(xrefA) {
Object obj1, obj2;
Ref r;
if (resDictA) {
......@@ -325,9 +324,9 @@ GfxResources::GfxResources(XRef *xrefA, Dict *resDictA, GfxResources *nextA) :
// build font dictionary
Dict *resDict = resDictA->copy(xref);
fonts = nullptr;
obj1 = resDict->lookupNF("Font");
const Object &obj1 = resDict->lookupNF("Font");
if (obj1.isRef()) {
obj2 = obj1.fetch(xref);
Object obj2 = obj1.fetch(xref);
if (obj2.isDict()) {
r = obj1.getRef();
fonts = new GfxFontDict(xref, &r, obj2.getDict());
......@@ -414,7 +413,7 @@ Object GfxResources::lookupXObjectNF(const char *name) {
for (resPtr = this; resPtr; resPtr = resPtr->next) {
if (resPtr->xObjDict.isDict()) {
Object obj = resPtr->xObjDict.dictLookupNF(name);
Object obj = resPtr->xObjDict.dictLookupNF(name).copy();
if (!obj.isNull())
return obj;
}
......@@ -428,7 +427,7 @@ Object GfxResources::lookupMarkedContentNF(const char *name) {
for (resPtr = this; resPtr; resPtr = resPtr->next) {
if (resPtr->propertiesDict.isDict()) {
Object obj = resPtr->propertiesDict.dictLookupNF(name);
Object obj = resPtr->propertiesDict.dictLookupNF(name).copy();
if (!obj.isNull())
return obj;
}
......@@ -457,7 +456,7 @@ GfxPattern *GfxResources::lookupPattern(const char *name, OutputDev *out, GfxSta
for (resPtr = this; resPtr; resPtr = resPtr->next) {
if (resPtr->patternDict.isDict()) {
Object obj = resPtr->patternDict.dictLookupNF(name);
Object obj = resPtr->patternDict.dictLookupNF(name).copy();
if (!obj.isNull()) {
Ref patternRef = { -1, -1 };
if (obj.isRef()) {
......@@ -515,7 +514,7 @@ Object GfxResources::lookupGStateNF(const char *name) {
for (resPtr = this; resPtr; resPtr = resPtr->next) {
if (resPtr->gStateDict.isDict()) {
Object obj = resPtr->gStateDict.dictLookupNF(name);
Object obj = resPtr->gStateDict.dictLookupNF(name).copy();
if (!obj.isNull()) {
return obj;
}
......@@ -4228,7 +4227,7 @@ void Gfx::doImage(Object *ref, Stream *str, bool inlineImg) {
// check for optional content key
if (ref) {
obj1 = dict->lookupNF("OC");
obj1 = dict->lookupNF("OC").copy();
if (catalog->getOptContentConfig() && !catalog->getOptContentConfig()->optContentIsVisible(&obj1)) {
return;
}
......@@ -4692,7 +4691,7 @@ void Gfx::doForm(Object *str) {
// check for optional content key
ocSaved = ocState;
obj1 = dict->lookupNF("OC");
obj1 = dict->lookupNF("OC").copy();
if (catalog->getOptContentConfig() && !catalog->getOptContentConfig()->optContentIsVisible(&obj1)) {
if (out->needCharCount()) {
ocState = false;
......
......@@ -341,14 +341,14 @@ GfxFontType GfxFont::getFontType(XRef *xref, Dict *fontDict, Ref *embID) {
Object fontDesc = fontDict2->lookup("FontDescriptor");
if (fontDesc.isDict()) {
Object obj3 = fontDesc.dictLookupNF("FontFile");
Object obj3 = fontDesc.dictLookupNF("FontFile").copy();
if (obj3.isRef()) {
*embID = obj3.getRef();
if (expectedType != fontType1) {
err = true;
}
}
if (embID->num == -1 && (obj3 = fontDesc.dictLookupNF("FontFile2"), obj3.isRef())) {
if (embID->num == -1 && (obj3 = fontDesc.dictLookupNF("FontFile2").copy(), obj3.isRef())) {
*embID = obj3.getRef();
if (isType0) {
expectedType = fontCIDType2;
......@@ -356,7 +356,7 @@ GfxFontType GfxFont::getFontType(XRef *xref, Dict *fontDict, Ref *embID) {
err = true;
}
}
if (embID->num == -1 && (obj3 = fontDesc.dictLookupNF("FontFile3"), obj3.isRef())) {
if (embID->num == -1 && (obj3 = fontDesc.dictLookupNF("FontFile3").copy(), obj3.isRef())) {
*embID = obj3.getRef();
Object obj4 = obj3.fetch(xref);
if (obj4.isStream()) {
......@@ -1684,7 +1684,7 @@ Object Gfx8BitFont::getCharProc(int code) {
Object Gfx8BitFont::getCharProcNF(int code) {
if (enc[code] && charProcs.isDict()) {
return charProcs.dictLookupNF(enc[code]);
return charProcs.dictLookupNF(enc[code]).copy();
} else {
return Object(objNull);
}
......
......@@ -163,7 +163,7 @@ LinkAction *LinkAction::parseAction(const Object *obj, const GooString *baseURI,
// Prevent circles in the tree by checking the ref against used refs in
// our current tree branch.
const Object nextRefObj = obj->dictLookupNF("Next");
const Object &nextRefObj = obj->dictLookupNF("Next");
if (nextRefObj.isRef()) {
const Ref ref = nextRefObj.getRef();
if (!seenNextActions->insert(ref.num).second) {
......@@ -637,7 +637,7 @@ LinkMovie::LinkMovie(const Object *obj) {
annotRef.num = -1;
annotTitle = nullptr;
Object tmp = obj->dictLookupNF("Annotation");
Object tmp = obj->dictLookupNF("Annotation").copy();
if (tmp.isRef()) {
annotRef = tmp.getRef();
}
......@@ -758,7 +758,7 @@ LinkRendition::LinkRendition(const Object *obj) {
renditionObj.setToNull();
}
screenRef = obj->dictLookupNF("AN");
screenRef = obj->dictLookupNF("AN").copy();
if (!screenRef.isRef() && operation >= 0 && operation <= 4) {
error(errSyntaxWarning, -1, "Invalid Rendition Action: no AN field with op = {0:d}", operationCode);
screenRef.setToNull();
......
......@@ -6,7 +6,7 @@
// Hugo Mercier <hmercier31[at]gmail.com> (c) 2008
// Pino Toscano <pino@kde.org> (c) 2008
// Carlos Garcia Campos <carlosgc@gnome.org> (c) 2010
// Albert Astals Cid <aacid@kde.org> (c) 2010, 2017, 2018
// Albert Astals Cid <aacid@kde.org> (c) 2010, 2017-2019
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
......@@ -213,7 +213,7 @@ void Movie::parseMovie (const Object *movieDict) {
//
// movie poster
//
poster = movieDict->dictLookupNF("Poster");
poster = movieDict->dictLookupNF("Poster").copy();
if (!poster.isNull()) {
if (poster.isRef() || poster.isStream()) {
showPoster = true;
......
......@@ -280,7 +280,7 @@ public:
void dictRemove(const char *key);
bool dictIs(const char *dictType) const;
Object dictLookup(const char *key, int recursion = 0) const;
Object dictLookupNF(const char *key) const;
const Object &dictLookupNF(const char *key) const;
const char *dictGetKey(int i) const;
Object dictGetVal(int i) const;
const Object &dictGetValNF(int i) const;
......@@ -368,7 +368,7 @@ inline bool Object::isDict(const char *dictType) const
inline Object Object::dictLookup(const char *key, int recursion) const
{ OBJECT_TYPE_CHECK(objDict); return dict->lookup(key, recursion); }
inline Object Object::dictLookupNF(const char *key) const
inline const Object &Object::dictLookupNF(const char *key) const
{ OBJECT_TYPE_CHECK(objDict); return dict->lookupNF(key); }
inline const char *Object::dictGetKey(int i) const
......
......@@ -163,7 +163,7 @@ bool OCGs::optContentIsVisible( Object *dictRef )
if (ve.isArray()) {
result = evalOCVisibilityExpr(&ve, 0);
} else {
Object ocg = dict->lookupNF("OCGs");
const Object &ocg = dict->lookupNF("OCGs");
if (ocg.isArray()) {
Object policy = dict->lookup("P");
if (policy.isName("AllOn")) {
......
......@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com>
// Copyright (C) 2008, 2016-2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2008, 2016-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Nick Jones <nick.jones@network-box.com>
// Copyright (C) 2016 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
......@@ -44,7 +44,7 @@ Outline::Outline(const Object *outlineObj, XRef *xref) {
if (!outlineObj->isDict()) {
return;
}
Object first = outlineObj->dictLookupNF("First");
const Object &first = outlineObj->dictLookupNF("First");
items = OutlineItem::readItemList(nullptr, &first, xref);
}
......@@ -85,9 +85,9 @@ OutlineItem::OutlineItem(const Dict *dict, int refNumA, OutlineItem *parentA, XR
}
}
firstRef = dict->lookupNF("First");
lastRef = dict->lookupNF("Last");
nextRef = dict->lookupNF("Next");
firstRef = dict->lookupNF("First").copy();
lastRef = dict->lookupNF("Last").copy();
nextRef = dict->lookupNF("Next").copy();
startsOpen = false;
obj1 = dict->lookup("Count");
......
......@@ -925,7 +925,7 @@ int PDFDoc::savePageAs(const GooString *name, int pageNo)
markPageObjects(infoDict, yRef, countRef, 0, refPage->num, rootNum + 2);
if (trailerObj->isDict()) {
Dict *trailerDict = trailerObj->getDict();
Object ref = trailerDict->lookupNF("Info");
const Object &ref = trailerDict->lookupNF("Info");
if (ref.isRef()) {
yRef->add(ref.getRef().num, ref.getRef().gen, 0, true);
if (getXRef()->getEntry(ref.getRef().num)->type == xrefEntryCompressed) {
......@@ -939,7 +939,7 @@ int PDFDoc::savePageAs(const GooString *name, int pageNo)
Object catObj = getXRef()->getCatalog();
Dict *catDict = catObj.getDict();
Object pagesObj = catDict->lookup("Pages");
Object afObj = catDict->lookupNF("AcroForm");
Object afObj = catDict->lookupNF("AcroForm").copy();
if (!afObj.isNull()) {
markAcroForm(&afObj, yRef, countRef, 0, refPage->num, rootNum + 2);
}
......@@ -958,7 +958,7 @@ int PDFDoc::savePageAs(const GooString *name, int pageNo)
}
}
markPageObjects(pageDict, yRef, countRef, 0, refPage->num, rootNum + 2);
Object annotsObj = pageDict->lookupNF("Annots");
Object annotsObj = pageDict->lookupNF("Annots").copy();
if (!annotsObj.isNull()) {
markAnnotations(&annotsObj, yRef, countRef, 0, refPage->num, rootNum + 2);
}
......@@ -1550,7 +1550,7 @@ Object PDFDoc::createTrailerDict(int uxrefSize, bool incrUpdate, Goffset startxR
bool hasEncrypt = false;
if (!xRef->getTrailerDict()->isNone()) {
Object obj2 = xRef->getTrailerDict()->dictLookupNF("Encrypt");
Object obj2 = xRef->getTrailerDict()->dictLookupNF("Encrypt").copy();
if (!obj2.isNull()) {
trailerDict->set("Encrypt", std::move(obj2));
hasEncrypt = true;
......@@ -1807,7 +1807,7 @@ bool PDFDoc::markAnnotations(Object *annotsObj, XRef *xRef, XRef *countRef, unsi
Dict *dict = obj1.getDict();
Object type = dict->lookup("Type");
if (type.isName() && strcmp(type.getName(), "Annot") == 0) {
Object obj2 = dict->lookupNF("P");
const Object &obj2 = dict->lookupNF("P");
if (obj2.isRef()) {
if (obj2.getRef().num == oldPageNum) {
const Object &obj3 = array->getNF(i);
......
......@@ -1854,7 +1854,7 @@ void PSOutputDev::setupFonts(Dict *resDict) {
int i;
gfxFontDict = nullptr;
Object obj1 = resDict->lookupNF("Font");
const Object &obj1 = resDict->lookupNF("Font");
if (obj1.isRef()) {
Object obj2 = obj1.fetch(xref);
if (obj2.isDict()) {
......
......@@ -258,7 +258,7 @@ Page::Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *a
attrs->clipBoxes();
// transtion
trans = pageObj.dictLookupNF("Trans");
trans = pageObj.dictLookupNF("Trans").copy();
if (!(trans.isRef() || trans.isDict() || trans.isNull())) {
error(errSyntaxError, -1, "Page transition object (page {0:d}) is wrong type ({1:s})",
num, trans.getTypeName());
......@@ -266,7 +266,7 @@ Page::Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *a
}
// duration
Object tmp = pageObj.dictLookupNF("Dur");
const Object &tmp = pageObj.dictLookupNF("Dur");
if (!(tmp.isNum() || tmp.isNull())) {
error(errSyntaxError, -1, "Page duration object (page {0:d}) is wrong type ({1:s})",
num, tmp.getTypeName());
......@@ -275,7 +275,7 @@ Page::Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *a
}
// annotations
annotsObj = pageObj.dictLookupNF("Annots");
annotsObj = pageObj.dictLookupNF("Annots").copy();
if (!(annotsObj.isRef() || annotsObj.isArray() || annotsObj.isNull())) {
error(errSyntaxError, -1, "Page annotations object (page {0:d}) is wrong type ({1:s})",
num, annotsObj.getTypeName());
......@@ -283,7 +283,7 @@ Page::Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *a
}
// contents
contents = pageObj.dictLookupNF("Contents");
contents = pageObj.dictLookupNF("Contents").copy();
if (!(contents.isRef() || contents.isArray() ||
contents.isNull())) {
error(errSyntaxError, -1, "Page contents object (page {0:d}) is wrong type ({1:s})",
......@@ -292,7 +292,7 @@ Page::Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *a
}
// thumb
thumb = pageObj.dictLookupNF("Thumb");
thumb = pageObj.dictLookupNF("Thumb").copy();
if (!(thumb.isStream() || thumb.isNull() || thumb.isRef())) {
error(errSyntaxError, -1, "Page thumb object (page {0:d}) is wrong type ({1:s})",
num, thumb.getTypeName());
......@@ -300,7 +300,7 @@ Page::Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *a
}
// actions
actions = pageObj.dictLookupNF("AA");
actions = pageObj.dictLookupNF("AA").copy();
if (!(actions.isDict() || actions.isNull())) {
error(errSyntaxError, -1, "Page additional action object (page {0:d}) is wrong type ({1:s})",
num, actions.getTypeName());
......@@ -340,15 +340,15 @@ void Page::replaceXRef(XRef *xrefA) {
Object obj1;
Dict *pageDict = pageObj.getDict()->copy(xrefA);
xref = xrefA;
trans = pageDict->lookupNF("Trans");
annotsObj = pageDict->lookupNF("Annots");
contents = pageDict->lookupNF("Contents");
trans = pageDict->lookupNF("Trans").copy();
annotsObj = pageDict->lookupNF("Annots").copy();
contents = pageDict->lookupNF("Contents").copy();
if (contents.isArray()) {
obj1 = pageDict->lookupNF("Contents");
obj1 = pageDict->lookupNF("Contents").copy();
contents = obj1.getArray()->copy(xrefA);
}
thumb = pageDict->lookupNF("Thumb");
actions = pageDict->lookupNF("AA");
thumb = pageDict->lookupNF("Thumb").copy();
actions = pageDict->lookupNF("AA").copy();
obj1 = pageDict->lookup("Resources");
if (obj1.isDict()) {
attrs->replaceResource(std::move(obj1));
......
......@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Jeff Muizelaar <jeff@infidigm.net>
// Copyright (C) 2006-2010, 2012-2014, 2016, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006-2010, 2012-2014, 2016-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
// Copyright (C) 2008 Julien Rebetez <julien@fhtagn.net>
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
......@@ -322,7 +322,7 @@ Stream *Stream::makeFilter(const char *name, Stream *str, Object *params, int re
Object globals;
if (params->isDict()) {
XRef *xref = params->getDict()->getXRef();
obj = params->dictLookupNF("JBIG2Globals");
obj = params->dictLookupNF("JBIG2Globals").copy();
globals = obj.fetch(xref, recursion);
}
str = new JBIG2Stream(str, std::move(globals), &obj);
......
......@@ -1045,7 +1045,7 @@ void StructElement::parse(Dict *element)
}
// Parent object reference (required).
s->parentRef = element->lookupNF("P");
s->parentRef = element->lookupNF("P").copy();
if (!s->parentRef.isRef()) {
error(errSyntaxError, -1, "P object is wrong type ({0:s})", obj.getTypeName());
return;
......@@ -1085,7 +1085,7 @@ void StructElement::parse(Dict *element)
// is to be rendered in. Note: each element stores only the /Pg value
// contained by it, and StructElement::getPageRef() may look in parent
// elements to find the page where an element belongs.
pageRef = element->lookupNF("Pg");
pageRef = element->lookupNF("Pg").copy();
// Revision number (optional).
obj = element->lookup("R");
......@@ -1201,17 +1201,17 @@ StructElement *StructElement::parseChild(const Object *ref,
child = new StructElement(mcidObj.getInt(), treeRoot, this);
Object pageRefObj = childObj->dictLookupNF("Pg");
Object pageRefObj = childObj->dictLookupNF("Pg").copy();
if (pageRefObj.isRef()) {
child->pageRef = std::move(pageRefObj);
}
} else if (childObj->isDict("OBJR")) {
Object refObj = childObj->dictLookupNF("Obj");
const Object &refObj = childObj->dictLookupNF("Obj");
if (refObj.isRef()) {
child = new StructElement(refObj.getRef(), treeRoot, this);
Object pageRefObj = childObj->dictLookupNF("Pg");
Object pageRefObj = childObj->dictLookupNF("Pg").copy();
if (pageRefObj.isRef()) {
child->pageRef = std::move(pageRefObj);
}
......@@ -1259,7 +1259,7 @@ void StructElement::parseChildren(Dict *element, std::set<int> &seen)
parseChild(&ref, &obj, seen);
}
} else if (kids.isDict() || kids.isInt()) {
Object ref = element->lookupNF("K");
const Object &ref = element->lookupNF("K");
parseChild(&ref, &kids, seen);
}
}
......
......@@ -95,7 +95,7 @@ void StructTreeRoot::parse(Dict *root)
StructElement *child = new StructElement(kids.getDict(), this, nullptr, seenElements);
if (child->isOk()) {
appendChild(child);
Object ref = root->lookupNF("K");
const Object &ref = root->lookupNF("K");
if (ref.isRef())
parentTreeAdd(ref.getRef(), child);
} else {
......
......@@ -291,7 +291,7 @@ XRef::XRef(BaseStream *strA, Goffset pos, Goffset mainXRefEntriesOffsetA, bool *
}
// set size to (at least) the size specified in trailer dict
obj = trailerDict.dictLookupNF("Size");
obj = trailerDict.dictLookupNF("Size").copy();
if (!obj.isInt()) {
error(errSyntaxWarning, -1, "No valid XRef size in trailer");
} else {
......@@ -306,7 +306,7 @@ XRef::XRef(BaseStream *strA, Goffset pos, Goffset mainXRefEntriesOffsetA, bool *
}
// get the root dictionary (catalog) object
obj = trailerDict.dictLookupNF("Root");
obj = trailerDict.dictLookupNF("Root").copy();
if (obj.isRef()) {
rootNum = obj.getRefNum();
rootGen = obj.getRefGen();
......@@ -588,7 +588,7 @@ bool XRef::readXRefTable(Parser *parser, Goffset *pos, std::vector<Goffset> *fol
}
// get the 'Prev' pointer
obj2 = obj.getDict()->lookupNF("Prev");
obj2 = obj.getDict()->lookupNF("Prev").copy();
if (obj2.isInt() || obj2.isInt64()) {
if (obj2.isInt())
pos2 = obj2.getInt();
......@@ -657,7 +657,7 @@ bool XRef::readXRefStream(Stream *xrefStr, Goffset *pos) {
ok = false;
Dict *dict = xrefStr->getDict();
obj = dict->lookupNF("Size");
obj = dict->lookupNF("Size").copy();
if (!obj.isInt()) {
return false;
}
......@@ -672,7 +672,7 @@ bool XRef::readXRefStream(Stream *xrefStr, Goffset *pos) {
}
}
obj = dict->lookupNF("W");
obj = dict->lookupNF("W").copy();
if (!obj.isArray() || obj.arrayGetLength() < 3) {