diff options
-rw-r--r-- | core/fpdfapi/page/cpdf_pageobjectholder.cpp | 8 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pageobjectholder.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 10 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_progressiverenderer.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_progressiverenderer.h | 2 | ||||
-rw-r--r-- | fpdfsdk/fpdf_annot.cpp | 13 |
6 files changed, 22 insertions, 17 deletions
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp index 67b356fc57..310858f7c8 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp +++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp @@ -119,3 +119,11 @@ bool CPDF_PageObjectHolder::RemovePageObject(CPDF_PageObject* pPageObj) { m_PageObjectList.erase(it); return true; } + +bool CPDF_PageObjectHolder::ErasePageObjectAtIndex(size_t index) { + if (index >= m_PageObjectList.size()) + return false; + + m_PageObjectList.erase(m_PageObjectList.begin() + index); + return true; +} diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.h b/core/fpdfapi/page/cpdf_pageobjectholder.h index bf6c476186..a65ccc8129 100644 --- a/core/fpdfapi/page/cpdf_pageobjectholder.h +++ b/core/fpdfapi/page/cpdf_pageobjectholder.h @@ -52,7 +52,6 @@ class CPDF_PageObjectHolder { void ContinueParse(PauseIndicatorIface* pPause); bool IsParsed() const { return m_ParseState == CONTENT_PARSED; } - CPDF_PageObjectList* GetPageObjectList() { return &m_PageObjectList; } const CPDF_PageObjectList* GetPageObjectList() const { return &m_PageObjectList; } @@ -61,6 +60,7 @@ class CPDF_PageObjectHolder { CPDF_PageObject* GetPageObjectByIndex(size_t index) const; void AppendPageObject(std::unique_ptr<CPDF_PageObject> pPageObj); bool RemovePageObject(CPDF_PageObject* pPageObj); + bool ErasePageObjectAtIndex(size_t index); const CFX_Matrix& GetLastCTM() const { return m_LastCTM; } diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 3b8dac9244..736e91b3c8 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -793,7 +793,7 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { } pFormObj->CalcBoundingBox(); SetGraphicStates(pFormObj.get(), true, true, true); - m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj)); + m_pObjectHolder->AppendPageObject(std::move(pFormObj)); } CPDF_ImageObject* CPDF_StreamContentParser::AddImage( @@ -836,7 +836,7 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImageObject( pImageObj->CalcBoundingBox(); CPDF_ImageObject* pRet = pImageObj.get(); - m_pObjectHolder->GetPageObjectList()->push_back(std::move(pImageObj)); + m_pObjectHolder->AppendPageObject(std::move(pImageObj)); return pRet; } @@ -1095,7 +1095,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill() { pObj->m_Right = bbox.right; pObj->m_Top = bbox.top; pObj->m_Bottom = bbox.bottom; - m_pObjectHolder->GetPageObjectList()->push_back(std::move(pObj)); + m_pObjectHolder->AppendPageObject(std::move(pObj)); } void CPDF_StreamContentParser::Handle_SetCharSpace() { @@ -1242,7 +1242,7 @@ void CPDF_StreamContentParser::AddTextObject(ByteString* pStrs, m_ClipTextList.push_back( std::unique_ptr<CPDF_TextObject>(pText->Clone())); } - m_pObjectHolder->GetPageObjectList()->push_back(std::move(pText)); + m_pObjectHolder->AppendPageObject(std::move(pText)); } if (pKerning && pKerning[nsegs - 1] != 0) { if (!pFont->IsVertWriting()) { @@ -1463,7 +1463,7 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) { pPathObj->m_Matrix = matrix; SetGraphicStates(pPathObj.get(), true, false, true); pPathObj->CalcBoundingBox(); - m_pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); + m_pObjectHolder->AppendPageObject(std::move(pPathObj)); } if (PathClipType) { if (!matrix.IsIdentity()) { diff --git a/core/fpdfapi/render/cpdf_progressiverenderer.cpp b/core/fpdfapi/render/cpdf_progressiverenderer.cpp index 922e3fd60d..b2d16300d4 100644 --- a/core/fpdfapi/render/cpdf_progressiverenderer.cpp +++ b/core/fpdfapi/render/cpdf_progressiverenderer.cpp @@ -63,8 +63,8 @@ void CPDF_ProgressiveRenderer::Continue(PauseIndicatorIface* pPause) { m_ClipRect = m_pCurrentLayer->m_Matrix.GetInverse().TransformRect( CFX_FloatRect(m_pDevice->GetClipBox())); } - CPDF_PageObjectList::iterator iter; - CPDF_PageObjectList::iterator iterEnd = + CPDF_PageObjectList::const_iterator iter; + CPDF_PageObjectList::const_iterator iterEnd = m_pCurrentLayer->m_pObjectHolder->GetPageObjectList()->end(); if (m_LastObjectRendered != iterEnd) { iter = m_LastObjectRendered; diff --git a/core/fpdfapi/render/cpdf_progressiverenderer.h b/core/fpdfapi/render/cpdf_progressiverenderer.h index 5703b42918..400909bda5 100644 --- a/core/fpdfapi/render/cpdf_progressiverenderer.h +++ b/core/fpdfapi/render/cpdf_progressiverenderer.h @@ -54,7 +54,7 @@ class CPDF_ProgressiveRenderer { CFX_FloatRect m_ClipRect; uint32_t m_LayerIndex; CPDF_RenderContext::Layer* m_pCurrentLayer; - CPDF_PageObjectList::iterator m_LastObjectRendered; + CPDF_PageObjectList::const_iterator m_LastObjectRendered; }; #endif // CORE_FPDFAPI_RENDER_CPDF_PROGRESSIVERENDERER_H_ diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp index ccc7596401..6504ee7402 100644 --- a/fpdfsdk/fpdf_annot.cpp +++ b/fpdfsdk/fpdf_annot.cpp @@ -381,7 +381,7 @@ FPDFAnnot_UpdateObject(FPDF_ANNOTATION annot, FPDF_PAGEOBJECT obj) { // Check that the object is already in this annotation's object list. CPDF_Form* pForm = pAnnot->GetForm(); - CPDF_PageObjectList* pObjList = pForm->GetPageObjectList(); + const CPDF_PageObjectList* pObjList = pForm->GetPageObjectList(); auto it = std::find_if(pObjList->begin(), pObjList->end(), [pObj](const std::unique_ptr<CPDF_PageObject>& candidate) { @@ -432,7 +432,7 @@ FPDFAnnot_AppendObject(FPDF_ANNOTATION annot, FPDF_PAGEOBJECT obj) { // Note that an object that came from a different annotation must not be // passed here, since an object cannot belong to more than one annotation. CPDF_Form* pForm = pAnnot->GetForm(); - CPDF_PageObjectList* pObjList = pForm->GetPageObjectList(); + const CPDF_PageObjectList* pObjList = pForm->GetPageObjectList(); auto it = std::find_if(pObjList->begin(), pObjList->end(), [pObj](const std::unique_ptr<CPDF_PageObject>& candidate) { @@ -442,8 +442,7 @@ FPDFAnnot_AppendObject(FPDF_ANNOTATION annot, FPDF_PAGEOBJECT obj) { return false; // Append the object to the object list. - std::unique_ptr<CPDF_PageObject> pPageObjHolder(pObj); - pObjList->push_back(std::move(pPageObjHolder)); + pForm->AppendPageObject(pdfium::WrapUnique(pObj)); // Set the content stream data in the annotation's AP stream. UpdateContentStream(pForm, pStream); @@ -481,7 +480,7 @@ FPDFAnnot_GetObject(FPDF_ANNOTATION annot, int index) { pAnnot->SetForm(pStream); } - return pAnnot->GetForm()->GetPageObjectList()->GetPageObjectByIndex(index); + return pAnnot->GetForm()->GetPageObjectByIndex(index); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV @@ -501,11 +500,9 @@ FPDFAnnot_RemoveObject(FPDF_ANNOTATION annot, int index) { if (!pStream) return false; - CPDF_PageObjectList* pObjList = pAnnot->GetForm()->GetPageObjectList(); - if (static_cast<size_t>(index) >= pObjList->size()) + if (!pAnnot->GetForm()->ErasePageObjectAtIndex(index)) return false; - pObjList->erase(pObjList->begin() + index); UpdateContentStream(pAnnot->GetForm(), pStream); return true; } |