Commit 70845beb authored by Albert Astals Cid's avatar Albert Astals Cid

Introduce Dict::getVal(int i, Ref *returnRef)

And use it in FontInfoScanner::scanFonts
parent 8051f678
......@@ -202,6 +202,17 @@ bool Dict::lookupInt(const char *key, const char *alt_key, int *value) const
return false;
}
Object Dict::getVal(int i, Ref *returnRef) const
{
const DictEntry &entry = entries[i];
if (entry.second.getType() == objRef) {
*returnRef = entry.second.getRef();
} else {
*returnRef = Ref::INVALID();
}
return entry.second.fetch(xref);
}
bool Dict::hasKey(const char *key) const {
return find(key) != nullptr;
}
......@@ -84,6 +84,8 @@ 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); }
// Same as above but if the returned object is a fetched Ref returns such Ref in returnRef, otherwise returnRef is Ref::INVALID()
Object getVal(int i, Ref *returnRef) const;
const Object &getValNF(int i) const { return entries[i].second; }
// Set the xref pointer. This is only used in one special case: the
......
......@@ -131,18 +131,17 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, std::vector<FontInfo
Object objDict = resDict->lookup(resTypes[resType]);
if (objDict.isDict()) {
for (int i = 0; i < objDict.dictGetLength(); ++i) {
const Object &dictObjI = objDict.dictGetValNF(i);
if (dictObjI.isRef()) {
Ref obj2Ref;
const Object obj2 = objDict.getDict()->getVal(i, &obj2Ref);
if (obj2Ref != Ref::INVALID()) {
// check for an already-seen object
const Ref r = dictObjI.getRef();
if (visitedObjects.find(r.num) != visitedObjects.end()) {
if (visitedObjects.find(obj2Ref.num) != visitedObjects.end()) {
continue;
}
visitedObjects.insert(r.num);
visitedObjects.insert(obj2Ref.num);
}
Object obj2 = dictObjI.fetch(xrefA);
if (obj2.isStream()) {
Ref resourcesRef;
const Object resObj = obj2.streamGetDict()->lookup("Resources", &resourcesRef);
......
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