OLD | NEW |
---|---|
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | |
10 #include "core/fpdfapi/fpdf_render/render_int.h" | |
11 | |
9 namespace { | 12 namespace { |
10 | 13 |
11 int RI_StringToId(const CFX_ByteString& ri) { | 14 int RI_StringToId(const CFX_ByteString& ri) { |
12 uint32_t id = ri.GetID(); | 15 uint32_t id = ri.GetID(); |
13 if (id == FXBSTR_ID('A', 'b', 's', 'o')) | 16 if (id == FXBSTR_ID('A', 'b', 's', 'o')) |
14 return 1; | 17 return 1; |
15 | 18 |
16 if (id == FXBSTR_ID('S', 'a', 't', 'u')) | 19 if (id == FXBSTR_ID('S', 'a', 't', 'u')) |
17 return 2; | 20 return 2; |
18 | 21 |
19 if (id == FXBSTR_ID('P', 'e', 'r', 'c')) | 22 if (id == FXBSTR_ID('P', 'e', 'r', 'c')) |
20 return 3; | 23 return 3; |
21 | 24 |
22 return 0; | 25 return 0; |
23 } | 26 } |
24 | 27 |
28 static int GetBlendTypeInternal(const CFX_ByteStringC& mode) { | |
29 switch (mode.GetID()) { | |
30 case FXBSTR_ID('N', 'o', 'r', 'm'): | |
31 case FXBSTR_ID('C', 'o', 'm', 'p'): | |
32 return FXDIB_BLEND_NORMAL; | |
33 case FXBSTR_ID('M', 'u', 'l', 't'): | |
34 return FXDIB_BLEND_MULTIPLY; | |
35 case FXBSTR_ID('S', 'c', 'r', 'e'): | |
36 return FXDIB_BLEND_SCREEN; | |
37 case FXBSTR_ID('O', 'v', 'e', 'r'): | |
38 return FXDIB_BLEND_OVERLAY; | |
39 case FXBSTR_ID('D', 'a', 'r', 'k'): | |
40 return FXDIB_BLEND_DARKEN; | |
41 case FXBSTR_ID('L', 'i', 'g', 'h'): | |
42 return FXDIB_BLEND_LIGHTEN; | |
43 case FXBSTR_ID('C', 'o', 'l', 'o'): | |
44 if (mode.GetLength() == 10) | |
45 return FXDIB_BLEND_COLORDODGE; | |
46 if (mode.GetLength() == 9) | |
47 return FXDIB_BLEND_COLORBURN; | |
48 return FXDIB_BLEND_COLOR; | |
49 case FXBSTR_ID('H', 'a', 'r', 'd'): | |
50 return FXDIB_BLEND_HARDLIGHT; | |
51 case FXBSTR_ID('S', 'o', 'f', 't'): | |
52 return FXDIB_BLEND_SOFTLIGHT; | |
53 case FXBSTR_ID('D', 'i', 'f', 'f'): | |
54 return FXDIB_BLEND_DIFFERENCE; | |
55 case FXBSTR_ID('E', 'x', 'c', 'l'): | |
56 return FXDIB_BLEND_EXCLUSION; | |
57 case FXBSTR_ID('H', 'u', 'e', 0): | |
58 return FXDIB_BLEND_HUE; | |
59 case FXBSTR_ID('S', 'a', 't', 'u'): | |
60 return FXDIB_BLEND_SATURATION; | |
61 case FXBSTR_ID('L', 'u', 'm', 'i'): | |
62 return FXDIB_BLEND_LUMINOSITY; | |
63 } | |
64 return FXDIB_BLEND_NORMAL; | |
65 } | |
66 | |
25 } // namespace | 67 } // namespace |
26 | 68 |
27 CPDF_GeneralState::CPDF_GeneralState() {} | 69 CPDF_GeneralState::CPDF_GeneralState() {} |
28 | 70 |
29 CPDF_GeneralState::CPDF_GeneralState(const CPDF_GeneralState& that) | 71 CPDF_GeneralState::CPDF_GeneralState(const CPDF_GeneralState& that) |
30 : m_Ref(that.m_Ref) {} | 72 : m_Ref(that.m_Ref) {} |
31 | 73 |
32 CPDF_GeneralState::~CPDF_GeneralState() {} | 74 CPDF_GeneralState::~CPDF_GeneralState() {} |
33 | 75 |
76 int CPDF_GeneralState::GetBlendType() const { | |
77 const StateData* pData = m_Ref.GetObject(); | |
78 return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL; | |
79 } | |
80 | |
81 void CPDF_GeneralState::SetBlendType(int type) { | |
82 m_Ref.GetPrivateCopy()->m_BlendType = type; | |
83 } | |
84 | |
85 int CPDF_GeneralState::GetFillAlpha() const { | |
86 const StateData* pData = m_Ref.GetObject(); | |
87 return pData ? FXSYS_round(255 * pData->m_FillAlpha) : 255; | |
88 } | |
89 | |
90 int CPDF_GeneralState::GetStrokeAlpha() const { | |
91 const StateData* pData = m_Ref.GetObject(); | |
92 return pData ? FXSYS_round(255 * pData->m_StrokeAlpha) : 255; | |
93 } | |
94 | |
95 void CPDF_GeneralState::SetSoftMask(CPDF_Object* pObject) { | |
96 m_Ref.GetPrivateCopy()->m_pSoftMask = pObject; | |
97 } | |
98 | |
99 CPDF_Object* CPDF_GeneralState::GetSoftMask() const { | |
100 const StateData* pData = m_Ref.GetObject(); | |
101 return pData ? pData->m_pSoftMask : nullptr; | |
102 } | |
103 | |
104 void CPDF_GeneralState::SetTR(CPDF_Object* pObject) { | |
105 m_Ref.GetPrivateCopy()->m_pTR = pObject; | |
106 } | |
107 | |
108 CPDF_Object* CPDF_GeneralState::GetTR() const { | |
109 return m_Ref.GetObject()->m_pTR; | |
110 } | |
111 | |
112 void CPDF_GeneralState::SetTransferFunc(CPDF_TransferFunc* pFunc) { | |
113 m_Ref.GetPrivateCopy()->m_pTransferFunc = pFunc; | |
114 } | |
115 | |
116 CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const { | |
117 return m_Ref.GetObject()->m_pTransferFunc; | |
118 } | |
119 | |
120 void CPDF_GeneralState::SetBlendMode(const CFX_ByteStringC& mode) { | |
121 m_Ref.GetPrivateCopy()->SetBlendMode(mode); | |
122 } | |
123 | |
124 const FX_FLOAT* CPDF_GeneralState::GetSMaskMatrix() const { | |
125 return m_Ref.GetObject()->m_SMaskMatrix; | |
126 } | |
127 | |
128 FX_FLOAT* CPDF_GeneralState::GetMutableSMaskMatrix() { | |
129 return m_Ref.GetPrivateCopy()->m_SMaskMatrix; | |
130 } | |
131 | |
132 void CPDF_GeneralState::SetStrokeAlpha(FX_FLOAT alpha) { | |
133 m_Ref.GetPrivateCopy()->m_StrokeAlpha = alpha; | |
134 } | |
135 | |
136 void CPDF_GeneralState::SetFillAlpha(FX_FLOAT alpha) { | |
137 m_Ref.GetPrivateCopy()->m_FillAlpha = alpha; | |
138 } | |
139 | |
140 void CPDF_GeneralState::SetFillOP(int op) { | |
141 m_Ref.GetPrivateCopy()->m_FillOP = op; | |
142 } | |
143 | |
144 int CPDF_GeneralState::GetFillOP() const { | |
145 return m_Ref.GetObject()->m_FillOP; | |
146 } | |
147 | |
148 void CPDF_GeneralState::SetStrokeOP(int op) { | |
149 m_Ref.GetPrivateCopy()->m_StrokeOP = op; | |
150 } | |
151 | |
152 int CPDF_GeneralState::GetStrokeOP() const { | |
153 return m_Ref.GetObject()->m_StrokeOP; | |
154 } | |
155 | |
156 void CPDF_GeneralState::SetOPMode(int mode) { | |
157 m_Ref.GetPrivateCopy()->m_OPMode = mode; | |
158 } | |
159 | |
160 int CPDF_GeneralState::GetOPMode() const { | |
161 return m_Ref.GetObject()->m_OPMode; | |
162 } | |
163 | |
164 void CPDF_GeneralState::SetBG(CPDF_Object* pObject) { | |
165 m_Ref.GetPrivateCopy()->m_pBG = pObject; | |
166 } | |
167 | |
168 void CPDF_GeneralState::SetUCR(CPDF_Object* pObject) { | |
169 m_Ref.GetPrivateCopy()->m_pUCR = pObject; | |
170 } | |
171 | |
172 void CPDF_GeneralState::SetHT(CPDF_Object* pObject) { | |
173 m_Ref.GetPrivateCopy()->m_pHT = pObject; | |
174 } | |
175 | |
176 void CPDF_GeneralState::SetFlatness(FX_FLOAT flatness) { | |
177 m_Ref.GetPrivateCopy()->m_Flatness = flatness; | |
178 } | |
179 | |
180 void CPDF_GeneralState::SetSmoothness(FX_FLOAT smoothness) { | |
181 m_Ref.GetPrivateCopy()->m_Smoothness = smoothness; | |
182 } | |
183 | |
184 void CPDF_GeneralState::SetStrokeAdjust(FX_FLOAT adjust) { | |
185 m_Ref.GetPrivateCopy()->m_StrokeAdjust = adjust; | |
186 } | |
187 | |
188 FX_FLOAT CPDF_GeneralState::GetStrokeAdjust() const { | |
189 return m_Ref.GetObject()->m_StrokeAdjust; | |
190 } | |
191 | |
192 void CPDF_GeneralState::SetAlphaSource(int source) { | |
193 m_Ref.GetPrivateCopy()->m_AlphaSource = source; | |
194 } | |
195 | |
196 void CPDF_GeneralState::SetTextKnockout(int knockout) { | |
197 m_Ref.GetPrivateCopy()->m_TextKnockout = knockout; | |
198 } | |
199 | |
200 void CPDF_GeneralState::SetMatrix(const CFX_Matrix& matrix) { | |
201 m_Ref.GetPrivateCopy()->m_Matrix = matrix; | |
202 } | |
203 | |
204 CFX_Matrix* CPDF_GeneralState::GetMutableMatrix() { | |
205 return &m_Ref.GetPrivateCopy()->m_Matrix; | |
206 } | |
207 | |
34 void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { | 208 void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { |
35 m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); | 209 m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); |
36 } | 210 } |
211 | |
212 CPDF_GeneralState::StateData::StateData() { | |
213 FXSYS_memset(this, 0, sizeof(CPDF_GeneralState::StateData)); | |
214 FXSYS_strcpy((FX_CHAR*)m_BlendMode, "Normal"); | |
dsinclair
2016/09/01 14:17:09
static_cast
Tom Sepez
2016/09/01 22:26:31
rewrote to use bytstrings
| |
215 m_StrokeAlpha = 1.0f; | |
216 m_FillAlpha = 1.0f; | |
217 m_Flatness = 1.0f; | |
218 m_Matrix.SetIdentity(); | |
219 } | |
220 | |
221 CPDF_GeneralState::StateData::StateData( | |
222 const CPDF_GeneralState::StateData& src) { | |
223 FXSYS_memcpy(this, &src, sizeof(CPDF_GeneralState::StateData)); | |
224 if (src.m_pTransferFunc && src.m_pTransferFunc->m_pPDFDoc) { | |
dsinclair
2016/09/01 14:17:09
invert and early return?
Tom Sepez
2016/09/01 22:26:31
Nah, but invert inner if.
| |
225 CPDF_DocRenderData* pDocCache = | |
226 src.m_pTransferFunc->m_pPDFDoc->GetRenderData(); | |
227 if (!pDocCache) | |
228 return; | |
229 | |
230 m_pTransferFunc = pDocCache->GetTransferFunc(m_pTR); | |
231 } | |
232 } | |
233 | |
234 CPDF_GeneralState::StateData::~StateData() { | |
235 if (m_pTransferFunc && m_pTransferFunc->m_pPDFDoc) { | |
dsinclair
2016/09/01 14:17:09
early return
Tom Sepez
2016/09/01 22:26:31
Same.
| |
236 CPDF_DocRenderData* pDocCache = m_pTransferFunc->m_pPDFDoc->GetRenderData(); | |
237 if (!pDocCache) | |
238 return; | |
239 | |
240 pDocCache->ReleaseTransferFunc(m_pTR); | |
241 } | |
242 } | |
243 | |
244 void CPDF_GeneralState::StateData::SetBlendMode( | |
245 const CFX_ByteStringC& blend_mode) { | |
246 if (blend_mode.GetLength() > 15) { | |
247 return; | |
248 } | |
dsinclair
2016/09/01 14:17:09
nit {}'s
Tom Sepez
2016/09/01 22:26:31
No longer exists.
| |
249 FXSYS_memcpy(m_BlendMode, blend_mode.raw_str(), blend_mode.GetLength()); | |
250 m_BlendMode[blend_mode.GetLength()] = 0; | |
251 m_BlendType = GetBlendTypeInternal(blend_mode); | |
252 } | |
OLD | NEW |