Revert "Make CFX_FontMgr member variables private."
[pdfium.git] / core / src / fxge / ge / fx_ge_text.cpp
index 3c08cd6..6938bb9 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../../../include/fxge/fx_ge.h"\r
-#include "../../../include/fxge/fx_freetype.h"\r
-#include "../../../include/fxcodec/fx_codec.h"\r
-#include "text_int.h"\r
-#undef FX_GAMMA\r
-#undef FX_GAMMA_INVERSE\r
-#define FX_GAMMA(value)                        (value)\r
-#define FX_GAMMA_INVERSE(value)        (value)\r
-FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos, int nChars, int anti_alias, FX_FLOAT retinaScaleX, FX_FLOAT retinaScaleY)\r
-{\r
-    FX_RECT rect(0, 0, 0, 0);\r
-    FX_BOOL bStarted = FALSE;\r
-    for (int iChar = 0; iChar < nChars; iChar ++) {\r
-        FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar];\r
-        const CFX_GlyphBitmap* pGlyph = glyph.m_pGlyph;\r
-        if (pGlyph == NULL) {\r
-            continue;\r
-        }\r
-        int char_left = glyph.m_OriginX + pGlyph->m_Left;\r
-        int char_width = (int)(pGlyph->m_Bitmap.GetWidth() / retinaScaleX);\r
-        if (anti_alias == FXFT_RENDER_MODE_LCD) {\r
-            char_width /= 3;\r
-        }\r
-        int char_right = char_left + char_width;\r
-        int char_top = glyph.m_OriginY - pGlyph->m_Top;\r
-        int char_bottom = char_top + (int)(pGlyph->m_Bitmap.GetHeight() / retinaScaleY);\r
-        if (!bStarted) {\r
-            rect.left = char_left;\r
-            rect.right = char_right;\r
-            rect.top = char_top;\r
-            rect.bottom = char_bottom;\r
-            bStarted = TRUE;\r
-        } else {\r
-            if (rect.left > char_left) {\r
-                rect.left = char_left;\r
-            }\r
-            if (rect.right < char_right) {\r
-                rect.right = char_right;\r
-            }\r
-            if (rect.top > char_top) {\r
-                rect.top = char_top;\r
-            }\r
-            if (rect.bottom < char_bottom) {\r
-                rect.bottom = char_bottom;\r
-            }\r
-        }\r
-    }\r
-    return rect;\r
-}\r
-static void _AdjustGlyphSpace(FXTEXT_GLYPHPOS* pGlyphAndPos, int nChars)\r
-{\r
-    ASSERT(nChars > 1);\r
-    FX_BOOL bVertical = FALSE;\r
-    if (pGlyphAndPos[nChars - 1].m_OriginX == pGlyphAndPos[0].m_OriginX) {\r
-        bVertical = TRUE;\r
-    } else if (pGlyphAndPos[nChars - 1].m_OriginY != pGlyphAndPos[0].m_OriginY) {\r
-        return;\r
-    }\r
-    int i = nChars - 1;\r
-    int* next_origin = bVertical ? &pGlyphAndPos[i].m_OriginY : &pGlyphAndPos[i].m_OriginX;\r
-    FX_FLOAT next_origin_f = bVertical ? pGlyphAndPos[i].m_fOriginY : pGlyphAndPos[i].m_fOriginX;\r
-    for (i --; i > 0; i --) {\r
-        int* this_origin = bVertical ? &pGlyphAndPos[i].m_OriginY : &pGlyphAndPos[i].m_OriginX;\r
-        FX_FLOAT this_origin_f = bVertical ? pGlyphAndPos[i].m_fOriginY : pGlyphAndPos[i].m_fOriginX;\r
-        int space = (*next_origin) - (*this_origin);\r
-        FX_FLOAT space_f = next_origin_f - this_origin_f;\r
-        FX_FLOAT error = (FX_FLOAT)(FXSYS_fabs(space_f) - FXSYS_fabs((FX_FLOAT)(space)));\r
-        if (error > 0.5f) {\r
-            *this_origin += space > 0 ? -1 : 1;\r
-        }\r
-        next_origin = this_origin;\r
-        next_origin_f = this_origin_f;\r
-    }\r
-}\r
-static const FX_BYTE g_GdipGamma_bgw[9] = {0, 0, 63, 120, 0, 168, 210, 239, 255};\r
-static const FX_BYTE g_GdipGamma_fgw[9] = {0, 0, 16, 45, 0, 87, 135, 192, 255};\r
-static const FX_BYTE g_GdipGammaAdjust_47[48] = {\r
-    0, 30, 33, 34, 35, 36, 37, 38, 38, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42, 42, 43,\r
-    43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 46,\r
-    46, 46, 46, 46, 46, 46, 46, 47\r
-};\r
-static const FX_BYTE g_GdipGammaAdjust_75[76] = {\r
-    0, 46, 50, 52, 54, 55, 56, 57, 58, 59, 60, 60, 61, 61, 62, 62, 63, 63, 64, 64, 64, 65,\r
-    65, 65, 66, 66, 66, 67, 67, 67, 67, 68, 68, 68, 68, 68, 69, 69, 69, 69, 69, 70, 70, 70,\r
-    70, 70, 71, 71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73, 73, 73,\r
-    73, 74, 74, 74, 74, 74, 74, 74, 74, 75\r
-};\r
-static const FX_BYTE g_GdipGammaAdjust_81[82] = {\r
-    0, 49, 53, 56, 58, 59, 60, 61, 62, 63, 64, 65, 65, 66, 66, 67, 67, 68, 68, 69, 69, 69, 70, 70, 70,\r
-    71, 71, 71, 72, 72, 72, 72, 73, 73, 73, 73, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 76, 76, 76, 76,\r
-    76, 76, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 80,\r
-    80, 80, 80, 80, 80, 80, 80, 81\r
-};\r
-static void _Adjust_alpha(int background, int foreground, int& src_alpha, int text_flags, int a)\r
-{\r
-}\r
-static const FX_BYTE g_TextGammaAdjust[256] = {\r
-    0, 2, 3, 4, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19,\r
-    21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 38,\r
-    39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55,\r
-    56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72,\r
-    73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,\r
-    89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,\r
-    105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,\r
-    121, 122, 123, 124, 125, 126, 127, 128, 129, 129, 130, 131, 132, 133, 134, 135,\r
-    136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151,\r
-    152, 153, 154, 155, 156, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166,\r
-    167, 168, 169, 170, 171, 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 181,\r
-    182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196,\r
-    197, 198, 199, 200, 201, 202, 203, 204, 204, 205, 206, 207, 208, 209, 210, 211,\r
-    212, 213, 214, 215, 216, 217, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226,\r
-    227, 228, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 239, 240,\r
-    241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 250, 251, 252, 253, 254, 255,\r
-};\r
-#define ADJUST_ALPHA(background, foreground, src_alpha, text_flags, a) \\r
-    src_alpha = g_TextGammaAdjust[(FX_BYTE)src_alpha];\r
-void _Color2Argb(FX_ARGB& argb, FX_DWORD color, int alpha_flag, void* pIccTransform)\r
-{\r
-    if (pIccTransform == NULL && !FXGETFLAG_COLORTYPE(alpha_flag)) {\r
-        argb = color;\r
-        return;\r
-    }\r
-    if (!CFX_GEModule::Get()->GetCodecModule() || !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {\r
-        pIccTransform = NULL;\r
-    }\r
-    FX_BYTE bgra[4];\r
-    if (pIccTransform) {\r
-        ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();\r
-        color = FXGETFLAG_COLORTYPE(alpha_flag) ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);\r
-        pIccModule->TranslateScanline(pIccTransform, bgra, (FX_LPCBYTE)&color, 1);\r
-        bgra[3] = FXGETFLAG_COLORTYPE(alpha_flag) ?\r
-                  (alpha_flag >> 24) ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXGETFLAG_ALPHA_STROKE(alpha_flag) :\r
-                  FXARGB_A(color);\r
-        argb = FXARGB_MAKE(bgra[3], bgra[2], bgra[1], bgra[0]);\r
-        return;\r
-    }\r
-    AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),\r
-                       FXSYS_GetYValue(color), FXSYS_GetKValue(color),\r
-                       bgra[2], bgra[1], bgra[0]);\r
-    bgra[3] = (alpha_flag >> 24) ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXGETFLAG_ALPHA_STROKE(alpha_flag);\r
-    argb = FXARGB_MAKE(bgra[3], bgra[2], bgra[1], bgra[0]);\r
-}\r
-FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, const FXTEXT_CHARPOS* pCharPos,\r
-        CFX_Font* pFont, CFX_FontCache* pCache,\r
-        FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device,\r
-        FX_DWORD fill_color, FX_DWORD text_flags,\r
-        int alpha_flag, void* pIccTransform)\r
-{\r
-    int nativetext_flags = text_flags;\r
-    if (m_DeviceClass != FXDC_DISPLAY) {\r
-        if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) {\r
-#if _FXM_PLATFORM_  == _FXM_PLATFORM_APPLE_\r
-            if (!(text_flags & FXFONT_CIDFONT) && pFont->GetPsName().Find(CFX_WideString::FromLocal("+ZJHL")) == -1)\r
-#ifdef FOXIT_CHROME_BUILD\r
-                if (pFont->GetPsName() != CFX_WideString::FromLocal("CNAAJI+cmex10"))\r
-#endif\r
-#endif\r
-                    if (m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, pText2Device, font_size, fill_color, alpha_flag, pIccTransform)) {\r
-                        return TRUE;\r
-                    }\r
-        }\r
-        int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(fill_color);\r
-        if (alpha < 255) {\r
-            return FALSE;\r
-        }\r
-    } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) {\r
-#if _FXM_PLATFORM_  == _FXM_PLATFORM_APPLE_\r
-        if (!(text_flags & FXFONT_CIDFONT))\r
-#ifdef FOXIT_CHROME_BUILD\r
-            if (pFont->GetPsName() != CFX_WideString::FromLocal("CNAAJI+cmex10"))\r
-#endif\r
-#endif\r
-                if (m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, pText2Device, font_size, fill_color, alpha_flag, pIccTransform)) {\r
-                    return TRUE;\r
-                }\r
-    }\r
-    CFX_AffineMatrix char2device, deviceCtm, text2Device;\r
-    if (pText2Device) {\r
-        char2device = *pText2Device;\r
-        text2Device = *pText2Device;\r
-    }\r
-    char2device.Scale(font_size, -font_size);\r
-    if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f ||\r
-            ((m_DeviceClass == FXDC_PRINTER && !m_pDeviceDriver->IsPSPrintDriver())\r
-             && !(text_flags & FXTEXT_PRINTIMAGETEXT))) {\r
-        if (pFont->GetFace() != NULL || (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) {\r
-            int nPathFlags = (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH;\r
-            return DrawTextPath(nChars, pCharPos, pFont, pCache, font_size, pText2Device, NULL, NULL, fill_color, 0, NULL, nPathFlags, alpha_flag, pIccTransform);\r
-        }\r
-    }\r
-    int anti_alias = FXFT_RENDER_MODE_MONO;\r
-    FX_BOOL bNormal = FALSE;\r
-    if ((text_flags & FXTEXT_NOSMOOTH) == 0) {\r
-        if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) {\r
-            FX_BOOL bClearType;\r
-            if (pFont->GetFace() == NULL && !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_CLEARTYPE)) {\r
-                bClearType = FALSE;\r
-            } else {\r
-                bClearType = text_flags & FXTEXT_CLEARTYPE;\r
-            }\r
-            if ((m_RenderCaps & (FXRC_ALPHA_OUTPUT | FXRC_CMYK_OUTPUT))) {\r
-                anti_alias = FXFT_RENDER_MODE_LCD;\r
-                bNormal = TRUE;\r
-            } else if (m_bpp < 16) {\r
-                anti_alias = FXFT_RENDER_MODE_NORMAL;\r
-            } else {\r
-                if (bClearType == FALSE) {\r
-                    anti_alias = FXFT_RENDER_MODE_LCD;\r
-                    bNormal = TRUE;\r
-                } else {\r
-                    anti_alias = FXFT_RENDER_MODE_LCD;\r
-                }\r
-            }\r
-        }\r
-    }\r
-    if (pCache == NULL) {\r
-        pCache = CFX_GEModule::Get()->GetFontCache();\r
-    }\r
-    CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont);\r
-    FX_FONTCACHE_DEFINE(pCache, pFont);\r
-    FXTEXT_GLYPHPOS* pGlyphAndPos = FX_Alloc(FXTEXT_GLYPHPOS, nChars);\r
-    if (!pGlyphAndPos) {\r
-        return FALSE;\r
-    }\r
-    int iChar;\r
-    deviceCtm = char2device;\r
-    CFX_AffineMatrix matrixCTM = GetCTM();\r
-    FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a);\r
-    FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d);\r
-    deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0);\r
-    text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0);\r
-    for (iChar = 0; iChar < nChars; iChar ++) {\r
-        FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar];\r
-        const FXTEXT_CHARPOS& charpos = pCharPos[iChar];\r
-        glyph.m_fOriginX = charpos.m_OriginX;\r
-        glyph.m_fOriginY = charpos.m_OriginY;\r
-        text2Device.Transform(glyph.m_fOriginX, glyph.m_fOriginY);\r
-        if (anti_alias < FXFT_RENDER_MODE_LCD) {\r
-            glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX);\r
-        } else {\r
-            glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX);\r
-        }\r
-        glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY);\r
-        if (charpos.m_bGlyphAdjust) {\r
-            CFX_AffineMatrix new_matrix(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],\r
-                                        charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0);\r
-            new_matrix.Concat(deviceCtm);\r
-            glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap(pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &new_matrix,\r
-                             charpos.m_FontCharWidth, anti_alias, nativetext_flags);\r
-        } else\r
-            glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap(pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &deviceCtm,\r
-                             charpos.m_FontCharWidth, anti_alias, nativetext_flags);\r
-    }\r
-    if (anti_alias < FXFT_RENDER_MODE_LCD && nChars > 1) {\r
-        _AdjustGlyphSpace(pGlyphAndPos, nChars);\r
-    }\r
-    FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(pGlyphAndPos, nChars, anti_alias);\r
-    if (scale_x > 1 && scale_y > 1) {\r
-        bmp_rect1.left--;\r
-        bmp_rect1.top --;\r
-        bmp_rect1.right ++;\r
-        bmp_rect1.bottom ++;\r
-    }\r
-    FX_RECT bmp_rect(FXSYS_round((FX_FLOAT)(bmp_rect1.left) / scale_x), FXSYS_round((FX_FLOAT)(bmp_rect1.top) / scale_y),\r
-                     FXSYS_round((FX_FLOAT)bmp_rect1.right / scale_x), FXSYS_round((FX_FLOAT)bmp_rect1.bottom / scale_y));\r
-    bmp_rect.Intersect(m_ClipBox);\r
-    if (bmp_rect.IsEmpty()) {\r
-        FX_Free(pGlyphAndPos);\r
-        return TRUE;\r
-    }\r
-    int pixel_width = FXSYS_round(bmp_rect.Width() * scale_x);\r
-    int pixel_height = FXSYS_round(bmp_rect.Height() * scale_y);\r
-    int pixel_left = FXSYS_round(bmp_rect.left * scale_x);\r
-    int pixel_top = FXSYS_round(bmp_rect.top * scale_y);\r
-    if (anti_alias == FXFT_RENDER_MODE_MONO) {\r
-        CFX_DIBitmap bitmap;\r
-        if (!bitmap.Create(pixel_width, pixel_height, FXDIB_1bppMask)) {\r
-            FX_Free(pGlyphAndPos);\r
-            return FALSE;\r
-        }\r
-        bitmap.Clear(0);\r
-        for (iChar = 0; iChar < nChars; iChar ++) {\r
-            FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar];\r
-            if (glyph.m_pGlyph == NULL) {\r
-                continue;\r
-            }\r
-            const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap;\r
-            bitmap.TransferBitmap(glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left,\r
-                                  glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top,\r
-                                  pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0, 0);\r
-        }\r
-        FX_Free(pGlyphAndPos);\r
-        return SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color);\r
-    }\r
-    CFX_DIBitmap bitmap;\r
-    if (m_bpp == 8) {\r
-        if (!bitmap.Create(pixel_width, pixel_height, FXDIB_8bppMask)) {\r
-            FX_Free(pGlyphAndPos);\r
-            return FALSE;\r
-        }\r
-    } else {\r
-        if (!CreateCompatibleBitmap(&bitmap, pixel_width, pixel_height)) {\r
-            FX_Free(pGlyphAndPos);\r
-            return FALSE;\r
-        }\r
-    }\r
-    if (!bitmap.HasAlpha() && !bitmap.IsAlphaMask()) {\r
-        bitmap.Clear(0xFFFFFFFF);\r
-        if (!GetDIBits(&bitmap, bmp_rect.left, bmp_rect.top)) {\r
-            FX_Free(pGlyphAndPos);\r
-            return FALSE;\r
-        }\r
-    } else {\r
-        bitmap.Clear(0);\r
-        if (bitmap.m_pAlphaMask) {\r
-            bitmap.m_pAlphaMask->Clear(0);\r
-        }\r
-    }\r
-    int dest_width = pixel_width;\r
-    FX_LPBYTE dest_buf = bitmap.GetBuffer();\r
-    int dest_pitch = bitmap.GetPitch();\r
-    int Bpp = bitmap.GetBPP() / 8;\r
-    int a, r, g, b;\r
-    if (anti_alias == FXFT_RENDER_MODE_LCD) {\r
-        _Color2Argb(fill_color, fill_color, alpha_flag | (1 << 24), pIccTransform);\r
-        ArgbDecode(fill_color, a, r, g, b);\r
-        r = FX_GAMMA(r);\r
-        g = FX_GAMMA(g);\r
-        b = FX_GAMMA(b);\r
-    }\r
-    for (iChar = 0; iChar < nChars; iChar ++) {\r
-        FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar];\r
-        if (glyph.m_pGlyph == NULL) {\r
-            continue;\r
-        }\r
-        const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap;\r
-        int left = glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left;\r
-        int top = glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top;\r
-        int ncols = pGlyph->GetWidth();\r
-        int nrows = pGlyph->GetHeight();\r
-        if (anti_alias == FXFT_RENDER_MODE_NORMAL) {\r
-            if (!bitmap.CompositeMask(left, top, ncols, nrows, pGlyph, fill_color,\r
-                                      0, 0, FXDIB_BLEND_NORMAL, NULL, FALSE, alpha_flag, pIccTransform)) {\r
-                FX_Free(pGlyphAndPos);\r
-                return FALSE;\r
-            }\r
-            continue;\r
-        }\r
-        FX_BOOL bBGRStripe = text_flags & FXTEXT_BGR_STRIPE;\r
-        ncols /= 3;\r
-        int x_subpixel = (int)(glyph.m_fOriginX * 3) % 3;\r
-        FX_LPBYTE src_buf = pGlyph->GetBuffer();\r
-        int src_pitch = pGlyph->GetPitch();\r
-        int start_col = left;\r
-        if (start_col < 0) {\r
-            start_col = 0;\r
-        }\r
-        int end_col = left + ncols;\r
-        if (end_col > dest_width) {\r
-            end_col = dest_width;\r
-        }\r
-        if (start_col >= end_col) {\r
-            continue;\r
-        }\r
-        if (bitmap.GetFormat() == FXDIB_Argb) {\r
-            for (int row = 0; row < nrows; row ++) {\r
-                int dest_row = row + top;\r
-                if (dest_row < 0 || dest_row >= bitmap.GetHeight()) {\r
-                    continue;\r
-                }\r
-                FX_LPBYTE src_scan = src_buf + row * src_pitch + (start_col - left) * 3;\r
-                FX_LPBYTE dest_scan = dest_buf + dest_row * dest_pitch + (start_col << 2);\r
-                if (bBGRStripe) {\r
-                    if (x_subpixel == 0) {\r
-                        for (int col = start_col; col < end_col; col ++) {\r
-                            int src_alpha = src_scan[2];\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[1];\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[0];\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan[3] = 255;\r
-                            dest_scan += 4;\r
-                            src_scan += 3;\r
-                        }\r
-                    } else if (x_subpixel == 1) {\r
-                        int src_alpha = src_scan[1];\r
-                        ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                        src_alpha = src_alpha * a / 255;\r
-                        dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                        src_alpha = src_scan[0];\r
-                        ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                        src_alpha = src_alpha * a / 255;\r
-                        dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                        if (start_col > left) {\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                        }\r
-                        dest_scan[3] = 255;\r
-                        dest_scan += 4;\r
-                        src_scan += 3;\r
-                        for (int col = start_col + 1; col < end_col - 1; col ++) {\r
-                            int src_alpha = src_scan[1];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan[3] = 255;\r
-                            dest_scan += 4;\r
-                            src_scan += 3;\r
-                        }\r
-                    } else {\r
-                        int src_alpha = src_scan[0];\r
-                        ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                        src_alpha = src_alpha * a / 255;\r
-                        dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                        if (start_col > left) {\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[-2];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                        }\r
-                        dest_scan[3] = 255;\r
-                        dest_scan += 4;\r
-                        src_scan += 3;\r
-                        for (int col = start_col + 1; col < end_col - 1; col ++) {\r
-                            int src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[-2];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan[3] = 255;\r
-                            dest_scan += 4;\r
-                            src_scan += 3;\r
-                        }\r
-                    }\r
-                } else {\r
-                    if (x_subpixel == 0) {\r
-                        for (int col = start_col; col < end_col; col ++) {\r
-                            if (bNormal) {\r
-                                int src_alpha1 = (src_scan[0] + src_scan[1] + src_scan[2]) / 3;\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                                src_alpha1 = src_alpha1 * a / 255;\r
-                                FX_BYTE back_alpha = dest_scan[3];\r
-                                if (back_alpha == 0) {\r
-                                    FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));\r
-                                    dest_scan += 4;\r
-                                    src_scan += 3;\r
-                                    continue;\r
-                                }\r
-                                if (src_alpha1 == 0) {\r
-                                    dest_scan += 4;\r
-                                    src_scan += 3;\r
-                                    continue;\r
-                                }\r
-                                FX_BYTE dest_alpha = back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;\r
-                                dest_scan[3] = dest_alpha;\r
-                                int alpha_ratio = src_alpha1 * 255 / dest_alpha;\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, alpha_ratio));\r
-                                dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, alpha_ratio));\r
-                                dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, alpha_ratio));\r
-                                dest_scan += 4;\r
-                                src_scan += 3;\r
-                                continue;\r
-                            }\r
-                            int src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[1];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[2];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan[3] = 255;\r
-                            dest_scan += 4;\r
-                            src_scan += 3;\r
-                        }\r
-                    } else if (x_subpixel == 1) {\r
-                        if (bNormal) {\r
-                            int src_alpha1 = start_col > left ? ((src_scan[-1] + src_scan[0] + src_scan[1]) / 3) : ((src_scan[0] + src_scan[1]) / 3);\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                            src_alpha1 = src_alpha1 * a / 255;\r
-                            if (src_alpha1 == 0) {\r
-                                dest_scan += 4;\r
-                                src_scan += 3;\r
-                            } else {\r
-                                FX_BYTE back_alpha = dest_scan[3];\r
-                                if (back_alpha == 0) {\r
-                                    FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));\r
-                                } else {\r
-                                    FX_BYTE dest_alpha = back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;\r
-                                    dest_scan[3] = dest_alpha;\r
-                                    int alpha_ratio = src_alpha1 * 255 / dest_alpha;\r
-                                    dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, alpha_ratio));\r
-                                    dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, alpha_ratio));\r
-                                    dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, alpha_ratio));\r
-                                }\r
-                                dest_scan += 4;\r
-                                src_scan += 3;\r
-                            }\r
-                        } else {\r
-                            if (start_col > left) {\r
-                                int src_alpha = src_scan[-1];\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                                src_alpha = src_alpha * a / 255;\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            }\r
-                            int src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[1];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan[3] = 255;\r
-                            dest_scan += 4;\r
-                            src_scan += 3;\r
-                        }\r
-                        for (int col = start_col + 1; col < end_col; col ++) {\r
-                            if (bNormal) {\r
-                                int src_alpha1 = (src_scan[-1] + src_scan[0] + src_scan[1]) / 3;\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                                src_alpha1 = src_alpha1 * a / 255;\r
-                                FX_BYTE back_alpha = dest_scan[3];\r
-                                if (back_alpha == 0) {\r
-                                    FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));\r
-                                    dest_scan += 4;\r
-                                    src_scan += 3;\r
-                                    continue;\r
-                                }\r
-                                if (src_alpha1 == 0) {\r
-                                    dest_scan += 4;\r
-                                    src_scan += 3;\r
-                                    continue;\r
-                                }\r
-                                FX_BYTE dest_alpha = back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;\r
-                                dest_scan[3] = dest_alpha;\r
-                                int alpha_ratio = src_alpha1 * 255 / dest_alpha;\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, alpha_ratio));\r
-                                dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, alpha_ratio));\r
-                                dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, alpha_ratio));\r
-                                dest_scan += 4;\r
-                                src_scan += 3;\r
-                                continue;\r
-                            }\r
-                            int src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[1];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan[3] = 255;\r
-                            dest_scan += 4;\r
-                            src_scan += 3;\r
-                        }\r
-                    } else {\r
-                        if (bNormal) {\r
-                            int src_alpha1 = start_col > left ? ((src_scan[-2] + src_scan[-1] + src_scan[0]) / 3) : ((src_scan[0]) / 3);\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                            src_alpha1 = src_alpha1 * a / 255;\r
-                            if (src_alpha1 == 0) {\r
-                                dest_scan += 4;\r
-                                src_scan += 3;\r
-                            } else {\r
-                                FX_BYTE back_alpha = dest_scan[3];\r
-                                if (back_alpha == 0) {\r
-                                    FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));\r
-                                } else {\r
-                                    FX_BYTE dest_alpha = back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;\r
-                                    dest_scan[3] = dest_alpha;\r
-                                    int alpha_ratio = src_alpha1 * 255 / dest_alpha;\r
-                                    dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, alpha_ratio));\r
-                                    dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, alpha_ratio));\r
-                                    dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, alpha_ratio));\r
-                                }\r
-                                dest_scan += 4;\r
-                                src_scan += 3;\r
-                            }\r
-                        } else {\r
-                            if (start_col > left) {\r
-                                int src_alpha = src_scan[-2];\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                                src_alpha = src_alpha * a / 255;\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                                src_alpha = src_scan[-1];\r
-                                ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                                src_alpha = src_alpha * a / 255;\r
-                                dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            }\r
-                            int src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan[3] = 255;\r
-                            dest_scan += 4;\r
-                            src_scan += 3;\r
-                        }\r
-                        for (int col = start_col + 1; col < end_col; col ++) {\r
-                            if (bNormal) {\r
-                                int src_alpha1 = (src_scan[-2] + src_scan[-1] + src_scan[0]) / 3;\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                                src_alpha1 = src_alpha1 * a / 255;\r
-                                FX_BYTE back_alpha = dest_scan[3];\r
-                                if (back_alpha == 0) {\r
-                                    FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));\r
-                                    dest_scan += 4;\r
-                                    src_scan += 3;\r
-                                    continue;\r
-                                }\r
-                                if (src_alpha1 == 0) {\r
-                                    dest_scan += 4;\r
-                                    src_scan += 3;\r
-                                    continue;\r
-                                }\r
-                                FX_BYTE dest_alpha = back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;\r
-                                dest_scan[3] = dest_alpha;\r
-                                int alpha_ratio = src_alpha1 * 255 / dest_alpha;\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, alpha_ratio));\r
-                                dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, alpha_ratio));\r
-                                dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, alpha_ratio));\r
-                                dest_scan += 4;\r
-                                src_scan += 3;\r
-                                continue;\r
-                            }\r
-                            int src_alpha = src_scan[-2];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan[3] = 255;\r
-                            dest_scan += 4;\r
-                            src_scan += 3;\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-        } else {\r
-            for (int row = 0; row < nrows; row ++) {\r
-                int dest_row = row + top;\r
-                if (dest_row < 0 || dest_row >= bitmap.GetHeight()) {\r
-                    continue;\r
-                }\r
-                FX_LPBYTE src_scan = src_buf + row * src_pitch + (start_col - left) * 3;\r
-                FX_LPBYTE dest_scan = dest_buf + dest_row * dest_pitch + start_col * Bpp;\r
-                if (bBGRStripe) {\r
-                    if (x_subpixel == 0) {\r
-                        for (int col = start_col; col < end_col; col ++) {\r
-                            int src_alpha = src_scan[2];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[1];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        }\r
-                    } else if (x_subpixel == 1) {\r
-                        int src_alpha = src_scan[1];\r
-                        ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                        src_alpha = src_alpha * a / 255;\r
-                        dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                        src_alpha = src_scan[0];\r
-                        ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                        src_alpha = src_alpha * a / 255;\r
-                        dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                        if (start_col > left) {\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                        }\r
-                        dest_scan += Bpp;\r
-                        src_scan += 3;\r
-                        for (int col = start_col + 1; col < end_col - 1; col ++) {\r
-                            int src_alpha = src_scan[1];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        }\r
-                    } else {\r
-                        int src_alpha = src_scan[0];\r
-                        ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                        src_alpha = src_alpha * a / 255;\r
-                        dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                        if (start_col > left) {\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[-2];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                        }\r
-                        dest_scan += Bpp;\r
-                        src_scan += 3;\r
-                        for (int col = start_col + 1; col < end_col - 1; col ++) {\r
-                            int src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[-2];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        }\r
-                    }\r
-                } else {\r
-                    if (x_subpixel == 0) {\r
-                        for (int col = start_col; col < end_col; col ++) {\r
-                            if (bNormal) {\r
-                                int src_alpha1 = (src_scan[0] + src_scan[1] + src_scan[2]) / 3;\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                                src_alpha1 = src_alpha1 * a / 255;\r
-                                if (src_alpha1 == 0) {\r
-                                    dest_scan += Bpp;\r
-                                    src_scan += 3;\r
-                                    continue;\r
-                                }\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));\r
-                                dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));\r
-                                dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));\r
-                                dest_scan += Bpp;\r
-                                src_scan += 3;\r
-                                continue;\r
-                            }\r
-                            int src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[1];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[2];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        }\r
-                    } else if (x_subpixel == 1) {\r
-                        if (bNormal) {\r
-                            int src_alpha1 = start_col > left ? (src_scan[0] + src_scan[1] + src_scan[-1]) / 3 : (src_scan[0] + src_scan[1]) / 3;\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                            src_alpha1 = src_alpha1 * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        } else {\r
-                            if (start_col > left) {\r
-                                int src_alpha = src_scan[-1];\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                                src_alpha = src_alpha * a / 255;\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            }\r
-                            int src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[1];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        }\r
-                        for (int col = start_col + 1; col < end_col; col ++) {\r
-                            if (bNormal) {\r
-                                int src_alpha1 = (src_scan[0] + src_scan[1] + src_scan[-1]) / 3;\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                                src_alpha1 = src_alpha1 * a / 255;\r
-                                if (src_alpha1 == 0) {\r
-                                    dest_scan += Bpp;\r
-                                    src_scan += 3;\r
-                                    continue;\r
-                                }\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));\r
-                                dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));\r
-                                dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));\r
-                                dest_scan += Bpp;\r
-                                src_scan += 3;\r
-                                continue;\r
-                            }\r
-                            int src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[1];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        }\r
-                    } else {\r
-                        if (bNormal) {\r
-                            int src_alpha1 = start_col > left ? (src_scan[0] + src_scan[-2] + src_scan[-1]) / 3 : src_scan[0] / 3;\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                            src_alpha1 = src_alpha1 * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        } else {\r
-                            if (start_col > left) {\r
-                                int src_alpha = src_scan[-2];\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                                src_alpha = src_alpha * a / 255;\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                                src_alpha = src_scan[-1];\r
-                                ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                                src_alpha = src_alpha * a / 255;\r
-                                dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            }\r
-                            int src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        }\r
-                        for (int col = start_col + 1; col < end_col; col ++) {\r
-                            if (bNormal) {\r
-                                int src_alpha1 = ((int)(src_scan[0]) + (int)(src_scan[-2]) + (int)(src_scan[-1])) / 3;\r
-                                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);\r
-                                src_alpha1 = src_alpha1 * a / 255;\r
-                                if (src_alpha1 == 0) {\r
-                                    dest_scan += Bpp;\r
-                                    src_scan += 3;\r
-                                    continue;\r
-                                }\r
-                                dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));\r
-                                dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));\r
-                                dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));\r
-                                dest_scan += Bpp;\r
-                                src_scan += 3;\r
-                                continue;\r
-                            }\r
-                            int src_alpha = src_scan[-2];\r
-                            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));\r
-                            src_alpha = src_scan[-1];\r
-                            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));\r
-                            src_alpha = src_scan[0];\r
-                            ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);\r
-                            src_alpha = src_alpha * a / 255;\r
-                            dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));\r
-                            dest_scan += Bpp;\r
-                            src_scan += 3;\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-        }\r
-    }\r
-    if (bitmap.IsAlphaMask()) {\r
-        SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color, alpha_flag, pIccTransform);\r
-    } else {\r
-        SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top);\r
-    }\r
-    FX_Free(pGlyphAndPos);\r
-    return TRUE;\r
-}\r
-FX_BOOL CFX_RenderDevice::DrawTextPath(int nChars, const FXTEXT_CHARPOS* pCharPos,\r
-                                       CFX_Font* pFont, CFX_FontCache* pCache,\r
-                                       FX_FLOAT font_size, const CFX_AffineMatrix* pText2User,\r
-                                       const CFX_AffineMatrix* pUser2Device, const CFX_GraphStateData* pGraphState,\r
-                                       FX_DWORD fill_color, FX_ARGB stroke_color, CFX_PathData* pClippingPath, int nFlag,\r
-                                       int alpha_flag, void* pIccTransform, int blend_type)\r
-{\r
-    if (pCache == NULL) {\r
-        pCache = CFX_GEModule::Get()->GetFontCache();\r
-    }\r
-    CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont);\r
-    FX_FONTCACHE_DEFINE(pCache, pFont);\r
-    for (int iChar = 0; iChar < nChars; iChar ++) {\r
-        const FXTEXT_CHARPOS& charpos = pCharPos[iChar];\r
-        CFX_AffineMatrix matrix;\r
-        if (charpos.m_bGlyphAdjust)\r
-            matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],\r
-                       charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0);\r
-        matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, charpos.m_OriginY);\r
-        const CFX_PathData* pPath = pFaceCache->LoadGlyphPath(pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth);\r
-        if (pPath == NULL) {\r
-            continue;\r
-        }\r
-        matrix.Concat(*pText2User);\r
-        CFX_PathData TransformedPath(*pPath);\r
-        TransformedPath.Transform(&matrix);\r
-        FX_BOOL bHasAlpha = FXGETFLAG_COLORTYPE(alpha_flag) ?\r
-                            (FXGETFLAG_ALPHA_FILL(alpha_flag) || FXGETFLAG_ALPHA_STROKE(alpha_flag)) :\r
-                            (fill_color || stroke_color);\r
-        if (bHasAlpha) {\r
-            int fill_mode = nFlag;\r
-            if (FXGETFLAG_COLORTYPE(alpha_flag)) {\r
-                if (FXGETFLAG_ALPHA_FILL(alpha_flag)) {\r
-                    fill_mode |= FXFILL_WINDING;\r
-                }\r
-            } else {\r
-                if (fill_color) {\r
-                    fill_mode |= FXFILL_WINDING;\r
-                }\r
-            }\r
-            fill_mode |= FX_FILL_TEXT_MODE;\r
-            if (!DrawPath(&TransformedPath, pUser2Device, pGraphState, fill_color, stroke_color, fill_mode, alpha_flag, pIccTransform, blend_type)) {\r
-                return FALSE;\r
-            }\r
-        }\r
-        if (pClippingPath) {\r
-            pClippingPath->Append(&TransformedPath, pUser2Device);\r
-        }\r
-    }\r
-    return TRUE;\r
-}\r
-CFX_FontCache::~CFX_FontCache()\r
-{\r
-    FreeCache(TRUE);\r
-}\r
-CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont)\r
-{\r
-    FX_BOOL bExternal = pFont->GetFace() == NULL;\r
-    void* face = bExternal ? pFont->GetSubstFont()->m_ExtHandle : pFont->GetFace();\r
-    CFX_FTCacheMap& map =  bExternal ? m_ExtFaceMap : m_FTFaceMap;\r
-    CFX_CountedFaceCache* counted_face_cache = NULL;\r
-    if (map.Lookup((FXFT_Face)face, counted_face_cache)) {\r
-        counted_face_cache->m_nCount++;\r
-        return counted_face_cache->m_Obj;\r
-    }\r
-    CFX_FaceCache* face_cache = NULL;\r
-    face_cache = FX_NEW CFX_FaceCache(bExternal ? NULL : (FXFT_Face)face);\r
-    if (face_cache == NULL)    {\r
-        return NULL;\r
-    }\r
-    counted_face_cache = FX_NEW CFX_CountedFaceCache;\r
-    if (!counted_face_cache) {\r
-        if (face_cache) {\r
-            delete face_cache;\r
-            face_cache = NULL;\r
-        }\r
-        return NULL;\r
-    }\r
-    counted_face_cache->m_nCount = 2;\r
-    counted_face_cache->m_Obj = face_cache;\r
-    map.SetAt((FXFT_Face)face, counted_face_cache);\r
-    return face_cache;\r
-}\r
-void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont)\r
-{\r
-    FX_BOOL bExternal = pFont->GetFace() == NULL;\r
-    void* face = bExternal ? pFont->GetSubstFont()->m_ExtHandle : pFont->GetFace();\r
-    CFX_FTCacheMap& map =  bExternal ? m_ExtFaceMap : m_FTFaceMap;\r
-    CFX_CountedFaceCache* counted_face_cache = NULL;\r
-    if (!map.Lookup((FXFT_Face)face, counted_face_cache)) {\r
-        return;\r
-    }\r
-    if (counted_face_cache->m_nCount > 1) {\r
-        counted_face_cache->m_nCount--;\r
-    }\r
-}\r
-void CFX_FontCache::FreeCache(FX_BOOL bRelease)\r
-{\r
-    {\r
-        FX_POSITION pos;\r
-        pos = m_FTFaceMap.GetStartPosition();\r
-        while (pos) {\r
-            FXFT_Face face;\r
-            CFX_CountedFaceCache* cache;\r
-            m_FTFaceMap.GetNextAssoc(pos, face, cache);\r
-            if (bRelease || cache->m_nCount < 2) {\r
-                delete cache->m_Obj;\r
-                delete cache;\r
-                m_FTFaceMap.RemoveKey(face);\r
-            }\r
-        }\r
-        pos = m_ExtFaceMap.GetStartPosition();\r
-        while (pos) {\r
-            FXFT_Face face;\r
-            CFX_CountedFaceCache* cache;\r
-            m_ExtFaceMap.GetNextAssoc(pos, face, cache);\r
-            if (bRelease || cache->m_nCount < 2) {\r
-                delete cache->m_Obj;\r
-                delete cache;\r
-                m_ExtFaceMap.RemoveKey(face);\r
-            }\r
-        }\r
-    }\r
-}\r
-CFX_FaceCache::CFX_FaceCache(FXFT_Face face)\r
-{\r
-    m_Face = face;\r
-    m_pBitmap = NULL;\r
-}\r
-CFX_FaceCache::~CFX_FaceCache()\r
-{\r
-    FX_POSITION pos = m_SizeMap.GetStartPosition();\r
-    CFX_ByteString Key;\r
-    CFX_SizeGlyphCache* pSizeCache = NULL;\r
-    while(pos) {\r
-        m_SizeMap.GetNextAssoc( pos, Key, (void*&)pSizeCache);\r
-        delete pSizeCache;\r
-    }\r
-    m_SizeMap.RemoveAll();\r
-    pos = m_PathMap.GetStartPosition();\r
-    FX_LPVOID key1;\r
-    CFX_PathData* pPath;\r
-    while (pos) {\r
-        m_PathMap.GetNextAssoc(pos, key1, (FX_LPVOID&)pPath);\r
-        delete pPath;\r
-    }\r
-    if (m_pBitmap) {\r
-        delete m_pBitmap;\r
-    }\r
-    m_PathMap.RemoveAll();\r
-}\r
-#if ((_FXM_PLATFORM_  != _FXM_PLATFORM_APPLE_)|| defined(_FPDFAPI_MINI_))\r
-void CFX_FaceCache::InitPlatform()\r
-{\r
-}\r
-#endif\r
-CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap(CFX_Font* pFont, const CFX_AffineMatrix* pMatrix,\r
-        CFX_ByteStringC& FaceGlyphsKey, FX_DWORD glyph_index, FX_BOOL bFontStyle,\r
-        int dest_width, int anti_alias)\r
-{\r
-    CFX_SizeGlyphCache* pSizeCache = NULL;\r
-    if (!m_SizeMap.Lookup(FaceGlyphsKey, (void*&)pSizeCache)) {\r
-        pSizeCache = FX_NEW CFX_SizeGlyphCache;\r
-        if (pSizeCache == NULL)        {\r
-            return NULL;\r
-        }\r
-        m_SizeMap.SetAt(FaceGlyphsKey, pSizeCache);\r
-    }\r
-    CFX_GlyphBitmap* pGlyphBitmap = NULL;\r
-    if (pSizeCache->m_GlyphMap.Lookup((FX_LPVOID)(FX_UINTPTR)glyph_index, (void*&)pGlyphBitmap)) {\r
-        return pGlyphBitmap;\r
-    }\r
-    pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, pMatrix, dest_width, anti_alias);\r
-    if (pGlyphBitmap == NULL)  {\r
-        return NULL;\r
-    }\r
-    pSizeCache->m_GlyphMap.SetAt((FX_LPVOID)(FX_UINTPTR)glyph_index, pGlyphBitmap);\r
-    return pGlyphBitmap;\r
-}\r
-const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(CFX_Font* pFont, FX_DWORD glyph_index, FX_BOOL bFontStyle, const CFX_AffineMatrix* pMatrix,\r
-        int dest_width, int anti_alias, int& text_flags)\r
-{\r
-    if (glyph_index == (FX_DWORD) - 1) {\r
-        return NULL;\r
-    }\r
-    _CFX_UniqueKeyGen keygen;\r
-#if ((_FXM_PLATFORM_  != _FXM_PLATFORM_APPLE_)|| defined(_FPDFAPI_MINI_))\r
-    if (pFont->GetSubstFont())\r
-        keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),\r
-                        (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), dest_width, anti_alias,\r
-                        pFont->GetSubstFont()->m_Weight, pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical());\r
-    else\r
-        keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),\r
-                        (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), dest_width, anti_alias);\r
-#else\r
-    if (text_flags & FXTEXT_NO_NATIVETEXT) {\r
-        if (pFont->GetSubstFont())\r
-            keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),\r
-                            (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), dest_width, anti_alias,\r
-                            pFont->GetSubstFont()->m_Weight, pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical());\r
-        else\r
-            keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),\r
-                            (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), dest_width, anti_alias);\r
-    } else {\r
-        if (pFont->GetSubstFont())\r
-            keygen.Generate(10, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),\r
-                            (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), dest_width, anti_alias,\r
-                            pFont->GetSubstFont()->m_Weight, pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical(), 3);\r
-        else\r
-            keygen.Generate(7, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),\r
-                            (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), dest_width, anti_alias, 3);\r
-    }\r
-#endif\r
-    CFX_ByteStringC FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen);\r
-#if ((_FXM_PLATFORM_  != _FXM_PLATFORM_APPLE_)|| defined(_FPDFAPI_MINI_))\r
-    return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey, glyph_index, bFontStyle, dest_width, anti_alias);\r
-#else\r
-    if (text_flags & FXTEXT_NO_NATIVETEXT) {\r
-        return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey, glyph_index, bFontStyle, dest_width, anti_alias);\r
-    } else {\r
-        CFX_GlyphBitmap* pGlyphBitmap;\r
-        CFX_SizeGlyphCache* pSizeCache = NULL;\r
-        if (m_SizeMap.Lookup(FaceGlyphsKey, (void*&)pSizeCache)) {\r
-            if (pSizeCache->m_GlyphMap.Lookup((FX_LPVOID)(FX_UINTPTR)glyph_index, (void*&)pGlyphBitmap)) {\r
-                return pGlyphBitmap;\r
-            }\r
-            pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix, dest_width, anti_alias);\r
-            if (pGlyphBitmap) {\r
-                pSizeCache->m_GlyphMap.SetAt((FX_LPVOID)(FX_UINTPTR)glyph_index, pGlyphBitmap);\r
-                return pGlyphBitmap;\r
-            }\r
-        } else {\r
-            pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix, dest_width, anti_alias);\r
-            if (pGlyphBitmap) {\r
-                pSizeCache = FX_NEW CFX_SizeGlyphCache;\r
-                if (pSizeCache == NULL)        {\r
-                    return NULL;\r
-                }\r
-                m_SizeMap.SetAt(FaceGlyphsKey, pSizeCache);\r
-                pSizeCache->m_GlyphMap.SetAt((FX_LPVOID)(FX_UINTPTR)glyph_index, pGlyphBitmap);\r
-                return pGlyphBitmap;\r
-            }\r
-        }\r
-        if (pFont->GetSubstFont())\r
-            keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),\r
-                            (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), dest_width, anti_alias,\r
-                            pFont->GetSubstFont()->m_Weight, pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical());\r
-        else\r
-            keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),\r
-                            (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000), dest_width, anti_alias);\r
-        CFX_ByteStringC FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen);\r
-        text_flags |= FXTEXT_NO_NATIVETEXT;\r
-        return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey, glyph_index, bFontStyle, dest_width, anti_alias);\r
-    }\r
-#endif\r
-}\r
-CFX_SizeGlyphCache::~CFX_SizeGlyphCache()\r
-{\r
-    FX_POSITION pos = m_GlyphMap.GetStartPosition();\r
-    FX_LPVOID Key;\r
-    CFX_GlyphBitmap* pGlyphBitmap = NULL;\r
-    while(pos) {\r
-        m_GlyphMap.GetNextAssoc(pos, Key, (void*&)pGlyphBitmap);\r
-        delete pGlyphBitmap;\r
-    }\r
-    m_GlyphMap.RemoveAll();\r
-}\r
-#if defined(_FPDFAPI_MINI_)\r
-#define CONTRAST_RAMP_STEP     16\r
-#else\r
-#define CONTRAST_RAMP_STEP     1\r
-#endif\r
-static const FX_BYTE g_adjust_contrast11[256] = {\r
-    0, 0, 2, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 24, 25, 26, 28, 29, 31,\r
-    32, 33, 35, 36, 38, 39, 40, 42, 43, 45, 46, 48, 49, 51, 52, 54, 55, 56, 58, 59, 61, 62, 64, 65,\r
-    67, 68, 70, 71, 72, 74, 75, 77, 78, 80, 81, 83, 84, 86, 87, 89, 90, 91, 93, 94, 96, 97, 99, 100,\r
-    101, 103, 104, 106, 107, 109, 110, 111, 113, 114, 116, 117, 118, 120, 121, 123, 124, 125, 127,\r
-    128, 130, 131, 132, 134, 135, 136, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149, 151, 152,\r
-    153, 155, 156, 157, 158, 160, 161, 162, 163, 165, 166, 167, 168, 169, 171, 172, 173, 174, 175,\r
-    177, 178, 179, 180, 181, 182, 183, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,\r
-    197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215,\r
-    215, 216, 217, 218, 219, 220, 221, 221, 222, 223, 224, 224, 225, 226, 227, 227, 228, 229, 230,\r
-    230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 237, 238, 239, 239, 240, 240, 241, 241,\r
-    242, 242, 243, 243, 244, 244, 245, 245, 246, 246, 246, 247, 247, 248, 248, 248, 249, 249, 249,\r
-    250, 250, 250, 251, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 253, 253, 254, 254,\r
-    254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255,\r
-};\r
-static const FX_BYTE g_adjust_contrast15[256] = {\r
-    0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\r
-    22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 40, 41, 42, 43, 45, 46, 47, 48, 50, 51,\r
-    52, 54, 55, 56, 58, 59, 60, 62, 63, 64, 66, 67, 68, 70, 71, 73, 74, 75, 77, 78, 80, 81, 82, 84, 85, 87,\r
-    88, 90, 91, 93, 94, 95, 97, 98, 100, 101, 103, 104, 106, 107, 109, 110, 111, 113, 114, 116, 117, 119,\r
-    120, 122, 123, 125, 126, 128, 129, 130, 132, 133, 135, 136, 138, 139, 141, 142, 143, 145, 146, 148,\r
-    149, 150, 152, 153, 155, 156, 157, 159, 160, 161, 163, 164, 166, 167, 168, 170, 171, 172, 174, 175,\r
-    176, 177, 179, 180, 181, 183, 184, 185, 186, 188, 189, 190, 191, 192, 194, 195, 196, 197, 198, 199,\r
-    201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,\r
-    221, 222, 223, 224, 225, 226, 227, 227, 228, 229, 230, 231, 232, 232, 233, 234, 235, 235, 236, 237,\r
-    237, 238, 239, 239, 240, 241, 241, 242, 242, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248,\r
-    248, 249, 249, 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 253, 254, 254,\r
-    254, 254, 254, 254, 254, 254, 254, 254, 254, 255,\r
-};\r
-static void _CalcContrastRamp(FX_LPBYTE ramp, int level)\r
-{\r
-    int contrast_min = 0, contrast_max = 255 - level, i;\r
-    for (i = 0; i < contrast_min; i ++) {\r
-        ramp[i] = 0;\r
-    }\r
-    for (i = contrast_min; i < contrast_max; i ++) {\r
-        ramp[i] = 255 * (i - contrast_min) / (contrast_max - contrast_min);\r
-    }\r
-    for (i = contrast_max; i < 256; i ++) {\r
-        ramp[i] = 255;\r
-    }\r
-}\r
-void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight)\r
-{\r
-    FXFT_MM_Var pMasters = NULL;\r
-    FXFT_Get_MM_Var(m_Face, &pMasters);\r
-    if (pMasters == NULL) {\r
-        return;\r
-    }\r
-    long coords[2];\r
-    if (weight == 0) {\r
-        coords[0] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 0)) / 65536;\r
-    } else {\r
-        coords[0] = weight;\r
-    }\r
-    if (dest_width == 0) {\r
-        coords[1] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;\r
-    } else {\r
-        int min_param = FXFT_Get_MM_Axis_Min(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;\r
-        int max_param = FXFT_Get_MM_Axis_Max(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;\r
-        coords[1] = min_param;\r
-        int error = FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);\r
-        error = FXFT_Load_Glyph(m_Face, glyph_index, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);\r
-        int min_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 / FXFT_Get_Face_UnitsPerEM(m_Face);\r
-        coords[1] = max_param;\r
-        error = FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);\r
-        error = FXFT_Load_Glyph(m_Face, glyph_index, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);\r
-        int max_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 / FXFT_Get_Face_UnitsPerEM(m_Face);\r
-        if (max_width == min_width) {\r
-            return;\r
-        }\r
-        int param = min_param + (max_param - min_param) * (dest_width - min_width) / (max_width - min_width);\r
-        coords[1] = param;\r
-    }\r
-    FXFT_Free(m_Face, pMasters);\r
-    FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);\r
-}\r
-extern const char g_AngleSkew[30] = {\r
-    0, 2, 3, 5, 7, 9, 11, 12, 14, 16,\r
-    18, 19, 21, 23, 25, 27, 29, 31, 32, 34,\r
-    36, 38, 40, 42, 45, 47, 49, 51, 53, 55,\r
-};\r
-static const FX_BYTE g_WeightPow[100] = {\r
-    0, 3, 6, 7, 8, 9, 11, 12, 14, 15, 16, 17, 18, 19, 20,\r
-    21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 35, 36, 36,\r
-    37, 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42,\r
-    42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47, 47,\r
-    47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 50, 51, 51,\r
-    51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53,\r
-};\r
-extern const FX_BYTE g_WeightPow_11[100] = {\r
-    0, 4, 7, 8, 9, 10, 12, 13, 15, 17, 18, 19, 20, 21, 22,\r
-    23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 39, 40, 40,\r
-    41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46,\r
-    46, 43, 47, 47, 48, 48, 48, 48, 45, 50, 50, 50, 46, 51, 51, 51, 52, 52,\r
-    52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 55, 56, 56,\r
-    56, 56, 56, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58,\r
-};\r
-extern const FX_BYTE g_WeightPow_SHIFTJIS[100] = {\r
-    0, 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 21, 22, 24, 26, 28,\r
-    30, 32, 33, 35, 37, 39, 41, 43, 45, 48, 48, 48, 48, 49, 49, 49, 50, 50, 50, 50,\r
-    51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 55, 55,\r
-    55, 55, 55, 56, 56, 56, 56, 56 , 56, 57, 57, 57 , 57 , 57, 57, 57, 58, 58, 58, 58, 58,\r
-    58, 58, 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60,\r
-};\r
-static void _GammaAdjust(FX_LPBYTE pData, int nWid, int nHei, int src_pitch, FX_LPCBYTE gammaTable)\r
-{\r
-    int count = nHei * src_pitch;\r
-    for(int i = 0; i < count; i++) {\r
-        pData[i] = gammaTable[pData[i]];\r
-    }\r
-}\r
-static void _ContrastAdjust(FX_LPBYTE pDataIn, FX_LPBYTE pDataOut, int nWid, int nHei, int nSrcRowBytes, int nDstRowBytes)\r
-{\r
-    int col, row, temp;\r
-    int max = 0, min = 255;\r
-    FX_FLOAT rate;\r
-    for (row = 0; row < nHei; row ++) {\r
-        FX_LPBYTE pRow = pDataIn + row * nSrcRowBytes;\r
-        for (col = 0; col < nWid; col++) {\r
-            temp = *pRow ++;\r
-            if (temp > max) {\r
-                max = temp;\r
-            }\r
-            if (temp < min) {\r
-                min = temp;\r
-            }\r
-        }\r
-    }\r
-    temp = max - min;\r
-    if (0 == temp || 255 == temp) {\r
-        int rowbytes = FXSYS_abs(nSrcRowBytes) > nDstRowBytes ? nDstRowBytes : FXSYS_abs(nSrcRowBytes);\r
-        for (row = 0; row < nHei; row ++) {\r
-            FXSYS_memcpy32(pDataOut + row * nDstRowBytes, pDataIn + row * nSrcRowBytes, rowbytes);\r
-        }\r
-        return;\r
-    }\r
-    rate = 255.f / temp;\r
-    for (row = 0; row < nHei; row ++) {\r
-        FX_LPBYTE pSrcRow = pDataIn + row * nSrcRowBytes;\r
-        FX_LPBYTE pDstRow = pDataOut + row * nDstRowBytes;\r
-        for (col = 0; col < nWid; col ++) {\r
-            temp = (int)((*(pSrcRow++) - min) * rate + 0.5);\r
-            if (temp > 255)    {\r
-                temp = 255;\r
-            } else if (temp < 0) {\r
-                temp = 0;\r
-            }\r
-            *pDstRow ++ = (FX_BYTE)temp;\r
-        }\r
-    }\r
-}\r
-CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, FX_DWORD glyph_index, FX_BOOL bFontStyle,\r
-        const CFX_AffineMatrix* pMatrix, int dest_width, int anti_alias)\r
-{\r
-    if (m_Face == NULL) {\r
-        return NULL;\r
-    }\r
-    FXFT_Matrix  ft_matrix;\r
-    ft_matrix.xx = (signed long)(pMatrix->GetA() / 64 * 65536);\r
-    ft_matrix.xy = (signed long)(pMatrix->GetC() / 64 * 65536);\r
-    ft_matrix.yx = (signed long)(pMatrix->GetB() / 64 * 65536);\r
-    ft_matrix.yy = (signed long)(pMatrix->GetD() / 64 * 65536);\r
-    FX_BOOL bUseCJKSubFont = FALSE;\r
-    const CFX_SubstFont* pSubstFont = pFont->GetSubstFont();\r
-    if (pSubstFont) {\r
-        bUseCJKSubFont = pSubstFont->m_bSubstOfCJK && bFontStyle;\r
-        int skew = 0;\r
-        if (bUseCJKSubFont) {\r
-            skew = pSubstFont->m_bItlicCJK ? -15 : 0;\r
-        } else {\r
-            skew = pSubstFont->m_ItalicAngle;\r
-        }\r
-        if (skew) {\r
-            skew = skew <= -30 ? -58 : -g_AngleSkew[-skew];\r
-            if (pFont->IsVertical()) {\r
-                ft_matrix.yx += ft_matrix.yy * skew / 100;\r
-            } else {\r
-                ft_matrix.xy += -ft_matrix.xx * skew / 100;\r
-            }\r
-        }\r
-        if (pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) {\r
-            pFont->AdjustMMParams(glyph_index, dest_width, pFont->GetSubstFont()->m_Weight);\r
-        }\r
-    }\r
-    int transflag = FXFT_Get_Face_Internal_Flag(m_Face);\r
-    FXFT_Set_Transform(m_Face, &ft_matrix, 0);\r
-    int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) ? FXFT_LOAD_NO_BITMAP : (FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING);\r
-    int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags);\r
-    if (error) {\r
-        FXFT_Set_Face_Internal_Flag(m_Face, transflag);\r
-        return NULL;\r
-    }\r
-    int weight = 0;\r
-    if (bUseCJKSubFont) {\r
-        weight = pSubstFont->m_WeightCJK;\r
-    } else {\r
-        weight = pSubstFont ? pSubstFont->m_Weight : 0;\r
-    }\r
-    if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && weight > 400) {\r
-        int index = (weight - 400) / 10;\r
-        if (index >= 100) {\r
-            FXFT_Set_Face_Internal_Flag(m_Face, transflag);\r
-            return NULL;\r
-        }\r
-        int level = 0;\r
-        if (pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) {\r
-            level = g_WeightPow_SHIFTJIS[index] * 2 * (FXSYS_abs(ft_matrix.xx) + FXSYS_abs(ft_matrix.xy)) / 36655;\r
-        } else {\r
-            level = g_WeightPow_11[index] * (FXSYS_abs(ft_matrix.xx) + FXSYS_abs(ft_matrix.xy)) / 36655;\r
-        }\r
-        FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);\r
-    }\r
-    FXFT_Library_SetLcdFilter(CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary, FT_LCD_FILTER_DEFAULT);\r
-    error = FXFT_Render_Glyph(m_Face, anti_alias);\r
-    if (error) {\r
-        FXFT_Set_Face_Internal_Flag(m_Face, transflag);\r
-        return NULL;\r
-    }\r
-    int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(m_Face));\r
-    int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(m_Face));\r
-    if (bmwidth > 2048 || bmheight > 2048) {\r
-        FXFT_Set_Face_Internal_Flag(m_Face, transflag);\r
-        return NULL;\r
-    }\r
-    int dib_width = bmwidth;\r
-    CFX_GlyphBitmap* pGlyphBitmap = FX_NEW CFX_GlyphBitmap;\r
-    if (!pGlyphBitmap) {\r
-        return NULL;\r
-    }\r
-    pGlyphBitmap->m_Bitmap.Create(dib_width, bmheight,\r
-                                  anti_alias == FXFT_RENDER_MODE_MONO ? FXDIB_1bppMask : FXDIB_8bppMask);\r
-    pGlyphBitmap->m_Left = FXFT_Get_Glyph_BitmapLeft(m_Face);\r
-    pGlyphBitmap->m_Top = FXFT_Get_Glyph_BitmapTop(m_Face);\r
-    int dest_pitch = pGlyphBitmap->m_Bitmap.GetPitch();\r
-    int src_pitch = FXFT_Get_Bitmap_Pitch(FXFT_Get_Glyph_Bitmap(m_Face));\r
-    FX_BYTE* pDestBuf = pGlyphBitmap->m_Bitmap.GetBuffer();\r
-    FX_BYTE* pSrcBuf = (FX_BYTE*)FXFT_Get_Bitmap_Buffer(FXFT_Get_Glyph_Bitmap(m_Face));\r
-    if (anti_alias != FXFT_RENDER_MODE_MONO && FXFT_Get_Bitmap_PixelMode(FXFT_Get_Glyph_Bitmap(m_Face)) == FXFT_PIXEL_MODE_MONO) {\r
-        int bytes = anti_alias == FXFT_RENDER_MODE_LCD ? 3 : 1;\r
-        for(int i = 0; i < bmheight; i++)\r
-            for(int n = 0; n < bmwidth; n++) {\r
-                FX_BYTE data = (pSrcBuf[i * src_pitch + n / 8] & (0x80 >> (n % 8))) ? 255 : 0;\r
-                for (int b = 0; b < bytes; b ++) {\r
-                    pDestBuf[i * dest_pitch + n * bytes + b] = data;\r
-                }\r
-            }\r
-    } else {\r
-        FXSYS_memset32(pDestBuf, 0, dest_pitch * bmheight);\r
-        if (anti_alias == FXFT_RENDER_MODE_MONO && FXFT_Get_Bitmap_PixelMode(FXFT_Get_Glyph_Bitmap(m_Face)) == FXFT_PIXEL_MODE_MONO) {\r
-            int rowbytes = FXSYS_abs(src_pitch) > dest_pitch ? dest_pitch : FXSYS_abs(src_pitch);\r
-            for (int row = 0; row < bmheight; row ++) {\r
-                FXSYS_memcpy32(pDestBuf + row * dest_pitch, pSrcBuf + row * src_pitch, rowbytes);\r
-            }\r
-        } else {\r
-            _ContrastAdjust(pSrcBuf, pDestBuf, bmwidth, bmheight, src_pitch, dest_pitch);\r
-            _GammaAdjust(pDestBuf, bmwidth, bmheight, dest_pitch, CFX_GEModule::Get()->GetTextGammaTable());\r
-        }\r
-    }\r
-    FXFT_Set_Face_Internal_Flag(m_Face, transflag);\r
-    return pGlyphBitmap;\r
-}\r
-FX_BOOL _OutputGlyph(void* dib, int x, int y, CFX_Font* pFont,\r
-                     int glyph_index, FX_ARGB argb)\r
-{\r
-    CFX_DIBitmap* pDib = (CFX_DIBitmap*)dib;\r
-    FXFT_Face face = pFont->GetFace();\r
-    int error = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_NO_BITMAP);\r
-    if (error) {\r
-        return FALSE;\r
-    }\r
-    error = FXFT_Render_Glyph(face, FXFT_RENDER_MODE_NORMAL);\r
-    if (error) {\r
-        return FALSE;\r
-    }\r
-    int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(face));\r
-    int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(face));\r
-    int left = FXFT_Get_Glyph_BitmapLeft(face);\r
-    int top = FXFT_Get_Glyph_BitmapTop(face);\r
-    FX_LPCBYTE src_buf = (FX_LPCBYTE)FXFT_Get_Bitmap_Buffer(FXFT_Get_Glyph_Bitmap(face));\r
-    int src_pitch = FXFT_Get_Bitmap_Pitch(FXFT_Get_Glyph_Bitmap(face));\r
-    CFX_DIBitmap mask;\r
-    mask.Create(bmwidth, bmheight, FXDIB_8bppMask);\r
-    FX_LPBYTE dest_buf = mask.GetBuffer();\r
-    int dest_pitch = mask.GetPitch();\r
-    for (int row = 0; row < bmheight; row ++) {\r
-        FX_LPCBYTE src_scan = src_buf + row * src_pitch;\r
-        FX_LPBYTE dest_scan = dest_buf + row * dest_pitch;\r
-        FXSYS_memcpy32(dest_scan, src_scan, dest_pitch);\r
-    }\r
-    pDib->CompositeMask(x + left, y - top, bmwidth, bmheight, &mask, argb, 0, 0);\r
-    return TRUE;\r
-}\r
-FX_BOOL OutputText(void* dib, int x, int y, CFX_Font* pFont, double font_size,\r
-                   CFX_AffineMatrix* pText_matrix, unsigned short const* text, unsigned long argb)\r
-{\r
-    if (!pFont) {\r
-        return FALSE;\r
-    }\r
-    FXFT_Face face = pFont->GetFace();\r
-    FXFT_Select_Charmap(pFont->m_Face, FXFT_ENCODING_UNICODE);\r
-    int transflag = FXFT_Get_Face_Internal_Flag(pFont->m_Face);\r
-    if (pText_matrix) {\r
-        FXFT_Matrix  ft_matrix;\r
-        ft_matrix.xx = (signed long)(pText_matrix->a / 64 * 65536);\r
-        ft_matrix.xy = (signed long)(pText_matrix->c / 64 * 65536);\r
-        ft_matrix.yx = (signed long)(pText_matrix->b / 64 * 65536);\r
-        ft_matrix.yy = (signed long)(pText_matrix->d / 64 * 65536);\r
-        FXFT_Set_Transform(face, &ft_matrix, 0);\r
-    }\r
-    FX_FLOAT x_pos = 0;\r
-    for (; *text != 0; text ++) {\r
-        FX_WCHAR unicode = *text;\r
-        int glyph_index = FXFT_Get_Char_Index(pFont->m_Face, unicode);\r
-        if (glyph_index <= 0) {\r
-            continue;\r
-        }\r
-        int err = FXFT_Load_Glyph(pFont->m_Face, glyph_index, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);\r
-        if (err) {\r
-            continue;\r
-        }\r
-        int w = FXFT_Get_Glyph_HoriAdvance(pFont->m_Face);\r
-        int em = FXFT_Get_Face_UnitsPerEM(pFont->m_Face);\r
-        FX_FLOAT x1, y1;\r
-        pText_matrix->Transform(x_pos, 0, x1, y1);\r
-        _OutputGlyph(dib, (int)x1 + x, (int) - y1 + y, pFont,\r
-                     glyph_index, argb);\r
-        x_pos += (FX_FLOAT)w / em;\r
-    }\r
-    FXFT_Set_Face_Internal_Flag(pFont->m_Face, transflag);\r
-    return TRUE;\r
-}\r
-FX_BOOL OutputGlyph(void* dib, int x, int y, CFX_Font* pFont, double font_size,\r
-                    CFX_AffineMatrix* pMatrix, unsigned long glyph_index, unsigned long argb)\r
-{\r
-    FXFT_Matrix  ft_matrix;\r
-    if (pMatrix) {\r
-        ft_matrix.xx = (signed long)(pMatrix->a * font_size / 64 * 65536);\r
-        ft_matrix.xy = (signed long)(pMatrix->c * font_size / 64 * 65536);\r
-        ft_matrix.yx = (signed long)(pMatrix->b * font_size / 64 * 65536);\r
-        ft_matrix.yy = (signed long)(pMatrix->d * font_size / 64 * 65536);\r
-    } else {\r
-        ft_matrix.xx = (signed long)(font_size / 64 * 65536);\r
-        ft_matrix.xy = ft_matrix.yx = 0;\r
-        ft_matrix.yy = (signed long)(font_size / 64 * 65536);\r
-    }\r
-    int transflag = FXFT_Get_Face_Internal_Flag(pFont->m_Face);\r
-    FXFT_Set_Transform(pFont->m_Face, &ft_matrix, 0);\r
-    FX_BOOL ret = _OutputGlyph(dib, x, y, pFont,\r
-                               glyph_index, argb);\r
-    FXFT_Set_Face_Internal_Flag(pFont->m_Face, transflag);\r
-    return ret;\r
-}\r
-const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont, FX_DWORD glyph_index, int dest_width)\r
-{\r
-    if (m_Face == NULL || glyph_index == (FX_DWORD) - 1) {\r
-        return NULL;\r
-    }\r
-    CFX_PathData* pGlyphPath = NULL;\r
-    FX_LPVOID key;\r
-    if (pFont->GetSubstFont())\r
-        key = (FX_LPVOID)(FX_UINTPTR)(glyph_index + ((pFont->GetSubstFont()->m_Weight / 16) << 15) +\r
-                                      ((pFont->GetSubstFont()->m_ItalicAngle / 2) << 21) + ((dest_width / 16) << 25) +\r
-                                      (pFont->IsVertical() << 31));\r
-    else {\r
-        key = (FX_LPVOID)(FX_UINTPTR)glyph_index;\r
-    }\r
-    if (m_PathMap.Lookup(key, (FX_LPVOID&)pGlyphPath)) {\r
-        return pGlyphPath;\r
-    }\r
-    pGlyphPath = pFont->LoadGlyphPath(glyph_index, dest_width);\r
-    m_PathMap.SetAt(key, pGlyphPath);\r
-    return pGlyphPath;\r
-}\r
-typedef struct {\r
-    FX_BOOL                    m_bCount;\r
-    int                                m_PointCount;\r
-    FX_PATHPOINT*      m_pPoints;\r
-    int                                m_CurX;\r
-    int                                m_CurY;\r
-    FX_FLOAT           m_CoordUnit;\r
-} OUTLINE_PARAMS;\r
-void _Outline_CheckEmptyContour(OUTLINE_PARAMS* param)\r
-{\r
-    if (param->m_PointCount >= 2 && param->m_pPoints[param->m_PointCount - 2].m_Flag == FXPT_MOVETO &&\r
-            param->m_pPoints[param->m_PointCount - 2].m_PointX == param->m_pPoints[param->m_PointCount - 1].m_PointX &&\r
-            param->m_pPoints[param->m_PointCount - 2].m_PointY == param->m_pPoints[param->m_PointCount - 1].m_PointY) {\r
-        param->m_PointCount -= 2;\r
-    }\r
-    if (param->m_PointCount >= 4 && param->m_pPoints[param->m_PointCount - 4].m_Flag == FXPT_MOVETO &&\r
-            param->m_pPoints[param->m_PointCount - 3].m_Flag == FXPT_BEZIERTO &&\r
-            param->m_pPoints[param->m_PointCount - 3].m_PointX == param->m_pPoints[param->m_PointCount - 4].m_PointX &&\r
-            param->m_pPoints[param->m_PointCount - 3].m_PointY == param->m_pPoints[param->m_PointCount - 4].m_PointY &&\r
-            param->m_pPoints[param->m_PointCount - 2].m_PointX == param->m_pPoints[param->m_PointCount - 4].m_PointX &&\r
-            param->m_pPoints[param->m_PointCount - 2].m_PointY == param->m_pPoints[param->m_PointCount - 4].m_PointY &&\r
-            param->m_pPoints[param->m_PointCount - 1].m_PointX == param->m_pPoints[param->m_PointCount - 4].m_PointX &&\r
-            param->m_pPoints[param->m_PointCount - 1].m_PointY == param->m_pPoints[param->m_PointCount - 4].m_PointY) {\r
-        param->m_PointCount -= 4;\r
-    }\r
-}\r
-extern "C" {\r
-    static int _Outline_MoveTo(const FXFT_Vector* to, void* user)\r
-    {\r
-        OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;\r
-        if (!param->m_bCount) {\r
-            _Outline_CheckEmptyContour(param);\r
-            param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount].m_Flag = FXPT_MOVETO;\r
-            param->m_CurX = to->x;\r
-            param->m_CurY = to->y;\r
-            if (param->m_PointCount) {\r
-                param->m_pPoints[param->m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;\r
-            }\r
-        }\r
-        param->m_PointCount ++;\r
-        return 0;\r
-    }\r
-};\r
-extern "C" {\r
-    static int _Outline_LineTo(const FXFT_Vector* to, void* user)\r
-    {\r
-        OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;\r
-        if (!param->m_bCount) {\r
-            param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount].m_Flag = FXPT_LINETO;\r
-            param->m_CurX = to->x;\r
-            param->m_CurY = to->y;\r
-        }\r
-        param->m_PointCount ++;\r
-        return 0;\r
-    }\r
-};\r
-extern "C" {\r
-    static int _Outline_ConicTo(const FXFT_Vector* control, const FXFT_Vector* to, void* user)\r
-    {\r
-        OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;\r
-        if (!param->m_bCount) {\r
-            param->m_pPoints[param->m_PointCount].m_PointX = (param->m_CurX + (control->x - param->m_CurX) * 2 / 3) / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount].m_PointY = (param->m_CurY + (control->y - param->m_CurY) * 2 / 3) / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount].m_Flag = FXPT_BEZIERTO;\r
-            param->m_pPoints[param->m_PointCount + 1].m_PointX = (control->x + (to->x - control->x) / 3) / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount + 1].m_PointY = (control->y + (to->y - control->y) / 3) / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount + 1].m_Flag = FXPT_BEZIERTO;\r
-            param->m_pPoints[param->m_PointCount + 2].m_PointX = to->x / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount + 2].m_PointY = to->y / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount + 2].m_Flag = FXPT_BEZIERTO;\r
-            param->m_CurX = to->x;\r
-            param->m_CurY = to->y;\r
-        }\r
-        param->m_PointCount += 3;\r
-        return 0;\r
-    }\r
-};\r
-extern "C" {\r
-    static int _Outline_CubicTo(const FXFT_Vector* control1, const FXFT_Vector* control2, const FXFT_Vector* to, void* user)\r
-    {\r
-        OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;\r
-        if (!param->m_bCount) {\r
-            param->m_pPoints[param->m_PointCount].m_PointX = control1->x / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount].m_PointY = control1->y / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount].m_Flag = FXPT_BEZIERTO;\r
-            param->m_pPoints[param->m_PointCount + 1].m_PointX = control2->x / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount + 1].m_PointY = control2->y / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount + 1].m_Flag = FXPT_BEZIERTO;\r
-            param->m_pPoints[param->m_PointCount + 2].m_PointX = to->x / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount + 2].m_PointY = to->y / param->m_CoordUnit;\r
-            param->m_pPoints[param->m_PointCount + 2].m_Flag = FXPT_BEZIERTO;\r
-            param->m_CurX = to->x;\r
-            param->m_CurY = to->y;\r
-        }\r
-        param->m_PointCount += 3;\r
-        return 0;\r
-    }\r
-};\r
-CFX_PathData* CFX_Font::LoadGlyphPath(FX_DWORD glyph_index, int dest_width)\r
-{\r
-    if (m_Face == NULL) {\r
-        return NULL;\r
-    }\r
-    FXFT_Set_Pixel_Sizes(m_Face, 0, 64);\r
-    FXFT_Matrix  ft_matrix = {65536, 0, 0, 65536};\r
-    if (m_pSubstFont) {\r
-        if (m_pSubstFont->m_ItalicAngle) {\r
-            int skew = m_pSubstFont->m_ItalicAngle;\r
-            skew = skew <= -30 ? -58 : -g_AngleSkew[-skew];\r
-            if (m_bVertical) {\r
-                ft_matrix.yx += ft_matrix.yy * skew / 100;\r
-            } else {\r
-                ft_matrix.xy += -ft_matrix.xx * skew / 100;\r
-            }\r
-        }\r
-        if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) {\r
-            AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight);\r
-        }\r
-    }\r
-    int transflag = FXFT_Get_Face_Internal_Flag(m_Face);\r
-    FXFT_Set_Transform(m_Face, &ft_matrix, 0);\r
-    int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) ? FXFT_LOAD_NO_BITMAP : FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING;\r
-    int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags);\r
-    if (error) {\r
-        FXFT_Set_Face_Internal_Flag(m_Face, transflag);\r
-        return NULL;\r
-    }\r
-    if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && m_pSubstFont->m_Weight > 400) {\r
-        int level = 0;\r
-        if (m_pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) {\r
-            level = g_WeightPow_SHIFTJIS[(m_pSubstFont->m_Weight - 400) / 10] * 2 * 65536 / 36655;\r
-        } else {\r
-            level = g_WeightPow[(m_pSubstFont->m_Weight - 400) / 10] * 2;\r
-        }\r
-        FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);\r
-    }\r
-    FXFT_Outline_Funcs funcs;\r
-    funcs.move_to = _Outline_MoveTo;\r
-    funcs.line_to = _Outline_LineTo;\r
-    funcs.conic_to = _Outline_ConicTo;\r
-    funcs.cubic_to = _Outline_CubicTo;\r
-    funcs.shift = 0;\r
-    funcs.delta = 0;\r
-    OUTLINE_PARAMS params;\r
-    params.m_bCount = TRUE;\r
-    params.m_PointCount = 0;\r
-    FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);\r
-    if (params.m_PointCount == 0) {\r
-        FXFT_Set_Face_Internal_Flag(m_Face, transflag);\r
-        return NULL;\r
-    }\r
-    CFX_PathData* pPath = FX_NEW CFX_PathData;\r
-    if (!pPath) {\r
-        return NULL;\r
-    }\r
-    pPath->SetPointCount(params.m_PointCount);\r
-    params.m_bCount = FALSE;\r
-    params.m_PointCount = 0;\r
-    params.m_pPoints = pPath->GetPoints();\r
-    params.m_CurX = params.m_CurY = 0;\r
-    params.m_CoordUnit = 64 * 64.0;\r
-    FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);\r
-    _Outline_CheckEmptyContour(&params);\r
-    pPath->TrimPoints(params.m_PointCount);\r
-    if (params.m_PointCount) {\r
-        pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;\r
-    }\r
-    FXFT_Set_Face_Internal_Flag(m_Face, transflag);\r
-    return pPath;\r
-}\r
-void _CFX_UniqueKeyGen::Generate(int count, ...)\r
-{\r
-    va_list argList;\r
-    va_start(argList, count);\r
-    for (int i = 0; i < count; i ++) {\r
-        int p = va_arg(argList, int);\r
-        ((FX_DWORD*)m_Key)[i] = p;\r
-    }\r
-    va_end(argList);\r
-    m_KeyLen = count * sizeof(FX_DWORD);\r
-}\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../../include/fxge/fx_ge.h"
+#include "../../../include/fxge/fx_freetype.h"
+#include "../../../include/fxcodec/fx_codec.h"
+#include "text_int.h"
+#undef FX_GAMMA
+#undef FX_GAMMA_INVERSE
+#define FX_GAMMA(value) (value)
+#define FX_GAMMA_INVERSE(value) (value)
+
+namespace {
+
+void ResetTransform(FT_Face face) {
+  FXFT_Matrix matrix;
+  matrix.xx = 0x10000L;
+  matrix.xy = 0;
+  matrix.yx = 0;
+  matrix.yy = 0x10000L;
+  FXFT_Set_Transform(face, &matrix, 0);
+}
+
+// Sets the given transform on the font, and resets it to the identity when it
+// goes out of scope.
+class ScopedFontTransform {
+ public:
+  ScopedFontTransform(FT_Face face, FXFT_Matrix* matrix) : m_Face(face) {
+    FXFT_Set_Transform(m_Face, matrix, 0);
+  }
+
+  ~ScopedFontTransform() { ResetTransform(m_Face); }
+
+ private:
+  FT_Face m_Face;
+};
+}
+
+FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos,
+                           int nChars,
+                           int anti_alias,
+                           FX_FLOAT retinaScaleX,
+                           FX_FLOAT retinaScaleY) {
+  FX_RECT rect(0, 0, 0, 0);
+  FX_BOOL bStarted = FALSE;
+  for (int iChar = 0; iChar < nChars; iChar++) {
+    FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar];
+    const CFX_GlyphBitmap* pGlyph = glyph.m_pGlyph;
+    if (pGlyph == NULL) {
+      continue;
+    }
+    int char_left = glyph.m_OriginX + pGlyph->m_Left;
+    int char_width = (int)(pGlyph->m_Bitmap.GetWidth() / retinaScaleX);
+    if (anti_alias == FXFT_RENDER_MODE_LCD) {
+      char_width /= 3;
+    }
+    int char_right = char_left + char_width;
+    int char_top = glyph.m_OriginY - pGlyph->m_Top;
+    int char_bottom =
+        char_top + (int)(pGlyph->m_Bitmap.GetHeight() / retinaScaleY);
+    if (!bStarted) {
+      rect.left = char_left;
+      rect.right = char_right;
+      rect.top = char_top;
+      rect.bottom = char_bottom;
+      bStarted = TRUE;
+    } else {
+      if (rect.left > char_left) {
+        rect.left = char_left;
+      }
+      if (rect.right < char_right) {
+        rect.right = char_right;
+      }
+      if (rect.top > char_top) {
+        rect.top = char_top;
+      }
+      if (rect.bottom < char_bottom) {
+        rect.bottom = char_bottom;
+      }
+    }
+  }
+  return rect;
+}
+static void _AdjustGlyphSpace(FXTEXT_GLYPHPOS* pGlyphAndPos, int nChars) {
+  ASSERT(nChars > 1);
+  FX_BOOL bVertical = FALSE;
+  if (pGlyphAndPos[nChars - 1].m_OriginX == pGlyphAndPos[0].m_OriginX) {
+    bVertical = TRUE;
+  } else if (pGlyphAndPos[nChars - 1].m_OriginY != pGlyphAndPos[0].m_OriginY) {
+    return;
+  }
+  int i = nChars - 1;
+  int* next_origin =
+      bVertical ? &pGlyphAndPos[i].m_OriginY : &pGlyphAndPos[i].m_OriginX;
+  FX_FLOAT next_origin_f =
+      bVertical ? pGlyphAndPos[i].m_fOriginY : pGlyphAndPos[i].m_fOriginX;
+  for (i--; i > 0; i--) {
+    int* this_origin =
+        bVertical ? &pGlyphAndPos[i].m_OriginY : &pGlyphAndPos[i].m_OriginX;
+    FX_FLOAT this_origin_f =
+        bVertical ? pGlyphAndPos[i].m_fOriginY : pGlyphAndPos[i].m_fOriginX;
+    int space = (*next_origin) - (*this_origin);
+    FX_FLOAT space_f = next_origin_f - this_origin_f;
+    FX_FLOAT error =
+        (FX_FLOAT)(FXSYS_fabs(space_f) - FXSYS_fabs((FX_FLOAT)(space)));
+    if (error > 0.5f) {
+      *this_origin += space > 0 ? -1 : 1;
+    }
+    next_origin = this_origin;
+    next_origin_f = this_origin_f;
+  }
+}
+static 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,
+};
+#define ADJUST_ALPHA(background, foreground, src_alpha, text_flags, a) \
+  src_alpha = g_TextGammaAdjust[(uint8_t)src_alpha];
+void _Color2Argb(FX_ARGB& argb,
+                 FX_DWORD color,
+                 int alpha_flag,
+                 void* pIccTransform) {
+  if (pIccTransform == NULL && !FXGETFLAG_COLORTYPE(alpha_flag)) {
+    argb = color;
+    return;
+  }
+  if (!CFX_GEModule::Get()->GetCodecModule() ||
+      !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
+    pIccTransform = NULL;
+  }
+  uint8_t bgra[4];
+  if (pIccTransform) {
+    ICodec_IccModule* pIccModule =
+        CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
+    color = FXGETFLAG_COLORTYPE(alpha_flag) ? FXCMYK_TODIB(color)
+                                            : FXARGB_TODIB(color);
+    pIccModule->TranslateScanline(pIccTransform, bgra, (const uint8_t*)&color,
+                                  1);
+    bgra[3] = FXGETFLAG_COLORTYPE(alpha_flag)
+                  ? (alpha_flag >> 24) ? FXGETFLAG_ALPHA_FILL(alpha_flag)
+                                       : FXGETFLAG_ALPHA_STROKE(alpha_flag)
+                  : FXARGB_A(color);
+    argb = FXARGB_MAKE(bgra[3], bgra[2], bgra[1], bgra[0]);
+    return;
+  }
+  AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
+                     FXSYS_GetYValue(color), FXSYS_GetKValue(color), bgra[2],
+                     bgra[1], bgra[0]);
+  bgra[3] = (alpha_flag >> 24) ? FXGETFLAG_ALPHA_FILL(alpha_flag)
+                               : FXGETFLAG_ALPHA_STROKE(alpha_flag);
+  argb = FXARGB_MAKE(bgra[3], bgra[2], bgra[1], bgra[0]);
+}
+FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars,
+                                         const FXTEXT_CHARPOS* pCharPos,
+                                         CFX_Font* pFont,
+                                         CFX_FontCache* pCache,
+                                         FX_FLOAT font_size,
+                                         const CFX_AffineMatrix* pText2Device,
+                                         FX_DWORD fill_color,
+                                         FX_DWORD text_flags,
+                                         int alpha_flag,
+                                         void* pIccTransform) {
+  int nativetext_flags = text_flags;
+  if (m_DeviceClass != FXDC_DISPLAY) {
+    if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) {
+      bool should_call_draw_device_text = true;
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+      if ((text_flags & FXFONT_CIDFONT) ||
+          (pFont->GetPsName().Find(CFX_WideString::FromLocal("+ZJHL")) != -1) ||
+          (pFont->GetPsName() == CFX_WideString::FromLocal("CNAAJI+cmex10"))) {
+        should_call_draw_device_text = false;
+      }
+#endif
+      if (should_call_draw_device_text &&
+          m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache,
+                                          pText2Device, font_size, fill_color,
+                                          alpha_flag, pIccTransform)) {
+        return TRUE;
+      }
+    }
+    int alpha = FXGETFLAG_COLORTYPE(alpha_flag)
+                    ? FXGETFLAG_ALPHA_FILL(alpha_flag)
+                    : FXARGB_A(fill_color);
+    if (alpha < 255) {
+      return FALSE;
+    }
+  } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) {
+    bool should_call_draw_device_text = true;
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+    if ((text_flags & FXFONT_CIDFONT) ||
+        (pFont->GetPsName() == CFX_WideString::FromLocal("CNAAJI+cmex10"))) {
+      should_call_draw_device_text = false;
+    }
+#endif
+    if (should_call_draw_device_text &&
+        m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache,
+                                        pText2Device, font_size, fill_color,
+                                        alpha_flag, pIccTransform)) {
+      return TRUE;
+    }
+  }
+  CFX_AffineMatrix char2device, deviceCtm, 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 && !m_pDeviceDriver->IsPSPrintDriver()) &&
+       !(text_flags & FXTEXT_PRINTIMAGETEXT))) {
+    if (pFont->GetFace() != NULL ||
+        (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) {
+      int nPathFlags =
+          (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH;
+      return DrawTextPath(nChars, pCharPos, pFont, pCache, font_size,
+                          pText2Device, NULL, NULL, fill_color, 0, NULL,
+                          nPathFlags, alpha_flag, pIccTransform);
+    }
+  }
+  int anti_alias = FXFT_RENDER_MODE_MONO;
+  FX_BOOL bNormal = FALSE;
+  if ((text_flags & FXTEXT_NOSMOOTH) == 0) {
+    if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) {
+      FX_BOOL bClearType;
+      if (pFont->GetFace() == NULL &&
+          !(pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_CLEARTYPE)) {
+        bClearType = FALSE;
+      } else {
+        bClearType = text_flags & FXTEXT_CLEARTYPE;
+      }
+      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 {
+        if (bClearType == FALSE) {
+          anti_alias = FXFT_RENDER_MODE_LCD;
+          bNormal = TRUE;
+        } else {
+          anti_alias = FXFT_RENDER_MODE_LCD;
+        }
+      }
+    }
+  }
+  if (pCache == NULL) {
+    pCache = CFX_GEModule::Get()->GetFontCache();
+  }
+  CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont);
+  FX_FONTCACHE_DEFINE(pCache, pFont);
+  FXTEXT_GLYPHPOS* pGlyphAndPos = FX_Alloc(FXTEXT_GLYPHPOS, nChars);
+  int iChar;
+  deviceCtm = char2device;
+  CFX_AffineMatrix matrixCTM = GetCTM();
+  FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a);
+  FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d);
+  deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0);
+  text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0);
+  for (iChar = 0; iChar < nChars; iChar++) {
+    FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar];
+    const FXTEXT_CHARPOS& charpos = pCharPos[iChar];
+    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_AffineMatrix 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 && nChars > 1) {
+    _AdjustGlyphSpace(pGlyphAndPos, nChars);
+  }
+  FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(pGlyphAndPos, nChars, 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()) {
+    FX_Free(pGlyphAndPos);
+    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)) {
+      FX_Free(pGlyphAndPos);
+      return FALSE;
+    }
+    bitmap.Clear(0);
+    for (iChar = 0; iChar < nChars; iChar++) {
+      FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar];
+      if (glyph.m_pGlyph == NULL) {
+        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);
+    }
+    FX_Free(pGlyphAndPos);
+    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)) {
+      FX_Free(pGlyphAndPos);
+      return FALSE;
+    }
+  } else {
+    if (!CreateCompatibleBitmap(&bitmap, pixel_width, pixel_height)) {
+      FX_Free(pGlyphAndPos);
+      return FALSE;
+    }
+  }
+  if (!bitmap.HasAlpha() && !bitmap.IsAlphaMask()) {
+    bitmap.Clear(0xFFFFFFFF);
+    if (!GetDIBits(&bitmap, bmp_rect.left, bmp_rect.top)) {
+      FX_Free(pGlyphAndPos);
+      return FALSE;
+    }
+  } else {
+    bitmap.Clear(0);
+    if (bitmap.m_pAlphaMask) {
+      bitmap.m_pAlphaMask->Clear(0);
+    }
+  }
+  int dest_width = pixel_width;
+  uint8_t* dest_buf = bitmap.GetBuffer();
+  int dest_pitch = bitmap.GetPitch();
+  int Bpp = bitmap.GetBPP() / 8;
+  int a, r, g, b;
+  if (anti_alias == FXFT_RENDER_MODE_LCD) {
+    _Color2Argb(fill_color, fill_color, alpha_flag | (1 << 24), pIccTransform);
+    ArgbDecode(fill_color, a, r, g, b);
+    r = FX_GAMMA(r);
+    g = FX_GAMMA(g);
+    b = FX_GAMMA(b);
+  }
+  for (iChar = 0; iChar < nChars; iChar++) {
+    FXTEXT_GLYPHPOS& glyph = pGlyphAndPos[iChar];
+    if (glyph.m_pGlyph == NULL) {
+      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, NULL, FALSE, alpha_flag,
+                                pIccTransform)) {
+        FX_Free(pGlyphAndPos);
+        return FALSE;
+      }
+      continue;
+    }
+    FX_BOOL bBGRStripe = text_flags & FXTEXT_BGR_STRIPE;
+    ncols /= 3;
+    int x_subpixel = (int)(glyph.m_fOriginX * 3) % 3;
+    uint8_t* src_buf = pGlyph->GetBuffer();
+    int src_pitch = pGlyph->GetPitch();
+    int start_col = left;
+    if (start_col < 0) {
+      start_col = 0;
+    }
+    int end_col = left + ncols;
+    if (end_col > dest_width) {
+      end_col = dest_width;
+    }
+    if (start_col >= end_col) {
+      continue;
+    }
+    if (bitmap.GetFormat() == FXDIB_Argb) {
+      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 << 2);
+        if (bBGRStripe) {
+          if (x_subpixel == 0) {
+            for (int col = start_col; col < end_col; col++) {
+              int src_alpha = src_scan[2];
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[1];
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[0];
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan[3] = 255;
+              dest_scan += 4;
+              src_scan += 3;
+            }
+          } else if (x_subpixel == 1) {
+            int src_alpha = src_scan[1];
+            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+            src_alpha = src_alpha * a / 255;
+            dest_scan[2] = FX_GAMMA_INVERSE(
+                FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+            src_alpha = src_scan[0];
+            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+            src_alpha = src_alpha * a / 255;
+            dest_scan[1] = FX_GAMMA_INVERSE(
+                FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+            if (start_col > left) {
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+            }
+            dest_scan[3] = 255;
+            dest_scan += 4;
+            src_scan += 3;
+            for (int col = start_col + 1; col < end_col - 1; col++) {
+              int src_alpha = src_scan[1];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan[3] = 255;
+              dest_scan += 4;
+              src_scan += 3;
+            }
+          } else {
+            int src_alpha = src_scan[0];
+            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+            src_alpha = src_alpha * a / 255;
+            dest_scan[2] = FX_GAMMA_INVERSE(
+                FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+            if (start_col > left) {
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[-2];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+            }
+            dest_scan[3] = 255;
+            dest_scan += 4;
+            src_scan += 3;
+            for (int col = start_col + 1; col < end_col - 1; col++) {
+              int src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[-2];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan[3] = 255;
+              dest_scan += 4;
+              src_scan += 3;
+            }
+          }
+        } else {
+          if (x_subpixel == 0) {
+            for (int col = start_col; col < end_col; col++) {
+              if (bNormal) {
+                int src_alpha1 = (src_scan[0] + src_scan[1] + src_scan[2]) / 3;
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+                src_alpha1 = src_alpha1 * a / 255;
+                uint8_t back_alpha = dest_scan[3];
+                if (back_alpha == 0) {
+                  FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));
+                  dest_scan += 4;
+                  src_scan += 3;
+                  continue;
+                }
+                if (src_alpha1 == 0) {
+                  dest_scan += 4;
+                  src_scan += 3;
+                  continue;
+                }
+                uint8_t dest_alpha =
+                    back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;
+                dest_scan[3] = dest_alpha;
+                int alpha_ratio = src_alpha1 * 255 / dest_alpha;
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, alpha_ratio));
+                dest_scan[1] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, alpha_ratio));
+                dest_scan[0] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, alpha_ratio));
+                dest_scan += 4;
+                src_scan += 3;
+                continue;
+              }
+              int src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[1];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[2];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan[3] = 255;
+              dest_scan += 4;
+              src_scan += 3;
+            }
+          } else if (x_subpixel == 1) {
+            if (bNormal) {
+              int src_alpha1 =
+                  start_col > left
+                      ? ((src_scan[-1] + src_scan[0] + src_scan[1]) / 3)
+                      : ((src_scan[0] + src_scan[1]) / 3);
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+              src_alpha1 = src_alpha1 * a / 255;
+              if (src_alpha1 == 0) {
+                dest_scan += 4;
+                src_scan += 3;
+              } else {
+                uint8_t back_alpha = dest_scan[3];
+                if (back_alpha == 0) {
+                  FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));
+                } else {
+                  uint8_t dest_alpha =
+                      back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;
+                  dest_scan[3] = dest_alpha;
+                  int alpha_ratio = src_alpha1 * 255 / dest_alpha;
+                  dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(
+                      FX_GAMMA(dest_scan[2]), r, alpha_ratio));
+                  dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(
+                      FX_GAMMA(dest_scan[1]), g, alpha_ratio));
+                  dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(
+                      FX_GAMMA(dest_scan[0]), b, alpha_ratio));
+                }
+                dest_scan += 4;
+                src_scan += 3;
+              }
+            } else {
+              if (start_col > left) {
+                int src_alpha = src_scan[-1];
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+                src_alpha = src_alpha * a / 255;
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              }
+              int src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[1];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan[3] = 255;
+              dest_scan += 4;
+              src_scan += 3;
+            }
+            for (int col = start_col + 1; col < end_col; col++) {
+              if (bNormal) {
+                int src_alpha1 = (src_scan[-1] + src_scan[0] + src_scan[1]) / 3;
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+                src_alpha1 = src_alpha1 * a / 255;
+                uint8_t back_alpha = dest_scan[3];
+                if (back_alpha == 0) {
+                  FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));
+                  dest_scan += 4;
+                  src_scan += 3;
+                  continue;
+                }
+                if (src_alpha1 == 0) {
+                  dest_scan += 4;
+                  src_scan += 3;
+                  continue;
+                }
+                uint8_t dest_alpha =
+                    back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;
+                dest_scan[3] = dest_alpha;
+                int alpha_ratio = src_alpha1 * 255 / dest_alpha;
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, alpha_ratio));
+                dest_scan[1] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, alpha_ratio));
+                dest_scan[0] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, alpha_ratio));
+                dest_scan += 4;
+                src_scan += 3;
+                continue;
+              }
+              int src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[1];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan[3] = 255;
+              dest_scan += 4;
+              src_scan += 3;
+            }
+          } else {
+            if (bNormal) {
+              int src_alpha1 =
+                  start_col > left
+                      ? ((src_scan[-2] + src_scan[-1] + src_scan[0]) / 3)
+                      : ((src_scan[0]) / 3);
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+              src_alpha1 = src_alpha1 * a / 255;
+              if (src_alpha1 == 0) {
+                dest_scan += 4;
+                src_scan += 3;
+              } else {
+                uint8_t back_alpha = dest_scan[3];
+                if (back_alpha == 0) {
+                  FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));
+                } else {
+                  uint8_t dest_alpha =
+                      back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;
+                  dest_scan[3] = dest_alpha;
+                  int alpha_ratio = src_alpha1 * 255 / dest_alpha;
+                  dest_scan[2] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(
+                      FX_GAMMA(dest_scan[2]), r, alpha_ratio));
+                  dest_scan[1] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(
+                      FX_GAMMA(dest_scan[1]), g, alpha_ratio));
+                  dest_scan[0] = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(
+                      FX_GAMMA(dest_scan[0]), b, alpha_ratio));
+                }
+                dest_scan += 4;
+                src_scan += 3;
+              }
+            } else {
+              if (start_col > left) {
+                int src_alpha = src_scan[-2];
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+                src_alpha = src_alpha * a / 255;
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+                src_alpha = src_scan[-1];
+                ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+                src_alpha = src_alpha * a / 255;
+                dest_scan[1] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              }
+              int src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan[3] = 255;
+              dest_scan += 4;
+              src_scan += 3;
+            }
+            for (int col = start_col + 1; col < end_col; col++) {
+              if (bNormal) {
+                int src_alpha1 =
+                    (src_scan[-2] + src_scan[-1] + src_scan[0]) / 3;
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+                src_alpha1 = src_alpha1 * a / 255;
+                uint8_t back_alpha = dest_scan[3];
+                if (back_alpha == 0) {
+                  FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_alpha1, r, g, b));
+                  dest_scan += 4;
+                  src_scan += 3;
+                  continue;
+                }
+                if (src_alpha1 == 0) {
+                  dest_scan += 4;
+                  src_scan += 3;
+                  continue;
+                }
+                uint8_t dest_alpha =
+                    back_alpha + src_alpha1 - back_alpha * src_alpha1 / 255;
+                dest_scan[3] = dest_alpha;
+                int alpha_ratio = src_alpha1 * 255 / dest_alpha;
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, alpha_ratio));
+                dest_scan[1] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, alpha_ratio));
+                dest_scan[0] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, alpha_ratio));
+                dest_scan += 4;
+                src_scan += 3;
+                continue;
+              }
+              int src_alpha = src_scan[-2];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan[3] = 255;
+              dest_scan += 4;
+              src_scan += 3;
+            }
+          }
+        }
+      }
+    } else {
+      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++) {
+              int src_alpha = src_scan[2];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[1];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan += Bpp;
+              src_scan += 3;
+            }
+          } else if (x_subpixel == 1) {
+            int src_alpha = src_scan[1];
+            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+            src_alpha = src_alpha * a / 255;
+            dest_scan[2] = FX_GAMMA_INVERSE(
+                FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+            src_alpha = src_scan[0];
+            ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+            src_alpha = src_alpha * a / 255;
+            dest_scan[1] = FX_GAMMA_INVERSE(
+                FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+            if (start_col > left) {
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+            }
+            dest_scan += Bpp;
+            src_scan += 3;
+            for (int col = start_col + 1; col < end_col - 1; col++) {
+              int src_alpha = src_scan[1];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan += Bpp;
+              src_scan += 3;
+            }
+          } else {
+            int src_alpha = src_scan[0];
+            ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+            src_alpha = src_alpha * a / 255;
+            dest_scan[2] = FX_GAMMA_INVERSE(
+                FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+            if (start_col > left) {
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[-2];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+            }
+            dest_scan += Bpp;
+            src_scan += 3;
+            for (int col = start_col + 1; col < end_col - 1; col++) {
+              int src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[-2];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan += Bpp;
+              src_scan += 3;
+            }
+          }
+        } else {
+          if (x_subpixel == 0) {
+            for (int col = start_col; col < end_col; col++) {
+              if (bNormal) {
+                int src_alpha1 = (src_scan[0] + src_scan[1] + src_scan[2]) / 3;
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+                src_alpha1 = src_alpha1 * a / 255;
+                if (src_alpha1 == 0) {
+                  dest_scan += Bpp;
+                  src_scan += 3;
+                  continue;
+                }
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));
+                dest_scan[1] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));
+                dest_scan[0] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));
+                dest_scan += Bpp;
+                src_scan += 3;
+                continue;
+              }
+              int src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[1];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[2];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan += Bpp;
+              src_scan += 3;
+            }
+          } else if (x_subpixel == 1) {
+            if (bNormal) {
+              int src_alpha1 =
+                  start_col > left
+                      ? (src_scan[0] + src_scan[1] + src_scan[-1]) / 3
+                      : (src_scan[0] + src_scan[1]) / 3;
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+              src_alpha1 = src_alpha1 * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));
+              dest_scan += Bpp;
+              src_scan += 3;
+            } else {
+              if (start_col > left) {
+                int src_alpha = src_scan[-1];
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+                src_alpha = src_alpha * a / 255;
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              }
+              int src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[1];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan += Bpp;
+              src_scan += 3;
+            }
+            for (int col = start_col + 1; col < end_col; col++) {
+              if (bNormal) {
+                int src_alpha1 = (src_scan[0] + src_scan[1] + src_scan[-1]) / 3;
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+                src_alpha1 = src_alpha1 * a / 255;
+                if (src_alpha1 == 0) {
+                  dest_scan += Bpp;
+                  src_scan += 3;
+                  continue;
+                }
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));
+                dest_scan[1] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));
+                dest_scan[0] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));
+                dest_scan += Bpp;
+                src_scan += 3;
+                continue;
+              }
+              int src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[1];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan += Bpp;
+              src_scan += 3;
+            }
+          } else {
+            if (bNormal) {
+              int src_alpha1 =
+                  start_col > left
+                      ? (src_scan[0] + src_scan[-2] + src_scan[-1]) / 3
+                      : src_scan[0] / 3;
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+              src_alpha1 = src_alpha1 * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));
+              dest_scan += Bpp;
+              src_scan += 3;
+            } else {
+              if (start_col > left) {
+                int src_alpha = src_scan[-2];
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+                src_alpha = src_alpha * a / 255;
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+                src_alpha = src_scan[-1];
+                ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+                src_alpha = src_alpha * a / 255;
+                dest_scan[1] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              }
+              int src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan += Bpp;
+              src_scan += 3;
+            }
+            for (int col = start_col + 1; col < end_col; col++) {
+              if (bNormal) {
+                int src_alpha1 = ((int)(src_scan[0]) + (int)(src_scan[-2]) +
+                                  (int)(src_scan[-1])) /
+                                 3;
+                ADJUST_ALPHA(dest_scan[2], r, src_alpha1, nativetext_flags, a);
+                src_alpha1 = src_alpha1 * a / 255;
+                if (src_alpha1 == 0) {
+                  dest_scan += Bpp;
+                  src_scan += 3;
+                  continue;
+                }
+                dest_scan[2] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha1));
+                dest_scan[1] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha1));
+                dest_scan[0] = FX_GAMMA_INVERSE(
+                    FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha1));
+                dest_scan += Bpp;
+                src_scan += 3;
+                continue;
+              }
+              int src_alpha = src_scan[-2];
+              ADJUST_ALPHA(dest_scan[2], r, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[2] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[2]), r, src_alpha));
+              src_alpha = src_scan[-1];
+              ADJUST_ALPHA(dest_scan[1], g, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[1] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[1]), g, src_alpha));
+              src_alpha = src_scan[0];
+              ADJUST_ALPHA(dest_scan[0], b, src_alpha, nativetext_flags, a);
+              src_alpha = src_alpha * a / 255;
+              dest_scan[0] = FX_GAMMA_INVERSE(
+                  FXDIB_ALPHA_MERGE(FX_GAMMA(dest_scan[0]), b, src_alpha));
+              dest_scan += Bpp;
+              src_scan += 3;
+            }
+          }
+        }
+      }
+    }
+  }
+  if (bitmap.IsAlphaMask()) {
+    SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color, alpha_flag,
+               pIccTransform);
+  } else {
+    SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top);
+  }
+  FX_Free(pGlyphAndPos);
+  return TRUE;
+}
+FX_BOOL CFX_RenderDevice::DrawTextPath(int nChars,
+                                       const FXTEXT_CHARPOS* pCharPos,
+                                       CFX_Font* pFont,
+                                       CFX_FontCache* pCache,
+                                       FX_FLOAT font_size,
+                                       const CFX_AffineMatrix* pText2User,
+                                       const CFX_AffineMatrix* pUser2Device,
+                                       const CFX_GraphStateData* pGraphState,
+                                       FX_DWORD fill_color,
+                                       FX_ARGB stroke_color,
+                                       CFX_PathData* pClippingPath,
+                                       int nFlag,
+                                       int alpha_flag,
+                                       void* pIccTransform,
+                                       int blend_type) {
+  if (pCache == NULL) {
+    pCache = CFX_GEModule::Get()->GetFontCache();
+  }
+  CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont);
+  FX_FONTCACHE_DEFINE(pCache, pFont);
+  for (int iChar = 0; iChar < nChars; iChar++) {
+    const FXTEXT_CHARPOS& charpos = pCharPos[iChar];
+    CFX_AffineMatrix 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 == NULL) {
+      continue;
+    }
+    matrix.Concat(*pText2User);
+    CFX_PathData TransformedPath(*pPath);
+    TransformedPath.Transform(&matrix);
+    FX_BOOL bHasAlpha = FXGETFLAG_COLORTYPE(alpha_flag)
+                            ? (FXGETFLAG_ALPHA_FILL(alpha_flag) ||
+                               FXGETFLAG_ALPHA_STROKE(alpha_flag))
+                            : (fill_color || stroke_color);
+    if (bHasAlpha) {
+      int fill_mode = nFlag;
+      if (FXGETFLAG_COLORTYPE(alpha_flag)) {
+        if (FXGETFLAG_ALPHA_FILL(alpha_flag)) {
+          fill_mode |= FXFILL_WINDING;
+        }
+      } else {
+        if (fill_color) {
+          fill_mode |= FXFILL_WINDING;
+        }
+      }
+      fill_mode |= FX_FILL_TEXT_MODE;
+      if (!DrawPath(&TransformedPath, pUser2Device, pGraphState, fill_color,
+                    stroke_color, fill_mode, alpha_flag, pIccTransform,
+                    blend_type)) {
+        return FALSE;
+      }
+    }
+    if (pClippingPath) {
+      pClippingPath->Append(&TransformedPath, pUser2Device);
+    }
+  }
+  return TRUE;
+}
+CFX_FontCache::~CFX_FontCache() {
+  FreeCache(TRUE);
+}
+
+CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) {
+  FXFT_Face internal_face = pFont->GetFace();
+  const FX_BOOL bExternal = internal_face == nullptr;
+  FXFT_Face face =
+      bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face;
+  CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
+  auto it = map.find(face);
+  if (it != map.end()) {
+    CFX_CountedFaceCache* counted_face_cache = it->second;
+    counted_face_cache->m_nCount++;
+    return counted_face_cache->m_Obj;
+  }
+
+  CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
+  CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache;
+  counted_face_cache->m_nCount = 2;
+  counted_face_cache->m_Obj = face_cache;
+  map[face] = counted_face_cache;
+  return face_cache;
+}
+
+void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) {
+  FXFT_Face internal_face = pFont->GetFace();
+  const FX_BOOL bExternal = internal_face == nullptr;
+  FXFT_Face face =
+      bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face;
+  CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
+
+  auto it = map.find(face);
+  if (it == map.end())
+    return;
+
+  CFX_CountedFaceCache* counted_face_cache = it->second;
+  if (counted_face_cache->m_nCount > 1) {
+    counted_face_cache->m_nCount--;
+  }
+}
+
+void CFX_FontCache::FreeCache(FX_BOOL bRelease) {
+  for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) {
+    auto curr_it = it++;
+    CFX_CountedFaceCache* cache = curr_it->second;
+    if (bRelease || cache->m_nCount < 2) {
+      delete cache->m_Obj;
+      delete cache;
+      m_FTFaceMap.erase(curr_it);
+    }
+  }
+
+  for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) {
+    auto curr_it = it++;
+    CFX_CountedFaceCache* cache = curr_it->second;
+    if (bRelease || cache->m_nCount < 2) {
+      delete cache->m_Obj;
+      delete cache;
+      m_ExtFaceMap.erase(curr_it);
+    }
+  }
+}
+
+CFX_FaceCache::CFX_FaceCache(FXFT_Face face) {
+  m_Face = face;
+}
+CFX_FaceCache::~CFX_FaceCache() {
+  for (const auto& pair : m_SizeMap) {
+    delete pair.second;
+  }
+  m_SizeMap.clear();
+  FX_POSITION pos = m_PathMap.GetStartPosition();
+  void* key1;
+  CFX_PathData* pPath;
+  while (pos) {
+    m_PathMap.GetNextAssoc(pos, key1, (void*&)pPath);
+    delete pPath;
+  }
+  m_PathMap.RemoveAll();
+}
+#if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
+void CFX_FaceCache::InitPlatform() {}
+#endif
+CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap(
+    CFX_Font* pFont,
+    const CFX_AffineMatrix* pMatrix,
+    CFX_ByteStringC& FaceGlyphsKey,
+    FX_DWORD glyph_index,
+    FX_BOOL bFontStyle,
+    int dest_width,
+    int anti_alias) {
+  CFX_SizeGlyphCache* pSizeCache;
+  auto it = m_SizeMap.find(FaceGlyphsKey);
+  if (it == m_SizeMap.end()) {
+    pSizeCache = new CFX_SizeGlyphCache;
+    m_SizeMap[FaceGlyphsKey] = pSizeCache;
+  } else {
+    pSizeCache = it->second;
+  }
+  CFX_GlyphBitmap* pGlyphBitmap = NULL;
+  if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index,
+                                    (void*&)pGlyphBitmap)) {
+    return pGlyphBitmap;
+  }
+  pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, pMatrix,
+                             dest_width, anti_alias);
+  if (pGlyphBitmap == NULL) {
+    return NULL;
+  }
+  pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap);
+  return pGlyphBitmap;
+}
+const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(
+    CFX_Font* pFont,
+    FX_DWORD glyph_index,
+    FX_BOOL bFontStyle,
+    const CFX_AffineMatrix* pMatrix,
+    int dest_width,
+    int anti_alias,
+    int& text_flags) {
+  if (glyph_index == (FX_DWORD)-1) {
+    return NULL;
+  }
+  _CFX_UniqueKeyGen keygen;
+#if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
+  if (pFont->GetSubstFont())
+    keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
+                    (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
+                    dest_width, anti_alias, pFont->GetSubstFont()->m_Weight,
+                    pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical());
+  else
+    keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
+                    (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
+                    dest_width, anti_alias);
+#else
+  if (text_flags & FXTEXT_NO_NATIVETEXT) {
+    if (pFont->GetSubstFont())
+      keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
+                      (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
+                      dest_width, anti_alias, pFont->GetSubstFont()->m_Weight,
+                      pFont->GetSubstFont()->m_ItalicAngle,
+                      pFont->IsVertical());
+    else
+      keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
+                      (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
+                      dest_width, anti_alias);
+  } else {
+    if (pFont->GetSubstFont())
+      keygen.Generate(10, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
+                      (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
+                      dest_width, anti_alias, pFont->GetSubstFont()->m_Weight,
+                      pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical(),
+                      3);
+    else
+      keygen.Generate(7, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
+                      (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
+                      dest_width, anti_alias, 3);
+  }
+#endif
+  CFX_ByteStringC FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen);
+#if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
+  return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey, glyph_index,
+                           bFontStyle, dest_width, anti_alias);
+#else
+  if (text_flags & FXTEXT_NO_NATIVETEXT) {
+    return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey, glyph_index,
+                             bFontStyle, dest_width, anti_alias);
+  }
+  CFX_GlyphBitmap* pGlyphBitmap;
+  auto it = m_SizeMap.find(FaceGlyphsKey);
+  if (it != m_SizeMap.end()) {
+    CFX_SizeGlyphCache* pSizeCache = it->second;
+    if (pSizeCache->m_GlyphMap.Lookup((void*)(uintptr_t)glyph_index,
+                                      (void*&)pGlyphBitmap)) {
+      return pGlyphBitmap;
+    }
+    pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix,
+                                          dest_width, anti_alias);
+    if (pGlyphBitmap) {
+      pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap);
+      return pGlyphBitmap;
+    }
+  } else {
+    pGlyphBitmap = RenderGlyph_Nativetext(pFont, glyph_index, pMatrix,
+                                          dest_width, anti_alias);
+    if (pGlyphBitmap) {
+      CFX_SizeGlyphCache* pSizeCache = new CFX_SizeGlyphCache;
+      m_SizeMap[FaceGlyphsKey] = pSizeCache;
+      pSizeCache->m_GlyphMap.SetAt((void*)(uintptr_t)glyph_index, pGlyphBitmap);
+      return pGlyphBitmap;
+    }
+  }
+  if (pFont->GetSubstFont())
+    keygen.Generate(9, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
+                    (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
+                    dest_width, anti_alias, pFont->GetSubstFont()->m_Weight,
+                    pFont->GetSubstFont()->m_ItalicAngle, pFont->IsVertical());
+  else
+    keygen.Generate(6, (int)(pMatrix->a * 10000), (int)(pMatrix->b * 10000),
+                    (int)(pMatrix->c * 10000), (int)(pMatrix->d * 10000),
+                    dest_width, anti_alias);
+  CFX_ByteStringC FaceGlyphsKey2(keygen.m_Key, keygen.m_KeyLen);
+  text_flags |= FXTEXT_NO_NATIVETEXT;
+  return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey2, glyph_index,
+                           bFontStyle, dest_width, anti_alias);
+#endif
+}
+CFX_SizeGlyphCache::~CFX_SizeGlyphCache() {
+  FX_POSITION pos = m_GlyphMap.GetStartPosition();
+  void* Key;
+  CFX_GlyphBitmap* pGlyphBitmap = NULL;
+  while (pos) {
+    m_GlyphMap.GetNextAssoc(pos, Key, (void*&)pGlyphBitmap);
+    delete pGlyphBitmap;
+  }
+  m_GlyphMap.RemoveAll();
+}
+#define CONTRAST_RAMP_STEP 1
+void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) {
+  FXFT_MM_Var pMasters = NULL;
+  FXFT_Get_MM_Var(m_Face, &pMasters);
+  if (pMasters == NULL) {
+    return;
+  }
+  long coords[2];
+  if (weight == 0) {
+    coords[0] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 0)) / 65536;
+  } else {
+    coords[0] = weight;
+  }
+  if (dest_width == 0) {
+    coords[1] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
+  } else {
+    int min_param = FXFT_Get_MM_Axis_Min(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
+    int max_param = FXFT_Get_MM_Axis_Max(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
+    coords[1] = min_param;
+    int error = FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
+    error = FXFT_Load_Glyph(
+        m_Face, glyph_index,
+        FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
+    int min_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 /
+                    FXFT_Get_Face_UnitsPerEM(m_Face);
+    coords[1] = max_param;
+    error = FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
+    error = FXFT_Load_Glyph(
+        m_Face, glyph_index,
+        FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
+    int max_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 /
+                    FXFT_Get_Face_UnitsPerEM(m_Face);
+    if (max_width == min_width) {
+      return;
+    }
+    int param = min_param +
+                (max_param - min_param) * (dest_width - min_width) /
+                    (max_width - min_width);
+    coords[1] = param;
+  }
+  FXFT_Free(m_Face, pMasters);
+  FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
+}
+static const size_t ANGLESKEW_ARRAY_SIZE = 30;
+static const char g_AngleSkew[ANGLESKEW_ARRAY_SIZE] = {
+    0,  2,  3,  5,  7,  9,  11, 12, 14, 16, 18, 19, 21, 23, 25,
+    27, 29, 31, 32, 34, 36, 38, 40, 42, 45, 47, 49, 51, 53, 55,
+};
+static const size_t WEIGHTPOW_ARRAY_SIZE = 100;
+static const uint8_t g_WeightPow[WEIGHTPOW_ARRAY_SIZE] = {
+    0,  3,  6,  7,  8,  9,  11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22,
+    23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 35, 36, 36, 37,
+    37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42,
+    42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47,
+    47, 47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 50,
+    51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53,
+};
+static const uint8_t g_WeightPow_11[WEIGHTPOW_ARRAY_SIZE] = {
+    0,  4,  7,  8,  9,  10, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 24,
+    25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 39, 40, 40, 41,
+    41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46,
+    46, 43, 47, 47, 48, 48, 48, 48, 45, 50, 50, 50, 46, 51, 51, 51, 52,
+    52, 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 55,
+    56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58,
+};
+static const uint8_t g_WeightPow_SHIFTJIS[WEIGHTPOW_ARRAY_SIZE] = {
+    0,  0,  1,  2,  3,  4,  5,  7,  8,  10, 11, 13, 14, 16, 17, 19, 21,
+    22, 24, 26, 28, 30, 32, 33, 35, 37, 39, 41, 43, 45, 48, 48, 48, 48,
+    49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53,
+    53, 53, 53, 53, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 56, 56, 56,
+    56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58,
+    59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60,
+};
+static void _GammaAdjust(uint8_t* pData,
+                         int nWid,
+                         int nHei,
+                         int src_pitch,
+                         const uint8_t* gammaTable) {
+  int count = nHei * src_pitch;
+  for (int i = 0; i < count; i++) {
+    pData[i] = gammaTable[pData[i]];
+  }
+}
+static void _ContrastAdjust(uint8_t* pDataIn,
+                            uint8_t* pDataOut,
+                            int nWid,
+                            int nHei,
+                            int nSrcRowBytes,
+                            int nDstRowBytes) {
+  int col, row, temp;
+  int max = 0, min = 255;
+  FX_FLOAT rate;
+  for (row = 0; row < nHei; row++) {
+    uint8_t* pRow = pDataIn + row * nSrcRowBytes;
+    for (col = 0; col < nWid; col++) {
+      temp = *pRow++;
+      if (temp > max) {
+        max = temp;
+      }
+      if (temp < min) {
+        min = temp;
+      }
+    }
+  }
+  temp = max - min;
+  if (0 == temp || 255 == temp) {
+    int rowbytes = FXSYS_abs(nSrcRowBytes) > nDstRowBytes
+                       ? nDstRowBytes
+                       : FXSYS_abs(nSrcRowBytes);
+    for (row = 0; row < nHei; row++) {
+      FXSYS_memcpy(pDataOut + row * nDstRowBytes, pDataIn + row * nSrcRowBytes,
+                   rowbytes);
+    }
+    return;
+  }
+  rate = 255.f / temp;
+  for (row = 0; row < nHei; row++) {
+    uint8_t* pSrcRow = pDataIn + row * nSrcRowBytes;
+    uint8_t* pDstRow = pDataOut + row * nDstRowBytes;
+    for (col = 0; col < nWid; col++) {
+      temp = (int)((*(pSrcRow++) - min) * rate + 0.5);
+      if (temp > 255) {
+        temp = 255;
+      } else if (temp < 0) {
+        temp = 0;
+      }
+      *pDstRow++ = (uint8_t)temp;
+    }
+  }
+}
+CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont,
+                                            FX_DWORD glyph_index,
+                                            FX_BOOL bFontStyle,
+                                            const CFX_AffineMatrix* pMatrix,
+                                            int dest_width,
+                                            int anti_alias) {
+  if (m_Face == NULL) {
+    return NULL;
+  }
+  FXFT_Matrix ft_matrix;
+  ft_matrix.xx = (signed long)(pMatrix->GetA() / 64 * 65536);
+  ft_matrix.xy = (signed long)(pMatrix->GetC() / 64 * 65536);
+  ft_matrix.yx = (signed long)(pMatrix->GetB() / 64 * 65536);
+  ft_matrix.yy = (signed long)(pMatrix->GetD() / 64 * 65536);
+  FX_BOOL bUseCJKSubFont = FALSE;
+  const CFX_SubstFont* pSubstFont = pFont->GetSubstFont();
+  if (pSubstFont) {
+    bUseCJKSubFont = pSubstFont->m_bSubstOfCJK && bFontStyle;
+    int skew = 0;
+    if (bUseCJKSubFont) {
+      skew = pSubstFont->m_bItlicCJK ? -15 : 0;
+    } else {
+      skew = pSubstFont->m_ItalicAngle;
+    }
+    if (skew) {
+      skew = skew <= -ANGLESKEW_ARRAY_SIZE ? -58 : -g_AngleSkew[-skew];
+      if (pFont->IsVertical()) {
+        ft_matrix.yx += ft_matrix.yy * skew / 100;
+      } else {
+        ft_matrix.xy += -ft_matrix.xx * skew / 100;
+      }
+    }
+    if (pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) {
+      pFont->AdjustMMParams(glyph_index, dest_width,
+                            pFont->GetSubstFont()->m_Weight);
+    }
+  }
+  ScopedFontTransform scoped_transform(m_Face, &ft_matrix);
+  int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT)
+                       ? FXFT_LOAD_NO_BITMAP
+                       : (FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING);
+  int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags);
+  if (error) {
+    // if an error is returned, try to reload glyphs without hinting.
+    if (load_flags & FT_LOAD_NO_HINTING || load_flags & FT_LOAD_NO_SCALE) {
+      return NULL;
+    }
+
+    load_flags |= FT_LOAD_NO_HINTING;
+    error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags);
+
+    if (error) {
+      return NULL;
+    }
+  }
+  int weight = 0;
+  if (bUseCJKSubFont) {
+    weight = pSubstFont->m_WeightCJK;
+  } else {
+    weight = pSubstFont ? pSubstFont->m_Weight : 0;
+  }
+  if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) &&
+      weight > 400) {
+    int index = (weight - 400) / 10;
+    if (index >= WEIGHTPOW_ARRAY_SIZE) {
+      return NULL;
+    }
+    int level = 0;
+    if (pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) {
+      level =
+          g_WeightPow_SHIFTJIS[index] * 2 *
+          (FXSYS_abs((int)(ft_matrix.xx)) + FXSYS_abs((int)(ft_matrix.xy))) /
+          36655;
+    } else {
+      level = g_WeightPow_11[index] * (FXSYS_abs((int)(ft_matrix.xx)) +
+                                       FXSYS_abs((int)(ft_matrix.xy))) /
+              36655;
+    }
+    FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);
+  }
+  FXFT_Library_SetLcdFilter(CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary,
+                            FT_LCD_FILTER_DEFAULT);
+  error = FXFT_Render_Glyph(m_Face, anti_alias);
+  if (error) {
+    return NULL;
+  }
+  int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(m_Face));
+  int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(m_Face));
+  if (bmwidth > 2048 || bmheight > 2048) {
+    return NULL;
+  }
+  int dib_width = bmwidth;
+  CFX_GlyphBitmap* pGlyphBitmap = new CFX_GlyphBitmap;
+  pGlyphBitmap->m_Bitmap.Create(
+      dib_width, bmheight,
+      anti_alias == FXFT_RENDER_MODE_MONO ? FXDIB_1bppMask : FXDIB_8bppMask);
+  pGlyphBitmap->m_Left = FXFT_Get_Glyph_BitmapLeft(m_Face);
+  pGlyphBitmap->m_Top = FXFT_Get_Glyph_BitmapTop(m_Face);
+  int dest_pitch = pGlyphBitmap->m_Bitmap.GetPitch();
+  int src_pitch = FXFT_Get_Bitmap_Pitch(FXFT_Get_Glyph_Bitmap(m_Face));
+  uint8_t* pDestBuf = pGlyphBitmap->m_Bitmap.GetBuffer();
+  uint8_t* pSrcBuf =
+      (uint8_t*)FXFT_Get_Bitmap_Buffer(FXFT_Get_Glyph_Bitmap(m_Face));
+  if (anti_alias != FXFT_RENDER_MODE_MONO &&
+      FXFT_Get_Bitmap_PixelMode(FXFT_Get_Glyph_Bitmap(m_Face)) ==
+          FXFT_PIXEL_MODE_MONO) {
+    int bytes = anti_alias == FXFT_RENDER_MODE_LCD ? 3 : 1;
+    for (int i = 0; i < bmheight; i++)
+      for (int n = 0; n < bmwidth; n++) {
+        uint8_t data =
+            (pSrcBuf[i * src_pitch + n / 8] & (0x80 >> (n % 8))) ? 255 : 0;
+        for (int b = 0; b < bytes; b++) {
+          pDestBuf[i * dest_pitch + n * bytes + b] = data;
+        }
+      }
+  } else {
+    FXSYS_memset(pDestBuf, 0, dest_pitch * bmheight);
+    if (anti_alias == FXFT_RENDER_MODE_MONO &&
+        FXFT_Get_Bitmap_PixelMode(FXFT_Get_Glyph_Bitmap(m_Face)) ==
+            FXFT_PIXEL_MODE_MONO) {
+      int rowbytes =
+          FXSYS_abs(src_pitch) > dest_pitch ? dest_pitch : FXSYS_abs(src_pitch);
+      for (int row = 0; row < bmheight; row++) {
+        FXSYS_memcpy(pDestBuf + row * dest_pitch, pSrcBuf + row * src_pitch,
+                     rowbytes);
+      }
+    } else {
+      _ContrastAdjust(pSrcBuf, pDestBuf, bmwidth, bmheight, src_pitch,
+                      dest_pitch);
+      _GammaAdjust(pDestBuf, bmwidth, bmheight, dest_pitch,
+                   CFX_GEModule::Get()->GetTextGammaTable());
+    }
+  }
+  return pGlyphBitmap;
+}
+const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont,
+                                                 FX_DWORD glyph_index,
+                                                 int dest_width) {
+  if (m_Face == NULL || glyph_index == (FX_DWORD)-1) {
+    return NULL;
+  }
+  CFX_PathData* pGlyphPath = NULL;
+  void* key;
+  if (pFont->GetSubstFont())
+    key = (void*)(uintptr_t)(
+        glyph_index + ((pFont->GetSubstFont()->m_Weight / 16) << 15) +
+        ((pFont->GetSubstFont()->m_ItalicAngle / 2) << 21) +
+        ((dest_width / 16) << 25) + (pFont->IsVertical() << 31));
+  else {
+    key = (void*)(uintptr_t)glyph_index;
+  }
+  if (m_PathMap.Lookup(key, (void*&)pGlyphPath)) {
+    return pGlyphPath;
+  }
+  pGlyphPath = pFont->LoadGlyphPath(glyph_index, dest_width);
+  m_PathMap.SetAt(key, pGlyphPath);
+  return pGlyphPath;
+}
+typedef struct {
+  FX_BOOL m_bCount;
+  int m_PointCount;
+  FX_PATHPOINT* m_pPoints;
+  int m_CurX;
+  int m_CurY;
+  FX_FLOAT m_CoordUnit;
+} OUTLINE_PARAMS;
+void _Outline_CheckEmptyContour(OUTLINE_PARAMS* param) {
+  if (param->m_PointCount >= 2 &&
+      param->m_pPoints[param->m_PointCount - 2].m_Flag == FXPT_MOVETO &&
+      param->m_pPoints[param->m_PointCount - 2].m_PointX ==
+          param->m_pPoints[param->m_PointCount - 1].m_PointX &&
+      param->m_pPoints[param->m_PointCount - 2].m_PointY ==
+          param->m_pPoints[param->m_PointCount - 1].m_PointY) {
+    param->m_PointCount -= 2;
+  }
+  if (param->m_PointCount >= 4 &&
+      param->m_pPoints[param->m_PointCount - 4].m_Flag == FXPT_MOVETO &&
+      param->m_pPoints[param->m_PointCount - 3].m_Flag == FXPT_BEZIERTO &&
+      param->m_pPoints[param->m_PointCount - 3].m_PointX ==
+          param->m_pPoints[param->m_PointCount - 4].m_PointX &&
+      param->m_pPoints[param->m_PointCount - 3].m_PointY ==
+          param->m_pPoints[param->m_PointCount - 4].m_PointY &&
+      param->m_pPoints[param->m_PointCount - 2].m_PointX ==
+          param->m_pPoints[param->m_PointCount - 4].m_PointX &&
+      param->m_pPoints[param->m_PointCount - 2].m_PointY ==
+          param->m_pPoints[param->m_PointCount - 4].m_PointY &&
+      param->m_pPoints[param->m_PointCount - 1].m_PointX ==
+          param->m_pPoints[param->m_PointCount - 4].m_PointX &&
+      param->m_pPoints[param->m_PointCount - 1].m_PointY ==
+          param->m_pPoints[param->m_PointCount - 4].m_PointY) {
+    param->m_PointCount -= 4;
+  }
+}
+extern "C" {
+static int _Outline_MoveTo(const FXFT_Vector* to, void* user) {
+  OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+  if (!param->m_bCount) {
+    _Outline_CheckEmptyContour(param);
+    param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount].m_Flag = FXPT_MOVETO;
+    param->m_CurX = to->x;
+    param->m_CurY = to->y;
+    if (param->m_PointCount) {
+      param->m_pPoints[param->m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
+    }
+  }
+  param->m_PointCount++;
+  return 0;
+}
+};
+extern "C" {
+static int _Outline_LineTo(const FXFT_Vector* to, void* user) {
+  OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+  if (!param->m_bCount) {
+    param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount].m_Flag = FXPT_LINETO;
+    param->m_CurX = to->x;
+    param->m_CurY = to->y;
+  }
+  param->m_PointCount++;
+  return 0;
+}
+};
+extern "C" {
+static int _Outline_ConicTo(const FXFT_Vector* control,
+                            const FXFT_Vector* to,
+                            void* user) {
+  OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+  if (!param->m_bCount) {
+    param->m_pPoints[param->m_PointCount].m_PointX =
+        (param->m_CurX + (control->x - param->m_CurX) * 2 / 3) /
+        param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount].m_PointY =
+        (param->m_CurY + (control->y - param->m_CurY) * 2 / 3) /
+        param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount].m_Flag = FXPT_BEZIERTO;
+    param->m_pPoints[param->m_PointCount + 1].m_PointX =
+        (control->x + (to->x - control->x) / 3) / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount + 1].m_PointY =
+        (control->y + (to->y - control->y) / 3) / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount + 1].m_Flag = FXPT_BEZIERTO;
+    param->m_pPoints[param->m_PointCount + 2].m_PointX =
+        to->x / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount + 2].m_PointY =
+        to->y / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount + 2].m_Flag = FXPT_BEZIERTO;
+    param->m_CurX = to->x;
+    param->m_CurY = to->y;
+  }
+  param->m_PointCount += 3;
+  return 0;
+}
+};
+extern "C" {
+static int _Outline_CubicTo(const FXFT_Vector* control1,
+                            const FXFT_Vector* control2,
+                            const FXFT_Vector* to,
+                            void* user) {
+  OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+  if (!param->m_bCount) {
+    param->m_pPoints[param->m_PointCount].m_PointX =
+        control1->x / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount].m_PointY =
+        control1->y / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount].m_Flag = FXPT_BEZIERTO;
+    param->m_pPoints[param->m_PointCount + 1].m_PointX =
+        control2->x / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount + 1].m_PointY =
+        control2->y / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount + 1].m_Flag = FXPT_BEZIERTO;
+    param->m_pPoints[param->m_PointCount + 2].m_PointX =
+        to->x / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount + 2].m_PointY =
+        to->y / param->m_CoordUnit;
+    param->m_pPoints[param->m_PointCount + 2].m_Flag = FXPT_BEZIERTO;
+    param->m_CurX = to->x;
+    param->m_CurY = to->y;
+  }
+  param->m_PointCount += 3;
+  return 0;
+}
+};
+CFX_PathData* CFX_Font::LoadGlyphPath(FX_DWORD glyph_index, int dest_width) {
+  if (m_Face == NULL) {
+    return NULL;
+  }
+  FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
+  FXFT_Matrix ft_matrix = {65536, 0, 0, 65536};
+  if (m_pSubstFont) {
+    if (m_pSubstFont->m_ItalicAngle) {
+      int skew = m_pSubstFont->m_ItalicAngle;
+      skew = skew <= -ANGLESKEW_ARRAY_SIZE ? -58 : -g_AngleSkew[-skew];
+      if (m_bVertical) {
+        ft_matrix.yx += ft_matrix.yy * skew / 100;
+      } else {
+        ft_matrix.xy += -ft_matrix.xx * skew / 100;
+      }
+    }
+    if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) {
+      AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight);
+    }
+  }
+  ScopedFontTransform scoped_transform(m_Face, &ft_matrix);
+  int load_flags = FXFT_LOAD_NO_BITMAP;
+  if (!(m_Face->face_flags & FT_FACE_FLAG_SFNT) || !FT_IS_TRICKY(m_Face)) {
+    load_flags |= FT_LOAD_NO_HINTING;
+  }
+  int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags);
+  if (error) {
+    return NULL;
+  }
+  if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) &&
+      m_pSubstFont->m_Weight > 400) {
+    int index = (m_pSubstFont->m_Weight - 400) / 10;
+    if (index >= WEIGHTPOW_ARRAY_SIZE)
+      index = WEIGHTPOW_ARRAY_SIZE - 1;
+    int level = 0;
+    if (m_pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET) {
+      level = g_WeightPow_SHIFTJIS[index] * 2 * 65536 / 36655;
+    } else {
+      level = g_WeightPow[index] * 2;
+    }
+    FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);
+  }
+  FXFT_Outline_Funcs funcs;
+  funcs.move_to = _Outline_MoveTo;
+  funcs.line_to = _Outline_LineTo;
+  funcs.conic_to = _Outline_ConicTo;
+  funcs.cubic_to = _Outline_CubicTo;
+  funcs.shift = 0;
+  funcs.delta = 0;
+  OUTLINE_PARAMS params;
+  params.m_bCount = TRUE;
+  params.m_PointCount = 0;
+  FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);
+  if (params.m_PointCount == 0) {
+    return NULL;
+  }
+  CFX_PathData* pPath = new CFX_PathData;
+  pPath->SetPointCount(params.m_PointCount);
+  params.m_bCount = FALSE;
+  params.m_PointCount = 0;
+  params.m_pPoints = pPath->GetPoints();
+  params.m_CurX = params.m_CurY = 0;
+  params.m_CoordUnit = 64 * 64.0;
+  FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);
+  _Outline_CheckEmptyContour(&params);
+  pPath->TrimPoints(params.m_PointCount);
+  if (params.m_PointCount) {
+    pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
+  }
+  return pPath;
+}
+void _CFX_UniqueKeyGen::Generate(int count, ...) {
+  va_list argList;
+  va_start(argList, count);
+  for (int i = 0; i < count; i++) {
+    int p = va_arg(argList, int);
+    ((FX_DWORD*)m_Key)[i] = p;
+  }
+  va_end(argList);
+  m_KeyLen = count * sizeof(FX_DWORD);
+}