Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: core/fpdfdoc/cpdf_numbertree.cpp

Issue 2190983002: Splitting fpdfdoc/doc_* part III. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@fpdf_doc_IV
Patch Set: move cb Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfdoc/cpdf_numbertree.h ('k') | core/fpdfdoc/cpdf_pagelabel.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfdoc/cpdf_numbertree.cpp
diff --git a/core/fpdfdoc/cpdf_numbertree.cpp b/core/fpdfdoc/cpdf_numbertree.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9e2881f414156a658aeec1a0c90ad163589542ef
--- /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);
+}
« no previous file with comments | « core/fpdfdoc/cpdf_numbertree.h ('k') | core/fpdfdoc/cpdf_pagelabel.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698