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/include/fxfa/xfa_fontmgr.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 11 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
14 #include "xfa/fxfa/app/xfa_ffapp.h" | 14 #include "xfa/include/fxfa/xfa_ffapp.h" |
15 #include "xfa/fxfa/app/xfa_ffdoc.h" | 15 #include "xfa/include/fxfa/xfa_ffdoc.h" |
16 | 16 |
17 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 17 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
18 static const XFA_FONTINFO g_XFAFontsMap[] = { | 18 static const XFA_FONTINFO g_XFAFontsMap[] = { |
19 {0x01d5d33e, L"SimSun", L"Arial", 0, 936}, | 19 {0x01d5d33e, L"SimSun", L"Arial", 0, 936}, |
20 {0x01e4f102, L"YouYuan", L"Arial", 1, 936}, | 20 {0x01e4f102, L"YouYuan", L"Arial", 1, 936}, |
21 {0x030549dc, L"LiSu", L"Arial", 1, 936}, | 21 {0x030549dc, L"LiSu", L"Arial", 1, 936}, |
22 {0x032edd44, L"Simhei", L"Arial", 1, 936}, | 22 {0x032edd44, L"Simhei", L"Arial", 1, 936}, |
23 {0x03eac6fc, L"PoorRichard-Regular", L"Arial", 2, 1252}, | 23 {0x03eac6fc, L"PoorRichard-Regular", L"Arial", 2, 1252}, |
24 {0x03ed90e6, L"Nina", L"Arial", 0, 1252}, | 24 {0x03ed90e6, L"Nina", L"Arial", 0, 1252}, |
25 {0x077b56b3, L"KingsoftPhoneticPlain", L"Arial", 0, 1252}, | 25 {0x077b56b3, L"KingsoftPhoneticPlain", L"Arial", 0, 1252}, |
(...skipping 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
1747 #else | 1747 #else |
1748 return NULL; | 1748 return NULL; |
1749 #endif | 1749 #endif |
1750 } | 1750 } |
1751 // static | 1751 |
1752 IXFA_FontMgr* IXFA_FontMgr::CreateDefault() { | |
1753 return new CXFA_DefFontMgr; | |
1754 } | |
1755 // virtual | |
1756 IXFA_FontMgr::~IXFA_FontMgr() {} | |
1757 CXFA_DefFontMgr::~CXFA_DefFontMgr() { | 1752 CXFA_DefFontMgr::~CXFA_DefFontMgr() { |
1758 int32_t iCounts = m_CacheFonts.GetSize(); | 1753 int32_t iCounts = m_CacheFonts.GetSize(); |
1759 for (int32_t i = 0; i < iCounts; i++) { | 1754 for (int32_t i = 0; i < iCounts; i++) { |
1760 ((IFX_Font*)m_CacheFonts[i])->Release(); | 1755 ((IFX_Font*)m_CacheFonts[i])->Release(); |
1761 } | 1756 } |
1762 m_CacheFonts.RemoveAll(); | 1757 m_CacheFonts.RemoveAll(); |
1763 } | 1758 } |
1764 | 1759 |
1765 IFX_Font* CXFA_DefFontMgr::GetFont(IXFA_Doc* hDoc, | 1760 IFX_Font* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc, |
1766 const CFX_WideStringC& wsFontFamily, | 1761 const CFX_WideStringC& wsFontFamily, |
1767 uint32_t dwFontStyles, | 1762 uint32_t dwFontStyles, |
1768 uint16_t wCodePage) { | 1763 uint16_t wCodePage) { |
1769 CFX_WideString wsFontName = wsFontFamily; | 1764 CFX_WideString wsFontName = wsFontFamily; |
1770 IFX_FontMgr* pFDEFontMgr = | 1765 IFX_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); |
1771 static_cast<CXFA_FFDoc*>(hDoc)->GetApp()->GetFDEFontMgr(); | |
1772 IFX_Font* pFont = pFDEFontMgr->LoadFont(wsFontName, dwFontStyles, wCodePage); | 1766 IFX_Font* pFont = pFDEFontMgr->LoadFont(wsFontName, dwFontStyles, wCodePage); |
1773 if (!pFont) { | 1767 if (!pFont) { |
1774 const XFA_FONTINFO* pCurFont = XFA_GetFontINFOByFontName(wsFontName); | 1768 const XFA_FONTINFO* pCurFont = XFA_GetFontINFOByFontName(wsFontName); |
1775 if (pCurFont && pCurFont->pReplaceFont) { | 1769 if (pCurFont && pCurFont->pReplaceFont) { |
1776 uint32_t dwStyle = 0; | 1770 uint32_t dwStyle = 0; |
1777 if (dwFontStyles & FX_FONTSTYLE_Bold) { | 1771 if (dwFontStyles & FX_FONTSTYLE_Bold) { |
1778 dwStyle |= FX_FONTSTYLE_Bold; | 1772 dwStyle |= FX_FONTSTYLE_Bold; |
1779 } | 1773 } |
1780 if (dwFontStyles & FX_FONTSTYLE_Italic) { | 1774 if (dwFontStyles & FX_FONTSTYLE_Italic) { |
1781 dwStyle |= FX_FONTSTYLE_Italic; | 1775 dwStyle |= FX_FONTSTYLE_Italic; |
(...skipping 17 matching lines...) Expand all Loading... |
1799 pReplace = pNameText; | 1793 pReplace = pNameText; |
1800 } | 1794 } |
1801 } | 1795 } |
1802 } | 1796 } |
1803 if (pFont) { | 1797 if (pFont) { |
1804 m_CacheFonts.Add(pFont); | 1798 m_CacheFonts.Add(pFont); |
1805 } | 1799 } |
1806 return pFont; | 1800 return pFont; |
1807 } | 1801 } |
1808 | 1802 |
1809 IFX_Font* CXFA_DefFontMgr::GetDefaultFont(IXFA_Doc* hDoc, | 1803 IFX_Font* CXFA_DefFontMgr::GetDefaultFont(CXFA_FFDoc* hDoc, |
1810 const CFX_WideStringC& wsFontFamily, | 1804 const CFX_WideStringC& wsFontFamily, |
1811 uint32_t dwFontStyles, | 1805 uint32_t dwFontStyles, |
1812 uint16_t wCodePage) { | 1806 uint16_t wCodePage) { |
1813 IFX_FontMgr* pFDEFontMgr = ((CXFA_FFDoc*)hDoc)->GetApp()->GetFDEFontMgr(); | 1807 IFX_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); |
1814 IFX_Font* pFont = | 1808 IFX_Font* pFont = |
1815 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); | 1809 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); |
1816 if (!pFont) | 1810 if (!pFont) |
1817 pFont = | 1811 pFont = |
1818 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); | 1812 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); |
1819 FXSYS_assert(pFont); | 1813 FXSYS_assert(pFont); |
1820 if (pFont) { | 1814 if (pFont) { |
1821 m_CacheFonts.Add(pFont); | 1815 m_CacheFonts.Add(pFont); |
1822 } | 1816 } |
1823 return pFont; | 1817 return pFont; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2011 return FALSE; | 2005 return FALSE; |
2012 } | 2006 } |
2013 wUnicode = (FX_WCHAR)pPDFFont->CharCodeFromUnicode(wUnicode); | 2007 wUnicode = (FX_WCHAR)pPDFFont->CharCodeFromUnicode(wUnicode); |
2014 iWidth = pPDFFont->GetCharWidthF(wUnicode); | 2008 iWidth = pPDFFont->GetCharWidthF(wUnicode); |
2015 return TRUE; | 2009 return TRUE; |
2016 } | 2010 } |
2017 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} | 2011 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} |
2018 CXFA_FontMgr::~CXFA_FontMgr() { | 2012 CXFA_FontMgr::~CXFA_FontMgr() { |
2019 DelAllMgrMap(); | 2013 DelAllMgrMap(); |
2020 } | 2014 } |
2021 IFX_Font* CXFA_FontMgr::GetFont(IXFA_Doc* hDoc, | 2015 IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, |
2022 const CFX_WideStringC& wsFontFamily, | 2016 const CFX_WideStringC& wsFontFamily, |
2023 uint32_t dwFontStyles, | 2017 uint32_t dwFontStyles, |
2024 uint16_t wCodePage) { | 2018 uint16_t wCodePage) { |
2025 uint32_t dwHash = FX_HashCode_String_GetW(wsFontFamily.GetPtr(), | 2019 uint32_t dwHash = FX_HashCode_String_GetW(wsFontFamily.GetPtr(), |
2026 wsFontFamily.GetLength(), FALSE); | 2020 wsFontFamily.GetLength(), FALSE); |
2027 CFX_ByteString bsKey; | 2021 CFX_ByteString bsKey; |
2028 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); | 2022 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); |
2029 auto it = m_FontMap.find(bsKey); | 2023 auto it = m_FontMap.find(bsKey); |
2030 if (it != m_FontMap.end()) | 2024 if (it != m_FontMap.end()) |
2031 return it->second; | 2025 return it->second; |
(...skipping 22 matching lines...) Expand all Loading... |
2054 } | 2048 } |
2055 if (pFont) { | 2049 if (pFont) { |
2056 if (pPDFFont) { | 2050 if (pPDFFont) { |
2057 pMgr->m_FDE2PDFFont.SetAt(pFont, pPDFFont); | 2051 pMgr->m_FDE2PDFFont.SetAt(pFont, pPDFFont); |
2058 pFont->SetFontProvider(pMgr); | 2052 pFont->SetFontProvider(pMgr); |
2059 } | 2053 } |
2060 m_FontMap[bsKey] = pFont; | 2054 m_FontMap[bsKey] = pFont; |
2061 } | 2055 } |
2062 return pFont; | 2056 return pFont; |
2063 } | 2057 } |
2064 void CXFA_FontMgr::LoadDocFonts(IXFA_Doc* hDoc) { | 2058 void CXFA_FontMgr::LoadDocFonts(CXFA_FFDoc* hDoc) { |
2065 if (!m_PDFFontMgrArray.GetValueAt(hDoc)) { | 2059 if (!m_PDFFontMgrArray.GetValueAt(hDoc)) { |
2066 m_PDFFontMgrArray.SetAt(hDoc, new CXFA_PDFFontMgr((CXFA_FFDoc*)hDoc)); | 2060 m_PDFFontMgrArray.SetAt(hDoc, new CXFA_PDFFontMgr(hDoc)); |
2067 } | 2061 } |
2068 } | 2062 } |
2069 void CXFA_FontMgr::ReleaseDocFonts(IXFA_Doc* hDoc) { | 2063 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) { |
2070 CXFA_PDFFontMgr* pMgr = NULL; | 2064 CXFA_PDFFontMgr* pMgr = NULL; |
2071 if (m_PDFFontMgrArray.Lookup(hDoc, (void*&)pMgr)) { | 2065 if (m_PDFFontMgrArray.Lookup(hDoc, (void*&)pMgr)) { |
2072 delete pMgr; | 2066 delete pMgr; |
2073 m_PDFFontMgrArray.RemoveKey(hDoc); | 2067 m_PDFFontMgrArray.RemoveKey(hDoc); |
2074 } | 2068 } |
2075 } | 2069 } |
2076 void CXFA_FontMgr::DelAllMgrMap() { | 2070 void CXFA_FontMgr::DelAllMgrMap() { |
2077 FX_POSITION ps = m_PDFFontMgrArray.GetStartPosition(); | 2071 FX_POSITION ps = m_PDFFontMgrArray.GetStartPosition(); |
2078 while (ps) { | 2072 while (ps) { |
2079 IXFA_Doc* hDoc = NULL; | 2073 CXFA_FFDoc* hDoc = NULL; |
2080 CXFA_PDFFontMgr* pMgr = NULL; | 2074 CXFA_PDFFontMgr* pMgr = NULL; |
2081 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); | 2075 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); |
2082 delete pMgr; | 2076 delete pMgr; |
2083 } | 2077 } |
2084 m_PDFFontMgrArray.RemoveAll(); | 2078 m_PDFFontMgrArray.RemoveAll(); |
2085 m_FontMap.clear(); | 2079 m_FontMap.clear(); |
2086 } | 2080 } |
2087 void CXFA_FontMgr::SetDefFontMgr(IXFA_FontMgr* pFontMgr) { | 2081 void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) { |
2088 m_pDefFontMgr = pFontMgr; | 2082 m_pDefFontMgr = pFontMgr; |
2089 } | 2083 } |
OLD | NEW |