OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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/fxge/include/fx_ge.h" | 7 #include "core/fxge/include/fx_ge.h" |
8 | 8 |
9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ | 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ |
10 | 10 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 if (caps_id == FXDC_VERT_SIZE) | 118 if (caps_id == FXDC_VERT_SIZE) |
119 return m_VertSize; | 119 return m_VertSize; |
120 return CGdiDeviceDriver::GetDeviceCaps(caps_id); | 120 return CGdiDeviceDriver::GetDeviceCaps(caps_id); |
121 } | 121 } |
122 | 122 |
123 FX_BOOL CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource, | 123 FX_BOOL CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource, |
124 uint32_t color, | 124 uint32_t color, |
125 const FX_RECT* pSrcRect, | 125 const FX_RECT* pSrcRect, |
126 int left, | 126 int left, |
127 int top, | 127 int top, |
128 int blend_type, | 128 int blend_type) { |
129 int alpha_flag, | |
130 void* pIccTransform) { | |
131 if (pSource->IsAlphaMask()) { | 129 if (pSource->IsAlphaMask()) { |
132 FX_RECT clip_rect(left, top, left + pSrcRect->Width(), | 130 FX_RECT clip_rect(left, top, left + pSrcRect->Width(), |
133 top + pSrcRect->Height()); | 131 top + pSrcRect->Height()); |
134 return StretchDIBits(pSource, color, left - pSrcRect->left, | 132 return StretchDIBits(pSource, color, left - pSrcRect->left, |
135 top - pSrcRect->top, pSource->GetWidth(), | 133 top - pSrcRect->top, pSource->GetWidth(), |
136 pSource->GetHeight(), &clip_rect, 0, alpha_flag, | 134 pSource->GetHeight(), &clip_rect, 0, |
137 pIccTransform, FXDIB_BLEND_NORMAL); | 135 FXDIB_BLEND_NORMAL); |
138 } | 136 } |
139 ASSERT(pSource && !pSource->IsAlphaMask() && pSrcRect); | 137 ASSERT(pSource && !pSource->IsAlphaMask() && pSrcRect); |
140 ASSERT(blend_type == FXDIB_BLEND_NORMAL); | 138 ASSERT(blend_type == FXDIB_BLEND_NORMAL); |
141 if (pSource->HasAlpha()) | 139 if (pSource->HasAlpha()) |
142 return FALSE; | 140 return FALSE; |
143 | 141 |
144 CFX_DIBExtractor temp(pSource); | 142 CFX_DIBExtractor temp(pSource); |
145 CFX_DIBitmap* pBitmap = temp; | 143 CFX_DIBitmap* pBitmap = temp; |
146 if (!pBitmap) | 144 if (!pBitmap) |
147 return FALSE; | 145 return FALSE; |
148 | 146 |
149 return GDI_SetDIBits(pBitmap, pSrcRect, left, top, pIccTransform); | 147 return GDI_SetDIBits(pBitmap, pSrcRect, left, top, nullptr); |
150 } | 148 } |
151 | 149 |
152 FX_BOOL CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource, | 150 FX_BOOL CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource, |
153 uint32_t color, | 151 uint32_t color, |
154 int dest_left, | 152 int dest_left, |
155 int dest_top, | 153 int dest_top, |
156 int dest_width, | 154 int dest_width, |
157 int dest_height, | 155 int dest_height, |
158 const FX_RECT* pClipRect, | 156 const FX_RECT* pClipRect, |
159 uint32_t flags, | 157 uint32_t flags, |
160 int alpha_flag, | |
161 void* pIccTransform, | |
162 int blend_type) { | 158 int blend_type) { |
163 if (pSource->IsAlphaMask()) { | 159 if (pSource->IsAlphaMask()) { |
164 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 160 int alpha = FXARGB_A(color); |
165 ? FXGETFLAG_ALPHA_FILL(alpha_flag) | |
166 : FXARGB_A(color); | |
167 if (pSource->GetBPP() != 1 || alpha != 255) | 161 if (pSource->GetBPP() != 1 || alpha != 255) |
168 return FALSE; | 162 return FALSE; |
169 | 163 |
170 if (dest_width < 0 || dest_height < 0) { | 164 if (dest_width < 0 || dest_height < 0) { |
171 std::unique_ptr<CFX_DIBitmap> pFlipped( | 165 std::unique_ptr<CFX_DIBitmap> pFlipped( |
172 pSource->FlipImage(dest_width < 0, dest_height < 0)); | 166 pSource->FlipImage(dest_width < 0, dest_height < 0)); |
173 if (!pFlipped) | 167 if (!pFlipped) |
174 return FALSE; | 168 return FALSE; |
175 | 169 |
176 if (dest_width < 0) | 170 if (dest_width < 0) |
177 dest_left += dest_width; | 171 dest_left += dest_width; |
178 if (dest_height < 0) | 172 if (dest_height < 0) |
179 dest_top += dest_height; | 173 dest_top += dest_height; |
180 | 174 |
181 return GDI_StretchBitMask(pFlipped.get(), dest_left, dest_top, | 175 return GDI_StretchBitMask(pFlipped.get(), dest_left, dest_top, |
182 abs(dest_width), abs(dest_height), color, flags, | 176 abs(dest_width), abs(dest_height), color, flags, |
183 alpha_flag, pIccTransform); | 177 0, nullptr); |
184 } | 178 } |
185 | 179 |
186 CFX_DIBExtractor temp(pSource); | 180 CFX_DIBExtractor temp(pSource); |
187 CFX_DIBitmap* pBitmap = temp; | 181 CFX_DIBitmap* pBitmap = temp; |
188 if (!pBitmap) | 182 if (!pBitmap) |
189 return FALSE; | 183 return FALSE; |
190 return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width, | 184 return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width, |
191 dest_height, color, flags, alpha_flag, | 185 dest_height, color, flags, 0, nullptr); |
192 pIccTransform); | |
193 } | 186 } |
194 | 187 |
195 if (pSource->HasAlpha()) | 188 if (pSource->HasAlpha()) |
196 return FALSE; | 189 return FALSE; |
197 | 190 |
198 if (dest_width < 0 || dest_height < 0) { | 191 if (dest_width < 0 || dest_height < 0) { |
199 std::unique_ptr<CFX_DIBitmap> pFlipped( | 192 std::unique_ptr<CFX_DIBitmap> pFlipped( |
200 pSource->FlipImage(dest_width < 0, dest_height < 0)); | 193 pSource->FlipImage(dest_width < 0, dest_height < 0)); |
201 if (!pFlipped) | 194 if (!pFlipped) |
202 return FALSE; | 195 return FALSE; |
203 | 196 |
204 if (dest_width < 0) | 197 if (dest_width < 0) |
205 dest_left += dest_width; | 198 dest_left += dest_width; |
206 if (dest_height < 0) | 199 if (dest_height < 0) |
207 dest_top += dest_height; | 200 dest_top += dest_height; |
208 | 201 |
209 return GDI_StretchDIBits(pFlipped.get(), dest_left, dest_top, | 202 return GDI_StretchDIBits(pFlipped.get(), dest_left, dest_top, |
210 abs(dest_width), abs(dest_height), flags, | 203 abs(dest_width), abs(dest_height), flags, nullptr); |
211 pIccTransform); | |
212 } | 204 } |
213 | 205 |
214 CFX_DIBExtractor temp(pSource); | 206 CFX_DIBExtractor temp(pSource); |
215 CFX_DIBitmap* pBitmap = temp; | 207 CFX_DIBitmap* pBitmap = temp; |
216 if (!pBitmap) | 208 if (!pBitmap) |
217 return FALSE; | 209 return FALSE; |
218 return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, | 210 return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, |
219 dest_height, flags, pIccTransform); | 211 dest_height, flags, nullptr); |
220 } | 212 } |
221 | 213 |
222 FX_BOOL CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource, | 214 FX_BOOL CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource, |
223 int bitmap_alpha, | 215 int bitmap_alpha, |
224 uint32_t color, | 216 uint32_t color, |
225 const CFX_Matrix* pMatrix, | 217 const CFX_Matrix* pMatrix, |
226 uint32_t render_flags, | 218 uint32_t render_flags, |
227 void*& handle, | 219 void*& handle, |
228 int alpha_flag, | |
229 void* pIccTransform, | |
230 int blend_type) { | 220 int blend_type) { |
231 if (bitmap_alpha < 255 || pSource->HasAlpha() || | 221 if (bitmap_alpha < 255 || pSource->HasAlpha() || |
232 (pSource->IsAlphaMask() && (pSource->GetBPP() != 1))) { | 222 (pSource->IsAlphaMask() && (pSource->GetBPP() != 1))) { |
233 return FALSE; | 223 return FALSE; |
234 } | 224 } |
235 CFX_FloatRect unit_rect = pMatrix->GetUnitRect(); | 225 CFX_FloatRect unit_rect = pMatrix->GetUnitRect(); |
236 FX_RECT full_rect = unit_rect.GetOutterRect(); | 226 FX_RECT full_rect = unit_rect.GetOutterRect(); |
237 if (FXSYS_fabs(pMatrix->b) < 0.5f && pMatrix->a != 0 && | 227 if (FXSYS_fabs(pMatrix->b) < 0.5f && pMatrix->a != 0 && |
238 FXSYS_fabs(pMatrix->c) < 0.5f && pMatrix->d != 0) { | 228 FXSYS_fabs(pMatrix->c) < 0.5f && pMatrix->d != 0) { |
239 FX_BOOL bFlipX = pMatrix->a < 0; | 229 FX_BOOL bFlipX = pMatrix->a < 0; |
240 FX_BOOL bFlipY = pMatrix->d > 0; | 230 FX_BOOL bFlipY = pMatrix->d > 0; |
241 return StretchDIBits(pSource, color, | 231 return StretchDIBits(pSource, color, |
242 bFlipX ? full_rect.right : full_rect.left, | 232 bFlipX ? full_rect.right : full_rect.left, |
243 bFlipY ? full_rect.bottom : full_rect.top, | 233 bFlipY ? full_rect.bottom : full_rect.top, |
244 bFlipX ? -full_rect.Width() : full_rect.Width(), | 234 bFlipX ? -full_rect.Width() : full_rect.Width(), |
245 bFlipY ? -full_rect.Height() : full_rect.Height(), | 235 bFlipY ? -full_rect.Height() : full_rect.Height(), |
246 nullptr, 0, alpha_flag, pIccTransform, blend_type); | 236 nullptr, 0, blend_type); |
247 } | 237 } |
248 if (FXSYS_fabs(pMatrix->a) < 0.5f && FXSYS_fabs(pMatrix->d) < 0.5f) { | 238 if (FXSYS_fabs(pMatrix->a) < 0.5f && FXSYS_fabs(pMatrix->d) < 0.5f) { |
249 std::unique_ptr<CFX_DIBitmap> pTransformed( | 239 std::unique_ptr<CFX_DIBitmap> pTransformed( |
250 pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0)); | 240 pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0)); |
251 if (!pTransformed) | 241 if (!pTransformed) |
252 return FALSE; | 242 return FALSE; |
253 | 243 |
254 return StretchDIBits(pTransformed.get(), color, full_rect.left, | 244 return StretchDIBits(pTransformed.get(), color, full_rect.left, |
255 full_rect.top, full_rect.Width(), full_rect.Height(), | 245 full_rect.top, full_rect.Width(), full_rect.Height(), |
256 nullptr, 0, alpha_flag, pIccTransform, blend_type); | 246 nullptr, 0, blend_type); |
257 } | 247 } |
258 if (pSource->GetBPP() != 1) | 248 return FALSE; |
259 return FALSE; | |
260 | |
261 std::unique_ptr<CFX_DIBitmap> pTransformed( | |
262 Transform1bppBitmap(pSource, pMatrix)); | |
263 if (!pIccTransform) | |
264 return FALSE; | |
265 | |
266 SaveState(); | |
267 CFX_PathData path; | |
268 path.AppendRect(0, 0, 1.0f, 1.0f); | |
269 SetClip_PathFill(&path, pMatrix, WINDING); | |
270 FX_BOOL ret = | |
271 StretchDIBits(pTransformed.get(), color, full_rect.left, full_rect.top, | |
272 full_rect.Width(), full_rect.Height(), nullptr, 0, | |
273 alpha_flag, pIccTransform, blend_type); | |
274 RestoreState(false); | |
275 handle = nullptr; | |
276 return ret; | |
277 } | 249 } |
278 | 250 |
279 #endif | 251 #endif |
OLD | NEW |