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 { | 10 { |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 return result; | 306 return result; |
307 } | 307 } |
308 CFX_WideString result; | 308 CFX_WideString result; |
309 result += '\\'; | 309 result += '\\'; |
310 result += ChangeSlashToPlatform(filepath.GetPtr()); | 310 result += ChangeSlashToPlatform(filepath.GetPtr()); |
311 return result; | 311 return result; |
312 #else | 312 #else |
313 return filepath; | 313 return filepath; |
314 #endif | 314 #endif |
315 } | 315 } |
316 FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString &csFileName) const | 316 bool CPDF_FileSpec::GetFileName(CFX_WideString &csFileName) const |
317 { | 317 { |
318 if (m_pObj == NULL) { | 318 if (m_pObj == NULL) { |
319 return FALSE; | 319 return false; |
320 } | 320 } |
321 if (m_pObj->GetType() == PDFOBJ_DICTIONARY) { | 321 if (m_pObj->GetType() == PDFOBJ_DICTIONARY) { |
322 CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj; | 322 CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj; |
323 csFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); | 323 csFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); |
324 if (csFileName.IsEmpty()) { | 324 if (csFileName.IsEmpty()) { |
325 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F"
))); | 325 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F"
))); |
326 } | 326 } |
327 if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) { | 327 if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) { |
328 return TRUE; | 328 return true; |
329 } | 329 } |
330 if (csFileName.IsEmpty()) { | 330 if (csFileName.IsEmpty()) { |
331 if (pDict->KeyExist(FX_BSTRC("DOS"))) { | 331 if (pDict->KeyExist(FX_BSTRC("DOS"))) { |
332 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC
("DOS"))); | 332 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC
("DOS"))); |
333 } else if (pDict->KeyExist(FX_BSTRC("Mac"))) { | 333 } else if (pDict->KeyExist(FX_BSTRC("Mac"))) { |
334 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC
("Mac"))); | 334 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC
("Mac"))); |
335 } else if (pDict->KeyExist(FX_BSTRC("Unix"))) { | 335 } else if (pDict->KeyExist(FX_BSTRC("Unix"))) { |
336 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC
("Unix"))); | 336 csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC
("Unix"))); |
337 } else { | 337 } else { |
338 return FALSE; | 338 return false; |
339 } | 339 } |
340 } | 340 } |
341 } else { | 341 } else { |
342 csFileName = CFX_WideString::FromLocal(m_pObj->GetString()); | 342 csFileName = CFX_WideString::FromLocal(m_pObj->GetString()); |
343 } | 343 } |
344 csFileName = FILESPEC_DecodeFileName(csFileName); | 344 csFileName = FILESPEC_DecodeFileName(csFileName); |
345 return TRUE; | 345 return true; |
346 } | 346 } |
347 CPDF_FileSpec::CPDF_FileSpec() | 347 CPDF_FileSpec::CPDF_FileSpec() |
348 { | 348 { |
349 m_pObj = CPDF_Dictionary::Create(); | 349 m_pObj = CPDF_Dictionary::Create(); |
350 if (m_pObj != NULL) { | 350 if (m_pObj != NULL) { |
351 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filesp
ec")); | 351 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filesp
ec")); |
352 } | 352 } |
353 } | 353 } |
354 FX_BOOL CPDF_FileSpec::IsURL() const | 354 bool CPDF_FileSpec::IsURL() const |
355 { | 355 { |
356 if (m_pObj == NULL) { | 356 if (m_pObj == NULL) { |
357 return FALSE; | 357 return false; |
358 } | 358 } |
359 if (m_pObj->GetType() != PDFOBJ_DICTIONARY) { | 359 if (m_pObj->GetType() != PDFOBJ_DICTIONARY) { |
360 return FALSE; | 360 return false; |
361 } | 361 } |
362 return ((CPDF_Dictionary*)m_pObj)->GetString(FX_BSTRC("FS")) == FX_BSTRC("UR
L"); | 362 return ((CPDF_Dictionary*)m_pObj)->GetString(FX_BSTRC("FS")) == FX_BSTRC("UR
L"); |
363 } | 363 } |
364 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) | 364 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) |
365 { | 365 { |
366 if (filepath.GetLength() <= 1) { | 366 if (filepath.GetLength() <= 1) { |
367 return CFX_WideString(); | 367 return CFX_WideString(); |
368 } | 368 } |
369 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 369 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
370 if (filepath.GetAt(1) == ':') { | 370 if (filepath.GetAt(1) == ':') { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 return (CPDF_Stream*)m_pObj; | 409 return (CPDF_Stream*)m_pObj; |
410 } else if (iType == PDFOBJ_DICTIONARY) { | 410 } else if (iType == PDFOBJ_DICTIONARY) { |
411 CPDF_Dictionary *pEF = ((CPDF_Dictionary*)m_pObj)->GetDict(FX_BSTRC("EF"
)); | 411 CPDF_Dictionary *pEF = ((CPDF_Dictionary*)m_pObj)->GetDict(FX_BSTRC("EF"
)); |
412 if (pEF == NULL) { | 412 if (pEF == NULL) { |
413 return NULL; | 413 return NULL; |
414 } | 414 } |
415 return pEF->GetStream(FX_BSTRC("F")); | 415 return pEF->GetStream(FX_BSTRC("F")); |
416 } | 416 } |
417 return NULL; | 417 return NULL; |
418 } | 418 } |
419 static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object *pObj, const CFX_WideString
C& wsFileName, FX_BOOL bURL) | 419 static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object *pObj, const CFX_WideString
C& wsFileName, bool bURL) |
420 { | 420 { |
421 ASSERT(pObj != NULL); | 421 ASSERT(pObj != NULL); |
422 CFX_WideString wsStr; | 422 CFX_WideString wsStr; |
423 if (bURL) { | 423 if (bURL) { |
424 wsStr = wsFileName; | 424 wsStr = wsFileName; |
425 } else { | 425 } else { |
426 wsStr = FILESPEC_EncodeFileName(wsFileName); | 426 wsStr = FILESPEC_EncodeFileName(wsFileName); |
427 } | 427 } |
428 int32_t iType = pObj->GetType(); | 428 int32_t iType = pObj->GetType(); |
429 if (iType == PDFOBJ_STRING) { | 429 if (iType == PDFOBJ_STRING) { |
430 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); | 430 pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); |
431 } else if (iType == PDFOBJ_DICTIONARY) { | 431 } else if (iType == PDFOBJ_DICTIONARY) { |
432 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; | 432 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; |
433 pDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(wsStr)); | 433 pDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(wsStr)); |
434 pDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsStr)); | 434 pDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsStr)); |
435 } | 435 } |
436 } | 436 } |
437 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, FX_BOOL bURL) | 437 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName, bool bURL) |
438 { | 438 { |
439 ASSERT(m_pObj != NULL); | 439 ASSERT(m_pObj != NULL); |
440 if (m_pObj->GetType() == PDFOBJ_DICTIONARY && bURL) { | 440 if (m_pObj->GetType() == PDFOBJ_DICTIONARY && bURL) { |
441 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("FS"), "URL"); | 441 ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("FS"), "URL"); |
442 } | 442 } |
443 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); | 443 FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL); |
444 } | 444 } |
445 static CFX_WideString _MakeRoman(int num) | 445 static CFX_WideString _MakeRoman(int num) |
446 { | 446 { |
447 const int arabic[] = { | 447 const int arabic[] = { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 if (nPage > 0 && nPage <= nPages) { | 562 if (nPage > 0 && nPage <= nPages) { |
563 return nPage; | 563 return nPage; |
564 } | 564 } |
565 return -1; | 565 return -1; |
566 } | 566 } |
567 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const | 567 int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const |
568 { | 568 { |
569 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); | 569 CFX_ByteString bsLabel = PDF_EncodeText(wsLabel.GetPtr()); |
570 return GetPageByLabel(bsLabel); | 570 return GetPageByLabel(bsLabel); |
571 } | 571 } |
OLD | NEW |