// ============================================================================= // TextUtilities::GetFont // Load or get the desired font // ----------------------------------------------------------------------------- CFont * GetFont(EFontType fontType) { // If this is the first time we're loading a font initialise smFonts static bool firstRun = true; if (firstRun) { firstRun = false; for (int i = 0; i < kFontTypeMax; i++) theFonts[i] = NULL; } // Load the font file if we haven't already if (theFonts[fontType] == NULL) { theFonts[fontType] = new CFont(GetFontFileName(fontType)); } return theFonts[fontType]; }
bool xFT2Font::init( xXmlNode* pFontNode) { xFontLoader* pFontLoader = m_pFontLoader; const wchar_t* pFontName = pFontNode->value(L"name"); const wchar_t* famillyName = pFontNode->value(L"familly" ) ; wstring fullFontName = wstring( famillyName ) + pFontName; const wchar_t* pFiltertName = pFontNode->value(L"filter"); //从配置文件取到数据 xFontInitor fi; fi.height = pFontNode->int_value(L"height"); fi.width = pFontNode->int_value(L"width"); fi.antialias = pFontNode->bool_value(L"antialias"); fi.bold = pFontNode->bool_value(L"bold"); fi.italic = pFontNode->bool_value(L"italic"); fi.underline = pFontNode->bool_value(L"underline"); fi.maxcache = pFontNode->int_value(L"maxcache"); fi.filter = pFontLoader->getFontSamplerFilter(pFiltertName); fi.linepitch = 0; if(pFontNode->value(L"line_pitch")) { fi.linepitch = pFontNode->int_value(L"line_pitch"); } wchar_t fileName[512]={0}; GetFontFileName(pFontNode->value(L"file") , fileName); wstring AbsFontFile = _XEVOL_ABSPATH_(fileName); //因为是个新字体,所以需要做一个FontCharMgr来管理它 createFontCharManager( fullFontName.c_str() ) ; xFT2FontCharMgr* pFontCharMgr = getFontCharManager(); pFontCharMgr->setRenderer(m_pRendeDevice); pFontCharMgr->m_UnderLine = fi.underline; pFontCharMgr->m_bBold = fi.bold; pFontCharMgr->m_Italic = fi.italic; pFontCharMgr->m_bAntilias = fi.antialias; int maxCache = fi.maxcache; if(maxCache == 0) maxCache = 1024; if( pFontCharMgr->load_font(AbsFontFile.c_str(), fi.width , fi.height) ==false) { delete pFontCharMgr; return NULL; } //pFontCharMgr->setMaxSize(maxCache); //g_FT2FontCharMgr.push_back(pFontCharMgr); //新建一个FreeType2的字体绘制器。并把它和Font m_Filter = fi.filter; m_Info.bAntialias = fi.antialias; m_Info.bBold = fi.bold; m_Info.bItalic = fi.italic; m_Info.bUnderLine = fi.underline; m_Info.nMaxWidth = GetBoldenSize(fi.bold,fi.width ); m_Info.nMaxHeight = GetBoldenSize(fi.bold,fi.height); wcsncpy(m_Info.strFamilly , famillyName , 32); wcsncpy(m_Info.strName , pFontName, 16); m_Info.nHeight = fi.height; m_Info.nWidth = fi.width; m_LinePitch = fi.linepitch; setCacheSize(maxCache ); return true; }