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 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 |
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 |
34 void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { | 76 void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { |
35 m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); | 77 m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); |
36 } | 78 } |
37 | 79 |
38 int CPDF_GeneralState::GetBlendType() const { | 80 int CPDF_GeneralState::GetBlendType() const { |
39 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 81 const StateData* pData = m_Ref.GetObject(); |
40 return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL; | 82 return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL; |
41 } | 83 } |
42 | 84 |
43 void CPDF_GeneralState::SetBlendType(int type) { | 85 void CPDF_GeneralState::SetBlendType(int type) { |
44 m_Ref.GetPrivateCopy()->m_BlendType = type; | 86 m_Ref.GetPrivateCopy()->m_BlendType = type; |
45 } | 87 } |
46 | 88 |
47 FX_FLOAT CPDF_GeneralState::GetFillAlpha() const { | 89 FX_FLOAT CPDF_GeneralState::GetFillAlpha() const { |
48 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 90 const StateData* pData = m_Ref.GetObject(); |
49 return pData ? pData->m_FillAlpha : 1.0f; | 91 return pData ? pData->m_FillAlpha : 1.0f; |
50 } | 92 } |
51 | 93 |
52 void CPDF_GeneralState::SetFillAlpha(FX_FLOAT alpha) { | 94 void CPDF_GeneralState::SetFillAlpha(FX_FLOAT alpha) { |
53 m_Ref.GetPrivateCopy()->m_FillAlpha = alpha; | 95 m_Ref.GetPrivateCopy()->m_FillAlpha = alpha; |
54 } | 96 } |
55 | 97 |
56 FX_FLOAT CPDF_GeneralState::GetStrokeAlpha() const { | 98 FX_FLOAT CPDF_GeneralState::GetStrokeAlpha() const { |
57 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 99 const StateData* pData = m_Ref.GetObject(); |
58 return pData ? pData->m_StrokeAlpha : 1.0f; | 100 return pData ? pData->m_StrokeAlpha : 1.0f; |
59 } | 101 } |
60 | 102 |
61 void CPDF_GeneralState::SetStrokeAlpha(FX_FLOAT alpha) { | 103 void CPDF_GeneralState::SetStrokeAlpha(FX_FLOAT alpha) { |
62 m_Ref.GetPrivateCopy()->m_StrokeAlpha = alpha; | 104 m_Ref.GetPrivateCopy()->m_StrokeAlpha = alpha; |
63 } | 105 } |
64 | 106 |
65 CPDF_Object* CPDF_GeneralState::GetSoftMask() const { | 107 CPDF_Object* CPDF_GeneralState::GetSoftMask() const { |
66 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 108 const StateData* pData = m_Ref.GetObject(); |
67 return pData ? pData->m_pSoftMask : nullptr; | 109 return pData ? pData->m_pSoftMask : nullptr; |
68 } | 110 } |
69 | 111 |
70 void CPDF_GeneralState::SetSoftMask(CPDF_Object* pObject) { | 112 void CPDF_GeneralState::SetSoftMask(CPDF_Object* pObject) { |
71 m_Ref.GetPrivateCopy()->m_pSoftMask = pObject; | 113 m_Ref.GetPrivateCopy()->m_pSoftMask = pObject; |
72 } | 114 } |
73 | 115 |
74 CPDF_Object* CPDF_GeneralState::GetTR() const { | 116 CPDF_Object* CPDF_GeneralState::GetTR() const { |
75 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 117 const StateData* pData = m_Ref.GetObject(); |
76 return pData ? pData->m_pTR : nullptr; | 118 return pData ? pData->m_pTR : nullptr; |
77 } | 119 } |
78 | 120 |
79 void CPDF_GeneralState::SetTR(CPDF_Object* pObject) { | 121 void CPDF_GeneralState::SetTR(CPDF_Object* pObject) { |
80 m_Ref.GetPrivateCopy()->m_pTR = pObject; | 122 m_Ref.GetPrivateCopy()->m_pTR = pObject; |
81 } | 123 } |
82 | 124 |
83 CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const { | 125 CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const { |
84 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 126 const StateData* pData = m_Ref.GetObject(); |
85 return pData ? pData->m_pTransferFunc : nullptr; | 127 return pData ? pData->m_pTransferFunc : nullptr; |
86 } | 128 } |
87 | 129 |
88 void CPDF_GeneralState::SetTransferFunc(CPDF_TransferFunc* pFunc) { | 130 void CPDF_GeneralState::SetTransferFunc(CPDF_TransferFunc* pFunc) { |
89 m_Ref.GetPrivateCopy()->m_pTransferFunc = pFunc; | 131 m_Ref.GetPrivateCopy()->m_pTransferFunc = pFunc; |
90 } | 132 } |
91 | 133 |
92 void CPDF_GeneralState::SetBlendMode(const CFX_ByteStringC& mode) { | 134 void CPDF_GeneralState::SetBlendMode(const CFX_ByteString& mode) { |
93 m_Ref.GetPrivateCopy()->SetBlendMode(mode); | 135 StateData* pData = m_Ref.GetPrivateCopy(); |
| 136 pData->m_BlendMode = mode; |
| 137 pData->m_BlendType = GetBlendTypeInternal(mode); |
94 } | 138 } |
95 | 139 |
96 const FX_FLOAT* CPDF_GeneralState::GetSMaskMatrix() const { | 140 const CFX_Matrix* CPDF_GeneralState::GetSMaskMatrix() const { |
97 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 141 const StateData* pData = m_Ref.GetObject(); |
98 return pData ? pData->m_SMaskMatrix : nullptr; | 142 return pData ? &pData->m_SMaskMatrix : nullptr; |
99 } | 143 } |
100 | 144 |
101 FX_FLOAT* CPDF_GeneralState::GetMutableSMaskMatrix() { | 145 void CPDF_GeneralState::SetSMaskMatrix(const CFX_Matrix& matrix) { |
102 return m_Ref.GetPrivateCopy()->m_SMaskMatrix; | 146 m_Ref.GetPrivateCopy()->m_SMaskMatrix = matrix; |
103 } | 147 } |
104 | 148 |
105 bool CPDF_GeneralState::GetFillOP() const { | 149 bool CPDF_GeneralState::GetFillOP() const { |
106 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 150 const StateData* pData = m_Ref.GetObject(); |
107 return pData && pData->m_FillOP; | 151 return pData && pData->m_FillOP; |
108 } | 152 } |
109 | 153 |
110 void CPDF_GeneralState::SetFillOP(bool op) { | 154 void CPDF_GeneralState::SetFillOP(bool op) { |
111 m_Ref.GetPrivateCopy()->m_FillOP = op; | 155 m_Ref.GetPrivateCopy()->m_FillOP = op; |
112 } | 156 } |
113 | 157 |
114 void CPDF_GeneralState::SetStrokeOP(bool op) { | 158 void CPDF_GeneralState::SetStrokeOP(bool op) { |
115 m_Ref.GetPrivateCopy()->m_StrokeOP = op; | 159 m_Ref.GetPrivateCopy()->m_StrokeOP = op; |
116 } | 160 } |
117 | 161 |
118 bool CPDF_GeneralState::GetStrokeOP() const { | 162 bool CPDF_GeneralState::GetStrokeOP() const { |
119 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 163 const StateData* pData = m_Ref.GetObject(); |
120 return pData && pData->m_StrokeOP; | 164 return pData && pData->m_StrokeOP; |
121 } | 165 } |
122 | 166 |
123 int CPDF_GeneralState::GetOPMode() const { | 167 int CPDF_GeneralState::GetOPMode() const { |
124 return m_Ref.GetObject()->m_OPMode; | 168 return m_Ref.GetObject()->m_OPMode; |
125 } | 169 } |
126 | 170 |
127 void CPDF_GeneralState::SetOPMode(int mode) { | 171 void CPDF_GeneralState::SetOPMode(int mode) { |
128 m_Ref.GetPrivateCopy()->m_OPMode = mode; | 172 m_Ref.GetPrivateCopy()->m_OPMode = mode; |
129 } | 173 } |
(...skipping 12 matching lines...) Expand all Loading... |
142 | 186 |
143 void CPDF_GeneralState::SetFlatness(FX_FLOAT flatness) { | 187 void CPDF_GeneralState::SetFlatness(FX_FLOAT flatness) { |
144 m_Ref.GetPrivateCopy()->m_Flatness = flatness; | 188 m_Ref.GetPrivateCopy()->m_Flatness = flatness; |
145 } | 189 } |
146 | 190 |
147 void CPDF_GeneralState::SetSmoothness(FX_FLOAT smoothness) { | 191 void CPDF_GeneralState::SetSmoothness(FX_FLOAT smoothness) { |
148 m_Ref.GetPrivateCopy()->m_Smoothness = smoothness; | 192 m_Ref.GetPrivateCopy()->m_Smoothness = smoothness; |
149 } | 193 } |
150 | 194 |
151 bool CPDF_GeneralState::GetStrokeAdjust() const { | 195 bool CPDF_GeneralState::GetStrokeAdjust() const { |
152 const CPDF_GeneralStateData* pData = m_Ref.GetObject(); | 196 const StateData* pData = m_Ref.GetObject(); |
153 return pData && pData->m_StrokeAdjust; | 197 return pData && pData->m_StrokeAdjust; |
154 } | 198 } |
155 | 199 |
156 void CPDF_GeneralState::SetStrokeAdjust(bool adjust) { | 200 void CPDF_GeneralState::SetStrokeAdjust(bool adjust) { |
157 m_Ref.GetPrivateCopy()->m_StrokeAdjust = adjust; | 201 m_Ref.GetPrivateCopy()->m_StrokeAdjust = adjust; |
158 } | 202 } |
159 | 203 |
160 void CPDF_GeneralState::SetAlphaSource(bool source) { | 204 void CPDF_GeneralState::SetAlphaSource(bool source) { |
161 m_Ref.GetPrivateCopy()->m_AlphaSource = source; | 205 m_Ref.GetPrivateCopy()->m_AlphaSource = source; |
162 } | 206 } |
163 | 207 |
164 void CPDF_GeneralState::SetTextKnockout(bool knockout) { | 208 void CPDF_GeneralState::SetTextKnockout(bool knockout) { |
165 m_Ref.GetPrivateCopy()->m_TextKnockout = knockout; | 209 m_Ref.GetPrivateCopy()->m_TextKnockout = knockout; |
166 } | 210 } |
167 | 211 |
168 void CPDF_GeneralState::SetMatrix(const CFX_Matrix& matrix) { | 212 void CPDF_GeneralState::SetMatrix(const CFX_Matrix& matrix) { |
169 m_Ref.GetPrivateCopy()->m_Matrix = matrix; | 213 m_Ref.GetPrivateCopy()->m_Matrix = matrix; |
170 } | 214 } |
171 | 215 |
172 CFX_Matrix* CPDF_GeneralState::GetMutableMatrix() { | 216 CFX_Matrix* CPDF_GeneralState::GetMutableMatrix() { |
173 return &m_Ref.GetPrivateCopy()->m_Matrix; | 217 return &m_Ref.GetPrivateCopy()->m_Matrix; |
174 } | 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 } |
OLD | NEW |