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 <set> |
7 #include <utility> | 8 #include <utility> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "../../../include/fpdfapi/fpdf_module.h" | 11 #include "../../../include/fpdfapi/fpdf_module.h" |
11 #include "../../../include/fpdfapi/fpdf_page.h" | 12 #include "../../../include/fpdfapi/fpdf_page.h" |
12 #include "../../../include/fpdfapi/fpdf_parser.h" | 13 #include "../../../include/fpdfapi/fpdf_parser.h" |
13 #include "../../../include/fxcrt/fx_safe_types.h" | 14 #include "../../../include/fxcrt/fx_safe_types.h" |
14 #include "../fpdf_page/pageint.h" | 15 #include "../fpdf_page/pageint.h" |
15 | 16 |
16 FX_BOOL IsSignatureDict(const CPDF_Dictionary* pDict) { | 17 FX_BOOL IsSignatureDict(const CPDF_Dictionary* pDict) { |
(...skipping 2988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3005 FX_DWORD m_dwEncryptObjNum; | 3006 FX_DWORD m_dwEncryptObjNum; |
3006 | 3007 |
3007 FX_FILESIZE m_dwPrevXRefOffset; | 3008 FX_FILESIZE m_dwPrevXRefOffset; |
3008 | 3009 |
3009 FX_BOOL m_bTotalLoadPageTree; | 3010 FX_BOOL m_bTotalLoadPageTree; |
3010 | 3011 |
3011 FX_BOOL m_bCurPageDictLoadOK; | 3012 FX_BOOL m_bCurPageDictLoadOK; |
3012 | 3013 |
3013 CPDF_PageNode m_pageNodes; | 3014 CPDF_PageNode m_pageNodes; |
3014 | 3015 |
3015 CFX_CMapDWordToDWord* m_pageMapCheckState; | 3016 std::set<FX_DWORD> m_pageMapCheckState; |
3016 | 3017 std::set<FX_DWORD> m_pagesLoadState; |
3017 CFX_CMapDWordToDWord* m_pagesLoadState; | |
3018 }; | 3018 }; |
3019 | 3019 |
3020 IPDF_DataAvail::IPDF_DataAvail(IFX_FileAvail* pFileAvail, | 3020 IPDF_DataAvail::IPDF_DataAvail(IFX_FileAvail* pFileAvail, |
3021 IFX_FileRead* pFileRead) | 3021 IFX_FileRead* pFileRead) |
3022 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) {} | 3022 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) {} |
3023 | 3023 |
3024 // static | 3024 // static |
3025 IPDF_DataAvail* IPDF_DataAvail::Create(IFX_FileAvail* pFileAvail, | 3025 IPDF_DataAvail* IPDF_DataAvail::Create(IFX_FileAvail* pFileAvail, |
3026 IFX_FileRead* pFileRead) { | 3026 IFX_FileRead* pFileRead) { |
3027 return new CPDF_DataAvail(pFileAvail, pFileRead); | 3027 return new CPDF_DataAvail(pFileAvail, pFileRead); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3065 m_bPageLoadedOK = FALSE; | 3065 m_bPageLoadedOK = FALSE; |
3066 m_bNeedDownLoadResource = FALSE; | 3066 m_bNeedDownLoadResource = FALSE; |
3067 m_bLinearizedFormParamLoad = FALSE; | 3067 m_bLinearizedFormParamLoad = FALSE; |
3068 m_pLinearized = NULL; | 3068 m_pLinearized = NULL; |
3069 m_pRoot = NULL; | 3069 m_pRoot = NULL; |
3070 m_pTrailer = NULL; | 3070 m_pTrailer = NULL; |
3071 m_pCurrentParser = NULL; | 3071 m_pCurrentParser = NULL; |
3072 m_pAcroForm = NULL; | 3072 m_pAcroForm = NULL; |
3073 m_pPageDict = NULL; | 3073 m_pPageDict = NULL; |
3074 m_pPageResource = NULL; | 3074 m_pPageResource = NULL; |
3075 m_pageMapCheckState = NULL; | |
3076 m_docStatus = PDF_DATAAVAIL_HEADER; | 3075 m_docStatus = PDF_DATAAVAIL_HEADER; |
3077 m_parser.m_bOwnFileRead = FALSE; | 3076 m_parser.m_bOwnFileRead = FALSE; |
3078 m_bTotalLoadPageTree = FALSE; | 3077 m_bTotalLoadPageTree = FALSE; |
3079 m_bCurPageDictLoadOK = FALSE; | 3078 m_bCurPageDictLoadOK = FALSE; |
3080 m_bLinearedDataOK = FALSE; | 3079 m_bLinearedDataOK = FALSE; |
3081 m_pagesLoadState = NULL; | |
3082 } | 3080 } |
3083 CPDF_DataAvail::~CPDF_DataAvail() { | 3081 CPDF_DataAvail::~CPDF_DataAvail() { |
3084 if (m_pLinearized) { | 3082 if (m_pLinearized) { |
3085 m_pLinearized->Release(); | 3083 m_pLinearized->Release(); |
3086 } | 3084 } |
3087 if (m_pRoot) { | 3085 if (m_pRoot) { |
3088 m_pRoot->Release(); | 3086 m_pRoot->Release(); |
3089 } | 3087 } |
3090 if (m_pTrailer) { | 3088 if (m_pTrailer) { |
3091 m_pTrailer->Release(); | 3089 m_pTrailer->Release(); |
3092 } | 3090 } |
3093 delete m_pageMapCheckState; | |
3094 delete m_pagesLoadState; | |
3095 int32_t i = 0; | 3091 int32_t i = 0; |
3096 int32_t iSize = m_arrayAcroforms.GetSize(); | 3092 int32_t iSize = m_arrayAcroforms.GetSize(); |
3097 for (i = 0; i < iSize; ++i) { | 3093 for (i = 0; i < iSize; ++i) { |
3098 ((CPDF_Object*)m_arrayAcroforms.GetAt(i))->Release(); | 3094 ((CPDF_Object*)m_arrayAcroforms.GetAt(i))->Release(); |
3099 } | 3095 } |
3100 } | 3096 } |
3101 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { | 3097 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { |
3102 m_pDocument = pDoc; | 3098 m_pDocument = pDoc; |
3103 } | 3099 } |
3104 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { | 3100 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) { |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3519 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 3515 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
3520 m_docStatus = PDF_DATAAVAIL_ERROR; | 3516 m_docStatus = PDF_DATAAVAIL_ERROR; |
3521 return FALSE; | 3517 return FALSE; |
3522 } | 3518 } |
3523 m_PagesObjNum = pRef->GetRefObjNum(); | 3519 m_PagesObjNum = pRef->GetRefObjNum(); |
3524 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser(); | 3520 m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser(); |
3525 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3521 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3526 return TRUE; | 3522 return TRUE; |
3527 } | 3523 } |
3528 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) { | 3524 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) { |
3529 if (NULL == m_pageMapCheckState) { | 3525 if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end()) |
3530 m_pageMapCheckState = new CFX_CMapDWordToDWord(); | |
3531 } | |
3532 FX_DWORD dwValue = 0; | |
3533 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { | |
3534 m_pageMapCheckState->SetAt(iPage, 1); | |
3535 return TRUE; | |
3536 } | |
3537 if (dwValue != 0) { | |
3538 return FALSE; | 3526 return FALSE; |
3539 } | 3527 |
3540 m_pageMapCheckState->SetAt(iPage, 1); | 3528 m_pageMapCheckState.insert(iPage); |
3541 return TRUE; | 3529 return TRUE; |
3542 } | 3530 } |
3543 void CPDF_DataAvail::ResetFirstCheck(int iPage) { | 3531 void CPDF_DataAvail::ResetFirstCheck(int iPage) { |
3544 if (NULL == m_pageMapCheckState) { | 3532 m_pageMapCheckState.erase(iPage); |
3545 m_pageMapCheckState = new CFX_CMapDWordToDWord(); | |
3546 } | |
3547 FX_DWORD dwValue = 1; | |
3548 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { | |
3549 return; | |
3550 } | |
3551 m_pageMapCheckState->SetAt(iPage, 0); | |
3552 } | 3533 } |
3553 FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) { | 3534 FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) { |
3554 FX_DWORD iPageObjs = m_PageObjList.GetSize(); | 3535 FX_DWORD iPageObjs = m_PageObjList.GetSize(); |
3555 CFX_DWordArray UnavailObjList; | 3536 CFX_DWordArray UnavailObjList; |
3556 for (FX_DWORD i = 0; i < iPageObjs; ++i) { | 3537 for (FX_DWORD i = 0; i < iPageObjs; ++i) { |
3557 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); | 3538 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); |
3558 FX_BOOL bExist = FALSE; | 3539 FX_BOOL bExist = FALSE; |
3559 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); | 3540 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); |
3560 if (!pObj) { | 3541 if (!pObj) { |
3561 if (bExist) { | 3542 if (bExist) { |
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4515 return FALSE; | 4496 return FALSE; |
4516 } | 4497 } |
4517 if (IsFirstCheck(iPage)) { | 4498 if (IsFirstCheck(iPage)) { |
4518 m_bCurPageDictLoadOK = FALSE; | 4499 m_bCurPageDictLoadOK = FALSE; |
4519 m_bPageLoadedOK = FALSE; | 4500 m_bPageLoadedOK = FALSE; |
4520 m_bAnnotsLoad = FALSE; | 4501 m_bAnnotsLoad = FALSE; |
4521 m_bNeedDownLoadResource = FALSE; | 4502 m_bNeedDownLoadResource = FALSE; |
4522 m_objs_array.RemoveAll(); | 4503 m_objs_array.RemoveAll(); |
4523 m_objnum_array.RemoveAll(); | 4504 m_objnum_array.RemoveAll(); |
4524 } | 4505 } |
4525 if (m_pagesLoadState == NULL) { | 4506 if (m_pagesLoadState.find(iPage) != m_pagesLoadState.end()) { |
4526 m_pagesLoadState = new CFX_CMapDWordToDWord(); | |
4527 } | |
4528 FX_DWORD dwPageLoad = 0; | |
4529 if (m_pagesLoadState->Lookup(iPage, dwPageLoad) && dwPageLoad != 0) { | |
4530 return TRUE; | 4507 return TRUE; |
4531 } | 4508 } |
4532 if (m_bLinearized) { | 4509 if (m_bLinearized) { |
4533 if ((FX_DWORD)iPage == m_dwFirstPageNo) { | 4510 if ((FX_DWORD)iPage == m_dwFirstPageNo) { |
4534 m_pagesLoadState->SetAt(iPage, TRUE); | 4511 m_pagesLoadState.insert(iPage); |
4535 return TRUE; | 4512 return TRUE; |
4536 } | 4513 } |
4537 if (!CheckLinearizedData(pHints)) { | 4514 if (!CheckLinearizedData(pHints)) { |
4538 return FALSE; | 4515 return FALSE; |
4539 } | 4516 } |
4540 if (m_bMainXRefLoadedOK) { | 4517 if (m_bMainXRefLoadedOK) { |
4541 if (m_bTotalLoadPageTree) { | 4518 if (m_bTotalLoadPageTree) { |
4542 if (!LoadPages(pHints)) { | 4519 if (!LoadPages(pHints)) { |
4543 return FALSE; | 4520 return FALSE; |
4544 } | 4521 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4619 FX_BOOL bRet = CheckResources(pHints); | 4596 FX_BOOL bRet = CheckResources(pHints); |
4620 if (!bRet) { | 4597 if (!bRet) { |
4621 return FALSE; | 4598 return FALSE; |
4622 } | 4599 } |
4623 m_bNeedDownLoadResource = FALSE; | 4600 m_bNeedDownLoadResource = FALSE; |
4624 } | 4601 } |
4625 m_bPageLoadedOK = FALSE; | 4602 m_bPageLoadedOK = FALSE; |
4626 m_bAnnotsLoad = FALSE; | 4603 m_bAnnotsLoad = FALSE; |
4627 m_bCurPageDictLoadOK = FALSE; | 4604 m_bCurPageDictLoadOK = FALSE; |
4628 ResetFirstCheck(iPage); | 4605 ResetFirstCheck(iPage); |
4629 m_pagesLoadState->SetAt(iPage, TRUE); | 4606 m_pagesLoadState.insert(iPage); |
4630 return TRUE; | 4607 return TRUE; |
4631 } | 4608 } |
4632 FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) { | 4609 FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) { |
4633 if (!m_objs_array.GetSize()) { | 4610 if (!m_objs_array.GetSize()) { |
4634 m_objs_array.RemoveAll(); | 4611 m_objs_array.RemoveAll(); |
4635 CFX_PtrArray obj_array; | 4612 CFX_PtrArray obj_array; |
4636 obj_array.Add(m_pPageResource); | 4613 obj_array.Add(m_pPageResource); |
4637 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); | 4614 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); |
4638 if (bRet) { | 4615 if (bRet) { |
4639 m_objs_array.RemoveAll(); | 4616 m_objs_array.RemoveAll(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4717 return FALSE; | 4694 return FALSE; |
4718 } | 4695 } |
4719 CPDF_PageNode::~CPDF_PageNode() { | 4696 CPDF_PageNode::~CPDF_PageNode() { |
4720 int32_t iSize = m_childNode.GetSize(); | 4697 int32_t iSize = m_childNode.GetSize(); |
4721 for (int32_t i = 0; i < iSize; ++i) { | 4698 for (int32_t i = 0; i < iSize; ++i) { |
4722 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4699 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; |
4723 delete pNode; | 4700 delete pNode; |
4724 } | 4701 } |
4725 m_childNode.RemoveAll(); | 4702 m_childNode.RemoveAll(); |
4726 } | 4703 } |
OLD | NEW |