From e2737ab646bff6aa07ba72e0cc15cc955d9afcc0 Mon Sep 17 00:00:00 2001 From: m-holger Date: Fri, 9 Feb 2024 13:09:08 +0000 Subject: [PATCH] Add new writeJSON methods Create an alternative to getJSON to allow an object handle to be written as JSON without the overhead of creating a JSON object. --- include/qpdf/QPDFObjectHandle.hh | 2 ++ libqpdf/QPDFObjectHandle.cc | 13 ++++++++++ libqpdf/QPDF_Array.cc | 38 ++++++++++++++++++++++++++++++ libqpdf/QPDF_Bool.cc | 8 +++++++ libqpdf/QPDF_Destroyed.cc | 6 +++++ libqpdf/QPDF_Dictionary.cc | 28 ++++++++++++++++++++++ libqpdf/QPDF_InlineImage.cc | 8 +++++++ libqpdf/QPDF_Integer.cc | 7 ++++++ libqpdf/QPDF_Name.cc | 19 +++++++++++++++ libqpdf/QPDF_Null.cc | 7 ++++++ libqpdf/QPDF_Operator.cc | 8 +++++++ libqpdf/QPDF_Real.cc | 16 +++++++++++++ libqpdf/QPDF_Reserved.cc | 6 +++++ libqpdf/QPDF_Stream.cc | 7 ++++++ libqpdf/QPDF_String.cc | 25 ++++++++++++++++++++ libqpdf/QPDF_Unresolved.cc | 6 +++++ libqpdf/QPDF_json.cc | 13 +++++++--- libqpdf/qpdf/QPDFObject_private.hh | 5 ++++ libqpdf/qpdf/QPDFValue.hh | 1 + libqpdf/qpdf/QPDF_Array.hh | 1 + libqpdf/qpdf/QPDF_Bool.hh | 2 ++ libqpdf/qpdf/QPDF_Destroyed.hh | 1 + libqpdf/qpdf/QPDF_Dictionary.hh | 1 + libqpdf/qpdf/QPDF_InlineImage.hh | 1 + libqpdf/qpdf/QPDF_Integer.hh | 1 + libqpdf/qpdf/QPDF_Name.hh | 1 + libqpdf/qpdf/QPDF_Null.hh | 1 + libqpdf/qpdf/QPDF_Operator.hh | 1 + libqpdf/qpdf/QPDF_Real.hh | 1 + libqpdf/qpdf/QPDF_Reserved.hh | 1 + libqpdf/qpdf/QPDF_Stream.hh | 1 + libqpdf/qpdf/QPDF_String.hh | 1 + libqpdf/qpdf/QPDF_Unresolved.hh | 1 + 33 files changed, 235 insertions(+), 3 deletions(-) diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index b2835495..a965f468 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -1353,6 +1353,8 @@ class QPDFObjectHandle return obj.get(); } + void writeJSON(int json_version, JSON::Writer& p, bool dereference_indirect = false); + private: QPDF_Array* asArray(); QPDF_Bool* asBool(); diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index d543f98e..7af83a68 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -1621,6 +1622,18 @@ QPDFObjectHandle::getJSON(int json_version, bool dereference_indirect) } } +void +QPDFObjectHandle::writeJSON(int json_version, JSON::Writer& p, bool dereference_indirect) +{ + if (!dereference_indirect && isIndirect()) { + p << "\"" << getObjGen().unparse(' ') << " R\""; + } else if (!dereference()) { + throw std::logic_error("attempted to dereference an uninitialized QPDFObjectHandle"); + } else { + obj->writeJSON(json_version, p); + } +} + JSON QPDFObjectHandle::getStreamJSON( int json_version, diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 789acc35..6e50a781 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -180,6 +181,43 @@ QPDF_Array::getJSON(int json_version) return j_array; } +void +QPDF_Array::writeJSON(int json_version, JSON::Writer& p) +{ + p.writeStart('['); + if (sp) { + int next = 0; + for (auto& item: sp->elements) { + int key = item.first; + for (int j = next; j < key; ++j) { + p.writeNext() << "null"; + } + p.writeNext(); + auto og = item.second->getObjGen(); + if (og.isIndirect()) { + p << "\"" << og.unparse(' ') << " R\""; + } else { + item.second->writeJSON(json_version, p); + } + next = ++key; + } + for (int j = next; j < sp->size; ++j) { + p.writeNext() << "null"; + } + } else { + for (auto const& item: elements) { + p.writeNext(); + auto og = item->getObjGen(); + if (og.isIndirect()) { + p << "\"" << og.unparse(' ') << " R\""; + } else { + item->writeJSON(json_version, p); + } + } + } + p.writeEnd(']'); +} + QPDFObjectHandle QPDF_Array::at(int n) const noexcept { diff --git a/libqpdf/QPDF_Bool.cc b/libqpdf/QPDF_Bool.cc index 05c52f22..9e57e68e 100644 --- a/libqpdf/QPDF_Bool.cc +++ b/libqpdf/QPDF_Bool.cc @@ -1,5 +1,7 @@ #include +#include + QPDF_Bool::QPDF_Bool(bool val) : QPDFValue(::ot_boolean, "boolean"), val(val) @@ -30,6 +32,12 @@ QPDF_Bool::getJSON(int json_version) return JSON::makeBool(this->val); } +void +QPDF_Bool::writeJSON(int json_version, JSON::Writer& p) +{ + p << val; +} + bool QPDF_Bool::getVal() const { diff --git a/libqpdf/QPDF_Destroyed.cc b/libqpdf/QPDF_Destroyed.cc index 4e34b508..06d1a83c 100644 --- a/libqpdf/QPDF_Destroyed.cc +++ b/libqpdf/QPDF_Destroyed.cc @@ -34,3 +34,9 @@ QPDF_Destroyed::getJSON(int json_version) throw std::logic_error("attempted to get JSON from a QPDFObjectHandle from a destroyed QPDF"); return JSON::makeNull(); } + +void +QPDF_Destroyed::writeJSON(int json_version, JSON::Writer& p) +{ + throw std::logic_error("attempted to get JSON from a QPDFObjectHandle from a destroyed QPDF"); +} \ No newline at end of file diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index f7e32fc9..53d78a2b 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -91,6 +92,33 @@ QPDF_Dictionary::getJSON(int json_version) return j; } +void +QPDF_Dictionary::writeJSON(int json_version, JSON::Writer& p) +{ + p.writeStart('{'); + for (auto& iter: this->items) { + if (!iter.second.isNull()) { + p.writeNext(); + if (json_version == 1) { + p << "\"" << JSON::Writer::encode_string(QPDF_Name::normalizeName(iter.first)) << "\": "; + } else { + bool has_8bit_chars; + bool is_valid_utf8; + bool is_utf16; + QUtil::analyze_encoding(iter.first, has_8bit_chars, is_valid_utf8, is_utf16); + if (!has_8bit_chars || is_valid_utf8) { + p << "\"" << JSON::Writer::encode_string(iter.first) << "\": "; + } else { + p << "\"n:" << JSON::Writer::encode_string(QPDF_Name::normalizeName(iter.first)) + << "\": "; + } + } + iter.second.writeJSON(json_version, p); + } + } + p.writeEnd('}'); +} + bool QPDF_Dictionary::hasKey(std::string const& key) { diff --git a/libqpdf/QPDF_InlineImage.cc b/libqpdf/QPDF_InlineImage.cc index 18f2fed6..bb5c4d0f 100644 --- a/libqpdf/QPDF_InlineImage.cc +++ b/libqpdf/QPDF_InlineImage.cc @@ -1,5 +1,7 @@ #include +#include + QPDF_InlineImage::QPDF_InlineImage(std::string const& val) : QPDFValue(::ot_inlineimage, "inline-image"), val(val) @@ -29,3 +31,9 @@ QPDF_InlineImage::getJSON(int json_version) { return JSON::makeNull(); } + +void +QPDF_InlineImage::writeJSON(int json_version, JSON::Writer& p) +{ + p << "null"; +} diff --git a/libqpdf/QPDF_Integer.cc b/libqpdf/QPDF_Integer.cc index 716a11e0..d65b3478 100644 --- a/libqpdf/QPDF_Integer.cc +++ b/libqpdf/QPDF_Integer.cc @@ -1,5 +1,6 @@ #include +#include #include QPDF_Integer::QPDF_Integer(long long val) : @@ -32,6 +33,12 @@ QPDF_Integer::getJSON(int json_version) return JSON::makeInt(this->val); } +void +QPDF_Integer::writeJSON(int json_version, JSON::Writer& p) +{ + p << std::to_string(this->val); +} + long long QPDF_Integer::getVal() const { diff --git a/libqpdf/QPDF_Name.cc b/libqpdf/QPDF_Name.cc index 5fde9c65..458b1428 100644 --- a/libqpdf/QPDF_Name.cc +++ b/libqpdf/QPDF_Name.cc @@ -1,5 +1,6 @@ #include +#include #include QPDF_Name::QPDF_Name(std::string const& name) : @@ -68,3 +69,21 @@ QPDF_Name::getJSON(int json_version) } } } + +void +QPDF_Name::writeJSON(int json_version, JSON::Writer& p) +{ + if (json_version == 1) { + p << "\"" << JSON::Writer::encode_string(normalizeName(name)) << "\""; + } else { + bool has_8bit_chars; + bool is_valid_utf8; + bool is_utf16; + QUtil::analyze_encoding(this->name, has_8bit_chars, is_valid_utf8, is_utf16); + if (!has_8bit_chars || is_valid_utf8) { + p << "\"" << JSON::Writer::encode_string(name) << "\""; + } else { + p << "\"n:" << JSON::Writer::encode_string(normalizeName(name)) << "\""; + } + } +} diff --git a/libqpdf/QPDF_Null.cc b/libqpdf/QPDF_Null.cc index fdabdfa7..13118e8c 100644 --- a/libqpdf/QPDF_Null.cc +++ b/libqpdf/QPDF_Null.cc @@ -1,5 +1,6 @@ #include +#include #include QPDF_Null::QPDF_Null() : @@ -49,3 +50,9 @@ QPDF_Null::getJSON(int json_version) // If this is updated, QPDF_Array::getJSON must also be updated. return JSON::makeNull(); } + +void +QPDF_Null::writeJSON(int json_version, JSON::Writer& p) +{ + p << "null"; +} diff --git a/libqpdf/QPDF_Operator.cc b/libqpdf/QPDF_Operator.cc index d1b2969d..763c4f12 100644 --- a/libqpdf/QPDF_Operator.cc +++ b/libqpdf/QPDF_Operator.cc @@ -1,5 +1,7 @@ #include +#include + QPDF_Operator::QPDF_Operator(std::string const& val) : QPDFValue(::ot_operator, "operator"), val(val) @@ -29,3 +31,9 @@ QPDF_Operator::getJSON(int json_version) { return JSON::makeNull(); } + +void +QPDF_Operator::writeJSON(int json_version, JSON::Writer& p) +{ + p << "null"; +} diff --git a/libqpdf/QPDF_Real.cc b/libqpdf/QPDF_Real.cc index 1d954dcd..af96c9df 100644 --- a/libqpdf/QPDF_Real.cc +++ b/libqpdf/QPDF_Real.cc @@ -1,5 +1,6 @@ #include +#include #include QPDF_Real::QPDF_Real(std::string const& val) : @@ -56,3 +57,18 @@ QPDF_Real::getJSON(int json_version) } return JSON::makeNumber(result); } + +void +QPDF_Real::writeJSON(int json_version, JSON::Writer& p) +{ + if (this->val.length() == 0) { + // Can't really happen... + p << "0"; + } else if (this->val.at(0) == '.') { + p << "0" << this->val; + } else if (this->val.length() >= 2 && this->val.at(0) == '-' && this->val.at(1) == '.') { + p << "-0." << this->val.substr(2); + } else { + p << this->val; + } +} diff --git a/libqpdf/QPDF_Reserved.cc b/libqpdf/QPDF_Reserved.cc index 845d6ebc..0be60c98 100644 --- a/libqpdf/QPDF_Reserved.cc +++ b/libqpdf/QPDF_Reserved.cc @@ -32,3 +32,9 @@ QPDF_Reserved::getJSON(int json_version) throw std::logic_error("QPDFObjectHandle: attempting to get JSON from a reserved object"); return JSON::makeNull(); } + +void +QPDF_Reserved::writeJSON(int json_version, JSON::Writer& p) +{ + throw std::logic_error("QPDFObjectHandle: attempting to get JSON from a reserved object"); +} diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index a43d91ff..bedc96b2 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -185,6 +186,12 @@ QPDF_Stream::getJSON(int json_version) return getStreamJSON(json_version, qpdf_sj_none, qpdf_dl_none, nullptr, ""); } +void +QPDF_Stream::writeJSON(int json_version, JSON::Writer& p) +{ + stream_dict.writeJSON(json_version, p); +} + JSON QPDF_Stream::getStreamJSON( int json_version, diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc index 3886b399..d3fcaaef 100644 --- a/libqpdf/QPDF_String.cc +++ b/libqpdf/QPDF_String.cc @@ -1,5 +1,6 @@ #include +#include #include // DO NOT USE ctype -- it is locale dependent for some things, and it's not worth the risk of @@ -74,6 +75,30 @@ QPDF_String::getJSON(int json_version) return JSON::makeString(result); } +void +QPDF_String::writeJSON(int json_version, JSON::Writer& p) +{ + auto candidate = getUTF8Val(); + if (json_version == 1) { + + p << "\"" << JSON::Writer::encode_string(candidate) << "\""; + } else { + // See if we can unambiguously represent as Unicode. + if (QUtil::is_utf16(this->val) || QUtil::is_explicit_utf8(this->val)) { + p << "\"u:" << JSON::Writer::encode_string(candidate) <<"\""; + return; + } else if (!useHexString()) { + std::string test; + if (QUtil::utf8_to_pdf_doc(candidate, test, '?') && (test == this->val)) { + // This is a PDF-doc string that can be losslessly encoded as Unicode. + p << "\"u:" << JSON::Writer::encode_string(candidate) <<"\""; + return; + } + } + p << "\"b:" << QUtil::hex_encode(val) <<"\""; + } +} + bool QPDF_String::useHexString() const { diff --git a/libqpdf/QPDF_Unresolved.cc b/libqpdf/QPDF_Unresolved.cc index fbf5e15f..c2a50dbf 100644 --- a/libqpdf/QPDF_Unresolved.cc +++ b/libqpdf/QPDF_Unresolved.cc @@ -33,3 +33,9 @@ QPDF_Unresolved::getJSON(int json_version) throw std::logic_error("attempted to get JSON from an unresolved QPDFObjectHandle"); return JSON::makeNull(); } + +void +QPDF_Unresolved::writeJSON(int json_version, JSON::Writer& p) +{ + throw std::logic_error("attempted to get JSON from an unresolved QPDFObjectHandle"); +} diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 8326e6a5..5560afec 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -864,9 +865,15 @@ void QPDF::writeJSONObject( int version, Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj) { - auto j = JSON::makeDictionary(); - j.addDictionaryMember("value", obj.getJSON(version, true)); - JSON::writeDictionaryItem(p, first, key, j, 3); + if (first) { + *p << "\n \"" << key << "\": {\n \"value\": "; + first = false; + } else { + *p << ",\n \"" << key << "\": {\n \"value\": "; + } + auto w = JSON::Writer(p, 4); + obj.writeJSON(version, w, true); + *p << "\n }"; } void diff --git a/libqpdf/qpdf/QPDFObject_private.hh b/libqpdf/qpdf/QPDFObject_private.hh index 5e87c215..b873bcd0 100644 --- a/libqpdf/qpdf/QPDFObject_private.hh +++ b/libqpdf/qpdf/QPDFObject_private.hh @@ -38,6 +38,11 @@ class QPDFObject { return value->getJSON(json_version); } + void + writeJSON(int json_version, JSON::Writer& p) + { + return value->writeJSON(json_version, p); + } std::string getStringValue() const { diff --git a/libqpdf/qpdf/QPDFValue.hh b/libqpdf/qpdf/QPDFValue.hh index db8fb923..f7783466 100644 --- a/libqpdf/qpdf/QPDFValue.hh +++ b/libqpdf/qpdf/QPDFValue.hh @@ -25,6 +25,7 @@ class QPDFValue: public std::enable_shared_from_this virtual std::shared_ptr copy(bool shallow = false) = 0; virtual std::string unparse() = 0; virtual JSON getJSON(int json_version) = 0; + virtual void writeJSON(int json_version, JSON::Writer& p) = 0; struct JSON_Descr { diff --git a/libqpdf/qpdf/QPDF_Array.hh b/libqpdf/qpdf/QPDF_Array.hh index 281e1d48..7ee69b8e 100644 --- a/libqpdf/qpdf/QPDF_Array.hh +++ b/libqpdf/qpdf/QPDF_Array.hh @@ -23,6 +23,7 @@ class QPDF_Array: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; void disconnect() override; int diff --git a/libqpdf/qpdf/QPDF_Bool.hh b/libqpdf/qpdf/QPDF_Bool.hh index 0b4a71fd..f4ce0b1c 100644 --- a/libqpdf/qpdf/QPDF_Bool.hh +++ b/libqpdf/qpdf/QPDF_Bool.hh @@ -11,6 +11,8 @@ class QPDF_Bool: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; + bool getVal() const; private: diff --git a/libqpdf/qpdf/QPDF_Destroyed.hh b/libqpdf/qpdf/QPDF_Destroyed.hh index 72e9130a..400921e3 100644 --- a/libqpdf/qpdf/QPDF_Destroyed.hh +++ b/libqpdf/qpdf/QPDF_Destroyed.hh @@ -10,6 +10,7 @@ class QPDF_Destroyed: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; static std::shared_ptr getInstance(); private: diff --git a/libqpdf/qpdf/QPDF_Dictionary.hh b/libqpdf/qpdf/QPDF_Dictionary.hh index 0fb6636e..32c926a3 100644 --- a/libqpdf/qpdf/QPDF_Dictionary.hh +++ b/libqpdf/qpdf/QPDF_Dictionary.hh @@ -17,6 +17,7 @@ class QPDF_Dictionary: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; void disconnect() override; // hasKey() and getKeys() treat keys with null values as if they aren't there. getKey() returns diff --git a/libqpdf/qpdf/QPDF_InlineImage.hh b/libqpdf/qpdf/QPDF_InlineImage.hh index bee12354..cc4dc31a 100644 --- a/libqpdf/qpdf/QPDF_InlineImage.hh +++ b/libqpdf/qpdf/QPDF_InlineImage.hh @@ -11,6 +11,7 @@ class QPDF_InlineImage: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; std::string getStringValue() const override { diff --git a/libqpdf/qpdf/QPDF_Integer.hh b/libqpdf/qpdf/QPDF_Integer.hh index 2c2cf2f9..dd2f9e0d 100644 --- a/libqpdf/qpdf/QPDF_Integer.hh +++ b/libqpdf/qpdf/QPDF_Integer.hh @@ -11,6 +11,7 @@ class QPDF_Integer: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; long long getVal() const; private: diff --git a/libqpdf/qpdf/QPDF_Name.hh b/libqpdf/qpdf/QPDF_Name.hh index c14d8659..167ddef5 100644 --- a/libqpdf/qpdf/QPDF_Name.hh +++ b/libqpdf/qpdf/QPDF_Name.hh @@ -11,6 +11,7 @@ class QPDF_Name: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; // Put # into strings with characters unsuitable for name token static std::string normalizeName(std::string const& name); diff --git a/libqpdf/qpdf/QPDF_Null.hh b/libqpdf/qpdf/QPDF_Null.hh index a59b7509..2a099bf9 100644 --- a/libqpdf/qpdf/QPDF_Null.hh +++ b/libqpdf/qpdf/QPDF_Null.hh @@ -19,6 +19,7 @@ class QPDF_Null: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; private: QPDF_Null(); diff --git a/libqpdf/qpdf/QPDF_Operator.hh b/libqpdf/qpdf/QPDF_Operator.hh index 77aa5a17..d8b99e17 100644 --- a/libqpdf/qpdf/QPDF_Operator.hh +++ b/libqpdf/qpdf/QPDF_Operator.hh @@ -11,6 +11,7 @@ class QPDF_Operator: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; std::string getStringValue() const override { diff --git a/libqpdf/qpdf/QPDF_Real.hh b/libqpdf/qpdf/QPDF_Real.hh index db5e0940..5fec919d 100644 --- a/libqpdf/qpdf/QPDF_Real.hh +++ b/libqpdf/qpdf/QPDF_Real.hh @@ -13,6 +13,7 @@ class QPDF_Real: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; std::string getStringValue() const override { diff --git a/libqpdf/qpdf/QPDF_Reserved.hh b/libqpdf/qpdf/QPDF_Reserved.hh index 9ba855b7..4503fb9e 100644 --- a/libqpdf/qpdf/QPDF_Reserved.hh +++ b/libqpdf/qpdf/QPDF_Reserved.hh @@ -11,6 +11,7 @@ class QPDF_Reserved: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; private: QPDF_Reserved(); diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index 8488e157..597a48a8 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -26,6 +26,7 @@ class QPDF_Stream: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; void setDescription( QPDF*, std::shared_ptr& description, qpdf_offset_t offset) override; void disconnect() override; diff --git a/libqpdf/qpdf/QPDF_String.hh b/libqpdf/qpdf/QPDF_String.hh index c34cafef..e7a87a53 100644 --- a/libqpdf/qpdf/QPDF_String.hh +++ b/libqpdf/qpdf/QPDF_String.hh @@ -17,6 +17,7 @@ class QPDF_String: public QPDFValue std::string unparse() override; std::string unparse(bool force_binary); JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; std::string getUTF8Val() const; std::string getStringValue() const override diff --git a/libqpdf/qpdf/QPDF_Unresolved.hh b/libqpdf/qpdf/QPDF_Unresolved.hh index 0a1fa9a5..669e314e 100644 --- a/libqpdf/qpdf/QPDF_Unresolved.hh +++ b/libqpdf/qpdf/QPDF_Unresolved.hh @@ -11,6 +11,7 @@ class QPDF_Unresolved: public QPDFValue std::shared_ptr copy(bool shallow = false) override; std::string unparse() override; JSON getJSON(int json_version) override; + void writeJSON(int json_version, JSON::Writer& p) override; private: QPDF_Unresolved(QPDF* qpdf, QPDFObjGen const& og);