summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_page
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-02-16 17:15:32 -0800
committerTom Sepez <tsepez@chromium.org>2016-02-16 17:15:32 -0800
commit32c70815316672091946be88e5941089c359d151 (patch)
tree5c09a48725bb43b07d09a435f38ead6a933e1712 /core/src/fpdfapi/fpdf_page
parent4e44b4049bd4790bcb6c835455632c81c34e78b6 (diff)
downloadpdfium-32c70815316672091946be88e5941089c359d151.tar.xz
Split CPDF_PageObjectHolder off from CPDF_PageObjectList
Eventually, we're going to expose an iterator over CPDF_PageObjectList that we don't want to be inherited by the CPDF_PageObjectHolder sub-classes: page and form. Also, the operations that the object holder performs dealing with inquiring about masks and such seem beyond the scope of what a list would provide. Hence the "Holder" name. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1701073002 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_page')
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page.cpp56
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp29
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h8
5 files changed, 44 insertions, 55 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
index c4a26e9921..1a81e1b901 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
@@ -670,7 +670,7 @@ void CPDF_FormObject::CalcBoundingBox() {
m_Right = form_rect.right;
m_Top = form_rect.top;
}
-CPDF_PageObjectList::CPDF_PageObjectList()
+CPDF_PageObjectHolder::CPDF_PageObjectHolder()
: m_pFormDict(nullptr),
m_pFormStream(nullptr),
m_pDocument(nullptr),
@@ -680,14 +680,15 @@ CPDF_PageObjectList::CPDF_PageObjectList()
m_bBackgroundAlphaNeeded(FALSE),
m_bHasImageMask(FALSE),
m_ParseState(CONTENT_NOT_PARSED),
- m_ObjectList(128) {}
-CPDF_PageObjectList::~CPDF_PageObjectList() {
- FX_POSITION pos = m_ObjectList.GetHeadPosition();
+ m_PageObjectList(128) {}
+
+CPDF_PageObjectHolder::~CPDF_PageObjectHolder() {
+ FX_POSITION pos = m_PageObjectList.GetHeadPosition();
while (pos) {
- delete (CPDF_PageObject*)m_ObjectList.GetNext(pos);
+ delete m_PageObjectList.GetNextObject(pos);
}
}
-void CPDF_PageObjectList::ContinueParse(IFX_Pause* pPause) {
+void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) {
if (!m_pParser) {
return;
}
@@ -700,43 +701,30 @@ void CPDF_PageObjectList::ContinueParse(IFX_Pause* pPause) {
FX_POSITION CPDF_PageObjectList::InsertObject(FX_POSITION posInsertAfter,
CPDF_PageObject* pNewObject) {
if (!posInsertAfter) {
- return m_ObjectList.AddHead(pNewObject);
- }
- return m_ObjectList.InsertAfter(posInsertAfter, pNewObject);
-}
-int CPDF_PageObjectList::GetObjectIndex(CPDF_PageObject* pObj) const {
- int index = 0;
- FX_POSITION pos = m_ObjectList.GetHeadPosition();
- while (pos) {
- CPDF_PageObject* pThisObj = (CPDF_PageObject*)m_ObjectList.GetNext(pos);
- if (pThisObj == pObj) {
- return index;
- }
- index++;
+ return AddHead(pNewObject);
}
- return -1;
+ return InsertAfter(posInsertAfter, pNewObject);
}
CPDF_PageObject* CPDF_PageObjectList::GetObjectByIndex(int index) const {
- FX_POSITION pos = m_ObjectList.FindIndex(index);
- return pos ? static_cast<CPDF_PageObject*>(m_ObjectList.GetAt(pos)) : nullptr;
+ FX_POSITION pos = FindIndex(index);
+ return pos ? GetObjectAt(pos) : nullptr;
}
-void CPDF_PageObjectList::Transform(const CFX_Matrix& matrix) {
- FX_POSITION pos = m_ObjectList.GetHeadPosition();
+void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) {
+ FX_POSITION pos = m_PageObjectList.GetHeadPosition();
while (pos) {
- CPDF_PageObject* pObj = (CPDF_PageObject*)m_ObjectList.GetNext(pos);
- pObj->Transform(matrix);
+ m_PageObjectList.GetNextObject(pos)->Transform(matrix);
}
}
-CFX_FloatRect CPDF_PageObjectList::CalcBoundingBox() const {
- if (m_ObjectList.GetCount() == 0) {
+CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const {
+ if (m_PageObjectList.GetCount() == 0) {
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_ObjectList.GetHeadPosition();
+ FX_POSITION pos = m_PageObjectList.GetHeadPosition();
while (pos) {
- CPDF_PageObject* pObj = (CPDF_PageObject*)m_ObjectList.GetNext(pos);
+ CPDF_PageObject* pObj = (CPDF_PageObject*)m_PageObjectList.GetNext(pos);
if (left > pObj->m_Left) {
left = pObj->m_Left;
}
@@ -752,7 +740,7 @@ CFX_FloatRect CPDF_PageObjectList::CalcBoundingBox() const {
}
return CFX_FloatRect(left, bottom, right, top);
}
-void CPDF_PageObjectList::LoadTransInfo() {
+void CPDF_PageObjectHolder::LoadTransInfo() {
if (!m_pFormDict) {
return;
}
@@ -926,10 +914,10 @@ void CPDF_Form::ParseContent(CPDF_AllStates* pGraphicStates,
CPDF_Form* CPDF_Form::Clone() const {
CPDF_Form* pClone =
new CPDF_Form(m_pDocument, m_pPageResources, m_pFormStream, m_pResources);
- FX_POSITION pos = m_ObjectList.GetHeadPosition();
+ FX_POSITION pos = m_PageObjectList.GetHeadPosition();
while (pos) {
- CPDF_PageObject* pObj = (CPDF_PageObject*)m_ObjectList.GetNext(pos);
- pClone->m_ObjectList.AddTail(pObj->Clone());
+ CPDF_PageObject* pObj = (CPDF_PageObject*)m_PageObjectList.GetNext(pos);
+ pClone->m_PageObjectList.AddTail(pObj->Clone());
}
return pClone;
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
index 20345138b4..a003d2047f 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -520,7 +520,7 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS,
pGeneralState->SetBlendMode(mode);
if (pGeneralState->m_BlendType > FXDIB_BLEND_MULTIPLY) {
- pParser->GetObjectList()->SetBackgroundAlphaNeeded(TRUE);
+ pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(TRUE);
}
break;
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index 7f242fdb0e..6e02cb11b4 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -114,7 +114,7 @@ CPDF_StreamContentParser::CPDF_StreamContentParser(
CPDF_Dictionary* pPageResources,
CPDF_Dictionary* pParentResources,
CFX_Matrix* pmtContentToUser,
- CPDF_PageObjectList* pObjList,
+ CPDF_PageObjectHolder* pObjHolder,
CPDF_Dictionary* pResources,
CPDF_Rect* pBBox,
CPDF_ParseOptions* pOptions,
@@ -124,7 +124,7 @@ CPDF_StreamContentParser::CPDF_StreamContentParser(
m_pPageResources(pPageResources),
m_pParentResources(pParentResources),
m_pResources(pResources),
- m_pObjectList(pObjList),
+ m_pObjectHolder(pObjHolder),
m_Level(level),
m_ParamStartPos(0),
m_ParamCount(0),
@@ -738,8 +738,8 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() {
CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE);
m_LastImageName = name;
m_pLastImage = pObj->m_pImage;
- if (!m_pObjectList->HasImageMask())
- m_pObjectList->SetHasImageMask(m_pLastImage->IsMask());
+ if (!m_pObjectHolder->HasImageMask())
+ m_pObjectHolder->SetHasImageMask(m_pLastImage->IsMask());
} else if (type == "Form") {
AddForm(pXObject);
} else {
@@ -764,7 +764,7 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
form_bbox.Transform(&form_matrix);
}
CPDF_StreamContentParser parser(m_pDocument, m_pPageResources, m_pResources,
- &m_mtContentToUser, m_pObjectList,
+ &m_mtContentToUser, m_pObjectHolder,
pResources, &form_bbox, &m_Options,
m_pCurStates.get(), m_Level + 1);
parser.m_pCurStates->m_CTM = form_matrix;
@@ -791,13 +791,13 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
status.m_ColorState = m_pCurStates->m_ColorState;
status.m_TextState = m_pCurStates->m_TextState;
pFormObj->m_pForm->ParseContent(&status, NULL, NULL, &m_Options, m_Level + 1);
- if (!m_pObjectList->BackgroundAlphaNeeded() &&
+ if (!m_pObjectHolder->BackgroundAlphaNeeded() &&
pFormObj->m_pForm->BackgroundAlphaNeeded()) {
- m_pObjectList->SetBackgroundAlphaNeeded(TRUE);
+ m_pObjectHolder->SetBackgroundAlphaNeeded(TRUE);
}
pFormObj->CalcBoundingBox();
SetGraphicStates(pFormObj, TRUE, TRUE, TRUE);
- m_pObjectList->AddTail(pFormObj);
+ m_pObjectHolder->GetPageObjectList()->AddTail(pFormObj);
}
CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream,
@@ -822,7 +822,7 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream,
SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE);
pImageObj->m_Matrix = ImageMatrix;
pImageObj->CalcBoundingBox();
- m_pObjectList->AddTail(pImageObj);
+ m_pObjectHolder->GetPageObjectList()->AddTail(pImageObj);
return pImageObj;
}
@@ -1211,7 +1211,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill() {
pObj->m_Right = bbox.right;
pObj->m_Top = bbox.top;
pObj->m_Bottom = bbox.bottom;
- m_pObjectList->AddTail(pObj);
+ m_pObjectHolder->GetPageObjectList()->AddTail(pObj);
}
void CPDF_StreamContentParser::Handle_SetCharSpace() {
@@ -1389,7 +1389,7 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
pCopy->Copy(pText);
m_ClipTextList.Add(pCopy);
}
- m_pObjectList->AddTail(pText);
+ m_pObjectHolder->GetPageObjectList()->AddTail(pText);
if (pKerning && pKerning[nsegs - 1] != 0) {
if (!pFont->IsVertWriting()) {
m_pCurStates->m_TextX -=
@@ -1624,7 +1624,7 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) {
pPathObj->m_Matrix = matrix;
SetGraphicStates(pPathObj, TRUE, FALSE, TRUE);
pPathObj->CalcBoundingBox();
- m_pObjectList->AddTail(pPathObj);
+ m_pObjectHolder->GetPageObjectList()->AddTail(pPathObj);
}
if (PathClipType) {
if (!matrix.IsIdentity()) {
@@ -1641,12 +1641,13 @@ FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData,
if (m_Level > _FPDF_MAX_FORM_LEVEL_) {
return dwSize;
}
- FX_DWORD InitObjCount = m_pObjectList->CountObjects();
+ FX_DWORD InitObjCount = m_pObjectHolder->GetPageObjectList()->GetCount();
CPDF_StreamParser syntax(pData, dwSize);
CPDF_StreamParserAutoClearer auto_clearer(&m_pSyntax, &syntax);
m_CompatCount = 0;
while (1) {
- FX_DWORD cost = m_pObjectList->CountObjects() - InitObjCount;
+ FX_DWORD cost =
+ m_pObjectHolder->GetPageObjectList()->GetCount() - 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 022c170bf0..7fa3286e11 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -841,10 +841,10 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) {
m_pType3Char->m_BBox.top =
FXSYS_round(m_pParser->GetType3Data()[5] * 1000);
}
- FX_POSITION pos = m_pObjects->GetFirstObjectPosition();
+ FX_POSITION pos = m_pObjects->GetPageObjectList()->GetHeadPosition();
while (pos) {
CPDF_PageObject* pObj =
- (CPDF_PageObject*)m_pObjects->GetNextObject(pos);
+ m_pObjects->GetPageObjectList()->GetNextObject(pos);
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 9c8946b721..4df8d6aa9f 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_PageObjectList* pObjList,
+ CPDF_PageObjectHolder* pObjHolder,
CPDF_Dictionary* pResources,
CFX_FloatRect* pBBox,
CPDF_ParseOptions* pOptions,
@@ -102,7 +102,7 @@ class CPDF_StreamContentParser {
int level);
~CPDF_StreamContentParser();
- CPDF_PageObjectList* GetObjectList() const { return m_pObjectList; }
+ CPDF_PageObjectHolder* GetPageObjectHolder() const { return m_pObjectHolder; }
CPDF_AllStates* GetCurStates() const { return m_pCurStates.get(); }
FX_BOOL IsColored() const { return m_bColored; }
const FX_FLOAT* GetType3Data() const { return m_Type3Data; }
@@ -236,7 +236,7 @@ class CPDF_StreamContentParser {
CPDF_Dictionary* m_pPageResources;
CPDF_Dictionary* m_pParentResources;
CPDF_Dictionary* m_pResources;
- CPDF_PageObjectList* m_pObjectList;
+ CPDF_PageObjectHolder* m_pObjectHolder;
int m_Level;
CFX_Matrix m_mtContentToUser;
CFX_FloatRect m_BBox;
@@ -298,7 +298,7 @@ class CPDF_ContentParser {
ParseStatus m_Status;
InternalStage m_InternalStage;
- CPDF_PageObjectList* m_pObjects;
+ CPDF_PageObjectHolder* m_pObjects;
FX_BOOL m_bForm;
CPDF_ParseOptions m_Options;
CPDF_Type3Char* m_pType3Char;