diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-02-17 16:46:26 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-02-17 16:46:26 -0800 |
commit | 2398d8938277a2492b411f8f807bf1935918ccae (patch) | |
tree | 0f8c13509e23d6a0ea80d461ab803fae62a4638f /core/src/fpdfapi/fpdf_page | |
parent | efbc1912f10f5a53e7df3a24ebfd6b78412f0bba (diff) | |
download | pdfium-2398d8938277a2492b411f8f807bf1935918ccae.tar.xz |
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 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_page')
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page.cpp | 93 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 87 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 20 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/pageint.h | 4 |
4 files changed, 100 insertions, 104 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp index 4194ff75eb..b1de6d6de2 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp @@ -6,8 +6,11 @@ #include "core/src/fpdfapi/fpdf_page/pageint.h" +#include <algorithm> + #include "core/include/fpdfapi/fpdf_module.h" #include "core/include/fpdfapi/fpdf_page.h" +#include "third_party/base/stl_util.h" CPDF_PageObject* CPDF_PageObject::Create(int type) { switch (type) { @@ -670,6 +673,19 @@ void CPDF_FormObject::CalcBoundingBox() { m_Right = form_rect.right; m_Top = form_rect.top; } + +CPDF_PageObject* CPDF_PageObjectList::GetPageObjectByIndex(int index) { + if (index < 0 || index >= pdfium::CollectionSize<int>(*this)) + return nullptr; + int current = 0; + for (const auto& pObj : *this) { + if (index == current) + return pObj.get(); + ++current; + } + return nullptr; +} + CPDF_PageObjectHolder::CPDF_PageObjectHolder() : m_pFormDict(nullptr), m_pFormStream(nullptr), @@ -679,15 +695,8 @@ CPDF_PageObjectHolder::CPDF_PageObjectHolder() m_Transparency(0), m_bBackgroundAlphaNeeded(FALSE), m_bHasImageMask(FALSE), - m_ParseState(CONTENT_NOT_PARSED), - m_PageObjectList(128) {} + m_ParseState(CONTENT_NOT_PARSED) {} -CPDF_PageObjectHolder::~CPDF_PageObjectHolder() { - FX_POSITION pos = m_PageObjectList.GetHeadPosition(); - while (pos) { - delete m_PageObjectList.GetNextObject(pos); - } -} void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { if (!m_pParser) { return; @@ -698,48 +707,29 @@ void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { m_pParser.reset(); } } -FX_POSITION CPDF_PageObjectList::InsertObject(FX_POSITION posInsertAfter, - CPDF_PageObject* pNewObject) { - if (!posInsertAfter) { - return AddHead(pNewObject); - } - return InsertAfter(posInsertAfter, pNewObject); -} -CPDF_PageObject* CPDF_PageObjectList::GetObjectByIndex(int index) const { - FX_POSITION pos = FindIndex(index); - return pos ? GetObjectAt(pos) : nullptr; -} + void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) { - FX_POSITION pos = m_PageObjectList.GetHeadPosition(); - while (pos) { - m_PageObjectList.GetNextObject(pos)->Transform(matrix); - } + for (auto& pObj : m_PageObjectList) + pObj->Transform(matrix); } + CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const { - if (m_PageObjectList.GetCount() == 0) { + if (m_PageObjectList.empty()) return CFX_FloatRect(0, 0, 0, 0); - } - FX_FLOAT left, right, top, bottom; - left = bottom = 1000000 * 1.0f; - right = top = -1000000 * 1.0f; - FX_POSITION pos = m_PageObjectList.GetHeadPosition(); - while (pos) { - CPDF_PageObject* pObj = (CPDF_PageObject*)m_PageObjectList.GetNext(pos); - if (left > pObj->m_Left) { - left = pObj->m_Left; - } - if (right < pObj->m_Right) { - right = pObj->m_Right; - } - if (top < pObj->m_Top) { - top = pObj->m_Top; - } - if (bottom > pObj->m_Bottom) { - bottom = pObj->m_Bottom; - } + + FX_FLOAT left = 1000000.0f; + FX_FLOAT right = -1000000.0f; + FX_FLOAT bottom = 1000000.0f; + FX_FLOAT top = -1000000.0f; + for (const auto& pObj : m_PageObjectList) { + left = std::min(left, pObj->m_Left); + right = std::max(right, pObj->m_Right); + bottom = std::min(bottom, pObj->m_Bottom); + top = std::max(top, pObj->m_Top); } return CFX_FloatRect(left, bottom, right, top); } + void CPDF_PageObjectHolder::LoadTransInfo() { if (!m_pFormDict) { return; @@ -889,7 +879,9 @@ CPDF_Form::CPDF_Form(CPDF_Document* pDoc, m_Transparency = 0; LoadTransInfo(); } + CPDF_Form::~CPDF_Form() {} + void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates, CFX_Matrix* pParentMatrix, CPDF_Type3Char* pType3Char, @@ -903,6 +895,7 @@ void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates, level); m_ParseState = CONTENT_PARSING; } + void CPDF_Form::ParseContent(CPDF_AllStates* pGraphicStates, CFX_Matrix* pParentMatrix, CPDF_Type3Char* pType3Char, @@ -911,16 +904,16 @@ void CPDF_Form::ParseContent(CPDF_AllStates* pGraphicStates, StartParse(pGraphicStates, pParentMatrix, pType3Char, pOptions, level); ContinueParse(NULL); } + CPDF_Form* CPDF_Form::Clone() const { - CPDF_Form* pClone = + CPDF_Form* pCloneForm = new CPDF_Form(m_pDocument, m_pPageResources, m_pFormStream, m_pResources); - FX_POSITION pos = m_PageObjectList.GetHeadPosition(); - while (pos) { - CPDF_PageObject* pObj = (CPDF_PageObject*)m_PageObjectList.GetNext(pos); - pClone->m_PageObjectList.AddTail(pObj->Clone()); - } - return pClone; + for (const auto& pObj : m_PageObjectList) + pCloneForm->m_PageObjectList.emplace_back(pObj->Clone()); + + return pCloneForm; } + void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, int xPos, int yPos, diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 6e02cb11b4..d49186374f 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -780,7 +780,7 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { parser.Parse(stream.GetData(), stream.GetSize(), 0); return; } - CPDF_FormObject* pFormObj = new CPDF_FormObject; + std::unique_ptr<CPDF_FormObject> pFormObj(new CPDF_FormObject); pFormObj->m_pForm = new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources); pFormObj->m_FormMatrix = m_pCurStates->m_CTM; @@ -796,8 +796,8 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { m_pObjectHolder->SetBackgroundAlphaNeeded(TRUE); } pFormObj->CalcBoundingBox(); - SetGraphicStates(pFormObj, TRUE, TRUE, TRUE); - m_pObjectHolder->GetPageObjectList()->AddTail(pFormObj); + SetGraphicStates(pFormObj.get(), TRUE, TRUE, TRUE); + m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj)); } CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, @@ -809,7 +809,8 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, CFX_Matrix ImageMatrix; ImageMatrix.Copy(m_pCurStates->m_CTM); ImageMatrix.Concat(m_mtContentToUser); - CPDF_ImageObject* pImageObj = new CPDF_ImageObject; + + std::unique_ptr<CPDF_ImageObject> pImageObj(new CPDF_ImageObject); if (pImage) { pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pImage->GetStream()); @@ -819,11 +820,13 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, pImageObj->m_pImage = new CPDF_Image(m_pDocument); pImageObj->m_pImage->LoadImageF(pStream, bInline); } - SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE); + SetGraphicStates(pImageObj.get(), pImageObj->m_pImage->IsMask(), FALSE, + FALSE); pImageObj->m_Matrix = ImageMatrix; pImageObj->CalcBoundingBox(); - m_pObjectHolder->GetPageObjectList()->AddTail(pImageObj); - return pImageObj; + CPDF_ImageObject* pRet = pImageObj.get(); + m_pObjectHolder->GetPageObjectList()->push_back(std::move(pImageObj)); + return pRet; } void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {} @@ -1190,9 +1193,9 @@ void CPDF_StreamContentParser::Handle_ShadeFill() { if (!pShading->Load()) { return; } - CPDF_ShadingObject* pObj = new CPDF_ShadingObject; + std::unique_ptr<CPDF_ShadingObject> pObj(new CPDF_ShadingObject); pObj->m_pShading = pShading; - SetGraphicStates(pObj, FALSE, FALSE, FALSE); + SetGraphicStates(pObj.get(), FALSE, FALSE, FALSE); pObj->m_Matrix = m_pCurStates->m_CTM; pObj->m_Matrix.Concat(m_mtContentToUser); CFX_FloatRect bbox; @@ -1211,7 +1214,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill() { pObj->m_Right = bbox.right; pObj->m_Top = bbox.top; pObj->m_Bottom = bbox.bottom; - m_pObjectHolder->GetPageObjectList()->AddTail(pObj); + m_pObjectHolder->GetPageObjectList()->push_back(std::move(pObj)); } void CPDF_StreamContentParser::Handle_SetCharSpace() { @@ -1365,31 +1368,34 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, } else { textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode; } - CPDF_TextObject* pText = new CPDF_TextObject; - m_pLastTextObject = pText; - SetGraphicStates(pText, TRUE, TRUE, TRUE); - if (textmode && textmode != 3 && textmode != 4 && textmode != 7) { - FX_FLOAT* pCTM = pText->m_TextState.GetModify()->m_CTM; - pCTM[0] = m_pCurStates->m_CTM.a; - pCTM[1] = m_pCurStates->m_CTM.c; - pCTM[2] = m_pCurStates->m_CTM.b; - pCTM[3] = m_pCurStates->m_CTM.d; - } - pText->SetSegments(pStrs, pKerning, nsegs); - pText->m_PosX = m_pCurStates->m_TextX; - pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise; - ConvertTextSpace(pText->m_PosX, pText->m_PosY); - FX_FLOAT x_advance, y_advance; - pText->CalcPositionData(&x_advance, &y_advance, m_pCurStates->m_TextHorzScale, - m_Level); - m_pCurStates->m_TextX += x_advance; - m_pCurStates->m_TextY += y_advance; - if (textmode > 3) { - CPDF_TextObject* pCopy = new CPDF_TextObject; - pCopy->Copy(pText); - m_ClipTextList.Add(pCopy); - } - m_pObjectHolder->GetPageObjectList()->AddTail(pText); + { + std::unique_ptr<CPDF_TextObject> pText(new CPDF_TextObject); + m_pLastTextObject = pText.get(); + SetGraphicStates(m_pLastTextObject, TRUE, TRUE, TRUE); + if (textmode && textmode != 3 && textmode != 4 && textmode != 7) { + FX_FLOAT* pCTM = pText->m_TextState.GetModify()->m_CTM; + pCTM[0] = m_pCurStates->m_CTM.a; + pCTM[1] = m_pCurStates->m_CTM.c; + pCTM[2] = m_pCurStates->m_CTM.b; + pCTM[3] = m_pCurStates->m_CTM.d; + } + pText->SetSegments(pStrs, pKerning, nsegs); + pText->m_PosX = m_pCurStates->m_TextX; + pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise; + ConvertTextSpace(pText->m_PosX, pText->m_PosY); + FX_FLOAT x_advance; + FX_FLOAT y_advance; + pText->CalcPositionData(&x_advance, &y_advance, + m_pCurStates->m_TextHorzScale, m_Level); + m_pCurStates->m_TextX += x_advance; + m_pCurStates->m_TextY += y_advance; + if (textmode > 3) { + CPDF_TextObject* pCopy = new CPDF_TextObject; + pCopy->Copy(pText.get()); + m_ClipTextList.Add(pCopy); + } + m_pObjectHolder->GetPageObjectList()->push_back(std::move(pText)); + } if (pKerning && pKerning[nsegs - 1] != 0) { if (!pFont->IsVertWriting()) { m_pCurStates->m_TextX -= @@ -1617,14 +1623,14 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) { CFX_Matrix matrix = m_pCurStates->m_CTM; matrix.Concat(m_mtContentToUser); if (bStroke || FillType) { - CPDF_PathObject* pPathObj = new CPDF_PathObject; + std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject); pPathObj->m_bStroke = bStroke; pPathObj->m_FillType = FillType; pPathObj->m_Path = Path; pPathObj->m_Matrix = matrix; - SetGraphicStates(pPathObj, TRUE, FALSE, TRUE); + SetGraphicStates(pPathObj.get(), TRUE, FALSE, TRUE); pPathObj->CalcBoundingBox(); - m_pObjectHolder->GetPageObjectList()->AddTail(pPathObj); + m_pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); } if (PathClipType) { if (!matrix.IsIdentity()) { @@ -1641,13 +1647,12 @@ FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData, if (m_Level > _FPDF_MAX_FORM_LEVEL_) { return dwSize; } - FX_DWORD InitObjCount = m_pObjectHolder->GetPageObjectList()->GetCount(); + FX_DWORD InitObjCount = m_pObjectHolder->GetPageObjectList()->size(); CPDF_StreamParser syntax(pData, dwSize); CPDF_StreamParserAutoClearer auto_clearer(&m_pSyntax, &syntax); m_CompatCount = 0; while (1) { - FX_DWORD cost = - m_pObjectHolder->GetPageObjectList()->GetCount() - InitObjCount; + FX_DWORD cost = m_pObjectHolder->GetPageObjectList()->size() - InitObjCount; if (max_cost && cost >= max_cost) { break; } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index 7fa3286e11..20f0c39c25 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -666,7 +666,7 @@ bool CPDF_StreamParser::PositionIsInBounds() const { CPDF_ContentParser::CPDF_ContentParser() : m_Status(Ready), m_InternalStage(STAGE_GETCONTENT), - m_pObjects(nullptr), + m_pObjectHolder(nullptr), m_bForm(false), m_pType3Char(nullptr), m_pData(nullptr), @@ -684,7 +684,7 @@ void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) { m_Status = Done; return; } - m_pObjects = pPage; + m_pObjectHolder = pPage; m_bForm = FALSE; if (pOptions) { m_Options = *pOptions; @@ -720,7 +720,7 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm, CPDF_ParseOptions* pOptions, int level) { m_pType3Char = pType3Char; - m_pObjects = pForm; + m_pObjectHolder = pForm; m_bForm = TRUE; CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixBy("Matrix"); if (pGraphicStates) { @@ -803,7 +803,8 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) { m_InternalStage = STAGE_PARSE; m_CurrentOffset = 0; } else { - CPDF_Array* pContent = m_pObjects->m_pFormDict->GetArrayBy("Contents"); + CPDF_Array* pContent = + m_pObjectHolder->m_pFormDict->GetArrayBy("Contents"); m_StreamArray[m_CurrentOffset].reset(new CPDF_StreamAcc); CPDF_Stream* pStreamObj = ToStream( pContent ? pContent->GetElementValue(m_CurrentOffset) : nullptr); @@ -814,9 +815,9 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) { if (m_InternalStage == STAGE_PARSE) { if (!m_pParser) { m_pParser.reset(new CPDF_StreamContentParser( - m_pObjects->m_pDocument, m_pObjects->m_pPageResources, nullptr, - nullptr, m_pObjects, m_pObjects->m_pResources, &m_pObjects->m_BBox, - &m_Options, nullptr, 0)); + m_pObjectHolder->m_pDocument, m_pObjectHolder->m_pPageResources, + nullptr, nullptr, m_pObjectHolder, m_pObjectHolder->m_pResources, + &m_pObjectHolder->m_BBox, &m_Options, nullptr, 0)); m_pParser->GetCurStates()->m_ColorState.GetModify()->Default(); } if (m_CurrentOffset >= m_Size) { @@ -841,10 +842,7 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) { m_pType3Char->m_BBox.top = FXSYS_round(m_pParser->GetType3Data()[5] * 1000); } - FX_POSITION pos = m_pObjects->GetPageObjectList()->GetHeadPosition(); - while (pos) { - CPDF_PageObject* pObj = - m_pObjects->GetPageObjectList()->GetNextObject(pos); + for (auto& pObj : *m_pObjectHolder->GetPageObjectList()) { if (pObj->m_ClipPath.IsNull()) { continue; } diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h index 4df8d6aa9f..fb95b6b30d 100644 --- a/core/src/fpdfapi/fpdf_page/pageint.h +++ b/core/src/fpdfapi/fpdf_page/pageint.h @@ -94,7 +94,7 @@ class CPDF_StreamContentParser { CPDF_Dictionary* pPageResources, CPDF_Dictionary* pParentResources, CFX_Matrix* pmtContentToUser, - CPDF_PageObjectHolder* pObjHolder, + CPDF_PageObjectHolder* pObjectHolder, CPDF_Dictionary* pResources, CFX_FloatRect* pBBox, CPDF_ParseOptions* pOptions, @@ -298,7 +298,7 @@ class CPDF_ContentParser { ParseStatus m_Status; InternalStage m_InternalStage; - CPDF_PageObjectHolder* m_pObjects; + CPDF_PageObjectHolder* m_pObjectHolder; FX_BOOL m_bForm; CPDF_ParseOptions m_Options; CPDF_Type3Char* m_pType3Char; |