| 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/include/fxfa/xfa_fontmgr.h" | 7 #include "xfa/include/fxfa/xfa_fontmgr.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 uint32_t dwLocalNameHash = FX_HashCode_String_GetW( | 1701 uint32_t dwLocalNameHash = FX_HashCode_String_GetW( |
| 1702 wsLocalName.GetPtr(), wsLocalName.GetLength(), TRUE); | 1702 wsLocalName.raw_str(), 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 uint32_t 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) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1883 } | 1883 } |
| 1884 return IFX_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); | 1884 return IFX_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); |
| 1885 } | 1885 } |
| 1886 return NULL; | 1886 return NULL; |
| 1887 } | 1887 } |
| 1888 IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, | 1888 IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, |
| 1889 uint32_t dwFontStyles, | 1889 uint32_t dwFontStyles, |
| 1890 CPDF_Font** pPDFFont, | 1890 CPDF_Font** pPDFFont, |
| 1891 FX_BOOL bStrictMatch) { | 1891 FX_BOOL bStrictMatch) { |
| 1892 uint32_t dwHashCode = | 1892 uint32_t dwHashCode = |
| 1893 FX_HashCode_String_GetW(wsFontFamily.GetPtr(), wsFontFamily.GetLength()); | 1893 FX_HashCode_String_GetW(wsFontFamily.raw_str(), wsFontFamily.GetLength()); |
| 1894 CFX_ByteString strKey; | 1894 CFX_ByteString strKey; |
| 1895 strKey.Format("%u%u", dwHashCode, dwFontStyles); | 1895 strKey.Format("%u%u", dwHashCode, dwFontStyles); |
| 1896 auto it = m_FontMap.find(strKey); | 1896 auto it = m_FontMap.find(strKey); |
| 1897 if (it != m_FontMap.end()) | 1897 if (it != m_FontMap.end()) |
| 1898 return it->second; | 1898 return it->second; |
| 1899 CFX_ByteString bsPsName = CFX_ByteString::FromUnicode(wsFontFamily); | 1899 CFX_ByteString bsPsName = CFX_ByteString::FromUnicode(wsFontFamily); |
| 1900 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; | 1900 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; |
| 1901 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; | 1901 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; |
| 1902 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); | 1902 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); |
| 1903 IFX_Font* pFont = | 1903 IFX_Font* pFont = |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2009 return TRUE; | 2009 return TRUE; |
| 2010 } | 2010 } |
| 2011 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} | 2011 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} |
| 2012 CXFA_FontMgr::~CXFA_FontMgr() { | 2012 CXFA_FontMgr::~CXFA_FontMgr() { |
| 2013 DelAllMgrMap(); | 2013 DelAllMgrMap(); |
| 2014 } | 2014 } |
| 2015 IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, | 2015 IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, |
| 2016 const CFX_WideStringC& wsFontFamily, | 2016 const CFX_WideStringC& wsFontFamily, |
| 2017 uint32_t dwFontStyles, | 2017 uint32_t dwFontStyles, |
| 2018 uint16_t wCodePage) { | 2018 uint16_t wCodePage) { |
| 2019 uint32_t dwHash = FX_HashCode_String_GetW(wsFontFamily.GetPtr(), | 2019 uint32_t dwHash = FX_HashCode_String_GetW(wsFontFamily.raw_str(), |
| 2020 wsFontFamily.GetLength(), FALSE); | 2020 wsFontFamily.GetLength(), FALSE); |
| 2021 CFX_ByteString bsKey; | 2021 CFX_ByteString bsKey; |
| 2022 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); | 2022 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); |
| 2023 auto it = m_FontMap.find(bsKey); | 2023 auto it = m_FontMap.find(bsKey); |
| 2024 if (it != m_FontMap.end()) | 2024 if (it != m_FontMap.end()) |
| 2025 return it->second; | 2025 return it->second; |
| 2026 CFX_WideString wsEnglishName; | 2026 CFX_WideString wsEnglishName; |
| 2027 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); | 2027 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); |
| 2028 CXFA_PDFFontMgr* pMgr = (CXFA_PDFFontMgr*)m_PDFFontMgrArray.GetValueAt(hDoc); | 2028 CXFA_PDFFontMgr* pMgr = (CXFA_PDFFontMgr*)m_PDFFontMgrArray.GetValueAt(hDoc); |
| 2029 CPDF_Font* pPDFFont = NULL; | 2029 CPDF_Font* pPDFFont = NULL; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2074 CXFA_PDFFontMgr* pMgr = NULL; | 2074 CXFA_PDFFontMgr* pMgr = NULL; |
| 2075 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); | 2075 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); |
| 2076 delete pMgr; | 2076 delete pMgr; |
| 2077 } | 2077 } |
| 2078 m_PDFFontMgrArray.RemoveAll(); | 2078 m_PDFFontMgrArray.RemoveAll(); |
| 2079 m_FontMap.clear(); | 2079 m_FontMap.clear(); |
| 2080 } | 2080 } |
| 2081 void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) { | 2081 void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) { |
| 2082 m_pDefFontMgr = pFontMgr; | 2082 m_pDefFontMgr = pFontMgr; |
| 2083 } | 2083 } |
| OLD | NEW |