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 "parser_int.h" | 7 #include "parser_int.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 if (!LoadCrossRefV5(&xrefpos, TRUE)) { | 589 if (!LoadCrossRefV5(&xrefpos, TRUE)) { |
590 return FALSE; | 590 return FALSE; |
591 } | 591 } |
592 std::set<FX_FILESIZE> seen_xrefpos; | 592 std::set<FX_FILESIZE> seen_xrefpos; |
593 while (xrefpos) { | 593 while (xrefpos) { |
594 seen_xrefpos.insert(xrefpos); | 594 seen_xrefpos.insert(xrefpos); |
595 if (!LoadCrossRefV5(&xrefpos, FALSE)) { | 595 if (!LoadCrossRefV5(&xrefpos, FALSE)) { |
596 return FALSE; | 596 return FALSE; |
597 } | 597 } |
598 // Check for circular references. | 598 // Check for circular references. |
599 if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) { | 599 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) { |
600 return FALSE; | 600 return FALSE; |
601 } | 601 } |
602 } | 602 } |
603 m_ObjectStreamMap.InitHashTable(101, FALSE); | 603 m_ObjectStreamMap.InitHashTable(101, FALSE); |
604 m_bXRefStream = TRUE; | 604 m_bXRefStream = TRUE; |
605 return TRUE; | 605 return TRUE; |
606 } | 606 } |
607 | 607 |
608 FX_BOOL CPDF_Parser::RebuildCrossRef() { | 608 FX_BOOL CPDF_Parser::RebuildCrossRef() { |
609 m_ObjectInfo.clear(); | 609 m_ObjectInfo.clear(); |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 if (!pObjStream) | 1197 if (!pObjStream) |
1198 return nullptr; | 1198 return nullptr; |
1199 | 1199 |
1200 ScopedFileStream file(FX_CreateMemoryStream( | 1200 ScopedFileStream file(FX_CreateMemoryStream( |
1201 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); | 1201 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); |
1202 CPDF_SyntaxParser syntax; | 1202 CPDF_SyntaxParser syntax; |
1203 syntax.InitParser(file.get(), 0); | 1203 syntax.InitParser(file.get(), 0); |
1204 const int32_t offset = GetStreamFirst(pObjStream); | 1204 const int32_t offset = GetStreamFirst(pObjStream); |
1205 | 1205 |
1206 // Read object numbers from |pObjStream| into a cache. | 1206 // Read object numbers from |pObjStream| into a cache. |
1207 if (m_ObjCache.find(pObjStream) == m_ObjCache.end()) { | 1207 if (!pdfium::ContainsKey(m_ObjCache, pObjStream)) { |
1208 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { | 1208 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { |
1209 FX_DWORD thisnum = syntax.GetDirectNum(); | 1209 FX_DWORD thisnum = syntax.GetDirectNum(); |
1210 FX_DWORD thisoff = syntax.GetDirectNum(); | 1210 FX_DWORD thisoff = syntax.GetDirectNum(); |
1211 m_ObjCache[pObjStream][thisnum] = thisoff; | 1211 m_ObjCache[pObjStream][thisnum] = thisoff; |
1212 } | 1212 } |
1213 } | 1213 } |
1214 | 1214 |
1215 const auto it = m_ObjCache[pObjStream].find(objnum); | 1215 const auto it = m_ObjCache[pObjStream].find(objnum); |
1216 if (it == m_ObjCache[pObjStream].end()) | 1216 if (it == m_ObjCache[pObjStream].end()) |
1217 return nullptr; | 1217 return nullptr; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 if (!LoadCrossRefV5(&xrefpos, FALSE)) { | 1627 if (!LoadCrossRefV5(&xrefpos, FALSE)) { |
1628 return FALSE; | 1628 return FALSE; |
1629 } | 1629 } |
1630 std::set<FX_FILESIZE> seen_xrefpos; | 1630 std::set<FX_FILESIZE> seen_xrefpos; |
1631 while (xrefpos) { | 1631 while (xrefpos) { |
1632 seen_xrefpos.insert(xrefpos); | 1632 seen_xrefpos.insert(xrefpos); |
1633 if (!LoadCrossRefV5(&xrefpos, FALSE)) { | 1633 if (!LoadCrossRefV5(&xrefpos, FALSE)) { |
1634 return FALSE; | 1634 return FALSE; |
1635 } | 1635 } |
1636 // Check for circular references. | 1636 // Check for circular references. |
1637 if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) { | 1637 if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) { |
1638 return FALSE; | 1638 return FALSE; |
1639 } | 1639 } |
1640 } | 1640 } |
1641 m_ObjectStreamMap.InitHashTable(101, FALSE); | 1641 m_ObjectStreamMap.InitHashTable(101, FALSE); |
1642 m_bXRefStream = TRUE; | 1642 m_bXRefStream = TRUE; |
1643 return TRUE; | 1643 return TRUE; |
1644 } | 1644 } |
1645 FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() { | 1645 FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() { |
1646 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum; | 1646 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum; |
1647 m_Syntax.m_MetadataObjnum = 0; | 1647 m_Syntax.m_MetadataObjnum = 0; |
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2759 int32_t& iCount, | 2759 int32_t& iCount, |
2760 IFX_DownloadHints* pHints, | 2760 IFX_DownloadHints* pHints, |
2761 int level); | 2761 int level); |
2762 FX_BOOL CheckUnkownPageNode(FX_DWORD dwPageNo, | 2762 FX_BOOL CheckUnkownPageNode(FX_DWORD dwPageNo, |
2763 CPDF_PageNode* pPageNode, | 2763 CPDF_PageNode* pPageNode, |
2764 IFX_DownloadHints* pHints); | 2764 IFX_DownloadHints* pHints); |
2765 FX_BOOL CheckArrayPageNode(FX_DWORD dwPageNo, | 2765 FX_BOOL CheckArrayPageNode(FX_DWORD dwPageNo, |
2766 CPDF_PageNode* pPageNode, | 2766 CPDF_PageNode* pPageNode, |
2767 IFX_DownloadHints* pHints); | 2767 IFX_DownloadHints* pHints); |
2768 FX_BOOL CheckPageCount(IFX_DownloadHints* pHints); | 2768 FX_BOOL CheckPageCount(IFX_DownloadHints* pHints); |
2769 FX_BOOL IsFirstCheck(int iPage); | 2769 bool IsFirstCheck(int iPage); |
2770 void ResetFirstCheck(int iPage); | 2770 void ResetFirstCheck(int iPage); |
2771 FX_BOOL IsDataAvail(FX_FILESIZE offset, | 2771 FX_BOOL IsDataAvail(FX_FILESIZE offset, |
2772 FX_DWORD size, | 2772 FX_DWORD size, |
2773 IFX_DownloadHints* pHints); | 2773 IFX_DownloadHints* pHints); |
2774 | 2774 |
2775 CPDF_Parser m_parser; | 2775 CPDF_Parser m_parser; |
2776 | 2776 |
2777 CPDF_SyntaxParser m_syntaxParser; | 2777 CPDF_SyntaxParser m_syntaxParser; |
2778 | 2778 |
2779 CPDF_Object* m_pRoot; | 2779 CPDF_Object* m_pRoot; |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3342 if (!pRef) { | 3342 if (!pRef) { |
3343 m_docStatus = PDF_DATAAVAIL_ERROR; | 3343 m_docStatus = PDF_DATAAVAIL_ERROR; |
3344 return FALSE; | 3344 return FALSE; |
3345 } | 3345 } |
3346 | 3346 |
3347 m_PagesObjNum = pRef->GetRefObjNum(); | 3347 m_PagesObjNum = pRef->GetRefObjNum(); |
3348 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser(); | 3348 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser(); |
3349 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3349 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3350 return TRUE; | 3350 return TRUE; |
3351 } | 3351 } |
3352 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) { | 3352 bool CPDF_DataAvail::IsFirstCheck(int iPage) { |
3353 if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end()) | 3353 return m_pageMapCheckState.insert(iPage).second; |
3354 return FALSE; | |
3355 | |
3356 m_pageMapCheckState.insert(iPage); | |
3357 return TRUE; | |
3358 } | 3354 } |
3359 void CPDF_DataAvail::ResetFirstCheck(int iPage) { | 3355 void CPDF_DataAvail::ResetFirstCheck(int iPage) { |
3360 m_pageMapCheckState.erase(iPage); | 3356 m_pageMapCheckState.erase(iPage); |
3361 } | 3357 } |
3362 FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) { | 3358 FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) { |
3363 FX_DWORD iPageObjs = m_PageObjList.GetSize(); | 3359 FX_DWORD iPageObjs = m_PageObjList.GetSize(); |
3364 CFX_DWordArray UnavailObjList; | 3360 CFX_DWordArray UnavailObjList; |
3365 for (FX_DWORD i = 0; i < iPageObjs; ++i) { | 3361 for (FX_DWORD i = 0; i < iPageObjs; ++i) { |
3366 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); | 3362 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); |
3367 FX_BOOL bExist = FALSE; | 3363 FX_BOOL bExist = FALSE; |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4374 return DataError; | 4370 return DataError; |
4375 } | 4371 } |
4376 if (IsFirstCheck(iPage)) { | 4372 if (IsFirstCheck(iPage)) { |
4377 m_bCurPageDictLoadOK = FALSE; | 4373 m_bCurPageDictLoadOK = FALSE; |
4378 m_bPageLoadedOK = FALSE; | 4374 m_bPageLoadedOK = FALSE; |
4379 m_bAnnotsLoad = FALSE; | 4375 m_bAnnotsLoad = FALSE; |
4380 m_bNeedDownLoadResource = FALSE; | 4376 m_bNeedDownLoadResource = FALSE; |
4381 m_objs_array.RemoveAll(); | 4377 m_objs_array.RemoveAll(); |
4382 m_objnum_array.RemoveAll(); | 4378 m_objnum_array.RemoveAll(); |
4383 } | 4379 } |
4384 if (m_pagesLoadState.find(iPage) != m_pagesLoadState.end()) { | 4380 if (pdfium::ContainsKey(m_pagesLoadState, iPage)) |
4385 return DataAvailable; | 4381 return DataAvailable; |
4386 } | 4382 |
4387 if (m_bLinearized) { | 4383 if (m_bLinearized) { |
4388 if ((FX_DWORD)iPage == m_dwFirstPageNo) { | 4384 if ((FX_DWORD)iPage == m_dwFirstPageNo) { |
4389 m_pagesLoadState.insert(iPage); | 4385 m_pagesLoadState.insert(iPage); |
4390 return DataAvailable; | 4386 return DataAvailable; |
4391 } | 4387 } |
4392 int32_t nResult = CheckLinearizedData(pHints); | 4388 int32_t nResult = CheckLinearizedData(pHints); |
4393 if (nResult != DataAvailable) { | 4389 if (nResult != DataAvailable) { |
4394 return nResult; | 4390 return nResult; |
4395 } | 4391 } |
4396 if (m_pHintTables) { | 4392 if (m_pHintTables) { |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4990 if (!m_pLinearizedDict) | 4986 if (!m_pLinearizedDict) |
4991 return -1; | 4987 return -1; |
4992 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4988 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4993 if (!pRange) | 4989 if (!pRange) |
4994 return -1; | 4990 return -1; |
4995 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4991 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4996 if (!pStreamLen) | 4992 if (!pStreamLen) |
4997 return -1; | 4993 return -1; |
4998 return pStreamLen->GetInteger(); | 4994 return pStreamLen->GetInteger(); |
4999 } | 4995 } |
OLD | NEW |