diff --git a/ChangeLog b/ChangeLog index fd078f98..e4919ca6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-01-20 Jay Berkenbilt + + * Added QPDF_Keyword and QPDF_InlineImage types along with + appropriate wrapper methods in QPDFObjectHandle. These new object + types are to facilitate content stream parsing. + 2013-01-17 Jay Berkenbilt * 4.0.1: release diff --git a/TODO b/TODO index ec797aaf..9ac85911 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,9 @@ +4.1.0 +===== + + * New public interfaces have been added. + + General ======= diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 75912e79..932a6678 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -76,7 +76,8 @@ class QPDFObjectHandle QPDF_DLL bool isInitialized() const; - // Exactly one of these will return true for any object. + // Exactly one of these will return true for any object. Keyword + // and InlineImage are only allowed in content streams. QPDF_DLL bool isBool(); QPDF_DLL @@ -90,6 +91,10 @@ class QPDFObjectHandle QPDF_DLL bool isString(); QPDF_DLL + bool isKeyword(); + QPDF_DLL + bool isInlineImage(); + QPDF_DLL bool isArray(); QPDF_DLL bool isDictionary(); @@ -103,7 +108,8 @@ class QPDFObjectHandle QPDF_DLL bool isIndirect(); - // True for everything except array, dictionary, and stream + // True for everything except array, dictionary, stream, word, and + // inline image. QPDF_DLL bool isScalar(); @@ -148,6 +154,10 @@ class QPDFObjectHandle QPDF_DLL static QPDFObjectHandle newString(std::string const& str); QPDF_DLL + static QPDFObjectHandle newKeyword(std::string const&); + QPDF_DLL + static QPDFObjectHandle newInlineImage(std::string const&); + QPDF_DLL static QPDFObjectHandle newArray(); QPDF_DLL static QPDFObjectHandle newArray( @@ -239,6 +249,12 @@ class QPDFObjectHandle QPDF_DLL std::string getUTF8Value(); + // Methods for content stream objects + QPDF_DLL + std::string getKeywordValue(); + QPDF_DLL + std::string getInlineImageValue(); + // Methods for array objects; see also name and array objects QPDF_DLL int getArrayNItems(); @@ -510,6 +526,10 @@ class QPDFObjectHandle QPDF_DLL void assertString(); QPDF_DLL + void assertKeyword(); + QPDF_DLL + void assertInlineImage(); + QPDF_DLL void assertArray(); QPDF_DLL void assertDictionary(); diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 54897b83..9b51a0cb 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -151,6 +153,20 @@ QPDFObjectHandle::isString() return QPDFObjectTypeAccessor::check(obj.getPointer()); } +bool +QPDFObjectHandle::isKeyword() +{ + dereference(); + return QPDFObjectTypeAccessor::check(obj.getPointer()); +} + +bool +QPDFObjectHandle::isInlineImage() +{ + dereference(); + return QPDFObjectTypeAccessor::check(obj.getPointer()); +} + bool QPDFObjectHandle::isArray() { @@ -190,7 +206,8 @@ QPDFObjectHandle::isIndirect() bool QPDFObjectHandle::isScalar() { - return (! (isArray() || isDictionary() || isStream())); + return (! (isArray() || isDictionary() || isStream() || + isKeyword() || isInlineImage())); } // Bool accessors @@ -245,6 +262,22 @@ QPDFObjectHandle::getUTF8Value() return dynamic_cast(obj.getPointer())->getUTF8Val(); } +// Keyword and Inline Image accessors + +std::string +QPDFObjectHandle::getKeywordValue() +{ + assertKeyword(); + return dynamic_cast(obj.getPointer())->getVal(); +} + +std::string +QPDFObjectHandle::getInlineImageValue() +{ + assertInlineImage(); + return dynamic_cast(obj.getPointer())->getVal(); +} + // Array accessors int @@ -928,6 +961,18 @@ QPDFObjectHandle::newString(std::string const& str) return QPDFObjectHandle(new QPDF_String(str)); } +QPDFObjectHandle +QPDFObjectHandle::newKeyword(std::string const& value) +{ + return QPDFObjectHandle(new QPDF_Keyword(value)); +} + +QPDFObjectHandle +QPDFObjectHandle::newInlineImage(std::string const& value) +{ + return QPDFObjectHandle(new QPDF_InlineImage(value)); +} + QPDFObjectHandle QPDFObjectHandle::newArray() { @@ -1212,6 +1257,18 @@ QPDFObjectHandle::assertString() assertType("String", isString()); } +void +QPDFObjectHandle::assertKeyword() +{ + assertType("Keyword", isKeyword()); +} + +void +QPDFObjectHandle::assertInlineImage() +{ + assertType("InlineImage", isInlineImage()); +} + void QPDFObjectHandle::assertArray() { diff --git a/libqpdf/QPDF_InlineImage.cc b/libqpdf/QPDF_InlineImage.cc new file mode 100644 index 00000000..e42ddbf2 --- /dev/null +++ b/libqpdf/QPDF_InlineImage.cc @@ -0,0 +1,24 @@ +#include + +#include + +QPDF_InlineImage::QPDF_InlineImage(std::string const& val) : + val(val) +{ +} + +QPDF_InlineImage::~QPDF_InlineImage() +{ +} + +std::string +QPDF_InlineImage::unparse() +{ + return this->val; +} + +std::string +QPDF_InlineImage::getVal() const +{ + return this->val; +} diff --git a/libqpdf/QPDF_Keyword.cc b/libqpdf/QPDF_Keyword.cc new file mode 100644 index 00000000..e2537842 --- /dev/null +++ b/libqpdf/QPDF_Keyword.cc @@ -0,0 +1,24 @@ +#include + +#include + +QPDF_Keyword::QPDF_Keyword(std::string const& val) : + val(val) +{ +} + +QPDF_Keyword::~QPDF_Keyword() +{ +} + +std::string +QPDF_Keyword::unparse() +{ + return this->val; +} + +std::string +QPDF_Keyword::getVal() const +{ + return this->val; +} diff --git a/libqpdf/build.mk b/libqpdf/build.mk index a12a0b2c..0b248a91 100644 --- a/libqpdf/build.mk +++ b/libqpdf/build.mk @@ -40,8 +40,10 @@ SRCS_libqpdf = \ libqpdf/QPDF_Array.cc \ libqpdf/QPDF_Bool.cc \ libqpdf/QPDF_Dictionary.cc \ + libqpdf/QPDF_InlineImage.cc \ libqpdf/QPDF_Integer.cc \ libqpdf/QPDF_Name.cc \ + libqpdf/QPDF_Keyword.cc \ libqpdf/QPDF_Null.cc \ libqpdf/QPDF_Real.cc \ libqpdf/QPDF_Reserved.cc \ diff --git a/libqpdf/qpdf/QPDF_InlineImage.hh b/libqpdf/qpdf/QPDF_InlineImage.hh new file mode 100644 index 00000000..6408a2f1 --- /dev/null +++ b/libqpdf/qpdf/QPDF_InlineImage.hh @@ -0,0 +1,18 @@ +#ifndef __QPDF_INLINEIMAGE_HH__ +#define __QPDF_INLINEIMAGE_HH__ + +#include + +class QPDF_InlineImage: public QPDFObject +{ + public: + QPDF_InlineImage(std::string const& val); + virtual ~QPDF_InlineImage(); + virtual std::string unparse(); + std::string getVal() const; + + private: + std::string val; +}; + +#endif // __QPDF_INLINEIMAGE_HH__ diff --git a/libqpdf/qpdf/QPDF_Keyword.hh b/libqpdf/qpdf/QPDF_Keyword.hh new file mode 100644 index 00000000..1a5c0ee6 --- /dev/null +++ b/libqpdf/qpdf/QPDF_Keyword.hh @@ -0,0 +1,18 @@ +#ifndef __QPDF_KEYWORD_HH__ +#define __QPDF_KEYWORD_HH__ + +#include + +class QPDF_Keyword: public QPDFObject +{ + public: + QPDF_Keyword(std::string const& val); + virtual ~QPDF_Keyword(); + virtual std::string unparse(); + std::string getVal() const; + + private: + std::string val; +}; + +#endif // __QPDF_KEYWORD_HH__