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

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

Issue 2031873003: Get rid of NULLs in xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@nullptr_fpdfsdk
Patch Set: 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 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } 1714 }
1715 const XFA_FONTINFO* XFA_GetFontINFOByFontName( 1715 const XFA_FONTINFO* XFA_GetFontINFOByFontName(
1716 const CFX_WideStringC& wsFontName) { 1716 const CFX_WideStringC& wsFontName) {
1717 CFX_WideString wsFontNameTemp(wsFontName); 1717 CFX_WideString wsFontNameTemp(wsFontName);
1718 wsFontNameTemp.Remove(L' '); 1718 wsFontNameTemp.Remove(L' ');
1719 uint32_t dwCurFontNameHash = 1719 uint32_t dwCurFontNameHash =
1720 FX_HashCode_GetW(wsFontNameTemp.AsStringC(), true); 1720 FX_HashCode_GetW(wsFontNameTemp.AsStringC(), true);
1721 int32_t iStart = 0; 1721 int32_t iStart = 0;
1722 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; 1722 int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1;
1723 int32_t iMid = 0; 1723 int32_t iMid = 0;
1724 const XFA_FONTINFO* pFontInfo = NULL; 1724 const XFA_FONTINFO* pFontInfo = nullptr;
1725 do { 1725 do {
1726 iMid = (iStart + iEnd) / 2; 1726 iMid = (iStart + iEnd) / 2;
1727 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash; 1727 uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash;
1728 if (dwFontNameHash == dwCurFontNameHash) { 1728 if (dwFontNameHash == dwCurFontNameHash) {
1729 pFontInfo = &g_XFAFontsMap[iMid]; 1729 pFontInfo = &g_XFAFontsMap[iMid];
1730 break; 1730 break;
1731 } else if (dwFontNameHash < dwCurFontNameHash) { 1731 } else if (dwFontNameHash < dwCurFontNameHash) {
1732 iStart = iMid + 1; 1732 iStart = iMid + 1;
1733 } else { 1733 } else {
1734 iEnd = iMid - 1; 1734 iEnd = iMid - 1;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 } 1788 }
1789 1789
1790 IFGAS_Font* CXFA_DefFontMgr::GetDefaultFont(CXFA_FFDoc* hDoc, 1790 IFGAS_Font* CXFA_DefFontMgr::GetDefaultFont(CXFA_FFDoc* hDoc,
1791 const CFX_WideStringC& wsFontFamily, 1791 const CFX_WideStringC& wsFontFamily,
1792 uint32_t dwFontStyles, 1792 uint32_t dwFontStyles,
1793 uint16_t wCodePage) { 1793 uint16_t wCodePage) {
1794 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); 1794 IFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr();
1795 IFGAS_Font* pFont = 1795 IFGAS_Font* pFont =
1796 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); 1796 pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage);
1797 if (!pFont) 1797 if (!pFont)
1798 pFont = 1798 pFont = pFDEFontMgr->LoadFont((const FX_WCHAR*)nullptr, dwFontStyles,
1799 pFDEFontMgr->LoadFont((const FX_WCHAR*)NULL, dwFontStyles, wCodePage); 1799 wCodePage);
1800 ASSERT(pFont); 1800 ASSERT(pFont);
1801 if (pFont) { 1801 if (pFont) {
1802 m_CacheFonts.Add(pFont); 1802 m_CacheFonts.Add(pFont);
1803 } 1803 }
1804 return pFont; 1804 return pFont;
1805 } 1805 }
1806 struct XFA_PDFFONTNAME { 1806 struct XFA_PDFFONTNAME {
1807 const FX_CHAR* lpPsName; 1807 const FX_CHAR* lpPsName;
1808 const FX_CHAR* lpNormal; 1808 const FX_CHAR* lpNormal;
1809 const FX_CHAR* lpBold; 1809 const FX_CHAR* lpBold;
(...skipping 13 matching lines...) Expand all
1823 if (pair.second) 1823 if (pair.second)
1824 pair.second->Release(); 1824 pair.second->Release();
1825 } 1825 }
1826 } 1826 }
1827 IFGAS_Font* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName, 1827 IFGAS_Font* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName,
1828 FX_BOOL bBold, 1828 FX_BOOL bBold,
1829 FX_BOOL bItalic, 1829 FX_BOOL bItalic,
1830 CPDF_Font** pDstPDFFont, 1830 CPDF_Font** pDstPDFFont,
1831 FX_BOOL bStrictMatch) { 1831 FX_BOOL bStrictMatch) {
1832 CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); 1832 CPDF_Document* pDoc = m_pDoc->GetPDFDoc();
1833 if (pDoc == NULL) { 1833 if (!pDoc)
1834 return NULL; 1834 return nullptr;
1835 } 1835
1836 CPDF_Dictionary* pFontSetDict = 1836 CPDF_Dictionary* pFontSetDict =
1837 pDoc->GetRoot()->GetDictBy("AcroForm")->GetDictBy("DR"); 1837 pDoc->GetRoot()->GetDictBy("AcroForm")->GetDictBy("DR");
1838 if (!pFontSetDict) { 1838 if (!pFontSetDict) {
1839 return NULL; 1839 return nullptr;
1840 } 1840 }
1841 pFontSetDict = (CPDF_Dictionary*)pFontSetDict->GetDictBy("Font"); 1841 pFontSetDict = (CPDF_Dictionary*)pFontSetDict->GetDictBy("Font");
1842 if (!pFontSetDict) { 1842 if (!pFontSetDict) {
1843 return NULL; 1843 return nullptr;
1844 } 1844 }
1845 strPsName.Remove(' '); 1845 strPsName.Remove(' ');
1846 IFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr(); 1846 IFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr();
1847 for (const auto& it : *pFontSetDict) { 1847 for (const auto& it : *pFontSetDict) {
1848 const CFX_ByteString& key = it.first; 1848 const CFX_ByteString& key = it.first;
1849 CPDF_Object* pObj = it.second; 1849 CPDF_Object* pObj = it.second;
1850 if (!PsNameMatchDRFontName(strPsName.AsStringC(), bBold, bItalic, key, 1850 if (!PsNameMatchDRFontName(strPsName.AsStringC(), bBold, bItalic, key,
1851 bStrictMatch)) { 1851 bStrictMatch)) {
1852 continue; 1852 continue;
1853 } 1853 }
1854 CPDF_Object* pDirect = pObj->GetDirect(); 1854 CPDF_Object* pDirect = pObj->GetDirect();
1855 if (!pDirect || !pDirect->IsDictionary()) { 1855 if (!pDirect || !pDirect->IsDictionary()) {
1856 return NULL; 1856 return nullptr;
1857 } 1857 }
1858 CPDF_Dictionary* pFontDict = (CPDF_Dictionary*)pDirect; 1858 CPDF_Dictionary* pFontDict = (CPDF_Dictionary*)pDirect;
1859 if (pFontDict->GetStringBy("Type") != "Font") { 1859 if (pFontDict->GetStringBy("Type") != "Font") {
1860 return NULL; 1860 return nullptr;
1861 } 1861 }
1862 CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict); 1862 CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict);
1863 if (!pPDFFont) { 1863 if (!pPDFFont) {
1864 return NULL; 1864 return nullptr;
1865 } 1865 }
1866 if (!pPDFFont->IsEmbedded()) { 1866 if (!pPDFFont->IsEmbedded()) {
1867 *pDstPDFFont = pPDFFont; 1867 *pDstPDFFont = pPDFFont;
1868 return NULL; 1868 return nullptr;
1869 } 1869 }
1870 return IFGAS_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); 1870 return IFGAS_Font::LoadFont(&pPDFFont->m_Font, pFDEFontMgr);
1871 } 1871 }
1872 return NULL; 1872 return nullptr;
1873 } 1873 }
1874 1874
1875 IFGAS_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, 1875 IFGAS_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily,
1876 uint32_t dwFontStyles, 1876 uint32_t dwFontStyles,
1877 CPDF_Font** pPDFFont, 1877 CPDF_Font** pPDFFont,
1878 FX_BOOL bStrictMatch) { 1878 FX_BOOL bStrictMatch) {
1879 uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); 1879 uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false);
1880 CFX_ByteString strKey; 1880 CFX_ByteString strKey;
1881 strKey.Format("%u%u", dwHashCode, dwFontStyles); 1881 strKey.Format("%u%u", dwHashCode, dwFontStyles);
1882 auto it = m_FontMap.find(strKey); 1882 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)); 2053 m_PDFFontMgrMap[hDoc].reset(new CXFA_PDFFontMgr(hDoc));
2054 } 2054 }
2055 2055
2056 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) { 2056 void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) {
2057 m_PDFFontMgrMap.erase(hDoc); 2057 m_PDFFontMgrMap.erase(hDoc);
2058 } 2058 }
2059 2059
2060 void CXFA_FontMgr::SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) { 2060 void CXFA_FontMgr::SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) {
2061 m_pDefFontMgr = std::move(pFontMgr); 2061 m_pDefFontMgr = std::move(pFontMgr);
2062 } 2062 }
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