aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-03 22:10:27 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-05 20:56:19 +0200
commit77e889495f7c513ba8677df5fe662f08053709eb (patch)
tree06191e152c3d7a4e398837ebc4f87038b1797bc9 /examples
parent12f1eb15ca3fed6310402847559a7c99d3c77847 (diff)
downloadqpdf-77e889495f7c513ba8677df5fe662f08053709eb.tar.zst
Update some code manually to get better formatting results
Add comments to force line breaks, parenthesize function arguments that are contatenated strings, etc. -- these kinds of changes improve clang-format's results and also cause emacs cc-mode to match clang-format. After this type of change, most of the time, when clang-format and emacs disagree, clang-format is better.
Diffstat (limited to 'examples')
-rw-r--r--examples/pdf-attach-file.cc96
-rw-r--r--examples/pdf-create.cc28
2 files changed, 66 insertions, 58 deletions
diff --git a/examples/pdf-attach-file.cc b/examples/pdf-attach-file.cc
index 964d247d..eb12a002 100644
--- a/examples/pdf-attach-file.cc
+++ b/examples/pdf-attach-file.cc
@@ -45,25 +45,29 @@ process(
// Create an indirect object for the built-in Helvetica font. This
// uses the qpdf literal syntax introduced in qpdf 10.6.
- auto f1 = q.makeIndirectObject("<<"
- " /Type /Font"
- " /Subtype /Type1"
- " /Name /F1"
- " /BaseFont /Helvetica"
- " /Encoding /WinAnsiEncoding"
- ">>"_qpdf);
+ auto f1 = q.makeIndirectObject(
+ // force line-break
+ "<<"
+ " /Type /Font"
+ " /Subtype /Type1"
+ " /Name /F1"
+ " /BaseFont /Helvetica"
+ " /Encoding /WinAnsiEncoding"
+ ">>"_qpdf);
// Create a resources dictionary with fonts. This uses the new
// parse introduced in qpdf 10.2 that takes a QPDF* and allows
// indirect object references.
- auto resources = q.makeIndirectObject(QPDFObjectHandle::parse(
- &q,
- "<<"
- " /Font <<"
- " /F1 " +
- f1.unparse() +
- " >>"
- ">>"));
+ auto resources = q.makeIndirectObject(
+ // line-break
+ QPDFObjectHandle::parse(
+ &q,
+ ("<<"
+ " /Font <<"
+ " /F1 " +
+ f1.unparse() +
+ " >>"
+ ">>")));
// Create a file spec.
std::string key = QUtil::path_basename(attachment);
@@ -108,45 +112,45 @@ process(
apdict.replaceKey("/BBox", "[ 0 0 20 20 ]"_qpdf);
auto annot = q.makeIndirectObject(QPDFObjectHandle::parse(
&q,
- "<<"
- " /AP <<"
- " /N " +
- ap.unparse() +
- " >>"
- " /Contents " +
- QPDFObjectHandle::newUnicodeString(attachment).unparse() +
- " /FS " + fs.getObjectHandle().unparse() + " /NM " +
- QPDFObjectHandle::newUnicodeString(attachment).unparse() +
- " /Rect [ 72 700 92 720 ]"
- " /Subtype /FileAttachment"
- " /Type /Annot"
- ">>"));
+ ("<<"
+ " /AP <<"
+ " /N " +
+ ap.unparse() +
+ " >>"
+ " /Contents " +
+ QPDFObjectHandle::newUnicodeString(attachment).unparse() + " /FS " +
+ fs.getObjectHandle().unparse() + " /NM " +
+ QPDFObjectHandle::newUnicodeString(attachment).unparse() +
+ " /Rect [ 72 700 92 720 ]"
+ " /Subtype /FileAttachment"
+ " /Type /Annot"
+ ">>")));
// Generate contents for the page.
auto contents = QPDFObjectHandle::newStream(
&q,
- "q\n"
- "BT\n"
- " 102 700 Td\n"
- " /F1 16 Tf\n"
- " (Here is an attachment.) Tj\n"
- "ET\n"
- "Q\n");
+ ("q\n"
+ "BT\n"
+ " 102 700 Td\n"
+ " /F1 16 Tf\n"
+ " (Here is an attachment.) Tj\n"
+ "ET\n"
+ "Q\n"));
// Create the page object.
auto page = QPDFObjectHandle::parse(
&q,
- "<<"
- " /Annots [ " +
- annot.unparse() +
- " ]"
- " /Contents " +
- contents.unparse() +
- " /MediaBox [0 0 612 792]"
- " /Resources " +
- resources.unparse() +
- " /Type /Page"
- ">>");
+ ("<<"
+ " /Annots [ " +
+ annot.unparse() +
+ " ]"
+ " /Contents " +
+ contents.unparse() +
+ " /MediaBox [0 0 612 792]"
+ " /Resources " +
+ resources.unparse() +
+ " /Type /Page"
+ ">>"));
// Add the page.
q.addPage(page, true);
diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc
index 5274d0a2..b070b3aa 100644
--- a/examples/pdf-create.cc
+++ b/examples/pdf-create.cc
@@ -180,11 +180,13 @@ add_page(
size_t width = p->getWidth();
size_t height = p->getHeight();
QPDFObjectHandle image = QPDFObjectHandle::newStream(&pdf);
- auto image_dict = "<<"
- " /Type /XObject"
- " /Subtype /Image"
- " /BitsPerComponent 8"
- ">>"_qpdf;
+ auto image_dict =
+ // line-break
+ "<<"
+ " /Type /XObject"
+ " /Subtype /Image"
+ " /BitsPerComponent 8"
+ ">>"_qpdf;
image_dict.replaceKey("/ColorSpace", newName(color_space));
image_dict.replaceKey("/Width", newInteger(width));
image_dict.replaceKey("/Height", newInteger(height));
@@ -352,13 +354,15 @@ create_pdf(char const* filename)
// Add an indirect object to contain a font descriptor for the
// built-in Helvetica font.
- QPDFObjectHandle font = pdf.makeIndirectObject("<<"
- " /Type /Font"
- " /Subtype /Type1"
- " /Name /F1"
- " /BaseFont /Helvetica"
- " /Encoding /WinAnsiEncoding"
- ">>"_qpdf);
+ QPDFObjectHandle font = pdf.makeIndirectObject(
+ // line-break
+ "<<"
+ " /Type /Font"
+ " /Subtype /Type1"
+ " /Name /F1"
+ " /BaseFont /Helvetica"
+ " /Encoding /WinAnsiEncoding"
+ ">>"_qpdf);
std::vector<std::string> color_spaces;
color_spaces.push_back("/DeviceCMYK");