mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
Merge pull request #932 from m-holger/wr_upo
Tune indentations in QPDFWriter::unparseObject
This commit is contained in:
commit
5981b25e98
@ -1441,8 +1441,13 @@ QPDFWriter::unparseObject(
|
|||||||
if (level < 0) {
|
if (level < 0) {
|
||||||
throw std::logic_error("invalid level in QPDFWriter::unparseObject");
|
throw std::logic_error("invalid level in QPDFWriter::unparseObject");
|
||||||
}
|
}
|
||||||
|
// For non-qdf, "indent" is a single space between tokens.
|
||||||
std::string const indent(static_cast<size_t>(2 * level), ' ');
|
// For qdf, indent includes the preceding newline.
|
||||||
|
std::string indent = " ";
|
||||||
|
if (m->qdf_mode) {
|
||||||
|
indent.append(static_cast<size_t>(2 * level), ' ');
|
||||||
|
indent[0] = '\n';
|
||||||
|
}
|
||||||
|
|
||||||
if (auto const tc = object.getTypeCode(); tc == ::ot_array) {
|
if (auto const tc = object.getTypeCode(); tc == ::ot_array) {
|
||||||
// Note: PDF spec 1.4 implementation note 121 states that
|
// Note: PDF spec 1.4 implementation note 121 states that
|
||||||
@ -1451,16 +1456,12 @@ QPDFWriter::unparseObject(
|
|||||||
// unconditionally for all arrays because it looks nicer and
|
// unconditionally for all arrays because it looks nicer and
|
||||||
// doesn't make the files that much bigger.
|
// doesn't make the files that much bigger.
|
||||||
writeString("[");
|
writeString("[");
|
||||||
writeStringQDF("\n");
|
|
||||||
for (auto const& item: object.getArrayAsVector()) {
|
for (auto const& item: object.getArrayAsVector()) {
|
||||||
writeStringQDF(indent);
|
writeString(indent);
|
||||||
writeStringQDF(" ");
|
writeStringQDF(" ");
|
||||||
writeStringNoQDF(" ");
|
|
||||||
unparseChild(item, level + 1, child_flags);
|
unparseChild(item, level + 1, child_flags);
|
||||||
writeStringQDF("\n");
|
|
||||||
}
|
}
|
||||||
writeStringQDF(indent);
|
writeString(indent);
|
||||||
writeStringNoQDF(" ");
|
|
||||||
writeString("]");
|
writeString("]");
|
||||||
} else if (tc == ::ot_dictionary) {
|
} else if (tc == ::ot_dictionary) {
|
||||||
// Make a shallow copy of this object so we can modify it
|
// Make a shallow copy of this object so we can modify it
|
||||||
@ -1619,14 +1620,12 @@ QPDFWriter::unparseObject(
|
|||||||
}
|
}
|
||||||
|
|
||||||
writeString("<<");
|
writeString("<<");
|
||||||
writeStringQDF("\n");
|
|
||||||
|
|
||||||
for (auto& item: object.getDictAsMap()) {
|
for (auto& item: object.getDictAsMap()) {
|
||||||
if (!item.second.isNull()) {
|
if (!item.second.isNull()) {
|
||||||
auto const& key = item.first;
|
auto const& key = item.first;
|
||||||
writeStringQDF(indent);
|
writeString(indent);
|
||||||
writeStringQDF(" ");
|
writeStringQDF(" ");
|
||||||
writeStringNoQDF(" ");
|
|
||||||
writeString(QPDF_Name::normalizeName(key));
|
writeString(QPDF_Name::normalizeName(key));
|
||||||
writeString(" ");
|
writeString(" ");
|
||||||
if (key == "/Contents" && object.isDictionaryOfType("/Sig") &&
|
if (key == "/Contents" && object.isDictionaryOfType("/Sig") &&
|
||||||
@ -1639,14 +1638,13 @@ QPDFWriter::unparseObject(
|
|||||||
} else {
|
} else {
|
||||||
unparseChild(item.second, level + 1, child_flags);
|
unparseChild(item.second, level + 1, child_flags);
|
||||||
}
|
}
|
||||||
writeStringQDF("\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & f_stream) {
|
if (flags & f_stream) {
|
||||||
writeStringQDF(indent);
|
writeString(indent);
|
||||||
writeStringQDF(" ");
|
writeStringQDF(" ");
|
||||||
writeString(" /Length ");
|
writeString("/Length ");
|
||||||
|
|
||||||
if (this->m->direct_stream_lengths) {
|
if (this->m->direct_stream_lengths) {
|
||||||
writeString(std::to_string(stream_length));
|
writeString(std::to_string(stream_length));
|
||||||
@ -1654,17 +1652,14 @@ QPDFWriter::unparseObject(
|
|||||||
writeString(std::to_string(this->m->cur_stream_length_id));
|
writeString(std::to_string(this->m->cur_stream_length_id));
|
||||||
writeString(" 0 R");
|
writeString(" 0 R");
|
||||||
}
|
}
|
||||||
writeStringQDF("\n");
|
|
||||||
if (compress && (flags & f_filtered)) {
|
if (compress && (flags & f_filtered)) {
|
||||||
writeStringQDF(indent);
|
writeString(indent);
|
||||||
writeStringQDF(" ");
|
writeStringQDF(" ");
|
||||||
writeString(" /Filter /FlateDecode");
|
writeString("/Filter /FlateDecode");
|
||||||
writeStringQDF("\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeStringQDF(indent);
|
writeString(indent);
|
||||||
writeStringNoQDF(" ");
|
|
||||||
writeString(">>");
|
writeString(">>");
|
||||||
} else if (tc == ::ot_stream) {
|
} else if (tc == ::ot_stream) {
|
||||||
// Write stream data to a buffer.
|
// Write stream data to a buffer.
|
||||||
|
Loading…
Reference in New Issue
Block a user