Commit 1d88955fa68fb7fb0fd2d705bc80655edb7a5972

Authored by Jay Berkenbilt
1 parent a844c2a3

Added new QPDFObjectHandle types Keyword and InlineImage

These object types are to facilitate content stream parsing.
ChangeLog
  1 +2013-01-20 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * Added QPDF_Keyword and QPDF_InlineImage types along with
  4 + appropriate wrapper methods in QPDFObjectHandle. These new object
  5 + types are to facilitate content stream parsing.
  6 +
1 2013-01-17 Jay Berkenbilt <ejb@ql.org> 7 2013-01-17 Jay Berkenbilt <ejb@ql.org>
2 8
3 * 4.0.1: release 9 * 4.0.1: release
  1 +4.1.0
  2 +=====
  3 +
  4 + * New public interfaces have been added.
  5 +
  6 +
1 General 7 General
2 ======= 8 =======
3 9
include/qpdf/QPDFObjectHandle.hh
@@ -76,7 +76,8 @@ class QPDFObjectHandle @@ -76,7 +76,8 @@ class QPDFObjectHandle
76 QPDF_DLL 76 QPDF_DLL
77 bool isInitialized() const; 77 bool isInitialized() const;
78 78
79 - // Exactly one of these will return true for any object. 79 + // Exactly one of these will return true for any object. Keyword
  80 + // and InlineImage are only allowed in content streams.
80 QPDF_DLL 81 QPDF_DLL
81 bool isBool(); 82 bool isBool();
82 QPDF_DLL 83 QPDF_DLL
@@ -90,6 +91,10 @@ class QPDFObjectHandle @@ -90,6 +91,10 @@ class QPDFObjectHandle
90 QPDF_DLL 91 QPDF_DLL
91 bool isString(); 92 bool isString();
92 QPDF_DLL 93 QPDF_DLL
  94 + bool isKeyword();
  95 + QPDF_DLL
  96 + bool isInlineImage();
  97 + QPDF_DLL
93 bool isArray(); 98 bool isArray();
94 QPDF_DLL 99 QPDF_DLL
95 bool isDictionary(); 100 bool isDictionary();
@@ -103,7 +108,8 @@ class QPDFObjectHandle @@ -103,7 +108,8 @@ class QPDFObjectHandle
103 QPDF_DLL 108 QPDF_DLL
104 bool isIndirect(); 109 bool isIndirect();
105 110
106 - // True for everything except array, dictionary, and stream 111 + // True for everything except array, dictionary, stream, word, and
  112 + // inline image.
107 QPDF_DLL 113 QPDF_DLL
108 bool isScalar(); 114 bool isScalar();
109 115
@@ -148,6 +154,10 @@ class QPDFObjectHandle @@ -148,6 +154,10 @@ class QPDFObjectHandle
148 QPDF_DLL 154 QPDF_DLL
149 static QPDFObjectHandle newString(std::string const& str); 155 static QPDFObjectHandle newString(std::string const& str);
150 QPDF_DLL 156 QPDF_DLL
  157 + static QPDFObjectHandle newKeyword(std::string const&);
  158 + QPDF_DLL
  159 + static QPDFObjectHandle newInlineImage(std::string const&);
  160 + QPDF_DLL
