| 1284 | } |
| 1285 | |
| 1286 | bool ResourcePool::LoadTTFFont(const char* name, const std::wstring& path, float width, float height)LNOEXCEPT |
| 1287 | { |
| 1288 | LDEBUG_RESOURCETIMER; |
| 1289 | |
| 1290 | { |
| 1291 | LDEBUG_RESOURCESCOPE; |
| 1292 | |
| 1293 | LASSERT(LAPP.GetRenderer()); |
| 1294 | |
| 1295 | if (m_TTFFontPool.find(name) != m_TTFFontPool.end()) |
| 1296 | { |
| 1297 | LWARNING("LoadTTFFont: ����'%m'�Ѵ��ڣ����ز����ѱ�ȡ��", name); |
| 1298 | return true; |
| 1299 | } |
| 1300 | |
| 1301 | fcyRefPointer<f2dFontProvider> tFontProvider; |
| 1302 | |
| 1303 | // ��ȡ�ļ� |
| 1304 | fcyRefPointer<fcyMemStream> tDataBuf; |
| 1305 | if (!m_pMgr->LoadFile(path.c_str(), tDataBuf)) |
| 1306 | { |
| 1307 | LINFO("LoadTTFFont: ����·��'%s'�ϼ������壬������ϵͳ����Դ�������ϵͳ����", path.c_str()); |
| 1308 | if (FCYFAILED(LAPP.GetRenderer()->CreateSystemFont(path.c_str(), 0, fcyVec2(width, height), F2DFONTFLAG_NONE, &tFontProvider))) |
| 1309 | { |
| 1310 | LERROR("LoadTTFFont: ����ʧ�ܣ�����·��'%s'�ϼ�������", path.c_str()); |
| 1311 | return false; |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | // �������� |
| 1316 | try |
| 1317 | { |
| 1318 | if (!tFontProvider) |
| 1319 | { |
| 1320 | if (FCYFAILED(LAPP.GetRenderer()->CreateFontFromFile(tDataBuf, 0, fcyVec2(width, height), F2DFONTFLAG_NONE, &tFontProvider))) |
| 1321 | { |
| 1322 | LERROR("LoadTTFFont: ���ļ�'%s'������������ʧ��", path.c_str()); |
| 1323 | return false; |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | fcyRefPointer<ResFont> tRes; |
| 1328 | tRes.DirectSet(new ResFont(name, tFontProvider)); |
| 1329 | tRes->SetBlendMode(BlendMode::AddAlpha); |
| 1330 | m_TTFFontPool.emplace(name, tRes); |
| 1331 | } |
| 1332 | catch (const bad_alloc&) |
| 1333 | { |
| 1334 | LERROR("LoadTTFFont: �ڴ治��"); |
| 1335 | return false; |
| 1336 | } |
| 1337 | #ifdef LSHOWRESLOADINFO |
| 1338 | LINFO("LoadTTFFont: truetype����'%m'��װ�� (%s)", name, getResourcePoolTypeName()); |
| 1339 | #endif |
| 1340 | } |
| 1341 | |
| 1342 | LDEBUG_RESOURCEHINT(ResourceType::TrueTypeFont, path.c_str()); |
| 1343 | return true; |
no test coverage detected