OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "../../../include/fxge/fx_ge.h" | 9 #include "../../../include/fxge/fx_ge.h" |
10 #include "../../../include/fxge/fx_freetype.h" | 10 #include "../../../include/fxge/fx_freetype.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 FXFT_Done_Face(m_SingleFace.m_pFace); | 51 FXFT_Done_Face(m_SingleFace.m_pFace); |
52 } | 52 } |
53 } else if (m_Type == 2) { | 53 } else if (m_Type == 2) { |
54 for (int i = 0; i < 16; i++) | 54 for (int i = 0; i < 16; i++) |
55 if (m_TTCFace.m_pFaces[i]) { | 55 if (m_TTCFace.m_pFaces[i]) { |
56 FXFT_Done_Face(m_TTCFace.m_pFaces[i]); | 56 FXFT_Done_Face(m_TTCFace.m_pFaces[i]); |
57 } | 57 } |
58 } | 58 } |
59 FX_Free(m_pFontData); | 59 FX_Free(m_pFontData); |
60 } | 60 } |
| 61 #ifndef PDF_ENABLE_XFA |
61 FX_BOOL CTTFontDesc::ReleaseFace(FXFT_Face face) { | 62 FX_BOOL CTTFontDesc::ReleaseFace(FXFT_Face face) { |
| 63 #else |
| 64 int32_t CTTFontDesc::ReleaseFace(FXFT_Face face) { |
| 65 #endif |
62 if (m_Type == 1) { | 66 if (m_Type == 1) { |
63 if (m_SingleFace.m_pFace != face) { | 67 if (m_SingleFace.m_pFace != face) { |
| 68 #ifndef PDF_ENABLE_XFA |
64 return FALSE; | 69 return FALSE; |
| 70 #else |
| 71 return -1; |
| 72 #endif |
65 } | 73 } |
66 } else if (m_Type == 2) { | 74 } else if (m_Type == 2) { |
67 int i; | 75 int i; |
68 for (i = 0; i < 16; i++) | 76 for (i = 0; i < 16; i++) |
69 if (m_TTCFace.m_pFaces[i] == face) { | 77 if (m_TTCFace.m_pFaces[i] == face) { |
70 break; | 78 break; |
71 } | 79 } |
72 if (i == 16) { | 80 if (i == 16) { |
| 81 #ifndef PDF_ENABLE_XFA |
73 return FALSE; | 82 return FALSE; |
| 83 #else |
| 84 return -1; |
| 85 #endif |
74 } | 86 } |
75 } | 87 } |
76 m_RefCount--; | 88 m_RefCount--; |
77 if (m_RefCount) { | 89 if (m_RefCount) { |
| 90 #ifndef PDF_ENABLE_XFA |
78 return FALSE; | 91 return FALSE; |
| 92 #else |
| 93 return m_RefCount; |
| 94 #endif |
79 } | 95 } |
80 delete this; | 96 delete this; |
| 97 #ifndef PDF_ENABLE_XFA |
81 return TRUE; | 98 return TRUE; |
| 99 #else |
| 100 return 0; |
| 101 #endif |
82 } | 102 } |
83 | 103 |
84 CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr) { | 104 CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr) { |
85 m_pBuiltinMapper.reset(new CFX_FontMapper(this)); | 105 m_pBuiltinMapper.reset(new CFX_FontMapper(this)); |
86 } | 106 } |
87 | 107 |
88 CFX_FontMgr::~CFX_FontMgr() { | 108 CFX_FontMgr::~CFX_FontMgr() { |
89 for (const auto& pair : m_FaceMap) | 109 for (const auto& pair : m_FaceMap) |
90 delete pair.second; | 110 delete pair.second; |
91 | 111 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 FXFT_Face face = nullptr; | 370 FXFT_Face face = nullptr; |
351 if (FXFT_New_Face(library, filename, face_index, &face)) | 371 if (FXFT_New_Face(library, filename, face_index, &face)) |
352 return nullptr; | 372 return nullptr; |
353 return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face; | 373 return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face; |
354 } | 374 } |
355 | 375 |
356 void CFX_FontMgr::ReleaseFace(FXFT_Face face) { | 376 void CFX_FontMgr::ReleaseFace(FXFT_Face face) { |
357 if (!face) { | 377 if (!face) { |
358 return; | 378 return; |
359 } | 379 } |
| 380 #ifdef PDF_ENABLE_XFA |
| 381 FX_BOOL bNeedFaceDone = TRUE; |
| 382 #endif |
360 auto it = m_FaceMap.begin(); | 383 auto it = m_FaceMap.begin(); |
361 while (it != m_FaceMap.end()) { | 384 while (it != m_FaceMap.end()) { |
362 auto temp = it++; | 385 auto temp = it++; |
| 386 #ifndef PDF_ENABLE_XFA |
363 if (temp->second->ReleaseFace(face)) { | 387 if (temp->second->ReleaseFace(face)) { |
| 388 #else |
| 389 int nRet = temp->second->ReleaseFace(face); |
| 390 if (nRet == 0) { |
| 391 #endif |
364 m_FaceMap.erase(temp); | 392 m_FaceMap.erase(temp); |
| 393 #ifdef PDF_ENABLE_XFA |
| 394 bNeedFaceDone = FALSE; |
| 395 } else if (nRet > 0) { |
| 396 bNeedFaceDone = FALSE; |
| 397 #endif |
365 } | 398 } |
366 } | 399 } |
| 400 #ifdef PDF_ENABLE_XFA |
| 401 if (bNeedFaceDone && !m_pBuiltinMapper->IsBuiltinFace(face)) { |
| 402 FXFT_Done_Face(face); |
| 403 } |
| 404 #endif |
367 } | 405 } |
368 const FoxitFonts g_FoxitFonts[14] = { | 406 const FoxitFonts g_FoxitFonts[14] = { |
369 {g_FoxitFixedFontData, 17597}, | 407 {g_FoxitFixedFontData, 17597}, |
370 {g_FoxitFixedBoldFontData, 18055}, | 408 {g_FoxitFixedBoldFontData, 18055}, |
371 {g_FoxitFixedBoldItalicFontData, 19151}, | 409 {g_FoxitFixedBoldItalicFontData, 19151}, |
372 {g_FoxitFixedItalicFontData, 18746}, | 410 {g_FoxitFixedItalicFontData, 18746}, |
373 {g_FoxitSansFontData, 15025}, | 411 {g_FoxitSansFontData, 15025}, |
374 {g_FoxitSansBoldFontData, 16344}, | 412 {g_FoxitSansBoldFontData, 16344}, |
375 {g_FoxitSansBoldItalicFontData, 16418}, | 413 {g_FoxitSansBoldItalicFontData, 16418}, |
376 {g_FoxitSansItalicFontData, 16339}, | 414 {g_FoxitSansItalicFontData, 16339}, |
(...skipping 29 matching lines...) Expand all Loading... |
406 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) | 444 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) |
407 : m_bListLoaded(FALSE), | 445 : m_bListLoaded(FALSE), |
408 m_pFontInfo(nullptr), | 446 m_pFontInfo(nullptr), |
409 m_pFontEnumerator(nullptr), | 447 m_pFontEnumerator(nullptr), |
410 m_pFontMgr(mgr) { | 448 m_pFontMgr(mgr) { |
411 m_MMFaces[0] = nullptr; | 449 m_MMFaces[0] = nullptr; |
412 m_MMFaces[1] = nullptr; | 450 m_MMFaces[1] = nullptr; |
413 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces)); | 451 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces)); |
414 } | 452 } |
415 CFX_FontMapper::~CFX_FontMapper() { | 453 CFX_FontMapper::~CFX_FontMapper() { |
| 454 #ifndef PDF_ENABLE_XFA |
416 for (size_t i = 0; i < FX_ArraySize(m_FoxitFaces); ++i) { | 455 for (size_t i = 0; i < FX_ArraySize(m_FoxitFaces); ++i) { |
417 if (m_FoxitFaces[i]) | 456 if (m_FoxitFaces[i]) |
| 457 #else |
| 458 for (int i = 0; i < 14; i++) |
| 459 if (m_FoxitFaces[i]) { |
| 460 #endif |
418 FXFT_Done_Face(m_FoxitFaces[i]); | 461 FXFT_Done_Face(m_FoxitFaces[i]); |
| 462 #ifndef PDF_ENABLE_XFA |
419 } | 463 } |
| 464 #else |
| 465 } |
| 466 #endif |
420 if (m_MMFaces[0]) { | 467 if (m_MMFaces[0]) { |
421 FXFT_Done_Face(m_MMFaces[0]); | 468 FXFT_Done_Face(m_MMFaces[0]); |
422 } | 469 } |
423 if (m_MMFaces[1]) { | 470 if (m_MMFaces[1]) { |
424 FXFT_Done_Face(m_MMFaces[1]); | 471 FXFT_Done_Face(m_MMFaces[1]); |
425 } | 472 } |
426 if (m_pFontInfo) { | 473 if (m_pFontInfo) { |
427 m_pFontInfo->Release(); | 474 m_pFontInfo->Release(); |
428 } | 475 } |
429 } | 476 } |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 bItalic = TRUE; | 1095 bItalic = TRUE; |
1049 } | 1096 } |
1050 } | 1097 } |
1051 iExact = !match.IsEmpty(); | 1098 iExact = !match.IsEmpty(); |
1052 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, | 1099 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, |
1053 family, iExact); | 1100 family, iExact); |
1054 if (iExact) { | 1101 if (iExact) { |
1055 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; | 1102 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; |
1056 } | 1103 } |
1057 if (hFont == NULL) { | 1104 if (hFont == NULL) { |
| 1105 #ifdef PDF_ENABLE_XFA |
| 1106 if (flags & FXFONT_EXACTMATCH) { |
| 1107 return NULL; |
| 1108 } |
| 1109 #endif |
1058 if (bCJK) { | 1110 if (bCJK) { |
1059 if (italic_angle != 0) { | 1111 if (italic_angle != 0) { |
1060 bItalic = TRUE; | 1112 bItalic = TRUE; |
1061 } else { | 1113 } else { |
1062 bItalic = FALSE; | 1114 bItalic = FALSE; |
1063 } | 1115 } |
1064 weight = old_weight; | 1116 weight = old_weight; |
1065 } | 1117 } |
1066 if (!match.IsEmpty()) { | 1118 if (!match.IsEmpty()) { |
1067 hFont = m_pFontInfo->GetFont(match); | 1119 hFont = m_pFontInfo->GetFont(match); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 if (italic_angle == 0) { | 1225 if (italic_angle == 0) { |
1174 italic_angle = -12; | 1226 italic_angle = -12; |
1175 } else if (FXSYS_abs(italic_angle) < 5) { | 1227 } else if (FXSYS_abs(italic_angle) < 5) { |
1176 italic_angle = 0; | 1228 italic_angle = 0; |
1177 } | 1229 } |
1178 pSubstFont->m_ItalicAngle = italic_angle; | 1230 pSubstFont->m_ItalicAngle = italic_angle; |
1179 } | 1231 } |
1180 m_pFontInfo->DeleteFont(hFont); | 1232 m_pFontInfo->DeleteFont(hFont); |
1181 return face; | 1233 return face; |
1182 } | 1234 } |
| 1235 #ifdef PDF_ENABLE_XFA |
| 1236 FXFT_Face CFX_FontMapper::FindSubstFontByUnicode(FX_DWORD dwUnicode, |
| 1237 FX_DWORD flags, |
| 1238 int weight, |
| 1239 int italic_angle) { |
| 1240 if (m_pFontInfo == NULL) { |
| 1241 return NULL; |
| 1242 } |
| 1243 FX_BOOL bItalic = (flags & FXFONT_ITALIC) != 0; |
| 1244 int PitchFamily = 0; |
| 1245 if (flags & FXFONT_SERIF) { |
| 1246 PitchFamily |= FXFONT_FF_ROMAN; |
| 1247 } |
| 1248 if (flags & FXFONT_SCRIPT) { |
| 1249 PitchFamily |= FXFONT_FF_SCRIPT; |
| 1250 } |
| 1251 if (flags & FXFONT_FIXED_PITCH) { |
| 1252 PitchFamily |= FXFONT_FF_FIXEDPITCH; |
| 1253 } |
| 1254 void* hFont = |
| 1255 m_pFontInfo->MapFontByUnicode(dwUnicode, weight, bItalic, PitchFamily); |
| 1256 if (hFont == NULL) { |
| 1257 return NULL; |
| 1258 } |
| 1259 FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, NULL, 0); |
| 1260 FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, NULL, 0); |
| 1261 if (font_size == 0 && ttc_size == 0) { |
| 1262 m_pFontInfo->DeleteFont(hFont); |
| 1263 return NULL; |
| 1264 } |
| 1265 FXFT_Face face = NULL; |
| 1266 if (ttc_size) { |
| 1267 uint8_t temp[1024]; |
| 1268 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); |
| 1269 FX_DWORD checksum = 0; |
| 1270 for (int i = 0; i < 256; i++) { |
| 1271 checksum += ((FX_DWORD*)temp)[i]; |
| 1272 } |
| 1273 uint8_t* pFontData; |
| 1274 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, |
| 1275 ttc_size - font_size, pFontData); |
| 1276 if (face == NULL) { |
| 1277 pFontData = FX_Alloc(uint8_t, ttc_size); |
| 1278 if (pFontData) { |
| 1279 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size); |
| 1280 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, |
| 1281 ttc_size, ttc_size - font_size); |
| 1282 } |
| 1283 } |
| 1284 } else { |
| 1285 CFX_ByteString SubstName; |
| 1286 m_pFontInfo->GetFaceName(hFont, SubstName); |
| 1287 uint8_t* pFontData; |
| 1288 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); |
| 1289 if (face == NULL) { |
| 1290 pFontData = FX_Alloc(uint8_t, font_size); |
| 1291 if (!pFontData) { |
| 1292 m_pFontInfo->DeleteFont(hFont); |
| 1293 return NULL; |
| 1294 } |
| 1295 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); |
| 1296 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData, |
| 1297 font_size, |
| 1298 m_pFontInfo->GetFaceIndex(hFont)); |
| 1299 } |
| 1300 } |
| 1301 m_pFontInfo->DeleteFont(hFont); |
| 1302 return face; |
| 1303 } |
| 1304 |
| 1305 FX_BOOL CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const { |
| 1306 for (int i = 0; i < MM_FACE_COUNT; ++i) { |
| 1307 if (m_MMFaces[i] == face) { |
| 1308 return TRUE; |
| 1309 } |
| 1310 } |
| 1311 for (int i = 0; i < FOXIT_FACE_COUNT; ++i) { |
| 1312 if (m_FoxitFaces[i] == face) { |
| 1313 return TRUE; |
| 1314 } |
| 1315 } |
| 1316 return FALSE; |
| 1317 } |
| 1318 #endif |
1183 extern "C" { | 1319 extern "C" { |
1184 unsigned long _FTStreamRead(FXFT_Stream stream, | 1320 unsigned long _FTStreamRead(FXFT_Stream stream, |
1185 unsigned long offset, | 1321 unsigned long offset, |
1186 unsigned char* buffer, | 1322 unsigned char* buffer, |
1187 unsigned long count); | 1323 unsigned long count); |
1188 void _FTStreamClose(FXFT_Stream stream); | 1324 void _FTStreamClose(FXFT_Stream stream); |
1189 }; | 1325 }; |
1190 CFontFileFaceInfo::CFontFileFaceInfo() { | 1326 CFontFileFaceInfo::CFontFileFaceInfo() { |
1191 m_pFile = NULL; | 1327 m_pFile = NULL; |
1192 m_Face = NULL; | 1328 m_Face = NULL; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 return pFind; | 1603 return pFind; |
1468 } | 1604 } |
1469 void* CFX_FolderFontInfo::MapFont(int weight, | 1605 void* CFX_FolderFontInfo::MapFont(int weight, |
1470 FX_BOOL bItalic, | 1606 FX_BOOL bItalic, |
1471 int charset, | 1607 int charset, |
1472 int pitch_family, | 1608 int pitch_family, |
1473 const FX_CHAR* family, | 1609 const FX_CHAR* family, |
1474 int& iExact) { | 1610 int& iExact) { |
1475 return NULL; | 1611 return NULL; |
1476 } | 1612 } |
| 1613 #ifdef PDF_ENABLE_XFA |
| 1614 void* CFX_FolderFontInfo::MapFontByUnicode(FX_DWORD dwUnicode, |
| 1615 int weight, |
| 1616 FX_BOOL bItalic, |
| 1617 int pitch_family) { |
| 1618 return NULL; |
| 1619 } |
| 1620 #endif |
1477 void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { | 1621 void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { |
1478 auto it = m_FontList.find(face); | 1622 auto it = m_FontList.find(face); |
1479 return it != m_FontList.end() ? it->second : nullptr; | 1623 return it != m_FontList.end() ? it->second : nullptr; |
1480 } | 1624 } |
1481 FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, | 1625 FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, |
1482 FX_DWORD table, | 1626 FX_DWORD table, |
1483 uint8_t* buffer, | 1627 uint8_t* buffer, |
1484 FX_DWORD size) { | 1628 FX_DWORD size) { |
1485 if (hFont == NULL) { | 1629 if (hFont == NULL) { |
1486 return 0; | 1630 return 0; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 int PDF_GetStandardFontName(CFX_ByteString* name) { | 1678 int PDF_GetStandardFontName(CFX_ByteString* name) { |
1535 AltFontName* found = static_cast<AltFontName*>( | 1679 AltFontName* found = static_cast<AltFontName*>( |
1536 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), | 1680 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), |
1537 sizeof(AltFontName), compareString)); | 1681 sizeof(AltFontName), compareString)); |
1538 if (!found) | 1682 if (!found) |
1539 return -1; | 1683 return -1; |
1540 | 1684 |
1541 *name = g_Base14FontNames[found->m_Index]; | 1685 *name = g_Base14FontNames[found->m_Index]; |
1542 return found->m_Index; | 1686 return found->m_Index; |
1543 } | 1687 } |
OLD | NEW |