| 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 "../../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 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 10 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { |
| 11 return 0; | 11 return 0; |
| 12 } | 12 } |
| 13 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); | 13 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); |
| 14 if (pPage == NULL) { | 14 if (pPage == NULL) { |
| 15 return 0; | 15 return 0; |
| 16 } | 16 } |
| 17 if (pPage->GetType() == PDFOBJ_NUMBER) { | 17 if (pPage->GetType() == PDFOBJ_NUMBER) { |
| 18 return pPage->GetInteger(); | 18 return pPage->GetInteger(); |
| 19 } | 19 } |
| 20 if (pPage->GetType() != PDFOBJ_DICTIONARY) { | 20 if (!pPage->IsDictionary()) { |
| 21 return 0; | 21 return 0; |
| 22 } | 22 } |
| 23 return pDoc->GetPageIndex(pPage->GetObjNum()); | 23 return pDoc->GetPageIndex(pPage->GetObjNum()); |
| 24 } | 24 } |
| 25 FX_DWORD CPDF_Dest::GetPageObjNum() { | 25 FX_DWORD CPDF_Dest::GetPageObjNum() { |
| 26 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 26 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { |
| 27 return 0; | 27 return 0; |
| 28 } | 28 } |
| 29 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); | 29 CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0); |
| 30 if (pPage == NULL) { | 30 if (pPage == NULL) { |
| 31 return 0; | 31 return 0; |
| 32 } | 32 } |
| 33 if (pPage->GetType() == PDFOBJ_NUMBER) { | 33 if (pPage->GetType() == PDFOBJ_NUMBER) { |
| 34 return pPage->GetInteger(); | 34 return pPage->GetInteger(); |
| 35 } | 35 } |
| 36 if (pPage->GetType() == PDFOBJ_DICTIONARY) { | 36 if (pPage->IsDictionary()) { |
| 37 return pPage->GetObjNum(); | 37 return pPage->GetObjNum(); |
| 38 } | 38 } |
| 39 return 0; | 39 return 0; |
| 40 } | 40 } |
| 41 const FX_CHAR* g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR", | 41 const FX_CHAR* g_sZoomModes[] = {"XYZ", "Fit", "FitH", "FitV", "FitR", |
| 42 "FitB", "FitBH", "FitBV", ""}; | 42 "FitB", "FitBH", "FitBV", ""}; |
| 43 int CPDF_Dest::GetZoomMode() { | 43 int CPDF_Dest::GetZoomMode() { |
| 44 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { | 44 if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) { |
| 45 return 0; | 45 return 0; |
| 46 } | 46 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 return NULL; | 236 return NULL; |
| 237 } | 237 } |
| 238 pValue = pDests->GetElementValue(sName); | 238 pValue = pDests->GetElementValue(sName); |
| 239 } | 239 } |
| 240 if (pValue == NULL) { | 240 if (pValue == NULL) { |
| 241 return NULL; | 241 return NULL; |
| 242 } | 242 } |
| 243 if (pValue->GetType() == PDFOBJ_ARRAY) { | 243 if (pValue->GetType() == PDFOBJ_ARRAY) { |
| 244 return (CPDF_Array*)pValue; | 244 return (CPDF_Array*)pValue; |
| 245 } | 245 } |
| 246 if (pValue->GetType() == PDFOBJ_DICTIONARY) { | 246 if (CPDF_Dictionary* pDict = pValue->AsDictionary()) { |
| 247 return ((CPDF_Dictionary*)pValue)->GetArray(FX_BSTRC("D")); | 247 return pDict->GetArray(FX_BSTRC("D")); |
| 248 } | 248 } |
| 249 return NULL; | 249 return NULL; |
| 250 } | 250 } |
| 251 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ | 251 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ |
| 252 _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 252 _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 253 static CFX_WideString ChangeSlashToPlatform(const FX_WCHAR* str) { | 253 static CFX_WideString ChangeSlashToPlatform(const FX_WCHAR* str) { |
| 254 CFX_WideString result; | 254 CFX_WideString result; |
| 255 while (*str) { | 255 while (*str) { |
| 256 if (*str == '/') { | 256 if (*str == '/') { |
| 257 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 257 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 304 } |
| 305 CFX_WideString result; | 305 CFX_WideString result; |
| 306 result += '\\'; | 306 result += '\\'; |
| 307 result += ChangeSlashToPlatform(filepath.GetPtr()); | 307 result += ChangeSlashToPlatform(filepath.GetPtr()); |
| 308 return result; | 308 return result; |
| 309 #else | 309 #else |
| 310 return filepath; | 310 return filepath; |
| 311 #endif | 311 #endif |
| 312 } | 312 } |
| 313 FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString& csFileName) const { | 313 FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString& csFileName) const { |
| 314 if (m_pObj == NULL) { | 314 if (!m_pObj) { |
| 315 return FALSE; | 315 return FALSE; |
| 316 } | 316 } |
| 317 if (m_pObj->GetType() == PDFOBJ_DICTIONARY) { | 317 if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { |
| 318 CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj; | |
| 319 csFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); | 318 csFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); |
| 320 if (csFileName.IsEmpty()) { | 319 if (csFileName.IsEmpty()) { |
| 321 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F"))); | 320 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F"))); |
| 322 } | 321 } |
| 323 if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) { | 322 if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) { |
| 324 return TRUE; | 323 return TRUE; |
| 325 } | 324 } |
| 326 if (csFileName.IsEmpty()) { | 325 if (csFileName.IsEmpty()) { |
| 327 if (pDict->KeyExist(FX_BSTRC("DOS"))) { | 326 if (pDict->KeyExist(FX_BSTRC("DOS"))) { |
| 328 csFileName = | 327 csFileName = |
| 329 CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("DOS"))); | 328 CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("DOS"))); |
| 330 } else if (pDict->KeyExist(FX_BSTRC("Mac"))) { | 329 } else if (pDict->KeyExist(FX_BSTRC("Mac"))) { |
| 331 csFileName = | 330 csFileName = |
| 332 CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("Mac"))); | 331 CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("Mac"))); |
| 333 } else if (pDict->KeyExist(FX_BSTRC("Unix"))) { | 332 } else if (pDict->KeyExist(FX_BSTRC("Unix"))) { |
| 334 csFileName = | 333 csFileName = |
| 335 CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("Unix"))); | 334 CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("Unix"))); |
| 336 } else { | 335 } else { |
| 337 return FALSE; | 336 return FALSE; |
| 338 } | 337 } |
| 339 } | 338 } |
| 340 } else { | 339 } else { |
| 341 csFileName = CFX_WideString::FromLocal(m_pObj->GetString()); | 340 csFileName = CFX_WideString::FromLocal(m_pObj->GetString()); |
| 342 } | 341 } |
| 343 csFileName = FILESPEC_DecodeFileName(csFileName); | 342 csFileName = FILESPEC_DecodeFileName(csFileName); |
| 344 return TRUE; | 343 return TRUE; |
| 345 } | 344 } |
| 346 CPDF_FileSpec::CPDF_FileSpec() { | 345 CPDF_FileSpec::CPDF_FileSpec() { |
| 347 m_pObj = CPDF_Dictionary::Create(); | 346 m_pObj = CPDF_Dictionary::Create(); |
| 348 if (m_pObj != NULL) { | 347 if (CPDF_Dictionary* pDict = ToDictionary(m_pObj)) { |
| 349 ((CPDF_Dictionary*)m_pObj) | 348 pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filespec")); |
| 350 ->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filespec")); | |
| 351 } | 349 } |
| 352 } | 350 } |
| 353 FX_BOOL CPDF_FileSpec::IsURL() const { | 351 FX_BOOL CPDF_FileSpec::IsURL() const { |
| 354 if (m_pObj == NULL) { | 352 if (CPDF_Dictionary* pDict = ToDictionary(m_pObj)) { |
| 355 return FALSE; | 353 return pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL"); |
| 356 } | 354 } |
| 357 if (m_pObj->GetType() != PDFOBJ_DICTIONARY) { | 355 return FALSE; |
| 358 return FALSE; | |
| 359 } | |
| 360 return ((CPDF_Dictionary*)m_pObj)->GetString(FX_BSTRC("FS")) == | |
| 361 FX_BSTRC("URL"); | |
| 362 } | 356 } |
| 363 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) { | 357 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) { |
| 364 if (filepath.GetLength() <= 1) { | 358 if (filepath.GetLength() <= 1) { |
| 365 return CFX_WideString(); | 359 return CFX_WideString(); |
| 366 } | 360 } |
| 367 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 361 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 368 if (filepath.GetAt(1) == ':') { | 362 if (filepath.GetAt(1) == ':') { |
| 369 CFX_WideString result; | 363 CFX_WideString result; |
| 370 result = '/'; | 364 result = '/'; |
| 371 result += filepath.GetAt(0); | 365 result += filepath.GetAt(0); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 395 return ChangeSlashToPDF(filepath.GetPtr()); | 389 return ChangeSlashToPDF(filepath.GetPtr()); |
| 396 #else | 390 #else |
| 397 return filepath; | 391 return filepath; |
| 398 #endif | 392 #endif |
| 399 } | 393 } |
| 400 CPDF_Stream* CPDF_FileSpec::GetFileStream() const { | 394 CPDF_Stream* CPDF_FileSpec::GetFileStream() const { |
| 401 if (m_pObj == NULL) { | 395 if (m_pObj == NULL) { |
| 402 return NULL; | 396 return NULL; |
| 403 } | 397 } |
| 404 int32_t iType = m_pObj->GetType(); | 398 int32_t iType = m_pObj->GetType(); |
| 405 if (iType == PDFOBJ_STREAM) { | 399 if (iType == PDFOBJ_STREAM) |
| 406 return (CPDF_Stream*)m_pObj; | 400 return (CPDF_Stream*)m_pObj; |
| 407 } else if (iType == PDFOBJ_DICTIONARY) { | 401 if (CPDF_Dictionary* pEF = m_pObj->AsDictionary()->GetDict(FX_BSTRC("EF"))) |
| 408 CPDF_Dictionary* pEF = ((CPDF_Dictionary*)m_pObj)->GetDict(FX_BSTRC("EF")); | |
| 409 if (pEF == NULL) { | |
| 410 return NULL; | |
| 411 } | |
| 412 return pEF->GetStream(FX_BSTRC("F")); | 402 return pEF->GetStream(FX_BSTRC("F")); |
| 413 } | |
| 414 return NULL; | 403 return NULL; |
| 415 } | 404 } |
| 416 static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj, | 405 static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj, |
| 417 const CFX_WideStringC& wsFileName, | 406 const CFX_WideStringC& wsFileName, |
| 418 FX_BOOL bURL) { | 407 FX_BOOL bURL) { |
| 419 ASSERT(pObj != NULL); | 408 ASSERT(pObj != NULL); |
| 420 CFX_WideString wsStr; | 409 CFX_WideString wsStr; |
| 421 if (bURL) { | 410 if (bURL) { |
| 422 wsStr = wsFileName; | 411 wsStr = wsFileName; |
| 423 } else { | 412 } else { |
| 424 wsStr = FILESPEC_EncodeFileName(wsFileName); | 413 wsStr = FILESPEC_EncodeFileName(wsFileName); |
| 425 } | 414 } |
| 426 int32_t iType = pObj->GetType(); | 415 int32_t iType = pObj->GetType(); |
| 427 if (iType == PDFOBJ_STRING) { | 416 if (iType == PDFOBJ_STRING) { |
| 428 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); | 417 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); |
| 429 } else if (iType == PDFOBJ_DICTIONARY) { | 418 } else if (CPDF_Dictionary* pDict = pObj->AsDictionary()) { |
| 430 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; | |
| 431 pDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(wsStr)); | 419 pDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(wsStr)); |
| 432 pDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsStr)); | 420 pDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsStr)); |
| 433 } | 421 } |
| 434 } | 422 } |
| 435 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, | 423 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, |
| 436 FX_BOOL bURL) { | 424 FX_BOOL bURL) { |
| 437 ASSERT(m_pObj != NULL); | 425 ASSERT(m_pObj != NULL); |
| 438 if (m_pObj->GetType() == PDFOBJ_DICTIONARY && bURL) { | 426 if (bURL) { |
| 439 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("FS"), "URL"); | 427 if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { |
| 428 pDict->SetAtName(FX_BSTRC("FS"), "URL"); |
| 429 } |
| 440 } | 430 } |
| 441 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); | 431 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); |
| 442 } | 432 } |
| 443 static CFX_WideString _MakeRoman(int num) { | 433 static CFX_WideString _MakeRoman(int num) { |
| 444 const int arabic[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; | 434 const int arabic[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; |
| 445 const CFX_WideString roman[] = {L"m", L"cm", L"d", L"cd", L"c", | 435 const CFX_WideString roman[] = {L"m", L"cm", L"d", L"cd", L"c", |
| 446 L"xc", L"l", L"xl", L"x", L"ix", | 436 L"xc", L"l", L"xl", L"x", L"ix", |
| 447 L"v", L"iv", L"i"}; | 437 L"v", L"iv", L"i"}; |
| 448 const int nMaxNum = 1000000; | 438 const int nMaxNum = 1000000; |
| 449 num %= nMaxNum; | 439 num %= nMaxNum; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 int n = nPage; | 500 int n = nPage; |
| 511 while (n >= 0) { | 501 while (n >= 0) { |
| 512 pValue = numberTree.LookupValue(n); | 502 pValue = numberTree.LookupValue(n); |
| 513 if (pValue != NULL) { | 503 if (pValue != NULL) { |
| 514 break; | 504 break; |
| 515 } | 505 } |
| 516 n--; | 506 n--; |
| 517 } | 507 } |
| 518 if (pValue != NULL) { | 508 if (pValue != NULL) { |
| 519 pValue = pValue->GetDirect(); | 509 pValue = pValue->GetDirect(); |
| 520 if (pValue->GetType() == PDFOBJ_DICTIONARY) { | 510 if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) { |
| 521 CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue; | |
| 522 if (pLabel->KeyExist(FX_BSTRC("P"))) { | 511 if (pLabel->KeyExist(FX_BSTRC("P"))) { |
| 523 wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P")); | 512 wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P")); |
| 524 } | 513 } |
| 525 CFX_ByteString bsNumberingStyle = pLabel->GetString(FX_BSTRC("S"), NULL); | 514 CFX_ByteString bsNumberingStyle = pLabel->GetString(FX_BSTRC("S"), NULL); |
| 526 int nLabelNum = nPage - n + pLabel->GetInteger(FX_BSTRC("St"), 1); | 515 int nLabelNum = nPage - n + pLabel->GetInteger(FX_BSTRC("St"), 1); |
| 527 CFX_WideString wsNumPortion = | 516 CFX_WideString wsNumPortion = |
| 528 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); | 517 _GetLabelNumPortion(nLabelNum, bsNumberingStyle); |
| 529 wsLabel += wsNumPortion; | 518 wsLabel += wsNumPortion; |
| 530 return wsLabel; | 519 return wsLabel; |
| 531 } | 520 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 554 int nPage = FXSYS_atoi(bsLbl); | 543 int nPage = FXSYS_atoi(bsLbl); |
| 555 if (nPage > 0 && nPage <= nPages) { | 544 if (nPage > 0 && nPage <= nPages) { |
| 556 return nPage; | 545 return nPage; |
| 557 } | 546 } |
| 558 return -1; | 547 return -1; |
| 559 } | 548 } |
| 560 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { | 549 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { |
| 561 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); | 550 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); |
| 562 return GetPageByLabel(bsLabel); | 551 return GetPageByLabel(bsLabel); |
| 563 } | 552 } |
| OLD | NEW |