Commit 4d0cbca6 authored by Albert Astals Cid's avatar Albert Astals Cid

Add an XRef::fetch variant that takes a const Ref

makes the code more compact and easier to understand
parent fc555c75
......@@ -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;
......
......@@ -3,7 +3,7 @@
// FontInfo.cc
//
// Copyright (C) 2005, 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2005-2008, 2010, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2005-2008, 2010, 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2005 Brad Hards <bradh@frogmouth.net>
// Copyright (C) 2006 Kouhei Sutou <kou@cozmixng.org>
// Copyright (C) 2009 Pino Toscano <pino@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();
}
......
......@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
// Copyright (C) 2005-2013, 2015-2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2005-2013, 2015-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006 Thorkild Stray <thorkild@ifi.uio.no>
// Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2006-2011 Carlos Garcia Campos <carlosgc@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();
}
......
......@@ -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@kde.org>
// Copyright (C) 2008, 2010, 2012, 2017, 2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2018 Adam Reichold <adam.reichold@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() {
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Brad Hards <bradh@frogmouth.net>
// Copyright (C) 2006, 2008, 2010-2013, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006, 2008, 2010-2013, 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2007-2008 Julien Rebetez <julienr@svn.gnome.org>
// Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2010 Ilya Gorenbein <igorenbein@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).
......
......@@ -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()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment