summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser')
-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
5 files changed, 51 insertions, 14 deletions
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 {