Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: core/fpdfapi/fpdf_page/cpdf_generalstate.cpp

Issue 2302683002: Make StateData private (Closed)
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « BUILD.gn ('k') | core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
diff --git a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
index 5e6fb7434d3da06e00b6db7b0831de4101c6237c..4905c1f00757706f2d788d27996d847412860124 100644
--- a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
@@ -6,6 +6,9 @@
#include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+#include "core/fpdfapi/fpdf_render/render_int.h"
+
namespace {
int RI_StringToId(const CFX_ByteString& ri) {
@@ -22,6 +25,45 @@ int RI_StringToId(const CFX_ByteString& ri) {
return 0;
}
+static int GetBlendTypeInternal(const CFX_ByteStringC& mode) {
+ switch (mode.GetID()) {
+ case FXBSTR_ID('N', 'o', 'r', 'm'):
+ case FXBSTR_ID('C', 'o', 'm', 'p'):
+ return FXDIB_BLEND_NORMAL;
+ case FXBSTR_ID('M', 'u', 'l', 't'):
+ return FXDIB_BLEND_MULTIPLY;
+ case FXBSTR_ID('S', 'c', 'r', 'e'):
+ return FXDIB_BLEND_SCREEN;
+ case FXBSTR_ID('O', 'v', 'e', 'r'):
+ return FXDIB_BLEND_OVERLAY;
+ case FXBSTR_ID('D', 'a', 'r', 'k'):
+ return FXDIB_BLEND_DARKEN;
+ case FXBSTR_ID('L', 'i', 'g', 'h'):
+ return FXDIB_BLEND_LIGHTEN;
+ case FXBSTR_ID('C', 'o', 'l', 'o'):
+ if (mode.GetLength() == 10)
+ return FXDIB_BLEND_COLORDODGE;
+ if (mode.GetLength() == 9)
+ return FXDIB_BLEND_COLORBURN;
+ return FXDIB_BLEND_COLOR;
+ case FXBSTR_ID('H', 'a', 'r', 'd'):
+ return FXDIB_BLEND_HARDLIGHT;
+ case FXBSTR_ID('S', 'o', 'f', 't'):
+ return FXDIB_BLEND_SOFTLIGHT;
+ case FXBSTR_ID('D', 'i', 'f', 'f'):
+ return FXDIB_BLEND_DIFFERENCE;
+ case FXBSTR_ID('E', 'x', 'c', 'l'):
+ return FXDIB_BLEND_EXCLUSION;
+ case FXBSTR_ID('H', 'u', 'e', 0):
+ return FXDIB_BLEND_HUE;
+ case FXBSTR_ID('S', 'a', 't', 'u'):
+ return FXDIB_BLEND_SATURATION;
+ case FXBSTR_ID('L', 'u', 'm', 'i'):
+ return FXDIB_BLEND_LUMINOSITY;
+ }
+ return FXDIB_BLEND_NORMAL;
+}
+
} // namespace
CPDF_GeneralState::CPDF_GeneralState() {}
@@ -31,6 +73,180 @@ CPDF_GeneralState::CPDF_GeneralState(const CPDF_GeneralState& that)
CPDF_GeneralState::~CPDF_GeneralState() {}
+int CPDF_GeneralState::GetBlendType() const {
+ const StateData* pData = m_Ref.GetObject();
+ return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL;
+}
+
+void CPDF_GeneralState::SetBlendType(int type) {
+ m_Ref.GetPrivateCopy()->m_BlendType = type;
+}
+
+int CPDF_GeneralState::GetFillAlpha() const {
+ const StateData* pData = m_Ref.GetObject();
+ return pData ? FXSYS_round(255 * pData->m_FillAlpha) : 255;
+}
+
+int CPDF_GeneralState::GetStrokeAlpha() const {
+ const StateData* pData = m_Ref.GetObject();
+ return pData ? FXSYS_round(255 * pData->m_StrokeAlpha) : 255;
+}
+
+void CPDF_GeneralState::SetSoftMask(CPDF_Object* pObject) {
+ m_Ref.GetPrivateCopy()->m_pSoftMask = pObject;
+}
+
+CPDF_Object* CPDF_GeneralState::GetSoftMask() const {
+ const StateData* pData = m_Ref.GetObject();
+ return pData ? pData->m_pSoftMask : nullptr;
+}
+
+void CPDF_GeneralState::SetTR(CPDF_Object* pObject) {
+ m_Ref.GetPrivateCopy()->m_pTR = pObject;
+}
+
+CPDF_Object* CPDF_GeneralState::GetTR() const {
+ return m_Ref.GetObject()->m_pTR;
+}
+
+void CPDF_GeneralState::SetTransferFunc(CPDF_TransferFunc* pFunc) {
+ m_Ref.GetPrivateCopy()->m_pTransferFunc = pFunc;
+}
+
+CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const {
+ return m_Ref.GetObject()->m_pTransferFunc;
+}
+
+void CPDF_GeneralState::SetBlendMode(const CFX_ByteStringC& mode) {
+ m_Ref.GetPrivateCopy()->SetBlendMode(mode);
+}
+
+const FX_FLOAT* CPDF_GeneralState::GetSMaskMatrix() const {
+ return m_Ref.GetObject()->m_SMaskMatrix;
+}
+
+FX_FLOAT* CPDF_GeneralState::GetMutableSMaskMatrix() {
+ return m_Ref.GetPrivateCopy()->m_SMaskMatrix;
+}
+
+void CPDF_GeneralState::SetStrokeAlpha(FX_FLOAT alpha) {
+ m_Ref.GetPrivateCopy()->m_StrokeAlpha = alpha;
+}
+
+void CPDF_GeneralState::SetFillAlpha(FX_FLOAT alpha) {
+ m_Ref.GetPrivateCopy()->m_FillAlpha = alpha;
+}
+
+void CPDF_GeneralState::SetFillOP(int op) {
+ m_Ref.GetPrivateCopy()->m_FillOP = op;
+}
+
+int CPDF_GeneralState::GetFillOP() const {
+ return m_Ref.GetObject()->m_FillOP;
+}
+
+void CPDF_GeneralState::SetStrokeOP(int op) {
+ m_Ref.GetPrivateCopy()->m_StrokeOP = op;
+}
+
+int CPDF_GeneralState::GetStrokeOP() const {
+ return m_Ref.GetObject()->m_StrokeOP;
+}
+
+void CPDF_GeneralState::SetOPMode(int mode) {
+ m_Ref.GetPrivateCopy()->m_OPMode = mode;
+}
+
+int CPDF_GeneralState::GetOPMode() const {
+ return m_Ref.GetObject()->m_OPMode;
+}
+
+void CPDF_GeneralState::SetBG(CPDF_Object* pObject) {
+ m_Ref.GetPrivateCopy()->m_pBG = pObject;
+}
+
+void CPDF_GeneralState::SetUCR(CPDF_Object* pObject) {
+ m_Ref.GetPrivateCopy()->m_pUCR = pObject;
+}
+
+void CPDF_GeneralState::SetHT(CPDF_Object* pObject) {
+ m_Ref.GetPrivateCopy()->m_pHT = pObject;
+}
+
+void CPDF_GeneralState::SetFlatness(FX_FLOAT flatness) {
+ m_Ref.GetPrivateCopy()->m_Flatness = flatness;
+}
+
+void CPDF_GeneralState::SetSmoothness(FX_FLOAT smoothness) {
+ m_Ref.GetPrivateCopy()->m_Smoothness = smoothness;
+}
+
+void CPDF_GeneralState::SetStrokeAdjust(FX_FLOAT adjust) {
+ m_Ref.GetPrivateCopy()->m_StrokeAdjust = adjust;
+}
+
+FX_FLOAT CPDF_GeneralState::GetStrokeAdjust() const {
+ return m_Ref.GetObject()->m_StrokeAdjust;
+}
+
+void CPDF_GeneralState::SetAlphaSource(int source) {
+ m_Ref.GetPrivateCopy()->m_AlphaSource = source;
+}
+
+void CPDF_GeneralState::SetTextKnockout(int knockout) {
+ m_Ref.GetPrivateCopy()->m_TextKnockout = knockout;
+}
+
+void CPDF_GeneralState::SetMatrix(const CFX_Matrix& matrix) {
+ m_Ref.GetPrivateCopy()->m_Matrix = matrix;
+}
+
+CFX_Matrix* CPDF_GeneralState::GetMutableMatrix() {
+ return &m_Ref.GetPrivateCopy()->m_Matrix;
+}
+
void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) {
m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri);
}
+
+CPDF_GeneralState::StateData::StateData() {
+ FXSYS_memset(this, 0, sizeof(CPDF_GeneralState::StateData));
+ FXSYS_strcpy((FX_CHAR*)m_BlendMode, "Normal");
dsinclair 2016/09/01 14:17:09 static_cast
Tom Sepez 2016/09/01 22:26:31 rewrote to use bytstrings
+ m_StrokeAlpha = 1.0f;
+ m_FillAlpha = 1.0f;
+ m_Flatness = 1.0f;
+ m_Matrix.SetIdentity();
+}
+
+CPDF_GeneralState::StateData::StateData(
+ const CPDF_GeneralState::StateData& src) {
+ FXSYS_memcpy(this, &src, sizeof(CPDF_GeneralState::StateData));
+ if (src.m_pTransferFunc && src.m_pTransferFunc->m_pPDFDoc) {
dsinclair 2016/09/01 14:17:09 invert and early return?
Tom Sepez 2016/09/01 22:26:31 Nah, but invert inner if.
+ CPDF_DocRenderData* pDocCache =
+ src.m_pTransferFunc->m_pPDFDoc->GetRenderData();
+ if (!pDocCache)
+ return;
+
+ m_pTransferFunc = pDocCache->GetTransferFunc(m_pTR);
+ }
+}
+
+CPDF_GeneralState::StateData::~StateData() {
+ if (m_pTransferFunc && m_pTransferFunc->m_pPDFDoc) {
dsinclair 2016/09/01 14:17:09 early return
Tom Sepez 2016/09/01 22:26:31 Same.
+ CPDF_DocRenderData* pDocCache = m_pTransferFunc->m_pPDFDoc->GetRenderData();
+ if (!pDocCache)
+ return;
+
+ pDocCache->ReleaseTransferFunc(m_pTR);
+ }
+}
+
+void CPDF_GeneralState::StateData::SetBlendMode(
+ const CFX_ByteStringC& blend_mode) {
+ if (blend_mode.GetLength() > 15) {
+ return;
+ }
dsinclair 2016/09/01 14:17:09 nit {}'s
Tom Sepez 2016/09/01 22:26:31 No longer exists.
+ FXSYS_memcpy(m_BlendMode, blend_mode.raw_str(), blend_mode.GetLength());
+ m_BlendMode[blend_mode.GetLength()] = 0;
+ m_BlendType = GetBlendTypeInternal(blend_mode);
+}
« no previous file with comments | « BUILD.gn ('k') | core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698