Chromium Code Reviews| 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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 | 734 |
| 735 std::vector<uint8_t> buffer(size); | 735 std::vector<uint8_t> buffer(size); |
| 736 uint8_t* buffer_ptr = buffer.data(); | 736 uint8_t* buffer_ptr = buffer.data(); |
| 737 uint32_t bytes_read = | 737 uint32_t bytes_read = |
| 738 m_pFontInfo->GetFontData(hFont, kTableNAME, buffer_ptr, size); | 738 m_pFontInfo->GetFontData(hFont, kTableNAME, buffer_ptr, size); |
| 739 return bytes_read == size ? GetNameFromTT(buffer_ptr, bytes_read, 6) | 739 return bytes_read == size ? GetNameFromTT(buffer_ptr, bytes_read, 6) |
| 740 : CFX_ByteString(); | 740 : CFX_ByteString(); |
| 741 } | 741 } |
| 742 | 742 |
| 743 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) { | 743 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) { |
| 744 if (!m_pFontInfo) { | 744 if (!m_pFontInfo) |
| 745 return; | 745 return; |
| 746 } | 746 |
| 747 if (m_CharsetArray.Find((uint32_t)charset) == -1) { | 747 if (m_CharsetArray.Find((uint32_t)charset) == -1) |
| 748 m_CharsetArray.Add((uint32_t)charset); | 748 m_CharsetArray.Add((uint32_t)charset); |
| 749 m_FaceArray.push_back(name); | 749 m_FaceArray.push_back(name); |
|
dsinclair
2016/04/07 19:03:22
This bit is the actual code change, m_FaceArray is
hong_zhang
2016/04/11 07:06:04
Actually we cannot make this change.
See line 1160
dsinclair
2016/04/11 13:52:11
Ok, I've removed m_CharsetArray and merged it with
hong_zhang
2016/04/12 17:19:21
It is good. I confirmed with my team. Feel free to
| |
| 750 } | 750 if (name == m_LastFamily) |
| 751 if (name == m_LastFamily) { | |
| 752 return; | 751 return; |
| 753 } | 752 |
| 754 const uint8_t* ptr = name; | 753 const uint8_t* ptr = name; |
| 755 FX_BOOL bLocalized = FALSE; | 754 FX_BOOL bLocalized = FALSE; |
| 756 for (int i = 0; i < name.GetLength(); i++) | 755 for (int i = 0; i < name.GetLength(); i++) { |
| 757 if (ptr[i] > 0x80) { | 756 if (ptr[i] > 0x80) { |
| 758 bLocalized = TRUE; | 757 bLocalized = TRUE; |
| 759 break; | 758 break; |
| 760 } | 759 } |
| 760 } | |
| 761 | |
| 761 if (bLocalized) { | 762 if (bLocalized) { |
| 762 void* hFont = m_pFontInfo->GetFont(name); | 763 void* hFont = m_pFontInfo->GetFont(name); |
| 763 if (!hFont) { | 764 if (!hFont) { |
| 764 int iExact; | 765 int iExact; |
| 765 hFont = | 766 hFont = |
| 766 m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, name, iExact); | 767 m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, name, iExact); |
| 767 if (!hFont) { | 768 if (!hFont) |
| 768 return; | 769 return; |
| 769 } | |
| 770 } | 770 } |
| 771 | |
| 771 CFX_ByteString new_name = GetPSNameFromTT(hFont); | 772 CFX_ByteString new_name = GetPSNameFromTT(hFont); |
| 772 if (!new_name.IsEmpty()) { | 773 if (!new_name.IsEmpty()) { |
| 773 new_name.Insert(0, ' '); | 774 new_name.Insert(0, ' '); |
| 774 m_InstalledTTFonts.push_back(new_name); | 775 m_InstalledTTFonts.push_back(new_name); |
| 775 } | 776 } |
| 776 m_pFontInfo->DeleteFont(hFont); | 777 m_pFontInfo->DeleteFont(hFont); |
| 777 } | 778 } |
| 778 m_InstalledTTFonts.push_back(name); | 779 m_InstalledTTFonts.push_back(name); |
| 779 m_LastFamily = name; | 780 m_LastFamily = name; |
| 780 } | 781 } |
| 782 | |
| 781 void CFX_FontMapper::LoadInstalledFonts() { | 783 void CFX_FontMapper::LoadInstalledFonts() { |
| 782 if (!m_pFontInfo) { | 784 if (!m_pFontInfo) { |
| 783 return; | 785 return; |
| 784 } | 786 } |
| 785 if (m_bListLoaded) { | 787 if (m_bListLoaded) { |
| 786 return; | 788 return; |
| 787 } | 789 } |
| 788 if (m_bListLoaded) { | 790 if (m_bListLoaded) { |
| 789 return; | 791 return; |
| 790 } | 792 } |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1364 } | 1366 } |
| 1365 } | 1367 } |
| 1366 void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) { | 1368 void CFX_FolderFontInfo::AddPath(const CFX_ByteStringC& path) { |
| 1367 m_PathList.push_back(path); | 1369 m_PathList.push_back(path); |
| 1368 } | 1370 } |
| 1369 void CFX_FolderFontInfo::Release() { | 1371 void CFX_FolderFontInfo::Release() { |
| 1370 delete this; | 1372 delete this; |
| 1371 } | 1373 } |
| 1372 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { | 1374 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { |
| 1373 m_pMapper = pMapper; | 1375 m_pMapper = pMapper; |
| 1374 for (const auto& path : m_PathList) { | 1376 for (const auto& path : m_PathList) |
| 1375 ScanPath(path); | 1377 ScanPath(path); |
| 1376 } | |
| 1377 return TRUE; | 1378 return TRUE; |
| 1378 } | 1379 } |
| 1379 void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) { | 1380 void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) { |
| 1380 void* handle = FX_OpenFolder(path); | 1381 void* handle = FX_OpenFolder(path); |
| 1381 if (!handle) { | 1382 if (!handle) |
| 1382 return; | 1383 return; |
| 1383 } | 1384 |
| 1384 CFX_ByteString filename; | 1385 CFX_ByteString filename; |
| 1385 FX_BOOL bFolder; | 1386 FX_BOOL bFolder; |
| 1386 while (FX_GetNextFile(handle, filename, bFolder)) { | 1387 while (FX_GetNextFile(handle, filename, bFolder)) { |
| 1387 if (bFolder) { | 1388 if (bFolder) { |
| 1388 if (filename == "." || filename == "..") { | 1389 if (filename == "." || filename == "..") |
| 1389 continue; | 1390 continue; |
| 1390 } | |
| 1391 } else { | 1391 } else { |
| 1392 CFX_ByteString ext = filename.Right(4); | 1392 CFX_ByteString ext = filename.Right(4); |
| 1393 ext.MakeUpper(); | 1393 ext.MakeUpper(); |
| 1394 if (ext != ".TTF" && ext != ".OTF" && ext != ".TTC") { | 1394 if (ext != ".TTF" && ext != ".OTF" && ext != ".TTC") |
| 1395 continue; | 1395 continue; |
| 1396 } | |
| 1397 } | 1396 } |
| 1397 | |
| 1398 CFX_ByteString fullpath = path; | 1398 CFX_ByteString fullpath = path; |
| 1399 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1399 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 1400 fullpath += "\\"; | 1400 fullpath += "\\"; |
| 1401 #else | 1401 #else |
| 1402 fullpath += "/"; | 1402 fullpath += "/"; |
| 1403 #endif | 1403 #endif |
| 1404 | |
| 1404 fullpath += filename; | 1405 fullpath += filename; |
| 1405 if (bFolder) { | 1406 bFolder ? ScanPath(fullpath) : ScanFile(fullpath); |
| 1406 ScanPath(fullpath); | |
| 1407 } else { | |
| 1408 ScanFile(fullpath); | |
| 1409 } | |
| 1410 } | 1407 } |
| 1411 FX_CloseFolder(handle); | 1408 FX_CloseFolder(handle); |
| 1412 } | 1409 } |
| 1410 | |
| 1413 void CFX_FolderFontInfo::ScanFile(const CFX_ByteString& path) { | 1411 void CFX_FolderFontInfo::ScanFile(const CFX_ByteString& path) { |
| 1414 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); | 1412 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); |
| 1415 if (!pFile) { | 1413 if (!pFile) |
| 1416 return; | 1414 return; |
| 1417 } | 1415 |
| 1418 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); | 1416 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); |
| 1417 | |
| 1419 uint32_t filesize = FXSYS_ftell(pFile); | 1418 uint32_t filesize = FXSYS_ftell(pFile); |
| 1420 uint8_t buffer[16]; | 1419 uint8_t buffer[16]; |
| 1421 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); | 1420 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); |
| 1421 | |
| 1422 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); | 1422 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); |
| 1423 if (readCnt != 1) { | 1423 if (readCnt != 1) { |
| 1424 FXSYS_fclose(pFile); | 1424 FXSYS_fclose(pFile); |
| 1425 return; | 1425 return; |
| 1426 } | 1426 } |
| 1427 | 1427 |
| 1428 if (GET_TT_LONG(buffer) == kTableTTCF) { | 1428 if (GET_TT_LONG(buffer) == kTableTTCF) { |
| 1429 uint32_t nFaces = GET_TT_LONG(buffer + 8); | 1429 uint32_t nFaces = GET_TT_LONG(buffer + 8); |
| 1430 if (nFaces > std::numeric_limits<uint32_t>::max() / 4) { | 1430 if (nFaces > std::numeric_limits<uint32_t>::max() / 4) { |
| 1431 FXSYS_fclose(pFile); | 1431 FXSYS_fclose(pFile); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1448 ReportFace(path, pFile, filesize, 0); | 1448 ReportFace(path, pFile, filesize, 0); |
| 1449 } | 1449 } |
| 1450 FXSYS_fclose(pFile); | 1450 FXSYS_fclose(pFile); |
| 1451 } | 1451 } |
| 1452 void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path, | 1452 void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path, |
| 1453 FXSYS_FILE* pFile, | 1453 FXSYS_FILE* pFile, |
| 1454 uint32_t filesize, | 1454 uint32_t filesize, |
| 1455 uint32_t offset) { | 1455 uint32_t offset) { |
| 1456 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); | 1456 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); |
| 1457 char buffer[16]; | 1457 char buffer[16]; |
| 1458 if (!FXSYS_fread(buffer, 12, 1, pFile)) { | 1458 if (!FXSYS_fread(buffer, 12, 1, pFile)) |
| 1459 return; | 1459 return; |
| 1460 } | 1460 |
| 1461 uint32_t nTables = GET_TT_SHORT(buffer + 4); | 1461 uint32_t nTables = GET_TT_SHORT(buffer + 4); |
| 1462 CFX_ByteString tables = FPDF_ReadStringFromFile(pFile, nTables * 16); | 1462 CFX_ByteString tables = FPDF_ReadStringFromFile(pFile, nTables * 16); |
| 1463 if (tables.IsEmpty()) { | 1463 if (tables.IsEmpty()) |
| 1464 return; | 1464 return; |
| 1465 } | 1465 |
| 1466 CFX_ByteString names = | 1466 CFX_ByteString names = |
| 1467 FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616d65); | 1467 FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616d65); |
| 1468 if (names.IsEmpty()) { | 1468 if (names.IsEmpty()) |
| 1469 return; | 1469 return; |
| 1470 } | 1470 |
| 1471 CFX_ByteString facename = GetNameFromTT(names, names.GetLength(), 1); | 1471 CFX_ByteString facename = GetNameFromTT(names, names.GetLength(), 1); |
| 1472 if (facename.IsEmpty()) { | 1472 if (facename.IsEmpty()) |
| 1473 return; | 1473 return; |
| 1474 } | 1474 |
| 1475 CFX_ByteString style = GetNameFromTT(names, names.GetLength(), 2); | 1475 CFX_ByteString style = GetNameFromTT(names, names.GetLength(), 2); |
| 1476 if (style != "Regular") { | 1476 if (style != "Regular") |
| 1477 facename += " " + style; | 1477 facename += " " + style; |
| 1478 } | 1478 |
| 1479 if (pdfium::ContainsKey(m_FontList, facename)) | 1479 if (pdfium::ContainsKey(m_FontList, facename)) |
| 1480 return; | 1480 return; |
| 1481 | 1481 |
| 1482 CFX_FontFaceInfo* pInfo = | 1482 CFX_FontFaceInfo* pInfo = |
| 1483 new CFX_FontFaceInfo(path, facename, tables, offset, filesize); | 1483 new CFX_FontFaceInfo(path, facename, tables, offset, filesize); |
| 1484 CFX_ByteString os2 = FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f32); | 1484 CFX_ByteString os2 = FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f32); |
| 1485 if (os2.GetLength() >= 86) { | 1485 if (os2.GetLength() >= 86) { |
| 1486 const uint8_t* p = (const uint8_t*)os2 + 78; | 1486 const uint8_t* p = (const uint8_t*)os2 + 78; |
| 1487 uint32_t codepages = GET_TT_LONG(p); | 1487 uint32_t codepages = GET_TT_LONG(p); |
| 1488 if (codepages & (1 << 17)) { | 1488 if (codepages & (1 << 17)) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1502 pInfo->m_Charsets |= CHARSET_FLAG_KOREAN; | 1502 pInfo->m_Charsets |= CHARSET_FLAG_KOREAN; |
| 1503 } | 1503 } |
| 1504 if (codepages & (1 << 31)) { | 1504 if (codepages & (1 << 31)) { |
| 1505 m_pMapper->AddInstalledFont(facename, FXFONT_SYMBOL_CHARSET); | 1505 m_pMapper->AddInstalledFont(facename, FXFONT_SYMBOL_CHARSET); |
| 1506 pInfo->m_Charsets |= CHARSET_FLAG_SYMBOL; | 1506 pInfo->m_Charsets |= CHARSET_FLAG_SYMBOL; |
| 1507 } | 1507 } |
| 1508 } | 1508 } |
| 1509 m_pMapper->AddInstalledFont(facename, FXFONT_ANSI_CHARSET); | 1509 m_pMapper->AddInstalledFont(facename, FXFONT_ANSI_CHARSET); |
| 1510 pInfo->m_Charsets |= CHARSET_FLAG_ANSI; | 1510 pInfo->m_Charsets |= CHARSET_FLAG_ANSI; |
| 1511 pInfo->m_Styles = 0; | 1511 pInfo->m_Styles = 0; |
| 1512 if (style.Find("Bold") > -1) { | 1512 if (style.Find("Bold") > -1) |
| 1513 pInfo->m_Styles |= FXFONT_BOLD; | 1513 pInfo->m_Styles |= FXFONT_BOLD; |
| 1514 } | 1514 if (style.Find("Italic") > -1 || style.Find("Oblique") > -1) |
| 1515 if (style.Find("Italic") > -1 || style.Find("Oblique") > -1) { | |
| 1516 pInfo->m_Styles |= FXFONT_ITALIC; | 1515 pInfo->m_Styles |= FXFONT_ITALIC; |
| 1517 } | 1516 if (facename.Find("Serif") > -1) |
| 1518 if (facename.Find("Serif") > -1) { | |
| 1519 pInfo->m_Styles |= FXFONT_SERIF; | 1517 pInfo->m_Styles |= FXFONT_SERIF; |
| 1520 } | 1518 |
| 1521 m_FontList[facename] = pInfo; | 1519 m_FontList[facename] = pInfo; |
| 1522 } | 1520 } |
| 1523 | 1521 |
| 1524 void* CFX_FolderFontInfo::GetSubstFont(const CFX_ByteString& face) { | 1522 void* CFX_FolderFontInfo::GetSubstFont(const CFX_ByteString& face) { |
| 1525 for (size_t iBaseFont = 0; iBaseFont < FX_ArraySize(Base14Substs); | 1523 for (size_t iBaseFont = 0; iBaseFont < FX_ArraySize(Base14Substs); |
| 1526 iBaseFont++) { | 1524 iBaseFont++) { |
| 1527 if (face == Base14Substs[iBaseFont].m_pName) { | 1525 if (face == Base14Substs[iBaseFont].m_pName) |
| 1528 return GetFont(Base14Substs[iBaseFont].m_pSubstName); | 1526 return GetFont(Base14Substs[iBaseFont].m_pSubstName); |
| 1529 } | |
| 1530 } | 1527 } |
| 1531 return nullptr; | 1528 return nullptr; |
| 1532 } | 1529 } |
| 1533 | 1530 |
| 1534 void* CFX_FolderFontInfo::FindFont(int weight, | 1531 void* CFX_FolderFontInfo::FindFont(int weight, |
| 1535 FX_BOOL bItalic, | 1532 FX_BOOL bItalic, |
| 1536 int charset, | 1533 int charset, |
| 1537 int pitch_family, | 1534 int pitch_family, |
| 1538 const FX_CHAR* family, | 1535 const FX_CHAR* family, |
| 1539 FX_BOOL bMatchName) { | 1536 FX_BOOL bMatchName) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1643 int PDF_GetStandardFontName(CFX_ByteString* name) { | 1640 int PDF_GetStandardFontName(CFX_ByteString* name) { |
| 1644 AltFontName* found = static_cast<AltFontName*>( | 1641 AltFontName* found = static_cast<AltFontName*>( |
| 1645 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), | 1642 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), |
| 1646 sizeof(AltFontName), CompareString)); | 1643 sizeof(AltFontName), CompareString)); |
| 1647 if (!found) | 1644 if (!found) |
| 1648 return -1; | 1645 return -1; |
| 1649 | 1646 |
| 1650 *name = g_Base14FontNames[found->m_Index]; | 1647 *name = g_Base14FontNames[found->m_Index]; |
| 1651 return found->m_Index; | 1648 return found->m_Index; |
| 1652 } | 1649 } |
| OLD | NEW |