summaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <jberkenbilt@users.noreply.github.com>2023-04-01 15:37:55 +0200
committerGitHub <noreply@github.com>2023-04-01 15:37:55 +0200
commit5981b25e984aed7a75494b552e4f934f331c0c3d (patch)
treee2e9f2817ef9f40459f4aa870aefbcbe9f7da551 /libqpdf
parentef6f5a97f42a6d59abc9ca81ae4e9ab3b7168f55 (diff)
parentce66604290a3a845c57100a8a675f43be4630d18 (diff)
downloadqpdf-5981b25e984aed7a75494b552e4f934f331c0c3d.tar.zst
Merge pull request #932 from m-holger/wr_upo
Tune indentations in QPDFWriter::unparseObject
Diffstat (limited to 'libqpdf')
-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.