151 static QPDFObjectHandle newArray(); 161 static QPDFObjectHandle newArray();
152 QPDF_DLL 162 QPDF_DLL
153 static QPDFObjectHandle newArray( 163 static QPDFObjectHandle newArray(
@@ -239,6 +249,12 @@ class QPDFObjectHandle @@ -239,6 +249,12 @@ class QPDFObjectHandle
239 QPDF_DLL 249 QPDF_DLL
240 std::string getUTF8Value(); 250 std::string getUTF8Value();
241 251
  252 + // Methods for content stream objects
  253 + QPDF_DLL
  254 + std::string getKeywordValue();
  255 + QPDF_DLL
  256 + std::string getInlineImageValue();
  257 +
242 // Methods for array objects; see also name and array objects 258 // Methods for array objects; see also name and array objects
243 QPDF_DLL 259 QPDF_DLL
244 int getArrayNItems(); 260 int getArrayNItems();
@@ -510,6 +526,10 @@ class QPDFObjectHandle @@ -510,6 +526,10 @@ class QPDFObjectHandle
510 QPDF_DLL 526 QPDF_DLL
511 void assertString(); 527 void assertString();
512 QPDF_DLL 528 QPDF_DLL
  529 + void assertKeyword();
  530 + QPDF_DLL
  531 + void assertInlineImage();
  532 + QPDF_DLL
513 void assertArray(); 533 void assertArray();
514 QPDF_DLL 534 QPDF_DLL
515 void assertDictionary(); 535 void assertDictionary();
libqpdf/QPDFObjectHandle.cc
@@ -7,6 +7,8 @@ @@ -7,6 +7,8 @@
7 #include <qpdf/QPDF_Real.hh> 7 #include <qpdf/QPDF_Real.hh>
8 #include <qpdf/QPDF_Name.hh> 8 #include <qpdf/QPDF_Name.hh>
9 #include <qpdf/QPDF_String.hh> 9 #include <qpdf/QPDF_String.hh>
  10 +#include <qpdf/QPDF_Keyword.hh>
  11 +#include <qpdf/QPDF_InlineImage.hh>
10 #include <qpdf/QPDF_Array.hh> 12 #include <qpdf/QPDF_Array.hh>
11 #include <qpdf/QPDF_Dictionary.hh> 13 #include <qpdf/QPDF_Dictionary.hh>
12 #include <qpdf/QPDF_Stream.hh> 14 #include <qpdf/QPDF_Stream.hh>
@@ -152,6 +154,20 @@ QPDFObjectHandle::isString() @@ -152,6 +154,20 @@ QPDFObjectHandle::isString()
152 } 154 }
153 155
154 bool 156 bool
  157 +QPDFObjectHandle::isKeyword()
  158 +{
  159 + dereference();
  160 + return QPDFObjectTypeAccessor<QPDF_Keyword>::check(obj.getPointer());
  161 +}
  162 +
  163 +bool
  164 +QPDFObjectHandle::isInlineImage()
  165 +{
  166 + dereference();
  167 + return QPDFObjectTypeAccessor<QPDF_InlineImage>::check(obj.getPointer());
  168 +}
  169 +
  170 +bool
155 QPDFObjectHandle::isArray() 171 QPDFObjectHandle::isArray()
156 { 172 {
157 dereference(); 173 dereference();
@@ -190,7 +206,8 @@ QPDFObjectHandle::isIndirect() @@ -190,7 +206,8 @@ QPDFObjectHandle::isIndirect()
190 bool 206 bool
191 QPDFObjectHandle::isScalar() 207 QPDFObjectHandle::isScalar()
192 { 208 {
193 - return (! (isArray() || isDictionary() || isStream())); 209 + return (! (isArray() || isDictionary() || isStream() ||
  210 + isKeyword() || isInlineImage()));
194 } 211 }
195 212
196 // Bool accessors 213 // Bool accessors
@@ -245,6 +262,22 @@ QPDFObjectHandle::getUTF8Value() @@ -245,6 +262,22 @@ QPDFObjectHandle::getUTF8Value()
245 return dynamic_cast<QPDF_String*>(obj.getPointer())->getUTF8Val(); 262 return dynamic_cast<QPDF_String*>(obj.getPointer())->getUTF8Val();
246 } 263 }
247 264
  265 +// Keyword and Inline Image accessors
  266 +
  267 +std::string
  268 +QPDFObjectHandle::getKeywordValue()
  269 +{
  270 + assertKeyword();
  271 + return dynamic_cast<QPDF_Keyword*>(obj.getPointer())->getVal();
  272 +}
  273 +
  274 +std::string
  275 +QPDFObjectHandle::getInlineImageValue()
  276 +{
  277 + assertInlineImage();
  278 + return dynamic_cast<QPDF_InlineImage*>(obj.getPointer())->getVal();
  279 +}
  280 +
248 // Array accessors 281 // Array accessors
249 282
250 int 283 int
@@ -929,6 +962,18 @@ QPDFObjectHandle::newString(std::string const&amp; str) @@ -929,6 +962,18 @@ QPDFObjectHandle::newString(std::string const&amp; str)
929 } 962 }
930 963
931 QPDFObjectHandle 964 QPDFObjectHandle
  965 +QPDFObjectHandle::newKeyword(std::string const& value)
  966 +{
  967 + return QPDFObjectHandle(new QPDF_Keyword(value));
  968 +}
  969 +
  970 +QPDFObjectHandle
  971 +QPDFObjectHandle::newInlineImage(std::string const& value)
  972 +{
  973 + return QPDFObjectHandle(new QPDF_InlineImage(value));
  974 +}
  975 +
  976 +QPDFObjectHandle
932 QPDFObjectHandle::newArray() 977 QPDFObjectHandle::newArray()
933 { 978 {
934 return newArray(std::vector<QPDFObjectHandle>()); 979 return newArray(std::vector<QPDFObjectHandle>());
@@ -1213,6 +1258,18 @@ QPDFObjectHandle::assertString() @@ -1213,6 +1258,18 @@ QPDFObjectHandle::assertString()
1213 } 1258 }
1214 1259
1215 void 1260 void
  1261 +QPDFObjectHandle::assertKeyword()
  1262 +{
  1263 + assertType("Keyword", isKeyword());
  1264 +}
  1265 +
  1266 +void
  1267 +QPDFObjectHandle::assertInlineImage()
  1268 +{
  1269 + assertType("InlineImage", isInlineImage());
  1270 +}
  1271 +
  1272 +void
