diff options
Diffstat (limited to 'core/fpdfapi/fpdf_parser')
55 files changed, 1493 insertions, 121 deletions
diff --git a/core/fpdfapi/fpdf_parser/cfdf_document.cpp b/core/fpdfapi/fpdf_parser/cfdf_document.cpp index fd144a10a9..dec8fbdfaf 100644 --- a/core/fpdfapi/fpdf_parser/cfdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cfdf_document.cpp @@ -4,11 +4,11 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cfdf_document.h" +#include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" +#include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h" #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" -#include "core/include/fpdfapi/cpdf_dictionary.h" -#include "core/include/fpdfapi/fpdf_serial.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" CFDF_Document::CFDF_Document() : CPDF_IndirectObjectHolder(NULL) { m_pRootDict = NULL; diff --git a/core/fpdfapi/fpdf_parser/cpdf_array.cpp b/core/fpdfapi/fpdf_parser/cpdf_array.cpp index 3b21a45ae2..acd39a9390 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_array.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_array.cpp @@ -4,13 +4,13 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/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" +#include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" CPDF_Array::CPDF_Array() {} diff --git a/core/fpdfapi/fpdf_parser/cpdf_boolean.cpp b/core/fpdfapi/fpdf_parser/cpdf_boolean.cpp index 75f2203954..cd7ed32a96 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_boolean.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_boolean.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_boolean.h" +#include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" CPDF_Boolean::CPDF_Boolean() : m_bValue(false) {} diff --git a/core/fpdfapi/fpdf_parser/cpdf_boolean.h b/core/fpdfapi/fpdf_parser/cpdf_boolean.h new file mode 100644 index 0000000000..9a35153a20 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/cpdf_boolean.h @@ -0,0 +1,35 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_CPDF_BOOLEAN_H_ +#define CORE_FPDFAPI_FPDF_PARSER_CPDF_BOOLEAN_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Boolean : public CPDF_Object { + public: + CPDF_Boolean(); + explicit CPDF_Boolean(FX_BOOL value); + + // CPDF_Object. + Type GetType() const override; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; + CFX_ByteString GetString() const override; + int GetInteger() const override; + void SetString(const CFX_ByteString& str) override; + bool IsBoolean() const override; + CPDF_Boolean* AsBoolean() override; + const CPDF_Boolean* AsBoolean() const override; + + protected: + ~CPDF_Boolean() override; + + FX_BOOL m_bValue; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_CPDF_BOOLEAN_H_ diff --git a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp index 93916cba8b..1f7f70fa91 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp @@ -4,15 +4,18 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include "core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h" + #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.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_reference.h" -#include "core/include/fpdfapi/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/include/cpdf_modulemgr.h" #include "core/include/fxcrt/fx_ext.h" #include "core/include/fxcrt/fx_safe_types.h" #include "third_party/base/stl_util.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_data_avail.h b/core/fpdfapi/fpdf_parser/cpdf_data_avail.h index 2a6995914c..c30093dd58 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_data_avail.h +++ b/core/fpdfapi/fpdf_parser/cpdf_data_avail.h @@ -9,8 +9,8 @@ #include "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" -#include "core/include/fpdfapi/cpdf_parser.h" -#include "core/include/fpdfapi/ipdf_data_avail.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" +#include "core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h" #include "core/include/fxcrt/fx_basic.h" class CPDF_Dictionary; diff --git a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp index 864cd59744..0155c43bb8 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp @@ -4,15 +4,15 @@ // 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 "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" + +#include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" #include "third_party/base/stl_util.h" CPDF_Dictionary::CPDF_Dictionary() {} diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp index c6bdcddfbe..6a6e40f1c6 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp @@ -4,16 +4,17 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_document.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include <set> +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" #include "core/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_parser.h" -#include "core/include/fpdfapi/cpdf_reference.h" -#include "core/include/fpdfapi/fpdf_module.h" +#include "core/fpdfapi/include/cpdf_modulemgr.h" +#include "core/fpdfapi/ipdf_rendermodule.h" #include "core/include/fxge/fx_font.h" #include "third_party/base/stl_util.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp index 1dc015f34f..166c68d51a 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp @@ -7,10 +7,10 @@ #include "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" -#include "core/include/fpdfapi/cpdf_array.h" -#include "core/include/fpdfapi/cpdf_dictionary.h" -#include "core/include/fpdfapi/cpdf_stream.h" -#include "core/include/fpdfapi/cpdf_stream_acc.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" #include "core/include/fxcrt/fx_safe_types.h" namespace { diff --git a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.h b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.h index a9a89b48bf..325f57611f 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.h +++ b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.h @@ -9,7 +9,7 @@ #include <vector> -#include "core/include/fpdfapi/ipdf_data_avail.h" +#include "core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h" #include "core/include/fxcrt/fx_basic.h" #include "core/include/fxcrt/fx_stream.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp b/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp index b1606f9857..1de1ef2252 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp @@ -4,9 +4,10 @@ // 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" +#include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) : m_pParser(pParser), m_LastObjNum(0) { diff --git a/core/fpdfapi/fpdf_parser/cpdf_name.cpp b/core/fpdfapi/fpdf_parser/cpdf_name.cpp index 03d523db19..db37754b66 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_name.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_name.cpp @@ -4,9 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_name.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" -#include "core/include/fpdfapi/fpdf_parser_decode.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" CPDF_Name::CPDF_Name(const CFX_ByteString& str) : m_Name(str) {} diff --git a/core/fpdfapi/fpdf_parser/cpdf_null.cpp b/core/fpdfapi/fpdf_parser/cpdf_null.cpp index c18449d08f..c74daf300f 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_null.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_null.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_null.h" +#include "core/fpdfapi/fpdf_parser/cpdf_null.h" CPDF_Null::CPDF_Null() {} diff --git a/core/fpdfapi/fpdf_parser/cpdf_null.h b/core/fpdfapi/fpdf_parser/cpdf_null.h new file mode 100644 index 0000000000..ae33bb0256 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/cpdf_null.h @@ -0,0 +1,21 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_CPDF_NULL_H_ +#define CORE_FPDFAPI_FPDF_PARSER_CPDF_NULL_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" + +class CPDF_Null : public CPDF_Object { + public: + CPDF_Null(); + + // CPDF_Object. + Type GetType() const override; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_CPDF_NULL_H_ diff --git a/core/fpdfapi/fpdf_parser/cpdf_number.cpp b/core/fpdfapi/fpdf_parser/cpdf_number.cpp index ddc7aa11a2..d2f0503bc1 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_number.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_number.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_number.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" CPDF_Number::CPDF_Number() : m_bInteger(TRUE), m_Integer(0) {} diff --git a/core/fpdfapi/fpdf_parser/cpdf_object.cpp b/core/fpdfapi/fpdf_parser/cpdf_object.cpp index 208bca8e6c..ad00cc113b 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_object.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_object.cpp @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_object.h" +#include "core/fpdfapi/fpdf_parser/include/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/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" #include "core/include/fxcrt/fx_string.h" #include "third_party/base/stl_util.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp index 971bdaf20e..529b6c4fd3 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp @@ -2,21 +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/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/fpdfapi/fpdf_parser/cpdf_boolean.h" +#include "core/fpdfapi/fpdf_parser/cpdf_null.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" #include <memory> #include <string> #include <vector> -#include "core/include/fpdfapi/cpdf_indirect_object_holder.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" #include "core/include/fxcrt/fx_basic.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp index b57405f092..c9b8583d16 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp @@ -4,21 +4,21 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_parser.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" #include <vector> #include "core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.h" #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.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_number.h" -#include "core/include/fpdfapi/cpdf_reference.h" -#include "core/include/fpdfapi/cpdf_stream.h" -#include "core/include/fpdfapi/cpdf_stream_acc.h" -#include "core/include/fpdfapi/ipdf_crypto_handler.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" +#include "core/fpdfapi/fpdf_parser/ipdf_crypto_handler.h" #include "core/include/fxcrt/fx_ext.h" #include "core/include/fxcrt/fx_safe_types.h" #include "third_party/base/stl_util.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser_unittest.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser_unittest.cpp index 2d1dcd4b5c..b343618f28 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_parser_unittest.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_parser_unittest.cpp @@ -6,7 +6,7 @@ #include <string> #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" -#include "core/include/fpdfapi/cpdf_parser.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" #include "core/include/fxcrt/fx_ext.h" #include "core/include/fxcrt/fx_stream.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_reference.cpp b/core/fpdfapi/fpdf_parser/cpdf_reference.cpp index 4aede7d07a..6aa8fe9b4a 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_reference.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_reference.cpp @@ -4,9 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" -#include "core/include/fpdfapi/cpdf_indirect_object_holder.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" CPDF_Reference::CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, int objnum) : m_pObjList(pDoc), m_RefObjNum(objnum) {} diff --git a/core/fpdfapi/fpdf_parser/cpdf_simple_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_simple_parser.cpp index 90d4e0b5ab..a13fb0f365 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_simple_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_simple_parser.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_simple_parser.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_simple_parser_unittest.cpp b/core/fpdfapi/fpdf_parser/cpdf_simple_parser_unittest.cpp index a9acff4155..cfb0b33279 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_simple_parser_unittest.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_simple_parser_unittest.cpp @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "core/include/fpdfapi/cpdf_simple_parser.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" #include <string> diff --git a/core/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.cpp b/core/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.cpp index 0be414a135..17ef914c80 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.cpp @@ -9,9 +9,9 @@ #include <time.h> #include "core/fdrm/crypto/include/fx_crypt.h" -#include "core/include/fpdfapi/cpdf_parser.h" -#include "core/include/fpdfapi/cpdf_simple_parser.h" -#include "core/include/fpdfapi/ipdf_security_handler.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" +#include "core/fpdfapi/fpdf_parser/ipdf_security_handler.h" IPDF_CryptoHandler::~IPDF_CryptoHandler() {} diff --git a/core/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.h b/core/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.h index 28b7503f6e..c40fa7d0a4 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.h +++ b/core/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.h @@ -7,7 +7,7 @@ #ifndef CORE_FPDFAPI_FPDF_PARSER_CPDF_STANDARD_CRYPTO_HANDLER_H_ #define CORE_FPDFAPI_FPDF_PARSER_CPDF_STANDARD_CRYPTO_HANDLER_H_ -#include "core/include/fpdfapi/ipdf_crypto_handler.h" +#include "core/fpdfapi/fpdf_parser/ipdf_crypto_handler.h" class CPDF_StandardCryptoHandler : public IPDF_CryptoHandler { public: diff --git a/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp b/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp index 6da4cb1ff6..14e7ed65d3 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.cpp @@ -10,10 +10,10 @@ #include "core/fdrm/crypto/include/fx_crypt.h" #include "core/fpdfapi/fpdf_parser/cpdf_standard_crypto_handler.h" -#include "core/include/fpdfapi/cpdf_array.h" -#include "core/include/fpdfapi/cpdf_dictionary.h" -#include "core/include/fpdfapi/cpdf_object.h" -#include "core/include/fpdfapi/cpdf_parser.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" namespace { diff --git a/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.h b/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.h index 3341ec391c..7acaabcaef 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.h +++ b/core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.h @@ -7,7 +7,7 @@ #ifndef CORE_FPDFAPI_FPDF_PARSER_CPDF_STANDARD_SECURITY_HANDLER_H_ #define CORE_FPDFAPI_FPDF_PARSER_CPDF_STANDARD_SECURITY_HANDLER_H_ -#include "core/include/fpdfapi/ipdf_security_handler.h" +#include "core/fpdfapi/fpdf_parser/ipdf_security_handler.h" #include "core/include/fxcrt/fx_string.h" #include "core/include/fxcrt/fx_system.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_stream.cpp b/core/fpdfapi/fpdf_parser/cpdf_stream.cpp index 7faf9ddd44..72ecb7e9de 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_stream.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_stream.cpp @@ -4,11 +4,11 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" -#include "core/include/fpdfapi/cpdf_dictionary.h" -#include "core/include/fpdfapi/cpdf_stream_acc.h" -#include "core/include/fpdfapi/fpdf_parser_decode.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) : m_pDict(pDict), diff --git a/core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp b/core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp index 51ab1c0134..f10e33758c 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp @@ -4,10 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_stream_acc.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" -#include "core/include/fpdfapi/cpdf_dictionary.h" -#include "core/include/fpdfapi/fpdf_parser_decode.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" CPDF_StreamAcc::CPDF_StreamAcc() : m_pData(nullptr), diff --git a/core/fpdfapi/fpdf_parser/cpdf_string.cpp b/core/fpdfapi/fpdf_parser/cpdf_string.cpp index 1d0bf0b829..9a88e937ab 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_string.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_string.cpp @@ -4,9 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/cpdf_string.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" -#include "core/include/fpdfapi/fpdf_parser_decode.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" CPDF_String::CPDF_String() : m_bHex(FALSE) {} diff --git a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp index f5464cc21e..9e5cb9d38a 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp @@ -8,19 +8,19 @@ #include <vector> +#include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" +#include "core/fpdfapi/fpdf_parser/cpdf_null.h" #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.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_stream.h" -#include "core/include/fpdfapi/cpdf_string.h" -#include "core/include/fpdfapi/fpdf_module.h" -#include "core/include/fpdfapi/fpdf_parser_decode.h" -#include "core/include/fpdfapi/ipdf_crypto_handler.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" +#include "core/fpdfapi/fpdf_parser/ipdf_crypto_handler.h" +#include "core/fpdfapi/include/cpdf_modulemgr.h" #include "core/include/fxcrt/fx_ext.h" #include "third_party/base/numerics/safe_math.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser_unittest.cpp b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser_unittest.cpp index f501c01715..53a01e0224 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser_unittest.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser_unittest.cpp @@ -6,7 +6,7 @@ #include <string> #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" -#include "core/include/fpdfapi/cpdf_parser.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" #include "core/include/fxcrt/fx_ext.h" #include "core/include/fxcrt/fx_stream.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index eeb365d0e6..f7fc3099fc 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/include/fpdfapi/fpdf_parser_decode.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" #include <limits.h> #include <vector> #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" -#include "core/include/fpdfapi/cpdf_array.h" -#include "core/include/fpdfapi/cpdf_dictionary.h" -#include "core/include/fpdfapi/fpdf_module.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/include/cpdf_modulemgr.h" #include "core/include/fxcodec/fx_codec.h" #include "core/include/fxcrt/fx_ext.h" #include "third_party/base/stl_util.h" diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp index 2412f4310c..9e8d3344c3 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp @@ -2,7 +2,7 @@ // 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_parser_decode.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" #include <cstring> #include <string> diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp index e00759da7a..81f8cae354 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp @@ -2,7 +2,7 @@ // 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_parser_decode.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp index 3df220b79e..ffd4388dcc 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp @@ -6,14 +6,14 @@ #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.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_stream_acc.h" -#include "core/include/fpdfapi/cpdf_string.h" -#include "core/include/fpdfapi/fpdf_parser_decode.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" +#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" #include "core/include/fxcrt/fx_ext.h" // Indexed by 8-bit character code, contains either: diff --git a/core/fpdfapi/fpdf_parser/include/cfdf_document.h b/core/fpdfapi/fpdf_parser/include/cfdf_document.h new file mode 100644 index 0000000000..bd68789a14 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cfdf_document.h @@ -0,0 +1,36 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CFDF_DOCUMENT_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CFDF_DOCUMENT_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/include/fxcrt/fx_basic.h" + +class CPDF_Dictionary; + +class CFDF_Document : public CPDF_IndirectObjectHolder { + public: + static CFDF_Document* CreateNewDoc(); + static CFDF_Document* ParseFile(IFX_FileRead* pFile, + FX_BOOL bOwnFile = FALSE); + static CFDF_Document* ParseMemory(const uint8_t* pData, FX_DWORD size); + ~CFDF_Document(); + + FX_BOOL WriteBuf(CFX_ByteTextBuf& buf) const; + CPDF_Dictionary* GetRoot() const { return m_pRootDict; } + + protected: + CFDF_Document(); + void ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile); + + CPDF_Dictionary* m_pRootDict; + IFX_FileRead* m_pFile; + FX_BOOL m_bOwnFile; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CFDF_DOCUMENT_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_array.h b/core/fpdfapi/fpdf_parser/include/cpdf_array.h new file mode 100644 index 0000000000..a166454eba --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_array.h @@ -0,0 +1,65 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_ARRAY_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_ARRAY_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/include/fxcrt/fx_basic.h" +#include "core/include/fxcrt/fx_coordinates.h" + +class CPDF_Array : public CPDF_Object { + public: + CPDF_Array(); + + // CPDF_Object. + Type GetType() const override; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; + CPDF_Array* GetArray() const override; + bool IsArray() const override; + CPDF_Array* AsArray() override; + const CPDF_Array* AsArray() const override; + + FX_DWORD GetCount() const { return m_Objects.GetSize(); } + CPDF_Object* GetElement(FX_DWORD index) const; + CPDF_Object* GetElementValue(FX_DWORD index) const; + CFX_Matrix GetMatrix(); + CFX_FloatRect GetRect(); + CFX_ByteString GetStringAt(FX_DWORD index) const; + CFX_ByteStringC GetConstStringAt(FX_DWORD index) const; + int GetIntegerAt(FX_DWORD index) const; + FX_FLOAT GetNumberAt(FX_DWORD index) const; + CPDF_Dictionary* GetDictAt(FX_DWORD index) const; + CPDF_Stream* GetStreamAt(FX_DWORD index) const; + CPDF_Array* GetArrayAt(FX_DWORD index) const; + FX_FLOAT GetFloatAt(FX_DWORD index) const { return GetNumberAt(index); } + + void SetAt(FX_DWORD index, + CPDF_Object* pObj, + CPDF_IndirectObjectHolder* pObjs = nullptr); + void InsertAt(FX_DWORD index, + CPDF_Object* pObj, + CPDF_IndirectObjectHolder* pObjs = nullptr); + void RemoveAt(FX_DWORD index, int nCount = 1); + + void Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs = nullptr); + void AddNumber(FX_FLOAT f); + void AddInteger(int i); + void AddString(const CFX_ByteString& str); + void AddName(const CFX_ByteString& str); + void AddReference(CPDF_IndirectObjectHolder* pDoc, FX_DWORD objnum); + void AddReference(CPDF_IndirectObjectHolder* pDoc, CPDF_Object* obj) { + AddReference(pDoc, obj->GetObjNum()); + } + + protected: + ~CPDF_Array() override; + + CFX_ArrayTemplate<CPDF_Object*> m_Objects; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_ARRAY_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h new file mode 100644 index 0000000000..896db62cc2 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h @@ -0,0 +1,99 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DICTIONARY_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DICTIONARY_H_ + +#include <map> + +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/include/fxcrt/fx_coordinates.h" +#include "core/include/fxcrt/fx_string.h" + +class CPDF_IndirectObjectHolder; + +class CPDF_Dictionary : public CPDF_Object { + public: + using iterator = std::map<CFX_ByteString, CPDF_Object*>::iterator; + using const_iterator = std::map<CFX_ByteString, CPDF_Object*>::const_iterator; + + CPDF_Dictionary(); + + // CPDF_Object. + Type GetType() const override; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; + CPDF_Dictionary* GetDict() const override; + bool IsDictionary() const override; + CPDF_Dictionary* AsDictionary() override; + const CPDF_Dictionary* AsDictionary() const override; + + size_t GetCount() const { return m_Map.size(); } + CPDF_Object* GetElement(const CFX_ByteStringC& key) const; + CPDF_Object* GetElementValue(const CFX_ByteStringC& key) const; + CFX_ByteString GetStringBy(const CFX_ByteStringC& key) const; + CFX_ByteStringC GetConstStringBy(const CFX_ByteStringC& key) const; + CFX_ByteString GetStringBy(const CFX_ByteStringC& key, + const CFX_ByteStringC& default_str) const; + CFX_ByteStringC GetConstStringBy(const CFX_ByteStringC& key, + const CFX_ByteStringC& default_str) const; + CFX_WideString GetUnicodeTextBy(const CFX_ByteStringC& key) const; + int GetIntegerBy(const CFX_ByteStringC& key) const; + int GetIntegerBy(const CFX_ByteStringC& key, int default_int) const; + FX_BOOL GetBooleanBy(const CFX_ByteStringC& key, + FX_BOOL bDefault = FALSE) const; + FX_FLOAT GetNumberBy(const CFX_ByteStringC& key) const; + CPDF_Dictionary* GetDictBy(const CFX_ByteStringC& key) const; + CPDF_Stream* GetStreamBy(const CFX_ByteStringC& key) const; + CPDF_Array* GetArrayBy(const CFX_ByteStringC& key) const; + CFX_FloatRect GetRectBy(const CFX_ByteStringC& key) const; + CFX_Matrix GetMatrixBy(const CFX_ByteStringC& key) const; + FX_FLOAT GetFloatBy(const CFX_ByteStringC& key) const { + return GetNumberBy(key); + } + + FX_BOOL KeyExist(const CFX_ByteStringC& key) const; + bool IsSignatureDict() const; + + // Set* functions invalidate iterators for the element with the key |key|. + void SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj); + void SetAtName(const CFX_ByteStringC& key, const CFX_ByteString& name); + void SetAtString(const CFX_ByteStringC& key, const CFX_ByteString& str); + void SetAtInteger(const CFX_ByteStringC& key, int i); + void SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f); + void SetAtReference(const CFX_ByteStringC& key, + CPDF_IndirectObjectHolder* pDoc, + FX_DWORD objnum); + void SetAtReference(const CFX_ByteStringC& key, + CPDF_IndirectObjectHolder* pDoc, + CPDF_Object* obj) { + SetAtReference(key, pDoc, obj->GetObjNum()); + } + void SetAtRect(const CFX_ByteStringC& key, const CFX_FloatRect& rect); + void SetAtMatrix(const CFX_ByteStringC& key, const CFX_Matrix& matrix); + void SetAtBoolean(const CFX_ByteStringC& key, FX_BOOL bValue); + + void AddReference(const CFX_ByteStringC& key, + CPDF_IndirectObjectHolder* pDoc, + FX_DWORD objnum); + + // Invalidates iterators for the element with the key |key|. + void RemoveAt(const CFX_ByteStringC& key); + + // Invalidates iterators for the element with the key |oldkey|. + void ReplaceKey(const CFX_ByteStringC& oldkey, const CFX_ByteStringC& newkey); + + iterator begin() { return m_Map.begin(); } + iterator end() { return m_Map.end(); } + const_iterator begin() const { return m_Map.begin(); } + const_iterator end() const { return m_Map.end(); } + + protected: + ~CPDF_Dictionary() override; + + std::map<CFX_ByteString, CPDF_Object*> m_Map; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DICTIONARY_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_document.h b/core/fpdfapi/fpdf_parser/include/cpdf_document.h new file mode 100644 index 0000000000..56e41b4328 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_document.h @@ -0,0 +1,137 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DOCUMENT_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DOCUMENT_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/include/fxcrt/fx_basic.h" + +class CFX_Font; +class CFX_Matrix; +class CPDF_ColorSpace; +class CPDF_DocPageData; +class CPDF_DocRenderData; +class CPDF_Font; +class CPDF_FontEncoding; +class CPDF_IccProfile; +class CPDF_Image; +class CPDF_Pattern; +class CPDF_StreamAcc; + +#define FPDFPERM_PRINT 0x0004 +#define FPDFPERM_MODIFY 0x0008 +#define FPDFPERM_EXTRACT 0x0010 +#define FPDFPERM_ANNOT_FORM 0x0020 +#define FPDFPERM_FILL_FORM 0x0100 +#define FPDFPERM_EXTRACT_ACCESS 0x0200 +#define FPDFPERM_ASSEMBLE 0x0400 +#define FPDFPERM_PRINT_HIGH 0x0800 +#define FPDF_PAGE_MAX_NUM 0xFFFFF + +class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjectHolder { + public: + CPDF_Document(); + explicit CPDF_Document(CPDF_Parser* pParser); + ~CPDF_Document(); + + CPDF_Parser* GetParser() const { return m_pParser; } + CPDF_Dictionary* GetRoot() const { return m_pRootDict; } + CPDF_Dictionary* GetInfo() const { return m_pInfoDict; } + + void GetID(CFX_ByteString& id1, CFX_ByteString& id2) const { + id1 = m_ID1; + id2 = m_ID2; + } + + int GetPageCount() const; + CPDF_Dictionary* GetPage(int iPage); + int GetPageIndex(FX_DWORD objnum); + FX_DWORD GetUserPermissions(FX_BOOL bCheckRevision = FALSE) const; + CPDF_DocPageData* GetPageData() { return GetValidatePageData(); } + void ClearPageData(); + void RemoveColorSpaceFromPageData(CPDF_Object* pObject); + + CPDF_DocRenderData* GetRenderData() { return GetValidateRenderData(); } + void ClearRenderData(); + void ClearRenderFont(); + + FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const; + + // |pFontDict| must not be null. + CPDF_Font* LoadFont(CPDF_Dictionary* pFontDict); + CPDF_ColorSpace* LoadColorSpace(CPDF_Object* pCSObj, + CPDF_Dictionary* pResources = NULL); + + CPDF_Pattern* LoadPattern(CPDF_Object* pObj, + FX_BOOL bShading, + const CFX_Matrix* matrix = NULL); + + CPDF_Image* LoadImageF(CPDF_Object* pObj); + CPDF_StreamAcc* LoadFontFile(CPDF_Stream* pStream); + CPDF_IccProfile* LoadIccProfile(CPDF_Stream* pStream); + +#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ + + CPDF_Font* AddWindowsFont(LOGFONTA* pLogFont, + FX_BOOL bVert, + FX_BOOL bTranslateName = FALSE); + CPDF_Font* AddWindowsFont(LOGFONTW* pLogFont, + FX_BOOL bVert, + FX_BOOL bTranslateName = FALSE); +#endif +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + CPDF_Font* AddMacFont(CTFontRef pFont, + FX_BOOL bVert, + FX_BOOL bTranslateName = FALSE); +#endif + + CPDF_Font* AddStandardFont(const FX_CHAR* font, CPDF_FontEncoding* pEncoding); + CPDF_Font* AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert); + void CreateNewDoc(); + + CPDF_Dictionary* CreateNewPage(int iPage); + void DeletePage(int iPage); + + void LoadDoc(); + void LoadAsynDoc(CPDF_Dictionary* pLinearized); + void LoadPages(); + + protected: + // Retrieve page count information by getting count value from the tree nodes + // or walking through the tree nodes to calculate it. + int RetrievePageCount() const; + CPDF_Dictionary* _FindPDFPage(CPDF_Dictionary* pPages, + int iPage, + int nPagesToGo, + int level); + int _FindPageIndex(CPDF_Dictionary* pNode, + FX_DWORD& skip_count, + FX_DWORD objnum, + int& index, + int level = 0); + FX_BOOL CheckOCGVisible(CPDF_Dictionary* pOCG, FX_BOOL bPrinting); + CPDF_DocPageData* GetValidatePageData(); + CPDF_DocRenderData* GetValidateRenderData(); + friend class CPDF_Creator; + friend class CPDF_Parser; + friend class CPDF_DataAvail; + friend class CPDF_OCContext; + + CPDF_Dictionary* m_pRootDict; + CPDF_Dictionary* m_pInfoDict; + CFX_ByteString m_ID1; + CFX_ByteString m_ID2; + FX_BOOL m_bLinearized; + FX_DWORD m_dwFirstPageNo; + FX_DWORD m_dwFirstPageObjNum; + CFX_DWordArray m_PageList; + CPDF_DocPageData* m_pDocPage; + CPDF_DocRenderData* m_pDocRender; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DOCUMENT_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h b/core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h new file mode 100644 index 0000000000..9fa6770c90 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h @@ -0,0 +1,44 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_INDIRECT_OBJECT_HOLDER_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_INDIRECT_OBJECT_HOLDER_H_ + +#include <map> + +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Object; +class CPDF_Parser; + +class CPDF_IndirectObjectHolder { + public: + using iterator = std::map<FX_DWORD, CPDF_Object*>::iterator; + using const_iterator = std::map<FX_DWORD, CPDF_Object*>::const_iterator; + + explicit CPDF_IndirectObjectHolder(CPDF_Parser* pParser); + ~CPDF_IndirectObjectHolder(); + + CPDF_Object* GetIndirectObject(FX_DWORD objnum); + FX_DWORD AddIndirectObject(CPDF_Object* pObj); + void ReleaseIndirectObject(FX_DWORD objnum); + + // Takes ownership of |pObj|. + FX_BOOL InsertIndirectObject(FX_DWORD objnum, CPDF_Object* pObj); + + FX_DWORD GetLastObjNum() const { return m_LastObjNum; } + iterator begin() { return m_IndirectObjs.begin(); } + const_iterator begin() const { return m_IndirectObjs.begin(); } + iterator end() { return m_IndirectObjs.end(); } + const_iterator end() const { return m_IndirectObjs.end(); } + + protected: + CPDF_Parser* m_pParser; + FX_DWORD m_LastObjNum; + std::map<FX_DWORD, CPDF_Object*> m_IndirectObjs; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_INDIRECT_OBJECT_HOLDER_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_name.h b/core/fpdfapi/fpdf_parser/include/cpdf_name.h new file mode 100644 index 0000000000..62fd5c14a8 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_name.h @@ -0,0 +1,35 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_NAME_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_NAME_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" + +class CPDF_Name : public CPDF_Object { + public: + explicit CPDF_Name(const CFX_ByteString& str); + explicit CPDF_Name(const CFX_ByteStringC& str); + explicit CPDF_Name(const FX_CHAR* str); + + // CPDF_Object. + Type GetType() const override; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; + CFX_ByteString GetString() const override; + CFX_ByteStringC GetConstString() const override; + CFX_WideString GetUnicodeText() const override; + void SetString(const CFX_ByteString& str) override; + bool IsName() const override; + CPDF_Name* AsName() override; + const CPDF_Name* AsName() const override; + + protected: + ~CPDF_Name() override; + + CFX_ByteString m_Name; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_NAME_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_number.h b/core/fpdfapi/fpdf_parser/include/cpdf_number.h new file mode 100644 index 0000000000..89586352f6 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_number.h @@ -0,0 +1,44 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_NUMBER_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_NUMBER_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Number : public CPDF_Object { + public: + CPDF_Number(); + explicit CPDF_Number(int value); + explicit CPDF_Number(FX_FLOAT value); + explicit CPDF_Number(const CFX_ByteStringC& str); + + // CPDF_Object. + Type GetType() const override; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; + CFX_ByteString GetString() const override; + FX_FLOAT GetNumber() const override; + int GetInteger() const override; + void SetString(const CFX_ByteString& str) override; + bool IsNumber() const override; + CPDF_Number* AsNumber() override; + const CPDF_Number* AsNumber() const override; + + FX_BOOL IsInteger() { return m_bInteger; } + + protected: + ~CPDF_Number() override; + + FX_BOOL m_bInteger; + union { + int m_Integer; + FX_FLOAT m_Float; + }; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_NUMBER_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_object.h b/core/fpdfapi/fpdf_parser/include/cpdf_object.h new file mode 100644 index 0000000000..9149510536 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_object.h @@ -0,0 +1,161 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Array; +class CPDF_Boolean; +class CPDF_Dictionary; +class CPDF_Name; +class CPDF_Null; +class CPDF_Number; +class CPDF_Reference; +class CPDF_Stream; +class CPDF_String; + +class CPDF_Object { + public: + enum Type { + BOOLEAN = 1, + NUMBER, + STRING, + NAME, + ARRAY, + DICTIONARY, + STREAM, + NULLOBJ, + REFERENCE + }; + + virtual Type GetType() const = 0; + FX_DWORD GetObjNum() const { return m_ObjNum; } + FX_DWORD GetGenNum() const { return m_GenNum; } + + virtual CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const = 0; + virtual CPDF_Object* GetDirect() const; + + FX_BOOL IsModified() const { return FALSE; } + void Release(); + + virtual CFX_ByteString GetString() const; + virtual CFX_ByteStringC GetConstString() const; + virtual CFX_WideString GetUnicodeText() const; + virtual FX_FLOAT GetNumber() const; + virtual int GetInteger() const; + virtual CPDF_Dictionary* GetDict() const; + virtual CPDF_Array* GetArray() const; + + virtual void SetString(const CFX_ByteString& str); + + virtual bool IsArray() const; + virtual bool IsBoolean() const; + virtual bool IsDictionary() const; + virtual bool IsName() const; + virtual bool IsNumber() const; + virtual bool IsReference() const; + virtual bool IsStream() const; + virtual bool IsString() const; + + virtual CPDF_Array* AsArray(); + virtual const CPDF_Array* AsArray() const; + virtual CPDF_Boolean* AsBoolean(); + virtual const CPDF_Boolean* AsBoolean() const; + virtual CPDF_Dictionary* AsDictionary(); + virtual const CPDF_Dictionary* AsDictionary() const; + virtual CPDF_Name* AsName(); + virtual const CPDF_Name* AsName() const; + virtual CPDF_Number* AsNumber(); + virtual const CPDF_Number* AsNumber() const; + virtual CPDF_Reference* AsReference(); + virtual const CPDF_Reference* AsReference() const; + virtual CPDF_Stream* AsStream(); + virtual const CPDF_Stream* AsStream() const; + virtual CPDF_String* AsString(); + virtual const CPDF_String* AsString() const; + + protected: + CPDF_Object() : m_ObjNum(0), m_GenNum(0) {} + virtual ~CPDF_Object(); + void Destroy() { delete this; } + + FX_DWORD m_ObjNum; + FX_DWORD m_GenNum; + + friend class CPDF_IndirectObjectHolder; + friend class CPDF_Parser; + + private: + CPDF_Object(const CPDF_Object& src) {} +}; + +inline CPDF_Boolean* ToBoolean(CPDF_Object* obj) { + return obj ? obj->AsBoolean() : nullptr; +} + +inline const CPDF_Boolean* ToBoolean(const CPDF_Object* obj) { + return obj ? obj->AsBoolean() : nullptr; +} + +inline CPDF_Number* ToNumber(CPDF_Object* obj) { + return obj ? obj->AsNumber() : nullptr; +} + +inline const CPDF_Number* ToNumber(const CPDF_Object* obj) { + return obj ? obj->AsNumber() : nullptr; +} + +inline CPDF_String* ToString(CPDF_Object* obj) { + return obj ? obj->AsString() : nullptr; +} + +inline const CPDF_String* ToString(const CPDF_Object* obj) { + return obj ? obj->AsString() : nullptr; +} + +inline CPDF_Name* ToName(CPDF_Object* obj) { + return obj ? obj->AsName() : nullptr; +} + +inline const CPDF_Name* ToName(const CPDF_Object* obj) { + return obj ? obj->AsName() : nullptr; +} + +inline CPDF_Array* ToArray(CPDF_Object* obj) { + return obj ? obj->AsArray() : nullptr; +} + +inline const CPDF_Array* ToArray(const CPDF_Object* obj) { + return obj ? obj->AsArray() : nullptr; +} + +inline CPDF_Dictionary* ToDictionary(CPDF_Object* obj) { + return obj ? obj->AsDictionary() : nullptr; +} + +inline const CPDF_Dictionary* ToDictionary(const CPDF_Object* obj) { + return obj ? obj->AsDictionary() : nullptr; +} +inline CPDF_Reference* ToReference(CPDF_Object* obj) { + return obj ? obj->AsReference() : nullptr; +} + +inline const CPDF_Reference* ToReference(const CPDF_Object* obj) { + return obj ? obj->AsReference() : nullptr; +} + +inline CPDF_Stream* ToStream(CPDF_Object* obj) { + return obj ? obj->AsStream() : nullptr; +} + +inline const CPDF_Stream* ToStream(const CPDF_Object* obj) { + return obj ? obj->AsStream() : nullptr; +} + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_parser.h b/core/fpdfapi/fpdf_parser/include/cpdf_parser.h new file mode 100644 index 0000000000..d5c5216b9c --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_parser.h @@ -0,0 +1,173 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_PARSER_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_PARSER_H_ + +#include <map> +#include <memory> +#include <set> + +#include "core/include/fxcrt/fx_basic.h" + +class CPDF_Array; +class CPDF_Dictionary; +class CPDF_Document; +class CPDF_IndirectObjectHolder; +class CPDF_Object; +class CPDF_StreamAcc; +class CPDF_SyntaxParser; +class IFX_FileRead; +class IPDF_CryptoHandler; +class IPDF_SecurityHandler; + +class CPDF_Parser { + public: + enum Error { + SUCCESS = 0, + FILE_ERROR, + FORMAT_ERROR, + PASSWORD_ERROR, + HANDLER_ERROR + }; + + CPDF_Parser(); + ~CPDF_Parser(); + + Error StartParse(IFX_FileRead* pFile); + FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE); + + void SetPassword(const FX_CHAR* password) { m_Password = password; } + CFX_ByteString GetPassword() { return m_Password; } + CPDF_Dictionary* GetTrailer() const { return m_pTrailer; } + FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; } + CPDF_Document* GetDocument() const { return m_pDocument; } + + FX_DWORD GetRootObjNum(); + FX_DWORD GetInfoObjNum(); + CPDF_Array* GetIDArray(); + + CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict; } + + CPDF_Object* ParseIndirectObject(CPDF_IndirectObjectHolder* pObjList, + FX_DWORD objnum); + + FX_DWORD GetLastObjNum() const; + bool IsValidObjectNumber(FX_DWORD objnum) const; + FX_FILESIZE GetObjectPositionOrZero(FX_DWORD objnum) const; + uint8_t GetObjectType(FX_DWORD objnum) const; + uint16_t GetObjectGenNum(FX_DWORD objnum) const; + bool IsVersionUpdated() const { return m_bVersionUpdated; } + bool IsObjectFreeOrNull(FX_DWORD objnum) const; + FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm); + IPDF_CryptoHandler* GetCryptoHandler(); + IFX_FileRead* GetFileAccess() const; + + FX_FILESIZE GetObjectOffset(FX_DWORD objnum) const; + FX_FILESIZE GetObjectSize(FX_DWORD objnum) const; + + void GetIndirectBinary(FX_DWORD objnum, uint8_t*& pBuffer, FX_DWORD& size); + int GetFileVersion() const { return m_FileVersion; } + FX_BOOL IsXRefStream() const { return m_bXRefStream; } + + CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjectHolder* pObjList, + FX_FILESIZE pos, + FX_DWORD objnum); + + CPDF_Object* ParseIndirectObjectAtByStrict( + CPDF_IndirectObjectHolder* pObjList, + FX_FILESIZE pos, + FX_DWORD objnum, + FX_FILESIZE* pResultPos); + + Error StartAsyncParse(IFX_FileRead* pFile); + + FX_DWORD GetFirstPageNo() const { return m_dwFirstPageNo; } + + protected: + struct ObjectInfo { + ObjectInfo() : pos(0), type(0), gennum(0) {} + + FX_FILESIZE pos; + uint8_t type; + uint16_t gennum; + }; + + void CloseParser(); + CPDF_Object* ParseDirect(CPDF_Object* pObj); + FX_BOOL LoadAllCrossRefV4(FX_FILESIZE pos); + FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos); + bool LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, FX_BOOL bSkip); + FX_BOOL LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef); + CPDF_Dictionary* LoadTrailerV4(); + FX_BOOL RebuildCrossRef(); + Error SetEncryptHandler(); + void ReleaseEncryptHandler(); + FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); + FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); + FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); + Error LoadLinearizedMainXRefTable(); + CPDF_StreamAcc* GetObjectStream(FX_DWORD number); + FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset); + void SetEncryptDictionary(CPDF_Dictionary* pDict); + void ShrinkObjectMap(FX_DWORD size); + + CPDF_Document* m_pDocument; + std::unique_ptr<CPDF_SyntaxParser> m_pSyntax; + bool m_bOwnFileRead; + int m_FileVersion; + CPDF_Dictionary* m_pTrailer; + CPDF_Dictionary* m_pEncryptDict; + FX_FILESIZE m_LastXRefOffset; + FX_BOOL m_bXRefStream; + std::unique_ptr<IPDF_SecurityHandler> m_pSecurityHandler; + CFX_ByteString m_bsRecipient; + CFX_ByteString m_FilePath; + CFX_ByteString m_Password; + std::map<FX_DWORD, ObjectInfo> m_ObjectInfo; + std::set<FX_FILESIZE> m_SortedOffset; + CFX_ArrayTemplate<CPDF_Dictionary*> m_Trailers; + bool m_bVersionUpdated; + CPDF_Object* m_pLinearized; + FX_DWORD m_dwFirstPageNo; + FX_DWORD m_dwXrefStartObjNum; + + // A map of object numbers to indirect streams. Map owns the streams. + std::map<FX_DWORD, std::unique_ptr<CPDF_StreamAcc>> m_ObjectStreamMap; + + // Mapping of object numbers to offsets. The offsets are relative to the first + // object in the stream. + using StreamObjectCache = std::map<FX_DWORD, FX_DWORD>; + + // Mapping of streams to their object caches. This is valid as long as the + // streams in |m_ObjectStreamMap| are valid. + std::map<CPDF_StreamAcc*, StreamObjectCache> m_ObjCache; + + // All indirect object numbers that are being parsed. + std::set<FX_DWORD> m_ParsingObjNums; + + friend class CPDF_DataAvail; + + private: + enum class ParserState { + kDefault, + kComment, + kWhitespace, + kString, + kHexString, + kEscapedString, + kXref, + kObjNum, + kPostObjNum, + kGenNum, + kPostGenNum, + kTrailer, + kBeginObj, + kEndObj + }; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_PARSER_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_reference.h b/core/fpdfapi/fpdf_parser/include/cpdf_reference.h new file mode 100644 index 0000000000..f44f1e437b --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_reference.h @@ -0,0 +1,51 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_REFERENCE_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_REFERENCE_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" + +class CPDF_IndirectObjectHolder; + +class CPDF_Reference : public CPDF_Object { + public: + CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, int objnum); + + // CPDF_Object. + Type GetType() const override; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; + CPDF_Object* GetDirect() const override; + CFX_ByteString GetString() const override; + CFX_ByteStringC GetConstString() const override; + FX_FLOAT GetNumber() const override; + int GetInteger() const override; + CPDF_Dictionary* GetDict() const override; + + // TODO(weili): check whether GetUnicodeText() and GetArray() are needed. + bool IsReference() const override; + CPDF_Reference* AsReference() override; + const CPDF_Reference* AsReference() const override; + + CPDF_IndirectObjectHolder* GetObjList() const { return m_pObjList; } + FX_DWORD GetRefObjNum() const { return m_RefObjNum; } + + void SetRef(CPDF_IndirectObjectHolder* pDoc, FX_DWORD objnum); + + protected: + ~CPDF_Reference() override; + CPDF_Object* SafeGetDirect() const { + CPDF_Object* obj = GetDirect(); + if (!obj || obj->IsReference()) + return nullptr; + return obj; + } + + CPDF_IndirectObjectHolder* m_pObjList; + FX_DWORD m_RefObjNum; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_REFERENCE_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h b/core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h new file mode 100644 index 0000000000..a2a39f10ea --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h @@ -0,0 +1,35 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_SIMPLE_PARSER_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_SIMPLE_PARSER_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_SimpleParser { + public: + CPDF_SimpleParser(const uint8_t* pData, FX_DWORD dwSize); + CPDF_SimpleParser(const CFX_ByteStringC& str); + + CFX_ByteStringC GetWord(); + + // Find the token and its |nParams| parameters from the start of data, + // and move the current position to the start of those parameters. + bool FindTagParamFromStart(const CFX_ByteStringC& token, int nParams); + + // For testing only. + FX_DWORD GetCurPos() const { return m_dwCurPos; } + + private: + void ParseWord(const uint8_t*& pStart, FX_DWORD& dwSize); + + const uint8_t* m_pData; + FX_DWORD m_dwSize; + FX_DWORD m_dwCurPos; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_SIMPLE_PARSER_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_stream.h b/core/fpdfapi/fpdf_parser/include/cpdf_stream.h new file mode 100644 index 0000000000..43853839a1 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_stream.h @@ -0,0 +1,61 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/include/fxcrt/fx_stream.h" + +class CPDF_Stream : public CPDF_Object { + public: + CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict); + + // CPDF_Object. + Type GetType() const override; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; + CPDF_Dictionary* GetDict() const override; + CFX_WideString GetUnicodeText() const override; + bool IsStream() const override; + CPDF_Stream* AsStream() override; + const CPDF_Stream* AsStream() const override; + + FX_DWORD GetRawSize() const { return m_dwSize; } + uint8_t* GetRawData() const { return m_pDataBuf; } + + void SetData(const uint8_t* pData, + FX_DWORD size, + FX_BOOL bCompressed, + FX_BOOL bKeepBuf); + + void InitStream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict); + void InitStreamFromFile(IFX_FileRead* pFile, CPDF_Dictionary* pDict); + + FX_BOOL ReadRawData(FX_FILESIZE start_pos, + uint8_t* pBuf, + FX_DWORD buf_size) const; + + bool IsMemoryBased() const { return m_GenNum == kMemoryBasedGenNum; } + + protected: + static const FX_DWORD kMemoryBasedGenNum = (FX_DWORD)-1; + + ~CPDF_Stream() override; + + void InitStreamInternal(CPDF_Dictionary* pDict); + + CPDF_Dictionary* m_pDict; + FX_DWORD m_dwSize; + FX_DWORD m_GenNum; + + union { + uint8_t* m_pDataBuf; + IFX_FileRead* m_pFile; + }; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h b/core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h new file mode 100644 index 0000000000..6920579c8e --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h @@ -0,0 +1,46 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_ACC_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_ACC_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_StreamAcc { + public: + CPDF_StreamAcc(); + ~CPDF_StreamAcc(); + + void LoadAllData(const CPDF_Stream* pStream, + FX_BOOL bRawAccess = FALSE, + FX_DWORD estimated_size = 0, + FX_BOOL bImageAcc = FALSE); + + const CPDF_Stream* GetStream() const { return m_pStream; } + CPDF_Dictionary* GetDict() const { + return m_pStream ? m_pStream->GetDict() : nullptr; + } + + const uint8_t* GetData() const; + FX_DWORD GetSize() const; + const CFX_ByteString& GetImageDecoder() const { return m_ImageDecoder; } + const CPDF_Dictionary* GetImageParam() const { return m_pImageParam; } + uint8_t* DetachData(); + + protected: + uint8_t* m_pData; + FX_DWORD m_dwSize; + FX_BOOL m_bNewBuf; + CFX_ByteString m_ImageDecoder; + CPDF_Dictionary* m_pImageParam; + const CPDF_Stream* m_pStream; + uint8_t* m_pSrcData; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_ACC_H_ diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_string.h b/core/fpdfapi/fpdf_parser/include/cpdf_string.h new file mode 100644 index 0000000000..088fe6e28d --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/cpdf_string.h @@ -0,0 +1,40 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STRING_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STRING_H_ + +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_String : public CPDF_Object { + public: + CPDF_String(); + CPDF_String(const CFX_ByteString& str, FX_BOOL bHex); + explicit CPDF_String(const CFX_WideString& str); + + // CPDF_Object. + Type GetType() const override; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const override; + CFX_ByteString GetString() const override; + CFX_ByteStringC GetConstString() const override; + CFX_WideString GetUnicodeText() const override; + void SetString(const CFX_ByteString& str) override; + bool IsString() const override; + CPDF_String* AsString() override; + const CPDF_String* AsString() const override; + + FX_BOOL IsHex() const { return m_bHex; } + + protected: + ~CPDF_String() override; + + CFX_ByteString m_String; + FX_BOOL m_bHex; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STRING_H_ diff --git a/core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h b/core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h new file mode 100644 index 0000000000..6a17ac5332 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h @@ -0,0 +1,76 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_FPDF_PARSER_DECODE_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_FPDF_PARSER_DECODE_H_ + +#include "core/include/fxcrt/fx_basic.h" + +class CPDF_Dictionary; + +// Indexed by 8-bit char code, contains unicode code points. +extern const FX_WORD PDFDocEncoding[256]; + +CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& orig); +CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig); +CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig); +CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, + FX_BOOL bHex = FALSE); +CFX_WideString PDF_DecodeText(const uint8_t* pData, FX_DWORD size); +CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr); +CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len = -1); +CFX_ByteString PDF_EncodeText(const CFX_WideString& str); + +void FlateEncode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size); +void FlateEncode(const uint8_t* src_buf, + FX_DWORD src_size, + int predictor, + int Colors, + int BitsPerComponent, + int Columns, + uint8_t*& dest_buf, + FX_DWORD& dest_size); +FX_DWORD FlateDecode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size); +FX_DWORD RunLengthDecode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size); + +// Public for testing. +FX_DWORD A85Decode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size); +// Public for testing. +FX_DWORD HexDecode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size); +// Public for testing. +FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, + const uint8_t* src_buf, + FX_DWORD src_size, + CPDF_Dictionary* pParams, + FX_DWORD estimated_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size); +FX_BOOL PDF_DataDecode(const uint8_t* src_buf, + FX_DWORD src_size, + const CPDF_Dictionary* pDict, + uint8_t*& dest_buf, + FX_DWORD& dest_size, + CFX_ByteString& ImageEncoding, + CPDF_Dictionary*& pImageParms, + FX_DWORD estimated_size, + FX_BOOL bImageAcc); + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_FPDF_PARSER_DECODE_H_ diff --git a/core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h b/core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h new file mode 100644 index 0000000000..90d137c34a --- /dev/null +++ b/core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h @@ -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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_IPDF_DATA_AVAIL_H_ +#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_IPDF_DATA_AVAIL_H_ + +#include "core/include/fxcrt/fx_stream.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Document; +class CPDF_Object; + +class IPDF_DataAvail { + public: + // Must match PDF_DATA_* definitions in public/fpdf_dataavail.h, but cannot + // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts + // to make sure the two sets of values match. + enum DocAvailStatus { + DataError = -1, // PDF_DATA_ERROR + DataNotAvailable = 0, // PDF_DATA_NOTAVAIL + DataAvailable = 1, // PDF_DATA_AVAIL + }; + + // Must match PDF_*LINEAR* definitions in public/fpdf_dataavail.h, but cannot + // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts + // to make sure the two sets of values match. + enum DocLinearizationStatus { + LinearizationUnknown = -1, // PDF_LINEARIZATION_UNKNOWN + NotLinearized = 0, // PDF_NOT_LINEARIZED + Linearized = 1, // PDF_LINEARIZED + }; + + // Must match PDF_FORM_* definitions in public/fpdf_dataavail.h, but cannot + // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts + // to make sure the two sets of values match. + enum DocFormStatus { + FormError = -1, // PDF_FORM_ERROR + FormNotAvailable = 0, // PDF_FORM_NOTAVAIL + FormAvailable = 1, // PDF_FORM_AVAIL + FormNotExist = 2, // PDF_FORM_NOTEXIST + }; + + class FileAvail { + public: + virtual ~FileAvail(); + virtual FX_BOOL IsDataAvail(FX_FILESIZE offset, FX_DWORD size) = 0; + }; + + class DownloadHints { + public: + virtual ~DownloadHints(); + virtual void AddSegment(FX_FILESIZE offset, FX_DWORD size) = 0; + }; + + static IPDF_DataAvail* Create(FileAvail* pFileAvail, IFX_FileRead* pFileRead); + virtual ~IPDF_DataAvail(); + + FileAvail* GetFileAvail() const { return m_pFileAvail; } + IFX_FileRead* GetFileRead() const { return m_pFileRead; } + + virtual DocAvailStatus IsDocAvail(DownloadHints* pHints) = 0; + virtual void SetDocument(CPDF_Document* pDoc) = 0; + virtual DocAvailStatus IsPageAvail(int iPage, DownloadHints* pHints) = 0; + virtual FX_BOOL IsLinearized() = 0; + virtual DocFormStatus IsFormAvail(DownloadHints* pHints) = 0; + virtual DocLinearizationStatus IsLinearizedPDF() = 0; + virtual void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, + FX_DWORD* pSize) = 0; + + protected: + IPDF_DataAvail(FileAvail* pFileAvail, IFX_FileRead* pFileRead); + + FileAvail* m_pFileAvail; + IFX_FileRead* m_pFileRead; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_IPDF_DATA_AVAIL_H_ diff --git a/core/fpdfapi/fpdf_parser/ipdf_crypto_handler.h b/core/fpdfapi/fpdf_parser/ipdf_crypto_handler.h new file mode 100644 index 0000000000..a1000760f3 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/ipdf_crypto_handler.h @@ -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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_IPDF_CRYPTO_HANDLER_H_ +#define CORE_FPDFAPI_FPDF_PARSER_IPDF_CRYPTO_HANDLER_H_ + +#include "core/include/fxcrt/fx_basic.h" + +class CPDF_Dictionary; +class IPDF_SecurityHandler; + +class IPDF_CryptoHandler { + public: + virtual ~IPDF_CryptoHandler(); + + virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict, + IPDF_SecurityHandler* pSecurityHandler) = 0; + + virtual FX_DWORD DecryptGetSize(FX_DWORD src_size) = 0; + virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) = 0; + virtual FX_BOOL DecryptStream(void* context, + const uint8_t* src_buf, + FX_DWORD src_size, + CFX_BinaryBuf& dest_buf) = 0; + + virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest_buf) = 0; + virtual FX_DWORD EncryptGetSize(FX_DWORD objnum, + FX_DWORD version, + const uint8_t* src_buf, + FX_DWORD src_size) = 0; + + virtual FX_BOOL EncryptContent(FX_DWORD objnum, + FX_DWORD version, + const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t* dest_buf, + FX_DWORD& dest_size) = 0; + + void Decrypt(FX_DWORD objnum, FX_DWORD version, CFX_ByteString& str); +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_IPDF_CRYPTO_HANDLER_H_ diff --git a/core/fpdfapi/fpdf_parser/ipdf_occontext.cpp b/core/fpdfapi/fpdf_parser/ipdf_occontext.cpp new file mode 100644 index 0000000000..56a2412d9a --- /dev/null +++ b/core/fpdfapi/fpdf_parser/ipdf_occontext.cpp @@ -0,0 +1,25 @@ +// 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/fpdfapi/fpdf_parser/ipdf_occontext.h" + +#include "core/include/fpdfapi/fpdf_pageobj.h" + +IPDF_OCContext::~IPDF_OCContext() {} + +FX_BOOL IPDF_OCContext::CheckObjectVisible(const CPDF_PageObject* pObj) { + const CPDF_ContentMarkData* pData = pObj->m_ContentMark; + int nItems = pData->CountItems(); + for (int i = 0; i < nItems; i++) { + const CPDF_ContentMarkItem& item = pData->GetItem(i); + if (item.GetName() == "OC" && + item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict && + !CheckOCGVisible(item.GetParam())) { + return FALSE; + } + } + return TRUE; +} diff --git a/core/fpdfapi/fpdf_parser/ipdf_occontext.h b/core/fpdfapi/fpdf_parser/ipdf_occontext.h new file mode 100644 index 0000000000..6c410037e2 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/ipdf_occontext.h @@ -0,0 +1,23 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_IPDF_OCCONTEXT_H_ +#define CORE_FPDFAPI_FPDF_PARSER_IPDF_OCCONTEXT_H_ + +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Dictionary; +class CPDF_PageObject; + +class IPDF_OCContext { + public: + virtual ~IPDF_OCContext(); + + virtual FX_BOOL CheckOCGVisible(const CPDF_Dictionary* pOCG) = 0; + FX_BOOL CheckObjectVisible(const CPDF_PageObject* pObj); +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_IPDF_OCCONTEXT_H_ diff --git a/core/fpdfapi/fpdf_parser/ipdf_security_handler.h b/core/fpdfapi/fpdf_parser/ipdf_security_handler.h new file mode 100644 index 0000000000..c73c4c5081 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/ipdf_security_handler.h @@ -0,0 +1,36 @@ +// 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 + +#ifndef CORE_FPDFAPI_FPDF_PARSER_IPDF_SECURITY_HANDLER_H_ +#define CORE_FPDFAPI_FPDF_PARSER_IPDF_SECURITY_HANDLER_H_ + +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Parser; +class CPDF_Dictionary; +class IPDF_CryptoHandler; + +#define FXCIPHER_NONE 0 +#define FXCIPHER_RC4 1 +#define FXCIPHER_AES 2 +#define FXCIPHER_AES2 3 + +class IPDF_SecurityHandler { + public: + virtual ~IPDF_SecurityHandler(); + virtual FX_BOOL OnInit(CPDF_Parser* pParser, + CPDF_Dictionary* pEncryptDict) = 0; + + virtual FX_DWORD GetPermissions() = 0; + virtual FX_BOOL GetCryptInfo(int& cipher, + const uint8_t*& buffer, + int& keylen) = 0; + + virtual FX_BOOL IsMetadataEncrypted() = 0; + virtual IPDF_CryptoHandler* CreateCryptoHandler() = 0; +}; + +#endif // CORE_FPDFAPI_FPDF_PARSER_IPDF_SECURITY_HANDLER_H_ |