From 4997b22f84307521a62838f874928bf56cd3423c Mon Sep 17 00:00:00 2001 From: thestig Date: Tue, 7 Jun 2016 10:46:22 -0700 Subject: Get rid of NULLs in core/ Review-Url: https://codereview.chromium.org/2032613003 --- core/fpdfdoc/cpdf_variabletext.cpp | 2 +- core/fpdfdoc/doc_action.cpp | 12 +++---- core/fpdfdoc/doc_annot.cpp | 6 ++-- core/fpdfdoc/doc_basic.cpp | 32 ++++++++--------- core/fpdfdoc/doc_form.cpp | 56 +++++++++++++++--------------- core/fpdfdoc/doc_tagged.cpp | 10 +++--- core/fpdfdoc/doc_utils.cpp | 59 ++++++++++++++++---------------- core/fpdfdoc/doc_viewerPreferences.cpp | 51 +++++++++++---------------- core/fpdfdoc/include/cpdf_variabletext.h | 14 ++++---- core/fpdfdoc/include/fpdf_doc.h | 3 +- core/fpdfdoc/pdf_vt.h | 2 +- 11 files changed, 120 insertions(+), 127 deletions(-) (limited to 'core/fpdfdoc') diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp index a8b9c3c778..1d5fde289d 100644 --- a/core/fpdfdoc/cpdf_variabletext.cpp +++ b/core/fpdfdoc/cpdf_variabletext.cpp @@ -310,7 +310,7 @@ CPVT_WordPlace CPDF_VariableText::InsertWord(const CPVT_WordPlace& place, int32_t nFontIndex = GetSubWord() > 0 ? GetDefaultFontIndex() : GetWordFontIndex(word, charset, GetDefaultFontIndex()); - return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, NULL)); + return AddWord(newplace, CPVT_WordInfo(word, charset, nFontIndex, nullptr)); } CPVT_WordPlace CPDF_VariableText::InsertSection( diff --git a/core/fpdfdoc/doc_action.cpp b/core/fpdfdoc/doc_action.cpp index e646df2b4c..c512d1afa9 100644 --- a/core/fpdfdoc/doc_action.cpp +++ b/core/fpdfdoc/doc_action.cpp @@ -109,7 +109,7 @@ size_t CPDF_ActionFields::GetFieldsCount() const { return 0; } CFX_ByteString csType = pDict->GetStringBy("S"); - CPDF_Object* pFields = NULL; + CPDF_Object* pFields = nullptr; if (csType == "Hide") { pFields = pDict->GetDirectObjectBy("T"); } else { @@ -159,23 +159,23 @@ std::vector CPDF_ActionFields::GetAllFields() const { CPDF_Object* CPDF_ActionFields::GetField(size_t iIndex) const { if (!m_pAction) { - return NULL; + return nullptr; } CPDF_Dictionary* pDict = m_pAction->GetDict(); if (!pDict) { - return NULL; + return nullptr; } CFX_ByteString csType = pDict->GetStringBy("S"); - CPDF_Object* pFields = NULL; + CPDF_Object* pFields = nullptr; if (csType == "Hide") { pFields = pDict->GetDirectObjectBy("T"); } else { pFields = pDict->GetArrayBy("Fields"); } if (!pFields) { - return NULL; + return nullptr; } - CPDF_Object* pFindObj = NULL; + CPDF_Object* pFindObj = nullptr; if (pFields->IsDictionary() || pFields->IsString()) { if (iIndex == 0) pFindObj = pFields; diff --git a/core/fpdfdoc/doc_annot.cpp b/core/fpdfdoc/doc_annot.cpp index f8bad07ceb..9b2f9e505f 100644 --- a/core/fpdfdoc/doc_annot.cpp +++ b/core/fpdfdoc/doc_annot.cpp @@ -158,7 +158,7 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Annot::AppearanceMode mode) { CPDF_Dictionary* pAP = pAnnotDict->GetDictBy("AP"); if (!pAP) { - return NULL; + return nullptr; } const FX_CHAR* ap_entry = "N"; if (mode == CPDF_Annot::Down) @@ -215,7 +215,7 @@ static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, CFX_Matrix& matrix) { CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode); if (!pForm) { - return NULL; + return nullptr; } CFX_FloatRect form_bbox = pForm->m_pFormDict->GetRectBy("BBox"); CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixBy("Matrix"); @@ -276,7 +276,7 @@ void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice, CPDF_Dictionary* pBS = m_pAnnotDict->GetDictBy("BS"); char style_char; FX_FLOAT width; - CPDF_Array* pDashArray = NULL; + CPDF_Array* pDashArray = nullptr; if (!pBS) { CPDF_Array* pBorderArray = m_pAnnotDict->GetArrayBy("Border"); style_char = 'S'; diff --git a/core/fpdfdoc/doc_basic.cpp b/core/fpdfdoc/doc_basic.cpp index ab99cff772..72f2985cef 100644 --- a/core/fpdfdoc/doc_basic.cpp +++ b/core/fpdfdoc/doc_basic.cpp @@ -92,7 +92,7 @@ static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, CPDF_Array** ppFind, int nLevel = 0) { if (nLevel > nMaxRecursion) { - return NULL; + return nullptr; } CPDF_Array* pLimits = pNode->GetArrayBy("Limits"); if (pLimits) { @@ -105,7 +105,7 @@ static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, } if (csName.Compare(csLeft.AsStringC()) < 0 || csName.Compare(csRight.AsStringC()) > 0) { - return NULL; + return nullptr; } } CPDF_Array* pNames = pNode->GetArrayBy("Names"); @@ -128,11 +128,11 @@ static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, return pNames->GetDirectObjectAt(i * 2 + 1); } nIndex += dwCount; - return NULL; + return nullptr; } CPDF_Array* pKids = pNode->GetArrayBy("Kids"); if (!pKids) { - return NULL; + return nullptr; } for (size_t i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); @@ -145,7 +145,7 @@ static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, return pFound; } } - return NULL; + return nullptr; } static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, @@ -155,14 +155,14 @@ static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, CPDF_Array** ppFind, int nLevel = 0) { if (nLevel > nMaxRecursion) - return NULL; + return nullptr; CPDF_Array* pNames = pNode->GetArrayBy("Names"); if (pNames) { size_t nCount = pNames->GetCount() / 2; if (nIndex >= nCurIndex + nCount) { nCurIndex += nCount; - return NULL; + return nullptr; } if (ppFind) *ppFind = pNames; @@ -171,7 +171,7 @@ static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, } CPDF_Array* pKids = pNode->GetArrayBy("Kids"); if (!pKids) - return NULL; + return nullptr; for (size_t i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); if (!pKid) @@ -181,7 +181,7 @@ static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, if (pFound) return pFound; } - return NULL; + return nullptr; } static size_t CountNames(CPDF_Dictionary* pNode, int nLevel = 0) { @@ -219,7 +219,7 @@ int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const { return -1; } size_t nIndex = 0; - if (!SearchNameNode(m_pRoot, csName, nIndex, NULL)) { + if (!SearchNameNode(m_pRoot, csName, nIndex, nullptr)) { return -1; } return nIndex; @@ -227,17 +227,17 @@ int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const { CPDF_Object* CPDF_NameTree::LookupValue(int nIndex, CFX_ByteString& csName) const { if (!m_pRoot) { - return NULL; + return nullptr; } size_t nCurIndex = 0; - return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, NULL); + return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, nullptr); } CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { if (!m_pRoot) { - return NULL; + return nullptr; } size_t nIndex = 0; - return SearchNameNode(m_pRoot, csName, nIndex, NULL); + return SearchNameNode(m_pRoot, csName, nIndex, nullptr); } CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, const CFX_ByteString& sName) { @@ -474,7 +474,7 @@ CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const { } CPDF_Dictionary* pLabels = pPDFRoot->GetDictBy("PageLabels"); CPDF_NumberTree numberTree(pLabels); - CPDF_Object* pValue = NULL; + CPDF_Object* pValue = nullptr; int n = nPage; while (n >= 0) { pValue = numberTree.LookupValue(n); @@ -489,7 +489,7 @@ CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const { if (pLabel->KeyExist("P")) { wsLabel += pLabel->GetUnicodeTextBy("P"); } - CFX_ByteString bsNumberingStyle = pLabel->GetStringBy("S", nullptr); + CFX_ByteString bsNumberingStyle = pLabel->GetStringBy("S", ""); int nLabelNum = nPage - n + pLabel->GetIntegerBy("St", 1); CFX_WideString wsNumPortion = _GetLabelNumPortion(nLabelNum, bsNumberingStyle); diff --git a/core/fpdfdoc/doc_form.cpp b/core/fpdfdoc/doc_form.cpp index 1570a6800c..7ecf35de37 100644 --- a/core/fpdfdoc/doc_form.cpp +++ b/core/fpdfdoc/doc_form.cpp @@ -97,13 +97,13 @@ class CFieldTree { return field_ptr; } --*fields_to_go; - return NULL; + return nullptr; } for (int i = 0; i < children.GetSize(); i++) { if (CPDF_FormField* pField = children.GetAt(i)->GetField(fields_to_go)) return pField; } - return NULL; + return nullptr; } CPDF_FormField* GetField(int index) { int fields_to_go = index; @@ -125,8 +125,8 @@ class CFieldTree { _Node m_Root; }; CFieldTree::CFieldTree() { - m_Root.parent = NULL; - m_Root.field_ptr = NULL; + m_Root.parent = nullptr; + m_Root.field_ptr = nullptr; } CFieldTree::~CFieldTree() { RemoveAll(); @@ -135,7 +135,7 @@ CFieldTree::_Node* CFieldTree::AddChild(_Node* pParent, const CFX_WideString& short_name, CPDF_FormField* field_ptr) { if (!pParent) { - return NULL; + return nullptr; } _Node* pNode = new _Node; pNode->parent = pParent; @@ -158,7 +158,7 @@ void CFieldTree::RemoveNode(_Node* pNode, int nLevel) { CFieldTree::_Node* CFieldTree::_Lookup(_Node* pParent, const CFX_WideString& short_name) { if (!pParent) { - return NULL; + return nullptr; } for (int i = 0; i < pParent->children.GetSize(); i++) { _Node* pNode = pParent->children[i]; @@ -168,7 +168,7 @@ CFieldTree::_Node* CFieldTree::_Lookup(_Node* pParent, return pNode; } } - return NULL; + return nullptr; } void CFieldTree::RemoveAll() { for (int i = 0; i < m_Root.children.GetSize(); i++) { @@ -184,13 +184,13 @@ void CFieldTree::SetField(const CFX_WideString& full_name, const FX_WCHAR* pName; FX_STRSIZE nLength; name_extractor.GetNext(pName, nLength); - _Node *pNode = &m_Root, *pLast = NULL; + _Node *pNode = &m_Root, *pLast = nullptr; while (nLength > 0) { pLast = pNode; CFX_WideString name = CFX_WideString(pName, nLength); pNode = _Lookup(pLast, name); if (!pNode) { - pNode = AddChild(pLast, name, NULL); + pNode = AddChild(pLast, name, nullptr); } name_extractor.GetNext(pName, nLength); } @@ -200,30 +200,31 @@ void CFieldTree::SetField(const CFX_WideString& full_name, } CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) { if (full_name == L"") { - return NULL; + return nullptr; } CFieldNameExtractor name_extractor(full_name); const FX_WCHAR* pName; FX_STRSIZE nLength; name_extractor.GetNext(pName, nLength); - _Node *pNode = &m_Root, *pLast = NULL; + _Node *pNode = &m_Root, *pLast = nullptr; while (nLength > 0 && pNode) { pLast = pNode; CFX_WideString name = CFX_WideString(pName, nLength); pNode = _Lookup(pLast, name); name_extractor.GetNext(pName, nLength); } - return pNode ? pNode->field_ptr : NULL; + return pNode ? pNode->field_ptr : nullptr; } CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) { if (full_name == L"") { - return NULL; + return nullptr; } CFieldNameExtractor name_extractor(full_name); const FX_WCHAR* pName; FX_STRSIZE nLength; name_extractor.GetNext(pName, nLength); - _Node *pNode = &m_Root, *pLast = NULL; + _Node* pNode = &m_Root; + _Node* pLast = nullptr; while (nLength > 0 && pNode) { pLast = pNode; CFX_WideString name = CFX_WideString(pName, nLength); @@ -241,17 +242,17 @@ CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) { RemoveNode(pNode); return pField; } - return NULL; + return nullptr; } CFieldTree::_Node* CFieldTree::FindNode(const CFX_WideString& full_name) { if (full_name == L"") { - return NULL; + return nullptr; } CFieldNameExtractor name_extractor(full_name); const FX_WCHAR* pName; FX_STRSIZE nLength; name_extractor.GetNext(pName, nLength); - _Node *pNode = &m_Root, *pLast = NULL; + _Node *pNode = &m_Root, *pLast = nullptr; while (nLength > 0 && pNode) { pLast = pNode; CFX_WideString name = CFX_WideString(pName, nLength); @@ -375,10 +376,10 @@ static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXA* lpelfe, static FX_BOOL RetrieveSpecificFont(LOGFONTA& lf) { PDF_FONTDATA fd; memset(&fd, 0, sizeof(PDF_FONTDATA)); - HDC hDC = ::GetDC(NULL); + HDC hDC = ::GetDC(nullptr); EnumFontFamiliesExA(hDC, &lf, (FONTENUMPROCA)EnumFontFamExProc, (LPARAM)&fd, 0); - ::ReleaseDC(NULL, hDC); + ::ReleaseDC(nullptr, hDC); if (fd.bFind) { memcpy(&lf, &fd.lf, sizeof(LOGFONTA)); } @@ -440,7 +441,8 @@ CFX_ByteString CPDF_InterForm::GetNativeFont(uint8_t charSet, void* pLogFont) { "Microsoft Sans Serif", lf); } if (!bRet) { - bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, NULL, lf); + bRet = + RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, nullptr, lf); } if (bRet) { if (pLogFont) { @@ -613,14 +615,14 @@ FX_BOOL CPDF_InterForm::ValidateFieldName( } FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName, int iType) { - return ValidateFieldName(csNewFieldName, iType, NULL, NULL); + return ValidateFieldName(csNewFieldName, iType, nullptr, nullptr); } FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField, CFX_WideString& csNewFieldName) { return pField && !csNewFieldName.IsEmpty() && ValidateFieldName(csNewFieldName, ((CPDF_FormField*)pField)->GetFieldType(), pField, - NULL); + nullptr); } FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl, CFX_WideString& csNewFieldName) { @@ -688,7 +690,7 @@ CPDF_FormField* CPDF_InterForm::GetField(uint32_t index, CPDF_FormField* CPDF_InterForm::GetFieldByDict( CPDF_Dictionary* pFieldDict) const { if (!pFieldDict) { - return NULL; + return nullptr; } CFX_WideString csWName = GetFullName(pFieldDict); return m_pFieldTree->GetField(csWName); @@ -926,14 +928,14 @@ void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { } CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { if (!pFieldDict->KeyExist("T")) { - return NULL; + return nullptr; } CPDF_Dictionary* pDict = pFieldDict; CFX_WideString csWName = GetFullName(pFieldDict); if (csWName.IsEmpty()) { - return NULL; + return nullptr; } - CPDF_FormField* pField = NULL; + CPDF_FormField* pField = nullptr; pField = m_pFieldTree->GetField(csWName); if (!pField) { CPDF_Dictionary* pParent = pFieldDict; @@ -1049,7 +1051,7 @@ CFDF_Document* CPDF_InterForm::ExportToFDF( bool bSimpleFileSpec) const { CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); if (!pDoc) { - return NULL; + return nullptr; } CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictBy("FDF"); if (!pdf_path.IsEmpty()) { diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp index b5b89a017e..05109bb747 100644 --- a/core/fpdfdoc/doc_tagged.cpp +++ b/core/fpdfdoc/doc_tagged.cpp @@ -132,14 +132,14 @@ CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode( std::map& map, int nLevel) { if (nLevel > nMaxRecursion) - return NULL; + return nullptr; auto it = map.find(pDict); if (it != map.end()) return it->second; CPDF_StructElementImpl* pElement = - new CPDF_StructElementImpl(this, NULL, pDict); + new CPDF_StructElementImpl(this, nullptr, pDict); map[pDict] = pElement; CPDF_Dictionary* pParent = pDict->GetDictBy("P"); if (!pParent || pParent->GetStringBy("Type") == "StructTreeRoot") { @@ -301,7 +301,7 @@ void CPDF_StructElementImpl::LoadKid(uint32_t PageObjNum, pKid->m_Element.m_pElement = new CPDF_StructElementImpl(m_pTree, this, pKidDict); } else { - pKid->m_Element.m_pElement = NULL; + pKid->m_Element.m_pElement = nullptr; } } } @@ -335,7 +335,7 @@ CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, FX_BOOL bInheritable, FX_FLOAT fLevel) { if (fLevel > nMaxRecursion) { - return NULL; + return nullptr; } if (bInheritable) { CPDF_Object* pAttr = GetAttr(owner, name, FALSE); @@ -343,7 +343,7 @@ CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, return pAttr; } if (!m_pParent) { - return NULL; + return nullptr; } return m_pParent->GetAttr(owner, name, TRUE, fLevel + 1); } diff --git a/core/fpdfdoc/doc_utils.cpp b/core/fpdfdoc/doc_utils.cpp index 6c61c3d75e..05197380a6 100644 --- a/core/fpdfdoc/doc_utils.cpp +++ b/core/fpdfdoc/doc_utils.cpp @@ -23,7 +23,7 @@ CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) { CPDF_Array* pLimits = pNode->GetArrayBy("Limits"); if (pLimits && (num < pLimits->GetIntegerAt(0) || num > pLimits->GetIntegerAt(1))) { - return NULL; + return nullptr; } CPDF_Array* pNumbers = pNode->GetArrayBy("Nums"); if (pNumbers) { @@ -36,11 +36,11 @@ CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) { break; } } - return NULL; + return nullptr; } CPDF_Array* pKids = pNode->GetArrayBy("Kids"); if (!pKids) { - return NULL; + return nullptr; } for (size_t i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); @@ -52,7 +52,7 @@ CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) { return pFound; } } - return NULL; + return nullptr; } } // namespace @@ -279,16 +279,17 @@ void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { } CFX_ByteString csDA; if (!pFormDict->KeyExist("DR")) { - CPDF_Font* pFont = NULL; - CFX_ByteString csBaseName, csDefault; + CFX_ByteString csBaseName; + CFX_ByteString csDefault; uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); - pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); + CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); if (pFont) { AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); csDefault = csBaseName; } if (charSet != 0) { - CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, NULL); + CFX_ByteString csFontName = + CPDF_InterForm::GetNativeFont(charSet, nullptr); if (!pFont || csFontName != "Helvetica") { pFont = CPDF_InterForm::AddNativeFont(pDocument); if (pFont) { @@ -341,15 +342,15 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, uint32_t index, CFX_ByteString& csNameTag) { if (!pFormDict) { - return NULL; + return nullptr; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { - return NULL; + return nullptr; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { - return NULL; + return nullptr; } uint32_t dwCount = 0; for (const auto& it : *pFonts) { @@ -369,46 +370,46 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, } dwCount++; } - return NULL; + return nullptr; } CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString csNameTag) { CFX_ByteString csAlias = PDF_NameDecode(csNameTag); if (!pFormDict || csAlias.IsEmpty()) { - return NULL; + return nullptr; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { - return NULL; + return nullptr; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { - return NULL; + return nullptr; } CPDF_Dictionary* pElement = pFonts->GetDictBy(csAlias); if (!pElement) { - return NULL; + return nullptr; } if (pElement->GetStringBy("Type") == "Font") { return pDocument->LoadFont(pElement); } - return NULL; + return nullptr; } CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString csFontName, CFX_ByteString& csNameTag) { if (!pFormDict || csFontName.IsEmpty()) { - return NULL; + return nullptr; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { - return NULL; + return nullptr; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { - return NULL; + return nullptr; } for (const auto& it : *pFonts) { const CFX_ByteString& csKey = it.first; @@ -434,22 +435,22 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, return pFind; } } - return NULL; + return nullptr; } CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, uint8_t charSet, CFX_ByteString& csNameTag) { if (!pFormDict) { - return NULL; + return nullptr; } CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); if (!pDR) { - return NULL; + return nullptr; } CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); if (!pFonts) { - return NULL; + return nullptr; } for (const auto& it : *pFonts) { const CFX_ByteString& csKey = it.first; @@ -475,7 +476,7 @@ CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, return pFind; } } - return NULL; + return nullptr; } CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, @@ -669,7 +670,7 @@ void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument) { if (!pFormDict) { - return NULL; + return nullptr; } CPDF_DefaultAppearance cDA(pFormDict->GetStringBy("DA")); CFX_ByteString csFontNameTag; @@ -735,10 +736,10 @@ CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, const FX_CHAR* name, int nLevel) { if (nLevel > FPDFDOC_UTILS_MAXRECURSION) { - return NULL; + return nullptr; } if (!pFieldDict) { - return NULL; + return nullptr; } CPDF_Object* pAttr = pFieldDict->GetDirectObjectBy(name); if (pAttr) { @@ -746,7 +747,7 @@ CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, } CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); if (!pParent) { - return NULL; + return nullptr; } return FPDF_GetFieldAttr(pParent, name, nLevel + 1); } diff --git a/core/fpdfdoc/doc_viewerPreferences.cpp b/core/fpdfdoc/doc_viewerPreferences.cpp index a355635bf0..1de8c92614 100644 --- a/core/fpdfdoc/doc_viewerPreferences.cpp +++ b/core/fpdfdoc/doc_viewerPreferences.cpp @@ -9,46 +9,35 @@ CPDF_ViewerPreferences::CPDF_ViewerPreferences(CPDF_Document* pDoc) : m_pDoc(pDoc) {} + CPDF_ViewerPreferences::~CPDF_ViewerPreferences() {} + FX_BOOL CPDF_ViewerPreferences::IsDirectionR2L() const { - CPDF_Dictionary* pDict = m_pDoc->GetRoot(); - pDict = pDict->GetDictBy("ViewerPreferences"); - if (!pDict) { - return FALSE; - } - return "R2L" == pDict->GetStringBy("Direction"); + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetStringBy("Direction") == "R2L" : FALSE; } + FX_BOOL CPDF_ViewerPreferences::PrintScaling() const { - CPDF_Dictionary* pDict = m_pDoc->GetRoot(); - pDict = pDict->GetDictBy("ViewerPreferences"); - if (!pDict) { - return TRUE; - } - return "None" != pDict->GetStringBy("PrintScaling"); + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetStringBy("PrintScaling") != "None" : TRUE; } + int32_t CPDF_ViewerPreferences::NumCopies() const { - CPDF_Dictionary* pDict = m_pDoc->GetRoot(); - pDict = pDict->GetDictBy("ViewerPreferences"); - if (!pDict) { - return 1; - } - return pDict->GetIntegerBy("NumCopies"); + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetIntegerBy("NumCopies") : 1; } + CPDF_Array* CPDF_ViewerPreferences::PrintPageRange() const { - CPDF_Dictionary* pDict = m_pDoc->GetRoot(); - CPDF_Array* pRange = NULL; - pDict = pDict->GetDictBy("ViewerPreferences"); - if (!pDict) { - return pRange; - } - pRange = pDict->GetArrayBy("PrintPageRange"); - return pRange; + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetArrayBy("PrintPageRange") : nullptr; } + CFX_ByteString CPDF_ViewerPreferences::Duplex() const { + CPDF_Dictionary* pDict = GetViewerPreferences(); + return pDict ? pDict->GetStringBy("Duplex") : CFX_ByteString("None"); +} + +CPDF_Dictionary* CPDF_ViewerPreferences::GetViewerPreferences() const { CPDF_Dictionary* pDict = m_pDoc->GetRoot(); - pDict = pDict->GetDictBy("ViewerPreferences"); - if (!pDict) { - return "None"; - } - return pDict->GetStringBy("Duplex"); + return pDict ? pDict->GetDictBy("ViewerPreferences") : nullptr; } diff --git a/core/fpdfdoc/include/cpdf_variabletext.h b/core/fpdfdoc/include/cpdf_variabletext.h index faa5036469..06b41f186c 100644 --- a/core/fpdfdoc/include/cpdf_variabletext.h +++ b/core/fpdfdoc/include/cpdf_variabletext.h @@ -115,20 +115,20 @@ class CPDF_VariableText : private CPDF_EditContainer { void ResetAll(); void SetText(const FX_WCHAR* text, int32_t charset = 1, - const CPVT_SecProps* pSecProps = NULL, - const CPVT_WordProps* pWordProps = NULL); + const CPVT_SecProps* pSecProps = nullptr, + const CPVT_WordProps* pWordProps = nullptr); CPVT_WordPlace InsertWord(const CPVT_WordPlace& place, uint16_t word, int32_t charset = 1, - const CPVT_WordProps* pWordProps = NULL); + const CPVT_WordProps* pWordProps = nullptr); CPVT_WordPlace InsertSection(const CPVT_WordPlace& place, - const CPVT_SecProps* pSecProps = NULL, - const CPVT_WordProps* pWordProps = NULL); + const CPVT_SecProps* pSecProps = nullptr, + const CPVT_WordProps* pWordProps = nullptr); CPVT_WordPlace InsertText(const CPVT_WordPlace& place, const FX_WCHAR* text, int32_t charset = 1, - const CPVT_SecProps* pSecProps = NULL, - const CPVT_WordProps* pWordProps = NULL); + const CPVT_SecProps* pSecProps = nullptr, + const CPVT_WordProps* pWordProps = nullptr); CPVT_WordPlace DeleteWords(const CPVT_WordRange& PlaceRange); CPVT_WordPlace DeleteWord(const CPVT_WordPlace& place); CPVT_WordPlace BackSpaceWord(const CPVT_WordPlace& place); diff --git a/core/fpdfdoc/include/fpdf_doc.h b/core/fpdfdoc/include/fpdf_doc.h index 339182c19b..a70a24c1e3 100644 --- a/core/fpdfdoc/include/fpdf_doc.h +++ b/core/fpdfdoc/include/fpdf_doc.h @@ -44,7 +44,6 @@ class CPDF_Page; class CPDF_PageObject; class CPDF_RenderContext; class CPDF_RenderOptions; -class CPDF_ViewerPreferences; class CXML_Element; class IPDF_FormNotify; @@ -899,6 +898,8 @@ class CPDF_ViewerPreferences { CFX_ByteString Duplex() const; protected: + CPDF_Dictionary* GetViewerPreferences() const; + CPDF_Document* const m_pDoc; }; diff --git a/core/fpdfdoc/pdf_vt.h b/core/fpdfdoc/pdf_vt.h index 9026eeee9e..3f06f7d6d6 100644 --- a/core/fpdfdoc/pdf_vt.h +++ b/core/fpdfdoc/pdf_vt.h @@ -28,7 +28,7 @@ class CPVT_ArrayTemplate : public CFX_ArrayTemplate { if (nIndex >= 0 && nIndex < CFX_ArrayTemplate::GetSize()) { return CFX_ArrayTemplate::GetAt(nIndex); } - return NULL; + return nullptr; } void RemoveAt(int nIndex) { if (nIndex >= 0 && nIndex < CFX_ArrayTemplate::GetSize()) { -- cgit v1.2.3