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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 const uint8_t* ptr = name.raw_str(); | 751 const uint8_t* ptr = name.raw_str(); |
752 FX_BOOL bLocalized = FALSE; | 752 FX_BOOL bLocalized = FALSE; |
753 for (int i = 0; i < name.GetLength(); i++) { | 753 for (int i = 0; i < name.GetLength(); i++) { |
754 if (ptr[i] > 0x80) { | 754 if (ptr[i] > 0x80) { |
755 bLocalized = TRUE; | 755 bLocalized = TRUE; |
756 break; | 756 break; |
757 } | 757 } |
758 } | 758 } |
759 | 759 |
760 if (bLocalized) { | 760 if (bLocalized) { |
761 void* hFont = m_pFontInfo->GetFont(name); | 761 void* hFont = m_pFontInfo->GetFont(name.c_str()); |
762 if (!hFont) { | 762 if (!hFont) { |
763 int iExact; | 763 int iExact; |
764 hFont = | 764 hFont = m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, |
765 m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, name, iExact); | 765 name.c_str(), iExact); |
766 if (!hFont) | 766 if (!hFont) |
767 return; | 767 return; |
768 } | 768 } |
769 | 769 |
770 CFX_ByteString new_name = GetPSNameFromTT(hFont); | 770 CFX_ByteString new_name = GetPSNameFromTT(hFont); |
771 if (!new_name.IsEmpty()) { | 771 if (!new_name.IsEmpty()) { |
772 new_name.Insert(0, ' '); | 772 new_name.Insert(0, ' '); |
773 m_InstalledTTFonts.push_back(new_name); | 773 m_InstalledTTFonts.push_back(new_name); |
774 } | 774 } |
775 m_pFontInfo->DeleteFont(hFont); | 775 m_pFontInfo->DeleteFont(hFont); |
(...skipping 13 matching lines...) Expand all Loading... |
789 return; | 789 return; |
790 } | 790 } |
791 m_pFontInfo->EnumFontList(this); | 791 m_pFontInfo->EnumFontList(this); |
792 m_bListLoaded = TRUE; | 792 m_bListLoaded = TRUE; |
793 } | 793 } |
794 CFX_ByteString CFX_FontMapper::MatchInstalledFonts( | 794 CFX_ByteString CFX_FontMapper::MatchInstalledFonts( |
795 const CFX_ByteString& norm_name) { | 795 const CFX_ByteString& norm_name) { |
796 LoadInstalledFonts(); | 796 LoadInstalledFonts(); |
797 int i; | 797 int i; |
798 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) { | 798 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) { |
799 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i]); | 799 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i].c_str()); |
800 if (norm1 == norm_name) { | 800 if (norm1 == norm_name) { |
801 break; | 801 break; |
802 } | 802 } |
803 } | 803 } |
804 if (i < 0) { | 804 if (i < 0) { |
805 return CFX_ByteString(); | 805 return CFX_ByteString(); |
806 } | 806 } |
807 CFX_ByteString match = m_InstalledTTFonts[i]; | 807 CFX_ByteString match = m_InstalledTTFonts[i]; |
808 if (match[0] == ' ') { | 808 if (match[0] == ' ') { |
809 match = m_InstalledTTFonts[i + 1]; | 809 match = m_InstalledTTFonts[i + 1]; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 } | 965 } |
966 if (flags & FXFONT_SCRIPT) { | 966 if (flags & FXFONT_SCRIPT) { |
967 PitchFamily |= FXFONT_FF_SCRIPT; | 967 PitchFamily |= FXFONT_FF_SCRIPT; |
968 } | 968 } |
969 if (flags & FXFONT_FIXED_PITCH) { | 969 if (flags & FXFONT_FIXED_PITCH) { |
970 PitchFamily |= FXFONT_FF_FIXEDPITCH; | 970 PitchFamily |= FXFONT_FF_FIXEDPITCH; |
971 } | 971 } |
972 } | 972 } |
973 if (!style.IsEmpty()) { | 973 if (!style.IsEmpty()) { |
974 int nLen = style.GetLength(); | 974 int nLen = style.GetLength(); |
975 const FX_CHAR* pStyle = style; | 975 const FX_CHAR* pStyle = style.c_str(); |
976 int i = 0; | 976 int i = 0; |
977 FX_BOOL bFirstItem = TRUE; | 977 FX_BOOL bFirstItem = TRUE; |
978 CFX_ByteString buf; | 978 CFX_ByteString buf; |
979 while (i < nLen) { | 979 while (i < nLen) { |
980 buf = ParseStyle(pStyle, nLen, i); | 980 buf = ParseStyle(pStyle, nLen, i); |
981 int32_t nRet = GetStyleType(buf, FALSE); | 981 int32_t nRet = GetStyleType(buf, FALSE); |
982 if ((i && !bStyleAvail) || (!i && nRet < 0)) { | 982 if ((i && !bStyleAvail) || (!i && nRet < 0)) { |
983 family = SubstName; | 983 family = SubstName; |
984 iBaseFont = 12; | 984 iBaseFont = 12; |
985 break; | 985 break; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 Charset == FXFONT_HANGEUL_CHARSET || | 1038 Charset == FXFONT_HANGEUL_CHARSET || |
1039 Charset == FXFONT_CHINESEBIG5_CHARSET) { | 1039 Charset == FXFONT_CHINESEBIG5_CHARSET) { |
1040 bCJK = TRUE; | 1040 bCJK = TRUE; |
1041 } | 1041 } |
1042 if (!m_pFontInfo) { | 1042 if (!m_pFontInfo) { |
1043 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 1043 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
1044 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, | 1044 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, |
1045 PitchFamily); | 1045 PitchFamily); |
1046 } | 1046 } |
1047 family = GetFontFamily(family, nStyle); | 1047 family = GetFontFamily(family, nStyle); |
1048 CFX_ByteString match = MatchInstalledFonts(TT_NormalizeName(family)); | 1048 CFX_ByteString match = MatchInstalledFonts(TT_NormalizeName(family.c_str())); |
1049 if (match.IsEmpty() && family != SubstName && | 1049 if (match.IsEmpty() && family != SubstName && |
1050 (!bHasComma && (!bHasHypen || (bHasHypen && !bStyleAvail)))) { | 1050 (!bHasComma && (!bHasHypen || (bHasHypen && !bStyleAvail)))) { |
1051 match = MatchInstalledFonts(TT_NormalizeName(SubstName)); | 1051 match = MatchInstalledFonts(TT_NormalizeName(SubstName.c_str())); |
1052 } | 1052 } |
1053 if (match.IsEmpty() && iBaseFont >= 12) { | 1053 if (match.IsEmpty() && iBaseFont >= 12) { |
1054 if (!bCJK) { | 1054 if (!bCJK) { |
1055 if (!CheckSupportThirdPartFont(family, PitchFamily)) { | 1055 if (!CheckSupportThirdPartFont(family, PitchFamily)) { |
1056 if (italic_angle != 0) { | 1056 if (italic_angle != 0) { |
1057 bItalic = TRUE; | 1057 bItalic = TRUE; |
1058 } else { | 1058 } else { |
1059 bItalic = FALSE; | 1059 bItalic = FALSE; |
1060 } | 1060 } |
1061 weight = old_weight; | 1061 weight = old_weight; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 family = g_Base14FontNames[iBaseFont]; | 1097 family = g_Base14FontNames[iBaseFont]; |
1098 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 1098 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
1099 } | 1099 } |
1100 } else { | 1100 } else { |
1101 if (flags & FXFONT_ITALIC) { | 1101 if (flags & FXFONT_ITALIC) { |
1102 bItalic = TRUE; | 1102 bItalic = TRUE; |
1103 } | 1103 } |
1104 } | 1104 } |
1105 iExact = !match.IsEmpty(); | 1105 iExact = !match.IsEmpty(); |
1106 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, | 1106 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, |
1107 family, iExact); | 1107 family.c_str(), iExact); |
1108 if (iExact) { | 1108 if (iExact) { |
1109 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; | 1109 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; |
1110 } | 1110 } |
1111 if (!hFont) { | 1111 if (!hFont) { |
1112 #ifdef PDF_ENABLE_XFA | 1112 #ifdef PDF_ENABLE_XFA |
1113 if (flags & FXFONT_EXACTMATCH) { | 1113 if (flags & FXFONT_EXACTMATCH) { |
1114 return NULL; | 1114 return NULL; |
1115 } | 1115 } |
1116 #endif // PDF_ENABLE_XFA | 1116 #endif // PDF_ENABLE_XFA |
1117 if (bCJK) { | 1117 if (bCJK) { |
1118 if (italic_angle != 0) { | 1118 if (italic_angle != 0) { |
1119 bItalic = TRUE; | 1119 bItalic = TRUE; |
1120 } else { | 1120 } else { |
1121 bItalic = FALSE; | 1121 bItalic = FALSE; |
1122 } | 1122 } |
1123 weight = old_weight; | 1123 weight = old_weight; |
1124 } | 1124 } |
1125 if (!match.IsEmpty()) { | 1125 if (!match.IsEmpty()) { |
1126 hFont = m_pFontInfo->GetFont(match); | 1126 hFont = m_pFontInfo->GetFont(match.c_str()); |
1127 if (!hFont) { | 1127 if (!hFont) { |
1128 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, | 1128 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, |
1129 PitchFamily); | 1129 PitchFamily); |
1130 } | 1130 } |
1131 } else { | 1131 } else { |
1132 if (Charset == FXFONT_SYMBOL_CHARSET) { | 1132 if (Charset == FXFONT_SYMBOL_CHARSET) { |
1133 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ | 1133 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ |
1134 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | 1134 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ |
1135 if (SubstName == "Symbol") { | 1135 if (SubstName == "Symbol") { |
1136 pSubstFont->m_Family = "Chrome Symbol"; | 1136 pSubstFont->m_Family = "Chrome Symbol"; |
(...skipping 21 matching lines...) Expand all Loading... |
1158 | 1158 |
1159 auto it = | 1159 auto it = |
1160 std::find_if(m_FaceArray.begin(), m_FaceArray.end(), | 1160 std::find_if(m_FaceArray.begin(), m_FaceArray.end(), |
1161 [Charset](const FaceData& face) { | 1161 [Charset](const FaceData& face) { |
1162 return face.charset == static_cast<uint32_t>(Charset); | 1162 return face.charset == static_cast<uint32_t>(Charset); |
1163 }); | 1163 }); |
1164 if (it == m_FaceArray.end()) { | 1164 if (it == m_FaceArray.end()) { |
1165 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, | 1165 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, |
1166 PitchFamily); | 1166 PitchFamily); |
1167 } | 1167 } |
1168 hFont = m_pFontInfo->GetFont(it->name); | 1168 hFont = m_pFontInfo->GetFont(it->name.c_str()); |
1169 } | 1169 } |
1170 } | 1170 } |
1171 pSubstFont->m_ExtHandle = m_pFontInfo->RetainFont(hFont); | 1171 pSubstFont->m_ExtHandle = m_pFontInfo->RetainFont(hFont); |
1172 if (!hFont) | 1172 if (!hFont) |
1173 return nullptr; | 1173 return nullptr; |
1174 | 1174 |
1175 m_pFontInfo->GetFaceName(hFont, SubstName); | 1175 m_pFontInfo->GetFaceName(hFont, SubstName); |
1176 if (Charset == FXFONT_DEFAULT_CHARSET) { | 1176 if (Charset == FXFONT_DEFAULT_CHARSET) { |
1177 m_pFontInfo->GetFontCharset(hFont, Charset); | 1177 m_pFontInfo->GetFontCharset(hFont, Charset); |
1178 } | 1178 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 void CFX_FolderFontInfo::Release() { | 1374 void CFX_FolderFontInfo::Release() { |
1375 delete this; | 1375 delete this; |
1376 } | 1376 } |
1377 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { | 1377 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { |
1378 m_pMapper = pMapper; | 1378 m_pMapper = pMapper; |
1379 for (const auto& path : m_PathList) | 1379 for (const auto& path : m_PathList) |
1380 ScanPath(path); | 1380 ScanPath(path); |
1381 return TRUE; | 1381 return TRUE; |
1382 } | 1382 } |
1383 void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) { | 1383 void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) { |
1384 void* handle = FX_OpenFolder(path); | 1384 void* handle = FX_OpenFolder(path.c_str()); |
1385 if (!handle) | 1385 if (!handle) |
1386 return; | 1386 return; |
1387 | 1387 |
1388 CFX_ByteString filename; | 1388 CFX_ByteString filename; |
1389 FX_BOOL bFolder; | 1389 FX_BOOL bFolder; |
1390 while (FX_GetNextFile(handle, filename, bFolder)) { | 1390 while (FX_GetNextFile(handle, filename, bFolder)) { |
1391 if (bFolder) { | 1391 if (bFolder) { |
1392 if (filename == "." || filename == "..") | 1392 if (filename == "." || filename == "..") |
1393 continue; | 1393 continue; |
1394 } else { | 1394 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
1405 fullpath += "/"; | 1405 fullpath += "/"; |
1406 #endif | 1406 #endif |
1407 | 1407 |
1408 fullpath += filename; | 1408 fullpath += filename; |
1409 bFolder ? ScanPath(fullpath) : ScanFile(fullpath); | 1409 bFolder ? ScanPath(fullpath) : ScanFile(fullpath); |
1410 } | 1410 } |
1411 FX_CloseFolder(handle); | 1411 FX_CloseFolder(handle); |
1412 } | 1412 } |
1413 | 1413 |
1414 void CFX_FolderFontInfo::ScanFile(const CFX_ByteString& path) { | 1414 void CFX_FolderFontInfo::ScanFile(const CFX_ByteString& path) { |
1415 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); | 1415 FXSYS_FILE* pFile = FXSYS_fopen(path.c_str(), "rb"); |
1416 if (!pFile) | 1416 if (!pFile) |
1417 return; | 1417 return; |
1418 | 1418 |
1419 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); | 1419 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); |
1420 | 1420 |
1421 uint32_t filesize = FXSYS_ftell(pFile); | 1421 uint32_t filesize = FXSYS_ftell(pFile); |
1422 uint8_t buffer[16]; | 1422 uint8_t buffer[16]; |
1423 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); | 1423 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); |
1424 | 1424 |
1425 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); | 1425 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 if (GET_TT_LONG(p) == table) { | 1609 if (GET_TT_LONG(p) == table) { |
1610 offset = GET_TT_LONG(p + 8); | 1610 offset = GET_TT_LONG(p + 8); |
1611 datasize = GET_TT_LONG(p + 12); | 1611 datasize = GET_TT_LONG(p + 12); |
1612 } | 1612 } |
1613 } | 1613 } |
1614 } | 1614 } |
1615 | 1615 |
1616 if (!datasize || size < datasize) | 1616 if (!datasize || size < datasize) |
1617 return datasize; | 1617 return datasize; |
1618 | 1618 |
1619 FXSYS_FILE* pFile = FXSYS_fopen(pFont->m_FilePath, "rb"); | 1619 FXSYS_FILE* pFile = FXSYS_fopen(pFont->m_FilePath.c_str(), "rb"); |
1620 if (!pFile) | 1620 if (!pFile) |
1621 return 0; | 1621 return 0; |
1622 | 1622 |
1623 if (FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET) < 0 || | 1623 if (FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET) < 0 || |
1624 FXSYS_fread(buffer, datasize, 1, pFile) != 1) { | 1624 FXSYS_fread(buffer, datasize, 1, pFile) != 1) { |
1625 datasize = 0; | 1625 datasize = 0; |
1626 } | 1626 } |
1627 FXSYS_fclose(pFile); | 1627 FXSYS_fclose(pFile); |
1628 return datasize; | 1628 return datasize; |
1629 } | 1629 } |
(...skipping 14 matching lines...) Expand all Loading... |
1644 int PDF_GetStandardFontName(CFX_ByteString* name) { | 1644 int PDF_GetStandardFontName(CFX_ByteString* name) { |
1645 AltFontName* found = static_cast<AltFontName*>( | 1645 AltFontName* found = static_cast<AltFontName*>( |
1646 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), | 1646 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), |
1647 sizeof(AltFontName), CompareString)); | 1647 sizeof(AltFontName), CompareString)); |
1648 if (!found) | 1648 if (!found) |
1649 return -1; | 1649 return -1; |
1650 | 1650 |
1651 *name = g_Base14FontNames[found->m_Index]; | 1651 *name = g_Base14FontNames[found->m_Index]; |
1652 return found->m_Index; | 1652 return found->m_Index; |
1653 } | 1653 } |
OLD | NEW |