OLD | NEW |
(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/fxge/include/cfx_renderdevice.h" |
| 8 |
| 9 #include "core/fxge/include/cfx_fxgedevice.h" |
| 10 #include "core/fxge/include/cfx_graphstatedata.h" |
| 11 #include "core/fxge/include/cfx_pathdata.h" |
| 12 #include "core/fxge/include/ifx_renderdevicedriver.h" |
| 13 |
| 14 #if defined _SKIA_SUPPORT_ |
| 15 #include "third_party/skia/include/core/SkTypes.h" |
| 16 #endif |
| 17 |
| 18 namespace { |
| 19 |
| 20 void AdjustGlyphSpace(std::vector<FXTEXT_GLYPHPOS>* pGlyphAndPos) { |
| 21 ASSERT(pGlyphAndPos->size() > 1); |
| 22 std::vector<FXTEXT_GLYPHPOS>& glyphs = *pGlyphAndPos; |
| 23 bool bVertical = glyphs.back().m_OriginX == glyphs.front().m_OriginX; |
| 24 if (!bVertical && (glyphs.back().m_OriginY != glyphs.front().m_OriginY)) |
| 25 return; |
| 26 |
| 27 for (size_t i = glyphs.size() - 1; i > 1; --i) { |
| 28 FXTEXT_GLYPHPOS& next = glyphs[i]; |
| 29 int next_origin = bVertical ? next.m_OriginY : next.m_OriginX; |
| 30 FX_FLOAT next_origin_f = bVertical ? next.m_fOriginY : next.m_fOriginX; |
| 31 |
| 32 FXTEXT_GLYPHPOS& current = glyphs[i - 1]; |
| 33 int& current_origin = bVertical ? current.m_OriginY : current.m_OriginX; |
| 34 FX_FLOAT current_origin_f = |
| 35 bVertical ? current.m_fOriginY : current.m_fOriginX; |
| 36 |
| 37 int space = next_origin - current_origin; |
| 38 FX_FLOAT space_f = next_origin_f - current_origin_f; |
| 39 FX_FLOAT error = |
| 40 FXSYS_fabs(space_f) - FXSYS_fabs(static_cast<FX_FLOAT>(space)); |
| 41 if (error > 0.5f) |
| 42 current_origin += space > 0 ? -1 : 1; |
| 43 } |
| 44 } |
| 45 |
| 46 const uint8_t g_TextGammaAdjust[256] = { |
| 47 0, 2, 3, 4, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, |
| 48 19, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, |
| 49 36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, |
| 50 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, |
| 51 68, 69, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, |
| 52 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, |
| 53 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, |
| 54 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, |
| 55 129, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, |
| 56 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 156, |
| 57 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, |
| 58 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, |
| 59 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, |
| 60 200, 201, 202, 203, 204, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, |
| 61 214, 215, 216, 217, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, |
| 62 228, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 239, 240, |
| 63 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 250, 251, 252, 253, 254, |
| 64 255, |
| 65 }; |
| 66 |
| 67 int TextGammaAdjust(int value) { |
| 68 ASSERT(value >= 0); |
| 69 ASSERT(value <= 255); |
| 70 return g_TextGammaAdjust[value]; |
| 71 } |
| 72 |
| 73 int CalcAlpha(int src, int alpha) { |
| 74 return src * alpha / 255; |
| 75 } |
| 76 |
| 77 void Merge(uint8_t src, int channel, int alpha, uint8_t* dest) { |
| 78 *dest = FXDIB_ALPHA_MERGE(*dest, channel, CalcAlpha(src, alpha)); |
| 79 } |
| 80 |
| 81 void MergeGammaAdjust(uint8_t src, int channel, int alpha, uint8_t* dest) { |
| 82 *dest = |
| 83 FXDIB_ALPHA_MERGE(*dest, channel, CalcAlpha(TextGammaAdjust(src), alpha)); |
| 84 } |
| 85 |
| 86 void MergeGammaAdjustBgr(const uint8_t* src, |
| 87 int r, |
| 88 int g, |
| 89 int b, |
| 90 int a, |
| 91 uint8_t* dest) { |
| 92 MergeGammaAdjust(src[0], b, a, &dest[0]); |
| 93 MergeGammaAdjust(src[1], g, a, &dest[1]); |
| 94 MergeGammaAdjust(src[2], r, a, &dest[2]); |
| 95 } |
| 96 |
| 97 void MergeGammaAdjustRgb(const uint8_t* src, |
| 98 int r, |
| 99 int g, |
| 100 int b, |
| 101 int a, |
| 102 uint8_t* dest) { |
| 103 MergeGammaAdjust(src[2], b, a, &dest[0]); |
| 104 MergeGammaAdjust(src[1], g, a, &dest[1]); |
| 105 MergeGammaAdjust(src[0], r, a, &dest[2]); |
| 106 } |
| 107 |
| 108 int AverageRgb(const uint8_t* src) { |
| 109 return (src[0] + src[1] + src[2]) / 3; |
| 110 } |
| 111 |
| 112 uint8_t CalculateDestAlpha(uint8_t back_alpha, int src_alpha) { |
| 113 return back_alpha + src_alpha - back_alpha * src_alpha / 255; |
| 114 } |
| 115 |
| 116 void ApplyDestAlpha(uint8_t back_alpha, |
| 117 int src_alpha, |
| 118 int r, |
| 119 int g, |
| 120 int b, |
| 121 uint8_t* dest) { |
| 122 uint8_t dest_alpha = CalculateDestAlpha(back_alpha, src_alpha); |
| 123 int alpha_ratio = src_alpha * 255 / dest_alpha; |
| 124 dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, alpha_ratio); |
| 125 dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, alpha_ratio); |
| 126 dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, alpha_ratio); |
| 127 dest[3] = dest_alpha; |
| 128 } |
| 129 |
| 130 void NormalizeRgbDst(int src_value, int r, int g, int b, int a, uint8_t* dest) { |
| 131 int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); |
| 132 dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, src_alpha); |
| 133 dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, src_alpha); |
| 134 dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, src_alpha); |
| 135 } |
| 136 |
| 137 void NormalizeRgbSrc(int src_value, int r, int g, int b, int a, uint8_t* dest) { |
| 138 int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); |
| 139 if (src_alpha == 0) |
| 140 return; |
| 141 |
| 142 dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, src_alpha); |
| 143 dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, src_alpha); |
| 144 dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, src_alpha); |
| 145 } |
| 146 |
| 147 void NormalizeArgbDest(int src_value, |
| 148 int r, |
| 149 int g, |
| 150 int b, |
| 151 int a, |
| 152 uint8_t* dest) { |
| 153 int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); |
| 154 uint8_t back_alpha = dest[3]; |
| 155 if (back_alpha == 0) { |
| 156 FXARGB_SETDIB(dest, FXARGB_MAKE(src_alpha, r, g, b)); |
| 157 } else if (src_alpha != 0) { |
| 158 ApplyDestAlpha(back_alpha, src_alpha, r, g, b, dest); |
| 159 } |
| 160 } |
| 161 |
| 162 void NormalizeArgbSrc(int src_value, |
| 163 int r, |
| 164 int g, |
| 165 int b, |
| 166 int a, |
| 167 uint8_t* dest) { |
| 168 int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); |
| 169 if (src_alpha == 0) |
| 170 return; |
| 171 |
| 172 uint8_t back_alpha = dest[3]; |
| 173 if (back_alpha == 0) { |
| 174 FXARGB_SETDIB(dest, FXARGB_MAKE(src_alpha, r, g, b)); |
| 175 } else { |
| 176 ApplyDestAlpha(back_alpha, src_alpha, r, g, b, dest); |
| 177 } |
| 178 } |
| 179 |
| 180 void NextPixel(uint8_t** src_scan, uint8_t** dst_scan, int bpp) { |
| 181 *src_scan += 3; |
| 182 *dst_scan += bpp; |
| 183 } |
| 184 |
| 185 void SetAlpha(uint8_t* alpha) { |
| 186 alpha[3] = 255; |
| 187 } |
| 188 |
| 189 void SetAlphaDoNothing(uint8_t* alpha) {} |
| 190 |
| 191 void DrawNormalTextHelper(CFX_DIBitmap* bitmap, |
| 192 const CFX_DIBitmap* pGlyph, |
| 193 int nrows, |
| 194 int left, |
| 195 int top, |
| 196 int start_col, |
| 197 int end_col, |
| 198 bool bNormal, |
| 199 bool bBGRStripe, |
| 200 int x_subpixel, |
| 201 int a, |
| 202 int r, |
| 203 int g, |
| 204 int b) { |
| 205 const bool has_alpha = bitmap->GetFormat() == FXDIB_Argb; |
| 206 uint8_t* src_buf = pGlyph->GetBuffer(); |
| 207 int src_pitch = pGlyph->GetPitch(); |
| 208 uint8_t* dest_buf = bitmap->GetBuffer(); |
| 209 int dest_pitch = bitmap->GetPitch(); |
| 210 const int Bpp = has_alpha ? 4 : bitmap->GetBPP() / 8; |
| 211 auto* pNormalizeSrcFunc = has_alpha ? &NormalizeArgbSrc : &NormalizeRgbDst; |
| 212 auto* pNormalizeDstFunc = has_alpha ? &NormalizeArgbDest : &NormalizeRgbSrc; |
| 213 auto* pSetAlpha = has_alpha ? &SetAlpha : &SetAlphaDoNothing; |
| 214 |
| 215 for (int row = 0; row < nrows; row++) { |
| 216 int dest_row = row + top; |
| 217 if (dest_row < 0 || dest_row >= bitmap->GetHeight()) |
| 218 continue; |
| 219 |
| 220 uint8_t* src_scan = src_buf + row * src_pitch + (start_col - left) * 3; |
| 221 uint8_t* dest_scan = dest_buf + dest_row * dest_pitch + start_col * Bpp; |
| 222 if (bBGRStripe) { |
| 223 if (x_subpixel == 0) { |
| 224 for (int col = start_col; col < end_col; col++) { |
| 225 if (has_alpha) { |
| 226 Merge(src_scan[2], r, a, &dest_scan[2]); |
| 227 Merge(src_scan[1], g, a, &dest_scan[1]); |
| 228 Merge(src_scan[0], b, a, &dest_scan[0]); |
| 229 } else { |
| 230 MergeGammaAdjustBgr(&src_scan[0], r, g, b, a, &dest_scan[0]); |
| 231 } |
| 232 pSetAlpha(dest_scan); |
| 233 NextPixel(&src_scan, &dest_scan, Bpp); |
| 234 } |
| 235 } else if (x_subpixel == 1) { |
| 236 MergeGammaAdjust(src_scan[1], r, a, &dest_scan[2]); |
| 237 MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); |
| 238 if (start_col > left) |
| 239 MergeGammaAdjust(src_scan[-1], b, a, &dest_scan[0]); |
| 240 pSetAlpha(dest_scan); |
| 241 NextPixel(&src_scan, &dest_scan, Bpp); |
| 242 for (int col = start_col + 1; col < end_col - 1; col++) { |
| 243 MergeGammaAdjustBgr(&src_scan[-1], r, g, b, a, &dest_scan[0]); |
| 244 pSetAlpha(dest_scan); |
| 245 NextPixel(&src_scan, &dest_scan, Bpp); |
| 246 } |
| 247 } else { |
| 248 MergeGammaAdjust(src_scan[0], r, a, &dest_scan[2]); |
| 249 if (start_col > left) { |
| 250 MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); |
| 251 MergeGammaAdjust(src_scan[-2], b, a, &dest_scan[0]); |
| 252 } |
| 253 pSetAlpha(dest_scan); |
| 254 NextPixel(&src_scan, &dest_scan, Bpp); |
| 255 for (int col = start_col + 1; col < end_col - 1; col++) { |
| 256 MergeGammaAdjustBgr(&src_scan[-2], r, g, b, a, &dest_scan[0]); |
| 257 pSetAlpha(dest_scan); |
| 258 NextPixel(&src_scan, &dest_scan, Bpp); |
| 259 } |
| 260 } |
| 261 } else { |
| 262 if (x_subpixel == 0) { |
| 263 for (int col = start_col; col < end_col; col++) { |
| 264 if (bNormal) { |
| 265 int src_value = AverageRgb(&src_scan[0]); |
| 266 pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); |
| 267 } else { |
| 268 MergeGammaAdjustRgb(&src_scan[0], r, g, b, a, &dest_scan[0]); |
| 269 pSetAlpha(dest_scan); |
| 270 } |
| 271 NextPixel(&src_scan, &dest_scan, Bpp); |
| 272 } |
| 273 } else if (x_subpixel == 1) { |
| 274 if (bNormal) { |
| 275 int src_value = start_col > left ? AverageRgb(&src_scan[-1]) |
| 276 : (src_scan[0] + src_scan[1]) / 3; |
| 277 pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); |
| 278 } else { |
| 279 if (start_col > left) |
| 280 MergeGammaAdjust(src_scan[-1], r, a, &dest_scan[2]); |
| 281 MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); |
| 282 MergeGammaAdjust(src_scan[1], b, a, &dest_scan[0]); |
| 283 pSetAlpha(dest_scan); |
| 284 } |
| 285 NextPixel(&src_scan, &dest_scan, Bpp); |
| 286 for (int col = start_col + 1; col < end_col; col++) { |
| 287 if (bNormal) { |
| 288 int src_value = AverageRgb(&src_scan[-1]); |
| 289 pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); |
| 290 } else { |
| 291 MergeGammaAdjustRgb(&src_scan[-1], r, g, b, a, &dest_scan[0]); |
| 292 pSetAlpha(dest_scan); |
| 293 } |
| 294 NextPixel(&src_scan, &dest_scan, Bpp); |
| 295 } |
| 296 } else { |
| 297 if (bNormal) { |
| 298 int src_value = |
| 299 start_col > left ? AverageRgb(&src_scan[-2]) : src_scan[0] / 3; |
| 300 pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); |
| 301 } else { |
| 302 if (start_col > left) { |
| 303 MergeGammaAdjust(src_scan[-2], r, a, &dest_scan[2]); |
| 304 MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); |
| 305 } |
| 306 MergeGammaAdjust(src_scan[0], b, a, &dest_scan[0]); |
| 307 pSetAlpha(dest_scan); |
| 308 } |
| 309 NextPixel(&src_scan, &dest_scan, Bpp); |
| 310 for (int col = start_col + 1; col < end_col; col++) { |
| 311 if (bNormal) { |
| 312 int src_value = AverageRgb(&src_scan[-2]); |
| 313 pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); |
| 314 } else { |
| 315 MergeGammaAdjustRgb(&src_scan[-2], r, g, b, a, &dest_scan[0]); |
| 316 pSetAlpha(dest_scan); |
| 317 } |
| 318 NextPixel(&src_scan, &dest_scan, Bpp); |
| 319 } |
| 320 } |
| 321 } |
| 322 } |
| 323 } |
| 324 |
| 325 bool ShouldDrawDeviceText(const CFX_Font* pFont, uint32_t text_flags) { |
| 326 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 327 if (text_flags & FXFONT_CIDFONT) |
| 328 return false; |
| 329 |
| 330 const CFX_ByteString bsPsName = pFont->GetPsName(); |
| 331 if (bsPsName.Find("+ZJHL") != -1) |
| 332 return false; |
| 333 |
| 334 if (bsPsName == "CNAAJI+cmex10") |
| 335 return false; |
| 336 #endif |
| 337 return true; |
| 338 } |
| 339 |
| 340 } // namespace |
| 341 |
| 342 CFX_RenderDevice::CFX_RenderDevice() |
| 343 : m_pBitmap(nullptr), |
| 344 m_Width(0), |
| 345 m_Height(0), |
| 346 m_bpp(0), |
| 347 m_RenderCaps(0), |
| 348 m_DeviceClass(0) {} |
| 349 |
| 350 CFX_RenderDevice::~CFX_RenderDevice() {} |
| 351 |
| 352 #ifdef _SKIA_SUPPORT_ |
| 353 void CFX_RenderDevice::Flush() { |
| 354 m_pDeviceDriver.reset(); |
| 355 } |
| 356 #endif |
| 357 |
| 358 void CFX_RenderDevice::SetDeviceDriver( |
| 359 std::unique_ptr<IFX_RenderDeviceDriver> pDriver) { |
| 360 m_pDeviceDriver = std::move(pDriver); |
| 361 InitDeviceInfo(); |
| 362 } |
| 363 |
| 364 void CFX_RenderDevice::InitDeviceInfo() { |
| 365 m_Width = m_pDeviceDriver->GetDeviceCaps(FXDC_PIXEL_WIDTH); |
| 366 m_Height = m_pDeviceDriver->GetDeviceCaps(FXDC_PIXEL_HEIGHT); |
| 367 m_bpp = m_pDeviceDriver->GetDeviceCaps(FXDC_BITS_PIXEL); |
| 368 m_RenderCaps = m_pDeviceDriver->GetDeviceCaps(FXDC_RENDER_CAPS); |
| 369 m_DeviceClass = m_pDeviceDriver->GetDeviceCaps(FXDC_DEVICE_CLASS); |
| 370 if (!m_pDeviceDriver->GetClipBox(&m_ClipBox)) { |
| 371 m_ClipBox.left = 0; |
| 372 m_ClipBox.top = 0; |
| 373 m_ClipBox.right = m_Width; |
| 374 m_ClipBox.bottom = m_Height; |
| 375 } |
| 376 } |
| 377 |
| 378 FX_BOOL CFX_RenderDevice::StartRendering() { |
| 379 return m_pDeviceDriver->StartRendering(); |
| 380 } |
| 381 |
| 382 void CFX_RenderDevice::EndRendering() { |
| 383 m_pDeviceDriver->EndRendering(); |
| 384 } |
| 385 |
| 386 void CFX_RenderDevice::SaveState() { |
| 387 m_pDeviceDriver->SaveState(); |
| 388 } |
| 389 |
| 390 void CFX_RenderDevice::RestoreState(bool bKeepSaved) { |
| 391 m_pDeviceDriver->RestoreState(bKeepSaved); |
| 392 UpdateClipBox(); |
| 393 } |
| 394 |
| 395 int CFX_RenderDevice::GetDeviceCaps(int caps_id) const { |
| 396 return m_pDeviceDriver->GetDeviceCaps(caps_id); |
| 397 } |
| 398 CFX_Matrix CFX_RenderDevice::GetCTM() const { |
| 399 return m_pDeviceDriver->GetCTM(); |
| 400 } |
| 401 |
| 402 FX_BOOL CFX_RenderDevice::CreateCompatibleBitmap(CFX_DIBitmap* pDIB, |
| 403 int width, |
| 404 int height) const { |
| 405 if (m_RenderCaps & FXRC_CMYK_OUTPUT) { |
| 406 return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT |
| 407 ? FXDIB_Cmyka |
| 408 : FXDIB_Cmyk); |
| 409 } |
| 410 if (m_RenderCaps & FXRC_BYTEMASK_OUTPUT) |
| 411 return pDIB->Create(width, height, FXDIB_8bppMask); |
| 412 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 413 return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT |
| 414 ? FXDIB_Argb |
| 415 : FXDIB_Rgb32); |
| 416 #else |
| 417 return pDIB->Create( |
| 418 width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT ? FXDIB_Argb : FXDIB_Rgb); |
| 419 #endif |
| 420 } |
| 421 |
| 422 FX_BOOL CFX_RenderDevice::SetClip_PathFill(const CFX_PathData* pPathData, |
| 423 const CFX_Matrix* pObject2Device, |
| 424 int fill_mode) { |
| 425 if (!m_pDeviceDriver->SetClip_PathFill(pPathData, pObject2Device, |
| 426 fill_mode)) { |
| 427 return FALSE; |
| 428 } |
| 429 UpdateClipBox(); |
| 430 return TRUE; |
| 431 } |
| 432 |
| 433 FX_BOOL CFX_RenderDevice::SetClip_PathStroke( |
| 434 const CFX_PathData* pPathData, |
| 435 const CFX_Matrix* pObject2Device, |
| 436 const CFX_GraphStateData* pGraphState) { |
| 437 if (!m_pDeviceDriver->SetClip_PathStroke(pPathData, pObject2Device, |
| 438 pGraphState)) { |
| 439 return FALSE; |
| 440 } |
| 441 UpdateClipBox(); |
| 442 return TRUE; |
| 443 } |
| 444 |
| 445 FX_BOOL CFX_RenderDevice::SetClip_Rect(const FX_RECT& rect) { |
| 446 CFX_PathData path; |
| 447 path.AppendRect(rect.left, rect.bottom, rect.right, rect.top); |
| 448 if (!SetClip_PathFill(&path, nullptr, FXFILL_WINDING)) |
| 449 return FALSE; |
| 450 |
| 451 UpdateClipBox(); |
| 452 return TRUE; |
| 453 } |
| 454 |
| 455 void CFX_RenderDevice::UpdateClipBox() { |
| 456 if (m_pDeviceDriver->GetClipBox(&m_ClipBox)) |
| 457 return; |
| 458 m_ClipBox.left = 0; |
| 459 m_ClipBox.top = 0; |
| 460 m_ClipBox.right = m_Width; |
| 461 m_ClipBox.bottom = m_Height; |
| 462 } |
| 463 |
| 464 FX_BOOL CFX_RenderDevice::DrawPathWithBlend( |
| 465 const CFX_PathData* pPathData, |
| 466 const CFX_Matrix* pObject2Device, |
| 467 const CFX_GraphStateData* pGraphState, |
| 468 uint32_t fill_color, |
| 469 uint32_t stroke_color, |
| 470 int fill_mode, |
| 471 int blend_type) { |
| 472 uint8_t stroke_alpha = pGraphState ? FXARGB_A(stroke_color) : 0; |
| 473 uint8_t fill_alpha = (fill_mode & 3) ? FXARGB_A(fill_color) : 0; |
| 474 if (stroke_alpha == 0 && pPathData->GetPointCount() == 2) { |
| 475 FX_PATHPOINT* pPoints = pPathData->GetPoints(); |
| 476 FX_FLOAT x1, x2, y1, y2; |
| 477 if (pObject2Device) { |
| 478 pObject2Device->Transform(pPoints[0].m_PointX, pPoints[0].m_PointY, x1, |
| 479 y1); |
| 480 pObject2Device->Transform(pPoints[1].m_PointX, pPoints[1].m_PointY, x2, |
| 481 y2); |
| 482 } else { |
| 483 x1 = pPoints[0].m_PointX; |
| 484 y1 = pPoints[0].m_PointY; |
| 485 x2 = pPoints[1].m_PointX; |
| 486 y2 = pPoints[1].m_PointY; |
| 487 } |
| 488 DrawCosmeticLineWithFillModeAndBlend(x1, y1, x2, y2, fill_color, fill_mode, |
| 489 blend_type); |
| 490 return TRUE; |
| 491 } |
| 492 if ((pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) && |
| 493 stroke_alpha == 0) { |
| 494 CFX_FloatRect rect_f; |
| 495 if (!(fill_mode & FXFILL_RECT_AA) && |
| 496 pPathData->IsRect(pObject2Device, &rect_f)) { |
| 497 FX_RECT rect_i = rect_f.GetOuterRect(); |
| 498 |
| 499 // Depending on the top/bottom, left/right values of the rect it's |
| 500 // possible to overflow the Width() and Height() calculations. Check that |
| 501 // the rect will have valid dimension before continuing. |
| 502 if (!rect_i.Valid()) |
| 503 return FALSE; |
| 504 |
| 505 int width = (int)FXSYS_ceil(rect_f.right - rect_f.left); |
| 506 if (width < 1) { |
| 507 width = 1; |
| 508 if (rect_i.left == rect_i.right) |
| 509 rect_i.right++; |
| 510 } |
| 511 int height = (int)FXSYS_ceil(rect_f.top - rect_f.bottom); |
| 512 if (height < 1) { |
| 513 height = 1; |
| 514 if (rect_i.bottom == rect_i.top) |
| 515 rect_i.bottom++; |
| 516 } |
| 517 if (rect_i.Width() >= width + 1) { |
| 518 if (rect_f.left - (FX_FLOAT)(rect_i.left) > |
| 519 (FX_FLOAT)(rect_i.right) - rect_f.right) { |
| 520 rect_i.left++; |
| 521 } else { |
| 522 rect_i.right--; |
| 523 } |
| 524 } |
| 525 if (rect_i.Height() >= height + 1) { |
| 526 if (rect_f.top - (FX_FLOAT)(rect_i.top) > |
| 527 (FX_FLOAT)(rect_i.bottom) - rect_f.bottom) { |
| 528 rect_i.top++; |
| 529 } else { |
| 530 rect_i.bottom--; |
| 531 } |
| 532 } |
| 533 if (FillRectWithBlend(&rect_i, fill_color, blend_type)) |
| 534 return TRUE; |
| 535 } |
| 536 } |
| 537 if ((fill_mode & 3) && stroke_alpha == 0 && !(fill_mode & FX_FILL_STROKE) && |
| 538 !(fill_mode & FX_FILL_TEXT_MODE)) { |
| 539 CFX_PathData newPath; |
| 540 FX_BOOL bThin = FALSE; |
| 541 if (pPathData->GetZeroAreaPath(newPath, (CFX_Matrix*)pObject2Device, bThin, |
| 542 m_pDeviceDriver->GetDriverType())) { |
| 543 CFX_GraphStateData graphState; |
| 544 graphState.m_LineWidth = 0.0f; |
| 545 uint32_t strokecolor = fill_color; |
| 546 if (bThin) |
| 547 strokecolor = (((fill_alpha >> 2) << 24) | (strokecolor & 0x00ffffff)); |
| 548 CFX_Matrix* pMatrix = nullptr; |
| 549 if (pObject2Device && !pObject2Device->IsIdentity()) |
| 550 pMatrix = (CFX_Matrix*)pObject2Device; |
| 551 int smooth_path = FX_ZEROAREA_FILL; |
| 552 if (fill_mode & FXFILL_NOPATHSMOOTH) |
| 553 smooth_path |= FXFILL_NOPATHSMOOTH; |
| 554 m_pDeviceDriver->DrawPath(&newPath, pMatrix, &graphState, 0, strokecolor, |
| 555 smooth_path, blend_type); |
| 556 } |
| 557 } |
| 558 if ((fill_mode & 3) && fill_alpha && stroke_alpha < 0xff && |
| 559 (fill_mode & FX_FILL_STROKE)) { |
| 560 if (m_RenderCaps & FXRC_FILLSTROKE_PATH) { |
| 561 return m_pDeviceDriver->DrawPath(pPathData, pObject2Device, pGraphState, |
| 562 fill_color, stroke_color, fill_mode, |
| 563 blend_type); |
| 564 } |
| 565 return DrawFillStrokePath(pPathData, pObject2Device, pGraphState, |
| 566 fill_color, stroke_color, fill_mode, blend_type); |
| 567 } |
| 568 return m_pDeviceDriver->DrawPath(pPathData, pObject2Device, pGraphState, |
| 569 fill_color, stroke_color, fill_mode, |
| 570 blend_type); |
| 571 } |
| 572 |
| 573 // This can be removed once PDFium entirely relies on Skia |
| 574 FX_BOOL CFX_RenderDevice::DrawFillStrokePath( |
| 575 const CFX_PathData* pPathData, |
| 576 const CFX_Matrix* pObject2Device, |
| 577 const CFX_GraphStateData* pGraphState, |
| 578 uint32_t fill_color, |
| 579 uint32_t stroke_color, |
| 580 int fill_mode, |
| 581 int blend_type) { |
| 582 if (!(m_RenderCaps & FXRC_GET_BITS)) |
| 583 return FALSE; |
| 584 CFX_FloatRect bbox; |
| 585 if (pGraphState) { |
| 586 bbox = pPathData->GetBoundingBox(pGraphState->m_LineWidth, |
| 587 pGraphState->m_MiterLimit); |
| 588 } else { |
| 589 bbox = pPathData->GetBoundingBox(); |
| 590 } |
| 591 if (pObject2Device) |
| 592 bbox.Transform(pObject2Device); |
| 593 CFX_Matrix ctm = GetCTM(); |
| 594 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a); |
| 595 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d); |
| 596 FX_RECT rect = bbox.GetOuterRect(); |
| 597 CFX_DIBitmap bitmap, Backdrop; |
| 598 if (!CreateCompatibleBitmap(&bitmap, FXSYS_round(rect.Width() * fScaleX), |
| 599 FXSYS_round(rect.Height() * fScaleY))) { |
| 600 return FALSE; |
| 601 } |
| 602 if (bitmap.HasAlpha()) { |
| 603 bitmap.Clear(0); |
| 604 Backdrop.Copy(&bitmap); |
| 605 } else { |
| 606 if (!m_pDeviceDriver->GetDIBits(&bitmap, rect.left, rect.top)) |
| 607 return FALSE; |
| 608 Backdrop.Copy(&bitmap); |
| 609 } |
| 610 CFX_FxgeDevice bitmap_device; |
| 611 bitmap_device.Attach(&bitmap, false, &Backdrop, true); |
| 612 CFX_Matrix matrix; |
| 613 if (pObject2Device) |
| 614 matrix = *pObject2Device; |
| 615 matrix.TranslateI(-rect.left, -rect.top); |
| 616 matrix.Concat(fScaleX, 0, 0, fScaleY, 0, 0); |
| 617 if (!bitmap_device.GetDeviceDriver()->DrawPath( |
| 618 pPathData, &matrix, pGraphState, fill_color, stroke_color, fill_mode, |
| 619 blend_type)) { |
| 620 return FALSE; |
| 621 } |
| 622 FX_RECT src_rect(0, 0, FXSYS_round(rect.Width() * fScaleX), |
| 623 FXSYS_round(rect.Height() * fScaleY)); |
| 624 return m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, rect.left, rect.top, |
| 625 FXDIB_BLEND_NORMAL); |
| 626 } |
| 627 |
| 628 FX_BOOL CFX_RenderDevice::SetPixel(int x, int y, uint32_t color) { |
| 629 if (m_pDeviceDriver->SetPixel(x, y, color)) |
| 630 return TRUE; |
| 631 |
| 632 FX_RECT rect(x, y, x + 1, y + 1); |
| 633 return FillRectWithBlend(&rect, color, FXDIB_BLEND_NORMAL); |
| 634 } |
| 635 |
| 636 FX_BOOL CFX_RenderDevice::FillRectWithBlend(const FX_RECT* pRect, |
| 637 uint32_t fill_color, |
| 638 int blend_type) { |
| 639 if (m_pDeviceDriver->FillRectWithBlend(pRect, fill_color, blend_type)) |
| 640 return TRUE; |
| 641 |
| 642 if (!(m_RenderCaps & FXRC_GET_BITS)) |
| 643 return FALSE; |
| 644 |
| 645 CFX_DIBitmap bitmap; |
| 646 if (!CreateCompatibleBitmap(&bitmap, pRect->Width(), pRect->Height())) |
| 647 return FALSE; |
| 648 |
| 649 if (!m_pDeviceDriver->GetDIBits(&bitmap, pRect->left, pRect->top)) |
| 650 return FALSE; |
| 651 |
| 652 if (!bitmap.CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color, |
| 653 0, nullptr)) { |
| 654 return FALSE; |
| 655 } |
| 656 FX_RECT src_rect(0, 0, pRect->Width(), pRect->Height()); |
| 657 m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, pRect->left, pRect->top, |
| 658 FXDIB_BLEND_NORMAL); |
| 659 return TRUE; |
| 660 } |
| 661 |
| 662 FX_BOOL CFX_RenderDevice::DrawCosmeticLineWithFillModeAndBlend(FX_FLOAT x1, |
| 663 FX_FLOAT y1, |
| 664 FX_FLOAT x2, |
| 665 FX_FLOAT y2, |
| 666 uint32_t color, |
| 667 int fill_mode, |
| 668 int blend_type) { |
| 669 if ((color >= 0xff000000) && |
| 670 m_pDeviceDriver->DrawCosmeticLine(x1, y1, x2, y2, color, blend_type)) { |
| 671 return TRUE; |
| 672 } |
| 673 CFX_GraphStateData graph_state; |
| 674 CFX_PathData path; |
| 675 path.SetPointCount(2); |
| 676 path.SetPoint(0, x1, y1, FXPT_MOVETO); |
| 677 path.SetPoint(1, x2, y2, FXPT_LINETO); |
| 678 return m_pDeviceDriver->DrawPath(&path, nullptr, &graph_state, 0, color, |
| 679 fill_mode, blend_type); |
| 680 } |
| 681 |
| 682 FX_BOOL CFX_RenderDevice::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { |
| 683 if (!(m_RenderCaps & FXRC_GET_BITS)) |
| 684 return FALSE; |
| 685 return m_pDeviceDriver->GetDIBits(pBitmap, left, top); |
| 686 } |
| 687 |
| 688 CFX_DIBitmap* CFX_RenderDevice::GetBackDrop() { |
| 689 return m_pDeviceDriver->GetBackDrop(); |
| 690 } |
| 691 |
| 692 FX_BOOL CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap, |
| 693 int left, |
| 694 int top, |
| 695 int blend_mode) { |
| 696 ASSERT(!pBitmap->IsAlphaMask()); |
| 697 CFX_Matrix ctm = GetCTM(); |
| 698 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a); |
| 699 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d); |
| 700 FX_RECT dest_rect(left, top, |
| 701 FXSYS_round(left + pBitmap->GetWidth() / fScaleX), |
| 702 FXSYS_round(top + pBitmap->GetHeight() / fScaleY)); |
| 703 dest_rect.Intersect(m_ClipBox); |
| 704 if (dest_rect.IsEmpty()) |
| 705 return TRUE; |
| 706 FX_RECT src_rect(dest_rect.left - left, dest_rect.top - top, |
| 707 dest_rect.left - left + dest_rect.Width(), |
| 708 dest_rect.top - top + dest_rect.Height()); |
| 709 src_rect.left = FXSYS_round(src_rect.left * fScaleX); |
| 710 src_rect.top = FXSYS_round(src_rect.top * fScaleY); |
| 711 src_rect.right = FXSYS_round(src_rect.right * fScaleX); |
| 712 src_rect.bottom = FXSYS_round(src_rect.bottom * fScaleY); |
| 713 if ((blend_mode != FXDIB_BLEND_NORMAL && !(m_RenderCaps & FXRC_BLEND_MODE)) || |
| 714 (pBitmap->HasAlpha() && !(m_RenderCaps & FXRC_ALPHA_IMAGE))) { |
| 715 if (!(m_RenderCaps & FXRC_GET_BITS)) |
| 716 return FALSE; |
| 717 int bg_pixel_width = FXSYS_round(dest_rect.Width() * fScaleX); |
| 718 int bg_pixel_height = FXSYS_round(dest_rect.Height() * fScaleY); |
| 719 CFX_DIBitmap background; |
| 720 if (!background.Create( |
| 721 bg_pixel_width, bg_pixel_height, |
| 722 (m_RenderCaps & FXRC_CMYK_OUTPUT) ? FXDIB_Cmyk : FXDIB_Rgb32)) { |
| 723 return FALSE; |
| 724 } |
| 725 if (!m_pDeviceDriver->GetDIBits(&background, dest_rect.left, |
| 726 dest_rect.top)) { |
| 727 return FALSE; |
| 728 } |
| 729 if (!background.CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height, |
| 730 pBitmap, src_rect.left, src_rect.top, |
| 731 blend_mode, nullptr, FALSE, nullptr)) { |
| 732 return FALSE; |
| 733 } |
| 734 FX_RECT rect(0, 0, bg_pixel_width, bg_pixel_height); |
| 735 return m_pDeviceDriver->SetDIBits(&background, 0, &rect, dest_rect.left, |
| 736 dest_rect.top, FXDIB_BLEND_NORMAL); |
| 737 } |
| 738 return m_pDeviceDriver->SetDIBits(pBitmap, 0, &src_rect, dest_rect.left, |
| 739 dest_rect.top, blend_mode); |
| 740 } |
| 741 |
| 742 FX_BOOL CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend( |
| 743 const CFX_DIBSource* pBitmap, |
| 744 int left, |
| 745 int top, |
| 746 int dest_width, |
| 747 int dest_height, |
| 748 uint32_t flags, |
| 749 int blend_mode) { |
| 750 FX_RECT dest_rect(left, top, left + dest_width, top + dest_height); |
| 751 FX_RECT clip_box = m_ClipBox; |
| 752 clip_box.Intersect(dest_rect); |
| 753 if (clip_box.IsEmpty()) |
| 754 return TRUE; |
| 755 return m_pDeviceDriver->StretchDIBits(pBitmap, 0, left, top, dest_width, |
| 756 dest_height, &clip_box, flags, |
| 757 blend_mode); |
| 758 } |
| 759 |
| 760 FX_BOOL CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap, |
| 761 int left, |
| 762 int top, |
| 763 uint32_t argb) { |
| 764 FX_RECT src_rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); |
| 765 return m_pDeviceDriver->SetDIBits(pBitmap, argb, &src_rect, left, top, |
| 766 FXDIB_BLEND_NORMAL); |
| 767 } |
| 768 |
| 769 FX_BOOL CFX_RenderDevice::StretchBitMask(const CFX_DIBSource* pBitmap, |
| 770 int left, |
| 771 int top, |
| 772 int dest_width, |
| 773 int dest_height, |
| 774 uint32_t color) { |
| 775 return StretchBitMaskWithFlags(pBitmap, left, top, dest_width, dest_height, |
| 776 color, 0); |
| 777 } |
| 778 |
| 779 FX_BOOL CFX_RenderDevice::StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap, |
| 780 int left, |
| 781 int top, |
| 782 int dest_width, |
| 783 int dest_height, |
| 784 uint32_t argb, |
| 785 uint32_t flags) { |
| 786 FX_RECT dest_rect(left, top, left + dest_width, top + dest_height); |
| 787 FX_RECT clip_box = m_ClipBox; |
| 788 clip_box.Intersect(dest_rect); |
| 789 return m_pDeviceDriver->StretchDIBits(pBitmap, argb, left, top, dest_width, |
| 790 dest_height, &clip_box, flags, |
| 791 FXDIB_BLEND_NORMAL); |
| 792 } |
| 793 |
| 794 FX_BOOL CFX_RenderDevice::StartDIBitsWithBlend(const CFX_DIBSource* pBitmap, |
| 795 int bitmap_alpha, |
| 796 uint32_t argb, |
| 797 const CFX_Matrix* pMatrix, |
| 798 uint32_t flags, |
| 799 void*& handle, |
| 800 int blend_mode) { |
| 801 return m_pDeviceDriver->StartDIBits(pBitmap, bitmap_alpha, argb, pMatrix, |
| 802 flags, handle, blend_mode); |
| 803 } |
| 804 |
| 805 FX_BOOL CFX_RenderDevice::ContinueDIBits(void* handle, IFX_Pause* pPause) { |
| 806 return m_pDeviceDriver->ContinueDIBits(handle, pPause); |
| 807 } |
| 808 |
| 809 void CFX_RenderDevice::CancelDIBits(void* handle) { |
| 810 m_pDeviceDriver->CancelDIBits(handle); |
| 811 } |
| 812 |
| 813 #ifdef _SKIA_SUPPORT_ |
| 814 |
| 815 void CFX_RenderDevice::DebugVerifyBitmapIsPreMultiplied() const { |
| 816 SkASSERT(0); |
| 817 } |
| 818 #endif |
| 819 |
| 820 FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, |
| 821 const FXTEXT_CHARPOS* pCharPos, |
| 822 CFX_Font* pFont, |
| 823 CFX_FontCache* pCache, |
| 824 FX_FLOAT font_size, |
| 825 const CFX_Matrix* pText2Device, |
| 826 uint32_t fill_color, |
| 827 uint32_t text_flags) { |
| 828 int nativetext_flags = text_flags; |
| 829 if (m_DeviceClass != FXDC_DISPLAY) { |
| 830 if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { |
| 831 if (ShouldDrawDeviceText(pFont, text_flags) && |
| 832 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, |
| 833 pText2Device, font_size, |
| 834 fill_color)) { |
| 835 return TRUE; |
| 836 } |
| 837 } |
| 838 if (FXARGB_A(fill_color) < 255) |
| 839 return FALSE; |
| 840 } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) { |
| 841 if (ShouldDrawDeviceText(pFont, text_flags) && |
| 842 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, |
| 843 pText2Device, font_size, fill_color)) { |
| 844 return TRUE; |
| 845 } |
| 846 } |
| 847 CFX_Matrix char2device; |
| 848 CFX_Matrix text2Device; |
| 849 if (pText2Device) { |
| 850 char2device = *pText2Device; |
| 851 text2Device = *pText2Device; |
| 852 } |
| 853 char2device.Scale(font_size, -font_size); |
| 854 if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || |
| 855 ((m_DeviceClass == FXDC_PRINTER) && |
| 856 !(text_flags & FXTEXT_PRINTIMAGETEXT))) { |
| 857 if (pFont->GetFace() || |
| 858 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { |
| 859 int nPathFlags = |
| 860 (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH; |
| 861 return DrawTextPathWithFlags(nChars, pCharPos, pFont, pCache, font_size, |
| 862 pText2Device, nullptr, nullptr, fill_color, |
| 863 0, nullptr, nPathFlags); |
| 864 } |
| 865 } |
| 866 int anti_alias = FXFT_RENDER_MODE_MONO; |
| 867 bool bNormal = false; |
| 868 if ((text_flags & FXTEXT_NOSMOOTH) == 0) { |
| 869 if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) { |
| 870 if (!CFX_GEModule::Get()->GetFontMgr()->FTLibrarySupportsHinting()) { |
| 871 // Some Freetype implementations (like the one packaged with Fedora) do |
| 872 // not support hinting due to patents 6219025, 6239783, 6307566, |
| 873 // 6225973, 6243070, 6393145, 6421054, 6282327, and 6624828; the latest |
| 874 // one expires 10/7/19. This makes LCD antialiasing very ugly, so we |
| 875 // instead fall back on NORMAL antialiasing. |
| 876 anti_alias = FXFT_RENDER_MODE_NORMAL; |
| 877 } else if ((m_RenderCaps & (FXRC_ALPHA_OUTPUT | FXRC_CMYK_OUTPUT))) { |
| 878 anti_alias = FXFT_RENDER_MODE_LCD; |
| 879 bNormal = true; |
| 880 } else if (m_bpp < 16) { |
| 881 anti_alias = FXFT_RENDER_MODE_NORMAL; |
| 882 } else { |
| 883 anti_alias = FXFT_RENDER_MODE_LCD; |
| 884 |
| 885 bool bClearType = false; |
| 886 if (pFont->GetFace() || |
| 887 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_CLEARTYPE)) { |
| 888 bClearType = !!(text_flags & FXTEXT_CLEARTYPE); |
| 889 } |
| 890 bNormal = !bClearType; |
| 891 } |
| 892 } |
| 893 } |
| 894 if (!pCache) |
| 895 pCache = CFX_GEModule::Get()->GetFontCache(); |
| 896 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); |
| 897 CFX_AutoFontCache autoFontCache(pCache, pFont); |
| 898 std::vector<FXTEXT_GLYPHPOS> glyphs(nChars); |
| 899 CFX_Matrix matrixCTM = GetCTM(); |
| 900 FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a); |
| 901 FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d); |
| 902 CFX_Matrix deviceCtm = char2device; |
| 903 deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0); |
| 904 text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0); |
| 905 for (size_t i = 0; i < glyphs.size(); ++i) { |
| 906 FXTEXT_GLYPHPOS& glyph = glyphs[i]; |
| 907 const FXTEXT_CHARPOS& charpos = pCharPos[i]; |
| 908 glyph.m_fOriginX = charpos.m_OriginX; |
| 909 glyph.m_fOriginY = charpos.m_OriginY; |
| 910 text2Device.Transform(glyph.m_fOriginX, glyph.m_fOriginY); |
| 911 if (anti_alias < FXFT_RENDER_MODE_LCD) |
| 912 glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX); |
| 913 else |
| 914 glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX); |
| 915 glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY); |
| 916 if (charpos.m_bGlyphAdjust) { |
| 917 CFX_Matrix new_matrix( |
| 918 charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
| 919 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
| 920 new_matrix.Concat(deviceCtm); |
| 921 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( |
| 922 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &new_matrix, |
| 923 charpos.m_FontCharWidth, anti_alias, nativetext_flags); |
| 924 } else { |
| 925 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( |
| 926 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &deviceCtm, |
| 927 charpos.m_FontCharWidth, anti_alias, nativetext_flags); |
| 928 } |
| 929 } |
| 930 if (anti_alias < FXFT_RENDER_MODE_LCD && glyphs.size() > 1) |
| 931 AdjustGlyphSpace(&glyphs); |
| 932 |
| 933 FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(glyphs, anti_alias); |
| 934 if (scale_x > 1 && scale_y > 1) { |
| 935 bmp_rect1.left--; |
| 936 bmp_rect1.top--; |
| 937 bmp_rect1.right++; |
| 938 bmp_rect1.bottom++; |
| 939 } |
| 940 FX_RECT bmp_rect(FXSYS_round((FX_FLOAT)(bmp_rect1.left) / scale_x), |
| 941 FXSYS_round((FX_FLOAT)(bmp_rect1.top) / scale_y), |
| 942 FXSYS_round((FX_FLOAT)bmp_rect1.right / scale_x), |
| 943 FXSYS_round((FX_FLOAT)bmp_rect1.bottom / scale_y)); |
| 944 bmp_rect.Intersect(m_ClipBox); |
| 945 if (bmp_rect.IsEmpty()) |
| 946 return TRUE; |
| 947 int pixel_width = FXSYS_round(bmp_rect.Width() * scale_x); |
| 948 int pixel_height = FXSYS_round(bmp_rect.Height() * scale_y); |
| 949 int pixel_left = FXSYS_round(bmp_rect.left * scale_x); |
| 950 int pixel_top = FXSYS_round(bmp_rect.top * scale_y); |
| 951 if (anti_alias == FXFT_RENDER_MODE_MONO) { |
| 952 CFX_DIBitmap bitmap; |
| 953 if (!bitmap.Create(pixel_width, pixel_height, FXDIB_1bppMask)) |
| 954 return FALSE; |
| 955 bitmap.Clear(0); |
| 956 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { |
| 957 if (!glyph.m_pGlyph) |
| 958 continue; |
| 959 const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; |
| 960 bitmap.TransferBitmap( |
| 961 glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left, |
| 962 glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top, |
| 963 pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0, 0); |
| 964 } |
| 965 return SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); |
| 966 } |
| 967 CFX_DIBitmap bitmap; |
| 968 if (m_bpp == 8) { |
| 969 if (!bitmap.Create(pixel_width, pixel_height, FXDIB_8bppMask)) |
| 970 return FALSE; |
| 971 } else { |
| 972 if (!CreateCompatibleBitmap(&bitmap, pixel_width, pixel_height)) |
| 973 return FALSE; |
| 974 } |
| 975 if (!bitmap.HasAlpha() && !bitmap.IsAlphaMask()) { |
| 976 bitmap.Clear(0xFFFFFFFF); |
| 977 if (!GetDIBits(&bitmap, bmp_rect.left, bmp_rect.top)) |
| 978 return FALSE; |
| 979 } else { |
| 980 bitmap.Clear(0); |
| 981 if (bitmap.m_pAlphaMask) |
| 982 bitmap.m_pAlphaMask->Clear(0); |
| 983 } |
| 984 int dest_width = pixel_width; |
| 985 int a = 0; |
| 986 int r = 0; |
| 987 int g = 0; |
| 988 int b = 0; |
| 989 if (anti_alias == FXFT_RENDER_MODE_LCD) |
| 990 ArgbDecode(fill_color, a, r, g, b); |
| 991 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { |
| 992 if (!glyph.m_pGlyph) |
| 993 continue; |
| 994 const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; |
| 995 int left = glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left; |
| 996 int top = glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top; |
| 997 int ncols = pGlyph->GetWidth(); |
| 998 int nrows = pGlyph->GetHeight(); |
| 999 if (anti_alias == FXFT_RENDER_MODE_NORMAL) { |
| 1000 if (!bitmap.CompositeMask(left, top, ncols, nrows, pGlyph, fill_color, 0, |
| 1001 0, FXDIB_BLEND_NORMAL, nullptr, FALSE, 0, |
| 1002 nullptr)) { |
| 1003 return FALSE; |
| 1004 } |
| 1005 continue; |
| 1006 } |
| 1007 bool bBGRStripe = !!(text_flags & FXTEXT_BGR_STRIPE); |
| 1008 ncols /= 3; |
| 1009 int x_subpixel = (int)(glyph.m_fOriginX * 3) % 3; |
| 1010 int start_col = std::max(left, 0); |
| 1011 int end_col = std::min(left + ncols, dest_width); |
| 1012 if (start_col >= end_col) |
| 1013 continue; |
| 1014 DrawNormalTextHelper(&bitmap, pGlyph, nrows, left, top, start_col, end_col, |
| 1015 bNormal, bBGRStripe, x_subpixel, a, r, g, b); |
| 1016 } |
| 1017 if (bitmap.IsAlphaMask()) |
| 1018 SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); |
| 1019 else |
| 1020 SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); |
| 1021 return TRUE; |
| 1022 } |
| 1023 |
| 1024 FX_BOOL CFX_RenderDevice::DrawTextPathWithFlags( |
| 1025 int nChars, |
| 1026 const FXTEXT_CHARPOS* pCharPos, |
| 1027 CFX_Font* pFont, |
| 1028 CFX_FontCache* pCache, |
| 1029 FX_FLOAT font_size, |
| 1030 const CFX_Matrix* pText2User, |
| 1031 const CFX_Matrix* pUser2Device, |
| 1032 const CFX_GraphStateData* pGraphState, |
| 1033 uint32_t fill_color, |
| 1034 FX_ARGB stroke_color, |
| 1035 CFX_PathData* pClippingPath, |
| 1036 int nFlag) { |
| 1037 if (!pCache) |
| 1038 pCache = CFX_GEModule::Get()->GetFontCache(); |
| 1039 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); |
| 1040 CFX_AutoFontCache autoFontCache(pCache, pFont); |
| 1041 for (int iChar = 0; iChar < nChars; iChar++) { |
| 1042 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; |
| 1043 CFX_Matrix matrix; |
| 1044 if (charpos.m_bGlyphAdjust) { |
| 1045 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
| 1046 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
| 1047 } |
| 1048 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, |
| 1049 charpos.m_OriginY); |
| 1050 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( |
| 1051 pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); |
| 1052 if (!pPath) |
| 1053 continue; |
| 1054 matrix.Concat(*pText2User); |
| 1055 CFX_PathData TransformedPath(*pPath); |
| 1056 TransformedPath.Transform(&matrix); |
| 1057 if (fill_color || stroke_color) { |
| 1058 int fill_mode = nFlag; |
| 1059 if (fill_color) |
| 1060 fill_mode |= FXFILL_WINDING; |
| 1061 fill_mode |= FX_FILL_TEXT_MODE; |
| 1062 if (!DrawPathWithBlend(&TransformedPath, pUser2Device, pGraphState, |
| 1063 fill_color, stroke_color, fill_mode, |
| 1064 FXDIB_BLEND_NORMAL)) { |
| 1065 return FALSE; |
| 1066 } |
| 1067 } |
| 1068 if (pClippingPath) |
| 1069 pClippingPath->Append(&TransformedPath, pUser2Device); |
| 1070 } |
| 1071 return TRUE; |
| 1072 } |
OLD | NEW |