mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-03 19:00:51 +00:00
Refactor QPDFJob::doJSONObjects
This commit is contained in:
parent
f0bc2f11ef
commit
4f54508f7f
|
@ -551,7 +551,6 @@ class QPDFJob
|
||||||
// JSON
|
// JSON
|
||||||
void doJSON(QPDF& pdf, Pipeline*);
|
void doJSON(QPDF& pdf, Pipeline*);
|
||||||
QPDFObjGen::set getWantedJSONObjects();
|
QPDFObjGen::set getWantedJSONObjects();
|
||||||
void doJSONObject(Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle&);
|
|
||||||
void doJSONObjects(Pipeline* p, bool& first, QPDF& pdf);
|
void doJSONObjects(Pipeline* p, bool& first, QPDF& pdf);
|
||||||
void doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf);
|
void doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf);
|
||||||
void doJSONPages(Pipeline* p, bool& first, QPDF& pdf);
|
void doJSONPages(Pipeline* p, bool& first, QPDF& pdf);
|
||||||
|
|
|
@ -954,23 +954,6 @@ QPDFJob::getWantedJSONObjects()
|
||||||
return wanted_og;
|
return wanted_og;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
QPDFJob::doJSONObject(Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj)
|
|
||||||
{
|
|
||||||
if (m->json_version == 1) {
|
|
||||||
JSON::writeDictionaryItem(p, first, key, obj.getJSON(1, true), 2);
|
|
||||||
} else {
|
|
||||||
auto j = JSON::makeDictionary();
|
|
||||||
if (obj.isStream()) {
|
|
||||||
j.addDictionaryMember("stream", JSON::makeDictionary())
|
|
||||||
.addDictionaryMember("dict", obj.getDict().getJSON(m->json_version, true));
|
|
||||||
} else {
|
|
||||||
j.addDictionaryMember("value", obj.getJSON(m->json_version, true));
|
|
||||||
}
|
|
||||||
JSON::writeDictionaryItem(p, first, key, j, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf)
|
QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf)
|
||||||
{
|
{
|
||||||
|
@ -982,16 +965,17 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf)
|
||||||
auto wanted_og = getWantedJSONObjects();
|
auto wanted_og = getWantedJSONObjects();
|
||||||
for (auto& obj: pdf.getAllObjects()) {
|
for (auto& obj: pdf.getAllObjects()) {
|
||||||
std::string key = obj.unparse();
|
std::string key = obj.unparse();
|
||||||
if (m->json_version > 1) {
|
|
||||||
key = "obj:" + key;
|
|
||||||
}
|
|
||||||
if (all_objects || wanted_og.count(obj.getObjGen())) {
|
if (all_objects || wanted_og.count(obj.getObjGen())) {
|
||||||
doJSONObject(p, first_object, key, obj);
|
JSON::writeDictionaryKey(p, first_object, obj.unparse(), 2);
|
||||||
|
obj.writeJSON(1, p, true, 2);
|
||||||
|
first_object = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (all_objects || m->json_objects.count("trailer")) {
|
if (all_objects || m->json_objects.count("trailer")) {
|
||||||
auto trailer = pdf.getTrailer();
|
JSON::writeDictionaryKey(p, first_object, "trailer", 2);
|
||||||
doJSONObject(p, first_object, "trailer", trailer);
|
pdf.getTrailer().writeJSON(1, p, true, 2);
|
||||||
|
first_object = false;
|
||||||
}
|
}
|
||||||
JSON::writeDictionaryClose(p, first_object, 1);
|
JSON::writeDictionaryClose(p, first_object, 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3097,8 +3081,9 @@ QPDFJob::writeOutfile(QPDF& pdf)
|
||||||
try {
|
try {
|
||||||
QUtil::remove_file(backup.c_str());
|
QUtil::remove_file(backup.c_str());
|
||||||
} catch (QPDFSystemError& e) {
|
} catch (QPDFSystemError& e) {
|
||||||
*m->log->getError() << m->message_prefix << ": unable to delete original file ("
|
*m->log->getError()
|
||||||
<< e.what() << ");" << " original file left in " << backup
|
<< m->message_prefix << ": unable to delete original file (" << e.what() << ");"
|
||||||
|
<< " original file left in " << backup
|
||||||
<< ", but the input was successfully replaced\n";
|
<< ", but the input was successfully replaced\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user