From 1972b16849fedfda675eacd5c8594b54dbd1264d Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 12 Jun 2015 19:14:11 -0700 Subject: Remove unneeded checks in CPDF_DocPageData::GetFontFileStreamAcc(). The input cannot be null. Same for CPDF_Document::LoadFontFile(). Also set the contract for CPDF_Document::LoadFont() and adjust callers accordingly. Also remove unused CPDF_Document::FindFont(). R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1184673002. --- core/include/fpdfapi/fpdf_parser.h | 8 ++--- core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 20 +++--------- core/src/fpdfdoc/doc_formcontrol.cpp | 47 ++++++++++++++++------------ fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp | 5 +-- 4 files changed, 35 insertions(+), 45 deletions(-) diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index 0a08df8df9..a5020ebd2c 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -114,12 +114,8 @@ public: FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const; - - - - CPDF_Font* LoadFont(CPDF_Dictionary* pFontDict); - - CPDF_Font* FindFont(CPDF_Dictionary* pFontDict); + // |pFontDict| must not be null. + CPDF_Font* LoadFont(CPDF_Dictionary* pFontDict); CPDF_ColorSpace* LoadColorSpace(CPDF_Object* pCSObj, CPDF_Dictionary* pResources = NULL); diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp index 7ccf948698..ab945c5f87 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp @@ -75,27 +75,18 @@ void CPDF_PageModule::NotifyCJKAvailable() { m_FontGlobals.m_CMapManager.ReloadAll(); } + CPDF_Font* CPDF_Document::LoadFont(CPDF_Dictionary* pFontDict) { - if (!pFontDict) { - return NULL; - } + ASSERT(pFontDict); return GetValidatePageData()->GetFont(pFontDict, FALSE); } -CPDF_Font* CPDF_Document::FindFont(CPDF_Dictionary* pFontDict) -{ - if (!pFontDict) { - return NULL; - } - return GetValidatePageData()->GetFont(pFontDict, TRUE); -} + CPDF_StreamAcc* CPDF_Document::LoadFontFile(CPDF_Stream* pStream) { - if (pStream == NULL) { - return NULL; - } return GetValidatePageData()->GetFontFileStreamAcc(pStream); } + CPDF_ColorSpace* _CSFromName(const CFX_ByteString& name); CPDF_ColorSpace* CPDF_Document::LoadColorSpace(CPDF_Object* pCSObj, CPDF_Dictionary* pResources) { @@ -599,8 +590,7 @@ void CPDF_DocPageData::ReleaseIccProfile(CPDF_IccProfile* pIccProfile) CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(CPDF_Stream* pFontStream) { - if (!pFontStream) - return nullptr; + ASSERT(pFontStream); auto it = m_FontFileMap.find(pFontStream); if (it != m_FontFileMap.end()) { diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp index bedd301600..7fa17b8ffa 100644 --- a/core/src/fpdfdoc/doc_formcontrol.cpp +++ b/core/src/fpdfdoc/doc_formcontrol.cpp @@ -286,44 +286,51 @@ CPDF_DefaultAppearance CPDF_FormControl::GetDefaultAppearance() return pObj->GetString(); } } + CPDF_Font* CPDF_FormControl::GetDefaultControlFont() { CPDF_DefaultAppearance cDA = GetDefaultAppearance(); CFX_ByteString csFontNameTag; FX_FLOAT fFontSize; cDA.GetFont(csFontNameTag, fFontSize); - if (csFontNameTag.IsEmpty()) { - return NULL; - } + if (csFontNameTag.IsEmpty()) + return nullptr; + CPDF_Object* pObj = FPDF_GetFieldAttr(m_pWidgetDict, "DR"); - if (pObj != NULL && pObj->GetType() == PDFOBJ_DICTIONARY) { + if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) { CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font"); - if (pFonts != NULL) { - CPDF_Dictionary *pElement = pFonts->GetDict(csFontNameTag); - CPDF_Font *pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement); - if (pFont != NULL) { - return pFont; + if (pFonts) { + CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag); + if (pElement) { + CPDF_Font* pFont = + m_pField->m_pForm->m_pDocument->LoadFont(pElement); + if (pFont) { + return pFont; + } } } } - CPDF_Font *pFont = m_pField->m_pForm->GetFormFont(csFontNameTag); - if (pFont != NULL) { - return pFont; - } + if (CPDF_Font* pFormFont = m_pField->m_pForm->GetFormFont(csFontNameTag)) + return pFormFont; + CPDF_Dictionary *pPageDict = m_pWidgetDict->GetDict("P"); pObj = FPDF_GetFieldAttr(pPageDict, "Resources"); - if (pObj != NULL && pObj->GetType() == PDFOBJ_DICTIONARY) { + if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) { CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font"); - if (pFonts != NULL) { - CPDF_Dictionary *pElement = pFonts->GetDict(csFontNameTag); - CPDF_Font *pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement); - if (pFont != NULL) { - return pFont; + if (pFonts) { + CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag); + if (pElement) { + CPDF_Font* pFont = + m_pField->m_pForm->m_pDocument->LoadFont(pElement); + if (pFont) { + return pFont; + } } } } - return NULL; + return nullptr; } + int CPDF_FormControl::GetControlAlignment() { if (m_pWidgetDict == NULL) { diff --git a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp index 24095c843f..699a7e4ffe 100644 --- a/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp +++ b/fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp @@ -286,10 +286,7 @@ CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString &sAlias) } } - if (pFontDict) - return m_pDocument->LoadFont(pFontDict); - else - return NULL; + return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; } void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) -- cgit v1.2.3