diff options
Diffstat (limited to 'Build/source/libs/poppler/poppler-src/poppler/StructTreeRoot.cc')
-rw-r--r-- | Build/source/libs/poppler/poppler-src/poppler/StructTreeRoot.cc | 82 |
1 files changed, 37 insertions, 45 deletions
diff --git a/Build/source/libs/poppler/poppler-src/poppler/StructTreeRoot.cc b/Build/source/libs/poppler/poppler-src/poppler/StructTreeRoot.cc index e46e3e28388..5f56111581e 100644 --- a/Build/source/libs/poppler/poppler-src/poppler/StructTreeRoot.cc +++ b/Build/source/libs/poppler/poppler-src/poppler/StructTreeRoot.cc @@ -6,6 +6,9 @@ // // Copyright 2013, 2014 Igalia S.L. // Copyright 2014 Fabio D'Urso <fabiodurso@hotmail.it> +// Copyright 2017 Jan-Erik S <janerik234678@gmail.com> +// Copyright 2017 Albert Astals Cid <aacid@kde.org> +// Copyright 2017 Adrian Johnson <ajohnson@redneon.com> // //======================================================================== @@ -35,8 +38,6 @@ StructTreeRoot::~StructTreeRoot() { for (ElemPtrArray::iterator i = elements.begin(); i != elements.end(); ++i) delete *i; - classMap.free(); - roleMap.free(); } void StructTreeRoot::parse(Dict *root) @@ -44,55 +45,53 @@ void StructTreeRoot::parse(Dict *root) // The RoleMap/ClassMap dictionaries are needed by all the parsing // functions, which will resolve the custom names to canonical // standard names. - root->lookup("RoleMap", &roleMap); - root->lookup("ClassMap", &classMap); + roleMap = root->lookup("RoleMap"); + classMap = root->lookup("ClassMap"); // ParentTree (optional). If present, it must be a number tree, // otherwise it is not possible to map stream objects to their // corresponsing structure element. Here only the references are // loaded into the array, the pointers to the StructElements will // be filled-in later when parsing them. - Object obj; - if (root->lookup("ParentTree", &obj)->isDict()) { - Object nums; - if (obj.dictLookup("Nums", &nums)->isArray()) { + Object obj = root->lookup("ParentTree"); + if (obj.isDict()) { + Object nums = obj.dictLookup("Nums"); + if (nums.isArray()) { if (nums.arrayGetLength() % 2 == 0) { parentTree.resize(nums.arrayGetLength() / 2); // Index numbers in even positions, references in odd ones for (int i = 0; i < nums.arrayGetLength(); i += 2) { - Object index, value; + Object index = nums.arrayGet(i); - if (!nums.arrayGet(i, &index)->isInt()) { + if (!index.isInt()) { error(errSyntaxError, -1, "Nums item at position {0:d} is wrong type ({1:s})", i, index.getTypeName()); - index.free(); continue; } - if (index.getInt() < 0) { - error(errSyntaxError, -1, "Nums item at position {0:d} is invalid value ({1:d})", i, index.getInt()); - index.free(); + const int idx = index.getInt(); + if (idx < 0 || idx >= (int)parentTree.size()) { + error(errSyntaxError, -1, "Nums item at position {0:d} is invalid value ({1:d}): [0..{2:d}]", i, idx, parentTree.size() - 1); continue; } - const unsigned idx = index.getInt(); - if (nums.arrayGetNF(i + 1, &value)->isRef()) { + Object value = nums.arrayGetNF(i + 1); + if (value.isRef()) { parentTree[idx].resize(1); parentTree[idx][0].ref = value.getRef(); - } else if (nums.arrayGet(i + 1, &value)->isArray()) { - parentTree[idx].resize(value.arrayGetLength()); - for (int j = 0; j < value.arrayGetLength(); j++) { - Object itemvalue; - if (value.arrayGetNF(j, &itemvalue)->isRef()) - parentTree[idx][j].ref = itemvalue.getRef(); - else - error(errSyntaxError, -1, "Nums array item at position {0:d}/{1:d} is invalid type ({2:s})", i, j, itemvalue.getTypeName()); - itemvalue.free(); - } } else { - error(errSyntaxError, -1, "Nums item at position {0:d} is wrong type ({1:s})", i + 1, value.getTypeName()); - } - - value.free(); - index.free(); + value = nums.arrayGet(i + 1); + if (value.isArray()) { + parentTree[idx].resize(value.arrayGetLength()); + for (int j = 0; j < value.arrayGetLength(); j++) { + Object itemvalue = value.arrayGetNF(j); + if (itemvalue.isRef()) + parentTree[idx][j].ref = itemvalue.getRef(); + else + error(errSyntaxError, -1, "Nums array item at position {0:d}/{1:d} is invalid type ({2:s})", i, j, itemvalue.getTypeName()); + } + } else { + error(errSyntaxError, -1, "Nums item at position {0:d} is wrong type ({1:s})", i + 1, value.getTypeName()); + } + } } } else { error(errSyntaxError, -1, "Nums array length is not a even ({0:d})", nums.arrayGetLength()); @@ -100,26 +99,24 @@ void StructTreeRoot::parse(Dict *root) } else { error(errSyntaxError, -1, "Nums object is wrong type ({0:s})", nums.getTypeName()); } - nums.free(); } - obj.free(); std::set<int> seenElements; // Parse the children StructElements const GBool marked = doc->getCatalog()->getMarkInfo() & Catalog::markInfoMarked; - Object kids; - if (root->lookup("K", &kids)->isArray()) { + Object kids = root->lookup("K"); + if (kids.isArray()) { if (marked && kids.arrayGetLength() > 1) { error(errSyntaxWarning, -1, "K in StructTreeRoot has more than one children in a tagged PDF"); } for (int i = 0; i < kids.arrayGetLength(); i++) { - Object obj, ref; - kids.arrayGetNF(i, &ref); + Object ref = kids.arrayGetNF(i); if (ref.isRef()) { seenElements.insert(ref.getRefNum()); } - if (kids.arrayGet(i, &obj)->isDict()) { + Object obj = kids.arrayGet(i); + if (obj.isDict()) { StructElement *child = new StructElement(obj.getDict(), this, NULL, seenElements); if (child->isOk()) { if (marked && !(child->getType() == StructElement::Document || @@ -139,8 +136,6 @@ void StructTreeRoot::parse(Dict *root) } else { error(errSyntaxWarning, -1, "K has a child of wrong type ({0:s})", obj.getTypeName()); } - obj.free(); - ref.free(); } } else if (kids.isDict()) { if (marked) { @@ -149,10 +144,9 @@ void StructTreeRoot::parse(Dict *root) StructElement *child = new StructElement(kids.getDict(), this, NULL, seenElements); if (child->isOk()) { appendChild(child); - Object ref; - if (root->lookupNF("K", &ref)->isRef()) + Object ref = root->lookupNF("K"); + if (ref.isRef()) parentTreeAdd(ref.getRef(), child); - ref.free(); } else { error(errSyntaxWarning, -1, "StructTreeRoot element could not be parsed"); delete child; @@ -160,8 +154,6 @@ void StructTreeRoot::parse(Dict *root) } else if (!kids.isNull()) { error(errSyntaxWarning, -1, "K in StructTreeRoot is wrong type ({0:s})", kids.getTypeName()); } - - kids.free(); } void StructTreeRoot::parentTreeAdd(const Ref &objectRef, StructElement *element) |