1 // Copyright 2016 PDFium Authors. All rights reserved.
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/fx_coordinates.h"
12 #include "core/fxcrt/fx_string.h"
13 #include "core/fxcrt/retain_ptr.h"
14 #include "core/fxcrt/shared_copy_on_write.h"
15 #include "core/fxge/fx_dib.h"
16 
17 class CPDF_Object;
18 class CPDF_TransferFunc;
19 
20 class CPDF_GeneralState {
21  public:
22   CPDF_GeneralState();
23   CPDF_GeneralState(const CPDF_GeneralState& that);
24   ~CPDF_GeneralState();
25 
Emplace()26   void Emplace() { m_Ref.Emplace(); }
HasRef()27   bool HasRef() const { return !!m_Ref; }
28 
29   void SetRenderIntent(const ByteString& ri);
30 
31   ByteString GetBlendMode() const;
32   BlendMode GetBlendType() const;
33   void SetBlendType(BlendMode type);
34 
35   float GetFillAlpha() const;
36   void SetFillAlpha(float alpha);
37 
38   float GetStrokeAlpha() const;
39   void SetStrokeAlpha(float alpha);
40 
41   CPDF_Object* GetSoftMask() const;
42   void SetSoftMask(CPDF_Object* pObject);
43 
44   const CPDF_Object* GetTR() const;
45   void SetTR(CPDF_Object* pObject);
46 
47   RetainPtr<CPDF_TransferFunc> GetTransferFunc() const;
48   void SetTransferFunc(const RetainPtr<CPDF_TransferFunc>& pFunc);
49 
50   void SetBlendMode(const ByteString& mode);
51 
52   const CFX_Matrix* GetSMaskMatrix() const;
53   void SetSMaskMatrix(const CFX_Matrix& matrix);
54 
55   bool GetFillOP() const;
56   void SetFillOP(bool op);
57 
58   bool GetStrokeOP() const;
59   void SetStrokeOP(bool op);
60 
61   int GetOPMode() const;
62   void SetOPMode(int mode);
63 
64   void SetBG(CPDF_Object* pObject);
65   void SetUCR(CPDF_Object* pObject);
66   void SetHT(CPDF_Object* pObject);
67 
68   void SetFlatness(float flatness);
69   void SetSmoothness(float smoothness);
70 
71   bool GetStrokeAdjust() const;
72   void SetStrokeAdjust(bool adjust);
73 
74   void SetAlphaSource(bool source);
75   void SetTextKnockout(bool knockout);
76 
77   void SetMatrix(const CFX_Matrix& matrix);
78   CFX_Matrix* GetMutableMatrix();
79 
80  private:
81   class StateData final : public Retainable {
82    public:
83     template <typename T, typename... Args>
84     friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
85 
86     RetainPtr<StateData> Clone() const;
87 
88     ByteString m_BlendMode = pdfium::transparency::kNormal;
89     BlendMode m_BlendType = BlendMode::kNormal;
90     RetainPtr<CPDF_Object> m_pSoftMask;
91     CFX_Matrix m_SMaskMatrix;
92     float m_StrokeAlpha = 1.0f;
93     float m_FillAlpha = 1.0f;
94     RetainPtr<const CPDF_Object> m_pTR;
95     RetainPtr<CPDF_TransferFunc> m_pTransferFunc;
96     CFX_Matrix m_Matrix;
97     int m_RenderIntent = 0;
98     bool m_StrokeAdjust = false;
99     bool m_AlphaSource = false;
100     bool m_TextKnockout = false;
101     bool m_StrokeOP = false;
102     bool m_FillOP = false;
103     int m_OPMode = 0;
104     RetainPtr<const CPDF_Object> m_pBG;
105     RetainPtr<const CPDF_Object> m_pUCR;
106     RetainPtr<const CPDF_Object> m_pHT;
107     float m_Flatness = 1.0f;
108     float m_Smoothness = 0.0f;
109 
110    private:
111     StateData();
112     StateData(const StateData& that);
113     ~StateData() override;
114   };
115 
116   SharedCopyOnWrite<StateData> m_Ref;
117 };
118 
119 #endif  // CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_
120