• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/fxcrt/span.h"
18 #include "core/fxge/dib/fx_dib.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 SetGraphicsResourceNames(std::vector<ByteString> names);
83   void AppendGraphicsResourceName(ByteString name);
84   pdfium::span<const ByteString> GetGraphicsResourceNames() const;
85 
86  private:
87   class StateData final : public Retainable {
88    public:
89     CONSTRUCT_VIA_MAKE_RETAIN;
90 
91     RetainPtr<StateData> Clone() const;
92 
93     ByteString m_BlendMode = pdfium::transparency::kNormal;
94     BlendMode m_BlendType = BlendMode::kNormal;
95     RetainPtr<CPDF_Dictionary> m_pSoftMask;
96     CFX_Matrix m_SMaskMatrix;
97     float m_StrokeAlpha = 1.0f;
98     float m_FillAlpha = 1.0f;
99     RetainPtr<const CPDF_Object> m_pTR;
100     RetainPtr<CPDF_TransferFunc> m_pTransferFunc;
101     int m_RenderIntent = 0;
102     bool m_StrokeAdjust = false;
103     bool m_AlphaSource = false;
104     bool m_TextKnockout = false;
105     bool m_StrokeOP = false;
106     bool m_FillOP = false;
107     int m_OPMode = 0;
108     RetainPtr<const CPDF_Object> m_pBG;
109     RetainPtr<const CPDF_Object> m_pUCR;
110     RetainPtr<const CPDF_Object> m_pHT;
111     float m_Flatness = 1.0f;
112     float m_Smoothness = 0.0f;
113     // The resource names of the graphics states that apply to this object.
114     std::vector<ByteString> m_GraphicsResourceNames;
115 
116    private:
117     StateData();
118     StateData(const StateData& that);
119     ~StateData() override;
120   };
121 
122   SharedCopyOnWrite<StateData> m_Ref;
123 };
124 
125 #endif  // CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_
126