summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp1
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp7
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_parser/cfdf_document.cpp1
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_array.cpp207
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_boolean.cpp45
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_data_avail.cpp7
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_dictionary.cpp271
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_document.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp80
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_name.cpp53
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_null.cpp17
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_number.cpp56
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_object.cpp158
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp (renamed from core/src/fpdfapi/fpdf_parser/fpdf_parser_objects_unittest.cpp)11
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_reference.cpp72
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_stream.cpp232
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_string.cpp56
-rw-r--r--core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp10
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp1148
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp7
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp1
42 files changed, 1349 insertions, 1155 deletions
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp
index cb3f8810ac..a8fddf6cfc 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp
@@ -4,6 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
index 099a5c208e..9a318eb824 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
@@ -8,8 +8,12 @@
#include <vector>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/cpdf_parser.h"
+#include "core/include/fpdfapi/cpdf_string.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
#include "core/include/fpdfapi/fpdf_parser_decode.h"
#include "core/include/fpdfapi/fpdf_serial.h"
#include "core/include/fpdfapi/ipdf_crypto_handler.h"
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
index df9c13714d..1d21727f72 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
@@ -6,7 +6,10 @@
#include <limits.h>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/src/fpdfapi/fpdf_page/pageint.h"
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
index 0d2f83682e..47e8367420 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp
@@ -4,7 +4,11 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_boolean.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
+#include "core/include/fpdfapi/cpdf_string.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fpdfapi/fpdf_render.h"
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 9b4c39aa84..ae6ebdd9f8 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -6,7 +6,11 @@
#include "core/src/fpdfapi/fpdf_font/font_int.h"
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
+#include "core/include/fpdfapi/cpdf_name.h"
+#include "core/include/fpdfapi/cpdf_number.h"
#include "core/include/fpdfapi/cpdf_simple_parser.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 1ea686e9e0..b86c2778db 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -6,6 +6,8 @@
#include "core/src/fpdfapi/fpdf_font/font_int.h"
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_simple_parser.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
index 1868d263d3..c7ebc67452 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
@@ -8,6 +8,8 @@
#include <algorithm>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
index 058cbe77d4..9a4c41017d 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
@@ -10,7 +10,10 @@
#include <algorithm>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
+#include "core/include/fpdfapi/cpdf_string.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fxcodec/fx_codec.h"
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index fbf236d472..7c5a0eab42 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -7,6 +7,8 @@
#include "core/src/fpdfapi/fpdf_page/pageint.h"
#include "core/include/fdrm/fx_crypt.h"
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
index e9ea7eb74f..1d7bf64903 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
@@ -12,6 +12,8 @@
#include <utility>
#include <vector>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_simple_parser.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
index eff2ff4009..1659cacc33 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -8,6 +8,8 @@
#include <algorithm>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
index 64d3264128..b7e3e5e116 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
@@ -6,6 +6,7 @@
#include "core/src/fpdfapi/fpdf_page/pageint.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fpdfapi/fpdf_pageobj.h"
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index 5ef5b48af3..1b6e5ac965 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -8,7 +8,12 @@
#include <vector>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
+#include "core/include/fpdfapi/cpdf_name.h"
+#include "core/include/fpdfapi/cpdf_number.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fpdfapi/fpdf_parser_decode.h"
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index 8bfb8b2f6b..feb2cde346 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -8,7 +8,14 @@
#include <limits.h>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_boolean.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
+#include "core/include/fpdfapi/cpdf_name.h"
+#include "core/include/fpdfapi/cpdf_null.h"
+#include "core/include/fpdfapi/cpdf_number.h"
+#include "core/include/fpdfapi/cpdf_string.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fpdfapi/fpdf_parser_decode.h"
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
index 7e8b2e525b..0db1c403a4 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
@@ -8,6 +8,8 @@
#include <algorithm>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_page.h"
diff --git a/core/src/fpdfapi/fpdf_parser/cfdf_document.cpp b/core/src/fpdfapi/fpdf_parser/cfdf_document.cpp
index c2a6e33604..2d1a04f081 100644
--- a/core/src/fpdfapi/fpdf_parser/cfdf_document.cpp
+++ b/core/src/fpdfapi/fpdf_parser/cfdf_document.cpp
@@ -6,6 +6,7 @@
#include "core/include/fpdfapi/cfdf_document.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/fpdf_serial.h"
#include "core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.h"
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_array.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_array.cpp
new file mode 100644
index 0000000000..3b21a45ae2
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_array.cpp
@@ -0,0 +1,207 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_array.h"
+
+#include "core/include/fpdfapi/cpdf_name.h"
+#include "core/include/fpdfapi/cpdf_number.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
+#include "core/include/fpdfapi/cpdf_stream.h"
+#include "core/include/fpdfapi/cpdf_string.h"
+
+CPDF_Array::CPDF_Array() {}
+
+CPDF_Array::~CPDF_Array() {
+ int size = m_Objects.GetSize();
+ CPDF_Object** pList = m_Objects.GetData();
+ for (int i = 0; i < size; i++) {
+ if (pList[i])
+ pList[i]->Release();
+ }
+}
+
+CPDF_Object::Type CPDF_Array::GetType() const {
+ return ARRAY;
+}
+
+CPDF_Array* CPDF_Array::GetArray() const {
+ // The method should be made non-const if we want to not be const.
+ // See bug #234.
+ return const_cast<CPDF_Array*>(this);
+}
+
+bool CPDF_Array::IsArray() const {
+ return true;
+}
+
+CPDF_Array* CPDF_Array::AsArray() {
+ return this;
+}
+
+const CPDF_Array* CPDF_Array::AsArray() const {
+ return this;
+}
+
+CPDF_Object* CPDF_Array::Clone(FX_BOOL bDirect) const {
+ CPDF_Array* pCopy = new CPDF_Array();
+ for (int i = 0; i < GetCount(); i++) {
+ CPDF_Object* value = m_Objects.GetAt(i);
+ pCopy->m_Objects.Add(value->Clone(bDirect));
+ }
+ return pCopy;
+}
+
+CFX_FloatRect CPDF_Array::GetRect() {
+ CFX_FloatRect rect;
+ if (!IsArray() || m_Objects.GetSize() != 4)
+ return rect;
+
+ rect.left = GetNumberAt(0);
+ rect.bottom = GetNumberAt(1);
+ rect.right = GetNumberAt(2);
+ rect.top = GetNumberAt(3);
+ return rect;
+}
+
+CFX_Matrix CPDF_Array::GetMatrix() {
+ CFX_Matrix matrix;
+ if (!IsArray() || m_Objects.GetSize() != 6)
+ return matrix;
+
+ matrix.Set(GetNumberAt(0), GetNumberAt(1), GetNumberAt(2), GetNumberAt(3),
+ GetNumberAt(4), GetNumberAt(5));
+ return matrix;
+}
+
+CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const {
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return nullptr;
+ return m_Objects.GetAt(i);
+}
+
+CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const {
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return nullptr;
+ return m_Objects.GetAt(i)->GetDirect();
+}
+
+CFX_ByteString CPDF_Array::GetStringAt(FX_DWORD i) const {
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return CFX_ByteString();
+ return m_Objects.GetAt(i)->GetString();
+}
+
+CFX_ByteStringC CPDF_Array::GetConstStringAt(FX_DWORD i) const {
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return CFX_ByteStringC();
+ return m_Objects.GetAt(i)->GetConstString();
+}
+
+int CPDF_Array::GetIntegerAt(FX_DWORD i) const {
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return 0;
+ return m_Objects.GetAt(i)->GetInteger();
+}
+
+FX_FLOAT CPDF_Array::GetNumberAt(FX_DWORD i) const {
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return 0;
+ return m_Objects.GetAt(i)->GetNumber();
+}
+
+CPDF_Dictionary* CPDF_Array::GetDictAt(FX_DWORD i) const {
+ CPDF_Object* p = GetElementValue(i);
+ if (!p)
+ return NULL;
+ if (CPDF_Dictionary* pDict = p->AsDictionary())
+ return pDict;
+ if (CPDF_Stream* pStream = p->AsStream())
+ return pStream->GetDict();
+ return NULL;
+}
+
+CPDF_Stream* CPDF_Array::GetStreamAt(FX_DWORD i) const {
+ return ToStream(GetElementValue(i));
+}
+
+CPDF_Array* CPDF_Array::GetArrayAt(FX_DWORD i) const {
+ return ToArray(GetElementValue(i));
+}
+
+void CPDF_Array::RemoveAt(FX_DWORD i, int nCount) {
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return;
+
+ if (nCount <= 0 || nCount > m_Objects.GetSize() - i)
+ return;
+
+ for (int j = 0; j < nCount; ++j) {
+ if (CPDF_Object* p = m_Objects.GetAt(i + j))
+ p->Release();
+ }
+ m_Objects.RemoveAt(i, nCount);
+}
+
+void CPDF_Array::SetAt(FX_DWORD i,
+ CPDF_Object* pObj,
+ CPDF_IndirectObjectHolder* pObjs) {
+ ASSERT(IsArray());
+ ASSERT(i < (FX_DWORD)m_Objects.GetSize());
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return;
+ if (CPDF_Object* pOld = m_Objects.GetAt(i))
+ pOld->Release();
+ if (pObj->GetObjNum()) {
+ ASSERT(pObjs);
+ pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
+ }
+ m_Objects.SetAt(i, pObj);
+}
+
+void CPDF_Array::InsertAt(FX_DWORD index,
+ CPDF_Object* pObj,
+ CPDF_IndirectObjectHolder* pObjs) {
+ if (pObj->GetObjNum()) {
+ ASSERT(pObjs);
+ pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
+ }
+ m_Objects.InsertAt(index, pObj);
+}
+
+void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs) {
+ if (pObj->GetObjNum()) {
+ ASSERT(pObjs);
+ pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
+ }
+ m_Objects.Add(pObj);
+}
+
+void CPDF_Array::AddName(const CFX_ByteString& str) {
+ ASSERT(IsArray());
+ Add(new CPDF_Name(str));
+}
+
+void CPDF_Array::AddString(const CFX_ByteString& str) {
+ ASSERT(IsArray());
+ Add(new CPDF_String(str, FALSE));
+}
+
+void CPDF_Array::AddInteger(int i) {
+ ASSERT(IsArray());
+ Add(new CPDF_Number(i));
+}
+
+void CPDF_Array::AddNumber(FX_FLOAT f) {
+ ASSERT(IsArray());
+ CPDF_Number* pNumber = new CPDF_Number(f);
+ Add(pNumber);
+}
+
+void CPDF_Array::AddReference(CPDF_IndirectObjectHolder* pDoc,
+ FX_DWORD objnum) {
+ ASSERT(IsArray());
+ Add(new CPDF_Reference(pDoc, objnum));
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_boolean.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_boolean.cpp
new file mode 100644
index 0000000000..75f2203954
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_boolean.cpp
@@ -0,0 +1,45 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_boolean.h"
+
+CPDF_Boolean::CPDF_Boolean() : m_bValue(false) {}
+
+CPDF_Boolean::CPDF_Boolean(FX_BOOL value) : m_bValue(value) {}
+
+CPDF_Boolean::~CPDF_Boolean() {}
+
+CPDF_Object::Type CPDF_Boolean::GetType() const {
+ return BOOLEAN;
+}
+
+CPDF_Object* CPDF_Boolean::Clone(FX_BOOL bDirect) const {
+ return new CPDF_Boolean(m_bValue);
+}
+
+CFX_ByteString CPDF_Boolean::GetString() const {
+ return m_bValue ? "true" : "false";
+}
+
+int CPDF_Boolean::GetInteger() const {
+ return m_bValue;
+}
+
+void CPDF_Boolean::SetString(const CFX_ByteString& str) {
+ m_bValue = (str == "true");
+}
+
+bool CPDF_Boolean::IsBoolean() const {
+ return true;
+}
+
+CPDF_Boolean* CPDF_Boolean::AsBoolean() {
+ return this;
+}
+
+const CPDF_Boolean* CPDF_Boolean::AsBoolean() const {
+ return this;
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_data_avail.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_data_avail.cpp
index 19905f871f..5ab15a3b76 100644
--- a/core/src/fpdfapi/fpdf_parser/cpdf_data_avail.cpp
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_data_avail.cpp
@@ -4,8 +4,13 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
-#include "core/include/fpdfapi/fpdf_objects.h"
+#include "core/include/fpdfapi/cpdf_name.h"
+#include "core/include/fpdfapi/cpdf_number.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
+#include "core/include/fpdfapi/cpdf_stream.h"
#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxcrt/fx_safe_types.h"
#include "core/src/fpdfapi/fpdf_parser/cpdf_data_avail.h"
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_dictionary.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_dictionary.cpp
new file mode 100644
index 0000000000..864cd59744
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_dictionary.cpp
@@ -0,0 +1,271 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_dictionary.h"
+
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_boolean.h"
+#include "core/include/fpdfapi/cpdf_name.h"
+#include "core/include/fpdfapi/cpdf_number.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
+#include "core/include/fpdfapi/cpdf_stream.h"
+#include "core/include/fpdfapi/cpdf_string.h"
+#include "third_party/base/stl_util.h"
+
+CPDF_Dictionary::CPDF_Dictionary() {}
+
+CPDF_Dictionary::~CPDF_Dictionary() {
+ for (const auto& it : m_Map)
+ it.second->Release();
+}
+
+CPDF_Object::Type CPDF_Dictionary::GetType() const {
+ return DICTIONARY;
+}
+
+CPDF_Dictionary* CPDF_Dictionary::GetDict() const {
+ // The method should be made non-const if we want to not be const.
+ // See bug #234.
+ return const_cast<CPDF_Dictionary*>(this);
+}
+
+bool CPDF_Dictionary::IsDictionary() const {
+ return true;
+}
+
+CPDF_Dictionary* CPDF_Dictionary::AsDictionary() {
+ return this;
+}
+
+const CPDF_Dictionary* CPDF_Dictionary::AsDictionary() const {
+ return this;
+}
+
+CPDF_Object* CPDF_Dictionary::Clone(FX_BOOL bDirect) const {
+ CPDF_Dictionary* pCopy = new CPDF_Dictionary();
+ for (const auto& it : *this)
+ pCopy->m_Map.insert(std::make_pair(it.first, it.second->Clone(bDirect)));
+ return pCopy;
+}
+
+CPDF_Object* CPDF_Dictionary::GetElement(const CFX_ByteStringC& key) const {
+ auto it = m_Map.find(key);
+ if (it == m_Map.end())
+ return nullptr;
+ return it->second;
+}
+CPDF_Object* CPDF_Dictionary::GetElementValue(
+ const CFX_ByteStringC& key) const {
+ CPDF_Object* p = GetElement(key);
+ return p ? p->GetDirect() : nullptr;
+}
+
+CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key) const {
+ CPDF_Object* p = GetElement(key);
+ return p ? p->GetString() : CFX_ByteString();
+}
+
+CFX_ByteStringC CPDF_Dictionary::GetConstStringBy(
+ const CFX_ByteStringC& key) const {
+ CPDF_Object* p = GetElement(key);
+ return p ? p->GetConstString() : CFX_ByteStringC();
+}
+
+CFX_WideString CPDF_Dictionary::GetUnicodeTextBy(
+ const CFX_ByteStringC& key) const {
+ CPDF_Object* p = GetElement(key);
+ if (CPDF_Reference* pRef = ToReference(p))
+ p = pRef->GetDirect();
+ return p ? p->GetUnicodeText() : CFX_WideString();
+}
+
+CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key,
+ const CFX_ByteStringC& def) const {
+ CPDF_Object* p = GetElement(key);
+ return p ? p->GetString() : CFX_ByteString(def);
+}
+
+CFX_ByteStringC CPDF_Dictionary::GetConstStringBy(
+ const CFX_ByteStringC& key,
+ const CFX_ByteStringC& def) const {
+ CPDF_Object* p = GetElement(key);
+ return p ? p->GetConstString() : CFX_ByteStringC(def);
+}
+
+int CPDF_Dictionary::GetIntegerBy(const CFX_ByteStringC& key) const {
+ CPDF_Object* p = GetElement(key);
+ return p ? p->GetInteger() : 0;
+}
+
+int CPDF_Dictionary::GetIntegerBy(const CFX_ByteStringC& key, int def) const {
+ CPDF_Object* p = GetElement(key);
+ return p ? p->GetInteger() : def;
+}
+
+FX_FLOAT CPDF_Dictionary::GetNumberBy(const CFX_ByteStringC& key) const {
+ CPDF_Object* p = GetElement(key);
+ return p ? p->GetNumber() : 0;
+}
+
+FX_BOOL CPDF_Dictionary::GetBooleanBy(const CFX_ByteStringC& key,
+ FX_BOOL bDefault) const {
+ CPDF_Object* p = GetElement(key);
+ return ToBoolean(p) ? p->GetInteger() : bDefault;
+}
+
+CPDF_Dictionary* CPDF_Dictionary::GetDictBy(const CFX_ByteStringC& key) const {
+ CPDF_Object* p = GetElementValue(key);
+ if (!p)
+ return nullptr;
+ if (CPDF_Dictionary* pDict = p->AsDictionary())
+ return pDict;
+ if (CPDF_Stream* pStream = p->AsStream())
+ return pStream->GetDict();
+ return nullptr;
+}
+
+CPDF_Array* CPDF_Dictionary::GetArrayBy(const CFX_ByteStringC& key) const {
+ return ToArray(GetElementValue(key));
+}
+
+CPDF_Stream* CPDF_Dictionary::GetStreamBy(const CFX_ByteStringC& key) const {
+ return ToStream(GetElementValue(key));
+}
+
+CFX_FloatRect CPDF_Dictionary::GetRectBy(const CFX_ByteStringC& key) const {
+ CFX_FloatRect rect;
+ CPDF_Array* pArray = GetArrayBy(key);
+ if (pArray)
+ rect = pArray->GetRect();
+ return rect;
+}
+
+CFX_Matrix CPDF_Dictionary::GetMatrixBy(const CFX_ByteStringC& key) const {
+ CFX_Matrix matrix;
+ CPDF_Array* pArray = GetArrayBy(key);
+ if (pArray)
+ matrix = pArray->GetMatrix();
+ return matrix;
+}
+
+FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const {
+ return pdfium::ContainsKey(m_Map, key);
+}
+
+bool CPDF_Dictionary::IsSignatureDict() const {
+ CPDF_Object* pType = GetElementValue("Type");
+ if (!pType)
+ pType = GetElementValue("FT");
+ return pType && pType->GetString() == "Sig";
+}
+
+void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj) {
+ ASSERT(IsDictionary());
+ // Avoid 2 constructions of CFX_ByteString.
+ CFX_ByteString key_bytestring = key;
+ auto it = m_Map.find(key_bytestring);
+ if (it == m_Map.end()) {
+ if (pObj)
+ m_Map.insert(std::make_pair(key_bytestring, pObj));
+ return;
+ }
+
+ if (it->second == pObj)
+ return;
+ it->second->Release();
+
+ if (pObj)
+ it->second = pObj;
+ else
+ m_Map.erase(it);
+}
+
+void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) {
+ auto it = m_Map.find(key);
+ if (it == m_Map.end())
+ return;
+
+ it->second->Release();
+ m_Map.erase(it);
+}
+
+void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey,
+ const CFX_ByteStringC& newkey) {
+ auto old_it = m_Map.find(oldkey);
+ if (old_it == m_Map.end())
+ return;
+
+ // Avoid 2 constructions of CFX_ByteString.
+ CFX_ByteString newkey_bytestring = newkey;
+ auto new_it = m_Map.find(newkey_bytestring);
+ if (new_it == old_it)
+ return;
+
+ if (new_it != m_Map.end()) {
+ new_it->second->Release();
+ new_it->second = old_it->second;
+ } else {
+ m_Map.insert(std::make_pair(newkey_bytestring, old_it->second));
+ }
+ m_Map.erase(old_it);
+}
+
+void CPDF_Dictionary::SetAtInteger(const CFX_ByteStringC& key, int i) {
+ SetAt(key, new CPDF_Number(i));
+}
+
+void CPDF_Dictionary::SetAtName(const CFX_ByteStringC& key,
+ const CFX_ByteString& name) {
+ SetAt(key, new CPDF_Name(name));
+}
+
+void CPDF_Dictionary::SetAtString(const CFX_ByteStringC& key,
+ const CFX_ByteString& str) {
+ SetAt(key, new CPDF_String(str, FALSE));
+}
+
+void CPDF_Dictionary::SetAtReference(const CFX_ByteStringC& key,
+ CPDF_IndirectObjectHolder* pDoc,
+ FX_DWORD objnum) {
+ SetAt(key, new CPDF_Reference(pDoc, objnum));
+}
+
+void CPDF_Dictionary::AddReference(const CFX_ByteStringC& key,
+ CPDF_IndirectObjectHolder* pDoc,
+ FX_DWORD objnum) {
+ SetAt(key, new CPDF_Reference(pDoc, objnum));
+}
+
+void CPDF_Dictionary::SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f) {
+ CPDF_Number* pNumber = new CPDF_Number(f);
+ SetAt(key, pNumber);
+}
+
+void CPDF_Dictionary::SetAtBoolean(const CFX_ByteStringC& key, FX_BOOL bValue) {
+ SetAt(key, new CPDF_Boolean(bValue));
+}
+
+void CPDF_Dictionary::SetAtRect(const CFX_ByteStringC& key,
+ const CFX_FloatRect& rect) {
+ CPDF_Array* pArray = new CPDF_Array;
+ pArray->AddNumber(rect.left);
+ pArray->AddNumber(rect.bottom);
+ pArray->AddNumber(rect.right);
+ pArray->AddNumber(rect.top);
+ SetAt(key, pArray);
+}
+
+void CPDF_Dictionary::SetAtMatrix(const CFX_ByteStringC& key,
+ const CFX_Matrix& matrix) {
+ CPDF_Array* pArray = new CPDF_Array;
+ pArray->AddNumber(matrix.a);
+ pArray->AddNumber(matrix.b);
+ pArray->AddNumber(matrix.c);
+ pArray->AddNumber(matrix.d);
+ pArray->AddNumber(matrix.e);
+ pArray->AddNumber(matrix.f);
+ SetAt(key, pArray);
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_document.cpp
index 394b17334e..b5789410e5 100644
--- a/core/src/fpdfapi/fpdf_parser/cpdf_document.cpp
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_document.cpp
@@ -8,7 +8,10 @@
#include <set>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_parser.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fxge/fx_font.h"
#include "core/src/fpdfapi/fpdf_render/render_int.h"
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
index 09148ba76a..6256f4c526 100644
--- a/core/src/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
@@ -7,7 +7,9 @@
#include "core/src/fpdfapi/fpdf_parser/cpdf_hint_tables.h"
#include "core/include/fxcrt/fx_safe_types.h"
-#include "core/include/fpdfapi/fpdf_objects.h"
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
+#include "core/include/fpdfapi/cpdf_stream.h"
#include "core/src/fpdfapi/fpdf_parser/cpdf_data_avail.h"
namespace {
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
new file mode 100644
index 0000000000..b1606f9857
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
@@ -0,0 +1,80 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_indirect_object_holder.h"
+#include "core/include/fpdfapi/cpdf_object.h"
+#include "core/include/fpdfapi/cpdf_parser.h"
+
+CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser)
+ : m_pParser(pParser), m_LastObjNum(0) {
+ if (pParser)
+ m_LastObjNum = m_pParser->GetLastObjNum();
+}
+
+CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {
+ for (const auto& pair : m_IndirectObjs)
+ pair.second->Destroy();
+}
+
+CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(FX_DWORD objnum) {
+ if (objnum == 0)
+ return nullptr;
+
+ auto it = m_IndirectObjs.find(objnum);
+ if (it != m_IndirectObjs.end())
+ return it->second->GetObjNum() != -1 ? it->second : nullptr;
+
+ if (!m_pParser)
+ return nullptr;
+
+ CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum);
+ if (!pObj)
+ return nullptr;
+
+ pObj->m_ObjNum = objnum;
+ m_LastObjNum = std::max(m_LastObjNum, objnum);
+ if (m_IndirectObjs[objnum])
+ m_IndirectObjs[objnum]->Destroy();
+
+ m_IndirectObjs[objnum] = pObj;
+ return pObj;
+}
+
+FX_DWORD CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) {
+ if (pObj->m_ObjNum)
+ return pObj->m_ObjNum;
+
+ m_LastObjNum++;
+ m_IndirectObjs[m_LastObjNum] = pObj;
+ pObj->m_ObjNum = m_LastObjNum;
+ return m_LastObjNum;
+}
+
+void CPDF_IndirectObjectHolder::ReleaseIndirectObject(FX_DWORD objnum) {
+ auto it = m_IndirectObjs.find(objnum);
+ if (it == m_IndirectObjs.end() || it->second->GetObjNum() == -1)
+ return;
+ it->second->Destroy();
+ m_IndirectObjs.erase(it);
+}
+
+FX_BOOL CPDF_IndirectObjectHolder::InsertIndirectObject(FX_DWORD objnum,
+ CPDF_Object* pObj) {
+ if (!objnum || !pObj)
+ return FALSE;
+ auto it = m_IndirectObjs.find(objnum);
+ if (it != m_IndirectObjs.end()) {
+ if (pObj->GetGenNum() <= it->second->GetGenNum()) {
+ pObj->Destroy();
+ return FALSE;
+ }
+ it->second->Destroy();
+ }
+ pObj->m_ObjNum = objnum;
+ m_IndirectObjs[objnum] = pObj;
+ m_LastObjNum = std::max(m_LastObjNum, objnum);
+ return TRUE;
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_name.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_name.cpp
new file mode 100644
index 0000000000..03d523db19
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_name.cpp
@@ -0,0 +1,53 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_name.h"
+
+#include "core/include/fpdfapi/fpdf_parser_decode.h"
+
+CPDF_Name::CPDF_Name(const CFX_ByteString& str) : m_Name(str) {}
+
+CPDF_Name::CPDF_Name(const CFX_ByteStringC& str) : m_Name(str) {}
+
+CPDF_Name::CPDF_Name(const FX_CHAR* str) : m_Name(str) {}
+
+CPDF_Name::~CPDF_Name() {}
+
+CPDF_Object::Type CPDF_Name::GetType() const {
+ return NAME;
+}
+
+CPDF_Object* CPDF_Name::Clone(FX_BOOL bDirect) const {
+ return new CPDF_Name(m_Name);
+}
+
+CFX_ByteString CPDF_Name::GetString() const {
+ return m_Name;
+}
+
+CFX_ByteStringC CPDF_Name::GetConstString() const {
+ return CFX_ByteStringC(m_Name);
+}
+
+void CPDF_Name::SetString(const CFX_ByteString& str) {
+ m_Name = str;
+}
+
+bool CPDF_Name::IsName() const {
+ return true;
+}
+
+CPDF_Name* CPDF_Name::AsName() {
+ return this;
+}
+
+const CPDF_Name* CPDF_Name::AsName() const {
+ return this;
+}
+
+CFX_WideString CPDF_Name::GetUnicodeText() const {
+ return PDF_DecodeText(m_Name);
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_null.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_null.cpp
new file mode 100644
index 0000000000..c18449d08f
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_null.cpp
@@ -0,0 +1,17 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_null.h"
+
+CPDF_Null::CPDF_Null() {}
+
+CPDF_Object::Type CPDF_Null::GetType() const {
+ return NULLOBJ;
+}
+
+CPDF_Object* CPDF_Null::Clone(FX_BOOL bDirect) const {
+ return new CPDF_Null;
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_number.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_number.cpp
new file mode 100644
index 0000000000..ddc7aa11a2
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_number.cpp
@@ -0,0 +1,56 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_number.h"
+
+CPDF_Number::CPDF_Number() : m_bInteger(TRUE), m_Integer(0) {}
+
+CPDF_Number::CPDF_Number(int value) : m_bInteger(TRUE), m_Integer(value) {}
+
+CPDF_Number::CPDF_Number(FX_FLOAT value) : m_bInteger(FALSE), m_Float(value) {}
+
+CPDF_Number::CPDF_Number(const CFX_ByteStringC& str) {
+ FX_atonum(str, m_bInteger, &m_Integer);
+}
+
+CPDF_Number::~CPDF_Number() {}
+
+CPDF_Object::Type CPDF_Number::GetType() const {
+ return NUMBER;
+}
+
+CPDF_Object* CPDF_Number::Clone(FX_BOOL bDirect) const {
+ return m_bInteger ? new CPDF_Number(m_Integer) : new CPDF_Number(m_Float);
+}
+
+FX_FLOAT CPDF_Number::GetNumber() const {
+ return m_bInteger ? static_cast<FX_FLOAT>(m_Integer) : m_Float;
+}
+
+int CPDF_Number::GetInteger() const {
+ return m_bInteger ? m_Integer : static_cast<int>(m_Float);
+}
+
+bool CPDF_Number::IsNumber() const {
+ return true;
+}
+
+CPDF_Number* CPDF_Number::AsNumber() {
+ return this;
+}
+
+const CPDF_Number* CPDF_Number::AsNumber() const {
+ return this;
+}
+
+void CPDF_Number::SetString(const CFX_ByteString& str) {
+ FX_atonum(str, m_bInteger, &m_Integer);
+}
+
+CFX_ByteString CPDF_Number::GetString() const {
+ return m_bInteger ? CFX_ByteString::FormatInteger(m_Integer, FXFORMAT_SIGNED)
+ : CFX_ByteString::FormatFloat(m_Float);
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_object.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_object.cpp
new file mode 100644
index 0000000000..208bca8e6c
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_object.cpp
@@ -0,0 +1,158 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_object.h"
+
+#include <algorithm>
+
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
+#include "core/include/fpdfapi/cpdf_indirect_object_holder.h"
+#include "core/include/fpdfapi/cpdf_parser.h"
+#include "core/include/fpdfapi/fpdf_parser_decode.h"
+#include "core/include/fxcrt/fx_string.h"
+#include "third_party/base/stl_util.h"
+
+CPDF_Object::~CPDF_Object() {}
+
+CPDF_Object* CPDF_Object::GetDirect() const {
+ return const_cast<CPDF_Object*>(this);
+}
+
+void CPDF_Object::Release() {
+ if (m_ObjNum)
+ return;
+
+ Destroy();
+}
+
+CFX_ByteString CPDF_Object::GetString() const {
+ return CFX_ByteString();
+}
+
+CFX_ByteStringC CPDF_Object::GetConstString() const {
+ return CFX_ByteStringC();
+}
+
+CFX_WideString CPDF_Object::GetUnicodeText() const {
+ return CFX_WideString();
+}
+
+FX_FLOAT CPDF_Object::GetNumber() const {
+ return 0;
+}
+
+int CPDF_Object::GetInteger() const {
+ return 0;
+}
+
+CPDF_Dictionary* CPDF_Object::GetDict() const {
+ return nullptr;
+}
+
+CPDF_Array* CPDF_Object::GetArray() const {
+ return nullptr;
+}
+
+void CPDF_Object::SetString(const CFX_ByteString& str) {
+ ASSERT(FALSE);
+}
+
+bool CPDF_Object::IsArray() const {
+ return false;
+}
+
+bool CPDF_Object::IsBoolean() const {
+ return false;
+}
+
+bool CPDF_Object::IsDictionary() const {
+ return false;
+}
+
+bool CPDF_Object::IsName() const {
+ return false;
+}
+
+bool CPDF_Object::IsNumber() const {
+ return false;
+}
+
+bool CPDF_Object::IsReference() const {
+ return false;
+}
+
+bool CPDF_Object::IsStream() const {
+ return false;
+}
+
+bool CPDF_Object::IsString() const {
+ return false;
+}
+
+CPDF_Array* CPDF_Object::AsArray() {
+ return nullptr;
+}
+
+const CPDF_Array* CPDF_Object::AsArray() const {
+ return nullptr;
+}
+
+CPDF_Boolean* CPDF_Object::AsBoolean() {
+ return nullptr;
+}
+
+const CPDF_Boolean* CPDF_Object::AsBoolean() const {
+ return nullptr;
+}
+
+CPDF_Dictionary* CPDF_Object::AsDictionary() {
+ return nullptr;
+}
+
+const CPDF_Dictionary* CPDF_Object::AsDictionary() const {
+ return nullptr;
+}
+
+CPDF_Name* CPDF_Object::AsName() {
+ return nullptr;
+}
+
+const CPDF_Name* CPDF_Object::AsName() const {
+ return nullptr;
+}
+
+CPDF_Number* CPDF_Object::AsNumber() {
+ return nullptr;
+}
+
+const CPDF_Number* CPDF_Object::AsNumber() const {
+ return nullptr;
+}
+
+CPDF_Reference* CPDF_Object::AsReference() {
+ return nullptr;
+}
+
+const CPDF_Reference* CPDF_Object::AsReference() const {
+ return nullptr;
+}
+
+CPDF_Stream* CPDF_Object::AsStream() {
+ return nullptr;
+}
+
+const CPDF_Stream* CPDF_Object::AsStream() const {
+ return nullptr;
+}
+
+CPDF_String* CPDF_Object::AsString() {
+ return nullptr;
+}
+
+const CPDF_String* CPDF_Object::AsString() const {
+ return nullptr;
+}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects_unittest.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp
index a377a92e44..87ef34fd6a 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects_unittest.cpp
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp
@@ -2,12 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/include/fpdfapi/fpdf_objects.h"
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_boolean.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
+#include "core/include/fpdfapi/cpdf_name.h"
+#include "core/include/fpdfapi/cpdf_null.h"
+#include "core/include/fpdfapi/cpdf_number.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
+#include "core/include/fpdfapi/cpdf_string.h"
+#include "core/include/fpdfapi/cpdf_stream.h"
#include <memory>
#include <string>
#include <vector>
+#include "core/include/fpdfapi/cpdf_indirect_object_holder.h"
#include "core/include/fxcrt/fx_basic.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp
index 2835c6ff38..c9a2d8d496 100644
--- a/core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp
@@ -8,7 +8,12 @@
#include <vector>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
+#include "core/include/fpdfapi/cpdf_number.h"
+#include "core/include/fpdfapi/cpdf_stream.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
#include "core/include/fpdfapi/ipdf_crypto_handler.h"
#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxcrt/fx_safe_types.h"
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_reference.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_reference.cpp
new file mode 100644
index 0000000000..4aede7d07a
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_reference.cpp
@@ -0,0 +1,72 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_reference.h"
+
+#include "core/include/fpdfapi/cpdf_indirect_object_holder.h"
+
+CPDF_Reference::CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, int objnum)
+ : m_pObjList(pDoc), m_RefObjNum(objnum) {}
+
+CPDF_Reference::~CPDF_Reference() {}
+
+CPDF_Object::Type CPDF_Reference::GetType() const {
+ return REFERENCE;
+}
+
+CFX_ByteString CPDF_Reference::GetString() const {
+ CPDF_Object* obj = SafeGetDirect();
+ return obj ? obj->GetString() : CFX_ByteString();
+}
+
+CFX_ByteStringC CPDF_Reference::GetConstString() const {
+ CPDF_Object* obj = SafeGetDirect();
+ return obj ? obj->GetConstString() : CFX_ByteStringC();
+}
+
+FX_FLOAT CPDF_Reference::GetNumber() const {
+ CPDF_Object* obj = SafeGetDirect();
+ return obj ? obj->GetNumber() : 0;
+}
+
+int CPDF_Reference::GetInteger() const {
+ CPDF_Object* obj = SafeGetDirect();
+ return obj ? obj->GetInteger() : 0;
+}
+
+CPDF_Dictionary* CPDF_Reference::GetDict() const {
+ CPDF_Object* obj = SafeGetDirect();
+ return obj ? obj->GetDict() : nullptr;
+}
+
+bool CPDF_Reference::IsReference() const {
+ return true;
+}
+
+CPDF_Reference* CPDF_Reference::AsReference() {
+ return this;
+}
+
+const CPDF_Reference* CPDF_Reference::AsReference() const {
+ return this;
+}
+
+CPDF_Object* CPDF_Reference::Clone(FX_BOOL bDirect) const {
+ if (bDirect) {
+ auto* pDirect = GetDirect();
+ return pDirect ? pDirect->Clone(TRUE) : nullptr;
+ }
+ return new CPDF_Reference(m_pObjList, m_RefObjNum);
+}
+
+void CPDF_Reference::SetRef(CPDF_IndirectObjectHolder* pDoc, FX_DWORD objnum) {
+ m_pObjList = pDoc;
+ m_RefObjNum = objnum;
+}
+
+CPDF_Object* CPDF_Reference::GetDirect() const {
+ return m_pObjList ? m_pObjList->GetIndirectObject(m_RefObjNum) : nullptr;
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp
index a89b2fb119..feb152ba4a 100644
--- a/core/src/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp
@@ -9,8 +9,10 @@
#include <time.h>
#include "core/include/fdrm/fx_crypt.h"
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_parser.h"
-#include "core/include/fpdfapi/fpdf_objects.h"
+#include "core/include/fpdfapi/cpdf_object.h"
#include "core/src/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.h"
namespace {
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_stream.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_stream.cpp
new file mode 100644
index 0000000000..45c946ab5f
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_stream.cpp
@@ -0,0 +1,232 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_stream.h"
+
+#include "core/include/fpdfapi/cpdf_dictionary.h"
+#include "core/include/fpdfapi/fpdf_parser_decode.h"
+
+CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict)
+ : m_pDict(pDict),
+ m_dwSize(size),
+ m_GenNum(kMemoryBasedGenNum),
+ m_pDataBuf(pData) {}
+
+CPDF_Stream::~CPDF_Stream() {
+ if (IsMemoryBased())
+ FX_Free(m_pDataBuf);
+
+ if (m_pDict)
+ m_pDict->Release();
+}
+
+CPDF_Object::Type CPDF_Stream::GetType() const {
+ return STREAM;
+}
+
+CPDF_Dictionary* CPDF_Stream::GetDict() const {
+ return m_pDict;
+}
+
+bool CPDF_Stream::IsStream() const {
+ return true;
+}
+
+CPDF_Stream* CPDF_Stream::AsStream() {
+ return this;
+}
+
+const CPDF_Stream* CPDF_Stream::AsStream() const {
+ return this;
+}
+
+void CPDF_Stream::InitStreamInternal(CPDF_Dictionary* pDict) {
+ if (pDict) {
+ if (m_pDict)
+ m_pDict->Release();
+ m_pDict = pDict;
+ }
+ if (IsMemoryBased())
+ FX_Free(m_pDataBuf);
+
+ m_GenNum = 0;
+ m_pFile = nullptr;
+}
+
+void CPDF_Stream::InitStream(uint8_t* pData,
+ FX_DWORD size,
+ CPDF_Dictionary* pDict) {
+ InitStreamInternal(pDict);
+ m_GenNum = kMemoryBasedGenNum;
+ m_pDataBuf = FX_Alloc(uint8_t, size);
+ if (pData)
+ FXSYS_memcpy(m_pDataBuf, pData, size);
+
+ m_dwSize = size;
+ if (m_pDict)
+ m_pDict->SetAtInteger("Length", size);
+}
+
+CPDF_Object* CPDF_Stream::Clone(FX_BOOL bDirect) const {
+ CPDF_StreamAcc acc;
+ acc.LoadAllData(this, TRUE);
+ FX_DWORD streamSize = acc.GetSize();
+ CPDF_Dictionary* pDict = GetDict();
+ if (pDict)
+ pDict = ToDictionary(pDict->Clone(bDirect));
+
+ return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
+}
+
+void CPDF_Stream::SetData(const uint8_t* pData,
+ FX_DWORD size,
+ FX_BOOL bCompressed,
+ FX_BOOL bKeepBuf) {
+ if (IsMemoryBased())
+ FX_Free(m_pDataBuf);
+ m_GenNum = kMemoryBasedGenNum;
+
+ if (bKeepBuf) {
+ m_pDataBuf = const_cast<uint8_t*>(pData);
+ } else {
+ m_pDataBuf = FX_Alloc(uint8_t, size);
+ if (pData) {
+ FXSYS_memcpy(m_pDataBuf, pData, size);
+ }
+ }
+ m_dwSize = size;
+ if (!m_pDict)
+ m_pDict = new CPDF_Dictionary;
+ m_pDict->SetAtInteger("Length", size);
+ if (!bCompressed) {
+ m_pDict->RemoveAt("Filter");
+ m_pDict->RemoveAt("DecodeParms");
+ }
+}
+
+FX_BOOL CPDF_Stream::ReadRawData(FX_FILESIZE offset,
+ uint8_t* buf,
+ FX_DWORD size) const {
+ if (!IsMemoryBased() && m_pFile)
+ return m_pFile->ReadBlock(buf, offset, size);
+
+ if (m_pDataBuf)
+ FXSYS_memcpy(buf, m_pDataBuf + offset, size);
+
+ return TRUE;
+}
+
+void CPDF_Stream::InitStreamFromFile(IFX_FileRead* pFile,
+ CPDF_Dictionary* pDict) {
+ InitStreamInternal(pDict);
+ m_pFile = pFile;
+ m_dwSize = (FX_DWORD)pFile->GetSize();
+ if (m_pDict)
+ m_pDict->SetAtInteger("Length", m_dwSize);
+}
+
+CFX_WideString CPDF_Stream::GetUnicodeText() const {
+ CPDF_StreamAcc stream;
+ stream.LoadAllData(this, FALSE);
+ return PDF_DecodeText(stream.GetData(), stream.GetSize());
+}
+
+CPDF_StreamAcc::CPDF_StreamAcc()
+ : m_pData(nullptr),
+ m_dwSize(0),
+ m_bNewBuf(FALSE),
+ m_pImageParam(nullptr),
+ m_pStream(nullptr),
+ m_pSrcData(nullptr) {}
+
+void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream,
+ FX_BOOL bRawAccess,
+ FX_DWORD estimated_size,
+ FX_BOOL bImageAcc) {
+ if (!pStream)
+ return;
+
+ m_pStream = pStream;
+ if (pStream->IsMemoryBased() &&
+ (!pStream->GetDict()->KeyExist("Filter") || bRawAccess)) {
+ m_dwSize = pStream->GetRawSize();
+ m_pData = pStream->GetRawData();
+ return;
+ }
+ uint8_t* pSrcData;
+ FX_DWORD dwSrcSize = pStream->GetRawSize();
+ if (dwSrcSize == 0)
+ return;
+
+ if (!pStream->IsMemoryBased()) {
+ pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize);
+ if (!pStream->ReadRawData(0, pSrcData, dwSrcSize))
+ return;
+ } else {
+ pSrcData = pStream->GetRawData();
+ }
+ uint8_t* pDecryptedData = pSrcData;
+ FX_DWORD dwDecryptedSize = dwSrcSize;
+ if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) {
+ m_pData = pDecryptedData;
+ m_dwSize = dwDecryptedSize;
+ } else {
+ FX_BOOL bRet = PDF_DataDecode(
+ pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData,
+ m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc);
+ if (!bRet) {
+ m_pData = pDecryptedData;
+ m_dwSize = dwDecryptedSize;
+ }
+ }
+ if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) {
+ FX_Free(pSrcData);
+ }
+ if (pDecryptedData != pSrcData && pDecryptedData != m_pData) {
+ FX_Free(pDecryptedData);
+ }
+ m_pSrcData = nullptr;
+ m_bNewBuf = m_pData != pStream->GetRawData();
+}
+
+CPDF_StreamAcc::~CPDF_StreamAcc() {
+ if (m_bNewBuf) {
+ FX_Free(m_pData);
+ }
+ FX_Free(m_pSrcData);
+}
+
+const uint8_t* CPDF_StreamAcc::GetData() const {
+ if (m_bNewBuf) {
+ return m_pData;
+ }
+ if (!m_pStream) {
+ return nullptr;
+ }
+ return m_pStream->GetRawData();
+}
+
+FX_DWORD CPDF_StreamAcc::GetSize() const {
+ if (m_bNewBuf) {
+ return m_dwSize;
+ }
+ if (!m_pStream) {
+ return 0;
+ }
+ return m_pStream->GetRawSize();
+}
+
+uint8_t* CPDF_StreamAcc::DetachData() {
+ if (m_bNewBuf) {
+ uint8_t* p = m_pData;
+ m_pData = nullptr;
+ m_dwSize = 0;
+ return p;
+ }
+ uint8_t* p = FX_Alloc(uint8_t, m_dwSize);
+ FXSYS_memcpy(p, m_pData, m_dwSize);
+ return p;
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_string.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_string.cpp
new file mode 100644
index 0000000000..1d0bf0b829
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_string.cpp
@@ -0,0 +1,56 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_string.h"
+
+#include "core/include/fpdfapi/fpdf_parser_decode.h"
+
+CPDF_String::CPDF_String() : m_bHex(FALSE) {}
+
+CPDF_String::CPDF_String(const CFX_ByteString& str, FX_BOOL bHex)
+ : m_String(str), m_bHex(bHex) {}
+
+CPDF_String::CPDF_String(const CFX_WideString& str) : m_bHex(FALSE) {
+ m_String = PDF_EncodeText(str);
+}
+
+CPDF_String::~CPDF_String() {}
+
+CPDF_Object::Type CPDF_String::GetType() const {
+ return STRING;
+}
+
+CPDF_Object* CPDF_String::Clone(FX_BOOL bDirect) const {
+ return new CPDF_String(m_String, m_bHex);
+}
+
+CFX_ByteString CPDF_String::GetString() const {
+ return m_String;
+}
+
+CFX_ByteStringC CPDF_String::GetConstString() const {
+ return CFX_ByteStringC(m_String);
+}
+
+void CPDF_String::SetString(const CFX_ByteString& str) {
+ m_String = str;
+}
+
+bool CPDF_String::IsString() const {
+ return true;
+}
+
+CPDF_String* CPDF_String::AsString() {
+ return this;
+}
+
+const CPDF_String* CPDF_String::AsString() const {
+ return this;
+}
+
+CFX_WideString CPDF_String::GetUnicodeText() const {
+ return PDF_DecodeText(m_String);
+}
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp
index e5b782ca1c..b414827f95 100644
--- a/core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp
@@ -8,8 +8,16 @@
#include <vector>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_boolean.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
+#include "core/include/fpdfapi/cpdf_name.h"
+#include "core/include/fpdfapi/cpdf_null.h"
+#include "core/include/fpdfapi/cpdf_number.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
+#include "core/include/fpdfapi/cpdf_stream.h"
+#include "core/include/fpdfapi/cpdf_string.h"
#include "core/include/fpdfapi/fpdf_module.h"
-#include "core/include/fpdfapi/fpdf_objects.h"
#include "core/include/fpdfapi/fpdf_parser_decode.h"
#include "core/include/fpdfapi/ipdf_crypto_handler.h"
#include "core/include/fxcrt/fx_ext.h"
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 7a38209979..e6de7cb7ff 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -9,8 +9,9 @@
#include <limits.h>
#include <vector>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/fpdf_module.h"
-#include "core/include/fpdfapi/fpdf_objects.h"
#include "core/include/fxcodec/fx_codec.h"
#include "core/include/fxcrt/fx_ext.h"
#include "core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.h"
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
deleted file mode 100644
index 05d85e6398..0000000000
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ /dev/null
@@ -1,1148 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/include/fpdfapi/fpdf_objects.h"
-
-#include <algorithm>
-
-#include "core/include/fpdfapi/cpdf_parser.h"
-#include "core/include/fpdfapi/fpdf_parser_decode.h"
-#include "core/include/fxcrt/fx_string.h"
-#include "third_party/base/stl_util.h"
-
-CPDF_Object::~CPDF_Object() {}
-
-CPDF_Object* CPDF_Object::GetDirect() const {
- return const_cast<CPDF_Object*>(this);
-}
-
-void CPDF_Object::Release() {
- if (m_ObjNum) {
- return;
- }
- Destroy();
-}
-
-CFX_ByteString CPDF_Object::GetString() const {
- return CFX_ByteString();
-}
-
-CFX_ByteStringC CPDF_Object::GetConstString() const {
- return CFX_ByteStringC();
-}
-
-CFX_WideString CPDF_Object::GetUnicodeText() const {
- return CFX_WideString();
-}
-
-FX_FLOAT CPDF_Object::GetNumber() const {
- return 0;
-}
-
-int CPDF_Object::GetInteger() const {
- return 0;
-}
-
-CPDF_Dictionary* CPDF_Object::GetDict() const {
- return nullptr;
-}
-
-CPDF_Array* CPDF_Object::GetArray() const {
- return nullptr;
-}
-
-void CPDF_Object::SetString(const CFX_ByteString& str) {
- ASSERT(FALSE);
-}
-
-bool CPDF_Object::IsArray() const {
- return false;
-}
-
-bool CPDF_Object::IsBoolean() const {
- return false;
-}
-
-bool CPDF_Object::IsDictionary() const {
- return false;
-}
-
-bool CPDF_Object::IsName() const {
- return false;
-}
-
-bool CPDF_Object::IsNumber() const {
- return false;
-}
-
-bool CPDF_Object::IsReference() const {
- return false;
-}
-
-bool CPDF_Object::IsStream() const {
- return false;
-}
-
-bool CPDF_Object::IsString() const {
- return false;
-}
-
-CPDF_Array* CPDF_Object::AsArray() {
- return nullptr;
-}
-
-const CPDF_Array* CPDF_Object::AsArray() const {
- return nullptr;
-}
-
-CPDF_Boolean* CPDF_Object::AsBoolean() {
- return nullptr;
-}
-
-const CPDF_Boolean* CPDF_Object::AsBoolean() const {
- return nullptr;
-}
-
-CPDF_Dictionary* CPDF_Object::AsDictionary() {
- return nullptr;
-}
-
-const CPDF_Dictionary* CPDF_Object::AsDictionary() const {
- return nullptr;
-}
-
-CPDF_Name* CPDF_Object::AsName() {
- return nullptr;
-}
-
-const CPDF_Name* CPDF_Object::AsName() const {
- return nullptr;
-}
-
-CPDF_Number* CPDF_Object::AsNumber() {
- return nullptr;
-}
-
-const CPDF_Number* CPDF_Object::AsNumber() const {
- return nullptr;
-}
-
-CPDF_Reference* CPDF_Object::AsReference() {
- return nullptr;
-}
-
-const CPDF_Reference* CPDF_Object::AsReference() const {
- return nullptr;
-}
-
-CPDF_Stream* CPDF_Object::AsStream() {
- return nullptr;
-}
-
-const CPDF_Stream* CPDF_Object::AsStream() const {
- return nullptr;
-}
-
-CPDF_String* CPDF_Object::AsString() {
- return nullptr;
-}
-
-const CPDF_String* CPDF_Object::AsString() const {
- return nullptr;
-}
-
-CPDF_Boolean::~CPDF_Boolean() {}
-
-CPDF_Object::Type CPDF_Boolean::GetType() const {
- return BOOLEAN;
-}
-
-CPDF_Object* CPDF_Boolean::Clone(FX_BOOL bDirect) const {
- return new CPDF_Boolean(m_bValue);
-}
-
-CFX_ByteString CPDF_Boolean::GetString() const {
- return m_bValue ? "true" : "false";
-}
-
-int CPDF_Boolean::GetInteger() const {
- return m_bValue;
-}
-
-void CPDF_Boolean::SetString(const CFX_ByteString& str) {
- m_bValue = (str == "true");
-}
-
-bool CPDF_Boolean::IsBoolean() const {
- return true;
-}
-
-CPDF_Boolean* CPDF_Boolean::AsBoolean() {
- return this;
-}
-
-const CPDF_Boolean* CPDF_Boolean::AsBoolean() const {
- return this;
-}
-
-CPDF_Number::CPDF_Number(const CFX_ByteStringC& str) {
- FX_atonum(str, m_bInteger, &m_Integer);
-}
-
-CPDF_Number::~CPDF_Number() {}
-
-CPDF_Object::Type CPDF_Number::GetType() const {
- return NUMBER;
-}
-
-CPDF_Object* CPDF_Number::Clone(FX_BOOL bDirect) const {
- return m_bInteger ? new CPDF_Number(m_Integer) : new CPDF_Number(m_Float);
-}
-
-FX_FLOAT CPDF_Number::GetNumber() const {
- return m_bInteger ? static_cast<FX_FLOAT>(m_Integer) : m_Float;
-}
-
-int CPDF_Number::GetInteger() const {
- return m_bInteger ? m_Integer : static_cast<int>(m_Float);
-}
-
-bool CPDF_Number::IsNumber() const {
- return true;
-}
-
-CPDF_Number* CPDF_Number::AsNumber() {
- return this;
-}
-
-const CPDF_Number* CPDF_Number::AsNumber() const {
- return this;
-}
-
-void CPDF_Number::SetString(const CFX_ByteString& str) {
- FX_atonum(str, m_bInteger, &m_Integer);
-}
-
-CFX_ByteString CPDF_Number::GetString() const {
- return m_bInteger ? CFX_ByteString::FormatInteger(m_Integer, FXFORMAT_SIGNED)
- : CFX_ByteString::FormatFloat(m_Float);
-}
-
-CPDF_String::CPDF_String(const CFX_WideString& str) : m_bHex(FALSE) {
- m_String = PDF_EncodeText(str);
-}
-
-CPDF_String::~CPDF_String() {}
-
-CPDF_Object::Type CPDF_String::GetType() const {
- return STRING;
-}
-
-CPDF_Object* CPDF_String::Clone(FX_BOOL bDirect) const {
- return new CPDF_String(m_String, m_bHex);
-}
-
-CFX_ByteString CPDF_String::GetString() const {
- return m_String;
-}
-
-CFX_ByteStringC CPDF_String::GetConstString() const {
- return CFX_ByteStringC(m_String);
-}
-
-void CPDF_String::SetString(const CFX_ByteString& str) {
- m_String = str;
-}
-
-bool CPDF_String::IsString() const {
- return true;
-}
-
-CPDF_String* CPDF_String::AsString() {
- return this;
-}
-
-const CPDF_String* CPDF_String::AsString() const {
- return this;
-}
-
-CFX_WideString CPDF_String::GetUnicodeText() const {
- return PDF_DecodeText(m_String);
-}
-
-CPDF_Name::~CPDF_Name() {}
-
-CPDF_Object::Type CPDF_Name::GetType() const {
- return NAME;
-}
-
-CPDF_Object* CPDF_Name::Clone(FX_BOOL bDirect) const {
- return new CPDF_Name(m_Name);
-}
-
-CFX_ByteString CPDF_Name::GetString() const {
- return m_Name;
-}
-
-CFX_ByteStringC CPDF_Name::GetConstString() const {
- return CFX_ByteStringC(m_Name);
-}
-
-void CPDF_Name::SetString(const CFX_ByteString& str) {
- m_Name = str;
-}
-
-bool CPDF_Name::IsName() const {
- return true;
-}
-
-CPDF_Name* CPDF_Name::AsName() {
- return this;
-}
-
-const CPDF_Name* CPDF_Name::AsName() const {
- return this;
-}
-
-CFX_WideString CPDF_Name::GetUnicodeText() const {
- return PDF_DecodeText(m_Name);
-}
-
-CPDF_Array::CPDF_Array() {}
-
-CPDF_Array::~CPDF_Array() {
- int size = m_Objects.GetSize();
- CPDF_Object** pList = m_Objects.GetData();
- for (int i = 0; i < size; i++) {
- if (pList[i])
- pList[i]->Release();
- }
-}
-
-CPDF_Object::Type CPDF_Array::GetType() const {
- return ARRAY;
-}
-
-CPDF_Array* CPDF_Array::GetArray() const {
- // The method should be made non-const if we want to not be const.
- // See bug #234.
- return const_cast<CPDF_Array*>(this);
-}
-
-bool CPDF_Array::IsArray() const {
- return true;
-}
-
-CPDF_Array* CPDF_Array::AsArray() {
- return this;
-}
-
-const CPDF_Array* CPDF_Array::AsArray() const {
- return this;
-}
-
-CPDF_Object* CPDF_Array::Clone(FX_BOOL bDirect) const {
- CPDF_Array* pCopy = new CPDF_Array();
- for (int i = 0; i < GetCount(); i++) {
- CPDF_Object* value = m_Objects.GetAt(i);
- pCopy->m_Objects.Add(value->Clone(bDirect));
- }
- return pCopy;
-}
-
-CFX_FloatRect CPDF_Array::GetRect() {
- CFX_FloatRect rect;
- if (!IsArray() || m_Objects.GetSize() != 4)
- return rect;
-
- rect.left = GetNumberAt(0);
- rect.bottom = GetNumberAt(1);
- rect.right = GetNumberAt(2);
- rect.top = GetNumberAt(3);
- return rect;
-}
-
-CFX_Matrix CPDF_Array::GetMatrix() {
- CFX_Matrix matrix;
- if (!IsArray() || m_Objects.GetSize() != 6)
- return matrix;
-
- matrix.Set(GetNumberAt(0), GetNumberAt(1), GetNumberAt(2), GetNumberAt(3),
- GetNumberAt(4), GetNumberAt(5));
- return matrix;
-}
-
-CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const {
- if (i >= (FX_DWORD)m_Objects.GetSize())
- return nullptr;
- return m_Objects.GetAt(i);
-}
-
-CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const {
- if (i >= (FX_DWORD)m_Objects.GetSize())
- return nullptr;
- return m_Objects.GetAt(i)->GetDirect();
-}
-
-CFX_ByteString CPDF_Array::GetStringAt(FX_DWORD i) const {
- if (i >= (FX_DWORD)m_Objects.GetSize())
- return CFX_ByteString();
- return m_Objects.GetAt(i)->GetString();
-}
-
-CFX_ByteStringC CPDF_Array::GetConstStringAt(FX_DWORD i) const {
- if (i >= (FX_DWORD)m_Objects.GetSize())
- return CFX_ByteStringC();
- return m_Objects.GetAt(i)->GetConstString();
-}
-
-int CPDF_Array::GetIntegerAt(FX_DWORD i) const {
- if (i >= (FX_DWORD)m_Objects.GetSize())
- return 0;
- return m_Objects.GetAt(i)->GetInteger();
-}
-
-FX_FLOAT CPDF_Array::GetNumberAt(FX_DWORD i) const {
- if (i >= (FX_DWORD)m_Objects.GetSize())
- return 0;
- return m_Objects.GetAt(i)->GetNumber();
-}
-
-CPDF_Dictionary* CPDF_Array::GetDictAt(FX_DWORD i) const {
- CPDF_Object* p = GetElementValue(i);
- if (!p)
- return NULL;
- if (CPDF_Dictionary* pDict = p->AsDictionary())
- return pDict;
- if (CPDF_Stream* pStream = p->AsStream())
- return pStream->GetDict();
- return NULL;
-}
-
-CPDF_Stream* CPDF_Array::GetStreamAt(FX_DWORD i) const {
- return ToStream(GetElementValue(i));
-}
-
-CPDF_Array* CPDF_Array::GetArrayAt(FX_DWORD i) const {
- return ToArray(GetElementValue(i));
-}
-
-void CPDF_Array::RemoveAt(FX_DWORD i, int nCount) {
- if (i >= (FX_DWORD)m_Objects.GetSize())
- return;
-
- if (nCount <= 0 || nCount > m_Objects.GetSize() - i)
- return;
-
- for (int j = 0; j < nCount; ++j) {
- if (CPDF_Object* p = m_Objects.GetAt(i + j))
- p->Release();
- }
- m_Objects.RemoveAt(i, nCount);
-}
-
-void CPDF_Array::SetAt(FX_DWORD i,
- CPDF_Object* pObj,
- CPDF_IndirectObjectHolder* pObjs) {
- ASSERT(IsArray());
- ASSERT(i < (FX_DWORD)m_Objects.GetSize());
- if (i >= (FX_DWORD)m_Objects.GetSize())
- return;
- if (CPDF_Object* pOld = m_Objects.GetAt(i))
- pOld->Release();
- if (pObj->GetObjNum()) {
- ASSERT(pObjs);
- pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
- }
- m_Objects.SetAt(i, pObj);
-}
-
-void CPDF_Array::InsertAt(FX_DWORD index,
- CPDF_Object* pObj,
- CPDF_IndirectObjectHolder* pObjs) {
- if (pObj->GetObjNum()) {
- ASSERT(pObjs);
- pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
- }
- m_Objects.InsertAt(index, pObj);
-}
-
-void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs) {
- if (pObj->GetObjNum()) {
- ASSERT(pObjs);
- pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
- }
- m_Objects.Add(pObj);
-}
-
-void CPDF_Array::AddName(const CFX_ByteString& str) {
- ASSERT(IsArray());
- Add(new CPDF_Name(str));
-}
-
-void CPDF_Array::AddString(const CFX_ByteString& str) {
- ASSERT(IsArray());
- Add(new CPDF_String(str, FALSE));
-}
-
-void CPDF_Array::AddInteger(int i) {
- ASSERT(IsArray());
- Add(new CPDF_Number(i));
-}
-
-void CPDF_Array::AddNumber(FX_FLOAT f) {
- ASSERT(IsArray());
- CPDF_Number* pNumber = new CPDF_Number(f);
- Add(pNumber);
-}
-
-void CPDF_Array::AddReference(CPDF_IndirectObjectHolder* pDoc,
- FX_DWORD objnum) {
- ASSERT(IsArray());
- Add(new CPDF_Reference(pDoc, objnum));
-}
-
-CPDF_Dictionary::CPDF_Dictionary() {}
-
-CPDF_Dictionary::~CPDF_Dictionary() {
- for (const auto& it : m_Map) {
- it.second->Release();
- }
-}
-
-CPDF_Object::Type CPDF_Dictionary::GetType() const {
- return DICTIONARY;
-}
-
-CPDF_Dictionary* CPDF_Dictionary::GetDict() const {
- // The method should be made non-const if we want to not be const.
- // See bug #234.
- return const_cast<CPDF_Dictionary*>(this);
-}
-
-bool CPDF_Dictionary::IsDictionary() const {
- return true;
-}
-
-CPDF_Dictionary* CPDF_Dictionary::AsDictionary() {
- return this;
-}
-
-const CPDF_Dictionary* CPDF_Dictionary::AsDictionary() const {
- return this;
-}
-
-CPDF_Object* CPDF_Dictionary::Clone(FX_BOOL bDirect) const {
- CPDF_Dictionary* pCopy = new CPDF_Dictionary();
- for (const auto& it : *this)
- pCopy->m_Map.insert(std::make_pair(it.first, it.second->Clone(bDirect)));
- return pCopy;
-}
-
-CPDF_Object* CPDF_Dictionary::GetElement(const CFX_ByteStringC& key) const {
- auto it = m_Map.find(key);
- if (it == m_Map.end())
- return nullptr;
- return it->second;
-}
-CPDF_Object* CPDF_Dictionary::GetElementValue(
- const CFX_ByteStringC& key) const {
- CPDF_Object* p = GetElement(key);
- return p ? p->GetDirect() : nullptr;
-}
-
-CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key) const {
- CPDF_Object* p = GetElement(key);
- if (p) {
- return p->GetString();
- }
- return CFX_ByteString();
-}
-
-CFX_ByteStringC CPDF_Dictionary::GetConstStringBy(
- const CFX_ByteStringC& key) const {
- CPDF_Object* p = GetElement(key);
- if (p) {
- return p->GetConstString();
- }
- return CFX_ByteStringC();
-}
-
-CFX_WideString CPDF_Dictionary::GetUnicodeTextBy(
- const CFX_ByteStringC& key) const {
- CPDF_Object* p = GetElement(key);
- if (CPDF_Reference* pRef = ToReference(p))
- p = pRef->GetDirect();
- return p ? p->GetUnicodeText() : CFX_WideString();
-}
-
-CFX_ByteString CPDF_Dictionary::GetStringBy(const CFX_ByteStringC& key,
- const CFX_ByteStringC& def) const {
- CPDF_Object* p = GetElement(key);
- if (p) {
- return p->GetString();
- }
- return CFX_ByteString(def);
-}
-
-CFX_ByteStringC CPDF_Dictionary::GetConstStringBy(
- const CFX_ByteStringC& key,
- const CFX_ByteStringC& def) const {
- CPDF_Object* p = GetElement(key);
- if (p) {
- return p->GetConstString();
- }
- return CFX_ByteStringC(def);
-}
-
-int CPDF_Dictionary::GetIntegerBy(const CFX_ByteStringC& key) const {
- CPDF_Object* p = GetElement(key);
- if (p) {
- return p->GetInteger();
- }
- return 0;
-}
-
-int CPDF_Dictionary::GetIntegerBy(const CFX_ByteStringC& key, int def) const {
- CPDF_Object* p = GetElement(key);
- if (p) {
- return p->GetInteger();
- }
- return def;
-}
-
-FX_FLOAT CPDF_Dictionary::GetNumberBy(const CFX_ByteStringC& key) const {
- CPDF_Object* p = GetElement(key);
- if (p) {
- return p->GetNumber();
- }
- return 0;
-}
-
-FX_BOOL CPDF_Dictionary::GetBooleanBy(const CFX_ByteStringC& key,
- FX_BOOL bDefault) const {
- CPDF_Object* p = GetElement(key);
- if (ToBoolean(p))
- return p->GetInteger();
- return bDefault;
-}
-
-CPDF_Dictionary* CPDF_Dictionary::GetDictBy(const CFX_ByteStringC& key) const {
- CPDF_Object* p = GetElementValue(key);
- if (!p)
- return nullptr;
- if (CPDF_Dictionary* pDict = p->AsDictionary())
- return pDict;
- if (CPDF_Stream* pStream = p->AsStream())
- return pStream->GetDict();
- return nullptr;
-}
-
-CPDF_Array* CPDF_Dictionary::GetArrayBy(const CFX_ByteStringC& key) const {
- return ToArray(GetElementValue(key));
-}
-
-CPDF_Stream* CPDF_Dictionary::GetStreamBy(const CFX_ByteStringC& key) const {
- return ToStream(GetElementValue(key));
-}
-
-CFX_FloatRect CPDF_Dictionary::GetRectBy(const CFX_ByteStringC& key) const {
- CFX_FloatRect rect;
- CPDF_Array* pArray = GetArrayBy(key);
- if (pArray)
- rect = pArray->GetRect();
- return rect;
-}
-
-CFX_Matrix CPDF_Dictionary::GetMatrixBy(const CFX_ByteStringC& key) const {
- CFX_Matrix matrix;
- CPDF_Array* pArray = GetArrayBy(key);
- if (pArray)
- matrix = pArray->GetMatrix();
- return matrix;
-}
-
-FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const {
- return pdfium::ContainsKey(m_Map, key);
-}
-
-bool CPDF_Dictionary::IsSignatureDict() const {
- CPDF_Object* pType = GetElementValue("Type");
- if (!pType)
- pType = GetElementValue("FT");
- return pType && pType->GetString() == "Sig";
-}
-
-void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj) {
- ASSERT(IsDictionary());
- // Avoid 2 constructions of CFX_ByteString.
- CFX_ByteString key_bytestring = key;
- auto it = m_Map.find(key_bytestring);
- if (it == m_Map.end()) {
- if (pObj) {
- m_Map.insert(std::make_pair(key_bytestring, pObj));
- }
- return;
- }
-
- if (it->second == pObj)
- return;
- it->second->Release();
-
- if (pObj)
- it->second = pObj;
- else
- m_Map.erase(it);
-}
-
-void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) {
- auto it = m_Map.find(key);
- if (it == m_Map.end())
- return;
-
- it->second->Release();
- m_Map.erase(it);
-}
-
-void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey,
- const CFX_ByteStringC& newkey) {
- auto old_it = m_Map.find(oldkey);
- if (old_it == m_Map.end())
- return;
-
- // Avoid 2 constructions of CFX_ByteString.
- CFX_ByteString newkey_bytestring = newkey;
- auto new_it = m_Map.find(newkey_bytestring);
- if (new_it == old_it)
- return;
-
- if (new_it != m_Map.end()) {
- new_it->second->Release();
- new_it->second = old_it->second;
- } else {
- m_Map.insert(std::make_pair(newkey_bytestring, old_it->second));
- }
- m_Map.erase(old_it);
-}
-
-void CPDF_Dictionary::SetAtInteger(const CFX_ByteStringC& key, int i) {
- SetAt(key, new CPDF_Number(i));
-}
-
-void CPDF_Dictionary::SetAtName(const CFX_ByteStringC& key,
- const CFX_ByteString& name) {
- SetAt(key, new CPDF_Name(name));
-}
-
-void CPDF_Dictionary::SetAtString(const CFX_ByteStringC& key,
- const CFX_ByteString& str) {
- SetAt(key, new CPDF_String(str, FALSE));
-}
-
-void CPDF_Dictionary::SetAtReference(const CFX_ByteStringC& key,
- CPDF_IndirectObjectHolder* pDoc,
- FX_DWORD objnum) {
- SetAt(key, new CPDF_Reference(pDoc, objnum));
-}
-
-void CPDF_Dictionary::AddReference(const CFX_ByteStringC& key,
- CPDF_IndirectObjectHolder* pDoc,
- FX_DWORD objnum) {
- SetAt(key, new CPDF_Reference(pDoc, objnum));
-}
-
-void CPDF_Dictionary::SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f) {
- CPDF_Number* pNumber = new CPDF_Number(f);
- SetAt(key, pNumber);
-}
-
-void CPDF_Dictionary::SetAtBoolean(const CFX_ByteStringC& key, FX_BOOL bValue) {
- SetAt(key, new CPDF_Boolean(bValue));
-}
-
-void CPDF_Dictionary::SetAtRect(const CFX_ByteStringC& key,
- const CFX_FloatRect& rect) {
- CPDF_Array* pArray = new CPDF_Array;
- pArray->AddNumber(rect.left);
- pArray->AddNumber(rect.bottom);
- pArray->AddNumber(rect.right);
- pArray->AddNumber(rect.top);
- SetAt(key, pArray);
-}
-
-void CPDF_Dictionary::SetAtMatrix(const CFX_ByteStringC& key,
- const CFX_Matrix& matrix) {
- CPDF_Array* pArray = new CPDF_Array;
- pArray->AddNumber(matrix.a);
- pArray->AddNumber(matrix.b);
- pArray->AddNumber(matrix.c);
- pArray->AddNumber(matrix.d);
- pArray->AddNumber(matrix.e);
- pArray->AddNumber(matrix.f);
- SetAt(key, pArray);
-}
-
-CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict)
- : m_pDict(pDict),
- m_dwSize(size),
- m_GenNum(kMemoryBasedGenNum),
- m_pDataBuf(pData) {}
-
-CPDF_Stream::~CPDF_Stream() {
- if (IsMemoryBased())
- FX_Free(m_pDataBuf);
-
- if (m_pDict)
- m_pDict->Release();
-}
-
-CPDF_Object::Type CPDF_Stream::GetType() const {
- return STREAM;
-}
-
-CPDF_Dictionary* CPDF_Stream::GetDict() const {
- return m_pDict;
-}
-
-bool CPDF_Stream::IsStream() const {
- return true;
-}
-
-CPDF_Stream* CPDF_Stream::AsStream() {
- return this;
-}
-
-const CPDF_Stream* CPDF_Stream::AsStream() const {
- return this;
-}
-
-void CPDF_Stream::InitStreamInternal(CPDF_Dictionary* pDict) {
- if (pDict) {
- if (m_pDict)
- m_pDict->Release();
- m_pDict = pDict;
- }
- if (IsMemoryBased())
- FX_Free(m_pDataBuf);
-
- m_GenNum = 0;
- m_pFile = nullptr;
-}
-
-void CPDF_Stream::InitStream(uint8_t* pData,
- FX_DWORD size,
- CPDF_Dictionary* pDict) {
- InitStreamInternal(pDict);
- m_GenNum = kMemoryBasedGenNum;
- m_pDataBuf = FX_Alloc(uint8_t, size);
- if (pData) {
- FXSYS_memcpy(m_pDataBuf, pData, size);
- }
- m_dwSize = size;
- if (m_pDict) {
- m_pDict->SetAtInteger("Length", size);
- }
-}
-
-CPDF_Object* CPDF_Stream::Clone(FX_BOOL bDirect) const {
- CPDF_StreamAcc acc;
- acc.LoadAllData(this, TRUE);
- FX_DWORD streamSize = acc.GetSize();
- CPDF_Dictionary* pDict = GetDict();
- if (pDict) {
- pDict = ToDictionary(pDict->Clone(bDirect));
- }
- return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
-}
-
-void CPDF_Stream::SetData(const uint8_t* pData,
- FX_DWORD size,
- FX_BOOL bCompressed,
- FX_BOOL bKeepBuf) {
- if (IsMemoryBased())
- FX_Free(m_pDataBuf);
- m_GenNum = kMemoryBasedGenNum;
-
- if (bKeepBuf) {
- m_pDataBuf = const_cast<uint8_t*>(pData);
- } else {
- m_pDataBuf = FX_Alloc(uint8_t, size);
- if (pData) {
- FXSYS_memcpy(m_pDataBuf, pData, size);
- }
- }
- m_dwSize = size;
- if (!m_pDict)
- m_pDict = new CPDF_Dictionary;
- m_pDict->SetAtInteger("Length", size);
- if (!bCompressed) {
- m_pDict->RemoveAt("Filter");
- m_pDict->RemoveAt("DecodeParms");
- }
-}
-
-FX_BOOL CPDF_Stream::ReadRawData(FX_FILESIZE offset,
- uint8_t* buf,
- FX_DWORD size) const {
- if (!IsMemoryBased() && m_pFile)
- return m_pFile->ReadBlock(buf, offset, size);
-
- if (m_pDataBuf)
- FXSYS_memcpy(buf, m_pDataBuf + offset, size);
- return TRUE;
-}
-void CPDF_Stream::InitStreamFromFile(IFX_FileRead* pFile,
- CPDF_Dictionary* pDict) {
- InitStreamInternal(pDict);
- m_pFile = pFile;
- m_dwSize = (FX_DWORD)pFile->GetSize();
- if (m_pDict) {
- m_pDict->SetAtInteger("Length", m_dwSize);
- }
-}
-
-CFX_WideString CPDF_Stream::GetUnicodeText() const {
- CPDF_StreamAcc stream;
- stream.LoadAllData(this, FALSE);
- return PDF_DecodeText(stream.GetData(), stream.GetSize());
-}
-
-CPDF_StreamAcc::CPDF_StreamAcc() {
- m_bNewBuf = FALSE;
- m_pData = NULL;
- m_dwSize = 0;
- m_pImageParam = NULL;
- m_pStream = NULL;
- m_pSrcData = NULL;
-}
-void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream,
- FX_BOOL bRawAccess,
- FX_DWORD estimated_size,
- FX_BOOL bImageAcc) {
- if (!pStream)
- return;
-
- m_pStream = pStream;
- if (pStream->IsMemoryBased() &&
- (!pStream->GetDict()->KeyExist("Filter") || bRawAccess)) {
- m_dwSize = pStream->GetRawSize();
- m_pData = pStream->GetRawData();
- return;
- }
- uint8_t* pSrcData;
- FX_DWORD dwSrcSize = pStream->GetRawSize();
- if (dwSrcSize == 0)
- return;
-
- if (!pStream->IsMemoryBased()) {
- pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize);
- if (!pStream->ReadRawData(0, pSrcData, dwSrcSize))
- return;
- } else {
- pSrcData = pStream->GetRawData();
- }
- uint8_t* pDecryptedData = pSrcData;
- FX_DWORD dwDecryptedSize = dwSrcSize;
- if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) {
- m_pData = pDecryptedData;
- m_dwSize = dwDecryptedSize;
- } else {
- FX_BOOL bRet = PDF_DataDecode(
- pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData,
- m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc);
- if (!bRet) {
- m_pData = pDecryptedData;
- m_dwSize = dwDecryptedSize;
- }
- }
- if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) {
- FX_Free(pSrcData);
- }
- if (pDecryptedData != pSrcData && pDecryptedData != m_pData) {
- FX_Free(pDecryptedData);
- }
- m_pSrcData = NULL;
- m_bNewBuf = m_pData != pStream->GetRawData();
-}
-
-CPDF_StreamAcc::~CPDF_StreamAcc() {
- if (m_bNewBuf) {
- FX_Free(m_pData);
- }
- FX_Free(m_pSrcData);
-}
-
-const uint8_t* CPDF_StreamAcc::GetData() const {
- if (m_bNewBuf) {
- return m_pData;
- }
- if (!m_pStream) {
- return NULL;
- }
- return m_pStream->GetRawData();
-}
-
-FX_DWORD CPDF_StreamAcc::GetSize() const {
- if (m_bNewBuf) {
- return m_dwSize;
- }
- if (!m_pStream) {
- return 0;
- }
- return m_pStream->GetRawSize();
-}
-
-uint8_t* CPDF_StreamAcc::DetachData() {
- if (m_bNewBuf) {
- uint8_t* p = m_pData;
- m_pData = NULL;
- m_dwSize = 0;
- return p;
- }
- uint8_t* p = FX_Alloc(uint8_t, m_dwSize);
- FXSYS_memcpy(p, m_pData, m_dwSize);
- return p;
-}
-
-CPDF_Object::Type CPDF_Null::GetType() const {
- return NULLOBJ;
-}
-
-CPDF_Object* CPDF_Null::Clone(FX_BOOL bDirect) const {
- return new CPDF_Null;
-}
-
-CPDF_Reference::~CPDF_Reference() {}
-
-CPDF_Object::Type CPDF_Reference::GetType() const {
- return REFERENCE;
-}
-
-CFX_ByteString CPDF_Reference::GetString() const {
- CPDF_Object* obj = SafeGetDirect();
- return obj ? obj->GetString() : CFX_ByteString();
-}
-
-CFX_ByteStringC CPDF_Reference::GetConstString() const {
- CPDF_Object* obj = SafeGetDirect();
- return obj ? obj->GetConstString() : CFX_ByteStringC();
-}
-
-FX_FLOAT CPDF_Reference::GetNumber() const {
- CPDF_Object* obj = SafeGetDirect();
- return obj ? obj->GetNumber() : 0;
-}
-
-int CPDF_Reference::GetInteger() const {
- CPDF_Object* obj = SafeGetDirect();
- return obj ? obj->GetInteger() : 0;
-}
-
-CPDF_Dictionary* CPDF_Reference::GetDict() const {
- CPDF_Object* obj = SafeGetDirect();
- return obj ? obj->GetDict() : nullptr;
-}
-
-bool CPDF_Reference::IsReference() const {
- return true;
-}
-
-CPDF_Reference* CPDF_Reference::AsReference() {
- return this;
-}
-
-const CPDF_Reference* CPDF_Reference::AsReference() const {
- return this;
-}
-
-CPDF_Object* CPDF_Reference::Clone(FX_BOOL bDirect) const {
- if (bDirect) {
- auto* pDirect = GetDirect();
- return pDirect ? pDirect->Clone(TRUE) : nullptr;
- }
- return new CPDF_Reference(m_pObjList, m_RefObjNum);
-}
-
-void CPDF_Reference::SetRef(CPDF_IndirectObjectHolder* pDoc, FX_DWORD objnum) {
- m_pObjList = pDoc;
- m_RefObjNum = objnum;
-}
-
-CPDF_Object* CPDF_Reference::GetDirect() const {
- return m_pObjList ? m_pObjList->GetIndirectObject(m_RefObjNum) : nullptr;
-}
-
-CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser)
- : m_pParser(pParser), m_LastObjNum(0) {
- if (pParser)
- m_LastObjNum = m_pParser->GetLastObjNum();
-}
-
-CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {
- for (const auto& pair : m_IndirectObjs) {
- pair.second->Destroy();
- }
-}
-
-CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(FX_DWORD objnum) {
- if (objnum == 0)
- return nullptr;
-
- auto it = m_IndirectObjs.find(objnum);
- if (it != m_IndirectObjs.end())
- return it->second->GetObjNum() != -1 ? it->second : nullptr;
-
- if (!m_pParser)
- return nullptr;
-
- CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum);
- if (!pObj)
- return nullptr;
-
- pObj->m_ObjNum = objnum;
- m_LastObjNum = std::max(m_LastObjNum, objnum);
- if (m_IndirectObjs[objnum])
- m_IndirectObjs[objnum]->Destroy();
-
- m_IndirectObjs[objnum] = pObj;
- return pObj;
-}
-
-FX_DWORD CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) {
- if (pObj->m_ObjNum) {
- return pObj->m_ObjNum;
- }
- m_LastObjNum++;
- m_IndirectObjs[m_LastObjNum] = pObj;
- pObj->m_ObjNum = m_LastObjNum;
- return m_LastObjNum;
-}
-
-void CPDF_IndirectObjectHolder::ReleaseIndirectObject(FX_DWORD objnum) {
- auto it = m_IndirectObjs.find(objnum);
- if (it == m_IndirectObjs.end() || it->second->GetObjNum() == -1)
- return;
- it->second->Destroy();
- m_IndirectObjs.erase(it);
-}
-
-FX_BOOL CPDF_IndirectObjectHolder::InsertIndirectObject(FX_DWORD objnum,
- CPDF_Object* pObj) {
- if (!objnum || !pObj)
- return FALSE;
- auto it = m_IndirectObjs.find(objnum);
- if (it != m_IndirectObjs.end()) {
- if (pObj->GetGenNum() <= it->second->GetGenNum()) {
- pObj->Destroy();
- return FALSE;
- }
- it->second->Destroy();
- }
- pObj->m_ObjNum = objnum;
- m_IndirectObjs[objnum] = pObj;
- m_LastObjNum = std::max(m_LastObjNum, objnum);
- return TRUE;
-}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index 0c948c5062..c5d21f4bdd 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -6,7 +6,12 @@
#include "core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.h"
-#include "core/include/fpdfapi/fpdf_objects.h"
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
+#include "core/include/fpdfapi/cpdf_number.h"
+#include "core/include/fpdfapi/cpdf_reference.h"
+#include "core/include/fpdfapi/cpdf_stream.h"
+#include "core/include/fpdfapi/cpdf_string.h"
#include "core/include/fpdfapi/fpdf_parser_decode.h"
#include "core/include/fxcrt/fx_ext.h"
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
index c054f95abd..1a7a83a55f 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
@@ -6,6 +6,8 @@
#include "core/src/fpdfapi/fpdf_render/render_int.h"
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_render.h"
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
index 3be74c5ce8..237be06c82 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
@@ -9,6 +9,8 @@
#include <utility>
#include <vector>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_pageobj.h"
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
index 72472ef8fb..6618a13709 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
@@ -10,6 +10,8 @@
#include <memory>
#include <vector>
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_pageobj.h"
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
index 92e0ff4d12..7e45399eef 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
@@ -6,6 +6,8 @@
#include "core/src/fpdfapi/fpdf_render/render_int.h"
+#include "core/include/fpdfapi/cpdf_array.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/fpdf_pageobj.h"
#include "core/include/fpdfapi/fpdf_render.h"
#include "core/include/fxge/fx_ge.h"
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
index 7051537ef3..c817c7c374 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
@@ -6,6 +6,7 @@
#include "core/src/fpdfapi/fpdf_render/render_int.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_document.h"
#include "core/include/fpdfapi/fpdf_pageobj.h"
#include "core/include/fpdfapi/fpdf_render.h"