Commit 4f54508f7f3b9d9d97b1163156a89bfad582a5ea
1 parent
f0bc2f11
Refactor QPDFJob::doJSONObjects
Showing
2 changed files
with
11 additions
and
27 deletions
include/qpdf/QPDFJob.hh
| ... | ... | @@ -551,7 +551,6 @@ class QPDFJob |
| 551 | 551 | // JSON |
| 552 | 552 | void doJSON(QPDF& pdf, Pipeline*); |
| 553 | 553 | QPDFObjGen::set getWantedJSONObjects(); |
| 554 | - void doJSONObject(Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle&); | |
| 555 | 554 | void doJSONObjects(Pipeline* p, bool& first, QPDF& pdf); |
| 556 | 555 | void doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf); |
| 557 | 556 | void doJSONPages(Pipeline* p, bool& first, QPDF& pdf); | ... | ... |
libqpdf/QPDFJob.cc
| ... | ... | @@ -955,23 +955,6 @@ QPDFJob::getWantedJSONObjects() |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | void |
| 958 | -QPDFJob::doJSONObject(Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj) | |
| 959 | -{ | |
| 960 | - if (m->json_version == 1) { | |
| 961 | - JSON::writeDictionaryItem(p, first, key, obj.getJSON(1, true), 2); | |
| 962 | - } else { | |
| 963 | - auto j = JSON::makeDictionary(); | |
| 964 | - if (obj.isStream()) { | |
| 965 | - j.addDictionaryMember("stream", JSON::makeDictionary()) | |
| 966 | - .addDictionaryMember("dict", obj.getDict().getJSON(m->json_version, true)); | |
| 967 | - } else { | |
| 968 | - j.addDictionaryMember("value", obj.getJSON(m->json_version, true)); | |
| 969 | - } | |
| 970 | - JSON::writeDictionaryItem(p, first, key, j, 2); | |
| 971 | - } | |
| 972 | -} | |
| 973 | - | |
| 974 | -void | |
| 975 | 958 | QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) |
| 976 | 959 | { |
| 977 | 960 | if (m->json_version == 1) { |
| ... | ... | @@ -982,16 +965,17 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) |
| 982 | 965 | auto wanted_og = getWantedJSONObjects(); |
| 983 | 966 | for (auto& obj: pdf.getAllObjects()) { |
| 984 | 967 | std::string key = obj.unparse(); |
| 985 | - if (m->json_version > 1) { | |
| 986 | - key = "obj:" + key; | |
| 987 | - } | |
| 968 | + | |
| 988 | 969 | if (all_objects || wanted_og.count(obj.getObjGen())) { |
| 989 | - doJSONObject(p, first_object, key, obj); | |
| 970 | + JSON::writeDictionaryKey(p, first_object, obj.unparse(), 2); | |
| 971 | + obj.writeJSON(1, p, true, 2); | |
| 972 | + first_object = false; | |
| 990 | 973 | } |
| 991 | 974 | } |
| 992 | 975 | if (all_objects || m->json_objects.count("trailer")) { |
| 993 | - auto trailer = pdf.getTrailer(); | |
| 994 | - doJSONObject(p, first_object, "trailer", trailer); | |
| 976 | + JSON::writeDictionaryKey(p, first_object, "trailer", 2); | |
| 977 | + pdf.getTrailer().writeJSON(1, p, true, 2); | |
| 978 | + first_object = false; | |
| 995 | 979 | } |
| 996 | 980 | JSON::writeDictionaryClose(p, first_object, 1); |
| 997 | 981 | } else { |
| ... | ... | @@ -3097,9 +3081,10 @@ QPDFJob::writeOutfile(QPDF& pdf) |
| 3097 | 3081 | try { |
| 3098 | 3082 | QUtil::remove_file(backup.c_str()); |
| 3099 | 3083 | } catch (QPDFSystemError& e) { |
| 3100 | - *m->log->getError() << m->message_prefix << ": unable to delete original file (" | |
| 3101 | - << e.what() << ");" << " original file left in " << backup | |
| 3102 | - << ", but the input was successfully replaced\n"; | |
| 3084 | + *m->log->getError() | |
| 3085 | + << m->message_prefix << ": unable to delete original file (" << e.what() << ");" | |
| 3086 | + << " original file left in " << backup | |
| 3087 | + << ", but the input was successfully replaced\n"; | |
| 3103 | 3088 | } |
| 3104 | 3089 | } |
| 3105 | 3090 | } | ... | ... |