diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-01-21 10:51:51 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-01-21 10:51:51 -0800 |
commit | da9355139b5dce270be02af31db326d60f488e8c (patch) | |
tree | 87198aca65808477b8eb425af1296c17c72452d4 | |
parent | ca6d98f4dfe7d4fc506b72c91f122f471a53c878 (diff) | |
download | pdfium-da9355139b5dce270be02af31db326d60f488e8c.tar.xz |
Redo CPDF_PageObjects - part 1
Remove default args.
Remove unreachable code.
R=ochang@chromium.org
Review URL: https://codereview.chromium.org/1601093009 .
-rw-r--r-- | core/include/fpdfapi/fpdf_page.h | 31 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page.cpp | 48 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp | 2 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 20 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/src/fpdf_flatten.cpp | 3 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfeditpage.cpp | 3 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfview.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Document.cpp | 12 |
9 files changed, 47 insertions, 78 deletions
diff --git a/core/include/fpdfapi/fpdf_page.h b/core/include/fpdfapi/fpdf_page.h index edcef3c0b6..2ff8a0596b 100644 --- a/core/include/fpdfapi/fpdf_page.h +++ b/core/include/fpdfapi/fpdf_page.h @@ -7,11 +7,12 @@ #ifndef CORE_INCLUDE_FPDFAPI_FPDF_PAGE_H_ #define CORE_INCLUDE_FPDFAPI_FPDF_PAGE_H_ +#include <memory> + +#include "core/include/fpdfapi/fpdf_parser.h" +#include "core/include/fpdfapi/fpdf_resource.h" #include "core/include/fxge/fx_dib.h" -#include "fpdf_parser.h" -#include "fpdf_resource.h" -class CPDF_PageObjects; class CPDF_Page; class CPDF_Form; class CPDF_ParseOptions; @@ -27,7 +28,7 @@ class CPDF_StreamContentParser; class CPDF_PageObjects { public: - CPDF_PageObjects(FX_BOOL bReleaseMembers = TRUE); + CPDF_PageObjects(); ~CPDF_PageObjects(); void ContinueParse(IFX_Pause* pPause); @@ -54,6 +55,7 @@ class CPDF_PageObjects { return (CPDF_PageObject*)m_ObjectList.GetAt(pos); } + void AddTail(CPDF_PageObject* obj) { m_ObjectList.AddTail(obj); } FX_DWORD CountObjects() const { return m_ObjectList.GetCount(); } int GetObjectIndex(CPDF_PageObject* pObj) const; @@ -66,9 +68,12 @@ class CPDF_PageObjects { void Transform(const CFX_Matrix& matrix); FX_BOOL BackgroundAlphaNeeded() const { return m_bBackgroundAlphaNeeded; } + void SetBackgroundAlphaNeeded(FX_BOOL needed) { + m_bBackgroundAlphaNeeded = needed; + } FX_BOOL HasImageMask() const { return m_bHasImageMask; } - + void SetHasImageMask(FX_BOOL value) { m_bHasImageMask = value; } CFX_FloatRect CalcBoundingBox() const; CPDF_Dictionary* m_pFormDict; @@ -80,21 +85,15 @@ class CPDF_PageObjects { int m_Transparency; protected: - friend class CPDF_ContentParser; - friend class CPDF_StreamContentParser; - friend class CPDF_AllStates; - enum ParseState { CONTENT_NOT_PARSED, CONTENT_PARSING, CONTENT_PARSED }; void LoadTransInfo(); - void ClearCacheObjects(); - CFX_PtrList m_ObjectList; FX_BOOL m_bBackgroundAlphaNeeded; FX_BOOL m_bHasImageMask; - FX_BOOL m_bReleaseMembers; - CPDF_ContentParser* m_pParser; ParseState m_ParseState; + std::unique_ptr<CPDF_ContentParser> m_pParser; + CFX_PtrList m_ObjectList; }; class CPDF_Page : public CPDF_PageObjects, public CFX_PrivateData { @@ -106,9 +105,7 @@ class CPDF_Page : public CPDF_PageObjects, public CFX_PrivateData { CPDF_Dictionary* pPageDict, FX_BOOL bPageCache = TRUE); - void StartParse(CPDF_ParseOptions* pOptions = NULL, FX_BOOL bReParse = FALSE); - void ParseContent(CPDF_ParseOptions* pOptions = NULL, - FX_BOOL bReParse = FALSE); + void ParseContent(CPDF_ParseOptions* pOptions); void GetDisplayMatrix(CFX_Matrix& matrix, int xPos, @@ -126,6 +123,8 @@ class CPDF_Page : public CPDF_PageObjects, public CFX_PrivateData { protected: friend class CPDF_ContentParser; + void StartParse(CPDF_ParseOptions* pOptions); + FX_FLOAT m_PageWidth; FX_FLOAT m_PageHeight; CFX_Matrix m_PageMatrix; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp index 7e2492fad7..1d18b5343d 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp @@ -666,24 +666,18 @@ void CPDF_FormObject::CalcBoundingBox() { m_Right = form_rect.right; m_Top = form_rect.top; } -CPDF_PageObjects::CPDF_PageObjects(FX_BOOL bReleaseMembers) +CPDF_PageObjects::CPDF_PageObjects() : m_pFormDict(nullptr), m_pFormStream(nullptr), m_pDocument(nullptr), m_pPageResources(nullptr), m_pResources(nullptr), m_Transparency(0), - m_ObjectList(128), m_bBackgroundAlphaNeeded(FALSE), m_bHasImageMask(FALSE), - m_bReleaseMembers(bReleaseMembers), - m_pParser(nullptr), - m_ParseState(CONTENT_NOT_PARSED) {} + m_ParseState(CONTENT_NOT_PARSED), + m_ObjectList(128) {} CPDF_PageObjects::~CPDF_PageObjects() { - delete m_pParser; - if (!m_bReleaseMembers) { - return; - } FX_POSITION pos = m_ObjectList.GetHeadPosition(); while (pos) { delete (CPDF_PageObject*)m_ObjectList.GetNext(pos); @@ -696,8 +690,7 @@ void CPDF_PageObjects::ContinueParse(IFX_Pause* pPause) { m_pParser->Continue(pPause); if (m_pParser->GetStatus() == CPDF_ContentParser::Done) { m_ParseState = CONTENT_PARSED; - delete m_pParser; - m_pParser = NULL; + m_pParser.reset(); } } FX_POSITION CPDF_PageObjects::InsertObject(FX_POSITION posInsertAfter, @@ -774,21 +767,9 @@ void CPDF_PageObjects::LoadTransInfo() { m_Transparency |= PDFTRANS_KNOCKOUT; } } -void CPDF_PageObjects::ClearCacheObjects() { - m_ParseState = CONTENT_NOT_PARSED; - delete m_pParser; - m_pParser = NULL; - if (m_bReleaseMembers) { - FX_POSITION pos = m_ObjectList.GetHeadPosition(); - while (pos) { - delete (CPDF_PageObject*)m_ObjectList.GetNext(pos); - } - } - m_ObjectList.RemoveAll(); -} -CPDF_Page::CPDF_Page() { - m_pPageRender = NULL; -} + +CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {} + void CPDF_Page::Load(CPDF_Document* pDocument, CPDF_Dictionary* pPageDict, FX_BOOL bPageCache) { @@ -858,20 +839,17 @@ void CPDF_Page::Load(CPDF_Document* pDocument, m_Transparency = PDFTRANS_ISOLATED; LoadTransInfo(); } -void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions, FX_BOOL bReParse) { - if (bReParse) { - ClearCacheObjects(); - } +void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) { if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { return; } - m_pParser = new CPDF_ContentParser; + m_pParser.reset(new CPDF_ContentParser); m_pParser->Start(this, pOptions); m_ParseState = CONTENT_PARSING; } -void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions, FX_BOOL bReParse) { - StartParse(pOptions, bReParse); - ContinueParse(NULL); +void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) { + StartParse(pOptions); + ContinueParse(nullptr); } CPDF_Page::~CPDF_Page() { if (m_pPageRender) { @@ -928,7 +906,7 @@ void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates, if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { return; } - m_pParser = new CPDF_ContentParser; + m_pParser.reset(new CPDF_ContentParser); m_pParser->Start(this, pGraphicStates, pParentMatrix, pType3Char, pOptions, level); m_ParseState = CONTENT_PARSING; 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 dd16aa85ce..e9f1747097 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()->m_bBackgroundAlphaNeeded = TRUE; + pParser->GetObjectList()->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 6ed3d3fc0e..08b10e5500 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -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->m_bHasImageMask) - m_pObjectList->m_bHasImageMask = m_pLastImage->IsMask(); + if (!m_pObjectList->HasImageMask()) + m_pObjectList->SetHasImageMask(m_pLastImage->IsMask()); } else if (type == "Form") { AddForm(pXObject); } else { @@ -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->m_bBackgroundAlphaNeeded && - pFormObj->m_pForm->m_bBackgroundAlphaNeeded) { - m_pObjectList->m_bBackgroundAlphaNeeded = TRUE; + if (!m_pObjectList->BackgroundAlphaNeeded() && + pFormObj->m_pForm->BackgroundAlphaNeeded()) { + m_pObjectList->SetBackgroundAlphaNeeded(TRUE); } pFormObj->CalcBoundingBox(); SetGraphicStates(pFormObj, TRUE, TRUE, TRUE); - m_pObjectList->m_ObjectList.AddTail(pFormObj); + m_pObjectList->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->m_ObjectList.AddTail(pImageObj); + m_pObjectList->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->m_ObjectList.AddTail(pObj); + m_pObjectList->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->m_ObjectList.AddTail(pText); + m_pObjectList->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->m_ObjectList.AddTail(pPathObj); + m_pObjectList->AddTail(pPathObj); } if (PathClipType) { if (!matrix.IsIdentity()) { 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 9e9b55177b..298f28235f 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->m_ObjectList.GetHeadPosition(); + FX_POSITION pos = m_pObjects->GetFirstObjectPosition(); while (pos) { CPDF_PageObject* pObj = - (CPDF_PageObject*)m_pObjects->m_ObjectList.GetNext(pos); + (CPDF_PageObject*)m_pObjects->GetNextObject(pos); if (pObj->m_ClipPath.IsNull()) { continue; } diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp index 50d5036724..c81955d6ca 100644 --- a/fpdfsdk/src/fpdf_flatten.cpp +++ b/fpdfsdk/src/fpdf_flatten.cpp @@ -40,10 +40,9 @@ FX_BOOL GetContentsRect(CPDF_Document* pDoc, CPDF_RectArray* pRectArray) { CPDF_Page* pPDFPage = new CPDF_Page; pPDFPage->Load(pDoc, pDict, FALSE); - pPDFPage->ParseContent(); + pPDFPage->ParseContent(nullptr); FX_POSITION pos = pPDFPage->GetFirstObjectPosition(); - while (pos) { CPDF_PageObject* pPageObject = pPDFPage->GetNextObject(pos); if (!pPageObject) diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp index 240724fe48..0a44724f98 100644 --- a/fpdfsdk/src/fpdfeditpage.cpp +++ b/fpdfsdk/src/fpdfeditpage.cpp @@ -80,8 +80,7 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, CPDF_Page* pPage = new CPDF_Page; pPage->Load(pDoc, pPageDict); - pPage->ParseContent(); - + pPage->ParseContent(nullptr); return pPage; } diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index e59515a863..d713e9773d 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -297,7 +297,7 @@ DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, return NULL; CPDF_Page* pPage = new CPDF_Page; pPage->Load(pDoc, pDict); - pPage->ParseContent(); + pPage->ParseContent(nullptr); return pPage; } diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index 1040c34770..ab733375ee 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -1378,8 +1378,7 @@ FX_BOOL Document::getPageNthWord(IJS_Context* cc, CPDF_Page page; page.Load(pDocument, pPageDict); - page.StartParse(); - page.ParseContent(); + page.ParseContent(nullptr); FX_POSITION pos = page.GetFirstObjectPosition(); @@ -1429,7 +1428,6 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc, return FALSE; int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; - CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); CJS_Context* pContext = static_cast<CJS_Context*>(cc); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { @@ -1443,13 +1441,10 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc, CPDF_Page page; page.Load(pDocument, pPageDict); - page.StartParse(); - page.ParseContent(); - - FX_POSITION pos = page.GetFirstObjectPosition(); + page.ParseContent(nullptr); int nWords = 0; - + FX_POSITION pos = page.GetFirstObjectPosition(); while (pos) { if (CPDF_PageObject* pPageObj = page.GetNextObject(pos)) { if (pPageObj->m_Type == PDFPAGE_TEXT) { @@ -1460,7 +1455,6 @@ FX_BOOL Document::getPageNumWords(IJS_Context* cc, } vRet = nWords; - return TRUE; } |