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/fpdfapi/parser/cpdf_document.h" | 7 #include "core/fpdfapi/parser/cpdf_document.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 if (objnum) { | 485 if (objnum) { |
486 if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(objnum))) | 486 if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(objnum))) |
487 return pDict; | 487 return pDict; |
488 return nullptr; | 488 return nullptr; |
489 } | 489 } |
490 | 490 |
491 CPDF_Dictionary* pPages = GetPagesDict(); | 491 CPDF_Dictionary* pPages = GetPagesDict(); |
492 if (!pPages) | 492 if (!pPages) |
493 return nullptr; | 493 return nullptr; |
494 | 494 |
| 495 if (iPage - m_iNextPageToTraverse + 1 <= 0) { |
| 496 // This can happen when the page does not have an object number. On repeated |
| 497 // calls to this function for the same page index, this condition causes |
| 498 // TraversePDFPages() to incorrectly return nullptr. |
| 499 // Example "testing/corpus/fx/other/jetman_std.pdf" |
| 500 // We should restart traversing in this case. |
| 501 // TODO(art-snake): optimize this. |
| 502 ResetTraversal(); |
| 503 } |
| 504 int nPagesToGo = iPage - m_iNextPageToTraverse + 1; |
495 if (m_pTreeTraversal.empty()) | 505 if (m_pTreeTraversal.empty()) |
496 m_pTreeTraversal.push_back(std::make_pair(pPages, 0)); | 506 m_pTreeTraversal.push_back(std::make_pair(pPages, 0)); |
497 int nPagesToGo = iPage - m_iNextPageToTraverse + 1; | |
498 CPDF_Dictionary* pPage = TraversePDFPages(iPage, &nPagesToGo, 0); | 507 CPDF_Dictionary* pPage = TraversePDFPages(iPage, &nPagesToGo, 0); |
499 m_iNextPageToTraverse = iPage + 1; | 508 m_iNextPageToTraverse = iPage + 1; |
500 return pPage; | 509 return pPage; |
501 } | 510 } |
502 | 511 |
503 void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) { | 512 void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) { |
504 m_PageList.SetAt(iPage, objNum); | 513 m_PageList.SetAt(iPage, objNum); |
505 } | 514 } |
506 | 515 |
507 int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, | 516 int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 pBBox, pLogFont->lfWeight / 5); | 1046 pBBox, pLogFont->lfWeight / 5); |
1038 pFontDesc->SetIntegerFor("CapHeight", capheight); | 1047 pFontDesc->SetIntegerFor("CapHeight", capheight); |
1039 pFontDict->SetReferenceFor("FontDescriptor", this, | 1048 pFontDict->SetReferenceFor("FontDescriptor", this, |
1040 AddIndirectObject(pFontDesc)); | 1049 AddIndirectObject(pFontDesc)); |
1041 hFont = SelectObject(hDC, hFont); | 1050 hFont = SelectObject(hDC, hFont); |
1042 DeleteObject(hFont); | 1051 DeleteObject(hFont); |
1043 DeleteDC(hDC); | 1052 DeleteDC(hDC); |
1044 return LoadFont(pBaseDict); | 1053 return LoadFont(pBaseDict); |
1045 } | 1054 } |
1046 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1055 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
OLD | NEW |