| 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 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 uint32_t dwCurFontNameHash = | 1728 uint32_t dwCurFontNameHash = FX_HashCode_String_GetW( |
| 1729 FX_HashCode_String_GetW(wsFontNameTemp, wsFontNameTemp.GetLength(), TRUE); | 1729 wsFontNameTemp.c_str(), 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 uint32_t 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; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1756 } | 1756 } |
| 1757 m_CacheFonts.RemoveAll(); | 1757 m_CacheFonts.RemoveAll(); |
| 1758 } | 1758 } |
| 1759 | 1759 |
| 1760 IFX_Font* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc, | 1760 IFX_Font* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc, |
| 1761 const CFX_WideStringC& wsFontFamily, | 1761 const CFX_WideStringC& wsFontFamily, |
| 1762 uint32_t dwFontStyles, | 1762 uint32_t dwFontStyles, |
| 1763 uint16_t wCodePage) { | 1763 uint16_t wCodePage) { |
| 1764 CFX_WideString wsFontName = wsFontFamily; | 1764 CFX_WideString wsFontName = wsFontFamily; |
| 1765 IFX_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); | 1765 IFX_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); |
| 1766 IFX_Font* pFont = pFDEFontMgr->LoadFont(wsFontName, dwFontStyles, wCodePage); | 1766 IFX_Font* pFont = |
| 1767 pFDEFontMgr->LoadFont(wsFontName.c_str(), dwFontStyles, wCodePage); |
| 1767 if (!pFont) { | 1768 if (!pFont) { |
| 1768 const XFA_FONTINFO* pCurFont = | 1769 const XFA_FONTINFO* pCurFont = |
| 1769 XFA_GetFontINFOByFontName(wsFontName.AsStringC()); | 1770 XFA_GetFontINFOByFontName(wsFontName.AsStringC()); |
| 1770 if (pCurFont && pCurFont->pReplaceFont) { | 1771 if (pCurFont && pCurFont->pReplaceFont) { |
| 1771 uint32_t dwStyle = 0; | 1772 uint32_t dwStyle = 0; |
| 1772 if (dwFontStyles & FX_FONTSTYLE_Bold) { | 1773 if (dwFontStyles & FX_FONTSTYLE_Bold) { |
| 1773 dwStyle |= FX_FONTSTYLE_Bold; | 1774 dwStyle |= FX_FONTSTYLE_Bold; |
| 1774 } | 1775 } |
| 1775 if (dwFontStyles & FX_FONTSTYLE_Italic) { | 1776 if (dwFontStyles & FX_FONTSTYLE_Italic) { |
| 1776 dwStyle |= FX_FONTSTYLE_Italic; | 1777 dwStyle |= FX_FONTSTYLE_Italic; |
| 1777 } | 1778 } |
| 1778 const FX_WCHAR* pReplace = pCurFont->pReplaceFont; | 1779 const FX_WCHAR* pReplace = pCurFont->pReplaceFont; |
| 1779 int32_t iLength = FXSYS_wcslen(pReplace); | 1780 int32_t iLength = FXSYS_wcslen(pReplace); |
| 1780 while (iLength > 0) { | 1781 while (iLength > 0) { |
| 1781 const FX_WCHAR* pNameText = pReplace; | 1782 const FX_WCHAR* pNameText = pReplace; |
| 1782 while (*pNameText != L',' && iLength > 0) { | 1783 while (*pNameText != L',' && iLength > 0) { |
| 1783 pNameText++; | 1784 pNameText++; |
| 1784 iLength--; | 1785 iLength--; |
| 1785 } | 1786 } |
| 1786 CFX_WideString wsReplace = | 1787 CFX_WideString wsReplace = |
| 1787 CFX_WideString(pReplace, pNameText - pReplace); | 1788 CFX_WideString(pReplace, pNameText - pReplace); |
| 1788 pFont = pFDEFontMgr->LoadFont(wsReplace, dwStyle, wCodePage); | 1789 pFont = pFDEFontMgr->LoadFont(wsReplace.c_str(), dwStyle, wCodePage); |
| 1789 if (pFont) { | 1790 if (pFont) { |
| 1790 break; | 1791 break; |
| 1791 } | 1792 } |
| 1792 iLength--; | 1793 iLength--; |
| 1793 pNameText++; | 1794 pNameText++; |
| 1794 pReplace = pNameText; | 1795 pReplace = pNameText; |
| 1795 } | 1796 } |
| 1796 } | 1797 } |
| 1797 } | 1798 } |
| 1798 if (pFont) { | 1799 if (pFont) { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2076 CXFA_PDFFontMgr* pMgr = NULL; | 2077 CXFA_PDFFontMgr* pMgr = NULL; |
| 2077 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); | 2078 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); |
| 2078 delete pMgr; | 2079 delete pMgr; |
| 2079 } | 2080 } |
| 2080 m_PDFFontMgrArray.RemoveAll(); | 2081 m_PDFFontMgrArray.RemoveAll(); |
| 2081 m_FontMap.clear(); | 2082 m_FontMap.clear(); |
| 2082 } | 2083 } |
| 2083 void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) { | 2084 void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) { |
| 2084 m_pDefFontMgr = pFontMgr; | 2085 m_pDefFontMgr = pFontMgr; |
| 2085 } | 2086 } |
| OLD | NEW |