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

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

Issue 2095653002: Remove NULL in xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master 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_ffwidgethandler.cpp ('k') | xfa/fxfa/app/xfa_fwltheme.cpp » ('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>
(...skipping 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 } 1715 }
1716 const XFA_FONTINFO* XFA_GetFontINFOByFontName( 1716 const XFA_FONTINFO* XFA_GetFontINFOByFontName(
1717 const CFX_WideStringC& wsFontName) { 1717 const CFX_WideStringC& wsFontName) {
1718 CFX_WideString wsFontNameTemp(wsFontName); 1718 CFX_WideString wsFontNameTemp(wsFontName);
1719 wsFontNameTemp.Remove(L' '); 1719 wsFontNameTemp.Remove(L' ');
1720 uint32_t dwCurFontNameHash = 1720 uint32_t dwCurFontNameHash =
1721 FX_HashCode_GetW(wsFontNameTemp.AsStringC(), true); 1721 FX_HashCode_GetW(wsFontNameTemp.AsStringC(), true);
1722 int32_t iStart = 0; 1722 int32_t iStart = 0;
1723 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; 1723 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1;
1724 int32_t iMid = 0; 1724 int32_t iMid = 0;
1725 const XFA_FONTINFO* pFontInfo = NULL; 1725 const XFA_FONTINFO* pFontInfo = nullptr;
1726 do { 1726 do {
1727 iMid = (iStart + iEnd) / 2; 1727 iMid = (iStart + iEnd) / 2;
1728 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; 1728 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash;
1729 if (dwFontNameHash == dwCurFontNameHash) { 1729 if (dwFontNameHash == dwCurFontNameHash) {
1730 pFontInfo = &g_XFAFontsMap[iMid]; 1730 pFontInfo = &g_XFAFontsMap[iMid];
1731 break; 1731 break;
1732 } else if (dwFontNameHash < dwCurFontNameHash) { 1732 } else if (dwFontNameHash < dwCurFontNameHash) {
1733 iStart = iMid + 1; 1733 iStart = iMid + 1;
1734 } else { 1734 } else {
1735 iEnd = iMid - 1; 1735 iEnd = iMid - 1;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 } 1791 }
1792 1792
1793 CFGAS_GEFont* CXFA_DefFontMgr::GetDefaultFont( 1793 CFGAS_GEFont* CXFA_DefFontMgr::GetDefaultFont(
1794 CXFA_FFDoc* hDoc, 1794 CXFA_FFDoc* hDoc,
1795 const CFX_WideStringC& wsFontFamily, 1795 const CFX_WideStringC& wsFontFamily,
1796 uint32_t dwFontStyles, 1796 uint32_t dwFontStyles,
1797 uint16_t wCodePage) { 1797 uint16_t wCodePage) {
1798 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); 1798 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr();
1799 CFGAS_GEFont* pFont = 1799 CFGAS_GEFont* pFont =
1800 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); 1800 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage);
1801 if (!pFont) 1801 if (!pFont) {
1802 pFont = 1802 pFont = pFDEFontMgr->LoadFont((const FX_WCHAR*)nullptr, dwFontStyles,
1803 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); 1803 wCodePage);
1804 }
1805
1804 ASSERT(pFont); 1806 ASSERT(pFont);
1805 if (pFont) { 1807 if (pFont) {
1806 m_CacheFonts.Add(pFont); 1808 m_CacheFonts.Add(pFont);
1807 } 1809 }
1808 return pFont; 1810 return pFont;
1809 } 1811 }
1810 struct XFA_PDFFONTNAME { 1812 struct XFA_PDFFONTNAME {
1811 const FX_CHAR* lpPsName; 1813 const FX_CHAR* lpPsName;
1812 const FX_CHAR* lpNormal; 1814 const FX_CHAR* lpNormal;
1813 const FX_CHAR* lpBold; 1815 const FX_CHAR* lpBold;
(...skipping 13 matching lines...) Expand all
1827 if (pair.second) 1829 if (pair.second)
1828 pair.second->Release(); 1830 pair.second->Release();
1829 } 1831 }
1830 } 1832 }
1831 CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName, 1833 CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName,
1832 FX_BOOL bBold, 1834 FX_BOOL bBold,
1833 FX_BOOL bItalic, 1835 FX_BOOL bItalic,
1834 CPDF_Font** pDstPDFFont, 1836 CPDF_Font** pDstPDFFont,
1835 FX_BOOL bStrictMatch) { 1837 FX_BOOL bStrictMatch) {
1836 CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); 1838 CPDF_Document* pDoc = m_pDoc->GetPDFDoc();
1837 if (pDoc == NULL) { 1839 if (!pDoc) {
1838 return NULL; 1840 return nullptr;
1839 } 1841 }
1840 CPDF_Dictionary* pFontSetDict = 1842 CPDF_Dictionary* pFontSetDict =
1841 pDoc->GetRoot()->GetDictBy("AcroForm")->GetDictBy("DR"); 1843 pDoc->GetRoot()->GetDictBy("AcroForm")->GetDictBy("DR");
1842 if (!pFontSetDict) { 1844 if (!pFontSetDict) {
1843 return NULL; 1845 return nullptr;
1844 } 1846 }
1845 pFontSetDict = pFontSetDict->GetDictBy("Font"); 1847 pFontSetDict = pFontSetDict->GetDictBy("Font");
1846 if (!pFontSetDict) { 1848 if (!pFontSetDict) {
1847 return NULL; 1849 return nullptr;
1848 } 1850 }
1849 strPsName.Remove(' '); 1851 strPsName.Remove(' ');
1850 IFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr(); 1852 IFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr();
1851 for (const auto& it : *pFontSetDict) { 1853 for (const auto& it : *pFontSetDict) {
1852 const CFX_ByteString& key = it.first; 1854 const CFX_ByteString& key = it.first;
1853 CPDF_Object* pObj = it.second; 1855 CPDF_Object* pObj = it.second;
1854 if (!PsNameMatchDRFontName(strPsName.AsStringC(), bBold, bItalic, key, 1856 if (!PsNameMatchDRFontName(strPsName.AsStringC(), bBold, bItalic, key,
1855 bStrictMatch)) { 1857 bStrictMatch)) {
1856 continue; 1858 continue;
1857 } 1859 }
1858 CPDF_Dictionary* pFontDict = ToDictionary(pObj->GetDirect()); 1860 CPDF_Dictionary* pFontDict = ToDictionary(pObj->GetDirect());
1859 if (!pFontDict || pFontDict->GetStringBy("Type") != "Font") { 1861 if (!pFontDict || pFontDict->GetStringBy("Type") != "Font") {
1860 return NULL; 1862 return nullptr;
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 nullptr;
1865 } 1867 }
1866 if (!pPDFFont->IsEmbedded()) { 1868 if (!pPDFFont->IsEmbedded()) {
1867 *pDstPDFFont = pPDFFont; 1869 *pDstPDFFont = pPDFFont;
1868 return NULL; 1870 return nullptr;
1869 } 1871 }
1870 return CFGAS_GEFont::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); 1872 return CFGAS_GEFont::LoadFont(&pPDFFont->m_Font, pFDEFontMgr);
1871 } 1873 }
1872 return NULL; 1874 return nullptr;
1873 } 1875 }
1874 1876
1875 CFGAS_GEFont* 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);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_ffwidgethandler.cpp ('k') | xfa/fxfa/app/xfa_fwltheme.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698