diff options
Diffstat (limited to 'libqpdf/QPDF_Array.cc')
-rw-r--r-- | libqpdf/QPDF_Array.cc | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 36c5aaea..2cb4bce5 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -151,20 +151,33 @@ QPDF_Array::unparse() JSON QPDF_Array::getJSON(int json_version) { + static const JSON j_null = JSON::makeNull(); + JSON j_array = JSON::makeArray(); if (sparse) { - JSON j = JSON::makeArray(); - for (int i = 0; i < sp_size; ++i) { - j.addArrayElement(at(i).getJSON(json_version)); + int next = 0; + for (auto& item: sp_elements) { + int key = item.first; + for (int j = next; j < key; ++j) { + j_array.addArrayElement(j_null); + } + auto og = item.second->getObjGen(); + j_array.addArrayElement( + og.isIndirect() ? JSON::makeString(og.unparse(' ') + " R") + : item.second->getJSON(json_version)); + next = ++key; + } + for (int j = next; j < sp_size; ++j) { + j_array.addArrayElement(j_null); } - return j; } else { - JSON j = JSON::makeArray(); - size_t size = elements.size(); - for (int i = 0; i < int(size); ++i) { - j.addArrayElement(at(i).getJSON(json_version)); + for (auto const& item: elements) { + auto og = item->getObjGen(); + j_array.addArrayElement( + og.isIndirect() ? JSON::makeString(og.unparse(' ') + " R") + : item->getJSON(json_version)); } - return j; } + return j_array; } QPDFObjectHandle |