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 UpdateClipBox(); |
| 451 return TRUE; |
| 452 } |
| 453 |
| 454 void CFX_RenderDevice::UpdateClipBox() { |
| 455 if (m_pDeviceDriver->GetClipBox(&m_ClipBox)) |
| 456 return; |
| 457 m_ClipBox.left = 0; |
| 458 m_ClipBox.top = 0; |
| 459 m_ClipBox.right = m_Width; |
| 460 m_ClipBox.bottom = m_Height; |
| 461 } |
| 462 |
| 463 FX_BOOL CFX_RenderDevice::DrawPathWithBlend( |
| 464 const CFX_PathData* pPathData, |
| 465 const CFX_Matrix* pObject2Device, |
| 466 const CFX_GraphStateData* pGraphState, |
| 467 uint32_t fill_color, |
| 468 uint32_t stroke_color, |
| 469 int fill_mode, |
| 470 int blend_type) { |
| 471 uint8_t stroke_alpha = pGraphState ? FXARGB_A(stroke_color) : 0; |
| 472 uint8_t fill_alpha = (fill_mode & 3) ? FXARGB_A(fill_color) : 0; |
| 473 if (stroke_alpha == 0 && pPathData->GetPointCount() == 2) { |
| 474 FX_PATHPOINT* pPoints = pPathData->GetPoints(); |
| 475 FX_FLOAT x1, x2, y1, y2; |
| 476 if (pObject2Device) { |
| 477 pObject2Device->Transform(pPoints[0].m_PointX, pPoints[0].m_PointY, x1, |
| 478 y1); |
| 479 pObject2Device->Transform(pPoints[1].m_PointX, pPoints[1].m_PointY, x2, |
| 480 y2); |
| 481 } else { |
| 482 x1 = pPoints[0].m_PointX; |
| 483 y1 = pPoints[0].m_PointY; |
| 484 x2 = pPoints[1].m_PointX; |
| 485 y2 = pPoints[1].m_PointY; |
| 486 } |
| 487 DrawCosmeticLineWithFillModeAndBlend(x1, y1, x2, y2, fill_color, fill_mode, |
| 488 blend_type); |
| 489 return TRUE; |
| 490 } |
| 491 if ((pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) && |
| 492 stroke_alpha == 0) { |
| 493 CFX_FloatRect rect_f; |
| 494 if (!(fill_mode & FXFILL_RECT_AA) && |
| 495 pPathData->IsRect(pObject2Device, &rect_f)) { |
| 496 FX_RECT rect_i = rect_f.GetOutterRect(); |
| 497 int width = (int)FXSYS_ceil(rect_f.right - rect_f.left); |
| 498 if (width < 1) { |
| 499 width = 1; |
| 500 if (rect_i.left == rect_i.right) |
| 501 rect_i.right++; |
| 502 } |
| 503 int height = (int)FXSYS_ceil(rect_f.top - rect_f.bottom); |
| 504 if (height < 1) { |
| 505 height = 1; |
| 506 if (rect_i.bottom == rect_i.top) |
| 507 rect_i.bottom++; |
| 508 } |
| 509 if (rect_i.Width() >= width + 1) { |
| 510 if (rect_f.left - (FX_FLOAT)(rect_i.left) > |
| 511 (FX_FLOAT)(rect_i.right) - rect_f.right) { |
| 512 rect_i.left++; |
| 513 } else { |
| 514 rect_i.right--; |
| 515 } |
| 516 } |
| 517 if (rect_i.Height() >= height + 1) { |
| 518 if (rect_f.top - (FX_FLOAT)(rect_i.top) > |
| 519 (FX_FLOAT)(rect_i.bottom) - rect_f.bottom) { |
| 520 rect_i.top++; |
| 521 } else { |
| 522 rect_i.bottom--; |
| 523 } |
| 524 } |
| 525 if (FillRectWithBlend(&rect_i, fill_color, blend_type)) { |
| 526 return TRUE; |
| 527 } |
| 528 } |
| 529 } |
| 530 if ((fill_mode & 3) && stroke_alpha == 0 && !(fill_mode & FX_FILL_STROKE) && |
| 531 !(fill_mode & FX_FILL_TEXT_MODE)) { |
| 532 CFX_PathData newPath; |
| 533 FX_BOOL bThin = FALSE; |
| 534 if (pPathData->GetZeroAreaPath(newPath, (CFX_Matrix*)pObject2Device, bThin, |
| 535 m_pDeviceDriver->GetDriverType())) { |
| 536 CFX_GraphStateData graphState; |
| 537 graphState.m_LineWidth = 0.0f; |
| 538 uint32_t strokecolor = fill_color; |
| 539 if (bThin) |
| 540 strokecolor = (((fill_alpha >> 2) << 24) | (strokecolor & 0x00ffffff)); |
| 541 CFX_Matrix* pMatrix = nullptr; |
| 542 if (pObject2Device && !pObject2Device->IsIdentity()) |
| 543 pMatrix = (CFX_Matrix*)pObject2Device; |
| 544 int smooth_path = FX_ZEROAREA_FILL; |
| 545 if (fill_mode & FXFILL_NOPATHSMOOTH) |
| 546 smooth_path |= FXFILL_NOPATHSMOOTH; |
| 547 m_pDeviceDriver->DrawPath(&newPath, pMatrix, &graphState, 0, strokecolor, |
| 548 smooth_path, blend_type); |
| 549 } |
| 550 } |
| 551 if ((fill_mode & 3) && fill_alpha && stroke_alpha < 0xff && |
| 552 (fill_mode & FX_FILL_STROKE)) { |
| 553 if (m_RenderCaps & FXRC_FILLSTROKE_PATH) { |
| 554 return m_pDeviceDriver->DrawPath(pPathData, pObject2Device, pGraphState, |
| 555 fill_color, stroke_color, fill_mode, |
| 556 blend_type); |
| 557 } |
| 558 return DrawFillStrokePath(pPathData, pObject2Device, pGraphState, |
| 559 fill_color, stroke_color, fill_mode, blend_type); |
| 560 } |
| 561 return m_pDeviceDriver->DrawPath(pPathData, pObject2Device, pGraphState, |
| 562 fill_color, stroke_color, fill_mode, |
| 563 blend_type); |
| 564 } |
| 565 |
| 566 // This can be removed once PDFium entirely relies on Skia |
| 567 FX_BOOL CFX_RenderDevice::DrawFillStrokePath( |
| 568 const CFX_PathData* pPathData, |
| 569 const CFX_Matrix* pObject2Device, |
| 570 const CFX_GraphStateData* pGraphState, |
| 571 uint32_t fill_color, |
| 572 uint32_t stroke_color, |
| 573 int fill_mode, |
| 574 int blend_type) { |
| 575 if (!(m_RenderCaps & FXRC_GET_BITS)) |
| 576 return FALSE; |
| 577 CFX_FloatRect bbox; |
| 578 if (pGraphState) { |
| 579 bbox = pPathData->GetBoundingBox(pGraphState->m_LineWidth, |
| 580 pGraphState->m_MiterLimit); |
| 581 } else { |
| 582 bbox = pPathData->GetBoundingBox(); |
| 583 } |
| 584 if (pObject2Device) |
| 585 bbox.Transform(pObject2Device); |
| 586 CFX_Matrix ctm = GetCTM(); |
| 587 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a); |
| 588 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d); |
| 589 FX_RECT rect = bbox.GetOutterRect(); |
| 590 CFX_DIBitmap bitmap, Backdrop; |
| 591 if (!CreateCompatibleBitmap(&bitmap, FXSYS_round(rect.Width() * fScaleX), |
| 592 FXSYS_round(rect.Height() * fScaleY))) { |
| 593 return FALSE; |
| 594 } |
| 595 if (bitmap.HasAlpha()) { |
| 596 bitmap.Clear(0); |
| 597 Backdrop.Copy(&bitmap); |
| 598 } else { |
| 599 if (!m_pDeviceDriver->GetDIBits(&bitmap, rect.left, rect.top)) |
| 600 return FALSE; |
| 601 Backdrop.Copy(&bitmap); |
| 602 } |
| 603 CFX_FxgeDevice bitmap_device; |
| 604 bitmap_device.Attach(&bitmap, false, &Backdrop, true); |
| 605 CFX_Matrix matrix; |
| 606 if (pObject2Device) |
| 607 matrix = *pObject2Device; |
| 608 matrix.TranslateI(-rect.left, -rect.top); |
| 609 matrix.Concat(fScaleX, 0, 0, fScaleY, 0, 0); |
| 610 if (!bitmap_device.GetDeviceDriver()->DrawPath( |
| 611 pPathData, &matrix, pGraphState, fill_color, stroke_color, fill_mode, |
| 612 blend_type)) { |
| 613 return FALSE; |
| 614 } |
| 615 FX_RECT src_rect(0, 0, FXSYS_round(rect.Width() * fScaleX), |
| 616 FXSYS_round(rect.Height() * fScaleY)); |
| 617 return m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, rect.left, rect.top, |
| 618 FXDIB_BLEND_NORMAL); |
| 619 } |
| 620 |
| 621 FX_BOOL CFX_RenderDevice::SetPixel(int x, int y, uint32_t color) { |
| 622 if (m_pDeviceDriver->SetPixel(x, y, color)) |
| 623 return TRUE; |
| 624 |
| 625 FX_RECT rect(x, y, x + 1, y + 1); |
| 626 return FillRectWithBlend(&rect, color, FXDIB_BLEND_NORMAL); |
| 627 } |
| 628 |
| 629 FX_BOOL CFX_RenderDevice::FillRectWithBlend(const FX_RECT* pRect, |
| 630 uint32_t fill_color, |
| 631 int blend_type) { |
| 632 if (m_pDeviceDriver->FillRectWithBlend(pRect, fill_color, blend_type)) |
| 633 return TRUE; |
| 634 if (!(m_RenderCaps & FXRC_GET_BITS)) |
| 635 return FALSE; |
| 636 CFX_DIBitmap bitmap; |
| 637 if (!CreateCompatibleBitmap(&bitmap, pRect->Width(), pRect->Height())) |
| 638 return FALSE; |
| 639 if (!m_pDeviceDriver->GetDIBits(&bitmap, pRect->left, pRect->top)) |
| 640 return FALSE; |
| 641 if (!bitmap.CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color, |
| 642 0, nullptr)) { |
| 643 return FALSE; |
| 644 } |
| 645 FX_RECT src_rect(0, 0, pRect->Width(), pRect->Height()); |
| 646 m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, pRect->left, pRect->top, |
| 647 FXDIB_BLEND_NORMAL); |
| 648 return TRUE; |
| 649 } |
| 650 |
| 651 FX_BOOL CFX_RenderDevice::DrawCosmeticLineWithFillModeAndBlend(FX_FLOAT x1, |
| 652 FX_FLOAT y1, |
| 653 FX_FLOAT x2, |
| 654 FX_FLOAT y2, |
| 655 uint32_t color, |
| 656 int fill_mode, |
| 657 int blend_type) { |
| 658 if ((color >= 0xff000000) && |
| 659 m_pDeviceDriver->DrawCosmeticLine(x1, y1, x2, y2, color, blend_type)) { |
| 660 return TRUE; |
| 661 } |
| 662 CFX_GraphStateData graph_state; |
| 663 CFX_PathData path; |
| 664 path.SetPointCount(2); |
| 665 path.SetPoint(0, x1, y1, FXPT_MOVETO); |
| 666 path.SetPoint(1, x2, y2, FXPT_LINETO); |
| 667 return m_pDeviceDriver->DrawPath(&path, nullptr, &graph_state, 0, color, |
| 668 fill_mode, blend_type); |
| 669 } |
| 670 |
| 671 FX_BOOL CFX_RenderDevice::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { |
| 672 if (!(m_RenderCaps & FXRC_GET_BITS)) |
| 673 return FALSE; |
| 674 return m_pDeviceDriver->GetDIBits(pBitmap, left, top); |
| 675 } |
| 676 |
| 677 CFX_DIBitmap* CFX_RenderDevice::GetBackDrop() { |
| 678 return m_pDeviceDriver->GetBackDrop(); |
| 679 } |
| 680 |
| 681 FX_BOOL CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap, |
| 682 int left, |
| 683 int top, |
| 684 int blend_mode) { |
| 685 ASSERT(!pBitmap->IsAlphaMask()); |
| 686 CFX_Matrix ctm = GetCTM(); |
| 687 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a); |
| 688 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d); |
| 689 FX_RECT dest_rect(left, top, |
| 690 FXSYS_round(left + pBitmap->GetWidth() / fScaleX), |
| 691 FXSYS_round(top + pBitmap->GetHeight() / fScaleY)); |
| 692 dest_rect.Intersect(m_ClipBox); |
| 693 if (dest_rect.IsEmpty()) |
| 694 return TRUE; |
| 695 FX_RECT src_rect(dest_rect.left - left, dest_rect.top - top, |
| 696 dest_rect.left - left + dest_rect.Width(), |
| 697 dest_rect.top - top + dest_rect.Height()); |
| 698 src_rect.left = FXSYS_round(src_rect.left * fScaleX); |
| 699 src_rect.top = FXSYS_round(src_rect.top * fScaleY); |
| 700 src_rect.right = FXSYS_round(src_rect.right * fScaleX); |
| 701 src_rect.bottom = FXSYS_round(src_rect.bottom * fScaleY); |
| 702 if ((blend_mode != FXDIB_BLEND_NORMAL && !(m_RenderCaps & FXRC_BLEND_MODE)) || |
| 703 (pBitmap->HasAlpha() && !(m_RenderCaps & FXRC_ALPHA_IMAGE))) { |
| 704 if (!(m_RenderCaps & FXRC_GET_BITS)) |
| 705 return FALSE; |
| 706 int bg_pixel_width = FXSYS_round(dest_rect.Width() * fScaleX); |
| 707 int bg_pixel_height = FXSYS_round(dest_rect.Height() * fScaleY); |
| 708 CFX_DIBitmap background; |
| 709 if (!background.Create( |
| 710 bg_pixel_width, bg_pixel_height, |
| 711 (m_RenderCaps & FXRC_CMYK_OUTPUT) ? FXDIB_Cmyk : FXDIB_Rgb32)) { |
| 712 return FALSE; |
| 713 } |
| 714 if (!m_pDeviceDriver->GetDIBits(&background, dest_rect.left, |
| 715 dest_rect.top)) { |
| 716 return FALSE; |
| 717 } |
| 718 if (!background.CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height, |
| 719 pBitmap, src_rect.left, src_rect.top, |
| 720 blend_mode, nullptr, FALSE, nullptr)) { |
| 721 return FALSE; |
| 722 } |
| 723 FX_RECT rect(0, 0, bg_pixel_width, bg_pixel_height); |
| 724 return m_pDeviceDriver->SetDIBits(&background, 0, &rect, dest_rect.left, |
| 725 dest_rect.top, FXDIB_BLEND_NORMAL); |
| 726 } |
| 727 return m_pDeviceDriver->SetDIBits(pBitmap, 0, &src_rect, dest_rect.left, |
| 728 dest_rect.top, blend_mode); |
| 729 } |
| 730 |
| 731 FX_BOOL CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend( |
| 732 const CFX_DIBSource* pBitmap, |
| 733 int left, |
| 734 int top, |
| 735 int dest_width, |
| 736 int dest_height, |
| 737 uint32_t flags, |
| 738 int blend_mode) { |
| 739 FX_RECT dest_rect(left, top, left + dest_width, top + dest_height); |
| 740 FX_RECT clip_box = m_ClipBox; |
| 741 clip_box.Intersect(dest_rect); |
| 742 if (clip_box.IsEmpty()) |
| 743 return TRUE; |
| 744 return m_pDeviceDriver->StretchDIBits(pBitmap, 0, left, top, dest_width, |
| 745 dest_height, &clip_box, flags, |
| 746 blend_mode); |
| 747 } |
| 748 |
| 749 FX_BOOL CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap, |
| 750 int left, |
| 751 int top, |
| 752 uint32_t argb) { |
| 753 FX_RECT src_rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); |
| 754 return m_pDeviceDriver->SetDIBits(pBitmap, argb, &src_rect, left, top, |
| 755 FXDIB_BLEND_NORMAL); |
| 756 } |
| 757 |
| 758 FX_BOOL CFX_RenderDevice::StretchBitMask(const CFX_DIBSource* pBitmap, |
| 759 int left, |
| 760 int top, |
| 761 int dest_width, |
| 762 int dest_height, |
| 763 uint32_t color) { |
| 764 return StretchBitMaskWithFlags(pBitmap, left, top, dest_width, dest_height, |
| 765 color, 0); |
| 766 } |
| 767 |
| 768 FX_BOOL CFX_RenderDevice::StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap, |
| 769 int left, |
| 770 int top, |
| 771 int dest_width, |
| 772 int dest_height, |
| 773 uint32_t argb, |
| 774 uint32_t flags) { |
| 775 FX_RECT dest_rect(left, top, left + dest_width, top + dest_height); |
| 776 FX_RECT clip_box = m_ClipBox; |
| 777 clip_box.Intersect(dest_rect); |
| 778 return m_pDeviceDriver->StretchDIBits(pBitmap, argb, left, top, dest_width, |
| 779 dest_height, &clip_box, flags, |
| 780 FXDIB_BLEND_NORMAL); |
| 781 } |
| 782 |
| 783 FX_BOOL CFX_RenderDevice::StartDIBitsWithBlend(const CFX_DIBSource* pBitmap, |
| 784 int bitmap_alpha, |
| 785 uint32_t argb, |
| 786 const CFX_Matrix* pMatrix, |
| 787 uint32_t flags, |
| 788 void*& handle, |
| 789 int blend_mode) { |
| 790 return m_pDeviceDriver->StartDIBits(pBitmap, bitmap_alpha, argb, pMatrix, |
| 791 flags, handle, blend_mode); |
| 792 } |
| 793 |
| 794 FX_BOOL CFX_RenderDevice::ContinueDIBits(void* handle, IFX_Pause* pPause) { |
| 795 return m_pDeviceDriver->ContinueDIBits(handle, pPause); |
| 796 } |
| 797 |
| 798 void CFX_RenderDevice::CancelDIBits(void* handle) { |
| 799 m_pDeviceDriver->CancelDIBits(handle); |
| 800 } |
| 801 |
| 802 #ifdef _SKIA_SUPPORT_ |
| 803 void CFX_RenderDevice::DebugVerifyBitmapIsPreMultiplied() const { |
| 804 SkASSERT(0); |
| 805 } |
| 806 #endif |
| 807 |
| 808 FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, |
| 809 const FXTEXT_CHARPOS* pCharPos, |
| 810 CFX_Font* pFont, |
| 811 CFX_FontCache* pCache, |
| 812 FX_FLOAT font_size, |
| 813 const CFX_Matrix* pText2Device, |
| 814 uint32_t fill_color, |
| 815 uint32_t text_flags) { |
| 816 int nativetext_flags = text_flags; |
| 817 if (m_DeviceClass != FXDC_DISPLAY) { |
| 818 if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { |
| 819 if (ShouldDrawDeviceText(pFont, text_flags) && |
| 820 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, |
| 821 pText2Device, font_size, |
| 822 fill_color)) { |
| 823 return TRUE; |
| 824 } |
| 825 } |
| 826 if (FXARGB_A(fill_color) < 255) |
| 827 return FALSE; |
| 828 } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) { |
| 829 if (ShouldDrawDeviceText(pFont, text_flags) && |
| 830 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, |
| 831 pText2Device, font_size, fill_color)) { |
| 832 return TRUE; |
| 833 } |
| 834 } |
| 835 CFX_Matrix char2device; |
| 836 CFX_Matrix text2Device; |
| 837 if (pText2Device) { |
| 838 char2device = *pText2Device; |
| 839 text2Device = *pText2Device; |
| 840 } |
| 841 char2device.Scale(font_size, -font_size); |
| 842 if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || |
| 843 ((m_DeviceClass == FXDC_PRINTER) && |
| 844 !(text_flags & FXTEXT_PRINTIMAGETEXT))) { |
| 845 if (pFont->GetFace() || |
| 846 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { |
| 847 int nPathFlags = |
| 848 (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH; |
| 849 return DrawTextPathWithFlags(nChars, pCharPos, pFont, pCache, font_size, |
| 850 pText2Device, nullptr, nullptr, fill_color, |
| 851 0, nullptr, nPathFlags); |
| 852 } |
| 853 } |
| 854 int anti_alias = FXFT_RENDER_MODE_MONO; |
| 855 bool bNormal = false; |
| 856 if ((text_flags & FXTEXT_NOSMOOTH) == 0) { |
| 857 if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) { |
| 858 if (!CFX_GEModule::Get()->GetFontMgr()->FTLibrarySupportsHinting()) { |
| 859 // Some Freetype implementations (like the one packaged with Fedora) do |
| 860 // not support hinting due to patents 6219025, 6239783, 6307566, |
| 861 // 6225973, 6243070, 6393145, 6421054, 6282327, and 6624828; the latest |
| 862 // one expires 10/7/19. This makes LCD antialiasing very ugly, so we |
| 863 // instead fall back on NORMAL antialiasing. |
| 864 anti_alias = FXFT_RENDER_MODE_NORMAL; |
| 865 } else if ((m_RenderCaps & (FXRC_ALPHA_OUTPUT | FXRC_CMYK_OUTPUT))) { |
| 866 anti_alias = FXFT_RENDER_MODE_LCD; |
| 867 bNormal = true; |
| 868 } else if (m_bpp < 16) { |
| 869 anti_alias = FXFT_RENDER_MODE_NORMAL; |
| 870 } else { |
| 871 anti_alias = FXFT_RENDER_MODE_LCD; |
| 872 |
| 873 bool bClearType = false; |
| 874 if (pFont->GetFace() || |
| 875 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_CLEARTYPE)) { |
| 876 bClearType = !!(text_flags & FXTEXT_CLEARTYPE); |
| 877 } |
| 878 bNormal = !bClearType; |
| 879 } |
| 880 } |
| 881 } |
| 882 if (!pCache) |
| 883 pCache = CFX_GEModule::Get()->GetFontCache(); |
| 884 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); |
| 885 CFX_AutoFontCache autoFontCache(pCache, pFont); |
| 886 std::vector<FXTEXT_GLYPHPOS> glyphs(nChars); |
| 887 CFX_Matrix matrixCTM = GetCTM(); |
| 888 FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a); |
| 889 FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d); |
| 890 CFX_Matrix deviceCtm = char2device; |
| 891 deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0); |
| 892 text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0); |
| 893 for (size_t i = 0; i < glyphs.size(); ++i) { |
| 894 FXTEXT_GLYPHPOS& glyph = glyphs[i]; |
| 895 const FXTEXT_CHARPOS& charpos = pCharPos[i]; |
| 896 glyph.m_fOriginX = charpos.m_OriginX; |
| 897 glyph.m_fOriginY = charpos.m_OriginY; |
| 898 text2Device.Transform(glyph.m_fOriginX, glyph.m_fOriginY); |
| 899 if (anti_alias < FXFT_RENDER_MODE_LCD) |
| 900 glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX); |
| 901 else |
| 902 glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX); |
| 903 glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY); |
| 904 if (charpos.m_bGlyphAdjust) { |
| 905 CFX_Matrix new_matrix( |
| 906 charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
| 907 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
| 908 new_matrix.Concat(deviceCtm); |
| 909 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( |
| 910 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &new_matrix, |
| 911 charpos.m_FontCharWidth, anti_alias, nativetext_flags); |
| 912 } else { |
| 913 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( |
| 914 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &deviceCtm, |
| 915 charpos.m_FontCharWidth, anti_alias, nativetext_flags); |
| 916 } |
| 917 } |
| 918 if (anti_alias < FXFT_RENDER_MODE_LCD && glyphs.size() > 1) |
| 919 AdjustGlyphSpace(&glyphs); |
| 920 |
| 921 FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(glyphs, anti_alias); |
| 922 if (scale_x > 1 && scale_y > 1) { |
| 923 bmp_rect1.left--; |
| 924 bmp_rect1.top--; |
| 925 bmp_rect1.right++; |
| 926 bmp_rect1.bottom++; |
| 927 } |
| 928 FX_RECT bmp_rect(FXSYS_round((FX_FLOAT)(bmp_rect1.left) / scale_x), |
| 929 FXSYS_round((FX_FLOAT)(bmp_rect1.top) / scale_y), |
| 930 FXSYS_round((FX_FLOAT)bmp_rect1.right / scale_x), |
| 931 FXSYS_round((FX_FLOAT)bmp_rect1.bottom / scale_y)); |
| 932 bmp_rect.Intersect(m_ClipBox); |
| 933 if (bmp_rect.IsEmpty()) |
| 934 return TRUE; |
| 935 int pixel_width = FXSYS_round(bmp_rect.Width() * scale_x); |
| 936 int pixel_height = FXSYS_round(bmp_rect.Height() * scale_y); |
| 937 int pixel_left = FXSYS_round(bmp_rect.left * scale_x); |
| 938 int pixel_top = FXSYS_round(bmp_rect.top * scale_y); |
| 939 if (anti_alias == FXFT_RENDER_MODE_MONO) { |
| 940 CFX_DIBitmap bitmap; |
| 941 if (!bitmap.Create(pixel_width, pixel_height, FXDIB_1bppMask)) |
| 942 return FALSE; |
| 943 bitmap.Clear(0); |
| 944 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { |
| 945 if (!glyph.m_pGlyph) |
| 946 continue; |
| 947 const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; |
| 948 bitmap.TransferBitmap( |
| 949 glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left, |
| 950 glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top, |
| 951 pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0, 0); |
| 952 } |
| 953 return SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); |
| 954 } |
| 955 CFX_DIBitmap bitmap; |
| 956 if (m_bpp == 8) { |
| 957 if (!bitmap.Create(pixel_width, pixel_height, FXDIB_8bppMask)) |
| 958 return FALSE; |
| 959 } else { |
| 960 if (!CreateCompatibleBitmap(&bitmap, pixel_width, pixel_height)) |
| 961 return FALSE; |
| 962 } |
| 963 if (!bitmap.HasAlpha() && !bitmap.IsAlphaMask()) { |
| 964 bitmap.Clear(0xFFFFFFFF); |
| 965 if (!GetDIBits(&bitmap, bmp_rect.left, bmp_rect.top)) |
| 966 return FALSE; |
| 967 } else { |
| 968 bitmap.Clear(0); |
| 969 if (bitmap.m_pAlphaMask) |
| 970 bitmap.m_pAlphaMask->Clear(0); |
| 971 } |
| 972 int dest_width = pixel_width; |
| 973 int a = 0; |
| 974 int r = 0; |
| 975 int g = 0; |
| 976 int b = 0; |
| 977 if (anti_alias == FXFT_RENDER_MODE_LCD) |
| 978 ArgbDecode(fill_color, a, r, g, b); |
| 979 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { |
| 980 if (!glyph.m_pGlyph) |
| 981 continue; |
| 982 const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; |
| 983 int left = glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left; |
| 984 int top = glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top; |
| 985 int ncols = pGlyph->GetWidth(); |
| 986 int nrows = pGlyph->GetHeight(); |
| 987 if (anti_alias == FXFT_RENDER_MODE_NORMAL) { |
| 988 if (!bitmap.CompositeMask(left, top, ncols, nrows, pGlyph, fill_color, 0, |
| 989 0, FXDIB_BLEND_NORMAL, nullptr, FALSE, 0, |
| 990 nullptr)) { |
| 991 return FALSE; |
| 992 } |
| 993 continue; |
| 994 } |
| 995 bool bBGRStripe = !!(text_flags & FXTEXT_BGR_STRIPE); |
| 996 ncols /= 3; |
| 997 int x_subpixel = (int)(glyph.m_fOriginX * 3) % 3; |
| 998 int start_col = std::max(left, 0); |
| 999 int end_col = std::min(left + ncols, dest_width); |
| 1000 if (start_col >= end_col) |
| 1001 continue; |
| 1002 DrawNormalTextHelper(&bitmap, pGlyph, nrows, left, top, start_col, end_col, |
| 1003 bNormal, bBGRStripe, x_subpixel, a, r, g, b); |
| 1004 } |
| 1005 if (bitmap.IsAlphaMask()) |
| 1006 SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); |
| 1007 else |
| 1008 SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); |
| 1009 return TRUE; |
| 1010 } |
| 1011 |
| 1012 FX_BOOL CFX_RenderDevice::DrawTextPathWithFlags( |
| 1013 int nChars, |
| 1014 const FXTEXT_CHARPOS* pCharPos, |
| 1015 CFX_Font* pFont, |
| 1016 CFX_FontCache* pCache, |
| 1017 FX_FLOAT font_size, |
| 1018 const CFX_Matrix* pText2User, |
| 1019 const CFX_Matrix* pUser2Device, |
| 1020 const CFX_GraphStateData* pGraphState, |
| 1021 uint32_t fill_color, |
| 1022 FX_ARGB stroke_color, |
| 1023 CFX_PathData* pClippingPath, |
| 1024 int nFlag) { |
| 1025 if (!pCache) |
| 1026 pCache = CFX_GEModule::Get()->GetFontCache(); |
| 1027 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); |
| 1028 CFX_AutoFontCache autoFontCache(pCache, pFont); |
| 1029 for (int iChar = 0; iChar < nChars; iChar++) { |
| 1030 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; |
| 1031 CFX_Matrix matrix; |
| 1032 if (charpos.m_bGlyphAdjust) { |
| 1033 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
| 1034 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
| 1035 } |
| 1036 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, |
| 1037 charpos.m_OriginY); |
| 1038 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( |
| 1039 pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); |
| 1040 if (!pPath) |
| 1041 continue; |
| 1042 matrix.Concat(*pText2User); |
| 1043 CFX_PathData TransformedPath(*pPath); |
| 1044 TransformedPath.Transform(&matrix); |
| 1045 if (fill_color || stroke_color) { |
| 1046 int fill_mode = nFlag; |
| 1047 if (fill_color) |
| 1048 fill_mode |= FXFILL_WINDING; |
| 1049 fill_mode |= FX_FILL_TEXT_MODE; |
| 1050 if (!DrawPathWithBlend(&TransformedPath, pUser2Device, pGraphState, |
| 1051 fill_color, stroke_color, fill_mode, |
| 1052 FXDIB_BLEND_NORMAL)) { |
| 1053 return FALSE; |
| 1054 } |
| 1055 } |
| 1056 if (pClippingPath) |
| 1057 pClippingPath->Append(&TransformedPath, pUser2Device); |
| 1058 } |
| 1059 return TRUE; |
| 1060 } |
OLD | NEW |