| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "core/include/fxge/fx_freetype.h" | 10 #include "core/include/fxge/fx_freetype.h" |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 m_pFontInfo->GetFontData(hFont, kTableNAME, buffer_ptr, size); | 717 m_pFontInfo->GetFontData(hFont, kTableNAME, buffer_ptr, size); |
| 718 return (bytes_read == size) ? GetNameFromTT(buffer_ptr, 6) : CFX_ByteString(); | 718 return (bytes_read == size) ? GetNameFromTT(buffer_ptr, 6) : CFX_ByteString(); |
| 719 } | 719 } |
| 720 | 720 |
| 721 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) { | 721 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) { |
| 722 if (!m_pFontInfo) { | 722 if (!m_pFontInfo) { |
| 723 return; | 723 return; |
| 724 } | 724 } |
| 725 if (m_CharsetArray.Find((FX_DWORD)charset) == -1) { | 725 if (m_CharsetArray.Find((FX_DWORD)charset) == -1) { |
| 726 m_CharsetArray.Add((FX_DWORD)charset); | 726 m_CharsetArray.Add((FX_DWORD)charset); |
| 727 m_FaceArray.Add(name); | 727 m_FaceArray.push_back(name); |
| 728 } | 728 } |
| 729 if (name == m_LastFamily) { | 729 if (name == m_LastFamily) { |
| 730 return; | 730 return; |
| 731 } | 731 } |
| 732 const uint8_t* ptr = name; | 732 const uint8_t* ptr = name; |
| 733 FX_BOOL bLocalized = FALSE; | 733 FX_BOOL bLocalized = FALSE; |
| 734 for (int i = 0; i < name.GetLength(); i++) | 734 for (int i = 0; i < name.GetLength(); i++) |
| 735 if (ptr[i] > 0x80) { | 735 if (ptr[i] > 0x80) { |
| 736 bLocalized = TRUE; | 736 bLocalized = TRUE; |
| 737 break; | 737 break; |
| 738 } | 738 } |
| 739 if (bLocalized) { | 739 if (bLocalized) { |
| 740 void* hFont = m_pFontInfo->GetFont(name); | 740 void* hFont = m_pFontInfo->GetFont(name); |
| 741 if (!hFont) { | 741 if (!hFont) { |
| 742 int iExact; | 742 int iExact; |
| 743 hFont = | 743 hFont = |
| 744 m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, name, iExact); | 744 m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, name, iExact); |
| 745 if (!hFont) { | 745 if (!hFont) { |
| 746 return; | 746 return; |
| 747 } | 747 } |
| 748 } | 748 } |
| 749 CFX_ByteString new_name = GetPSNameFromTT(hFont); | 749 CFX_ByteString new_name = GetPSNameFromTT(hFont); |
| 750 if (!new_name.IsEmpty()) { | 750 if (!new_name.IsEmpty()) { |
| 751 new_name.Insert(0, ' '); | 751 new_name.Insert(0, ' '); |
| 752 m_InstalledTTFonts.Add(new_name); | 752 m_InstalledTTFonts.push_back(new_name); |
| 753 } | 753 } |
| 754 m_pFontInfo->DeleteFont(hFont); | 754 m_pFontInfo->DeleteFont(hFont); |
| 755 } | 755 } |
| 756 m_InstalledTTFonts.Add(name); | 756 m_InstalledTTFonts.push_back(name); |
| 757 m_LastFamily = name; | 757 m_LastFamily = name; |
| 758 } | 758 } |
| 759 void CFX_FontMapper::LoadInstalledFonts() { | 759 void CFX_FontMapper::LoadInstalledFonts() { |
| 760 if (!m_pFontInfo) { | 760 if (!m_pFontInfo) { |
| 761 return; | 761 return; |
| 762 } | 762 } |
| 763 if (m_bListLoaded) { | 763 if (m_bListLoaded) { |
| 764 return; | 764 return; |
| 765 } | 765 } |
| 766 if (m_bListLoaded) { | 766 if (m_bListLoaded) { |
| 767 return; | 767 return; |
| 768 } | 768 } |
| 769 m_pFontInfo->EnumFontList(this); | 769 m_pFontInfo->EnumFontList(this); |
| 770 m_bListLoaded = TRUE; | 770 m_bListLoaded = TRUE; |
| 771 } | 771 } |
| 772 CFX_ByteString CFX_FontMapper::MatchInstalledFonts( | 772 CFX_ByteString CFX_FontMapper::MatchInstalledFonts( |
| 773 const CFX_ByteString& norm_name) { | 773 const CFX_ByteString& norm_name) { |
| 774 LoadInstalledFonts(); | 774 LoadInstalledFonts(); |
| 775 int i; | 775 int i; |
| 776 for (i = m_InstalledTTFonts.GetSize() - 1; i >= 0; i--) { | 776 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) { |
| 777 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i]); | 777 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i]); |
| 778 if (norm1 == norm_name) { | 778 if (norm1 == norm_name) { |
| 779 break; | 779 break; |
| 780 } | 780 } |
| 781 } | 781 } |
| 782 if (i < 0) { | 782 if (i < 0) { |
| 783 return CFX_ByteString(); | 783 return CFX_ByteString(); |
| 784 } | 784 } |
| 785 CFX_ByteString match = m_InstalledTTFonts[i]; | 785 CFX_ByteString match = m_InstalledTTFonts[i]; |
| 786 if (match[0] == ' ') { | 786 if (match[0] == ' ') { |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 return NULL; | 1314 return NULL; |
| 1315 } | 1315 } |
| 1316 #endif | 1316 #endif |
| 1317 CFX_FolderFontInfo::CFX_FolderFontInfo() {} | 1317 CFX_FolderFontInfo::CFX_FolderFontInfo() {} |
| 1318 CFX_FolderFontInfo::~CFX_FolderFontInfo() { | 1318 CFX_FolderFontInfo::~CFX_FolderFontInfo() { |
| 1319 for (const auto& pair : m_FontList) { | 1319 for (const auto& pair : m_FontList) { |
| 1320 delete pair.second; | 1320 delete pair.second; |
| 1321 } | 1321 } |
| 1322 } | 1322 } |
| 1323 void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) { | 1323 void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) { |
| 1324 m_PathList.Add(path); | 1324 m_PathList.push_back(path); |
| 1325 } | 1325 } |
| 1326 void CFX_FolderFontInfo::Release() { | 1326 void CFX_FolderFontInfo::Release() { |
| 1327 delete this; | 1327 delete this; |
| 1328 } | 1328 } |
| 1329 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { | 1329 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { |
| 1330 m_pMapper = pMapper; | 1330 m_pMapper = pMapper; |
| 1331 for (int i = 0; i < m_PathList.GetSize(); i++) { | 1331 for (const auto& path : m_PathList) { |
| 1332 ScanPath(m_PathList[i]); | 1332 ScanPath(path); |
| 1333 } | 1333 } |
| 1334 return TRUE; | 1334 return TRUE; |
| 1335 } | 1335 } |
| 1336 void CFX_FolderFontInfo::ScanPath(CFX_ByteString& path) { | 1336 void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) { |
| 1337 void* handle = FX_OpenFolder(path); | 1337 void* handle = FX_OpenFolder(path); |
| 1338 if (!handle) { | 1338 if (!handle) { |
| 1339 return; | 1339 return; |
| 1340 } | 1340 } |
| 1341 CFX_ByteString filename; | 1341 CFX_ByteString filename; |
| 1342 FX_BOOL bFolder; | 1342 FX_BOOL bFolder; |
| 1343 while (FX_GetNextFile(handle, filename, bFolder)) { | 1343 while (FX_GetNextFile(handle, filename, bFolder)) { |
| 1344 if (bFolder) { | 1344 if (bFolder) { |
| 1345 if (filename == "." || filename == "..") { | 1345 if (filename == "." || filename == "..") { |
| 1346 continue; | 1346 continue; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1360 #endif | 1360 #endif |
| 1361 fullpath += filename; | 1361 fullpath += filename; |
| 1362 if (bFolder) { | 1362 if (bFolder) { |
| 1363 ScanPath(fullpath); | 1363 ScanPath(fullpath); |
| 1364 } else { | 1364 } else { |
| 1365 ScanFile(fullpath); | 1365 ScanFile(fullpath); |
| 1366 } | 1366 } |
| 1367 } | 1367 } |
| 1368 FX_CloseFolder(handle); | 1368 FX_CloseFolder(handle); |
| 1369 } | 1369 } |
| 1370 void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path) { | 1370 void CFX_FolderFontInfo::ScanFile(const CFX_ByteString& path) { |
| 1371 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); | 1371 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); |
| 1372 if (!pFile) { | 1372 if (!pFile) { |
| 1373 return; | 1373 return; |
| 1374 } | 1374 } |
| 1375 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); | 1375 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); |
| 1376 FX_DWORD filesize = FXSYS_ftell(pFile); | 1376 FX_DWORD filesize = FXSYS_ftell(pFile); |
| 1377 uint8_t buffer[16]; | 1377 uint8_t buffer[16]; |
| 1378 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); | 1378 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); |
| 1379 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); | 1379 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); |
| 1380 if (readCnt != 1) { | 1380 if (readCnt != 1) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1399 for (FX_DWORD i = 0; i < nFaces; i++) { | 1399 for (FX_DWORD i = 0; i < nFaces; i++) { |
| 1400 uint8_t* p = offsets + i * 4; | 1400 uint8_t* p = offsets + i * 4; |
| 1401 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); | 1401 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); |
| 1402 } | 1402 } |
| 1403 FX_Free(offsets); | 1403 FX_Free(offsets); |
| 1404 } else { | 1404 } else { |
| 1405 ReportFace(path, pFile, filesize, 0); | 1405 ReportFace(path, pFile, filesize, 0); |
| 1406 } | 1406 } |
| 1407 FXSYS_fclose(pFile); | 1407 FXSYS_fclose(pFile); |
| 1408 } | 1408 } |
| 1409 void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, | 1409 void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path, |
| 1410 FXSYS_FILE* pFile, | 1410 FXSYS_FILE* pFile, |
| 1411 FX_DWORD filesize, | 1411 FX_DWORD filesize, |
| 1412 FX_DWORD offset) { | 1412 FX_DWORD offset) { |
| 1413 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); | 1413 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); |
| 1414 char buffer[16]; | 1414 char buffer[16]; |
| 1415 if (!FXSYS_fread(buffer, 12, 1, pFile)) { | 1415 if (!FXSYS_fread(buffer, 12, 1, pFile)) { |
| 1416 return; | 1416 return; |
| 1417 } | 1417 } |
| 1418 FX_DWORD nTables = GET_TT_SHORT(buffer + 4); | 1418 FX_DWORD nTables = GET_TT_SHORT(buffer + 4); |
| 1419 CFX_ByteString tables = FPDF_ReadStringFromFile(pFile, nTables * 16); | 1419 CFX_ByteString tables = FPDF_ReadStringFromFile(pFile, nTables * 16); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 int PDF_GetStandardFontName(CFX_ByteString* name) { | 1594 int PDF_GetStandardFontName(CFX_ByteString* name) { |
| 1595 AltFontName* found = static_cast<AltFontName*>( | 1595 AltFontName* found = static_cast<AltFontName*>( |
| 1596 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), | 1596 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), |
| 1597 sizeof(AltFontName), CompareString)); | 1597 sizeof(AltFontName), CompareString)); |
| 1598 if (!found) | 1598 if (!found) |
| 1599 return -1; | 1599 return -1; |
| 1600 | 1600 |
| 1601 *name = g_Base14FontNames[found->m_Index]; | 1601 *name = g_Base14FontNames[found->m_Index]; |
| 1602 return found->m_Index; | 1602 return found->m_Index; |
| 1603 } | 1603 } |
| OLD | NEW |