aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFWriter.cc
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-03-20 23:53:51 +0100
committerm-holger <m-holger@kubitscheck.org>2023-03-21 11:59:05 +0100
commitce66604290a3a845c57100a8a675f43be4630d18 (patch)
tree223a864690d72f56ac172e6d234655fd1915f2a2 /libqpdf/QPDFWriter.cc
parentf89196b6c898ac8fa7ce3fb477d0c4b03d0ece4f (diff)
downloadqpdf-ce66604290a3a845c57100a8a675f43be4630d18.tar.zst
Tune indentations in QPDFWriter::unparseObject
Set indent differently for qdf and non-qdf files. Combine with preceding newline for qdf files.
Diffstat (limited to 'libqpdf/QPDFWriter.cc')
-rw-r--r--libqpdf/QPDFWriter.cc39
1 files changed, 17 insertions, 22 deletions
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index 8287412c..de1aa45b 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -1441,8 +1441,13 @@ QPDFWriter::unparseObject(
if (level < 0) {
throw std::logic_error("invalid level in QPDFWriter::unparseObject");
}
-
- std::string const indent(static_cast<size_t>(2 * level), ' ');
+ // For non-qdf, "indent" is a single space between tokens.
+ // 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) {
// 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
// doesn't make the files that much bigger.
writeString("[");
- writeStringQDF("\n");
for (auto const& item: object.getArrayAsVector()) {
- writeStringQDF(indent);
+ writeString(indent);
writeStringQDF(" ");
- writeStringNoQDF(" ");
unparseChild(item, level + 1, child_flags);
- writeStringQDF("\n");
}
- writeStringQDF(indent);
- writeStringNoQDF(" ");
+ writeString(indent);
writeString("]");
} else if (tc == ::ot_dictionary) {
// Make a shallow copy of this object so we can modify it
@@ -1619,14 +1620,12 @@ QPDFWriter::unparseObject(
}
writeString("<<");
- writeStringQDF("\n");
for (auto& item: object.getDictAsMap()) {
if (!item.second.isNull()) {
auto const& key = item.first;
- writeStringQDF(indent);
+ writeString(indent);
writeStringQDF(" ");
- writeStringNoQDF(" ");
writeString(QPDF_Name::normalizeName(key));
writeString(" ");
if (key == "/Contents" && object.isDictionaryOfType("/Sig") &&
@@ -1639,14 +1638,13 @@ QPDFWriter::unparseObject(
} else {
unparseChild(item.second, level + 1, child_flags);
}
- writeStringQDF("\n");
}
}
if (flags & f_stream) {
- writeStringQDF(indent);
- writeStringQDF(" ");
- writeString(" /Length ");
+ writeString(indent);
+ writeStringQDF(" ");
+ writeString("/Length ");
if (this->m->direct_stream_lengths) {
writeString(std::to_string(stream_length));
@@ -1654,17 +1652,14 @@ QPDFWriter::unparseObject(
writeString(std::to_string(this->m->cur_stream_length_id));
writeString(" 0 R");
}
- writeStringQDF("\n");
if (compress && (flags & f_filtered)) {
- writeStringQDF(indent);
- writeStringQDF(" ");
- writeString(" /Filter /FlateDecode");
- writeStringQDF("\n");
+ writeString(indent);
+ writeStringQDF(" ");
+ writeString("/Filter /FlateDecode");
}
}
- writeStringQDF(indent);
- writeStringNoQDF(" ");
+ writeString(indent);
writeString(">>");
} else if (tc == ::ot_stream) {
// Write stream data to a buffer.