CFGAS_GEFont* CFGAS_FontMgr::LoadFont(CFGAS_GEFont* pSrcFont, uint32_t dwFontStyles, uint16_t wCodePage) { ASSERT(pSrcFont); if (pSrcFont->GetFontStyles() == dwFontStyles) return pSrcFont->Retain(); void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, (void*)(uintptr_t)wCodePage}; uint32_t dwHash = FX_HashCode_GetA( CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); CFGAS_GEFont* pFont = nullptr; if (m_DeriveFonts.GetCount() > 0) { m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); if (pFont) return pFont->Retain(); } pFont = pSrcFont->Derive(dwFontStyles, wCodePage); if (!pFont) return nullptr; m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); int32_t index = m_Fonts.Find(pFont); if (index < 0) { m_Fonts.Add(pFont); pFont->Retain(); } return pFont; }
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_FontMgrImp::GetFontByCodePage( uint16_t wCodePage, uint32_t dwFontStyles, const FX_WCHAR* pszFontFamily) { CFX_ByteString bsHash; 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; if (pFonts->GetSize() != 0) return pFonts->GetAt(0)->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), 0); m_Hash2CandidateList.SetAt(dwHash, sortedFonts); } if (sortedFonts->GetSize() == 0) return nullptr; CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; CFGAS_GEFont* pFont = LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); if (pFont) pFont->SetLogicalFontStyle(dwFontStyles); pFonts->Add(pFont); return pFont; }