diff options
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 61 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.cpp | 44 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document_unittest.cpp | 4 |
5 files changed, 51 insertions, 64 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index d94ef2c69c..4205ed2456 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -453,24 +453,21 @@ void CPDF_DataAvail::ResetFirstCheck(uint32_t dwPage) { } bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) { - uint32_t iPageObjs = m_PageObjList.GetSize(); - CFX_ArrayTemplate<uint32_t> UnavailObjList; - for (uint32_t i = 0; i < iPageObjs; ++i) { - uint32_t dwPageObjNum = m_PageObjList.GetAt(i); - bool bExist = false; + std::vector<uint32_t> UnavailObjList; + for (uint32_t dwPageObjNum : m_PageObjList) { + bool bExists = false; std::unique_ptr<CPDF_Object> pObj = - GetObject(dwPageObjNum, pHints, &bExist); + GetObject(dwPageObjNum, pHints, &bExists); if (!pObj) { - if (bExist) - UnavailObjList.Add(dwPageObjNum); + if (bExists) + UnavailObjList.push_back(dwPageObjNum); continue; } - CPDF_Array* pArray = ToArray(pObj.get()); if (pArray) { for (const auto& pArrayObj : *pArray) { if (CPDF_Reference* pRef = ToReference(pArrayObj.get())) - UnavailObjList.Add(pRef->GetRefObjNum()); + UnavailObjList.push_back(pRef->GetRefObjNum()); } } if (!pObj->IsDictionary()) @@ -482,15 +479,13 @@ bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) { continue; } } - - m_PageObjList.RemoveAll(); - if (UnavailObjList.GetSize()) { - m_PageObjList.Append(UnavailObjList); + m_PageObjList.clear(); + if (!UnavailObjList.empty()) { + m_PageObjList = std::move(UnavailObjList); return false; } - - uint32_t iPages = m_PagesArray.size(); - for (uint32_t i = 0; i < iPages; i++) { + size_t iPages = m_PagesArray.size(); + for (size_t i = 0; i < iPages; ++i) { std::unique_ptr<CPDF_Object> pPages = std::move(m_PagesArray[i]); if (pPages && !GetPageKids(m_pCurrentParser, pPages.get())) { m_PagesArray.clear(); @@ -499,7 +494,7 @@ bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) { } } m_PagesArray.clear(); - if (!m_PageObjList.GetSize()) + if (m_PageObjList.empty()) m_docStatus = PDF_DATAAVAIL_DONE; return true; @@ -518,13 +513,13 @@ bool CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { switch (pKids->GetType()) { case CPDF_Object::REFERENCE: - m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); + m_PageObjList.push_back(pKids->AsReference()->GetRefObjNum()); break; case CPDF_Object::ARRAY: { CPDF_Array* pKidsArray = pKids->AsArray(); for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i))) - m_PageObjList.Add(pRef->GetRefObjNum()); + m_PageObjList.push_back(pRef->GetRefObjNum()); } } break; default: @@ -535,10 +530,10 @@ bool CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { } bool CPDF_DataAvail::CheckPages(DownloadHints* pHints) { - bool bExist = false; + bool bExists = false; std::unique_ptr<CPDF_Object> pPages = - GetObject(m_PagesObjNum, pHints, &bExist); - if (!bExist) { + GetObject(m_PagesObjNum, pHints, &bExists); + if (!bExists) { m_docStatus = PDF_DATAAVAIL_LOADALLFILE; return true; } @@ -1121,9 +1116,9 @@ bool CPDF_DataAvail::CheckPage(uint32_t dwPage, DownloadHints* pHints) { bool CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo, PageNode* pPageNode, DownloadHints* pHints) { - bool bExist = false; - std::unique_ptr<CPDF_Object> pPages = GetObject(dwPageNo, pHints, &bExist); - if (!bExist) { + bool bExists = false; + std::unique_ptr<CPDF_Object> pPages = GetObject(dwPageNo, pHints, &bExists); + if (!bExists) { m_docStatus = PDF_DATAAVAIL_ERROR; return false; } @@ -1158,9 +1153,9 @@ bool CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo, bool CPDF_DataAvail::CheckUnknownPageNode(uint32_t dwPageNo, PageNode* pPageNode, DownloadHints* pHints) { - bool bExist = false; - std::unique_ptr<CPDF_Object> pPage = GetObject(dwPageNo, pHints, &bExist); - if (!bExist) { + bool bExists = false; + std::unique_ptr<CPDF_Object> pPage = GetObject(dwPageNo, pHints, &bExists); + if (!bExists) { m_docStatus = PDF_DATAAVAIL_ERROR; return false; } @@ -1292,14 +1287,13 @@ bool CPDF_DataAvail::LoadDocPage(uint32_t dwPage, DownloadHints* pHints) { } bool CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) { - bool bExist = false; + bool bExists = false; std::unique_ptr<CPDF_Object> pPages = - GetObject(m_PagesObjNum, pHints, &bExist); - if (!bExist) { + GetObject(m_PagesObjNum, pHints, &bExists); + if (!bExists) { m_docStatus = PDF_DATAAVAIL_ERROR; return false; } - if (!pPages) return false; @@ -1308,7 +1302,6 @@ bool CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) { m_docStatus = PDF_DATAAVAIL_ERROR; return false; } - if (!pPagesDict->KeyExist("Kids")) return true; diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index 42013e93ec..65638cff0b 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -221,8 +221,8 @@ class CPDF_DataAvail final { uint32_t m_bufferSize; CFX_ByteString m_WordBuf; uint8_t m_bufferData[512]; - CFX_ArrayTemplate<uint32_t> m_XRefStreamList; - CFX_ArrayTemplate<uint32_t> m_PageObjList; + std::vector<uint32_t> m_XRefStreamList; + std::vector<uint32_t> m_PageObjList; uint32_t m_PagesObjNum; bool m_bLinearedDataOK; bool m_bMainXRefLoadTried; diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 4ac0aa6aa9..9e60aaa882 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -381,20 +381,20 @@ void CPDF_Document::LoadDocInternal() { void CPDF_Document::LoadDoc() { LoadDocInternal(); - m_PageList.SetSize(RetrievePageCount()); + LoadPages(); } void CPDF_Document::LoadLinearizedDoc( const CPDF_LinearizedHeader* pLinearizationParams) { m_bLinearized = true; LoadDocInternal(); - m_PageList.SetSize(pLinearizationParams->GetPageCount()); + m_PageList.resize(pLinearizationParams->GetPageCount()); m_iFirstPageNo = pLinearizationParams->GetFirstPageNo(); m_dwFirstPageObjNum = pLinearizationParams->GetFirstPageObjNum(); } void CPDF_Document::LoadPages() { - m_PageList.SetSize(RetrievePageCount()); + m_PageList.resize(RetrievePageCount()); } CPDF_Dictionary* CPDF_Document::TraversePDFPages(int iPage, @@ -402,21 +402,20 @@ CPDF_Dictionary* CPDF_Document::TraversePDFPages(int iPage, size_t level) { if (*nPagesToGo < 0 || m_bReachedMaxPageLevel) return nullptr; + CPDF_Dictionary* pPages = m_pTreeTraversal[level].first; CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); if (!pKidList) { if (*nPagesToGo != 1) return nullptr; - m_PageList.SetAt(iPage, pPages->GetObjNum()); + m_PageList[iPage] = pPages->GetObjNum(); return pPages; } - if (level >= FX_MAX_PAGE_LEVEL) { m_pTreeTraversal.pop_back(); m_bReachedMaxPageLevel = true; return nullptr; } - CPDF_Dictionary* page = nullptr; for (size_t i = m_pTreeTraversal[level].second; i < pKidList->GetCount(); i++) { @@ -433,7 +432,7 @@ CPDF_Dictionary* CPDF_Document::TraversePDFPages(int iPage, continue; } if (!pKid->KeyExist("Kids")) { - m_PageList.SetAt(iPage - (*nPagesToGo) + 1, pKid->GetObjNum()); + m_PageList[iPage - (*nPagesToGo) + 1] = pKid->GetObjNum(); (*nPagesToGo)--; m_pTreeTraversal[level].second++; if (*nPagesToGo == 0) { @@ -474,11 +473,11 @@ CPDF_Dictionary* CPDF_Document::GetPagesDict() const { } bool CPDF_Document::IsPageLoaded(int iPage) const { - return !!m_PageList.GetAt(iPage); + return !!m_PageList[iPage]; } CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { - if (iPage < 0 || iPage >= m_PageList.GetSize()) + if (iPage < 0 || iPage >= pdfium::CollectionSize<int>(m_PageList)) return nullptr; if (m_bLinearized && (iPage == m_iFirstPageNo)) { @@ -487,13 +486,9 @@ CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { return pDict; } } - - int objnum = m_PageList.GetAt(iPage); - if (objnum) { - if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(objnum))) - return pDict; - return nullptr; - } + uint32_t objnum = m_PageList[iPage]; + if (objnum) + return ToDictionary(GetOrParseIndirectObject(objnum)); CPDF_Dictionary* pPages = GetPagesDict(); if (!pPages) @@ -517,7 +512,7 @@ CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { } void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) { - m_PageList.SetAt(iPage, objNum); + m_PageList[iPage] = objNum; } int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, @@ -554,7 +549,7 @@ int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, for (size_t i = 0; i < count; i++) { if (CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i))) { if (pKid->GetRefObjNum() == objnum) { - m_PageList.SetAt(index + i, objnum); + m_PageList[index + i] = objnum; return static_cast<int>(index + i); } } @@ -574,15 +569,14 @@ int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, } int CPDF_Document::GetPageIndex(uint32_t objnum) { - uint32_t nPages = m_PageList.GetSize(); + uint32_t nPages = m_PageList.size(); uint32_t skip_count = 0; bool bSkipped = false; for (uint32_t i = 0; i < nPages; i++) { - uint32_t objnum1 = m_PageList.GetAt(i); - if (objnum1 == objnum) + if (m_PageList[i] == objnum) return i; - if (!bSkipped && objnum1 == 0) { + if (!bSkipped && m_PageList[i] == 0) { skip_count = i; bSkipped = true; } @@ -596,7 +590,7 @@ int CPDF_Document::GetPageIndex(uint32_t objnum) { } int CPDF_Document::GetPageCount() const { - return m_PageList.GetSize(); + return pdfium::CollectionSize<int>(m_PageList); } int CPDF_Document::RetrievePageCount() const { @@ -747,7 +741,7 @@ bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) { if (!InsertDeletePDFPage(pPages, iPage, pPageDict, true, &stack)) return false; } - m_PageList.InsertAt(iPage, pPageDict->GetObjNum()); + m_PageList.insert(m_PageList.begin() + iPage, pPageDict->GetObjNum()); return true; } @@ -764,7 +758,7 @@ void CPDF_Document::DeletePage(int iPage) { if (!InsertDeletePDFPage(pPages, iPage, nullptr, false, &stack)) return; - m_PageList.RemoveAt(iPage); + m_PageList.erase(m_PageList.begin() + iPage); } CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font, diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h index 0da6577360..65455480a4 100644 --- a/core/fpdfapi/parser/cpdf_document.h +++ b/core/fpdfapi/parser/cpdf_document.h @@ -147,7 +147,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { std::unique_ptr<CPDF_DocRenderData> m_pDocRender; std::unique_ptr<JBig2_DocumentContext> m_pCodecContext; std::unique_ptr<CPDF_LinkList> m_pLinksContext; - CFX_ArrayTemplate<uint32_t> m_PageList; + std::vector<uint32_t> m_PageList; }; #endif // CORE_FPDFAPI_PARSER_CPDF_DOCUMENT_H_ diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp index 91beba3a6b..4815ffba52 100644 --- a/core/fpdfapi/parser/cpdf_document_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp @@ -88,7 +88,7 @@ class CPDF_TestDocumentForPages : public CPDF_Document { m_pOwnedRootDict->SetNewFor<CPDF_Reference>("Pages", this, pagesDict->GetObjNum()); m_pRootDict = m_pOwnedRootDict.get(); - m_PageList.SetSize(7); + m_PageList.resize(7); } private: @@ -112,7 +112,7 @@ class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document { m_pOwnedRootDict->SetNewFor<CPDF_Reference>("Pages", this, pagesDict->GetObjNum()); m_pRootDict = m_pOwnedRootDict.get(); - m_PageList.SetSize(3); + m_PageList.resize(3); } private: |