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 "core/include/fxge/fx_freetype.h" | 9 #include "core/include/fxge/fx_freetype.h" |
10 #include "core/include/fxge/fx_ge.h" | 10 #include "core/include/fxge/fx_ge.h" |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 bItalic = TRUE; | 1076 bItalic = TRUE; |
1077 } | 1077 } |
1078 } | 1078 } |
1079 iExact = !match.IsEmpty(); | 1079 iExact = !match.IsEmpty(); |
1080 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, | 1080 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, |
1081 family, iExact); | 1081 family, iExact); |
1082 if (iExact) { | 1082 if (iExact) { |
1083 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; | 1083 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; |
1084 } | 1084 } |
1085 if (hFont == NULL) { | 1085 if (hFont == NULL) { |
| 1086 #ifdef PDF_ENABLE_XFA |
| 1087 if (flags & FXFONT_EXACTMATCH) { |
| 1088 return NULL; |
| 1089 } |
| 1090 #endif |
1086 if (bCJK) { | 1091 if (bCJK) { |
1087 if (italic_angle != 0) { | 1092 if (italic_angle != 0) { |
1088 bItalic = TRUE; | 1093 bItalic = TRUE; |
1089 } else { | 1094 } else { |
1090 bItalic = FALSE; | 1095 bItalic = FALSE; |
1091 } | 1096 } |
1092 weight = old_weight; | 1097 weight = old_weight; |
1093 } | 1098 } |
1094 if (!match.IsEmpty()) { | 1099 if (!match.IsEmpty()) { |
1095 hFont = m_pFontInfo->GetFont(match); | 1100 hFont = m_pFontInfo->GetFont(match); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 if (italic_angle == 0) { | 1206 if (italic_angle == 0) { |
1202 italic_angle = -12; | 1207 italic_angle = -12; |
1203 } else if (FXSYS_abs(italic_angle) < 5) { | 1208 } else if (FXSYS_abs(italic_angle) < 5) { |
1204 italic_angle = 0; | 1209 italic_angle = 0; |
1205 } | 1210 } |
1206 pSubstFont->m_ItalicAngle = italic_angle; | 1211 pSubstFont->m_ItalicAngle = italic_angle; |
1207 } | 1212 } |
1208 m_pFontInfo->DeleteFont(hFont); | 1213 m_pFontInfo->DeleteFont(hFont); |
1209 return face; | 1214 return face; |
1210 } | 1215 } |
| 1216 #ifdef PDF_ENABLE_XFA |
| 1217 FXFT_Face CFX_FontMapper::FindSubstFontByUnicode(FX_DWORD dwUnicode, |
| 1218 FX_DWORD flags, |
| 1219 int weight, |
| 1220 int italic_angle) { |
| 1221 if (m_pFontInfo == NULL) { |
| 1222 return NULL; |
| 1223 } |
| 1224 FX_BOOL bItalic = (flags & FXFONT_ITALIC) != 0; |
| 1225 int PitchFamily = 0; |
| 1226 if (flags & FXFONT_SERIF) { |
| 1227 PitchFamily |= FXFONT_FF_ROMAN; |
| 1228 } |
| 1229 if (flags & FXFONT_SCRIPT) { |
| 1230 PitchFamily |= FXFONT_FF_SCRIPT; |
| 1231 } |
| 1232 if (flags & FXFONT_FIXED_PITCH) { |
| 1233 PitchFamily |= FXFONT_FF_FIXEDPITCH; |
| 1234 } |
| 1235 void* hFont = |
| 1236 m_pFontInfo->MapFontByUnicode(dwUnicode, weight, bItalic, PitchFamily); |
| 1237 if (hFont == NULL) { |
| 1238 return NULL; |
| 1239 } |
| 1240 FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, NULL, 0); |
| 1241 FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, NULL, 0); |
| 1242 if (font_size == 0 && ttc_size == 0) { |
| 1243 m_pFontInfo->DeleteFont(hFont); |
| 1244 return NULL; |
| 1245 } |
| 1246 FXFT_Face face = NULL; |
| 1247 if (ttc_size) { |
| 1248 uint8_t temp[1024]; |
| 1249 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); |
| 1250 FX_DWORD checksum = 0; |
| 1251 for (int i = 0; i < 256; i++) { |
| 1252 checksum += ((FX_DWORD*)temp)[i]; |
| 1253 } |
| 1254 uint8_t* pFontData; |
| 1255 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, |
| 1256 ttc_size - font_size, pFontData); |
| 1257 if (face == NULL) { |
| 1258 pFontData = FX_Alloc(uint8_t, ttc_size); |
| 1259 if (pFontData) { |
| 1260 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size); |
| 1261 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, |
| 1262 ttc_size, ttc_size - font_size); |
| 1263 } |
| 1264 } |
| 1265 } else { |
| 1266 CFX_ByteString SubstName; |
| 1267 m_pFontInfo->GetFaceName(hFont, SubstName); |
| 1268 uint8_t* pFontData; |
| 1269 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); |
| 1270 if (face == NULL) { |
| 1271 pFontData = FX_Alloc(uint8_t, font_size); |
| 1272 if (!pFontData) { |
| 1273 m_pFontInfo->DeleteFont(hFont); |
| 1274 return NULL; |
| 1275 } |
| 1276 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); |
| 1277 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData, |
| 1278 font_size, |
| 1279 m_pFontInfo->GetFaceIndex(hFont)); |
| 1280 } |
| 1281 } |
| 1282 m_pFontInfo->DeleteFont(hFont); |
| 1283 return face; |
| 1284 } |
| 1285 |
| 1286 FX_BOOL CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const { |
| 1287 for (int i = 0; i < MM_FACE_COUNT; ++i) { |
| 1288 if (m_MMFaces[i] == face) { |
| 1289 return TRUE; |
| 1290 } |
| 1291 } |
| 1292 for (int i = 0; i < FOXIT_FACE_COUNT; ++i) { |
| 1293 if (m_FoxitFaces[i] == face) { |
| 1294 return TRUE; |
| 1295 } |
| 1296 } |
| 1297 return FALSE; |
| 1298 } |
| 1299 #endif |
1211 extern "C" { | 1300 extern "C" { |
1212 unsigned long _FTStreamRead(FXFT_Stream stream, | 1301 unsigned long _FTStreamRead(FXFT_Stream stream, |
1213 unsigned long offset, | 1302 unsigned long offset, |
1214 unsigned char* buffer, | 1303 unsigned char* buffer, |
1215 unsigned long count); | 1304 unsigned long count); |
1216 void _FTStreamClose(FXFT_Stream stream); | 1305 void _FTStreamClose(FXFT_Stream stream); |
1217 }; | 1306 }; |
1218 #if _FX_OS_ == _FX_ANDROID_ | 1307 #if _FX_OS_ == _FX_ANDROID_ |
1219 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) { | 1308 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) { |
1220 return NULL; | 1309 return NULL; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 return pFind; | 1511 return pFind; |
1423 } | 1512 } |
1424 void* CFX_FolderFontInfo::MapFont(int weight, | 1513 void* CFX_FolderFontInfo::MapFont(int weight, |
1425 FX_BOOL bItalic, | 1514 FX_BOOL bItalic, |
1426 int charset, | 1515 int charset, |
1427 int pitch_family, | 1516 int pitch_family, |
1428 const FX_CHAR* family, | 1517 const FX_CHAR* family, |
1429 int& iExact) { | 1518 int& iExact) { |
1430 return NULL; | 1519 return NULL; |
1431 } | 1520 } |
| 1521 #ifdef PDF_ENABLE_XFA |
| 1522 void* CFX_FolderFontInfo::MapFontByUnicode(FX_DWORD dwUnicode, |
| 1523 int weight, |
| 1524 FX_BOOL bItalic, |
| 1525 int pitch_family) { |
| 1526 return NULL; |
| 1527 } |
| 1528 #endif |
1432 void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { | 1529 void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) { |
1433 auto it = m_FontList.find(face); | 1530 auto it = m_FontList.find(face); |
1434 return it != m_FontList.end() ? it->second : nullptr; | 1531 return it != m_FontList.end() ? it->second : nullptr; |
1435 } | 1532 } |
1436 | 1533 |
1437 FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, | 1534 FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, |
1438 FX_DWORD table, | 1535 FX_DWORD table, |
1439 uint8_t* buffer, | 1536 uint8_t* buffer, |
1440 FX_DWORD size) { | 1537 FX_DWORD size) { |
1441 if (!hFont) | 1538 if (!hFont) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 int PDF_GetStandardFontName(CFX_ByteString* name) { | 1588 int PDF_GetStandardFontName(CFX_ByteString* name) { |
1492 AltFontName* found = static_cast<AltFontName*>( | 1589 AltFontName* found = static_cast<AltFontName*>( |
1493 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), | 1590 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), |
1494 sizeof(AltFontName), CompareString)); | 1591 sizeof(AltFontName), CompareString)); |
1495 if (!found) | 1592 if (!found) |
1496 return -1; | 1593 return -1; |
1497 | 1594 |
1498 *name = g_Base14FontNames[found->m_Index]; | 1595 *name = g_Base14FontNames[found->m_Index]; |
1499 return found->m_Index; | 1596 return found->m_Index; |
1500 } | 1597 } |
OLD | NEW |