From 6b26e1ae69321717c5ce098a1cd2c9f3e1099344 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Mon, 16 Apr 2018 21:48:37 +0000 Subject: Remove non-const CPDF_PageObjectHolder::GetPageObjectList(). This makes it easier to control modifications to the page object list. Bug: pdfium:1051 Change-Id: Ia85c597fa6d39e89041b990b4b6c91e327ef811d Reviewed-on: https://pdfium-review.googlesource.com/30803 Commit-Queue: Henrique Nakashima Reviewed-by: Lei Zhang --- fpdfsdk/fpdf_annot.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'fpdfsdk/fpdf_annot.cpp') 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& 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& 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 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(index) >= pObjList->size()) + if (!pAnnot->GetForm()->ErasePageObjectAtIndex(index)) return false; - pObjList->erase(pObjList->begin() + index); UpdateContentStream(pAnnot->GetForm(), pStream); return true; } -- cgit v1.2.3