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/app/xfa_fontmgr.h" | 7 #include "xfa/fxfa/app/xfa_fontmgr.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ |
1698 _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ | 1698 _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ |
1699 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ | 1699 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ |
1700 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | 1700 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ |
1701 FX_DWORD dwLocalNameHash = FX_HashCode_String_GetW( | 1701 uint32_t dwLocalNameHash = FX_HashCode_String_GetW( |
1702 wsLocalName.GetPtr(), wsLocalName.GetLength(), TRUE); | 1702 wsLocalName.GetPtr(), wsLocalName.GetLength(), TRUE); |
1703 int32_t iStart = 0; | 1703 int32_t iStart = 0; |
1704 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; | 1704 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; |
1705 int32_t iMid = 0; | 1705 int32_t iMid = 0; |
1706 do { | 1706 do { |
1707 iMid = (iStart + iEnd) / 2; | 1707 iMid = (iStart + iEnd) / 2; |
1708 FX_DWORD dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; | 1708 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; |
1709 if (dwFontNameHash == dwLocalNameHash) { | 1709 if (dwFontNameHash == dwLocalNameHash) { |
1710 wsEnglishName = g_XFAFontsMap[iMid].pPsName; | 1710 wsEnglishName = g_XFAFontsMap[iMid].pPsName; |
1711 break; | 1711 break; |
1712 } else if (dwFontNameHash < dwLocalNameHash) { | 1712 } else if (dwFontNameHash < dwLocalNameHash) { |
1713 iStart = iMid + 1; | 1713 iStart = iMid + 1; |
1714 } else { | 1714 } else { |
1715 iEnd = iMid - 1; | 1715 iEnd = iMid - 1; |
1716 } | 1716 } |
1717 } while (iEnd >= iStart); | 1717 } while (iEnd >= iStart); |
1718 #endif | 1718 #endif |
1719 } | 1719 } |
1720 const XFA_FONTINFO* XFA_GetFontINFOByFontName( | 1720 const XFA_FONTINFO* XFA_GetFontINFOByFontName( |
1721 const CFX_WideStringC& wsFontName) { | 1721 const CFX_WideStringC& wsFontName) { |
1722 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ | 1722 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ |
1723 _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ | 1723 _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ |
1724 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ | 1724 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ |
1725 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | 1725 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ |
1726 CFX_WideString wsFontNameTemp = wsFontName; | 1726 CFX_WideString wsFontNameTemp = wsFontName; |
1727 wsFontNameTemp.Remove(L' '); | 1727 wsFontNameTemp.Remove(L' '); |
1728 FX_DWORD dwCurFontNameHash = | 1728 uint32_t dwCurFontNameHash = |
1729 FX_HashCode_String_GetW(wsFontNameTemp, wsFontNameTemp.GetLength(), TRUE); | 1729 FX_HashCode_String_GetW(wsFontNameTemp, wsFontNameTemp.GetLength(), TRUE); |
1730 int32_t iStart = 0; | 1730 int32_t iStart = 0; |
1731 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; | 1731 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; |
1732 int32_t iMid = 0; | 1732 int32_t iMid = 0; |
1733 const XFA_FONTINFO* pFontInfo = NULL; | 1733 const XFA_FONTINFO* pFontInfo = NULL; |
1734 do { | 1734 do { |
1735 iMid = (iStart + iEnd) / 2; | 1735 iMid = (iStart + iEnd) / 2; |
1736 FX_DWORD dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; | 1736 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; |
1737 if (dwFontNameHash == dwCurFontNameHash) { | 1737 if (dwFontNameHash == dwCurFontNameHash) { |
1738 pFontInfo = &g_XFAFontsMap[iMid]; | 1738 pFontInfo = &g_XFAFontsMap[iMid]; |
1739 break; | 1739 break; |
1740 } else if (dwFontNameHash < dwCurFontNameHash) { | 1740 } else if (dwFontNameHash < dwCurFontNameHash) { |
1741 iStart = iMid + 1; | 1741 iStart = iMid + 1; |
1742 } else { | 1742 } else { |
1743 iEnd = iMid - 1; | 1743 iEnd = iMid - 1; |
1744 } | 1744 } |
1745 } while (iEnd >= iStart); | 1745 } while (iEnd >= iStart); |
1746 return pFontInfo; | 1746 return pFontInfo; |
(...skipping 10 matching lines...) Expand all Loading... |
1757 CXFA_DefFontMgr::~CXFA_DefFontMgr() { | 1757 CXFA_DefFontMgr::~CXFA_DefFontMgr() { |
1758 int32_t iCounts = m_CacheFonts.GetSize(); | 1758 int32_t iCounts = m_CacheFonts.GetSize(); |
1759 for (int32_t i = 0; i < iCounts; i++) { | 1759 for (int32_t i = 0; i < iCounts; i++) { |
1760 ((IFX_Font*)m_CacheFonts[i])->Release(); | 1760 ((IFX_Font*)m_CacheFonts[i])->Release(); |
1761 } | 1761 } |
1762 m_CacheFonts.RemoveAll(); | 1762 m_CacheFonts.RemoveAll(); |
1763 } | 1763 } |
1764 | 1764 |
1765 IFX_Font* CXFA_DefFontMgr::GetFont(IXFA_Doc* hDoc, | 1765 IFX_Font* CXFA_DefFontMgr::GetFont(IXFA_Doc* hDoc, |
1766 const CFX_WideStringC& wsFontFamily, | 1766 const CFX_WideStringC& wsFontFamily, |
1767 FX_DWORD dwFontStyles, | 1767 uint32_t dwFontStyles, |
1768 uint16_t wCodePage) { | 1768 uint16_t wCodePage) { |
1769 CFX_WideString wsFontName = wsFontFamily; | 1769 CFX_WideString wsFontName = wsFontFamily; |
1770 IFX_FontMgr* pFDEFontMgr = | 1770 IFX_FontMgr* pFDEFontMgr = |
1771 static_cast<CXFA_FFDoc*>(hDoc)->GetApp()->GetFDEFontMgr(); | 1771 static_cast<CXFA_FFDoc*>(hDoc)->GetApp()->GetFDEFontMgr(); |
1772 IFX_Font* pFont = pFDEFontMgr->LoadFont(wsFontName, dwFontStyles, wCodePage); | 1772 IFX_Font* pFont = pFDEFontMgr->LoadFont(wsFontName, dwFontStyles, wCodePage); |
1773 if (!pFont) { | 1773 if (!pFont) { |
1774 const XFA_FONTINFO* pCurFont = XFA_GetFontINFOByFontName(wsFontName); | 1774 const XFA_FONTINFO* pCurFont = XFA_GetFontINFOByFontName(wsFontName); |
1775 if (pCurFont && pCurFont->pReplaceFont) { | 1775 if (pCurFont && pCurFont->pReplaceFont) { |
1776 FX_DWORD dwStyle = 0; | 1776 uint32_t dwStyle = 0; |
1777 if (dwFontStyles & FX_FONTSTYLE_Bold) { | 1777 if (dwFontStyles & FX_FONTSTYLE_Bold) { |
1778 dwStyle |= FX_FONTSTYLE_Bold; | 1778 dwStyle |= FX_FONTSTYLE_Bold; |
1779 } | 1779 } |
1780 if (dwFontStyles & FX_FONTSTYLE_Italic) { | 1780 if (dwFontStyles & FX_FONTSTYLE_Italic) { |
1781 dwStyle |= FX_FONTSTYLE_Italic; | 1781 dwStyle |= FX_FONTSTYLE_Italic; |
1782 } | 1782 } |
1783 const FX_WCHAR* pReplace = pCurFont->pReplaceFont; | 1783 const FX_WCHAR* pReplace = pCurFont->pReplaceFont; |
1784 int32_t iLength = FXSYS_wcslen(pReplace); | 1784 int32_t iLength = FXSYS_wcslen(pReplace); |
1785 while (iLength > 0) { | 1785 while (iLength > 0) { |
1786 const FX_WCHAR* pNameText = pReplace; | 1786 const FX_WCHAR* pNameText = pReplace; |
(...skipping 14 matching lines...) Expand all Loading... |
1801 } | 1801 } |
1802 } | 1802 } |
1803 if (pFont) { | 1803 if (pFont) { |
1804 m_CacheFonts.Add(pFont); | 1804 m_CacheFonts.Add(pFont); |
1805 } | 1805 } |
1806 return pFont; | 1806 return pFont; |
1807 } | 1807 } |
1808 | 1808 |
1809 IFX_Font* CXFA_DefFontMgr::GetDefaultFont(IXFA_Doc* hDoc, | 1809 IFX_Font* CXFA_DefFontMgr::GetDefaultFont(IXFA_Doc* hDoc, |
1810 const CFX_WideStringC& wsFontFamily, | 1810 const CFX_WideStringC& wsFontFamily, |
1811 FX_DWORD dwFontStyles, | 1811 uint32_t dwFontStyles, |
1812 uint16_t wCodePage) { | 1812 uint16_t wCodePage) { |
1813 IFX_FontMgr* pFDEFontMgr = ((CXFA_FFDoc*)hDoc)->GetApp()->GetFDEFontMgr(); | 1813 IFX_FontMgr* pFDEFontMgr = ((CXFA_FFDoc*)hDoc)->GetApp()->GetFDEFontMgr(); |
1814 IFX_Font* pFont = | 1814 IFX_Font* pFont = |
1815 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); | 1815 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); |
1816 if (!pFont) | 1816 if (!pFont) |
1817 pFont = | 1817 pFont = |
1818 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); | 1818 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); |
1819 FXSYS_assert(pFont); | 1819 FXSYS_assert(pFont); |
1820 if (pFont) { | 1820 if (pFont) { |
1821 m_CacheFonts.Add(pFont); | 1821 m_CacheFonts.Add(pFont); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 } | 1884 } |
1885 if (!pPDFFont->IsEmbedded()) { | 1885 if (!pPDFFont->IsEmbedded()) { |
1886 *pDstPDFFont = pPDFFont; | 1886 *pDstPDFFont = pPDFFont; |
1887 return NULL; | 1887 return NULL; |
1888 } | 1888 } |
1889 return IFX_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); | 1889 return IFX_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); |
1890 } | 1890 } |
1891 return NULL; | 1891 return NULL; |
1892 } | 1892 } |
1893 IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, | 1893 IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, |
1894 FX_DWORD dwFontStyles, | 1894 uint32_t dwFontStyles, |
1895 CPDF_Font** pPDFFont, | 1895 CPDF_Font** pPDFFont, |
1896 FX_BOOL bStrictMatch) { | 1896 FX_BOOL bStrictMatch) { |
1897 FX_DWORD dwHashCode = | 1897 uint32_t dwHashCode = |
1898 FX_HashCode_String_GetW(wsFontFamily.GetPtr(), wsFontFamily.GetLength()); | 1898 FX_HashCode_String_GetW(wsFontFamily.GetPtr(), wsFontFamily.GetLength()); |
1899 CFX_ByteString strKey; | 1899 CFX_ByteString strKey; |
1900 strKey.Format("%u%u", dwHashCode, dwFontStyles); | 1900 strKey.Format("%u%u", dwHashCode, dwFontStyles); |
1901 auto it = m_FontMap.find(strKey); | 1901 auto it = m_FontMap.find(strKey); |
1902 if (it != m_FontMap.end()) | 1902 if (it != m_FontMap.end()) |
1903 return it->second; | 1903 return it->second; |
1904 CFX_ByteString bsPsName = CFX_ByteString::FromUnicode(wsFontFamily); | 1904 CFX_ByteString bsPsName = CFX_ByteString::FromUnicode(wsFontFamily); |
1905 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; | 1905 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; |
1906 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; | 1906 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; |
1907 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); | 1907 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 wUnicode = (FX_WCHAR)pPDFFont->CharCodeFromUnicode(wUnicode); | 2013 wUnicode = (FX_WCHAR)pPDFFont->CharCodeFromUnicode(wUnicode); |
2014 iWidth = pPDFFont->GetCharWidthF(wUnicode); | 2014 iWidth = pPDFFont->GetCharWidthF(wUnicode); |
2015 return TRUE; | 2015 return TRUE; |
2016 } | 2016 } |
2017 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} | 2017 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} |
2018 CXFA_FontMgr::~CXFA_FontMgr() { | 2018 CXFA_FontMgr::~CXFA_FontMgr() { |
2019 DelAllMgrMap(); | 2019 DelAllMgrMap(); |
2020 } | 2020 } |
2021 IFX_Font* CXFA_FontMgr::GetFont(IXFA_Doc* hDoc, | 2021 IFX_Font* CXFA_FontMgr::GetFont(IXFA_Doc* hDoc, |
2022 const CFX_WideStringC& wsFontFamily, | 2022 const CFX_WideStringC& wsFontFamily, |
2023 FX_DWORD dwFontStyles, | 2023 uint32_t dwFontStyles, |
2024 uint16_t wCodePage) { | 2024 uint16_t wCodePage) { |
2025 FX_DWORD dwHash = FX_HashCode_String_GetW(wsFontFamily.GetPtr(), | 2025 uint32_t dwHash = FX_HashCode_String_GetW(wsFontFamily.GetPtr(), |
2026 wsFontFamily.GetLength(), FALSE); | 2026 wsFontFamily.GetLength(), FALSE); |
2027 CFX_ByteString bsKey; | 2027 CFX_ByteString bsKey; |
2028 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); | 2028 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); |
2029 auto it = m_FontMap.find(bsKey); | 2029 auto it = m_FontMap.find(bsKey); |
2030 if (it != m_FontMap.end()) | 2030 if (it != m_FontMap.end()) |
2031 return it->second; | 2031 return it->second; |
2032 CFX_WideString wsEnglishName; | 2032 CFX_WideString wsEnglishName; |
2033 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); | 2033 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); |
2034 CXFA_PDFFontMgr* pMgr = (CXFA_PDFFontMgr*)m_PDFFontMgrArray.GetValueAt(hDoc); | 2034 CXFA_PDFFontMgr* pMgr = (CXFA_PDFFontMgr*)m_PDFFontMgrArray.GetValueAt(hDoc); |
2035 CPDF_Font* pPDFFont = NULL; | 2035 CPDF_Font* pPDFFont = NULL; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2080 CXFA_PDFFontMgr* pMgr = NULL; | 2080 CXFA_PDFFontMgr* pMgr = NULL; |
2081 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); | 2081 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); |
2082 delete pMgr; | 2082 delete pMgr; |
2083 } | 2083 } |
2084 m_PDFFontMgrArray.RemoveAll(); | 2084 m_PDFFontMgrArray.RemoveAll(); |
2085 m_FontMap.clear(); | 2085 m_FontMap.clear(); |
2086 } | 2086 } |
2087 void CXFA_FontMgr::SetDefFontMgr(IXFA_FontMgr* pFontMgr) { | 2087 void CXFA_FontMgr::SetDefFontMgr(IXFA_FontMgr* pFontMgr) { |
2088 m_pDefFontMgr = pFontMgr; | 2088 m_pDefFontMgr = pFontMgr; |
2089 } | 2089 } |
OLD | NEW |