CFGAS_GEFont* CFGAS_FontMgr::GetFontByUnicode(FX_WCHAR wUnicode, uint32_t dwFontStyles, const FX_WCHAR* pszFontFamily) { CFGAS_GEFont* pFont = nullptr; if (m_FailedUnicodes2Nullptr.Lookup(wUnicode, pFont)) return nullptr; const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; uint16_t wBitField = x ? x->wBitField : 0x03E7; CFX_ByteString bsHash; if (wCodePage == 0xFFFF) bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); else bsHash.Format("%d, %d", wCodePage, dwFontStyles); bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts = nullptr; if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { if (!pFonts) return nullptr; for (int32_t i = 0; i < pFonts->GetSize(); ++i) { if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) return pFonts->GetAt(i)->Retain(); } } if (!pFonts) pFonts = new CFX_ArrayTemplate<CFGAS_GEFont*>; m_Hash2Fonts.SetAt(dwHash, pFonts); CFX_FontDescriptorInfos* sortedFonts = nullptr; if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { sortedFonts = new CFX_FontDescriptorInfos; MatchFonts(*sortedFonts, wCodePage, dwFontStyles, CFX_WideString(pszFontFamily), wUnicode); m_Hash2CandidateList.SetAt(dwHash, sortedFonts); } for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) { CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont; if (!VerifyUnicode(pDesc, wUnicode)) continue; pFont = LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); if (!pFont) continue; pFont->SetLogicalFontStyle(dwFontStyles); pFonts->Add(pFont); return pFont; } if (!pszFontFamily) m_FailedUnicodes2Nullptr.SetAt(wUnicode, nullptr); return nullptr; }
CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByUnicode( FX_WCHAR wUnicode, uint32_t dwFontStyles, const FX_WCHAR* pszFontFamily) { const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); if (pRet->wBitField == 999) return nullptr; uint32_t dwHash = FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); CFGAS_GEFont* pFont = nullptr; if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; FX_FONTDESCRIPTOR const* pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage, pRet->wBitField, wUnicode); if (!pFD && pszFontFamily) { pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage, pRet->wBitField, wUnicode); } if (!pFD) return nullptr; uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); const FX_WCHAR* pFontFace = pFD->wsFontFace; pFont = CFGAS_GEFont::LoadFont(pFontFace, dwFontStyles, wCodePage, this); if (pFont) { m_Fonts.Add(pFont); m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); return LoadFont(pFont, dwFontStyles, wCodePage); } return nullptr; }
int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bRecursive, IFX_Font** ppFont, FX_BOOL bCharCode) { FXSYS_assert(m_pFontEncoding != NULL); int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); if (iGlyphIndex > 0) { if (ppFont != NULL) { *ppFont = (IFX_Font*)this; } return iGlyphIndex; } FGAS_LPCFONTUSB pFontUSB = FGAS_GetUnicodeBitField(wUnicode); if (pFontUSB == NULL) { return 0xFFFF; } FX_WORD wBitField = pFontUSB->wBitField; if (wBitField >= 128) { return 0xFFFF; } IFX_Font* pFont = NULL; m_FontMapper.Lookup((void*)(uintptr_t)wUnicode, (void*&)pFont); if (pFont != NULL && pFont != (IFX_Font*)this) { iGlyphIndex = ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); if (iGlyphIndex != 0xFFFF) { int32_t i = m_SubstFonts.Find(pFont); if (i > -1) { iGlyphIndex |= ((i + 1) << 24); if (ppFont != NULL) { *ppFont = pFont; } return iGlyphIndex; } } } if (m_pFontMgr != NULL && bRecursive) { CFX_WideString wsFamily; GetFamilyName(wsFamily); #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ IFX_Font* pFont = m_pFontMgr->GetDefFontByUnicode( wUnicode, GetFontStyles(), (const FX_WCHAR*)wsFamily); #else IFX_Font* pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), (const FX_WCHAR*)wsFamily); if (NULL == pFont) { pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); } #endif if (pFont != NULL) { if (pFont == (IFX_Font*)this) { pFont->Release(); return 0xFFFF; } m_FontMapper.SetAt((void*)(uintptr_t)wUnicode, (void*)pFont); int32_t i = m_SubstFonts.GetSize(); m_SubstFonts.Add(pFont); iGlyphIndex = ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); if (iGlyphIndex != 0xFFFF) { iGlyphIndex |= ((i + 1) << 24); if (ppFont != NULL) { *ppFont = pFont; } return iGlyphIndex; } } } return 0xFFFF; }
uint16_t FX_GetUnicodeBit(FX_WCHAR wcUnicode) { const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wcUnicode); return x ? x->wBitField : 999; }
int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bRecursive, CFGAS_GEFont** ppFont, FX_BOOL bCharCode) { ASSERT(m_pFontEncoding); int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); if (iGlyphIndex > 0) { if (ppFont) { *ppFont = this; } return iGlyphIndex; } const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); if (!pFontUSB) { return 0xFFFF; } uint16_t wBitField = pFontUSB->wBitField; if (wBitField >= 128) { return 0xFFFF; } auto it = m_FontMapper.find(wUnicode); CFGAS_GEFont* pFont = it != m_FontMapper.end() ? it->second : nullptr; if (pFont && pFont != this) { iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, nullptr, bCharCode); if (iGlyphIndex != 0xFFFF) { int32_t i = m_SubstFonts.Find(pFont); if (i > -1) { iGlyphIndex |= ((i + 1) << 24); if (ppFont) *ppFont = pFont; return iGlyphIndex; } } } if (m_pFontMgr && bRecursive) { CFX_WideString wsFamily; GetFamilyName(wsFamily); #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ CFGAS_GEFont* pFont = m_pFontMgr->GetDefFontByUnicode( wUnicode, GetFontStyles(), wsFamily.c_str()); #else CFGAS_GEFont* pFont = m_pFontMgr->GetFontByUnicode( wUnicode, GetFontStyles(), wsFamily.c_str()); if (!pFont) pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), nullptr); #endif if (pFont) { if (pFont == this) { pFont->Release(); return 0xFFFF; } m_FontMapper[wUnicode] = pFont; int32_t i = m_SubstFonts.GetSize(); m_SubstFonts.Add(pFont); iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, nullptr, bCharCode); if (iGlyphIndex != 0xFFFF) { iGlyphIndex |= ((i + 1) << 24); if (ppFont) *ppFont = pFont; return iGlyphIndex; } } } return 0xFFFF; }