1216 QPDFObjectHandle::assertArray() 1273 QPDFObjectHandle::assertArray()
1217 { 1274 {
1218 assertType("Array", isArray()); 1275 assertType("Array", isArray());
libqpdf/QPDF_InlineImage.cc 0 โ†’ 100644
  1 +#include <qpdf/QPDF_InlineImage.hh>
  2 +
  3 +#include <qpdf/QUtil.hh>
  4 +
  5 +QPDF_InlineImage::QPDF_InlineImage(std::string const& val) :
  6 + val(val)
  7 +{
  8 +}
  9 +
  10 +QPDF_InlineImage::~QPDF_InlineImage()
  11 +{
  12 +}
  13 +
  14 +std::string
  15 +QPDF_InlineImage::unparse()
  16 +{
  17 + return this->val;
  18 +}
  19 +
  20 +std::string
  21 +QPDF_InlineImage::getVal() const
  22 +{
  23 + return this->val;
  24 +}
libqpdf/QPDF_Keyword.cc 0 โ†’ 100644
  1 +#include <qpdf/QPDF_Keyword.hh>
  2 +
  3 +#include <qpdf/QUtil.hh>
  4 +
  5 +QPDF_Keyword::QPDF_Keyword(std::string const& val) :
  6 + val(val)
  7 +{
  8 +}
  9 +
  10 +QPDF_Keyword::~QPDF_Keyword()
  11 +{
  12 +}
  13 +
  14 +std::string
  15 +QPDF_Keyword::unparse()
  16 +{
  17 + return this->val;
  18 +}
  19 +
  20 +std::string
  21 +QPDF_Keyword::getVal() const
  22 +{
  23 + return this->val;
  24 +}
libqpdf/build.mk
@@ -40,8 +40,10 @@ SRCS_libqpdf = \ @@ -40,8 +40,10 @@ SRCS_libqpdf = \
40 libqpdf/QPDF_Array.cc \ 40 libqpdf/QPDF_Array.cc \
41 libqpdf/QPDF_Bool.cc \ 41 libqpdf/QPDF_Bool.cc \
42 libqpdf/QPDF_Dictionary.cc \ 42 libqpdf/QPDF_Dictionary.cc \
  43 + libqpdf/QPDF_InlineImage.cc \
43 libqpdf/QPDF_Integer.cc \ 44 libqpdf/QPDF_Integer.cc \
44 libqpdf/QPDF_Name.cc \ 45 libqpdf/QPDF_Name.cc \
  46 + libqpdf/QPDF_Keyword.cc \
45 libqpdf/QPDF_Null.cc \ 47 libqpdf/QPDF_Null.cc \
46 libqpdf/QPDF_Real.cc \ 48 libqpdf/QPDF_Real.cc \
47 libqpdf/QPDF_Reserved.cc \ 49 libqpdf/QPDF_Reserved.cc \
libqpdf/qpdf/QPDF_InlineImage.hh 0 โ†’ 100644
  1 +#ifndef __QPDF_INLINEIMAGE_HH__
  2 +#define __QPDF_INLINEIMAGE_HH__
  3 +
  4 +#include <qpdf/QPDFObject.hh>
  5 +
  6 +class QPDF_InlineImage: public QPDFObject
  7 +{
  8 + public:
  9 + QPDF_InlineImage(std::string const& val);
  10 + virtual ~QPDF_InlineImage();
  11 + virtual std::string unparse();
  12 + std::string getVal() const;
  13 +
  14 + private:
  15 + std::string val;
  16 +};
  17 +
  18 +#endif // __QPDF_INLINEIMAGE_HH__
libqpdf/qpdf/QPDF_Keyword.hh 0 โ†’ 100644
  1 +#ifndef __QPDF_KEYWORD_HH__
  2 +#define __QPDF_KEYWORD_HH__
  3 +
  4 +#include <qpdf/QPDFObject.hh>
  5 +
  6 +class QPDF_Keyword: public QPDFObject
  7 +{
  8 + public:
  9 + QPDF_Keyword(std::string const& val);
  10 + virtual ~QPDF_Keyword();
  11 + virtual std::string unparse();
  12 + std::string getVal() const;
  13 +
  14 + private:
  15 + std::string val;
  16 +};
  17 +
  18 +#endif // __QPDF_KEYWORD_HH__