summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/page/cpdf_form.cpp3
-rw-r--r--core/fpdfapi/page/cpdf_formobject.cpp6
-rw-r--r--core/fpdfapi/page/cpdf_formobject.h6
-rw-r--r--core/fpdfapi/page/cpdf_pageobjectholder.cpp5
-rw-r--r--core/fpdfapi/page/cpdf_pageobjectholder.h2
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp17
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp42
7 files changed, 44 insertions, 37 deletions
diff --git a/core/fpdfapi/page/cpdf_form.cpp b/core/fpdfapi/page/cpdf_form.cpp
index e4334016b4..ae06cb2f7e 100644
--- a/core/fpdfapi/page/cpdf_form.cpp
+++ b/core/fpdfapi/page/cpdf_form.cpp
@@ -17,8 +17,7 @@ CPDF_Form::CPDF_Form(CPDF_Document* pDoc,
CPDF_Dictionary* pPageResources,
CPDF_Stream* pFormStream,
CPDF_Dictionary* pParentResources)
- : CPDF_PageObjectHolder(pDoc,
- pFormStream ? pFormStream->GetDict() : nullptr) {
+ : CPDF_PageObjectHolder(pDoc, pFormStream->GetDict()) {
m_pFormStream = pFormStream;
m_pResources = m_pFormDict->GetDictFor("Resources");
m_pPageResources = pPageResources;
diff --git a/core/fpdfapi/page/cpdf_formobject.cpp b/core/fpdfapi/page/cpdf_formobject.cpp
index c0cdd3e950..eca92ca0ff 100644
--- a/core/fpdfapi/page/cpdf_formobject.cpp
+++ b/core/fpdfapi/page/cpdf_formobject.cpp
@@ -6,9 +6,13 @@
#include "core/fpdfapi/page/cpdf_formobject.h"
+#include <utility>
+
#include "core/fpdfapi/page/cpdf_form.h"
-CPDF_FormObject::CPDF_FormObject() {}
+CPDF_FormObject::CPDF_FormObject(std::unique_ptr<CPDF_Form> pForm,
+ const CFX_Matrix& matrix)
+ : m_pForm(std::move(pForm)), m_FormMatrix(matrix) {}
CPDF_FormObject::~CPDF_FormObject() {}
diff --git a/core/fpdfapi/page/cpdf_formobject.h b/core/fpdfapi/page/cpdf_formobject.h
index b13cb5fbe4..c723cc0eaf 100644
--- a/core/fpdfapi/page/cpdf_formobject.h
+++ b/core/fpdfapi/page/cpdf_formobject.h
@@ -16,7 +16,7 @@ class CPDF_Form;
class CPDF_FormObject : public CPDF_PageObject {
public:
- CPDF_FormObject();
+ CPDF_FormObject(std::unique_ptr<CPDF_Form> pForm, const CFX_Matrix& matrix);
~CPDF_FormObject() override;
// CPDF_PageObject:
@@ -28,8 +28,10 @@ class CPDF_FormObject : public CPDF_PageObject {
void CalcBoundingBox();
const CPDF_Form* form() const { return m_pForm.get(); }
+ const CFX_Matrix& form_matrix() const { return m_FormMatrix; }
- std::unique_ptr<CPDF_Form> m_pForm;
+ private:
+ const std::unique_ptr<CPDF_Form> m_pForm;
CFX_Matrix m_FormMatrix;
};
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
index 5de911513f..4e9da63dea 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder.cpp
+++ b/core/fpdfapi/page/cpdf_pageobjectholder.cpp
@@ -22,7 +22,10 @@ CPDF_PageObjectHolder::CPDF_PageObjectHolder(CPDF_Document* pDoc,
m_pResources(nullptr),
m_iTransparency(0),
m_bBackgroundAlphaNeeded(false),
- m_ParseState(CONTENT_NOT_PARSED) {}
+ m_ParseState(CONTENT_NOT_PARSED) {
+ // TODO(thestig): Check if |m_pFormDict| is never a nullptr and simplify
+ // callers that checks for that.
+}
CPDF_PageObjectHolder::~CPDF_PageObjectHolder() {}
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.h b/core/fpdfapi/page/cpdf_pageobjectholder.h
index 1a8b1aae38..f649ef7b62 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder.h
+++ b/core/fpdfapi/page/cpdf_pageobjectholder.h
@@ -71,7 +71,7 @@ class CPDF_PageObjectHolder {
void Transform(const CFX_Matrix& matrix);
CFX_FloatRect CalcBoundingBox() const;
- UnownedPtr<CPDF_Dictionary> m_pFormDict;
+ const UnownedPtr<CPDF_Dictionary> m_pFormDict;
UnownedPtr<CPDF_Stream> m_pFormStream;
UnownedPtr<CPDF_Document> m_pDocument;
UnownedPtr<CPDF_Dictionary> m_pPageResources;
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 4ba1d2a44e..9e9c450c7d 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -767,20 +767,21 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() {
}
void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
- auto pFormObj = pdfium::MakeUnique<CPDF_FormObject>();
- pFormObj->m_pForm = pdfium::MakeUnique<CPDF_Form>(
- m_pDocument.Get(), m_pPageResources.Get(), pStream, m_pResources.Get());
- pFormObj->m_FormMatrix = m_pCurStates->m_CTM;
- pFormObj->m_FormMatrix.Concat(m_mtContentToUser);
CPDF_AllStates status;
status.m_GeneralState = m_pCurStates->m_GeneralState;
status.m_GraphState = m_pCurStates->m_GraphState;
status.m_ColorState = m_pCurStates->m_ColorState;
status.m_TextState = m_pCurStates->m_TextState;
- pFormObj->m_pForm->ParseContentWithParams(&status, nullptr, nullptr,
- m_ParsedSet.Get());
+ auto form = pdfium::MakeUnique<CPDF_Form>(
+ m_pDocument.Get(), m_pPageResources.Get(), pStream, m_pResources.Get());
+ form->ParseContentWithParams(&status, nullptr, nullptr, m_ParsedSet.Get());
+
+ CFX_Matrix matrix = m_pCurStates->m_CTM;
+ matrix.Concat(m_mtContentToUser);
+
+ auto pFormObj = pdfium::MakeUnique<CPDF_FormObject>(std::move(form), matrix);
if (!m_pObjectHolder->BackgroundAlphaNeeded() &&
- pFormObj->m_pForm->BackgroundAlphaNeeded()) {
+ pFormObj->form()->BackgroundAlphaNeeded()) {
m_pObjectHolder->SetBackgroundAlphaNeeded(true);
}
pFormObj->CalcBoundingBox();
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index df5a41db3a..5f9a8992d3 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1237,11 +1237,11 @@ void CPDF_RenderStatus::DrawObjWithBackground(CPDF_PageObject* pObj,
matrix.Concat(*buffer.GetMatrix());
GetScaledMatrix(matrix);
CPDF_Dictionary* pFormResource = nullptr;
- if (pObj->IsForm()) {
- const CPDF_FormObject* pFormObj = pObj->AsForm();
- if (pFormObj->m_pForm && pFormObj->m_pForm->m_pFormDict) {
- pFormResource = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources");
- }
+ const CPDF_FormObject* pFormObj = pObj->AsForm();
+ if (pFormObj) {
+ const auto& pFormDict = pFormObj->form()->m_pFormDict;
+ if (pFormDict)
+ pFormResource = pFormDict->GetDictFor("Resources");
}
CPDF_RenderStatus status;
status.Initialize(m_pContext.Get(), buffer.GetDevice(), buffer.GetMatrix(),
@@ -1256,17 +1256,16 @@ bool CPDF_RenderStatus::ProcessForm(const CPDF_FormObject* pFormObj,
#if defined _SKIA_SUPPORT_
DebugVerifyDeviceIsPreMultiplied();
#endif
- CPDF_Dictionary* pOC = pFormObj->m_pForm->m_pFormDict->GetDictFor("OC");
+ CPDF_Dictionary* pOC = pFormObj->form()->m_pFormDict->GetDictFor("OC");
if (pOC && m_Options.GetOCContext() &&
!m_Options.GetOCContext()->CheckOCGVisible(pOC)) {
return true;
}
- CFX_Matrix matrix = pFormObj->m_FormMatrix;
+ CFX_Matrix matrix = pFormObj->form_matrix();
matrix.Concat(*pObj2Device);
- CPDF_Dictionary* pResources = nullptr;
- if (pFormObj->m_pForm && pFormObj->m_pForm->m_pFormDict) {
- pResources = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources");
- }
+ const auto& pFormDict = pFormObj->form()->m_pFormDict;
+ CPDF_Dictionary* pResources =
+ pFormDict ? pFormDict->GetDictFor("Resources") : nullptr;
CPDF_RenderStatus status;
status.Initialize(m_pContext.Get(), m_pDevice, nullptr, m_pStopObj, this,
pFormObj, &m_Options, m_iTransparency, m_bDropObjects,
@@ -1274,7 +1273,7 @@ bool CPDF_RenderStatus::ProcessForm(const CPDF_FormObject* pFormObj,
status.m_curBlend = m_curBlend;
{
CFX_RenderDevice::StateRestorer restorer(m_pDevice);
- status.RenderObjectList(pFormObj->m_pForm.get(), &matrix);
+ status.RenderObjectList(pFormObj->form(), &matrix);
m_bStopped = status.m_bStopped;
}
#if defined _SKIA_SUPPORT_
@@ -1487,14 +1486,14 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
float group_alpha = 1.0f;
int iTransparency = m_iTransparency;
bool bGroupTransparent = false;
- if (pPageObj->IsForm()) {
- const CPDF_FormObject* pFormObj = pPageObj->AsForm();
+ const CPDF_FormObject* pFormObj = pPageObj->AsForm();
+ if (pFormObj) {
group_alpha = pFormObj->m_GeneralState.GetFillAlpha();
- iTransparency = pFormObj->m_pForm->m_iTransparency;
+ iTransparency = pFormObj->form()->m_iTransparency;
bGroupTransparent = !!(iTransparency & PDFTRANS_ISOLATED);
- if (pFormObj->m_pForm->m_pFormDict) {
- pFormResource = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources");
- }
+ const auto& pFormDict = pFormObj->form()->m_pFormDict;
+ if (pFormDict)
+ pFormResource = pFormDict->GetDictFor("Resources");
}
bool bTextClip =
(pPageObj->m_ClipPath.HasRef() && pPageObj->m_ClipPath.GetTextCount() &&
@@ -2269,10 +2268,9 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
if (!pPattern->colored())
pStates = CloneObjStates(pPageObj, bStroke);
- CPDF_Dictionary* pFormResource = nullptr;
- if (pPattern->form()->m_pFormDict)
- pFormResource = pPattern->form()->m_pFormDict->GetDictFor("Resources");
-
+ auto& pFormDict = pPattern->form()->m_pFormDict;
+ CPDF_Dictionary* pFormResource =
+ pFormDict ? pFormDict->GetDictFor("Resources") : nullptr;
for (int col = min_col; col <= max_col; col++) {
for (int row = min_row; row <= max_row; row++) {
CFX_PointF original = mtPattern2Device.Transform(