From 12f1eb15ca3fed6310402847559a7c99d3c77847 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 2 Apr 2022 17:14:10 -0400 Subject: Programmatically apply new formatting to code Run this: for i in **/*.cc **/*.c **/*.h **/*.hh; do clang-format < $i >| $i.new && mv $i.new $i done --- examples/pdf-double-page-size.cc | 56 ++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'examples/pdf-double-page-size.cc') diff --git a/examples/pdf-double-page-size.cc b/examples/pdf-double-page-size.cc index a2f79301..37e07ff8 100644 --- a/examples/pdf-double-page-size.cc +++ b/examples/pdf-double-page-size.cc @@ -1,16 +1,17 @@ -#include -#include -#include +#include #include #include #include -#include -#include #include +#include +#include +#include +#include static char const* whoami = 0; -void usage() +void +usage() { std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl @@ -21,45 +22,43 @@ void usage() // If there is a box of name box_name, replace it with a new box whose // elements are double the values of the original box. -static void doubleBoxSize(QPDFPageObjectHelper& page, char const* box_name) +static void +doubleBoxSize(QPDFPageObjectHelper& page, char const* box_name) { // We need to use getAttribute rather than getKey as some boxes could // be inherited. auto box = page.getAttribute(box_name, true); - if (box.isNull()) - { + if (box.isNull()) { return; } - if (! box.isRectangle()) - { - throw std::runtime_error(std::string("box ") + box_name + - " is not an array of four elements"); + if (!box.isRectangle()) { + throw std::runtime_error( + std::string("box ") + box_name + + " is not an array of four elements"); } std::vector doubled; - for (auto& item : box.aitems()) - { + for (auto& item : box.aitems()) { doubled.push_back( QPDFObjectHandle::newReal(item.getNumericValue() * 2.0, 2)); } - page.getObjectHandle() - .replaceKey(box_name, QPDFObjectHandle::newArray(doubled)); + page.getObjectHandle().replaceKey( + box_name, QPDFObjectHandle::newArray(doubled)); } -int main(int argc, char* argv[]) +int +main(int argc, char* argv[]) { whoami = QUtil::getWhoami(argv[0]); // For test suite bool static_id = false; - if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0)) - { + if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0)) { static_id = true; --argc; ++argv; } - if (! ((argc == 3) || (argc == 4))) - { + if (!((argc == 3) || (argc == 4))) { usage(); } @@ -70,13 +69,11 @@ int main(int argc, char* argv[]) // Text to prepend to each page's contents std::string content = "2 0 0 2 0 0 cm\n"; - try - { + try { QPDF qpdf; qpdf.processFile(infilename, password); - for (auto& page : QPDFPageDocumentHelper(qpdf).getAllPages()) - { + for (auto& page : QPDFPageDocumentHelper(qpdf).getAllPages()) { // Prepend the buffer to the page's contents page.addPageContents( QPDFObjectHandle::newStream(&qpdf, content), true); @@ -91,8 +88,7 @@ int main(int argc, char* argv[]) // Write out a new file QPDFWriter w(qpdf, outfilename); - if (static_id) - { + if (static_id) { // For the test suite, uncompress streams and use static IDs. w.setStaticID(true); // for testing only w.setStreamDataMode(qpdf_s_uncompress); @@ -100,9 +96,7 @@ int main(int argc, char* argv[]) w.write(); std::cout << whoami << ": new file written to " << outfilename << std::endl; - } - catch (std::exception &e) - { + } catch (std::exception& e) { std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl; exit(2); -- cgit v1.2.3-54-g00ecf