Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_generalstate.cpp

Issue 2386423004: Move core/fpdfapi/fpdf_page to core/fpdfapi/page (Closed)
Patch Set: Rebase to master Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_generalstate.h ('k') | core/fpdfapi/fpdf_page/cpdf_graphicstates.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "core/fpdfapi/fpdf_page/cpdf_generalstate.h"
8
9 #include "core/fpdfapi/fpdf_parser/cpdf_document.h"
10 #include "core/fpdfapi/fpdf_render/render_int.h"
11
12 namespace {
13
14 int RI_StringToId(const CFX_ByteString& ri) {
15 uint32_t id = ri.GetID();
16 if (id == FXBSTR_ID('A', 'b', 's', 'o'))
17 return 1;
18
19 if (id == FXBSTR_ID('S', 'a', 't', 'u'))
20 return 2;
21
22 if (id == FXBSTR_ID('P', 'e', 'r', 'c'))
23 return 3;
24
25 return 0;
26 }
27
28 int GetBlendTypeInternal(const CFX_ByteString& 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
67 } // namespace
68
69 CPDF_GeneralState::CPDF_GeneralState() {}
70
71 CPDF_GeneralState::CPDF_GeneralState(const CPDF_GeneralState& that)
72 : m_Ref(that.m_Ref) {}
73
74 CPDF_GeneralState::~CPDF_GeneralState() {}
75
76 void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) {
77 m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri);
78 }
79
80 int CPDF_GeneralState::GetBlendType() const {
81 const StateData* pData = m_Ref.GetObject();
82 return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL;
83 }
84
85 void CPDF_GeneralState::SetBlendType(int type) {
86 m_Ref.GetPrivateCopy()->m_BlendType = type;
87 }
88
89 FX_FLOAT CPDF_GeneralState::GetFillAlpha() const {
90 const StateData* pData = m_Ref.GetObject();
91 return pData ? pData->m_FillAlpha : 1.0f;
92 }
93
94 void CPDF_GeneralState::SetFillAlpha(FX_FLOAT alpha) {
95 m_Ref.GetPrivateCopy()->m_FillAlpha = alpha;
96 }
97
98 FX_FLOAT CPDF_GeneralState::GetStrokeAlpha() const {
99 const StateData* pData = m_Ref.GetObject();
100 return pData ? pData->m_StrokeAlpha : 1.0f;
101 }
102
103 void CPDF_GeneralState::SetStrokeAlpha(FX_FLOAT alpha) {
104 m_Ref.GetPrivateCopy()->m_StrokeAlpha = alpha;
105 }
106
107 CPDF_Object* CPDF_GeneralState::GetSoftMask() const {
108 const StateData* pData = m_Ref.GetObject();
109 return pData ? pData->m_pSoftMask : nullptr;
110 }
111
112 void CPDF_GeneralState::SetSoftMask(CPDF_Object* pObject) {
113 m_Ref.GetPrivateCopy()->m_pSoftMask = pObject;
114 }
115
116 CPDF_Object* CPDF_GeneralState::GetTR() const {
117 const StateData* pData = m_Ref.GetObject();
118 return pData ? pData->m_pTR : nullptr;
119 }
120
121 void CPDF_GeneralState::SetTR(CPDF_Object* pObject) {
122 m_Ref.GetPrivateCopy()->m_pTR = pObject;
123 }
124
125 CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const {
126 const StateData* pData = m_Ref.GetObject();
127 return pData ? pData->m_pTransferFunc : nullptr;
128 }
129
130 void CPDF_GeneralState::SetTransferFunc(CPDF_TransferFunc* pFunc) {
131 m_Ref.GetPrivateCopy()->m_pTransferFunc = pFunc;
132 }
133
134 void CPDF_GeneralState::SetBlendMode(const CFX_ByteString& mode) {
135 StateData* pData = m_Ref.GetPrivateCopy();
136 pData->m_BlendMode = mode;
137 pData->m_BlendType = GetBlendTypeInternal(mode);
138 }
139
140 const CFX_Matrix* CPDF_GeneralState::GetSMaskMatrix() const {
141 const StateData* pData = m_Ref.GetObject();
142 return pData ? &pData->m_SMaskMatrix : nullptr;
143 }
144
145 void CPDF_GeneralState::SetSMaskMatrix(const CFX_Matrix& matrix) {
146 m_Ref.GetPrivateCopy()->m_SMaskMatrix = matrix;
147 }
148
149 bool CPDF_GeneralState::GetFillOP() const {
150 const StateData* pData = m_Ref.GetObject();
151 return pData && pData->m_FillOP;
152 }
153
154 void CPDF_GeneralState::SetFillOP(bool op) {
155 m_Ref.GetPrivateCopy()->m_FillOP = op;
156 }
157
158 void CPDF_GeneralState::SetStrokeOP(bool op) {
159 m_Ref.GetPrivateCopy()->m_StrokeOP = op;
160 }
161
162 bool CPDF_GeneralState::GetStrokeOP() const {
163 const StateData* pData = m_Ref.GetObject();
164 return pData && pData->m_StrokeOP;
165 }
166
167 int CPDF_GeneralState::GetOPMode() const {
168 return m_Ref.GetObject()->m_OPMode;
169 }
170
171 void CPDF_GeneralState::SetOPMode(int mode) {
172 m_Ref.GetPrivateCopy()->m_OPMode = mode;
173 }
174
175 void CPDF_GeneralState::SetBG(CPDF_Object* pObject) {
176 m_Ref.GetPrivateCopy()->m_pBG = pObject;
177 }
178
179 void CPDF_GeneralState::SetUCR(CPDF_Object* pObject) {
180 m_Ref.GetPrivateCopy()->m_pUCR = pObject;
181 }
182
183 void CPDF_GeneralState::SetHT(CPDF_Object* pObject) {
184 m_Ref.GetPrivateCopy()->m_pHT = pObject;
185 }
186
187 void CPDF_GeneralState::SetFlatness(FX_FLOAT flatness) {
188 m_Ref.GetPrivateCopy()->m_Flatness = flatness;
189 }
190
191 void CPDF_GeneralState::SetSmoothness(FX_FLOAT smoothness) {
192 m_Ref.GetPrivateCopy()->m_Smoothness = smoothness;
193 }
194
195 bool CPDF_GeneralState::GetStrokeAdjust() const {
196 const StateData* pData = m_Ref.GetObject();
197 return pData && pData->m_StrokeAdjust;
198 }
199
200 void CPDF_GeneralState::SetStrokeAdjust(bool adjust) {
201 m_Ref.GetPrivateCopy()->m_StrokeAdjust = adjust;
202 }
203
204 void CPDF_GeneralState::SetAlphaSource(bool source) {
205 m_Ref.GetPrivateCopy()->m_AlphaSource = source;
206 }
207
208 void CPDF_GeneralState::SetTextKnockout(bool knockout) {
209 m_Ref.GetPrivateCopy()->m_TextKnockout = knockout;
210 }
211
212 void CPDF_GeneralState::SetMatrix(const CFX_Matrix& matrix) {
213 m_Ref.GetPrivateCopy()->m_Matrix = matrix;
214 }
215
216 CFX_Matrix* CPDF_GeneralState::GetMutableMatrix() {
217 return &m_Ref.GetPrivateCopy()->m_Matrix;
218 }
219
220 CPDF_GeneralState::StateData::StateData()
221 : m_BlendMode("Normal"),
222 m_BlendType(0),
223 m_pSoftMask(nullptr),
224 m_StrokeAlpha(1.0),
225 m_FillAlpha(1.0f),
226 m_pTR(nullptr),
227 m_pTransferFunc(nullptr),
228 m_RenderIntent(0),
229 m_StrokeAdjust(false),
230 m_AlphaSource(false),
231 m_TextKnockout(false),
232 m_StrokeOP(false),
233 m_FillOP(false),
234 m_OPMode(0),
235 m_pBG(nullptr),
236 m_pUCR(nullptr),
237 m_pHT(nullptr),
238 m_Flatness(1.0f),
239 m_Smoothness(0.0f) {
240 m_SMaskMatrix.SetIdentity();
241 m_Matrix.SetIdentity();
242 }
243
244 CPDF_GeneralState::StateData::StateData(const StateData& that)
245 : m_BlendMode(that.m_BlendMode),
246 m_BlendType(that.m_BlendType),
247 m_pSoftMask(that.m_pSoftMask),
248 m_StrokeAlpha(that.m_StrokeAlpha),
249 m_FillAlpha(that.m_FillAlpha),
250 m_pTR(that.m_pTR),
251 m_pTransferFunc(that.m_pTransferFunc),
252 m_RenderIntent(that.m_RenderIntent),
253 m_StrokeAdjust(that.m_StrokeAdjust),
254 m_AlphaSource(that.m_AlphaSource),
255 m_TextKnockout(that.m_TextKnockout),
256 m_StrokeOP(that.m_StrokeOP),
257 m_FillOP(that.m_FillOP),
258 m_OPMode(that.m_OPMode),
259 m_pBG(that.m_pBG),
260 m_pUCR(that.m_pUCR),
261 m_pHT(that.m_pHT),
262 m_Flatness(that.m_Flatness),
263 m_Smoothness(that.m_Smoothness) {
264 m_Matrix = that.m_Matrix;
265 m_SMaskMatrix = that.m_SMaskMatrix;
266
267 if (that.m_pTransferFunc && that.m_pTransferFunc->m_pPDFDoc) {
268 CPDF_DocRenderData* pDocCache =
269 that.m_pTransferFunc->m_pPDFDoc->GetRenderData();
270 if (pDocCache)
271 m_pTransferFunc = pDocCache->GetTransferFunc(m_pTR);
272 }
273 }
274
275 CPDF_GeneralState::StateData::~StateData() {
276 if (m_pTransferFunc && m_pTransferFunc->m_pPDFDoc) {
277 CPDF_DocRenderData* pDocCache = m_pTransferFunc->m_pPDFDoc->GetRenderData();
278 if (pDocCache)
279 pDocCache->ReleaseTransferFunc(m_pTR);
280 }
281 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_generalstate.h ('k') | core/fpdfapi/fpdf_page/cpdf_graphicstates.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698