summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_numbertree.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-08-02 15:43:46 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-02 15:43:46 -0700
commit27053d81ca80a2f9433abf3e9c393d2914c91ad8 (patch)
treeecf94b4610dfd09d42a83b1ab86ec22223957390 /core/fpdfdoc/cpdf_numbertree.cpp
parente21501d9427539828b5d547b9d20a752d06914aa (diff)
downloadpdfium-27053d81ca80a2f9433abf3e9c393d2914c91ad8.tar.xz
Splitting fpdfdoc/doc_* part III.
This CL cleans up the remaining doc_* files, splitting into .h and .pp files as needed. Review-Url: https://codereview.chromium.org/2190983002
Diffstat (limited to 'core/fpdfdoc/cpdf_numbertree.cpp')
-rw-r--r--core/fpdfdoc/cpdf_numbertree.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/core/fpdfdoc/cpdf_numbertree.cpp b/core/fpdfdoc/cpdf_numbertree.cpp
new file mode 100644
index 0000000000..9e2881f414
--- /dev/null
+++ b/core/fpdfdoc/cpdf_numbertree.cpp
@@ -0,0 +1,52 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfdoc/cpdf_numbertree.h"
+
+#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
+
+namespace {
+
+CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) {
+ CPDF_Array* pLimits = pNode->GetArrayBy("Limits");
+ if (pLimits &&
+ (num < pLimits->GetIntegerAt(0) || num > pLimits->GetIntegerAt(1))) {
+ return nullptr;
+ }
+ CPDF_Array* pNumbers = pNode->GetArrayBy("Nums");
+ if (pNumbers) {
+ for (size_t i = 0; i < pNumbers->GetCount() / 2; i++) {
+ int index = pNumbers->GetIntegerAt(i * 2);
+ if (num == index)
+ return pNumbers->GetDirectObjectAt(i * 2 + 1);
+ if (index > num)
+ break;
+ }
+ return nullptr;
+ }
+
+ CPDF_Array* pKids = pNode->GetArrayBy("Kids");
+ if (!pKids)
+ return nullptr;
+
+ for (size_t i = 0; i < pKids->GetCount(); i++) {
+ CPDF_Dictionary* pKid = pKids->GetDictAt(i);
+ if (!pKid)
+ continue;
+
+ CPDF_Object* pFound = SearchNumberNode(pKid, num);
+ if (pFound)
+ return pFound;
+ }
+ return nullptr;
+}
+
+} // namespace
+
+CPDF_Object* CPDF_NumberTree::LookupValue(int num) const {
+ return SearchNumberNode(m_pRoot, num);
+}