summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-09 23:15:12 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-09 23:15:12 +0000
commit3774c7a452886b9c8beeb5fa1b54a34611551180 (patch)
treeaba96eeb7d9fc266ecbe7bc460dcaac869514ecf /core/fpdfapi
parent7e28208d26764438bef62e051d2e1fed13e1e0ec (diff)
downloadpdfium-3774c7a452886b9c8beeb5fa1b54a34611551180.tar.xz
Add proper const/non-const versions of CPDF_Array methods.
Instead of having const methods that return non-const pointers. BUG=pdfium:234 Change-Id: I61495543f67229500dfcf2248e93468e9a9b23cf Reviewed-on: https://pdfium-review.googlesource.com/32183 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/edit/cpdf_creator.cpp7
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.cpp10
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.cpp4
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.h6
-rw-r--r--core/fpdfapi/page/cpdf_iccprofile.cpp2
-rw-r--r--core/fpdfapi/page/cpdf_iccprofile.h8
-rw-r--r--core/fpdfapi/parser/cpdf_array.cpp43
-rw-r--r--core/fpdfapi/parser/cpdf_array.h15
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp3
-rw-r--r--core/fpdfapi/parser/cpdf_document.h2
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.cpp2
11 files changed, 71 insertions, 31 deletions
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp
index 872860b0ed..71237f7915 100644
--- a/core/fpdfapi/edit/cpdf_creator.cpp
+++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -258,7 +258,7 @@ bool CPDF_Creator::WriteDirectObj(uint32_t objnum,
const CPDF_Array* p = pObj->AsArray();
for (size_t i = 0; i < p->GetCount(); i++) {
- CPDF_Object* pElement = p->GetObjectAt(i);
+ const CPDF_Object* pElement = p->GetObjectAt(i);
if (!pElement->IsInline()) {
if (!m_Archive->WriteString(" ") ||
!m_Archive->WriteDWord(pElement->GetObjNum()) ||
@@ -773,7 +773,8 @@ void CPDF_Creator::InitID() {
bool idArrayPreExisting = !!m_pIDArray;
if (!idArrayPreExisting) {
m_pIDArray = pdfium::MakeUnique<CPDF_Array>();
- CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr;
+ const CPDF_Object* pID1 =
+ pOldIDArray ? pOldIDArray->GetObjectAt(0) : nullptr;
if (pID1) {
m_pIDArray->Add(pID1->Clone());
} else {
@@ -785,7 +786,7 @@ void CPDF_Creator::InitID() {
}
if (pOldIDArray) {
- CPDF_Object* pID2 = pOldIDArray->GetObjectAt(1);
+ const CPDF_Object* pID2 = pOldIDArray->GetObjectAt(1);
if (IsIncremental() && m_pEncryptDict && pID2) {
m_pIDArray->Add(pID2->Clone());
return;
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 4f68329862..354a342d90 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -854,7 +854,7 @@ CPDF_ICCBasedCS::CPDF_ICCBasedCS(CPDF_Document* pDoc)
CPDF_ICCBasedCS::~CPDF_ICCBasedCS() {
if (m_pProfile && m_pDocument) {
- CPDF_Stream* pStream = m_pProfile->GetStream();
+ const CPDF_Stream* pStream = m_pProfile->GetStream();
m_pProfile.Reset(); // Give up our reference first.
auto* pPageData = m_pDocument->GetPageData();
if (pPageData)
@@ -865,7 +865,7 @@ CPDF_ICCBasedCS::~CPDF_ICCBasedCS() {
uint32_t CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc,
const CPDF_Array* pArray,
std::set<const CPDF_Object*>* pVisited) {
- CPDF_Stream* pStream = pArray->GetStreamAt(1);
+ const CPDF_Stream* pStream = pArray->GetStreamAt(1);
if (!pStream)
return 0;
@@ -1118,13 +1118,13 @@ uint32_t CPDF_IndexedCS::v_Load(CPDF_Document* pDoc,
}
m_MaxIndex = pArray->GetIntegerAt(2);
- CPDF_Object* pTableObj = pArray->GetDirectObjectAt(3);
+ const CPDF_Object* pTableObj = pArray->GetDirectObjectAt(3);
if (!pTableObj)
return 0;
- if (CPDF_String* pString = pTableObj->AsString()) {
+ if (const CPDF_String* pString = pTableObj->AsString()) {
m_Table = pString->GetString();
- } else if (CPDF_Stream* pStream = pTableObj->AsStream()) {
+ } else if (const CPDF_Stream* pStream = pTableObj->AsStream()) {
auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
pAcc->LoadAllDataFiltered();
m_Table = ByteStringView(pAcc->GetData(), pAcc->GetSize());
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index 9ac5c1e304..79e148c72a 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -421,7 +421,7 @@ void CPDF_DocPageData::MaybePurgeImage(uint32_t dwStreamObjNum) {
}
RetainPtr<CPDF_IccProfile> CPDF_DocPageData::GetIccProfile(
- CPDF_Stream* pProfileStream) {
+ const CPDF_Stream* pProfileStream) {
if (!pProfileStream)
return nullptr;
@@ -449,7 +449,7 @@ RetainPtr<CPDF_IccProfile> CPDF_DocPageData::GetIccProfile(
return pProfile;
}
-void CPDF_DocPageData::MaybePurgeIccProfile(CPDF_Stream* pProfileStream) {
+void CPDF_DocPageData::MaybePurgeIccProfile(const CPDF_Stream* pProfileStream) {
ASSERT(pProfileStream);
auto it = m_IccProfileMap.find(pProfileStream);
if (it != m_IccProfileMap.end() && it->second->HasOneRef())
diff --git a/core/fpdfapi/page/cpdf_docpagedata.h b/core/fpdfapi/page/cpdf_docpagedata.h
index 2d22ee991d..04b77cf3ed 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.h
+++ b/core/fpdfapi/page/cpdf_docpagedata.h
@@ -61,8 +61,8 @@ class CPDF_DocPageData {
RetainPtr<CPDF_Image> GetImage(uint32_t dwStreamObjNum);
void MaybePurgeImage(uint32_t dwStreamObjNum);
- RetainPtr<CPDF_IccProfile> GetIccProfile(CPDF_Stream* pProfileStream);
- void MaybePurgeIccProfile(CPDF_Stream* pProfileStream);
+ RetainPtr<CPDF_IccProfile> GetIccProfile(const CPDF_Stream* pProfileStream);
+ void MaybePurgeIccProfile(const CPDF_Stream* pProfileStream);
RetainPtr<CPDF_StreamAcc> GetFontFileStreamAcc(CPDF_Stream* pFontStream);
void MaybePurgeFontFileStreamAcc(const CPDF_Stream* pFontStream);
@@ -86,7 +86,7 @@ class CPDF_DocPageData {
bool m_bForceClear;
UnownedPtr<CPDF_Document> const m_pPDFDoc;
- std::map<ByteString, CPDF_Stream*> m_HashProfileMap;
+ std::map<ByteString, const CPDF_Stream*> m_HashProfileMap;
std::map<const CPDF_Object*, CPDF_CountedColorSpace*> m_ColorSpaceMap;
std::map<const CPDF_Stream*, RetainPtr<CPDF_StreamAcc>> m_FontFileMap;
std::map<const CPDF_Dictionary*, CPDF_CountedFont*> m_FontMap;
diff --git a/core/fpdfapi/page/cpdf_iccprofile.cpp b/core/fpdfapi/page/cpdf_iccprofile.cpp
index 144f530a2c..c0bf7cd2a2 100644
--- a/core/fpdfapi/page/cpdf_iccprofile.cpp
+++ b/core/fpdfapi/page/cpdf_iccprofile.cpp
@@ -18,7 +18,7 @@ bool DetectSRGB(const uint8_t* pData, uint32_t dwSize) {
} // namespace
-CPDF_IccProfile::CPDF_IccProfile(CPDF_Stream* pStream,
+CPDF_IccProfile::CPDF_IccProfile(const CPDF_Stream* pStream,
const uint8_t* pData,
uint32_t dwSize)
: m_bsRGB(DetectSRGB(pData, dwSize)), m_pStream(pStream) {
diff --git a/core/fpdfapi/page/cpdf_iccprofile.h b/core/fpdfapi/page/cpdf_iccprofile.h
index 1bc498aa1f..a5c9f6dbfe 100644
--- a/core/fpdfapi/page/cpdf_iccprofile.h
+++ b/core/fpdfapi/page/cpdf_iccprofile.h
@@ -20,7 +20,7 @@ class CPDF_IccProfile : public Retainable {
template <typename T, typename... Args>
friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
- CPDF_Stream* GetStream() const { return m_pStream.Get(); }
+ const CPDF_Stream* GetStream() const { return m_pStream.Get(); }
bool IsValid() const { return IsSRGB() || IsSupported(); }
bool IsSRGB() const { return m_bsRGB; }
bool IsSupported() const { return !!m_Transform; }
@@ -28,11 +28,13 @@ class CPDF_IccProfile : public Retainable {
uint32_t GetComponents() const { return m_nSrcComponents; }
private:
- CPDF_IccProfile(CPDF_Stream* pStream, const uint8_t* pData, uint32_t dwSize);
+ CPDF_IccProfile(const CPDF_Stream* pStream,
+ const uint8_t* pData,
+ uint32_t dwSize);
~CPDF_IccProfile() override;
const bool m_bsRGB;
- UnownedPtr<CPDF_Stream> const m_pStream;
+ UnownedPtr<const CPDF_Stream> const m_pStream;
std::unique_ptr<CLcmsCmm> m_Transform;
uint32_t m_nSrcComponents = 0;
};
diff --git a/core/fpdfapi/parser/cpdf_array.cpp b/core/fpdfapi/parser/cpdf_array.cpp
index 9293101b32..4f802d9e7f 100644
--- a/core/fpdfapi/parser/cpdf_array.cpp
+++ b/core/fpdfapi/parser/cpdf_array.cpp
@@ -87,13 +87,25 @@ CFX_Matrix CPDF_Array::GetMatrix() const {
GetNumberAt(3), GetNumberAt(4), GetNumberAt(5));
}
-CPDF_Object* CPDF_Array::GetObjectAt(size_t i) const {
+CPDF_Object* CPDF_Array::GetObjectAt(size_t i) {
if (i >= m_Objects.size())
return nullptr;
return m_Objects[i].get();
}
-CPDF_Object* CPDF_Array::GetDirectObjectAt(size_t i) const {
+const CPDF_Object* CPDF_Array::GetObjectAt(size_t i) const {
+ if (i >= m_Objects.size())
+ return nullptr;
+ return m_Objects[i].get();
+}
+
+CPDF_Object* CPDF_Array::GetDirectObjectAt(size_t i) {
+ if (i >= m_Objects.size())
+ return nullptr;
+ return m_Objects[i]->GetDirect();
+}
+
+const CPDF_Object* CPDF_Array::GetDirectObjectAt(size_t i) const {
if (i >= m_Objects.size())
return nullptr;
return m_Objects[i]->GetDirect();
@@ -123,7 +135,7 @@ float CPDF_Array::GetNumberAt(size_t i) const {
return m_Objects[i]->GetNumber();
}
-CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) const {
+CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) {
CPDF_Object* p = GetDirectObjectAt(i);
if (!p)
return nullptr;
@@ -134,11 +146,30 @@ CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) const {
return nullptr;
}
-CPDF_Stream* CPDF_Array::GetStreamAt(size_t i) const {
+const CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) const {
+ const CPDF_Object* p = GetDirectObjectAt(i);
+ if (!p)
+ return nullptr;
+ if (const CPDF_Dictionary* pDict = p->AsDictionary())
+ return pDict;
+ if (const CPDF_Stream* pStream = p->AsStream())
+ return pStream->GetDict();
+ return nullptr;
+}
+
+CPDF_Stream* CPDF_Array::GetStreamAt(size_t i) {
return ToStream(GetDirectObjectAt(i));
}
-CPDF_Array* CPDF_Array::GetArrayAt(size_t i) const {
+const CPDF_Stream* CPDF_Array::GetStreamAt(size_t i) const {
+ return ToStream(GetDirectObjectAt(i));
+}
+
+CPDF_Array* CPDF_Array::GetArrayAt(size_t i) {
+ return ToArray(GetDirectObjectAt(i));
+}
+
+const CPDF_Array* CPDF_Array::GetArrayAt(size_t i) const {
return ToArray(GetDirectObjectAt(i));
}
@@ -204,7 +235,7 @@ bool CPDF_Array::WriteTo(IFX_ArchiveStream* archive) const {
return false;
for (size_t i = 0; i < GetCount(); ++i) {
- CPDF_Object* pElement = GetObjectAt(i);
+ const CPDF_Object* pElement = GetObjectAt(i);
if (!pElement->IsInline()) {
if (!archive->WriteString(" ") ||
!archive->WriteDWord(pElement->GetObjNum()) ||
diff --git a/core/fpdfapi/parser/cpdf_array.h b/core/fpdfapi/parser/cpdf_array.h
index 442b85cc80..d980b14507 100644
--- a/core/fpdfapi/parser/cpdf_array.h
+++ b/core/fpdfapi/parser/cpdf_array.h
@@ -37,15 +37,20 @@ class CPDF_Array : public CPDF_Object {
bool IsEmpty() const { return m_Objects.empty(); }
size_t GetCount() const { return m_Objects.size(); }
- CPDF_Object* GetObjectAt(size_t index) const;
- CPDF_Object* GetDirectObjectAt(size_t index) const;
+ CPDF_Object* GetObjectAt(size_t index);
+ const CPDF_Object* GetObjectAt(size_t index) const;
+ CPDF_Object* GetDirectObjectAt(size_t index);
+ const CPDF_Object* GetDirectObjectAt(size_t index) const;
ByteString GetStringAt(size_t index) const;
WideString GetUnicodeTextAt(size_t index) const;
int GetIntegerAt(size_t index) const;
float GetNumberAt(size_t index) const;
- CPDF_Dictionary* GetDictAt(size_t index) const;
- CPDF_Stream* GetStreamAt(size_t index) const;
- CPDF_Array* GetArrayAt(size_t index) const;
+ CPDF_Dictionary* GetDictAt(size_t index);
+ const CPDF_Dictionary* GetDictAt(size_t index) const;
+ CPDF_Stream* GetStreamAt(size_t index);
+ const CPDF_Stream* GetStreamAt(size_t index) const;
+ CPDF_Array* GetArrayAt(size_t index);
+ const CPDF_Array* GetArrayAt(size_t index) const;
float GetFloatAt(size_t index) const { return GetNumberAt(index); }
CFX_Matrix GetMatrix() const;
CFX_FloatRect GetRect() const;
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index fea0bddb33..982539cd72 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -491,7 +491,8 @@ CPDF_Pattern* CPDF_Document::LoadPattern(CPDF_Object* pPatternObj,
return m_pDocPage->GetPattern(pPatternObj, bShading, matrix);
}
-RetainPtr<CPDF_IccProfile> CPDF_Document::LoadIccProfile(CPDF_Stream* pStream) {
+RetainPtr<CPDF_IccProfile> CPDF_Document::LoadIccProfile(
+ const CPDF_Stream* pStream) {
return m_pDocPage->GetIccProfile(pStream);
}
diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h
index 6357049777..4bbc6939e2 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -92,7 +92,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
RetainPtr<CPDF_Image> LoadImageFromPageData(uint32_t dwStreamObjNum);
RetainPtr<CPDF_StreamAcc> LoadFontFile(CPDF_Stream* pStream);
- RetainPtr<CPDF_IccProfile> LoadIccProfile(CPDF_Stream* pStream);
+ RetainPtr<CPDF_IccProfile> LoadIccProfile(const CPDF_Stream* pStream);
void LoadDoc();
void LoadLinearizedDoc(const CPDF_LinearizedHeader* pLinearizationParams);
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index 2c0b0818f1..1dad2a8ab3 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -180,7 +180,7 @@ std::ostream& operator<<(std::ostream& buf, const CPDF_Object* pObj) {
const CPDF_Array* p = pObj->AsArray();
buf << "[";
for (size_t i = 0; i < p->GetCount(); i++) {
- CPDF_Object* pElement = p->GetObjectAt(i);
+ const CPDF_Object* pElement = p->GetObjectAt(i);
if (pElement && !pElement->IsInline()) {
buf << " " << pElement->GetObjNum() << " 0 R";
} else {