xref: /aosp_15_r20/external/pdfium/core/fpdfapi/page/cpdf_generalstate.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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 <vector>
11 
12 #include "constants/transparency.h"
13 #include "core/fxcrt/bytestring.h"
14 #include "core/fxcrt/fx_coordinates.h"
15 #include "core/fxcrt/retain_ptr.h"
16 #include "core/fxcrt/shared_copy_on_write.h"
17 #include "core/fxge/dib/fx_dib.h"
18 #include "third_party/base/containers/span.h"
19 
20 class CPDF_Dictionary;
21 class CPDF_Object;
22 class CPDF_TransferFunc;
23 
24 class CPDF_GeneralState {
25  public:
26   CPDF_GeneralState();
27   CPDF_GeneralState(const CPDF_GeneralState& that);
28   ~CPDF_GeneralState();
29 
Emplace()30   void Emplace() { m_Ref.Emplace(); }
HasRef()31   bool HasRef() const { return !!m_Ref; }
32 
33   void SetRenderIntent(const ByteString& ri);
34 
35   ByteString GetBlendMode() const;
36   BlendMode GetBlendType() const;
37   void SetBlendType(BlendMode type);
38 
39   float GetFillAlpha() const;
40   void SetFillAlpha(float alpha);
41 
42   float GetStrokeAlpha() const;
43   void SetStrokeAlpha(float alpha);
44 
45   RetainPtr<const CPDF_Dictionary> GetSoftMask() const;
46   RetainPtr<CPDF_Dictionary> GetMutableSoftMask();
47   void SetSoftMask(RetainPtr<CPDF_Dictionary> pDict);
48 
49   RetainPtr<const CPDF_Object> GetTR() const;
50   void SetTR(RetainPtr<const CPDF_Object> pObject);
51 
52   RetainPtr<CPDF_TransferFunc> GetTransferFunc() const;
53   void SetTransferFunc(RetainPtr<CPDF_TransferFunc> pFunc);
54 
55   void SetBlendMode(const ByteString& mode);
56 
57   const CFX_Matrix* GetSMaskMatrix() const;
58   void SetSMaskMatrix(const CFX_Matrix& matrix);
59 
60   bool GetFillOP() const;
61   void SetFillOP(bool op);
62 
63   bool GetStrokeOP() const;
64   void SetStrokeOP(bool op);
65 
66   int GetOPMode() const;
67   void SetOPMode(int mode);
68 
69   void SetBG(RetainPtr<const CPDF_Object> pObject);
70   void SetUCR(RetainPtr<const CPDF_Object> pObject);
71   void SetHT(RetainPtr<const CPDF_Object> pObject);
72 
73   void SetFlatness(float flatness);
74   void SetSmoothness(float smoothness);
75 
76   bool GetStrokeAdjust() const;
77   void SetStrokeAdjust(bool adjust);
78 
79   void SetAlphaSource(bool source);
80   void SetTextKnockout(bool knockout);
81 
82   void SetMatrix(const CFX_Matrix& matrix);
83   CFX_Matrix* GetMutableMatrix();
84 
85   void SetGraphicsResourceNames(std::vector<ByteString> names);
86   void AppendGraphicsResourceName(ByteString name);
87   pdfium::span<const ByteString> GetGraphicsResourceNames() const;
88 
89  private:
90   class StateData final : public Retainable {
91    public:
92     CONSTRUCT_VIA_MAKE_RETAIN;
93 
94     RetainPtr<StateData> Clone() const;
95 
96     ByteString m_BlendMode = pdfium::transparency::kNormal;
97     BlendMode m_BlendType = BlendMode::kNormal;
98     RetainPtr<CPDF_Dictionary> m_pSoftMask;
99     CFX_Matrix m_SMaskMatrix;
100     float m_StrokeAlpha = 1.0f;
101     float m_FillAlpha = 1.0f;
102     RetainPtr<const CPDF_Object> m_pTR;
103     RetainPtr<CPDF_TransferFunc> m_pTransferFunc;
104     CFX_Matrix m_Matrix;
105     int m_RenderIntent = 0;
106     bool m_StrokeAdjust = false;
107     bool m_AlphaSource = false;
108     bool m_TextKnockout = false;
109     bool m_StrokeOP = false;
110     bool m_FillOP = false;
111     int m_OPMode = 0;
112     RetainPtr<const CPDF_Object> m_pBG;
113     RetainPtr<const CPDF_Object> m_pUCR;
114     RetainPtr<const CPDF_Object> m_pHT;
115     float m_Flatness = 1.0f;
116     float m_Smoothness = 0.0f;
117     // The resource names of the graphics states that apply to this object.
118     std::vector<ByteString> m_GraphicsResourceNames;
119 
120    private:
121     StateData();
122     StateData(const StateData& that);
123     ~StateData() override;
124   };
125 
126   SharedCopyOnWrite<StateData> m_Ref;
127 };
128 
129 #endif  // CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_
130