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

Side by Side Diff: core/src/fpdfdoc/doc_basic.cpp

Issue 1194933003: Make CPDF_Object::GetString() a virtual method. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 5 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 unified diff | Download patch
OLDNEW
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 "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 const int nMaxRecursion = 32; 8 const int nMaxRecursion = 32;
9 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) 9 int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc)
10 { 10 {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 m_pRoot = NULL; 80 m_pRoot = NULL;
81 } 81 }
82 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, const CFX_ByteString& csName, 82 static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, const CFX_ByteString& csName,
83 int& nIndex, CPDF_Array** ppFind, int nLevel = 0) 83 int& nIndex, CPDF_Array** ppFind, int nLevel = 0)
84 { 84 {
85 if (nLevel > nMaxRecursion) { 85 if (nLevel > nMaxRecursion) {
86 return NULL; 86 return NULL;
87 } 87 }
88 CPDF_Array* pLimits = pNode->GetArray(FX_BSTRC("Limits")); 88 CPDF_Array* pLimits = pNode->GetArray(FX_BSTRC("Limits"));
89 if (pLimits != NULL) { 89 if (pLimits != NULL) {
90 CFX_ByteString csLeft = pLimits->GetString(0); 90 CFX_ByteString csLeft = pLimits->GetStringAt(0);
91 CFX_ByteString csRight = pLimits->GetString(1); 91 CFX_ByteString csRight = pLimits->GetStringAt(1);
92 if (csLeft.Compare(csRight) > 0) { 92 if (csLeft.Compare(csRight) > 0) {
93 CFX_ByteString csTmp = csRight; 93 CFX_ByteString csTmp = csRight;
94 csRight = csLeft; 94 csRight = csLeft;
95 csLeft = csTmp; 95 csLeft = csTmp;
96 } 96 }
97 if (csName.Compare(csLeft) < 0 || csName.Compare(csRight) > 0) { 97 if (csName.Compare(csLeft) < 0 || csName.Compare(csRight) > 0) {
98 return NULL; 98 return NULL;
99 } 99 }
100 } 100 }
101 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names")); 101 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names"));
102 if (pNames) { 102 if (pNames) {
103 FX_DWORD dwCount = pNames->GetCount() / 2; 103 FX_DWORD dwCount = pNames->GetCount() / 2;
104 for (FX_DWORD i = 0; i < dwCount; i ++) { 104 for (FX_DWORD i = 0; i < dwCount; i ++) {
105 CFX_ByteString csValue = pNames->GetString(i * 2); 105 CFX_ByteString csValue = pNames->GetStringAt(i * 2);
106 int32_t iCompare = csValue.Compare(csName); 106 int32_t iCompare = csValue.Compare(csName);
107 if (iCompare <= 0) { 107 if (iCompare <= 0) {
108 if (ppFind != NULL) { 108 if (ppFind != NULL) {
109 *ppFind = pNames; 109 *ppFind = pNames;
110 } 110 }
111 if (iCompare < 0) { 111 if (iCompare < 0) {
112 continue; 112 continue;
113 } 113 }
114 } else { 114 } else {
115 break; 115 break;
(...skipping 29 matching lines...) Expand all
145 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names")); 145 CPDF_Array* pNames = pNode->GetArray(FX_BSTRC("Names"));
146 if (pNames) { 146 if (pNames) {
147 int nCount = pNames->GetCount() / 2; 147 int nCount = pNames->GetCount() / 2;
148 if (nIndex >= nCurIndex + nCount) { 148 if (nIndex >= nCurIndex + nCount) {
149 nCurIndex += nCount; 149 nCurIndex += nCount;
150 return NULL; 150 return NULL;
151 } else { 151 } else {
152 if (ppFind != NULL) { 152 if (ppFind != NULL) {
153 *ppFind = pNames; 153 *ppFind = pNames;
154 } 154 }
155 csName = pNames->GetString((nIndex - nCurIndex) * 2); 155 csName = pNames->GetStringAt((nIndex - nCurIndex) * 2);
156 return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1); 156 return pNames->GetElementValue((nIndex - nCurIndex) * 2 + 1);
157 } 157 }
158 } 158 }
159 CPDF_Array* pKids = pNode->GetArray(FX_BSTRC("Kids")); 159 CPDF_Array* pKids = pNode->GetArray(FX_BSTRC("Kids"));
160 if (pKids == NULL) { 160 if (pKids == NULL) {
161 return NULL; 161 return NULL;
162 } 162 }
163 for (FX_DWORD i = 0; i < pKids->GetCount(); i ++) { 163 for (FX_DWORD i = 0; i < pKids->GetCount(); i ++) {
164 CPDF_Dictionary* pKid = pKids->GetDict(i); 164 CPDF_Dictionary* pKid = pKids->GetDict(i);
165 if (pKid == NULL) { 165 if (pKid == NULL) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 316 }
317 FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString &csFileName) const 317 FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString &csFileName) const
318 { 318 {
319 if (m_pObj == NULL) { 319 if (m_pObj == NULL) {
320 return FALSE; 320 return FALSE;
321 } 321 }
322 if (m_pObj->GetType() == PDFOBJ_DICTIONARY) { 322 if (m_pObj->GetType() == PDFOBJ_DICTIONARY) {
323 CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj; 323 CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj;
324 csFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); 324 csFileName = pDict->GetUnicodeText(FX_BSTRC("UF"));
325 if (csFileName.IsEmpty()) { 325 if (csFileName.IsEmpty()) {
326 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F" ))); 326 csFileName = CFX_WideString::FromLocal(pDict->GetStringAt("F"));
327 } 327 }
328 if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) { 328 if (pDict->GetStringAt("FS") == "URL") {
329 return TRUE; 329 return TRUE;
330 } 330 }
331 if (csFileName.IsEmpty()) { 331 if (csFileName.IsEmpty()) {
332 if (pDict->KeyExist(FX_BSTRC("DOS"))) { 332 if (pDict->KeyExist(FX_BSTRC("DOS"))) {
333 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC ("DOS"))); 333 csFileName = CFX_WideString::FromLocal(
334 pDict->GetStringAt("DOS"));
334 } else if (pDict->KeyExist(FX_BSTRC("Mac"))) { 335 } else if (pDict->KeyExist(FX_BSTRC("Mac"))) {
335 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC ("Mac"))); 336 csFileName = CFX_WideString::FromLocal(
337 pDict->GetStringAt("Mac"));
336 } else if (pDict->KeyExist(FX_BSTRC("Unix"))) { 338 } else if (pDict->KeyExist(FX_BSTRC("Unix"))) {
337 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC ("Unix"))); 339 csFileName = CFX_WideString::FromLocal(
340 pDict->GetStringAt("Unix"));
338 } else { 341 } else {
339 return FALSE; 342 return FALSE;
340 } 343 }
341 } 344 }
342 } else { 345 } else {
343 csFileName = CFX_WideString::FromLocal(m_pObj->GetString()); 346 csFileName = CFX_WideString::FromLocal(m_pObj->GetString());
344 } 347 }
345 csFileName = FILESPEC_DecodeFileName(csFileName); 348 csFileName = FILESPEC_DecodeFileName(csFileName);
346 return TRUE; 349 return TRUE;
347 } 350 }
348 CPDF_FileSpec::CPDF_FileSpec() 351 CPDF_FileSpec::CPDF_FileSpec()
349 { 352 {
350 m_pObj = CPDF_Dictionary::Create(); 353 m_pObj = CPDF_Dictionary::Create();
351 if (m_pObj != NULL) { 354 if (m_pObj != NULL) {
352 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filesp ec")); 355 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filesp ec"));
353 } 356 }
354 } 357 }
355 FX_BOOL CPDF_FileSpec::IsURL() const 358 FX_BOOL CPDF_FileSpec::IsURL() const
356 { 359 {
357 if (m_pObj == NULL) { 360 if (m_pObj == NULL) {
358 return FALSE; 361 return FALSE;
359 } 362 }
360 if (m_pObj->GetType() != PDFOBJ_DICTIONARY) { 363 if (m_pObj->GetType() != PDFOBJ_DICTIONARY) {
361 return FALSE; 364 return FALSE;
362 } 365 }
363 return ((CPDF_Dictionary*)m_pObj)->GetString(FX_BSTRC("FS")) == FX_BSTRC("UR L"); 366 return ((CPDF_Dictionary*)m_pObj)->GetStringAt("FS") == "URL";
364 } 367 }
365 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) 368 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath)
366 { 369 {
367 if (filepath.GetLength() <= 1) { 370 if (filepath.GetLength() <= 1) {
368 return CFX_WideString(); 371 return CFX_WideString();
369 } 372 }
370 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 373 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
371 if (filepath.GetAt(1) == ':') { 374 if (filepath.GetAt(1) == ':') {
372 CFX_WideString result; 375 CFX_WideString result;
373 result = '/'; 376 result = '/';
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 526 }
524 n--; 527 n--;
525 } 528 }
526 if (pValue != NULL) { 529 if (pValue != NULL) {
527 pValue = pValue->GetDirect(); 530 pValue = pValue->GetDirect();
528 if (pValue->GetType() == PDFOBJ_DICTIONARY) { 531 if (pValue->GetType() == PDFOBJ_DICTIONARY) {
529 CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue; 532 CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue;
530 if (pLabel->KeyExist(FX_BSTRC("P"))) { 533 if (pLabel->KeyExist(FX_BSTRC("P"))) {
531 wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P")); 534 wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P"));
532 } 535 }
533 CFX_ByteString bsNumberingStyle = pLabel->GetString(FX_BSTRC("S"), N ULL); 536 CFX_ByteString bsNumberingStyle = pLabel->GetStringAt("S", NULL);
534 int nLabelNum = nPage - n + pLabel->GetInteger(FX_BSTRC("St"), 1); 537 int nLabelNum = nPage - n + pLabel->GetInteger(FX_BSTRC("St"), 1);
535 CFX_WideString wsNumPortion = _GetLabelNumPortion(nLabelNum, bsNumbe ringStyle); 538 CFX_WideString wsNumPortion = _GetLabelNumPortion(nLabelNum, bsNumbe ringStyle);
536 wsLabel += wsNumPortion; 539 wsLabel += wsNumPortion;
537 return wsLabel; 540 return wsLabel;
538 } 541 }
539 } 542 }
540 wsLabel.Format(L"%d", nPage + 1); 543 wsLabel.Format(L"%d", nPage + 1);
541 return wsLabel; 544 return wsLabel;
542 } 545 }
543 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const 546 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const
(...skipping 19 matching lines...) Expand all
563 if (nPage > 0 && nPage <= nPages) { 566 if (nPage > 0 && nPage <= nPages) {
564 return nPage; 567 return nPage;
565 } 568 }
566 return -1; 569 return -1;
567 } 570 }
568 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const 571 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const
569 { 572 {
570 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); 573 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr());
571 return GetPageByLabel(bsLabel); 574 return GetPageByLabel(bsLabel);
572 } 575 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698