diff options
author | Tobias Koenig <tobias.koenig@kdab.com> | 2017-02-14 08:53:11 +0100 |
---|---|---|
committer | Tobias Koenig <tobias.koenig@kdab.com> | 2017-02-14 21:31:22 +0000 |
commit | 146f6d261ba743b643825d62cdb2deb1e701d3d2 (patch) | |
tree | a7c8371eff2580c07fdd3526d2e43efc40e26d5f /src/gui/painting/qpdf.cpp | |
parent | f0ee4ed0a28d274c7a8efeb9e6ac8642e020e2cc (diff) |
Make output of QPdfWriter more PDF/A-1b compliant
Add the recommended comment line after the header line, which contains
4 bytes with character codes > 128 (see PDF 32000 7.5.2), add the missing
EOL markers in front of any 'endstream' and 'endobj' keywords and modify
writeString to use '()' for empty strings (no UTF-16 encoding needed in that case).
Change-Id: I17aabde0ba06061ba14e37405e02edf47f3ddd81
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/painting/qpdf.cpp')
-rw-r--r-- | src/gui/painting/qpdf.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 7b8bae1642..bac9740892 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1465,6 +1465,7 @@ void QPdfEnginePrivate::writeHeader() addXrefEntry(0,false); xprintf("%%PDF-1.4\n"); + xprintf("%%\303\242\303\243\n"); writeInfo(); @@ -1597,7 +1598,7 @@ void QPdfEnginePrivate::embedFont(QFontSubset *font) "/CapHeight " << properties.capHeight.toReal()*scale << "\n" "/StemV " << properties.lineWidth.toReal()*scale << "\n" "/FontFile2 " << fontstream << "0 R\n" - ">> endobj\n"; + ">>\nendobj\n"; write(descriptor); } { @@ -1615,7 +1616,7 @@ void QPdfEnginePrivate::embedFont(QFontSubset *font) "stream\n"; write(header); int len = writeCompressed(fontData); - write("endstream\n" + write("\nendstream\n" "endobj\n"); addXrefEntry(length_object); xprintf("%d\n" @@ -1642,7 +1643,7 @@ void QPdfEnginePrivate::embedFont(QFontSubset *font) xprintf("<< /Length %d >>\n" "stream\n", touc.length()); write(touc); - write("endstream\n" + write("\nendstream\n" "endobj\n"); } { @@ -1748,7 +1749,7 @@ void QPdfEnginePrivate::writePage() xprintf("stream\n"); QIODevice *content = currentPage->stream(); int len = writeCompressed(content); - xprintf("endstream\n" + xprintf("\nendstream\n" "endobj\n"); addXrefEntry(pageStreamLength); @@ -1794,7 +1795,13 @@ int QPdfEnginePrivate::addXrefEntry(int object, bool printostr) return object; } -void QPdfEnginePrivate::printString(const QString &string) { +void QPdfEnginePrivate::printString(const QString &string) +{ + if (string.isEmpty()) { + write("()"); + return; + } + // The 'text string' type in PDF is encoded either as PDFDocEncoding, or // Unicode UTF-16 with a Unicode byte order mark as the first character // (0xfeff), with the high-order byte first. |