summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_ppo.cpp
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2018-06-28 14:59:03 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-28 14:59:03 +0000
commit35ab1bd0328a244cc2f6dcde2822c8117738b01d (patch)
treebd7d758a9122475e9df4584279555c0cc277ba66 /fpdfsdk/fpdf_ppo.cpp
parentb74c8d1619602afb71b3f9f00d4fee3114f9c149 (diff)
downloadpdfium-35ab1bd0328a244cc2f6dcde2822c8117738b01d.tar.xz
Simplify CPDF_PageOrganizer::UpdateReference method.
Change-Id: I52fe66472bdc2a61d7074f77627a3ee1d5646255 Reviewed-on: https://pdfium-review.googlesource.com/35611 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'fpdfsdk/fpdf_ppo.cpp')
-rw-r--r--fpdfsdk/fpdf_ppo.cpp65
1 files changed, 18 insertions, 47 deletions
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index 8bbae7258d..a35702efd9 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -20,6 +20,7 @@
#include "core/fpdfapi/parser/cpdf_name.h"
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_object.h"
+#include "core/fpdfapi/parser/cpdf_object_walker.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
@@ -355,55 +356,25 @@ bool CPDF_PageOrganizer::PDFDocInit() {
bool CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
ObjectNumberMap* pObjNumberMap) {
- switch (pObj->GetType()) {
- case CPDF_Object::REFERENCE: {
- CPDF_Reference* pReference = pObj->AsReference();
- uint32_t newobjnum = GetNewObjId(pObjNumberMap, pReference);
- if (newobjnum == 0)
- return false;
- pReference->SetRef(dest(), newobjnum);
- break;
- }
- case CPDF_Object::DICTIONARY: {
- CPDF_Dictionary* pDict = pObj->AsDictionary();
- auto it = pDict->begin();
- while (it != pDict->end()) {
- const ByteString& key = it->first;
- CPDF_Object* pNextObj = it->second.get();
- ++it;
- if (key == "Parent" || key == "Prev" || key == "First")
- continue;
- if (!pNextObj)
- return false;
- if (!UpdateReference(pNextObj, pObjNumberMap))
- pDict->RemoveFor(key);
- }
- break;
- }
- case CPDF_Object::ARRAY: {
- CPDF_Array* pArray = pObj->AsArray();
- for (size_t i = 0; i < pArray->GetCount(); ++i) {
- CPDF_Object* pNextObj = pArray->GetObjectAt(i);
- if (!pNextObj)
- return false;
- if (!UpdateReference(pNextObj, pObjNumberMap))
- return false;
- }
- break;
- }
- case CPDF_Object::STREAM: {
- CPDF_Stream* pStream = pObj->AsStream();
- CPDF_Dictionary* pDict = pStream->GetDict();
- if (!pDict)
- return false;
- if (!UpdateReference(pDict, pObjNumberMap))
- return false;
- break;
+ for (CPDF_NonConstObjectWalker walker(pObj);
+ CPDF_Object* child = walker.GetNext();) {
+ if (walker.dictionary_key() == "Parent" ||
+ walker.dictionary_key() == "Prev" ||
+ walker.dictionary_key() == "First") {
+ walker.SkipWalkIntoCurrentObject();
+ continue;
}
- default:
- break;
- }
+ if (!child->IsReference())
+ continue;
+ CPDF_Reference* ref = ToReference(child);
+
+ const uint32_t newobjnum = GetNewObjId(pObjNumberMap, ref);
+ if (newobjnum == 0)
+ return false;
+
+ ref->SetRef(dest(), newobjnum);
+ }
return true;
}