From 8d42eb2632ca5c2ae1200160e78116505b57f6b0 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 14 May 2022 08:49:42 -0400 Subject: Add scaffolding for QPDF JSON reactor --- include/qpdf/QPDF.hh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 5cba93a8..61efa4ed 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -115,22 +115,18 @@ class QPDF // complete representation of a PDF. See "QPDF JSON Format" in the // manual for details. QPDF_DLL - void - createFromJSON(std::string const& json_file); + void createFromJSON(std::string const& json_file); QPDF_DLL - void - createFromJSON(std::shared_ptr); + void createFromJSON(std::shared_ptr); // Update a PDF from an input source that contains JSON in the // same format as is written by qpdf --json (version 2 or higher). // Objects in the PDF and not in the JSON are not modified. See // "QPDF JSON Format" in the manual for details. QPDF_DLL - void - updateFromJSON(std::string const& json_file); + void updateFromJSON(std::string const& json_file); QPDF_DLL - void - updateFromJSON(std::shared_ptr); + void updateFromJSON(std::shared_ptr); // Close or otherwise release the input source. Once this has been // called, no other methods of qpdf can be called safely except @@ -999,6 +995,20 @@ class QPDF }; friend class ResolveRecorder; + class JSONReactor: public JSON::Reactor + { + public: + virtual ~JSONReactor() = default; + virtual void dictionaryStart() override; + virtual void arrayStart() override; + virtual void containerEnd(JSON const& value) override; + virtual void topLevelScalar() override; + virtual bool + dictionaryItem(std::string const& key, JSON const& value) override; + virtual bool arrayItem(JSON const& value) override; + }; + friend class JSONReactor; + void parse(char const* password); void inParse(bool); void setTrailer(QPDFObjectHandle obj); @@ -1508,6 +1518,9 @@ class QPDF int depth); void filterCompressedObjects(std::map const& object_stream_data); + // JSON import + void importJSON(std::shared_ptr, bool must_be_complete); + // Type conversion helper methods template static qpdf_offset_t -- cgit v1.2.3-54-g00ecf