Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Side by Side Diff: xfa/fxfa/app/xfa_fontmgr.cpp

Issue 2037563002: Replace IFGAS_Font with underlying concrete type (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/app/xfa_ffwidgetacc.cpp ('k') | xfa/fxfa/app/xfa_fwltheme.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 IFGAS_Font* CXFA_DefFontMgr::GetFont(CXFA_FFDoc* hDoc, 1746 CFGAS_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 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); 1751 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr();
1751 IFGAS_Font* pFont = 1752 CFGAS_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
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 IFGAS_Font* CXFA_DefFontMgr::GetDefaultFont(CXFA_FFDoc* hDoc, 1791 CFGAS_GEFont* CXFA_DefFontMgr::GetDefaultFont(
1791 const CFX_WideStringC& wsFontFamily, 1792 CXFA_FFDoc* hDoc,
1792 uint32_t dwFontStyles, 1793 const CFX_WideStringC& wsFontFamily,
1793 uint16_t wCodePage) { 1794 uint32_t dwFontStyles,
1795 uint16_t wCodePage) {
1794 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); 1796 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr();
1795 IFGAS_Font* pFont = 1797 CFGAS_GEFont* pFont =
1796 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); 1798 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage);
1797 if (!pFont) 1799 if (!pFont)
1798 pFont = 1800 pFont =
1799 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); 1801 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage);
1800 ASSERT(pFont); 1802 ASSERT(pFont);
1801 if (pFont) { 1803 if (pFont) {
1802 m_CacheFonts.Add(pFont); 1804 m_CacheFonts.Add(pFont);
1803 } 1805 }
1804 return pFont; 1806 return pFont;
1805 } 1807 }
(...skipping 11 matching lines...) Expand all
1817 }; 1819 };
1818 CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) { 1820 CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) {
1819 m_pDoc = pDoc; 1821 m_pDoc = pDoc;
1820 } 1822 }
1821 CXFA_PDFFontMgr::~CXFA_PDFFontMgr() { 1823 CXFA_PDFFontMgr::~CXFA_PDFFontMgr() {
1822 for (const auto& pair : m_FontMap) { 1824 for (const auto& pair : m_FontMap) {
1823 if (pair.second) 1825 if (pair.second)
1824 pair.second->Release(); 1826 pair.second->Release();
1825 } 1827 }
1826 } 1828 }
1827 IFGAS_Font* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName, 1829 CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName,
1828 FX_BOOL bBold, 1830 FX_BOOL bBold,
1829 FX_BOOL bItalic, 1831 FX_BOOL bItalic,
1830 CPDF_Font** pDstPDFFont, 1832 CPDF_Font** pDstPDFFont,
1831 FX_BOOL bStrictMatch) { 1833 FX_BOOL bStrictMatch) {
1832 CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); 1834 CPDF_Document* pDoc = m_pDoc->GetPDFDoc();
1833 if (pDoc == NULL) { 1835 if (pDoc == NULL) {
1834 return NULL; 1836 return NULL;
1835 } 1837 }
1836 CPDF_Dictionary* pFontSetDict = 1838 CPDF_Dictionary* pFontSetDict =
1837 pDoc->GetRoot()->GetDictBy("AcroForm")->GetDictBy("DR"); 1839 pDoc->GetRoot()->GetDictBy("AcroForm")->GetDictBy("DR");
1838 if (!pFontSetDict) { 1840 if (!pFontSetDict) {
1839 return NULL; 1841 return NULL;
1840 } 1842 }
1841 pFontSetDict = (CPDF_Dictionary*)pFontSetDict->GetDictBy("Font"); 1843 pFontSetDict = (CPDF_Dictionary*)pFontSetDict->GetDictBy("Font");
(...skipping 18 matching lines...) Expand all
1860 return NULL; 1862 return NULL;
1861 } 1863 }
1862 CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict); 1864 CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict);
1863 if (!pPDFFont) { 1865 if (!pPDFFont) {
1864 return NULL; 1866 return NULL;
1865 } 1867 }
1866 if (!pPDFFont->IsEmbedded()) { 1868 if (!pPDFFont->IsEmbedded()) {
1867 *pDstPDFFont = pPDFFont; 1869 *pDstPDFFont = pPDFFont;
1868 return NULL; 1870 return NULL;
1869 } 1871 }
1870 return IFGAS_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); 1872 return CFGAS_GEFont::LoadFont(&pPDFFont->m_Font, pFDEFontMgr, FALSE);
1871 } 1873 }
1872 return NULL; 1874 return NULL;
1873 } 1875 }
1874 1876
1875 IFGAS_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, 1877 CFGAS_GEFont* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily,
1876 uint32_t dwFontStyles, 1878 uint32_t dwFontStyles,
1877 CPDF_Font** pPDFFont, 1879 CPDF_Font** pPDFFont,
1878 FX_BOOL bStrictMatch) { 1880 FX_BOOL bStrictMatch) {
1879 uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); 1881 uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false);
1880 CFX_ByteString strKey; 1882 CFX_ByteString strKey;
1881 strKey.Format("%u%u", dwHashCode, dwFontStyles); 1883 strKey.Format("%u%u", dwHashCode, dwFontStyles);
1882 auto it = m_FontMap.find(strKey); 1884 auto it = m_FontMap.find(strKey);
1883 if (it != m_FontMap.end()) 1885 if (it != m_FontMap.end())
1884 return it->second; 1886 return it->second;
1885 CFX_ByteString bsPsName = 1887 CFX_ByteString bsPsName =
1886 CFX_ByteString::FromUnicode(CFX_WideString(wsFontFamily)); 1888 CFX_ByteString::FromUnicode(CFX_WideString(wsFontFamily));
1887 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; 1889 FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold;
1888 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; 1890 FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic;
1889 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); 1891 CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic);
1890 IFGAS_Font* pFont = 1892 CFGAS_GEFont* pFont =
1891 FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch); 1893 FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch);
1892 if (pFont) 1894 if (pFont)
1893 m_FontMap[strKey] = pFont; 1895 m_FontMap[strKey] = pFont;
1894 return pFont; 1896 return pFont;
1895 } 1897 }
1896 1898
1897 CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName( 1899 CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName(
1898 const CFX_ByteString& strPsName, 1900 const CFX_ByteString& strPsName,
1899 FX_BOOL bBold, 1901 FX_BOOL bBold,
1900 FX_BOOL bItalic) { 1902 FX_BOOL bItalic) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 } 1977 }
1976 } break; 1978 } break;
1977 default: 1979 default:
1978 break; 1980 break;
1979 } 1981 }
1980 return bMatch; 1982 return bMatch;
1981 } 1983 }
1982 } 1984 }
1983 return TRUE; 1985 return TRUE;
1984 } 1986 }
1985 FX_BOOL CXFA_PDFFontMgr::GetCharWidth(IFGAS_Font* pFont, 1987 FX_BOOL CXFA_PDFFontMgr::GetCharWidth(CFGAS_GEFont* pFont,
1986 FX_WCHAR wUnicode, 1988 FX_WCHAR wUnicode,
1987 int32_t& iWidth, 1989 int32_t& iWidth,
1988 FX_BOOL bCharCode) { 1990 FX_BOOL bCharCode) {
1989 if (wUnicode != 0x20 || bCharCode) 1991 if (wUnicode != 0x20 || bCharCode)
1990 return FALSE; 1992 return FALSE;
1991 1993
1992 auto it = m_FDE2PDFFont.find(pFont); 1994 auto it = m_FDE2PDFFont.find(pFont);
1993 if (it == m_FDE2PDFFont.end()) 1995 if (it == m_FDE2PDFFont.end())
1994 return FALSE; 1996 return FALSE;
1995 1997
1996 CPDF_Font* pPDFFont = it->second; 1998 CPDF_Font* pPDFFont = it->second;
1997 iWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode)); 1999 iWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode));
1998 return TRUE; 2000 return TRUE;
1999 } 2001 }
2000 2002
2001 CXFA_FontMgr::CXFA_FontMgr() {} 2003 CXFA_FontMgr::CXFA_FontMgr() {}
2002 2004
2003 CXFA_FontMgr::~CXFA_FontMgr() {} 2005 CXFA_FontMgr::~CXFA_FontMgr() {}
2004 2006
2005 IFGAS_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, 2007 CFGAS_GEFont* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc,
2006 const CFX_WideStringC& wsFontFamily, 2008 const CFX_WideStringC& wsFontFamily,
2007 uint32_t dwFontStyles, 2009 uint32_t dwFontStyles,
2008 uint16_t wCodePage) { 2010 uint16_t wCodePage) {
2009 uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false); 2011 uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false);
2010 CFX_ByteString bsKey; 2012 CFX_ByteString bsKey;
2011 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); 2013 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage);
2012 auto iter = m_FontMap.find(bsKey); 2014 auto iter = m_FontMap.find(bsKey);
2013 if (iter != m_FontMap.end()) 2015 if (iter != m_FontMap.end())
2014 return iter->second; 2016 return iter->second;
2015 CFX_WideString wsEnglishName; 2017 CFX_WideString wsEnglishName;
2016 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName); 2018 XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName);
2017 auto it = m_PDFFontMgrMap.find(hDoc); 2019 auto it = m_PDFFontMgrMap.find(hDoc);
2018 CXFA_PDFFontMgr* pMgr = 2020 CXFA_PDFFontMgr* pMgr =
2019 it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr; 2021 it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr;
2020 CPDF_Font* pPDFFont = nullptr; 2022 CPDF_Font* pPDFFont = nullptr;
2021 IFGAS_Font* pFont = nullptr; 2023 CFGAS_GEFont* pFont = nullptr;
2022 if (pMgr) { 2024 if (pMgr) {
2023 pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont); 2025 pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont);
2024 if (pFont) 2026 if (pFont)
2025 return pFont; 2027 return pFont;
2026 } 2028 }
2027 if (!pFont && m_pDefFontMgr) 2029 if (!pFont && m_pDefFontMgr)
2028 pFont = m_pDefFontMgr->GetFont(hDoc, wsFontFamily, dwFontStyles, wCodePage); 2030 pFont = m_pDefFontMgr->GetFont(hDoc, wsFontFamily, dwFontStyles, wCodePage);
2029 2031
2030 if (!pFont && pMgr) { 2032 if (!pFont && pMgr) {
2031 pPDFFont = nullptr; 2033 pPDFFont = nullptr;
(...skipping 21 matching lines...) Expand all
2053 m_PDFFontMgrMap[hDoc].reset(new CXFA_PDFFontMgr(hDoc)); 2055 m_PDFFontMgrMap[hDoc].reset(new CXFA_PDFFontMgr(hDoc));
2054 } 2056 }
2055 2057
2056 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) { 2058 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) {
2057 m_PDFFontMgrMap.erase(hDoc); 2059 m_PDFFontMgrMap.erase(hDoc);
2058 } 2060 }
2059 2061
2060 void CXFA_FontMgr::SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) { 2062 void CXFA_FontMgr::SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) {
2061 m_pDefFontMgr = std::move(pFontMgr); 2063 m_pDefFontMgr = std::move(pFontMgr);
2062 } 2064 }
OLDNEW
« no previous file with comments | « xfa/fxfa/app/xfa_ffwidgetacc.cpp ('k') | xfa/fxfa/app/xfa_fwltheme.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698