diff options
Diffstat (limited to 'core')
24 files changed, 105 insertions, 102 deletions
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp index 4ac86fe104..4a89a7d9ff 100644 --- a/core/fpdfdoc/cpdf_action.cpp +++ b/core/fpdfdoc/cpdf_action.cpp @@ -22,7 +22,7 @@ const char* const g_sATypes[] = { } // namespace -CPDF_Action::CPDF_Action(CPDF_Dictionary* pDict) : m_pDict(pDict) {} +CPDF_Action::CPDF_Action(const CPDF_Dictionary* pDict) : m_pDict(pDict) {} CPDF_Action::CPDF_Action(const CPDF_Action& that) = default; @@ -76,7 +76,7 @@ WideString CPDF_Action::GetFilePath() const { return CPDF_FileSpec(pFile).GetFileName(); if (type == "Launch") { - CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win"); + const CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win"); if (pWinDict) { return WideString::FromLocal( pWinDict->GetStringFor(pdfium::stream::kF).AsStringView()); @@ -94,7 +94,7 @@ ByteString CPDF_Action::GetURI(const CPDF_Document* pDoc) const { csURI = m_pDict->GetStringFor("URI"); const CPDF_Dictionary* pRoot = pDoc->GetRoot(); - CPDF_Dictionary* pURI = pRoot->GetDictFor("URI"); + const CPDF_Dictionary* pURI = pRoot->GetDictFor("URI"); if (pURI) { auto result = csURI.Find(":"); if (!result.has_value() || result.value() == 0) diff --git a/core/fpdfdoc/cpdf_action.h b/core/fpdfdoc/cpdf_action.h index 1d9b722f40..43bf123b71 100644 --- a/core/fpdfdoc/cpdf_action.h +++ b/core/fpdfdoc/cpdf_action.h @@ -37,11 +37,11 @@ class CPDF_Action { GoTo3DView }; - explicit CPDF_Action(CPDF_Dictionary* pDict); + explicit CPDF_Action(const CPDF_Dictionary* pDict); CPDF_Action(const CPDF_Action& that); ~CPDF_Action(); - CPDF_Dictionary* GetDict() const { return m_pDict.Get(); } + const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); } ActionType GetType() const; CPDF_Dest GetDest(CPDF_Document* pDoc) const; WideString GetFilePath() const; @@ -54,7 +54,7 @@ class CPDF_Action { CPDF_Action GetSubAction(size_t iIndex) const; private: - UnownedPtr<CPDF_Dictionary> const m_pDict; + UnownedPtr<const CPDF_Dictionary> const m_pDict; }; #endif // CORE_FPDFDOC_CPDF_ACTION_H_ diff --git a/core/fpdfdoc/cpdf_actionfields.cpp b/core/fpdfdoc/cpdf_actionfields.cpp index cee256d3fb..89636bfc23 100644 --- a/core/fpdfdoc/cpdf_actionfields.cpp +++ b/core/fpdfdoc/cpdf_actionfields.cpp @@ -19,12 +19,12 @@ size_t CPDF_ActionFields::GetFieldsCount() const { if (!m_pAction) return 0; - CPDF_Dictionary* pDict = m_pAction->GetDict(); + const CPDF_Dictionary* pDict = m_pAction->GetDict(); if (!pDict) return 0; ByteString csType = pDict->GetStringFor("S"); - CPDF_Object* pFields = nullptr; + const CPDF_Object* pFields; if (csType == "Hide") pFields = pDict->GetDirectObjectFor("T"); else @@ -36,22 +36,21 @@ size_t CPDF_ActionFields::GetFieldsCount() const { return 1; if (pFields->IsString()) return 1; - if (CPDF_Array* pArray = pFields->AsArray()) - return pArray->GetCount(); - return 0; + const CPDF_Array* pArray = pFields->AsArray(); + return pArray ? pArray->GetCount() : 0; } -std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const { - std::vector<CPDF_Object*> fields; +std::vector<const CPDF_Object*> CPDF_ActionFields::GetAllFields() const { + std::vector<const CPDF_Object*> fields; if (!m_pAction) return fields; - CPDF_Dictionary* pDict = m_pAction->GetDict(); + const CPDF_Dictionary* pDict = m_pAction->GetDict(); if (!pDict) return fields; ByteString csType = pDict->GetStringFor("S"); - CPDF_Object* pFields; + const CPDF_Object* pFields; if (csType == "Hide") pFields = pDict->GetDirectObjectFor("T"); else @@ -62,9 +61,9 @@ std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const { if (pFields->IsDictionary() || pFields->IsString()) { fields.push_back(pFields); - } else if (CPDF_Array* pArray = pFields->AsArray()) { + } else if (const CPDF_Array* pArray = pFields->AsArray()) { for (size_t i = 0; i < pArray->GetCount(); ++i) { - CPDF_Object* pObj = pArray->GetDirectObjectAt(i); + const CPDF_Object* pObj = pArray->GetDirectObjectAt(i); if (pObj) fields.push_back(pObj); } @@ -72,16 +71,16 @@ std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const { return fields; } -CPDF_Object* CPDF_ActionFields::GetField(size_t iIndex) const { +const CPDF_Object* CPDF_ActionFields::GetField(size_t iIndex) const { if (!m_pAction) return nullptr; - CPDF_Dictionary* pDict = m_pAction->GetDict(); + const CPDF_Dictionary* pDict = m_pAction->GetDict(); if (!pDict) return nullptr; ByteString csType = pDict->GetStringFor("S"); - CPDF_Object* pFields = nullptr; + const CPDF_Object* pFields; if (csType == "Hide") pFields = pDict->GetDirectObjectFor("T"); else @@ -90,11 +89,11 @@ CPDF_Object* CPDF_ActionFields::GetField(size_t iIndex) const { if (!pFields) return nullptr; - CPDF_Object* pFindObj = nullptr; + const CPDF_Object* pFindObj = nullptr; if (pFields->IsDictionary() || pFields->IsString()) { if (iIndex == 0) pFindObj = pFields; - } else if (CPDF_Array* pArray = pFields->AsArray()) { + } else if (const CPDF_Array* pArray = pFields->AsArray()) { pFindObj = pArray->GetDirectObjectAt(iIndex); } return pFindObj; diff --git a/core/fpdfdoc/cpdf_actionfields.h b/core/fpdfdoc/cpdf_actionfields.h index 83c70f6375..affc03cfec 100644 --- a/core/fpdfdoc/cpdf_actionfields.h +++ b/core/fpdfdoc/cpdf_actionfields.h @@ -22,8 +22,8 @@ class CPDF_ActionFields { ~CPDF_ActionFields(); size_t GetFieldsCount() const; - std::vector<CPDF_Object*> GetAllFields() const; - CPDF_Object* GetField(size_t iIndex) const; + std::vector<const CPDF_Object*> GetAllFields() const; + const CPDF_Object* GetField(size_t iIndex) const; private: UnownedPtr<const CPDF_Action> const m_pAction; diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp index dc2e8acfdf..5734e192e3 100644 --- a/core/fpdfdoc/cpdf_annot.cpp +++ b/core/fpdfdoc/cpdf_annot.cpp @@ -64,7 +64,7 @@ CPDF_Form* AnnotGetMatrix(const CPDF_Page* pPage, CPDF_Stream* FPDFDOC_GetAnnotAPInternal(const CPDF_Dictionary* pAnnotDict, CPDF_Annot::AppearanceMode eMode, bool bFallbackToNormal) { - CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP"); + const CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP"); if (!pAP) return nullptr; @@ -90,7 +90,7 @@ CPDF_Stream* FPDFDOC_GetAnnotAPInternal(const CPDF_Dictionary* pAnnotDict, if (as.IsEmpty()) { ByteString value = pAnnotDict->GetStringFor("V"); if (value.IsEmpty()) { - CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent"); + const CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent"); value = pParentDict ? pParentDict->GetStringFor("V") : ByteString(); } as = (!value.IsEmpty() && pDict->KeyExist(value)) ? value : "Off"; @@ -230,11 +230,12 @@ CFX_FloatRect CPDF_Annot::RectFromQuadPointsArray(const CPDF_Array* pArray, // static CFX_FloatRect CPDF_Annot::BoundingRectFromQuadPoints( const CPDF_Dictionary* pAnnotDict) { - CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints"); + CFX_FloatRect ret; + const CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints"); if (!pArray) - return CFX_FloatRect(); + return ret; - CFX_FloatRect ret = RectFromQuadPointsArray(pArray, 0); + ret = RectFromQuadPointsArray(pArray, 0); size_t nQuadPointCount = QuadPointCount(pArray); for (size_t i = 1; i < nQuadPointCount; ++i) { CFX_FloatRect rect = RectFromQuadPointsArray(pArray, i); diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp index 77a2d0c2af..e364a72d35 100644 --- a/core/fpdfdoc/cpdf_annotlist.cpp +++ b/core/fpdfdoc/cpdf_annotlist.cpp @@ -129,7 +129,7 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) return; const CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); - CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); + const CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); bool bRegenerateAP = pAcroForm && pAcroForm->GetBooleanFor("NeedAppearances"); for (size_t i = 0; i < pAnnots->GetCount(); ++i) { CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); diff --git a/core/fpdfdoc/cpdf_bookmark.cpp b/core/fpdfdoc/cpdf_bookmark.cpp index 5f8997d647..32375808a6 100644 --- a/core/fpdfdoc/cpdf_bookmark.cpp +++ b/core/fpdfdoc/cpdf_bookmark.cpp @@ -24,7 +24,7 @@ CPDF_Bookmark::CPDF_Bookmark() {} CPDF_Bookmark::CPDF_Bookmark(const CPDF_Bookmark& that) = default; -CPDF_Bookmark::CPDF_Bookmark(CPDF_Dictionary* pDict) : m_pDict(pDict) {} +CPDF_Bookmark::CPDF_Bookmark(const CPDF_Dictionary* pDict) : m_pDict(pDict) {} CPDF_Bookmark::~CPDF_Bookmark() {} @@ -32,7 +32,7 @@ uint32_t CPDF_Bookmark::GetColorRef() const { if (!m_pDict) return kBlackBGR; - CPDF_Array* pColor = m_pDict->GetArrayFor("C"); + const CPDF_Array* pColor = m_pDict->GetArrayFor("C"); if (!pColor) return kBlackBGR; diff --git a/core/fpdfdoc/cpdf_bookmark.h b/core/fpdfdoc/cpdf_bookmark.h index 60c86dd7b0..ff31af1149 100644 --- a/core/fpdfdoc/cpdf_bookmark.h +++ b/core/fpdfdoc/cpdf_bookmark.h @@ -19,10 +19,10 @@ class CPDF_Bookmark { public: CPDF_Bookmark(); CPDF_Bookmark(const CPDF_Bookmark& that); - explicit CPDF_Bookmark(CPDF_Dictionary* pDict); + explicit CPDF_Bookmark(const CPDF_Dictionary* pDict); ~CPDF_Bookmark(); - CPDF_Dictionary* GetDict() const { return m_pDict.Get(); } + const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); } uint32_t GetColorRef() const; uint32_t GetFontStyle() const; WideString GetTitle() const; @@ -30,7 +30,7 @@ class CPDF_Bookmark { CPDF_Action GetAction() const; private: - UnownedPtr<CPDF_Dictionary> m_pDict; + UnownedPtr<const CPDF_Dictionary> m_pDict; }; #endif // CORE_FPDFDOC_CPDF_BOOKMARK_H_ diff --git a/core/fpdfdoc/cpdf_bookmarktree.cpp b/core/fpdfdoc/cpdf_bookmarktree.cpp index 33c9f3d15b..3b178f01b1 100644 --- a/core/fpdfdoc/cpdf_bookmarktree.cpp +++ b/core/fpdfdoc/cpdf_bookmarktree.cpp @@ -14,7 +14,7 @@ CPDF_BookmarkTree::~CPDF_BookmarkTree() {} CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild( const CPDF_Bookmark& parent) const { - CPDF_Dictionary* pParentDict = parent.GetDict(); + const CPDF_Dictionary* pParentDict = parent.GetDict(); if (pParentDict) return CPDF_Bookmark(pParentDict->GetDictFor("First")); @@ -22,17 +22,17 @@ CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild( if (!pRoot) return CPDF_Bookmark(); - CPDF_Dictionary* pOutlines = pRoot->GetDictFor("Outlines"); + const CPDF_Dictionary* pOutlines = pRoot->GetDictFor("Outlines"); return pOutlines ? CPDF_Bookmark(pOutlines->GetDictFor("First")) : CPDF_Bookmark(); } CPDF_Bookmark CPDF_BookmarkTree::GetNextSibling( const CPDF_Bookmark& bookmark) const { - CPDF_Dictionary* pDict = bookmark.GetDict(); + const CPDF_Dictionary* pDict = bookmark.GetDict(); if (!pDict) return CPDF_Bookmark(); - CPDF_Dictionary* pNext = pDict->GetDictFor("Next"); + const CPDF_Dictionary* pNext = pDict->GetDictFor("Next"); return pNext == pDict ? CPDF_Bookmark() : CPDF_Bookmark(pNext); } diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index bfc39b08f1..acad073b17 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -64,7 +64,7 @@ CPDF_Object* FPDF_GetFieldAttr(const CPDF_Dictionary* pFieldDict, if (pAttr) return pAttr; - CPDF_Dictionary* pParent = pFieldDict->GetDictFor("Parent"); + const CPDF_Dictionary* pParent = pFieldDict->GetDictFor("Parent"); return pParent ? FPDF_GetFieldAttr(pParent, name, nLevel + 1) : nullptr; } diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index 0c548d8e0b..83df36b39b 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -690,7 +690,7 @@ ByteString CPDF_InterForm::GenerateNewResourceName( if (!pResDict) return csTmp; - CPDF_Dictionary* pDict = pResDict->GetDictFor(csType); + const CPDF_Dictionary* pDict = pResDict->GetDictFor(csType); if (!pDict) return csTmp; @@ -963,8 +963,8 @@ bool CPDF_InterForm::HasXFAForm() const { return m_pFormDict && m_pFormDict->GetArrayFor("XFA"); } -void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { - const CPDF_Dictionary* pPageDict = pPage->GetFormDict(); +void CPDF_InterForm::FixPageFields(CPDF_Page* pPage) { + CPDF_Dictionary* pPageDict = pPage->GetFormDict(); if (!pPageDict) return; diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h index 2f60bf77b5..796c336ea0 100644 --- a/core/fpdfdoc/cpdf_interform.h +++ b/core/fpdfdoc/cpdf_interform.h @@ -87,7 +87,7 @@ class CPDF_InterForm { void SetFormNotify(IPDF_FormNotify* pNotify); bool HasXFAForm() const; - void FixPageFields(const CPDF_Page* pPage); + void FixPageFields(CPDF_Page* pPage); IPDF_FormNotify* GetFormNotify() const { return m_pFormNotify.Get(); } CPDF_Document* GetDocument() const { return m_pDocument.Get(); } diff --git a/core/fpdfdoc/cpdf_numbertree.cpp b/core/fpdfdoc/cpdf_numbertree.cpp index 952fb4ef1d..74aeb67e85 100644 --- a/core/fpdfdoc/cpdf_numbertree.cpp +++ b/core/fpdfdoc/cpdf_numbertree.cpp @@ -11,13 +11,13 @@ namespace { -CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) { - CPDF_Array* pLimits = pNode->GetArrayFor("Limits"); +const CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) { + const CPDF_Array* pLimits = pNode->GetArrayFor("Limits"); if (pLimits && (num < pLimits->GetIntegerAt(0) || num > pLimits->GetIntegerAt(1))) { return nullptr; } - CPDF_Array* pNumbers = pNode->GetArrayFor("Nums"); + const CPDF_Array* pNumbers = pNode->GetArrayFor("Nums"); if (pNumbers) { for (size_t i = 0; i < pNumbers->GetCount() / 2; i++) { int index = pNumbers->GetIntegerAt(i * 2); @@ -29,16 +29,16 @@ CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) { return nullptr; } - CPDF_Array* pKids = pNode->GetArrayFor("Kids"); + const CPDF_Array* pKids = pNode->GetArrayFor("Kids"); if (!pKids) return nullptr; for (size_t i = 0; i < pKids->GetCount(); i++) { - CPDF_Dictionary* pKid = pKids->GetDictAt(i); + const CPDF_Dictionary* pKid = pKids->GetDictAt(i); if (!pKid) continue; - CPDF_Object* pFound = SearchNumberNode(pKid, num); + const CPDF_Object* pFound = SearchNumberNode(pKid, num); if (pFound) return pFound; } @@ -47,10 +47,11 @@ CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) { } // namespace -CPDF_NumberTree::CPDF_NumberTree(CPDF_Dictionary* pRoot) : m_pRoot(pRoot) {} +CPDF_NumberTree::CPDF_NumberTree(const CPDF_Dictionary* pRoot) + : m_pRoot(pRoot) {} CPDF_NumberTree::~CPDF_NumberTree() {} -CPDF_Object* CPDF_NumberTree::LookupValue(int num) const { +const CPDF_Object* CPDF_NumberTree::LookupValue(int num) const { return SearchNumberNode(m_pRoot.Get(), num); } diff --git a/core/fpdfdoc/cpdf_numbertree.h b/core/fpdfdoc/cpdf_numbertree.h index 47c40b93d3..1c65fd2cae 100644 --- a/core/fpdfdoc/cpdf_numbertree.h +++ b/core/fpdfdoc/cpdf_numbertree.h @@ -14,13 +14,13 @@ class CPDF_Object; class CPDF_NumberTree { public: - explicit CPDF_NumberTree(CPDF_Dictionary* pRoot); + explicit CPDF_NumberTree(const CPDF_Dictionary* pRoot); ~CPDF_NumberTree(); - CPDF_Object* LookupValue(int num) const; + const CPDF_Object* LookupValue(int num) const; protected: - UnownedPtr<CPDF_Dictionary> const m_pRoot; + UnownedPtr<const CPDF_Dictionary> const m_pRoot; }; #endif // CORE_FPDFDOC_CPDF_NUMBERTREE_H_ diff --git a/core/fpdfdoc/cpdf_occontext.cpp b/core/fpdfdoc/cpdf_occontext.cpp index e59690996c..192a254329 100644 --- a/core/fpdfdoc/cpdf_occontext.cpp +++ b/core/fpdfdoc/cpdf_occontext.cpp @@ -150,9 +150,9 @@ bool CPDF_OCContext::LoadOCGState(const CPDF_Dictionary* pOCGDict) const { return true; ByteString csState = GetUsageTypeString(m_eUsageType); - CPDF_Dictionary* pUsage = pOCGDict->GetDictFor("Usage"); + const CPDF_Dictionary* pUsage = pOCGDict->GetDictFor("Usage"); if (pUsage) { - CPDF_Dictionary* pState = pUsage->GetDictFor(csState); + const CPDF_Dictionary* pState = pUsage->GetDictFor(csState); if (pState) { ByteString csFind = csState + "State"; if (pState->KeyExist(csFind)) @@ -192,18 +192,18 @@ bool CPDF_OCContext::CheckObjectVisible(const CPDF_PageObject* pObj) { return true; } -bool CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, int nLevel) { +bool CPDF_OCContext::GetOCGVE(const CPDF_Array* pExpression, int nLevel) { if (nLevel > 32 || !pExpression) return false; ByteString csOperator = pExpression->GetStringAt(0); if (csOperator == "Not") { - CPDF_Object* pOCGObj = pExpression->GetDirectObjectAt(1); + const CPDF_Object* pOCGObj = pExpression->GetDirectObjectAt(1); if (!pOCGObj) return false; - if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) + if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) return !GetOCGVisible(pDict); - if (CPDF_Array* pArray = pOCGObj->AsArray()) + if (const CPDF_Array* pArray = pOCGObj->AsArray()) return !GetOCGVE(pArray, nLevel + 1); return false; } @@ -213,14 +213,14 @@ bool CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, int nLevel) { bool bValue = false; for (size_t i = 1; i < pExpression->GetCount(); i++) { - CPDF_Object* pOCGObj = pExpression->GetDirectObjectAt(1); + const CPDF_Object* pOCGObj = pExpression->GetDirectObjectAt(1); if (!pOCGObj) continue; bool bItem = false; - if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) + if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) bItem = GetOCGVisible(pDict); - else if (CPDF_Array* pArray = pOCGObj->AsArray()) + else if (const CPDF_Array* pArray = pOCGObj->AsArray()) bItem = GetOCGVE(pArray, nLevel + 1); if (i == 1) { @@ -237,7 +237,7 @@ bool CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression, int nLevel) { } bool CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict) { - CPDF_Array* pVE = pOCMDDict->GetArrayFor("VE"); + const CPDF_Array* pVE = pOCMDDict->GetArrayFor("VE"); if (pVE) return GetOCGVE(pVE, 0); diff --git a/core/fpdfdoc/cpdf_occontext.h b/core/fpdfdoc/cpdf_occontext.h index c47b93311d..67763610f4 100644 --- a/core/fpdfdoc/cpdf_occontext.h +++ b/core/fpdfdoc/cpdf_occontext.h @@ -35,7 +35,7 @@ class CPDF_OCContext : public Retainable { const CPDF_Dictionary* pOCGDict) const; bool LoadOCGState(const CPDF_Dictionary* pOCGDict) const; bool GetOCGVisible(const CPDF_Dictionary* pOCGDict); - bool GetOCGVE(CPDF_Array* pExpression, int nLevel); + bool GetOCGVE(const CPDF_Array* pExpression, int nLevel); bool LoadOCMDState(const CPDF_Dictionary* pOCMDDict); UnownedPtr<CPDF_Document> const m_pDocument; diff --git a/core/fpdfdoc/cpdf_pagelabel.cpp b/core/fpdfdoc/cpdf_pagelabel.cpp index f06e4018bb..e6a7780a95 100644 --- a/core/fpdfdoc/cpdf_pagelabel.cpp +++ b/core/fpdfdoc/cpdf_pagelabel.cpp @@ -89,12 +89,12 @@ Optional<WideString> CPDF_PageLabel::GetLabel(int nPage) const { if (!pPDFRoot) return {}; - CPDF_Dictionary* pLabels = pPDFRoot->GetDictFor("PageLabels"); + const CPDF_Dictionary* pLabels = pPDFRoot->GetDictFor("PageLabels"); if (!pLabels) return {}; CPDF_NumberTree numberTree(pLabels); - CPDF_Object* pValue = nullptr; + const CPDF_Object* pValue = nullptr; int n = nPage; while (n >= 0) { pValue = numberTree.LookupValue(n); @@ -106,7 +106,7 @@ Optional<WideString> CPDF_PageLabel::GetLabel(int nPage) const { WideString label; if (pValue) { pValue = pValue->GetDirect(); - if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) { + if (const CPDF_Dictionary* pLabel = pValue->AsDictionary()) { if (pLabel->KeyExist("P")) label += pLabel->GetUnicodeTextFor("P"); diff --git a/core/fpdfdoc/cpdf_structelement.cpp b/core/fpdfdoc/cpdf_structelement.cpp index 13985b8fed..ed5c8c7366 100644 --- a/core/fpdfdoc/cpdf_structelement.cpp +++ b/core/fpdfdoc/cpdf_structelement.cpp @@ -17,7 +17,6 @@ CPDF_StructKid::CPDF_StructKid() : m_Type(Invalid), - m_pDict(nullptr), m_PageObjNum(0), m_RefObjNum(0), m_ContentId(0) {} @@ -28,7 +27,7 @@ CPDF_StructKid::~CPDF_StructKid() = default; CPDF_StructElement::CPDF_StructElement(CPDF_StructTree* pTree, CPDF_StructElement* pParent, - CPDF_Dictionary* pDict) + const CPDF_Dictionary* pDict) : m_pTree(pTree), m_pParent(pParent), m_pDict(pDict), @@ -54,10 +53,10 @@ CPDF_StructElement* CPDF_StructElement::GetKidIfElement(size_t index) const { : nullptr; } -void CPDF_StructElement::LoadKids(CPDF_Dictionary* pDict) { - CPDF_Object* pObj = pDict->GetObjectFor("Pg"); +void CPDF_StructElement::LoadKids(const CPDF_Dictionary* pDict) { + const CPDF_Object* pObj = pDict->GetObjectFor("Pg"); uint32_t PageObjNum = 0; - if (CPDF_Reference* pRef = ToReference(pObj)) + if (const CPDF_Reference* pRef = ToReference(pObj)) PageObjNum = pRef->GetRefObjNum(); CPDF_Object* pKids = pDict->GetDirectObjectFor("K"); diff --git a/core/fpdfdoc/cpdf_structelement.h b/core/fpdfdoc/cpdf_structelement.h index 51ee93bd54..2586d9ca13 100644 --- a/core/fpdfdoc/cpdf_structelement.h +++ b/core/fpdfdoc/cpdf_structelement.h @@ -28,7 +28,7 @@ class CPDF_StructKid { enum { Invalid, Element, PageContent, StreamContent, Object } m_Type; RetainPtr<CPDF_StructElement> m_pElement; // For Element. - UnownedPtr<CPDF_Dictionary> m_pDict; // For Element. + UnownedPtr<const CPDF_Dictionary> m_pDict; // For Element. uint32_t m_PageObjNum; // For PageContent, StreamContent, Object. uint32_t m_RefObjNum; // For StreamContent, Object. uint32_t m_ContentId; // For PageContent, StreamContent. @@ -41,7 +41,7 @@ class CPDF_StructElement : public Retainable { const ByteString& GetType() const { return m_Type; } const ByteString& GetTitle() const { return m_Title; } - CPDF_Dictionary* GetDict() const { return m_pDict.Get(); } + const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); } size_t CountKids() const; CPDF_StructElement* GetKidIfElement(size_t index) const; @@ -50,15 +50,15 @@ class CPDF_StructElement : public Retainable { private: CPDF_StructElement(CPDF_StructTree* pTree, CPDF_StructElement* pParent, - CPDF_Dictionary* pDict); + const CPDF_Dictionary* pDict); ~CPDF_StructElement() override; - void LoadKids(CPDF_Dictionary* pDict); + void LoadKids(const CPDF_Dictionary* pDict); void LoadKid(uint32_t PageObjNum, CPDF_Object* pObj, CPDF_StructKid* pKid); UnownedPtr<CPDF_StructTree> const m_pTree; UnownedPtr<CPDF_StructElement> const m_pParent; - UnownedPtr<CPDF_Dictionary> const m_pDict; + UnownedPtr<const CPDF_Dictionary> const m_pDict; ByteString m_Type; ByteString m_Title; std::vector<CPDF_StructKid> m_Kids; diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp index 97db691425..1e4d08aa3c 100644 --- a/core/fpdfdoc/cpdf_structtree.cpp +++ b/core/fpdfdoc/cpdf_structtree.cpp @@ -61,7 +61,7 @@ void CPDF_StructTree::LoadPageTree(const CPDF_Dictionary* pPageDict) { m_Kids.clear(); m_Kids.resize(dwKids); - CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictFor("ParentTree"); + const CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictFor("ParentTree"); if (!pParentTree) return; @@ -70,20 +70,20 @@ void CPDF_StructTree::LoadPageTree(const CPDF_Dictionary* pPageDict) { if (parents_id < 0) return; - CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id)); + const CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id)); if (!pParentArray) return; - std::map<CPDF_Dictionary*, RetainPtr<CPDF_StructElement>> element_map; + StructElementMap element_map; for (size_t i = 0; i < pParentArray->GetCount(); i++) { - if (CPDF_Dictionary* pParent = pParentArray->GetDictAt(i)) + if (const CPDF_Dictionary* pParent = pParentArray->GetDictAt(i)) AddPageNode(pParent, &element_map, 0); } } RetainPtr<CPDF_StructElement> CPDF_StructTree::AddPageNode( - CPDF_Dictionary* pDict, - std::map<CPDF_Dictionary*, RetainPtr<CPDF_StructElement>>* map, + const CPDF_Dictionary* pDict, + StructElementMap* map, int nLevel) { static constexpr int kStructTreeMaxRecursion = 32; if (nLevel > kStructTreeMaxRecursion) @@ -95,7 +95,7 @@ RetainPtr<CPDF_StructElement> CPDF_StructTree::AddPageNode( auto pElement = pdfium::MakeRetain<CPDF_StructElement>(this, nullptr, pDict); (*map)[pDict] = pElement; - CPDF_Dictionary* pParent = pDict->GetDictFor("P"); + const CPDF_Dictionary* pParent = pDict->GetDictFor("P"); if (!pParent || pParent->GetStringFor("Type") == "StructTreeRoot") { if (!AddTopLevelNode(pDict, pElement)) map->erase(pDict); @@ -117,7 +117,7 @@ RetainPtr<CPDF_StructElement> CPDF_StructTree::AddPageNode( } bool CPDF_StructTree::AddTopLevelNode( - CPDF_Dictionary* pDict, + const CPDF_Dictionary* pDict, const RetainPtr<CPDF_StructElement>& pElement) { CPDF_Object* pObj = m_pTreeRoot->GetDirectObjectFor("K"); if (!pObj) diff --git a/core/fpdfdoc/cpdf_structtree.h b/core/fpdfdoc/cpdf_structtree.h index 99342fb6de..13bf148677 100644 --- a/core/fpdfdoc/cpdf_structtree.h +++ b/core/fpdfdoc/cpdf_structtree.h @@ -34,12 +34,14 @@ class CPDF_StructTree { const CPDF_Dictionary* GetTreeRoot() const { return m_pTreeRoot.Get(); } private: + using StructElementMap = + std::map<const CPDF_Dictionary*, RetainPtr<CPDF_StructElement>>; + void LoadPageTree(const CPDF_Dictionary* pPageDict); - RetainPtr<CPDF_StructElement> AddPageNode( - CPDF_Dictionary* pElement, - std::map<CPDF_Dictionary*, RetainPtr<CPDF_StructElement>>* map, - int nLevel); - bool AddTopLevelNode(CPDF_Dictionary* pDict, + RetainPtr<CPDF_StructElement> AddPageNode(const CPDF_Dictionary* pElement, + StructElementMap* map, + int nLevel); + bool AddTopLevelNode(const CPDF_Dictionary* pDict, const RetainPtr<CPDF_StructElement>& pElement); UnownedPtr<const CPDF_Dictionary> const m_pTreeRoot; diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp index aaf8661f1e..6164062164 100644 --- a/core/fpdfdoc/cpvt_fontmap.cpp +++ b/core/fpdfdoc/cpvt_fontmap.cpp @@ -25,8 +25,9 @@ CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc, CPVT_FontMap::~CPVT_FontMap() {} +// static CPDF_Font* CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc, - const CPDF_Dictionary* pResDict, + CPDF_Dictionary* pResDict, ByteString* sSysFontAlias) { if (!pDoc || !pResDict) return nullptr; diff --git a/core/fpdfdoc/cpvt_fontmap.h b/core/fpdfdoc/cpvt_fontmap.h index a0b94cf25a..f1a27753ac 100644 --- a/core/fpdfdoc/cpvt_fontmap.h +++ b/core/fpdfdoc/cpvt_fontmap.h @@ -35,7 +35,7 @@ class CPVT_FontMap : public IPVT_FontMap { int32_t CharSetFromUnicode(uint16_t word, int32_t nOldCharset) override; static CPDF_Font* GetAnnotSysPDFFont(CPDF_Document* pDoc, - const CPDF_Dictionary* pResDict, + CPDF_Dictionary* pResDict, ByteString* sSysFontAlias); private: diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index 22f7c8f5d9..e395fbfa4a 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -313,12 +313,12 @@ ByteString GetColorStringWithDefault(CPDF_Array* pColor, } float GetBorderWidth(const CPDF_Dictionary& pAnnotDict) { - if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) { + if (const CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) { if (pBorderStyleDict->KeyExist("W")) return pBorderStyleDict->GetNumberFor("W"); } - if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) { + if (const CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) { if (pBorderArray->GetCount() > 2) return pBorderArray->GetNumberAt(2); } @@ -326,13 +326,13 @@ float GetBorderWidth(const CPDF_Dictionary& pAnnotDict) { return 1; } -CPDF_Array* GetDashArray(const CPDF_Dictionary& pAnnotDict) { - if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) { +const CPDF_Array* GetDashArray(const CPDF_Dictionary& pAnnotDict) { + if (const CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) { if (pBorderStyleDict->GetStringFor("S") == "D") return pBorderStyleDict->GetArrayFor("D"); } - if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) { + if (const CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) { if (pBorderArray->GetCount() == 4) return pBorderArray->GetArrayAt(3); } @@ -341,7 +341,7 @@ CPDF_Array* GetDashArray(const CPDF_Dictionary& pAnnotDict) { } ByteString GetDashPatternString(const CPDF_Dictionary& pAnnotDict) { - CPDF_Array* pDashArray = GetDashArray(pAnnotDict); + const CPDF_Array* pDashArray = GetDashArray(pAnnotDict); if (!pDashArray || pDashArray->IsEmpty()) return ByteString(); @@ -907,11 +907,11 @@ bool GenerateStrikeOutAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { void CPVT_GenerateAP::GenerateFormAP(Type type, CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - const CPDF_Dictionary* pRootDict = pDoc->GetRoot(); + CPDF_Dictionary* pRootDict = pDoc->GetRoot(); if (!pRootDict) return; - const CPDF_Dictionary* pFormDict = pRootDict->GetDictFor("AcroForm"); + CPDF_Dictionary* pFormDict = pRootDict->GetDictFor("AcroForm"); if (!pFormDict) return; |