FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, int weight, FX_BOOL bItalic, FX_LPBYTE pData, FX_DWORD size, int face_index) { CTTFontDesc* pFontDesc = FX_NEW CTTFontDesc; if (!pFontDesc) { return NULL; } pFontDesc->m_Type = 1; pFontDesc->m_SingleFace.m_pFace = NULL; pFontDesc->m_SingleFace.m_bBold = weight; pFontDesc->m_SingleFace.m_bItalic = bItalic; pFontDesc->m_pFontData = pData; pFontDesc->m_RefCount = 1; FXFT_Library library; if (m_FTLibrary == NULL) { FXFT_Init_FreeType(&m_FTLibrary); } library = m_FTLibrary; int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &pFontDesc->m_SingleFace.m_pFace); if (ret) { delete pFontDesc; return NULL; } ret = FXFT_Set_Pixel_Sizes(pFontDesc->m_SingleFace.m_pFace, 64, 64); if (ret) { delete pFontDesc; return NULL; } CFX_ByteString key(face_name); key += ','; key += CFX_ByteString::FormatInteger(weight); key += bItalic ? 'I' : 'N'; m_FaceMap.SetAt(key, pFontDesc); return pFontDesc->m_SingleFace.m_pFace; }
FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, int weight, FX_BOOL bItalic, uint8_t* pData, uint32_t size, int face_index) { CTTFontDesc* pFontDesc = new CTTFontDesc; pFontDesc->m_Type = 1; pFontDesc->m_SingleFace.m_pFace = nullptr; pFontDesc->m_SingleFace.m_bBold = weight; pFontDesc->m_SingleFace.m_bItalic = bItalic; pFontDesc->m_pFontData = pData; pFontDesc->m_RefCount = 1; InitFTLibrary(); FXFT_Library library = m_FTLibrary; int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &pFontDesc->m_SingleFace.m_pFace); if (ret) { delete pFontDesc; return nullptr; } ret = FXFT_Set_Pixel_Sizes(pFontDesc->m_SingleFace.m_pFace, 64, 64); if (ret) { delete pFontDesc; return nullptr; } m_FaceMap[KeyNameFromFace(face_name, weight, bItalic)] = pFontDesc; return pFontDesc->m_SingleFace.m_pFace; }
FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData, uint32_t size, int face_index) { InitFTLibrary(); FXFT_Library library = m_FTLibrary; FXFT_Face face = nullptr; if (FXFT_New_Memory_Face(library, pData, size, face_index, &face)) return nullptr; return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face; }
static FXFT_Face FT_LoadFont(FX_LPBYTE pData, int size) { FXFT_Library library; if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) { FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary); } library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; FXFT_Face face; int error = FXFT_New_Memory_Face(library, pData, size, 0, &face); if (error) { return NULL; } error = FXFT_Set_Pixel_Sizes(face, 64, 64); if (error) { return NULL; } return face; }
FXFT_Face CFX_FontMgr::GetFixedFace(FX_LPCBYTE pData, FX_DWORD size, int face_index) { FXFT_Library library; if (m_FTLibrary == NULL) { FXFT_Init_FreeType(&m_FTLibrary); } library = m_FTLibrary; FXFT_Face face = NULL; int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &face); if (ret) { return NULL; } ret = FXFT_Set_Pixel_Sizes(face, 64, 64); if (ret) { return NULL; } return face; }