summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_page
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-04-26 11:46:02 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-26 11:46:02 -0700
commit5cc24654fb345189140acb4711ff981e1c720951 (patch)
tree1e9e11a9136363e2b330ffbbce6fdf9e3827b5b1 /core/fpdfapi/fpdf_page
parent76c53794b6202ec37f6dcace5f2ae86870e953b6 (diff)
downloadpdfium-5cc24654fb345189140acb4711ff981e1c720951.tar.xz
Clean up CPDF_Page.
- Merge CPDF_Page::Load() into ctor. - Remove always nullptr param for CPDF_Page::ParseContent(). - Remove unneeded indirection in IPDF_RenderModule. - Delete CPDF_ParseOptions. - Fix up CPDF_Pattern. Review URL: https://codereview.chromium.org/1918113002
Diffstat (limited to 'core/fpdfapi/fpdf_page')
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_color.cpp34
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstate.cpp18
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_form.cpp7
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_page.cpp116
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_parseoptions.cpp12
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_parseoptions.h22
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_pattern.cpp5
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_pattern.h20
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp10
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_shadingpattern.h7
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_tilingpattern.cpp7
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_tilingpattern.h16
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_doc.cpp8
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp205
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp126
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_form.h3
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_page.h26
-rw-r--r--core/fpdfapi/fpdf_page/pageint.h12
18 files changed, 180 insertions, 474 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_color.cpp b/core/fpdfapi/fpdf_page/cpdf_color.cpp
index d174660d4a..5536f71f9f 100644
--- a/core/fpdfapi/fpdf_page/cpdf_color.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_color.cpp
@@ -37,10 +37,10 @@ void CPDF_Color::ReleaseBuffer() {
PatternValue* pvalue = (PatternValue*)m_pBuffer;
CPDF_Pattern* pPattern =
pvalue->m_pCountedPattern ? pvalue->m_pCountedPattern->get() : nullptr;
- if (pPattern && pPattern->m_pDocument) {
- CPDF_DocPageData* pPageData = pPattern->m_pDocument->GetPageData();
+ if (pPattern && pPattern->document()) {
+ CPDF_DocPageData* pPageData = pPattern->document()->GetPageData();
if (pPageData)
- pPageData->ReleasePattern(pPattern->m_pPatternObj);
+ pPageData->ReleasePattern(pPattern->pattern_obj());
}
}
FX_Free(m_pBuffer);
@@ -92,10 +92,10 @@ void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) {
CPDF_DocPageData* pDocPageData = nullptr;
PatternValue* pvalue = (PatternValue*)m_pBuffer;
- if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) {
- pDocPageData = pvalue->m_pPattern->m_pDocument->GetPageData();
+ if (pvalue->m_pPattern && pvalue->m_pPattern->document()) {
+ pDocPageData = pvalue->m_pPattern->document()->GetPageData();
if (pDocPageData)
- pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj);
+ pDocPageData->ReleasePattern(pvalue->m_pPattern->pattern_obj());
}
pvalue->m_nComps = ncomps;
pvalue->m_pPattern = pPattern;
@@ -103,12 +103,12 @@ void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) {
FXSYS_memcpy(pvalue->m_Comps, comps, ncomps * sizeof(FX_FLOAT));
pvalue->m_pCountedPattern = nullptr;
- if (pPattern && pPattern->m_pDocument) {
+ if (pPattern && pPattern->document()) {
if (!pDocPageData)
- pDocPageData = pPattern->m_pDocument->GetPageData();
+ pDocPageData = pPattern->document()->GetPageData();
pvalue->m_pCountedPattern =
- pDocPageData->FindPatternPtr(pPattern->m_pPatternObj);
+ pDocPageData->FindPatternPtr(pPattern->pattern_obj());
}
}
@@ -127,14 +127,14 @@ void CPDF_Color::Copy(const CPDF_Color* pSrc) {
m_pBuffer = m_pCS->CreateBuf();
FXSYS_memcpy(m_pBuffer, pSrc->m_pBuffer, m_pCS->GetBufSize());
- if (m_pCS->GetFamily() == PDFCS_PATTERN) {
- PatternValue* pvalue = (PatternValue*)m_pBuffer;
- if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) {
- pvalue->m_pPattern =
- pvalue->m_pPattern->m_pDocument->GetPageData()->GetPattern(
- pvalue->m_pPattern->m_pPatternObj, FALSE,
- &pvalue->m_pPattern->m_ParentMatrix);
- }
+ if (m_pCS->GetFamily() != PDFCS_PATTERN)
+ return;
+
+ PatternValue* pValue = reinterpret_cast<PatternValue*>(m_pBuffer);
+ CPDF_Pattern* pPattern = pValue->m_pPattern;
+ if (pPattern && pPattern->document()) {
+ pValue->m_pPattern = pPattern->document()->GetPageData()->GetPattern(
+ pPattern->pattern_obj(), FALSE, pPattern->parent_matrix());
}
}
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
index 580b58a06a..88e9f561c3 100644
--- a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
@@ -49,10 +49,11 @@ void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern,
pData->m_FillColor.SetValue(pPattern, pValue, nValues);
int R, G, B;
FX_BOOL ret = pData->m_FillColor.GetRGB(R, G, B);
- if (pPattern->m_PatternType == 1 &&
- ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) {
- pData->m_FillRGB = 0x00BFBFBF;
- return;
+ if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) {
+ if (!ret && pTilingPattern->colored()) {
+ pData->m_FillRGB = 0x00BFBFBF;
+ return;
+ }
}
pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (uint32_t)-1;
}
@@ -64,10 +65,11 @@ void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern,
pData->m_StrokeColor.SetValue(pPattern, pValue, nValues);
int R, G, B;
FX_BOOL ret = pData->m_StrokeColor.GetRGB(R, G, B);
- if (pPattern->m_PatternType == 1 &&
- ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) {
- pData->m_StrokeRGB = 0x00BFBFBF;
- return;
+ if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) {
+ if (!ret && pTilingPattern->colored()) {
+ pData->m_StrokeRGB = 0x00BFBFBF;
+ return;
+ }
}
pData->m_StrokeRGB =
pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1;
diff --git a/core/fpdfapi/fpdf_page/cpdf_form.cpp b/core/fpdfapi/fpdf_page/cpdf_form.cpp
index 403baa2482..54698c60b6 100644
--- a/core/fpdfapi/fpdf_page/cpdf_form.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_form.cpp
@@ -36,23 +36,20 @@ CPDF_Form::~CPDF_Form() {}
void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates,
CFX_Matrix* pParentMatrix,
CPDF_Type3Char* pType3Char,
- CPDF_ParseOptions* pOptions,
int level) {
if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
return;
}
m_pParser.reset(new CPDF_ContentParser);
- m_pParser->Start(this, pGraphicStates, pParentMatrix, pType3Char, pOptions,
- level);
+ m_pParser->Start(this, pGraphicStates, pParentMatrix, pType3Char, level);
m_ParseState = CONTENT_PARSING;
}
void CPDF_Form::ParseContent(CPDF_AllStates* pGraphicStates,
CFX_Matrix* pParentMatrix,
CPDF_Type3Char* pType3Char,
- CPDF_ParseOptions* pOptions,
int level) {
- StartParse(pGraphicStates, pParentMatrix, pType3Char, pOptions, level);
+ StartParse(pGraphicStates, pParentMatrix, pType3Char, level);
ContinueParse(NULL);
}
diff --git a/core/fpdfapi/fpdf_page/cpdf_page.cpp b/core/fpdfapi/fpdf_page/cpdf_page.cpp
index dd298f382f..6b0609ff00 100644
--- a/core/fpdfapi/fpdf_page/cpdf_page.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_page.cpp
@@ -6,95 +6,59 @@
#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
+#include <set>
+
#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
-#include "core/fpdfapi/include/cpdf_modulemgr.h"
-#include "core/fpdfapi/ipdf_rendermodule.h"
-
-CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict,
- const CFX_ByteStringC& name) {
- int level = 0;
- while (1) {
- CPDF_Object* pObj = pPageDict->GetDirectObjectBy(name);
- if (pObj) {
- return pObj;
- }
- CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent");
- if (!pParent || pParent == pPageDict) {
- return NULL;
- }
- pPageDict = pParent;
- level++;
- if (level == 1000) {
- return NULL;
- }
- }
-}
+#include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h"
+#include "third_party/base/stl_util.h"
-CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {}
-
-CPDF_Page::~CPDF_Page() {
- if (m_pPageRender) {
- IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule();
- pModule->DestroyPageCache(m_pPageRender);
- }
-}
-
-void CPDF_Page::Load(CPDF_Document* pDocument,
+CPDF_Page::CPDF_Page(CPDF_Document* pDocument,
CPDF_Dictionary* pPageDict,
- FX_BOOL bPageCache) {
- m_pDocument = (CPDF_Document*)pDocument;
+ bool bPageCache)
+ : m_PageWidth(100),
+ m_PageHeight(100),
+ m_pPageRender(bPageCache ? new CPDF_PageRenderCache(this) : nullptr) {
m_pFormDict = pPageDict;
- if (bPageCache) {
- m_pPageRender =
- CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this);
- }
- if (!pPageDict) {
- m_PageWidth = m_PageHeight = 100 * 1.0f;
- m_pPageResources = m_pResources = NULL;
+ m_pDocument = pDocument;
+ if (!pPageDict)
return;
- }
+
CPDF_Object* pageAttr = GetPageAttr("Resources");
- m_pResources = pageAttr ? pageAttr->GetDict() : NULL;
+ m_pResources = pageAttr ? pageAttr->GetDict() : nullptr;
m_pPageResources = m_pResources;
CPDF_Object* pRotate = GetPageAttr("Rotate");
- int rotate = 0;
- if (pRotate) {
- rotate = pRotate->GetInteger() / 90 % 4;
- }
- if (rotate < 0) {
+ int rotate = pRotate ? pRotate->GetInteger() / 90 % 4 : 0;
+ if (rotate < 0)
rotate += 4;
- }
+
CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox"));
CFX_FloatRect mediabox;
if (pMediaBox) {
mediabox = pMediaBox->GetRect();
mediabox.Normalize();
}
- if (mediabox.IsEmpty()) {
+ if (mediabox.IsEmpty())
mediabox = CFX_FloatRect(0, 0, 612, 792);
- }
CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox"));
if (pCropBox) {
m_BBox = pCropBox->GetRect();
m_BBox.Normalize();
}
- if (m_BBox.IsEmpty()) {
+ if (m_BBox.IsEmpty())
m_BBox = mediabox;
- } else {
+ else
m_BBox.Intersect(mediabox);
- }
- if (rotate % 2) {
- m_PageHeight = m_BBox.right - m_BBox.left;
- m_PageWidth = m_BBox.top - m_BBox.bottom;
- } else {
- m_PageWidth = m_BBox.right - m_BBox.left;
- m_PageHeight = m_BBox.top - m_BBox.bottom;
- }
+
+ m_PageWidth = m_BBox.right - m_BBox.left;
+ m_PageHeight = m_BBox.top - m_BBox.bottom;
+ if (rotate % 2)
+ std::swap(m_PageWidth, m_PageHeight);
+
switch (rotate) {
case 0:
m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom);
@@ -109,26 +73,40 @@ void CPDF_Page::Load(CPDF_Document* pDocument,
m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left);
break;
}
+
m_Transparency = PDFTRANS_ISOLATED;
LoadTransInfo();
}
-void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) {
- if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
+CPDF_Page::~CPDF_Page() {}
+
+void CPDF_Page::StartParse() {
+ if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING)
return;
- }
+
m_pParser.reset(new CPDF_ContentParser);
- m_pParser->Start(this, pOptions);
+ m_pParser->Start(this);
m_ParseState = CONTENT_PARSING;
}
-void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) {
- StartParse(pOptions);
+void CPDF_Page::ParseContent() {
+ StartParse();
ContinueParse(nullptr);
}
-CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const {
- return FPDFAPI_GetPageAttr(m_pFormDict, name);
+CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteString& name) const {
+ CPDF_Dictionary* pPageDict = m_pFormDict;
+ std::set<CPDF_Dictionary*> visited;
+ while (1) {
+ visited.insert(pPageDict);
+ if (CPDF_Object* pObj = pPageDict->GetDirectObjectBy(name))
+ return pObj;
+
+ pPageDict = pPageDict->GetDictBy("Parent");
+ if (!pPageDict || pdfium::ContainsKey(visited, pPageDict))
+ break;
+ }
+ return nullptr;
}
void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix,
diff --git a/core/fpdfapi/fpdf_page/cpdf_parseoptions.cpp b/core/fpdfapi/fpdf_page/cpdf_parseoptions.cpp
deleted file mode 100644
index d22b6f13c9..0000000000
--- a/core/fpdfapi/fpdf_page/cpdf_parseoptions.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h"
-
-CPDF_ParseOptions::CPDF_ParseOptions()
- : m_bTextOnly(FALSE),
- m_bMarkedContent(TRUE),
- m_bSeparateForm(TRUE),
- m_bDecodeInlineImage(FALSE) {}
diff --git a/core/fpdfapi/fpdf_page/cpdf_parseoptions.h b/core/fpdfapi/fpdf_page/cpdf_parseoptions.h
deleted file mode 100644
index 3d091ab7cf..0000000000
--- a/core/fpdfapi/fpdf_page/cpdf_parseoptions.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_PARSEOPTIONS_H_
-#define CORE_FPDFAPI_FPDF_PAGE_CPDF_PARSEOPTIONS_H_
-
-#include "core/fxcrt/include/fx_system.h"
-
-class CPDF_ParseOptions {
- public:
- CPDF_ParseOptions();
-
- FX_BOOL m_bTextOnly;
- FX_BOOL m_bMarkedContent;
- FX_BOOL m_bSeparateForm;
- FX_BOOL m_bDecodeInlineImage;
-};
-
-#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_PARSEOPTIONS_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_pattern.cpp b/core/fpdfapi/fpdf_page/cpdf_pattern.cpp
index fc9d10e7ab..838f4af09b 100644
--- a/core/fpdfapi/fpdf_page/cpdf_pattern.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_pattern.cpp
@@ -10,10 +10,7 @@ CPDF_Pattern::CPDF_Pattern(PatternType type,
CPDF_Document* pDoc,
CPDF_Object* pObj,
const CFX_Matrix* pParentMatrix)
- : m_PatternType(type),
- m_pDocument(pDoc),
- m_pPatternObj(pObj),
- m_bForceClear(FALSE) {
+ : m_PatternType(type), m_pDocument(pDoc), m_pPatternObj(pObj) {
if (pParentMatrix)
m_ParentMatrix = *pParentMatrix;
}
diff --git a/core/fpdfapi/fpdf_page/cpdf_pattern.h b/core/fpdfapi/fpdf_page/cpdf_pattern.h
index 7f9a33bac9..d6ef49c7fb 100644
--- a/core/fpdfapi/fpdf_page/cpdf_pattern.h
+++ b/core/fpdfapi/fpdf_page/cpdf_pattern.h
@@ -12,6 +12,8 @@
class CPDF_Document;
class CPDF_Object;
+class CPDF_ShadingPattern;
+class CPDF_TilingPattern;
class CPDF_Pattern {
public:
@@ -19,13 +21,13 @@ class CPDF_Pattern {
virtual ~CPDF_Pattern();
- void SetForceClear(FX_BOOL bForceClear) { m_bForceClear = bForceClear; }
+ virtual CPDF_TilingPattern* AsTilingPattern() = 0;
+ virtual CPDF_ShadingPattern* AsShadingPattern() = 0;
- const PatternType m_PatternType;
- CPDF_Document* const m_pDocument;
- CPDF_Object* const m_pPatternObj;
- CFX_Matrix m_Pattern2Form;
- CFX_Matrix m_ParentMatrix;
+ CPDF_Document* document() { return m_pDocument; }
+ CPDF_Object* pattern_obj() { return m_pPatternObj; }
+ CFX_Matrix* pattern_to_form() { return &m_Pattern2Form; }
+ CFX_Matrix* parent_matrix() { return &m_ParentMatrix; }
protected:
CPDF_Pattern(PatternType type,
@@ -33,7 +35,11 @@ class CPDF_Pattern {
CPDF_Object* pObj,
const CFX_Matrix* pParentMatrix);
- FX_BOOL m_bForceClear;
+ const PatternType m_PatternType;
+ CPDF_Document* const m_pDocument;
+ CPDF_Object* const m_pPatternObj;
+ CFX_Matrix m_Pattern2Form;
+ CFX_Matrix m_ParentMatrix;
};
#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_PATTERN_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp b/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp
index 56dd6d4af4..0858132291 100644
--- a/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp
@@ -19,12 +19,12 @@ CPDF_ShadingObject* CPDF_ShadingObject::Clone() const {
obj->CopyData(this);
obj->m_pShading = m_pShading;
- if (obj->m_pShading && obj->m_pShading->m_pDocument) {
- CPDF_DocPageData* pDocPageData =
- obj->m_pShading->m_pDocument->GetPageData();
- obj->m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern(
+ if (obj->m_pShading && obj->m_pShading->document()) {
+ CPDF_DocPageData* pDocPageData = obj->m_pShading->document()->GetPageData();
+ CPDF_Pattern* pattern = pDocPageData->GetPattern(
obj->m_pShading->m_pShadingObj, m_pShading->m_bShadingObj,
- &obj->m_pShading->m_ParentMatrix);
+ obj->m_pShading->parent_matrix());
+ obj->m_pShading = pattern ? pattern->AsShadingPattern() : nullptr;
}
obj->m_Matrix = m_Matrix;
return obj;
diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h
index c9bbd07d2e..7e5a24d4fe 100644
--- a/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h
+++ b/core/fpdfapi/fpdf_page/cpdf_shadingpattern.h
@@ -12,7 +12,7 @@
#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fxcrt/include/fx_system.h"
-typedef enum {
+enum ShadingType {
kInvalidShading = 0,
kFunctionBasedShading = 1,
kAxialShading = 2,
@@ -22,7 +22,7 @@ typedef enum {
kCoonsPatchMeshShading = 6,
kTensorProductPatchMeshShading = 7,
kMaxShading = 8
-} ShadingType;
+};
class CFX_Matrix;
class CPDF_ColorSpace;
@@ -38,6 +38,9 @@ class CPDF_ShadingPattern : public CPDF_Pattern {
~CPDF_ShadingPattern() override;
+ CPDF_TilingPattern* AsTilingPattern() override { return nullptr; }
+ CPDF_ShadingPattern* AsShadingPattern() override { return this; }
+
bool IsMeshShading() const {
return m_ShadingType == kFreeFormGouraudTriangleMeshShading ||
m_ShadingType == kLatticeFormGouraudTriangleMeshShading ||
diff --git a/core/fpdfapi/fpdf_page/cpdf_tilingpattern.cpp b/core/fpdfapi/fpdf_page/cpdf_tilingpattern.cpp
index f49ad2b8fb..3ace57063c 100644
--- a/core/fpdfapi/fpdf_page/cpdf_tilingpattern.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_tilingpattern.cpp
@@ -20,12 +20,9 @@ CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc,
m_bColored = pDict->GetIntegerBy("PaintType") == 1;
if (parentMatrix)
m_Pattern2Form.Concat(*parentMatrix);
-
- m_pForm = nullptr;
}
CPDF_TilingPattern::~CPDF_TilingPattern() {
- delete m_pForm;
}
FX_BOOL CPDF_TilingPattern::Load() {
@@ -44,8 +41,8 @@ FX_BOOL CPDF_TilingPattern::Load() {
if (!pStream)
return FALSE;
- m_pForm = new CPDF_Form(m_pDocument, NULL, pStream);
- m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL);
+ m_pForm.reset(new CPDF_Form(m_pDocument, nullptr, pStream));
+ m_pForm->ParseContent(nullptr, &m_ParentMatrix, nullptr);
m_BBox = pDict->GetRectBy("BBox");
return TRUE;
}
diff --git a/core/fpdfapi/fpdf_page/cpdf_tilingpattern.h b/core/fpdfapi/fpdf_page/cpdf_tilingpattern.h
index 44446eac91..5936307271 100644
--- a/core/fpdfapi/fpdf_page/cpdf_tilingpattern.h
+++ b/core/fpdfapi/fpdf_page/cpdf_tilingpattern.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_TILINGPATTERN_H_
#define CORE_FPDFAPI_FPDF_PAGE_CPDF_TILINGPATTERN_H_
+#include <memory>
+
#include "core/fpdfapi/fpdf_page/cpdf_pattern.h"
#include "core/fxcrt/include/fx_coordinates.h"
#include "core/fxcrt/include/fx_system.h"
@@ -22,13 +24,23 @@ class CPDF_TilingPattern : public CPDF_Pattern {
const CFX_Matrix* parentMatrix);
~CPDF_TilingPattern() override;
+ CPDF_TilingPattern* AsTilingPattern() override { return this; }
+ CPDF_ShadingPattern* AsShadingPattern() override { return nullptr; }
+
FX_BOOL Load();
- FX_BOOL m_bColored;
+ bool colored() const { return m_bColored; }
+ const CFX_FloatRect& bbox() const { return m_BBox; }
+ FX_FLOAT x_step() const { return m_XStep; }
+ FX_FLOAT y_step() const { return m_YStep; }
+ CPDF_Form* form() const { return m_pForm.get(); }
+
+ private:
+ bool m_bColored;
CFX_FloatRect m_BBox;
FX_FLOAT m_XStep;
FX_FLOAT m_YStep;
- CPDF_Form* m_pForm;
+ std::unique_ptr<CPDF_Form> m_pForm;
};
#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_TILINGPATTERN_H_
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index b9019f8577..aed6e1e05c 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -150,10 +150,8 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) {
if (!ptData->get())
continue;
- if (bForceRelease || ptData->use_count() < 2) {
- ptData->get()->SetForceClear(bForceRelease);
+ if (bForceRelease || ptData->use_count() < 2)
ptData->clear();
- }
}
for (auto& it : m_FontMap) {
@@ -436,9 +434,9 @@ CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj,
CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : nullptr;
if (pDict) {
int type = pDict->GetIntegerBy("PatternType");
- if (type == 1) {
+ if (type == CPDF_Pattern::TILING) {
pPattern = new CPDF_TilingPattern(m_pPDFDoc, pPatternObj, matrix);
- } else if (type == 2) {
+ } else if (type == CPDF_Pattern::SHADING) {
pPattern =
new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, FALSE, matrix);
}
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index d2889d89b1..1f10b4ea4e 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -128,7 +128,6 @@ CPDF_StreamContentParser::CPDF_StreamContentParser(
CPDF_PageObjectHolder* pObjHolder,
CPDF_Dictionary* pResources,
CFX_FloatRect* pBBox,
- CPDF_ParseOptions* pOptions,
CPDF_AllStates* pStates,
int level)
: m_pDocument(pDocument),
@@ -154,21 +153,14 @@ CPDF_StreamContentParser::CPDF_StreamContentParser(
m_bReleaseLastDict(TRUE),
m_bColored(FALSE),
m_bResourceMissing(FALSE) {
- if (pmtContentToUser) {
+ if (pmtContentToUser)
m_mtContentToUser = *pmtContentToUser;
- }
- if (pOptions) {
- m_Options = *pOptions;
- }
- if (!m_pResources) {
+ if (!m_pResources)
m_pResources = m_pParentResources;
- }
- if (!m_pResources) {
+ if (!m_pResources)
m_pResources = m_pPageResources;
- }
- if (pBBox) {
+ if (pBBox)
m_BBox = *pBBox;
- }
if (pStates) {
m_pCurStates->Copy(*pStates);
} else {
@@ -492,39 +484,24 @@ void CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) {
}
void CPDF_StreamContentParser::Handle_CloseFillStrokePath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
Handle_ClosePath();
AddPathObject(FXFILL_WINDING, TRUE);
}
void CPDF_StreamContentParser::Handle_FillStrokePath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathObject(FXFILL_WINDING, TRUE);
}
void CPDF_StreamContentParser::Handle_CloseEOFillStrokePath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);
AddPathObject(FXFILL_ALTERNATE, TRUE);
}
void CPDF_StreamContentParser::Handle_EOFillStrokePath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathObject(FXFILL_ALTERNATE, TRUE);
}
void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() {
- if (!m_Options.m_bMarkedContent) {
- return;
- }
CFX_ByteString tag = GetString(1);
CPDF_Object* pProperty = GetObject(0);
if (!pProperty) {
@@ -586,8 +563,8 @@ void CPDF_StreamContentParser::Handle_BeginImage() {
}
}
}
- CPDF_Stream* pStream = m_pSyntax->ReadInlineStream(
- m_pDocument, pDict, pCSObj, m_Options.m_bDecodeInlineImage);
+ CPDF_Stream* pStream =
+ m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj);
while (1) {
CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement();
if (type == CPDF_StreamParser::EndOfData) {
@@ -601,14 +578,6 @@ void CPDF_StreamContentParser::Handle_BeginImage() {
break;
}
}
- if (m_Options.m_bTextOnly) {
- if (pStream) {
- pStream->Release();
- } else {
- pDict->Release();
- }
- return;
- }
pDict->SetAtName("Subtype", "Image");
CPDF_ImageObject* pImgObj = AddImage(pStream, NULL, TRUE);
if (!pImgObj) {
@@ -621,9 +590,6 @@ void CPDF_StreamContentParser::Handle_BeginImage() {
}
void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
- if (!m_Options.m_bMarkedContent) {
- return;
- }
CFX_ByteString tag = GetString(0);
m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE);
}
@@ -638,9 +604,6 @@ void CPDF_StreamContentParser::Handle_BeginText() {
}
void CPDF_StreamContentParser::Handle_CurveTo_123() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathPoint(GetNumber(5), GetNumber(4), FXPT_BEZIERTO);
AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
@@ -657,9 +620,6 @@ void CPDF_StreamContentParser::Handle_ConcatMatrix() {
}
void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() {
- if (m_Options.m_bTextOnly) {
- return;
- }
CFX_ByteString csname = GetString(0);
CPDF_ColorSpace* pCS = FindColorSpace(csname);
if (!pCS) {
@@ -669,9 +629,6 @@ void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() {
}
void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() {
- if (m_Options.m_bTextOnly) {
- return;
- }
CFX_ByteString csname = GetString(0);
CPDF_ColorSpace* pCS = FindColorSpace(csname);
if (!pCS) {
@@ -681,13 +638,10 @@ void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() {
}
void CPDF_StreamContentParser::Handle_SetDash() {
- if (m_Options.m_bTextOnly) {
+ CPDF_Array* pArray = GetObject(1) ? GetObject(1)->GetArray() : nullptr;
+ if (!pArray)
return;
- }
- CPDF_Array* pArray = GetObject(1) ? GetObject(1)->GetArray() : NULL;
- if (!pArray) {
- return;
- }
+
m_pCurStates->SetLineDash(pArray, GetNumber(0), 1.0f);
}
@@ -712,24 +666,6 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() {
return;
}
- if (m_Options.m_bTextOnly) {
- if (!m_pResources)
- return;
-
- CPDF_Dictionary* pList = m_pResources->GetDictBy("XObject");
- if (!pList && m_pPageResources && m_pResources != m_pPageResources)
- pList = m_pPageResources->GetDictBy("XObject");
- if (!pList)
- return;
- CPDF_Reference* pRes = ToReference(pList->GetObjectBy(name));
- if (!pRes)
- return;
-
- FX_BOOL bForm;
- if (m_pDocument->IsFormStream(pRes->GetRefObjNum(), bForm) && !bForm)
- return;
- }
-
CPDF_Stream* pXObject = ToStream(FindResourceObj("XObject", name));
if (!pXObject) {
m_bResourceMissing = TRUE;
@@ -741,9 +677,6 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() {
type = pXObject->GetDict()->GetStringBy("Subtype");
if (type == "Image") {
- if (m_Options.m_bTextOnly) {
- return;
- }
CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE);
m_LastImageName = name;
m_pLastImage = pObj->m_pImage;
@@ -751,44 +684,10 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() {
m_pObjectHolder->SetHasImageMask(m_pLastImage->IsMask());
} else if (type == "Form") {
AddForm(pXObject);
- } else {
- return;
}
}
void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
- if (!m_Options.m_bSeparateForm) {
- CPDF_Dictionary* pResources = pStream->GetDict()->GetDictBy("Resources");
- CFX_Matrix form_matrix = pStream->GetDict()->GetMatrixBy("Matrix");
- form_matrix.Concat(m_pCurStates->m_CTM);
- CPDF_Array* pBBox = pStream->GetDict()->GetArrayBy("BBox");
- CFX_FloatRect form_bbox;
- CPDF_Path ClipPath;
- if (pBBox) {
- form_bbox = pStream->GetDict()->GetRectBy("BBox");
- ClipPath.New();
- ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right,
- form_bbox.top);
- ClipPath.Transform(&form_matrix);
- form_bbox.Transform(&form_matrix);
- }
- CPDF_StreamContentParser parser(m_pDocument, m_pPageResources, m_pResources,
- &m_mtContentToUser, m_pObjectHolder,
- pResources, &form_bbox, &m_Options,
- m_pCurStates.get(), m_Level + 1);
- parser.m_pCurStates->m_CTM = form_matrix;
- if (ClipPath.NotNull()) {
- parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING,
- TRUE);
- }
- CPDF_StreamAcc stream;
- stream.LoadAllData(pStream, FALSE);
- if (stream.GetSize() == 0) {
- return;
- }
- parser.Parse(stream.GetData(), stream.GetSize(), 0);
- return;
- }
std::unique_ptr<CPDF_FormObject> pFormObj(new CPDF_FormObject);
pFormObj->m_pForm =
new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources);
@@ -799,7 +698,7 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
status.m_GraphState = m_pCurStates->m_GraphState;
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);
+ pFormObj->m_pForm->ParseContent(&status, nullptr, nullptr, m_Level + 1);
if (!m_pObjectHolder->BackgroundAlphaNeeded() &&
pFormObj->m_pForm->BackgroundAlphaNeeded()) {
m_pObjectHolder->SetBackgroundAlphaNeeded(TRUE);
@@ -843,12 +742,9 @@ void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {}
void CPDF_StreamContentParser::Handle_EndImage() {}
void CPDF_StreamContentParser::Handle_EndMarkedContent() {
- if (!m_Options.m_bMarkedContent) {
+ if (m_CurContentMark.IsNull())
return;
- }
- if (m_CurContentMark.IsNull()) {
- return;
- }
+
int count = m_CurContentMark.GetObject()->CountItems();
if (count == 1) {
m_CurContentMark.SetNull();
@@ -873,23 +769,14 @@ void CPDF_StreamContentParser::Handle_EndText() {
}
void CPDF_StreamContentParser::Handle_FillPath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathObject(FXFILL_WINDING, FALSE);
}
void CPDF_StreamContentParser::Handle_FillPathOld() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathObject(FXFILL_WINDING, FALSE);
}
void CPDF_StreamContentParser::Handle_EOFillPath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathObject(FXFILL_ALTERNATE, FALSE);
}
@@ -916,9 +803,6 @@ void CPDF_StreamContentParser::Handle_SetExtendGraphState() {
}
void CPDF_StreamContentParser::Handle_ClosePath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
if (m_PathPointCount == 0) {
return;
}
@@ -973,9 +857,6 @@ void CPDF_StreamContentParser::Handle_LineTo() {
if (m_ParamCount != 2)
return;
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathPoint(GetNumber(1), GetNumber(0), FXPT_LINETO);
}
@@ -983,10 +864,6 @@ void CPDF_StreamContentParser::Handle_MoveTo() {
if (m_ParamCount != 2)
return;
- if (m_Options.m_bTextOnly) {
- m_pSyntax->SkipPathObject();
- return;
- }
AddPathPoint(GetNumber(1), GetNumber(0), FXPT_MOVETO);
ParsePathObject();
}
@@ -998,9 +875,6 @@ void CPDF_StreamContentParser::Handle_SetMiterLimit() {
void CPDF_StreamContentParser::Handle_MarkPlace() {}
void CPDF_StreamContentParser::Handle_EndPath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathObject(0, FALSE);
}
@@ -1019,9 +893,6 @@ void CPDF_StreamContentParser::Handle_RestoreGraphState() {
}
void CPDF_StreamContentParser::Handle_Rectangle() {
- if (m_Options.m_bTextOnly) {
- return;
- }
FX_FLOAT x = GetNumber(3), y = GetNumber(2);
FX_FLOAT w = GetNumber(1), h = GetNumber(0);
AddPathRect(x, y, w, h);
@@ -1065,24 +936,15 @@ void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke() {
void CPDF_StreamContentParser::Handle_SetRenderIntent() {}
void CPDF_StreamContentParser::Handle_CloseStrokePath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
Handle_ClosePath();
AddPathObject(0, TRUE);
}
void CPDF_StreamContentParser::Handle_StrokePath() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathObject(0, TRUE);
}
void CPDF_StreamContentParser::Handle_SetColor_Fill() {
- if (m_Options.m_bTextOnly) {
- return;
- }
FX_FLOAT values[4];
int nargs = m_ParamCount;
if (nargs > 4) {
@@ -1095,9 +957,6 @@ void CPDF_StreamContentParser::Handle_SetColor_Fill() {
}
void CPDF_StreamContentParser::Handle_SetColor_Stroke() {
- if (m_Options.m_bTextOnly) {
- return;
- }
FX_FLOAT values[4];
int nargs = m_ParamCount;
if (nargs > 4) {
@@ -1110,9 +969,6 @@ void CPDF_StreamContentParser::Handle_SetColor_Stroke() {
}
void CPDF_StreamContentParser::Handle_SetColorPS_Fill() {
- if (m_Options.m_bTextOnly) {
- return;
- }
CPDF_Object* pLastParam = GetObject(0);
if (!pLastParam) {
return;
@@ -1140,9 +996,6 @@ void CPDF_StreamContentParser::Handle_SetColorPS_Fill() {
}
void CPDF_StreamContentParser::Handle_SetColorPS_Stroke() {
- if (m_Options.m_bTextOnly) {
- return;
- }
CPDF_Object* pLastParam = GetObject(0);
if (!pLastParam) {
return;
@@ -1178,34 +1031,24 @@ CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream,
CPDF_ColorSpace* pCS);
void CPDF_StreamContentParser::Handle_ShadeFill() {
- if (m_Options.m_bTextOnly) {
- return;
- }
CPDF_Pattern* pPattern = FindPattern(GetString(0), TRUE);
- if (!pPattern) {
- return;
- }
- if (pPattern->m_PatternType != CPDF_Pattern::SHADING) {
+ if (!pPattern)
return;
- }
- CPDF_ShadingPattern* pShading = static_cast<CPDF_ShadingPattern*>(pPattern);
- if (!pShading->m_bShadingObj) {
+
+ CPDF_ShadingPattern* pShading = pPattern->AsShadingPattern();
+ if (!pShading)
return;
- }
- if (!pShading->Load()) {
+
+ if (!pShading->m_bShadingObj || !pShading->Load())
return;
- }
+
std::unique_ptr<CPDF_ShadingObject> pObj(new CPDF_ShadingObject);
pObj->m_pShading = pShading;
SetGraphicStates(pObj.get(), FALSE, FALSE, FALSE);
pObj->m_Matrix = m_pCurStates->m_CTM;
pObj->m_Matrix.Concat(m_mtContentToUser);
- CFX_FloatRect bbox;
- if (!pObj->m_ClipPath.IsNull()) {
- bbox = pObj->m_ClipPath.GetClipBox();
- } else {
- bbox = m_BBox;
- }
+ CFX_FloatRect bbox =
+ pObj->m_ClipPath.IsNull() ? m_BBox : pObj->m_ClipPath.GetClipBox();
if (pShading->IsMeshShading()) {
bbox.Intersect(GetShadingBBox(ToStream(pShading->m_pShadingObj),
pShading->m_ShadingType, &pObj->m_Matrix,
@@ -1518,9 +1361,6 @@ void CPDF_StreamContentParser::Handle_MoveToNextLine() {
}
void CPDF_StreamContentParser::Handle_CurveTo_23() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathPoint(m_PathCurrentX, m_PathCurrentY, FXPT_BEZIERTO);
AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
@@ -1540,9 +1380,6 @@ void CPDF_StreamContentParser::Handle_EOClip() {
}
void CPDF_StreamContentParser::Handle_CurveTo_13() {
- if (m_Options.m_bTextOnly) {
- return;
- }
AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index cf29aa2684..dff4bb6182 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -124,8 +124,7 @@ uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf,
CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc,
CPDF_Dictionary* pDict,
- CPDF_Object* pCSObj,
- FX_BOOL bDecode) {
+ CPDF_Object* pCSObj) {
if (m_Pos == m_Size)
return nullptr;
@@ -199,48 +198,33 @@ CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc,
dwStreamSize =
PDF_DecodeInlineStream(m_pBuf + m_Pos, m_Size - m_Pos, width, height,
Decoder, pParam, pData, dwDestSize);
- if ((int)dwStreamSize < 0) {
- FX_Free(pData);
+ FX_Free(pData);
+ if ((int)dwStreamSize < 0)
return NULL;
- }
- if (bDecode) {
- m_Pos += dwStreamSize;
- dwStreamSize = dwDestSize;
- if (CPDF_Array* pArray = pFilter->AsArray()) {
- pArray->RemoveAt(0);
- CPDF_Array* pParams = pDict->GetArrayBy("DecodeParms");
- if (pParams)
- pParams->RemoveAt(0);
- } else {
- pDict->RemoveAt("Filter");
- pDict->RemoveAt("DecodeParms");
- }
- } else {
- FX_Free(pData);
- uint32_t dwSavePos = m_Pos;
- m_Pos += dwStreamSize;
- while (1) {
- uint32_t dwPrevPos = m_Pos;
- CPDF_StreamParser::SyntaxType type = ParseNextElement();
- if (type == CPDF_StreamParser::EndOfData) {
- break;
- }
- if (type != CPDF_StreamParser::Keyword) {
- dwStreamSize += m_Pos - dwPrevPos;
- continue;
- }
- if (GetWordSize() == 2 && GetWordBuf()[0] == 'E' &&
- GetWordBuf()[1] == 'I') {
- m_Pos = dwPrevPos;
- break;
- }
+
+ uint32_t dwSavePos = m_Pos;
+ m_Pos += dwStreamSize;
+ while (1) {
+ uint32_t dwPrevPos = m_Pos;
+ CPDF_StreamParser::SyntaxType type = ParseNextElement();
+ if (type == CPDF_StreamParser::EndOfData)
+ break;
+
+ if (type != CPDF_StreamParser::Keyword) {
dwStreamSize += m_Pos - dwPrevPos;
+ continue;
+ }
+ if (GetWordSize() == 2 && GetWordBuf()[0] == 'E' &&
+ GetWordBuf()[1] == 'I') {
+ m_Pos = dwPrevPos;
+ break;
}
- m_Pos = dwSavePos;
- pData = FX_Alloc(uint8_t, dwStreamSize);
- FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize);
- m_Pos += dwStreamSize;
+ dwStreamSize += m_Pos - dwPrevPos;
}
+ m_Pos = dwSavePos;
+ pData = FX_Alloc(uint8_t, dwStreamSize);
+ FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize);
+ m_Pos += dwStreamSize;
}
pDict->SetAtInteger("Length", (int)dwStreamSize);
return new CPDF_Stream(pData, dwStreamSize, pDict);
@@ -331,57 +315,6 @@ CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() {
return Keyword;
}
-void CPDF_StreamParser::SkipPathObject() {
- uint32_t command_startpos = m_Pos;
- if (!PositionIsInBounds())
- return;
-
- int ch = m_pBuf[m_Pos++];
- while (1) {
- while (PDFCharIsWhitespace(ch)) {
- if (!PositionIsInBounds())
- return;
- ch = m_pBuf[m_Pos++];
- }
-
- if (!PDFCharIsNumeric(ch)) {
- m_Pos = command_startpos;
- return;
- }
-
- while (1) {
- while (!PDFCharIsWhitespace(ch)) {
- if (!PositionIsInBounds())
- return;
- ch = m_pBuf[m_Pos++];
- }
-
- while (PDFCharIsWhitespace(ch)) {
- if (!PositionIsInBounds())
- return;
- ch = m_pBuf[m_Pos++];
- }
-
- if (PDFCharIsNumeric(ch))
- continue;
-
- uint32_t op_startpos = m_Pos - 1;
- while (!PDFCharIsWhitespace(ch) && !PDFCharIsDelimiter(ch)) {
- if (!PositionIsInBounds())
- return;
- ch = m_pBuf[m_Pos++];
- }
-
- if (IsPathOperator(&m_pBuf[op_startpos], m_Pos - 1 - op_startpos)) {
- command_startpos = m_Pos;
- break;
- }
- m_Pos = command_startpos;
- return;
- }
- }
-}
-
CPDF_Object* CPDF_StreamParser::ReadNextObject(FX_BOOL bAllowNestedArray,
FX_BOOL bInArray) {
FX_BOOL bIsNumber;
@@ -697,7 +630,7 @@ CPDF_ContentParser::~CPDF_ContentParser() {
FX_Free(m_pData);
}
-void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) {
+void CPDF_ContentParser::Start(CPDF_Page* pPage) {
if (m_Status != Ready || !pPage || !pPage->m_pDocument ||
!pPage->m_pFormDict) {
m_Status = Done;
@@ -705,9 +638,6 @@ void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) {
}
m_pObjectHolder = pPage;
m_bForm = FALSE;
- if (pOptions) {
- m_Options = *pOptions;
- }
m_Status = ToBeContinued;
m_InternalStage = STAGE_GETCONTENT;
m_CurrentOffset = 0;
@@ -736,7 +666,6 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm,
CPDF_AllStates* pGraphicStates,
CFX_Matrix* pParentMatrix,
CPDF_Type3Char* pType3Char,
- CPDF_ParseOptions* pOptions,
int level) {
m_pType3Char = pType3Char;
m_pObjectHolder = pForm;
@@ -765,8 +694,7 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm,
CPDF_Dictionary* pResources = pForm->m_pFormDict->GetDictBy("Resources");
m_pParser.reset(new CPDF_StreamContentParser(
pForm->m_pDocument, pForm->m_pPageResources, pForm->m_pResources,
- pParentMatrix, pForm, pResources, &form_bbox, pOptions, pGraphicStates,
- level));
+ pParentMatrix, pForm, pResources, &form_bbox, pGraphicStates, level));
m_pParser->GetCurStates()->m_CTM = form_matrix;
m_pParser->GetCurStates()->m_ParentMatrix = form_matrix;
if (ClipPath.NotNull()) {
@@ -836,7 +764,7 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) {
m_pParser.reset(new CPDF_StreamContentParser(
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_pObjectHolder->m_BBox, nullptr, 0));
m_pParser->GetCurStates()->m_ColorState.GetModify()->Default();
}
if (m_CurrentOffset >= m_Size) {
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_form.h b/core/fpdfapi/fpdf_page/include/cpdf_form.h
index 3b9f1cc7fb..542ab498a6 100644
--- a/core/fpdfapi/fpdf_page/include/cpdf_form.h
+++ b/core/fpdfapi/fpdf_page/include/cpdf_form.h
@@ -15,7 +15,6 @@ class CPDF_Stream;
class CPDF_AllStates;
class CFX_Matrix;
class CPDF_Type3Char;
-class CPDF_ParseOptions;
class CPDF_Form : public CPDF_PageObjectHolder {
public:
@@ -29,13 +28,11 @@ class CPDF_Form : public CPDF_PageObjectHolder {
void StartParse(CPDF_AllStates* pGraphicStates,
CFX_Matrix* pParentMatrix,
CPDF_Type3Char* pType3Char,
- CPDF_ParseOptions* pOptions,
int level = 0);
void ParseContent(CPDF_AllStates* pGraphicStates,
CFX_Matrix* pParentMatrix,
CPDF_Type3Char* pType3Char,
- CPDF_ParseOptions* pOptions,
int level = 0);
CPDF_Form* Clone() const;
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_page.h b/core/fpdfapi/fpdf_page/include/cpdf_page.h
index 3ede3c9404..7f4430187a 100644
--- a/core/fpdfapi/fpdf_page/include/cpdf_page.h
+++ b/core/fpdfapi/fpdf_page/include/cpdf_page.h
@@ -7,30 +7,26 @@
#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PAGE_H_
#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PAGE_H_
+#include <memory>
+
#include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h"
#include "core/fxcrt/include/fx_basic.h"
#include "core/fxcrt/include/fx_coordinates.h"
#include "core/fxcrt/include/fx_system.h"
-class CPDF_Document;
class CPDF_Dictionary;
+class CPDF_Document;
class CPDF_Object;
class CPDF_PageRenderCache;
-class CPDF_ParseOptions;
-
-CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict,
- const CFX_ByteStringC& name);
class CPDF_Page : public CPDF_PageObjectHolder, public CFX_PrivateData {
public:
- CPDF_Page();
- ~CPDF_Page();
-
- void Load(CPDF_Document* pDocument,
+ CPDF_Page(CPDF_Document* pDocument,
CPDF_Dictionary* pPageDict,
- FX_BOOL bPageCache = TRUE);
+ bool bPageCache);
+ ~CPDF_Page();
- void ParseContent(CPDF_ParseOptions* pOptions);
+ void ParseContent();
void GetDisplayMatrix(CFX_Matrix& matrix,
int xPos,
@@ -43,18 +39,18 @@ class CPDF_Page : public CPDF_PageObjectHolder, public CFX_PrivateData {
FX_FLOAT GetPageHeight() const { return m_PageHeight; }
CFX_FloatRect GetPageBBox() const { return m_BBox; }
const CFX_Matrix& GetPageMatrix() const { return m_PageMatrix; }
- CPDF_Object* GetPageAttr(const CFX_ByteStringC& name) const;
- CPDF_PageRenderCache* GetRenderCache() const { return m_pPageRender; }
+ CPDF_Object* GetPageAttr(const CFX_ByteString& name) const;
+ CPDF_PageRenderCache* GetRenderCache() const { return m_pPageRender.get(); }
protected:
friend class CPDF_ContentParser;
- void StartParse(CPDF_ParseOptions* pOptions);
+ void StartParse();
FX_FLOAT m_PageWidth;
FX_FLOAT m_PageHeight;
CFX_Matrix m_PageMatrix;
- CPDF_PageRenderCache* m_pPageRender;
+ std::unique_ptr<CPDF_PageRenderCache> m_pPageRender;
};
#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PAGE_H_
diff --git a/core/fpdfapi/fpdf_page/pageint.h b/core/fpdfapi/fpdf_page/pageint.h
index 98a05d5495..24ed226aa0 100644
--- a/core/fpdfapi/fpdf_page/pageint.h
+++ b/core/fpdfapi/fpdf_page/pageint.h
@@ -14,7 +14,6 @@
#include "core/fpdfapi/fpdf_page/cpdf_contentmark.h"
#include "core/fpdfapi/fpdf_page/cpdf_countedobject.h"
-#include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h"
#include "core/fxge/include/fx_ge.h"
@@ -27,7 +26,6 @@ class CPDF_IccProfile;
class CPDF_Image;
class CPDF_ImageObject;
class CPDF_Page;
-class CPDF_ParseOptions;
class CPDF_Pattern;
class CPDF_StreamAcc;
class CPDF_TextObject;
@@ -44,8 +42,7 @@ class CPDF_StreamParser {
CPDF_Stream* ReadInlineStream(CPDF_Document* pDoc,
CPDF_Dictionary* pDict,
- CPDF_Object* pCSObj,
- FX_BOOL bDecode);
+ CPDF_Object* pCSObj);
SyntaxType ParseNextElement();
uint8_t* GetWordBuf() { return m_WordBuffer; }
uint32_t GetWordSize() const { return m_WordSize; }
@@ -58,7 +55,6 @@ class CPDF_StreamParser {
void SetPos(uint32_t pos) { m_Pos = pos; }
CPDF_Object* ReadNextObject(FX_BOOL bAllowNestedArray = FALSE,
FX_BOOL bInArray = FALSE);
- void SkipPathObject();
protected:
friend class fpdf_page_parser_old_ReadHexString_Test;
@@ -113,7 +109,6 @@ class CPDF_StreamContentParser {
CPDF_PageObjectHolder* pObjectHolder,
CPDF_Dictionary* pResources,
CFX_FloatRect* pBBox,
- CPDF_ParseOptions* pOptions,
CPDF_AllStates* pAllStates,
int level);
~CPDF_StreamContentParser();
@@ -252,7 +247,6 @@ class CPDF_StreamContentParser {
int m_Level;
CFX_Matrix m_mtContentToUser;
CFX_FloatRect m_BBox;
- CPDF_ParseOptions m_Options;
ContentParam m_ParamBuf[PARAM_BUF_SIZE];
uint32_t m_ParamStartPos;
uint32_t m_ParamCount;
@@ -291,12 +285,11 @@ class CPDF_ContentParser {
~CPDF_ContentParser();
ParseStatus GetStatus() const { return m_Status; }
- void Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions);
+ void Start(CPDF_Page* pPage);
void Start(CPDF_Form* pForm,
CPDF_AllStates* pGraphicStates,
CFX_Matrix* pParentMatrix,
CPDF_Type3Char* pType3Char,
- CPDF_ParseOptions* pOptions,
int level);
void Continue(IFX_Pause* pPause);
@@ -311,7 +304,6 @@ class CPDF_ContentParser {
InternalStage m_InternalStage;
CPDF_PageObjectHolder* m_pObjectHolder;
FX_BOOL m_bForm;
- CPDF_ParseOptions m_Options;
CPDF_Type3Char* m_pType3Char;
uint32_t m_nStreams;
std::unique_ptr<CPDF_StreamAcc> m_pSingleStream;