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/include/fxge/fx_ge.h" | 7 #include "core/include/fxge/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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 pSource->GetHeight(), &clip_rect, 0, alpha_flag, | 49 pSource->GetHeight(), &clip_rect, 0, alpha_flag, |
50 pIccTransform, FXDIB_BLEND_NORMAL); | 50 pIccTransform, FXDIB_BLEND_NORMAL); |
51 } | 51 } |
52 ASSERT(pSource && !pSource->IsAlphaMask() && pSrcRect); | 52 ASSERT(pSource && !pSource->IsAlphaMask() && pSrcRect); |
53 ASSERT(blend_type == FXDIB_BLEND_NORMAL); | 53 ASSERT(blend_type == FXDIB_BLEND_NORMAL); |
54 if (pSource->HasAlpha()) { | 54 if (pSource->HasAlpha()) { |
55 return FALSE; | 55 return FALSE; |
56 } | 56 } |
57 CFX_DIBExtractor temp(pSource); | 57 CFX_DIBExtractor temp(pSource); |
58 CFX_DIBitmap* pBitmap = temp; | 58 CFX_DIBitmap* pBitmap = temp; |
59 if (pBitmap == NULL) { | 59 if (!pBitmap) { |
60 return FALSE; | 60 return FALSE; |
61 } | 61 } |
62 return GDI_SetDIBits(pBitmap, pSrcRect, left, top, pIccTransform); | 62 return GDI_SetDIBits(pBitmap, pSrcRect, left, top, pIccTransform); |
63 } | 63 } |
64 FX_BOOL CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource, | 64 FX_BOOL CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource, |
65 FX_DWORD color, | 65 FX_DWORD color, |
66 int dest_left, | 66 int dest_left, |
67 int dest_top, | 67 int dest_top, |
68 int dest_width, | 68 int dest_width, |
69 int dest_height, | 69 int dest_height, |
70 const FX_RECT* pClipRect, | 70 const FX_RECT* pClipRect, |
71 FX_DWORD flags, | 71 FX_DWORD flags, |
72 int alpha_flag, | 72 int alpha_flag, |
73 void* pIccTransform, | 73 void* pIccTransform, |
74 int blend_type) { | 74 int blend_type) { |
75 if (pSource->IsAlphaMask()) { | 75 if (pSource->IsAlphaMask()) { |
76 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 76 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) |
77 ? FXGETFLAG_ALPHA_FILL(alpha_flag) | 77 ? FXGETFLAG_ALPHA_FILL(alpha_flag) |
78 : FXARGB_A(color); | 78 : FXARGB_A(color); |
79 if (pSource->GetBPP() != 1 || alpha != 255 || !m_bSupportROP) { | 79 if (pSource->GetBPP() != 1 || alpha != 255 || !m_bSupportROP) { |
80 return FALSE; | 80 return FALSE; |
81 } | 81 } |
82 if (dest_width < 0 || dest_height < 0) { | 82 if (dest_width < 0 || dest_height < 0) { |
83 CFX_DIBitmap* pFlipped = | 83 CFX_DIBitmap* pFlipped = |
84 pSource->FlipImage(dest_width < 0, dest_height < 0); | 84 pSource->FlipImage(dest_width < 0, dest_height < 0); |
85 if (pFlipped == NULL) { | 85 if (!pFlipped) { |
86 return FALSE; | 86 return FALSE; |
87 } | 87 } |
88 if (dest_width < 0) { | 88 if (dest_width < 0) { |
89 dest_left += dest_width; | 89 dest_left += dest_width; |
90 } | 90 } |
91 if (dest_height < 0) { | 91 if (dest_height < 0) { |
92 dest_top += dest_height; | 92 dest_top += dest_height; |
93 } | 93 } |
94 FX_BOOL ret = GDI_StretchBitMask(pFlipped, dest_left, dest_top, | 94 FX_BOOL ret = GDI_StretchBitMask(pFlipped, dest_left, dest_top, |
95 abs(dest_width), abs(dest_height), color, | 95 abs(dest_width), abs(dest_height), color, |
96 flags, alpha_flag, pIccTransform); | 96 flags, alpha_flag, pIccTransform); |
97 delete pFlipped; | 97 delete pFlipped; |
98 return ret; | 98 return ret; |
99 } | 99 } |
100 CFX_DIBExtractor temp(pSource); | 100 CFX_DIBExtractor temp(pSource); |
101 CFX_DIBitmap* pBitmap = temp; | 101 CFX_DIBitmap* pBitmap = temp; |
102 if (pBitmap == NULL) { | 102 if (!pBitmap) { |
103 return FALSE; | 103 return FALSE; |
104 } | 104 } |
105 return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width, | 105 return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width, |
106 dest_height, color, flags, alpha_flag, | 106 dest_height, color, flags, alpha_flag, |
107 pIccTransform); | 107 pIccTransform); |
108 } | 108 } |
109 if (pSource->HasAlpha()) { | 109 if (pSource->HasAlpha()) { |
110 return FALSE; | 110 return FALSE; |
111 } | 111 } |
112 if (dest_width < 0 || dest_height < 0) { | 112 if (dest_width < 0 || dest_height < 0) { |
113 CFX_DIBitmap* pFlipped = | 113 CFX_DIBitmap* pFlipped = |
114 pSource->FlipImage(dest_width < 0, dest_height < 0); | 114 pSource->FlipImage(dest_width < 0, dest_height < 0); |
115 if (pFlipped == NULL) { | 115 if (!pFlipped) { |
116 return FALSE; | 116 return FALSE; |
117 } | 117 } |
118 if (dest_width < 0) { | 118 if (dest_width < 0) { |
119 dest_left += dest_width; | 119 dest_left += dest_width; |
120 } | 120 } |
121 if (dest_height < 0) { | 121 if (dest_height < 0) { |
122 dest_top += dest_height; | 122 dest_top += dest_height; |
123 } | 123 } |
124 FX_BOOL ret = | 124 FX_BOOL ret = |
125 GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width), | 125 GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width), |
126 abs(dest_height), flags, pIccTransform); | 126 abs(dest_height), flags, pIccTransform); |
127 delete pFlipped; | 127 delete pFlipped; |
128 return ret; | 128 return ret; |
129 } | 129 } |
130 CFX_DIBExtractor temp(pSource); | 130 CFX_DIBExtractor temp(pSource); |
131 CFX_DIBitmap* pBitmap = temp; | 131 CFX_DIBitmap* pBitmap = temp; |
132 if (pBitmap == NULL) { | 132 if (!pBitmap) { |
133 return FALSE; | 133 return FALSE; |
134 } | 134 } |
135 return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, | 135 return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, |
136 dest_height, flags, pIccTransform); | 136 dest_height, flags, pIccTransform); |
137 } | 137 } |
138 static CFX_DIBitmap* Transform1bppBitmap(const CFX_DIBSource* pSrc, | 138 static CFX_DIBitmap* Transform1bppBitmap(const CFX_DIBSource* pSrc, |
139 const CFX_Matrix* pDestMatrix) { | 139 const CFX_Matrix* pDestMatrix) { |
140 ASSERT(pSrc->GetFormat() == FXDIB_1bppRgb || | 140 ASSERT(pSrc->GetFormat() == FXDIB_1bppRgb || |
141 pSrc->GetFormat() == FXDIB_1bppMask || | 141 pSrc->GetFormat() == FXDIB_1bppMask || |
142 pSrc->GetFormat() == FXDIB_1bppCmyk); | 142 pSrc->GetFormat() == FXDIB_1bppCmyk); |
143 CFX_DIBExtractor src_bitmap(pSrc); | 143 CFX_DIBExtractor src_bitmap(pSrc); |
144 CFX_DIBitmap* pSrcBitmap = src_bitmap; | 144 CFX_DIBitmap* pSrcBitmap = src_bitmap; |
145 if (pSrcBitmap == NULL) { | 145 if (!pSrcBitmap) { |
146 return NULL; | 146 return NULL; |
147 } | 147 } |
148 int src_width = pSrcBitmap->GetWidth(), src_height = pSrcBitmap->GetHeight(); | 148 int src_width = pSrcBitmap->GetWidth(), src_height = pSrcBitmap->GetHeight(); |
149 uint8_t* src_buf = pSrcBitmap->GetBuffer(); | 149 uint8_t* src_buf = pSrcBitmap->GetBuffer(); |
150 FX_DWORD src_pitch = pSrcBitmap->GetPitch(); | 150 FX_DWORD src_pitch = pSrcBitmap->GetPitch(); |
151 FX_FLOAT dest_area = pDestMatrix->GetUnitArea(); | 151 FX_FLOAT dest_area = pDestMatrix->GetUnitArea(); |
152 FX_FLOAT area_scale = | 152 FX_FLOAT area_scale = |
153 FXSYS_Div((FX_FLOAT)(src_width * src_height), dest_area); | 153 FXSYS_Div((FX_FLOAT)(src_width * src_height), dest_area); |
154 FX_FLOAT size_scale = FXSYS_sqrt(area_scale); | 154 FX_FLOAT size_scale = FXSYS_sqrt(area_scale); |
155 CFX_Matrix adjusted_matrix(*pDestMatrix); | 155 CFX_Matrix adjusted_matrix(*pDestMatrix); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return StretchDIBits(pSource, color, | 243 return StretchDIBits(pSource, color, |
244 bFlipX ? full_rect.right : full_rect.left, | 244 bFlipX ? full_rect.right : full_rect.left, |
245 bFlipY ? full_rect.bottom : full_rect.top, | 245 bFlipY ? full_rect.bottom : full_rect.top, |
246 bFlipX ? -full_rect.Width() : full_rect.Width(), | 246 bFlipX ? -full_rect.Width() : full_rect.Width(), |
247 bFlipY ? -full_rect.Height() : full_rect.Height(), | 247 bFlipY ? -full_rect.Height() : full_rect.Height(), |
248 NULL, 0, alpha_flag, pIccTransform, blend_type); | 248 NULL, 0, alpha_flag, pIccTransform, blend_type); |
249 } | 249 } |
250 if (FXSYS_fabs(pMatrix->a) < 0.5f && FXSYS_fabs(pMatrix->d) < 0.5f) { | 250 if (FXSYS_fabs(pMatrix->a) < 0.5f && FXSYS_fabs(pMatrix->d) < 0.5f) { |
251 CFX_DIBitmap* pTransformed = | 251 CFX_DIBitmap* pTransformed = |
252 pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0); | 252 pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0); |
253 if (pTransformed == NULL) { | 253 if (!pTransformed) { |
254 return FALSE; | 254 return FALSE; |
255 } | 255 } |
256 FX_BOOL ret = StretchDIBits( | 256 FX_BOOL ret = StretchDIBits( |
257 pTransformed, color, full_rect.left, full_rect.top, full_rect.Width(), | 257 pTransformed, color, full_rect.left, full_rect.top, full_rect.Width(), |
258 full_rect.Height(), NULL, 0, alpha_flag, pIccTransform, blend_type); | 258 full_rect.Height(), NULL, 0, alpha_flag, pIccTransform, blend_type); |
259 delete pTransformed; | 259 delete pTransformed; |
260 return ret; | 260 return ret; |
261 } | 261 } |
262 if (pSource->GetBPP() == 1) { | 262 if (pSource->GetBPP() == 1) { |
263 CFX_DIBitmap* pTransformed = Transform1bppBitmap(pSource, pMatrix); | 263 CFX_DIBitmap* pTransformed = Transform1bppBitmap(pSource, pMatrix); |
264 if (pIccTransform == NULL) { | 264 if (!pIccTransform) { |
265 return FALSE; | 265 return FALSE; |
266 } | 266 } |
267 SaveState(); | 267 SaveState(); |
268 CFX_PathData path; | 268 CFX_PathData path; |
269 path.AppendRect(0, 0, 1.0f, 1.0f); | 269 path.AppendRect(0, 0, 1.0f, 1.0f); |
270 SetClip_PathFill(&path, pMatrix, WINDING); | 270 SetClip_PathFill(&path, pMatrix, WINDING); |
271 FX_BOOL ret = StretchDIBits( | 271 FX_BOOL ret = StretchDIBits( |
272 pTransformed, color, full_rect.left, full_rect.top, full_rect.Width(), | 272 pTransformed, color, full_rect.left, full_rect.top, full_rect.Width(), |
273 full_rect.Height(), NULL, 0, alpha_flag, pIccTransform, blend_type); | 273 full_rect.Height(), NULL, 0, alpha_flag, pIccTransform, blend_type); |
274 RestoreState(); | 274 RestoreState(); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 CFX_FontCache* pCache, | 465 CFX_FontCache* pCache, |
466 const CFX_Matrix* pObject2Device, | 466 const CFX_Matrix* pObject2Device, |
467 FX_FLOAT font_size, | 467 FX_FLOAT font_size, |
468 FX_DWORD color, | 468 FX_DWORD color, |
469 int alpha_flag, | 469 int alpha_flag, |
470 void* pIccTransform) { | 470 void* pIccTransform) { |
471 return m_PSRenderer.DrawText(nChars, pCharPos, pFont, pCache, pObject2Device, | 471 return m_PSRenderer.DrawText(nChars, pCharPos, pFont, pCache, pObject2Device, |
472 font_size, color, alpha_flag, pIccTransform); | 472 font_size, color, alpha_flag, pIccTransform); |
473 } | 473 } |
474 #endif | 474 #endif |
OLD | NEW |