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 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 12 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 15 #include "xfa/fgas/font/fgas_gefont.h" |
15 #include "xfa/fxfa/include/xfa_ffapp.h" | 16 #include "xfa/fxfa/include/xfa_ffapp.h" |
16 #include "xfa/fxfa/include/xfa_ffdoc.h" | 17 #include "xfa/fxfa/include/xfa_ffdoc.h" |
17 | 18 |
18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 19 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
19 static const XFA_FONTINFO g_XFAFontsMap[] = { | 20 static const XFA_FONTINFO g_XFAFontsMap[] = { |
20 {0x01d5d33e, L"SimSun", L"Arial", 0, 936}, | 21 {0x01d5d33e, L"SimSun", L"Arial", 0, 936}, |
21 {0x01e4f102, L"YouYuan", L"Arial", 1, 936}, | 22 {0x01e4f102, L"YouYuan", L"Arial", 1, 936}, |
22 {0x030549dc, L"LiSu", L"Arial", 1, 936}, | 23 {0x030549dc, L"LiSu", L"Arial", 1, 936}, |
23 {0x032edd44, L"Simhei", L"Arial", 1, 936}, | 24 {0x032edd44, L"Simhei", L"Arial", 1, 936}, |
24 {0x03eac6fc, L"PoorRichard-Regular", L"Arial", 2, 1252}, | 25 {0x03eac6fc, L"PoorRichard-Regular", L"Arial", 2, 1252}, |
(...skipping 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 } | 1736 } |
1736 } while (iEnd >= iStart); | 1737 } while (iEnd >= iStart); |
1737 return pFontInfo; | 1738 return pFontInfo; |
1738 } | 1739 } |
1739 | 1740 |
1740 CXFA_DefFontMgr::~CXFA_DefFontMgr() { | 1741 CXFA_DefFontMgr::~CXFA_DefFontMgr() { |
1741 for (int32_t i = 0; i < m_CacheFonts.GetSize(); i++) | 1742 for (int32_t i = 0; i < m_CacheFonts.GetSize(); i++) |
1742 m_CacheFonts[i]->Release(); | 1743 m_CacheFonts[i]->Release(); |
1743 } | 1744 } |
1744 | 1745 |
1745 IFX_Font* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc, | 1746 CFX_GEFont* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc, |
1746 const CFX_WideStringC& wsFontFamily, | 1747 const CFX_WideStringC& wsFontFamily, |
1747 uint32_t dwFontStyles, | 1748 uint32_t dwFontStyles, |
1748 uint16_t wCodePage) { | 1749 uint16_t wCodePage) { |
1749 CFX_WideString wsFontName(wsFontFamily); | 1750 CFX_WideString wsFontName(wsFontFamily); |
1750 IFX_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); | 1751 IFX_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); |
1751 IFX_Font* pFont = | 1752 CFX_GEFont* pFont = |
1752 pFDEFontMgr->LoadFont(wsFontName.c_str(), dwFontStyles, wCodePage); | 1753 pFDEFontMgr->LoadFont(wsFontName.c_str(), dwFontStyles, wCodePage); |
1753 if (!pFont) { | 1754 if (!pFont) { |
1754 const XFA_FONTINFO* pCurFont = | 1755 const XFA_FONTINFO* pCurFont = |
1755 XFA_GetFontINFOByFontName(wsFontName.AsStringC()); | 1756 XFA_GetFontINFOByFontName(wsFontName.AsStringC()); |
1756 if (pCurFont && pCurFont->pReplaceFont) { | 1757 if (pCurFont && pCurFont->pReplaceFont) { |
1757 uint32_t dwStyle = 0; | 1758 uint32_t dwStyle = 0; |
1758 if (dwFontStyles & FX_FONTSTYLE_Bold) { | 1759 if (dwFontStyles & FX_FONTSTYLE_Bold) { |
1759 dwStyle |= FX_FONTSTYLE_Bold; | 1760 dwStyle |= FX_FONTSTYLE_Bold; |
1760 } | 1761 } |
1761 if (dwFontStyles & FX_FONTSTYLE_Italic) { | 1762 if (dwFontStyles & FX_FONTSTYLE_Italic) { |
(...skipping 18 matching lines...) Expand all Loading... |
1780 pReplace = pNameText; | 1781 pReplace = pNameText; |
1781 } | 1782 } |
1782 } | 1783 } |
1783 } | 1784 } |
1784 if (pFont) { | 1785 if (pFont) { |
1785 m_CacheFonts.Add(pFont); | 1786 m_CacheFonts.Add(pFont); |
1786 } | 1787 } |
1787 return pFont; | 1788 return pFont; |
1788 } | 1789 } |
1789 | 1790 |
1790 IFX_Font* CXFA_DefFontMgr::GetDefaultFont(CXFA_FFDoc* hDoc, | 1791 CFX_GEFont* CXFA_DefFontMgr::GetDefaultFont(CXFA_FFDoc* hDoc, |
1791 const CFX_WideStringC& wsFontFamily, | 1792 const CFX_WideStringC& wsFontFamily, |
1792 uint32_t dwFontStyles, | 1793 uint32_t dwFontStyles, |
1793 uint16_t wCodePage) { | 1794 uint16_t wCodePage) { |
1794 IFX_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); | 1795 IFX_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); |
1795 IFX_Font* pFont = | 1796 CFX_GEFont* pFont = |
1796 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); | 1797 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); |
1797 if (!pFont) | 1798 if (!pFont) |
1798 pFont = | 1799 pFont = |
1799 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); | 1800 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); |
1800 ASSERT(pFont); | 1801 ASSERT(pFont); |
1801 if (pFont) { | 1802 if (pFont) { |
1802 m_CacheFonts.Add(pFont); | 1803 m_CacheFonts.Add(pFont); |
1803 } | 1804 } |
1804 return pFont; | 1805 return pFont; |
1805 } | 1806 } |
(...skipping 11 matching lines...) Expand all Loading... |
1817 }; | 1818 }; |
1818 CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) { | 1819 CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) { |
1819 m_pDoc = pDoc; | 1820 m_pDoc = pDoc; |
1820 } | 1821 } |
1821 CXFA_PDFFontMgr::~CXFA_PDFFontMgr() { | 1822 CXFA_PDFFontMgr::~CXFA_PDFFontMgr() { |
1822 for (const auto& pair : m_FontMap) { | 1823 for (const auto& pair : m_FontMap) { |
1823 if (pair.second) | 1824 if (pair.second) |
1824 pair.second->Release(); | 1825 pair.second->Release(); |
1825 } | 1826 } |
1826 } | 1827 } |
1827 IFX_Font* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName, | 1828 CFX_GEFont* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName, |
1828 FX_BOOL bBold, | 1829 FX_BOOL bBold, |
1829 FX_BOOL bItalic, | 1830 FX_BOOL bItalic, |
1830 CPDF_Font** pDstPDFFont, | 1831 CPDF_Font** pDstPDFFont, |
1831 FX_BOOL bStrictMatch) { | 1832 FX_BOOL bStrictMatch) { |
1832 CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); | 1833 CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); |
1833 if (pDoc == NULL) { | 1834 if (pDoc == NULL) { |
1834 return NULL; | 1835 return NULL; |
1835 } | 1836 } |
1836 CPDF_Dictionary* pFontSetDict = | 1837 CPDF_Dictionary* pFontSetDict = |
1837 pDoc->GetRoot()->GetDictBy("AcroForm")->GetDictBy("DR"); | 1838 pDoc->GetRoot()->GetDictBy("AcroForm")->GetDictBy("DR"); |
1838 if (!pFontSetDict) { | 1839 if (!pFontSetDict) { |
1839 return NULL; | 1840 return NULL; |
1840 } | 1841 } |
1841 pFontSetDict = (CPDF_Dictionary*)pFontSetDict->GetDictBy("Font"); | 1842 pFontSetDict = (CPDF_Dictionary*)pFontSetDict->GetDictBy("Font"); |
(...skipping 18 matching lines...) Expand all Loading... |
1860 return NULL; | 1861 return NULL; |
1861 } | 1862 } |
1862 CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict); | 1863 CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict); |
1863 if (!pPDFFont) { | 1864 if (!pPDFFont) { |
1864 return NULL; | 1865 return NULL; |
1865 } | 1866 } |
1866 if (!pPDFFont->IsEmbedded()) { | 1867 if (!pPDFFont->IsEmbedded()) { |
1867 *pDstPDFFont = pPDFFont; | 1868 *pDstPDFFont = pPDFFont; |
1868 return NULL; | 1869 return NULL; |
1869 } | 1870 } |
1870 return IFX_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); | 1871 return CFX_GEFont::LoadFont(&pPDFFont->m_Font, pFDEFontMgr, FALSE); |
1871 } | 1872 } |
1872 return NULL; | 1873 return NULL; |
1873 } | 1874 } |
1874 | 1875 |
1875 IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, | 1876 CFX_GEFont* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, |
1876 uint32_t dwFontStyles, | 1877 uint32_t dwFontStyles, |
1877 CPDF_Font** pPDFFont, | 1878 CPDF_Font** pPDFFont, |
1878 FX_BOOL bStrictMatch) { | 1879 FX_BOOL bStrictMatch) { |
1879 uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); | 1880 uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); |
1880 CFX_ByteString strKey; | 1881 CFX_ByteString strKey; |
1881 strKey.Format("%u%u", dwHashCode, dwFontStyles); | 1882 strKey.Format("%u%u", dwHashCode, dwFontStyles); |
1882 auto it = m_FontMap.find(strKey); | 1883 auto it = m_FontMap.find(strKey); |
1883 if (it != m_FontMap.end()) | 1884 if (it != m_FontMap.end()) |
1884 return it->second; | 1885 return it->second; |
1885 CFX_ByteString bsPsName = | 1886 CFX_ByteString bsPsName = |
1886 CFX_ByteString::FromUnicode(CFX_WideString(wsFontFamily)); | 1887 CFX_ByteString::FromUnicode(CFX_WideString(wsFontFamily)); |
1887 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; | 1888 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; |
1888 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; | 1889 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; |
1889 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); | 1890 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); |
1890 IFX_Font* pFont = | 1891 CFX_GEFont* pFont = |
1891 FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch); | 1892 FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch); |
1892 if (pFont) | 1893 if (pFont) |
1893 m_FontMap[strKey] = pFont; | 1894 m_FontMap[strKey] = pFont; |
1894 return pFont; | 1895 return pFont; |
1895 } | 1896 } |
1896 | 1897 |
1897 CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName( | 1898 CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName( |
1898 const CFX_ByteString& strPsName, | 1899 const CFX_ByteString& strPsName, |
1899 FX_BOOL bBold, | 1900 FX_BOOL bBold, |
1900 FX_BOOL bItalic) { | 1901 FX_BOOL bItalic) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1975 } | 1976 } |
1976 } break; | 1977 } break; |
1977 default: | 1978 default: |
1978 break; | 1979 break; |
1979 } | 1980 } |
1980 return bMatch; | 1981 return bMatch; |
1981 } | 1982 } |
1982 } | 1983 } |
1983 return TRUE; | 1984 return TRUE; |
1984 } | 1985 } |
1985 FX_BOOL CXFA_PDFFontMgr::GetCharWidth(IFX_Font* pFont, | 1986 FX_BOOL CXFA_PDFFontMgr::GetCharWidth(CFX_GEFont* pFont, |
1986 FX_WCHAR wUnicode, | 1987 FX_WCHAR wUnicode, |
1987 int32_t& iWidth, | 1988 int32_t& iWidth, |
1988 FX_BOOL bCharCode) { | 1989 FX_BOOL bCharCode) { |
1989 if (wUnicode != 0x20 || bCharCode) | 1990 if (wUnicode != 0x20 || bCharCode) |
1990 return FALSE; | 1991 return FALSE; |
1991 | 1992 |
1992 auto it = m_FDE2PDFFont.find(pFont); | 1993 auto it = m_FDE2PDFFont.find(pFont); |
1993 if (it == m_FDE2PDFFont.end()) | 1994 if (it == m_FDE2PDFFont.end()) |
1994 return FALSE; | 1995 return FALSE; |
1995 | 1996 |
1996 CPDF_Font* pPDFFont = it->second; | 1997 CPDF_Font* pPDFFont = it->second; |
1997 iWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode)); | 1998 iWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode)); |
1998 return TRUE; | 1999 return TRUE; |
1999 } | 2000 } |
2000 | 2001 |
2001 CXFA_FontMgr::CXFA_FontMgr() {} | 2002 CXFA_FontMgr::CXFA_FontMgr() {} |
2002 | 2003 |
2003 CXFA_FontMgr::~CXFA_FontMgr() {} | 2004 CXFA_FontMgr::~CXFA_FontMgr() {} |
2004 | 2005 |
2005 IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, | 2006 CFX_GEFont* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, |
2006 const CFX_WideStringC& wsFontFamily, | 2007 const CFX_WideStringC& wsFontFamily, |
2007 uint32_t dwFontStyles, | 2008 uint32_t dwFontStyles, |
2008 uint16_t wCodePage) { | 2009 uint16_t wCodePage) { |
2009 uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false); | 2010 uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false); |
2010 CFX_ByteString bsKey; | 2011 CFX_ByteString bsKey; |
2011 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); | 2012 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); |
2012 auto iter = m_FontMap.find(bsKey); | 2013 auto iter = m_FontMap.find(bsKey); |
2013 if (iter != m_FontMap.end()) | 2014 if (iter != m_FontMap.end()) |
2014 return iter->second; | 2015 return iter->second; |
2015 CFX_WideString wsEnglishName; | 2016 CFX_WideString wsEnglishName; |
2016 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); | 2017 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); |
2017 auto it = m_PDFFontMgrMap.find(hDoc); | 2018 auto it = m_PDFFontMgrMap.find(hDoc); |
2018 CXFA_PDFFontMgr* pMgr = | 2019 CXFA_PDFFontMgr* pMgr = |
2019 it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr; | 2020 it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr; |
2020 CPDF_Font* pPDFFont = nullptr; | 2021 CPDF_Font* pPDFFont = nullptr; |
2021 IFX_Font* pFont = nullptr; | 2022 CFX_GEFont* pFont = nullptr; |
2022 if (pMgr) { | 2023 if (pMgr) { |
2023 pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont); | 2024 pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont); |
2024 if (pFont) | 2025 if (pFont) |
2025 return pFont; | 2026 return pFont; |
2026 } | 2027 } |
2027 if (!pFont && m_pDefFontMgr) | 2028 if (!pFont && m_pDefFontMgr) |
2028 pFont = m_pDefFontMgr->GetFont(hDoc, wsFontFamily, dwFontStyles, wCodePage); | 2029 pFont = m_pDefFontMgr->GetFont(hDoc, wsFontFamily, dwFontStyles, wCodePage); |
2029 | 2030 |
2030 if (!pFont && pMgr) { | 2031 if (!pFont && pMgr) { |
2031 pPDFFont = nullptr; | 2032 pPDFFont = nullptr; |
(...skipping 21 matching lines...) Expand all Loading... |
2053 m_PDFFontMgrMap[hDoc].reset(new CXFA_PDFFontMgr(hDoc)); | 2054 m_PDFFontMgrMap[hDoc].reset(new CXFA_PDFFontMgr(hDoc)); |
2054 } | 2055 } |
2055 | 2056 |
2056 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) { | 2057 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) { |
2057 m_PDFFontMgrMap.erase(hDoc); | 2058 m_PDFFontMgrMap.erase(hDoc); |
2058 } | 2059 } |
2059 | 2060 |
2060 void CXFA_FontMgr::SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) { | 2061 void CXFA_FontMgr::SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) { |
2061 m_pDefFontMgr = std::move(pFontMgr); | 2062 m_pDefFontMgr = std::move(pFontMgr); |
2062 } | 2063 } |
OLD | NEW |