diff options
-rw-r--r-- | include/qpdf/QPDF.hh | 29 | ||||
-rw-r--r-- | libqpdf/QPDF_json.cc | 50 |
2 files changed, 68 insertions, 11 deletions
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<InputSource>); + void createFromJSON(std::shared_ptr<InputSource>); // 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<InputSource>); + void updateFromJSON(std::shared_ptr<InputSource>); // 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<int, int> const& object_stream_data); + // JSON import + void importJSON(std::shared_ptr<InputSource>, bool must_be_complete); + // Type conversion helper methods template <typename T> static qpdf_offset_t diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 908615b6..316c9935 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -3,15 +3,53 @@ #include <qpdf/FileInputSource.hh> void +QPDF::JSONReactor::dictionaryStart() +{ + // QXXXXQ +} + +void +QPDF::JSONReactor::arrayStart() +{ + // QXXXXQ +} + +void +QPDF::JSONReactor::containerEnd(JSON const& value) +{ + // QXXXXQ +} + +void +QPDF::JSONReactor::topLevelScalar() +{ + // QXXXXQ +} + +bool +QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) +{ + // QXXXXQ + return true; +} + +bool +QPDF::JSONReactor::arrayItem(JSON const& value) +{ + // QXXXXQ + return true; +} + +void QPDF::createFromJSON(std::string const& json_file) { createFromJSON(std::make_shared<FileInputSource>(json_file.c_str())); } void -QPDF::createFromJSON(std::shared_ptr<InputSource>) +QPDF::createFromJSON(std::shared_ptr<InputSource> is) { - // QXXXQ + importJSON(is, true); } void @@ -21,7 +59,13 @@ QPDF::updateFromJSON(std::string const& json_file) } void -QPDF::updateFromJSON(std::shared_ptr<InputSource>) +QPDF::updateFromJSON(std::shared_ptr<InputSource> is) +{ + importJSON(is, false); +} + +void +QPDF::importJSON(std::shared_ptr<InputSource>, bool must_be_complete) { // QXXXQ } |