diff options
author | npm <npm@chromium.org> | 2016-08-10 07:51:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-10 07:51:39 -0700 |
commit | 9ada2d83cbb629f286936ebc7a208a61164f873b (patch) | |
tree | 227aa12df825dbda00a961bd894c35d9987638f2 /core/fxge/ge/fx_ge_text.cpp | |
parent | f3dc8c6941635e5c4cc20c8388289f6b148dc9eb (diff) | |
download | pdfium-9ada2d83cbb629f286936ebc7a208a61164f873b.tar.xz |
Move CFX_RenderDevice, CFX_FxgeDevice, and CFX_GraphStateData into their own files.
This is the third CL to separate fx_ge into classes, one per file.
All fx_ge.h includes had to be replaced with new includes
The method definitions for CFX_FxgeDevice were not moved to a single file.
These methods are defined in two folders different from fxge/ge, so they were left untouched for now.
Review-Url: https://codereview.chromium.org/2223213002
Diffstat (limited to 'core/fxge/ge/fx_ge_text.cpp')
-rw-r--r-- | core/fxge/ge/fx_ge_text.cpp | 588 |
1 files changed, 0 insertions, 588 deletions
diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp index 83655495b3..ac110b0291 100644 --- a/core/fxge/ge/fx_ge_text.cpp +++ b/core/fxge/ge/fx_ge_text.cpp @@ -13,7 +13,6 @@ #include "core/fxge/include/cfx_gemodule.h" #include "core/fxge/include/cfx_pathdata.h" #include "core/fxge/include/fx_freetype.h" -#include "core/fxge/include/fx_ge.h" #include "core/fxge/include/ifx_renderdevicedriver.h" #ifdef _SKIA_SUPPORT_ @@ -46,326 +45,6 @@ class ScopedFontTransform { FT_Face m_Face; }; -void AdjustGlyphSpace(std::vector<FXTEXT_GLYPHPOS>* pGlyphAndPos) { - ASSERT(pGlyphAndPos->size() > 1); - std::vector<FXTEXT_GLYPHPOS>& glyphs = *pGlyphAndPos; - bool bVertical = glyphs.back().m_OriginX == glyphs.front().m_OriginX; - if (!bVertical && (glyphs.back().m_OriginY != glyphs.front().m_OriginY)) - return; - - for (size_t i = glyphs.size() - 1; i > 1; --i) { - FXTEXT_GLYPHPOS& next = glyphs[i]; - int next_origin = bVertical ? next.m_OriginY : next.m_OriginX; - FX_FLOAT next_origin_f = bVertical ? next.m_fOriginY : next.m_fOriginX; - - FXTEXT_GLYPHPOS& current = glyphs[i - 1]; - int& current_origin = bVertical ? current.m_OriginY : current.m_OriginX; - FX_FLOAT current_origin_f = - bVertical ? current.m_fOriginY : current.m_fOriginX; - - int space = next_origin - current_origin; - FX_FLOAT space_f = next_origin_f - current_origin_f; - FX_FLOAT error = - FXSYS_fabs(space_f) - FXSYS_fabs(static_cast<FX_FLOAT>(space)); - if (error > 0.5f) - current_origin += space > 0 ? -1 : 1; - } -} - -const uint8_t g_TextGammaAdjust[256] = { - 0, 2, 3, 4, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, - 19, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, - 36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, - 68, 69, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, - 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, - 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, - 129, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, - 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 156, - 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, - 200, 201, 202, 203, 204, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, - 214, 215, 216, 217, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, - 228, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 239, 240, - 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 250, 251, 252, 253, 254, - 255, -}; - -int TextGammaAdjust(int value) { - ASSERT(value >= 0); - ASSERT(value <= 255); - return g_TextGammaAdjust[value]; -} - -int CalcAlpha(int src, int alpha) { - return src * alpha / 255; -} - -void Merge(uint8_t src, int channel, int alpha, uint8_t* dest) { - *dest = FXDIB_ALPHA_MERGE(*dest, channel, CalcAlpha(src, alpha)); -} - -void MergeGammaAdjust(uint8_t src, int channel, int alpha, uint8_t* dest) { - *dest = - FXDIB_ALPHA_MERGE(*dest, channel, CalcAlpha(TextGammaAdjust(src), alpha)); -} - -void MergeGammaAdjustBgr(const uint8_t* src, - int r, - int g, - int b, - int a, - uint8_t* dest) { - MergeGammaAdjust(src[0], b, a, &dest[0]); - MergeGammaAdjust(src[1], g, a, &dest[1]); - MergeGammaAdjust(src[2], r, a, &dest[2]); -} - -void MergeGammaAdjustRgb(const uint8_t* src, - int r, - int g, - int b, - int a, - uint8_t* dest) { - MergeGammaAdjust(src[2], b, a, &dest[0]); - MergeGammaAdjust(src[1], g, a, &dest[1]); - MergeGammaAdjust(src[0], r, a, &dest[2]); -} - -int AverageRgb(const uint8_t* src) { - return (src[0] + src[1] + src[2]) / 3; -} - -uint8_t CalculateDestAlpha(uint8_t back_alpha, int src_alpha) { - return back_alpha + src_alpha - back_alpha * src_alpha / 255; -} - -void ApplyDestAlpha(uint8_t back_alpha, - int src_alpha, - int r, - int g, - int b, - uint8_t* dest) { - uint8_t dest_alpha = CalculateDestAlpha(back_alpha, src_alpha); - int alpha_ratio = src_alpha * 255 / dest_alpha; - dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, alpha_ratio); - dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, alpha_ratio); - dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, alpha_ratio); - dest[3] = dest_alpha; -} - -void NormalizeRgbDst(int src_value, int r, int g, int b, int a, uint8_t* dest) { - int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); - dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, src_alpha); - dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, src_alpha); - dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, src_alpha); -} - -void NormalizeRgbSrc(int src_value, int r, int g, int b, int a, uint8_t* dest) { - int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); - if (src_alpha == 0) - return; - - dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, src_alpha); - dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, src_alpha); - dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, src_alpha); -} - -void NormalizeArgbDest(int src_value, - int r, - int g, - int b, - int a, - uint8_t* dest) { - int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); - uint8_t back_alpha = dest[3]; - if (back_alpha == 0) { - FXARGB_SETDIB(dest, FXARGB_MAKE(src_alpha, r, g, b)); - } else if (src_alpha != 0) { - ApplyDestAlpha(back_alpha, src_alpha, r, g, b, dest); - } -} - -void NormalizeArgbSrc(int src_value, - int r, - int g, - int b, - int a, - uint8_t* dest) { - int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); - if (src_alpha == 0) - return; - - uint8_t back_alpha = dest[3]; - if (back_alpha == 0) { - FXARGB_SETDIB(dest, FXARGB_MAKE(src_alpha, r, g, b)); - } else { - ApplyDestAlpha(back_alpha, src_alpha, r, g, b, dest); - } -} - -void NextPixel(uint8_t** src_scan, uint8_t** dst_scan, int bpp) { - *src_scan += 3; - *dst_scan += bpp; -} - -void SetAlpha(uint8_t* alpha) { - alpha[3] = 255; -} - -void SetAlphaDoNothing(uint8_t* alpha) {} - -void DrawNormalTextHelper(CFX_DIBitmap* bitmap, - const CFX_DIBitmap* pGlyph, - int nrows, - int left, - int top, - int start_col, - int end_col, - bool bNormal, - bool bBGRStripe, - int x_subpixel, - int a, - int r, - int g, - int b) { - const bool has_alpha = bitmap->GetFormat() == FXDIB_Argb; - uint8_t* src_buf = pGlyph->GetBuffer(); - int src_pitch = pGlyph->GetPitch(); - uint8_t* dest_buf = bitmap->GetBuffer(); - int dest_pitch = bitmap->GetPitch(); - const int Bpp = has_alpha ? 4 : bitmap->GetBPP() / 8; - auto* pNormalizeSrcFunc = has_alpha ? &NormalizeArgbSrc : &NormalizeRgbDst; - auto* pNormalizeDstFunc = has_alpha ? &NormalizeArgbDest : &NormalizeRgbSrc; - auto* pSetAlpha = has_alpha ? &SetAlpha : &SetAlphaDoNothing; - - for (int row = 0; row < nrows; row++) { - int dest_row = row + top; - if (dest_row < 0 || dest_row >= bitmap->GetHeight()) - continue; - - uint8_t* src_scan = src_buf + row * src_pitch + (start_col - left) * 3; - uint8_t* dest_scan = dest_buf + dest_row * dest_pitch + start_col * Bpp; - if (bBGRStripe) { - if (x_subpixel == 0) { - for (int col = start_col; col < end_col; col++) { - if (has_alpha) { - Merge(src_scan[2], r, a, &dest_scan[2]); - Merge(src_scan[1], g, a, &dest_scan[1]); - Merge(src_scan[0], b, a, &dest_scan[0]); - } else { - MergeGammaAdjustBgr(&src_scan[0], r, g, b, a, &dest_scan[0]); - } - pSetAlpha(dest_scan); - NextPixel(&src_scan, &dest_scan, Bpp); - } - } else if (x_subpixel == 1) { - MergeGammaAdjust(src_scan[1], r, a, &dest_scan[2]); - MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); - if (start_col > left) - MergeGammaAdjust(src_scan[-1], b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - NextPixel(&src_scan, &dest_scan, Bpp); - for (int col = start_col + 1; col < end_col - 1; col++) { - MergeGammaAdjustBgr(&src_scan[-1], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - NextPixel(&src_scan, &dest_scan, Bpp); - } - } else { - MergeGammaAdjust(src_scan[0], r, a, &dest_scan[2]); - if (start_col > left) { - MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); - MergeGammaAdjust(src_scan[-2], b, a, &dest_scan[0]); - } - pSetAlpha(dest_scan); - NextPixel(&src_scan, &dest_scan, Bpp); - for (int col = start_col + 1; col < end_col - 1; col++) { - MergeGammaAdjustBgr(&src_scan[-2], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - NextPixel(&src_scan, &dest_scan, Bpp); - } - } - } else { - if (x_subpixel == 0) { - for (int col = start_col; col < end_col; col++) { - if (bNormal) { - int src_value = AverageRgb(&src_scan[0]); - pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); - } else { - MergeGammaAdjustRgb(&src_scan[0], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - } - NextPixel(&src_scan, &dest_scan, Bpp); - } - } else if (x_subpixel == 1) { - if (bNormal) { - int src_value = start_col > left ? AverageRgb(&src_scan[-1]) - : (src_scan[0] + src_scan[1]) / 3; - pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); - } else { - if (start_col > left) - MergeGammaAdjust(src_scan[-1], r, a, &dest_scan[2]); - MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); - MergeGammaAdjust(src_scan[1], b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - } - NextPixel(&src_scan, &dest_scan, Bpp); - for (int col = start_col + 1; col < end_col; col++) { - if (bNormal) { - int src_value = AverageRgb(&src_scan[-1]); - pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); - } else { - MergeGammaAdjustRgb(&src_scan[-1], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - } - NextPixel(&src_scan, &dest_scan, Bpp); - } - } else { - if (bNormal) { - int src_value = - start_col > left ? AverageRgb(&src_scan[-2]) : src_scan[0] / 3; - pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); - } else { - if (start_col > left) { - MergeGammaAdjust(src_scan[-2], r, a, &dest_scan[2]); - MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); - } - MergeGammaAdjust(src_scan[0], b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - } - NextPixel(&src_scan, &dest_scan, Bpp); - for (int col = start_col + 1; col < end_col; col++) { - if (bNormal) { - int src_value = AverageRgb(&src_scan[-2]); - pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); - } else { - MergeGammaAdjustRgb(&src_scan[-2], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - } - NextPixel(&src_scan, &dest_scan, Bpp); - } - } - } - } -} - -bool ShouldDrawDeviceText(const CFX_Font* pFont, uint32_t text_flags) { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - if (text_flags & FXFONT_CIDFONT) - return false; - - const CFX_ByteString bsPsName = pFont->GetPsName(); - if (bsPsName.Find("+ZJHL") != -1) - return false; - - if (bsPsName == "CNAAJI+cmex10") - return false; -#endif - return true; -} - } // namespace FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, @@ -404,273 +83,6 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, return rect; } -FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, - const FXTEXT_CHARPOS* pCharPos, - CFX_Font* pFont, - CFX_FontCache* pCache, - FX_FLOAT font_size, - const CFX_Matrix* pText2Device, - uint32_t fill_color, - uint32_t text_flags) { - int nativetext_flags = text_flags; - if (m_DeviceClass != FXDC_DISPLAY) { - if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { - if (ShouldDrawDeviceText(pFont, text_flags) && - m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, - pText2Device, font_size, - fill_color)) { - return TRUE; - } - } - if (FXARGB_A(fill_color) < 255) - return FALSE; - } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) { - if (ShouldDrawDeviceText(pFont, text_flags) && - m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, - pText2Device, font_size, fill_color)) { - return TRUE; - } - } - CFX_Matrix char2device; - CFX_Matrix text2Device; - if (pText2Device) { - char2device = *pText2Device; - text2Device = *pText2Device; - } - char2device.Scale(font_size, -font_size); - if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || - ((m_DeviceClass == FXDC_PRINTER) && - !(text_flags & FXTEXT_PRINTIMAGETEXT))) { - if (pFont->GetFace() || - (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { - int nPathFlags = - (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH; - return DrawTextPathWithFlags(nChars, pCharPos, pFont, pCache, font_size, - pText2Device, nullptr, nullptr, fill_color, - 0, nullptr, nPathFlags); - } - } - int anti_alias = FXFT_RENDER_MODE_MONO; - bool bNormal = false; - if ((text_flags & FXTEXT_NOSMOOTH) == 0) { - if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) { - if (!CFX_GEModule::Get()->GetFontMgr()->FTLibrarySupportsHinting()) { - // Some Freetype implementations (like the one packaged with Fedora) do - // not support hinting due to patents 6219025, 6239783, 6307566, - // 6225973, 6243070, 6393145, 6421054, 6282327, and 6624828; the latest - // one expires 10/7/19. This makes LCD antialiasing very ugly, so we - // instead fall back on NORMAL antialiasing. - anti_alias = FXFT_RENDER_MODE_NORMAL; - } else if ((m_RenderCaps & (FXRC_ALPHA_OUTPUT | FXRC_CMYK_OUTPUT))) { - anti_alias = FXFT_RENDER_MODE_LCD; - bNormal = true; - } else if (m_bpp < 16) { - anti_alias = FXFT_RENDER_MODE_NORMAL; - } else { - anti_alias = FXFT_RENDER_MODE_LCD; - - bool bClearType = false; - if (pFont->GetFace() || - (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_CLEARTYPE)) { - bClearType = !!(text_flags & FXTEXT_CLEARTYPE); - } - bNormal = !bClearType; - } - } - } - if (!pCache) - pCache = CFX_GEModule::Get()->GetFontCache(); - - CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); - CFX_AutoFontCache autoFontCache(pCache, pFont); - std::vector<FXTEXT_GLYPHPOS> glyphs(nChars); - CFX_Matrix matrixCTM = GetCTM(); - FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a); - FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d); - CFX_Matrix deviceCtm = char2device; - deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0); - text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0); - for (size_t i = 0; i < glyphs.size(); ++i) { - FXTEXT_GLYPHPOS& glyph = glyphs[i]; - const FXTEXT_CHARPOS& charpos = pCharPos[i]; - glyph.m_fOriginX = charpos.m_OriginX; - glyph.m_fOriginY = charpos.m_OriginY; - text2Device.Transform(glyph.m_fOriginX, glyph.m_fOriginY); - if (anti_alias < FXFT_RENDER_MODE_LCD) { - glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX); - } else { - glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX); - } - glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY); - if (charpos.m_bGlyphAdjust) { - CFX_Matrix new_matrix( - charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], - charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); - new_matrix.Concat(deviceCtm); - glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( - pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &new_matrix, - charpos.m_FontCharWidth, anti_alias, nativetext_flags); - } else { - glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( - pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &deviceCtm, - charpos.m_FontCharWidth, anti_alias, nativetext_flags); - } - } - if (anti_alias < FXFT_RENDER_MODE_LCD && glyphs.size() > 1) - AdjustGlyphSpace(&glyphs); - - FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(glyphs, anti_alias); - if (scale_x > 1 && scale_y > 1) { - bmp_rect1.left--; - bmp_rect1.top--; - bmp_rect1.right++; - bmp_rect1.bottom++; - } - FX_RECT bmp_rect(FXSYS_round((FX_FLOAT)(bmp_rect1.left) / scale_x), - FXSYS_round((FX_FLOAT)(bmp_rect1.top) / scale_y), - FXSYS_round((FX_FLOAT)bmp_rect1.right / scale_x), - FXSYS_round((FX_FLOAT)bmp_rect1.bottom / scale_y)); - bmp_rect.Intersect(m_ClipBox); - if (bmp_rect.IsEmpty()) - return TRUE; - - int pixel_width = FXSYS_round(bmp_rect.Width() * scale_x); - int pixel_height = FXSYS_round(bmp_rect.Height() * scale_y); - int pixel_left = FXSYS_round(bmp_rect.left * scale_x); - int pixel_top = FXSYS_round(bmp_rect.top * scale_y); - if (anti_alias == FXFT_RENDER_MODE_MONO) { - CFX_DIBitmap bitmap; - if (!bitmap.Create(pixel_width, pixel_height, FXDIB_1bppMask)) - return FALSE; - - bitmap.Clear(0); - for (const FXTEXT_GLYPHPOS& glyph : glyphs) { - if (!glyph.m_pGlyph) - continue; - - const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; - bitmap.TransferBitmap( - glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left, - glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top, - pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0, 0); - } - return SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); - } - CFX_DIBitmap bitmap; - if (m_bpp == 8) { - if (!bitmap.Create(pixel_width, pixel_height, FXDIB_8bppMask)) - return FALSE; - } else { - if (!CreateCompatibleBitmap(&bitmap, pixel_width, pixel_height)) - return FALSE; - } - - if (!bitmap.HasAlpha() && !bitmap.IsAlphaMask()) { - bitmap.Clear(0xFFFFFFFF); - if (!GetDIBits(&bitmap, bmp_rect.left, bmp_rect.top)) - return FALSE; - } else { - bitmap.Clear(0); - if (bitmap.m_pAlphaMask) { - bitmap.m_pAlphaMask->Clear(0); - } - } - - int dest_width = pixel_width; - int a = 0; - int r = 0; - int g = 0; - int b = 0; - if (anti_alias == FXFT_RENDER_MODE_LCD) - ArgbDecode(fill_color, a, r, g, b); - - for (const FXTEXT_GLYPHPOS& glyph : glyphs) { - if (!glyph.m_pGlyph) - continue; - - const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; - int left = glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left; - int top = glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top; - int ncols = pGlyph->GetWidth(); - int nrows = pGlyph->GetHeight(); - if (anti_alias == FXFT_RENDER_MODE_NORMAL) { - if (!bitmap.CompositeMask(left, top, ncols, nrows, pGlyph, fill_color, 0, - 0, FXDIB_BLEND_NORMAL, nullptr, FALSE, 0, - nullptr)) { - return FALSE; - } - continue; - } - - bool bBGRStripe = !!(text_flags & FXTEXT_BGR_STRIPE); - ncols /= 3; - int x_subpixel = (int)(glyph.m_fOriginX * 3) % 3; - int start_col = std::max(left, 0); - int end_col = std::min(left + ncols, dest_width); - if (start_col >= end_col) - continue; - - DrawNormalTextHelper(&bitmap, pGlyph, nrows, left, top, start_col, end_col, - bNormal, bBGRStripe, x_subpixel, a, r, g, b); - } - if (bitmap.IsAlphaMask()) - SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); - else - SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); - return TRUE; -} - -FX_BOOL CFX_RenderDevice::DrawTextPathWithFlags( - int nChars, - const FXTEXT_CHARPOS* pCharPos, - CFX_Font* pFont, - CFX_FontCache* pCache, - FX_FLOAT font_size, - const CFX_Matrix* pText2User, - const CFX_Matrix* pUser2Device, - const CFX_GraphStateData* pGraphState, - uint32_t fill_color, - FX_ARGB stroke_color, - CFX_PathData* pClippingPath, - int nFlag) { - if (!pCache) - pCache = CFX_GEModule::Get()->GetFontCache(); - - CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); - CFX_AutoFontCache autoFontCache(pCache, pFont); - for (int iChar = 0; iChar < nChars; iChar++) { - const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; - CFX_Matrix matrix; - if (charpos.m_bGlyphAdjust) - matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], - charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); - matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, - charpos.m_OriginY); - const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( - pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); - if (!pPath) - continue; - - matrix.Concat(*pText2User); - CFX_PathData TransformedPath(*pPath); - TransformedPath.Transform(&matrix); - if (fill_color || stroke_color) { - int fill_mode = nFlag; - if (fill_color) - fill_mode |= FXFILL_WINDING; - fill_mode |= FX_FILL_TEXT_MODE; - if (!DrawPathWithBlend(&TransformedPath, pUser2Device, pGraphState, - fill_color, stroke_color, fill_mode, - FXDIB_BLEND_NORMAL)) { - return FALSE; - } - } - if (pClippingPath) - pClippingPath->Append(&TransformedPath, pUser2Device); - } - return TRUE; -} - CFX_FontCache::CFX_FontCache() {} CFX_FontCache::~CFX_FontCache() { |