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

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

Issue 1846993002: Remove IXFA_* interfaces. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 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
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/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
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 =
1771 static_cast<CXFA_FFDoc*>(hDoc)->GetApp()->GetFDEFontMgr(); 1766 static_cast<CXFA_FFDoc*>(hDoc)->GetApp()->GetFDEFontMgr();
Tom Sepez 2016/03/31 17:01:57 cast not needed. You might want to take another p
dsinclair 2016/03/31 19:52:27 Done.
1772 IFX_Font* pFont = pFDEFontMgr->LoadFont(wsFontName, dwFontStyles, wCodePage); 1767 IFX_Font* pFont = pFDEFontMgr->LoadFont(wsFontName, dwFontStyles, wCodePage);
1773 if (!pFont) { 1768 if (!pFont) {
1774 const XFA_FONTINFO* pCurFont = XFA_GetFontINFOByFontName(wsFontName); 1769 const XFA_FONTINFO* pCurFont = XFA_GetFontINFOByFontName(wsFontName);
1775 if (pCurFont && pCurFont->pReplaceFont) { 1770 if (pCurFont && pCurFont->pReplaceFont) {
1776 uint32_t dwStyle = 0; 1771 uint32_t dwStyle = 0;
1777 if (dwFontStyles & FX_FONTSTYLE_Bold) { 1772 if (dwFontStyles & FX_FONTSTYLE_Bold) {
1778 dwStyle |= FX_FONTSTYLE_Bold; 1773 dwStyle |= FX_FONTSTYLE_Bold;
1779 } 1774 }
1780 if (dwFontStyles & FX_FONTSTYLE_Italic) { 1775 if (dwFontStyles & FX_FONTSTYLE_Italic) {
1781 dwStyle |= FX_FONTSTYLE_Italic; 1776 dwStyle |= FX_FONTSTYLE_Italic;
(...skipping 17 matching lines...) Expand all
1799 pReplace = pNameText; 1794 pReplace = pNameText;
1800 } 1795 }
1801 } 1796 }
1802 } 1797 }
1803 if (pFont) { 1798 if (pFont) {
1804 m_CacheFonts.Add(pFont); 1799 m_CacheFonts.Add(pFont);
1805 } 1800 }
1806 return pFont; 1801 return pFont;
1807 } 1802 }
1808 1803
1809 IFX_Font* CXFA_DefFontMgr::GetDefaultFont(IXFA_Doc* hDoc, 1804 IFX_Font* CXFA_DefFontMgr::GetDefaultFont(CXFA_FFDoc* hDoc,
1810 const CFX_WideStringC& wsFontFamily, 1805 const CFX_WideStringC& wsFontFamily,
1811 uint32_t dwFontStyles, 1806 uint32_t dwFontStyles,
1812 uint16_t wCodePage) { 1807 uint16_t wCodePage) {
1813 IFX_FontMgr* pFDEFontMgr = ((CXFA_FFDoc*)hDoc)->GetApp()->GetFDEFontMgr(); 1808 IFX_FontMgr* pFDEFontMgr = ((CXFA_FFDoc*)hDoc)->GetApp()->GetFDEFontMgr();
1814 IFX_Font* pFont = 1809 IFX_Font* pFont =
1815 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); 1810 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage);
1816 if (!pFont) 1811 if (!pFont)
1817 pFont = 1812 pFont =
1818 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); 1813 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage);
1819 FXSYS_assert(pFont); 1814 FXSYS_assert(pFont);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 return FALSE; 2006 return FALSE;
2012 } 2007 }
2013 wUnicode = (FX_WCHAR)pPDFFont->CharCodeFromUnicode(wUnicode); 2008 wUnicode = (FX_WCHAR)pPDFFont->CharCodeFromUnicode(wUnicode);
2014 iWidth = pPDFFont->GetCharWidthF(wUnicode); 2009 iWidth = pPDFFont->GetCharWidthF(wUnicode);
2015 return TRUE; 2010 return TRUE;
2016 } 2011 }
2017 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} 2012 CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {}
2018 CXFA_FontMgr::~CXFA_FontMgr() { 2013 CXFA_FontMgr::~CXFA_FontMgr() {
2019 DelAllMgrMap(); 2014 DelAllMgrMap();
2020 } 2015 }
2021 IFX_Font* CXFA_FontMgr::GetFont(IXFA_Doc* hDoc, 2016 IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc,
2022 const CFX_WideStringC& wsFontFamily, 2017 const CFX_WideStringC& wsFontFamily,
2023 uint32_t dwFontStyles, 2018 uint32_t dwFontStyles,
2024 uint16_t wCodePage) { 2019 uint16_t wCodePage) {
2025 uint32_t dwHash = FX_HashCode_String_GetW(wsFontFamily.GetPtr(), 2020 uint32_t dwHash = FX_HashCode_String_GetW(wsFontFamily.GetPtr(),
2026 wsFontFamily.GetLength(), FALSE); 2021 wsFontFamily.GetLength(), FALSE);
2027 CFX_ByteString bsKey; 2022 CFX_ByteString bsKey;
2028 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); 2023 bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage);
2029 auto it = m_FontMap.find(bsKey); 2024 auto it = m_FontMap.find(bsKey);
2030 if (it != m_FontMap.end()) 2025 if (it != m_FontMap.end())
2031 return it->second; 2026 return it->second;
(...skipping 22 matching lines...) Expand all
2054 } 2049 }
2055 if (pFont) { 2050 if (pFont) {
2056 if (pPDFFont) { 2051 if (pPDFFont) {
2057 pMgr->m_FDE2PDFFont.SetAt(pFont, pPDFFont); 2052 pMgr->m_FDE2PDFFont.SetAt(pFont, pPDFFont);
2058 pFont->SetFontProvider(pMgr); 2053 pFont->SetFontProvider(pMgr);
2059 } 2054 }
2060 m_FontMap[bsKey] = pFont; 2055 m_FontMap[bsKey] = pFont;
2061 } 2056 }
2062 return pFont; 2057 return pFont;
2063 } 2058 }
2064 void CXFA_FontMgr::LoadDocFonts(IXFA_Doc* hDoc) { 2059 void CXFA_FontMgr::LoadDocFonts(CXFA_FFDoc* hDoc) {
2065 if (!m_PDFFontMgrArray.GetValueAt(hDoc)) { 2060 if (!m_PDFFontMgrArray.GetValueAt(hDoc)) {
2066 m_PDFFontMgrArray.SetAt(hDoc, new CXFA_PDFFontMgr((CXFA_FFDoc*)hDoc)); 2061 m_PDFFontMgrArray.SetAt(hDoc, new CXFA_PDFFontMgr((CXFA_FFDoc*)hDoc));
Tom Sepez 2016/03/31 17:01:57 like here.
dsinclair 2016/03/31 19:52:27 Done.
2067 } 2062 }
2068 } 2063 }
2069 void CXFA_FontMgr::ReleaseDocFonts(IXFA_Doc* hDoc) { 2064 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) {
2070 CXFA_PDFFontMgr* pMgr = NULL; 2065 CXFA_PDFFontMgr* pMgr = NULL;
2071 if (m_PDFFontMgrArray.Lookup(hDoc, (void*&)pMgr)) { 2066 if (m_PDFFontMgrArray.Lookup(hDoc, (void*&)pMgr)) {
2072 delete pMgr; 2067 delete pMgr;
2073 m_PDFFontMgrArray.RemoveKey(hDoc); 2068 m_PDFFontMgrArray.RemoveKey(hDoc);
2074 } 2069 }
2075 } 2070 }
2076 void CXFA_FontMgr::DelAllMgrMap() { 2071 void CXFA_FontMgr::DelAllMgrMap() {
2077 FX_POSITION ps = m_PDFFontMgrArray.GetStartPosition(); 2072 FX_POSITION ps = m_PDFFontMgrArray.GetStartPosition();
2078 while (ps) { 2073 while (ps) {
2079 IXFA_Doc* hDoc = NULL; 2074 CXFA_FFDoc* hDoc = NULL;
2080 CXFA_PDFFontMgr* pMgr = NULL; 2075 CXFA_PDFFontMgr* pMgr = NULL;
2081 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr); 2076 m_PDFFontMgrArray.GetNextAssoc(ps, (void*&)hDoc, (void*&)pMgr);
2082 delete pMgr; 2077 delete pMgr;
2083 } 2078 }
2084 m_PDFFontMgrArray.RemoveAll(); 2079 m_PDFFontMgrArray.RemoveAll();
2085 m_FontMap.clear(); 2080 m_FontMap.clear();
2086 } 2081 }
2087 void CXFA_FontMgr::SetDefFontMgr(IXFA_FontMgr* pFontMgr) { 2082 void CXFA_FontMgr::SetDefFontMgr(CXFA_DefFontMgr* pFontMgr) {
2088 m_pDefFontMgr = pFontMgr; 2083 m_pDefFontMgr = pFontMgr;
2089 } 2084 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698