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); | 392 ASSERT(pObj); |
Tom Sepez
2015/12/14 19:14:11
nit: will segv at line 399.
Lei Zhang
2015/12/15 01:38:32
Done.
| |
393 CFX_WideString wsStr; | 393 CFX_WideString wsStr; |
394 if (bURL) { | 394 if (bURL) { |
395 wsStr = wsFileName; | 395 wsStr = wsFileName; |
396 } else { | 396 } else { |
397 wsStr = FILESPEC_EncodeFileName(wsFileName); | 397 wsStr = FILESPEC_EncodeFileName(wsFileName); |
398 } | 398 } |
399 if (pObj->IsString()) { | 399 if (pObj->IsString()) { |
400 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); | 400 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); |
401 } else if (CPDF_Dictionary* pDict = pObj->AsDictionary()) { | 401 } else if (CPDF_Dictionary* pDict = pObj->AsDictionary()) { |
402 pDict->SetAtString("F", CFX_ByteString::FromUnicode(wsStr)); | 402 pDict->SetAtString("F", CFX_ByteString::FromUnicode(wsStr)); |
403 pDict->SetAtString("UF", PDF_EncodeText(wsStr)); | 403 pDict->SetAtString("UF", PDF_EncodeText(wsStr)); |
404 } | 404 } |
405 } | 405 } |
406 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, | 406 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, |
407 FX_BOOL bURL) { | 407 FX_BOOL bURL) { |
408 ASSERT(m_pObj != NULL); | 408 ASSERT(m_pObj); |
Tom Sepez
2015/12/14 19:14:09
nitto
Lei Zhang
2015/12/15 01:38:32
Done.
| |
409 if (bURL) { | 409 if (bURL) { |
410 if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { | 410 if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { |
411 pDict->SetAtName("FS", "URL"); | 411 pDict->SetAtName("FS", "URL"); |
412 } | 412 } |
413 } | 413 } |
414 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); | 414 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); |
415 } | 415 } |
416 static CFX_WideString _MakeRoman(int num) { | 416 static CFX_WideString _MakeRoman(int num) { |
417 const int arabic[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; | 417 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", | 418 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(); | 476 CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); |
477 if (pPDFRoot == NULL) { | 477 if (pPDFRoot == NULL) { |
478 return wsLabel; | 478 return wsLabel; |
479 } | 479 } |
480 CPDF_Dictionary* pLabels = pPDFRoot->GetDict("PageLabels"); | 480 CPDF_Dictionary* pLabels = pPDFRoot->GetDict("PageLabels"); |
481 CPDF_NumberTree numberTree(pLabels); | 481 CPDF_NumberTree numberTree(pLabels); |
482 CPDF_Object* pValue = NULL; | 482 CPDF_Object* pValue = NULL; |
483 int n = nPage; | 483 int n = nPage; |
484 while (n >= 0) { | 484 while (n >= 0) { |
485 pValue = numberTree.LookupValue(n); | 485 pValue = numberTree.LookupValue(n); |
486 if (pValue != NULL) { | 486 if (pValue) { |
487 break; | 487 break; |
488 } | 488 } |
489 n--; | 489 n--; |
490 } | 490 } |
491 if (pValue != NULL) { | 491 if (pValue) { |
492 pValue = pValue->GetDirect(); | 492 pValue = pValue->GetDirect(); |
493 if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) { | 493 if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) { |
494 if (pLabel->KeyExist("P")) { | 494 if (pLabel->KeyExist("P")) { |
495 wsLabel += pLabel->GetUnicodeText("P"); | 495 wsLabel += pLabel->GetUnicodeText("P"); |
496 } | 496 } |
497 CFX_ByteString bsNumberingStyle = pLabel->GetString("S", NULL); | 497 CFX_ByteString bsNumberingStyle = pLabel->GetString("S", NULL); |
498 int nLabelNum = nPage - n + pLabel->GetInteger("St", 1); | 498 int nLabelNum = nPage - n + pLabel->GetInteger("St", 1); |
499 CFX_WideString wsNumPortion = | 499 CFX_WideString wsNumPortion = |
500 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); | 500 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); |
501 wsLabel += wsNumPortion; | 501 wsLabel += wsNumPortion; |
(...skipping 24 matching lines...) Expand all Loading... | |
526 int nPage = FXSYS_atoi(bsLbl); | 526 int nPage = FXSYS_atoi(bsLbl); |
527 if (nPage > 0 && nPage <= nPages) { | 527 if (nPage > 0 && nPage <= nPages) { |
528 return nPage; | 528 return nPage; |
529 } | 529 } |
530 return -1; | 530 return -1; |
531 } | 531 } |
532 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { | 532 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { |
533 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); | 533 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); |
534 return GetPageByLabel(bsLabel); | 534 return GetPageByLabel(bsLabel); |
535 } | 535 } |
OLD | NEW |