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/include/fpdfdoc/fpdf_doc.h" | 7 #include "core/include/fpdfdoc/fpdf_doc.h" |
8 | 8 |
9 const int nMaxRecursion = 32; | 9 const int nMaxRecursion = 32; |
10 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) { | 10 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, | 71 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, |
72 const CFX_ByteString& csName, | 72 const CFX_ByteString& csName, |
73 int& nIndex, | 73 int& nIndex, |
74 CPDF_Array** ppFind, | 74 CPDF_Array** ppFind, |
75 int nLevel = 0) { | 75 int nLevel = 0) { |
76 if (nLevel > nMaxRecursion) { | 76 if (nLevel > nMaxRecursion) { |
77 return NULL; | 77 return NULL; |
78 } | 78 } |
79 CPDF_Array* pLimits = pNode->GetArray("Limits"); | 79 CPDF_Array* pLimits = pNode->GetArray("Limits"); |
80 if (pLimits != NULL) { | 80 if (pLimits) { |
81 CFX_ByteString csLeft = pLimits->GetString(0); | 81 CFX_ByteString csLeft = pLimits->GetString(0); |
82 CFX_ByteString csRight = pLimits->GetString(1); | 82 CFX_ByteString csRight = pLimits->GetString(1); |
83 if (csLeft.Compare(csRight) > 0) { | 83 if (csLeft.Compare(csRight) > 0) { |
84 CFX_ByteString csTmp = csRight; | 84 CFX_ByteString csTmp = csRight; |
85 csRight = csLeft; | 85 csRight = csLeft; |
86 csLeft = csTmp; | 86 csLeft = csTmp; |
87 } | 87 } |
88 if (csName.Compare(csLeft) < 0 || csName.Compare(csRight) > 0) { | 88 if (csName.Compare(csLeft) < 0 || csName.Compare(csRight) > 0) { |
89 return NULL; | 89 return NULL; |
90 } | 90 } |
91 } | 91 } |
92 CPDF_Array* pNames = pNode->GetArray("Names"); | 92 CPDF_Array* pNames = pNode->GetArray("Names"); |
93 if (pNames) { | 93 if (pNames) { |
94 FX_DWORD dwCount = pNames->GetCount() / 2; | 94 FX_DWORD dwCount = pNames->GetCount() / 2; |
95 for (FX_DWORD i = 0; i < dwCount; i++) { | 95 for (FX_DWORD i = 0; i < dwCount; i++) { |
96 CFX_ByteString csValue = pNames->GetString(i * 2); | 96 CFX_ByteString csValue = pNames->GetString(i * 2); |
97 int32_t iCompare = csValue.Compare(csName); | 97 int32_t iCompare = csValue.Compare(csName); |
98 if (iCompare <= 0) { | 98 if (iCompare <= 0) { |
99 if (ppFind != NULL) { | 99 if (ppFind) { |
100 *ppFind = pNames; | 100 *ppFind = pNames; |
101 } | 101 } |
102 if (iCompare < 0) { | 102 if (iCompare < 0) { |
103 continue; | 103 continue; |
104 } | 104 } |
105 } else { | 105 } else { |
106 break; | 106 break; |
107 } | 107 } |
108 nIndex += i; | 108 nIndex += i; |
109 return pNames->GetElementValue(i * 2 + 1); | 109 return pNames->GetElementValue(i * 2 + 1); |
(...skipping 27 matching lines...) Expand all Loading... |
137 if (nLevel > nMaxRecursion) { | 137 if (nLevel > nMaxRecursion) { |
138 return NULL; | 138 return NULL; |
139 } | 139 } |
140 CPDF_Array* pNames = pNode->GetArray("Names"); | 140 CPDF_Array* pNames = pNode->GetArray("Names"); |
141 if (pNames) { | 141 if (pNames) { |
142 int nCount = pNames->GetCount() / 2; | 142 int nCount = pNames->GetCount() / 2; |
143 if (nIndex >= nCurIndex + nCount) { | 143 if (nIndex >= nCurIndex + nCount) { |
144 nCurIndex += nCount; | 144 nCurIndex += nCount; |
145 return NULL; | 145 return NULL; |
146 } | 146 } |
147 if (ppFind != NULL) { | 147 if (ppFind) { |
148 *ppFind = pNames; | 148 *ppFind = pNames; |
149 } | 149 } |
150 csName = pNames->GetString((nIndex - nCurIndex) * 2); | 150 csName = pNames->GetString((nIndex - nCurIndex) * 2); |
151 return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1); | 151 return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1); |
152 } | 152 } |
153 CPDF_Array* pKids = pNode->GetArray("Kids"); | 153 CPDF_Array* pKids = pNode->GetArray("Kids"); |
154 if (pKids == NULL) { | 154 if (pKids == NULL) { |
155 return NULL; | 155 return NULL; |
156 } | 156 } |
157 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { | 157 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 return nullptr; | 382 return nullptr; |
383 if (CPDF_Stream* pStream = m_pObj->AsStream()) | 383 if (CPDF_Stream* pStream = m_pObj->AsStream()) |
384 return pStream; | 384 return pStream; |
385 if (CPDF_Dictionary* pEF = m_pObj->AsDictionary()->GetDict("EF")) | 385 if (CPDF_Dictionary* pEF = m_pObj->AsDictionary()->GetDict("EF")) |
386 return pEF->GetStream("F"); | 386 return pEF->GetStream("F"); |
387 return nullptr; | 387 return nullptr; |
388 } | 388 } |
389 static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj, | 389 static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj, |
390 const CFX_WideStringC& wsFileName, | 390 const CFX_WideStringC& wsFileName, |
391 FX_BOOL bURL) { | 391 FX_BOOL bURL) { |
392 ASSERT(pObj != NULL); | |
393 CFX_WideString wsStr; | 392 CFX_WideString wsStr; |
394 if (bURL) { | 393 if (bURL) { |
395 wsStr = wsFileName; | 394 wsStr = wsFileName; |
396 } else { | 395 } else { |
397 wsStr = FILESPEC_EncodeFileName(wsFileName); | 396 wsStr = FILESPEC_EncodeFileName(wsFileName); |
398 } | 397 } |
399 if (pObj->IsString()) { | 398 if (pObj->IsString()) { |
400 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); | 399 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); |
401 } else if (CPDF_Dictionary* pDict = pObj->AsDictionary()) { | 400 } else if (CPDF_Dictionary* pDict = pObj->AsDictionary()) { |
402 pDict->SetAtString("F", CFX_ByteString::FromUnicode(wsStr)); | 401 pDict->SetAtString("F", CFX_ByteString::FromUnicode(wsStr)); |
403 pDict->SetAtString("UF", PDF_EncodeText(wsStr)); | 402 pDict->SetAtString("UF", PDF_EncodeText(wsStr)); |
404 } | 403 } |
405 } | 404 } |
406 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, | 405 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, |
407 FX_BOOL bURL) { | 406 FX_BOOL bURL) { |
408 ASSERT(m_pObj != NULL); | |
409 if (bURL) { | 407 if (bURL) { |
410 if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { | 408 if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { |
411 pDict->SetAtName("FS", "URL"); | 409 pDict->SetAtName("FS", "URL"); |
412 } | 410 } |
413 } | 411 } |
414 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); | 412 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); |
415 } | 413 } |
416 static CFX_WideString _MakeRoman(int num) { | 414 static CFX_WideString _MakeRoman(int num) { |
417 const int arabic[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; | 415 const int arabic[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; |
418 const CFX_WideString roman[] = {L"m", L"cm", L"d", L"cd", L"c", | 416 const CFX_WideString roman[] = {L"m", L"cm", L"d", L"cd", L"c", |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); | 474 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); |
477 if (pPDFRoot == NULL) { | 475 if (pPDFRoot == NULL) { |
478 return wsLabel; | 476 return wsLabel; |
479 } | 477 } |
480 CPDF_Dictionary* pLabels = pPDFRoot->GetDict("PageLabels"); | 478 CPDF_Dictionary* pLabels = pPDFRoot->GetDict("PageLabels"); |
481 CPDF_NumberTree numberTree(pLabels); | 479 CPDF_NumberTree numberTree(pLabels); |
482 CPDF_Object* pValue = NULL; | 480 CPDF_Object* pValue = NULL; |
483 int n = nPage; | 481 int n = nPage; |
484 while (n >= 0) { | 482 while (n >= 0) { |
485 pValue = numberTree.LookupValue(n); | 483 pValue = numberTree.LookupValue(n); |
486 if (pValue != NULL) { | 484 if (pValue) { |
487 break; | 485 break; |
488 } | 486 } |
489 n--; | 487 n--; |
490 } | 488 } |
491 if (pValue != NULL) { | 489 if (pValue) { |
492 pValue = pValue->GetDirect(); | 490 pValue = pValue->GetDirect(); |
493 if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) { | 491 if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) { |
494 if (pLabel->KeyExist("P")) { | 492 if (pLabel->KeyExist("P")) { |
495 wsLabel += pLabel->GetUnicodeText("P"); | 493 wsLabel += pLabel->GetUnicodeText("P"); |
496 } | 494 } |
497 CFX_ByteString bsNumberingStyle = pLabel->GetString("S", NULL); | 495 CFX_ByteString bsNumberingStyle = pLabel->GetString("S", NULL); |
498 int nLabelNum = nPage - n + pLabel->GetInteger("St", 1); | 496 int nLabelNum = nPage - n + pLabel->GetInteger("St", 1); |
499 CFX_WideString wsNumPortion = | 497 CFX_WideString wsNumPortion = |
500 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); | 498 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); |
501 wsLabel += wsNumPortion; | 499 wsLabel += wsNumPortion; |
(...skipping 24 matching lines...) Expand all Loading... |
526 int nPage = FXSYS_atoi(bsLbl); | 524 int nPage = FXSYS_atoi(bsLbl); |
527 if (nPage > 0 && nPage <= nPages) { | 525 if (nPage > 0 && nPage <= nPages) { |
528 return nPage; | 526 return nPage; |
529 } | 527 } |
530 return -1; | 528 return -1; |
531 } | 529 } |
532 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { | 530 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { |
533 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); | 531 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); |
534 return GetPageByLabel(bsLabel); | 532 return GetPageByLabel(bsLabel); |
535 } | 533 } |
OLD | NEW |