1 // Copyright 2016 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_ 9 10 #include "constants/transparency.h" 11 #include "core/fxcrt/bytestring.h" 12 #include "core/fxcrt/fx_coordinates.h" 13 #include "core/fxcrt/retain_ptr.h" 14 #include "core/fxcrt/shared_copy_on_write.h" 15 #include "core/fxge/dib/fx_dib.h" 16 17 class CPDF_Dictionary; 18 class CPDF_Object; 19 class CPDF_TransferFunc; 20 21 class CPDF_GeneralState { 22 public: 23 CPDF_GeneralState(); 24 CPDF_GeneralState(const CPDF_GeneralState& that); 25 ~CPDF_GeneralState(); 26 Emplace()27 void Emplace() { m_Ref.Emplace(); } HasRef()28 bool HasRef() const { return !!m_Ref; } 29 30 void SetRenderIntent(const ByteString& ri); 31 32 ByteString GetBlendMode() const; 33 BlendMode GetBlendType() const; 34 void SetBlendType(BlendMode type); 35 36 float GetFillAlpha() const; 37 void SetFillAlpha(float alpha); 38 39 float GetStrokeAlpha() const; 40 void SetStrokeAlpha(float alpha); 41 42 RetainPtr<const CPDF_Dictionary> GetSoftMask() const; 43 RetainPtr<CPDF_Dictionary> GetMutableSoftMask(); 44 void SetSoftMask(RetainPtr<CPDF_Dictionary> pDict); 45 46 RetainPtr<const CPDF_Object> GetTR() const; 47 void SetTR(RetainPtr<const CPDF_Object> pObject); 48 49 RetainPtr<CPDF_TransferFunc> GetTransferFunc() const; 50 void SetTransferFunc(RetainPtr<CPDF_TransferFunc> pFunc); 51 52 void SetBlendMode(const ByteString& mode); 53 54 const CFX_Matrix* GetSMaskMatrix() const; 55 void SetSMaskMatrix(const CFX_Matrix& matrix); 56 57 bool GetFillOP() const; 58 void SetFillOP(bool op); 59 60 bool GetStrokeOP() const; 61 void SetStrokeOP(bool op); 62 63 int GetOPMode() const; 64 void SetOPMode(int mode); 65 66 void SetBG(RetainPtr<const CPDF_Object> pObject); 67 void SetUCR(RetainPtr<const CPDF_Object> pObject); 68 void SetHT(RetainPtr<const CPDF_Object> pObject); 69 70 void SetFlatness(float flatness); 71 void SetSmoothness(float smoothness); 72 73 bool GetStrokeAdjust() const; 74 void SetStrokeAdjust(bool adjust); 75 76 void SetAlphaSource(bool source); 77 void SetTextKnockout(bool knockout); 78 79 void SetMatrix(const CFX_Matrix& matrix); 80 CFX_Matrix* GetMutableMatrix(); 81 82 private: 83 class StateData final : public Retainable { 84 public: 85 CONSTRUCT_VIA_MAKE_RETAIN; 86 87 RetainPtr<StateData> Clone() const; 88 89 ByteString m_BlendMode = pdfium::transparency::kNormal; 90 BlendMode m_BlendType = BlendMode::kNormal; 91 RetainPtr<CPDF_Dictionary> m_pSoftMask; 92 CFX_Matrix m_SMaskMatrix; 93 float m_StrokeAlpha = 1.0f; 94 float m_FillAlpha = 1.0f; 95 RetainPtr<const CPDF_Object> m_pTR; 96 RetainPtr<CPDF_TransferFunc> m_pTransferFunc; 97 CFX_Matrix m_Matrix; 98 int m_RenderIntent = 0; 99 bool m_StrokeAdjust = false; 100 bool m_AlphaSource = false; 101 bool m_TextKnockout = false; 102 bool m_StrokeOP = false; 103 bool m_FillOP = false; 104 int m_OPMode = 0; 105 RetainPtr<const CPDF_Object> m_pBG; 106 RetainPtr<const CPDF_Object> m_pUCR; 107 RetainPtr<const CPDF_Object> m_pHT; 108 float m_Flatness = 1.0f; 109 float m_Smoothness = 0.0f; 110 111 private: 112 StateData(); 113 StateData(const StateData& that); 114 ~StateData() override; 115 }; 116 117 SharedCopyOnWrite<StateData> m_Ref; 118 }; 119 120 #endif // CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_ 121