Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Side by Side Diff: core/src/fxge/ge/fx_ge_fontmap.cpp

Issue 1701883004: Banish CFX_ByteStringArray and CFX_WideStringArray to the XFA side. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nits Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdftext/text_int.h ('k') | fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData, 1281 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData,
1282 font_size, 1282 font_size,
1283 m_pFontInfo->GetFaceIndex(hFont)); 1283 m_pFontInfo->GetFaceIndex(hFont));
1284 } 1284 }
1285 } 1285 }
1286 m_pFontInfo->DeleteFont(hFont); 1286 m_pFontInfo->DeleteFont(hFont);
1287 return face; 1287 return face;
1288 } 1288 }
1289 #endif // PDF_ENABLE_XFA 1289 #endif // PDF_ENABLE_XFA
1290 1290
1291 int CFX_FontMapper::GetFaceSize() const {
1292 return pdfium::CollectionSize<int>(m_FaceArray);
1293 }
1294
1291 FX_BOOL CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const { 1295 FX_BOOL CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const {
1292 for (int i = 0; i < MM_FACE_COUNT; ++i) { 1296 for (int i = 0; i < MM_FACE_COUNT; ++i) {
1293 if (m_MMFaces[i] == face) { 1297 if (m_MMFaces[i] == face) {
1294 return TRUE; 1298 return TRUE;
1295 } 1299 }
1296 } 1300 }
1297 for (int i = 0; i < FOXIT_FACE_COUNT; ++i) { 1301 for (int i = 0; i < FOXIT_FACE_COUNT; ++i) {
1298 if (m_FoxitFaces[i] == face) { 1302 if (m_FoxitFaces[i] == face) {
1299 return TRUE; 1303 return TRUE;
1300 } 1304 }
(...skipping 13 matching lines...) Expand all
1314 return NULL; 1318 return NULL;
1315 } 1319 }
1316 #endif 1320 #endif
1317 CFX_FolderFontInfo::CFX_FolderFontInfo() {} 1321 CFX_FolderFontInfo::CFX_FolderFontInfo() {}
1318 CFX_FolderFontInfo::~CFX_FolderFontInfo() { 1322 CFX_FolderFontInfo::~CFX_FolderFontInfo() {
1319 for (const auto& pair : m_FontList) { 1323 for (const auto& pair : m_FontList) {
1320 delete pair.second; 1324 delete pair.second;
1321 } 1325 }
1322 } 1326 }
1323 void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) { 1327 void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) {
1324 m_PathList.Add(path); 1328 m_PathList.push_back(path);
1325 } 1329 }
1326 void CFX_FolderFontInfo::Release() { 1330 void CFX_FolderFontInfo::Release() {
1327 delete this; 1331 delete this;
1328 } 1332 }
1329 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { 1333 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) {
1330 m_pMapper = pMapper; 1334 m_pMapper = pMapper;
1331 for (int i = 0; i < m_PathList.GetSize(); i++) { 1335 for (const auto& path : m_PathList) {
1332 ScanPath(m_PathList[i]); 1336 ScanPath(path);
1333 } 1337 }
1334 return TRUE; 1338 return TRUE;
1335 } 1339 }
1336 void CFX_FolderFontInfo::ScanPath(CFX_ByteString& path) { 1340 void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) {
1337 void* handle = FX_OpenFolder(path); 1341 void* handle = FX_OpenFolder(path);
1338 if (!handle) { 1342 if (!handle) {
1339 return; 1343 return;
1340 } 1344 }
1341 CFX_ByteString filename; 1345 CFX_ByteString filename;
1342 FX_BOOL bFolder; 1346 FX_BOOL bFolder;
1343 while (FX_GetNextFile(handle, filename, bFolder)) { 1347 while (FX_GetNextFile(handle, filename, bFolder)) {
1344 if (bFolder) { 1348 if (bFolder) {
1345 if (filename == "." || filename == "..") { 1349 if (filename == "." || filename == "..") {
1346 continue; 1350 continue;
(...skipping 13 matching lines...) Expand all
1360 #endif 1364 #endif
1361 fullpath += filename; 1365 fullpath += filename;
1362 if (bFolder) { 1366 if (bFolder) {
1363 ScanPath(fullpath); 1367 ScanPath(fullpath);
1364 } else { 1368 } else {
1365 ScanFile(fullpath); 1369 ScanFile(fullpath);
1366 } 1370 }
1367 } 1371 }
1368 FX_CloseFolder(handle); 1372 FX_CloseFolder(handle);
1369 } 1373 }
1370 void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path) { 1374 void CFX_FolderFontInfo::ScanFile(const CFX_ByteString& path) {
1371 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); 1375 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb");
1372 if (!pFile) { 1376 if (!pFile) {
1373 return; 1377 return;
1374 } 1378 }
1375 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); 1379 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END);
1376 FX_DWORD filesize = FXSYS_ftell(pFile); 1380 FX_DWORD filesize = FXSYS_ftell(pFile);
1377 uint8_t buffer[16]; 1381 uint8_t buffer[16];
1378 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); 1382 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET);
1379 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); 1383 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile);
1380 if (readCnt != 1) { 1384 if (readCnt != 1) {
(...skipping 18 matching lines...) Expand all
1399 for (FX_DWORD i = 0; i < nFaces; i++) { 1403 for (FX_DWORD i = 0; i < nFaces; i++) {
1400 uint8_t* p = offsets + i * 4; 1404 uint8_t* p = offsets + i * 4;
1401 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); 1405 ReportFace(path, pFile, filesize, GET_TT_LONG(p));
1402 } 1406 }
1403 FX_Free(offsets); 1407 FX_Free(offsets);
1404 } else { 1408 } else {
1405 ReportFace(path, pFile, filesize, 0); 1409 ReportFace(path, pFile, filesize, 0);
1406 } 1410 }
1407 FXSYS_fclose(pFile); 1411 FXSYS_fclose(pFile);
1408 } 1412 }
1409 void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, 1413 void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path,
1410 FXSYS_FILE* pFile, 1414 FXSYS_FILE* pFile,
1411 FX_DWORD filesize, 1415 FX_DWORD filesize,
1412 FX_DWORD offset) { 1416 FX_DWORD offset) {
1413 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); 1417 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
1414 char buffer[16]; 1418 char buffer[16];
1415 if (!FXSYS_fread(buffer, 12, 1, pFile)) { 1419 if (!FXSYS_fread(buffer, 12, 1, pFile)) {
1416 return; 1420 return;
1417 } 1421 }
1418 FX_DWORD nTables = GET_TT_SHORT(buffer + 4); 1422 FX_DWORD nTables = GET_TT_SHORT(buffer + 4);
1419 CFX_ByteString tables = FPDF_ReadStringFromFile(pFile, nTables * 16); 1423 CFX_ByteString tables = FPDF_ReadStringFromFile(pFile, nTables * 16);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 int PDF_GetStandardFontName(CFX_ByteString* name) { 1598 int PDF_GetStandardFontName(CFX_ByteString* name) {
1595 AltFontName* found = static_cast<AltFontName*>( 1599 AltFontName* found = static_cast<AltFontName*>(
1596 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), 1600 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
1597 sizeof(AltFontName), CompareString)); 1601 sizeof(AltFontName), CompareString));
1598 if (!found) 1602 if (!found)
1599 return -1; 1603 return -1;
1600 1604
1601 *name = g_Base14FontNames[found->m_Index]; 1605 *name = g_Base14FontNames[found->m_Index];
1602 return found->m_Index; 1606 return found->m_Index;
1603 } 1607 }
OLDNEW
« no previous file with comments | « core/src/fpdftext/text_int.h ('k') | fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698