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

Side by Side Diff: xfa/fxfa/app/xfa_fontmgr.cpp

Issue 2362063003: Clean up xfa_fontmgr.cpp. (Closed)
Patch Set: nits Created 4 years, 2 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 | « xfa/fgas/layout/fgas_textbreak.cpp ('k') | xfa/fxfa/include/xfa_fontmgr.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 "xfa/fxfa/include/xfa_fontmgr.h" 7 #include "xfa/fxfa/include/xfa_fontmgr.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory>
10 #include <utility> 11 #include <utility>
11 12
12 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 13 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
15 #include "xfa/fgas/font/fgas_gefont.h" 16 #include "xfa/fgas/font/fgas_gefont.h"
16 #include "xfa/fxfa/include/xfa_ffapp.h" 17 #include "xfa/fxfa/include/xfa_ffapp.h"
17 #include "xfa/fxfa/include/xfa_ffdoc.h" 18 #include "xfa/fxfa/include/xfa_ffdoc.h"
18 19
20 namespace {
21
22 // The 5 names per entry are: PsName, Normal, Bold, Italic, BoldItalic.
23 const char* const g_XFAPDFFontName[][5] = {
24 {"Adobe PI Std", "AdobePIStd", "AdobePIStd", "AdobePIStd", "AdobePIStd"},
25 {"Myriad Pro Light", "MyriadPro-Light", "MyriadPro-Semibold",
26 "MyriadPro-LightIt", "MyriadPro-SemiboldIt"},
27 };
28
19 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 29 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
20 static const XFA_FONTINFO g_XFAFontsMap[] = { 30 const XFA_FONTINFO g_XFAFontsMap[] = {
21 {0x01d5d33e, L"SimSun", L"Arial", 0, 936}, 31 {0x01d5d33e, L"SimSun", L"Arial", 0, 936},
22 {0x01e4f102, L"YouYuan", L"Arial", 1, 936}, 32 {0x01e4f102, L"YouYuan", L"Arial", 1, 936},
23 {0x030549dc, L"LiSu", L"Arial", 1, 936}, 33 {0x030549dc, L"LiSu", L"Arial", 1, 936},
24 {0x032edd44, L"Simhei", L"Arial", 1, 936}, 34 {0x032edd44, L"Simhei", L"Arial", 1, 936},
25 {0x03eac6fc, L"PoorRichard-Regular", L"Arial", 2, 1252}, 35 {0x03eac6fc, L"PoorRichard-Regular", L"Arial", 2, 1252},
26 {0x03ed90e6, L"Nina", L"Arial", 0, 1252}, 36 {0x03ed90e6, L"Nina", L"Arial", 0, 1252},
27 {0x077b56b3, L"KingsoftPhoneticPlain", L"Arial", 0, 1252}, 37 {0x077b56b3, L"KingsoftPhoneticPlain", L"Arial", 0, 1252},
28 {0x078ed524, L"MicrosoftSansSerif", L"Arial", 0, 1252}, 38 {0x078ed524, L"MicrosoftSansSerif", L"Arial", 0, 1252},
29 {0x089b18a9, L"Arial", L"Arial", 0, 1252}, 39 {0x089b18a9, L"Arial", L"Arial", 0, 1252},
30 {0x0b2cad72, L"MonotypeCorsiva", L"Arial", 8, 1252}, 40 {0x0b2cad72, L"MonotypeCorsiva", L"Arial", 8, 1252},
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 {0xf1da7eb9, L"ShowcardGothic", L"Arial", 0, 1252}, 268 {0xf1da7eb9, L"ShowcardGothic", L"Arial", 0, 1252},
259 {0xf210f06a, L"ArialMT", L"Arial", 0, 1252}, 269 {0xf210f06a, L"ArialMT", L"Arial", 0, 1252},
260 {0xf477f16a, L"Latha", L"Arial", 0, 1252}, 270 {0xf477f16a, L"Latha", L"Arial", 0, 1252},
261 {0xf616f3dd, L"LiSu", L"Arial", 1, 936}, 271 {0xf616f3dd, L"LiSu", L"Arial", 1, 936},
262 {0xfa479aa6, L"MicrosoftYaHei", L"Arial", 0, 936}, 272 {0xfa479aa6, L"MicrosoftYaHei", L"Arial", 0, 936},
263 {0xfcd19697, L"BookmanOldStyle", L"Arial", 0, 1252}, 273 {0xfcd19697, L"BookmanOldStyle", L"Arial", 0, 1252},
264 {0xfe209a82, L"LucidaCalligraphy", L"Arial", 0, 1252}, 274 {0xfe209a82, L"LucidaCalligraphy", L"Arial", 0, 1252},
265 {0xfef135f8, L"AdobeHeitiStd-Regular", L"Batang,Century,Dotum", 0, 936}, 275 {0xfef135f8, L"AdobeHeitiStd-Regular", L"Batang,Century,Dotum", 0, 936},
266 }; 276 };
267 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ 277 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
268 static const XFA_FONTINFO g_XFAFontsMap[] = { 278 const XFA_FONTINFO g_XFAFontsMap[] = {
269 {0x01d5d33e, L"SimSun", 279 {0x01d5d33e, L"SimSun",
270 L"WenQuanYi Zen Hei Mono,AR PL UMing CN,AR PL UMing HK,AR PL UMing TW,AR " 280 L"WenQuanYi Zen Hei Mono,AR PL UMing CN,AR PL UMing HK,AR PL UMing TW,AR "
271 L"PL UMing TW MBE", 281 L"PL UMing TW MBE",
272 0, 936}, 282 0, 936},
273 {0x01e4f102, L"YouYuan", 283 {0x01e4f102, L"YouYuan",
274 L"WenQuanYi Zen Hei Mono,AR PL UMing CN,AR PL UMing HK,AR PL UMing TW,AR " 284 L"WenQuanYi Zen Hei Mono,AR PL UMing CN,AR PL UMing HK,AR PL UMing TW,AR "
275 L"PL UMing TW MBE", 285 L"PL UMing TW MBE",
276 1, 936}, 286 1, 936},
277 {0x030549dc, L"LiSu", 287 {0x030549dc, L"LiSu",
278 L"WenQuanYi Zen Hei,WenQuanYi Zen Hei Sharp,WenQuanYi Zen Hei " 288 L"WenQuanYi Zen Hei,WenQuanYi Zen Hei Sharp,WenQuanYi Zen Hei "
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 {0xfe209a82, L"LucidaCalligraphy", 857 {0xfe209a82, L"LucidaCalligraphy",
848 L"KacstQurn,Droid Arabic Naskh,Droid Sans Ethiopic,mry_KacstQurn,Droid " 858 L"KacstQurn,Droid Arabic Naskh,Droid Sans Ethiopic,mry_KacstQurn,Droid "
849 L"Sans Japanese,DejaVu Serif,DejaVu Sans,FreeMono", 859 L"Sans Japanese,DejaVu Serif,DejaVu Sans,FreeMono",
850 0, 1252}, 860 0, 1252},
851 {0xfef135f8, L"AdobeHeitiStd-Regular", 861 {0xfef135f8, L"AdobeHeitiStd-Regular",
852 L"WenQuanYi Zen Hei Mono,WenQuanYi Zen Hei,WenQuanYi Zen Hei " 862 L"WenQuanYi Zen Hei Mono,WenQuanYi Zen Hei,WenQuanYi Zen Hei "
853 L"Sharp,WenQuanYi Micro Hei", 863 L"Sharp,WenQuanYi Micro Hei",
854 0, 936}, 864 0, 936},
855 }; 865 };
856 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 866 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
857 static const XFA_FONTINFO g_XFAFontsMap[] = { 867 const XFA_FONTINFO g_XFAFontsMap[] = {
858 {0x01d5d33e, L"SimSun", L"STHeiti,Heiti TC,STFangsong", 0, 936}, 868 {0x01d5d33e, L"SimSun", L"STHeiti,Heiti TC,STFangsong", 0, 936},
859 {0x01e4f102, L"YouYuan", L"STHeiti,Heiti TC,STFangsong", 1, 936}, 869 {0x01e4f102, L"YouYuan", L"STHeiti,Heiti TC,STFangsong", 1, 936},
860 {0x030549dc, L"LiSu", L"STHeiti,Heiti TC,STFangsong", 1, 936}, 870 {0x030549dc, L"LiSu", L"STHeiti,Heiti TC,STFangsong", 1, 936},
861 {0x032edd44, L"Simhei", L"STHeiti,Heiti TC,STFangsong", 1, 936}, 871 {0x032edd44, L"Simhei", L"STHeiti,Heiti TC,STFangsong", 1, 936},
862 {0x03eac6fc, L"PoorRichard-Regular", 872 {0x03eac6fc, L"PoorRichard-Regular",
863 L"Noteworthy,Avenir Next Condensed,Impact", 2, 1252}, 873 L"Noteworthy,Avenir Next Condensed,Impact", 2, 1252},
864 {0x03ed90e6, L"Nina", L"Microsoft Sans Serif", 0, 1252}, 874 {0x03ed90e6, L"Nina", L"Microsoft Sans Serif", 0, 1252},
865 {0x077b56b3, L"KingsoftPhoneticPlain", 875 {0x077b56b3, L"KingsoftPhoneticPlain",
866 L"LastResort,Apple " 876 L"LastResort,Apple "
867 L"Chancery,STIXVariants,STIXSizeOneSym,STIXSizeOneSym,Apple Braille", 877 L"Chancery,STIXVariants,STIXSizeOneSym,STIXSizeOneSym,Apple Braille",
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 L"Arial Narrow,Damascus,STIXNonUnicode,American Typewriter", 0, 1252}, 1258 L"Arial Narrow,Damascus,STIXNonUnicode,American Typewriter", 0, 1252},
1249 {0xf616f3dd, L"LiSu", L"STHeiti,Heiti TC,STFangsong", 1, 936}, 1259 {0xf616f3dd, L"LiSu", L"STHeiti,Heiti TC,STFangsong", 1, 936},
1250 {0xfa479aa6, L"MicrosoftYaHei", L"Arial Unicode MS", 0, 936}, 1260 {0xfa479aa6, L"MicrosoftYaHei", L"Arial Unicode MS", 0, 936},
1251 {0xfcd19697, L"BookmanOldStyle", 1261 {0xfcd19697, L"BookmanOldStyle",
1252 L"Geeza Pro,Damascus,Andale Mono,Songti SC,Arial Unicode MS", 0, 1252}, 1262 L"Geeza Pro,Damascus,Andale Mono,Songti SC,Arial Unicode MS", 0, 1252},
1253 {0xfe209a82, L"LucidaCalligraphy", 1263 {0xfe209a82, L"LucidaCalligraphy",
1254 L"Kokonor,Damascus,STIXNonUnicode,STHeiti,Arial Black", 0, 1252}, 1264 L"Kokonor,Damascus,STIXNonUnicode,STHeiti,Arial Black", 0, 1252},
1255 {0xfef135f8, L"AdobeHeitiStd-Regular", L"Heiti TC,STHeiti", 0, 936}, 1265 {0xfef135f8, L"AdobeHeitiStd-Regular", L"Heiti TC,STHeiti", 0, 936},
1256 }; 1266 };
1257 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ 1267 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_
1258 static const XFA_FONTINFO g_XFAFontsMap[] = { 1268 const XFA_FONTINFO g_XFAFontsMap[] = {
1259 {0x01d5d33e, L"SimSun", L"Droid Sans Fallback", 0, 936}, 1269 {0x01d5d33e, L"SimSun", L"Droid Sans Fallback", 0, 936},
1260 {0x01e4f102, L"YouYuan", L"Droid Sans Fallback", 1, 936}, 1270 {0x01e4f102, L"YouYuan", L"Droid Sans Fallback", 1, 936},
1261 {0x030549dc, L"LiSu", L"Droid Sans Fallback", 1, 936}, 1271 {0x030549dc, L"LiSu", L"Droid Sans Fallback", 1, 936},
1262 {0x032edd44, L"Simhei", L"Droid Sans Fallback", 1, 936}, 1272 {0x032edd44, L"Simhei", L"Droid Sans Fallback", 1, 936},
1263 {0x03eac6fc, L"PoorRichard-Regular", 1273 {0x03eac6fc, L"PoorRichard-Regular",
1264 L"Roboto,Droid Serif,Droid Sans Mono,Droid Sans Fallback,Droid Arabic " 1274 L"Roboto,Droid Serif,Droid Sans Mono,Droid Sans Fallback,Droid Arabic "
1265 L"Naskh,Droid Sans Ethiopic", 1275 L"Naskh,Droid Sans Ethiopic",
1266 2, 1252}, 1276 2, 1252},
1267 {0x03ed90e6, L"Nina", 1277 {0x03ed90e6, L"Nina",
1268 L"Roboto,Droid Serif,Droid Sans Mono,Droid Sans Fallback", 0, 1252}, 1278 L"Roboto,Droid Serif,Droid Sans Mono,Droid Sans Fallback", 0, 1252},
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 {0xfa479aa6, L"MicrosoftYaHei", L"Droid Sans Fallback", 0, 936}, 1696 {0xfa479aa6, L"MicrosoftYaHei", L"Droid Sans Fallback", 0, 936},
1687 {0xfcd19697, L"BookmanOldStyle", 1697 {0xfcd19697, L"BookmanOldStyle",
1688 L"Droid Serif,Roboto,Droid Sans Mono,Droid Sans Fallback", 0, 1252}, 1698 L"Droid Serif,Roboto,Droid Sans Mono,Droid Sans Fallback", 0, 1252},
1689 {0xfe209a82, L"LucidaCalligraphy", 1699 {0xfe209a82, L"LucidaCalligraphy",
1690 L"Droid Arabic Naskh,Droid Sans Ethiopic,Droid Serif,Roboto,Droid Sans " 1700 L"Droid Arabic Naskh,Droid Sans Ethiopic,Droid Serif,Roboto,Droid Sans "
1691 L"Mono", 1701 L"Mono",
1692 0, 1252}, 1702 0, 1252},
1693 {0xfef135f8, L"AdobeHeitiStd-Regular", L"Droid Sans Fallback", 0, 936}, 1703 {0xfef135f8, L"AdobeHeitiStd-Regular", L"Droid Sans Fallback", 0, 936},
1694 }; 1704 };
1695 #endif 1705 #endif
1696 void XFA_LocalFontNameToEnglishName(const CFX_WideStringC& wsLocalName, 1706
1697 CFX_WideString& wsEnglishName) { 1707 CFX_WideString XFA_LocalFontNameToEnglishName(
1698 wsEnglishName = wsLocalName; 1708 const CFX_WideStringC& wsLocalName) {
1699 uint32_t dwLocalNameHash = FX_HashCode_GetW(wsLocalName, true); 1709 uint32_t dwLocalNameHash = FX_HashCode_GetW(wsLocalName, true);
1700 int32_t iStart = 0; 1710 const XFA_FONTINFO* pEnd = g_XFAFontsMap + FX_ArraySize(g_XFAFontsMap);
1701 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; 1711 const XFA_FONTINFO* pFontInfo =
1702 int32_t iMid = 0; 1712 std::lower_bound(g_XFAFontsMap, pEnd, dwLocalNameHash,
1703 do { 1713 [](const XFA_FONTINFO& entry, uint32_t hash) {
1704 iMid = (iStart + iEnd) / 2; 1714 return entry.dwFontNameHash < hash;
1705 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; 1715 });
1706 if (dwFontNameHash == dwLocalNameHash) { 1716 if (pFontInfo < pEnd && pFontInfo->dwFontNameHash == dwLocalNameHash)
1707 wsEnglishName = g_XFAFontsMap[iMid].pPsName; 1717 return pFontInfo->pPsName;
1708 break; 1718 return CFX_WideString(wsLocalName);
1709 } else if (dwFontNameHash < dwLocalNameHash) {
1710 iStart = iMid + 1;
1711 } else {
1712 iEnd = iMid - 1;
1713 }
1714 } while (iEnd >= iStart);
1715 } 1719 }
1720
1716 const XFA_FONTINFO* XFA_GetFontINFOByFontName( 1721 const XFA_FONTINFO* XFA_GetFontINFOByFontName(
1717 const CFX_WideStringC& wsFontName) { 1722 const CFX_WideStringC& wsFontName) {
1718 CFX_WideString wsFontNameTemp(wsFontName); 1723 CFX_WideString wsFontNameTemp(wsFontName);
1719 wsFontNameTemp.Remove(L' '); 1724 wsFontNameTemp.Remove(L' ');
1720 uint32_t dwCurFontNameHash = 1725 uint32_t dwCurFontNameHash =
1721 FX_HashCode_GetW(wsFontNameTemp.AsStringC(), true); 1726 FX_HashCode_GetW(wsFontNameTemp.AsStringC(), true);
1722 int32_t iStart = 0; 1727 const XFA_FONTINFO* pEnd = g_XFAFontsMap + FX_ArraySize(g_XFAFontsMap);
1723 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; 1728 const XFA_FONTINFO* pFontInfo =
1724 int32_t iMid = 0; 1729 std::lower_bound(g_XFAFontsMap, pEnd, dwCurFontNameHash,
1725 const XFA_FONTINFO* pFontInfo = nullptr; 1730 [](const XFA_FONTINFO& entry, uint32_t hash) {
1726 do { 1731 return entry.dwFontNameHash < hash;
1727 iMid = (iStart + iEnd) / 2; 1732 });
1728 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; 1733 if (pFontInfo < pEnd && pFontInfo->dwFontNameHash == dwCurFontNameHash)
1729 if (dwFontNameHash == dwCurFontNameHash) { 1734 return pFontInfo;
1730 pFontInfo = &g_XFAFontsMap[iMid]; 1735 return nullptr;
1731 break;
1732 } else if (dwFontNameHash < dwCurFontNameHash) {
1733 iStart = iMid + 1;
1734 } else {
1735 iEnd = iMid - 1;
1736 }
1737 } while (iEnd >= iStart);
1738 return pFontInfo;
1739 } 1736 }
1740 1737
1738 } // namespace
1739
1741 CXFA_DefFontMgr::CXFA_DefFontMgr() {} 1740 CXFA_DefFontMgr::CXFA_DefFontMgr() {}
1742 1741
1743 CXFA_DefFontMgr::~CXFA_DefFontMgr() { 1742 CXFA_DefFontMgr::~CXFA_DefFontMgr() {
1744 for (int32_t i = 0; i < m_CacheFonts.GetSize(); i++) 1743 for (int32_t i = 0; i < m_CacheFonts.GetSize(); i++)
1745 m_CacheFonts[i]->Release(); 1744 m_CacheFonts[i]->Release();
1746 } 1745 }
1747 1746
1748 CFGAS_GEFont* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc, 1747 CFGAS_GEFont* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc,
1749 const CFX_WideStringC& wsFontFamily, 1748 const CFX_WideStringC& wsFontFamily,
1750 uint32_t dwFontStyles, 1749 uint32_t dwFontStyles,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 1790
1792 CFGAS_GEFont* CXFA_DefFontMgr::GetDefaultFont( 1791 CFGAS_GEFont* CXFA_DefFontMgr::GetDefaultFont(
1793 CXFA_FFDoc* hDoc, 1792 CXFA_FFDoc* hDoc,
1794 const CFX_WideStringC& wsFontFamily, 1793 const CFX_WideStringC& wsFontFamily,
1795 uint32_t dwFontStyles, 1794 uint32_t dwFontStyles,
1796 uint16_t wCodePage) { 1795 uint16_t wCodePage) {
1797 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); 1796 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr();
1798 CFGAS_GEFont* pFont = 1797 CFGAS_GEFont* pFont =
1799 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); 1798 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage);
1800 if (!pFont) { 1799 if (!pFont) {
1801 pFont = pFDEFontMgr->LoadFont((const FX_WCHAR*)nullptr, dwFontStyles, 1800 pFont = pFDEFontMgr->LoadFont(static_cast<const FX_WCHAR*>(nullptr),
1802 wCodePage); 1801 dwFontStyles, wCodePage);
1803 } 1802 }
1804 1803
1805 ASSERT(pFont); 1804 ASSERT(pFont);
1806 if (pFont) 1805 if (pFont)
1807 m_CacheFonts.Add(pFont); 1806 m_CacheFonts.Add(pFont);
1808 return pFont; 1807 return pFont;
1809 } 1808 }
1810 struct XFA_PDFFONTNAME { 1809
1811 const FX_CHAR* lpPsName; 1810 CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {}
1812 const FX_CHAR* lpNormal; 1811
1813 const FX_CHAR* lpBold;
1814 const FX_CHAR* lpItalic;
1815 const FX_CHAR* lpBoldItalic;
1816 };
1817 const XFA_PDFFONTNAME g_XFAPDFFontName[] = {
1818 {"Adobe PI Std", "AdobePIStd", "AdobePIStd", "AdobePIStd", "AdobePIStd"},
1819 {"Myriad Pro Light", "MyriadPro-Light", "MyriadPro-Semibold",
1820 "MyriadPro-LightIt", "MyriadPro-SemiboldIt"},
1821 };
1822 CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) {
1823 m_pDoc = pDoc;
1824 }
1825 CXFA_PDFFontMgr::~CXFA_PDFFontMgr() { 1812 CXFA_PDFFontMgr::~CXFA_PDFFontMgr() {
1826 for (const auto& pair : m_FontMap) { 1813 for (const auto& pair : m_FontMap) {
1827 if (pair.second) 1814 if (pair.second)
1828 pair.second->Release(); 1815 pair.second->Release();
1829 } 1816 }
1830 } 1817 }
1831 CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName, 1818
1832 FX_BOOL bBold, 1819 CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(const CFX_ByteString& strPsName,
1833 FX_BOOL bItalic, 1820 bool bBold,
1821 bool bItalic,
1834 CPDF_Font** pDstPDFFont, 1822 CPDF_Font** pDstPDFFont,
1835 FX_BOOL bStrictMatch) { 1823 bool bStrictMatch) {
1836 CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); 1824 CPDF_Document* pDoc = m_pDoc->GetPDFDoc();
1837 if (!pDoc) { 1825 if (!pDoc) {
1838 return nullptr; 1826 return nullptr;
1839 } 1827 }
1840 CPDF_Dictionary* pFontSetDict = 1828 CPDF_Dictionary* pFontSetDict =
1841 pDoc->GetRoot()->GetDictFor("AcroForm")->GetDictFor("DR"); 1829 pDoc->GetRoot()->GetDictFor("AcroForm")->GetDictFor("DR");
1842 if (!pFontSetDict) { 1830 if (!pFontSetDict) {
1843 return nullptr; 1831 return nullptr;
1844 } 1832 }
1845 pFontSetDict = pFontSetDict->GetDictFor("Font"); 1833 pFontSetDict = pFontSetDict->GetDictFor("Font");
1846 if (!pFontSetDict) { 1834 if (!pFontSetDict) {
1847 return nullptr; 1835 return nullptr;
1848 } 1836 }
1849 strPsName.Remove(' '); 1837 CFX_ByteString name = strPsName;
1838 name.Remove(' ');
1850 IFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr(); 1839 IFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr();
1851 for (const auto& it : *pFontSetDict) { 1840 for (const auto& it : *pFontSetDict) {
1852 const CFX_ByteString& key = it.first; 1841 const CFX_ByteString& key = it.first;
1853 CPDF_Object* pObj = it.second; 1842 CPDF_Object* pObj = it.second;
1854 if (!PsNameMatchDRFontName(strPsName.AsStringC(), bBold, bItalic, key, 1843 if (!PsNameMatchDRFontName(name.AsStringC(), bBold, bItalic, key,
1855 bStrictMatch)) { 1844 bStrictMatch)) {
1856 continue; 1845 continue;
1857 } 1846 }
1858 CPDF_Dictionary* pFontDict = ToDictionary(pObj->GetDirect()); 1847 CPDF_Dictionary* pFontDict = ToDictionary(pObj->GetDirect());
1859 if (!pFontDict || pFontDict->GetStringFor("Type") != "Font") { 1848 if (!pFontDict || pFontDict->GetStringFor("Type") != "Font") {
1860 return nullptr; 1849 return nullptr;
1861 } 1850 }
1862 CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict); 1851 CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict);
1863 if (!pPDFFont) { 1852 if (!pPDFFont) {
1864 return nullptr; 1853 return nullptr;
1865 } 1854 }
1866 if (!pPDFFont->IsEmbedded()) { 1855 if (!pPDFFont->IsEmbedded()) {
1867 *pDstPDFFont = pPDFFont; 1856 *pDstPDFFont = pPDFFont;
1868 return nullptr; 1857 return nullptr;
1869 } 1858 }
1870 return CFGAS_GEFont::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); 1859 return CFGAS_GEFont::LoadFont(&pPDFFont->m_Font, pFDEFontMgr);
1871 } 1860 }
1872 return nullptr; 1861 return nullptr;
1873 } 1862 }
1874 1863
1875 CFGAS_GEFont* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, 1864 CFGAS_GEFont* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily,
1876 uint32_t dwFontStyles, 1865 uint32_t dwFontStyles,
1877 CPDF_Font** pPDFFont, 1866 CPDF_Font** pPDFFont,
1878 FX_BOOL bStrictMatch) { 1867 bool bStrictMatch) {
1879 uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); 1868 uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false);
1880 CFX_ByteString strKey; 1869 CFX_ByteString strKey;
1881 strKey.Format("%u%u", dwHashCode, dwFontStyles); 1870 strKey.Format("%u%u", dwHashCode, dwFontStyles);
1882 auto it = m_FontMap.find(strKey); 1871 auto it = m_FontMap.find(strKey);
1883 if (it != m_FontMap.end()) 1872 if (it != m_FontMap.end())
1884 return it->second; 1873 return it->second;
1885 CFX_ByteString bsPsName = 1874 CFX_ByteString bsPsName =
1886 CFX_ByteString::FromUnicode(CFX_WideString(wsFontFamily)); 1875 CFX_ByteString::FromUnicode(CFX_WideString(wsFontFamily));
1887 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; 1876 bool bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold;
1888 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; 1877 bool bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic;
1889 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); 1878 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic);
1890 CFGAS_GEFont* pFont = 1879 CFGAS_GEFont* pFont =
1891 FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch); 1880 FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch);
1892 if (pFont) 1881 if (pFont)
1893 m_FontMap[strKey] = pFont; 1882 m_FontMap[strKey] = pFont;
1894 return pFont; 1883 return pFont;
1895 } 1884 }
1896 1885
1897 CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName( 1886 CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName(
1898 const CFX_ByteString& strPsName, 1887 const CFX_ByteString& strPsName,
1899 FX_BOOL bBold, 1888 bool bBold,
1900 FX_BOOL bItalic) { 1889 bool bItalic) {
1901 int32_t nCount = sizeof(g_XFAPDFFontName) / sizeof(XFA_PDFFONTNAME); 1890 for (size_t i = 0; i < FX_ArraySize(g_XFAPDFFontName); ++i) {
1902 for (int32_t i = 0; i < nCount; i++) { 1891 if (strPsName == g_XFAPDFFontName[i][0]) {
1903 if (strPsName == g_XFAPDFFontName[i].lpPsName) { 1892 size_t index = 1;
1904 int32_t index = 1 + ((bItalic << 1) | bBold); 1893 if (bBold)
1905 return *(&g_XFAPDFFontName[i].lpPsName + index); 1894 ++index;
1895 if (bItalic)
1896 index += 2;
1897 return g_XFAPDFFontName[i][index];
1906 } 1898 }
1907 } 1899 }
1908 return strPsName; 1900 return strPsName;
1909 } 1901 }
1910 1902
1911 FX_BOOL CXFA_PDFFontMgr::PsNameMatchDRFontName( 1903 bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName,
1912 const CFX_ByteStringC& bsPsName, 1904 bool bBold,
1913 FX_BOOL bBold, 1905 bool bItalic,
1914 FX_BOOL bItalic, 1906 const CFX_ByteString& bsDRFontName,
1915 const CFX_ByteString& bsDRFontName, 1907 bool bStrictMatch) {
1916 FX_BOOL bStrictMatch) {
1917 CFX_ByteString bsDRName = bsDRFontName; 1908 CFX_ByteString bsDRName = bsDRFontName;
1918 bsDRName.Remove('-'); 1909 bsDRName.Remove('-');
1919 int32_t iPsLen = bsPsName.GetLength(); 1910 int32_t iPsLen = bsPsName.GetLength();
1920 int32_t nIndex = bsDRName.Find(bsPsName); 1911 int32_t nIndex = bsDRName.Find(bsPsName);
1921 if (nIndex != -1 && !bStrictMatch) { 1912 if (nIndex != -1 && !bStrictMatch)
1922 return TRUE; 1913 return true;
1923 } 1914
1924 if (nIndex != 0) { 1915 if (nIndex != 0)
1925 return FALSE; 1916 return false;
1926 } 1917
1927 int32_t iDifferLength = bsDRName.GetLength() - iPsLen; 1918 int32_t iDifferLength = bsDRName.GetLength() - iPsLen;
1928 if (iDifferLength > 1 || (bBold || bItalic)) { 1919 if (iDifferLength > 1 || (bBold || bItalic)) {
1929 int32_t iBoldIndex = bsDRName.Find("Bold"); 1920 int32_t iBoldIndex = bsDRName.Find("Bold");
1930 FX_BOOL bBoldFont = iBoldIndex > 0; 1921 bool bBoldFont = iBoldIndex > 0;
1931 if (bBold ^ bBoldFont) { 1922 if (bBold != bBoldFont)
1932 return FALSE; 1923 return false;
1933 } 1924
1934 if (bBoldFont) { 1925 if (bBoldFont) {
1935 iDifferLength = 1926 iDifferLength =
1936 std::min(iDifferLength - 4, bsDRName.GetLength() - iBoldIndex - 4); 1927 std::min(iDifferLength - 4, bsDRName.GetLength() - iBoldIndex - 4);
1937 } 1928 }
1938 FX_BOOL bItalicFont = TRUE; 1929 bool bItalicFont = true;
1939 if (bsDRName.Find("Italic") > 0) { 1930 if (bsDRName.Find("Italic") > 0) {
1940 iDifferLength -= 6; 1931 iDifferLength -= 6;
1941 } else if (bsDRName.Find("It") > 0) { 1932 } else if (bsDRName.Find("It") > 0) {
1942 iDifferLength -= 2; 1933 iDifferLength -= 2;
1943 } else if (bsDRName.Find("Oblique") > 0) { 1934 } else if (bsDRName.Find("Oblique") > 0) {
1944 iDifferLength -= 7; 1935 iDifferLength -= 7;
1945 } else { 1936 } else {
1946 bItalicFont = FALSE; 1937 bItalicFont = false;
1947 } 1938 }
1948 if (bItalic ^ bItalicFont) { 1939 if (bItalic != bItalicFont)
1949 return FALSE; 1940 return false;
1950 } 1941
1951 if (iDifferLength > 1) { 1942 if (iDifferLength > 1) {
1952 CFX_ByteString bsDRTailer = bsDRName.Right(iDifferLength); 1943 CFX_ByteString bsDRTailer = bsDRName.Right(iDifferLength);
1953 if (bsDRTailer == "MT" || bsDRTailer == "PSMT" || 1944 if (bsDRTailer == "MT" || bsDRTailer == "PSMT" ||
1954 bsDRTailer == "Regular" || bsDRTailer == "Reg") { 1945 bsDRTailer == "Regular" || bsDRTailer == "Reg") {
1955 return TRUE; 1946 return true;
1956 } 1947 }
1957 if (bBoldFont || bItalicFont) { 1948 if (bBoldFont || bItalicFont)
1958 return FALSE; 1949 return false;
1959 } 1950
1960 FX_BOOL bMatch = FALSE; 1951 bool bMatch = false;
1961 switch (bsPsName.GetAt(iPsLen - 1)) { 1952 switch (bsPsName.GetAt(iPsLen - 1)) {
1962 case 'L': { 1953 case 'L': {
1963 if (bsDRName.Right(5) == "Light") { 1954 if (bsDRName.Right(5) == "Light") {
1964 bMatch = TRUE; 1955 bMatch = true;
1965 } 1956 }
1966 } break; 1957 } break;
1967 case 'R': { 1958 case 'R': {
1968 if (bsDRName.Right(7) == "Regular" || bsDRName.Right(3) == "Reg") { 1959 if (bsDRName.Right(7) == "Regular" || bsDRName.Right(3) == "Reg") {
1969 bMatch = TRUE; 1960 bMatch = true;
1970 } 1961 }
1971 } break; 1962 } break;
1972 case 'M': { 1963 case 'M': {
1973 if (bsDRName.Right(5) == "Medium") { 1964 if (bsDRName.Right(5) == "Medium") {
1974 bMatch = TRUE; 1965 bMatch = true;
1975 } 1966 }
1976 } break; 1967 } break;
1977 default: 1968 default:
1978 break; 1969 break;
1979 } 1970 }
1980 return bMatch; 1971 return bMatch;
1981 } 1972 }
1982 } 1973 }
1983 return TRUE; 1974 return true;
1984 } 1975 }
1985 FX_BOOL CXFA_PDFFontMgr::GetCharWidth(CFGAS_GEFont* pFont, 1976
1986 FX_WCHAR wUnicode, 1977 bool CXFA_PDFFontMgr::GetCharWidth(const CFGAS_GEFont* pFont,
1987 int32_t& iWidth, 1978 FX_WCHAR wUnicode,
1988 FX_BOOL bCharCode) { 1979 bool bCharCode,
1980 int32_t* pWidth) {
1989 if (wUnicode != 0x20 || bCharCode) 1981 if (wUnicode != 0x20 || bCharCode)
1990 return FALSE; 1982 return false;
1991 1983
1992 auto it = m_FDE2PDFFont.find(pFont); 1984 auto it = m_FDE2PDFFont.find(pFont);
1993 if (it == m_FDE2PDFFont.end()) 1985 if (it == m_FDE2PDFFont.end())
1994 return FALSE; 1986 return false;
1995 1987
1996 CPDF_Font* pPDFFont = it->second; 1988 CPDF_Font* pPDFFont = it->second;
1997 iWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode)); 1989 *pWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode));
1998 return TRUE; 1990 return true;
1991 }
1992
1993 void CXFA_PDFFontMgr::SetFont(const CFGAS_GEFont* pFont, CPDF_Font* pPDFFont) {
1994 m_FDE2PDFFont[pFont] = pPDFFont;
1999 } 1995 }
2000 1996
2001 CXFA_FontMgr::CXFA_FontMgr() {} 1997 CXFA_FontMgr::CXFA_FontMgr() {}
2002 1998
2003 CXFA_FontMgr::~CXFA_FontMgr() {} 1999 CXFA_FontMgr::~CXFA_FontMgr() {}
2004 2000
2005 CFGAS_GEFont* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, 2001 CFGAS_GEFont* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc,
2006 const CFX_WideStringC& wsFontFamily, 2002 const CFX_WideStringC& wsFontFamily,
2007 uint32_t dwFontStyles, 2003 uint32_t dwFontStyles,
2008 uint16_t wCodePage) { 2004 uint16_t wCodePage) {
2009 uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false); 2005 uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false);
2010 CFX_ByteString bsKey; 2006 CFX_ByteString bsKey;
2011 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); 2007 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage);
2012 auto iter = m_FontMap.find(bsKey); 2008 auto iter = m_FontMap.find(bsKey);
2013 if (iter != m_FontMap.end()) 2009 if (iter != m_FontMap.end())
2014 return iter->second; 2010 return iter->second;
2015 CFX_WideString wsEnglishName; 2011
2016 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); 2012 CFX_WideString wsEnglishName = XFA_LocalFontNameToEnglishName(wsFontFamily);
2017 auto it = m_PDFFontMgrMap.find(hDoc); 2013 auto it = m_PDFFontMgrMap.find(hDoc);
2018 CXFA_PDFFontMgr* pMgr = 2014 CXFA_PDFFontMgr* pMgr =
2019 it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr; 2015 it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr;
2020 CPDF_Font* pPDFFont = nullptr; 2016 CPDF_Font* pPDFFont = nullptr;
2021 CFGAS_GEFont* pFont = nullptr; 2017 CFGAS_GEFont* pFont = nullptr;
2022 if (pMgr) { 2018 if (pMgr) {
2023 pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont); 2019 pFont =
2020 pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont, TRUE);
2024 if (pFont) 2021 if (pFont)
2025 return pFont; 2022 return pFont;
2026 } 2023 }
2027 if (!pFont && m_pDefFontMgr) 2024 if (!pFont && m_pDefFontMgr)
2028 pFont = m_pDefFontMgr->GetFont(hDoc, wsFontFamily, dwFontStyles, wCodePage); 2025 pFont = m_pDefFontMgr->GetFont(hDoc, wsFontFamily, dwFontStyles, wCodePage);
2029 2026
2030 if (!pFont && pMgr) { 2027 if (!pFont && pMgr) {
2031 pPDFFont = nullptr; 2028 pPDFFont = nullptr;
2032 pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont, 2029 pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont,
2033 FALSE); 2030 FALSE);
2034 if (pFont) 2031 if (pFont)
2035 return pFont; 2032 return pFont;
2036 } 2033 }
2037 if (!pFont && m_pDefFontMgr) { 2034 if (!pFont && m_pDefFontMgr) {
2038 pFont = m_pDefFontMgr->GetDefaultFont(hDoc, wsFontFamily, dwFontStyles, 2035 pFont = m_pDefFontMgr->GetDefaultFont(hDoc, wsFontFamily, dwFontStyles,
2039 wCodePage); 2036 wCodePage);
2040 } 2037 }
2041 if (pFont) { 2038 if (pFont) {
2042 if (pPDFFont) { 2039 if (pPDFFont) {
2043 pMgr->m_FDE2PDFFont[pFont] = pPDFFont; 2040 pMgr->SetFont(pFont, pPDFFont);
2044 pFont->SetFontProvider(pMgr); 2041 pFont->SetFontProvider(pMgr);
2045 } 2042 }
2046 m_FontMap[bsKey] = pFont; 2043 m_FontMap[bsKey] = pFont;
2047 } 2044 }
2048 return pFont; 2045 return pFont;
2049 } 2046 }
2050 2047
2051 void CXFA_FontMgr::LoadDocFonts(CXFA_FFDoc* hDoc) { 2048 void CXFA_FontMgr::LoadDocFonts(CXFA_FFDoc* hDoc) {
2052 if (!m_PDFFontMgrMap[hDoc]) 2049 if (!m_PDFFontMgrMap[hDoc])
2053 m_PDFFontMgrMap[hDoc].reset(new CXFA_PDFFontMgr(hDoc)); 2050 m_PDFFontMgrMap[hDoc].reset(new CXFA_PDFFontMgr(hDoc));
2054 } 2051 }
2055 2052
2056 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) { 2053 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) {
2057 m_PDFFontMgrMap.erase(hDoc); 2054 m_PDFFontMgrMap.erase(hDoc);
2058 } 2055 }
2059 2056
2060 void CXFA_FontMgr::SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) { 2057 void CXFA_FontMgr::SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) {
2061 m_pDefFontMgr = std::move(pFontMgr); 2058 m_pDefFontMgr = std::move(pFontMgr);
2062 } 2059 }
OLDNEW
« no previous file with comments | « xfa/fgas/layout/fgas_textbreak.cpp ('k') | xfa/fxfa/include/xfa_fontmgr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698