Commit c40f8b5329a645bd7ec2202af3433d11e6eae1d8

Authored by Jay Berkenbilt
1 parent cce715cd

Make object types available to C API

ChangeLog
1 2021-12-17 Jay Berkenbilt <ejb@ql.org> 1 2021-12-17 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * QPDFObjectHandle object types have been moved from
  4 + QPDFObject::object_type_e to qpdf_object_type_e (defined in
  5 + Constants.h). Old values are available for backward compatibility.
  6 +
3 * Add Pl_Buffer::getMallocBuffer() to initialize a buffer with 7 * Add Pl_Buffer::getMallocBuffer() to initialize a buffer with
4 malloc in support of the C API 8 malloc in support of the C API
5 9
include/qpdf/Constants.h
@@ -41,6 +41,34 @@ enum qpdf_error_code_e @@ -41,6 +41,34 @@ enum qpdf_error_code_e
41 qpdf_e_object, /* type/bounds errors accessing objects */ 41 qpdf_e_object, /* type/bounds errors accessing objects */
42 }; 42 };
43 43
  44 +/* Object Types */
  45 +
  46 +/* PDF objects represented by QPDFObjectHandle or, in the C API, by
  47 + * qpdf_oh, have a unique type code that has one of the values in the
  48 + * list below. As new object types are added to qpdf, additional items
  49 + * may be added to the list, so code that switches on these values
  50 + * should take that into consideration.
  51 + */
  52 +enum qpdf_object_type_e {
  53 + /* Object types internal to qpdf */
  54 + qpdf_ot_uninitialized,
  55 + qpdf_ot_reserved,
  56 + /* Object types that can occur in the main document */
  57 + qpdf_ot_null,
  58 + qpdf_ot_boolean,
  59 + qpdf_ot_integer,
  60 + qpdf_ot_real,
  61 + qpdf_ot_string,
  62 + qpdf_ot_name,
  63 + qpdf_ot_array,
  64 + qpdf_ot_dictionary,
  65 + qpdf_ot_stream,
  66 + /* Additional object types that can occur in content streams */
  67 + qpdf_ot_operator,
  68 + qpdf_ot_inlineimage,
  69 + /* NOTE: if adding to this list, update QPDFObject.hh */
  70 +};
  71 +
44 /* Write Parameters. See QPDFWriter.hh for details. */ 72 /* Write Parameters. See QPDFWriter.hh for details. */
45 73
46 enum qpdf_object_stream_e 74 enum qpdf_object_stream_e
include/qpdf/QPDFObject.hh
@@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 #include <qpdf/Types.h> 26 #include <qpdf/Types.h>
27 #include <qpdf/JSON.hh> 27 #include <qpdf/JSON.hh>
  28 +#include <qpdf/Constants.h>
28 29
29 #include <string> 30 #include <string>
30 31
@@ -37,29 +38,29 @@ class QPDF_DLL_CLASS QPDFObject @@ -37,29 +38,29 @@ class QPDF_DLL_CLASS QPDFObject
37 QPDFObject(); 38 QPDFObject();
38 39
39 // Objects derived from QPDFObject are accessible through 40 // Objects derived from QPDFObject are accessible through
40 - // QPDFObjectHandle. Each object returns a unique type code that  
41 - // has one of the values in the list below. As new object types  
42 - // are added to qpdf, additional items may be added to the list,  
43 - // so code that switches on these values should take that into  
44 - // consideration.  
45 - enum object_type_e {  
46 - // Object types internal to qpdf  
47 - ot_uninitialized,  
48 - ot_reserved,  
49 - // Object types that can occur in the main document  
50 - ot_null,  
51 - ot_boolean,  
52 - ot_integer,  
53 - ot_real,  
54 - ot_string,  
55 - ot_name,  
56 - ot_array,  
57 - ot_dictionary,  
58 - ot_stream,  
59 - // Additional object types that can occur in content streams  
60 - ot_operator,  
61 - ot_inlineimage,  
62 - }; 41 + // QPDFObjectHandle. Each object returns a unique type code that
  42 + // has one of the valid qpdf_object_type_e values. As new object
  43 + // types are added to qpdf, additional items may be added to the
  44 + // list, so code that switches on these values should take that
  45 + // into consideration.
  46 +
  47 + // Prior to qpdf 10.5, qpdf_object_type_e was
  48 + // QPDFObject::object_type_e but was moved to make it accessible
  49 + // to the C API. The code below is for backward compatibility.
  50 + typedef enum qpdf_object_type_e object_type_e;
  51 + static constexpr object_type_e ot_uninitialized = ::qpdf_ot_uninitialized;
  52 + static constexpr object_type_e ot_reserved = ::qpdf_ot_reserved;
  53 + static constexpr object_type_e ot_null = ::qpdf_ot_null;
  54 + static constexpr object_type_e ot_boolean = ::qpdf_ot_boolean;
  55 + static constexpr object_type_e ot_integer = ::qpdf_ot_integer;
  56 + static constexpr object_type_e ot_real = ::qpdf_ot_real;
  57 + static constexpr object_type_e ot_string = ::qpdf_ot_string;
  58 + static constexpr object_type_e ot_name = ::qpdf_ot_name;
  59 + static constexpr object_type_e ot_array = ::qpdf_ot_array;
  60 + static constexpr object_type_e ot_dictionary = ::qpdf_ot_dictionary;
  61 + static constexpr object_type_e ot_stream = ::qpdf_ot_stream;
  62 + static constexpr object_type_e ot_operator = ::qpdf_ot_operator;
  63 + static constexpr object_type_e ot_inlineimage = ::qpdf_ot_inlineimage;
63 64
64 virtual ~QPDFObject() {} 65 virtual ~QPDFObject() {}
65 virtual std::string unparse() = 0; 66 virtual std::string unparse() = 0;