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 "xfa/fxfa/include/xfa_fontmgr.h" | 7 #include "xfa/fxfa/include/xfa_fontmgr.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 {0xfe209a82, L"LucidaCalligraphy", | 1687 {0xfe209a82, L"LucidaCalligraphy", |
1688 L"Droid Arabic Naskh,Droid Sans Ethiopic,Droid Serif,Roboto,Droid Sans " | 1688 L"Droid Arabic Naskh,Droid Sans Ethiopic,Droid Serif,Roboto,Droid Sans " |
1689 L"Mono", | 1689 L"Mono", |
1690 0, 1252}, | 1690 0, 1252}, |
1691 {0xfef135f8, L"AdobeHeitiStd-Regular", L"Droid Sans Fallback", 0, 936}, | 1691 {0xfef135f8, L"AdobeHeitiStd-Regular", L"Droid Sans Fallback", 0, 936}, |
1692 }; | 1692 }; |
1693 #endif | 1693 #endif |
1694 void XFA_LocalFontNameToEnglishName(const CFX_WideStringC& wsLocalName, | 1694 void XFA_LocalFontNameToEnglishName(const CFX_WideStringC& wsLocalName, |
1695 CFX_WideString& wsEnglishName) { | 1695 CFX_WideString& wsEnglishName) { |
1696 wsEnglishName = wsLocalName; | 1696 wsEnglishName = wsLocalName; |
1697 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ | 1697 uint32_t dwLocalNameHash = FX_HashCode_GetW(wsLocalName, true); |
1698 _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ | |
1699 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ | |
1700 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | |
1701 uint32_t dwLocalNameHash = FX_HashCode_String_GetW( | |
1702 wsLocalName.c_str(), wsLocalName.GetLength(), TRUE); | |
1703 int32_t iStart = 0; | 1698 int32_t iStart = 0; |
1704 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; | 1699 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; |
1705 int32_t iMid = 0; | 1700 int32_t iMid = 0; |
1706 do { | 1701 do { |
1707 iMid = (iStart + iEnd) / 2; | 1702 iMid = (iStart + iEnd) / 2; |
1708 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; | 1703 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; |
1709 if (dwFontNameHash == dwLocalNameHash) { | 1704 if (dwFontNameHash == dwLocalNameHash) { |
1710 wsEnglishName = g_XFAFontsMap[iMid].pPsName; | 1705 wsEnglishName = g_XFAFontsMap[iMid].pPsName; |
1711 break; | 1706 break; |
1712 } else if (dwFontNameHash < dwLocalNameHash) { | 1707 } else if (dwFontNameHash < dwLocalNameHash) { |
1713 iStart = iMid + 1; | 1708 iStart = iMid + 1; |
1714 } else { | 1709 } else { |
1715 iEnd = iMid - 1; | 1710 iEnd = iMid - 1; |
1716 } | 1711 } |
1717 } while (iEnd >= iStart); | 1712 } while (iEnd >= iStart); |
1718 #endif | |
1719 } | 1713 } |
1720 const XFA_FONTINFO* XFA_GetFontINFOByFontName( | 1714 const XFA_FONTINFO* XFA_GetFontINFOByFontName( |
1721 const CFX_WideStringC& wsFontName) { | 1715 const CFX_WideStringC& wsFontName) { |
1722 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ | |
1723 _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ | |
1724 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ | |
1725 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | |
1726 CFX_WideString wsFontNameTemp = wsFontName; | 1716 CFX_WideString wsFontNameTemp = wsFontName; |
1727 wsFontNameTemp.Remove(L' '); | 1717 wsFontNameTemp.Remove(L' '); |
1728 uint32_t dwCurFontNameHash = FX_HashCode_String_GetW( | 1718 uint32_t dwCurFontNameHash = |
1729 wsFontNameTemp.c_str(), wsFontNameTemp.GetLength(), TRUE); | 1719 FX_HashCode_GetW(wsFontNameTemp.AsStringC(), true); |
1730 int32_t iStart = 0; | 1720 int32_t iStart = 0; |
1731 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; | 1721 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; |
1732 int32_t iMid = 0; | 1722 int32_t iMid = 0; |
1733 const XFA_FONTINFO* pFontInfo = NULL; | 1723 const XFA_FONTINFO* pFontInfo = NULL; |
1734 do { | 1724 do { |
1735 iMid = (iStart + iEnd) / 2; | 1725 iMid = (iStart + iEnd) / 2; |
1736 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; | 1726 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; |
1737 if (dwFontNameHash == dwCurFontNameHash) { | 1727 if (dwFontNameHash == dwCurFontNameHash) { |
1738 pFontInfo = &g_XFAFontsMap[iMid]; | 1728 pFontInfo = &g_XFAFontsMap[iMid]; |
1739 break; | 1729 break; |
1740 } else if (dwFontNameHash < dwCurFontNameHash) { | 1730 } else if (dwFontNameHash < dwCurFontNameHash) { |
1741 iStart = iMid + 1; | 1731 iStart = iMid + 1; |
1742 } else { | 1732 } else { |
1743 iEnd = iMid - 1; | 1733 iEnd = iMid - 1; |
1744 } | 1734 } |
1745 } while (iEnd >= iStart); | 1735 } while (iEnd >= iStart); |
1746 return pFontInfo; | 1736 return pFontInfo; |
1747 #else | |
1748 return NULL; | |
1749 #endif | |
1750 } | 1737 } |
1751 | 1738 |
1752 CXFA_DefFontMgr::~CXFA_DefFontMgr() { | 1739 CXFA_DefFontMgr::~CXFA_DefFontMgr() { |
1753 int32_t iCounts = m_CacheFonts.GetSize(); | 1740 int32_t iCounts = m_CacheFonts.GetSize(); |
1754 for (int32_t i = 0; i < iCounts; i++) { | 1741 for (int32_t i = 0; i < iCounts; i++) { |
1755 ((IFX_Font*)m_CacheFonts[i])->Release(); | 1742 ((IFX_Font*)m_CacheFonts[i])->Release(); |
1756 } | 1743 } |
1757 m_CacheFonts.RemoveAll(); | 1744 m_CacheFonts.RemoveAll(); |
1758 } | 1745 } |
1759 | 1746 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 return NULL; | 1871 return NULL; |
1885 } | 1872 } |
1886 return IFX_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); | 1873 return IFX_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); |
1887 } | 1874 } |
1888 return NULL; | 1875 return NULL; |
1889 } | 1876 } |
1890 IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, | 1877 IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, |
1891 uint32_t dwFontStyles, | 1878 uint32_t dwFontStyles, |
1892 CPDF_Font** pPDFFont, | 1879 CPDF_Font** pPDFFont, |
1893 FX_BOOL bStrictMatch) { | 1880 FX_BOOL bStrictMatch) { |
1894 uint32_t dwHashCode = | 1881 uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); |
1895 FX_HashCode_String_GetW(wsFontFamily.c_str(), wsFontFamily.GetLength()); | |
1896 CFX_ByteString strKey; | 1882 CFX_ByteString strKey; |
1897 strKey.Format("%u%u", dwHashCode, dwFontStyles); | 1883 strKey.Format("%u%u", dwHashCode, dwFontStyles); |
1898 auto it = m_FontMap.find(strKey); | 1884 auto it = m_FontMap.find(strKey); |
1899 if (it != m_FontMap.end()) | 1885 if (it != m_FontMap.end()) |
1900 return it->second; | 1886 return it->second; |
1901 CFX_ByteString bsPsName = CFX_ByteString::FromUnicode(wsFontFamily); | 1887 CFX_ByteString bsPsName = CFX_ByteString::FromUnicode(wsFontFamily); |
1902 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; | 1888 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; |
1903 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; | 1889 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; |
1904 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); | 1890 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); |
1905 IFX_Font* pFont = | 1891 IFX_Font* pFont = |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2011 return TRUE; | 1997 return TRUE; |
2012 } | 1998 } |
2013 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} | 1999 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} |
2014 CXFA_FontMgr::~CXFA_FontMgr() { | 2000 CXFA_FontMgr::~CXFA_FontMgr() { |
2015 DelAllMgrMap(); | 2001 DelAllMgrMap(); |
2016 } | 2002 } |
2017 IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, | 2003 IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, |
2018 const CFX_WideStringC& wsFontFamily, | 2004 const CFX_WideStringC& wsFontFamily, |
2019 uint32_t dwFontStyles, | 2005 uint32_t dwFontStyles, |
2020 uint16_t wCodePage) { | 2006 uint16_t wCodePage) { |
2021 uint32_t dwHash = FX_HashCode_String_GetW(wsFontFamily.c_str(), | 2007 uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false); |
2022 wsFontFamily.GetLength(), FALSE); | |
2023 CFX_ByteString bsKey; | 2008 CFX_ByteString bsKey; |
2024 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); | 2009 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); |
2025 auto it = m_FontMap.find(bsKey); | 2010 auto it = m_FontMap.find(bsKey); |
2026 if (it != m_FontMap.end()) | 2011 if (it != m_FontMap.end()) |
2027 return it->second; | 2012 return it->second; |
2028 CFX_WideString wsEnglishName; | 2013 CFX_WideString wsEnglishName; |
2029 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); | 2014 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); |
2030 CXFA_PDFFontMgr* pMgr = (CXFA_PDFFontMgr*)m_PDFFontMgrArray.GetValueAt(hDoc); | 2015 CXFA_PDFFontMgr* pMgr = (CXFA_PDFFontMgr*)m_PDFFontMgrArray.GetValueAt(hDoc); |
2031 CPDF_Font* pPDFFont = NULL; | 2016 CPDF_Font* pPDFFont = NULL; |
2032 IFX_Font* pFont = NULL; | 2017 IFX_Font* pFont = NULL; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 CXFA_PDFFontMgr* pMgr = NULL; | 2062 CXFA_PDFFontMgr* pMgr = NULL; |
2078 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); | 2063 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); |
2079 delete pMgr; | 2064 delete pMgr; |
2080 } | 2065 } |
2081 m_PDFFontMgrArray.RemoveAll(); | 2066 m_PDFFontMgrArray.RemoveAll(); |
2082 m_FontMap.clear(); | 2067 m_FontMap.clear(); |
2083 } | 2068 } |
2084 void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) { | 2069 void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) { |
2085 m_pDefFontMgr = pFontMgr; | 2070 m_pDefFontMgr = pFontMgr; |
2086 } | 2071 } |
OLD | NEW |