aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-01-20 21:26:45 +0100
committerJay Berkenbilt <ejb@ql.org>2013-01-20 21:35:39 +0100
commitf81152311e5737e5e0de9dd9462311f306c6921b (patch)
treee015c0efd7022cc259e898255db872fa52b73ca1 /include
parent1d88955fa68fb7fb0fd2d705bc80655edb7a5972 (diff)
downloadqpdf-f81152311e5737e5e0de9dd9462311f306c6921b.tar.zst
Add QPDFObjectHandle::parseContentStream method
This method allows parsing of the PDF objects in a content stream or array of content streams.
Diffstat (limited to 'include')
-rw-r--r--include/qpdf/QPDFObjectHandle.hh25
-rw-r--r--include/qpdf/QPDFTokenizer.hh10
2 files changed, 34 insertions, 1 deletions
diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh
index 932a6678..c4a922d1 100644
--- a/include/qpdf/QPDFObjectHandle.hh
+++ b/include/qpdf/QPDFObjectHandle.hh
@@ -71,6 +71,21 @@ class QPDFObjectHandle
virtual void decryptString(std::string& val) = 0;
};
+ // This class is used by parseContentStream. Callers must
+ // instantiate a subclass of this with handlers defined to accept
+ // QPDFObjectHandles that are parsed from the stream.
+ class ParserCallbacks
+ {
+ public:
+ QPDF_DLL
+ virtual ~ParserCallbacks()
+ {
+ }
+ virtual void handleObject(QPDFObjectHandle) = 0;
+ virtual void handleEOF() = 0;
+ };
+
+
QPDF_DLL
QPDFObjectHandle();
QPDF_DLL
@@ -138,6 +153,11 @@ class QPDFObjectHandle
StringDecrypter* decrypter,
QPDF* context);
+ // Helpers for parsing content streams
+ QPDF_DLL
+ static void parseContentStream(QPDFObjectHandle stream_or_array,
+ ParserCallbacks* callbacks);
+
// Type-specific factories
QPDF_DLL
static QPDFObjectHandle newNull();
@@ -571,7 +591,10 @@ class QPDFObjectHandle
std::string const& object_description,
QPDFTokenizer& tokenizer, bool& empty,
StringDecrypter* decrypter, QPDF* context,
- bool in_array, bool in_dictionary);
+ bool in_array, bool in_dictionary,
+ bool content_stream);
+ static void parseContentStream_internal(
+ QPDFObjectHandle stream, ParserCallbacks* callbacks);
bool initialized;
diff --git a/include/qpdf/QPDFTokenizer.hh b/include/qpdf/QPDFTokenizer.hh
index 1835fcb1..081e12d3 100644
--- a/include/qpdf/QPDFTokenizer.hh
+++ b/include/qpdf/QPDFTokenizer.hh
@@ -18,6 +18,8 @@
class QPDFTokenizer
{
public:
+ // Token type tt_eof is only returned of allowEOF() is called on
+ // the tokenizer. tt_eof was introduced in QPDF version 4.1.
enum token_type_e
{
tt_bad,
@@ -34,6 +36,7 @@ class QPDFTokenizer
tt_null,
tt_bool,
tt_word,
+ tt_eof,
};
class Token
@@ -97,6 +100,12 @@ class QPDFTokenizer
QPDF_DLL
void allowPoundAnywhereInName();
+ // If called, treat EOF as a separate token type instead of an
+ // error. This was introduced in QPDF 4.1 to facilitate
+ // tokenizing content streams.
+ QPDF_DLL
+ void allowEOF();
+
// Mode of operation:
// Keep presenting characters and calling getToken() until
@@ -140,6 +149,7 @@ class QPDFTokenizer
st_literal, st_in_hexstring, st_token_ready } state;
bool pound_special_in_name;
+ bool allow_eof;
// Current token accumulation
token_type_e type;