Convert CPDF_GeneralState::m_pSoftMask to CPDF_Dictionary.
Currently, it is being stored as a CPDF_Object, but it is always
a dictionary, so avoid some ToDictionary() calls.
Change-Id: I04416665e36d5681d56798deb21a4c20985c0477
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96311
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_allstates.cpp b/core/fpdfapi/page/cpdf_allstates.cpp
index 5af6327..e7ee91a 100644
--- a/core/fpdfapi/page/cpdf_allstates.cpp
+++ b/core/fpdfapi/page/cpdf_allstates.cpp
@@ -106,14 +106,13 @@
pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(true);
break;
}
- case FXBSTR_ID('S', 'M', 'a', 's'):
- if (ToDictionary(pObject)) {
- m_GeneralState.SetSoftMask(pObject);
+ case FXBSTR_ID('S', 'M', 'a', 's'): {
+ RetainPtr<CPDF_Dictionary> pMaskDict = ToDictionary(pObject);
+ m_GeneralState.SetSoftMask(pMaskDict);
+ if (pMaskDict)
m_GeneralState.SetSMaskMatrix(pParser->GetCurStates()->m_CTM);
- } else {
- m_GeneralState.SetSoftMask(nullptr);
- }
break;
+ }
case FXBSTR_ID('C', 'A', 0, 0):
m_GeneralState.SetStrokeAlpha(
pdfium::clamp(pObject->GetNumber(), 0.0f, 1.0f));
diff --git a/core/fpdfapi/page/cpdf_generalstate.cpp b/core/fpdfapi/page/cpdf_generalstate.cpp
index 550cfc9..75cf5a4 100644
--- a/core/fpdfapi/page/cpdf_generalstate.cpp
+++ b/core/fpdfapi/page/cpdf_generalstate.cpp
@@ -9,6 +9,7 @@
#include <utility>
#include "core/fpdfapi/page/cpdf_transferfunc.h"
+#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_object.h"
namespace {
@@ -144,18 +145,18 @@
m_Ref.GetPrivateCopy()->m_StrokeAlpha = alpha;
}
-const CPDF_Object* CPDF_GeneralState::GetSoftMask() const {
+const CPDF_Dictionary* CPDF_GeneralState::GetSoftMask() const {
const StateData* pData = m_Ref.GetObject();
return pData ? pData->m_pSoftMask.Get() : nullptr;
}
-RetainPtr<CPDF_Object> CPDF_GeneralState::GetMutableSoftMask() {
+RetainPtr<CPDF_Dictionary> CPDF_GeneralState::GetMutableSoftMask() {
const StateData* pData = m_Ref.GetObject();
return pData ? pData->m_pSoftMask : nullptr;
}
-void CPDF_GeneralState::SetSoftMask(RetainPtr<CPDF_Object> pObject) {
- m_Ref.GetPrivateCopy()->m_pSoftMask = std::move(pObject);
+void CPDF_GeneralState::SetSoftMask(RetainPtr<CPDF_Dictionary> pDict) {
+ m_Ref.GetPrivateCopy()->m_pSoftMask = std::move(pDict);
}
const CPDF_Object* CPDF_GeneralState::GetTR() const {
diff --git a/core/fpdfapi/page/cpdf_generalstate.h b/core/fpdfapi/page/cpdf_generalstate.h
index 6b4b307..140b6bd 100644
--- a/core/fpdfapi/page/cpdf_generalstate.h
+++ b/core/fpdfapi/page/cpdf_generalstate.h
@@ -14,6 +14,7 @@
#include "core/fxcrt/shared_copy_on_write.h"
#include "core/fxge/dib/fx_dib.h"
+class CPDF_Dictionary;
class CPDF_Object;
class CPDF_TransferFunc;
@@ -38,9 +39,9 @@
float GetStrokeAlpha() const;
void SetStrokeAlpha(float alpha);
- const CPDF_Object* GetSoftMask() const;
- RetainPtr<CPDF_Object> GetMutableSoftMask();
- void SetSoftMask(RetainPtr<CPDF_Object> pObject);
+ const CPDF_Dictionary* GetSoftMask() const;
+ RetainPtr<CPDF_Dictionary> GetMutableSoftMask();
+ void SetSoftMask(RetainPtr<CPDF_Dictionary> pDict);
const CPDF_Object* GetTR() const;
void SetTR(const CPDF_Object* pObject);
@@ -87,7 +88,7 @@
ByteString m_BlendMode = pdfium::transparency::kNormal;
BlendMode m_BlendType = BlendMode::kNormal;
- RetainPtr<CPDF_Object> m_pSoftMask;
+ RetainPtr<CPDF_Dictionary> m_pSoftMask;
CFX_Matrix m_SMaskMatrix;
float m_StrokeAlpha = 1.0f;
float m_FillAlpha = 1.0f;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 6c3b541..d9ba042 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -601,7 +601,7 @@
#endif
const BlendMode blend_type = pPageObj->m_GeneralState.GetBlendType();
RetainPtr<CPDF_Dictionary> pSMaskDict =
- ToDictionary(pPageObj->m_GeneralState.GetMutableSoftMask());
+ pPageObj->m_GeneralState.GetMutableSoftMask();
if (pSMaskDict) {
if (pPageObj->IsImage() &&
pPageObj->AsImage()->GetImage()->GetDict()->KeyExist("SMask")) {
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index a6fa591..7092a09 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -485,8 +485,7 @@
if (pPageObj->m_GeneralState.GetBlendType() != BlendMode::kNormal)
return true;
- const CPDF_Dictionary* pSMaskDict =
- ToDictionary(pPageObj->m_GeneralState.GetSoftMask());
+ const CPDF_Dictionary* pSMaskDict = pPageObj->m_GeneralState.GetSoftMask();
if (pSMaskDict)
return true;