diff options
Diffstat (limited to 'core/fpdfapi/fpdf_page')
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_allstates.cpp | 48 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_generalstate.cpp | 147 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_pageobject.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 11 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_generalstate.h | 71 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h | 10 |
7 files changed, 238 insertions, 54 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp index acecafd01e..89c13215ae 100644 --- a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp @@ -50,7 +50,6 @@ void CPDF_AllStates::SetLineDash(CPDF_Array* pArray, void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser* pParser) { - CPDF_GeneralStateData* pGeneralState = m_GeneralState.GetPrivateCopy(); for (const auto& it : *pGS) { const CFX_ByteString& key_str = it.first; CPDF_Object* pElement = it.second; @@ -103,80 +102,77 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, continue; } case FXBSTR_ID('T', 'R', '2', 0): - pGeneralState->m_pTR = - (pObject && !pObject->IsName()) ? pObject : nullptr; + m_GeneralState.SetTR(pObject && !pObject->IsName() ? pObject : nullptr); break; case FXBSTR_ID('B', 'M', 0, 0): { CPDF_Array* pArray = pObject->AsArray(); CFX_ByteString mode = pArray ? pArray->GetStringAt(0) : pObject->GetString(); - pGeneralState->SetBlendMode(mode.AsStringC()); - if (pGeneralState->m_BlendType > FXDIB_BLEND_MULTIPLY) { + m_GeneralState.SetBlendMode(mode.AsStringC()); + if (m_GeneralState.GetBlendType() > FXDIB_BLEND_MULTIPLY) pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(TRUE); - } break; } case FXBSTR_ID('S', 'M', 'a', 's'): if (ToDictionary(pObject)) { - pGeneralState->m_pSoftMask = pObject; - FXSYS_memcpy(pGeneralState->m_SMaskMatrix, + m_GeneralState.SetSoftMask(pObject); + FXSYS_memcpy(m_GeneralState.GetMutableSMaskMatrix(), &pParser->GetCurStates()->m_CTM, sizeof(CFX_Matrix)); } else { - pGeneralState->m_pSoftMask = nullptr; + m_GeneralState.SetSoftMask(nullptr); } break; case FXBSTR_ID('C', 'A', 0, 0): - pGeneralState->m_StrokeAlpha = ClipFloat(pObject->GetNumber()); + m_GeneralState.SetStrokeAlpha(ClipFloat(pObject->GetNumber())); break; case FXBSTR_ID('c', 'a', 0, 0): - pGeneralState->m_FillAlpha = ClipFloat(pObject->GetNumber()); + m_GeneralState.SetFillAlpha(ClipFloat(pObject->GetNumber())); break; case FXBSTR_ID('O', 'P', 0, 0): - pGeneralState->m_StrokeOP = pObject->GetInteger(); - if (!pGS->KeyExist("op")) { - pGeneralState->m_FillOP = pObject->GetInteger(); - } + m_GeneralState.SetStrokeOP(!!pObject->GetInteger()); + if (!pGS->KeyExist("op")) + m_GeneralState.SetFillOP(!!pObject->GetInteger()); break; case FXBSTR_ID('o', 'p', 0, 0): - pGeneralState->m_FillOP = pObject->GetInteger(); + m_GeneralState.SetFillOP(!!pObject->GetInteger()); break; case FXBSTR_ID('O', 'P', 'M', 0): - pGeneralState->m_OPMode = pObject->GetInteger(); + m_GeneralState.SetOPMode(pObject->GetInteger()); break; case FXBSTR_ID('B', 'G', 0, 0): if (pGS->KeyExist("BG2")) { continue; } case FXBSTR_ID('B', 'G', '2', 0): - pGeneralState->m_pBG = pObject; + m_GeneralState.SetBG(pObject); break; case FXBSTR_ID('U', 'C', 'R', 0): if (pGS->KeyExist("UCR2")) { continue; } case FXBSTR_ID('U', 'C', 'R', '2'): - pGeneralState->m_pUCR = pObject; + m_GeneralState.SetUCR(pObject); break; case FXBSTR_ID('H', 'T', 0, 0): - pGeneralState->m_pHT = pObject; + m_GeneralState.SetHT(pObject); break; case FXBSTR_ID('F', 'L', 0, 0): - pGeneralState->m_Flatness = pObject->GetNumber(); + m_GeneralState.SetFlatness(pObject->GetNumber()); break; case FXBSTR_ID('S', 'M', 0, 0): - pGeneralState->m_Smoothness = pObject->GetNumber(); + m_GeneralState.SetSmoothness(pObject->GetNumber()); break; case FXBSTR_ID('S', 'A', 0, 0): - pGeneralState->m_StrokeAdjust = pObject->GetInteger(); + m_GeneralState.SetStrokeAdjust(!!pObject->GetInteger()); break; case FXBSTR_ID('A', 'I', 'S', 0): - pGeneralState->m_AlphaSource = pObject->GetInteger(); + m_GeneralState.SetAlphaSource(!!pObject->GetInteger()); break; case FXBSTR_ID('T', 'K', 0, 0): - pGeneralState->m_TextKnockout = pObject->GetInteger(); + m_GeneralState.SetTextKnockout(!!pObject->GetInteger()); break; } } - pGeneralState->m_Matrix = m_CTM; + m_GeneralState.SetMatrix(m_CTM); } diff --git a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp index 0f6cce6e29..e34801f534 100644 --- a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp @@ -24,6 +24,151 @@ int RI_StringToId(const CFX_ByteString& ri) { } // namespace +CPDF_GeneralState::CPDF_GeneralState() {} + +CPDF_GeneralState::CPDF_GeneralState(const CPDF_GeneralState& that) + : m_Ref(that.m_Ref) {} + +CPDF_GeneralState::~CPDF_GeneralState() {} + void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { - GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); + m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); +} + +int CPDF_GeneralState::GetBlendType() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL; +} + +void CPDF_GeneralState::SetBlendType(int type) { + m_Ref.GetPrivateCopy()->m_BlendType = type; +} + +FX_FLOAT CPDF_GeneralState::GetFillAlpha() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_FillAlpha : 1.0f; +} + +void CPDF_GeneralState::SetFillAlpha(FX_FLOAT alpha) { + m_Ref.GetPrivateCopy()->m_FillAlpha = alpha; +} + +FX_FLOAT CPDF_GeneralState::GetStrokeAlpha() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_StrokeAlpha : 1.0f; +} + +void CPDF_GeneralState::SetStrokeAlpha(FX_FLOAT alpha) { + m_Ref.GetPrivateCopy()->m_StrokeAlpha = alpha; +} + +CPDF_Object* CPDF_GeneralState::GetSoftMask() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_pSoftMask : nullptr; +} + +void CPDF_GeneralState::SetSoftMask(CPDF_Object* pObject) { + m_Ref.GetPrivateCopy()->m_pSoftMask = pObject; +} + +CPDF_Object* CPDF_GeneralState::GetTR() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_pTR : nullptr; +} + +void CPDF_GeneralState::SetTR(CPDF_Object* pObject) { + m_Ref.GetPrivateCopy()->m_pTR = pObject; +} + +CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_pTransferFunc : nullptr; +} + +void CPDF_GeneralState::SetTransferFunc(CPDF_TransferFunc* pFunc) { + m_Ref.GetPrivateCopy()->m_pTransferFunc = pFunc; +} + +void CPDF_GeneralState::SetBlendMode(const CFX_ByteStringC& mode) { + m_Ref.GetPrivateCopy()->SetBlendMode(mode); +} + +const FX_FLOAT* CPDF_GeneralState::GetSMaskMatrix() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_SMaskMatrix : nullptr; +} + +FX_FLOAT* CPDF_GeneralState::GetMutableSMaskMatrix() { + return m_Ref.GetPrivateCopy()->m_SMaskMatrix; +} + +bool CPDF_GeneralState::GetFillOP() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData && pData->m_FillOP; +} + +void CPDF_GeneralState::SetFillOP(bool op) { + m_Ref.GetPrivateCopy()->m_FillOP = op; +} + +void CPDF_GeneralState::SetStrokeOP(bool op) { + m_Ref.GetPrivateCopy()->m_StrokeOP = op; +} + +bool CPDF_GeneralState::GetStrokeOP() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData && pData->m_StrokeOP; +} + +int CPDF_GeneralState::GetOPMode() const { + return m_Ref.GetObject()->m_OPMode; +} + +void CPDF_GeneralState::SetOPMode(int mode) { + m_Ref.GetPrivateCopy()->m_OPMode = mode; +} + +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; +} + +bool CPDF_GeneralState::GetStrokeAdjust() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData && pData->m_StrokeAdjust; +} + +void CPDF_GeneralState::SetStrokeAdjust(bool adjust) { + m_Ref.GetPrivateCopy()->m_StrokeAdjust = adjust; +} + +void CPDF_GeneralState::SetAlphaSource(bool source) { + m_Ref.GetPrivateCopy()->m_AlphaSource = source; +} + +void CPDF_GeneralState::SetTextKnockout(bool 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; } diff --git a/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp b/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp index 17014c4883..1ce83a85bc 100644 --- a/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp @@ -88,8 +88,7 @@ void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) { void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) { if (!m_GeneralState) return; - CPDF_GeneralStateData* pGS = m_GeneralState.GetPrivateCopy(); - pGS->m_Matrix.Concat(matrix); + m_GeneralState.GetMutableMatrix()->Concat(matrix); } FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const { diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 4712ea0725..cf77de15a4 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -865,7 +865,7 @@ void CPDF_StreamContentParser::Handle_ClosePath() { } void CPDF_StreamContentParser::Handle_SetFlat() { - m_pCurStates->m_GeneralState.GetPrivateCopy()->m_Flatness = GetNumber(0); + m_pCurStates->m_GeneralState.SetFlatness(GetNumber(0)); } void CPDF_StreamContentParser::Handle_BeginImageData() {} diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index 92a9d6c92e..745a707902 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -711,12 +711,11 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm, TRUE); } if (pForm->m_Transparency & PDFTRANS_GROUP) { - CPDF_GeneralStateData* pData = - m_pParser->GetCurStates()->m_GeneralState.GetPrivateCopy(); - pData->m_BlendType = FXDIB_BLEND_NORMAL; - pData->m_StrokeAlpha = 1.0f; - pData->m_FillAlpha = 1.0f; - pData->m_pSoftMask = nullptr; + CPDF_GeneralState* pState = &m_pParser->GetCurStates()->m_GeneralState; + pState->SetBlendType(FXDIB_BLEND_NORMAL); + pState->SetStrokeAlpha(1.0f); + pState->SetFillAlpha(1.0f); + pState->SetSoftMask(nullptr); } m_nStreams = 0; m_pSingleStream.reset(new CPDF_StreamAcc); diff --git a/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h b/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h index dff8371119..b653d640d7 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h @@ -10,22 +10,67 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h" #include "core/fxcrt/include/fx_basic.h" -class CPDF_GeneralState : public CFX_CountRef<CPDF_GeneralStateData> { +class CPDF_GeneralState { public: + CPDF_GeneralState(); + CPDF_GeneralState(const CPDF_GeneralState& that); + ~CPDF_GeneralState(); + + void Emplace() { m_Ref.Emplace(); } + operator bool() const { return !!m_Ref; } + void SetRenderIntent(const CFX_ByteString& ri); - int GetBlendType() const { - const CPDF_GeneralStateData* pData = GetObject(); - return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL; - } - - int GetAlpha(FX_BOOL bStroke) const { - const CPDF_GeneralStateData* pData = GetObject(); - if (!pData) - return 255; - return FXSYS_round((bStroke ? pData->m_StrokeAlpha : pData->m_FillAlpha) * - 255); - } + int GetBlendType() const; + void SetBlendType(int type); + + FX_FLOAT GetFillAlpha() const; + void SetFillAlpha(FX_FLOAT alpha); + + FX_FLOAT GetStrokeAlpha() const; + void SetStrokeAlpha(FX_FLOAT alpha); + + CPDF_Object* GetSoftMask() const; + void SetSoftMask(CPDF_Object* pObject); + + CPDF_Object* GetTR() const; + void SetTR(CPDF_Object* pObject); + + CPDF_TransferFunc* GetTransferFunc() const; + void SetTransferFunc(CPDF_TransferFunc* pFunc); + + void SetBlendMode(const CFX_ByteStringC& mode); + + const FX_FLOAT* GetSMaskMatrix() const; + FX_FLOAT* GetMutableSMaskMatrix(); + + bool GetFillOP() const; + void SetFillOP(bool op); + + bool GetStrokeOP() const; + void SetStrokeOP(bool op); + + int GetOPMode() const; + void SetOPMode(int mode); + + void SetBG(CPDF_Object* pObject); + void SetUCR(CPDF_Object* pObject); + void SetHT(CPDF_Object* pObject); + + void SetFlatness(FX_FLOAT flatness); + void SetSmoothness(FX_FLOAT smoothness); + + bool GetStrokeAdjust() const; + void SetStrokeAdjust(bool adjust); + + void SetAlphaSource(bool source); + void SetTextKnockout(bool knockout); + + void SetMatrix(const CFX_Matrix& matrix); + CFX_Matrix* GetMutableMatrix(); + + private: + CFX_CountRef<CPDF_GeneralStateData> m_Ref; }; #endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATE_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h b/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h index a4577a6cb0..e19bcc76ac 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h @@ -33,11 +33,11 @@ class CPDF_GeneralStateData { CPDF_TransferFunc* m_pTransferFunc; CFX_Matrix m_Matrix; int m_RenderIntent; - FX_BOOL m_StrokeAdjust; - FX_BOOL m_AlphaSource; - FX_BOOL m_TextKnockout; - FX_BOOL m_StrokeOP; - FX_BOOL m_FillOP; + bool m_StrokeAdjust; + bool m_AlphaSource; + bool m_TextKnockout; + bool m_StrokeOP; + bool m_FillOP; int m_OPMode; CPDF_Object* m_pBG; CPDF_Object* m_pUCR; |