mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Prepare code for JSON v2
Update getJSON() methods and calls to them
This commit is contained in:
parent
a9fbbd5dca
commit
16f4f94cd9
2
TODO
2
TODO
@ -50,8 +50,6 @@ Output JSON v2
|
||||
|
||||
General things to remember:
|
||||
|
||||
* deprecate getJSON without a version
|
||||
|
||||
* Make sure all the information from --check and other informational
|
||||
options (--show-linearization, --show-encryption, --show-xref,
|
||||
--list-attachments, --show-npages) is available in the json output.
|
||||
|
@ -142,7 +142,7 @@ FuzzHelper::testPages()
|
||||
page.getImages();
|
||||
pldh.getLabelForPage(pageno);
|
||||
QPDFObjectHandle page_obj(page.getObjectHandle());
|
||||
page_obj.getJSON(true).unparse();
|
||||
page_obj.getJSON(JSON::LATEST, true).unparse();
|
||||
odh.getOutlinesForPage(page_obj.getObjGen());
|
||||
|
||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
||||
|
@ -51,6 +51,8 @@ class InputSource;
|
||||
class JSON
|
||||
{
|
||||
public:
|
||||
static int constexpr LATEST = 2;
|
||||
|
||||
QPDF_DLL
|
||||
std::string unparse() const;
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <qpdf/DLL.h>
|
||||
#include <qpdf/PDFVersion.hh>
|
||||
#include <qpdf/QPDF.hh>
|
||||
#include <qpdf/QPDFOutlineObjectHelper.hh>
|
||||
#include <qpdf/QPDFPageObjectHelper.hh>
|
||||
|
||||
#include <functional>
|
||||
@ -520,6 +521,10 @@ class QPDFJob
|
||||
void doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf);
|
||||
void doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf);
|
||||
void doJSONAttachments(Pipeline* p, bool& first, QPDF& pdf);
|
||||
void addOutlinesToJson(
|
||||
std::vector<QPDFOutlineObjectHelper> outlines,
|
||||
JSON& j,
|
||||
std::map<QPDFObjGen, int>& page_numbers);
|
||||
|
||||
enum remove_unref_e { re_auto, re_yes, re_no };
|
||||
|
||||
|
@ -64,7 +64,7 @@ class QPDFObject
|
||||
|
||||
virtual ~QPDFObject() = default;
|
||||
virtual std::string unparse() = 0;
|
||||
virtual JSON getJSON() = 0;
|
||||
virtual JSON getJSON(int json_version) = 0;
|
||||
|
||||
// Return a unique type code for the object
|
||||
virtual object_type_e getTypeCode() const = 0;
|
||||
|
@ -1304,15 +1304,40 @@ class QPDFObjectHandle
|
||||
QPDF_DLL
|
||||
std::string unparseBinary();
|
||||
|
||||
// Return encoded as JSON. For most object types, there is an
|
||||
// obvious mapping. The JSON is generated as follows:
|
||||
// * Names are encoded as strings representing the normalized name
|
||||
// in PDF syntax as returned by unparse()
|
||||
// Return encoded as JSON. The constant JSON::LATEST can be used
|
||||
// to specify the latest available JSON version. The JSON is
|
||||
// generated as follows:
|
||||
// * Arrays, dictionaries, booleans, nulls, integers, and real
|
||||
// numbers are represented by their native JSON types.
|
||||
// * Names are encoded as strings representing the canonical
|
||||
// representation (after parsing #xx) and preceded by a slash,
|
||||
// just as unparse() returns. For example, the JSON for the
|
||||
// PDF-syntax name /Text#2fPlain would be "/Text/Plain".
|
||||
// * Indirect references are encoded as strings containing "obj gen R"
|
||||
// * Strings are encoded as UTF-8 strings with unrepresentable binary
|
||||
// characters encoded as \uHHHH
|
||||
// * Encoding streams just encodes the stream's dictionary; the stream
|
||||
// data is not represented
|
||||
// * Strings
|
||||
// * JSON v1: Strings are encoded as UTF-8 strings with
|
||||
// unrepresentable binary characters encoded as \uHHHH.
|
||||
// Characters in PDF Doc encoding that don't have
|
||||
// bidirectional unicode mappings are not reversible. There is
|
||||
// no way to tell the difference between a string that looks
|
||||
// like a name or indirect object from an actual name or
|
||||
// indirect object.
|
||||
// * JSON v2:
|
||||
// * Unicode strings and strings encoded with PDF Doc encoding
|
||||
// that can be bidrectionally mapped two Unicode (which is
|
||||
// all strings without undefined characters) are represented
|
||||
// as "u:" followed by the UTF-8 encoded string. Example:
|
||||
// "u:potato".
|
||||
// * All other strings are represented as "b:" followed by a
|
||||
// hexadecimal encoding of the string. Example: "b:0102cacb"
|
||||
// * Streams
|
||||
// * JSON v1: Only the stream's dictionary is encoded. There is
|
||||
// no way tell a stream from a dictionary other than context.
|
||||
// * JSON v2: A stream is encoded as {"dict": {...}} with the
|
||||
// value being the encoding of the stream's dictionary. Since
|
||||
// "dict" does not otherwise represent anything, this is
|
||||
// unambiguous. The getStreamJSON() call can be used to add
|
||||
// encoding of the stream's data.
|
||||
// * Object types that are only valid in content streams (inline
|
||||
// image, operator) as well as "reserved" objects are not
|
||||
// representable and will be serialized as "null".
|
||||
@ -1321,6 +1346,12 @@ class QPDFObjectHandle
|
||||
// dereference_indirect applies only to this object. It is not
|
||||
// recursive.
|
||||
QPDF_DLL
|
||||
JSON getJSON(int json_version, bool dereference_indirect = false);
|
||||
|
||||
// Deprecated version uses v1 for backward compatibility.
|
||||
// ABI: remove for qpdf 12
|
||||
[[deprecated("Use getJSON(int version)")]]
|
||||
QPDF_DLL
|
||||
JSON getJSON(bool dereference_indirect = false);
|
||||
|
||||
// Legacy helper methods for commonly performed operations on
|
||||
|
6
job.sums
6
job.sums
@ -6,12 +6,12 @@ include/qpdf/auto_job_c_enc.hh 28446f3c32153a52afa239ea40503e6cc8ac2c026813526a3
|
||||
include/qpdf/auto_job_c_main.hh 940aa6f1ead18ed08ba33f11254e9f042348262c85b91de742f0427094412a80
|
||||
include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c18911614fe8e568ec
|
||||
include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1
|
||||
job.yml 3c130913b3546f272c06b334ece9aa70450449539db10e39673b5ee79d863f48
|
||||
job.yml e3d9752ea8810872447190b0b2b913f591ae03dfdd876945adf1bbb76942cd0f
|
||||
libqpdf/qpdf/auto_job_decl.hh 74df4d7fdbdf51ecd0d58ce1e9844bb5525b9adac5a45f7c9a787ecdda2868df
|
||||
libqpdf/qpdf/auto_job_help.hh a3d1a326a3f8ff61a7d451176acde3bb6c8ad66c1ea7a0b8c5d789917ad3a9ee
|
||||
libqpdf/qpdf/auto_job_init.hh c8477a597f037d7de5fd131b008a75f1fe435bba248261abe422e8bfb24c8755
|
||||
libqpdf/qpdf/auto_job_init.hh 1dcefadac02bb4b3a5d112912483902ad46489b1cacefefd3ebe4f64fc1b8a29
|
||||
libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297
|
||||
libqpdf/qpdf/auto_job_json_init.hh e7047a7c83737adfaae49abc295a579bb9b9e0a4644e911d1656a604cb202208
|
||||
libqpdf/qpdf/auto_job_json_init.hh 784ff973e7efbf589f6a9b3ad22b3aada5c5393e9c5cd31845b8fe4af6e03f98
|
||||
libqpdf/qpdf/auto_job_schema.hh cbbcae166cfecbdbdeb40c5a30870e03604a019a8b4f7a217d554a82431d2e5f
|
||||
manual/_ext/qpdf.py 6add6321666031d55ed4aedf7c00e5662bba856dfcd66ccb526563bffefbb580
|
||||
manual/cli.rst 8684ca1f601f2832cded52d1b2f74730f97b7b85b57e31a399231731fbe80d26
|
||||
|
1
job.yml
1
job.yml
@ -38,6 +38,7 @@ choices:
|
||||
- screen
|
||||
json_version:
|
||||
- 1
|
||||
- 2
|
||||
- latest
|
||||
json_key:
|
||||
# The list of selectable top-level keys id duplicated in the
|
||||
|
@ -1053,12 +1053,20 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf)
|
||||
for (auto& obj: objects) {
|
||||
if (all_objects || wanted_og.count(obj.getObjGen())) {
|
||||
JSON::writeDictionaryItem(
|
||||
p, first_object, obj.unparse(), obj.getJSON(true), 1);
|
||||
p,
|
||||
first_object,
|
||||
obj.unparse(),
|
||||
obj.getJSON(this->m->json_version, true),
|
||||
1);
|
||||
}
|
||||
}
|
||||
if (all_objects || m->json_objects.count("trailer")) {
|
||||
JSON::writeDictionaryItem(
|
||||
p, first_object, "trailer", pdf.getTrailer().getJSON(true), 1);
|
||||
p,
|
||||
first_object,
|
||||
"trailer",
|
||||
pdf.getTrailer().getJSON(this->m->json_version, true),
|
||||
1);
|
||||
}
|
||||
JSON::writeDictionaryClose(p, first_object, 1);
|
||||
}
|
||||
@ -1080,11 +1088,13 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf)
|
||||
j_stream.addDictionaryMember("is", JSON::makeBool(is_stream));
|
||||
j_stream.addDictionaryMember(
|
||||
"length",
|
||||
(is_stream ? obj.getDict().getKey("/Length").getJSON(true)
|
||||
(is_stream ? obj.getDict().getKey("/Length").getJSON(
|
||||
this->m->json_version, true)
|
||||
: JSON::makeNull()));
|
||||
j_stream.addDictionaryMember(
|
||||
"filter",
|
||||
(is_stream ? obj.getDict().getKey("/Filter").getJSON(true)
|
||||
(is_stream ? obj.getDict().getKey("/Filter").getJSON(
|
||||
this->m->json_version, true)
|
||||
: JSON::makeNull()));
|
||||
JSON::writeDictionaryItem(
|
||||
p, first_object, obj.unparse(), j_details, 1);
|
||||
@ -1108,7 +1118,8 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
|
||||
++pageno;
|
||||
JSON j_page = JSON::makeDictionary();
|
||||
QPDFObjectHandle page = ph.getObjectHandle();
|
||||
j_page.addDictionaryMember("object", page.getJSON());
|
||||
j_page.addDictionaryMember(
|
||||
"object", page.getJSON(this->m->json_version));
|
||||
JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray());
|
||||
std::map<std::string, QPDFObjectHandle> images = ph.getImages();
|
||||
for (auto const& iter2: images) {
|
||||
@ -1116,17 +1127,23 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
|
||||
j_image.addDictionaryMember("name", JSON::makeString(iter2.first));
|
||||
QPDFObjectHandle image = iter2.second;
|
||||
QPDFObjectHandle dict = image.getDict();
|
||||
j_image.addDictionaryMember("object", image.getJSON());
|
||||
j_image.addDictionaryMember(
|
||||
"width", dict.getKey("/Width").getJSON());
|
||||
"object", image.getJSON(this->m->json_version));
|
||||
j_image.addDictionaryMember(
|
||||
"height", dict.getKey("/Height").getJSON());
|
||||
"width", dict.getKey("/Width").getJSON(this->m->json_version));
|
||||
j_image.addDictionaryMember(
|
||||
"colorspace", dict.getKey("/ColorSpace").getJSON());
|
||||
"height",
|
||||
dict.getKey("/Height").getJSON(this->m->json_version));
|
||||
j_image.addDictionaryMember(
|
||||
"bitspercomponent", dict.getKey("/BitsPerComponent").getJSON());
|
||||
"colorspace",
|
||||
dict.getKey("/ColorSpace").getJSON(this->m->json_version));
|
||||
j_image.addDictionaryMember(
|
||||
"bitspercomponent",
|
||||
dict.getKey("/BitsPerComponent")
|
||||
.getJSON(this->m->json_version));
|
||||
QPDFObjectHandle filters = dict.getKey("/Filter").wrapInArray();
|
||||
j_image.addDictionaryMember("filter", filters.getJSON());
|
||||
j_image.addDictionaryMember(
|
||||
"filter", filters.getJSON(this->m->json_version));
|
||||
QPDFObjectHandle decode_parms = dict.getKey("/DecodeParms");
|
||||
QPDFObjectHandle dp_array;
|
||||
if (decode_parms.isArray()) {
|
||||
@ -1137,7 +1154,8 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
|
||||
dp_array.appendItem(decode_parms);
|
||||
}
|
||||
}
|
||||
j_image.addDictionaryMember("decodeparms", dp_array.getJSON());
|
||||
j_image.addDictionaryMember(
|
||||
"decodeparms", dp_array.getJSON(this->m->json_version));
|
||||
j_image.addDictionaryMember(
|
||||
"filterable",
|
||||
JSON::makeBool(
|
||||
@ -1148,10 +1166,11 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
|
||||
j_page.addDictionaryMember("contents", JSON::makeArray());
|
||||
std::vector<QPDFObjectHandle> content = ph.getPageContents();
|
||||
for (auto& iter2: content) {
|
||||
j_contents.addArrayElement(iter2.getJSON());
|
||||
j_contents.addArrayElement(iter2.getJSON(this->m->json_version));
|
||||
}
|
||||
j_page.addDictionaryMember(
|
||||
"label", pldh.getLabelForPage(pageno).getJSON());
|
||||
"label",
|
||||
pldh.getLabelForPage(pageno).getJSON(this->m->json_version));
|
||||
JSON j_outlines =
|
||||
j_page.addDictionaryMember("outlines", JSON::makeArray());
|
||||
std::vector<QPDFOutlineObjectHelper> outlines =
|
||||
@ -1159,11 +1178,12 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
|
||||
for (auto& oiter: outlines) {
|
||||
JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary());
|
||||
j_outline.addDictionaryMember(
|
||||
"object", oiter.getObjectHandle().getJSON());
|
||||
"object",
|
||||
oiter.getObjectHandle().getJSON(this->m->json_version));
|
||||
j_outline.addDictionaryMember(
|
||||
"title", JSON::makeString(oiter.getTitle()));
|
||||
j_outline.addDictionaryMember(
|
||||
"dest", oiter.getDest().getJSON(true));
|
||||
"dest", oiter.getDest().getJSON(this->m->json_version, true));
|
||||
}
|
||||
j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno));
|
||||
JSON::writeArrayItem(p, first_page, j_page, 1);
|
||||
@ -1192,25 +1212,29 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf)
|
||||
break;
|
||||
}
|
||||
JSON j_label = j_labels.addArrayElement(JSON::makeDictionary());
|
||||
j_label.addDictionaryMember("index", (*iter).getJSON());
|
||||
j_label.addDictionaryMember(
|
||||
"index", (*iter).getJSON(this->m->json_version));
|
||||
++iter;
|
||||
j_label.addDictionaryMember("label", (*iter).getJSON());
|
||||
j_label.addDictionaryMember(
|
||||
"label", (*iter).getJSON(this->m->json_version));
|
||||
}
|
||||
}
|
||||
JSON::writeDictionaryItem(p, first, "pagelabels", j_labels, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
add_outlines_to_json(
|
||||
void
|
||||
QPDFJob::addOutlinesToJson(
|
||||
std::vector<QPDFOutlineObjectHelper> outlines,
|
||||
JSON& j,
|
||||
std::map<QPDFObjGen, int>& page_numbers)
|
||||
{
|
||||
for (auto& ol: outlines) {
|
||||
JSON jo = j.addArrayElement(JSON::makeDictionary());
|
||||
jo.addDictionaryMember("object", ol.getObjectHandle().getJSON());
|
||||
jo.addDictionaryMember(
|
||||
"object", ol.getObjectHandle().getJSON(this->m->json_version));
|
||||
jo.addDictionaryMember("title", JSON::makeString(ol.getTitle()));
|
||||
jo.addDictionaryMember("dest", ol.getDest().getJSON(true));
|
||||
jo.addDictionaryMember(
|
||||
"dest", ol.getDest().getJSON(this->m->json_version, true));
|
||||
jo.addDictionaryMember("open", JSON::makeBool(ol.getCount() >= 0));
|
||||
QPDFObjectHandle page = ol.getDestPage();
|
||||
JSON j_destpage = JSON::makeNull();
|
||||
@ -1222,7 +1246,7 @@ add_outlines_to_json(
|
||||
}
|
||||
jo.addDictionaryMember("destpageposfrom1", j_destpage);
|
||||
JSON j_kids = jo.addDictionaryMember("kids", JSON::makeArray());
|
||||
add_outlines_to_json(ol.getKids(), j_kids, page_numbers);
|
||||
addOutlinesToJson(ol.getKids(), j_kids, page_numbers);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1240,7 +1264,7 @@ QPDFJob::doJSONOutlines(Pipeline* p, bool& first, QPDF& pdf)
|
||||
|
||||
JSON j_outlines = JSON::makeArray();
|
||||
QPDFOutlineDocumentHelper odh(pdf);
|
||||
add_outlines_to_json(odh.getTopLevelOutlines(), j_outlines, page_numbers);
|
||||
addOutlinesToJson(odh.getTopLevelOutlines(), j_outlines, page_numbers);
|
||||
JSON::writeDictionaryItem(p, first, "outlines", j_outlines, 0);
|
||||
}
|
||||
|
||||
@ -1265,9 +1289,11 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
|
||||
QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh);
|
||||
JSON j_field = j_fields.addArrayElement(JSON::makeDictionary());
|
||||
j_field.addDictionaryMember(
|
||||
"object", ffh.getObjectHandle().getJSON());
|
||||
"object", ffh.getObjectHandle().getJSON(this->m->json_version));
|
||||
j_field.addDictionaryMember(
|
||||
"parent", ffh.getObjectHandle().getKey("/Parent").getJSON());
|
||||
"parent",
|
||||
ffh.getObjectHandle().getKey("/Parent").getJSON(
|
||||
this->m->json_version));
|
||||
j_field.addDictionaryMember(
|
||||
"pageposfrom1", JSON::makeInt(pagepos1));
|
||||
j_field.addDictionaryMember(
|
||||
@ -1282,9 +1308,11 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
|
||||
"alternativename", JSON::makeString(ffh.getAlternativeName()));
|
||||
j_field.addDictionaryMember(
|
||||
"mappingname", JSON::makeString(ffh.getMappingName()));
|
||||
j_field.addDictionaryMember("value", ffh.getValue().getJSON());
|
||||
j_field.addDictionaryMember(
|
||||
"defaultvalue", ffh.getDefaultValue().getJSON());
|
||||
"value", ffh.getValue().getJSON(this->m->json_version));
|
||||
j_field.addDictionaryMember(
|
||||
"defaultvalue",
|
||||
ffh.getDefaultValue().getJSON(this->m->json_version));
|
||||
j_field.addDictionaryMember(
|
||||
"quadding", JSON::makeInt(ffh.getQuadding()));
|
||||
j_field.addDictionaryMember(
|
||||
@ -1303,7 +1331,7 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
|
||||
JSON j_annot = j_field.addDictionaryMember(
|
||||
"annotation", JSON::makeDictionary());
|
||||
j_annot.addDictionaryMember(
|
||||
"object", aoh.getObjectHandle().getJSON());
|
||||
"object", aoh.getObjectHandle().getJSON(this->m->json_version));
|
||||
j_annot.addDictionaryMember(
|
||||
"appearancestate", JSON::makeString(aoh.getAppearanceState()));
|
||||
j_annot.addDictionaryMember(
|
||||
@ -1621,7 +1649,8 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p)
|
||||
// change is made to the JSON format. Clients of the JSON are to
|
||||
// ignore unrecognized keys, so we only update the version of a
|
||||
// key disappears or if its value changes meaning.
|
||||
JSON::writeDictionaryItem(p, first, "version", JSON::makeInt(1), 0);
|
||||
JSON::writeDictionaryItem(
|
||||
p, first, "version", JSON::makeInt(this->m->json_version), 0);
|
||||
JSON j_params = JSON::makeDictionary();
|
||||
std::string decode_level_str;
|
||||
switch (m->decode_level) {
|
||||
|
@ -235,11 +235,11 @@ QPDFJob::Config*
|
||||
QPDFJob::Config::json(std::string const& parameter)
|
||||
{
|
||||
if (parameter.empty() || (parameter == "latest")) {
|
||||
o.m->json_version = 1;
|
||||
o.m->json_version = JSON::LATEST;
|
||||
} else {
|
||||
o.m->json_version = QUtil::string_to_int(parameter.c_str());
|
||||
}
|
||||
if (o.m->json_version != 1) {
|
||||
if ((o.m->json_version < 1) || (o.m->json_version > JSON::LATEST)) {
|
||||
usage(std::string("unsupported json version ") + parameter);
|
||||
}
|
||||
o.m->require_outfile = false;
|
||||
|
@ -1775,8 +1775,15 @@ QPDFObjectHandle::unparseBinary()
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated versionless getJSON to be removed in qpdf 12
|
||||
JSON
|
||||
QPDFObjectHandle::getJSON(bool dereference_indirect)
|
||||
{
|
||||
return getJSON(1, dereference_indirect);
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDFObjectHandle::getJSON(int json_version, bool dereference_indirect)
|
||||
{
|
||||
if ((!dereference_indirect) && this->isIndirect()) {
|
||||
return JSON::makeString(unparse());
|
||||
@ -1786,7 +1793,7 @@ QPDFObjectHandle::getJSON(bool dereference_indirect)
|
||||
throw std::logic_error(
|
||||
"QPDFObjectHandle: attempting to unparse a reserved object");
|
||||
}
|
||||
return this->obj->getJSON();
|
||||
return this->obj->getJSON(json_version);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,12 +34,12 @@ QPDF_Array::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Array::getJSON()
|
||||
QPDF_Array::getJSON(int json_version)
|
||||
{
|
||||
JSON j = JSON::makeArray();
|
||||
size_t size = this->elements.size();
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
j.addArrayElement(this->elements.at(i).getJSON());
|
||||
j.addArrayElement(this->elements.at(i).getJSON(json_version));
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ QPDF_Bool::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Bool::getJSON()
|
||||
QPDF_Bool::getJSON(int json_version)
|
||||
{
|
||||
return JSON::makeBool(this->val);
|
||||
}
|
||||
|
@ -32,13 +32,14 @@ QPDF_Dictionary::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Dictionary::getJSON()
|
||||
QPDF_Dictionary::getJSON(int json_version)
|
||||
{
|
||||
JSON j = JSON::makeDictionary();
|
||||
for (auto& iter: this->items) {
|
||||
if (!iter.second.isNull()) {
|
||||
j.addDictionaryMember(
|
||||
QPDF_Name::normalizeName(iter.first), iter.second.getJSON());
|
||||
QPDF_Name::normalizeName(iter.first),
|
||||
iter.second.getJSON(json_version));
|
||||
}
|
||||
}
|
||||
return j;
|
||||
|
@ -14,7 +14,7 @@ QPDF_InlineImage::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_InlineImage::getJSON()
|
||||
QPDF_InlineImage::getJSON(int json_version)
|
||||
{
|
||||
return JSON::makeNull();
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ QPDF_Integer::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Integer::getJSON()
|
||||
QPDF_Integer::getJSON(int json_version)
|
||||
{
|
||||
return JSON::makeInt(this->val);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ QPDF_Name::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Name::getJSON()
|
||||
QPDF_Name::getJSON(int json_version)
|
||||
{
|
||||
return JSON::makeString(normalizeName(this->name));
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ QPDF_Null::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Null::getJSON()
|
||||
QPDF_Null::getJSON(int json_version)
|
||||
{
|
||||
return JSON::makeNull();
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ QPDF_Operator::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Operator::getJSON()
|
||||
QPDF_Operator::getJSON(int json_version)
|
||||
{
|
||||
return JSON::makeNull();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ QPDF_Real::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Real::getJSON()
|
||||
QPDF_Real::getJSON(int json_version)
|
||||
{
|
||||
// While PDF allows .x or -.x, JSON does not. Rather than
|
||||
// converting from string to double and back, just handle this as a
|
||||
|
@ -10,7 +10,7 @@ QPDF_Reserved::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Reserved::getJSON()
|
||||
QPDF_Reserved::getJSON(int json_version)
|
||||
{
|
||||
throw std::logic_error("attempt to generate JSON from QPDF_Reserved");
|
||||
return JSON::makeNull();
|
||||
|
@ -151,9 +151,10 @@ QPDF_Stream::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_Stream::getJSON()
|
||||
QPDF_Stream::getJSON(int json_version)
|
||||
{
|
||||
return this->stream_dict.getJSON();
|
||||
// QXXXQ
|
||||
return this->stream_dict.getJSON(json_version);
|
||||
}
|
||||
|
||||
QPDFObject::object_type_e
|
||||
|
@ -43,8 +43,9 @@ QPDF_String::unparse()
|
||||
}
|
||||
|
||||
JSON
|
||||
QPDF_String::getJSON()
|
||||
QPDF_String::getJSON(int json_version)
|
||||
{
|
||||
// QXXXQ
|
||||
return JSON::makeString(getUTF8Val());
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ class QPDF_Array: public QPDFObject
|
||||
QPDF_Array(SparseOHArray const& items);
|
||||
virtual ~QPDF_Array() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
virtual void setDescription(QPDF*, std::string const&);
|
||||
|
@ -9,7 +9,7 @@ class QPDF_Bool: public QPDFObject
|
||||
QPDF_Bool(bool val);
|
||||
virtual ~QPDF_Bool() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
bool getVal() const;
|
||||
|
@ -14,7 +14,7 @@ class QPDF_Dictionary: public QPDFObject
|
||||
QPDF_Dictionary(std::map<std::string, QPDFObjectHandle> const& items);
|
||||
virtual ~QPDF_Dictionary() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
virtual void setDescription(QPDF*, std::string const&);
|
||||
|
@ -9,7 +9,7 @@ class QPDF_InlineImage: public QPDFObject
|
||||
QPDF_InlineImage(std::string const& val);
|
||||
virtual ~QPDF_InlineImage() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
std::string getVal() const;
|
||||
|
@ -9,7 +9,7 @@ class QPDF_Integer: public QPDFObject
|
||||
QPDF_Integer(long long val);
|
||||
virtual ~QPDF_Integer() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
long long getVal() const;
|
||||
|
@ -9,7 +9,7 @@ class QPDF_Name: public QPDFObject
|
||||
QPDF_Name(std::string const& name);
|
||||
virtual ~QPDF_Name() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
std::string getName() const;
|
||||
|
@ -8,7 +8,7 @@ class QPDF_Null: public QPDFObject
|
||||
public:
|
||||
virtual ~QPDF_Null() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
};
|
||||
|
@ -9,7 +9,7 @@ class QPDF_Operator: public QPDFObject
|
||||
QPDF_Operator(std::string const& val);
|
||||
virtual ~QPDF_Operator() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
std::string getVal() const;
|
||||
|
@ -10,7 +10,7 @@ class QPDF_Real: public QPDFObject
|
||||
QPDF_Real(double value, int decimal_places, bool trim_trailing_zeroes);
|
||||
virtual ~QPDF_Real() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
std::string getVal();
|
||||
|
@ -8,7 +8,7 @@ class QPDF_Reserved: public QPDFObject
|
||||
public:
|
||||
virtual ~QPDF_Reserved() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
};
|
||||
|
@ -25,7 +25,7 @@ class QPDF_Stream: public QPDFObject
|
||||
size_t length);
|
||||
virtual ~QPDF_Stream() = default;
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
virtual void setDescription(QPDF*, std::string const&);
|
||||
|
@ -15,7 +15,7 @@ class QPDF_String: public QPDFObject
|
||||
virtual QPDFObject::object_type_e getTypeCode() const;
|
||||
virtual char const* getTypeName() const;
|
||||
std::string unparse(bool force_binary);
|
||||
virtual JSON getJSON();
|
||||
virtual JSON getJSON(int json_version);
|
||||
std::string getVal() const;
|
||||
std::string getUTF8Val() const;
|
||||
|
||||
|
@ -19,7 +19,7 @@ static char const* decode_level_choices[] = {"none", "generalized", "specialized
|
||||
static char const* object_streams_choices[] = {"disable", "preserve", "generate", 0};
|
||||
static char const* remove_unref_choices[] = {"auto", "yes", "no", 0};
|
||||
static char const* flatten_choices[] = {"all", "print", "screen", 0};
|
||||
static char const* json_version_choices[] = {"1", "latest", 0};
|
||||
static char const* json_version_choices[] = {"1", "2", "latest", 0};
|
||||
static char const* json_key_choices[] = {"acroform", "attachments", "encrypt", "objectinfo", "objects", "outlines", "pagelabels", "pages", 0};
|
||||
static char const* print128_choices[] = {"full", "low", "none", 0};
|
||||
static char const* modify128_choices[] = {"all", "annotate", "form", "assembly", "none", 0};
|
||||
|
@ -12,7 +12,7 @@ static char const* decode_level_choices[] = {"none", "generalized", "specialized
|
||||
static char const* object_streams_choices[] = {"disable", "preserve", "generate", 0};
|
||||
static char const* remove_unref_choices[] = {"auto", "yes", "no", 0};
|
||||
static char const* flatten_choices[] = {"all", "print", "screen", 0};
|
||||
static char const* json_version_choices[] = {"1", "latest", 0};
|
||||
static char const* json_version_choices[] = {"1", "2", "latest", 0};
|
||||
static char const* json_key_choices[] = {"acroform", "attachments", "encrypt", "objectinfo", "objects", "outlines", "pagelabels", "pages", 0};
|
||||
static char const* print128_choices[] = {"full", "low", "none", 0};
|
||||
static char const* modify128_choices[] = {"all", "annotate", "form", "assembly", "none", 0};
|
||||
|
@ -100,10 +100,12 @@ test_main()
|
||||
" ],\n"
|
||||
" \"yes\": false\n"
|
||||
"}");
|
||||
check(QPDFObjectHandle::newReal("0.12").getJSON(), "0.12");
|
||||
check(QPDFObjectHandle::newReal(".34").getJSON(), "0.34");
|
||||
check(QPDFObjectHandle::newReal("-0.56").getJSON(), "-0.56");
|
||||
check(QPDFObjectHandle::newReal("-.78").getJSON(), "-0.78");
|
||||
for (int i = 1; i <= JSON::LATEST; ++i) {
|
||||
check(QPDFObjectHandle::newReal("0.12").getJSON(i), "0.12");
|
||||
check(QPDFObjectHandle::newReal(".34").getJSON(i), "0.34");
|
||||
check(QPDFObjectHandle::newReal("-0.56").getJSON(i), "-0.56");
|
||||
check(QPDFObjectHandle::newReal("-.78").getJSON(i), "-0.78");
|
||||
}
|
||||
JSON jmap2 = JSON::parse(R"({"a": 1, "b": "two", "c": [true]})");
|
||||
std::map<std::string, std::string> dvalue;
|
||||
assert(jmap2.forEachDictItem(
|
||||
|
@ -4279,7 +4279,7 @@ foreach my $d (@encrypted_files)
|
||||
my $enc_details = "";
|
||||
my $enc_json =
|
||||
"{\n" .
|
||||
" \"version\": 1,\n" .
|
||||
" \"version\": 2,\n" .
|
||||
" \"parameters\": {\n" .
|
||||
" \"decodelevel\": \"generalized\"\n" .
|
||||
" },\n" .
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"parameters": {
|
||||
"decodelevel": "generalized"
|
||||
},
|
||||
|
@ -1922,7 +1922,7 @@ test_50(QPDF& pdf, char const* arg2)
|
||||
QPDFObjectHandle d1 = pdf.getTrailer().getKey("/Dict1");
|
||||
QPDFObjectHandle d2 = pdf.getTrailer().getKey("/Dict2");
|
||||
d1.mergeResources(d2);
|
||||
std::cout << d1.getJSON().unparse() << std::endl;
|
||||
std::cout << d1.getJSON(JSON::LATEST).unparse() << std::endl;
|
||||
// Top-level type mismatch
|
||||
d1.mergeResources(d2.getKey("/k1"));
|
||||
for (auto const& name: d1.getResourceNames()) {
|
||||
@ -3114,7 +3114,7 @@ test_87(QPDF& pdf, char const* arg2)
|
||||
});
|
||||
assert(dict.unparse() == "<< /A 2 >>");
|
||||
assert(dict.getKeys() == std::set<std::string>({"/A"}));
|
||||
assert(dict.getJSON().unparse() == "{\n \"/A\": 2\n}");
|
||||
assert(dict.getJSON(JSON::LATEST).unparse() == "{\n \"/A\": 2\n}");
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user