From 2398d8938277a2492b411f8f807bf1935918ccae Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 17 Feb 2016 16:46:26 -0800 Subject: Remove CFX_PtrList from renderer main loop. Exposes an iterator over the object list, but not the object holder, since pages and forms inherit from object holder, and we don't want to imply that there's only one thing that might be iterated over for those classes. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1700183002 . --- fpdfsdk/src/fpdf_flatten.cpp | 20 ++++++------------- fpdfsdk/src/fpdfeditpage.cpp | 14 ++++++------- fpdfsdk/src/fxedit/fxet_pageobjs.cpp | 38 +++++++++++++++++------------------- fpdfsdk/src/javascript/Document.cpp | 33 +++++++++++-------------------- fpdfsdk/src/pdfwindow/PWL_Edit.cpp | 8 ++++---- 5 files changed, 46 insertions(+), 67 deletions(-) (limited to 'fpdfsdk/src') diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp index 36b8319dca..9aee35f760 100644 --- a/fpdfsdk/src/fpdf_flatten.cpp +++ b/fpdfsdk/src/fpdf_flatten.cpp @@ -35,17 +35,14 @@ FX_BOOL IsValiableRect(CPDF_Rect rect, CPDF_Rect rcPage) { return TRUE; } -FX_BOOL GetContentsRect(CPDF_Document* pDoc, - CPDF_Dictionary* pDict, - CPDF_RectArray* pRectArray) { - CPDF_Page* pPDFPage = new CPDF_Page; +void GetContentsRect(CPDF_Document* pDoc, + CPDF_Dictionary* pDict, + CPDF_RectArray* pRectArray) { + std::unique_ptr pPDFPage(new CPDF_Page); pPDFPage->Load(pDoc, pDict, FALSE); pPDFPage->ParseContent(nullptr); - FX_POSITION pos = pPDFPage->GetPageObjectList()->GetHeadPosition(); - while (pos) { - CPDF_PageObject* pPageObject = - pPDFPage->GetPageObjectList()->GetNextObject(pos); + for (auto& pPageObject : *pPDFPage->GetPageObjectList()) { if (!pPageObject) continue; @@ -54,14 +51,9 @@ FX_BOOL GetContentsRect(CPDF_Document* pDoc, rc.right = pPageObject->m_Right; rc.bottom = pPageObject->m_Bottom; rc.top = pPageObject->m_Top; - - if (IsValiableRect(rc, pDict->GetRectBy("MediaBox"))) { + if (IsValiableRect(rc, pDict->GetRectBy("MediaBox"))) pRectArray->Add(rc); - } } - - delete pPDFPage; - return TRUE; } void ParserStream(CPDF_Dictionary* pPageDic, diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp index 6d39cb100f..6c14079131 100644 --- a/fpdfsdk/src/fpdfeditpage.cpp +++ b/fpdfsdk/src/fpdfeditpage.cpp @@ -8,6 +8,7 @@ #include "fpdfsdk/include/fsdk_define.h" #include "public/fpdf_formfill.h" +#include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" @@ -135,9 +136,10 @@ DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_obj; if (!pPageObj) return; - FX_POSITION LastPersition = pPage->GetPageObjectList()->GetTailPosition(); - pPage->GetPageObjectList()->InsertObject(LastPersition, pPageObj); + pPage->GetPageObjectList()->push_back( + std::unique_ptr(pPageObj)); + switch (pPageObj->m_Type) { case FPDF_PAGEOBJ_PATH: { CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj; @@ -145,8 +147,6 @@ DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, break; } case FPDF_PAGEOBJ_TEXT: { - // CPDF_PathObject* pPathObj = (CPDF_PathObject*)pPageObj; - // pPathObj->CalcBoundingBox(); break; } case FPDF_PAGEOBJ_IMAGE: { @@ -177,7 +177,7 @@ DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { "Page")) { return -1; } - return pPage->GetPageObjectList()->GetCount(); + return pdfium::CollectionSize(*pPage->GetPageObjectList()); } DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, @@ -186,9 +186,9 @@ DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare( "Page")) { - return NULL; + return nullptr; } - return pPage->GetPageObjectList()->GetObjectByIndex(index); + return pPage->GetPageObjectList()->GetPageObjectByIndex(index); } DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page) { diff --git a/fpdfsdk/src/fxedit/fxet_pageobjs.cpp b/fpdfsdk/src/fxedit/fxet_pageobjs.cpp index d54e4649db..c3bd79759b 100644 --- a/fpdfsdk/src/fxedit/fxet_pageobjs.cpp +++ b/fpdfsdk/src/fxedit/fxet_pageobjs.cpp @@ -409,10 +409,10 @@ void IFX_Edit::DrawRichEdit(CFX_RenderDevice* pDevice, pDevice->RestoreState(); } -static void AddRectToPageObjects(CPDF_PageObjectHolder* pPageObjs, +static void AddRectToPageObjects(CPDF_PageObjectHolder* pObjectHolder, FX_COLORREF crFill, const CPDF_Rect& rcFill) { - CPDF_PathObject* pPathObj = new CPDF_PathObject; + std::unique_ptr pPathObj(new CPDF_PathObject); CPDF_PathData* pPathData = pPathObj->m_Path.GetModify(); pPathData->AppendRect(rcFill.left, rcFill.bottom, rcFill.right, rcFill.top); @@ -425,12 +425,11 @@ static void AddRectToPageObjects(CPDF_PageObjectHolder* pPageObjs, pPathObj->m_FillType = FXFILL_ALTERNATE; pPathObj->m_bStroke = FALSE; - pPageObjs->GetPageObjectList()->InsertObject( - pPageObjs->GetPageObjectList()->GetTailPosition(), pPathObj); + pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); } static CPDF_TextObject* AddTextObjToPageObjects( - CPDF_PageObjectHolder* pPageObjs, + CPDF_PageObjectHolder* pObjectHolder, FX_COLORREF crText, CPDF_Font* pFont, FX_FLOAT fFontSize, @@ -438,8 +437,7 @@ static CPDF_TextObject* AddTextObjToPageObjects( int32_t nHorzScale, const CPDF_Point& point, const CFX_ByteString& text) { - CPDF_TextObject* pTxtObj = new CPDF_TextObject; - + std::unique_ptr pTxtObj(new CPDF_TextObject); CPDF_TextStateData* pTextStateData = pTxtObj->m_TextState.GetModify(); pTextStateData->m_pFont = pFont; pTextStateData->m_FontSize = fFontSize; @@ -462,14 +460,14 @@ static CPDF_TextObject* AddTextObjToPageObjects( pTxtObj->SetPosition(point.x, point.y); pTxtObj->SetText(text); - pPageObjs->GetPageObjectList()->InsertObject( - pPageObjs->GetPageObjectList()->GetTailPosition(), pTxtObj); - return pTxtObj; + CPDF_TextObject* pRet = pTxtObj.get(); + pObjectHolder->GetPageObjectList()->push_back(std::move(pTxtObj)); + return pRet; } void IFX_Edit::GeneratePageObjects( - CPDF_PageObjectHolder* pPageObjects, + CPDF_PageObjectHolder* pObjectHolder, IFX_Edit* pEdit, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, @@ -504,7 +502,7 @@ void IFX_Edit::GeneratePageObjects( nOldFontIndex != word.nFontIndex) { if (sTextBuf.GetLength() > 0) { ObjArray.Add(AddTextObjToPageObjects( - pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), + pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, 0.0f, 100, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), sTextBuf.GetByteString())); @@ -523,7 +521,7 @@ void IFX_Edit::GeneratePageObjects( if (sTextBuf.GetLength() > 0) { ObjArray.Add(AddTextObjToPageObjects( - pPageObjects, crText, pFontMap->GetPDFFont(nOldFontIndex), + pObjectHolder, crText, pFontMap->GetPDFFont(nOldFontIndex), fFontSize, 0.0f, 100, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), sTextBuf.GetByteString())); @@ -533,7 +531,7 @@ void IFX_Edit::GeneratePageObjects( } void IFX_Edit::GenerateRichPageObjects( - CPDF_PageObjectHolder* pPageObjects, + CPDF_PageObjectHolder* pObjectHolder, IFX_Edit* pEdit, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, @@ -574,7 +572,7 @@ void IFX_Edit::GenerateRichPageObjects( crOld != crCurText) { if (sTextBuf.GetLength() > 0) { ObjArray.Add(AddTextObjToPageObjects( - pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), + pObjectHolder, crOld, pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, wp.fCharSpace, wp.nHorzScale, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), sTextBuf.GetByteString())); @@ -597,7 +595,7 @@ void IFX_Edit::GenerateRichPageObjects( rcUnderline.top += ptOffset.y; rcUnderline.bottom += ptOffset.y; - AddRectToPageObjects(pPageObjects, crCurText, rcUnderline); + AddRectToPageObjects(pObjectHolder, crCurText, rcUnderline); } if (word.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) { @@ -607,7 +605,7 @@ void IFX_Edit::GenerateRichPageObjects( rcCrossout.top += ptOffset.y; rcCrossout.bottom += ptOffset.y; - AddRectToPageObjects(pPageObjects, crCurText, rcCrossout); + AddRectToPageObjects(pObjectHolder, crCurText, rcCrossout); } oldplace = place; @@ -616,7 +614,7 @@ void IFX_Edit::GenerateRichPageObjects( if (sTextBuf.GetLength() > 0) { ObjArray.Add(AddTextObjToPageObjects( - pPageObjects, crOld, pFontMap->GetPDFFont(wp.nFontIndex), + pObjectHolder, crOld, pFontMap->GetPDFFont(wp.nFontIndex), wp.fFontSize, wp.fCharSpace, wp.nHorzScale, CPDF_Point(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), sTextBuf.GetByteString())); @@ -625,7 +623,7 @@ void IFX_Edit::GenerateRichPageObjects( } } -void IFX_Edit::GenerateUnderlineObjects(CPDF_PageObjectHolder* pPageObjects, +void IFX_Edit::GenerateUnderlineObjects(CPDF_PageObjectHolder* pObjectHolder, IFX_Edit* pEdit, const CPDF_Point& ptOffset, const CPVT_WordRange* pRange, @@ -651,7 +649,7 @@ void IFX_Edit::GenerateUnderlineObjects(CPDF_PageObjectHolder* pPageObjects, rcUnderline.right += ptOffset.x; rcUnderline.top += ptOffset.y; rcUnderline.bottom += ptOffset.y; - AddRectToPageObjects(pPageObjects, color, rcUnderline); + AddRectToPageObjects(pObjectHolder, color, rcUnderline); } } } diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index c2638d012d..733384a154 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -1382,20 +1382,15 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc, int nWords = 0; CFX_WideString swRet; - FX_POSITION pos = page.GetPageObjectList()->GetHeadPosition(); - while (pos) { - if (CPDF_PageObject* pPageObj = - page.GetPageObjectList()->GetNextObject(pos)) { - if (pPageObj->m_Type == CPDF_PageObject::TEXT) { - int nObjWords = CountWords((CPDF_TextObject*)pPageObj); - - if (nWords + nObjWords >= nWordNo) { - swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords); - break; - } - - nWords += nObjWords; + for (auto& pPageObj : *page.GetPageObjectList()) { + if (pPageObj->m_Type == CPDF_PageObject::TEXT) { + CPDF_TextObject* pTextObj = static_cast(pPageObj.get()); + int nObjWords = CountWords(pTextObj); + if (nWords + nObjWords >= nWordNo) { + swRet = GetObjWordStr(pTextObj, nWordNo - nWords); + break; } + nWords += nObjWords; } } @@ -1442,15 +1437,9 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc, page.ParseContent(nullptr); int nWords = 0; - FX_POSITION pos = page.GetPageObjectList()->GetHeadPosition(); - while (pos) { - if (CPDF_PageObject* pPageObj = - page.GetPageObjectList()->GetNextObject(pos)) { - if (pPageObj->m_Type == CPDF_PageObject::TEXT) { - CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj; - nWords += CountWords(pTextObj); - } - } + for (auto& pPageObj : *page.GetPageObjectList()) { + if (pPageObj->m_Type == CPDF_PageObject::TEXT) + nWords += CountWords(static_cast(pPageObj.get())); } vRet = nWords; diff --git a/fpdfsdk/src/pdfwindow/PWL_Edit.cpp b/fpdfsdk/src/pdfwindow/PWL_Edit.cpp index 4b3886a11d..ce9274aeb9 100644 --- a/fpdfsdk/src/pdfwindow/PWL_Edit.cpp +++ b/fpdfsdk/src/pdfwindow/PWL_Edit.cpp @@ -1166,20 +1166,20 @@ CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place, } void CPWL_Edit::GeneratePageObjects( - CPDF_PageObjectHolder* pPageObjects, + CPDF_PageObjectHolder* pObjectHolder, const CPDF_Point& ptOffset, CFX_ArrayTemplate& ObjArray) { IFX_Edit::GeneratePageObjects( - pPageObjects, m_pEdit, ptOffset, NULL, + pObjectHolder, m_pEdit, ptOffset, NULL, CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), ObjArray); } -void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pPageObjects, +void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder, const CPDF_Point& ptOffset) { CFX_ArrayTemplate ObjArray; IFX_Edit::GeneratePageObjects( - pPageObjects, m_pEdit, ptOffset, NULL, + pObjectHolder, m_pEdit, ptOffset, NULL, CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), ObjArray); } -- cgit v1.2.3