OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
8 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
9 #include "core/fpdfdoc/doc_utils.h" | 9 #include "core/fpdfdoc/doc_utils.h" |
10 #include "core/fpdfdoc/include/fpdf_doc.h" | 10 #include "core/fpdfdoc/include/fpdf_doc.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return 0; | 64 return 0; |
65 } | 65 } |
66 | 66 |
67 FX_FLOAT CPDF_Dest::GetParam(int index) { | 67 FX_FLOAT CPDF_Dest::GetParam(int index) { |
68 CPDF_Array* pArray = ToArray(m_pObj); | 68 CPDF_Array* pArray = ToArray(m_pObj); |
69 return pArray ? pArray->GetNumberAt(2 + index) : 0; | 69 return pArray ? pArray->GetNumberAt(2 + index) : 0; |
70 } | 70 } |
71 CFX_ByteString CPDF_Dest::GetRemoteName() { | 71 CFX_ByteString CPDF_Dest::GetRemoteName() { |
72 return m_pObj ? m_pObj->GetString() : CFX_ByteString(); | 72 return m_pObj ? m_pObj->GetString() : CFX_ByteString(); |
73 } | 73 } |
| 74 |
74 CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc, | 75 CPDF_NameTree::CPDF_NameTree(CPDF_Document* pDoc, |
75 const CFX_ByteStringC& category) { | 76 const CFX_ByteString& category) |
76 if (pDoc->GetRoot() && pDoc->GetRoot()->GetDictBy("Names")) | 77 : m_pRoot(nullptr) { |
77 m_pRoot = pDoc->GetRoot()->GetDictBy("Names")->GetDictBy(category); | 78 CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
78 else | 79 if (!pRoot) |
79 m_pRoot = NULL; | 80 return; |
| 81 |
| 82 CPDF_Dictionary* pNames = pRoot->GetDictBy("Names"); |
| 83 if (!pNames) |
| 84 return; |
| 85 |
| 86 m_pRoot = pNames->GetDictBy(category); |
80 } | 87 } |
81 | 88 |
82 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, | 89 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, |
83 const CFX_ByteString& csName, | 90 const CFX_ByteString& csName, |
84 size_t& nIndex, | 91 size_t& nIndex, |
85 CPDF_Array** ppFind, | 92 CPDF_Array** ppFind, |
86 int nLevel = 0) { | 93 int nLevel = 0) { |
87 if (nLevel > nMaxRecursion) { | 94 if (nLevel > nMaxRecursion) { |
88 return NULL; | 95 return NULL; |
89 } | 96 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, NULL); | 233 return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, NULL); |
227 } | 234 } |
228 CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { | 235 CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { |
229 if (!m_pRoot) { | 236 if (!m_pRoot) { |
230 return NULL; | 237 return NULL; |
231 } | 238 } |
232 size_t nIndex = 0; | 239 size_t nIndex = 0; |
233 return SearchNameNode(m_pRoot, csName, nIndex, NULL); | 240 return SearchNameNode(m_pRoot, csName, nIndex, NULL); |
234 } | 241 } |
235 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, | 242 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, |
236 const CFX_ByteStringC& sName) { | 243 const CFX_ByteString& sName) { |
237 CPDF_Object* pValue = LookupValue(sName); | 244 CPDF_Object* pValue = LookupValue(sName); |
238 if (!pValue) { | 245 if (!pValue) { |
239 CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDictBy("Dests"); | 246 CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDictBy("Dests"); |
240 if (!pDests) | 247 if (!pDests) |
241 return nullptr; | 248 return nullptr; |
242 pValue = pDests->GetDirectObjectBy(sName); | 249 pValue = pDests->GetDirectObjectBy(sName); |
243 } | 250 } |
244 if (!pValue) | 251 if (!pValue) |
245 return nullptr; | 252 return nullptr; |
246 if (CPDF_Array* pArray = pValue->AsArray()) | 253 if (CPDF_Array* pArray = pValue->AsArray()) |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 bsLbl = bsOrig; | 520 bsLbl = bsOrig; |
514 int nPage = FXSYS_atoi(bsLbl.c_str()); | 521 int nPage = FXSYS_atoi(bsLbl.c_str()); |
515 if (nPage > 0 && nPage <= nPages) { | 522 if (nPage > 0 && nPage <= nPages) { |
516 return nPage; | 523 return nPage; |
517 } | 524 } |
518 return -1; | 525 return -1; |
519 } | 526 } |
520 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { | 527 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { |
521 return GetPageByLabel(PDF_EncodeText(wsLabel.c_str()).AsStringC()); | 528 return GetPageByLabel(PDF_EncodeText(wsLabel.c_str()).AsStringC()); |
522 } | 529 } |
OLD | NEW |