aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2023-05-21 19:35:09 +0200
committerJay Berkenbilt <ejb@ql.org>2023-05-21 19:35:09 +0200
commit60965d5f4d608bdccc2ffd4e8753e12cbbbd71d2 (patch)
treea707602da466c02ff1a54b3263c3a881cd7204a4
parent6b077332d38c093de2618d5e1481b42222106065 (diff)
downloadqpdf-60965d5f4d608bdccc2ffd4e8753e12cbbbd71d2.tar.zst
Rerun clang-format
-rw-r--r--examples/pdf-attach-file.cc3
-rw-r--r--examples/pdf-bookmarks.cc25
-rw-r--r--examples/pdf-c-objects.c14
-rw-r--r--examples/pdf-count-strings.cc3
-rw-r--r--examples/pdf-create.cc35
-rw-r--r--examples/pdf-custom-filter.cc33
-rw-r--r--examples/pdf-double-page-size.cc18
-rw-r--r--examples/pdf-filter-tokens.cc23
-rw-r--r--examples/pdf-invert-images.cc30
-rw-r--r--examples/pdf-linearize.c8
-rw-r--r--examples/pdf-mod-info.cc9
-rw-r--r--examples/pdf-name-number-tree.cc32
-rw-r--r--examples/pdf-overlay-page.cc7
-rw-r--r--examples/pdf-parse-content.cc9
-rw-r--r--examples/pdf-set-form-values.cc12
-rw-r--r--examples/pdf-split-pages.cc6
-rw-r--r--examples/qpdfjob-c-save-attachment.c3
-rw-r--r--examples/qpdfjob-remove-annotations.cc13
-rw-r--r--examples/qpdfjob-save-attachment.cc3
-rw-r--r--fuzz/qpdf_fuzzer.cc7
-rw-r--r--fuzz/standalone_fuzz_target_runner.cc3
-rw-r--r--fuzz/tiffpredictor_fuzzer.cc3
-rw-r--r--include/qpdf/BufferInputSource.hh6
-rw-r--r--include/qpdf/Constants.h5
-rw-r--r--include/qpdf/InputSource.hh15
-rw-r--r--include/qpdf/JSON.hh25
-rw-r--r--include/qpdf/Pl_Function.hh9
-rw-r--r--include/qpdf/Pl_QPDFTokenizer.hh4
-rw-r--r--include/qpdf/QIntC.hh41
-rw-r--r--include/qpdf/QPDF.hh168
-rw-r--r--include/qpdf/QPDFAcroFormDocumentHelper.hh23
-rw-r--r--include/qpdf/QPDFAnnotationObjectHelper.hh3
-rw-r--r--include/qpdf/QPDFCryptoImpl.hh9
-rw-r--r--include/qpdf/QPDFCryptoProvider.hh3
-rw-r--r--include/qpdf/QPDFEFStreamObjectHelper.hh6
-rw-r--r--include/qpdf/QPDFEmbeddedFileDocumentHelper.hh9
-rw-r--r--include/qpdf/QPDFFileSpecObjectHelper.hh12
-rw-r--r--include/qpdf/QPDFFormFieldObjectHelper.hh6
-rw-r--r--include/qpdf/QPDFJob.hh45
-rw-r--r--include/qpdf/QPDFLogger.hh3
-rw-r--r--include/qpdf/QPDFMatrix.hh3
-rw-r--r--include/qpdf/QPDFNameTreeObjectHelper.hh3
-rw-r--r--include/qpdf/QPDFNumberTreeObjectHelper.hh6
-rw-r--r--include/qpdf/QPDFObjectHandle.hh81
-rw-r--r--include/qpdf/QPDFPageDocumentHelper.hh8
-rw-r--r--include/qpdf/QPDFPageObjectHelper.hh40
-rw-r--r--include/qpdf/QPDFSystemError.hh3
-rw-r--r--include/qpdf/QPDFTokenizer.hh9
-rw-r--r--include/qpdf/QPDFWriter.hh18
-rw-r--r--include/qpdf/QUtil.hh68
-rw-r--r--include/qpdf/qpdf-c.h91
-rw-r--r--include/qpdf/qpdfjob-c.h10
-rw-r--r--include/qpdf/qpdflogger-c.h18
-rw-r--r--libqpdf/AES_PDF_native.cc9
-rw-r--r--libqpdf/BitStream.cc9
-rw-r--r--libqpdf/BufferInputSource.cc12
-rw-r--r--libqpdf/ContentNormalizer.cc12
-rw-r--r--libqpdf/FileInputSource.cc7
-rw-r--r--libqpdf/InputSource.cc39
-rw-r--r--libqpdf/InsecureRandomDataProvider.cc3
-rw-r--r--libqpdf/JSON.cc137
-rw-r--r--libqpdf/JSONHandler.cc35
-rw-r--r--libqpdf/MD5.cc11
-rw-r--r--libqpdf/NNTree.cc112
-rw-r--r--libqpdf/OffsetInputSource.cc9
-rw-r--r--libqpdf/PDFVersion.cc9
-rw-r--r--libqpdf/Pipeline.cc3
-rw-r--r--libqpdf/Pl_AES_PDF.cc12
-rw-r--r--libqpdf/Pl_ASCII85Decoder.cc14
-rw-r--r--libqpdf/Pl_ASCIIHexDecoder.cc5
-rw-r--r--libqpdf/Pl_Base64.cc9
-rw-r--r--libqpdf/Pl_Buffer.cc3
-rw-r--r--libqpdf/Pl_DCT.cc40
-rw-r--r--libqpdf/Pl_Flate.cc34
-rw-r--r--libqpdf/Pl_Function.cc12
-rw-r--r--libqpdf/Pl_LZWDecoder.cc18
-rw-r--r--libqpdf/Pl_MD5.cc3
-rw-r--r--libqpdf/Pl_OStream.cc3
-rw-r--r--libqpdf/Pl_PNGFilter.cc35
-rw-r--r--libqpdf/Pl_QPDFTokenizer.cc17
-rw-r--r--libqpdf/Pl_RC4.cc7
-rw-r--r--libqpdf/Pl_RunLength.cc17
-rw-r--r--libqpdf/Pl_SHA2.cc9
-rw-r--r--libqpdf/Pl_StdioFile.cc6
-rw-r--r--libqpdf/Pl_TIFFPredictor.cc23
-rw-r--r--libqpdf/QPDF.cc352
-rw-r--r--libqpdf/QPDFAcroFormDocumentHelper.cc131
-rw-r--r--libqpdf/QPDFAnnotationObjectHelper.cc12
-rw-r--r--libqpdf/QPDFArgParser.cc134
-rw-r--r--libqpdf/QPDFCryptoProvider.cc6
-rw-r--r--libqpdf/QPDFCrypto_gnutls.cc43
-rw-r--r--libqpdf/QPDFCrypto_native.cc10
-rw-r--r--libqpdf/QPDFCrypto_openssl.cc24
-rw-r--r--libqpdf/QPDFEFStreamObjectHelper.cc31
-rw-r--r--libqpdf/QPDFEmbeddedFileDocumentHelper.cc9
-rw-r--r--libqpdf/QPDFFileSpecObjectHelper.cc6
-rw-r--r--libqpdf/QPDFFormFieldObjectHelper.cc133
-rw-r--r--libqpdf/QPDFJob.cc716
-rw-r--r--libqpdf/QPDFJob_argv.cc14
-rw-r--r--libqpdf/QPDFJob_config.cc24
-rw-r--r--libqpdf/QPDFJob_json.cc27
-rw-r--r--libqpdf/QPDFLogger.cc8
-rw-r--r--libqpdf/QPDFMatrix.cc7
-rw-r--r--libqpdf/QPDFNameTreeObjectHelper.cc24
-rw-r--r--libqpdf/QPDFNumberTreeObjectHelper.cc15
-rw-r--r--libqpdf/QPDFObjectHandle.cc286
-rw-r--r--libqpdf/QPDFOutlineDocumentHelper.cc6
-rw-r--r--libqpdf/QPDFOutlineObjectHelper.cc3
-rw-r--r--libqpdf/QPDFPageDocumentHelper.cc39
-rw-r--r--libqpdf/QPDFPageLabelDocumentHelper.cc14
-rw-r--r--libqpdf/QPDFPageObjectHelper.cc189
-rw-r--r--libqpdf/QPDFParser.cc46
-rw-r--r--libqpdf/QPDFSystemError.cc3
-rw-r--r--libqpdf/QPDFTokenizer.cc43
-rw-r--r--libqpdf/QPDFValue.cc12
-rw-r--r--libqpdf/QPDFWriter.cc415
-rw-r--r--libqpdf/QPDFXRefEntry.cc6
-rw-r--r--libqpdf/QPDF_Array.cc31
-rw-r--r--libqpdf/QPDF_Destroyed.cc9
-rw-r--r--libqpdf/QPDF_Dictionary.cc15
-rw-r--r--libqpdf/QPDF_Name.cc5
-rw-r--r--libqpdf/QPDF_Null.cc8
-rw-r--r--libqpdf/QPDF_Real.cc10
-rw-r--r--libqpdf/QPDF_Reserved.cc6
-rw-r--r--libqpdf/QPDF_Stream.cc88
-rw-r--r--libqpdf/QPDF_String.cc16
-rw-r--r--libqpdf/QPDF_Unresolved.cc9
-rw-r--r--libqpdf/QPDF_encryption.cc208
-rw-r--r--libqpdf/QPDF_json.cc90
-rw-r--r--libqpdf/QPDF_linearization.cc388
-rw-r--r--libqpdf/QPDF_optimization.cc26
-rw-r--r--libqpdf/QPDF_pages.cc27
-rw-r--r--libqpdf/QUtil.cc288
-rw-r--r--libqpdf/RC4_native.cc6
-rw-r--r--libqpdf/SF_FlateLzwDecode.cc10
-rw-r--r--libqpdf/SHA2_native.cc9
-rw-r--r--libqpdf/SecureRandomDataProvider.cc20
-rw-r--r--libqpdf/qpdf-c.cc510
-rw-r--r--libqpdf/qpdf/JSONHandler.hh17
-rw-r--r--libqpdf/qpdf/MD5.hh10
-rw-r--r--libqpdf/qpdf/NNTree.hh18
-rw-r--r--libqpdf/qpdf/OffsetInputSource.hh3
-rw-r--r--libqpdf/qpdf/Pl_LZWDecoder.hh3
-rw-r--r--libqpdf/qpdf/QPDFArgParser.hh29
-rw-r--r--libqpdf/qpdf/QPDFCrypto_gnutls.hh6
-rw-r--r--libqpdf/qpdf/QPDFCrypto_native.hh6
-rw-r--r--libqpdf/qpdf/QPDFCrypto_openssl.hh7
-rw-r--r--libqpdf/qpdf/QPDFObject_private.hh7
-rw-r--r--libqpdf/qpdf/QPDFParser.hh16
-rw-r--r--libqpdf/qpdf/QPDFValue.hh17
-rw-r--r--libqpdf/qpdf/QPDF_Array.hh3
-rw-r--r--libqpdf/qpdf/QPDF_Dictionary.hh6
-rw-r--r--libqpdf/qpdf/QPDF_Stream.hh22
-rw-r--r--libqpdf/qpdf/QPDF_String.hh3
-rw-r--r--libqpdf/qpdf/RC4.hh3
-rw-r--r--libqpdf/qpdf/RC4_native.hh3
-rw-r--r--libqpdf/qpdf/ResourceFinder.hh3
-rw-r--r--libqpdf/qpdf/SF_ASCII85Decode.hh3
-rw-r--r--libqpdf/qpdf/SF_ASCIIHexDecode.hh3
-rw-r--r--libqpdf/qpdf/SF_RunLengthDecode.hh4
-rw-r--r--libqpdf/qpdf/bits_functions.hh39
-rw-r--r--libqpdf/qpdf/rijndael.h6
-rw-r--r--libqpdf/qpdfjob-c.cc35
-rw-r--r--libqpdf/qpdflogger-c.cc39
-rw-r--r--libtests/aes.cc3
-rw-r--r--libtests/arg_parser.cc34
-rw-r--r--libtests/bits.cc22
-rw-r--r--libtests/concatenate.cc3
-rw-r--r--libtests/cxx11.cc3
-rw-r--r--libtests/input_source.cc41
-rw-r--r--libtests/json.cc20
-rw-r--r--libtests/json_handler.cc4
-rw-r--r--libtests/json_parse.cc3
-rw-r--r--libtests/logger.cc3
-rw-r--r--libtests/logger_c.c23
-rw-r--r--libtests/lzw.cc3
-rw-r--r--libtests/matrix.cc32
-rw-r--r--libtests/md5.cc16
-rw-r--r--libtests/nntree.cc33
-rw-r--r--libtests/pointer_holder.cc3
-rw-r--r--libtests/qintc.cc20
-rw-r--r--libtests/qutil.cc67
-rw-r--r--libtests/runlength.cc8
-rw-r--r--libtests/sha2.cc7
-rw-r--r--qpdf/fix-qdf.cc26
-rw-r--r--qpdf/pdf_from_scratch.cc27
-rw-r--r--qpdf/qpdf-ctest.c492
-rw-r--r--qpdf/qpdf.cc13
-rw-r--r--qpdf/test_driver.cc576
-rw-r--r--qpdf/test_large_file.cc35
-rw-r--r--qpdf/test_parsedoffset.cc20
-rw-r--r--qpdf/test_pdf_unicode.cc3
-rw-r--r--qpdf/test_renumber.cc23
-rw-r--r--qpdf/test_tokenizer.cc24
-rw-r--r--qpdf/test_xref.cc15
-rw-r--r--zlib-flate/zlib-flate.cc9
196 files changed, 2596 insertions, 5616 deletions
diff --git a/examples/pdf-attach-file.cc b/examples/pdf-attach-file.cc
index 9cb55741..b5a1c64a 100644
--- a/examples/pdf-attach-file.cc
+++ b/examples/pdf-attach-file.cc
@@ -71,8 +71,7 @@ process(
// Create a file spec.
std::string key = QUtil::path_basename(attachment);
- std::cout << whoami << ": attaching " << attachment << " as " << key
- << std::endl;
+ std::cout << whoami << ": attaching " << attachment << " as " << key << std::endl;
auto fs = QPDFFileSpecObjectHelper::createFileSpec(q, key, attachment);
if (mimetype) {
diff --git a/examples/pdf-bookmarks.cc b/examples/pdf-bookmarks.cc
index 8128fed1..d40ded6a 100644
--- a/examples/pdf-bookmarks.cc
+++ b/examples/pdf-bookmarks.cc
@@ -23,16 +23,12 @@ static std::map<QPDFObjGen, int> page_map;
void
usage()
{
- std::cerr
- << "Usage: " << whoami << " [options] file.pdf [password]" << std::endl
- << "Options:" << std::endl
- << " --numbers give bookmarks outline-style numbers"
- << std::endl
- << " --lines draw lines to show bookmark hierarchy"
- << std::endl
- << " --show-open indicate whether a bookmark is initially open"
- << std::endl
- << " --show-targets show target if possible" << std::endl;
+ std::cerr << "Usage: " << whoami << " [options] file.pdf [password]" << std::endl
+ << "Options:" << std::endl
+ << " --numbers give bookmarks outline-style numbers" << std::endl
+ << " --lines draw lines to show bookmark hierarchy" << std::endl
+ << " --show-open indicate whether a bookmark is initially open" << std::endl
+ << " --show-targets show target if possible" << std::endl;
exit(2);
}
@@ -120,16 +116,14 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector<int> numbers)
}
void
-extract_bookmarks(
- std::vector<QPDFOutlineObjectHelper> outlines, std::vector<int>& numbers)
+extract_bookmarks(std::vector<QPDFOutlineObjectHelper> outlines, std::vector<int>& numbers)
{
// For style == st_numbers, numbers.at(n) contains the numerical
// label for the outline, so we count up from 1.
// For style == st_lines, numbers.at(n) == 0 indicates the last
// outline at level n, and we don't otherwise care what the value
// is, so we count up to zero.
- numbers.push_back(
- (style == st_lines) ? -QIntC::to_int(outlines.size()) : 0);
+ numbers.push_back((style == st_lines) ? -QIntC::to_int(outlines.size()) : 0);
for (auto& outline: outlines) {
++(numbers.back());
show_bookmark_details(outline, numbers);
@@ -196,8 +190,7 @@ main(int argc, char* argv[])
std::cout << filename << " has no bookmarks" << std::endl;
}
} catch (std::exception& e) {
- std::cerr << whoami << " processing file " << filename << ": "
- << e.what() << std::endl;
+ std::cerr << whoami << " processing file " << filename << ": " << e.what() << std::endl;
exit(2);
}
diff --git a/examples/pdf-c-objects.c b/examples/pdf-c-objects.c
index 78a4a746..f4b872a7 100644
--- a/examples/pdf-c-objects.c
+++ b/examples/pdf-c-objects.c
@@ -33,8 +33,7 @@ modify_file(qpdf_data qpdf)
qpdf_oh_remove_key(qpdf, root, "/OpenAction");
/* 0 is never a valid qpdf_oh */
qpdf_oh pagemode = 0;
- if (qpdf_oh_is_dictionary(
- qpdf, qpdf_oh_get_key(qpdf, root, "/PageLabels"))) {
+ if (qpdf_oh_is_dictionary(qpdf, qpdf_oh_get_key(qpdf, root, "/PageLabels"))) {
pagemode = qpdf_oh_new_name(qpdf, "/UseOutlines");
} else {
pagemode = qpdf_oh_new_null(qpdf);
@@ -71,8 +70,7 @@ main(int argc, char* argv[])
password = argv[2];
outfile = argv[3];
- if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
- modify_file(qpdf) &&
+ if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && modify_file(qpdf) &&
((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) {
/* Use static ID for testing only. For production, a
* non-static ID is used. See also
@@ -82,15 +80,11 @@ main(int argc, char* argv[])
}
while (qpdf_more_warnings(qpdf)) {
warnings = 1;
- printf(
- "warning: %s\n",
- qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
+ printf("warning: %s\n", qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
}
if (qpdf_has_error(qpdf)) {
errors = 1;
- printf(
- "error: %s\n",
- qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
+ printf("error: %s\n", qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
}
qpdf_cleanup(&qpdf);
if (errors) {
diff --git a/examples/pdf-count-strings.cc b/examples/pdf-count-strings.cc
index e9eb827d..c70e183e 100644
--- a/examples/pdf-count-strings.cc
+++ b/examples/pdf-count-strings.cc
@@ -97,8 +97,7 @@ main(int argc, char* argv[])
page.filterContents(&counter, &out);
std::cout << "\n% end " << pageno << std::endl;
}
- std::cout << "Page " << pageno
- << ": strings = " << counter.getCount() << std::endl;
+ std::cout << "Page " << pageno << ": strings = " << counter.getCount() << std::endl;
}
} catch (std::exception& e) {
std::cerr << whoami << ": " << e.what() << std::endl;
diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc
index 641572d0..e0fa93b1 100644
--- a/examples/pdf-create.cc
+++ b/examples/pdf-create.cc
@@ -41,8 +41,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider
J_COLOR_SPACE j_color_space;
};
-ImageProvider::ImageProvider(
- std::string const& color_space, std::string const& filter) :
+ImageProvider::ImageProvider(std::string const& color_space, std::string const& filter) :
width(400),
stripe_height(80),
color_space(color_space),
@@ -107,8 +106,7 @@ ImageProvider::provideStreamData(QPDFObjGen const&, Pipeline* pipeline)
to_delete.push_back(p_new);
p = p_new.get();
} else if (filter == "/RunLengthDecode") {
- p_new = std::make_shared<Pl_RunLength>(
- "image encoder", pipeline, Pl_RunLength::a_encode);
+ p_new = std::make_shared<Pl_RunLength>("image encoder", pipeline, Pl_RunLength::a_encode);
to_delete.push_back(p_new);
p = p_new.get();
}
@@ -184,8 +182,7 @@ add_page(
image.replaceDict(image_dict);
// Provide the stream data.
- image.replaceStreamData(
- provider, QPDFObjectHandle::parse(filter), QPDFObjectHandle::newNull());
+ image.replaceStreamData(provider, QPDFObjectHandle::parse(filter), QPDFObjectHandle::newNull());
// Create direct objects as needed by the page dictionary.
QPDFObjectHandle procset = "[/PDF /Text /ImageC]"_qpdf;
@@ -202,8 +199,7 @@ add_page(
resources.replaceKey("/XObject", xobject);
// Create the page content stream
- QPDFObjectHandle contents =
- createPageContents(pdf, color_space + " with filter " + filter);
+ QPDFObjectHandle contents = createPageContents(pdf, color_space + " with filter " + filter);
// Create the page dictionary
QPDFObjectHandle page = pdf.makeIndirectObject("<<"
@@ -256,8 +252,7 @@ check(
}
// Check filter and color space.
- std::string desired_color_space =
- color_spaces[(pageno - 1) / n_color_spaces];
+ std::string desired_color_space = color_spaces[(pageno - 1) / n_color_spaces];
std::string desired_filter = filters[(pageno - 1) % n_filters];
// In the default mode, QPDFWriter will compress with
// /FlateDecode if no filters are provided.
@@ -271,16 +266,13 @@ check(
bool this_errors = false;
if (!filter.isNameAndEquals(desired_filter)) {
this_errors = errors = true;
- std::cout << "page " << pageno << ": expected filter "
- << desired_filter
+ std::cout << "page " << pageno << ": expected filter " << desired_filter
<< "; actual filter = " << filter.unparse() << std::endl;
}
if (!color_space.isNameAndEquals(desired_color_space)) {
this_errors = errors = true;
- std::cout << "page " << pageno << ": expected color space "
- << desired_color_space
- << "; actual color space = " << color_space.unparse()
- << std::endl;
+ std::cout << "page " << pageno << ": expected color space " << desired_color_space
+ << "; actual color space = " << color_space.unparse() << std::endl;
}
if (!this_errors) {
@@ -293,8 +285,7 @@ check(
std::shared_ptr<Buffer> desired_data(b_p.getBuffer());
if (desired_data->getSize() != actual_data->getSize()) {
- std::cout << "page " << pageno << ": image data length mismatch"
- << std::endl;
+ std::cout << "page " << pageno << ": image data length mismatch" << std::endl;
this_errors = errors = true;
} else {
// Compare bytes. For JPEG, allow a certain number of
@@ -308,8 +299,7 @@ check(
size_t len = actual_data->getSize();
unsigned int mismatches = 0;
int tolerance = (desired_filter == "/DCTDecode" ? 10 : 0);
- size_t threshold =
- (desired_filter == "/DCTDecode" ? len / 40U : 0);
+ size_t threshold = (desired_filter == "/DCTDecode" ? len / 40U : 0);
for (size_t i = 0; i < len; ++i) {
int delta = actual_bytes[i] - desired_bytes[i];
if ((delta > tolerance) || (delta < -tolerance)) {
@@ -317,9 +307,8 @@ check(
}
}
if (mismatches > threshold) {
- std::cout << "page " << pageno << ": "
- << desired_color_space << ", " << desired_filter
- << ": mismatches: " << mismatches << " of " << len
+ std::cout << "page " << pageno << ": " << desired_color_space << ", "
+ << desired_filter << ": mismatches: " << mismatches << " of " << len
<< std::endl;
this_errors = errors = true;
}
diff --git a/examples/pdf-custom-filter.cc b/examples/pdf-custom-filter.cc
index c2d4a441..57eedf74 100644
--- a/examples/pdf-custom-filter.cc
+++ b/examples/pdf-custom-filter.cc
@@ -132,8 +132,7 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms)
this->key = buf->getBuffer()[0];
return true;
} catch (std::exception& e) {
- std::cerr << "Error extracting key for /XORDecode: " << e.what()
- << std::endl;
+ std::cerr << "Error extracting key for /XORDecode: " << e.what() << std::endl;
}
return false;
}
@@ -203,8 +202,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider
void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override;
void registerStream(
- QPDFObjectHandle stream,
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self);
+ QPDFObjectHandle stream, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self);
private:
bool maybeReplace(
@@ -300,12 +298,10 @@ StreamReplacer::maybeReplace(
// changes. For example, an image resampler might change the
// dimensions or other properties of the image.
dict_updates->replaceKey(
- "/OrigLength",
- QPDFObjectHandle::newInteger(QIntC::to_longlong(out->getSize())));
+ "/OrigLength", QPDFObjectHandle::newInteger(QIntC::to_longlong(out->getSize())));
// We are also storing the "key" that we will access when
// writing the data.
- this->keys[og] = QIntC::to_uchar(
- (og.getObj() * QIntC::to_int(out->getSize())) & 0xff);
+ this->keys[og] = QIntC::to_uchar((og.getObj() * QIntC::to_int(out->getSize())) & 0xff);
}
if (pipeline) {
@@ -319,8 +315,7 @@ StreamReplacer::maybeReplace(
void
StreamReplacer::registerStream(
- QPDFObjectHandle stream,
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self)
+ QPDFObjectHandle stream, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self)
{
QPDFObjGen og(stream.getObjGen());
@@ -344,8 +339,7 @@ StreamReplacer::registerStream(
try {
should_replace = maybeReplace(og, stream, nullptr, &dict_updates);
} catch (std::exception& e) {
- stream.warnIfPossible(
- std::string("exception while attempting to replace: ") + e.what());
+ stream.warnIfPossible(std::string("exception while attempting to replace: ") + e.what());
}
if (should_replace) {
@@ -369,8 +363,7 @@ StreamReplacer::registerStream(
// /XORDecode filter.
QPDFObjectHandle decode_parms =
QPDFObjectHandle::newDictionary({{"/KeyStream", dp_stream}});
- stream.replaceStreamData(
- self, QPDFObjectHandle::newName("/XORDecode"), decode_parms);
+ stream.replaceStreamData(self, QPDFObjectHandle::newName("/XORDecode"), decode_parms);
// Further, if /ProtectXOR = true, we disable filtering on write
// so that QPDFWriter will not decode the stream even though we
// have registered a stream filter for /XORDecode.
@@ -393,14 +386,12 @@ StreamReplacer::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline)
// Since this only gets called for streams we already
// determined we are replacing, a false return would indicate
// a logic error.
- throw std::logic_error(
- "should_replace return false in provideStreamData");
+ throw std::logic_error("should_replace return false in provideStreamData");
}
}
static void
-process(
- char const* infilename, char const* outfilename, bool decode_specialized)
+process(char const* infilename, char const* outfilename, bool decode_specialized)
{
QPDF qpdf;
qpdf.processFile(infilename);
@@ -434,8 +425,7 @@ static void
usage()
{
std::cerr << "\n"
- << "Usage: " << whoami
- << " [--decode-specialized] infile outfile\n"
+ << "Usage: " << whoami << " [--decode-specialized] infile outfile\n"
<< std::endl;
exit(2);
}
@@ -468,8 +458,7 @@ main(int argc, char* argv[])
// decode our streams. This is not a real filter, so no real
// PDF reading application would be able to interpret it. This
// is just for illustrative purposes.
- QPDF::registerStreamFilter(
- "/XORDecode", [] { return std::make_shared<SF_XORDecode>(); });
+ QPDF::registerStreamFilter("/XORDecode", [] { return std::make_shared<SF_XORDecode>(); });
// Do the actual processing.
process(infilename, outfilename, decode_specialized);
} catch (std::exception& e) {
diff --git a/examples/pdf-double-page-size.cc b/examples/pdf-double-page-size.cc
index 1c9cb3e5..6e1b4f8b 100644
--- a/examples/pdf-double-page-size.cc
+++ b/examples/pdf-double-page-size.cc
@@ -13,8 +13,7 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]"
- << std::endl
+ std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl
<< "Double size of all pages in infile.pdf;"
<< " write output to outfile.pdf" << std::endl;
exit(2);
@@ -33,16 +32,13 @@ doubleBoxSize(QPDFPageObjectHelper& page, char const* box_name)
}
if (!box.isRectangle()) {
throw std::runtime_error(
- std::string("box ") + box_name +
- " is not an array of four elements");
+ std::string("box ") + box_name + " is not an array of four elements");
}
std::vector<QPDFObjectHandle> doubled;
for (auto& item: box.aitems()) {
- doubled.push_back(
- QPDFObjectHandle::newReal(item.getNumericValue() * 2.0, 2));
+ 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
@@ -93,11 +89,9 @@ main(int argc, char* argv[])
w.setStreamDataMode(qpdf_s_uncompress);
}
w.write();
- std::cout << whoami << ": new file written to " << outfilename
- << std::endl;
+ std::cout << whoami << ": new file written to " << outfilename << std::endl;
} catch (std::exception& e) {
- std::cerr << whoami << " processing file " << infilename << ": "
- << e.what() << std::endl;
+ std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl;
exit(2);
}
diff --git a/examples/pdf-filter-tokens.cc b/examples/pdf-filter-tokens.cc
index 9cfd3949..68d6e149 100644
--- a/examples/pdf-filter-tokens.cc
+++ b/examples/pdf-filter-tokens.cc
@@ -22,8 +22,7 @@ void
usage()
{
std::cerr << "Usage: " << whoami << " infile outfile" << std::endl
- << "Applies token filters to infile and writes outfile"
- << std::endl;
+ << "Applies token filters to infile and writes outfile" << std::endl;
exit(2);
}
@@ -82,17 +81,13 @@ class ColorToGray: public QPDFObjectHandle::TokenFilter
bool
ColorToGray::isNumeric(QPDFTokenizer::token_type_e token_type)
{
- return (
- (token_type == QPDFTokenizer::tt_integer) ||
- (token_type == QPDFTokenizer::tt_real));
+ return ((token_type == QPDFTokenizer::tt_integer) || (token_type == QPDFTokenizer::tt_real));
}
bool
ColorToGray::isIgnorable(QPDFTokenizer::token_type_e token_type)
{
- return (
- (token_type == QPDFTokenizer::tt_space) ||
- (token_type == QPDFTokenizer::tt_comment));
+ return ((token_type == QPDFTokenizer::tt_space) || (token_type == QPDFTokenizer::tt_comment));
}
double
@@ -128,8 +123,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const& token)
// kinds of operands, replace the command. Flush any additional
// accumulated tokens to keep the stack only four tokens deep.
- while ((!this->all_stack.empty()) &&
- isIgnorable(this->all_stack.at(0).getType())) {
+ while ((!this->all_stack.empty()) && isIgnorable(this->all_stack.at(0).getType())) {
writeToken(this->all_stack.at(0));
this->all_stack.pop_front();
}
@@ -138,8 +132,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const& token)
if (!isIgnorable(token_type)) {
this->stack.push_back(token);
if ((this->stack.size() == 4) && token.isWord("rg") &&
- (isNumeric(this->stack.at(0).getType())) &&
- (isNumeric(this->stack.at(1).getType())) &&
+ (isNumeric(this->stack.at(0).getType())) && (isNumeric(this->stack.at(1).getType())) &&
(isNumeric(this->stack.at(2).getType()))) {
double r = numericValue(this->stack.at(0));
double g = numericValue(this->stack.at(1));
@@ -195,11 +188,9 @@ main(int argc, char* argv[])
// applied. See comments on the filters for additional
// details.
page.addContentTokenFilter(
- std::shared_ptr<QPDFObjectHandle::TokenFilter>(
- new StringReverser));
+ std::shared_ptr<QPDFObjectHandle::TokenFilter>(new StringReverser));
page.addContentTokenFilter(
- std::shared_ptr<QPDFObjectHandle::TokenFilter>(
- new ColorToGray));
+ std::shared_ptr<QPDFObjectHandle::TokenFilter>(new ColorToGray));
}
QPDFWriter w(pdf, outfilename);
diff --git a/examples/pdf-invert-images.cc b/examples/pdf-invert-images.cc
index a7fa15fd..5692e7b2 100644
--- a/examples/pdf-invert-images.cc
+++ b/examples/pdf-invert-images.cc
@@ -14,8 +14,7 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]"
- << std::endl
+ std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl
<< "Invert some images in infile.pdf;"
<< " write output to outfile.pdf" << std::endl;
exit(2);
@@ -37,8 +36,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider
void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override;
void registerImage(
- QPDFObjectHandle image,
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self);
+ QPDFObjectHandle image, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self);
private:
std::map<QPDFObjGen, QPDFObjectHandle> copied_images;
@@ -46,8 +44,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider
void
ImageInverter::registerImage(
- QPDFObjectHandle image,
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self)
+ QPDFObjectHandle image, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self)
{
// replaceStreamData requires a pointer holder to the stream data
// provider, but there's no way for us to generate one ourselves,
@@ -76,8 +73,7 @@ ImageInverter::registerImage(
// filterable in the input QPDF object, so we don't have to deal
// with it explicitly here. We could explicitly use /DCTDecode and
// write through a DCT filter if we wanted.
- image.replaceStreamData(
- self, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
+ image.replaceStreamData(self, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
}
void
@@ -86,8 +82,7 @@ ImageInverter::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline)
// Use the object and generation number supplied to look up the
// image data. Then invert the image data and write the inverted
// data to the pipeline.
- std::shared_ptr<Buffer> data =
- this->copied_images[og].getStreamData(qpdf_dl_all);
+ std::shared_ptr<Buffer> data = this->copied_images[og].getStreamData(qpdf_dl_all);
size_t size = data->getSize();
unsigned char* buf = data->getBuffer();
unsigned char ch;
@@ -133,18 +128,15 @@ main(int argc, char* argv[])
QPDFObjectHandle& image = iter.second;
QPDFObjectHandle image_dict = image.getDict();
QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");
- QPDFObjectHandle bits_per_component =
- image_dict.getKey("/BitsPerComponent");
+ QPDFObjectHandle bits_per_component = image_dict.getKey("/BitsPerComponent");
// For our example, we can only work with images 8-bit
// grayscale images that we can fully decode. Use
// pipeStreamData with a null pipeline to determine
// whether the image is filterable. Directly inspect
// keys to determine the image type.
- if (image.pipeStreamData(
- nullptr, qpdf_ef_compress, qpdf_dl_all) &&
- color_space.isNameAndEquals("/DeviceGray") &&
- bits_per_component.isInteger() &&
+ if (image.pipeStreamData(nullptr, qpdf_ef_compress, qpdf_dl_all) &&
+ color_space.isNameAndEquals("/DeviceGray") && bits_per_component.isInteger() &&
(bits_per_component.getIntValue() == 8)) {
inv->registerImage(image, p);
}
@@ -159,11 +151,9 @@ main(int argc, char* argv[])
w.setStaticID(true); // for testing only
}
w.write();
- std::cout << whoami << ": new file written to " << outfilename
- << std::endl;
+ std::cout << whoami << ": new file written to " << outfilename << std::endl;
} catch (std::exception& e) {
- std::cerr << whoami << " processing file " << infilename << ": "
- << e.what() << std::endl;
+ std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl;
exit(2);
}
diff --git a/examples/pdf-linearize.c b/examples/pdf-linearize.c
index f972fa71..3a7a335d 100644
--- a/examples/pdf-linearize.c
+++ b/examples/pdf-linearize.c
@@ -61,15 +61,11 @@ main(int argc, char* argv[])
}
while (qpdf_more_warnings(qpdf)) {
warnings = 1;
- printf(
- "warning: %s\n",
- qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
+ printf("warning: %s\n", qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
}
if (qpdf_has_error(qpdf)) {
errors = 1;
- printf(
- "error: %s\n",
- qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
+ printf("error: %s\n", qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
}
qpdf_cleanup(&qpdf);
if (errors) {
diff --git a/examples/pdf-mod-info.cc b/examples/pdf-mod-info.cc
index a77070d2..3a9671e1 100644
--- a/examples/pdf-mod-info.cc
+++ b/examples/pdf-mod-info.cc
@@ -16,8 +16,7 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami
- << " --in in_file [--out out_file] [--key key [--val val]?]+\n"
+ std::cerr << "Usage: " << whoami << " --in in_file [--out out_file] [--key key [--val val]?]+\n"
<< "Modifies/Adds/Removes PDF /Info entries in the in_file\n"
<< "and stores the result in out_file\n"
<< "Special mode: " << whoami << " --dump file\n"
@@ -26,8 +25,7 @@ usage()
}
void
-dumpInfoDict(
- QPDF& pdf, std::ostream& os = std::cout, std::string const& sep = ":\t")
+dumpInfoDict(QPDF& pdf, std::ostream& os = std::cout, std::string const& sep = ":\t")
{
QPDFObjectHandle trailer = pdf.getTrailer();
if (trailer.hasKey("/Info")) {
@@ -164,8 +162,7 @@ main(int argc, char* argv[])
try {
(void)remove(fl_out);
QUtil::os_wrapper(
- "rename " + fl_tmp + " " + std::string(fl_out),
- rename(fl_tmp.c_str(), fl_out));
+ "rename " + fl_tmp + " " + std::string(fl_out), rename(fl_tmp.c_str(), fl_out));
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
exit(2);
diff --git a/examples/pdf-name-number-tree.cc b/examples/pdf-name-number-tree.cc
index e1dfde05..a14ad126 100644
--- a/examples/pdf-name-number-tree.cc
+++ b/examples/pdf-name-number-tree.cc
@@ -11,8 +11,7 @@ void
usage()
{
std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl
- << "Create some name/number trees and write to a file"
- << std::endl;
+ << "Create some name/number trees and write to a file" << std::endl;
exit(2);
}
@@ -61,24 +60,19 @@ main(int argc, char* argv[])
name_tree.insert("R", QPDFObjectHandle::newUnicodeString("rook"));
name_tree.insert("B", QPDFObjectHandle::newUnicodeString("bishop"));
name_tree.insert("N", QPDFObjectHandle::newUnicodeString("knight"));
- auto iter =
- name_tree.insert("P", QPDFObjectHandle::newUnicodeString("pawn"));
+ auto iter = name_tree.insert("P", QPDFObjectHandle::newUnicodeString("pawn"));
// Look at the iterator
- std::cout << "just inserted " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "just inserted " << iter->first << " -> " << iter->second.unparse() << std::endl;
--iter;
- std::cout << "predecessor: " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "predecessor: " << iter->first << " -> " << iter->second.unparse() << std::endl;
++iter;
++iter;
- std::cout << "successor: " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "successor: " << iter->first << " -> " << iter->second.unparse() << std::endl;
// Use range-for iteration
std::cout << "Name tree items:" << std::endl;
for (auto i: name_tree) {
- std::cout << " " << i.first << " -> " << i.second.unparse()
- << std::endl;
+ std::cout << " " << i.first << " -> " << i.second.unparse() << std::endl;
}
// This is a small tree, so everything will be at the root. We can
@@ -107,14 +101,13 @@ main(int argc, char* argv[])
// 10.2 API
iter = name_tree.find("Q");
- std::cout << "Q: " << iter->first << " -> " << iter->second.unparse()
- << std::endl;
+ std::cout << "Q: " << iter->first << " -> " << iter->second.unparse() << std::endl;
iter = name_tree.find("W");
std::cout << "W found: " << (iter != name_tree.end()) << std::endl;
// Allow find to return predecessor
iter = name_tree.find("W", true);
- std::cout << "W's predecessor: " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "W's predecessor: " << iter->first << " -> " << iter->second.unparse()
+ << std::endl;
// We can also remove items
std::cout << "Remove P: " << name_tree.remove("P", &obj) << std::endl;
@@ -124,8 +117,8 @@ main(int argc, char* argv[])
iter = name_tree.find("K");
std::cout << "Find K: " << iter->second.unparse() << std::endl;
iter.remove();
- std::cout << "Iter after removing K: " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "Iter after removing K: " << iter->first << " -> " << iter->second.unparse()
+ << std::endl;
std::cout << "Has K?: " << name_tree.hasName("K") << std::endl;
// Illustrate some more advanced usage using number trees. These
@@ -142,8 +135,7 @@ main(int argc, char* argv[])
example.replaceKey("/NumberTree", number_tree_oh);
auto iter2 = number_tree.begin();
for (int i = 7; i <= 350; i += 7) {
- iter2.insertAfter(
- i, QPDFObjectHandle::newString("-" + std::to_string(i) + "-"));
+ iter2.insertAfter(i, QPDFObjectHandle::newString("-" + std::to_string(i) + "-"));
}
std::cout << "Numbers:" << std::endl;
int n = 1;
diff --git a/examples/pdf-overlay-page.cc b/examples/pdf-overlay-page.cc
index 5b74d58b..6d1cd0b0 100644
--- a/examples/pdf-overlay-page.cc
+++ b/examples/pdf-overlay-page.cc
@@ -31,8 +31,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile)
stamppdf.processFile(stampfile);
// Get first page from other file
- QPDFPageObjectHelper stamp_page_1 =
- QPDFPageDocumentHelper(stamppdf).getAllPages().at(0);
+ QPDFPageObjectHelper stamp_page_1 = QPDFPageDocumentHelper(stamppdf).getAllPages().at(0);
// Convert page to a form XObject
QPDFObjectHandle foreign_fo = stamp_page_1.getFormXObjectForPage();
// Copy form XObject to the input file
@@ -48,8 +47,8 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile)
// Generate content to place the form XObject centered within
// destination page's trim box.
QPDFMatrix m;
- std::string content = ph.placeFormXObject(
- stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m);
+ std::string content =
+ ph.placeFormXObject(stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m);
if (!content.empty()) {
// Append the content to the page's content. Surround the
// original content with q...Q to the new content from the
diff --git a/examples/pdf-parse-content.cc b/examples/pdf-parse-content.cc
index 888656e5..743986a1 100644
--- a/examples/pdf-parse-content.cc
+++ b/examples/pdf-parse-content.cc
@@ -35,11 +35,9 @@ ParserCallbacks::contentSize(size_t size)
}
void
-ParserCallbacks::handleObject(
- QPDFObjectHandle obj, size_t offset, size_t length)
+ParserCallbacks::handleObject(QPDFObjectHandle obj, size_t offset, size_t length)
{
- std::cout << obj.getTypeName() << ", offset=" << offset
- << ", length=" << length << ": ";
+ std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": ";
if (obj.isInlineImage()) {
std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl;
} else {
@@ -67,8 +65,7 @@ main(int argc, char* argv[])
try {
QPDF pdf;
pdf.processFile(filename);
- std::vector<QPDFPageObjectHelper> pages =
- QPDFPageDocumentHelper(pdf).getAllPages();
+ std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(pdf).getAllPages();
if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size())) {
usage();
}
diff --git a/examples/pdf-set-form-values.cc b/examples/pdf-set-form-values.cc
index a41cb3f7..c2793142 100644
--- a/examples/pdf-set-form-values.cc
+++ b/examples/pdf-set-form-values.cc
@@ -11,10 +11,8 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value"
- << std::endl
- << "Set the value of all text fields to a specified value"
- << std::endl;
+ std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value" << std::endl
+ << "Set the value of all text fields to a specified value" << std::endl;
exit(2);
}
@@ -55,8 +53,7 @@ main(int argc, char* argv[])
for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) {
// For each annotation, find its associated field. If
// it's a text field, set its value.
- QPDFFormFieldObjectHelper ffh =
- afdh.getFieldForAnnotation(annot);
+ QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(annot);
if (ffh.getFieldType() == "/Tx") {
// Set the value. Passing false as the second
// value prevents qpdf from setting
@@ -79,8 +76,7 @@ main(int argc, char* argv[])
w.setStaticID(true); // for testing only
w.write();
} catch (std::exception& e) {
- std::cerr << whoami << " processing file " << infilename << ": "
- << e.what() << std::endl;
+ std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl;
exit(2);
}
diff --git a/examples/pdf-split-pages.cc b/examples/pdf-split-pages.cc
index e8320201..9890ccf4 100644
--- a/examples/pdf-split-pages.cc
+++ b/examples/pdf-split-pages.cc
@@ -22,13 +22,11 @@ process(char const* whoami, char const* infile, std::string outprefix)
{
QPDF inpdf;
inpdf.processFile(infile);
- std::vector<QPDFPageObjectHelper> pages =
- QPDFPageDocumentHelper(inpdf).getAllPages();
+ std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(inpdf).getAllPages();
int pageno_len = QIntC::to_int(std::to_string(pages.size()).length());
int pageno = 0;
for (auto& page: pages) {
- std::string outfile =
- outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf";
+ std::string outfile = outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf";
QPDF outpdf;
outpdf.emptyPDF();
QPDFPageDocumentHelper(outpdf).addPage(page, false);
diff --git a/examples/qpdfjob-c-save-attachment.c b/examples/qpdfjob-c-save-attachment.c
index 301bf635..c461f974 100644
--- a/examples/qpdfjob-c-save-attachment.c
+++ b/examples/qpdfjob-c-save-attachment.c
@@ -83,8 +83,7 @@ main(int argc, char* argv[])
* saved data. You can use other qpdf logger functions to capture
* informational output, warnings, and errors.
*/
- qpdflogger_set_save(
- l, qpdf_log_dest_custom, save_to_file, (void*)outfile, 0);
+ qpdflogger_set_save(l, qpdf_log_dest_custom, save_to_file, (void*)outfile, 0);
qpdflogger_cleanup(&l);
j = qpdfjob_init();
status = (qpdfjob_initialize_from_argv(j, j_argv) || qpdfjob_run(j));
diff --git a/examples/qpdfjob-remove-annotations.cc b/examples/qpdfjob-remove-annotations.cc
index 5334e7dc..b0afa2da 100644
--- a/examples/qpdfjob-remove-annotations.cc
+++ b/examples/qpdfjob-remove-annotations.cc
@@ -20,15 +20,10 @@ usageExit(std::string const& msg)
<< whoami << ": " << msg << std::endl
<< std::endl
<< "For help:" << std::endl
- << " " << whoami << " --help=usage usage information"
- << std::endl
- << " " << whoami << " --help=topic help on a topic"
- << std::endl
- << " " << whoami << " --help=--option help on an option"
- << std::endl
- << " " << whoami
- << " --help general help and a topic list"
- << std::endl
+ << " " << whoami << " --help=usage usage information" << std::endl
+ << " " << whoami << " --help=topic help on a topic" << std::endl
+ << " " << whoami << " --help=--option help on an option" << std::endl
+ << " " << whoami << " --help general help and a topic list" << std::endl
<< std::endl;
exit(QPDFJob::EXIT_ERROR);
}
diff --git a/examples/qpdfjob-save-attachment.cc b/examples/qpdfjob-save-attachment.cc
index 2c08620a..045e38bf 100644
--- a/examples/qpdfjob-save-attachment.cc
+++ b/examples/qpdfjob-save-attachment.cc
@@ -14,8 +14,7 @@ main(int argc, char* argv[])
auto whoami = QUtil::getWhoami(argv[0]);
if (argc != 4) {
- std::cerr << "Usage: " << whoami << " file attachment-key outfile"
- << std::endl;
+ std::cerr << "Usage: " << whoami << " file attachment-key outfile" << std::endl;
exit(2);
}
diff --git a/fuzz/qpdf_fuzzer.cc b/fuzz/qpdf_fuzzer.cc
index 8d4534bd..6f941276 100644
--- a/fuzz/qpdf_fuzzer.cc
+++ b/fuzz/qpdf_fuzzer.cc
@@ -53,8 +53,8 @@ FuzzHelper::FuzzHelper(unsigned char const* data, size_t size) :
std::shared_ptr<QPDF>
FuzzHelper::getQpdf()
{
- auto is = std::shared_ptr<InputSource>(
- new BufferInputSource("fuzz input", &this->input_buffer));
+ auto is =
+ std::shared_ptr<InputSource>(new BufferInputSource("fuzz input", &this->input_buffer));
auto qpdf = QPDF::create();
qpdf->processInputSource(is);
return qpdf;
@@ -99,8 +99,7 @@ FuzzHelper::testWrite()
w = getWriter(q);
w->setStaticID(true);
w->setLinearization(true);
- w->setR6EncryptionParameters(
- "u", "o", true, true, true, true, true, true, qpdf_r3p_full, true);
+ w->setR6EncryptionParameters("u", "o", true, true, true, true, true, true, qpdf_r3p_full, true);
doWrite(w);
q = getQpdf();
diff --git a/fuzz/standalone_fuzz_target_runner.cc b/fuzz/standalone_fuzz_target_runner.cc
index 143f4e6f..9d57481d 100644
--- a/fuzz/standalone_fuzz_target_runner.cc
+++ b/fuzz/standalone_fuzz_target_runner.cc
@@ -11,8 +11,7 @@ main(int argc, char** argv)
std::shared_ptr<char> file_buf;
size_t size = 0;
QUtil::read_file_into_memory(argv[i], file_buf, size);
- LLVMFuzzerTestOneInput(
- reinterpret_cast<unsigned char*>(file_buf.get()), size);
+ LLVMFuzzerTestOneInput(reinterpret_cast<unsigned char*>(file_buf.get()), size);
std::cout << argv[i] << " successful" << std::endl;
}
return 0;
diff --git a/fuzz/tiffpredictor_fuzzer.cc b/fuzz/tiffpredictor_fuzzer.cc
index 61c24e57..fd0e4c6e 100644
--- a/fuzz/tiffpredictor_fuzzer.cc
+++ b/fuzz/tiffpredictor_fuzzer.cc
@@ -26,8 +26,7 @@ void
FuzzHelper::doChecks()
{
Pl_Discard discard;
- Pl_TIFFPredictor p(
- "decoder", &discard, Pl_TIFFPredictor::a_decode, 16, 1, 8);
+ Pl_TIFFPredictor p("decoder", &discard, Pl_TIFFPredictor::a_decode, 16, 1, 8);
p.write(const_cast<unsigned char*>(data), size);
p.finish();
}
diff --git a/include/qpdf/BufferInputSource.hh b/include/qpdf/BufferInputSource.hh
index c5a2eae5..8e1ea484 100644
--- a/include/qpdf/BufferInputSource.hh
+++ b/include/qpdf/BufferInputSource.hh
@@ -31,11 +31,9 @@ class QPDF_DLL_CLASS BufferInputSource: public InputSource
// If own_memory is true, BufferInputSource will delete the buffer
// when finished with it. Otherwise, the caller owns the memory.
QPDF_DLL
- BufferInputSource(
- std::string const& description, Buffer* buf, bool own_memory = false);
+ BufferInputSource(std::string const& description, Buffer* buf, bool own_memory = false);
QPDF_DLL
- BufferInputSource(
- std::string const& description, std::string const& contents);
+ BufferInputSource(std::string const& description, std::string const& contents);
QPDF_DLL
virtual ~BufferInputSource();
QPDF_DLL
diff --git a/include/qpdf/Constants.h b/include/qpdf/Constants.h
index 995857ab..74c9aeac 100644
--- a/include/qpdf/Constants.h
+++ b/include/qpdf/Constants.h
@@ -230,9 +230,6 @@ enum pdf_annotation_flag_e {
};
/* Encryption/password status for QPDFJob */
-enum qpdf_encryption_status_e {
- qpdf_es_encrypted = 1 << 0,
- qpdf_es_password_incorrect = 1 << 1
-};
+enum qpdf_encryption_status_e { qpdf_es_encrypted = 1 << 0, qpdf_es_password_incorrect = 1 << 1 };
#endif /* QPDFCONSTANTS_H */
diff --git a/include/qpdf/InputSource.hh b/include/qpdf/InputSource.hh
index 631ab75f..91a5c6e5 100644
--- a/include/qpdf/InputSource.hh
+++ b/include/qpdf/InputSource.hh
@@ -69,17 +69,9 @@ class QPDF_DLL_CLASS InputSource
// methods return true and leave the input source positioned
// wherever check() left it at the end of the matching pattern.
QPDF_DLL
- bool findFirst(
- char const* start_chars,
- qpdf_offset_t offset,
- size_t len,
- Finder& finder);
+ bool findFirst(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder);
QPDF_DLL
- bool findLast(
- char const* start_chars,
- qpdf_offset_t offset,
- size_t len,
- Finder& finder);
+ bool findLast(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder);
virtual qpdf_offset_t findAndSkipNextEOL() = 0;
virtual std::string const& getName() const = 0;
@@ -144,8 +136,7 @@ InputSource::fastTell()
loadBuffer();
} else {
auto curr = tell();
- if (curr < this->buf_start ||
- curr >= (this->buf_start + this->buf_len)) {
+ if (curr < this->buf_start || curr >= (this->buf_start + this->buf_len)) {
loadBuffer();
} else {
this->last_offset = curr;
diff --git a/include/qpdf/JSON.hh b/include/qpdf/JSON.hh
index ef820b66..00f78112 100644
--- a/include/qpdf/JSON.hh
+++ b/include/qpdf/JSON.hh
@@ -104,19 +104,14 @@ class JSON
// the first item and always set it to false.
QPDF_DLL
static void writeDictionaryItem(
- Pipeline*,
- bool& first,
- std::string const& key,
- JSON const& value,
- size_t depth = 0);
+ Pipeline*, bool& first, std::string const& key, JSON const& value, size_t depth = 0);
// Write just the key of a new dictionary item, useful if writing
// nested structures. Calls writeNext.
QPDF_DLL
- static void writeDictionaryKey(
- Pipeline* p, bool& first, std::string const& key, size_t depth = 0);
+ static void
+ writeDictionaryKey(Pipeline* p, bool& first, std::string const& key, size_t depth = 0);
QPDF_DLL
- static void writeArrayItem(
- Pipeline*, bool& first, JSON const& element, size_t depth = 0);
+ static void writeArrayItem(Pipeline*, bool& first, JSON const& element, size_t depth = 0);
// If writing nested structures incrementally, call writeNext
// before opening a new array or container in the midst of an
// existing one. The `first` you pass to writeNext should be the
@@ -188,8 +183,7 @@ class JSON
QPDF_DLL
bool isNull() const;
QPDF_DLL
- bool forEachDictItem(
- std::function<void(std::string const& key, JSON value)> fn) const;
+ bool forEachDictItem(std::function<void(std::string const& key, JSON value)> fn) const;
QPDF_DLL
bool forEachArrayItem(std::function<void(JSON value)> fn) const;
@@ -239,8 +233,7 @@ class JSON
f_optional = 1 << 0,
};
QPDF_DLL
- bool checkSchema(
- JSON schema, unsigned long flags, std::list<std::string>& errors);
+ bool checkSchema(JSON schema, unsigned long flags, std::list<std::string>& errors);
// Same as passing 0 for flags
QPDF_DLL
@@ -311,8 +304,7 @@ class JSON
// methods and decrementing on end methods.
QPDF_DLL
- virtual bool
- dictionaryItem(std::string const& key, JSON const& value) = 0;
+ virtual bool dictionaryItem(std::string const& key, JSON const& value) = 0;
QPDF_DLL
virtual bool arrayItem(JSON const& value) = 0;
};
@@ -339,8 +331,7 @@ class JSON
private:
static std::string encode_string(std::string const& utf8);
- static void
- writeClose(Pipeline* p, bool first, size_t depth, char const* delimeter);
+ static void writeClose(Pipeline* p, bool first, size_t depth, char const* delimeter);
enum value_type_e {
vt_none,
diff --git a/include/qpdf/Pl_Function.hh b/include/qpdf/Pl_Function.hh
index 7df164d1..e31d497d 100644
--- a/include/qpdf/Pl_Function.hh
+++ b/include/qpdf/Pl_Function.hh
@@ -54,15 +54,10 @@ class QPDF_DLL_CLASS Pl_Function: public Pipeline
// is thrown.
typedef int (*writer_c_t)(unsigned char const*, size_t, void*);
QPDF_DLL
- Pl_Function(
- char const* identifier, Pipeline* next, writer_c_t fn, void* udata);
+ Pl_Function(char const* identifier, Pipeline* next, writer_c_t fn, void* udata);
typedef int (*writer_c_char_t)(char const*, size_t, void*);
QPDF_DLL
- Pl_Function(
- char const* identifier,
- Pipeline* next,
- writer_c_char_t fn,
- void* udata);
+ Pl_Function(char const* identifier, Pipeline* next, writer_c_char_t fn, void* udata);
QPDF_DLL
virtual ~Pl_Function();
diff --git a/include/qpdf/Pl_QPDFTokenizer.hh b/include/qpdf/Pl_QPDFTokenizer.hh
index 0b8cafc2..37e87b4d 100644
--- a/include/qpdf/Pl_QPDFTokenizer.hh
+++ b/include/qpdf/Pl_QPDFTokenizer.hh
@@ -49,9 +49,7 @@ class QPDF_DLL_CLASS Pl_QPDFTokenizer: public Pipeline
// provided, any output written by the filter will be discarded.
QPDF_DLL
Pl_QPDFTokenizer(
- char const* identifier,
- QPDFObjectHandle::TokenFilter* filter,
- Pipeline* next = nullptr);
+ char const* identifier, QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr);
QPDF_DLL
virtual ~Pl_QPDFTokenizer();
QPDF_DLL
diff --git a/include/qpdf/QIntC.hh b/include/qpdf/QIntC.hh
index 4f224560..e6c337c2 100644
--- a/include/qpdf/QIntC.hh
+++ b/include/qpdf/QIntC.hh
@@ -78,9 +78,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion
{
std::ostringstream msg;
msg.imbue(std::locale::classic());
- msg << "integer out of range converting " << i << " from a "
- << sizeof(From) << "-byte unsigned type to a " << sizeof(To)
- << "-byte unsigned type";
+ msg << "integer out of range converting " << i << " from a " << sizeof(From)
+ << "-byte unsigned type to a " << sizeof(To) << "-byte unsigned type";
throw std::range_error(msg.str());
}
};
@@ -93,8 +92,7 @@ namespace QIntC // QIntC = qpdf Integer Conversion
convert(From const& i)
{
// From and To are both signed.
- if ((i < std::numeric_limits<To>::min()) ||
- (i > std::numeric_limits<To>::max())) {
+ if ((i < std::numeric_limits<To>::min()) || (i > std::numeric_limits<To>::max())) {
error(i);
}
return static_cast<To>(i);
@@ -105,9 +103,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion
{
std::ostringstream msg;
msg.imbue(std::locale::classic());
- msg << "integer out of range converting " << i << " from a "
- << sizeof(From) << "-byte signed type to a " << sizeof(To)
- << "-byte signed type";
+ msg << "integer out of range converting " << i << " from a " << sizeof(From)
+ << "-byte signed type to a " << sizeof(To) << "-byte signed type";
throw std::range_error(msg.str());
}
};
@@ -134,9 +131,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion
{
std::ostringstream msg;
msg.imbue(std::locale::classic());
- msg << "integer out of range converting " << i << " from a "
- << sizeof(From) << "-byte signed type to a " << sizeof(To)
- << "-byte unsigned type";
+ msg << "integer out of range converting " << i << " from a " << sizeof(From)
+ << "-byte signed type to a " << sizeof(To) << "-byte unsigned type";
throw std::range_error(msg.str());
}
};
@@ -150,8 +146,7 @@ namespace QIntC // QIntC = qpdf Integer Conversion
{
// From is unsigned, and to is signed. Convert To's max to the
// unsigned version of To and compare i against that.
- auto maxval = static_cast<typename to_u<To>::type>(
- std::numeric_limits<To>::max());
+ auto maxval = static_cast<typename to_u<To>::type>(std::numeric_limits<To>::max());
if (i > maxval) {
error(i);
}
@@ -163,9 +158,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion
{
std::ostringstream msg;
msg.imbue(std::locale::classic());
- msg << "integer out of range converting " << i << " from a "
- << sizeof(From) << "-byte unsigned type to a " << sizeof(To)
- << "-byte signed type";
+ msg << "integer out of range converting " << i << " from a " << sizeof(From)
+ << "-byte unsigned type to a " << sizeof(To) << "-byte signed type";
throw std::range_error(msg.str());
}
};
@@ -263,15 +257,12 @@ namespace QIntC // QIntC = qpdf Integer Conversion
if ((delta > 0) && ((std::numeric_limits<T>::max() - cur) < delta)) {
std::ostringstream msg;
msg.imbue(std::locale::classic());
- msg << "adding " << delta << " to " << cur
- << " would cause an integer overflow";
+ msg << "adding " << delta << " to " << cur << " would cause an integer overflow";
throw std::range_error(msg.str());
- } else if (
- (delta < 0) && ((std::numeric_limits<T>::min() - cur) > delta)) {
+ } else if ((delta < 0) && ((std::numeric_limits<T>::min() - cur) > delta)) {
std::ostringstream msg;
msg.imbue(std::locale::classic());
- msg << "adding " << delta << " to " << cur
- << " would cause an integer underflow";
+ msg << "adding " << delta << " to " << cur << " would cause an integer underflow";
throw std::range_error(msg.str());
}
}
@@ -296,12 +287,10 @@ namespace QIntC // QIntC = qpdf Integer Conversion
msg << "subtracting " << delta << " from " << cur
<< " would cause an integer underflow";
throw std::range_error(msg.str());
- } else if (
- (delta < 0) && ((std::numeric_limits<T>::max() + delta) < cur)) {
+ } else if ((delta < 0) && ((std::numeric_limits<T>::max() + delta) < cur)) {
std::ostringstream msg;
msg.imbue(std::locale::classic());
- msg << "subtracting " << delta << " from " << cur
- << " would cause an integer overflow";
+ msg << "subtracting " << delta << " from " << cur << " would cause an integer overflow";
throw std::range_error(msg.str());
}
}
diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh
index 905c4b05..87849dbd 100644
--- a/include/qpdf/QPDF.hh
+++ b/include/qpdf/QPDF.hh
@@ -93,10 +93,7 @@ class QPDF
// responsible for closing the file.
QPDF_DLL
void processFile(
- char const* description,
- FILE* file,
- bool close_file,
- char const* password = nullptr);
+ char const* description, FILE* file, bool close_file, char const* password = nullptr);
// Parse a PDF file loaded into a memory buffer. This works
// exactly like processFile except that the PDF file is in memory
@@ -104,17 +101,13 @@ class QPDF
// error message in place of the file name.
QPDF_DLL
void processMemoryFile(
- char const* description,
- char const* buf,
- size_t length,
- char const* password = nullptr);
+ char const* description, char const* buf, size_t length, char const* password = nullptr);
// Parse a PDF file loaded from a custom InputSource. If you have
// your own method of retrieving a PDF file, you can subclass
// InputSource and use this method.
QPDF_DLL
- void processInputSource(
- std::shared_ptr<InputSource>, char const* password = nullptr);
+ void processInputSource(std::shared_ptr<InputSource>, char const* password = nullptr);
// Create a PDF from an input source that contains JSON as written
// by writeJSON (or qpdf --json-output, version 2 or higher). The
@@ -234,8 +227,7 @@ class QPDF
// QPDFStreamFilter classes.
QPDF_DLL
static void registerStreamFilter(
- std::string const& filter_name,
- std::function<std::shared_ptr<QPDFStreamFilter>()> factory);
+ std::string const& filter_name, std::function<std::shared_ptr<QPDFStreamFilter>()> factory);
// Parameter settings
@@ -260,8 +252,7 @@ class QPDF
// configures a private logger, separating this object from the
// default logger, and calls setOutputStreams on that logger. See
// QPDFLogger.hh for additional details.
- [[deprecated(
- "configure logger from getLogger() or call setLogger()")]] QPDF_DLL void
+ [[deprecated("configure logger from getLogger() or call setLogger()")]] QPDF_DLL void
setOutputStreams(std::ostream* out_stream, std::ostream* err_stream);
// If true, ignore any cross-reference streams in a hybrid file
@@ -481,8 +472,7 @@ class QPDF
// reserved object. After this call, reserved will be a reference
// to replacement.
QPDF_DLL
- void
- replaceReserved(QPDFObjectHandle reserved, QPDFObjectHandle replacement);
+ void replaceReserved(QPDFObjectHandle reserved, QPDFObjectHandle replacement);
// Copy an object from another QPDF to this one. Starting with
// qpdf version 8.3.0, it is no longer necessary to keep the
@@ -657,8 +647,8 @@ class QPDF
int encryption_V,
int encryption_R);
QPDF_DLL
- static std::string compute_encryption_key(
- std::string const& password, EncryptionData const& data);
+ static std::string
+ compute_encryption_key(std::string const& password, EncryptionData const& data);
QPDF_DLL
static void compute_encryption_O_U(
@@ -843,8 +833,7 @@ class QPDF
QPDF_DLL
void addPage(QPDFObjectHandle newpage, bool first);
QPDF_DLL
- void
- addPageAt(QPDFObjectHandle newpage, bool before, QPDFObjectHandle refpage);
+ void addPageAt(QPDFObjectHandle newpage, bool before, QPDFObjectHandle refpage);
QPDF_DLL
void removePage(QPDFObjectHandle page);
// End legacy page helpers
@@ -866,8 +855,7 @@ class QPDF
std::vector<QPDFObjectHandle>& part8,
std::vector<QPDFObjectHandle>& part9)
{
- qpdf.getLinearizedParts(
- object_stream_data, part4, part6, part7, part8, part9);
+ qpdf.getLinearizedParts(object_stream_data, part4, part6, part7, part8, part9);
}
static void
@@ -880,8 +868,7 @@ class QPDF
int& S,
int& O)
{
- return qpdf.generateHintStream(
- xref, lengths, obj_renumber, hint_stream, S, O);
+ return qpdf.generateHintStream(xref, lengths, obj_renumber, hint_stream, S, O);
}
static void
@@ -919,10 +906,7 @@ class QPDF
private:
static void
- copyStreamData(
- QPDF* qpdf,
- QPDFObjectHandle const& dest,
- QPDFObjectHandle const& src)
+ copyStreamData(QPDF* qpdf, QPDFObjectHandle const& dest, QPDFObjectHandle const& src)
{
qpdf->copyStreamData(dest, src);
}
@@ -968,13 +952,7 @@ class QPDF
bool will_retry)
{
return qpdf->pipeStreamData(
- og,
- offset,
- length,
- dict,
- pipeline,
- suppress_warnings,
- will_retry);
+ og, offset, length, dict, pipeline, suppress_warnings, will_retry);
}
};
@@ -1096,16 +1074,13 @@ class QPDF
Pipeline* pipeline,
bool suppress_warnings,
bool will_retry) override;
- void registerForeignStream(
- QPDFObjGen const& local_og, QPDFObjectHandle foreign_stream);
- void registerForeignStream(
- QPDFObjGen const& local_og, std::shared_ptr<ForeignStreamData>);
+ void registerForeignStream(QPDFObjGen const& local_og, QPDFObjectHandle foreign_stream);
+ void registerForeignStream(QPDFObjGen const& local_og, std::shared_ptr<ForeignStreamData>);
private:
QPDF& destination_qpdf;
std::map<QPDFObjGen, QPDFObjectHandle> foreign_streams;
- std::map<QPDFObjGen, std::shared_ptr<ForeignStreamData>>
- foreign_stream_data;
+ std::map<QPDFObjGen, std::shared_ptr<ForeignStreamData>> foreign_stream_data;
};
class StringDecrypter: public QPDFObjectHandle::StringDecrypter
@@ -1148,29 +1123,21 @@ class QPDF
void read_xref(qpdf_offset_t offset);
bool resolveXRefTable();
void reconstruct_xref(QPDFExc& e);
- bool
- parse_xrefFirst(std::string const& line, int& obj, int& num, int& bytes);
- bool parse_xrefEntry(
- std::string const& line, qpdf_offset_t& f1, int& f2, char& type);
+ bool parse_xrefFirst(std::string const& line, int& obj, int& num, int& bytes);
+ bool parse_xrefEntry(std::string const& line, qpdf_offset_t& f1, int& f2, char& type);
qpdf_offset_t read_xrefTable(qpdf_offset_t offset);
qpdf_offset_t read_xrefStream(qpdf_offset_t offset);
- qpdf_offset_t
- processXRefStream(qpdf_offset_t offset, QPDFObjectHandle& xref_stream);
- void insertXrefEntry(
- int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite = false);
- void setLastObjectDescription(
- std::string const& description, QPDFObjGen const& og);
+ qpdf_offset_t processXRefStream(qpdf_offset_t offset, QPDFObjectHandle& xref_stream);
+ void insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite = false);
+ void setLastObjectDescription(std::string const& description, QPDFObjGen const& og);
QPDFObjectHandle readObject(
std::shared_ptr<InputSource>,
std::string const& description,
QPDFObjGen const& og,
bool in_object_stream);
size_t recoverStreamLength(
- std::shared_ptr<InputSource> input,
- QPDFObjGen const& og,
- qpdf_offset_t stream_offset);
- QPDFTokenizer::Token
- readToken(std::shared_ptr<InputSource>, size_t max_len = 0);
+ std::shared_ptr<InputSource> input, QPDFObjGen const& og, qpdf_offset_t stream_offset);
+ QPDFTokenizer::Token readToken(std::shared_ptr<InputSource>, size_t max_len = 0);
QPDFObjectHandle readObjectAtOffset(
bool attempt_recovery,
@@ -1185,10 +1152,8 @@ class QPDF
QPDFObjectHandle reserveObjectIfNotExists(QPDFObjGen const& og);
QPDFObjectHandle reserveStream(QPDFObjGen const& og);
QPDFObjGen nextObjGen();
- QPDFObjectHandle
- newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&);
- QPDFObjectHandle
- makeIndirectFromQPDFObject(std::shared_ptr<QPDFObject> const& obj);
+ QPDFObjectHandle newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&);
+ QPDFObjectHandle makeIndirectFromQPDFObject(std::shared_ptr<QPDFObject> const& obj);
bool isCached(QPDFObjGen const& og);
bool isUnresolved(QPDFObjGen const& og);
void updateCache(
@@ -1205,10 +1170,7 @@ class QPDF
std::shared_ptr<InputSource> const& input,
qpdf_offset_t offset,
std::string const& message);
- QPDFExc damagedPDF(
- std::string const& object,
- qpdf_offset_t offset,
- std::string const& message);
+ QPDFExc damagedPDF(std::string const& object, qpdf_offset_t offset, std::string const& message);
QPDFExc damagedPDF(std::string const& object, std::string const& message);
QPDFExc damagedPDF(qpdf_offset_t offset, std::string const& message);
QPDFExc damagedPDF(std::string const& message);
@@ -1223,10 +1185,7 @@ class QPDF
bool suppress_warnings,
bool will_retry);
bool pipeForeignStreamData(
- std::shared_ptr<ForeignStreamData>,
- Pipeline*,
- bool suppress_warnings,
- bool will_retry);
+ std::shared_ptr<ForeignStreamData>, Pipeline*, bool suppress_warnings, bool will_retry);
static bool pipeStreamData(
std::shared_ptr<QPDF::EncryptionParameters> encp,
std::shared_ptr<InputSource> file,
@@ -1269,31 +1228,24 @@ class QPDF
// methods to support page handling
void getAllPagesInternal(
- QPDFObjectHandle cur_pages,
- QPDFObjGen::set& visited,
- QPDFObjGen::set& seen);
+ QPDFObjectHandle cur_pages, QPDFObjGen::set& visited, QPDFObjGen::set& seen);
void insertPage(QPDFObjectHandle newpage, int pos);
void flattenPagesTree();
- void insertPageobjToPage(
- QPDFObjectHandle const& obj, int pos, bool check_duplicate);
+ void insertPageobjToPage(QPDFObjectHandle const& obj, int pos, bool check_duplicate);
// methods to support encryption -- implemented in QPDF_encryption.cc
static encryption_method_e
interpretCF(std::shared_ptr<EncryptionParameters> encp, QPDFObjectHandle);
void initializeEncryption();
- static std::string getKeyForObject(
- std::shared_ptr<EncryptionParameters> encp,
- QPDFObjGen const& og,
- bool use_aes);
+ static std::string
+ getKeyForObject(std::shared_ptr<EncryptionParameters> encp, QPDFObjGen const& og, bool use_aes);
void decryptString(std::string&, QPDFObjGen const& og);
- static std::string compute_encryption_key_from_password(
- std::string const& password, EncryptionData const& data);
- static std::string recover_encryption_key_with_password(
- std::string const& password, EncryptionData const& data);
+ static std::string
+ compute_encryption_key_from_password(std::string const& password, EncryptionData const& data);
+ static std::string
+ recover_encryption_key_with_password(std::string const& password, EncryptionData const& data);
static std::string recover_encryption_key_with_password(
- std::string const& password,
- EncryptionData const& data,
- bool& perms_valid);
+ std::string const& password, EncryptionData const& data, bool& perms_valid);
static void decryptStream(
std::shared_ptr<EncryptionParameters> encp,
std::shared_ptr<InputSource> file,
@@ -1304,12 +1256,10 @@ class QPDF
std::vector<std::shared_ptr<Pipeline>>& heap);
// Methods to support object copying
- void
- reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top);
- QPDFObjectHandle replaceForeignIndirectObjects(
- QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top);
- void
- copyStreamData(QPDFObjectHandle dest_stream, QPDFObjectHandle src_stream);
+ void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top);
+ QPDFObjectHandle
+ replaceForeignIndirectObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top);
+ void copyStreamData(QPDFObjectHandle dest_stream, QPDFObjectHandle src_stream);
// Linearization Hint table structures.
// Naming conventions:
@@ -1538,14 +1488,7 @@ class QPDF
class ObjUser
{
public:
- enum user_e {
- ou_bad,
- ou_page,
- ou_thumb,
- ou_trailer_key,
- ou_root_key,
- ou_root
- };
+ enum user_e { ou_bad, ou_page, ou_thumb, ou_trailer_key, ou_root_key, ou_root };
// type is set to ou_bad
ObjUser();
@@ -1598,29 +1541,25 @@ class QPDF
bool checkLinearizationInternal();
void dumpLinearizationDataInternal();
void linearizationWarning(std::string_view);
- QPDFObjectHandle
- readHintStream(Pipeline&, qpdf_offset_t offset, size_t length);
+ QPDFObjectHandle readHintStream(Pipeline&, qpdf_offset_t offset, size_t length);
void readHPageOffset(BitStream);
void readHSharedObject(BitStream);
void readHGeneric(BitStream, HGeneric&);
qpdf_offset_t maxEnd(ObjUser const& ou);
qpdf_offset_t getLinearizationOffset(QPDFObjGen const&);
- QPDFObjectHandle getUncompressedObject(
- QPDFObjectHandle&, std::map<int, int> const& object_stream_data);
+ QPDFObjectHandle
+ getUncompressedObject(QPDFObjectHandle&, std::map<int, int> const& object_stream_data);
int lengthNextN(int first_object, int n);
- void checkHPageOffset(
- std::vector<QPDFObjectHandle> const& pages,
- std::map<int, int>& idx_to_obj);
- void checkHSharedObject(
- std::vector<QPDFObjectHandle> const& pages,
- std::map<int, int>& idx_to_obj);
+ void
+ checkHPageOffset(std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& idx_to_obj);
+ void
+ checkHSharedObject(std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& idx_to_obj);
void checkHOutlines();
void dumpHPageOffset();
void dumpHSharedObject();
void dumpHGeneric(HGeneric&);
qpdf_offset_t adjusted_offset(qpdf_offset_t offset);
- void
- calculateLinearizationData(std::map<int, int> const& object_stream_data);
+ void calculateLinearizationData(std::map<int, int> const& object_stream_data);
void pushOutlinesToPart(
std::vector<QPDFObjectHandle>& part,
std::set<QPDFObjGen>& lc_outlines,
@@ -1648,8 +1587,7 @@ class QPDF
// Methods to support optimization
- void
- pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys);
+ void pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys);
void pushInheritedAttributesToPageInternal(
QPDFObjectHandle,
std::map<std::string, std::vector<QPDFObjectHandle>>&,
@@ -1681,11 +1619,7 @@ class QPDF
qpdf_json_stream_data_e,
std::string const& file_prefix);
void writeJSONObject(
- int version,
- Pipeline* p,
- bool& first,
- std::string const& key,
- QPDFObjectHandle&);
+ int version, Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle&);
// Type conversion helper methods
template <typename T>
diff --git a/include/qpdf/QPDFAcroFormDocumentHelper.hh b/include/qpdf/QPDFAcroFormDocumentHelper.hh
index d1ac6253..1ae593af 100644
--- a/include/qpdf/QPDFAcroFormDocumentHelper.hh
+++ b/include/qpdf/QPDFAcroFormDocumentHelper.hh
@@ -148,18 +148,15 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
// underlying object will typically be the same as the underlying
// object for the field.
QPDF_DLL
- std::vector<QPDFAnnotationObjectHelper>
- getAnnotationsForField(QPDFFormFieldObjectHelper);
+ std::vector<QPDFAnnotationObjectHelper> getAnnotationsForField(QPDFFormFieldObjectHelper);
// Return annotations of subtype /Widget for a page.
QPDF_DLL
- std::vector<QPDFAnnotationObjectHelper>
- getWidgetAnnotationsForPage(QPDFPageObjectHelper);
+ std::vector<QPDFAnnotationObjectHelper> getWidgetAnnotationsForPage(QPDFPageObjectHelper);
// Return top-level form fields for a page.
QPDF_DLL
- std::vector<QPDFFormFieldObjectHelper>
- getFormFieldsForPage(QPDFPageObjectHelper);
+ std::vector<QPDFFormFieldObjectHelper> getFormFieldsForPage(QPDFPageObjectHelper);
// Return the terminal field that is associated with this
// annotation. If the annotation dictionary is merged with the
@@ -251,10 +248,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
private:
void analyze();
void traverseField(
- QPDFObjectHandle field,
- QPDFObjectHandle parent,
- int depth,
- QPDFObjGen::set& visited);
+ QPDFObjectHandle field, QPDFObjectHandle parent, int depth, QPDFObjGen::set& visited);
QPDFObjectHandle getOrCreateAcroForm();
void adjustInheritedFields(
QPDFObjectHandle obj,
@@ -264,11 +258,9 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
int from_default_q);
void adjustDefaultAppearances(
QPDFObjectHandle obj,
- std::map<std::string, std::map<std::string, std::string>> const&
- dr_map);
+ std::map<std::string, std::map<std::string, std::string>> const& dr_map);
void adjustAppearanceStream(
- QPDFObjectHandle stream,
- std::map<std::string, std::map<std::string, std::string>> dr_map);
+ QPDFObjectHandle stream, std::map<std::string, std::map<std::string, std::string>> dr_map);
class Members
{
@@ -283,8 +275,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
Members(Members const&) = delete;
bool cache_valid;
- std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>>
- field_to_annotations;
+ std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>> field_to_annotations;
std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field;
std::map<QPDFObjGen, std::string> field_to_name;
std::map<std::string, std::set<QPDFObjGen>> name_to_fields;
diff --git a/include/qpdf/QPDFAnnotationObjectHelper.hh b/include/qpdf/QPDFAnnotationObjectHelper.hh
index a28bf495..b3d57092 100644
--- a/include/qpdf/QPDFAnnotationObjectHelper.hh
+++ b/include/qpdf/QPDFAnnotationObjectHelper.hh
@@ -76,8 +76,7 @@ class QPDFAnnotationObjectHelper: public QPDFObjectHelper
// which appearance stream is desired. If not specified, the
// appearance state in "/AS" will used.
QPDF_DLL
- QPDFObjectHandle getAppearanceStream(
- std::string const& which, std::string const& state = "");
+ QPDFObjectHandle getAppearanceStream(std::string const& which, std::string const& state = "");
// Generate text suitable for addition to the containing page's
// content stream that draws this annotation's appearance stream
diff --git a/include/qpdf/QPDFCryptoImpl.hh b/include/qpdf/QPDFCryptoImpl.hh
index 3fd64d3a..522b72aa 100644
--- a/include/qpdf/QPDFCryptoImpl.hh
+++ b/include/qpdf/QPDFCryptoImpl.hh
@@ -77,10 +77,8 @@ class QPDF_DLL_CLASS QPDFCryptoImpl
virtual void RC4_init(unsigned char const* key_data, int key_len = -1) = 0;
// out_data = 0 means to encrypt/decrypt in place
QPDF_DLL
- virtual void RC4_process(
- unsigned char const* in_data,
- size_t len,
- unsigned char* out_data = nullptr) = 0;
+ virtual void
+ RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = nullptr) = 0;
QPDF_DLL
virtual void RC4_finalize() = 0;
@@ -93,8 +91,7 @@ class QPDF_DLL_CLASS QPDFCryptoImpl
bool cbc_mode,
unsigned char* cbc_block) = 0;
QPDF_DLL
- virtual void
- rijndael_process(unsigned char* in_data, unsigned char* out_data) = 0;
+ virtual void rijndael_process(unsigned char* in_data, unsigned char* out_data) = 0;
QPDF_DLL
virtual void rijndael_finalize() = 0;
};
diff --git a/include/qpdf/QPDFCryptoProvider.hh b/include/qpdf/QPDFCryptoProvider.hh
index 122cb882..46a9379d 100644
--- a/include/qpdf/QPDFCryptoProvider.hh
+++ b/include/qpdf/QPDFCryptoProvider.hh
@@ -78,8 +78,7 @@ class QPDFCryptoProvider
static QPDFCryptoProvider& getInstance();
- std::shared_ptr<QPDFCryptoImpl>
- getImpl_internal(std::string const& name) const;
+ std::shared_ptr<QPDFCryptoImpl> getImpl_internal(std::string const& name) const;
template <typename T>
void registerImpl_internal(std::string const& name);
void setDefaultProvider_internal(std::string const& name);
diff --git a/include/qpdf/QPDFEFStreamObjectHelper.hh b/include/qpdf/QPDFEFStreamObjectHelper.hh
index 2a24c0c3..b164dbe3 100644
--- a/include/qpdf/QPDFEFStreamObjectHelper.hh
+++ b/include/qpdf/QPDFEFStreamObjectHelper.hh
@@ -75,11 +75,9 @@ class QPDFEFStreamObjectHelper: public QPDFObjectHelper
// checksum and size are computed automatically and stored. Other
// parameters may be supplied using setters defined below.
QPDF_DLL
- static QPDFEFStreamObjectHelper
- createEFStream(QPDF& qpdf, std::shared_ptr<Buffer> data);
+ static QPDFEFStreamObjectHelper createEFStream(QPDF& qpdf, std::shared_ptr<Buffer> data);
QPDF_DLL
- static QPDFEFStreamObjectHelper
- createEFStream(QPDF& qpdf, std::string const& data);
+ static QPDFEFStreamObjectHelper createEFStream(QPDF& qpdf, std::string const& data);
// The provider function must write the data to the given
// pipeline. The function may be called multiple times by the qpdf
// library. You can pass QUtil::file_provider(filename) as the
diff --git a/include/qpdf/QPDFEmbeddedFileDocumentHelper.hh b/include/qpdf/QPDFEmbeddedFileDocumentHelper.hh
index 9bab725a..5ee608bd 100644
--- a/include/qpdf/QPDFEmbeddedFileDocumentHelper.hh
+++ b/include/qpdf/QPDFEmbeddedFileDocumentHelper.hh
@@ -48,19 +48,16 @@ class QPDFEmbeddedFileDocumentHelper: public QPDFDocumentHelper
bool hasEmbeddedFiles() const;
QPDF_DLL
- std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>>
- getEmbeddedFiles();
+ std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> getEmbeddedFiles();
// If an embedded file with the given name exists, return a
// (shared) pointer to it. Otherwise, return nullptr.
QPDF_DLL
- std::shared_ptr<QPDFFileSpecObjectHelper>
- getEmbeddedFile(std::string const& name);
+ std::shared_ptr<QPDFFileSpecObjectHelper> getEmbeddedFile(std::string const& name);
// Add or replace an attachment
QPDF_DLL
- void replaceEmbeddedFile(
- std::string const& name, QPDFFileSpecObjectHelper const&);
+ void replaceEmbeddedFile(std::string const& name, QPDFFileSpecObjectHelper const&);
// Remove an embedded file if present. Return value is true if the
// file was present and was removed. This method not only removes
diff --git a/include/qpdf/QPDFFileSpecObjectHelper.hh b/include/qpdf/QPDFFileSpecObjectHelper.hh
index fa70c035..040399bc 100644
--- a/include/qpdf/QPDFFileSpecObjectHelper.hh
+++ b/include/qpdf/QPDFFileSpecObjectHelper.hh
@@ -77,16 +77,16 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper
// filename, and attach the contents of the specified file as data
// in an embedded file stream.
QPDF_DLL
- static QPDFFileSpecObjectHelper createFileSpec(
- QPDF& qpdf, std::string const& filename, std::string const& fullpath);
+ static QPDFFileSpecObjectHelper
+ createFileSpec(QPDF& qpdf, std::string const& filename, std::string const& fullpath);
// Create a new filespec as an indirect object with the given
// unicode filename and embedded file stream. The file name will
// be used as both /UF and /F. If you need to override, call
// setFilename.
QPDF_DLL
- static QPDFFileSpecObjectHelper createFileSpec(
- QPDF& qpdf, std::string const& filename, QPDFEFStreamObjectHelper);
+ static QPDFFileSpecObjectHelper
+ createFileSpec(QPDF& qpdf, std::string const& filename, QPDFEFStreamObjectHelper);
QPDF_DLL
QPDFFileSpecObjectHelper& setDescription(std::string const&);
@@ -96,8 +96,8 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper
// QPDFObjectHandle literally, preserving whatever encoding it
// might happen to have.
QPDF_DLL
- QPDFFileSpecObjectHelper& setFilename(
- std::string const& unicode_name, std::string const& compat_name = "");
+ QPDFFileSpecObjectHelper&
+ setFilename(std::string const& unicode_name, std::string const& compat_name = "");
private:
class Members
diff --git a/include/qpdf/QPDFFormFieldObjectHelper.hh b/include/qpdf/QPDFFormFieldObjectHelper.hh
index 1d8317b3..2221684a 100644
--- a/include/qpdf/QPDFFormFieldObjectHelper.hh
+++ b/include/qpdf/QPDFFormFieldObjectHelper.hh
@@ -183,8 +183,7 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper
// of a field, use QPDFAcroFormDocumentHelper::setFormFieldName
// instead.
QPDF_DLL
- void
- setFieldAttribute(std::string const& key, std::string const& utf8_value);
+ void setFieldAttribute(std::string const& key, std::string const& utf8_value);
// Set /V (field value) to the given value. If need_appearances is
// true and the field type is either /Tx (text) or /Ch (choice),
@@ -218,8 +217,7 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper
void setRadioButtonValue(QPDFObjectHandle name);
void setCheckBoxValue(bool value);
void generateTextAppearance(QPDFAnnotationObjectHelper&);
- QPDFObjectHandle getFontFromResource(
- QPDFObjectHandle resources, std::string const& font_name);
+ QPDFObjectHandle getFontFromResource(QPDFObjectHandle resources, std::string const& font_name);
class Members
{
diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh
index 27ab96d3..4f90990f 100644
--- a/include/qpdf/QPDFJob.hh
+++ b/include/qpdf/QPDFJob.hh
@@ -83,8 +83,7 @@ class QPDFJob
// about converting arguments to UTF-8. This method will mutate
// arguments that are passed to it.
QPDF_DLL
- void initializeFromArgv(
- char const* const argv[], char const* progname_env = nullptr);
+ void initializeFromArgv(char const* const argv[], char const* progname_env = nullptr);
// Initialize a QPDFJob from json. Passing partial = true prevents
// this method from doing the final checks (calling
@@ -132,8 +131,7 @@ class QPDFJob
// configures a private logger, separating this object from the
// default logger, and calls setOutputStreams on that logger. See
// QPDFLogger.hh for additional details.
- [[deprecated(
- "configure logger from getLogger() or call setLogger()")]] QPDF_DLL void
+ [[deprecated("configure logger from getLogger() or call setLogger()")]] QPDF_DLL void
setOutputStreams(std::ostream* out_stream, std::ostream* err_stream);
// You can register a custom progress reporter to be called by
@@ -187,10 +185,7 @@ class QPDFJob
struct PageSpec
{
- PageSpec(
- std::string const& filename,
- char const* password,
- std::string const& range);
+ PageSpec(std::string const& filename, char const* password, std::string const& range);
std::string filename;
std::shared_ptr<char> password;
@@ -284,9 +279,7 @@ class QPDFJob
Config* endPages();
QPDF_DLL
PagesConfig* pageSpec(
- std::string const& filename,
- std::string const& range,
- char const* password = nullptr);
+ std::string const& filename, std::string const& range, char const* password = nullptr);
#include <qpdf/auto_job_c_pages.hh>
@@ -366,10 +359,8 @@ class QPDFJob
QPDF_DLL
std::shared_ptr<UOConfig> underlay();
QPDF_DLL
- std::shared_ptr<EncConfig> encrypt(
- int keylen,
- std::string const& user_password,
- std::string const& owner_password);
+ std::shared_ptr<EncConfig>
+ encrypt(int keylen, std::string const& user_password, std::string const& owner_password);
#include <qpdf/auto_job_c_main.hh>
@@ -438,8 +429,7 @@ class QPDFJob
// If in verbose mode, call the given function, passing in the
// output stream and message prefix.
QPDF_DLL
- void
- doIfVerbose(std::function<void(Pipeline&, std::string const& prefix)> fn);
+ void doIfVerbose(std::function<void(Pipeline&, std::string const& prefix)> fn);
// Provide a string that is the help information ("schema" for the
// qpdf-specific JSON object) for the specified version of JSON
@@ -447,16 +437,14 @@ class QPDFJob
QPDF_DLL
static std::string json_out_schema(int version);
- [[deprecated("use json_out_schema(version)")]] static std::string QPDF_DLL
- json_out_schema_v1();
+ [[deprecated("use json_out_schema(version)")]] static std::string QPDF_DLL json_out_schema_v1();
// Provide a string that is the help information for specified
// version of JSON format for QPDFJob.
QPDF_DLL
static std::string job_json_schema(int version);
- [[deprecated("use job_json_schema(version)")]] static std::string QPDF_DLL
- job_json_schema_v1();
+ [[deprecated("use job_json_schema(version)")]] static std::string QPDF_DLL job_json_schema_v1();
private:
struct RotationSpec
@@ -497,10 +485,8 @@ class QPDFJob
// Helper functions
static void usage(std::string const& msg);
- static JSON
- json_schema(int json_version, std::set<std::string>* keys = nullptr);
- static void parse_object_id(
- std::string const& objspec, bool& trailer, int& obj, int& gen);
+ static JSON json_schema(int json_version, std::set<std::string>* keys = nullptr);
+ static void parse_object_id(std::string const& objspec, bool& trailer, int& obj, int& gen);
void parseRotationParameter(std::string const&);
std::vector<int> parseNumrange(char const* range, int max);
@@ -533,12 +519,10 @@ class QPDFJob
// Transformations
void setQPDFOptions(QPDF& pdf);
- void
- handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_heap);
+ void handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_heap);
bool shouldRemoveUnreferencedResources(QPDF& pdf);
void handleRotations(QPDF& pdf);
- void
- getUOPagenos(UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos);
+ void getUOPagenos(UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos);
void handleUnderOverlay(QPDF& pdf);
std::string doUnderOverlayForPage(
QPDF& pdf,
@@ -573,8 +557,7 @@ class QPDFJob
// JSON
void doJSON(QPDF& pdf, Pipeline*);
QPDFObjGen::set getWantedJSONObjects();
- void doJSONObject(
- Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle&);
+ void doJSONObject(Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle&);
void doJSONObjects(Pipeline* p, bool& first, QPDF& pdf);
void doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf);
void doJSONPages(Pipeline* p, bool& first, QPDF& pdf);
diff --git a/include/qpdf/QPDFLogger.hh b/include/qpdf/QPDFLogger.hh
index 6875721f..2b7c7a9b 100644
--- a/include/qpdf/QPDFLogger.hh
+++ b/include/qpdf/QPDFLogger.hh
@@ -153,8 +153,7 @@ class QPDFLogger
private:
QPDFLogger();
- std::shared_ptr<Pipeline>
- throwIfNull(std::shared_ptr<Pipeline>, bool null_okay);
+ std::shared_ptr<Pipeline> throwIfNull(std::shared_ptr<Pipeline>, bool null_okay);
class Members
{
diff --git a/include/qpdf/QPDFMatrix.hh b/include/qpdf/QPDFMatrix.hh
index 0756921a..fb005e50 100644
--- a/include/qpdf/QPDFMatrix.hh
+++ b/include/qpdf/QPDFMatrix.hh
@@ -79,8 +79,7 @@ class QPDFMatrix
// bounds the polygon resulting from transforming the four
// corners.
QPDF_DLL
- QPDFObjectHandle::Rectangle
- transformRectangle(QPDFObjectHandle::Rectangle r) const;
+ QPDFObjectHandle::Rectangle transformRectangle(QPDFObjectHandle::Rectangle r) const;
// operator== tests for exact equality, not considering deltas for
// floating point.
diff --git a/include/qpdf/QPDFNameTreeObjectHelper.hh b/include/qpdf/QPDFNameTreeObjectHelper.hh
index 8dbe4191..e0023013 100644
--- a/include/qpdf/QPDFNameTreeObjectHelper.hh
+++ b/include/qpdf/QPDFNameTreeObjectHelper.hh
@@ -156,8 +156,7 @@ class QPDF_DLL_CLASS QPDFNameTreeObjectHelper: public QPDFObjectHelper
// Find the entry with the given key. If return_prev_if_not_found
// is true and the item is not found, return the next lower item.
QPDF_DLL
- iterator
- find(std::string const& key, bool return_prev_if_not_found = false);
+ iterator find(std::string const& key, bool return_prev_if_not_found = false);
// Insert a new item. If the key already exists, it is replaced.
QPDF_DLL
diff --git a/include/qpdf/QPDFNumberTreeObjectHelper.hh b/include/qpdf/QPDFNumberTreeObjectHelper.hh
index f88f185a..82933b21 100644
--- a/include/qpdf/QPDFNumberTreeObjectHelper.hh
+++ b/include/qpdf/QPDFNumberTreeObjectHelper.hh
@@ -45,8 +45,7 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper
// The qpdf object is required so that this class can issue
// warnings, attempt repairs, and add indirect objects.
QPDF_DLL
- QPDFNumberTreeObjectHelper(
- QPDFObjectHandle, QPDF&, bool auto_repair = true);
+ QPDFNumberTreeObjectHelper(QPDFObjectHandle, QPDF&, bool auto_repair = true);
QPDF_DLL
virtual ~QPDFNumberTreeObjectHelper();
@@ -82,8 +81,7 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper
// oh to the value with index 3, and set offset to 2 (5 - 3). See
// also find().
QPDF_DLL
- bool findObjectAtOrBelow(
- numtree_number idx, QPDFObjectHandle& oh, numtree_number& offset);
+ bool findObjectAtOrBelow(numtree_number idx, QPDFObjectHandle& oh, numtree_number& offset);
class QPDF_DLL_PRIVATE iterator
{
diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh
index aeca4bf6..358f0465 100644
--- a/include/qpdf/QPDFObjectHandle.hh
+++ b/include/qpdf/QPDFObjectHandle.hh
@@ -128,22 +128,13 @@ class QPDFObjectHandle
// version of the method, which should also return a boolean
// indicating whether it ran without errors.
QPDF_DLL
- virtual void
- provideStreamData(QPDFObjGen const& og, Pipeline* pipeline);
+ virtual void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline);
QPDF_DLL
virtual bool provideStreamData(
- QPDFObjGen const& og,
- Pipeline* pipeline,
- bool suppress_warnings,
- bool will_retry);
- QPDF_DLL virtual void
- provideStreamData(int objid, int generation, Pipeline* pipeline);
+ QPDFObjGen const& og, Pipeline* pipeline, bool suppress_warnings, bool will_retry);
+ QPDF_DLL virtual void provideStreamData(int objid, int generation, Pipeline* pipeline);
QPDF_DLL virtual bool provideStreamData(
- int objid,
- int generation,
- Pipeline* pipeline,
- bool suppress_warnings,
- bool will_retry);
+ int objid, int generation, Pipeline* pipeline, bool suppress_warnings, bool will_retry);
QPDF_DLL
bool supportsRetry();
@@ -246,8 +237,7 @@ class QPDFObjectHandle
QPDF_DLL
virtual void handleObject(QPDFObjectHandle);
QPDF_DLL
- virtual void
- handleObject(QPDFObjectHandle, size_t offset, size_t length);
+ virtual void handleObject(QPDFObjectHandle, size_t offset, size_t length);
virtual void handleEOF() = 0;
@@ -408,14 +398,12 @@ class QPDFObjectHandle
// True if the object is a dictionary of the specified type and
// subtype, if any.
QPDF_DLL
- bool isDictionaryOfType(
- std::string const& type, std::string const& subtype = "");
+ bool isDictionaryOfType(std::string const& type, std::string const& subtype = "");
// True if the object is a stream of the specified type and
// subtype, if any.
QPDF_DLL
- bool
- isStreamOfType(std::string const& type, std::string const& subtype = "");
+ bool isStreamOfType(std::string const& type, std::string const& subtype = "");
// Public factory methods
@@ -433,9 +421,8 @@ class QPDFObjectHandle
// in the message of any QPDFExc exception thrown for invalid
// syntax. See also the global `operator ""_qpdf` defined below.
QPDF_DLL
- static QPDFObjectHandle parse(
- std::string const& object_str,
- std::string const& object_description = "");
+ static QPDFObjectHandle
+ parse(std::string const& object_str, std::string const& object_description = "");
// Construct an object of any type from a string representation of
// the object. Indirect object syntax (obj gen R) is allowed and
@@ -447,10 +434,8 @@ class QPDFObjectHandle
// object, which will just be the first number and will report
// that there is trailing data at the end of the string.
QPDF_DLL
- static QPDFObjectHandle parse(
- QPDF* context,
- std::string const& object_str,
- std::string const& object_description = "");
+ static QPDFObjectHandle
+ parse(QPDF* context, std::string const& object_str, std::string const& object_description = "");
// Construct an object as above by reading from the given
// InputSource at its current position and using the tokenizer you
@@ -480,8 +465,7 @@ class QPDFObjectHandle
// error messages will also be more useful because the page object
// information will be known.
QPDF_DLL
- static void parseContentStream(
- QPDFObjectHandle stream_or_array, ParserCallbacks* callbacks);
+ static void parseContentStream(QPDFObjectHandle stream_or_array, ParserCallbacks* callbacks);
// When called on a stream or stream array that is some page's
// content streams, do the same as pipePageContents. This method
@@ -500,10 +484,8 @@ class QPDFObjectHandle
// Pl_Concatenate and then call manualFinish() on the
// Pl_Concatenate pipeline at the end.
QPDF_DLL
- void pipeContentStreams(
- Pipeline* p,
- std::string const& description,
- std::string& all_description);
+ void
+ pipeContentStreams(Pipeline* p, std::string const& description, std::string& all_description);
// As of qpdf 8, it is possible to add custom token filters to a
// stream. The tokenized stream data is passed through the token
@@ -554,8 +536,8 @@ class QPDFObjectHandle
QPDF_DLL
static QPDFObjectHandle newReal(std::string const& value);
QPDF_DLL
- static QPDFObjectHandle newReal(
- double value, int decimal_places = 0, bool trim_trailing_zeroes = true);
+ static QPDFObjectHandle
+ newReal(double value, int decimal_places = 0, bool trim_trailing_zeroes = true);
// Note about name objects: qpdf's internal representation of a
// PDF name is a sequence of bytes, excluding the NUL character,
// and starting with a slash. Name objects as represented in the
@@ -591,8 +573,7 @@ class QPDFObjectHandle
QPDF_DLL
static QPDFObjectHandle newArray();
QPDF_DLL
- static QPDFObjectHandle
- newArray(std::vector<QPDFObjectHandle> const& items);
+ static QPDFObjectHandle newArray(std::vector<QPDFObjectHandle> const& items);
QPDF_DLL
static QPDFObjectHandle newArray(Rectangle const&);
QPDF_DLL
@@ -602,8 +583,7 @@ class QPDFObjectHandle
QPDF_DLL
static QPDFObjectHandle newDictionary();
QPDF_DLL
- static QPDFObjectHandle
- newDictionary(std::map<std::string, QPDFObjectHandle> const& items);
+ static QPDFObjectHandle newDictionary(std::map<std::string, QPDFObjectHandle> const& items);
// Create an array from a rectangle. Equivalent to the rectangle
// form of newArray.
@@ -686,8 +666,7 @@ class QPDFObjectHandle
// else. To add objects from another qpdf, use copyForeignObject
// instead.
QPDF_DLL
- void setObjectDescription(
- QPDF* owning_qpdf, std::string const& object_description);
+ void setObjectDescription(QPDF* owning_qpdf, std::string const& object_description);
QPDF_DLL
bool hasObjectDescription();
@@ -964,8 +943,7 @@ class QPDFObjectHandle
QPDF_DLL
void mergeResources(
QPDFObjectHandle other,
- std::map<std::string, std::map<std::string, std::string>>* conflicts =
- nullptr);
+ std::map<std::string, std::map<std::string, std::string>>* conflicts = nullptr);
// Get all resource names from a resource dictionary. If this
// object is a dictionary, this method returns a set of all the
@@ -1118,13 +1096,11 @@ class QPDFObjectHandle
void replaceKey(std::string const& key, QPDFObjectHandle const& value);
// Replace value of key and return the value.
QPDF_DLL
- QPDFObjectHandle
- replaceKeyAndGetNew(std::string const& key, QPDFObjectHandle const& value);
+ QPDFObjectHandle replaceKeyAndGetNew(std::string const& key, QPDFObjectHandle const& value);
// Replace value of key and return the old value, or null if the
// key was previously not present.
QPDF_DLL
- QPDFObjectHandle
- replaceKeyAndGetOld(std::string const& key, QPDFObjectHandle const& value);
+ QPDFObjectHandle replaceKeyAndGetOld(std::string const& key, QPDFObjectHandle const& value);
// Remove key, doing nothing if key does not exist.
QPDF_DLL
void removeKey(std::string const& key);
@@ -1167,8 +1143,7 @@ class QPDFObjectHandle
// Returns filtered (uncompressed) stream data. Throws an
// exception if the stream is filtered and we can't decode it.
QPDF_DLL
- std::shared_ptr<Buffer>
- getStreamData(qpdf_stream_decode_level_e level = qpdf_dl_generalized);
+ std::shared_ptr<Buffer> getStreamData(qpdf_stream_decode_level_e level = qpdf_dl_generalized);
// Returns unfiltered (raw) stream data.
QPDF_DLL
@@ -1347,8 +1322,7 @@ class QPDFObjectHandle
// returning true if it succeeded without errors.
QPDF_DLL
void replaceStreamData(
- std::function<bool(Pipeline*, bool suppress_warnings, bool will_retry)>
- provider,
+ std::function<bool(Pipeline*, bool suppress_warnings, bool will_retry)> provider,
QPDFObjectHandle const& filter,
QPDFObjectHandle const& decode_parms);
@@ -1615,15 +1589,14 @@ class QPDFObjectHandle
void makeDirect(QPDFObjGen::set& visited, bool stop_at_streams);
void disconnect();
void setParsedOffset(qpdf_offset_t offset);
- void parseContentStream_internal(
- std::string const& description, ParserCallbacks* callbacks);
+ void parseContentStream_internal(std::string const& description, ParserCallbacks* callbacks);
static void parseContentStream_data(
std::shared_ptr<Buffer>,
std::string const& description,
ParserCallbacks* callbacks,
QPDF* context);
- std::vector<QPDFObjectHandle> arrayOrStreamToStreamArray(
- std::string const& description, std::string& all_description);
+ std::vector<QPDFObjectHandle>
+ arrayOrStreamToStreamArray(std::string const& description, std::string& all_description);
static void warn(QPDF*, QPDFExc const&);
void checkOwnership(QPDFObjectHandle const&) const;
diff --git a/include/qpdf/QPDFPageDocumentHelper.hh b/include/qpdf/QPDFPageDocumentHelper.hh
index b41110fd..2cabbbb0 100644
--- a/include/qpdf/QPDFPageDocumentHelper.hh
+++ b/include/qpdf/QPDFPageDocumentHelper.hh
@@ -104,10 +104,7 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper
// Add new page before or after refpage. See comments for addPage
// for details about what newpage should be.
QPDF_DLL
- void addPageAt(
- QPDFPageObjectHelper newpage,
- bool before,
- QPDFPageObjectHelper refpage);
+ void addPageAt(QPDFPageObjectHelper newpage, bool before, QPDFPageObjectHelper refpage);
// Remove page from the pdf.
QPDF_DLL
@@ -125,8 +122,7 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper
// comments there in QPDFAnnotationObjectHelper.hh for meanings of
// those flags.
QPDF_DLL
- void flattenAnnotations(
- int required_flags = 0, int forbidden_flags = an_invisible | an_hidden);
+ void flattenAnnotations(int required_flags = 0, int forbidden_flags = an_invisible | an_hidden);
private:
void flattenAnnotationsForPage(
diff --git a/include/qpdf/QPDFPageObjectHelper.hh b/include/qpdf/QPDFPageObjectHelper.hh
index ffc515e0..05a57b5c 100644
--- a/include/qpdf/QPDFPageObjectHelper.hh
+++ b/include/qpdf/QPDFPageObjectHelper.hh
@@ -170,26 +170,22 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
// Return the effective CropBox. If not defined, fall back to
// MediaBox
QPDF_DLL
- QPDFObjectHandle
- getCropBox(bool copy_if_shared = false, bool copy_if_fallback = false);
+ QPDFObjectHandle getCropBox(bool copy_if_shared = false, bool copy_if_fallback = false);
// Return the effective BleedBox. If not defined, fall back to
// CropBox.
QPDF_DLL
- QPDFObjectHandle
- getBleedBox(bool copy_if_shared = false, bool copy_if_fallback = false);
+ QPDFObjectHandle getBleedBox(bool copy_if_shared = false, bool copy_if_fallback = false);
// Return the effective TrimBox. If not defined, fall back to
// CropBox.
QPDF_DLL
- QPDFObjectHandle
- getTrimBox(bool copy_if_shared = false, bool copy_if_fallback = false);
+ QPDFObjectHandle getTrimBox(bool copy_if_shared = false, bool copy_if_fallback = false);
// Return the effective ArtBox. If not defined, fall back to
// CropBox.
QPDF_DLL
- QPDFObjectHandle
- getArtBox(bool copy_if_shared = false, bool copy_if_fallback = false);
+ QPDFObjectHandle getArtBox(bool copy_if_shared = false, bool copy_if_fallback = false);
// Iterate through XObjects, possibly recursing into form
// XObjects. This works with pages or form XObjects. Call action
@@ -203,26 +199,20 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
void forEachXObject(
bool recursive,
std::function<void(
- QPDFObjectHandle& obj,
- QPDFObjectHandle& xobj_dict,
- std::string const& key)> action,
+ QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)> action,
std::function<bool(QPDFObjectHandle)> selector = nullptr);
// Only call action for images
QPDF_DLL
void forEachImage(
bool recursive,
std::function<void(
- QPDFObjectHandle& obj,
- QPDFObjectHandle& xobj_dict,
- std::string const& key)> action);
+ QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)> action);
// Only call action for form XObjects
QPDF_DLL
void forEachFormXObject(
bool recursive,
std::function<void(
- QPDFObjectHandle& obj,
- QPDFObjectHandle& xobj_dict,
- std::string const& key)> action);
+ QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)> action);
// Returns an empty map if there are no images or no resources.
// Prior to qpdf 8.4.0, this function did not support inherited
@@ -258,8 +248,7 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
// only_subtype is non-empty, only include annotations of the
// given subtype.
QPDF_DLL
- std::vector<QPDFAnnotationObjectHelper>
- getAnnotations(std::string const& only_subtype = "");
+ std::vector<QPDFAnnotationObjectHelper> getAnnotations(std::string const& only_subtype = "");
// Returns a vector of stream objects representing the content
// streams for the given page. This routine allows the caller to
@@ -319,13 +308,11 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
// contents, as happens with addContentTokenFilter. See
// examples/pdf-count-strings.cc for an example.
QPDF_DLL
- void filterContents(
- QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr);
+ void filterContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr);
// Old name -- calls filterContents()
QPDF_DLL
- void filterPageContents(
- QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr);
+ void filterPageContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr);
// Pipe a page's contents through the given pipeline. This method
// works whether the contents are a single stream or an array of
@@ -341,8 +328,7 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
// The token filter is applied to the page's contents as a single
// stream. Also works on form XObjects.
QPDF_DLL
- void addContentTokenFilter(
- std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter);
+ void addContentTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter);
// A page's resources dictionary maps names to objects elsewhere
// in the file. This method walks through a page's contents and
@@ -500,8 +486,8 @@ class QPDFPageObjectHelper: public QPDFObjectHelper
bool copy_if_shared,
std::function<QPDFObjectHandle()> get_fallback,
bool copy_if_fallback);
- static bool removeUnreferencedResourcesHelper(
- QPDFPageObjectHelper ph, std::set<std::string>& unresolved);
+ static bool
+ removeUnreferencedResourcesHelper(QPDFPageObjectHelper ph, std::set<std::string>& unresolved);
class Members
{
diff --git a/include/qpdf/QPDFSystemError.hh b/include/qpdf/QPDFSystemError.hh
index 6d23fa94..fe75b272 100644
--- a/include/qpdf/QPDFSystemError.hh
+++ b/include/qpdf/QPDFSystemError.hh
@@ -48,8 +48,7 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error
private:
QPDF_DLL_PRIVATE
- static std::string
- createWhat(std::string const& description, int system_errno);
+ static std::string createWhat(std::string const& description, int system_errno);
// This class does not use the Members pattern to avoid needless
// memory allocations during exception handling.
diff --git a/include/qpdf/QPDFTokenizer.hh b/include/qpdf/QPDFTokenizer.hh
index 5dd8f9d8..b07b7c0b 100644
--- a/include/qpdf/QPDFTokenizer.hh
+++ b/include/qpdf/QPDFTokenizer.hh
@@ -104,8 +104,7 @@ class QPDFTokenizer
{
// Ignore fields other than type and value
return (
- (this->type != tt_bad) && (this->type == rhs.type) &&
- (this->value == rhs.value));
+ (this->type != tt_bad) && (this->type == rhs.type) && (this->value == rhs.value));
}
bool
isInteger() const
@@ -216,8 +215,7 @@ class QPDFTokenizer
// beginning of the token. Returns false if the token is bad
// or if scanning produced an error message for any reason.
- bool nextToken(
- InputSource& input, std::string const& context, size_t max_len = 0);
+ bool nextToken(InputSource& input, std::string const& context, size_t max_len = 0);
// The following methods are only valid after nextToken has been called
// and until another QPDFTokenizer method is called. They allow the results
@@ -317,8 +315,7 @@ QPDFTokenizer::getType() const noexcept
inline std::string const&
QPDFTokenizer::getValue() const noexcept
{
- return (this->type == tt_name || this->type == tt_string) ? this->val
- : this->raw_val;
+ return (this->type == tt_name || this->type == tt_string) ? this->val : this->raw_val;
}
inline std::string const&
QPDFTokenizer::getRawValue() const noexcept
diff --git a/include/qpdf/QPDFWriter.hh b/include/qpdf/QPDFWriter.hh
index 0d445177..d14d907f 100644
--- a/include/qpdf/QPDFWriter.hh
+++ b/include/qpdf/QPDFWriter.hh
@@ -561,16 +561,11 @@ class QPDFWriter
void writePad(size_t nspaces);
void assignCompressedObjectNumbers(QPDFObjGen const& og);
void enqueueObject(QPDFObjectHandle object);
- void writeObjectStreamOffsets(
- std::vector<qpdf_offset_t>& offsets, int first_obj);
+ void writeObjectStreamOffsets(std::vector<qpdf_offset_t>& offsets, int first_obj);
void writeObjectStream(QPDFObjectHandle object);
void writeObject(QPDFObjectHandle object, int object_stream_index = -1);
void writeTrailer(
- trailer_e which,
- int size,
- bool xref_stream,
- qpdf_offset_t prev,
- int linearization_pass);
+ trailer_e which, int size, bool xref_stream, qpdf_offset_t prev, int linearization_pass);
bool willFilterStream(
QPDFObjectHandle stream,
bool& compress_stream,
@@ -601,8 +596,7 @@ class QPDFWriter
bool allow_modify_other,
qpdf_r3_print_e print,
qpdf_r3_modify_e modify);
- void
- disableIncompatibleEncryption(int major, int minor, int extension_level);
+ void disableIncompatibleEncryption(int major, int minor, int extension_level);
void parseVersion(std::string const& version, int& major, int& minor) const;
int compareVersions(int major1, int minor1, int major2, int minor2) const;
void setEncryptionParameters(
@@ -640,8 +634,7 @@ class QPDFWriter
void doWriteSetup();
void writeHeader();
void writeHintStream(int hint_id);
- qpdf_offset_t
- writeXRefTable(trailer_e which, int first, int last, int size);
+ qpdf_offset_t writeXRefTable(trailer_e which, int first, int last, int size);
qpdf_offset_t writeXRefTable(
trailer_e which,
int first,
@@ -693,8 +686,7 @@ class QPDFWriter
void pushMD5Pipeline(PipelinePopper&);
void computeDeterministicIDData();
- void discardGeneration(
- std::map<QPDFObjGen, int> const& in, std::map<int, int>& out);
+ void discardGeneration(std::map<QPDFObjGen, int> const& in, std::map<int, int>& out);
class Members
{
diff --git a/include/qpdf/QUtil.hh b/include/qpdf/QUtil.hh
index 85224059..85e7f907 100644
--- a/include/qpdf/QUtil.hh
+++ b/include/qpdf/QUtil.hh
@@ -49,11 +49,9 @@ namespace QUtil
QPDF_DLL
std::string int_to_string_base(long long, int base, int length = 0);
QPDF_DLL
- std::string
- uint_to_string_base(unsigned long long, int base, int length = 0);
+ std::string uint_to_string_base(unsigned long long, int base, int length = 0);
QPDF_DLL
- std::string double_to_string(
- double, int decimal_places = 0, bool trim_trailing_zeroes = true);
+ std::string double_to_string(double, int decimal_places = 0, bool trim_trailing_zeroes = true);
// These string to number methods throw std::runtime_error on
// underflow/overflow.
@@ -257,14 +255,7 @@ namespace QUtil
QPDFTime() = default;
QPDFTime(QPDFTime const&) = default;
QPDFTime& operator=(QPDFTime const&) = default;
- QPDFTime(
- int year,
- int month,
- int day,
- int hour,
- int minute,
- int second,
- int tz_delta) :
+ QPDFTime(int year, int month, int day, int hour, int minute, int second, int tz_delta) :
year(year),
month(month),
day(day),
@@ -331,8 +322,7 @@ namespace QUtil
// to pass a value of pos that is greater than or equal to the
// length of the string.
QPDF_DLL
- unsigned long get_next_utf8_codepoint(
- std::string const& utf8_val, size_t& pos, bool& error);
+ unsigned long get_next_utf8_codepoint(std::string const& utf8_val, size_t& pos, bool& error);
// Test whether this is a UTF-16 string. This is indicated by
// first two bytes being 0xFE 0xFF (big-endian) or 0xFF 0xFE
@@ -360,30 +350,23 @@ namespace QUtil
QPDF_DLL
std::string utf8_to_ascii(std::string const& utf8, char unknown_char = '?');
QPDF_DLL
- std::string
- utf8_to_win_ansi(std::string const& utf8, char unknown_char = '?');
+ std::string utf8_to_win_ansi(std::string const& utf8, char unknown_char = '?');
QPDF_DLL
- std::string
- utf8_to_mac_roman(std::string const& utf8, char unknown_char = '?');
+ std::string utf8_to_mac_roman(std::string const& utf8, char unknown_char = '?');
QPDF_DLL
- std::string
- utf8_to_pdf_doc(std::string const& utf8, char unknown_char = '?');
+ std::string utf8_to_pdf_doc(std::string const& utf8, char unknown_char = '?');
// These versions return true if the conversion was successful and
// false if any unrepresentable characters were found and had to
// be substituted with the unknown character.
QPDF_DLL
- bool utf8_to_ascii(
- std::string const& utf8, std::string& ascii, char unknown_char = '?');
+ bool utf8_to_ascii(std::string const& utf8, std::string& ascii, char unknown_char = '?');
QPDF_DLL
- bool utf8_to_win_ansi(
- std::string const& utf8, std::string& win, char unknown_char = '?');
+ bool utf8_to_win_ansi(std::string const& utf8, std::string& win, char unknown_char = '?');
QPDF_DLL
- bool utf8_to_mac_roman(
- std::string const& utf8, std::string& mac, char unknown_char = '?');
+ bool utf8_to_mac_roman(std::string const& utf8, std::string& mac, char unknown_char = '?');
QPDF_DLL
- bool utf8_to_pdf_doc(
- std::string const& utf8, std::string& pdfdoc, char unknown_char = '?');
+ bool utf8_to_pdf_doc(std::string const& utf8, std::string& pdfdoc, char unknown_char = '?');
// Convert a UTF-16 encoded string to UTF-8. Unrepresentable code
// points are converted to U+FFFD.
@@ -412,10 +395,7 @@ namespace QUtil
// about everything else) accepts UTF-16LE (as of 10.6.2).
QPDF_DLL
void analyze_encoding(
- std::string const& str,
- bool& has_8bit_chars,
- bool& is_valid_utf8,
- bool& is_utf16);
+ std::string const& str, bool& has_8bit_chars, bool& is_valid_utf8, bool& is_utf16);
// Try to compensate for previously incorrectly encoded strings.
// We want to compensate for the following errors:
@@ -472,14 +452,11 @@ namespace QUtil
// Filename is UTF-8 encoded, even on Windows, as described in the
// comments for safe_fopen.
QPDF_DLL
- std::list<std::string>
- read_lines_from_file(char const* filename, bool preserve_eol = false);
+ std::list<std::string> read_lines_from_file(char const* filename, bool preserve_eol = false);
QPDF_DLL
- std::list<std::string>
- read_lines_from_file(std::istream&, bool preserve_eol = false);
+ std::list<std::string> read_lines_from_file(std::istream&, bool preserve_eol = false);
QPDF_DLL
- std::list<std::string>
- read_lines_from_file(FILE*, bool preserve_eol = false);
+ std::list<std::string> read_lines_from_file(FILE*, bool preserve_eol = false);
QPDF_DLL
void read_lines_from_file(
std::function<bool(char&)> next_char,
@@ -487,8 +464,7 @@ namespace QUtil
bool preserve_eol = false);
QPDF_DLL
- void read_file_into_memory(
- char const* filename, std::shared_ptr<char>& file_buf, size_t& size);
+ void read_file_into_memory(char const* filename, std::shared_ptr<char>& file_buf, size_t& size);
QPDF_DLL
std::string read_file_into_string(char const* filename);
@@ -532,8 +508,7 @@ namespace QUtil
// invoked, convert all UTF-16 encoded strings to UTF-8, and call
// another main.
QPDF_DLL
- int call_main_from_wmain(
- int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain);
+ int call_main_from_wmain(int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain);
QPDF_DLL
int call_main_from_wmain(
int argc,
@@ -561,8 +536,7 @@ QUtil::is_hex_digit(char ch)
inline bool
QUtil::is_space(char ch)
{
- return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f' ||
- ch == '\v';
+ return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f' || ch == '\v';
}
inline bool
@@ -603,8 +577,7 @@ inline std::string
QUtil::hex_encode_char(char c)
{
static auto constexpr hexchars = "0123456789abcdef";
- return {
- '#', hexchars[static_cast<unsigned char>(c) >> 4], hexchars[c & 0x0f]};
+ return {'#', hexchars[static_cast<unsigned char>(c) >> 4], hexchars[c & 0x0f]};
}
inline constexpr char
@@ -612,8 +585,7 @@ QUtil::hex_decode_char(char digit) noexcept
{
return digit <= '9' && digit >= '0'
? char(digit - '0')
- : (digit >= 'a' ? char(digit - 'a' + 10)
- : (digit >= 'A' ? char(digit - 'A' + 10) : '\20'));
+ : (digit >= 'a' ? char(digit - 'a' + 10) : (digit >= 'A' ? char(digit - 'A' + 10) : '\20'));
}
#endif // QUTIL_HH
diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h
index 3b56c427..4e258e9a 100644
--- a/include/qpdf/qpdf-c.h
+++ b/include/qpdf/qpdf-c.h
@@ -326,8 +326,7 @@ extern "C" {
*/
QPDF_DLL
QPDF_ERROR_CODE
- qpdf_create_from_json_data(
- qpdf_data qpdf, char const* buffer, unsigned long long size);
+ qpdf_create_from_json_data(qpdf_data qpdf, char const* buffer, unsigned long long size);
/* JSON UPDATE FUNCTIONS */
@@ -341,8 +340,7 @@ extern "C" {
qpdf_update_from_json_file(qpdf_data qpdf, char const* filename);
QPDF_DLL
QPDF_ERROR_CODE
- qpdf_update_from_json_data(
- qpdf_data qpdf, char const* buffer, unsigned long long size);
+ qpdf_update_from_json_data(qpdf_data qpdf, char const* buffer, unsigned long long size);
/* READ FUNCTIONS */
@@ -492,23 +490,19 @@ extern "C" {
unsigned char const* qpdf_get_buffer(qpdf_data qpdf);
QPDF_DLL
- void
- qpdf_set_object_stream_mode(qpdf_data qpdf, enum qpdf_object_stream_e mode);
+ void qpdf_set_object_stream_mode(qpdf_data qpdf, enum qpdf_object_stream_e mode);
QPDF_DLL
- void
- qpdf_set_stream_data_mode(qpdf_data qpdf, enum qpdf_stream_data_e mode);
+ void qpdf_set_stream_data_mode(qpdf_data qpdf, enum qpdf_stream_data_e mode);
QPDF_DLL
void qpdf_set_compress_streams(qpdf_data qpdf, QPDF_BOOL value);
QPDF_DLL
- void qpdf_set_decode_level(
- qpdf_data qpdf, enum qpdf_stream_decode_level_e level);
+ void qpdf_set_decode_level(qpdf_data qpdf, enum qpdf_stream_decode_level_e level);
QPDF_DLL
- void
- qpdf_set_preserve_unreferenced_objects(qpdf_data qpdf, QPDF_BOOL value);
+ void qpdf_set_preserve_unreferenced_objects(qpdf_data qpdf, QPDF_BOOL value);
QPDF_DLL
void qpdf_set_newline_before_endstream(qpdf_data qpdf, QPDF_BOOL value);
@@ -625,8 +619,8 @@ extern "C" {
void qpdf_force_pdf_version(qpdf_data qpdf, char const* version);
QPDF_DLL
- void qpdf_force_pdf_version_and_extension(
- qpdf_data qpdf, char const* version, int extension_level);
+ void
+ qpdf_force_pdf_version_and_extension(qpdf_data qpdf, char const* version, int extension_level);
/* During write, your report_progress function will be called with
* a value between 0 and 100 representing the approximate write
@@ -640,9 +634,7 @@ extern "C" {
*/
QPDF_DLL
void qpdf_register_progress_reporter(
- qpdf_data qpdf,
- void (*report_progress)(int percent, void* data),
- void* data);
+ qpdf_data qpdf, void (*report_progress)(int percent, void* data), void* data);
/* Do actual write operation. */
QPDF_DLL
@@ -733,8 +725,7 @@ extern "C" {
QPDF_DLL
qpdf_oh qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh);
QPDF_DLL
- void
- qpdf_replace_object(qpdf_data qpdf, int objid, int generation, qpdf_oh oh);
+ void qpdf_replace_object(qpdf_data qpdf, int objid, int generation, qpdf_oh oh);
/* Wrappers around QPDFObjectHandle methods. Be sure to read
* corresponding comments in QPDFObjectHandle.hh to understand
@@ -811,8 +802,7 @@ extern "C" {
QPDF_DLL
unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh);
QPDF_DLL
- QPDF_BOOL qpdf_oh_get_value_as_ulonglong(
- qpdf_data qpdf, qpdf_oh oh, unsigned long long* value);
+ QPDF_BOOL qpdf_oh_get_value_as_ulonglong(qpdf_data qpdf, qpdf_oh oh, unsigned long long* value);
QPDF_DLL
unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh);
QPDF_DLL
@@ -822,8 +812,8 @@ extern "C" {
QPDF_DLL
char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh);
QPDF_DLL
- QPDF_BOOL qpdf_oh_get_value_as_real(
- qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
+ QPDF_BOOL
+ qpdf_oh_get_value_as_real(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
QPDF_DLL
QPDF_BOOL qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh);
@@ -836,8 +826,8 @@ extern "C" {
QPDF_DLL
char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh);
QPDF_DLL
- QPDF_BOOL qpdf_oh_get_value_as_name(
- qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
+ QPDF_BOOL
+ qpdf_oh_get_value_as_name(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
/* Return the length of the last string returned. This enables you
* to retrieve the entire string for cases in which a char*
@@ -858,19 +848,17 @@ extern "C" {
QPDF_DLL
char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh);
QPDF_DLL
- QPDF_BOOL qpdf_oh_get_value_as_string(
- qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
+ QPDF_BOOL
+ qpdf_oh_get_value_as_string(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
QPDF_DLL
char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh);
QPDF_DLL
- QPDF_BOOL qpdf_oh_get_value_as_utf8(
- qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
+ QPDF_BOOL
+ qpdf_oh_get_value_as_utf8(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length);
QPDF_DLL
- char const*
- qpdf_oh_get_binary_string_value(qpdf_data qpdf, qpdf_oh oh, size_t* length);
+ char const* qpdf_oh_get_binary_string_value(qpdf_data qpdf, qpdf_oh oh, size_t* length);
QPDF_DLL
- char const*
- qpdf_oh_get_binary_utf8_value(qpdf_data qpdf, qpdf_oh oh, size_t* length);
+ char const* qpdf_oh_get_binary_utf8_value(qpdf_data qpdf, qpdf_oh oh, size_t* length);
QPDF_DLL
int qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh);
@@ -906,8 +894,7 @@ extern "C" {
QPDF_DLL
qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key);
QPDF_DLL
- qpdf_oh
- qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key);
+ qpdf_oh qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key);
QPDF_DLL
QPDF_BOOL
@@ -924,8 +911,7 @@ extern "C" {
QPDF_DLL
qpdf_oh qpdf_oh_new_real_from_string(qpdf_data qpdf, char const* value);
QPDF_DLL
- qpdf_oh qpdf_oh_new_real_from_double(
- qpdf_data qpdf, double value, int decimal_places);
+ qpdf_oh qpdf_oh_new_real_from_double(qpdf_data qpdf, double value, int decimal_places);
QPDF_DLL
qpdf_oh qpdf_oh_new_name(qpdf_data qpdf, char const* name);
QPDF_DLL
@@ -936,11 +922,9 @@ extern "C" {
* contain atrbitary binary data including embedded null characters.
*/
QPDF_DLL
- qpdf_oh
- qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length);
+ qpdf_oh qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length);
QPDF_DLL
- qpdf_oh qpdf_oh_new_binary_unicode_string(
- qpdf_data qpdf, char const* str, size_t length);
+ qpdf_oh qpdf_oh_new_binary_unicode_string(qpdf_data qpdf, char const* str, size_t length);
QPDF_DLL
qpdf_oh qpdf_oh_new_array(qpdf_data qpdf);
QPDF_DLL
@@ -959,8 +943,7 @@ extern "C" {
void qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh);
QPDF_DLL
- void
- qpdf_oh_set_array_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item);
+ void qpdf_oh_set_array_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item);
QPDF_DLL
void qpdf_oh_insert_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item);
QPDF_DLL
@@ -969,13 +952,11 @@ extern "C" {
void qpdf_oh_erase_item(qpdf_data qpdf, qpdf_oh oh, int at);
QPDF_DLL
- void qpdf_oh_replace_key(
- qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item);
+ void qpdf_oh_replace_key(qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item);
QPDF_DLL
void qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key);
QPDF_DLL
- void qpdf_oh_replace_or_remove_key(
- qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item);
+ void qpdf_oh_replace_or_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item);
QPDF_DLL
qpdf_oh qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh);
@@ -1005,8 +986,7 @@ extern "C" {
* while `foreign_oh` belongs to `other_qpdf`.
*/
QPDF_DLL
- qpdf_oh qpdf_oh_copy_foreign_object(
- qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh);
+ qpdf_oh qpdf_oh_copy_foreign_object(qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh);
/* STREAM FUNCTIONS */
@@ -1105,19 +1085,12 @@ extern "C" {
/* addPage() */
QPDF_DLL
- QPDF_ERROR_CODE qpdf_add_page(
- qpdf_data qpdf,
- qpdf_data newpage_qpdf,
- qpdf_oh newpage,
- QPDF_BOOL first);
+ QPDF_ERROR_CODE
+ qpdf_add_page(qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL first);
/* addPageAt() */
QPDF_DLL
QPDF_ERROR_CODE qpdf_add_page_at(
- qpdf_data qpdf,
- qpdf_data newpage_qpdf,
- qpdf_oh newpage,
- QPDF_BOOL before,
- qpdf_oh refpage);
+ qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL before, qpdf_oh refpage);
/* removePage() */
QPDF_DLL
QPDF_ERROR_CODE qpdf_remove_page(qpdf_data qpdf, qpdf_oh page);
diff --git a/include/qpdf/qpdfjob-c.h b/include/qpdf/qpdfjob-c.h
index a251bd93..c41dbeee 100644
--- a/include/qpdf/qpdfjob-c.h
+++ b/include/qpdf/qpdfjob-c.h
@@ -111,8 +111,7 @@ extern "C" {
* is invalid to call any other functions this job handle.
*/
QPDF_DLL
- int
- qpdfjob_initialize_from_argv(qpdfjob_handle j, char const* const argv[]);
+ int qpdfjob_initialize_from_argv(qpdfjob_handle j, char const* const argv[]);
#ifndef QPDF_NO_WCHAR_T
/* This function is the same as qpdfjob_initialize_from_argv
@@ -120,8 +119,7 @@ extern "C" {
* suitable for calling from a Windows wmain function.
*/
QPDF_DLL
- int qpdfjob_initialize_from_wide_argv(
- qpdfjob_handle j, wchar_t const* const argv[]);
+ int qpdfjob_initialize_from_wide_argv(qpdfjob_handle j, wchar_t const* const argv[]);
#endif /* QPDF_NO_WCHAR_T */
/* This function wraps QPDFJob::initializeFromJson. The return
@@ -167,9 +165,7 @@ extern "C" {
*/
QPDF_DLL
void qpdfjob_register_progress_reporter(
- qpdfjob_handle j,
- void (*report_progress)(int percent, void* data),
- void* data);
+ qpdfjob_handle j, void (*report_progress)(int percent, void* data), void* data);
#ifdef __cplusplus
}
diff --git a/include/qpdf/qpdflogger-c.h b/include/qpdf/qpdflogger-c.h
index 96276c07..966c47f1 100644
--- a/include/qpdf/qpdflogger-c.h
+++ b/include/qpdf/qpdflogger-c.h
@@ -76,22 +76,13 @@ extern "C" {
QPDF_DLL
void qpdflogger_set_info(
- qpdflogger_handle l,
- enum qpdf_log_dest_e dest,
- qpdf_log_fn_t fn,
- void* udata);
+ qpdflogger_handle l, enum qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata);
QPDF_DLL
void qpdflogger_set_warn(
- qpdflogger_handle l,
- enum qpdf_log_dest_e dest,
- qpdf_log_fn_t fn,
- void* udata);
+ qpdflogger_handle l, enum qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata);
QPDF_DLL
void qpdflogger_set_error(
- qpdflogger_handle l,
- enum qpdf_log_dest_e dest,
- qpdf_log_fn_t fn,
- void* udata);
+ qpdflogger_handle l, enum qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata);
/* A non-zero value for only_if_not_set means that the save
* pipeline will only be changed if it is not already set.
@@ -104,8 +95,7 @@ extern "C" {
void* udata,
int only_if_not_set);
QPDF_DLL
- void qpdflogger_save_to_standard_output(
- qpdflogger_handle l, int only_if_not_set);
+ void qpdflogger_save_to_standard_output(qpdflogger_handle l, int only_if_not_set);
/* For testing */
QPDF_DLL
diff --git a/libqpdf/AES_PDF_native.cc b/libqpdf/AES_PDF_native.cc
index 1316a643..42f1cda7 100644
--- a/libqpdf/AES_PDF_native.cc
+++ b/libqpdf/AES_PDF_native.cc
@@ -27,11 +27,9 @@ AES_PDF_native::AES_PDF_native(
std::memcpy(this->key.get(), key, key_bytes);
std::memset(this->rk.get(), 0, rk_bytes);
if (encrypt) {
- this->nrounds =
- rijndaelSetupEncrypt(this->rk.get(), this->key.get(), keybits);
+ this->nrounds = rijndaelSetupEncrypt(this->rk.get(), this->key.get(), keybits);
} else {
- this->nrounds =
- rijndaelSetupDecrypt(this->rk.get(), this->key.get(), keybits);
+ this->nrounds = rijndaelSetupDecrypt(this->rk.get(), this->key.get(), keybits);
}
}
@@ -46,8 +44,7 @@ AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data)
}
rijndaelEncrypt(this->rk.get(), this->nrounds, in_data, out_data);
if (this->cbc_mode) {
- memcpy(
- this->cbc_block, out_data, QPDFCryptoImpl::rijndael_buf_size);
+ memcpy(this->cbc_block, out_data, QPDFCryptoImpl::rijndael_buf_size);
}
} else {
rijndaelDecrypt(this->rk.get(), this->nrounds, in_data, out_data);
diff --git a/libqpdf/BitStream.cc b/libqpdf/BitStream.cc
index 35b9e63e..8efb85ba 100644
--- a/libqpdf/BitStream.cc
+++ b/libqpdf/BitStream.cc
@@ -33,8 +33,7 @@ BitStream::getBits(size_t nbits)
long long
BitStream::getBitsSigned(size_t nbits)
{
- unsigned long long bits =
- read_bits(this->p, this->bit_offset, this->bits_available, nbits);
+ unsigned long long bits = read_bits(this->p, this->bit_offset, this->bits_available, nbits);
long long result = 0;
if (static_cast<long long>(bits) > 1LL << (nbits - 1)) {
result = static_cast<long long>(bits - (1ULL << nbits));
@@ -49,8 +48,7 @@ BitStream::getBitsInt(size_t nbits)
{
return static_cast<int>(
// line-break
- QIntC::to_uint(
- read_bits(this->p, this->bit_offset, this->bits_available, nbits)));
+ QIntC::to_uint(read_bits(this->p, this->bit_offset, this->bits_available, nbits)));
}
void
@@ -59,8 +57,7 @@ BitStream::skipToNextByte()
if (bit_offset != 7) {
size_t bits_to_skip = bit_offset + 1;
if (bits_available < bits_to_skip) {
- throw std::logic_error(
- "INTERNAL ERROR: overflow skipping to next byte in bitstream");
+ throw std::logic_error("INTERNAL ERROR: overflow skipping to next byte in bitstream");
}
bit_offset = 7;
++p;
diff --git a/libqpdf/BufferInputSource.cc b/libqpdf/BufferInputSource.cc
index 4fff642a..4246016d 100644
--- a/libqpdf/BufferInputSource.cc
+++ b/libqpdf/BufferInputSource.cc
@@ -5,8 +5,7 @@
#include <cstring>
#include <sstream>
-BufferInputSource::BufferInputSource(
- std::string const& description, Buffer* buf, bool own_memory) :
+BufferInputSource::BufferInputSource(std::string const& description, Buffer* buf, bool own_memory) :
own_memory(own_memory),
description(description),
buf(buf),
@@ -15,8 +14,7 @@ BufferInputSource::BufferInputSource(
{
}
-BufferInputSource::BufferInputSource(
- std::string const& description, std::string const& contents) :
+BufferInputSource::BufferInputSource(std::string const& description, std::string const& contents) :
own_memory(true),
description(description),
buf(new Buffer(contents.length())),
@@ -100,14 +98,12 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence)
break;
default:
- throw std::logic_error(
- "INTERNAL ERROR: invalid argument to BufferInputSource::seek");
+ throw std::logic_error("INTERNAL ERROR: invalid argument to BufferInputSource::seek");
break;
}
if (this->cur_offset < 0) {
- throw std::runtime_error(
- this->description + ": seek before beginning of buffer");
+ throw std::runtime_error(this->description + ": seek before beginning of buffer");
}
}
diff --git a/libqpdf/ContentNormalizer.cc b/libqpdf/ContentNormalizer.cc
index 93f3aad1..b05b4220 100644
--- a/libqpdf/ContentNormalizer.cc
+++ b/libqpdf/ContentNormalizer.cc
@@ -44,13 +44,11 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
// Replacing string and name tokens in this way normalizes
// their representation as this will automatically handle
// quoting of unprintable characters, etc.
- writeToken(
- QPDFTokenizer::Token(QPDFTokenizer::tt_string, token.getValue()));
+ writeToken(QPDFTokenizer::Token(QPDFTokenizer::tt_string, token.getValue()));
break;
case QPDFTokenizer::tt_name:
- writeToken(
- QPDFTokenizer::Token(QPDFTokenizer::tt_name, token.getValue()));
+ writeToken(QPDFTokenizer::Token(QPDFTokenizer::tt_name, token.getValue()));
break;
default:
@@ -59,10 +57,8 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
}
value = token.getRawValue();
- if (((token_type == QPDFTokenizer::tt_string) ||
- (token_type == QPDFTokenizer::tt_name)) &&
- ((value.find('\r') != std::string::npos) ||
- (value.find('\n') != std::string::npos))) {
+ if (((token_type == QPDFTokenizer::tt_string) || (token_type == QPDFTokenizer::tt_name)) &&
+ ((value.find('\r') != std::string::npos) || (value.find('\n') != std::string::npos))) {
write("\n");
}
}
diff --git a/libqpdf/FileInputSource.cc b/libqpdf/FileInputSource.cc
index a5f0f4f0..0e0cfa50 100644
--- a/libqpdf/FileInputSource.cc
+++ b/libqpdf/FileInputSource.cc
@@ -18,8 +18,7 @@ FileInputSource::FileInputSource(char const* filename) :
{
}
-FileInputSource::FileInputSource(
- char const* description, FILE* filep, bool close_file) :
+FileInputSource::FileInputSource(char const* description, FILE* filep, bool close_file) :
close_file(close_file),
filename(description),
file(filep)
@@ -104,8 +103,8 @@ FileInputSource::seek(qpdf_offset_t offset, int whence)
{
if (QUtil::seek(this->file, offset, whence) == -1) {
QUtil::throw_system_error(
- std::string("seek to ") + this->filename + ", offset " +
- std::to_string(offset) + " (" + std::to_string(whence) + ")");
+ std::string("seek to ") + this->filename + ", offset " + std::to_string(offset) + " (" +
+ std::to_string(whence) + ")");
}
}
diff --git a/libqpdf/InputSource.cc b/libqpdf/InputSource.cc
index acb459d9..597781fe 100644
--- a/libqpdf/InputSource.cc
+++ b/libqpdf/InputSource.cc
@@ -43,8 +43,7 @@ InputSource::readLine(size_t max_line_length)
}
bool
-InputSource::findFirst(
- char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder)
+InputSource::findFirst(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder)
{
// Basic approach: search for the first character of start_chars
// starting from offset but not going past len (if len != 0). Once
@@ -64,9 +63,8 @@ InputSource::findFirst(
// so that buf[size] is valid memory.
size_t size = sizeof(buf) - 1;
if ((strlen(start_chars) < 1) || (strlen(start_chars) > size)) {
- throw std::logic_error(
- "InputSource::findSource called with"
- " too small or too large of a character sequence");
+ throw std::logic_error("InputSource::findSource called with"
+ " too small or too large of a character sequence");
}
char* p = nullptr;
@@ -86,13 +84,10 @@ InputSource::findFirst(
// If p points to buf[size], since strlen(start_chars) is
// always >= 1, this overflow test will be correct for that
// case regardless of start_chars.
- if ((p == nullptr) ||
- ((p + strlen(start_chars)) > (buf + bytes_read))) {
+ if ((p == nullptr) || ((p + strlen(start_chars)) > (buf + bytes_read))) {
if (p) {
QTC::TC(
- "libtests",
- "InputSource read next block",
- ((p == buf + bytes_read) ? 0 : 1));
+ "libtests", "InputSource read next block", ((p == buf + bytes_read) ? 0 : 1));
buf_offset += (p - buf);
}
this->seek(buf_offset, SEEK_SET);
@@ -102,10 +97,7 @@ InputSource::findFirst(
// protection against overrun when using string functions.
bytes_read = this->read(buf, size);
if (bytes_read < strlen(start_chars)) {
- QTC::TC(
- "libtests",
- "InputSource find EOF",
- bytes_read == 0 ? 0 : 1);
+ QTC::TC("libtests", "InputSource find EOF", bytes_read == 0 ? 0 : 1);
return false;
}
memset(buf + bytes_read, '\0', 1 + (size - bytes_read));
@@ -115,18 +107,14 @@ InputSource::findFirst(
// Search for the first character.
if ((p = static_cast<char*>(
// line-break
- memchr(
- p,
- start_chars[0],
- bytes_read - QIntC::to_size(p - buf)))) != nullptr) {
+ memchr(p, start_chars[0], bytes_read - QIntC::to_size(p - buf)))) != nullptr) {
if (p == buf) {
QTC::TC("libtests", "InputSource found match at buf[0]");
}
// Found first letter.
if (len != 0) {
// Make sure it's in range.
- size_t p_relative_offset =
- QIntC::to_size((p - buf) + (buf_offset - offset));
+ size_t p_relative_offset = QIntC::to_size((p - buf) + (buf_offset - offset));
if (p_relative_offset >= len) {
// out of range
QTC::TC("libtests", "InputSource out of range");
@@ -151,14 +139,10 @@ InputSource::findFirst(
if (finder.check()) {
return true;
} else {
- QTC::TC(
- "libtests",
- "InputSource start_chars matched but not check");
+ QTC::TC("libtests", "InputSource start_chars matched but not check");
}
} else {
- QTC::TC(
- "libtests",
- "InputSource first char matched but not string");
+ QTC::TC("libtests", "InputSource first char matched but not string");
}
// This occurrence of the first character wasn't a match.
// Skip over it and keep searching.
@@ -172,8 +156,7 @@ InputSource::findFirst(
}
bool
-InputSource::findLast(
- char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder)
+InputSource::findLast(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder)
{
bool found = false;
qpdf_offset_t after_found_offset = 0;
diff --git a/libqpdf/InsecureRandomDataProvider.cc b/libqpdf/InsecureRandomDataProvider.cc
index ed62d6c7..5f247167 100644
--- a/libqpdf/InsecureRandomDataProvider.cc
+++ b/libqpdf/InsecureRandomDataProvider.cc
@@ -24,8 +24,7 @@ InsecureRandomDataProvider::random()
// Seed the random number generator with something simple, but
// just to be interesting, don't use the unmodified current
// time. It would be better if this were a more secure seed.
- auto seed =
- static_cast<unsigned int>(QUtil::get_current_time() ^ 0xcccc);
+ auto seed = static_cast<unsigned int>(QUtil::get_current_time() ^ 0xcccc);
#ifdef HAVE_RANDOM
::srandom(seed);
#else
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc
index a2b71a21..e144c7a4 100644
--- a/libqpdf/JSON.cc
+++ b/libqpdf/JSON.cc
@@ -73,8 +73,7 @@ JSON::writeArrayClose(Pipeline* p, bool first, size_t depth)
}
void
-JSON::writeDictionaryKey(
- Pipeline* p, bool& first, std::string const& key, size_t depth)
+JSON::writeDictionaryKey(Pipeline* p, bool& first, std::string const& key, size_t depth)
{
writeNext(p, first, depth);
*p << std::string("\"") + key + "\": ";
@@ -82,19 +81,14 @@ JSON::writeDictionaryKey(
void
JSON::writeDictionaryItem(
- Pipeline* p,
- bool& first,
- std::string const& key,
- JSON const& value,
- size_t depth)
+ Pipeline* p, bool& first, std::string const& key, JSON const& value, size_t depth)
{
writeDictionaryKey(p, first, key, depth);
value.write(p, depth);
}
void
-JSON::writeArrayItem(
- Pipeline* p, bool& first, JSON const& element, size_t depth)
+JSON::writeArrayItem(Pipeline* p, bool& first, JSON const& element, size_t depth)
{
writeNext(p, first, depth);
element.write(p, depth);
@@ -283,11 +277,9 @@ JSON
JSON::addDictionaryMember(std::string const& key, JSON const& val)
{
if (auto* obj = dynamic_cast<JSON_dictionary*>(m->value.get())) {
- return obj->members[encode_string(key)] =
- val.m->value ? val : makeNull();
+ return obj->members[encode_string(key)] = val.m->value ? val : makeNull();
} else {
- throw std::runtime_error(
- "JSON::addDictionaryMember called on non-dictionary");
+ throw std::runtime_error("JSON::addDictionaryMember called on non-dictionary");
}
}
@@ -296,8 +288,7 @@ JSON::checkDictionaryKeySeen(std::string const& key)
{
auto* obj = dynamic_cast<JSON_dictionary*>(m->value.get());
if (nullptr == obj) {
- throw std::logic_error(
- "JSON::checkDictionaryKey called on non-dictionary");
+ throw std::logic_error("JSON::checkDictionaryKey called on non-dictionary");
}
if (obj->parsed_keys.count(key)) {
return true;
@@ -421,8 +412,7 @@ JSON::isNull() const
}
bool
-JSON::forEachDictItem(
- std::function<void(std::string const& key, JSON value)> fn) const
+JSON::forEachDictItem(std::function<void(std::string const& key, JSON value)> fn) const
{
auto v = dynamic_cast<JSON_dictionary const*>(m->value.get());
if (v == nullptr) {
@@ -450,16 +440,13 @@ JSON::forEachArrayItem(std::function<void(JSON value)> fn) const
bool
JSON::checkSchema(JSON schema, std::list<std::string>& errors)
{
- return checkSchemaInternal(
- m->value.get(), schema.m->value.get(), 0, errors, "");
+ return checkSchemaInternal(m->value.get(), schema.m->value.get(), 0, errors, "");
}
bool
-JSON::checkSchema(
- JSON schema, unsigned long flags, std::list<std::string>& errors)
+JSON::checkSchema(JSON schema, unsigned long flags, std::list<std::string>& errors)
{
- return checkSchemaInternal(
- m->value.get(), schema.m->value.get(), flags, errors, "");
+ return checkSchemaInternal(m->value.get(), schema.m->value.get(), flags, errors, "");
}
bool
@@ -495,8 +482,8 @@ JSON::checkSchemaInternal(
auto members = sch_dict->members;
std::string key;
if ((members.size() == 1) &&
- ((key = members.begin()->first, key.length() > 2) &&
- (key.at(0) == '<') && (key.at(key.length() - 1) == '>'))) {
+ ((key = members.begin()->first, key.length() > 2) && (key.at(0) == '<') &&
+ (key.at(key.length() - 1) == '>'))) {
pattern_key = key;
}
}
@@ -565,17 +552,12 @@ JSON::checkSchemaInternal(
} else {
QTC::TC("libtests", "JSON schema array for single item");
checkSchemaInternal(
- this_v,
- sch_arr->elements.at(0).m->value.get(),
- flags,
- errors,
- prefix);
+ this_v, sch_arr->elements.at(0).m->value.get(), flags, errors, prefix);
}
} else if (!this_arr || (this_arr->elements.size() != n_elements)) {
QTC::TC("libtests", "JSON schema array length mismatch");
errors.push_back(
- err_prefix + " is supposed to be an array of length " +
- std::to_string(n_elements));
+ err_prefix + " is supposed to be an array of length " + std::to_string(n_elements));
return false;
} else {
// A multi-element array in the schema must correspond to
@@ -595,8 +577,7 @@ JSON::checkSchemaInternal(
}
} else if (!sch_str) {
QTC::TC("libtests", "JSON schema other type");
- errors.push_back(
- err_prefix + " schema value is not dictionary, array, or string");
+ errors.push_back(err_prefix + " schema value is not dictionary, array, or string");
return false;
}
@@ -736,8 +717,7 @@ JSONParser::handle_u_code(
" surrogate");
}
high_offset = 0;
- codepoint =
- 0x10000U + ((high_surrogate & 0x3FFU) << 10U) + (codepoint & 0x3FF);
+ codepoint = 0x10000U + ((high_surrogate & 0x3FFU) << 10U) + (codepoint & 0x3FF);
result += QUtil::toUTF8(codepoint);
} else {
result += QUtil::toUTF8(codepoint);
@@ -760,8 +740,8 @@ JSONParser::tokenError()
} else if (lex_state == ls_alpha) {
QTC::TC("libtests", "JSON parse keyword bad character");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": keyword: unexpected character " + std::string(p, 1));
+ "JSON: offset " + std::to_string(offset) + ": keyword: unexpected character " +
+ std::string(p, 1));
} else if (lex_state == ls_string) {
QTC::TC("libtests", "JSON parse control char in string");
throw std::runtime_error(
@@ -775,8 +755,7 @@ JSONParser::tokenError()
}
if (*p == '.') {
- if (lex_state == ls_number || lex_state == ls_number_e ||
- lex_state == ls_number_e_sign) {
+ if (lex_state == ls_number || lex_state == ls_number_e || lex_state == ls_number_e_sign) {
QTC::TC("libtests", "JSON parse point after e");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
@@ -790,24 +769,21 @@ JSONParser::tokenError()
} else if (*p == 'e' || *p == 'E') {
QTC::TC("libtests", "JSON parse duplicate e");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": numeric literal: e already seen");
+ "JSON: offset " + std::to_string(offset) + ": numeric literal: e already seen");
} else if ((*p == '+') || (*p == '-')) {
QTC::TC("libtests", "JSON parse unexpected sign");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": numeric literal: unexpected sign");
+ "JSON: offset " + std::to_string(offset) + ": numeric literal: unexpected sign");
} else if (QUtil::is_space(*p) || strchr("{}[]:,", *p)) {
QTC::TC("libtests", "JSON parse incomplete number");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": numeric literal: incomplete number");
+ "JSON: offset " + std::to_string(offset) + ": numeric literal: incomplete number");
} else {
QTC::TC("libtests", "JSON parse numeric bad character");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": numeric literal: unexpected character " + std::string(p, 1));
+ "JSON: offset " + std::to_string(offset) + ": numeric literal: unexpected character " +
+ std::string(p, 1));
}
throw std::logic_error("JSON::tokenError : unhandled error");
}
@@ -884,8 +860,7 @@ JSONParser::getToken()
} else {
QTC::TC("libtests", "JSON parse null character");
throw std::runtime_error(
- "JSON: control or null character at offset " +
- std::to_string(offset));
+ "JSON: control or null character at offset " + std::to_string(offset));
}
} else if (*p == ',') {
if (lex_state == ls_top) {
@@ -968,8 +943,8 @@ JSONParser::getToken()
} else {
QTC::TC("libtests", "JSON parse bad character");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": unexpected character " + std::string(p, 1));
+ "JSON: offset " + std::to_string(offset) + ": unexpected character " +
+ std::string(p, 1));
}
break;
@@ -994,8 +969,7 @@ JSONParser::getToken()
} else {
QTC::TC("libtests", "JSON parse leading zero");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": number with leading zero");
+ "JSON: offset " + std::to_string(offset) + ": number with leading zero");
}
break;
@@ -1127,20 +1101,14 @@ JSONParser::getToken()
tokenError();
}
if (++u_count == 4) {
- handle_u_code(
- u_value,
- offset - 5,
- high_surrogate,
- high_offset,
- token);
+ handle_u_code(u_value, offset - 5, high_surrogate, high_offset, token);
lex_state = ls_string;
}
ignore();
break;
default:
- throw std::logic_error(
- "JSONParser::getToken : trying to handle delimiter state");
+ throw std::logic_error("JSONParser::getToken : trying to handle delimiter state");
}
}
}
@@ -1205,19 +1173,16 @@ JSONParser::handleToken()
if (parser_state != ps_dict_after_key) {
QTC::TC("libtests", "JSON parse unexpected :");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": unexpected colon");
+ "JSON: offset " + std::to_string(offset) + ": unexpected colon");
}
parser_state = ps_dict_after_colon;
return;
case ls_comma:
- if (!((parser_state == ps_dict_after_item) ||
- (parser_state == ps_array_after_item))) {
+ if (!((parser_state == ps_dict_after_item) || (parser_state == ps_array_after_item))) {
QTC::TC("libtests", "JSON parse unexpected ,");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": unexpected comma");
+ "JSON: offset " + std::to_string(offset) + ": unexpected comma");
}
if (parser_state == ps_dict_after_item) {
parser_state = ps_dict_after_comma;
@@ -1230,12 +1195,10 @@ JSONParser::handleToken()
return;
case ls_end_array:
- if (!(parser_state == ps_array_begin ||
- parser_state == ps_array_after_item)) {
+ if (!(parser_state == ps_array_begin || parser_state == ps_array_after_item)) {
QTC::TC("libtests", "JSON parse unexpected ]");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": unexpected array end delimiter");
+ "JSON: offset " + std::to_string(offset) + ": unexpected array end delimiter");
}
parser_state = stack.back().state;
tos.setEnd(offset);
@@ -1248,12 +1211,10 @@ JSONParser::handleToken()
return;
case ls_end_dict:
- if (!((parser_state == ps_dict_begin) ||
- (parser_state == ps_dict_after_item))) {
+ if (!((parser_state == ps_dict_begin) || (parser_state == ps_dict_after_item))) {
QTC::TC("libtests", "JSON parse unexpected }");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": unexpected dictionary end delimiter");
+ "JSON: offset " + std::to_string(offset) + ": unexpected dictionary end delimiter");
}
parser_state = stack.back().state;
tos.setEnd(offset);
@@ -1279,14 +1240,12 @@ JSONParser::handleToken()
} else {
QTC::TC("libtests", "JSON parse invalid keyword");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": invalid keyword " + token);
+ "JSON: offset " + std::to_string(offset) + ": invalid keyword " + token);
}
break;
case ls_string:
- if (parser_state == ps_dict_begin ||
- parser_state == ps_dict_after_comma) {
+ if (parser_state == ps_dict_begin || parser_state == ps_dict_after_comma) {
dict_key = token;
dict_key_offset = token_start;
parser_state = ps_dict_after_key;
@@ -1297,8 +1256,7 @@ JSONParser::handleToken()
break;
default:
- throw std::logic_error(
- "JSONParser::handleToken : non-terminal lexer state encountered");
+ throw std::logic_error("JSONParser::handleToken : non-terminal lexer state encountered");
break;
}
@@ -1310,16 +1268,14 @@ JSONParser::handleToken()
case ps_dict_after_comma:
QTC::TC("libtests", "JSON parse string as dict key");
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": expect string as dictionary key");
+ "JSON: offset " + std::to_string(offset) + ": expect string as dictionary key");
break;
case ps_dict_after_colon:
if (tos.checkDictionaryKeySeen(dict_key)) {
QTC::TC("libtests", "JSON parse duplicate key");
throw std::runtime_error(
- "JSON: offset " + std::to_string(dict_key_offset) +
- ": duplicated dictionary key");
+ "JSON: offset " + std::to_string(dict_key_offset) + ": duplicated dictionary key");
}
if (!reactor || !reactor->dictionaryItem(dict_key, item)) {
tos.addDictionaryMember(dict_key, item);
@@ -1346,8 +1302,7 @@ JSONParser::handleToken()
case ps_dict_after_key:
QTC::TC("libtests", "JSON parse expected colon");
- throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) + ": expected ':'");
+ throw std::runtime_error("JSON: offset " + std::to_string(offset) + ": expected ':'");
break;
case ps_dict_after_item:
@@ -1363,8 +1318,7 @@ JSONParser::handleToken()
break;
case ps_done:
- throw std::logic_error(
- "JSONParser::handleToken: unexpected parser state");
+ throw std::logic_error("JSONParser::handleToken: unexpected parser state");
}
if (item.isDictionary() || item.isArray()) {
@@ -1387,8 +1341,7 @@ JSONParser::handleToken()
if (stack.size() > 500) {
throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": maximum object depth exceeded");
+ "JSON: offset " + std::to_string(offset) + ": maximum object depth exceeded");
}
}
}
diff --git a/libqpdf/JSONHandler.cc b/libqpdf/JSONHandler.cc
index d169780d..f4360a2d 100644
--- a/libqpdf/JSONHandler.cc
+++ b/libqpdf/JSONHandler.cc
@@ -53,8 +53,7 @@ JSONHandler::addDictHandlers(json_handler_t start_fn, void_handler_t end_fn)
}
void
-JSONHandler::addDictKeyHandler(
- std::string const& key, std::shared_ptr<JSONHandler> dkh)
+JSONHandler::addDictKeyHandler(std::string const& key, std::shared_ptr<JSONHandler> dkh)
{
m->h.dict_handlers[key] = dkh;
}
@@ -67,9 +66,7 @@ JSONHandler::addFallbackDictHandler(std::shared_ptr<JSONHandler> fdh)
void
JSONHandler::addArrayHandlers(
- json_handler_t start_fn,
- void_handler_t end_fn,
- std::shared_ptr<JSONHandler> ah)
+ json_handler_t start_fn, void_handler_t end_fn, std::shared_ptr<JSONHandler> ah)
{
m->h.array_start_handler = start_fn;
m->h.array_end_handler = end_fn;
@@ -108,22 +105,19 @@ JSONHandler::handle(std::string const& path, JSON j)
if (path_base != ".") {
path_base += ".";
}
- j.forEachDictItem(
- [&path, &path_base, this](std::string const& k, JSON v) {
- auto i = m->h.dict_handlers.find(k);
- if (i == m->h.dict_handlers.end()) {
- if (m->h.fallback_dict_handler.get()) {
- m->h.fallback_dict_handler->handle(path_base + k, v);
- } else {
- QTC::TC("libtests", "JSONHandler unexpected key");
- usage(
- "JSON handler found unexpected key " + k +
- " in object at " + path);
- }
+ j.forEachDictItem([&path, &path_base, this](std::string const& k, JSON v) {
+ auto i = m->h.dict_handlers.find(k);
+ if (i == m->h.dict_handlers.end()) {
+ if (m->h.fallback_dict_handler.get()) {
+ m->h.fallback_dict_handler->handle(path_base + k, v);
} else {
- i->second->handle(path_base + k, v);
+ QTC::TC("libtests", "JSONHandler unexpected key");
+ usage("JSON handler found unexpected key " + k + " in object at " + path);
}
- });
+ } else {
+ i->second->handle(path_base + k, v);
+ }
+ });
m->h.dict_end_handler(path);
handled = true;
}
@@ -131,8 +125,7 @@ JSONHandler::handle(std::string const& path, JSON j)
m->h.array_start_handler(path, j);
size_t i = 0;
j.forEachArrayItem([&i, &path, this](JSON v) {
- m->h.array_item_handler->handle(
- path + "[" + std::to_string(i) + "]", v);
+ m->h.array_item_handler->handle(path + "[" + std::to_string(i) + "]", v);
++i;
});
m->h.array_end_handler(path);
diff --git a/libqpdf/MD5.cc b/libqpdf/MD5.cc
index 9668c982..c0782124 100644
--- a/libqpdf/MD5.cc
+++ b/libqpdf/MD5.cc
@@ -81,8 +81,7 @@ MD5::encodeFile(char const* filename, qpdf_offset_t up_to_offset)
// Assume, perhaps incorrectly, that errno was set by the
// underlying call to read....
(void)fclose(file);
- QUtil::throw_system_error(
- std::string("MD5: read error on ") + filename);
+ QUtil::throw_system_error(std::string("MD5: read error on ") + filename);
}
(void)fclose(file);
@@ -115,8 +114,7 @@ MD5::unparse()
this->crypto->MD5_finalize();
Digest digest_val;
digest(digest_val);
- return QUtil::hex_encode(
- std::string(reinterpret_cast<char*>(digest_val), 16));
+ return QUtil::hex_encode(std::string(reinterpret_cast<char*>(digest_val), 16));
}
std::string
@@ -143,10 +141,7 @@ MD5::checkDataChecksum(char const* const checksum, char const* buf, size_t len)
}
bool
-MD5::checkFileChecksum(
- char const* const checksum,
- char const* filename,
- qpdf_offset_t up_to_offset)
+MD5::checkFileChecksum(char const* const checksum, char const* filename, qpdf_offset_t up_to_offset)
{
bool result = false;
try {
diff --git a/libqpdf/NNTree.cc b/libqpdf/NNTree.cc
index 6b15a1cf..bbdd83f8 100644
--- a/libqpdf/NNTree.cc
+++ b/libqpdf/NNTree.cc
@@ -24,8 +24,7 @@ warn(QPDF& qpdf, QPDFObjectHandle& node, std::string const& msg)
static void
error(QPDF& qpdf, QPDFObjectHandle& node, std::string const& msg)
{
- throw QPDFExc(
- qpdf_e_damaged_pdf, qpdf.getFilename(), get_description(node), 0, msg);
+ throw QPDFExc(qpdf_e_damaged_pdf, qpdf.getFilename(), get_description(node), 0, msg);
}
NNTreeIterator::NNTreeIterator(NNTreeImpl& impl) :
@@ -76,8 +75,7 @@ NNTreeIterator::updateIValue(bool allow_invalid)
}
}
-NNTreeIterator::PathElement::PathElement(
- QPDFObjectHandle const& node, int kid_number) :
+NNTreeIterator::PathElement::PathElement(QPDFObjectHandle const& node, int kid_number) :
node(node),
kid_number(kid_number)
{
@@ -94,16 +92,14 @@ NNTreeIterator::getNextKid(PathElement& pe, bool backward)
if ((pe.kid_number >= 0) && (pe.kid_number < kids.getArrayNItems())) {
result = kids.getArrayItem(pe.kid_number);
if (result.isDictionary() &&
- (result.hasKey("/Kids") ||
- result.hasKey(impl.details.itemsKey()))) {
+ (result.hasKey("/Kids") || result.hasKey(impl.details.itemsKey()))) {
found = true;
} else {
QTC::TC("qpdf", "NNTree skip invalid kid");
warn(
impl.qpdf,
pe.node,
- ("skipping over invalid kid at index " +
- std::to_string(pe.kid_number)));
+ ("skipping over invalid kid at index " + std::to_string(pe.kid_number)));
}
} else {
result = QPDFObjectHandle::newNull();
@@ -131,8 +127,7 @@ NNTreeIterator::increment(bool backward)
while (valid() && (!found_valid_key)) {
this->item_number += backward ? -2 : 2;
auto items = this->node.getKey(impl.details.itemsKey());
- if ((this->item_number < 0) ||
- (this->item_number >= items.getArrayNItems())) {
+ if ((this->item_number < 0) || (this->item_number >= items.getArrayNItems())) {
bool found = false;
setItemNumber(QPDFObjectHandle(), -1);
while (!(found || this->path.empty())) {
@@ -149,18 +144,13 @@ NNTreeIterator::increment(bool backward)
items = this->node.getKey(impl.details.itemsKey());
if (this->item_number + 1 >= items.getArrayNItems()) {
QTC::TC("qpdf", "NNTree skip item at end of short items");
- warn(
- impl.qpdf,
- this->node,
- "items array doesn't have enough elements");
- } else if (!impl.details.keyValid(
- items.getArrayItem(this->item_number))) {
+ warn(impl.qpdf, this->node, "items array doesn't have enough elements");
+ } else if (!impl.details.keyValid(items.getArrayItem(this->item_number))) {
QTC::TC("qpdf", "NNTree skip invalid key");
warn(
impl.qpdf,
this->node,
- ("item " + std::to_string(this->item_number) +
- " has the wrong type"));
+ ("item " + std::to_string(this->item_number) + " has the wrong type"));
} else {
found_valid_key = true;
}
@@ -169,8 +159,7 @@ NNTreeIterator::increment(bool backward)
}
void
-NNTreeIterator::resetLimits(
- QPDFObjectHandle node, std::list<PathElement>::iterator parent)
+NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::iterator parent)
{
bool done = false;
while (!done) {
@@ -197,10 +186,8 @@ NNTreeIterator::resetLimits(
if (first_kid.isDictionary() && last_kid.isDictionary()) {
auto first_limits = first_kid.getKey("/Limits");
auto last_limits = last_kid.getKey("/Limits");
- if (first_limits.isArray() &&
- (first_limits.getArrayNItems() >= 2) &&
- last_limits.isArray() &&
- (last_limits.getArrayNItems() >= 2)) {
+ if (first_limits.isArray() && (first_limits.getArrayNItems() >= 2) &&
+ last_limits.isArray() && (last_limits.getArrayNItems() >= 2)) {
first = first_limits.getArrayItem(0);
last = last_limits.getArrayItem(1);
}
@@ -214,8 +201,7 @@ NNTreeIterator::resetLimits(
if (olimits.isArray() && (olimits.getArrayNItems() == 2)) {
auto ofirst = olimits.getArrayItem(0);
auto olast = olimits.getArrayItem(1);
- if (impl.details.keyValid(ofirst) &&
- impl.details.keyValid(olast) &&
+ if (impl.details.keyValid(ofirst) && impl.details.keyValid(olast) &&
(impl.details.compareKeys(first, ofirst) == 0) &&
(impl.details.compareKeys(last, olast) == 0)) {
QTC::TC("qpdf", "NNTree limits didn't change");
@@ -240,8 +226,7 @@ NNTreeIterator::resetLimits(
}
void
-NNTreeIterator::split(
- QPDFObjectHandle to_split, std::list<PathElement>::iterator parent)
+NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterator parent)
{
// Split some node along the path to the item pointed to by this
// iterator, and adjust the iterator so it points to the same
@@ -272,8 +257,7 @@ NNTreeIterator::split(
// item_number: 0
if (!valid()) {
- throw std::logic_error(
- "NNTreeIterator::split called an invalid iterator");
+ throw std::logic_error("NNTreeIterator::split called an invalid iterator");
}
// Find the array we actually need to split, which is either this
@@ -335,8 +319,7 @@ NNTreeIterator::split(
// non-root case so remaining logic can handle them in the
// same way.
- auto first_node =
- impl.qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
+ auto first_node = impl.qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
first_node.replaceKey(key, first_half);
QPDFObjectHandle new_kids = QPDFObjectHandle::newArray();
new_kids.appendItem(first_node);
@@ -371,8 +354,7 @@ NNTreeIterator::split(
resetLimits(to_split, parent);
// Create a new node to contain the second half
- QPDFObjectHandle second_node =
- impl.qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
+ QPDFObjectHandle second_node = impl.qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
second_node.replaceKey(key, second_half);
resetLimits(second_node, parent);
@@ -457,10 +439,7 @@ NNTreeIterator::remove()
auto items = this->node.getKey(impl.details.itemsKey());
int nitems = items.getArrayNItems();
if (this->item_number + 2 > nitems) {
- error(
- impl.qpdf,
- this->node,
- "found short items array while removing an item");
+ error(impl.qpdf, this->node, "found short items array while removing an item");
}
items.eraseItem(this->item_number);
@@ -491,8 +470,7 @@ NNTreeIterator::remove()
} else {
// We already checked to ensure this condition would not
// happen.
- throw std::logic_error(
- "NNTreeIterator::remove: item_number > nitems after erase");
+ throw std::logic_error("NNTreeIterator::remove: item_number > nitems after erase");
}
return;
}
@@ -549,8 +527,7 @@ NNTreeIterator::remove()
// empty items array.
QTC::TC("qpdf", "NNTree non-flat tree is empty after remove");
element->node.removeKey("/Kids");
- element->node.replaceKey(
- impl.details.itemsKey(), QPDFObjectHandle::newArray());
+ element->node.replaceKey(impl.details.itemsKey(), QPDFObjectHandle::newArray());
this->path.clear();
setItemNumber(impl.oh, -1);
done = true;
@@ -645,20 +622,14 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty)
while (!failed) {
if (!seen.add(node)) {
QTC::TC("qpdf", "NNTree deepen: loop");
- warn(
- impl.qpdf,
- node,
- "loop detected while traversing name/number tree");
+ warn(impl.qpdf, node, "loop detected while traversing name/number tree");
failed = true;
break;
}
if (!node.isDictionary()) {
QTC::TC("qpdf", "NNTree node is not a dictionary");
- warn(
- impl.qpdf,
- node,
- "non-dictionary node while traversing name/number tree");
+ warn(impl.qpdf, node, "non-dictionary node while traversing name/number tree");
failed = true;
break;
}
@@ -703,8 +674,8 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty)
warn(
impl.qpdf,
node,
- ("name/number tree node has neither non-empty " +
- impl.details.itemsKey() + " nor /Kids"));
+ ("name/number tree node has neither non-empty " + impl.details.itemsKey() +
+ " nor /Kids"));
failed = true;
break;
}
@@ -717,10 +688,7 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty)
}
NNTreeImpl::NNTreeImpl(
- NNTreeDetails const& details,
- QPDF& qpdf,
- QPDFObjectHandle& oh,
- bool auto_repair) :
+ NNTreeDetails const& details, QPDF& qpdf, QPDFObjectHandle& oh, bool auto_repair) :
details(details),
qpdf(qpdf),
split_threshold(32),
@@ -763,8 +731,7 @@ NNTreeImpl::withinLimits(QPDFObjectHandle key, QPDFObjectHandle node)
int result = 0;
auto limits = node.getKey("/Limits");
if (limits.isArray() && (limits.getArrayNItems() >= 2) &&
- details.keyValid(limits.getArrayItem(0)) &&
- details.keyValid(limits.getArrayItem(1))) {
+ details.keyValid(limits.getArrayItem(0)) && details.keyValid(limits.getArrayItem(1))) {
if (details.compareKeys(key, limits.getArrayItem(0)) < 0) {
result = -1;
} else if (details.compareKeys(key, limits.getArrayItem(1)) > 0) {
@@ -783,8 +750,7 @@ NNTreeImpl::binarySearch(
QPDFObjectHandle items,
int num_items,
bool return_prev_if_not_found,
- int (NNTreeImpl::*compare)(
- QPDFObjectHandle& key, QPDFObjectHandle& arr, int item))
+ int (NNTreeImpl::*compare)(QPDFObjectHandle& key, QPDFObjectHandle& arr, int item))
{
int max_idx = 1;
while (max_idx < num_items) {
@@ -838,8 +804,7 @@ NNTreeImpl::binarySearch(
}
int
-NNTreeImpl::compareKeyItem(
- QPDFObjectHandle& key, QPDFObjectHandle& items, int idx)
+NNTreeImpl::compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx)
{
if (!((items.isArray() && (items.getArrayNItems() > (2 * idx)) &&
details.keyValid(items.getArrayItem(2 * idx))))) {
@@ -847,15 +812,13 @@ NNTreeImpl::compareKeyItem(
error(
qpdf,
this->oh,
- ("item at index " + std::to_string(2 * idx) +
- " is not the right type"));
+ ("item at index " + std::to_string(2 * idx) + " is not the right type"));
}
return details.compareKeys(key, items.getArrayItem(2 * idx));
}
int
-NNTreeImpl::compareKeyKid(
- QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx)
+NNTreeImpl::compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx)
{
if (!(kids.isArray() && (idx < kids.getArrayNItems()) &&
kids.getArrayItem(idx).isDictionary())) {
@@ -875,8 +838,7 @@ NNTreeImpl::repair()
repl.insert(i.first, i.second);
}
this->oh.replaceKey("/Kids", new_node.getKey("/Kids"));
- this->oh.replaceKey(
- details.itemsKey(), new_node.getKey(details.itemsKey()));
+ this->oh.replaceKey(details.itemsKey(), new_node.getKey(details.itemsKey()));
}
NNTreeImpl::iterator
@@ -887,10 +849,7 @@ NNTreeImpl::find(QPDFObjectHandle key, bool return_prev_if_not_found)
} catch (QPDFExc& e) {
if (this->auto_repair) {
QTC::TC("qpdf", "NNTree repair");
- warn(
- qpdf,
- this->oh,
- std::string("attempting to repair after error: ") + e.what());
+ warn(qpdf, this->oh, std::string("attempting to repair after error: ") + e.what());
repair();
return findInternal(key, return_prev_if_not_found);
} else {
@@ -939,18 +898,13 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found)
int nitems = items.isArray() ? items.getArrayNItems() : 0;
if (nitems > 0) {
int idx = binarySearch(
- key,
- items,
- nitems / 2,
- return_prev_if_not_found,
- &NNTreeImpl::compareKeyItem);
+ key, items, nitems / 2, return_prev_if_not_found, &NNTreeImpl::compareKeyItem);
if (idx >= 0) {
result.setItemNumber(node, 2 * idx);
}
break;
} else if (nkids > 0) {
- int idx = binarySearch(
- key, kids, nkids, true, &NNTreeImpl::compareKeyKid);
+ int idx = binarySearch(key, kids, nkids, true, &NNTreeImpl::compareKeyKid);
if (idx == -1) {
QTC::TC("qpdf", "NNTree -1 in binary search");
error(
diff --git a/libqpdf/OffsetInputSource.cc b/libqpdf/OffsetInputSource.cc
index 3ea4fb9d..d0028f0d 100644
--- a/libqpdf/OffsetInputSource.cc
+++ b/libqpdf/OffsetInputSource.cc
@@ -10,11 +10,9 @@ OffsetInputSource::OffsetInputSource(
global_offset(global_offset)
{
if (global_offset < 0) {
- throw std::logic_error(
- "OffsetInputSource constructed with negative offset");
+ throw std::logic_error("OffsetInputSource constructed with negative offset");
}
- this->max_safe_offset =
- std::numeric_limits<qpdf_offset_t>::max() - global_offset;
+ this->max_safe_offset = std::numeric_limits<qpdf_offset_t>::max() - global_offset;
}
qpdf_offset_t
@@ -51,8 +49,7 @@ OffsetInputSource::seek(qpdf_offset_t offset, int whence)
this->proxied->seek(offset, whence);
}
if (tell() < 0) {
- throw std::runtime_error(
- "offset input source: seek before beginning of file");
+ throw std::runtime_error("offset input source: seek before beginning of file");
}
}
diff --git a/libqpdf/PDFVersion.cc b/libqpdf/PDFVersion.cc
index a2b807c6..d093b068 100644
--- a/libqpdf/PDFVersion.cc
+++ b/libqpdf/PDFVersion.cc
@@ -7,8 +7,7 @@ PDFVersion::PDFVersion() :
{
}
-PDFVersion::PDFVersion(
- int major_version, int minor_version, int extension_level) :
+PDFVersion::PDFVersion(int major_version, int minor_version, int extension_level) :
major_version(major_version),
minor_version(minor_version),
extension_level(extension_level)
@@ -31,8 +30,7 @@ bool
PDFVersion::operator==(PDFVersion const& rhs) const
{
return (
- (this->major_version == rhs.major_version) &&
- (this->minor_version == rhs.minor_version) &&
+ (this->major_version == rhs.major_version) && (this->minor_version == rhs.minor_version) &&
(this->extension_level == rhs.extension_level));
}
@@ -48,8 +46,7 @@ void
PDFVersion::getVersion(std::string& version, int& extension_level) const
{
extension_level = this->extension_level;
- version = std::to_string(this->major_version) + "." +
- std::to_string(this->minor_version);
+ version = std::to_string(this->major_version) + "." + std::to_string(this->minor_version);
}
int
diff --git a/libqpdf/Pipeline.cc b/libqpdf/Pipeline.cc
index 73bd1675..3f5fc3bc 100644
--- a/libqpdf/Pipeline.cc
+++ b/libqpdf/Pipeline.cc
@@ -14,8 +14,7 @@ Pipeline::getNext(bool allow_null)
{
if ((this->next == nullptr) && (!allow_null)) {
throw std::logic_error(
- this->identifier +
- ": Pipeline::getNext() called on pipeline with no next");
+ this->identifier + ": Pipeline::getNext() called on pipeline with no next");
}
return this->next;
}
diff --git a/libqpdf/Pl_AES_PDF.cc b/libqpdf/Pl_AES_PDF.cc
index 89bde7ce..a71052a5 100644
--- a/libqpdf/Pl_AES_PDF.cc
+++ b/libqpdf/Pl_AES_PDF.cc
@@ -117,8 +117,7 @@ Pl_AES_PDF::finish()
throw std::logic_error("buffer overflow in AES encryption"
" pipeline");
}
- std::memset(
- this->inbuf + this->offset, 0, this->buf_size - this->offset);
+ std::memset(this->inbuf + this->offset, 0, this->buf_size - this->offset);
this->offset = this->buf_size;
}
flush(!this->disable_padding);
@@ -149,8 +148,7 @@ void
Pl_AES_PDF::flush(bool strip_padding)
{
if (this->offset != this->buf_size) {
- throw std::logic_error(
- "AES pipeline: flush called when buffer was not full");
+ throw std::logic_error("AES pipeline: flush called when buffer was not full");
}
if (first) {
@@ -177,11 +175,7 @@ Pl_AES_PDF::flush(bool strip_padding)
}
}
this->crypto->rijndael_init(
- encrypt,
- this->key.get(),
- key_bytes,
- this->cbc_mode,
- this->cbc_block);
+ encrypt, this->key.get(), key_bytes, this->cbc_mode, this->cbc_block);
if (return_after_init) {
return;
}
diff --git a/libqpdf/Pl_ASCII85Decoder.cc b/libqpdf/Pl_ASCII85Decoder.cc
index 6280c362..e789a753 100644
--- a/libqpdf/Pl_ASCII85Decoder.cc
+++ b/libqpdf/Pl_ASCII85Decoder.cc
@@ -26,8 +26,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len)
flush();
eod = 2;
} else {
- throw std::runtime_error(
- "broken end-of-data sequence in base 85 data");
+ throw std::runtime_error("broken end-of-data sequence in base 85 data");
}
} else {
switch (buf[i]) {
@@ -47,8 +46,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len)
case 'z':
if (pos != 0) {
- throw std::runtime_error(
- "unexpected z during base 85 decode");
+ throw std::runtime_error("unexpected z during base 85 decode");
} else {
QTC::TC("libtests", "Pl_ASCII85Decoder read z");
unsigned char zeroes[4];
@@ -59,8 +57,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len)
default:
if ((buf[i] < 33) || (buf[i] > 117)) {
- throw std::runtime_error(
- "character out of range during base 85 decode");
+ throw std::runtime_error("character out of range during base 85 decode");
} else {
this->inbuf[this->pos++] = buf[i];
if (pos == 5) {
@@ -93,10 +90,7 @@ Pl_ASCII85Decoder::flush()
lval >>= 8;
}
- QTC::TC(
- "libtests",
- "Pl_ASCII85Decoder partial flush",
- (this->pos == 5) ? 0 : 1);
+ QTC::TC("libtests", "Pl_ASCII85Decoder partial flush", (this->pos == 5) ? 0 : 1);
// Reset before calling getNext()->write in case that throws an
// exception.
auto t = this->pos - 1;
diff --git a/libqpdf/Pl_ASCIIHexDecoder.cc b/libqpdf/Pl_ASCIIHexDecoder.cc
index 3548f33e..313d8fed 100644
--- a/libqpdf/Pl_ASCIIHexDecoder.cc
+++ b/libqpdf/Pl_ASCIIHexDecoder.cc
@@ -78,10 +78,7 @@ Pl_ASCIIHexDecoder::flush()
}
auto ch = static_cast<unsigned char>((b[0] << 4) + b[1]);
- QTC::TC(
- "libtests",
- "Pl_ASCIIHexDecoder partial flush",
- (this->pos == 2) ? 0 : 1);
+ QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", (this->pos == 2) ? 0 : 1);
// Reset before calling getNext()->write in case that throws an
// exception.
this->pos = 0;
diff --git a/libqpdf/Pl_Base64.cc b/libqpdf/Pl_Base64.cc
index af5ff0bb..e42c9cb6 100644
--- a/libqpdf/Pl_Base64.cc
+++ b/libqpdf/Pl_Base64.cc
@@ -91,8 +91,7 @@ void
Pl_Base64::flush_decode()
{
if (this->end_of_data) {
- throw std::runtime_error(
- getIdentifier() + ": base64 decode: data follows pad characters");
+ throw std::runtime_error(getIdentifier() + ": base64 decode: data follows pad characters");
}
int pad = 0;
int shift = 18;
@@ -110,14 +109,12 @@ Pl_Base64::flush_decode()
v = 62;
} else if ((ch == '/') || (ch == '_')) {
v = 63;
- } else if (
- (ch == '=') && ((i == 3) || ((i == 2) && (this->buf[3] == '=')))) {
+ } else if ((ch == '=') && ((i == 3) || ((i == 2) && (this->buf[3] == '=')))) {
++pad;
this->end_of_data = true;
v = 0;
} else {
- throw std::runtime_error(
- getIdentifier() + ": base64 decode: invalid input");
+ throw std::runtime_error(getIdentifier() + ": base64 decode: invalid input");
}
outval |= v << shift;
shift -= 6;
diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc
index 98356325..76c8a5d5 100644
--- a/libqpdf/Pl_Buffer.cc
+++ b/libqpdf/Pl_Buffer.cc
@@ -64,8 +64,7 @@ void
Pl_Buffer::getMallocBuffer(unsigned char** buf, size_t* len)
{
if (!m->ready) {
- throw std::logic_error(
- "Pl_Buffer::getMallocBuffer() called when not ready");
+ throw std::logic_error("Pl_Buffer::getMallocBuffer() called when not ready");
}
auto size = m->data.length();
*len = size;
diff --git a/libqpdf/Pl_DCT.cc b/libqpdf/Pl_DCT.cc
index a910d1b0..5634e022 100644
--- a/libqpdf/Pl_DCT.cc
+++ b/libqpdf/Pl_DCT.cc
@@ -182,15 +182,12 @@ term_pipeline_destination(j_compress_ptr cinfo)
}
static void
-jpeg_pipeline_dest(
- j_compress_ptr cinfo, unsigned char* outbuffer, size_t size, Pipeline* next)
+jpeg_pipeline_dest(j_compress_ptr cinfo, unsigned char* outbuffer, size_t size, Pipeline* next)
{
cinfo->dest = static_cast<struct jpeg_destination_mgr*>(
// line-break
(*cinfo->mem->alloc_small)(
- reinterpret_cast<j_common_ptr>(cinfo),
- JPOOL_PERMANENT,
- sizeof(dct_pipeline_dest)));
+ reinterpret_cast<j_common_ptr>(cinfo), JPOOL_PERMANENT, sizeof(dct_pipeline_dest)));
auto* dest = reinterpret_cast<dct_pipeline_dest*>(cinfo->dest);
dest->pub.init_destination = init_pipeline_destination;
dest->pub.empty_output_buffer = empty_pipeline_output_buffer;
@@ -243,9 +240,7 @@ jpeg_buffer_src(j_decompress_ptr cinfo, Buffer* buffer)
cinfo->src = reinterpret_cast<jpeg_source_mgr*>(
// line-break
(*cinfo->mem->alloc_small)(
- reinterpret_cast<j_common_ptr>(cinfo),
- JPOOL_PERMANENT,
- sizeof(jpeg_source_mgr)));
+ reinterpret_cast<j_common_ptr>(cinfo), JPOOL_PERMANENT, sizeof(jpeg_source_mgr)));
jpeg_source_mgr* src = cinfo->src;
src->init_source = init_buffer_source;
@@ -262,16 +257,12 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b)
{
auto* cinfo = reinterpret_cast<jpeg_compress_struct*>(cinfo_p);
-#if ( \
- (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
- defined(__clang__))
+#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__))
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
jpeg_create_compress(cinfo);
-#if ( \
- (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
- defined(__clang__))
+#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__))
# pragma GCC diagnostic pop
#endif
static int const BUF_SIZE = 65536;
@@ -290,11 +281,9 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b)
jpeg_start_compress(cinfo, TRUE);
- unsigned int width =
- cinfo->image_width * QIntC::to_uint(cinfo->input_components);
+ unsigned int width = cinfo->image_width * QIntC::to_uint(cinfo->input_components);
size_t expected_size = QIntC::to_size(cinfo->image_height) *
- QIntC::to_size(cinfo->image_width) *
- QIntC::to_size(cinfo->input_components);
+ QIntC::to_size(cinfo->image_width) * QIntC::to_size(cinfo->input_components);
if (b->getSize() != expected_size) {
throw std::runtime_error(
"Pl_DCT: image buffer size = " + std::to_string(b->getSize()) +
@@ -316,16 +305,12 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b)
{
auto* cinfo = reinterpret_cast<jpeg_decompress_struct*>(cinfo_p);
-#if ( \
- (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
- defined(__clang__))
+#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__))
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
jpeg_create_decompress(cinfo);
-#if ( \
- (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
- defined(__clang__))
+#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__))
# pragma GCC diagnostic pop
#endif
jpeg_buffer_src(cinfo, b);
@@ -333,10 +318,9 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b)
(void)jpeg_read_header(cinfo, TRUE);
(void)jpeg_calc_output_dimensions(cinfo);
- unsigned int width =
- cinfo->output_width * QIntC::to_uint(cinfo->output_components);
- JSAMPARRAY buffer = (*cinfo->mem->alloc_sarray)(
- reinterpret_cast<j_common_ptr>(cinfo), JPOOL_IMAGE, width, 1);
+ unsigned int width = cinfo->output_width * QIntC::to_uint(cinfo->output_components);
+ JSAMPARRAY buffer =
+ (*cinfo->mem->alloc_sarray)(reinterpret_cast<j_common_ptr>(cinfo), JPOOL_IMAGE, width, 1);
(void)jpeg_start_decompress(cinfo);
while (cinfo->output_scanline < cinfo->output_height) {
diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc
index dfd00c05..c3e4a9f5 100644
--- a/libqpdf/Pl_Flate.cc
+++ b/libqpdf/Pl_Flate.cc
@@ -54,10 +54,7 @@ Pl_Flate::Members::~Members()
}
Pl_Flate::Pl_Flate(
- char const* identifier,
- Pipeline* next,
- action_e action,
- unsigned int out_bufsize_int) :
+ char const* identifier, Pipeline* next, action_e action, unsigned int out_bufsize_int) :
Pipeline(identifier, next),
m(new Members(QIntC::to_size(out_bufsize_int), action))
{
@@ -88,8 +85,7 @@ Pl_Flate::write(unsigned char const* data, size_t len)
{
if (m->outbuf == nullptr) {
throw std::logic_error(
- this->identifier +
- ": Pl_Flate: write() called after finish() called");
+ this->identifier + ": Pl_Flate: write() called after finish() called");
}
// Write in chunks in case len is too big to fit in an int.
@@ -99,8 +95,7 @@ Pl_Flate::write(unsigned char const* data, size_t len)
unsigned char const* buf = data;
while (bytes_left > 0) {
size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
- handleData(
- buf, bytes, (m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH));
+ handleData(buf, bytes, (m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH));
bytes_left -= bytes;
buf += bytes;
}
@@ -124,9 +119,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush)
// deflateInit and inflateInit are macros that use old-style
// casts.
-#if ( \
- (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
- defined(__clang__))
+#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__))
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
@@ -135,9 +128,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush)
} else {
err = inflateInit(&zstream);
}
-#if ( \
- (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
- defined(__clang__))
+#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__))
# pragma GCC diagnostic pop
#endif
@@ -171,8 +162,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush)
// least one in qpdf's test suite). In some cases, we want
// to know about this, because it indicates incorrect
// compression, so call a callback if provided.
- this->warn(
- "input stream is complete but output may still be valid", err);
+ this->warn("input stream is complete but output may still be valid", err);
done = true;
break;
@@ -188,8 +178,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush)
// needed, so we're done for now.
done = true;
}
- uLong ready =
- QIntC::to_ulong(m->out_bufsize - zstream.avail_out);
+ uLong ready = QIntC::to_ulong(m->out_bufsize - zstream.avail_out);
if (ready > 0) {
this->getNext()->write(m->outbuf.get(), ready);
zstream.next_out = m->outbuf.get();
@@ -249,10 +238,8 @@ Pl_Flate::checkError(char const* prefix, int error_code)
{
z_stream& zstream = *(static_cast<z_stream*>(m->zdata));
if (error_code != Z_OK) {
- char const* action_str =
- (m->action == a_deflate ? "deflate" : "inflate");
- std::string msg =
- this->identifier + ": " + action_str + ": " + prefix + ": ";
+ char const* action_str = (m->action == a_deflate ? "deflate" : "inflate");
+ std::string msg = this->identifier + ": " + action_str + ": " + prefix + ": ";
if (zstream.msg) {
msg += zstream.msg;
@@ -283,8 +270,7 @@ Pl_Flate::checkError(char const* prefix, int error_code)
break;
default:
- msg += std::string("zlib unknown error (") +
- std::to_string(error_code) + ")";
+ msg += std::string("zlib unknown error (") + std::to_string(error_code) + ")";
break;
}
}
diff --git a/libqpdf/Pl_Function.cc b/libqpdf/Pl_Function.cc
index a18f3ef2..2cb22926 100644
--- a/libqpdf/Pl_Function.cc
+++ b/libqpdf/Pl_Function.cc
@@ -13,8 +13,7 @@ Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_t fn) :
{
}
-Pl_Function::Pl_Function(
- char const* identifier, Pipeline* next, writer_c_t fn, void* udata) :
+Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_c_t fn, void* udata) :
Pipeline(identifier, next),
m(new Members(nullptr))
{
@@ -22,14 +21,12 @@ Pl_Function::Pl_Function(
int code = fn(data, len, udata);
if (code != 0) {
throw std::runtime_error(
- std::string(identifier) + " function returned code " +
- std::to_string(code));
+ std::string(identifier) + " function returned code " + std::to_string(code));
}
};
}
-Pl_Function::Pl_Function(
- char const* identifier, Pipeline* next, writer_c_char_t fn, void* udata) :
+Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_c_char_t fn, void* udata) :
Pipeline(identifier, next),
m(new Members(nullptr))
{
@@ -37,8 +34,7 @@ Pl_Function::Pl_Function(
int code = fn(reinterpret_cast<char const*>(data), len, udata);
if (code != 0) {
throw std::runtime_error(
- std::string(identifier) + " function returned code " +
- std::to_string(code));
+ std::string(identifier) + " function returned code " + std::to_string(code));
}
};
}
diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc
index aa9257fb..8e5fd9d1 100644
--- a/libqpdf/Pl_LZWDecoder.cc
+++ b/libqpdf/Pl_LZWDecoder.cc
@@ -6,8 +6,7 @@
#include <cstring>
#include <stdexcept>
-Pl_LZWDecoder::Pl_LZWDecoder(
- char const* identifier, Pipeline* next, bool early_code_change) :
+Pl_LZWDecoder::Pl_LZWDecoder(char const* identifier, Pipeline* next, bool early_code_change) :
Pipeline(identifier, next),
code_size(9),
next(0),
@@ -90,15 +89,13 @@ Pl_LZWDecoder::getFirstChar(unsigned int code)
} else if (code > 257) {
unsigned int idx = code - 258;
if (idx >= table.size()) {
- throw std::runtime_error(
- "Pl_LZWDecoder::getFirstChar: table overflow");
+ throw std::runtime_error("Pl_LZWDecoder::getFirstChar: table overflow");
}
Buffer& b = table.at(idx);
result = b.getBuffer()[0];
} else {
throw std::runtime_error(
- "Pl_LZWDecoder::getFirstChar called with invalid code (" +
- std::to_string(code) + ")");
+ "Pl_LZWDecoder::getFirstChar called with invalid code (" + std::to_string(code) + ")");
}
return result;
}
@@ -117,8 +114,7 @@ Pl_LZWDecoder::addToTable(unsigned char next)
} else if (this->last_code > 257) {
unsigned int idx = this->last_code - 258;
if (idx >= table.size()) {
- throw std::runtime_error(
- "Pl_LZWDecoder::addToTable: table overflow");
+ throw std::runtime_error("Pl_LZWDecoder::addToTable: table overflow");
}
Buffer& b = table.at(idx);
last_data = b.getBuffer();
@@ -182,8 +178,7 @@ Pl_LZWDecoder::handleCode(unsigned int code)
}
addToTable(next);
unsigned int change_idx = new_idx + code_change_delta;
- if ((change_idx == 511) || (change_idx == 1023) ||
- (change_idx == 2047)) {
+ if ((change_idx == 511) || (change_idx == 1023) || (change_idx == 2047)) {
++this->code_size;
}
}
@@ -194,8 +189,7 @@ Pl_LZWDecoder::handleCode(unsigned int code)
} else {
unsigned int idx = code - 258;
if (idx >= table.size()) {
- throw std::runtime_error(
- "Pl_LZWDecoder::handleCode: table overflow");
+ throw std::runtime_error("Pl_LZWDecoder::handleCode: table overflow");
}
Buffer& b = table.at(idx);
getNext()->write(b.getBuffer(), b.getSize());
diff --git a/libqpdf/Pl_MD5.cc b/libqpdf/Pl_MD5.cc
index 358f5806..c0714839 100644
--- a/libqpdf/Pl_MD5.cc
+++ b/libqpdf/Pl_MD5.cc
@@ -26,8 +26,7 @@ Pl_MD5::write(unsigned char const* buf, size_t len)
unsigned char const* data = buf;
while (bytes_left > 0) {
size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
- this->md5.encodeDataIncrementally(
- reinterpret_cast<char const*>(data), bytes);
+ this->md5.encodeDataIncrementally(reinterpret_cast<char const*>(data), bytes);
bytes_left -= bytes;
data += bytes;
}
diff --git a/libqpdf/Pl_OStream.cc b/libqpdf/Pl_OStream.cc
index 78dd835e..28a08bdc 100644
--- a/libqpdf/Pl_OStream.cc
+++ b/libqpdf/Pl_OStream.cc
@@ -22,8 +22,7 @@ Pl_OStream::~Pl_OStream()
void
Pl_OStream::write(unsigned char const* buf, size_t len)
{
- m->os.write(
- reinterpret_cast<char const*>(buf), static_cast<std::streamsize>(len));
+ m->os.write(reinterpret_cast<char const*>(buf), static_cast<std::streamsize>(len));
}
void
diff --git a/libqpdf/Pl_PNGFilter.cc b/libqpdf/Pl_PNGFilter.cc
index 31ef3cc8..b9e297d7 100644
--- a/libqpdf/Pl_PNGFilter.cc
+++ b/libqpdf/Pl_PNGFilter.cc
@@ -29,36 +29,28 @@ Pl_PNGFilter::Pl_PNGFilter(
pos(0)
{
if (samples_per_pixel < 1) {
- throw std::runtime_error(
- "PNGFilter created with invalid samples_per_pixel");
+ throw std::runtime_error("PNGFilter created with invalid samples_per_pixel");
}
- if (!((bits_per_sample == 1) || (bits_per_sample == 2) ||
- (bits_per_sample == 4) || (bits_per_sample == 8) ||
- (bits_per_sample == 16))) {
- throw std::runtime_error(
- "PNGFilter created with invalid bits_per_sample not"
- " 1, 2, 4, 8, or 16");
+ if (!((bits_per_sample == 1) || (bits_per_sample == 2) || (bits_per_sample == 4) ||
+ (bits_per_sample == 8) || (bits_per_sample == 16))) {
+ throw std::runtime_error("PNGFilter created with invalid bits_per_sample not"
+ " 1, 2, 4, 8, or 16");
}
this->bytes_per_pixel = ((bits_per_sample * samples_per_pixel) + 7) / 8;
- unsigned long long bpr =
- ((columns * bits_per_sample * samples_per_pixel) + 7) / 8;
+ unsigned long long bpr = ((columns * bits_per_sample * samples_per_pixel) + 7) / 8;
if ((bpr == 0) || (bpr > (UINT_MAX - 1))) {
- throw std::runtime_error(
- "PNGFilter created with invalid columns value");
+ throw std::runtime_error("PNGFilter created with invalid columns value");
}
this->bytes_per_row = bpr & UINT_MAX;
- this->buf1 =
- QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1);
- this->buf2 =
- QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1);
+ this->buf1 = QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1);
+ this->buf2 = QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1);
memset(this->buf1.get(), 0, this->bytes_per_row + 1);
memset(this->buf2.get(), 0, this->bytes_per_row + 1);
this->cur_row = this->buf1.get();
this->prev_row = this->buf2.get();
// number of bytes per incoming row
- this->incoming =
- (action == a_encode ? this->bytes_per_row : this->bytes_per_row + 1);
+ this->incoming = (action == a_encode ? this->bytes_per_row : this->bytes_per_row + 1);
}
void
@@ -197,8 +189,8 @@ Pl_PNGFilter::decodePaeth()
upper_left = above_buffer[i - bpp];
}
- buffer[i] = static_cast<unsigned char>(
- buffer[i] + this->PaethPredictor(left, up, upper_left));
+ buffer[i] =
+ static_cast<unsigned char>(buffer[i] + this->PaethPredictor(left, up, upper_left));
}
}
@@ -227,8 +219,7 @@ Pl_PNGFilter::encodeRow()
getNext()->write(&ch, 1);
if (this->prev_row) {
for (unsigned int i = 0; i < this->bytes_per_row; ++i) {
- ch = static_cast<unsigned char>(
- this->cur_row[i] - this->prev_row[i]);
+ ch = static_cast<unsigned char>(this->cur_row[i] - this->prev_row[i]);
getNext()->write(&ch, 1);
}
} else {
diff --git a/libqpdf/Pl_QPDFTokenizer.cc b/libqpdf/Pl_QPDFTokenizer.cc
index 34edd8fb..f2612e85 100644
--- a/libqpdf/Pl_QPDFTokenizer.cc
+++ b/libqpdf/Pl_QPDFTokenizer.cc
@@ -11,15 +11,12 @@ Pl_QPDFTokenizer::Members::Members() :
}
Pl_QPDFTokenizer::Pl_QPDFTokenizer(
- char const* identifier,
- QPDFObjectHandle::TokenFilter* filter,
- Pipeline* next) :
+ char const* identifier, QPDFObjectHandle::TokenFilter* filter, Pipeline* next) :
Pipeline(identifier, next),
m(new Members)
{
m->filter = filter;
- QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(
- m->filter, next);
+ QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(m->filter, next);
m->tokenizer.allowEOF();
m->tokenizer.includeIgnorable();
}
@@ -45,8 +42,8 @@ Pl_QPDFTokenizer::finish()
new BufferInputSource("tokenizer data", m->buf.getBuffer(), true));
while (true) {
- QPDFTokenizer::Token token = m->tokenizer.readToken(
- input, "offset " + std::to_string(input->tell()), true);
+ QPDFTokenizer::Token token =
+ m->tokenizer.readToken(input, "offset " + std::to_string(input->tell()), true);
m->filter->handleToken(token);
if (token.getType() == QPDFTokenizer::tt_eof) {
break;
@@ -56,15 +53,13 @@ Pl_QPDFTokenizer::finish()
input->read(&ch, 1);
m->filter->handleToken(
// line-break
- QPDFTokenizer::Token(
- QPDFTokenizer::tt_space, std::string(1, ch)));
+ QPDFTokenizer::Token(QPDFTokenizer::tt_space, std::string(1, ch)));
QTC::TC("qpdf", "Pl_QPDFTokenizer found ID");
m->tokenizer.expectInlineImage(input);
}
}
m->filter->handleEOF();
- QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(
- m->filter, nullptr);
+ QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(m->filter, nullptr);
Pipeline* next = this->getNext(true);
if (next) {
next->finish();
diff --git a/libqpdf/Pl_RC4.cc b/libqpdf/Pl_RC4.cc
index ba0cb201..a244152b 100644
--- a/libqpdf/Pl_RC4.cc
+++ b/libqpdf/Pl_RC4.cc
@@ -19,17 +19,14 @@ void
Pl_RC4::write(unsigned char const* data, size_t len)
{
if (this->outbuf == nullptr) {
- throw std::logic_error(
- this->identifier +
- ": Pl_RC4: write() called after finish() called");
+ throw std::logic_error(this->identifier + ": Pl_RC4: write() called after finish() called");
}
size_t bytes_left = len;
unsigned char const* p = data;
while (bytes_left > 0) {
- size_t bytes =
- (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
+ size_t bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
bytes_left -= bytes;
// lgtm[cpp/weak-cryptographic-algorithm]
rc4.process(p, bytes, outbuf.get());
diff --git a/libqpdf/Pl_RunLength.cc b/libqpdf/Pl_RunLength.cc
index f47e45e1..d9e6799a 100644
--- a/libqpdf/Pl_RunLength.cc
+++ b/libqpdf/Pl_RunLength.cc
@@ -10,8 +10,7 @@ Pl_RunLength::Members::Members(action_e action) :
{
}
-Pl_RunLength::Pl_RunLength(
- char const* identifier, Pipeline* next, action_e action) :
+Pl_RunLength::Pl_RunLength(char const* identifier, Pipeline* next, action_e action) :
Pipeline(identifier, next),
m(new Members(action))
{
@@ -38,17 +37,12 @@ Pl_RunLength::encode(unsigned char const* data, size_t len)
{
for (size_t i = 0; i < len; ++i) {
if ((m->state == st_top) != (m->length <= 1)) {
- throw std::logic_error(
- "Pl_RunLength::encode: state/length inconsistency");
+ throw std::logic_error("Pl_RunLength::encode: state/length inconsistency");
}
unsigned char ch = data[i];
- if ((m->length > 0) &&
- ((m->state == st_copying) || (m->length < 128)) &&
+ if ((m->length > 0) && ((m->state == st_copying) || (m->length < 128)) &&
(ch == m->buf[m->length - 1])) {
- QTC::TC(
- "libtests",
- "Pl_RunLength: switch to run",
- (m->length == 128) ? 0 : 1);
+ QTC::TC("libtests", "Pl_RunLength: switch to run", (m->length == 128) ? 0 : 1);
if (m->state == st_copying) {
--m->length;
flush_encode();
@@ -124,8 +118,7 @@ Pl_RunLength::flush_encode()
}
if (m->state == st_run) {
if ((m->length < 2) || (m->length > 128)) {
- throw std::logic_error(
- "Pl_RunLength: invalid length in flush_encode for run");
+ throw std::logic_error("Pl_RunLength: invalid length in flush_encode for run");
}
auto ch = static_cast<unsigned char>(257 - m->length);
this->getNext()->write(&ch, 1);
diff --git a/libqpdf/Pl_SHA2.cc b/libqpdf/Pl_SHA2.cc
index 852e5db7..f431ff7d 100644
--- a/libqpdf/Pl_SHA2.cc
+++ b/libqpdf/Pl_SHA2.cc
@@ -51,8 +51,7 @@ void
Pl_SHA2::resetBits(int bits)
{
if (this->in_progress) {
- throw std::logic_error(
- "bit reset requested for in-progress SHA2 Pipeline");
+ throw std::logic_error("bit reset requested for in-progress SHA2 Pipeline");
}
this->crypto = QPDFCryptoProvider::getImpl();
this->crypto->SHA2_init(bits);
@@ -62,8 +61,7 @@ std::string
Pl_SHA2::getRawDigest()
{
if (this->in_progress) {
- throw std::logic_error(
- "digest requested for in-progress SHA2 Pipeline");
+ throw std::logic_error("digest requested for in-progress SHA2 Pipeline");
}
return this->crypto->SHA2_digest();
}
@@ -72,8 +70,7 @@ std::string
Pl_SHA2::getHexDigest()
{
if (this->in_progress) {
- throw std::logic_error(
- "digest requested for in-progress SHA2 Pipeline");
+ throw std::logic_error("digest requested for in-progress SHA2 Pipeline");
}
return QUtil::hex_encode(getRawDigest());
}
diff --git a/libqpdf/Pl_StdioFile.cc b/libqpdf/Pl_StdioFile.cc
index 26dd7ace..918aacde 100644
--- a/libqpdf/Pl_StdioFile.cc
+++ b/libqpdf/Pl_StdioFile.cc
@@ -30,8 +30,7 @@ Pl_StdioFile::write(unsigned char const* buf, size_t len)
while (len > 0) {
so_far = fwrite(buf, 1, len, m->file);
if (so_far == 0) {
- QUtil::throw_system_error(
- this->identifier + ": Pl_StdioFile::write");
+ QUtil::throw_system_error(this->identifier + ": Pl_StdioFile::write");
} else {
buf += so_far;
len -= so_far;
@@ -43,7 +42,6 @@ void
Pl_StdioFile::finish()
{
if ((fflush(m->file) == -1) && (errno == EBADF)) {
- throw std::logic_error(
- this->identifier + ": Pl_StdioFile::finish: stream already closed");
+ throw std::logic_error(this->identifier + ": Pl_StdioFile::finish: stream already closed");
}
}
diff --git a/libqpdf/Pl_TIFFPredictor.cc b/libqpdf/Pl_TIFFPredictor.cc
index ad620f62..51594d11 100644
--- a/libqpdf/Pl_TIFFPredictor.cc
+++ b/libqpdf/Pl_TIFFPredictor.cc
@@ -25,23 +25,17 @@ Pl_TIFFPredictor::Pl_TIFFPredictor(
pos(0)
{
if (samples_per_pixel < 1) {
- throw std::runtime_error(
- "TIFFPredictor created with invalid samples_per_pixel");
+ throw std::runtime_error("TIFFPredictor created with invalid samples_per_pixel");
}
- if ((bits_per_sample < 1) ||
- (bits_per_sample > (8 * (sizeof(unsigned long long))))) {
- throw std::runtime_error(
- "TIFFPredictor created with invalid bits_per_sample");
+ if ((bits_per_sample < 1) || (bits_per_sample > (8 * (sizeof(unsigned long long))))) {
+ throw std::runtime_error("TIFFPredictor created with invalid bits_per_sample");
}
- unsigned long long bpr =
- ((columns * bits_per_sample * samples_per_pixel) + 7) / 8;
+ unsigned long long bpr = ((columns * bits_per_sample * samples_per_pixel) + 7) / 8;
if ((bpr == 0) || (bpr > (UINT_MAX - 1))) {
- throw std::runtime_error(
- "TIFFPredictor created with invalid columns value");
+ throw std::runtime_error("TIFFPredictor created with invalid columns value");
}
this->bytes_per_row = bpr & UINT_MAX;
- this->cur_row =
- QUtil::make_shared_array<unsigned char>(this->bytes_per_row);
+ this->cur_row = QUtil::make_shared_array<unsigned char>(this->bytes_per_row);
memset(this->cur_row.get(), 0, this->bytes_per_row);
}
@@ -72,10 +66,7 @@ Pl_TIFFPredictor::write(unsigned char const* data, size_t len)
void
Pl_TIFFPredictor::processRow()
{
- QTC::TC(
- "libtests",
- "Pl_TIFFPredictor processRow",
- (action == a_decode ? 0 : 1));
+ QTC::TC("libtests", "Pl_TIFFPredictor processRow", (action == a_decode ? 0 : 1));
BitWriter bw(this->getNext());
BitStream in(this->cur_row.get(), this->bytes_per_row);
std::vector<long long> prev;
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index fba5380a..806a8cb2 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -105,11 +105,10 @@ namespace
void
throwException()
{
- throw std::logic_error(
- "QPDF operation attempted on a QPDF object with no input "
- "source."
- " QPDF operations are invalid before processFile (or another"
- " process method) or after closeInputSource");
+ throw std::logic_error("QPDF operation attempted on a QPDF object with no input "
+ "source."
+ " QPDF operations are invalid before processFile (or another"
+ " process method) or after closeInputSource");
}
};
} // namespace
@@ -130,8 +129,7 @@ QPDF::ForeignStreamData::ForeignStreamData(
{
}
-QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider(
- QPDF& destination_qpdf) :
+QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider(QPDF& destination_qpdf) :
QPDFObjectHandle::StreamDataProvider(true),
destination_qpdf(destination_qpdf)
{
@@ -139,10 +137,7 @@ QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider(
bool
QPDF::CopiedStreamDataProvider::provideStreamData(
- QPDFObjGen const& og,
- Pipeline* pipeline,
- bool suppress_warnings,
- bool will_retry)
+ QPDFObjGen const& og, Pipeline* pipeline, bool suppress_warnings, bool will_retry)
{
std::shared_ptr<ForeignStreamData> foreign_data = foreign_stream_data[og];
bool result = false;
@@ -154,8 +149,7 @@ QPDF::CopiedStreamDataProvider::provideStreamData(
auto foreign_stream = foreign_streams[og];
result = foreign_stream.pipeStreamData(
pipeline, nullptr, 0, qpdf_dl_none, suppress_warnings, will_retry);
- QTC::TC(
- "qpdf", "QPDF copy foreign with foreign_stream", result ? 0 : 1);
+ QTC::TC("qpdf", "QPDF copy foreign with foreign_stream", result ? 0 : 1);
}
return result;
}
@@ -169,8 +163,7 @@ QPDF::CopiedStreamDataProvider::registerForeignStream(
void
QPDF::CopiedStreamDataProvider::registerForeignStream(
- QPDFObjGen const& local_og,
- std::shared_ptr<ForeignStreamData> foreign_stream)
+ QPDFObjGen const& local_og, std::shared_ptr<ForeignStreamData> foreign_stream)
{
this->foreign_stream_data[local_og] = foreign_stream;
}
@@ -269,8 +262,7 @@ QPDF::processFile(char const* filename, char const* password)
}
void
-QPDF::processFile(
- char const* description, FILE* filep, bool close_file, char const* password)
+QPDF::processFile(char const* description, FILE* filep, bool close_file, char const* password)
{
auto* fi = new FileInputSource(description, filep, close_file);
processInputSource(std::shared_ptr<InputSource>(fi), password);
@@ -278,24 +270,18 @@ QPDF::processFile(
void
QPDF::processMemoryFile(
- char const* description,
- char const* buf,
- size_t length,
- char const* password)
+ char const* description, char const* buf, size_t length, char const* password)
{
processInputSource(
std::shared_ptr<InputSource>(
// line-break
new BufferInputSource(
- description,
- new Buffer(QUtil::unsigned_char_pointer(buf), length),
- true)),
+ description, new Buffer(QUtil::unsigned_char_pointer(buf), length), true)),
password);
}
void
-QPDF::processInputSource(
- std::shared_ptr<InputSource> source, char const* password)
+QPDF::processInputSource(std::shared_ptr<InputSource> source, char const* password)
{
m->file = source;
parse(password);
@@ -321,8 +307,7 @@ QPDF::emptyPDF()
void
QPDF::registerStreamFilter(
- std::string const& filter_name,
- std::function<std::shared_ptr<QPDFStreamFilter>()> factory)
+ std::string const& filter_name, std::function<std::shared_ptr<QPDFStreamFilter>()> factory)
{
QPDF_Stream::registerStreamFilter(filter_name, factory);
}
@@ -434,8 +419,7 @@ QPDF::findHeader()
// offsets in the file are such that 0 points to the
// beginning of the header.
QTC::TC("qpdf", "QPDF global offset");
- m->file = std::shared_ptr<InputSource>(
- new OffsetInputSource(m->file, global_offset));
+ m->file = std::shared_ptr<InputSource>(new OffsetInputSource(m->file, global_offset));
}
}
return valid;
@@ -444,8 +428,7 @@ QPDF::findHeader()
bool
QPDF::findStartxref()
{
- if (readToken(m->file).isWord("startxref") &&
- readToken(m->file).isInteger()) {
+ if (readToken(m->file).isWord("startxref") && readToken(m->file).isInteger()) {
// Position in front of offset token
m->file->seek(m->file->getLastOffset(), SEEK_SET);
return true;
@@ -479,8 +462,7 @@ QPDF::parse(char const* password)
PatternFinder sf(*this, &QPDF::findStartxref);
qpdf_offset_t xref_offset = 0;
if (m->file->findLast("startxref", start_offset, 0, sf)) {
- xref_offset =
- QUtil::string_to_ll(readToken(m->file).getValue().c_str());
+ xref_offset = QUtil::string_to_ll(readToken(m->file).getValue().c_str());
}
try {
@@ -493,8 +475,7 @@ QPDF::parse(char const* password)
} catch (QPDFExc&) {
throw;
} catch (std::exception& e) {
- throw damagedPDF(
- "", 0, std::string("error reading xref: ") + e.what());
+ throw damagedPDF("", 0, std::string("error reading xref: ") + e.what());
}
} catch (QPDFExc& e) {
if (m->attempt_recovery) {
@@ -515,9 +496,8 @@ QPDF::inParse(bool v)
if (m->in_parse == v) {
// This happens if QPDFParser::parse tries to
// resolve an indirect object while it is parsing.
- throw std::logic_error(
- "QPDF: re-entrant parsing detected. This is a qpdf bug."
- " Please report at https://github.com/qpdf/qpdf/issues.");
+ throw std::logic_error("QPDF: re-entrant parsing detected. This is a qpdf bug."
+ " Please report at https://github.com/qpdf/qpdf/issues.");
}
m->in_parse = v;
}
@@ -590,22 +570,19 @@ QPDF::reconstruct_xref(QPDFExc& e)
qpdf_offset_t next_line_start = m->file->tell();
m->file->seek(line_start, SEEK_SET);
QPDFTokenizer::Token t1 = readToken(m->file, MAX_LEN);
- qpdf_offset_t token_start =
- m->file->tell() - toO(t1.getValue().length());
+ qpdf_offset_t token_start = m->file->tell() - toO(t1.getValue().length());
if (token_start >= next_line_start) {
// don't process yet -- wait until we get to the line
// containing this token
} else if (t1.isInteger()) {
QPDFTokenizer::Token t2 = readToken(m->file, MAX_LEN);
- if ((t2.isInteger()) &&
- (readToken(m->file, MAX_LEN).isWord("obj"))) {
+ if ((t2.isInteger()) && (readToken(m->file, MAX_LEN).isWord("obj"))) {
int obj = QUtil::string_to_int(t1.getValue().c_str());
int gen = QUtil::string_to_int(t2.getValue().c_str());
insertXrefEntry(obj, 1, token_start, gen, true);
}
} else if (!m->trailer.isInitialized() && t1.isWord("trailer")) {
- QPDFObjectHandle t =
- readObject(m->file, "trailer", QPDFObjGen(), false);
+ QPDFObjectHandle t = readObject(m->file, "trailer", QPDFObjGen(), false);
if (!t.isDictionary()) {
// Oh well. It was worth a try.
} else {
@@ -623,10 +600,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
// with bad startxref pointers even when they have object
// streams.
- throw damagedPDF(
- "",
- 0,
- "unable to find trailer dictionary while recovering damaged file");
+ throw damagedPDF("", 0, "unable to find trailer dictionary while recovering damaged file");
}
// We could iterate through the objects looking for streams and
@@ -666,10 +640,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
done = true;
}
} else {
- QTC::TC(
- "qpdf",
- "QPDF eof skipping spaces before xref",
- skipped_space ? 0 : 1);
+ QTC::TC("qpdf", "QPDF eof skipping spaces before xref", skipped_space ? 0 : 1);
done = true;
}
}
@@ -681,8 +652,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
if ((strncmp(buf, "xref", 4) == 0) && QUtil::is_space(buf[4])) {
if (skipped_space) {
QTC::TC("qpdf", "QPDF xref skipped space");
- warn(damagedPDF(
- "", 0, "extraneous whitespace seen before xref"));
+ warn(damagedPDF("", 0, "extraneous whitespace seen before xref"));
}
QTC::TC(
"qpdf",
@@ -724,8 +694,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
"",
0,
("reported number of objects (" + std::to_string(size) +
- ") is not one plus the highest object number (" +
- std::to_string(max_obj) + ")")));
+ ") is not one plus the highest object number (" + std::to_string(max_obj) + ")")));
}
// We no longer need the deleted_objects table, so go ahead and
@@ -782,8 +751,7 @@ QPDF::parse_xrefFirst(std::string const& line, int& obj, int& num, int& bytes)
}
bool
-QPDF::parse_xrefEntry(
- std::string const& line, qpdf_offset_t& f1, int& f2, char& type)
+QPDF::parse_xrefEntry(std::string const& line, qpdf_offset_t& f1, int& f2, char& type)
{
// is_space and is_digit both return false on '\0', so this will
// not overrun the null-terminated buffer.
@@ -891,8 +859,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
if (!parse_xrefEntry(xref_entry, f1, f2, type)) {
QTC::TC("qpdf", "QPDF invalid xref entry");
throw damagedPDF(
- "xref table",
- "invalid xref entry (obj=" + std::to_string(i) + ")");
+ "xref table", "invalid xref entry (obj=" + std::to_string(i) + ")");
}
if (type == 'f') {
// Save deleted items until after we've checked the
@@ -911,8 +878,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
}
// Set offset to previous xref table if any
- QPDFObjectHandle cur_trailer =
- readObject(m->file, "trailer", QPDFObjGen(), false);
+ QPDFObjectHandle cur_trailer = readObject(m->file, "trailer", QPDFObjGen(), false);
if (!cur_trailer.isDictionary()) {
QTC::TC("qpdf", "QPDF missing trailer");
throw damagedPDF("", "expected trailer dictionary");
@@ -927,8 +893,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
}
if (!m->trailer.getKey("/Size").isInteger()) {
QTC::TC("qpdf", "QPDF trailer size not integer");
- throw damagedPDF(
- "trailer", "/Size key in trailer dictionary is not an integer");
+ throw damagedPDF("trailer", "/Size key in trailer dictionary is not an integer");
}
}
@@ -940,11 +905,9 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
// Read the xref stream but disregard any return value
// -- we'll use our trailer's /Prev key instead of the
// xref stream's.
- (void)read_xrefStream(
- cur_trailer.getKey("/XRefStm").getIntValue());
+ (void)read_xrefStream(cur_trailer.getKey("/XRefStm").getIntValue());
} else {
- throw damagedPDF(
- "xref stream", xref_offset, "invalid /XRefStm");
+ throw damagedPDF("xref stream", xref_offset, "invalid /XRefStm");
}
}
}
@@ -957,8 +920,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
if (cur_trailer.hasKey("/Prev")) {
if (!cur_trailer.getKey("/Prev").isInteger()) {
QTC::TC("qpdf", "QPDF trailer prev not integer");
- throw damagedPDF(
- "trailer", "/Prev key in trailer dictionary is not an integer");
+ throw damagedPDF("trailer", "/Prev key in trailer dictionary is not an integer");
}
QTC::TC("qpdf", "QPDF prev key in trailer dictionary");
xref_offset = cur_trailer.getKey("/Prev").getIntValue();
@@ -977,13 +939,8 @@ QPDF::read_xrefStream(qpdf_offset_t xref_offset)
QPDFObjGen x_og;
QPDFObjectHandle xref_obj;
try {
- xref_obj = readObjectAtOffset(
- false,
- xref_offset,
- "xref stream",
- QPDFObjGen(0, 0),
- x_og,
- true);
+ xref_obj =
+ readObjectAtOffset(false, xref_offset, "xref stream", QPDFObjGen(0, 0), x_og, true);
} catch (QPDFExc&) {
// ignore -- report error below
}
@@ -1008,12 +965,9 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
QPDFObjectHandle dict = xref_obj.getDict();
QPDFObjectHandle W_obj = dict.getKey("/W");
QPDFObjectHandle Index_obj = dict.getKey("/Index");
- if (!(W_obj.isArray() && (W_obj.getArrayNItems() >= 3) &&
- W_obj.getArrayItem(0).isInteger() &&
- W_obj.getArrayItem(1).isInteger() &&
- W_obj.getArrayItem(2).isInteger() &&
- dict.getKey("/Size").isInteger() &&
- (Index_obj.isArray() || Index_obj.isNull()))) {
+ if (!(W_obj.isArray() && (W_obj.getArrayNItems() >= 3) && W_obj.getArrayItem(0).isInteger() &&
+ W_obj.getArrayItem(1).isInteger() && W_obj.getArrayItem(2).isInteger() &&
+ dict.getKey("/Size").isInteger() && (Index_obj.isArray() || Index_obj.isNull()))) {
throw damagedPDF(
"xref stream",
xref_offset,
@@ -1035,12 +989,9 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
}
if (entry_size == 0) {
throw damagedPDF(
- "xref stream",
- xref_offset,
- "Cross-reference stream's /W indicates entry size of 0");
+ "xref stream", xref_offset, "Cross-reference stream's /W indicates entry size of 0");
}
- unsigned long long max_num_entries =
- static_cast<unsigned long long>(-1) / entry_size;
+ unsigned long long max_num_entries = static_cast<unsigned long long>(-1) / entry_size;
std::vector<long long> indx;
if (Index_obj.isArray()) {
@@ -1059,8 +1010,8 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
throw damagedPDF(
"xref stream",
xref_offset,
- ("Cross-reference stream's /Index's item " +
- std::to_string(i) + " is not an integer"));
+ ("Cross-reference stream's /Index's item " + std::to_string(i) +
+ " is not an integer"));
}
}
QTC::TC("qpdf", "QPDF xref /Index is array", n_index == 2 ? 0 : 1);
@@ -1078,8 +1029,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
"xref stream",
xref_offset,
("Cross-reference stream claims to contain too many entries: " +
- std::to_string(indx.at(i)) + " " +
- std::to_string(max_num_entries) + " " +
+ std::to_string(indx.at(i)) + " " + std::to_string(max_num_entries) + " " +
std::to_string(num_entries)));
}
num_entries += toS(indx.at(i));
@@ -1097,8 +1047,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
"xref stream",
xref_offset,
("Cross-reference stream data has the wrong size; expected = " +
- std::to_string(expected_size) +
- "; actual = " + std::to_string(actual_size)));
+ std::to_string(expected_size) + "; actual = " + std::to_string(actual_size)));
if (expected_size > actual_size) {
throw x;
} else {
@@ -1137,8 +1086,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
// an uncompressed object record, in which case the generation
// number appears as the third field.
int obj = toI(indx.at(cur_chunk));
- if ((obj < 0) ||
- ((std::numeric_limits<int>::max() - obj) < chunk_count)) {
+ if ((obj < 0) || ((std::numeric_limits<int>::max() - obj) < chunk_count)) {
std::ostringstream msg;
msg.imbue(std::locale::classic());
msg << "adding " << chunk_count << " to " << obj
@@ -1181,8 +1129,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
if (dict.hasKey("/Prev")) {
if (!dict.getKey("/Prev").isInteger()) {
throw damagedPDF(
- "xref stream",
- "/Prev key in xref stream dictionary is not an integer");
+ "xref stream", "/Prev key in xref stream dictionary is not an integer");
}
QTC::TC("qpdf", "QPDF prev key in xref stream dictionary");
xref_offset = dict.getKey("/Prev").getIntValue();
@@ -1241,9 +1188,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite)
break;
default:
- throw damagedPDF(
- "xref stream",
- "unknown xref stream entry type " + std::to_string(f0));
+ throw damagedPDF("xref stream", "unknown xref stream entry type " + std::to_string(f0));
break;
}
}
@@ -1262,9 +1207,8 @@ QPDF::showXRefTable()
break;
case 2:
- *m->log->getInfo()
- << "compressed; stream = " << entry.getObjStreamNumber()
- << ", index = " << entry.getObjStreamIndex();
+ *m->log->getInfo() << "compressed; stream = " << entry.getObjStreamNumber()
+ << ", index = " << entry.getObjStreamIndex();
break;
default:
@@ -1337,8 +1281,7 @@ QPDF::getAllObjects()
}
void
-QPDF::setLastObjectDescription(
- std::string const& description, QPDFObjGen const& og)
+QPDF::setLastObjectDescription(std::string const& description, QPDFObjGen const& og)
{
m->last_object_description.clear();
if (!description.empty()) {
@@ -1369,16 +1312,13 @@ QPDF::readObject(
decrypter_ph = std::make_shared<StringDecrypter>(this, og);
decrypter = decrypter_ph.get();
}
- auto object =
- QPDFParser(
- input, m->last_object_description, m->tokenizer, decrypter, this)
- .parse(empty, false);
+ auto object = QPDFParser(input, m->last_object_description, m->tokenizer, decrypter, this)
+ .parse(empty, false);
if (empty) {
// Nothing in the PDF spec appears to allow empty objects, but
// they have been encountered in actual PDF files and Adobe
// Reader appears to ignore them.
- warn(damagedPDF(
- input, input->getLastOffset(), "empty object treated as null"));
+ warn(damagedPDF(input, input->getLastOffset(), "empty object treated as null"));
} else if (object.isDictionary() && (!in_object_stream)) {
// check for stream
qpdf_offset_t cur_offset = input->tell();
@@ -1428,9 +1368,7 @@ QPDF::readObject(
}
} else if (QUtil::is_space(ch)) {
warn(damagedPDF(
- input,
- input->tell(),
- "stream keyword followed by extraneous whitespace"));
+ input, input->tell(), "stream keyword followed by extraneous whitespace"));
done = false;
} else {
QTC::TC("qpdf", "QPDF stream without newline");
@@ -1450,13 +1388,11 @@ QPDF::readObject(
size_t length = 0;
try {
- std::map<std::string, QPDFObjectHandle> dict =
- object.getDictAsMap();
+ std::map<std::string, QPDFObjectHandle> dict = object.getDictAsMap();
if (dict.count("/Length") == 0) {
QTC::TC("qpdf", "QPDF stream without length");
- throw damagedPDF(
- input, offset, "stream dictionary lacks /Length key");
+ throw damagedPDF(input, offset, "stream dictionary lacks /Length key");
}
QPDFObjectHandle length_obj = dict["/Length"];
@@ -1475,8 +1411,7 @@ QPDF::readObject(
input->seek(toO(length), SEEK_CUR);
if (!readToken(input).isWord("endstream")) {
QTC::TC("qpdf", "QPDF missing endstream");
- throw damagedPDF(
- input, input->getLastOffset(), "expected endstream");
+ throw damagedPDF(input, input->getLastOffset(), "expected endstream");
}
} catch (QPDFExc& e) {
if (m->attempt_recovery) {
@@ -1486,9 +1421,7 @@ QPDF::readObject(
throw;
}
}
- object = newIndirect(
- og,
- QPDF_Stream::create(this, og, object, stream_offset, length));
+ object = newIndirect(og, QPDF_Stream::create(this, og, object, stream_offset, length));
} else {
input->seek(cur_offset, SEEK_SET);
}
@@ -1514,14 +1447,11 @@ QPDF::findEndstream()
size_t
QPDF::recoverStreamLength(
- std::shared_ptr<InputSource> input,
- QPDFObjGen const& og,
- qpdf_offset_t stream_offset)
+ std::shared_ptr<InputSource> input, QPDFObjGen const& og, qpdf_offset_t stream_offset)
{
// Try to reconstruct stream length by looking for
// endstream or endobj
- warn(damagedPDF(
- input, stream_offset, "attempting to recover stream length"));
+ warn(damagedPDF(input, stream_offset, "attempting to recover stream length"));
PatternFinder ef(*this, &QPDF::findEndstream);
size_t length = 0;
@@ -1544,8 +1474,7 @@ QPDF::recoverStreamLength(
if (entry.getType() == 1) {
qpdf_offset_t obj_offset = entry.getOffset();
if ((obj_offset > stream_offset) &&
- ((this_obj_offset == 0) ||
- (this_obj_offset > obj_offset))) {
+ ((this_obj_offset == 0) || (this_obj_offset > obj_offset))) {
this_obj_offset = obj_offset;
this_og = iter.first;
}
@@ -1562,14 +1491,10 @@ QPDF::recoverStreamLength(
if (length == 0) {
warn(damagedPDF(
- input,
- stream_offset,
- "unable to recover stream data; treating stream as empty"));
+ input, stream_offset, "unable to recover stream data; treating stream as empty"));
} else {
- warn(damagedPDF(
- input,
- stream_offset,
- "recovered stream length: " + std::to_string(length)));
+ warn(
+ damagedPDF(input, stream_offset, "recovered stream length: " + std::to_string(length)));
}
QTC::TC("qpdf", "QPDF recovered stream length");
@@ -1579,8 +1504,7 @@ QPDF::recoverStreamLength(
QPDFTokenizer::Token
QPDF::readToken(std::shared_ptr<InputSource> input, size_t max_len)
{
- return m->tokenizer.readToken(
- input, m->last_object_description, true, max_len);
+ return m->tokenizer.readToken(input, m->last_object_description, true, max_len);
}
QPDFObjectHandle
@@ -1650,8 +1574,7 @@ QPDF::readObjectAtOffset(
}
if (check_og && (exp_og != og)) {
QTC::TC("qpdf", "QPDF err wrong objid/generation");
- QPDFExc e =
- damagedPDF(offset, "expected " + exp_og.unparse(' ') + " obj");
+ QPDFExc e = damagedPDF(offset, "expected " + exp_og.unparse(' ') + " obj");
if (try_recovery) {
// Will be retried below
throw e;
@@ -1665,11 +1588,10 @@ QPDF::readObjectAtOffset(
if (try_recovery) {
// Try again after reconstructing xref table
reconstruct_xref(e);
- if (m->xref_table.count(exp_og) &&
- (m->xref_table[exp_og].getType() == 1)) {
+ if (m->xref_table.count(exp_og) && (m->xref_table[exp_og].getType() == 1)) {
qpdf_offset_t new_offset = m->xref_table[exp_og].getOffset();
- QPDFObjectHandle result = readObjectAtOffset(
- false, new_offset, description, exp_og, og, false);
+ QPDFObjectHandle result =
+ readObjectAtOffset(false, new_offset, description, exp_og, og, false);
QTC::TC("qpdf", "QPDF recovered in readObjectAtOffset");
return result;
} else {
@@ -1777,8 +1699,7 @@ QPDF::resolve(QPDFObjGen og)
// indirectly in some key that has to be resolved during
// object parsing, such as stream length.
QTC::TC("qpdf", "QPDF recursion loop in resolve");
- warn(damagedPDF(
- "", "loop detected resolving object " + og.unparse(' ')));
+ warn(damagedPDF("", "loop detected resolving object " + og.unparse(' ')));
updateCache(og, QPDF_Null::create(), -1, -1);
return;
}
@@ -1793,8 +1714,7 @@ QPDF::resolve(QPDFObjGen og)
qpdf_offset_t offset = entry.getOffset();
// Object stored in cache by readObjectAtOffset
QPDFObjGen a_og;
- QPDFObjectHandle oh =
- readObjectAtOffset(true, offset, "", og, a_og, false);
+ QPDFObjectHandle oh = readObjectAtOffset(true, offset, "", og, a_og, false);
}
break;
@@ -1804,19 +1724,13 @@ QPDF::resolve(QPDFObjGen og)
default:
throw damagedPDF(
- "",
- 0,
- ("object " + og.unparse('/') +
- " has unexpected xref entry type"));
+ "", 0, ("object " + og.unparse('/') + " has unexpected xref entry type"));
}
} catch (QPDFExc& e) {
warn(e);
} catch (std::exception& e) {
warn(damagedPDF(
- "",
- 0,
- ("object " + og.unparse('/') +
- ": error reading object: " + e.what())));
+ "", 0, ("object " + og.unparse('/') + ": error reading object: " + e.what())));
}
}
@@ -1841,8 +1755,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
QPDFObjectHandle obj_stream = getObjectByID(obj_stream_number, 0);
if (!obj_stream.isStream()) {
throw damagedPDF(
- "supposed object stream " + std::to_string(obj_stream_number) +
- " is not a stream");
+ "supposed object stream " + std::to_string(obj_stream_number) + " is not a stream");
}
// For linearization data in the object, use the data from the
@@ -1855,14 +1768,12 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
if (!dict.isDictionaryOfType("/ObjStm")) {
QTC::TC("qpdf", "QPDF ERR object stream with wrong type");
warn(damagedPDF(
- "supposed object stream " + std::to_string(obj_stream_number) +
- " has wrong type"));
+ "supposed object stream " + std::to_string(obj_stream_number) + " has wrong type"));
}
if (!(dict.getKey("/N").isInteger() && dict.getKey("/First").isInteger())) {
throw damagedPDF(
- ("object stream " + std::to_string(obj_stream_number) +
- " has incorrect keys"));
+ ("object stream " + std::to_string(obj_stream_number) + " has incorrect keys"));
}
int n = dict.getKey("/N").getIntValueAsInt();
@@ -1874,8 +1785,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
auto input = std::shared_ptr<InputSource>(
// line-break
new BufferInputSource(
- (m->file->getName() + " object stream " +
- std::to_string(obj_stream_number)),
+ (m->file->getName() + " object stream " + std::to_string(obj_stream_number)),
bp.get()));
for (int i = 0; i < n; ++i) {
@@ -1902,8 +1812,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
for (auto const& iter: offsets) {
QPDFObjGen og(iter.first, 0);
QPDFXRefEntry const& entry = m->xref_table[og];
- if ((entry.getType() == 2) &&
- (entry.getObjStreamNumber() == obj_stream_number)) {
+ if ((entry.getType() == 2) && (entry.getObjStreamNumber() == obj_stream_number)) {
int offset = iter.second;
input->seek(offset, SEEK_SET);
QPDFObjectHandle oh = readObject(input, "", og, true);
@@ -1956,8 +1865,7 @@ QPDF::nextObjGen()
{
int max_objid = toI(getObjectCount());
if (max_objid == std::numeric_limits<int>::max()) {
- throw std::range_error(
- "max object id is too high to create new objects");
+ throw std::range_error("max object id is too high to create new objects");
}
return QPDFObjGen(max_objid + 1, 0);
}
@@ -1974,8 +1882,7 @@ QPDFObjectHandle
QPDF::makeIndirectObject(QPDFObjectHandle oh)
{
if (!oh.isInitialized()) {
- throw std::logic_error(
- "attempted to make an uninitialized QPDFObjectHandle indirect");
+ throw std::logic_error("attempted to make an uninitialized QPDFObjectHandle indirect");
}
return makeIndirectFromQPDFObject(oh.getObj());
}
@@ -1989,16 +1896,15 @@ QPDF::newReserved()
QPDFObjectHandle
QPDF::newStream()
{
- return makeIndirectFromQPDFObject(QPDF_Stream::create(
- this, nextObjGen(), QPDFObjectHandle::newDictionary(), 0, 0));
+ return makeIndirectFromQPDFObject(
+ QPDF_Stream::create(this, nextObjGen(), QPDFObjectHandle::newDictionary(), 0, 0));
}
QPDFObjectHandle
QPDF::newStream(std::shared_ptr<Buffer> data)
{
auto result = newStream();
- result.replaceStreamData(
- data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
+ result.replaceStreamData(data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
return result;
}
@@ -2006,8 +1912,7 @@ QPDFObjectHandle
QPDF::newStream(std::string const& data)
{
auto result = newStream();
- result.replaceStreamData(
- data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
+ result.replaceStreamData(data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
return result;
}
@@ -2025,8 +1930,7 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const& og)
QPDFObjectHandle
QPDF::reserveStream(QPDFObjGen const& og)
{
- return {
- QPDF_Stream::create(this, og, QPDFObjectHandle::newDictionary(), 0, 0)};
+ return {QPDF_Stream::create(this, og, QPDFObjectHandle::newDictionary(), 0, 0)};
}
QPDFObjectHandle
@@ -2069,8 +1973,7 @@ QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh)
{
if (oh.isIndirect() || !oh.isInitialized()) {
QTC::TC("qpdf", "QPDF replaceObject called with indirect object");
- throw std::logic_error(
- "QPDF::replaceObject called with indirect object handle");
+ throw std::logic_error("QPDF::replaceObject called with indirect object handle");
}
updateCache(og, oh.getObj(), -1, -1);
}
@@ -2132,14 +2035,12 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign)
// the intention is to not update the pages tree.
if (!foreign.isIndirect()) {
QTC::TC("qpdf", "QPDF copyForeign direct");
- throw std::logic_error(
- "QPDF::copyForeign called with direct object handle");
+ throw std::logic_error("QPDF::copyForeign called with direct object handle");
}
QPDF& other = foreign.getQPDF();
if (&other == this) {
QTC::TC("qpdf", "QPDF copyForeign not foreign");
- throw std::logic_error(
- "QPDF::copyForeign called with object from this QPDF");
+ throw std::logic_error("QPDF::copyForeign called with object from this QPDF");
}
ObjCopier& obj_copier = m->object_copiers[other.m->unique_id];
@@ -2163,8 +2064,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign)
// Copy any new objects and replace the reservations.
for (auto& to_copy: obj_copier.to_copy) {
- QPDFObjectHandle copy =
- replaceForeignIndirectObjects(to_copy, obj_copier, true);
+ QPDFObjectHandle copy = replaceForeignIndirectObjects(to_copy, obj_copier, true);
if (!to_copy.isStream()) {
QPDFObjGen og(to_copy.getObjGen());
replaceReserved(obj_copier.object_map[og], copy);
@@ -2180,8 +2080,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
{
auto foreign_tc = foreign.getTypeCode();
if (foreign_tc == ::ot_reserved) {
- throw std::logic_error(
- "QPDF: attempting to copy a foreign reserved object");
+ throw std::logic_error("QPDF: attempting to copy a foreign reserved object");
}
if (foreign.isPagesObject()) {
@@ -2209,8 +2108,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
QTC::TC("qpdf", "QPDF copy indirect");
if (obj_copier.object_map.count(foreign_og) == 0) {
obj_copier.to_copy.push_back(foreign);
- obj_copier.object_map[foreign_og] =
- foreign.isStream() ? newStream() : newReserved();
+ obj_copier.object_map[foreign_og] = foreign.isStream() ? newStream() : newReserved();
}
}
@@ -2234,8 +2132,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
}
QPDFObjectHandle
-QPDF::replaceForeignIndirectObjects(
- QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
+QPDF::replaceForeignIndirectObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
{
auto foreign_tc = foreign.getTypeCode();
QPDFObjectHandle result;
@@ -2257,8 +2154,7 @@ QPDF::replaceForeignIndirectObjects(
for (int i = 0; i < n; ++i) {
result.appendItem(
// line-break
- replaceForeignIndirectObjects(
- foreign.getArrayItem(i), obj_copier, false));
+ replaceForeignIndirectObjects(foreign.getArrayItem(i), obj_copier, false));
}
} else if (foreign_tc == ::ot_dictionary) {
QTC::TC("qpdf", "QPDF replace dictionary");
@@ -2266,9 +2162,7 @@ QPDF::replaceForeignIndirectObjects(
std::set<std::string> keys = foreign.getKeys();
for (auto const& iter: keys) {
result.replaceKey(
- iter,
- replaceForeignIndirectObjects(
- foreign.getKey(iter), obj_copier, false));
+ iter, replaceForeignIndirectObjects(foreign.getKey(iter), obj_copier, false));
}
} else if (foreign_tc == ::ot_stream) {
QTC::TC("qpdf", "QPDF replace stream");
@@ -2279,9 +2173,7 @@ QPDF::replaceForeignIndirectObjects(
std::set<std::string> keys = old_dict.getKeys();
for (auto const& iter: keys) {
dict.replaceKey(
- iter,
- replaceForeignIndirectObjects(
- old_dict.getKey(iter), obj_copier, false));
+ iter, replaceForeignIndirectObjects(old_dict.getKey(iter), obj_copier, false));
}
copyStreamData(result, foreign);
} else {
@@ -2309,8 +2201,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign)
if (m->copied_stream_data_provider == nullptr) {
m->copied_stream_data_provider = new CopiedStreamDataProvider(*this);
m->copied_streams =
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(
- m->copied_stream_data_provider);
+ std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(m->copied_stream_data_provider);
}
QPDFObjGen local_og(result.getObjGen());
// Copy information from the foreign stream so we can pipe its
@@ -2325,8 +2216,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign)
" stream object from foreign stream");
}
std::shared_ptr<Buffer> stream_buffer = stream->getStreamDataBuffer();
- if ((foreign_stream_qpdf.m->immediate_copy_from) &&
- (stream_buffer == nullptr)) {
+ if ((foreign_stream_qpdf.m->immediate_copy_from) && (stream_buffer == nullptr)) {
// Pull the stream data into a buffer before attempting
// the copy operation. Do it on the source stream so that
// if the source stream is copied multiple times, we don't
@@ -2347,12 +2237,9 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign)
} else if (stream_provider.get()) {
// In this case, the remote stream's QPDF must stay in scope.
QTC::TC("qpdf", "QPDF copy foreign stream with provider");
- m->copied_stream_data_provider->registerForeignStream(
- local_og, foreign);
+ m->copied_stream_data_provider->registerForeignStream(local_og, foreign);
result.replaceStreamData(
- m->copied_streams,
- dict.getKey("/Filter"),
- dict.getKey("/DecodeParms"));
+ m->copied_streams, dict.getKey("/Filter"), dict.getKey("/DecodeParms"));
} else {
auto foreign_stream_data = std::make_shared<ForeignStreamData>(
foreign_stream_qpdf.m->encp,
@@ -2361,20 +2248,16 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign)
stream->getParsedOffset(),
stream->getLength(),
dict);
- m->copied_stream_data_provider->registerForeignStream(
- local_og, foreign_stream_data);
+ m->copied_stream_data_provider->registerForeignStream(local_og, foreign_stream_data);
result.replaceStreamData(
- m->copied_streams,
- dict.getKey("/Filter"),
- dict.getKey("/DecodeParms"));
+ m->copied_streams, dict.getKey("/Filter"), dict.getKey("/DecodeParms"));
}
}
void
QPDF::swapObjects(int objid1, int generation1, int objid2, int generation2)
{
- swapObjects(
- QPDFObjGen(objid1, generation1), QPDFObjGen(objid2, generation2));
+ swapObjects(QPDFObjGen(objid1, generation1), QPDFObjGen(objid2, generation2));
}
void
@@ -2519,8 +2402,7 @@ QPDF::getCompressibleObjGens()
if (og == encryption_dict_og) {
QTC::TC("qpdf", "QPDF exclude encryption dictionary");
} else if (!(obj.isStream() ||
- (obj.isDictionaryOfType("/Sig") &&
- obj.hasKey("/ByteRange") &&
+ (obj.isDictionaryOfType("/Sig") && obj.hasKey("/ByteRange") &&
obj.hasKey("/Contents")))) {
result.push_back(og);
}
@@ -2571,8 +2453,7 @@ QPDF::pipeStreamData(
{
std::vector<std::shared_ptr<Pipeline>> to_delete;
if (encp->encrypted) {
- decryptStream(
- encp, file, qpdf_for_warning, pipeline, og, stream_dict, to_delete);
+ decryptStream(encp, file, qpdf_for_warning, pipeline, og, stream_dict, to_delete);
}
bool success = false;
@@ -2584,10 +2465,7 @@ QPDF::pipeStreamData(
size_t len = file->read(buf, to_read);
if (len == 0) {
throw damagedPDF(
- file,
- "",
- file->getLastOffset(),
- "unexpected EOF reading stream data");
+ file, "", file->getLastOffset(), "unexpected EOF reading stream data");
}
length -= len;
pipeline->write(buf, len);
@@ -2607,8 +2485,8 @@ QPDF::pipeStreamData(
file,
"",
file->getLastOffset(),
- ("error decoding stream data for object " +
- og.unparse(' ') + ": " + e.what())));
+ ("error decoding stream data for object " + og.unparse(' ') + ": " +
+ e.what())));
if (will_retry) {
qpdf_for_warning.warn(
// line-break
@@ -2694,17 +2572,14 @@ QPDF::damagedPDF(
qpdf_offset_t offset,
std::string const& message)
{
- return QPDFExc(
- qpdf_e_damaged_pdf, input->getName(), object, offset, message);
+ return QPDFExc(qpdf_e_damaged_pdf, input->getName(), object, offset, message);
}
// Return an exception of type qpdf_e_damaged_pdf. The object is taken from
// m->last_object_description.
QPDFExc
QPDF::damagedPDF(
- std::shared_ptr<InputSource> const& input,
- qpdf_offset_t offset,
- std::string const& message)
+ std::shared_ptr<InputSource> const& input, qpdf_offset_t offset, std::string const& message)
{
return damagedPDF(input, m->last_object_description, offset, message);
}
@@ -2712,11 +2587,9 @@ QPDF::damagedPDF(
// Return an exception of type qpdf_e_damaged_pdf. The filename is taken from
// m->file.
QPDFExc
-QPDF::damagedPDF(
- std::string const& object, qpdf_offset_t offset, std::string const& message)
+QPDF::damagedPDF(std::string const& object, qpdf_offset_t offset, std::string const& message)
{
- return QPDFExc(
- qpdf_e_damaged_pdf, m->file->getName(), object, offset, message);
+ return QPDFExc(qpdf_e_damaged_pdf, m->file->getName(), object, offset, message);
}
// Return an exception of type qpdf_e_damaged_pdf. The filename is taken from
@@ -2741,8 +2614,7 @@ QPDF::damagedPDF(qpdf_offset_t offset, std::string const& message)
QPDFExc
QPDF::damagedPDF(std::string const& message)
{
- return damagedPDF(
- m->last_object_description, m->file->getLastOffset(), message);
+ return damagedPDF(m->last_object_description, m->file->getLastOffset(), message);
}
bool
diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc
index f03aa8eb..d210d50a 100644
--- a/libqpdf/QPDFAcroFormDocumentHelper.cc
+++ b/libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -41,8 +41,7 @@ QPDFAcroFormDocumentHelper::getOrCreateAcroForm()
auto acroform = this->qpdf.getRoot().getKey("/AcroForm");
if (!acroform.isDictionary()) {
acroform = this->qpdf.getRoot().replaceKeyAndGetNew(
- "/AcroForm",
- this->qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary()));
+ "/AcroForm", this->qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary()));
}
return acroform;
}
@@ -53,24 +52,20 @@ QPDFAcroFormDocumentHelper::addFormField(QPDFFormFieldObjectHelper ff)
auto acroform = getOrCreateAcroForm();
auto fields = acroform.getKey("/Fields");
if (!fields.isArray()) {
- fields = acroform.replaceKeyAndGetNew(
- "/Fields", QPDFObjectHandle::newArray());
+ fields = acroform.replaceKeyAndGetNew("/Fields", QPDFObjectHandle::newArray());
}
fields.appendItem(ff.getObjectHandle());
QPDFObjGen::set visited;
- traverseField(
- ff.getObjectHandle(), QPDFObjectHandle::newNull(), 0, visited);
+ traverseField(ff.getObjectHandle(), QPDFObjectHandle::newNull(), 0, visited);
}
void
-QPDFAcroFormDocumentHelper::addAndRenameFormFields(
- std::vector<QPDFObjectHandle> fields)
+QPDFAcroFormDocumentHelper::addAndRenameFormFields(std::vector<QPDFObjectHandle> fields)
{
analyze();
std::map<std::string, std::string> renames;
QPDFObjGen::set seen;
- for (std::list<QPDFObjectHandle> queue{fields.begin(), fields.end()};
- !queue.empty();
+ for (std::list<QPDFObjectHandle> queue{fields.begin(), fields.end()}; !queue.empty();
queue.pop_front()) {
auto& obj = queue.front();
if (seen.add(obj)) {
@@ -90,8 +85,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields(
// at the end of the fully qualified name, appending to /T
// has the effect of appending the same thing to the fully
// qualified name.
- std::string old_name =
- QPDFFormFieldObjectHelper(obj).getFullyQualifiedName();
+ std::string old_name = QPDFFormFieldObjectHelper(obj).getFullyQualifiedName();
if (renames.count(old_name) == 0) {
std::string new_name = old_name;
int suffix = 0;
@@ -120,8 +114,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields(
}
void
-QPDFAcroFormDocumentHelper::removeFormFields(
- std::set<QPDFObjGen> const& to_remove)
+QPDFAcroFormDocumentHelper::removeFormFields(std::set<QPDFObjGen> const& to_remove)
{
auto acroform = this->qpdf.getRoot().getKey("/AcroForm");
if (!acroform.isDictionary()) {
@@ -162,8 +155,7 @@ QPDFAcroFormDocumentHelper::removeFormFields(
}
void
-QPDFAcroFormDocumentHelper::setFormFieldName(
- QPDFFormFieldObjectHelper ff, std::string const& name)
+QPDFAcroFormDocumentHelper::setFormFieldName(QPDFFormFieldObjectHelper ff, std::string const& name)
{
ff.setFieldAttribute("/T", name);
QPDFObjGen::set visited;
@@ -257,8 +249,7 @@ QPDFAcroFormDocumentHelper::analyze()
QPDFObjectHandle fields = acroform.getKey("/Fields");
if (!fields.isArray()) {
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper fields not array");
- acroform.warnIfPossible(
- "/Fields key of /AcroForm dictionary is not an array; ignoring");
+ acroform.warnIfPossible("/Fields key of /AcroForm dictionary is not an array; ignoring");
fields = QPDFObjectHandle::newArray();
}
@@ -294,12 +285,10 @@ QPDFAcroFormDocumentHelper::analyze()
// adding a self-contained annotation (merged with the
// field dictionary) to the page's /Annots array and
// forgetting to also put it in /AcroForm.
- annot.warnIfPossible(
- "this widget annotation is not"
- " reachable from /AcroForm in the document catalog");
+ annot.warnIfPossible("this widget annotation is not"
+ " reachable from /AcroForm in the document catalog");
m->annotation_to_field[og] = QPDFFormFieldObjectHelper(annot);
- m->field_to_annotations[og].push_back(
- QPDFAnnotationObjectHelper(annot));
+ m->field_to_annotations[og].push_back(QPDFAnnotationObjectHelper(annot));
}
}
}
@@ -307,10 +296,7 @@ QPDFAcroFormDocumentHelper::analyze()
void
QPDFAcroFormDocumentHelper::traverseField(
- QPDFObjectHandle field,
- QPDFObjectHandle parent,
- int depth,
- QPDFObjGen::set& visited)
+ QPDFObjectHandle field, QPDFObjectHandle parent, int depth, QPDFObjGen::set& visited)
{
if (depth > 100) {
// Arbitrarily cut off recursion at a fixed depth to avoid
@@ -319,16 +305,14 @@ QPDFAcroFormDocumentHelper::traverseField(
}
if (!field.isIndirect()) {
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper direct field");
- field.warnIfPossible(
- "encountered a direct object as a field or annotation while"
- " traversing /AcroForm; ignoring field or annotation");
+ field.warnIfPossible("encountered a direct object as a field or annotation while"
+ " traversing /AcroForm; ignoring field or annotation");
return;
}
if (!field.isDictionary()) {
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper non-dictionary field");
- field.warnIfPossible(
- "encountered a non-dictionary as a field or annotation while"
- " traversing /AcroForm; ignoring field or annotation");
+ field.warnIfPossible("encountered a non-dictionary as a field or annotation while"
+ " traversing /AcroForm; ignoring field or annotation");
return;
}
QPDFObjGen og(field.getObjGen());
@@ -359,23 +343,17 @@ QPDFAcroFormDocumentHelper::traverseField(
if (field.hasKey("/Parent")) {
is_field = true;
}
- if (field.hasKey("/Subtype") || field.hasKey("/Rect") ||
- field.hasKey("/AP")) {
+ if (field.hasKey("/Subtype") || field.hasKey("/Rect") || field.hasKey("/AP")) {
is_annotation = true;
}
}
- QTC::TC(
- "qpdf", "QPDFAcroFormDocumentHelper field found", (depth == 0) ? 0 : 1);
- QTC::TC(
- "qpdf",
- "QPDFAcroFormDocumentHelper annotation found",
- (is_field ? 0 : 1));
+ QTC::TC("qpdf", "QPDFAcroFormDocumentHelper field found", (depth == 0) ? 0 : 1);
+ QTC::TC("qpdf", "QPDFAcroFormDocumentHelper annotation found", (is_field ? 0 : 1));
if (is_annotation) {
QPDFObjectHandle our_field = (is_field ? field : parent);
- m->field_to_annotations[our_field.getObjGen()].push_back(
- QPDFAnnotationObjectHelper(field));
+ m->field_to_annotations[our_field.getObjGen()].push_back(QPDFAnnotationObjectHelper(field));
m->annotation_to_field[og] = QPDFFormFieldObjectHelper(our_field);
}
@@ -400,8 +378,7 @@ QPDFAcroFormDocumentHelper::getNeedAppearances()
{
bool result = false;
QPDFObjectHandle acroform = this->qpdf.getRoot().getKey("/AcroForm");
- if (acroform.isDictionary() &&
- acroform.getKey("/NeedAppearances").isBool()) {
+ if (acroform.isDictionary() && acroform.getKey("/NeedAppearances").isBool()) {
result = acroform.getKey("/NeedAppearances").getBoolValue();
}
return result;
@@ -418,8 +395,7 @@ QPDFAcroFormDocumentHelper::setNeedAppearances(bool val)
return;
}
if (val) {
- acroform.replaceKey(
- "/NeedAppearances", QPDFObjectHandle::newBool(true));
+ acroform.replaceKey("/NeedAppearances", QPDFObjectHandle::newBool(true));
} else {
acroform.removeKey("/NeedAppearances");
}
@@ -472,8 +448,7 @@ QPDFAcroFormDocumentHelper::adjustInheritedFields(
// we may be put a value on the field that is unused. This is
// harmless, so it's not worth trying to work around.
- auto has_explicit = [](QPDFFormFieldObjectHelper& field,
- std::string const& key) {
+ auto has_explicit = [](QPDFFormFieldObjectHelper& field, std::string const& key) {
if (field.getObjectHandle().hasKey(key)) {
return true;
}
@@ -490,16 +465,14 @@ QPDFAcroFormDocumentHelper::adjustInheritedFields(
std::string da = cur_field.getDefaultAppearance();
if (da != from_default_da) {
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper override da");
- obj.replaceKey(
- "/DA", QPDFObjectHandle::newUnicodeString(from_default_da));
+ obj.replaceKey("/DA", QPDFObjectHandle::newUnicodeString(from_default_da));
}
}
if (override_q && (!has_explicit(cur_field, "/Q"))) {
int q = cur_field.getQuadding();
if (q != from_default_q) {
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper override q");
- obj.replaceKey(
- "/Q", QPDFObjectHandle::newInteger(from_default_q));
+ obj.replaceKey("/Q", QPDFObjectHandle::newInteger(from_default_q));
}
}
}
@@ -511,11 +484,8 @@ namespace
{
public:
ResourceReplacer(
- std::map<std::string, std::map<std::string, std::string>> const&
- dr_map,
- std::map<
- std::string,
- std::map<std::string, std::set<size_t>>> const& rnames);
+ std::map<std::string, std::map<std::string, std::string>> const& dr_map,
+ std::map<std::string, std::map<std::string, std::set<size_t>>> const& rnames);
virtual ~ResourceReplacer() = default;
virtual void handleToken(QPDFTokenizer::Token const&) override;
@@ -527,8 +497,7 @@ namespace
ResourceReplacer::ResourceReplacer(
std::map<std::string, std::map<std::string, std::string>> const& dr_map,
- std::map<std::string, std::map<std::string, std::set<size_t>>> const&
- rnames) :
+ std::map<std::string, std::map<std::string, std::set<size_t>>> const& rnames) :
offset(0)
{
// We have:
@@ -564,8 +533,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const& token)
{
bool wrote = false;
if (token.getType() == QPDFTokenizer::tt_name) {
- std::string name =
- QPDFObjectHandle::newName(token.getValue()).getName();
+ std::string name = QPDFObjectHandle::newName(token.getValue()).getName();
if (to_replace.count(name) && to_replace[name].count(offset)) {
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper replaced DA token");
write(to_replace[name][offset]);
@@ -580,8 +548,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const& token)
void
QPDFAcroFormDocumentHelper::adjustDefaultAppearances(
- QPDFObjectHandle obj,
- std::map<std::string, std::map<std::string, std::string>> const& dr_map)
+ QPDFObjectHandle obj, std::map<std::string, std::map<std::string, std::string>> const& dr_map)
{
// This method is called on a field that has been copied from
// another file but whose /DA still refers to resources in the
@@ -624,8 +591,7 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances(
// then filter it. We don't attach the stream to anything, so it
// will get discarded.
ResourceFinder rf;
- auto da_stream =
- QPDFObjectHandle::newStream(&this->qpdf, DA.getUTF8Value());
+ auto da_stream = QPDFObjectHandle::newStream(&this->qpdf, DA.getUTF8Value());
try {
auto nwarnings = this->qpdf.numWarnings();
da_stream.parseAsContents(&rf);
@@ -646,15 +612,13 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances(
Pl_Buffer buf_pl("filtered DA");
da_stream.filterAsContents(&rr, &buf_pl);
auto buf = buf_pl.getBufferSharedPointer();
- std::string new_da(
- reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
+ std::string new_da(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
obj.replaceKey("/DA", QPDFObjectHandle::newString(new_da));
}
void
QPDFAcroFormDocumentHelper::adjustAppearanceStream(
- QPDFObjectHandle stream,
- std::map<std::string, std::map<std::string, std::string>> dr_map)
+ QPDFObjectHandle stream, std::map<std::string, std::map<std::string, std::string>> dr_map)
{
// We don't have to modify appearance streams or their resource
// dictionaries for them to display properly, but we need to do so
@@ -740,8 +704,7 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream(
} catch (std::exception& e) {
// No way to reproduce in test suite right now since error
// conditions are converted to warnings.
- stream.warnIfPossible(
- std::string("Unable to parse appearance stream: ") + e.what());
+ stream.warnIfPossible(std::string("Unable to parse appearance stream: ") + e.what());
}
}
@@ -839,8 +802,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
}
dr.makeResourcesIndirect(this->qpdf);
if (!dr.isIndirect()) {
- dr = acroform.replaceKeyAndGetNew(
- "/DR", this->qpdf.makeIndirectObject(dr));
+ dr = acroform.replaceKeyAndGetNew("/DR", this->qpdf.makeIndirectObject(dr));
}
// Merge the other document's /DR, creating a conflict
// map. mergeResources checks to make sure both objects
@@ -969,8 +931,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
obj.replaceKey("/Parent", orig_to_copy[parent_og]);
} else {
parent.warnIfPossible(
- "while traversing field " +
- obj.getObjGen().unparse(',') +
+ "while traversing field " + obj.getObjGen().unparse(',') +
", found parent (" + parent_og.unparse(',') +
") that had not been seen, indicating likely"
" invalid field structure");
@@ -989,11 +950,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
if (override_da || override_q) {
adjustInheritedFields(
- obj,
- override_da,
- from_default_da,
- override_q,
- from_default_q);
+ obj, override_da, from_default_da, override_q, from_default_q);
}
if (foreign) {
// Lazily initialize our /DR and the conflict map.
@@ -1013,8 +970,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
obj.replaceKey("/DR", dr);
}
}
- if (foreign && obj.getKey("/DA").isString() &&
- (!dr_map.empty())) {
+ if (foreign && obj.getKey("/DA").isString() && (!dr_map.empty())) {
adjustDefaultAppearances(obj, dr_map);
}
}
@@ -1060,15 +1016,13 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
if (apdict.isDictionary()) {
for (auto& ap: apdict.ditems()) {
if (ap.second.isStream()) {
- streams.push_back(
- replace_stream(apdict, ap.first, ap.second));
+ streams.push_back(replace_stream(apdict, ap.first, ap.second));
} else if (ap.second.isDictionary()) {
for (auto& ap2: ap.second.ditems()) {
if (ap2.second.isStream()) {
streams.push_back(
// line-break
- replace_stream(
- ap.second, ap2.first, ap2.second));
+ replace_stream(ap.second, ap2.first, ap2.second));
}
}
}
@@ -1096,8 +1050,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations(
adjustAppearanceStream(stream, dr_map);
}
}
- auto rect =
- cm.transformRectangle(annot.getKey("/Rect").getArrayAsRectangle());
+ auto rect = cm.transformRectangle(annot.getKey("/Rect").getArrayAsRectangle());
annot.replaceKey("/Rect", QPDFObjectHandle::newFromRectangle(rect));
}
}
diff --git a/libqpdf/QPDFAnnotationObjectHelper.cc b/libqpdf/QPDFAnnotationObjectHelper.cc
index ff985ed0..81ea5a7f 100644
--- a/libqpdf/QPDFAnnotationObjectHelper.cc
+++ b/libqpdf/QPDFAnnotationObjectHelper.cc
@@ -47,8 +47,7 @@ QPDFAnnotationObjectHelper::getFlags()
}
QPDFObjectHandle
-QPDFAnnotationObjectHelper::getAppearanceStream(
- std::string const& which, std::string const& state)
+QPDFAnnotationObjectHelper::getAppearanceStream(std::string const& which, std::string const& state)
{
QPDFObjectHandle ap = getAppearanceDictionary();
std::string desired_state = state.empty() ? getAppearanceState() : state;
@@ -80,10 +79,7 @@ QPDFAnnotationObjectHelper::getAppearanceStream(
std::string
QPDFAnnotationObjectHelper::getPageContentForAppearance(
- std::string const& name,
- int rotate,
- int required_flags,
- int forbidden_flags)
+ std::string const& name, int rotate, int required_flags, int forbidden_flags)
{
if (!getAppearanceStream("/N").isStream()) {
return "";
@@ -242,9 +238,7 @@ QPDFAnnotationObjectHelper::getPageContentForAppearance(
// Compute a matrix to transform the appearance box to the rectangle
QPDFMatrix AA;
AA.translate(rect.llx, rect.lly);
- AA.scale(
- (rect.urx - rect.llx) / (T.urx - T.llx),
- (rect.ury - rect.lly) / (T.ury - T.lly));
+ AA.scale((rect.urx - rect.llx) / (T.urx - T.llx), (rect.ury - rect.lly) / (T.ury - T.lly));
AA.translate(-T.llx, -T.lly);
if (do_rotate) {
AA.rotatex90(rotate);
diff --git a/libqpdf/QPDFArgParser.cc b/libqpdf/QPDFArgParser.cc
index 76b65a67..7e1980ad 100644
--- a/libqpdf/QPDFArgParser.cc
+++ b/libqpdf/QPDFArgParser.cc
@@ -9,8 +9,7 @@
#include <cstring>
#include <iostream>
-QPDFArgParser::Members::Members(
- int argc, char const* const argv[], char const* progname_env) :
+QPDFArgParser::Members::Members(int argc, char const* const argv[], char const* progname_env) :
argc(argc),
argv(argv),
@@ -25,19 +24,15 @@ QPDFArgParser::Members::Members(
whoami = QUtil::getWhoami(tmp.get());
}
-QPDFArgParser::QPDFArgParser(
- int argc, char const* const argv[], char const* progname_env) :
+QPDFArgParser::QPDFArgParser(int argc, char const* const argv[], char const* progname_env) :
m(new Members(argc, argv, progname_env))
{
selectHelpOptionTable();
char const* help_choices[] = {"all", nullptr};
// More help choices are added dynamically.
- addChoices(
- "help", bindParam(&QPDFArgParser::argHelp, this), false, help_choices);
- addInvalidChoiceHandler(
- "help", bindParam(&QPDFArgParser::invalidHelpArg, this));
- addBare(
- "completion-bash", bindBare(&QPDFArgParser::argCompletionBash, this));
+ addChoices("help", bindParam(&QPDFArgParser::argHelp, this), false, help_choices);
+ addInvalidChoiceHandler("help", bindParam(&QPDFArgParser::invalidHelpArg, this));
+ addBare("completion-bash", bindBare(&QPDFArgParser::argCompletionBash, this));
addBare("completion-zsh", bindBare(&QPDFArgParser::argCompletionZsh, this));
selectMainOptionTable();
}
@@ -62,22 +57,19 @@ QPDFArgParser::selectOptionTable(std::string const& name)
auto t = m->option_tables.find(name);
if (t == m->option_tables.end()) {
QTC::TC("libtests", "QPDFArgParser select unregistered table");
- throw std::logic_error(
- "QPDFArgParser: selecting unregistered option table " + name);
+ throw std::logic_error("QPDFArgParser: selecting unregistered option table " + name);
}
m->option_table = &(t->second);
m->option_table_name = name;
}
void
-QPDFArgParser::registerOptionTable(
- std::string const& name, bare_arg_handler_t end_handler)
+QPDFArgParser::registerOptionTable(std::string const& name, bare_arg_handler_t end_handler)
{
if (0 != m->option_tables.count(name)) {
QTC::TC("libtests", "QPDFArgParser register registered table");
throw std::logic_error(
- "QPDFArgParser: registering already registered option table " +
- name);
+ "QPDFArgParser: registering already registered option table " + name);
}
m->option_tables[name];
selectOptionTable(name);
@@ -90,8 +82,8 @@ QPDFArgParser::registerArg(std::string const& arg)
if (0 != m->option_table->count(arg)) {
QTC::TC("libtests", "QPDFArgParser duplicate handler");
throw std::logic_error(
- "QPDFArgParser: adding a duplicate handler for option " + arg +
- " in " + m->option_table_name + " option table");
+ "QPDFArgParser: adding a duplicate handler for option " + arg + " in " +
+ m->option_table_name + " option table");
}
return ((*m->option_table)[arg]);
}
@@ -113,9 +105,7 @@ QPDFArgParser::addBare(std::string const& arg, bare_arg_handler_t handler)
void
QPDFArgParser::addRequiredParameter(
- std::string const& arg,
- param_arg_handler_t handler,
- char const* parameter_name)
+ std::string const& arg, param_arg_handler_t handler, char const* parameter_name)
{
OptionEntry& oe = registerArg(arg);
oe.parameter_needed = true;
@@ -124,8 +114,7 @@ QPDFArgParser::addRequiredParameter(
}
void
-QPDFArgParser::addOptionalParameter(
- std::string const& arg, param_arg_handler_t handler)
+QPDFArgParser::addOptionalParameter(std::string const& arg, param_arg_handler_t handler)
{
OptionEntry& oe = registerArg(arg);
oe.parameter_needed = false;
@@ -134,10 +123,7 @@ QPDFArgParser::addOptionalParameter(
void
QPDFArgParser::addChoices(
- std::string const& arg,
- param_arg_handler_t handler,
- bool required,
- char const** choices)
+ std::string const& arg, param_arg_handler_t handler, bool required, char const** choices)
{
OptionEntry& oe = registerArg(arg);
oe.parameter_needed = required;
@@ -148,15 +134,13 @@ QPDFArgParser::addChoices(
}
void
-QPDFArgParser::addInvalidChoiceHandler(
- std::string const& arg, param_arg_handler_t handler)
+QPDFArgParser::addInvalidChoiceHandler(std::string const& arg, param_arg_handler_t handler)
{
auto i = m->option_table->find(arg);
if (i == m->option_table->end()) {
QTC::TC("libtests", "QPDFArgParser invalid choice handler to unknown");
- throw std::logic_error(
- "QPDFArgParser: attempt to add invalid choice handler"
- " to unknown argument");
+ throw std::logic_error("QPDFArgParser: attempt to add invalid choice handler"
+ " to unknown argument");
}
auto& oe = i->second;
oe.invalid_choice_handler = handler;
@@ -195,9 +179,7 @@ QPDFArgParser::completionCommon(bool zsh)
std::string appimage;
if (QUtil::get_env(m->progname_env.c_str(), &executable)) {
progname = executable;
- } else if (
- QUtil::get_env("APPDIR", &appdir) &&
- QUtil::get_env("APPIMAGE", &appimage)) {
+ } else if (QUtil::get_env("APPDIR", &appdir) && QUtil::get_env("APPIMAGE", &appimage)) {
// Detect if we're in an AppImage and adjust
if ((appdir.length() < strlen(m->argv[0])) &&
(strncmp(appdir.c_str(), m->argv[0], appdir.length()) == 0)) {
@@ -345,8 +327,7 @@ QPDFArgParser::handleBashArguments()
}
// Explicitly discard any non-space-terminated word. The "current
// word" is handled specially.
- m->bash_argv_ph =
- QUtil::make_shared_array<char const*>(1 + m->bash_argv.size());
+ m->bash_argv_ph = QUtil::make_shared_array<char const*>(1 + m->bash_argv.size());
for (size_t i = 0; i < m->bash_argv.size(); ++i) {
m->bash_argv_ph.get()[i] = m->bash_argv.at(i).get();
}
@@ -479,8 +460,7 @@ QPDFArgParser::parseArgs()
end_option = true;
if (oep == m->option_table->end()) {
// This is registered automatically, so this can't happen.
- throw std::logic_error(
- "QPDFArgParser: -- handler not registered");
+ throw std::logic_error("QPDFArgParser: -- handler not registered");
}
} else if ((arg[0] == '-') && (strcmp(arg, "-") != 0)) {
++arg;
@@ -531,18 +511,15 @@ QPDFArgParser::parseArgs()
QTC::TC("libtests", "QPDFArgParser unrecognized");
std::string message = "unrecognized argument " + o_arg;
if (m->option_table != &m->main_option_table) {
- message += " (" + m->option_table_name +
- " options must be terminated with --)";
+ message += " (" + m->option_table_name + " options must be terminated with --)";
}
usage(message);
}
OptionEntry& oe = oep->second;
if ((oe.parameter_needed && (!have_parameter)) ||
- ((!oe.choices.empty() && have_parameter &&
- (0 == oe.choices.count(parameter))))) {
- std::string message =
- "--" + arg_s + " must be given as --" + arg_s + "=";
+ ((!oe.choices.empty() && have_parameter && (0 == oe.choices.count(parameter))))) {
+ std::string message = "--" + arg_s + " must be given as --" + arg_s + "=";
if (oe.invalid_choice_handler) {
oe.invalid_choice_handler(parameter);
// Method should call usage() or exit. Just in case it
@@ -609,9 +586,7 @@ QPDFArgParser::doFinalChecks()
void
QPDFArgParser::addChoicesToCompletions(
- option_table_t& option_table,
- std::string const& option,
- std::string const& extra_prefix)
+ option_table_t& option_table, std::string const& option, std::string const& extra_prefix)
{
if (option_table.count(option) != 0) {
OptionEntry& oe = option_table[option];
@@ -648,9 +623,7 @@ QPDFArgParser::addOptionsToCompletions(option_table_t& option_table)
void
QPDFArgParser::insertCompletions(
- option_table_t& option_table,
- std::string const& choice_option,
- std::string const& extra_prefix)
+ option_table_t& option_table, std::string const& choice_option, std::string const& extra_prefix)
{
if (!choice_option.empty()) {
addChoicesToCompletions(option_table, choice_option, extra_prefix);
@@ -666,21 +639,17 @@ QPDFArgParser::handleCompletion()
if (m->completions.empty()) {
// Detect --option=... Bash treats the = as a word separator.
std::string choice_option;
- if (m->bash_cur.empty() && (m->bash_prev.length() > 2) &&
- (m->bash_prev.at(0) == '-') && (m->bash_prev.at(1) == '-') &&
- (m->bash_line.at(m->bash_line.length() - 1) == '=')) {
+ if (m->bash_cur.empty() && (m->bash_prev.length() > 2) && (m->bash_prev.at(0) == '-') &&
+ (m->bash_prev.at(1) == '-') && (m->bash_line.at(m->bash_line.length() - 1) == '=')) {
choice_option = m->bash_prev.substr(2, std::string::npos);
- } else if (
- (m->bash_prev == "=") &&
- (m->bash_line.length() > (m->bash_cur.length() + 1))) {
+ } else if ((m->bash_prev == "=") && (m->bash_line.length() > (m->bash_cur.length() + 1))) {
// We're sitting at --option=x. Find previous option.
size_t end_mark = m->bash_line.length() - m->bash_cur.length() - 1;
char before_cur = m->bash_line.at(end_mark);
if (before_cur == '=') {
size_t space = m->bash_line.find_last_of(' ', end_mark);
if (space != std::string::npos) {
- std::string candidate =
- m->bash_line.substr(space + 1, end_mark - space - 1);
+ std::string candidate = m->bash_line.substr(space + 1, end_mark - space - 1);
if ((candidate.length() > 2) && (candidate.at(0) == '-') &&
(candidate.at(1) == '-')) {
choice_option = candidate.substr(2, std::string::npos);
@@ -695,8 +664,7 @@ QPDFArgParser::handleCompletion()
insertCompletions(*m->option_table, choice_option, extra_prefix);
if (m->argc == 1) {
// Help options are valid only by themselves.
- insertCompletions(
- m->help_option_table, choice_option, extra_prefix);
+ insertCompletions(m->help_option_table, choice_option, extra_prefix);
}
}
std::string prefix = extra_prefix + m->bash_cur;
@@ -716,24 +684,19 @@ QPDFArgParser::addHelpFooter(std::string const& text)
void
QPDFArgParser::addHelpTopic(
- std::string const& topic,
- std::string const& short_text,
- std::string const& long_text)
+ std::string const& topic, std::string const& short_text, std::string const& long_text)
{
if (topic == "all") {
QTC::TC("libtests", "QPDFArgParser add reserved help topic");
- throw std::logic_error(
- "QPDFArgParser: can't register reserved help topic " + topic);
+ throw std::logic_error("QPDFArgParser: can't register reserved help topic " + topic);
}
if (!((topic.length() > 0) && (topic.at(0) != '-'))) {
QTC::TC("libtests", "QPDFArgParser bad topic for help");
- throw std::logic_error(
- "QPDFArgParser: help topics must not start with -");
+ throw std::logic_error("QPDFArgParser: help topics must not start with -");
}
if (m->help_topics.count(topic)) {
QTC::TC("libtests", "QPDFArgParser add existing topic");
- throw std::logic_error(
- "QPDFArgParser: topic " + topic + " has already been added");
+ throw std::logic_error("QPDFArgParser: topic " + topic + " has already been added");
}
m->help_topics[topic] = HelpTopic(short_text, long_text);
@@ -747,23 +710,20 @@ QPDFArgParser::addOptionHelp(
std::string const& short_text,
std::string const& long_text)
{
- if (!((option_name.length() > 2) && (option_name.at(0) == '-') &&
- (option_name.at(1) == '-'))) {
+ if (!((option_name.length() > 2) && (option_name.at(0) == '-') && (option_name.at(1) == '-'))) {
QTC::TC("libtests", "QPDFArgParser bad option for help");
- throw std::logic_error(
- "QPDFArgParser: options for help must start with --");
+ throw std::logic_error("QPDFArgParser: options for help must start with --");
}
if (m->option_help.count(option_name)) {
QTC::TC("libtests", "QPDFArgParser duplicate option help");
- throw std::logic_error(
- "QPDFArgParser: option " + option_name + " already has help");
+ throw std::logic_error("QPDFArgParser: option " + option_name + " already has help");
}
auto ht = m->help_topics.find(topic);
if (ht == m->help_topics.end()) {
QTC::TC("libtests", "QPDFArgParser add to unknown topic");
throw std::logic_error(
- "QPDFArgParser: unable to add option " + option_name +
- " to unknown help topic " + topic);
+ "QPDFArgParser: unable to add option " + option_name + " to unknown help topic " +
+ topic);
}
m->option_help[option_name] = HelpTopic(short_text, long_text);
ht->second.options.insert(option_name);
@@ -773,12 +733,9 @@ QPDFArgParser::addOptionHelp(
void
QPDFArgParser::getTopHelp(std::ostringstream& msg)
{
- msg << "Run \"" << m->whoami << " --help=topic\" for help on a topic."
- << std::endl
- << "Run \"" << m->whoami << " --help=--option\" for help on an option."
- << std::endl
- << "Run \"" << m->whoami << " --help=all\" to see all available help."
- << std::endl
+ msg << "Run \"" << m->whoami << " --help=topic\" for help on a topic." << std::endl
+ << "Run \"" << m->whoami << " --help=--option\" for help on an option." << std::endl
+ << "Run \"" << m->whoami << " --help=all\" to see all available help." << std::endl
<< std::endl
<< "Topics:" << std::endl;
for (auto const& i: m->help_topics) {
@@ -794,8 +751,7 @@ QPDFArgParser::getAllHelp(std::ostringstream& msg)
for (auto const& i: topics) {
auto const& topic = i.first;
msg << std::endl
- << "== " << topic << " (" << i.second.short_text
- << ") ==" << std::endl
+ << "== " << topic << " (" << i.second.short_text << ") ==" << std::endl
<< std::endl;
getTopicHelp(topic, i.second, msg);
}
@@ -806,8 +762,7 @@ QPDFArgParser::getAllHelp(std::ostringstream& msg)
}
void
-QPDFArgParser::getTopicHelp(
- std::string const& name, HelpTopic const& ht, std::ostringstream& msg)
+QPDFArgParser::getTopicHelp(std::string const& name, HelpTopic const& ht, std::ostringstream& msg)
{
if (ht.long_text.empty()) {
msg << ht.short_text << std::endl;
@@ -817,8 +772,7 @@ QPDFArgParser::getTopicHelp(
if (!ht.options.empty()) {
msg << std::endl << "Related options:" << std::endl;
for (auto const& i: ht.options) {
- msg << " " << i << ": " << m->option_help[i].short_text
- << std::endl;
+ msg << " " << i << ": " << m->option_help[i].short_text << std::endl;
}
}
}
diff --git a/libqpdf/QPDFCryptoProvider.cc b/libqpdf/QPDFCryptoProvider.cc
index f906eaf8..37f152c9 100644
--- a/libqpdf/QPDFCryptoProvider.cc
+++ b/libqpdf/QPDFCryptoProvider.cc
@@ -19,8 +19,7 @@ QPDFCryptoProvider::getImpl()
{
QPDFCryptoProvider& p = getInstance();
if (p.m->default_provider.empty()) {
- throw std::logic_error(
- "QPDFCryptoProvider::getImpl called with no default provider.");
+ throw std::logic_error("QPDFCryptoProvider::getImpl called with no default provider.");
}
return p.getImpl_internal(p.m->default_provider);
}
@@ -76,8 +75,7 @@ QPDFCryptoProvider::getImpl_internal(std::string const& name) const
auto iter = m->providers.find(name);
if (iter == m->providers.end()) {
throw std::logic_error(
- "QPDFCryptoProvider requested unknown implementation \"" + name +
- "\"");
+ "QPDFCryptoProvider requested unknown implementation \"" + name + "\"");
}
return m->providers[name]();
}
diff --git a/libqpdf/QPDFCrypto_gnutls.cc b/libqpdf/QPDFCrypto_gnutls.cc
index d9d14bee..c96cdfbc 100644
--- a/libqpdf/QPDFCrypto_gnutls.cc
+++ b/libqpdf/QPDFCrypto_gnutls.cc
@@ -47,8 +47,7 @@ QPDFCrypto_gnutls::MD5_init()
if (code < 0) {
this->hash_ctx = nullptr;
throw std::runtime_error(
- std::string("gnutls: MD5 error: ") +
- std::string(gnutls_strerror(code)));
+ std::string("gnutls: MD5 error: ") + std::string(gnutls_strerror(code)));
}
}
@@ -78,26 +77,22 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len)
{
RC4_finalize();
if (key_len == -1) {
- key_len =
- QIntC::to_int(strlen(reinterpret_cast<char const*>(key_data)));
+ key_len = QIntC::to_int(strlen(reinterpret_cast<char const*>(key_data)));
}
gnutls_datum_t key;
key.data = const_cast<unsigned char*>(key_data);
key.size = QIntC::to_uint(key_len);
- int code = gnutls_cipher_init(
- &this->cipher_ctx, GNUTLS_CIPHER_ARCFOUR_128, &key, nullptr);
+ int code = gnutls_cipher_init(&this->cipher_ctx, GNUTLS_CIPHER_ARCFOUR_128, &key, nullptr);
if (code < 0) {
this->cipher_ctx = nullptr;
throw std::runtime_error(
- std::string("gnutls: RC4 error: ") +
- std::string(gnutls_strerror(code)));
+ std::string("gnutls: RC4 error: ") + std::string(gnutls_strerror(code)));
}
}
void
-QPDFCrypto_gnutls::RC4_process(
- unsigned char const* in_data, size_t len, unsigned char* out_data)
+QPDFCrypto_gnutls::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data)
{
gnutls_cipher_encrypt2(this->cipher_ctx, in_data, len, out_data, len);
}
@@ -223,29 +218,19 @@ QPDFCrypto_gnutls::rijndael_init(
if (code < 0) {
this->cipher_ctx = nullptr;
throw std::runtime_error(
- std::string("gnutls: AES error: ") +
- std::string(gnutls_strerror(code)));
+ std::string("gnutls: AES error: ") + std::string(gnutls_strerror(code)));
}
}
void
-QPDFCrypto_gnutls::rijndael_process(
- unsigned char* in_data, unsigned char* out_data)
+QPDFCrypto_gnutls::rijndael_process(unsigned char* in_data, unsigned char* out_data)
{
if (this->encrypt) {
gnutls_cipher_encrypt2(
- this->cipher_ctx,
- in_data,
- rijndael_buf_size,
- out_data,
- rijndael_buf_size);
+ this->cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size);
} else {
gnutls_cipher_decrypt2(
- this->cipher_ctx,
- in_data,
- rijndael_buf_size,
- out_data,
- rijndael_buf_size);
+ this->cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size);
}
// Gnutls doesn't support AES in ECB (non-CBC) mode, but the
@@ -253,14 +238,8 @@ QPDFCrypto_gnutls::rijndael_process(
// zeroes each time. We jump through a few hoops here to make this
// work.
if (!this->cbc_mode) {
- static unsigned char zeroes[16] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- rijndael_init(
- this->encrypt,
- this->aes_key_data,
- this->aes_key_len,
- false,
- zeroes);
+ static unsigned char zeroes[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ rijndael_init(this->encrypt, this->aes_key_data, this->aes_key_len, false, zeroes);
}
}
diff --git a/libqpdf/QPDFCrypto_native.cc b/libqpdf/QPDFCrypto_native.cc
index 5cd3c887..9e9cba51 100644
--- a/libqpdf/QPDFCrypto_native.cc
+++ b/libqpdf/QPDFCrypto_native.cc
@@ -68,8 +68,7 @@ QPDFCrypto_native::RC4_init(unsigned char const* key_data, int key_len)
}
void
-QPDFCrypto_native::RC4_process(
- unsigned char const* in_data, size_t len, unsigned char* out_data)
+QPDFCrypto_native::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data)
{
this->rc4->process(in_data, len, out_data);
}
@@ -112,13 +111,12 @@ QPDFCrypto_native::rijndael_init(
unsigned char* cbc_block)
{
- this->aes_pdf = std::make_shared<AES_PDF_native>(
- encrypt, key_data, key_len, cbc_mode, cbc_block);
+ this->aes_pdf =
+ std::make_shared<AES_PDF_native>(encrypt, key_data, key_len, cbc_mode, cbc_block);
}
void
-QPDFCrypto_native::rijndael_process(
- unsigned char* in_data, unsigned char* out_data)
+QPDFCrypto_native::rijndael_process(unsigned char* in_data, unsigned char* out_data)
{
this->aes_pdf->update(in_data, out_data);
}
diff --git a/libqpdf/QPDFCrypto_openssl.cc b/libqpdf/QPDFCrypto_openssl.cc
index 6bd579a5..87591eb5 100644
--- a/libqpdf/QPDFCrypto_openssl.cc
+++ b/libqpdf/QPDFCrypto_openssl.cc
@@ -76,8 +76,7 @@ RC4Loader::~RC4Loader()
static void
bad_bits(int bits)
{
- throw std::logic_error(
- std::string("unsupported key length: ") + std::to_string(bits));
+ throw std::logic_error(std::string("unsupported key length: ") + std::to_string(bits));
}
static void
@@ -208,14 +207,11 @@ QPDFCrypto_openssl::RC4_init(unsigned char const* key_data, int key_len)
#endif
check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx));
if (key_len == -1) {
- key_len =
- QIntC::to_int(strlen(reinterpret_cast<const char*>(key_data)));
+ key_len = QIntC::to_int(strlen(reinterpret_cast<const char*>(key_data)));
}
- check_openssl(
- EVP_EncryptInit_ex(cipher_ctx, rc4, nullptr, nullptr, nullptr));
+ check_openssl(EVP_EncryptInit_ex(cipher_ctx, rc4, nullptr, nullptr, nullptr));
check_openssl(EVP_CIPHER_CTX_set_key_length(cipher_ctx, key_len));
- check_openssl(
- EVP_EncryptInit_ex(cipher_ctx, nullptr, nullptr, key_data, nullptr));
+ check_openssl(EVP_EncryptInit_ex(cipher_ctx, nullptr, nullptr, key_data, nullptr));
}
void
@@ -242,23 +238,19 @@ QPDFCrypto_openssl::rijndael_init(
check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx));
check_openssl(
// line-break
- EVP_CipherInit_ex(
- cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt));
+ EVP_CipherInit_ex(cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt));
check_openssl(EVP_CIPHER_CTX_set_padding(cipher_ctx, 0));
}
void
-QPDFCrypto_openssl::RC4_process(
- unsigned char const* in_data, size_t len, unsigned char* out_data)
+QPDFCrypto_openssl::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data)
{
int out_len = static_cast<int>(len);
- check_openssl(
- EVP_EncryptUpdate(cipher_ctx, out_data, &out_len, in_data, out_len));
+ check_openssl(EVP_EncryptUpdate(cipher_ctx, out_data, &out_len, in_data, out_len));
}
void
-QPDFCrypto_openssl::rijndael_process(
- unsigned char* in_data, unsigned char* out_data)
+QPDFCrypto_openssl::rijndael_process(unsigned char* in_data, unsigned char* out_data)
{
int len = QPDFCryptoImpl::rijndael_buf_size;
check_openssl(EVP_CipherUpdate(cipher_ctx, out_data, &len, in_data, len));
diff --git a/libqpdf/QPDFEFStreamObjectHelper.cc b/libqpdf/QPDFEFStreamObjectHelper.cc
index 28e2cef0..a7ece6ae 100644
--- a/libqpdf/QPDFEFStreamObjectHelper.cc
+++ b/libqpdf/QPDFEFStreamObjectHelper.cc
@@ -24,13 +24,12 @@ QPDFEFStreamObjectHelper::getParam(std::string const& pkey)
}
void
-QPDFEFStreamObjectHelper::setParam(
- std::string const& pkey, QPDFObjectHandle const& pval)
+QPDFEFStreamObjectHelper::setParam(std::string const& pkey, QPDFObjectHandle const& pval)
{
auto params = this->oh.getDict().getKey("/Params");
if (!params.isDictionary()) {
- params = this->oh.getDict().replaceKeyAndGetNew(
- "/Params", QPDFObjectHandle::newDictionary());
+ params =
+ this->oh.getDict().replaceKeyAndGetNew("/Params", QPDFObjectHandle::newDictionary());
}
params.replaceKey(pkey, pval);
}
@@ -89,8 +88,7 @@ QPDFEFStreamObjectHelper::getChecksum()
}
QPDFEFStreamObjectHelper
-QPDFEFStreamObjectHelper::createEFStream(
- QPDF& qpdf, std::shared_ptr<Buffer> data)
+QPDFEFStreamObjectHelper::createEFStream(QPDF& qpdf, std::shared_ptr<Buffer> data)
{
return newFromStream(qpdf.newStream(data));
}
@@ -102,12 +100,10 @@ QPDFEFStreamObjectHelper::createEFStream(QPDF& qpdf, std::string const& data)
}
QPDFEFStreamObjectHelper
-QPDFEFStreamObjectHelper::createEFStream(
- QPDF& qpdf, std::function<void(Pipeline*)> provider)
+QPDFEFStreamObjectHelper::createEFStream(QPDF& qpdf, std::function<void(Pipeline*)> provider)
{
auto stream = qpdf.newStream();
- stream.replaceStreamData(
- provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
+ stream.replaceStreamData(provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
return newFromStream(stream);
}
@@ -128,8 +124,7 @@ QPDFEFStreamObjectHelper::setModDate(std::string const& date)
QPDFEFStreamObjectHelper&
QPDFEFStreamObjectHelper::setSubtype(std::string const& subtype)
{
- this->oh.getDict().replaceKey(
- "/Subtype", QPDFObjectHandle::newName("/" + subtype));
+ this->oh.getDict().replaceKey("/Subtype", QPDFObjectHandle::newName("/" + subtype));
return *this;
}
@@ -137,22 +132,18 @@ QPDFEFStreamObjectHelper
QPDFEFStreamObjectHelper::newFromStream(QPDFObjectHandle stream)
{
QPDFEFStreamObjectHelper result(stream);
- stream.getDict().replaceKey(
- "/Type", QPDFObjectHandle::newName("/EmbeddedFile"));
+ stream.getDict().replaceKey("/Type", QPDFObjectHandle::newName("/EmbeddedFile"));
Pl_Discard discard;
// The PDF spec specifies use of MD5 here and notes that it is not
// to be used for security. MD5 is known to be insecure.
Pl_MD5 md5("EF md5", &discard);
Pl_Count count("EF size", &md5);
if (!stream.pipeStreamData(&count, nullptr, 0, qpdf_dl_all)) {
- stream.warnIfPossible(
- "unable to get stream data for new embedded file stream");
+ stream.warnIfPossible("unable to get stream data for new embedded file stream");
} else {
+ result.setParam("/Size", QPDFObjectHandle::newInteger(count.getCount()));
result.setParam(
- "/Size", QPDFObjectHandle::newInteger(count.getCount()));
- result.setParam(
- "/CheckSum",
- QPDFObjectHandle::newString(QUtil::hex_decode(md5.getHexDigest())));
+ "/CheckSum", QPDFObjectHandle::newString(QUtil::hex_decode(md5.getHexDigest())));
}
return result;
}
diff --git a/libqpdf/QPDFEmbeddedFileDocumentHelper.cc b/libqpdf/QPDFEmbeddedFileDocumentHelper.cc
index 25c3c6ae..d1c7a05c 100644
--- a/libqpdf/QPDFEmbeddedFileDocumentHelper.cc
+++ b/libqpdf/QPDFEmbeddedFileDocumentHelper.cc
@@ -40,8 +40,7 @@ QPDFEmbeddedFileDocumentHelper::QPDFEmbeddedFileDocumentHelper(QPDF& qpdf) :
if (names.isDictionary()) {
auto embedded_files = names.getKey("/EmbeddedFiles");
if (embedded_files.isDictionary()) {
- m->embedded_files = std::make_shared<QPDFNameTreeObjectHelper>(
- embedded_files, qpdf);
+ m->embedded_files = std::make_shared<QPDFNameTreeObjectHelper>(embedded_files, qpdf);
}
}
}
@@ -61,8 +60,7 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles()
auto root = qpdf.getRoot();
auto names = root.getKey("/Names");
if (!names.isDictionary()) {
- names = root.replaceKeyAndGetNew(
- "/Names", QPDFObjectHandle::newDictionary());
+ names = root.replaceKeyAndGetNew("/Names", QPDFObjectHandle::newDictionary());
}
auto embedded_files = names.getKey("/EmbeddedFiles");
if (!embedded_files.isDictionary()) {
@@ -91,8 +89,7 @@ QPDFEmbeddedFileDocumentHelper::getEmbeddedFiles()
std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> result;
if (m->embedded_files) {
for (auto const& i: *(m->embedded_files)) {
- result[i.first] =
- std::make_shared<QPDFFileSpecObjectHelper>(i.second);
+ result[i.first] = std::make_shared<QPDFFileSpecObjectHelper>(i.second);
}
}
return result;
diff --git a/libqpdf/QPDFFileSpecObjectHelper.cc b/libqpdf/QPDFFileSpecObjectHelper.cc
index fcc19b45..eada4613 100644
--- a/libqpdf/QPDFFileSpecObjectHelper.cc
+++ b/libqpdf/QPDFFileSpecObjectHelper.cc
@@ -19,8 +19,7 @@ QPDFFileSpecObjectHelper::QPDFFileSpecObjectHelper(QPDFObjectHandle oh) :
}
}
-static std::vector<std::string> name_keys = {
- "/UF", "/F", "/Unix", "/DOS", "/Mac"};
+static std::vector<std::string> name_keys = {"/UF", "/F", "/Unix", "/DOS", "/Mac"};
std::string
QPDFFileSpecObjectHelper::getDescription()
@@ -90,8 +89,7 @@ QPDFFileSpecObjectHelper::createFileSpec(
return createFileSpec(
qpdf,
filename,
- QPDFEFStreamObjectHelper::createEFStream(
- qpdf, QUtil::file_provider(fullpath)));
+ QPDFEFStreamObjectHelper::createEFStream(qpdf, QUtil::file_provider(fullpath)));
}
QPDFFileSpecObjectHelper
diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc
index 255270a8..ef5570f3 100644
--- a/libqpdf/QPDFFormFieldObjectHelper.cc
+++ b/libqpdf/QPDFFormFieldObjectHelper.cc
@@ -76,9 +76,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name)
node = node.getKey("/Parent");
result = node.getKey(name);
if (!result.isNull()) {
- QTC::TC(
- "qpdf",
- "QPDFFormFieldObjectHelper non-trivial inheritance");
+ QTC::TC("qpdf", "QPDFFormFieldObjectHelper non-trivial inheritance");
return result;
}
}
@@ -87,8 +85,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name)
}
std::string
-QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(
- std::string const& name)
+QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& name)
{
QPDFObjectHandle fv = getInheritableFieldValue(name);
std::string result;
@@ -99,8 +96,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(
}
std::string
-QPDFFormFieldObjectHelper::getInheritableFieldValueAsName(
- std::string const& name)
+QPDFFormFieldObjectHelper::getInheritableFieldValueAsName(std::string const& name)
{
QPDFObjectHandle fv = getInheritableFieldValue(name);
std::string result;
@@ -125,9 +121,7 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName()
while (!node.isNull() && seen.add(node)) {
if (node.getKey("/T").isString()) {
if (!result.empty()) {
- QTC::TC(
- "qpdf",
- "QPDFFormFieldObjectHelper non-trivial qualified name");
+ QTC::TC("qpdf", "QPDFFormFieldObjectHelper non-trivial qualified name");
result = "." + result;
}
result = node.getKey("/T").getUTF8Value() + result;
@@ -210,10 +204,7 @@ QPDFFormFieldObjectHelper::getDefaultAppearance()
}
std::string result;
if (value.isString()) {
- QTC::TC(
- "qpdf",
- "QPDFFormFieldObjectHelper DA present",
- looked_in_acroform ? 0 : 1);
+ QTC::TC("qpdf", "QPDFFormFieldObjectHelper DA present", looked_in_acroform ? 0 : 1);
result = value.getUTF8Value();
}
return result;
@@ -230,10 +221,7 @@ QPDFFormFieldObjectHelper::getQuadding()
}
int result = 0;
if (fv.isInteger()) {
- QTC::TC(
- "qpdf",
- "QPDFFormFieldObjectHelper Q present",
- looked_in_acroform ? 0 : 1);
+ QTC::TC("qpdf", "QPDFFormFieldObjectHelper Q present", looked_in_acroform ? 0 : 1);
result = QIntC::to_int(fv.getIntValue());
}
return result;
@@ -255,25 +243,19 @@ QPDFFormFieldObjectHelper::isText()
bool
QPDFFormFieldObjectHelper::isCheckbox()
{
- return (
- (getFieldType() == "/Btn") &&
- ((getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0));
+ return ((getFieldType() == "/Btn") && ((getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0));
}
bool
QPDFFormFieldObjectHelper::isRadioButton()
{
- return (
- (getFieldType() == "/Btn") &&
- ((getFlags() & ff_btn_radio) == ff_btn_radio));
+ return ((getFieldType() == "/Btn") && ((getFlags() & ff_btn_radio) == ff_btn_radio));
}
bool
QPDFFormFieldObjectHelper::isPushbutton()
{
- return (
- (getFieldType() == "/Btn") &&
- ((getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton));
+ return ((getFieldType() == "/Btn") && ((getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton));
}
bool
@@ -303,15 +285,13 @@ QPDFFormFieldObjectHelper::getChoices()
}
void
-QPDFFormFieldObjectHelper::setFieldAttribute(
- std::string const& key, QPDFObjectHandle value)
+QPDFFormFieldObjectHelper::setFieldAttribute(std::string const& key, QPDFObjectHandle value)
{
this->oh.replaceKey(key, value);
}
void
-QPDFFormFieldObjectHelper::setFieldAttribute(
- std::string const& key, std::string const& utf8_value)
+QPDFFormFieldObjectHelper::setFieldAttribute(std::string const& key, std::string const& utf8_value)
{
this->oh.replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value));
}
@@ -330,41 +310,36 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances)
}
}
if (!okay) {
- this->oh.warnIfPossible(
- "ignoring attempt to set a checkbox field to a"
- " value of other than /Yes or /Off");
+ this->oh.warnIfPossible("ignoring attempt to set a checkbox field to a"
+ " value of other than /Yes or /Off");
}
} else if (isRadioButton()) {
if (value.isName()) {
setRadioButtonValue(value);
} else {
- this->oh.warnIfPossible(
- "ignoring attempt to set a radio button field to"
- " an object that is not a name");
+ this->oh.warnIfPossible("ignoring attempt to set a radio button field to"
+ " an object that is not a name");
}
} else if (isPushbutton()) {
- this->oh.warnIfPossible(
- "ignoring attempt set the value of a pushbutton field");
+ this->oh.warnIfPossible("ignoring attempt set the value of a pushbutton field");
}
return;
}
if (value.isString()) {
- setFieldAttribute(
- "/V", QPDFObjectHandle::newUnicodeString(value.getUTF8Value()));
+ setFieldAttribute("/V", QPDFObjectHandle::newUnicodeString(value.getUTF8Value()));
} else {
setFieldAttribute("/V", value);
}
if (need_appearances) {
- QPDF& qpdf = this->oh.getQPDF(
- "QPDFFormFieldObjectHelper::setV called with need_appearances = "
- "true on an object that is not associated with an owning QPDF");
+ QPDF& qpdf =
+ this->oh.getQPDF("QPDFFormFieldObjectHelper::setV called with need_appearances = "
+ "true on an object that is not associated with an owning QPDF");
QPDFAcroFormDocumentHelper(qpdf).setNeedAppearances(true);
}
}
void
-QPDFFormFieldObjectHelper::setV(
- std::string const& utf8_value, bool need_appearances)
+QPDFFormFieldObjectHelper::setV(std::string const& utf8_value, bool need_appearances)
{
setV(QPDFObjectHandle::newUnicodeString(utf8_value), need_appearances);
}
@@ -390,8 +365,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name)
if (ph.isRadioButton()) {
// This is most likely one of the individual buttons. Try
// calling on the parent.
- QTC::TC(
- "qpdf", "QPDFFormFieldObjectHelper set parent radio button");
+ QTC::TC("qpdf", "QPDFFormFieldObjectHelper set parent radio button");
ph.setRadioButtonValue(name);
return;
}
@@ -419,9 +393,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name)
QPDFObjectHandle grandkid = grandkids.getArrayItem(j);
AP = grandkid.getKey("/AP");
if (!AP.isNull()) {
- QTC::TC(
- "qpdf",
- "QPDFFormFieldObjectHelper radio button grandkid");
+ QTC::TC("qpdf", "QPDFFormFieldObjectHelper radio button grandkid");
annot = grandkid;
break;
}
@@ -432,8 +404,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name)
}
if (!annot.isInitialized()) {
QTC::TC("qpdf", "QPDFObjectHandle broken radio button");
- this->oh.warnIfPossible(
- "unable to set the value of this radio button");
+ this->oh.warnIfPossible("unable to set the value of this radio button");
continue;
}
if (AP.isDictionary() && AP.getKey("/N").isDictionary() &&
@@ -465,9 +436,7 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value)
QPDFObjectHandle kid = kids.getArrayItem(i);
AP = kid.getKey("/AP");
if (!AP.isNull()) {
- QTC::TC(
- "qpdf",
- "QPDFFormFieldObjectHelper checkbox kid widget");
+ QTC::TC("qpdf", "QPDFFormFieldObjectHelper checkbox kid widget");
annot = kid;
break;
}
@@ -555,8 +524,7 @@ ValueSetter::handleToken(QPDFTokenizer::Token const& token)
break;
case st_bmc:
- if ((ttype == QPDFTokenizer::tt_space) ||
- (ttype == QPDFTokenizer::tt_comment)) {
+ if ((ttype == QPDFTokenizer::tt_space) || (ttype == QPDFTokenizer::tt_comment)) {
writeToken(token);
} else {
state = st_emc;
@@ -642,9 +610,7 @@ ValueSetter::writeAppearance()
}
highlight = true;
highlight_idx = found_idx - QIntC::to_size(wanted_first);
- for (size_t i = QIntC::to_size(wanted_first);
- i <= QIntC::to_size(wanted_last);
- ++i) {
+ for (size_t i = QIntC::to_size(wanted_first); i <= QIntC::to_size(wanted_last); ++i) {
lines.push_back(opt.at(i));
}
} else {
@@ -661,14 +627,12 @@ ValueSetter::writeAppearance()
// Write the lines centered vertically, highlighting if needed
size_t nlines = lines.size();
- double dy = bbox.ury -
- ((bbox.ury - bbox.lly - (static_cast<double>(nlines) * tfh)) / 2.0);
+ double dy = bbox.ury - ((bbox.ury - bbox.lly - (static_cast<double>(nlines) * tfh)) / 2.0);
if (highlight) {
write(
"q\n0.85 0.85 0.85 rg\n" + QUtil::double_to_string(bbox.llx) + " " +
QUtil::double_to_string(
- bbox.lly + dy -
- (tfh * (static_cast<double>(highlight_idx + 1)))) +
+ bbox.lly + dy - (tfh * (static_cast<double>(highlight_idx + 1)))) +
" " + QUtil::double_to_string(bbox.urx - bbox.llx) + " " +
QUtil::double_to_string(tfh) + " re f\nQ\n");
}
@@ -681,10 +645,8 @@ ValueSetter::writeAppearance()
// which doesn't seem really worth the effort.
if (i == 0) {
write(
- QUtil::double_to_string(bbox.llx + static_cast<double>(dx)) +
- " " +
- QUtil::double_to_string(bbox.lly + static_cast<double>(dy)) +
- " Td\n");
+ QUtil::double_to_string(bbox.llx + static_cast<double>(dx)) + " " +
+ QUtil::double_to_string(bbox.lly + static_cast<double>(dy)) + " Td\n");
} else {
write("0 " + QUtil::double_to_string(-tfh) + " Td\n");
}
@@ -794,8 +756,7 @@ TfFinder::getFontName()
}
QPDFObjectHandle
-QPDFFormFieldObjectHelper::getFontFromResource(
- QPDFObjectHandle resources, std::string const& name)
+QPDFFormFieldObjectHelper::getFontFromResource(QPDFObjectHandle resources, std::string const& name)
{
QPDFObjectHandle result;
if (resources.isDictionary() && resources.getKey("/Font").isDictionary() &&
@@ -806,40 +767,34 @@ QPDFFormFieldObjectHelper::getFontFromResource(
}
void
-QPDFFormFieldObjectHelper::generateTextAppearance(
- QPDFAnnotationObjectHelper& aoh)
+QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& aoh)
{
QPDFObjectHandle AS = aoh.getAppearanceStream("/N");
if (AS.isNull()) {
QTC::TC("qpdf", "QPDFFormFieldObjectHelper create AS from scratch");
QPDFObjectHandle::Rectangle rect = aoh.getRect();
- QPDFObjectHandle::Rectangle bbox(
- 0, 0, rect.urx - rect.llx, rect.ury - rect.lly);
- QPDFObjectHandle dict = QPDFObjectHandle::parse(
- "<< /Resources << /ProcSet [ /PDF /Text ] >>"
- " /Type /XObject /Subtype /Form >>");
+ QPDFObjectHandle::Rectangle bbox(0, 0, rect.urx - rect.llx, rect.ury - rect.lly);
+ QPDFObjectHandle dict =
+ QPDFObjectHandle::parse("<< /Resources << /ProcSet [ /PDF /Text ] >>"
+ " /Type /XObject /Subtype /Form >>");
dict.replaceKey("/BBox", QPDFObjectHandle::newFromRectangle(bbox));
- AS = QPDFObjectHandle::newStream(
- this->oh.getOwningQPDF(), "/Tx BMC\nEMC\n");
+ AS = QPDFObjectHandle::newStream(this->oh.getOwningQPDF(), "/Tx BMC\nEMC\n");
AS.replaceDict(dict);
QPDFObjectHandle AP = aoh.getAppearanceDictionary();
if (AP.isNull()) {
QTC::TC("qpdf", "QPDFFormFieldObjectHelper create AP from scratch");
- aoh.getObjectHandle().replaceKey(
- "/AP", QPDFObjectHandle::newDictionary());
+ aoh.getObjectHandle().replaceKey("/AP", QPDFObjectHandle::newDictionary());
AP = aoh.getAppearanceDictionary();
}
AP.replaceKey("/N", AS);
}
if (!AS.isStream()) {
- aoh.getObjectHandle().warnIfPossible(
- "unable to get normal appearance stream for update");
+ aoh.getObjectHandle().warnIfPossible("unable to get normal appearance stream for update");
return;
}
QPDFObjectHandle bbox_obj = AS.getDict().getKey("/BBox");
if (!bbox_obj.isRectangle()) {
- aoh.getObjectHandle().warnIfPossible(
- "unable to get appearance stream bounding box");
+ aoh.getObjectHandle().warnIfPossible("unable to get appearance stream bounding box");
return;
}
QPDFObjectHandle::Rectangle bbox = bbox_obj.getArrayAsRectangle();
@@ -872,8 +827,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(
if (found_font_in_dr && resources.isDictionary()) {
QTC::TC("qpdf", "QPDFFormFieldObjectHelper get font from /DR");
if (resources.isIndirect()) {
- resources = resources.getQPDF().makeIndirectObject(
- resources.shallowCopy());
+ resources = resources.getQPDF().makeIndirectObject(resources.shallowCopy());
AS.getDict().replaceKey("/Resources", resources);
}
// Use mergeResources to force /Font to be local
@@ -899,6 +853,5 @@ QPDFFormFieldObjectHelper::generateTextAppearance(
AS.addTokenFilter(
// line-break
- std::shared_ptr<QPDFObjectHandle::TokenFilter>(
- new ValueSetter(DA, V, opt, tf, bbox)));
+ std::shared_ptr<QPDFObjectHandle::TokenFilter>(new ValueSetter(DA, V, opt, tf, bbox)));
}
diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc
index f785d668..50ea5ea7 100644
--- a/libqpdf/QPDFJob.cc
+++ b/libqpdf/QPDFJob.cc
@@ -50,8 +50,7 @@ namespace
QPDFObjectHandle& image);
~ImageOptimizer() override = default;
void provideStreamData(QPDFObjGen const&, Pipeline* pipeline) override;
- std::shared_ptr<Pipeline>
- makePipeline(std::string const& description, Pipeline* next);
+ std::shared_ptr<Pipeline> makePipeline(std::string const& description, Pipeline* next);
bool evaluate(std::string const& description);
private:
@@ -78,8 +77,7 @@ namespace
struct QPDFPageData
{
- QPDFPageData(
- std::string const& filename, QPDF* qpdf, std::string const& range);
+ QPDFPageData(std::string const& filename, QPDF* qpdf, std::string const& range);
QPDFPageData(QPDFPageData const& other, int page);
std::string filename;
@@ -91,8 +89,7 @@ namespace
class ProgressReporter: public QPDFWriter::ProgressReporter
{
public:
- ProgressReporter(
- Pipeline& p, std::string const& prefix, char const* filename) :
+ ProgressReporter(Pipeline& p, std::string const& prefix, char const* filename) :
p(p),
prefix(prefix),
filename(filename)
@@ -133,8 +130,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next)
if (!(w_obj.isNumber() && h_obj.isNumber())) {
if (!description.empty()) {
o.doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << prefix << ": " << description
- << ": not optimizing because image dictionary"
+ v << prefix << ": " << description << ": not optimizing because image dictionary"
<< " is missing required keys\n";
});
}
@@ -166,8 +162,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next)
} else {
h = static_cast<JDIMENSION>(h_obj.getNumericValue());
}
- std::string colorspace =
- (colorspace_obj.isName() ? colorspace_obj.getName() : std::string());
+ std::string colorspace = (colorspace_obj.isName() ? colorspace_obj.getName() : std::string());
int components = 0;
J_COLOR_SPACE cs = JCS_UNKNOWN;
if (colorspace == "/DeviceRGB") {
@@ -183,8 +178,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next)
QTC::TC("qpdf", "QPDFJob image optimize colorspace");
if (!description.empty()) {
o.doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << prefix << ": " << description
- << ": not optimizing because qpdf can't optimize"
+ v << prefix << ": " << description << ": not optimizing because qpdf can't optimize"
<< " images with this colorspace\n";
});
}
@@ -196,8 +190,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next)
QTC::TC("qpdf", "QPDFJob image optimize too small");
if (!description.empty()) {
o.doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << prefix << ": " << description
- << ": not optimizing because image"
+ v << prefix << ": " << description << ": not optimizing because image"
<< " is smaller than requested minimum dimensions\n";
});
}
@@ -214,8 +207,7 @@ ImageOptimizer::evaluate(std::string const& description)
if (!image.pipeStreamData(nullptr, 0, qpdf_dl_specialized, true)) {
QTC::TC("qpdf", "QPDFJob image optimize no pipeline");
o.doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << prefix << ": " << description
- << ": not optimizing because unable to decode data"
+ v << prefix << ": " << description << ": not optimizing because unable to decode data"
<< " or data already uses DCT\n";
});
return false;
@@ -241,9 +233,8 @@ ImageOptimizer::evaluate(std::string const& description)
return false;
}
o.doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << prefix << ": " << description
- << ": optimizing image reduces size from " << orig_length << " to "
- << c.getCount() << "\n";
+ v << prefix << ": " << description << ": optimizing image reduces size from " << orig_length
+ << " to " << c.getCount() << "\n";
});
return true;
}
@@ -263,9 +254,7 @@ ImageOptimizer::provideStreamData(QPDFObjGen const&, Pipeline* pipeline)
}
QPDFJob::PageSpec::PageSpec(
- std::string const& filename,
- char const* password,
- std::string const& range) :
+ std::string const& filename, char const* password, std::string const& range) :
filename(filename),
range(range)
{
@@ -274,18 +263,16 @@ QPDFJob::PageSpec::PageSpec(
}
}
-QPDFPageData::QPDFPageData(
- std::string const& filename, QPDF* qpdf, std::string const& range) :
+QPDFPageData::QPDFPageData(std::string const& filename, QPDF* qpdf, std::string const& range) :
filename(filename),
qpdf(qpdf),
orig_pages(qpdf->getAllPages())
{
try {
- this->selected_pages = QUtil::parse_numrange(
- range.c_str(), QIntC::to_int(this->orig_pages.size()));
+ this->selected_pages =
+ QUtil::parse_numrange(range.c_str(), QIntC::to_int(this->orig_pages.size()));
} catch (std::runtime_error& e) {
- throw std::runtime_error(
- "parsing numeric range for " + filename + ": " + e.what());
+ throw std::runtime_error("parsing numeric range for " + filename + ": " + e.what());
}
}
@@ -300,8 +287,7 @@ QPDFPageData::QPDFPageData(QPDFPageData const& other, int page) :
void
ProgressReporter::reportProgress(int percentage)
{
- this->p << prefix << ": " << filename << ": write progress: " << percentage
- << "%\n";
+ this->p << prefix << ": " << filename << ": write progress: " << percentage << "%\n";
}
QPDFJob::Members::Members() :
@@ -358,8 +344,7 @@ QPDFJob::registerProgressReporter(std::function<void(int)> handler)
}
void
-QPDFJob::doIfVerbose(
- std::function<void(Pipeline&, std::string const& prefix)> fn)
+QPDFJob::doIfVerbose(std::function<void(Pipeline&, std::string const& prefix)> fn)
{
if (m->verbose) {
fn(*m->log->getInfo(), m->message_prefix);
@@ -459,8 +444,7 @@ QPDFJob::createQPDF()
// Allow certain operations to work when an incorrect
// password is supplied.
if (m->check_is_encrypted || m->check_requires_password) {
- m->encryption_status =
- qpdf_es_encrypted | qpdf_es_password_incorrect;
+ m->encryption_status = qpdf_es_encrypted | qpdf_es_password_incorrect;
return nullptr;
}
if (m->show_encryption && pdf_sp) {
@@ -513,12 +497,10 @@ QPDFJob::writeQPDF(QPDF& pdf)
}
if (m->warnings && (!m->suppress_warnings)) {
if (createsOutput()) {
- *m->log->getWarn()
- << m->message_prefix << ": operation succeeded with warnings;"
- << " resulting file may have some problems\n";
+ *m->log->getWarn() << m->message_prefix << ": operation succeeded with warnings;"
+ << " resulting file may have some problems\n";
} else {
- *m->log->getWarn()
- << m->message_prefix << ": operation succeeded with warnings\n";
+ *m->log->getWarn() << m->message_prefix << ": operation succeeded with warnings\n";
}
}
if (m->report_mem_usage) {
@@ -611,13 +593,9 @@ QPDFJob::checkConfiguration()
usage("an input file name is required");
} else if (m->replace_input && (strlen(m->infilename.get()) == 0)) {
usage("--replace-input may not be used with --empty");
- } else if (
- m->require_outfile && (m->outfilename == nullptr) &&
- (!m->replace_input)) {
+ } else if (m->require_outfile && (m->outfilename == nullptr) && (!m->replace_input)) {
usage("an output file name is required; use - for standard output");
- } else if (
- (!m->require_outfile) &&
- ((m->outfilename != nullptr) || m->replace_input)) {
+ } else if ((!m->require_outfile) && ((m->outfilename != nullptr) || m->replace_input)) {
usage("no output file may be given for this option");
}
if (m->check_requires_password && m->check_is_encrypted) {
@@ -626,8 +604,7 @@ QPDFJob::checkConfiguration()
}
if (m->encrypt && (!m->allow_insecure) &&
- (m->owner_password.empty() && (!m->user_password.empty()) &&
- (m->keylen == 256))) {
+ (m->owner_password.empty() && (!m->user_password.empty()) && (m->keylen == 256))) {
// Note that empty owner passwords for R < 5 are copied from
// the user password, so this lack of security is not an issue
// for those files. Also we are consider only the ability to
@@ -642,8 +619,7 @@ QPDFJob::checkConfiguration()
}
bool save_to_stdout = false;
- if (m->require_outfile && m->outfilename &&
- (strcmp(m->outfilename.get(), "-") == 0)) {
+ if (m->require_outfile && m->outfilename && (strcmp(m->outfilename.get(), "-") == 0)) {
if (m->split_pages) {
usage("--split-pages may not be used when"
" writing to standard output");
@@ -656,8 +632,7 @@ QPDFJob::checkConfiguration()
if (save_to_stdout) {
m->log->saveToStandardOutput(true);
}
- if ((!m->split_pages) &&
- QUtil::same_file(m->infilename.get(), m->outfilename.get())) {
+ if ((!m->split_pages) && QUtil::same_file(m->infilename.get(), m->outfilename.get())) {
QTC::TC("qpdf", "QPDFJob same file error");
usage("input file and output file are the same;"
" use --replace-input to intentionally"
@@ -751,8 +726,7 @@ QPDFJob::showEncryption(QPDF& pdf)
std::string encryption_key = pdf.getEncryptionKey();
cout << "User password = " << user_password << "\n";
if (m->show_encryption_key) {
- cout << "Encryption key = " << QUtil::hex_encode(encryption_key)
- << "\n";
+ cout << "Encryption key = " << QUtil::hex_encode(encryption_key) << "\n";
}
if (pdf.ownerPasswordMatched()) {
cout << "Supplied password is owner password\n";
@@ -760,28 +734,19 @@ QPDFJob::showEncryption(QPDF& pdf)
if (pdf.userPasswordMatched()) {
cout << "Supplied password is user password\n";
}
- cout << "extract for accessibility: "
- << show_bool(pdf.allowAccessibility()) << "\n"
- << "extract for any purpose: " << show_bool(pdf.allowExtractAll())
- << "\n"
- << "print low resolution: " << show_bool(pdf.allowPrintLowRes())
- << "\n"
- << "print high resolution: " << show_bool(pdf.allowPrintHighRes())
- << "\n"
- << "modify document assembly: "
- << show_bool(pdf.allowModifyAssembly()) << "\n"
+ cout << "extract for accessibility: " << show_bool(pdf.allowAccessibility()) << "\n"
+ << "extract for any purpose: " << show_bool(pdf.allowExtractAll()) << "\n"
+ << "print low resolution: " << show_bool(pdf.allowPrintLowRes()) << "\n"
+ << "print high resolution: " << show_bool(pdf.allowPrintHighRes()) << "\n"
+ << "modify document assembly: " << show_bool(pdf.allowModifyAssembly()) << "\n"
<< "modify forms: " << show_bool(pdf.allowModifyForm()) << "\n"
- << "modify annotations: " << show_bool(pdf.allowModifyAnnotation())
- << "\n"
+ << "modify annotations: " << show_bool(pdf.allowModifyAnnotation()) << "\n"
<< "modify other: " << show_bool(pdf.allowModifyOther()) << "\n"
<< "modify anything: " << show_bool(pdf.allowModifyAll()) << "\n";
if (V >= 4) {
- cout << "stream encryption method: "
- << show_encryption_method(stream_method) << "\n"
- << "string encryption method: "
- << show_encryption_method(string_method) << "\n"
- << "file encryption method: "
- << show_encryption_method(file_method) << "\n";
+ cout << "stream encryption method: " << show_encryption_method(stream_method) << "\n"
+ << "string encryption method: " << show_encryption_method(string_method) << "\n"
+ << "file encryption method: " << show_encryption_method(file_method) << "\n";
}
}
}
@@ -830,8 +795,7 @@ QPDFJob::doCheck(QPDF& pdf)
page.parseContents(&discard_contents);
} catch (QPDFExc& e) {
okay = false;
- *m->log->getError()
- << "ERROR: page " << pageno << ": " << e.what() << "\n";
+ *m->log->getError() << "ERROR: page " << pageno << ": " << e.what() << "\n";
}
}
} catch (std::exception& e) {
@@ -885,8 +849,7 @@ QPDFJob::doShowObj(QPDF& pdf)
*m->log->getInfo() << obj.unparseResolved() << "\n";
}
if (error) {
- throw std::runtime_error(
- "unable to get object " + obj.getObjGen().unparse(','));
+ throw std::runtime_error("unable to get object " + obj.getObjGen().unparse(','));
}
}
@@ -899,8 +862,8 @@ QPDFJob::doShowPages(QPDF& pdf)
QPDFObjectHandle page = ph.getObjectHandle();
++pageno;
- cout << "page " << pageno << ": " << page.getObjectID() << " "
- << page.getGeneration() << " R\n";
+ cout << "page " << pageno << ": " << page.getObjectID() << " " << page.getGeneration()
+ << " R\n";
if (m->show_page_images) {
std::map<std::string, QPDFObjectHandle> images = ph.getImages();
if (!images.empty()) {
@@ -911,8 +874,8 @@ QPDFJob::doShowPages(QPDF& pdf)
QPDFObjectHandle dict = image.getDict();
int width = dict.getKey("/Width").getIntValueAsInt();
int height = dict.getKey("/Height").getIntValueAsInt();
- cout << " " << name << ": " << image.unparse() << ", "
- << width << " x " << height << "\n";
+ cout << " " << name << ": " << image.unparse() << ", " << width << " x "
+ << height << "\n";
}
}
}
@@ -932,10 +895,8 @@ QPDFJob::doListAttachments(QPDF& pdf)
for (auto const& i: efdh.getEmbeddedFiles()) {
std::string const& key = i.first;
auto efoh = i.second;
- *m->log->getInfo()
- << key << " -> "
- << efoh->getEmbeddedFileStream().getObjGen().unparse(',')
- << "\n";
+ *m->log->getInfo() << key << " -> "
+ << efoh->getEmbeddedFileStream().getObjGen().unparse(',') << "\n";
doIfVerbose([&](Pipeline& v, std::string const& prefix) {
auto desc = efoh->getDescription();
if (!desc.empty()) {
@@ -951,12 +912,10 @@ QPDFJob::doListAttachments(QPDF& pdf)
auto efs = QPDFEFStreamObjectHelper(i2.second);
v << " " << i2.first << " -> "
<< efs.getObjectHandle().getObjGen().unparse(',') << "\n";
- v << " creation date: " << efs.getCreationDate()
- << "\n"
+ v << " creation date: " << efs.getCreationDate() << "\n"
<< " modification date: " << efs.getModDate() << "\n"
<< " mime type: " << efs.getSubtype() << "\n"
- << " checksum: "
- << QUtil::hex_encode(efs.getChecksum()) << "\n";
+ << " checksum: " << QUtil::hex_encode(efs.getChecksum()) << "\n";
}
});
}
@@ -971,8 +930,7 @@ QPDFJob::doShowAttachment(QPDF& pdf)
QPDFEmbeddedFileDocumentHelper efdh(pdf);
auto fs = efdh.getEmbeddedFile(m->attachment_to_show);
if (!fs) {
- throw std::runtime_error(
- "attachment " + m->attachment_to_show + " not found");
+ throw std::runtime_error("attachment " + m->attachment_to_show + " not found");
}
auto efs = fs->getEmbeddedFileStream();
// saveToStandardOutput has already been called, but it's harmless
@@ -982,8 +940,7 @@ QPDFJob::doShowAttachment(QPDF& pdf)
}
void
-QPDFJob::parse_object_id(
- std::string const& objspec, bool& trailer, int& obj, int& gen)
+QPDFJob::parse_object_id(std::string const& objspec, bool& trailer, int& obj, int& gen)
{
if (objspec == "trailer") {
trailer = true;
@@ -992,8 +949,7 @@ QPDFJob::parse_object_id(
obj = QUtil::string_to_int(objspec.c_str());
size_t comma = objspec.find(',');
if ((comma != std::string::npos) && (comma + 1 < objspec.length())) {
- gen = QUtil::string_to_int(
- objspec.substr(1 + comma, std::string::npos).c_str());
+ gen = QUtil::string_to_int(objspec.substr(1 + comma, std::string::npos).c_str());
}
}
}
@@ -1013,8 +969,7 @@ QPDFJob::getWantedJSONObjects()
}
void
-QPDFJob::doJSONObject(
- Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj)
+QPDFJob::doJSONObject(Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj)
{
if (m->json_version == 1) {
JSON::writeDictionaryItem(p, first, key, obj.getJSON(1, true), 2);
@@ -1022,8 +977,7 @@ QPDFJob::doJSONObject(
auto j = JSON::makeDictionary();
if (obj.isStream()) {
j.addDictionaryMember("stream", JSON::makeDictionary())
- .addDictionaryMember(
- "dict", obj.getDict().getJSON(m->json_version, true));
+ .addDictionaryMember("dict", obj.getDict().getJSON(m->json_version, true));
} else {
j.addDictionaryMember("value", obj.getJSON(m->json_version, true));
}
@@ -1085,22 +1039,18 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf)
for (auto& obj: pdf.getAllObjects()) {
if (all_objects || wanted_og.count(obj.getObjGen())) {
auto j_details = JSON::makeDictionary();
- auto j_stream =
- j_details.addDictionaryMember("stream", JSON::makeDictionary());
+ auto j_stream = j_details.addDictionaryMember("stream", JSON::makeDictionary());
bool is_stream = obj.isStream();
j_stream.addDictionaryMember("is", JSON::makeBool(is_stream));
j_stream.addDictionaryMember(
"length",
- (is_stream ? obj.getDict().getKey("/Length").getJSON(
- m->json_version, true)
+ (is_stream ? obj.getDict().getKey("/Length").getJSON(m->json_version, true)
: JSON::makeNull()));
j_stream.addDictionaryMember(
"filter",
- (is_stream ? obj.getDict().getKey("/Filter").getJSON(
- m->json_version, true)
+ (is_stream ? obj.getDict().getKey("/Filter").getJSON(m->json_version, true)
: JSON::makeNull()));
- JSON::writeDictionaryItem(
- p, first_object, obj.unparse(), j_details, 2);
+ JSON::writeDictionaryItem(p, first_object, obj.unparse(), j_details, 2);
}
}
JSON::writeDictionaryClose(p, first_object, 1);
@@ -1126,21 +1076,15 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
j_image.addDictionaryMember("name", JSON::makeString(iter2.first));
QPDFObjectHandle image = iter2.second;
QPDFObjectHandle dict = image.getDict();
+ j_image.addDictionaryMember("object", image.getJSON(m->json_version));
+ j_image.addDictionaryMember("width", dict.getKey("/Width").getJSON(m->json_version));
+ j_image.addDictionaryMember("height", dict.getKey("/Height").getJSON(m->json_version));
j_image.addDictionaryMember(
- "object", image.getJSON(m->json_version));
- j_image.addDictionaryMember(
- "width", dict.getKey("/Width").getJSON(m->json_version));
- j_image.addDictionaryMember(
- "height", dict.getKey("/Height").getJSON(m->json_version));
- j_image.addDictionaryMember(
- "colorspace",
- dict.getKey("/ColorSpace").getJSON(m->json_version));
+ "colorspace", dict.getKey("/ColorSpace").getJSON(m->json_version));
j_image.addDictionaryMember(
- "bitspercomponent",
- dict.getKey("/BitsPerComponent").getJSON(m->json_version));
+ "bitspercomponent", dict.getKey("/BitsPerComponent").getJSON(m->json_version));
QPDFObjectHandle filters = dict.getKey("/Filter").wrapInArray();
- j_image.addDictionaryMember(
- "filter", filters.getJSON(m->json_version));
+ j_image.addDictionaryMember("filter", filters.getJSON(m->json_version));
QPDFObjectHandle decode_parms = dict.getKey("/DecodeParms");
QPDFObjectHandle dp_array;
if (decode_parms.isArray()) {
@@ -1151,33 +1095,25 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
dp_array.appendItem(decode_parms);
}
}
- j_image.addDictionaryMember(
- "decodeparms", dp_array.getJSON(m->json_version));
+ j_image.addDictionaryMember("decodeparms", dp_array.getJSON(m->json_version));
j_image.addDictionaryMember(
"filterable",
- JSON::makeBool(
- image.pipeStreamData(nullptr, 0, m->decode_level, true)));
+ JSON::makeBool(image.pipeStreamData(nullptr, 0, m->decode_level, true)));
}
j_page.addDictionaryMember("images", j_images);
- JSON j_contents =
- j_page.addDictionaryMember("contents", JSON::makeArray());
+ JSON j_contents = j_page.addDictionaryMember("contents", JSON::makeArray());
for (auto& iter2: ph.getPageContents()) {
j_contents.addArrayElement(iter2.getJSON(m->json_version));
}
- j_page.addDictionaryMember(
- "label", pldh.getLabelForPage(pageno).getJSON(m->json_version));
- JSON j_outlines =
- j_page.addDictionaryMember("outlines", JSON::makeArray());
- std::vector<QPDFOutlineObjectHelper> outlines =
- odh.getOutlinesForPage(page.getObjGen());
+ j_page.addDictionaryMember("label", pldh.getLabelForPage(pageno).getJSON(m->json_version));
+ JSON j_outlines = j_page.addDictionaryMember("outlines", JSON::makeArray());
+ std::vector<QPDFOutlineObjectHelper> outlines = odh.getOutlinesForPage(page.getObjGen());
for (auto& oiter: outlines) {
JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary());
j_outline.addDictionaryMember(
"object", oiter.getObjectHandle().getJSON(m->json_version));
- j_outline.addDictionaryMember(
- "title", JSON::makeString(oiter.getTitle()));
- j_outline.addDictionaryMember(
- "dest", oiter.getDest().getJSON(m->json_version, true));
+ j_outline.addDictionaryMember("title", JSON::makeString(oiter.getTitle()));
+ j_outline.addDictionaryMember("dest", oiter.getDest().getJSON(m->json_version, true));
}
j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno));
JSON::writeArrayItem(p, first_page, j_page, 2);
@@ -1190,8 +1126,7 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf)
{
JSON j_labels = JSON::makeArray();
QPDFPageLabelDocumentHelper pldh(pdf);
- long long npages =
- QIntC::to_longlong(QPDFPageDocumentHelper(pdf).getAllPages().size());
+ long long npages = QIntC::to_longlong(QPDFPageDocumentHelper(pdf).getAllPages().size());
if (pldh.hasPageLabels()) {
std::vector<QPDFObjectHandle> labels;
pldh.getLabelsForPageRange(0, npages - 1, 0, labels);
@@ -1203,11 +1138,9 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf)
break;
}
JSON j_label = j_labels.addArrayElement(JSON::makeDictionary());
- j_label.addDictionaryMember(
- "index", (*iter).getJSON(m->json_version));
+ j_label.addDictionaryMember("index", (*iter).getJSON(m->json_version));
++iter;
- j_label.addDictionaryMember(
- "label", (*iter).getJSON(m->json_version));
+ j_label.addDictionaryMember("label", (*iter).getJSON(m->json_version));
}
}
JSON::writeDictionaryItem(p, first, "pagelabels", j_labels, 1);
@@ -1215,17 +1148,13 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf)
void
QPDFJob::addOutlinesToJson(
- std::vector<QPDFOutlineObjectHelper> outlines,
- JSON& j,
- std::map<QPDFObjGen, int>& page_numbers)
+ std::vector<QPDFOutlineObjectHelper> outlines, JSON& j, std::map<QPDFObjGen, int>& page_numbers)
{
for (auto& ol: outlines) {
JSON jo = j.addArrayElement(JSON::makeDictionary());
- jo.addDictionaryMember(
- "object", ol.getObjectHandle().getJSON(m->json_version));
+ jo.addDictionaryMember("object", ol.getObjectHandle().getJSON(m->json_version));
jo.addDictionaryMember("title", JSON::makeString(ol.getTitle()));
- jo.addDictionaryMember(
- "dest", ol.getDest().getJSON(m->json_version, true));
+ jo.addDictionaryMember("dest", ol.getDest().getJSON(m->json_version, true));
jo.addDictionaryMember("open", JSON::makeBool(ol.getCount() >= 0));
QPDFObjectHandle page = ol.getDestPage();
JSON j_destpage = JSON::makeNull();
@@ -1262,10 +1191,8 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
{
JSON j_acroform = JSON::makeDictionary();
QPDFAcroFormDocumentHelper afdh(pdf);
- j_acroform.addDictionaryMember(
- "hasacroform", JSON::makeBool(afdh.hasAcroForm()));
- j_acroform.addDictionaryMember(
- "needappearances", JSON::makeBool(afdh.getNeedAppearances()));
+ j_acroform.addDictionaryMember("hasacroform", JSON::makeBool(afdh.hasAcroForm()));
+ j_acroform.addDictionaryMember("needappearances", JSON::makeBool(afdh.getNeedAppearances()));
JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray());
int pagepos1 = 0;
for (auto const& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
@@ -1273,52 +1200,34 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh);
JSON j_field = j_fields.addArrayElement(JSON::makeDictionary());
+ j_field.addDictionaryMember("object", ffh.getObjectHandle().getJSON(m->json_version));
j_field.addDictionaryMember(
- "object", ffh.getObjectHandle().getJSON(m->json_version));
- j_field.addDictionaryMember(
- "parent",
- ffh.getObjectHandle().getKey("/Parent").getJSON(
- m->json_version));
- j_field.addDictionaryMember(
- "pageposfrom1", JSON::makeInt(pagepos1));
- j_field.addDictionaryMember(
- "fieldtype", JSON::makeString(ffh.getFieldType()));
- j_field.addDictionaryMember(
- "fieldflags", JSON::makeInt(ffh.getFlags()));
- j_field.addDictionaryMember(
- "fullname", JSON::makeString(ffh.getFullyQualifiedName()));
- j_field.addDictionaryMember(
- "partialname", JSON::makeString(ffh.getPartialName()));
+ "parent", ffh.getObjectHandle().getKey("/Parent").getJSON(m->json_version));
+ j_field.addDictionaryMember("pageposfrom1", JSON::makeInt(pagepos1));
+ j_field.addDictionaryMember("fieldtype", JSON::makeString(ffh.getFieldType()));
+ j_field.addDictionaryMember("fieldflags", JSON::makeInt(ffh.getFlags()));
+ j_field.addDictionaryMember("fullname", JSON::makeString(ffh.getFullyQualifiedName()));
+ j_field.addDictionaryMember("partialname", JSON::makeString(ffh.getPartialName()));
j_field.addDictionaryMember(
"alternativename", JSON::makeString(ffh.getAlternativeName()));
- j_field.addDictionaryMember(
- "mappingname", JSON::makeString(ffh.getMappingName()));
- j_field.addDictionaryMember(
- "value", ffh.getValue().getJSON(m->json_version));
+ j_field.addDictionaryMember("mappingname", JSON::makeString(ffh.getMappingName()));
+ j_field.addDictionaryMember("value", ffh.getValue().getJSON(m->json_version));
j_field.addDictionaryMember(
"defaultvalue", ffh.getDefaultValue().getJSON(m->json_version));
- j_field.addDictionaryMember(
- "quadding", JSON::makeInt(ffh.getQuadding()));
- j_field.addDictionaryMember(
- "ischeckbox", JSON::makeBool(ffh.isCheckbox()));
- j_field.addDictionaryMember(
- "isradiobutton", JSON::makeBool(ffh.isRadioButton()));
- j_field.addDictionaryMember(
- "ischoice", JSON::makeBool(ffh.isChoice()));
+ j_field.addDictionaryMember("quadding", JSON::makeInt(ffh.getQuadding()));
+ j_field.addDictionaryMember("ischeckbox", JSON::makeBool(ffh.isCheckbox()));
+ j_field.addDictionaryMember("isradiobutton", JSON::makeBool(ffh.isRadioButton()));
+ j_field.addDictionaryMember("ischoice", JSON::makeBool(ffh.isChoice()));
j_field.addDictionaryMember("istext", JSON::makeBool(ffh.isText()));
- JSON j_choices =
- j_field.addDictionaryMember("choices", JSON::makeArray());
+ JSON j_choices = j_field.addDictionaryMember("choices", JSON::makeArray());
for (auto const& choice: ffh.getChoices()) {
j_choices.addArrayElement(JSON::makeString(choice));
}
- JSON j_annot = j_field.addDictionaryMember(
- "annotation", JSON::makeDictionary());
- j_annot.addDictionaryMember(
- "object", aoh.getObjectHandle().getJSON(m->json_version));
+ JSON j_annot = j_field.addDictionaryMember("annotation", JSON::makeDictionary());
+ j_annot.addDictionaryMember("object", aoh.getObjectHandle().getJSON(m->json_version));
j_annot.addDictionaryMember(
"appearancestate", JSON::makeString(aoh.getAppearanceState()));
- j_annot.addDictionaryMember(
- "annotationflags", JSON::makeInt(aoh.getFlags()));
+ j_annot.addDictionaryMember("annotationflags", JSON::makeInt(aoh.getFlags()));
}
}
JSON::writeDictionaryItem(p, first, "acroform", j_acroform, 1);
@@ -1333,50 +1242,34 @@ QPDFJob::doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf)
QPDF::encryption_method_e stream_method = QPDF::e_none;
QPDF::encryption_method_e string_method = QPDF::e_none;
QPDF::encryption_method_e file_method = QPDF::e_none;
- bool is_encrypted =
- pdf.isEncrypted(R, P, V, stream_method, string_method, file_method);
+ bool is_encrypted = pdf.isEncrypted(R, P, V, stream_method, string_method, file_method);
JSON j_encrypt = JSON::makeDictionary();
j_encrypt.addDictionaryMember("encrypted", JSON::makeBool(is_encrypted));
j_encrypt.addDictionaryMember(
- "userpasswordmatched",
- JSON::makeBool(is_encrypted && pdf.userPasswordMatched()));
+ "userpasswordmatched", JSON::makeBool(is_encrypted && pdf.userPasswordMatched()));
j_encrypt.addDictionaryMember(
- "ownerpasswordmatched",
- JSON::makeBool(is_encrypted && pdf.ownerPasswordMatched()));
- if (is_encrypted && (V < 5) && pdf.ownerPasswordMatched() &&
- (!pdf.userPasswordMatched())) {
+ "ownerpasswordmatched", JSON::makeBool(is_encrypted && pdf.ownerPasswordMatched()));
+ if (is_encrypted && (V < 5) && pdf.ownerPasswordMatched() && (!pdf.userPasswordMatched())) {
std::string user_password = pdf.getTrimmedUserPassword();
- j_encrypt.addDictionaryMember(
- "recovereduserpassword", JSON::makeString(user_password));
+ j_encrypt.addDictionaryMember("recovereduserpassword", JSON::makeString(user_password));
} else {
- j_encrypt.addDictionaryMember(
- "recovereduserpassword", JSON::makeNull());
- }
- JSON j_capabilities =
- j_encrypt.addDictionaryMember("capabilities", JSON::makeDictionary());
- j_capabilities.addDictionaryMember(
- "accessibility", JSON::makeBool(pdf.allowAccessibility()));
- j_capabilities.addDictionaryMember(
- "extract", JSON::makeBool(pdf.allowExtractAll()));
- j_capabilities.addDictionaryMember(
- "printlow", JSON::makeBool(pdf.allowPrintLowRes()));
- j_capabilities.addDictionaryMember(
- "printhigh", JSON::makeBool(pdf.allowPrintHighRes()));
- j_capabilities.addDictionaryMember(
- "modifyassembly", JSON::makeBool(pdf.allowModifyAssembly()));
- j_capabilities.addDictionaryMember(
- "modifyforms", JSON::makeBool(pdf.allowModifyForm()));
+ j_encrypt.addDictionaryMember("recovereduserpassword", JSON::makeNull());
+ }
+ JSON j_capabilities = j_encrypt.addDictionaryMember("capabilities", JSON::makeDictionary());
+ j_capabilities.addDictionaryMember("accessibility", JSON::makeBool(pdf.allowAccessibility()));
+ j_capabilities.addDictionaryMember("extract", JSON::makeBool(pdf.allowExtractAll()));
+ j_capabilities.addDictionaryMember("printlow", JSON::makeBool(pdf.allowPrintLowRes()));
+ j_capabilities.addDictionaryMember("printhigh", JSON::makeBool(pdf.allowPrintHighRes()));
+ j_capabilities.addDictionaryMember("modifyassembly", JSON::makeBool(pdf.allowModifyAssembly()));
+ j_capabilities.addDictionaryMember("modifyforms", JSON::makeBool(pdf.allowModifyForm()));
/* cSpell:ignore moddifyannotations */
std::string MODIFY_ANNOTATIONS =
(m->json_version == 1 ? "moddifyannotations" : "modifyannotations");
j_capabilities.addDictionaryMember(
MODIFY_ANNOTATIONS, JSON::makeBool(pdf.allowModifyAnnotation()));
- j_capabilities.addDictionaryMember(
- "modifyother", JSON::makeBool(pdf.allowModifyOther()));
- j_capabilities.addDictionaryMember(
- "modify", JSON::makeBool(pdf.allowModifyAll()));
- JSON j_parameters =
- j_encrypt.addDictionaryMember("parameters", JSON::makeDictionary());
+ j_capabilities.addDictionaryMember("modifyother", JSON::makeBool(pdf.allowModifyOther()));
+ j_capabilities.addDictionaryMember("modify", JSON::makeBool(pdf.allowModifyAll()));
+ JSON j_parameters = j_encrypt.addDictionaryMember("parameters", JSON::makeDictionary());
j_parameters.addDictionaryMember("R", JSON::makeInt(R));
j_parameters.addDictionaryMember("V", JSON::makeInt(V));
j_parameters.addDictionaryMember("P", JSON::makeInt(P));
@@ -1408,14 +1301,10 @@ QPDFJob::doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf)
} else {
s_overall_method = "mixed";
}
- j_parameters.addDictionaryMember(
- "method", JSON::makeString(s_overall_method));
- j_parameters.addDictionaryMember(
- "streammethod", JSON::makeString(s_stream_method));
- j_parameters.addDictionaryMember(
- "stringmethod", JSON::makeString(s_string_method));
- j_parameters.addDictionaryMember(
- "filemethod", JSON::makeString(s_file_method));
+ j_parameters.addDictionaryMember("method", JSON::makeString(s_overall_method));
+ j_parameters.addDictionaryMember("streammethod", JSON::makeString(s_stream_method));
+ j_parameters.addDictionaryMember("stringmethod", JSON::makeString(s_string_method));
+ j_parameters.addDictionaryMember("filemethod", JSON::makeString(s_file_method));
JSON::writeDictionaryItem(p, first, "encrypt", j_encrypt, 1);
}
@@ -1443,39 +1332,28 @@ QPDFJob::doJSONAttachments(Pipeline* p, bool& first, QPDF& pdf)
for (auto const& iter: efdh.getEmbeddedFiles()) {
std::string const& key = iter.first;
auto fsoh = iter.second;
- auto j_details =
- j_attachments.addDictionaryMember(key, JSON::makeDictionary());
+ auto j_details = j_attachments.addDictionaryMember(key, JSON::makeDictionary());
j_details.addDictionaryMember(
"filespec", JSON::makeString(fsoh->getObjectHandle().unparse()));
+ j_details.addDictionaryMember("preferredname", JSON::makeString(fsoh->getFilename()));
j_details.addDictionaryMember(
- "preferredname", JSON::makeString(fsoh->getFilename()));
- j_details.addDictionaryMember(
- "preferredcontents",
- JSON::makeString(fsoh->getEmbeddedFileStream().unparse()));
- j_details.addDictionaryMember(
- "description", null_or_string(fsoh->getDescription()));
- auto j_names =
- j_details.addDictionaryMember("names", JSON::makeDictionary());
+ "preferredcontents", JSON::makeString(fsoh->getEmbeddedFileStream().unparse()));
+ j_details.addDictionaryMember("description", null_or_string(fsoh->getDescription()));
+ auto j_names = j_details.addDictionaryMember("names", JSON::makeDictionary());
for (auto const& i2: fsoh->getFilenames()) {
j_names.addDictionaryMember(i2.first, JSON::makeString(i2.second));
}
- auto j_streams =
- j_details.addDictionaryMember("streams", JSON::makeDictionary());
+ auto j_streams = j_details.addDictionaryMember("streams", JSON::makeDictionary());
for (auto i2: fsoh->getEmbeddedFileStreams().ditems()) {
auto efs = QPDFEFStreamObjectHelper(i2.second);
- auto j_stream =
- j_streams.addDictionaryMember(i2.first, JSON::makeDictionary());
- j_stream.addDictionaryMember(
- "creationdate",
- null_or_string(to_iso8601(efs.getCreationDate())));
+ auto j_stream = j_streams.addDictionaryMember(i2.first, JSON::makeDictionary());
j_stream.addDictionaryMember(
- "modificationdate",
- null_or_string(to_iso8601(efs.getCreationDate())));
+ "creationdate", null_or_string(to_iso8601(efs.getCreationDate())));
j_stream.addDictionaryMember(
- "mimetype", null_or_string(efs.getSubtype()));
+ "modificationdate", null_or_string(to_iso8601(efs.getCreationDate())));
+ j_stream.addDictionaryMember("mimetype", null_or_string(efs.getSubtype()));
j_stream.addDictionaryMember(
- "checksum",
- null_or_string(QUtil::hex_encode(efs.getChecksum())));
+ "checksum", null_or_string(QUtil::hex_encode(efs.getChecksum())));
}
}
JSON::writeDictionaryItem(p, first, "attachments", j_attachments, 1);
@@ -1503,8 +1381,7 @@ QPDFJob::json_schema(int json_version, std::set<std::string>* keys)
JSON schema = JSON::makeDictionary();
schema.addDictionaryMember(
"version",
- JSON::makeString(
- "JSON format serial number; increased for non-compatible changes"));
+ JSON::makeString("JSON format serial number; increased for non-compatible changes"));
JSON j_params = schema.addDictionaryMember("parameters", JSON::parse(R"({
"decodelevel": "decode level used to determine stream filterability"
})"));
@@ -1521,8 +1398,7 @@ QPDFJob::json_schema(int json_version, std::set<std::string>* keys)
})"));
}
if (all_keys || keys->count("objectinfo")) {
- JSON objectinfo =
- schema.addDictionaryMember("objectinfo", JSON::parse(R"({
+ JSON objectinfo = schema.addDictionaryMember("objectinfo", JSON::parse(R"({
"<object-id>": {
"stream": {
"filter": "if stream, its filters, otherwise null",
@@ -1667,8 +1543,7 @@ QPDFJob::json_schema(int json_version, std::set<std::string>* keys)
})"));
}
if (all_keys || keys->count("attachments")) {
- JSON attachments =
- schema.addDictionaryMember("attachments", JSON::parse(R"({
+ JSON attachments = schema.addDictionaryMember("attachments", JSON::parse(R"({
"<attachment-key>": {
"filespec": "object containing the file spec",
"preferredcontents": "most preferred embedded file stream",
@@ -1728,8 +1603,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p)
// change is made to the JSON format. Clients of the JSON are to
// ignore unrecognized keys, so we only update the version of a
// key disappears or if its value changes meaning.
- JSON::writeDictionaryItem(
- p, first, "version", JSON::makeInt(m->json_version), 1);
+ JSON::writeDictionaryItem(p, first, "version", JSON::makeInt(m->json_version), 1);
JSON j_params = JSON::makeDictionary();
std::string decode_level_str;
switch (m->decode_level) {
@@ -1746,8 +1620,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p)
decode_level_str = "all";
break;
}
- j_params.addDictionaryMember(
- "decodelevel", JSON::makeString(decode_level_str));
+ j_params.addDictionaryMember("decodelevel", JSON::makeString(decode_level_str));
JSON::writeDictionaryItem(p, first, "parameters", j_params, 1);
}
bool all_keys = m->json_keys.empty();
@@ -1784,8 +1657,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p)
// repairing the page tree. To see the original file with any page
// tree problems and the page tree not flattened, select
// qpdf/objects/objectinfo without other keys.
- if (all_keys || m->json_keys.count("objects") ||
- m->json_keys.count("qpdf")) {
+ if (all_keys || m->json_keys.count("objects") || m->json_keys.count("qpdf")) {
doJSONObjects(p, first, pdf);
}
if (m->json_version == 1) {
@@ -1823,8 +1695,7 @@ QPDFJob::doInspection(QPDF& pdf)
}
if (m->show_npages) {
QTC::TC("qpdf", "QPDFJob npages");
- cout << pdf.getRoot().getKey("/Pages").getKey("/Count").getIntValue()
- << "\n";
+ cout << pdf.getRoot().getKey("/Pages").getKey("/Count").getIntValue() << "\n";
}
if (m->show_encryption) {
showEncryption(pdf);
@@ -1917,8 +1788,7 @@ QPDFJob::doProcess(
password = ptemp.c_str();
}
}
- if ((password == nullptr) || empty || m->password_is_hex_key ||
- m->suppress_password_recovery) {
+ if ((password == nullptr) || empty || m->password_is_hex_key || m->suppress_password_recovery) {
// There is no password, or we're not doing recovery, so just
// do the normal processing with the supplied password.
doProcessOnce(pdf, fn, password, empty, used_for_input, main_input);
@@ -1927,8 +1797,7 @@ QPDFJob::doProcess(
// Get a list of otherwise encoded strings. Keep in scope for this
// method.
- std::vector<std::string> passwords_str =
- QUtil::possible_repaired_encodings(password);
+ std::vector<std::string> passwords_str = QUtil::possible_repaired_encodings(password);
// Represent to char const*, as required by the QPDF class.
std::vector<char const*> passwords;
for (auto const& iter: passwords_str) {
@@ -1981,15 +1850,8 @@ QPDFJob::processFile(
bool main_input)
{
auto f1 = std::mem_fn<void(char const*, char const*)>(&QPDF::processFile);
- auto fn =
- std::bind(f1, std::placeholders::_1, filename, std::placeholders::_2);
- doProcess(
- pdf,
- fn,
- password,
- strcmp(filename, "") == 0,
- used_for_input,
- main_input);
+ auto fn = std::bind(f1, std::placeholders::_1, filename, std::placeholders::_2);
+ doProcess(pdf, fn, password, strcmp(filename, "") == 0, used_for_input, main_input);
}
void
@@ -2019,32 +1881,26 @@ QPDFJob::validateUnderOverlay(QPDF& pdf, UnderOverlay* uo)
uo->to_pagenos = QUtil::parse_numrange(uo->to_nr.c_str(), main_npages);
} catch (std::runtime_error& e) {
throw std::runtime_error(
- "parsing numeric range for " + uo->which +
- " \"to\" pages: " + e.what());
+ "parsing numeric range for " + uo->which + " \"to\" pages: " + e.what());
}
try {
if (uo->from_nr.empty()) {
QTC::TC("qpdf", "QPDFJob from_nr from repeat_nr");
uo->from_nr = uo->repeat_nr;
}
- uo->from_pagenos =
- QUtil::parse_numrange(uo->from_nr.c_str(), uo_npages);
+ uo->from_pagenos = QUtil::parse_numrange(uo->from_nr.c_str(), uo_npages);
if (!uo->repeat_nr.empty()) {
- uo->repeat_pagenos =
- QUtil::parse_numrange(uo->repeat_nr.c_str(), uo_npages);
+ uo->repeat_pagenos = QUtil::parse_numrange(uo->repeat_nr.c_str(), uo_npages);
}
} catch (std::runtime_error& e) {
throw std::runtime_error(
- "parsing numeric range for " + uo->which + " file " + uo->filename +
- ": " + e.what());
+ "parsing numeric range for " + uo->which + " file " + uo->filename + ": " + e.what());
}
}
static QPDFAcroFormDocumentHelper*
get_afdh_for_qpdf(
- std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>>&
- afdh_map,
- QPDF* q)
+ std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>>& afdh_map, QPDF* q)
{
auto uid = q->getUniqueId();
if (!afdh_map.count(uid)) {
@@ -2068,8 +1924,7 @@ QPDFJob::doUnderOverlayForPage(
return "";
}
- std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>>
- afdh;
+ std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>> afdh;
auto make_afdh = [&](QPDFPageObjectHelper& ph) {
QPDF& q = ph.getObjectHandle().getQPDF();
return get_afdh_for_qpdf(afdh, &q);
@@ -2085,8 +1940,7 @@ QPDFJob::doUnderOverlayForPage(
});
auto from_page = pages.at(QIntC::to_size(from_pageno - 1));
if (0 == fo.count(from_pageno)) {
- fo[from_pageno] =
- pdf.copyForeignObject(from_page.getFormXObjectForPage());
+ fo[from_pageno] = pdf.copyForeignObject(from_page.getFormXObjectForPage());
}
// If the same page is overlaid or underlaid multiple times,
@@ -2096,12 +1950,8 @@ QPDFJob::doUnderOverlayForPage(
std::string name = resources.getUniqueResourceName("/Fx", min_suffix);
QPDFMatrix cm;
std::string new_content = dest_page.placeFormXObject(
- fo[from_pageno],
- name,
- dest_page.getTrimBox().getArrayAsRectangle(),
- cm);
- dest_page.copyAnnotations(
- from_page, cm, dest_afdh, make_afdh(from_page));
+ fo[from_pageno], name, dest_page.getTrimBox().getArrayAsRectangle(), cm);
+ dest_page.copyAnnotations(from_page, cm, dest_afdh, make_afdh(from_page));
if (!new_content.empty()) {
resources.mergeResources("<< /XObject << >> >>"_qpdf);
auto xobject = resources.getKey("/XObject");
@@ -2116,8 +1966,7 @@ QPDFJob::doUnderOverlayForPage(
}
void
-QPDFJob::getUOPagenos(
- QPDFJob::UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos)
+QPDFJob::getUOPagenos(QPDFJob::UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos)
{
size_t idx = 0;
size_t from_size = uo.from_pagenos.size();
@@ -2126,8 +1975,7 @@ QPDFJob::getUOPagenos(
if (idx < from_size) {
pagenos[to_pageno].push_back(uo.from_pagenos.at(idx));
} else if (repeat_size) {
- pagenos[to_pageno].push_back(
- uo.repeat_pagenos.at((idx - from_size) % repeat_size));
+ pagenos[to_pageno].push_back(uo.repeat_pagenos.at((idx - from_size) % repeat_size));
}
++idx;
}
@@ -2163,12 +2011,10 @@ QPDFJob::handleUnderOverlay(QPDF& pdf)
v << prefix << ": processing underlay/overlay\n";
});
for (size_t i = 0; i < main_npages; ++i) {
- doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << " page " << 1 + i << "\n";
- });
+ doIfVerbose(
+ [&](Pipeline& v, std::string const& prefix) { v << " page " << 1 + i << "\n"; });
auto pageno = QIntC::to_int(i) + 1;
- if (!(underlay_pagenos.count(pageno) ||
- overlay_pagenos.count(pageno))) {
+ if (!(underlay_pagenos.count(pageno) || overlay_pagenos.count(pageno))) {
continue;
}
// This code converts the original page, any underlays, and
@@ -2184,19 +2030,12 @@ QPDFJob::handleUnderOverlay(QPDF& pdf)
// the original page, which we are going to replace. Therefore
// we have to explicitly copy it.
auto content_data = this_page_fo.getRawStreamData();
- this_page_fo.replaceStreamData(
- content_data, QPDFObjectHandle(), QPDFObjectHandle());
- auto resources = dest_page_oh.replaceKeyAndGetNew(
- "/Resources", "<< /XObject << >> >>"_qpdf);
+ this_page_fo.replaceStreamData(content_data, QPDFObjectHandle(), QPDFObjectHandle());
+ auto resources =
+ dest_page_oh.replaceKeyAndGetNew("/Resources", "<< /XObject << >> >>"_qpdf);
resources.getKey("/XObject").replaceKeyAndGetNew("/Fx0", this_page_fo);
auto content = doUnderOverlayForPage(
- pdf,
- m->underlay,
- underlay_pagenos,
- i,
- underlay_fo,
- upages,
- dest_page);
+ pdf, m->underlay, underlay_pagenos, i, underlay_fo, upages, dest_page);
content += dest_page.placeFormXObject(
this_page_fo,
"/Fx0",
@@ -2231,8 +2070,7 @@ QPDFJob::addAttachments(QPDF& pdf)
continue;
}
- auto fs = QPDFFileSpecObjectHelper::createFileSpec(
- pdf, to_add.filename, to_add.path);
+ auto fs = QPDFFileSpecObjectHelper::createFileSpec(pdf, to_add.filename, to_add.path);
if (!to_add.description.empty()) {
fs.setDescription(to_add.description);
}
@@ -2244,8 +2082,8 @@ QPDFJob::addAttachments(QPDF& pdf)
efdh.replaceEmbeddedFile(to_add.key, fs);
doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << prefix << ": attached " << to_add.path << " as "
- << to_add.filename << " with key " << to_add.key << "\n";
+ v << prefix << ": attached " << to_add.path << " as " << to_add.filename << " with key "
+ << to_add.key << "\n";
});
}
@@ -2273,28 +2111,19 @@ QPDFJob::copyAttachments(QPDF& pdf)
std::vector<std::string> duplicates;
for (auto const& to_copy: m->attachments_to_copy) {
doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << prefix << ": copying attachments from " << to_copy.path
- << "\n";
+ v << prefix << ": copying attachments from " << to_copy.path << "\n";
});
std::unique_ptr<QPDF> other;
- processFile(
- other,
- to_copy.path.c_str(),
- to_copy.password.c_str(),
- false,
- false);
+ processFile(other, to_copy.path.c_str(), to_copy.password.c_str(), false, false);
QPDFEmbeddedFileDocumentHelper other_efdh(*other);
auto other_attachments = other_efdh.getEmbeddedFiles();
for (auto const& iter: other_attachments) {
std::string new_key = to_copy.prefix + iter.first;
if (efdh.getEmbeddedFile(new_key)) {
- duplicates.push_back(
- "file: " + to_copy.path + ", key: " + new_key);
+ duplicates.push_back("file: " + to_copy.path + ", key: " + new_key);
} else {
- auto new_fs_oh =
- pdf.copyForeignObject(iter.second->getObjectHandle());
- efdh.replaceEmbeddedFile(
- new_key, QPDFFileSpecObjectHelper(new_fs_oh));
+ auto new_fs_oh = pdf.copyForeignObject(iter.second->getObjectHandle());
+ efdh.replaceEmbeddedFile(new_key, QPDFFileSpecObjectHelper(new_fs_oh));
doIfVerbose([&](Pipeline& v, std::string const& prefix) {
v << " " << iter.first << " -> " << new_key << "\n";
});
@@ -2337,8 +2166,7 @@ QPDFJob::handleTransformations(QPDF& pdf)
if (m->remove_restrictions) {
pdf.removeSecurityRestrictions();
}
- if (m->externalize_inline_images ||
- (m->optimize_images && (!m->keep_inline_images))) {
+ if (m->externalize_inline_images || (m->optimize_images && (!m->keep_inline_images))) {
for (auto& ph: dh.getAllPages()) {
ph.externalizeInlineImages(m->ii_min_bytes);
}
@@ -2350,18 +2178,10 @@ QPDFJob::handleTransformations(QPDF& pdf)
ph.forEachImage(
true,
[this, pageno, &pdf](
- QPDFObjectHandle& obj,
- QPDFObjectHandle& xobj_dict,
- std::string const& key) {
+ QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key) {
auto io = std::make_unique<ImageOptimizer>(
- *this,
- m->oi_min_width,
- m->oi_min_height,
- m->oi_min_area,
- obj);
- if (io->evaluate(
- "image " + key + " on page " +
- std::to_string(pageno))) {
+ *this, m->oi_min_width, m->oi_min_height, m->oi_min_area, obj);
+ if (io->evaluate("image " + key + " on page " + std::to_string(pageno))) {
QPDFObjectHandle new_image = pdf.newStream();
new_image.replaceDict(obj.getDict().shallowCopy());
new_image.replaceStreamData(
@@ -2378,8 +2198,7 @@ QPDFJob::handleTransformations(QPDF& pdf)
afdh->generateAppearancesIfNeeded();
}
if (m->flatten_annotations) {
- dh.flattenAnnotations(
- m->flatten_annotations_required, m->flatten_annotations_forbidden);
+ dh.flattenAnnotations(m->flatten_annotations_required, m->flatten_annotations_forbidden);
}
if (m->coalesce_contents) {
for (auto& page: dh.getAllPages()) {
@@ -2438,8 +2257,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf)
QPDFObjGen::set nodes_seen; // loop detection
doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << prefix << ": " << pdf.getFilename()
- << ": checking for shared resources\n";
+ v << prefix << ": " << pdf.getFilename() << ": checking for shared resources\n";
});
std::list<QPDFObjectHandle> queue;
@@ -2458,8 +2276,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf)
if (dict.hasKey("/Resources")) {
QTC::TC("qpdf", "QPDFJob found resources in non-leaf");
doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << " found resources in non-leaf page node "
- << og.unparse(' ') << "\n";
+ v << " found resources in non-leaf page node " << og.unparse(' ') << "\n";
});
return true;
}
@@ -2474,8 +2291,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf)
if (!resources_seen.add(resources)) {
QTC::TC("qpdf", "QPDFJob found shared resources in leaf");
doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << " found shared resources in leaf node "
- << og.unparse(' ') << ": "
+ v << " found shared resources in leaf node " << og.unparse(' ') << ": "
<< resources.getObjGen().unparse(' ') << "\n";
});
return true;
@@ -2488,8 +2304,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf)
if (!resources_seen.add(xobject)) {
QTC::TC("qpdf", "QPDFJob found shared xobject in leaf");
doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << " found shared xobject in leaf node "
- << og.unparse(' ') << ": "
+ v << " found shared xobject in leaf node " << og.unparse(' ') << ": "
<< xobject.getObjGen().unparse(' ') << "\n";
});
return true;
@@ -2531,8 +2346,7 @@ added_page(QPDF& pdf, QPDFPageObjectHelper page)
}
void
-QPDFJob::handlePageSpecs(
- QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_heap)
+QPDFJob::handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_heap)
{
// Parse all page specifications and translate them into lists of
// actual pages.
@@ -2554,13 +2368,10 @@ QPDFJob::handlePageSpecs(
filenames.insert(page_spec.filename);
}
m->keep_files_open = (filenames.size() <= m->keep_files_open_threshold);
- QTC::TC(
- "qpdf",
- "QPDFJob automatically set keep files open",
- m->keep_files_open ? 0 : 1);
+ QTC::TC("qpdf", "QPDFJob automatically set keep files open", m->keep_files_open ? 0 : 1);
doIfVerbose([&](Pipeline& v, std::string const& prefix) {
- v << prefix << ": selecting --keep-open-files="
- << (m->keep_files_open ? "y" : "n") << "\n";
+ v << prefix << ": selecting --keep-open-files=" << (m->keep_files_open ? "y" : "n")
+ << "\n";
});
}
@@ -2600,8 +2411,7 @@ QPDFJob::handlePageSpecs(
cis->stayOpen(true);
} else {
QTC::TC("qpdf", "QPDFJob keep files open y");
- FileInputSource* fis =
- new FileInputSource(page_spec.filename.c_str());
+ FileInputSource* fis = new FileInputSource(page_spec.filename.c_str());
is = std::shared_ptr<InputSource>(fis);
}
std::unique_ptr<QPDF> qpdf_sp;
@@ -2618,10 +2428,7 @@ QPDFJob::handlePageSpecs(
// associated with this occurrence of the file.
parsed_specs.push_back(
// line-break
- QPDFPageData(
- page_spec.filename,
- page_spec_qpdfs[page_spec.filename],
- page_spec.range));
+ QPDFPageData(page_spec.filename, page_spec_qpdfs[page_spec.filename], page_spec.range));
}
std::map<unsigned long long, bool> remove_unreferenced;
@@ -2636,8 +2443,7 @@ QPDFJob::handlePageSpecs(
QPDF& other(*(iter.second));
auto other_uuid = other.getUniqueId();
if (remove_unreferenced.count(other_uuid) == 0) {
- remove_unreferenced[other_uuid] =
- shouldRemoveUnreferencedResources(other);
+ remove_unreferenced[other_uuid] = shouldRemoveUnreferencedResources(other);
}
if (cis) {
cis->stayOpen(false);
@@ -2676,9 +2482,7 @@ QPDFJob::handlePageSpecs(
got_pages = true;
new_parsed_specs.push_back(
// line-break
- QPDFPageData(
- page_data,
- page_data.selected_pages.at(cur_page + j)));
+ QPDFPageData(page_data, page_data.selected_pages.at(cur_page + j)));
}
}
}
@@ -2694,8 +2498,7 @@ QPDFJob::handlePageSpecs(
std::vector<QPDFObjectHandle> new_labels;
bool any_page_labels = false;
int out_pageno = 0;
- std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>>
- afdh_map;
+ std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>> afdh_map;
auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf);
std::set<QPDFObjGen> referenced_fields;
for (auto& page_data: parsed_specs) {
@@ -2716,10 +2519,8 @@ QPDFJob::handlePageSpecs(
// Pages are specified from 1 but numbered from 0 in the
// vector
int pageno = pageno_iter - 1;
- pldh.getLabelsForPageRange(
- pageno, pageno, out_pageno++, new_labels);
- QPDFPageObjectHelper to_copy =
- page_data.orig_pages.at(QIntC::to_size(pageno));
+ pldh.getLabelsForPageRange(pageno, pageno, out_pageno++, new_labels);
+ QPDFPageObjectHelper to_copy = page_data.orig_pages.at(QIntC::to_size(pageno));
QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen();
unsigned long long from_uuid = page_data.qpdf->getUniqueId();
if (copied_pages[from_uuid].count(to_copy_og)) {
@@ -2754,8 +2555,7 @@ QPDFJob::handlePageSpecs(
// adjusted. If we copy any page from the original file
// more than once, that page would be in conflict with the
// previous copy of itself.
- if (other_afdh->hasAcroForm() &&
- ((!this_file) || (!first_copy_from_orig))) {
+ if (other_afdh->hasAcroForm() && ((!this_file) || (!first_copy_from_orig))) {
if (!this_file) {
QTC::TC("qpdf", "QPDFJob copy fields not this file");
} else if (!first_copy_from_orig) {
@@ -2763,10 +2563,7 @@ QPDFJob::handlePageSpecs(
}
try {
this_afdh->fixCopiedAnnotations(
- new_page,
- to_copy.getObjectHandle(),
- *other_afdh,
- &referenced_fields);
+ new_page, to_copy.getObjectHandle(), *other_afdh, &referenced_fields);
} catch (std::exception& e) {
pdf.warn(
qpdf_e_damaged_pdf,
@@ -2800,9 +2597,7 @@ QPDFJob::handlePageSpecs(
referenced_fields.insert(field.getObjectHandle().getObjGen());
}
} else {
- pdf.replaceObject(
- page.getObjectHandle().getObjGen(),
- QPDFObjectHandle::newNull());
+ pdf.replaceObject(page.getObjectHandle().getObjGen(), QPDFObjectHandle::newNull());
}
}
// Remove unreferenced form fields
@@ -2843,8 +2638,7 @@ QPDFJob::handleRotations(QPDF& pdf)
for (int pageno_iter: QUtil::parse_numrange(range.c_str(), npages)) {
int pageno = pageno_iter - 1;
if ((pageno >= 0) && (pageno < npages)) {
- pages.at(QIntC::to_size(pageno))
- .rotatePage(rspec.angle, rspec.relative);
+ pages.at(QIntC::to_size(pageno)).rotatePage(rspec.angle, rspec.relative);
}
}
}
@@ -2869,24 +2663,21 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password)
bool has_8bit_chars;
bool is_valid_utf8;
bool is_utf16;
- QUtil::analyze_encoding(
- password, has_8bit_chars, is_valid_utf8, is_utf16);
+ QUtil::analyze_encoding(password, has_8bit_chars, is_valid_utf8, is_utf16);
if (!has_8bit_chars) {
return;
}
if (m->password_mode == QPDFJob::pm_unicode) {
if (!is_valid_utf8) {
QTC::TC("qpdf", "QPDFJob password not unicode");
- throw std::runtime_error(
- "supplied password is not valid UTF-8");
+ throw std::runtime_error("supplied password is not valid UTF-8");
}
if (R < 5) {
std::string encoded;
if (!QUtil::utf8_to_pdf_doc(password, encoded)) {
QTC::TC("qpdf", "QPDFJob password not encodable");
- throw std::runtime_error(
- "supplied password cannot be encoded for"
- " 40-bit or 128-bit encryption formats");
+ throw std::runtime_error("supplied password cannot be encoded for"
+ " 40-bit or 128-bit encryption formats");
}
password = encoded;
}
@@ -2895,8 +2686,7 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password)
std::string encoded;
if (QUtil::utf8_to_pdf_doc(password, encoded)) {
QTC::TC("qpdf", "QPDFJob auto-encode password");
- doIfVerbose([&](Pipeline& v,
- std::string const& prefix) {
+ doIfVerbose([&](Pipeline& v, std::string const& prefix) {
v << prefix << ": automatically converting Unicode"
<< " password to single-byte encoding as"
<< " required for 40-bit or 128-bit"
@@ -2905,25 +2695,23 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password)
password = encoded;
} else {
QTC::TC("qpdf", "QPDFJob bytes fallback warning");
- *m->log->getError()
- << m->message_prefix << ": WARNING: "
- << "supplied password looks like a Unicode"
- << " password with characters not allowed in"
- << " passwords for 40-bit and 128-bit "
- "encryption;"
- << " most readers will not be able to open this"
- << " file with the supplied password."
- << " (Use --password-mode=bytes to suppress "
- "this"
- << " warning and use the password anyway.)\n";
+ *m->log->getError() << m->message_prefix << ": WARNING: "
+ << "supplied password looks like a Unicode"
+ << " password with characters not allowed in"
+ << " passwords for 40-bit and 128-bit "
+ "encryption;"
+ << " most readers will not be able to open this"
+ << " file with the supplied password."
+ << " (Use --password-mode=bytes to suppress "
+ "this"
+ << " warning and use the password anyway.)\n";
}
} else if ((R >= 5) && (!is_valid_utf8)) {
QTC::TC("qpdf", "QPDFJob invalid utf-8 in auto");
- throw std::runtime_error(
- "supplied password is not a valid Unicode password,"
- " which is required for 256-bit encryption; to"
- " really use this password, rerun with the"
- " --password-mode=bytes option");
+ throw std::runtime_error("supplied password is not a valid Unicode password,"
+ " which is required for 256-bit encryption; to"
+ " really use this password, rerun with the"
+ " --password-mode=bytes option");
}
}
}
@@ -2953,28 +2741,25 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w)
throw std::logic_error("bad encryption keylen");
}
if ((R > 3) && (m->r3_accessibility == false)) {
- *m->log->getError()
- << m->message_prefix << ": -accessibility=n is ignored for modern"
- << " encryption formats\n";
+ *m->log->getError() << m->message_prefix << ": -accessibility=n is ignored for modern"
+ << " encryption formats\n";
}
maybeFixWritePassword(R, m->user_password);
maybeFixWritePassword(R, m->owner_password);
if ((R < 4) || ((R == 4) && (!m->use_aes))) {
if (!m->allow_weak_crypto) {
QTC::TC("qpdf", "QPDFJob weak crypto error");
- *m->log->getError()
- << m->message_prefix
- << ": refusing to write a file with RC4, a weak "
- "cryptographic "
- "algorithm\n"
- << "Please use 256-bit keys for better security.\n"
- << "Pass --allow-weak-crypto to enable writing insecure "
- "files.\n"
- << "See also "
- "https://qpdf.readthedocs.io/en/stable/"
- "weak-crypto.html\n";
- throw std::runtime_error(
- "refusing to write a file with weak crypto");
+ *m->log->getError() << m->message_prefix
+ << ": refusing to write a file with RC4, a weak "
+ "cryptographic "
+ "algorithm\n"
+ << "Please use 256-bit keys for better security.\n"
+ << "Pass --allow-weak-crypto to enable writing insecure "
+ "files.\n"
+ << "See also "
+ "https://qpdf.readthedocs.io/en/stable/"
+ "weak-crypto.html\n";
+ throw std::runtime_error("refusing to write a file with weak crypto");
}
}
switch (R) {
@@ -3046,10 +2831,7 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w)
}
static void
-parse_version(
- std::string const& full_version_string,
- std::string& version,
- int& extension_level)
+parse_version(std::string const& full_version_string, std::string& version, int& extension_level)
{
auto vp = QUtil::make_unique_cstr(full_version_string);
char* v = vp.get();
@@ -3144,18 +2926,13 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w)
}
if (m->progress) {
if (m->progress_handler) {
- w.registerProgressReporter(
- std::shared_ptr<QPDFWriter::ProgressReporter>(
- new QPDFWriter::FunctionProgressReporter(
- m->progress_handler)));
+ w.registerProgressReporter(std::shared_ptr<QPDFWriter::ProgressReporter>(
+ new QPDFWriter::FunctionProgressReporter(m->progress_handler)));
} else {
- char const* outfilename =
- m->outfilename ? m->outfilename.get() : "standard output";
- w.registerProgressReporter(
- std::shared_ptr<QPDFWriter::ProgressReporter>(
- // line-break
- new ProgressReporter(
- *m->log->getInfo(), m->message_prefix, outfilename)));
+ char const* outfilename = m->outfilename ? m->outfilename.get() : "standard output";
+ w.registerProgressReporter(std::shared_ptr<QPDFWriter::ProgressReporter>(
+ // line-break
+ new ProgressReporter(*m->log->getInfo(), m->message_prefix, outfilename)));
}
}
}
@@ -3170,14 +2947,10 @@ QPDFJob::doSplitPages(QPDF& pdf)
char* num_spot = strstr(const_cast<char*>(m->outfilename.get()), "%d");
if (num_spot != nullptr) {
QTC::TC("qpdf", "QPDFJob split-pages %d");
- before = std::string(
- m->outfilename.get(),
- QIntC::to_size(num_spot - m->outfilename.get()));
+ before = std::string(m->outfilename.get(), QIntC::to_size(num_spot - m->outfilename.get()));
after = num_spot + 2;
} else if (
- (len >= 4) &&
- (QUtil::str_compare_nocase(m->outfilename.get() + len - 4, ".pdf") ==
- 0)) {
+ (len >= 4) && (QUtil::str_compare_nocase(m->outfilename.get() + len - 4, ".pdf") == 0)) {
QTC::TC("qpdf", "QPDFJob split-pages .pdf");
before = std::string(m->outfilename.get(), len - 4) + "-";
after = m->outfilename.get() + len - 4;
@@ -3232,24 +3005,18 @@ QPDFJob::doSplitPages(QPDF& pdf)
if (pldh.hasPageLabels()) {
std::vector<QPDFObjectHandle> labels;
pldh.getLabelsForPageRange(
- QIntC::to_longlong(first - 1),
- QIntC::to_longlong(last - 1),
- 0,
- labels);
+ QIntC::to_longlong(first - 1), QIntC::to_longlong(last - 1), 0, labels);
QPDFObjectHandle page_labels = QPDFObjectHandle::newDictionary();
page_labels.replaceKey("/Nums", QPDFObjectHandle::newArray(labels));
outpdf.getRoot().replaceKey("/PageLabels", page_labels);
}
- std::string page_range =
- QUtil::uint_to_string(first, QIntC::to_int(pageno_len));
+ std::string page_range = QUtil::uint_to_string(first, QIntC::to_int(pageno_len));
if (m->split_pages > 1) {
- page_range +=
- "-" + QUtil::uint_to_string(last, QIntC::to_int(pageno_len));
+ page_range += "-" + QUtil::uint_to_string(last, QIntC::to_int(pageno_len));
}
std::string outfile = before + page_range + after;
if (QUtil::same_file(m->infilename.get(), outfile.c_str())) {
- throw std::runtime_error(
- "split pages would overwrite input file with " + outfile);
+ throw std::runtime_error("split pages would overwrite input file with " + outfile);
}
QPDFWriter w(outpdf, outfile.c_str());
setWriterOptions(outpdf, w);
@@ -3268,8 +3035,7 @@ QPDFJob::writeOutfile(QPDF& pdf)
// Append but don't prepend to the path to generate a
// temporary name. This saves us from having to split the path
// by directory and non-directory.
- temp_out = QUtil::make_shared_cstr(
- std::string(m->infilename.get()) + ".~qpdf-temp#");
+ temp_out = QUtil::make_shared_cstr(std::string(m->infilename.get()) + ".~qpdf-temp#");
// m->outfilename will be restored to 0 before temp_out
// goes out of scope.
m->outfilename = temp_out;
@@ -3312,17 +3078,14 @@ QPDFJob::writeOutfile(QPDF& pdf)
QUtil::rename_file(m->infilename.get(), backup.c_str());
QUtil::rename_file(temp_out.get(), m->infilename.get());
if (warnings) {
- *m->log->getError()
- << m->message_prefix
- << ": there are warnings; original file kept in " << backup
- << "\n";
+ *m->log->getError() << m->message_prefix
+ << ": there are warnings; original file kept in " << backup << "\n";
} else {
try {
QUtil::remove_file(backup.c_str());
} catch (QPDFSystemError& e) {
*m->log->getError()
- << m->message_prefix << ": unable to delete original file ("
- << e.what() << ");"
+ << m->message_prefix << ": unable to delete original file (" << e.what() << ");"
<< " original file left in " << backup
<< ", but the input was successfully replaced\n";
}
@@ -3342,12 +3105,9 @@ QPDFJob::writeJSON(QPDF& pdf)
if (m->json_stream_prefix.empty()) {
m->json_stream_prefix = m->outfilename.get();
}
- fc = std::make_shared<QUtil::FileCloser>(
- QUtil::safe_fopen(m->outfilename.get(), "w"));
+ fc = std::make_shared<QUtil::FileCloser>(QUtil::safe_fopen(m->outfilename.get(), "w"));
fp = std::make_shared<Pl_StdioFile>("json output", fc->f);
- } else if (
- (m->json_stream_data == qpdf_sj_file) &&
- m->json_stream_prefix.empty()) {
+ } else if ((m->json_stream_data == qpdf_sj_file) && m->json_stream_prefix.empty()) {
QTC::TC("qpdf", "QPDFJob need json-stream-prefix for stdout");
usage("please specify --json-stream-prefix since the input file "
"name is unknown");
diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc
index a95cd415..3116b097 100644
--- a/libqpdf/QPDFJob_argv.cc
+++ b/libqpdf/QPDFJob_argv.cc
@@ -46,8 +46,7 @@ namespace
};
} // namespace
-ArgParser::ArgParser(
- QPDFArgParser& ap, std::shared_ptr<QPDFJob::Config> c_main) :
+ArgParser::ArgParser(QPDFArgParser& ap, std::shared_ptr<QPDFJob::Config> c_main) :
ap(ap),
c_main(c_main),
pages_password(nullptr),
@@ -107,8 +106,7 @@ ArgParser::argVersion()
auto whoami = this->ap.getProgname();
*QPDFLogger::defaultLogger()->getInfo()
<< whoami << " version " << QPDF::QPDFVersion() << "\n"
- << "Run " << whoami
- << " --copyright to see copyright and license information.\n";
+ << "Run " << whoami << " --copyright to see copyright and license information.\n";
}
void
@@ -152,8 +150,7 @@ ArgParser::argJsonHelp(std::string const& parameter)
if ((version < 1) || (version > JSON::LATEST)) {
usage(std::string("unsupported json version ") + parameter);
}
- *QPDFLogger::defaultLogger()->getInfo()
- << QPDFJob::json_out_schema(version) << "\n";
+ *QPDFLogger::defaultLogger()->getInfo() << QPDFJob::json_out_schema(version) << "\n";
}
void
@@ -263,10 +260,7 @@ ArgParser::argPagesPositional(std::string const& arg)
if (range_p == nullptr) {
if (arg.empty()) {
// The filename or password was the last argument
- QTC::TC(
- "qpdf",
- "QPDFJob pages range omitted at end",
- this->pages_password ? 0 : 1);
+ QTC::TC("qpdf", "QPDFJob pages range omitted at end", this->pages_password ? 0 : 1);
} else {
// We need to accumulate some more arguments
return;
diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc
index a7f22443..7c275f20 100644
--- a/libqpdf/QPDFJob_config.cc
+++ b/libqpdf/QPDFJob_config.cc
@@ -658,8 +658,7 @@ QPDFJob::Config::passwordFile(std::string const& parameter)
if (lines.size() > 1) {
*QPDFLogger::defaultLogger()->getError()
- << this->o.m->message_prefix
- << ": WARNING: all but the first line of"
+ << this->o.m->message_prefix << ": WARNING: all but the first line of"
<< " the password file are ignored\n";
}
}
@@ -751,8 +750,7 @@ QPDFJob::Config::removeUnreferencedResources(std::string const& parameter)
QPDFJob::Config*
QPDFJob::Config::showObject(std::string const& parameter)
{
- QPDFJob::parse_object_id(
- parameter, o.m->show_trailer, o.m->show_obj, o.m->show_gen);
+ QPDFJob::parse_object_id(parameter, o.m->show_trailer, o.m->show_obj, o.m->show_gen);
o.m->require_outfile = false;
return this;
}
@@ -761,13 +759,11 @@ QPDFJob::Config*
QPDFJob::Config::jobJsonFile(std::string const& parameter)
{
try {
- o.initializeFromJson(
- QUtil::read_file_into_string(parameter.c_str()), true);
+ o.initializeFromJson(QUtil::read_file_into_string(parameter.c_str()), true);
} catch (std::exception& e) {
throw std::runtime_error(
- "error with job-json file " + std::string(parameter) + ": " +
- e.what() + "\nRun " + this->o.m->message_prefix +
- " --job-json-help for information on the file format.");
+ "error with job-json file " + std::string(parameter) + ": " + e.what() + "\nRun " +
+ this->o.m->message_prefix + " --job-json-help for information on the file format.");
}
return this;
}
@@ -900,8 +896,7 @@ QPDFJob::AttConfig::replace()
QPDFJob::Config*
QPDFJob::AttConfig::endAddAttachment()
{
- static std::string now =
- QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time());
+ static std::string now = QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time());
if (this->att.path.empty()) {
usage("add attachment: no file specified");
}
@@ -953,8 +948,7 @@ QPDFJob::PagesConfig*
QPDFJob::PagesConfig::pageSpec(
std::string const& filename, std::string const& range, char const* password)
{
- this->config->o.m->page_specs.push_back(
- QPDFJob::PageSpec(filename, password, range));
+ this->config->o.m->page_specs.push_back(QPDFJob::PageSpec(filename, password, range));
return this;
}
@@ -1035,9 +1029,7 @@ QPDFJob::UOConfig::password(std::string const& parameter)
std::shared_ptr<QPDFJob::EncConfig>
QPDFJob::Config::encrypt(
- int keylen,
- std::string const& user_password,
- std::string const& owner_password)
+ int keylen, std::string const& user_password, std::string const& owner_password)
{
o.m->keylen = keylen;
if (keylen == 256) {
diff --git a/libqpdf/QPDFJob_json.cc b/libqpdf/QPDFJob_json.cc
index 9adfe2b9..126f9a13 100644
--- a/libqpdf/QPDFJob_json.cc
+++ b/libqpdf/QPDFJob_json.cc
@@ -125,32 +125,28 @@ Handlers::initHandlers()
void
Handlers::addBare(bare_handler_t fn)
{
- jh->addStringHandler(
- [this, fn](std::string const& path, std::string const& parameter) {
- if (!parameter.empty()) {
- QTC::TC("qpdf", "QPDFJob json bare not empty");
- usage(path + ": value must be the empty string");
- } else {
- fn();
- }
- });
+ jh->addStringHandler([this, fn](std::string const& path, std::string const& parameter) {
+ if (!parameter.empty()) {
+ QTC::TC("qpdf", "QPDFJob json bare not empty");
+ usage(path + ": value must be the empty string");
+ } else {
+ fn();
+ }
+ });
}
void
Handlers::addParameter(param_handler_t fn)
{
jh->addStringHandler(
- [fn](std::string const& path, std::string const& parameter) {
- fn(parameter.c_str());
- });
+ [fn](std::string const& path, std::string const& parameter) { fn(parameter.c_str()); });
}
void
Handlers::addChoices(char const** choices, bool required, param_handler_t fn)
{
jh->addStringHandler(
- [fn, choices, required, this](
- std::string const& path, std::string const& parameter) {
+ [fn, choices, required, this](std::string const& path, std::string const& parameter) {
char const* p = parameter.c_str();
bool matches = false;
if ((!required) && (parameter.empty())) {
@@ -494,8 +490,7 @@ Handlers::beginPages(JSON j)
QTC::TC("qpdf", "QPDFJob json pages no file");
usage("file is required in page specification");
}
- this->c_pages->pageSpec(
- file, range, password_seen ? password.c_str() : nullptr);
+ this->c_pages->pageSpec(file, range, password_seen ? password.c_str() : nullptr);
}
void
diff --git a/libqpdf/QPDFLogger.cc b/libqpdf/QPDFLogger.cc
index 290ae0a1..76c3c70c 100644
--- a/libqpdf/QPDFLogger.cc
+++ b/libqpdf/QPDFLogger.cc
@@ -198,9 +198,8 @@ QPDFLogger::setSave(std::shared_ptr<Pipeline> p, bool only_if_not_set)
if (p == m->p_stdout) {
auto pt = dynamic_cast<Pl_Track*>(p.get());
if (pt->getUsed()) {
- throw std::logic_error(
- "QPDFLogger: called setSave on standard output after standard"
- " output has already been used");
+ throw std::logic_error("QPDFLogger: called setSave on standard output after standard"
+ " output has already been used");
}
if (m->p_info == m->p_stdout) {
m->p_info = m->p_stderr;
@@ -251,8 +250,7 @@ std::shared_ptr<Pipeline>
QPDFLogger::throwIfNull(std::shared_ptr<Pipeline> p, bool null_okay)
{
if (!(null_okay || p)) {
- throw std::logic_error(
- "QPDFLogger: requested a null pipeline without null_okay == true");
+ throw std::logic_error("QPDFLogger: requested a null pipeline without null_okay == true");
}
return p;
}
diff --git a/libqpdf/QPDFMatrix.cc b/libqpdf/QPDFMatrix.cc
index 9fb24888..a54b4370 100644
--- a/libqpdf/QPDFMatrix.cc
+++ b/libqpdf/QPDFMatrix.cc
@@ -13,8 +13,7 @@ QPDFMatrix::QPDFMatrix() :
{
}
-QPDFMatrix::QPDFMatrix(
- double a, double b, double c, double d, double e, double f) :
+QPDFMatrix::QPDFMatrix(double a, double b, double c, double d, double e, double f) :
a(a),
b(b),
c(c),
@@ -136,6 +135,6 @@ bool
QPDFMatrix::operator==(QPDFMatrix const& rhs) const
{
return (
- (this->a == rhs.a) && (this->b == rhs.b) && (this->c == rhs.c) &&
- (this->d == rhs.d) && (this->e == rhs.e) && (this->f == rhs.f));
+ (this->a == rhs.a) && (this->b == rhs.b) && (this->c == rhs.c) && (this->d == rhs.d) &&
+ (this->e == rhs.e) && (this->f == rhs.f));
}
diff --git a/libqpdf/QPDFNameTreeObjectHelper.cc b/libqpdf/QPDFNameTreeObjectHelper.cc
index 6e4ae693..bfe67ecc 100644
--- a/libqpdf/QPDFNameTreeObjectHelper.cc
+++ b/libqpdf/QPDFNameTreeObjectHelper.cc
@@ -41,14 +41,12 @@ QPDFNameTreeObjectHelper::~QPDFNameTreeObjectHelper()
// #745.
}
-QPDFNameTreeObjectHelper::Members::Members(
- QPDFObjectHandle& oh, QPDF& q, bool auto_repair) :
+QPDFNameTreeObjectHelper::Members::Members(QPDFObjectHandle& oh, QPDF& q, bool auto_repair) :
impl(std::make_shared<NNTreeImpl>(name_tree_details, q, oh, auto_repair))
{
}
-QPDFNameTreeObjectHelper::QPDFNameTreeObjectHelper(
- QPDFObjectHandle oh, QPDF& q, bool auto_repair) :
+QPDFNameTreeObjectHelper::QPDFNameTreeObjectHelper(QPDFObjectHandle oh, QPDF& q, bool auto_repair) :
QPDFObjectHelper(oh),
m(new Members(oh, q, auto_repair))
{
@@ -61,8 +59,7 @@ QPDFNameTreeObjectHelper::newEmpty(QPDF& qpdf, bool auto_repair)
qpdf.makeIndirectObject("<< /Names [] >>"_qpdf), qpdf, auto_repair);
}
-QPDFNameTreeObjectHelper::iterator::iterator(
- std::shared_ptr<NNTreeIterator> const& i) :
+QPDFNameTreeObjectHelper::iterator::iterator(std::shared_ptr<NNTreeIterator> const& i) :
impl(i)
{
}
@@ -123,8 +120,7 @@ QPDFNameTreeObjectHelper::iterator::operator==(iterator const& other) const
}
void
-QPDFNameTreeObjectHelper::iterator::insertAfter(
- std::string const& key, QPDFObjectHandle value)
+QPDFNameTreeObjectHelper::iterator::insertAfter(std::string const& key, QPDFObjectHandle value)
{
impl->insertAfter(QPDFObjectHandle::newUnicodeString(key), value);
updateIValue();
@@ -156,11 +152,9 @@ QPDFNameTreeObjectHelper::last() const
}
QPDFNameTreeObjectHelper::iterator
-QPDFNameTreeObjectHelper::find(
- std::string const& key, bool return_prev_if_not_found)
+QPDFNameTreeObjectHelper::find(std::string const& key, bool return_prev_if_not_found)
{
- auto i = m->impl->find(
- QPDFObjectHandle::newUnicodeString(key), return_prev_if_not_found);
+ auto i = m->impl->find(QPDFObjectHandle::newUnicodeString(key), return_prev_if_not_found);
return iterator(std::make_shared<NNTreeIterator>(i));
}
@@ -172,8 +166,7 @@ QPDFNameTreeObjectHelper::insert(std::string const& key, QPDFObjectHandle value)
}
bool
-QPDFNameTreeObjectHelper::remove(
- std::string const& key, QPDFObjectHandle* value)
+QPDFNameTreeObjectHelper::remove(std::string const& key, QPDFObjectHandle* value)
{
return m->impl->remove(QPDFObjectHandle::newUnicodeString(key), value);
}
@@ -186,8 +179,7 @@ QPDFNameTreeObjectHelper::hasName(std::string const& name)
}
bool
-QPDFNameTreeObjectHelper::findObject(
- std::string const& name, QPDFObjectHandle& oh)
+QPDFNameTreeObjectHelper::findObject(std::string const& name, QPDFObjectHandle& oh)
{
auto i = find(name);
if (i == end()) {
diff --git a/libqpdf/QPDFNumberTreeObjectHelper.cc b/libqpdf/QPDFNumberTreeObjectHelper.cc
index c82eaf57..f35158d5 100644
--- a/libqpdf/QPDFNumberTreeObjectHelper.cc
+++ b/libqpdf/QPDFNumberTreeObjectHelper.cc
@@ -42,8 +42,7 @@ QPDFNumberTreeObjectHelper::~QPDFNumberTreeObjectHelper()
// #745.
}
-QPDFNumberTreeObjectHelper::Members::Members(
- QPDFObjectHandle& oh, QPDF& q, bool auto_repair) :
+QPDFNumberTreeObjectHelper::Members::Members(QPDFObjectHandle& oh, QPDF& q, bool auto_repair) :
impl(std::make_shared<NNTreeImpl>(number_tree_details, q, oh, auto_repair))
{
}
@@ -62,8 +61,7 @@ QPDFNumberTreeObjectHelper::newEmpty(QPDF& qpdf, bool auto_repair)
qpdf.makeIndirectObject("<< /Nums [] >>"_qpdf), qpdf, auto_repair);
}
-QPDFNumberTreeObjectHelper::iterator::iterator(
- std::shared_ptr<NNTreeIterator> const& i) :
+QPDFNumberTreeObjectHelper::iterator::iterator(std::shared_ptr<NNTreeIterator> const& i) :
impl(i)
{
}
@@ -124,8 +122,7 @@ QPDFNumberTreeObjectHelper::iterator::operator==(iterator const& other) const
}
void
-QPDFNumberTreeObjectHelper::iterator::insertAfter(
- numtree_number key, QPDFObjectHandle value)
+QPDFNumberTreeObjectHelper::iterator::insertAfter(numtree_number key, QPDFObjectHandle value)
{
impl->insertAfter(QPDFObjectHandle::newInteger(key), value);
updateIValue();
@@ -157,11 +154,9 @@ QPDFNumberTreeObjectHelper::last() const
}
QPDFNumberTreeObjectHelper::iterator
-QPDFNumberTreeObjectHelper::find(
- numtree_number key, bool return_prev_if_not_found)
+QPDFNumberTreeObjectHelper::find(numtree_number key, bool return_prev_if_not_found)
{
- auto i = m->impl->find(
- QPDFObjectHandle::newInteger(key), return_prev_if_not_found);
+ auto i = m->impl->find(QPDFObjectHandle::newInteger(key), return_prev_if_not_found);
return iterator(std::make_shared<NNTreeIterator>(i));
}
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index cc23db8e..7270b76d 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -56,41 +56,30 @@ QPDFObjectHandle::StreamDataProvider::~StreamDataProvider()
}
void
-QPDFObjectHandle::StreamDataProvider::provideStreamData(
- QPDFObjGen const& og, Pipeline* pipeline)
+QPDFObjectHandle::StreamDataProvider::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline)
{
return provideStreamData(og.getObj(), og.getGen(), pipeline);
}
bool
QPDFObjectHandle::StreamDataProvider::provideStreamData(
- QPDFObjGen const& og,
- Pipeline* pipeline,
- bool suppress_warnings,
- bool will_retry)
+ QPDFObjGen const& og, Pipeline* pipeline, bool suppress_warnings, bool will_retry)
{
- return provideStreamData(
- og.getObj(), og.getGen(), pipeline, suppress_warnings, will_retry);
+ return provideStreamData(og.getObj(), og.getGen(), pipeline, suppress_warnings, will_retry);
}
void
QPDFObjectHandle::StreamDataProvider::provideStreamData(
int objid, int generation, Pipeline* pipeline)
{
- throw std::logic_error(
- "you must override provideStreamData -- see QPDFObjectHandle.hh");
+ throw std::logic_error("you must override provideStreamData -- see QPDFObjectHandle.hh");
}
bool
QPDFObjectHandle::StreamDataProvider::provideStreamData(
- int objid,
- int generation,
- Pipeline* pipeline,
- bool suppress_warnings,
- bool will_retry)
+ int objid, int generation, Pipeline* pipeline, bool suppress_warnings, bool will_retry)
{
- throw std::logic_error(
- "you must override provideStreamData -- see QPDFObjectHandle.hh");
+ throw std::logic_error("you must override provideStreamData -- see QPDFObjectHandle.hh");
return false;
}
@@ -105,8 +94,7 @@ namespace
class CoalesceProvider: public QPDFObjectHandle::StreamDataProvider
{
public:
- CoalesceProvider(
- QPDFObjectHandle containing_page, QPDFObjectHandle old_contents) :
+ CoalesceProvider(QPDFObjectHandle containing_page, QPDFObjectHandle old_contents) :
containing_page(containing_page),
old_contents(old_contents)
{
@@ -124,8 +112,7 @@ void
CoalesceProvider::provideStreamData(QPDFObjGen const&, Pipeline* p)
{
QTC::TC("qpdf", "QPDFObjectHandle coalesce provide stream data");
- std::string description =
- "page object " + containing_page.getObjGen().unparse(' ');
+ std::string description = "page object " + containing_page.getObjGen().unparse(' ');
std::string all_description;
old_contents.pipeContentStreams(p, description, all_description);
}
@@ -173,8 +160,7 @@ QPDFObjectHandle::ParserCallbacks::handleObject(QPDFObjectHandle)
}
void
-QPDFObjectHandle::ParserCallbacks::handleObject(
- QPDFObjectHandle oh, size_t, size_t)
+QPDFObjectHandle::ParserCallbacks::handleObject(QPDFObjectHandle oh, size_t, size_t)
{
// This version of handleObject was added in qpdf 9. If the
// developer did not override it, fall back to the older
@@ -365,9 +351,7 @@ QPDFObjectHandle::isDirectNull() const
{
// Don't call dereference() -- this is a const method, and we know
// objid == 0, so there's nothing to resolve.
- return (
- isInitialized() && (getObjectID() == 0) &&
- (obj->getTypeCode() == ::ot_null));
+ return (isInitialized() && (getObjectID() == 0) && (obj->getTypeCode() == ::ot_null));
}
bool
@@ -470,8 +454,7 @@ QPDFObjectHandle::isReserved()
bool
QPDFObjectHandle::isScalar()
{
- return isBool() || isInteger() || isName() || isNull() || isReal() ||
- isString();
+ return isBool() || isInteger() || isName() || isNull() || isReal() || isString();
}
bool
@@ -481,17 +464,14 @@ QPDFObjectHandle::isNameAndEquals(std::string const& name)
}
bool
-QPDFObjectHandle::isDictionaryOfType(
- std::string const& type, std::string const& subtype)
+QPDFObjectHandle::isDictionaryOfType(std::string const& type, std::string const& subtype)
{
- return isDictionary() &&
- (type.empty() || getKey("/Type").isNameAndEquals(type)) &&
+ return isDictionary() && (type.empty() || getKey("/Type").isNameAndEquals(type)) &&
(subtype.empty() || getKey("/Subtype").isNameAndEquals(subtype));
}
bool
-QPDFObjectHandle::isStreamOfType(
- std::string const& type, std::string const& subtype)
+QPDFObjectHandle::isStreamOfType(std::string const& type, std::string const& subtype)
{
return isStream() && getDict().isDictionaryOfType(type, subtype);
}
@@ -555,13 +535,11 @@ QPDFObjectHandle::getIntValueAsInt()
long long v = getIntValue();
if (v < INT_MIN) {
QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MIN");
- warnIfPossible(
- "requested value of integer is too small; returning INT_MIN");
+ warnIfPossible("requested value of integer is too small; returning INT_MIN");
result = INT_MIN;
} else if (v > INT_MAX) {
QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MAX");
- warnIfPossible(
- "requested value of integer is too big; returning INT_MAX");
+ warnIfPossible("requested value of integer is too big; returning INT_MAX");
result = INT_MAX;
} else {
result = static_cast<int>(v);
@@ -586,8 +564,7 @@ QPDFObjectHandle::getUIntValue()
long long v = getIntValue();
if (v < 0) {
QTC::TC("qpdf", "QPDFObjectHandle uint returning 0");
- warnIfPossible(
- "unsigned value request for negative number; returning 0");
+ warnIfPossible("unsigned value request for negative number; returning 0");
} else {
result = static_cast<unsigned long long>(v);
}
@@ -611,8 +588,7 @@ QPDFObjectHandle::getUIntValueAsUInt()
long long v = getIntValue();
if (v < 0) {
QTC::TC("qpdf", "QPDFObjectHandle uint uint returning 0");
- warnIfPossible(
- "unsigned integer value request for negative number; returning 0");
+ warnIfPossible("unsigned integer value request for negative number; returning 0");
result = 0;
} else if (v > UINT_MAX) {
QTC::TC("qpdf", "QPDFObjectHandle uint returning UINT_MAX");
@@ -878,8 +854,7 @@ QPDFObjectHandle::getArrayAsMatrix()
return {};
}
}
- return Matrix(
- items[0], items[1], items[2], items[3], items[4], items[5]);
+ return Matrix(items[0], items[1], items[2], items[3], items[4], items[5]);
}
return {};
}
@@ -928,8 +903,7 @@ QPDFObjectHandle::insertItem(int at, QPDFObjectHandle const& item)
{
if (auto array = asArray()) {
if (!array->insert(at, item)) {
- objectWarning(
- "ignoring attempt to insert out of bounds array item");
+ objectWarning("ignoring attempt to insert out of bounds array item");
QTC::TC("qpdf", "QPDFObjectHandle insert array bounds");
}
} else {
@@ -981,8 +955,7 @@ QPDFObjectHandle
QPDFObjectHandle::eraseItemAndGetOld(int at)
{
auto array = asArray();
- auto result =
- (array && at < array->size() && at >= 0) ? array->at(at) : newNull();
+ auto result = (array && at < array->size() && at >= 0) ? array->at(at) : newNull();
eraseItem(at);
return result;
}
@@ -1002,8 +975,7 @@ QPDFObjectHandle::hasKey(std::string const& key)
if (dict) {
return dict->hasKey(key);
} else {
- typeWarning(
- "dictionary", "returning false for a key containment request");
+ typeWarning("dictionary", "returning false for a key containment request");
QTC::TC("qpdf", "QPDFObjectHandle dictionary false for hasKey");
return false;
}
@@ -1017,8 +989,7 @@ QPDFObjectHandle::getKey(std::string const& key)
} else {
typeWarning("dictionary", "returning null for attempted key retrieval");
QTC::TC("qpdf", "QPDFObjectHandle dictionary null for getKey");
- static auto constexpr msg =
- " -> null returned from getting key $VD from non-Dictionary"sv;
+ static auto constexpr msg = " -> null returned from getting key $VD from non-Dictionary"sv;
return QPDF_Null::create(obj, msg, "");
}
}
@@ -1096,8 +1067,7 @@ QPDFObjectHandle::makeResourcesIndirect(QPDF& owning_qpdf)
void
QPDFObjectHandle::mergeResources(
- QPDFObjectHandle other,
- std::map<std::string, std::map<std::string, std::string>>* conflicts)
+ QPDFObjectHandle other, std::map<std::string, std::map<std::string, std::string>>* conflicts)
{
if (!(isDictionary() && other.isDictionary())) {
QTC::TC("qpdf", "QPDFObjectHandle merge top type mismatch");
@@ -1128,8 +1098,7 @@ QPDFObjectHandle::mergeResources(
// subdictionaries just to get this shallow copy
// functionality.
QTC::TC("qpdf", "QPDFObjectHandle replace with copy");
- this_val =
- replaceKeyAndGetNew(rtype, this_val.shallowCopy());
+ this_val = replaceKeyAndGetNew(rtype, this_val.shallowCopy());
}
std::map<QPDFObjGen, std::string> og_to_name;
std::set<std::string> rnames;
@@ -1140,8 +1109,7 @@ QPDFObjectHandle::mergeResources(
QPDFObjectHandle rval = ov_iter.second;
if (!this_val.hasKey(key)) {
if (!rval.isIndirect()) {
- QTC::TC(
- "qpdf", "QPDFObjectHandle merge shallow copy");
+ QTC::TC("qpdf", "QPDFObjectHandle merge shallow copy");
rval = rval.shallowCopy();
}
this_val.replaceKey(key, rval);
@@ -1160,8 +1128,8 @@ QPDFObjectHandle::mergeResources(
}
} else {
QTC::TC("qpdf", "QPDFObjectHandle merge generate");
- std::string new_key = getUniqueResourceName(
- key + "_", min_suffix, &rnames);
+ std::string new_key =
+ getUniqueResourceName(key + "_", min_suffix, &rnames);
(*conflicts)[rtype][key] = new_key;
this_val.replaceKey(new_key, rval);
}
@@ -1237,8 +1205,7 @@ QPDFObjectHandle::getUniqueResourceName(
// Dictionary mutators
void
-QPDFObjectHandle::replaceKey(
- std::string const& key, QPDFObjectHandle const& value)
+QPDFObjectHandle::replaceKey(std::string const& key, QPDFObjectHandle const& value)
{
auto dict = asDictionary();
if (dict) {
@@ -1251,16 +1218,14 @@ QPDFObjectHandle::replaceKey(
}
QPDFObjectHandle
-QPDFObjectHandle::replaceKeyAndGetNew(
- std::string const& key, QPDFObjectHandle const& value)
+QPDFObjectHandle::replaceKeyAndGetNew(std::string const& key, QPDFObjectHandle const& value)
{
replaceKey(key, value);
return value;
}
QPDFObjectHandle
-QPDFObjectHandle::replaceKeyAndGetOld(
- std::string const& key, QPDFObjectHandle const& value)
+QPDFObjectHandle::replaceKeyAndGetOld(std::string const& key, QPDFObjectHandle const& value)
{
QPDFObjectHandle old = removeKeyAndGetOld(key);
replaceKey(key, value);
@@ -1292,8 +1257,7 @@ QPDFObjectHandle::removeKeyAndGetOld(std::string const& key)
}
void
-QPDFObjectHandle::replaceOrRemoveKey(
- std::string const& key, QPDFObjectHandle const& value)
+QPDFObjectHandle::replaceOrRemoveKey(std::string const& key, QPDFObjectHandle const& value)
{
replaceKey(key, value);
}
@@ -1351,12 +1315,7 @@ QPDFObjectHandle::pipeStreamData(
bool will_retry)
{
return asStreamWithAssert()->pipeStreamData(
- p,
- filtering_attempted,
- encode_flags,
- decode_level,
- suppress_warnings,
- will_retry);
+ p, filtering_attempted, encode_flags, decode_level, suppress_warnings, will_retry);
}
bool
@@ -1369,18 +1328,12 @@ QPDFObjectHandle::pipeStreamData(
{
bool filtering_attempted;
asStreamWithAssert()->pipeStreamData(
- p,
- &filtering_attempted,
- encode_flags,
- decode_level,
- suppress_warnings,
- will_retry);
+ p, &filtering_attempted, encode_flags, decode_level, suppress_warnings, will_retry);
return filtering_attempted;
}
bool
-QPDFObjectHandle::pipeStreamData(
- Pipeline* p, bool filter, bool normalize, bool compress)
+QPDFObjectHandle::pipeStreamData(Pipeline* p, bool filter, bool normalize, bool compress)
{
int encode_flags = 0;
qpdf_stream_decode_level_e decode_level = qpdf_dl_none;
@@ -1407,9 +1360,7 @@ QPDFObjectHandle::replaceStreamData(
void
QPDFObjectHandle::replaceStreamData(
- std::string const& data,
- QPDFObjectHandle const& filter,
- QPDFObjectHandle const& decode_parms)
+ std::string const& data, QPDFObjectHandle const& filter, QPDFObjectHandle const& decode_parms)
{
auto b = std::make_shared<Buffer>(data.length());
unsigned char* bp = b->getBuffer();
@@ -1454,10 +1405,7 @@ namespace
bool
provideStreamData(
- QPDFObjGen const&,
- Pipeline* pipeline,
- bool suppress_warnings,
- bool will_retry) override
+ QPDFObjGen const&, Pipeline* pipeline, bool suppress_warnings, bool will_retry) override
{
return p2(pipeline, suppress_warnings, will_retry);
}
@@ -1474,8 +1422,7 @@ QPDFObjectHandle::replaceStreamData(
QPDFObjectHandle const& filter,
QPDFObjectHandle const& decode_parms)
{
- auto sdp =
- std::shared_ptr<StreamDataProvider>(new FunctionProvider(provider));
+ auto sdp = std::shared_ptr<StreamDataProvider>(new FunctionProvider(provider));
asStreamWithAssert()->replaceStreamData(sdp, filter, decode_parms);
}
@@ -1485,8 +1432,7 @@ QPDFObjectHandle::replaceStreamData(
QPDFObjectHandle const& filter,
QPDFObjectHandle const& decode_parms)
{
- auto sdp =
- std::shared_ptr<StreamDataProvider>(new FunctionProvider(provider));
+ auto sdp = std::shared_ptr<StreamDataProvider>(new FunctionProvider(provider));
asStreamWithAssert()->replaceStreamData(sdp, filter, decode_parms);
}
@@ -1515,8 +1461,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
QPDFExc(
qpdf_e_damaged_pdf,
"",
- description + ": item index " + std::to_string(i) +
- " (from 0)",
+ description + ": item index " + std::to_string(i) + " (from 0)",
0,
"ignoring non-stream in an array of streams"));
}
@@ -1553,8 +1498,7 @@ QPDFObjectHandle::getPageContents()
{
std::string description = "page object " + getObjGen().unparse(' ');
std::string all_description;
- return this->getKey("/Contents")
- .arrayOrStreamToStreamArray(description, all_description);
+ return this->getKey("/Contents").arrayOrStreamToStreamArray(description, all_description);
}
void
@@ -1600,10 +1544,7 @@ QPDFObjectHandle::rotatePage(int angle, bool relative)
break;
}
}
- QTC::TC(
- "qpdf",
- "QPDFObjectHandle found old angle",
- visited.size() > 1 ? 0 : 1);
+ QTC::TC("qpdf", "QPDFObjectHandle found old angle", visited.size() > 1 ? 0 : 1);
if ((old_angle % 90) != 0) {
old_angle = 0;
}
@@ -1632,14 +1573,12 @@ QPDFObjectHandle::coalesceContentStreams()
// incorrect way. However, it can happen in a PDF file whose
// page structure is direct, which is against spec but still
// possible to hand construct, as in fuzz issue 27393.
- QPDF& qpdf = getQPDF(
- "coalesceContentStreams called on object with no associated PDF file");
+ QPDF& qpdf = getQPDF("coalesceContentStreams called on object with no associated PDF file");
QPDFObjectHandle new_contents = newStream(&qpdf);
this->replaceKey("/Contents", new_contents);
- auto provider = std::shared_ptr<StreamDataProvider>(
- new CoalesceProvider(*this, contents));
+ auto provider = std::shared_ptr<StreamDataProvider>(new CoalesceProvider(*this, contents));
new_contents.replaceStreamData(provider, newNull(), newNull());
}
@@ -1659,8 +1598,7 @@ std::string
QPDFObjectHandle::unparseResolved()
{
if (!dereference()) {
- throw std::logic_error(
- "attempted to dereference an uninitialized QPDFObjectHandle");
+ throw std::logic_error("attempted to dereference an uninitialized QPDFObjectHandle");
}
return obj->unparse();
}
@@ -1689,8 +1627,7 @@ QPDFObjectHandle::getJSON(int json_version, bool dereference_indirect)
if ((!dereference_indirect) && isIndirect()) {
return JSON::makeString(unparse());
} else if (!dereference()) {
- throw std::logic_error(
- "attempted to dereference an uninitialized QPDFObjectHandle");
+ throw std::logic_error("attempted to dereference an uninitialized QPDFObjectHandle");
} else {
return obj->getJSON(json_version);
}
@@ -1720,24 +1657,19 @@ QPDFObjectHandle::wrapInArray()
}
QPDFObjectHandle
-QPDFObjectHandle::parse(
- std::string const& object_str, std::string const& object_description)
+QPDFObjectHandle::parse(std::string const& object_str, std::string const& object_description)
{
return parse(nullptr, object_str, object_description);
}
QPDFObjectHandle
QPDFObjectHandle::parse(
- QPDF* context,
- std::string const& object_str,
- std::string const& object_description)
+ QPDF* context, std::string const& object_str, std::string const& object_description)
{
- auto input = std::shared_ptr<InputSource>(
- new BufferInputSource("parsed object", object_str));
+ auto input = std::shared_ptr<InputSource>(new BufferInputSource("parsed object", object_str));
QPDFTokenizer tokenizer;
bool empty = false;
- QPDFObjectHandle result =
- parse(input, object_description, tokenizer, empty, nullptr, context);
+ QPDFObjectHandle result = parse(input, object_description, tokenizer, empty, nullptr, context);
size_t offset = QIntC::to_size(input->tell());
while (offset < object_str.length()) {
if (!isspace(object_str.at(offset))) {
@@ -1759,8 +1691,7 @@ QPDFObjectHandle::pipePageContents(Pipeline* p)
{
std::string description = "page object " + getObjGen().unparse(' ');
std::string all_description;
- this->getKey("/Contents")
- .pipeContentStreams(p, description, all_description);
+ this->getKey("/Contents").pipeContentStreams(p, description, all_description);
}
void
@@ -1798,8 +1729,7 @@ void
QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks)
{
std::string description = "page object " + getObjGen().unparse(' ');
- this->getKey("/Contents")
- .parseContentStream_internal(description, callbacks);
+ this->getKey("/Contents").parseContentStream_internal(description, callbacks);
}
void
@@ -1812,8 +1742,7 @@ QPDFObjectHandle::parseAsContents(ParserCallbacks* callbacks)
void
QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next)
{
- auto description =
- "token filter for page object " + getObjGen().unparse(' ');
+ auto description = "token filter for page object " + getObjGen().unparse(' ');
Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next);
this->pipePageContents(&token_pipeline);
}
@@ -1827,11 +1756,9 @@ QPDFObjectHandle::filterAsContents(TokenFilter* filter, Pipeline* next)
}
void
-QPDFObjectHandle::parseContentStream(
- QPDFObjectHandle stream_or_array, ParserCallbacks* callbacks)
+QPDFObjectHandle::parseContentStream(QPDFObjectHandle stream_or_array, ParserCallbacks* callbacks)
{
- stream_or_array.parseContentStream_internal(
- "content stream objects", callbacks);
+ stream_or_array.parseContentStream_internal("content stream objects", callbacks);
}
void
@@ -1844,8 +1771,7 @@ QPDFObjectHandle::parseContentStream_internal(
auto stream_data = buf.getBufferSharedPointer();
callbacks->contentSize(stream_data->getSize());
try {
- parseContentStream_data(
- stream_data, all_description, callbacks, getOwningQPDF());
+ parseContentStream_data(stream_data, all_description, callbacks, getOwningQPDF());
} catch (TerminateParsing&) {
return;
}
@@ -1860,8 +1786,8 @@ QPDFObjectHandle::parseContentStream_data(
QPDF* context)
{
size_t stream_length = stream_data->getSize();
- auto input = std::shared_ptr<InputSource>(
- new BufferInputSource(description, stream_data.get()));
+ auto input =
+ std::shared_ptr<InputSource>(new BufferInputSource(description, stream_data.get()));
QPDFTokenizer tokenizer;
tokenizer.allowEOF();
bool empty = false;
@@ -1873,8 +1799,7 @@ QPDFObjectHandle::parseContentStream_data(
tokenizer.readToken(input, "content", true);
qpdf_offset_t offset = input->getLastOffset();
input->seek(offset, SEEK_SET);
- auto obj = QPDFParser(input, "content", tokenizer, nullptr, context)
- .parse(empty, true);
+ auto obj = QPDFParser(input, "content", tokenizer, nullptr, context).parse(empty, true);
if (!obj.isInitialized()) {
// EOF
break;
@@ -1888,8 +1813,7 @@ QPDFObjectHandle::parseContentStream_data(
char ch;
input->read(&ch, 1);
tokenizer.expectInlineImage(input);
- QPDFTokenizer::Token t =
- tokenizer.readToken(input, description, true);
+ QPDFTokenizer::Token t = tokenizer.readToken(input, description, true);
offset = input->getLastOffset();
length = QIntC::to_size(input->tell() - offset);
if (t.getType() == QPDFTokenizer::tt_bad) {
@@ -1906,9 +1830,7 @@ QPDFObjectHandle::parseContentStream_data(
std::string inline_image = t.getValue();
QTC::TC("qpdf", "QPDFObjectHandle inline image token");
callbacks->handleObject(
- QPDFObjectHandle::newInlineImage(inline_image),
- QIntC::to_size(offset),
- length);
+ QPDFObjectHandle::newInlineImage(inline_image), QIntC::to_size(offset), length);
}
}
}
@@ -1936,8 +1858,7 @@ QPDFObjectHandle::parse(
StringDecrypter* decrypter,
QPDF* context)
{
- return QPDFParser(input, object_description, tokenizer, decrypter, context)
- .parse(empty, false);
+ return QPDFParser(input, object_description, tokenizer, decrypter, context).parse(empty, false);
}
qpdf_offset_t
@@ -1975,11 +1896,9 @@ QPDFObjectHandle::newReal(std::string const& value)
}
QPDFObjectHandle
-QPDFObjectHandle::newReal(
- double value, int decimal_places, bool trim_trailing_zeroes)
+QPDFObjectHandle::newReal(double value, int decimal_places, bool trim_trailing_zeroes)
{
- return QPDFObjectHandle(
- QPDF_Real::create(value, decimal_places, trim_trailing_zeroes));
+ return QPDFObjectHandle(QPDF_Real::create(value, decimal_places, trim_trailing_zeroes));
}
QPDFObjectHandle
@@ -2086,8 +2005,7 @@ QPDFObjectHandle::newDictionary()
}
QPDFObjectHandle
-QPDFObjectHandle::newDictionary(
- std::map<std::string, QPDFObjectHandle> const& items)
+QPDFObjectHandle::newDictionary(std::map<std::string, QPDFObjectHandle> const& items)
{
return QPDFObjectHandle(QPDF_Dictionary::create(items));
}
@@ -2096,8 +2014,7 @@ QPDFObjectHandle
QPDFObjectHandle::newStream(QPDF* qpdf)
{
if (qpdf == nullptr) {
- throw std::runtime_error(
- "attempt to create stream in null qpdf object");
+ throw std::runtime_error("attempt to create stream in null qpdf object");
}
QTC::TC("qpdf", "QPDFObjectHandle newStream");
return qpdf->newStream();
@@ -2107,8 +2024,7 @@ QPDFObjectHandle
QPDFObjectHandle::newStream(QPDF* qpdf, std::shared_ptr<Buffer> data)
{
if (qpdf == nullptr) {
- throw std::runtime_error(
- "attempt to create stream in null qpdf object");
+ throw std::runtime_error("attempt to create stream in null qpdf object");
}
QTC::TC("qpdf", "QPDFObjectHandle newStream with data");
return qpdf->newStream(data);
@@ -2118,8 +2034,7 @@ QPDFObjectHandle
QPDFObjectHandle::newStream(QPDF* qpdf, std::string const& data)
{
if (qpdf == nullptr) {
- throw std::runtime_error(
- "attempt to create stream in null qpdf object");
+ throw std::runtime_error("attempt to create stream in null qpdf object");
}
QTC::TC("qpdf", "QPDFObjectHandle newStream with string");
return qpdf->newStream(data);
@@ -2129,21 +2044,18 @@ QPDFObjectHandle
QPDFObjectHandle::newReserved(QPDF* qpdf)
{
if (qpdf == nullptr) {
- throw std::runtime_error(
- "attempt to create reserved object in null qpdf object");
+ throw std::runtime_error("attempt to create reserved object in null qpdf object");
}
return qpdf->newReserved();
}
void
-QPDFObjectHandle::setObjectDescription(
- QPDF* owning_qpdf, std::string const& object_description)
+QPDFObjectHandle::setObjectDescription(QPDF* owning_qpdf, std::string const& object_description)
{
// This is called during parsing on newly created direct objects,
// so we can't call dereference() here.
if (isInitialized() && obj.get()) {
- auto descr =
- std::make_shared<QPDFValue::Description>(object_description);
+ auto descr = std::make_shared<QPDFValue::Description>(object_description);
obj->setDescription(owning_qpdf, descr);
}
}
@@ -2186,8 +2098,7 @@ QPDFObjectHandle::makeDirect(QPDFObjGen::set& visited, bool stop_at_streams)
"indirect to direct");
}
- if (isBool() || isInteger() || isName() || isNull() || isReal() ||
- isString()) {
+ if (isBool() || isInteger() || isName() || isNull() || isReal() || isString()) {
this->obj = obj->copy(true);
} else if (isArray()) {
std::vector<QPDFObjectHandle> items;
@@ -2207,11 +2118,9 @@ QPDFObjectHandle::makeDirect(QPDFObjGen::set& visited, bool stop_at_streams)
}
this->obj = QPDF_Dictionary::create(items);
} else if (isStream()) {
- QTC::TC(
- "qpdf", "QPDFObjectHandle copy stream", stop_at_streams ? 0 : 1);
+ QTC::TC("qpdf", "QPDFObjectHandle copy stream", stop_at_streams ? 0 : 1);
if (!stop_at_streams) {
- throw std::runtime_error(
- "attempt to make a stream into a direct object");
+ throw std::runtime_error("attempt to make a stream into a direct object");
}
} else if (isReserved()) {
throw std::logic_error("QPDFObjectHandle: attempting to make a"
@@ -2259,16 +2168,14 @@ QPDFObjectHandle::assertInitialized() const
}
void
-QPDFObjectHandle::typeWarning(
- char const* expected_type, std::string const& warning)
+QPDFObjectHandle::typeWarning(char const* expected_type, std::string const& warning)
{
QPDF* context = nullptr;
std::string description;
// Type checks above guarantee that the object has been dereferenced.
// Nevertheless, dereference throws exceptions in the test suite
if (!dereference()) {
- throw std::logic_error(
- "attempted to dereference an uninitialized QPDFObjectHandle");
+ throw std::logic_error("attempted to dereference an uninitialized QPDFObjectHandle");
}
this->obj->getDescription(context, description);
// Null context handled by warn
@@ -2279,9 +2186,8 @@ QPDFObjectHandle::typeWarning(
"",
description,
0,
- std::string("operation for ") + expected_type +
- " attempted on object of type " + getTypeName() + ": " +
- warning));
+ std::string("operation for ") + expected_type + " attempted on object of type " +
+ getTypeName() + ": " + warning));
}
void
@@ -2312,8 +2218,8 @@ QPDFObjectHandle::assertType(char const* type_name, bool istype)
{
if (!istype) {
throw std::runtime_error(
- std::string("operation for ") + type_name +
- " attempted on object of type " + getTypeName());
+ std::string("operation for ") + type_name + " attempted on object of type " +
+ getTypeName());
}
}
@@ -2393,8 +2299,7 @@ void
QPDFObjectHandle::assertIndirect()
{
if (!isIndirect()) {
- throw std::logic_error(
- "operation for indirect object attempted on direct object");
+ throw std::logic_error("operation for indirect object attempted on direct object");
}
}
@@ -2471,9 +2376,8 @@ QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const
auto item_qpdf = item.getOwningQPDF();
if ((qpdf != nullptr) && (item_qpdf != nullptr) && (qpdf != item_qpdf)) {
QTC::TC("qpdf", "QPDFObjectHandle check ownership");
- throw std::logic_error(
- "Attempting to add an object from a different QPDF."
- " Use QPDF::copyForeignObject to add objects from another file.");
+ throw std::logic_error("Attempting to add an object from a different QPDF."
+ " Use QPDF::copyForeignObject to add objects from another file.");
}
}
@@ -2545,8 +2449,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::operator->()
}
bool
-QPDFObjectHandle::QPDFDictItems::iterator::operator==(
- iterator const& other) const
+QPDFObjectHandle::QPDFDictItems::iterator::operator==(iterator const& other) const
{
if (m->is_end && other.m->is_end) {
return true;
@@ -2557,8 +2460,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::operator==(
return (this->ivalue.first == other.ivalue.first);
}
-QPDFObjectHandle::QPDFDictItems::iterator::iterator(
- QPDFObjectHandle& oh, bool for_begin) :
+QPDFObjectHandle::QPDFDictItems::iterator::iterator(QPDFObjectHandle& oh, bool for_begin) :
m(new Members(oh, for_begin))
{
updateIValue();
@@ -2577,8 +2479,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::updateIValue()
}
}
-QPDFObjectHandle::QPDFDictItems::iterator::Members::Members(
- QPDFObjectHandle& oh, bool for_begin) :
+QPDFObjectHandle::QPDFDictItems::iterator::Members::Members(QPDFObjectHandle& oh, bool for_begin) :
oh(oh)
{
this->keys = oh.getKeys();
@@ -2637,14 +2538,12 @@ QPDFObjectHandle::QPDFArrayItems::iterator::operator->()
}
bool
-QPDFObjectHandle::QPDFArrayItems::iterator::operator==(
- iterator const& other) const
+QPDFObjectHandle::QPDFArrayItems::iterator::operator==(iterator const& other) const
{
return (m->item_number == other.m->item_number);
}
-QPDFObjectHandle::QPDFArrayItems::iterator::iterator(
- QPDFObjectHandle& oh, bool for_begin) :
+QPDFObjectHandle::QPDFArrayItems::iterator::iterator(QPDFObjectHandle& oh, bool for_begin) :
m(new Members(oh, for_begin))
{
updateIValue();
@@ -2661,8 +2560,7 @@ QPDFObjectHandle::QPDFArrayItems::iterator::updateIValue()
}
}
-QPDFObjectHandle::QPDFArrayItems::iterator::Members::Members(
- QPDFObjectHandle& oh, bool for_begin) :
+QPDFObjectHandle::QPDFArrayItems::iterator::Members::Members(QPDFObjectHandle& oh, bool for_begin) :
oh(oh)
{
this->item_number = for_begin ? 0 : oh.getArrayNItems();
@@ -2698,8 +2596,7 @@ QPDFObjectHandle::getQPDF(std::string const& error_msg) const
{
auto result = isInitialized() ? this->obj->getQPDF() : nullptr;
if (result == nullptr) {
- throw std::runtime_error(
- error_msg == "" ? "attempt to use a null qpdf object" : error_msg);
+ throw std::runtime_error(error_msg == "" ? "attempt to use a null qpdf object" : error_msg);
}
return *result;
}
@@ -2717,6 +2614,5 @@ QPDFObjectHandle::setParsedOffset(qpdf_offset_t offset)
QPDFObjectHandle
operator""_qpdf(char const* v, size_t len)
{
- return QPDFObjectHandle::parse(
- std::string(v, len), "QPDFObjectHandle literal");
+ return QPDFObjectHandle::parse(std::string(v, len), "QPDFObjectHandle literal");
}
diff --git a/libqpdf/QPDFOutlineDocumentHelper.cc b/libqpdf/QPDFOutlineDocumentHelper.cc
index efb31194..45ed696a 100644
--- a/libqpdf/QPDFOutlineDocumentHelper.cc
+++ b/libqpdf/QPDFOutlineDocumentHelper.cc
@@ -17,8 +17,7 @@ QPDFOutlineDocumentHelper::QPDFOutlineDocumentHelper(QPDF& qpdf) :
QPDFObjectHandle cur = outlines.getKey("/First");
QPDFObjGen::set seen;
while (!cur.isNull() && seen.add(cur)) {
- m->outlines.push_back(
- QPDFOutlineObjectHelper::Accessor::create(cur, *this, 1));
+ m->outlines.push_back(QPDFOutlineObjectHelper::Accessor::create(cur, *this, 1));
cur = cur.getKey("/Next");
}
}
@@ -81,8 +80,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name)
if (names.isDictionary()) {
QPDFObjectHandle dests = names.getKey("/Dests");
if (dests.isDictionary()) {
- m->names_dest = std::make_shared<QPDFNameTreeObjectHelper>(
- dests, this->qpdf);
+ m->names_dest = std::make_shared<QPDFNameTreeObjectHelper>(dests, this->qpdf);
}
}
}
diff --git a/libqpdf/QPDFOutlineObjectHelper.cc b/libqpdf/QPDFOutlineObjectHelper.cc
index 11c6c2e1..37e2c0d2 100644
--- a/libqpdf/QPDFOutlineObjectHelper.cc
+++ b/libqpdf/QPDFOutlineObjectHelper.cc
@@ -18,8 +18,7 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper(
// temporarily changing max depth to 1.
return;
}
- if (QPDFOutlineDocumentHelper::Accessor::checkSeen(
- m->dh, this->oh.getObjGen())) {
+ if (QPDFOutlineDocumentHelper::Accessor::checkSeen(m->dh, this->oh.getObjGen())) {
QTC::TC("qpdf", "QPDFOutlineObjectHelper loop");
return;
}
diff --git a/libqpdf/QPDFPageDocumentHelper.cc b/libqpdf/QPDFPageDocumentHelper.cc
index 31d84e4b..06ec5ff7 100644
--- a/libqpdf/QPDFPageDocumentHelper.cc
+++ b/libqpdf/QPDFPageDocumentHelper.cc
@@ -43,8 +43,7 @@ void
QPDFPageDocumentHelper::addPageAt(
QPDFPageObjectHelper newpage, bool before, QPDFPageObjectHelper refpage)
{
- this->qpdf.addPageAt(
- newpage.getObjectHandle(), before, refpage.getObjectHandle());
+ this->qpdf.addPageAt(newpage.getObjectHandle(), before, refpage.getObjectHandle());
}
void
@@ -54,8 +53,7 @@ QPDFPageDocumentHelper::removePage(QPDFPageObjectHelper page)
}
void
-QPDFPageDocumentHelper::flattenAnnotations(
- int required_flags, int forbidden_flags)
+QPDFPageDocumentHelper::flattenAnnotations(int required_flags, int forbidden_flags)
{
QPDFAcroFormDocumentHelper afdh(this->qpdf);
if (afdh.getNeedAppearances()) {
@@ -67,14 +65,11 @@ QPDFPageDocumentHelper::flattenAnnotations(
for (auto& ph: getAllPages()) {
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
if (!resources.isDictionary()) {
- QTC::TC(
- "qpdf",
- "QPDFPageDocumentHelper flatten resources missing or invalid");
+ QTC::TC("qpdf", "QPDFPageDocumentHelper flatten resources missing or invalid");
resources = ph.getObjectHandle().replaceKeyAndGetNew(
"/Resources", QPDFObjectHandle::newDictionary());
}
- flattenAnnotationsForPage(
- ph, resources, afdh, required_flags, forbidden_flags);
+ flattenAnnotationsForPage(ph, resources, afdh, required_flags, forbidden_flags);
}
if (!afdh.getNeedAppearances()) {
this->qpdf.getRoot().removeKey("/AcroForm");
@@ -104,21 +99,17 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage(
bool is_widget = (aoh.getSubtype() == "/Widget");
bool process = true;
if (need_appearances && is_widget) {
- QTC::TC(
- "qpdf", "QPDFPageDocumentHelper skip widget need appearances");
+ QTC::TC("qpdf", "QPDFPageDocumentHelper skip widget need appearances");
process = false;
}
if (process && as.isStream()) {
if (is_widget) {
QTC::TC("qpdf", "QPDFPageDocumentHelper merge DR");
QPDFFormFieldObjectHelper ff = afdh.getFieldForAnnotation(aoh);
- QPDFObjectHandle as_resources =
- as.getDict().getKey("/Resources");
+ QPDFObjectHandle as_resources = as.getDict().getKey("/Resources");
if (as_resources.isIndirect()) {
- QTC::TC(
- "qpdf", "QPDFPageDocumentHelper indirect as resources");
- as.getDict().replaceKey(
- "/Resources", as_resources.shallowCopy());
+ QTC::TC("qpdf", "QPDFPageDocumentHelper indirect as resources");
+ as.getDict().replaceKey("/Resources", as_resources.shallowCopy());
as_resources = as.getDict().getKey("/Resources");
}
as_resources.mergeResources(ff.getDefaultResources());
@@ -126,8 +117,8 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage(
QTC::TC("qpdf", "QPDFPageDocumentHelper non-widget annotation");
}
std::string name = resources.getUniqueResourceName("/Fxo", next_fx);
- std::string content = aoh.getPageContentForAppearance(
- name, rotate, required_flags, forbidden_flags);
+ std::string content =
+ aoh.getPageContentForAppearance(name, rotate, required_flags, forbidden_flags);
if (!content.empty()) {
resources.mergeResources("<< /XObject << >> >>"_qpdf);
resources.getKey("/XObject").replaceKey(name, as);
@@ -140,9 +131,7 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage(
// unchecked checkboxes and radio buttons, popup windows
// associated with comments that aren't visible, and other
// types of annotations that aren't visible.
- QTC::TC(
- "qpdf",
- "QPDFPageDocumentHelper ignore annotation with no appearance");
+ QTC::TC("qpdf", "QPDFPageDocumentHelper ignore annotation with no appearance");
} else {
new_annots.push_back(aoh.getObjectHandle());
}
@@ -154,11 +143,9 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage(
page_oh.removeKey("/Annots");
} else {
QPDFObjectHandle old_annots = page_oh.getKey("/Annots");
- QPDFObjectHandle new_annots_oh =
- QPDFObjectHandle::newArray(new_annots);
+ QPDFObjectHandle new_annots_oh = QPDFObjectHandle::newArray(new_annots);
if (old_annots.isIndirect()) {
- QTC::TC(
- "qpdf", "QPDFPageDocumentHelper replace indirect annots");
+ QTC::TC("qpdf", "QPDFPageDocumentHelper replace indirect annots");
this->qpdf.replaceObject(old_annots.getObjGen(), new_annots_oh);
} else {
QTC::TC("qpdf", "QPDFPageDocumentHelper replace direct annots");
diff --git a/libqpdf/QPDFPageLabelDocumentHelper.cc b/libqpdf/QPDFPageLabelDocumentHelper.cc
index b74f940b..4a9b456f 100644
--- a/libqpdf/QPDFPageLabelDocumentHelper.cc
+++ b/libqpdf/QPDFPageLabelDocumentHelper.cc
@@ -8,8 +8,8 @@ QPDFPageLabelDocumentHelper::QPDFPageLabelDocumentHelper(QPDF& qpdf) :
{
QPDFObjectHandle root = qpdf.getRoot();
if (root.hasKey("/PageLabels")) {
- m->labels = std::make_shared<QPDFNumberTreeObjectHelper>(
- root.getKey("/PageLabels"), this->qpdf);
+ m->labels =
+ std::make_shared<QPDFNumberTreeObjectHelper>(root.getKey("/PageLabels"), this->qpdf);
}
}
@@ -66,8 +66,7 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange(
QPDFObjectHandle label = getLabelForPage(start_idx);
if (label.isNull()) {
label = QPDFObjectHandle::newDictionary();
- label.replaceKey(
- "/St", QPDFObjectHandle::newInteger(1 + new_start_idx));
+ label.replaceKey("/St", QPDFObjectHandle::newInteger(1 + new_start_idx));
}
// See if the new label is redundant based on the previous entry
// in the vector. If so, don't add it.
@@ -80,8 +79,8 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange(
(label.getKey("/S").unparse() == last.getKey("/S").unparse()) &&
(label.getKey("/P").unparse() == last.getKey("/P").unparse()) &&
label.getKey("/St").isInteger() && last.getKey("/St").isInteger()) {
- long long int st_delta = label.getKey("/St").getIntValue() -
- last.getKey("/St").getIntValue();
+ long long int st_delta =
+ label.getKey("/St").getIntValue() - last.getKey("/St").getIntValue();
long long int idx_delta = new_start_idx - last_idx.getIntValue();
if (st_delta == idx_delta) {
QTC::TC("qpdf", "QPDFPageLabelDocumentHelper skip first");
@@ -96,8 +95,7 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange(
long long int idx_offset = new_start_idx - start_idx;
for (long long i = start_idx + 1; i <= end_idx; ++i) {
- if (m->labels->hasIndex(i) &&
- (label = getLabelForPage(i)).isDictionary()) {
+ if (m->labels->hasIndex(i) && (label = getLabelForPage(i)).isDictionary()) {
new_labels.push_back(QPDFObjectHandle::newInteger(i + idx_offset));
new_labels.push_back(label);
}
diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc
index f884b071..a34ed28f 100644
--- a/libqpdf/QPDFPageObjectHelper.cc
+++ b/libqpdf/QPDFPageObjectHelper.cc
@@ -32,11 +32,9 @@ void
ContentProvider::provideStreamData(QPDFObjGen const&, Pipeline* p)
{
Pl_Concatenate concat("concatenate", p);
- std::string description =
- "contents from page object " + from_page.getObjGen().unparse(' ');
+ std::string description = "contents from page object " + from_page.getObjGen().unparse(' ');
std::string all_description;
- from_page.getKey("/Contents")
- .pipeContentStreams(&concat, description, all_description);
+ from_page.getKey("/Contents").pipeContentStreams(&concat, description, all_description);
concat.manualFinish();
}
@@ -61,8 +59,7 @@ namespace
};
} // namespace
-InlineImageTracker::InlineImageTracker(
- QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) :
+InlineImageTracker::InlineImageTracker(QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) :
qpdf(qpdf),
min_size(min_size),
resources(resources),
@@ -117,15 +114,12 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict)
// /ColorSpace dictionary. We need to look it up
// and use its value as the color space for the
// image.
- QPDFObjectHandle colorspace =
- resources.getKey("/ColorSpace");
+ QPDFObjectHandle colorspace = resources.getKey("/ColorSpace");
if (colorspace.isDictionary() && colorspace.hasKey(name)) {
- QTC::TC(
- "qpdf", "QPDFPageObjectHelper colorspace lookup");
+ QTC::TC("qpdf", "QPDFPageObjectHelper colorspace lookup");
value = colorspace.getKey(name);
} else {
- resources.warnIfPossible(
- "unable to resolve colorspace " + name);
+ resources.warnIfPossible("unable to resolve colorspace " + name);
}
name.clear();
}
@@ -185,20 +179,15 @@ InlineImageTracker::handleToken(QPDFTokenizer::Token const& token)
std::string image_data(token.getValue());
size_t len = image_data.length();
if (len >= this->min_size) {
- QTC::TC(
- "qpdf", "QPDFPageObjectHelper externalize inline image");
+ QTC::TC("qpdf", "QPDFPageObjectHelper externalize inline image");
Pl_Buffer b("image_data");
b.writeString(image_data);
b.finish();
- QPDFObjectHandle dict =
- convertIIDict(QPDFObjectHandle::parse(dict_str));
- dict.replaceKey(
- "/Length",
- QPDFObjectHandle::newInteger(QIntC::to_longlong(len)));
- std::string name =
- resources.getUniqueResourceName("/IIm", this->min_suffix);
- QPDFObjectHandle image = QPDFObjectHandle::newStream(
- this->qpdf, b.getBufferSharedPointer());
+ QPDFObjectHandle dict = convertIIDict(QPDFObjectHandle::parse(dict_str));
+ dict.replaceKey("/Length", QPDFObjectHandle::newInteger(QIntC::to_longlong(len)));
+ std::string name = resources.getUniqueResourceName("/IIm", this->min_suffix);
+ QPDFObjectHandle image =
+ QPDFObjectHandle::newStream(this->qpdf, b.getBufferSharedPointer());
image.replaceDict(dict);
resources.getKey("/XObject").replaceKey(name, image);
write(name);
@@ -252,8 +241,7 @@ QPDFPageObjectHelper::getAttribute(
auto result = dict.getKey(name);
if (!is_form_xobject && result.isNull() &&
- (name == "/MediaBox" || name == "/CropBox" || name == "/Resources" ||
- name == "/Rotate")) {
+ (name == "/MediaBox" || name == "/CropBox" || name == "/Resources" || name == "/Rotate")) {
QPDFObjectHandle node = dict;
QPDFObjGen::set seen{};
while (seen.add(node) && node.hasKey("/Parent")) {
@@ -267,10 +255,7 @@ QPDFPageObjectHelper::getAttribute(
}
}
if (copy_if_shared && (inherited || result.isIndirect())) {
- QTC::TC(
- "qpdf",
- "QPDFPageObjectHelper copy shared attribute",
- is_form_xobject ? 0 : 1);
+ QTC::TC("qpdf", "QPDFPageObjectHelper copy shared attribute", is_form_xobject ? 0 : 1);
result = dict.replaceKeyAndGetNew(name, result.shallowCopy());
}
if (result.isNull() && get_fallback) {
@@ -279,8 +264,7 @@ QPDFPageObjectHelper::getAttribute(
QTC::TC("qpdf", "QPDFPageObjectHelper copied fallback");
result = dict.replaceKeyAndGetNew(name, result.shallowCopy());
} else {
- QTC::TC(
- "qpdf", "QPDFPageObjectHelper used fallback without copying");
+ QTC::TC("qpdf", "QPDFPageObjectHelper used fallback without copying");
}
}
return result;
@@ -341,25 +325,21 @@ QPDFPageObjectHelper::getBleedBox(bool copy_if_shared, bool copy_if_fallback)
void
QPDFPageObjectHelper::forEachXObject(
bool recursive,
- std::function<void(
- QPDFObjectHandle& obj,
- QPDFObjectHandle& xobj_dict,
- std::string const& key)> action,
+ std::function<void(QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)>
+ action,
std::function<bool(QPDFObjectHandle)> selector)
{
QTC::TC(
"qpdf",
"QPDFPageObjectHelper::forEachXObject",
- recursive ? (this->oh.isFormXObject() ? 0 : 1)
- : (this->oh.isFormXObject() ? 2 : 3));
+ recursive ? (this->oh.isFormXObject() ? 0 : 1) : (this->oh.isFormXObject() ? 2 : 3));
QPDFObjGen::set seen;
std::list<QPDFPageObjectHelper> queue;
queue.push_back(*this);
while (!queue.empty()) {
auto& ph = queue.front();
if (seen.add(ph)) {
- auto xobj_dict =
- ph.getAttribute("/Resources", false).getKeyIfDict("/XObject");
+ auto xobj_dict = ph.getAttribute("/Resources", false).getKeyIfDict("/XObject");
if (xobj_dict.isDictionary()) {
for (auto const& key: xobj_dict.getKeys()) {
QPDFObjectHandle obj = xobj_dict.getKey(key);
@@ -379,26 +359,19 @@ QPDFPageObjectHelper::forEachXObject(
void
QPDFPageObjectHelper::forEachImage(
bool recursive,
- std::function<void(
- QPDFObjectHandle& obj,
- QPDFObjectHandle& xobj_dict,
- std::string const& key)> action)
+ std::function<void(QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)>
+ action)
{
- forEachXObject(
- recursive, action, [](QPDFObjectHandle obj) { return obj.isImage(); });
+ forEachXObject(recursive, action, [](QPDFObjectHandle obj) { return obj.isImage(); });
}
void
QPDFPageObjectHelper::forEachFormXObject(
bool recursive,
- std::function<void(
- QPDFObjectHandle& obj,
- QPDFObjectHandle& xobj_dict,
- std::string const& key)> action)
+ std::function<void(QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)>
+ action)
{
- forEachXObject(recursive, action, [](QPDFObjectHandle obj) {
- return obj.isFormXObject();
- });
+ forEachXObject(recursive, action, [](QPDFObjectHandle obj) { return obj.isFormXObject(); });
}
std::map<std::string, QPDFObjectHandle>
@@ -412,9 +385,7 @@ QPDFPageObjectHelper::getImages()
{
std::map<std::string, QPDFObjectHandle> result;
forEachImage(
- false,
- [&result](
- QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const& key) {
+ false, [&result](QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const& key) {
result[key] = obj;
});
return result;
@@ -425,9 +396,7 @@ QPDFPageObjectHelper::getFormXObjects()
{
std::map<std::string, QPDFObjectHandle> result;
forEachFormXObject(
- false,
- [&result](
- QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const& key) {
+ false, [&result](QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const& key) {
result[key] = obj;
});
return result;
@@ -462,18 +431,14 @@ QPDFPageObjectHelper::externalizeInlineImages(size_t min_size, bool shallow)
} else {
this->oh.replaceKey(
"/Contents",
- QPDFObjectHandle::newStream(
- &this->oh.getQPDF(), b.getBufferSharedPointer()));
+ QPDFObjectHandle::newStream(&this->oh.getQPDF(), b.getBufferSharedPointer()));
}
}
} else {
externalizeInlineImages(min_size, true);
forEachFormXObject(
- true,
- [min_size](
- QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const&) {
- QPDFPageObjectHelper(obj).externalizeInlineImages(
- min_size, true);
+ true, [min_size](QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const&) {
+ QPDFPageObjectHelper(obj).externalizeInlineImages(min_size, true);
});
}
}
@@ -520,15 +485,13 @@ QPDFPageObjectHelper::coalesceContentStreams()
}
void
-QPDFPageObjectHelper::parsePageContents(
- QPDFObjectHandle::ParserCallbacks* callbacks)
+QPDFPageObjectHelper::parsePageContents(QPDFObjectHandle::ParserCallbacks* callbacks)
{
parseContents(callbacks);
}
void
-QPDFPageObjectHelper::parseContents(
- QPDFObjectHandle::ParserCallbacks* callbacks)
+QPDFPageObjectHelper::parseContents(QPDFObjectHandle::ParserCallbacks* callbacks)
{
if (this->oh.isFormXObject()) {
this->oh.parseAsContents(callbacks);
@@ -538,15 +501,13 @@ QPDFPageObjectHelper::parseContents(
}
void
-QPDFPageObjectHelper::filterPageContents(
- QPDFObjectHandle::TokenFilter* filter, Pipeline* next)
+QPDFPageObjectHelper::filterPageContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next)
{
return filterContents(filter, next);
}
void
-QPDFPageObjectHelper::filterContents(
- QPDFObjectHandle::TokenFilter* filter, Pipeline* next)
+QPDFPageObjectHelper::filterContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next)
{
if (this->oh.isFormXObject()) {
this->oh.filterAsContents(filter, next);
@@ -598,10 +559,9 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
ph.parseContents(&rf);
size_t after_nw = (q ? q->numWarnings() : 0);
if (after_nw > before_nw) {
- ph.oh.warnIfPossible(
- "Bad token found while scanning content stream; "
- "not attempting to remove unreferenced objects from"
- " this object");
+ ph.oh.warnIfPossible("Bad token found while scanning content stream; "
+ "not attempting to remove unreferenced objects from"
+ " this object");
return false;
}
} catch (std::exception& e) {
@@ -699,10 +659,8 @@ QPDFPageObjectHelper::removeUnreferencedResources()
bool any_failures = false;
forEachFormXObject(
true,
- [&any_failures, &unresolved](
- QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const&) {
- if (!removeUnreferencedResourcesHelper(
- QPDFPageObjectHelper(obj), unresolved)) {
+ [&any_failures, &unresolved](QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const&) {
+ if (!removeUnreferencedResourcesHelper(QPDFPageObjectHelper(obj), unresolved)) {
any_failures = true;
}
});
@@ -714,8 +672,8 @@ QPDFPageObjectHelper::removeUnreferencedResources()
QPDFPageObjectHelper
QPDFPageObjectHelper::shallowCopyPage()
{
- QPDF& qpdf = this->oh.getQPDF(
- "QPDFPageObjectHelper::shallowCopyPage called with a direct object");
+ QPDF& qpdf =
+ this->oh.getQPDF("QPDFPageObjectHelper::shallowCopyPage called with a direct object");
QPDFObjectHandle new_page = this->oh.shallowCopy();
return QPDFPageObjectHelper(qpdf.makeIndirectObject(new_page));
}
@@ -734,10 +692,8 @@ QPDFPageObjectHelper::getMatrixForTransformations(bool invert)
QPDFObjectHandle::Rectangle rect = bbox.getArrayAsRectangle();
double width = rect.urx - rect.llx;
double height = rect.ury - rect.lly;
- double scale =
- (scale_obj.isNumber() ? scale_obj.getNumericValue() : 1.0);
- int rotate =
- (rotate_obj.isInteger() ? rotate_obj.getIntValueAsInt() : 0);
+ double scale = (scale_obj.isNumber() ? scale_obj.getNumericValue() : 1.0);
+ int rotate = (rotate_obj.isInteger() ? rotate_obj.getIntValueAsInt() : 0);
if (invert) {
if (scale == 0.0) {
return matrix;
@@ -749,16 +705,13 @@ QPDFPageObjectHelper::getMatrixForTransformations(bool invert)
// Ignore invalid rotation angle
switch (rotate) {
case 90:
- matrix =
- QPDFObjectHandle::Matrix(0, -scale, scale, 0, 0, width * scale);
+ matrix = QPDFObjectHandle::Matrix(0, -scale, scale, 0, 0, width * scale);
break;
case 180:
- matrix = QPDFObjectHandle::Matrix(
- -scale, 0, 0, -scale, width * scale, height * scale);
+ matrix = QPDFObjectHandle::Matrix(-scale, 0, 0, -scale, width * scale, height * scale);
break;
case 270:
- matrix = QPDFObjectHandle::Matrix(
- 0, scale, -scale, 0, height * scale, 0);
+ matrix = QPDFObjectHandle::Matrix(0, scale, -scale, 0, height * scale, 0);
break;
default:
matrix = QPDFObjectHandle::Matrix(scale, 0, 0, scale, 0, 0);
@@ -778,8 +731,7 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations)
QPDFObjectHandle newdict = result.getDict();
newdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject"));
newdict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form"));
- newdict.replaceKey(
- "/Resources", getAttribute("/Resources", false).shallowCopy());
+ newdict.replaceKey("/Resources", getAttribute("/Resources", false).shallowCopy());
newdict.replaceKey("/Group", getAttribute("/Group", false).shallowCopy());
QPDFObjectHandle bbox = getTrimBox(false).shallowCopy();
if (!bbox.isRectangle()) {
@@ -787,17 +739,13 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations)
" XObject created from page will not work");
}
newdict.replaceKey("/BBox", bbox);
- auto provider = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(
- new ContentProvider(this->oh));
- result.replaceStreamData(
- provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
+ auto provider =
+ std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(new ContentProvider(this->oh));
+ result.replaceStreamData(provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false);
QPDFObjectHandle scale_obj = getAttribute("/UserUnit", false);
- if (handle_transformations &&
- (!(rotate_obj.isNull() && scale_obj.isNull()))) {
- newdict.replaceKey(
- "/Matrix",
- QPDFObjectHandle::newArray(getMatrixForTransformations()));
+ if (handle_transformations && (!(rotate_obj.isNull() && scale_obj.isNull()))) {
+ newdict.replaceKey("/Matrix", QPDFObjectHandle::newArray(getMatrixForTransformations()));
}
return result;
@@ -921,8 +869,7 @@ QPDFPageObjectHelper::placeFormXObject(
bool allow_expand)
{
QPDFMatrix cm;
- return placeFormXObject(
- fo, name, rect, cm, invert_transformations, allow_shrink, allow_expand);
+ return placeFormXObject(fo, name, rect, cm, invert_transformations, allow_shrink, allow_expand);
}
std::string
@@ -943,8 +890,8 @@ QPDFPageObjectHelper::placeFormXObject(
void
QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh)
{
- QPDF& qpdf = this->oh.getQPDF(
- "QPDFPageObjectHelper::flattenRotation called with a direct object");
+ QPDF& qpdf =
+ this->oh.getQPDF("QPDFPageObjectHelper::flattenRotation called with a direct object");
auto rotate_oh = this->oh.getKey("/Rotate");
int rotate = 0;
if (rotate_oh.isInteger()) {
@@ -1013,8 +960,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh)
break;
}
- this->oh.replaceKey(
- boxkey, QPDFObjectHandle::newFromRectangle(new_rect));
+ this->oh.replaceKey(boxkey, QPDFObjectHandle::newFromRectangle(new_rect));
}
// When we rotate the page, pivot about the point 0, 0 and then
@@ -1066,8 +1012,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh)
afdhph = std::make_shared<QPDFAcroFormDocumentHelper>(qpdf);
afdh = afdhph.get();
}
- afdh->transformAnnotations(
- annots, new_annots, new_fields, old_fields, cm);
+ afdh->transformAnnotations(annots, new_annots, new_fields, old_fields, cm);
afdh->removeFormFields(old_fields);
for (auto const& f: new_fields) {
afdh->addFormField(QPDFFormFieldObjectHelper(f));
@@ -1090,8 +1035,8 @@ QPDFPageObjectHelper::copyAnnotations(
QPDF& from_qpdf = from_page.getObjectHandle().getQPDF(
"QPDFPageObjectHelper::copyAnnotations: from page is a direct object");
- QPDF& this_qpdf = this->oh.getQPDF(
- "QPDFPageObjectHelper::copyAnnotations: this page is a direct object");
+ QPDF& this_qpdf =
+ this->oh.getQPDF("QPDFPageObjectHelper::copyAnnotations: this page is a direct object");
std::vector<QPDFObjectHandle> new_annots;
std::vector<QPDFObjectHandle> new_fields;
@@ -1106,9 +1051,8 @@ QPDFPageObjectHelper::copyAnnotations(
from_afdh = afdh;
} else if (from_afdh) {
if (from_afdh->getQPDF().getUniqueId() != from_qpdf.getUniqueId()) {
- throw std::logic_error(
- "QPDFAcroFormDocumentHelper::copyAnnotations: from_afdh"
- " is not from the same QPDF as from_page");
+ throw std::logic_error("QPDFAcroFormDocumentHelper::copyAnnotations: from_afdh"
+ " is not from the same QPDF as from_page");
}
} else {
from_afdhph = std::make_shared<QPDFAcroFormDocumentHelper>(from_qpdf);
@@ -1116,18 +1060,11 @@ QPDFPageObjectHelper::copyAnnotations(
}
afdh->transformAnnotations(
- old_annots,
- new_annots,
- new_fields,
- old_fields,
- cm,
- &from_qpdf,
- from_afdh);
+ old_annots, new_annots, new_fields, old_fields, cm, &from_qpdf, from_afdh);
afdh->addAndRenameFormFields(new_fields);
auto annots = this->oh.getKey("/Annots");
if (!annots.isArray()) {
- annots = this->oh.replaceKeyAndGetNew(
- "/Annots", QPDFObjectHandle::newArray());
+ annots = this->oh.replaceKeyAndGetNew("/Annots", QPDFObjectHandle::newArray());
}
for (auto const& annot: new_annots) {
annots.appendItem(annot);
diff --git a/libqpdf/QPDFParser.cc b/libqpdf/QPDFParser.cc
index e56fcce3..5d695897 100644
--- a/libqpdf/QPDFParser.cc
+++ b/libqpdf/QPDFParser.cc
@@ -140,9 +140,8 @@ QPDFParser::parse(bool& empty, bool content_stream)
} else {
state = st_start;
state_stack.push_back(
- (tokenizer.getType() == QPDFTokenizer::tt_array_open)
- ? st_array
- : st_dictionary);
+ (tokenizer.getType() == QPDFTokenizer::tt_array_open) ? st_array
+ : st_dictionary);
b_contents = false;
stack.push_back(StackFrame(input));
}
@@ -187,18 +186,15 @@ QPDFParser::parse(bool& empty, bool content_stream)
if (content_stream) {
object = QPDF_Operator::create(value);
} else if (
- value == "R" && state != st_top && size >= 2 &&
- olist.back() &&
+ value == "R" && state != st_top && size >= 2 && olist.back() &&
olist.back()->getTypeCode() == ::ot_integer &&
- !olist.back()->getObjGen().isIndirect() &&
- olist.at(size - 2) &&
+ !olist.back()->getObjGen().isIndirect() && olist.at(size - 2) &&
olist.at(size - 2)->getTypeCode() == ::ot_integer &&
!olist.at(size - 2)->getObjGen().isIndirect()) {
if (context == nullptr) {
QTC::TC("qpdf", "QPDFParser indirect without context");
- throw std::logic_error(
- "QPDFObjectHandle::parse called without context"
- " on an object with indirect references");
+ throw std::logic_error("QPDFObjectHandle::parse called without context"
+ " on an object with indirect references");
}
auto ref_og = QPDFObjGen(
QPDFObjectHandle(olist.at(size - 2)).getIntValueAsInt(),
@@ -262,8 +258,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
}
if (object == nullptr && !is_null &&
- (!((state == st_start) || (state == st_stop) ||
- (state == st_eof)))) {
+ (!((state == st_start) || (state == st_stop) || (state == st_eof)))) {
throw std::logic_error("QPDFObjectHandle::parseInternal: "
"unexpected uninitialized object");
is_null = true;
@@ -321,15 +316,13 @@ QPDFParser::parse(bool& empty, bool content_stream)
case st_stop:
if ((state_stack.size() < 2) || (stack.size() < 2)) {
- throw std::logic_error(
- "QPDFObjectHandle::parseInternal: st_stop encountered"
- " with insufficient elements in stack");
+ throw std::logic_error("QPDFObjectHandle::parseInternal: st_stop encountered"
+ " with insufficient elements in stack");
}
parser_state_e old_state = state_stack.back();
state_stack.pop_back();
if (old_state == st_array) {
- object = QPDF_Array::create(
- std::move(olist), frame.null_count > 100);
+ object = QPDF_Array::create(std::move(olist), frame.null_count > 100);
setDescription(object, offset - 1);
// The `offset` points to the next of "[". Set the rewind
// offset to point to the beginning of "[". This has been
@@ -361,10 +354,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
for (bool found_fake = false; !found_fake;) {
key = "/QPDFFake" + std::to_string(next_fake_key++);
found_fake = (names.count(key) == 0);
- QTC::TC(
- "qpdf",
- "QPDFParser found fake",
- (found_fake ? 0 : 1));
+ QTC::TC("qpdf", "QPDFParser found fake", (found_fake ? 0 : 1));
}
warn(
offset,
@@ -398,11 +388,9 @@ QPDFParser::parse(bool& empty, bool content_stream)
dict[std::move(key)] = std::move(val);
}
if (!frame.contents_string.empty() && dict.count("/Type") &&
- dict["/Type"].isNameAndEquals("/Sig") &&
- dict.count("/ByteRange") && dict.count("/Contents") &&
- dict["/Contents"].isString()) {
- dict["/Contents"] =
- QPDFObjectHandle::newString(frame.contents_string);
+ dict["/Type"].isNameAndEquals("/Sig") && dict.count("/ByteRange") &&
+ dict.count("/Contents") && dict["/Contents"].isString()) {
+ dict["/Contents"] = QPDFObjectHandle::newString(frame.contents_string);
dict["/Contents"].setParsedOffset(frame.contents_offset);
}
object = QPDF_Dictionary::create(std::move(dict));
@@ -433,8 +421,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
}
void
-QPDFParser::setDescription(
- std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset)
+QPDFParser::setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset)
{
if (obj) {
obj->setDescription(context, description, parsed_offset);
@@ -458,8 +445,7 @@ QPDFParser::warn(QPDFExc const& e) const
void
QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const
{
- warn(QPDFExc(
- qpdf_e_damaged_pdf, input->getName(), object_description, offset, msg));
+ warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(), object_description, offset, msg));
}
void
diff --git a/libqpdf/QPDFSystemError.cc b/libqpdf/QPDFSystemError.cc
index ebd0d773..5a1b2869 100644
--- a/libqpdf/QPDFSystemError.cc
+++ b/libqpdf/QPDFSystemError.cc
@@ -2,8 +2,7 @@
#include <cstring>
-QPDFSystemError::QPDFSystemError(
- std::string const& description, int system_errno) :
+QPDFSystemError::QPDFSystemError(std::string const& description, int system_errno) :
std::runtime_error(createWhat(description, system_errno)),
description(description),
system_errno(system_errno)
diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc
index d2c66e29..da02a0fe 100644
--- a/libqpdf/QPDFTokenizer.cc
+++ b/libqpdf/QPDFTokenizer.cc
@@ -18,10 +18,9 @@ static inline bool
is_delimiter(char ch)
{
return (
- ch == ' ' || ch == '\n' || ch == '/' || ch == '(' || ch == ')' ||
- ch == '{' || ch == '}' || ch == '<' || ch == '>' || ch == '[' ||
- ch == ']' || ch == '%' || ch == '\t' || ch == '\r' || ch == '\v' ||
- ch == '\f' || ch == 0);
+ ch == ' ' || ch == '\n' || ch == '/' || ch == '(' || ch == ')' || ch == '{' || ch == '}' ||
+ ch == '<' || ch == '>' || ch == '[' || ch == ']' || ch == '%' || ch == '\t' || ch == '\r' ||
+ ch == '\v' || ch == '\f' || ch == 0);
}
namespace
@@ -29,8 +28,7 @@ namespace
class QPDFWordTokenFinder: public InputSource::Finder
{
public:
- QPDFWordTokenFinder(
- std::shared_ptr<InputSource> is, std::string const& str) :
+ QPDFWordTokenFinder(std::shared_ptr<InputSource> is, std::string const& str) :
is(is),
str(str)
{
@@ -243,8 +241,7 @@ QPDFTokenizer::handleCharacter(char ch)
return;
default:
- throw std::logic_error(
- "INTERNAL ERROR: invalid state while reading token");
+ throw std::logic_error("INTERNAL ERROR: invalid state while reading token");
}
}
@@ -673,8 +670,7 @@ QPDFTokenizer::inHexstring(char ch)
} else {
this->type = tt_bad;
QTC::TC("qpdf", "QPDFTokenizer bad hexstring character");
- this->error_message =
- std::string("invalid character (") + ch + ") in hexstring";
+ this->error_message = std::string("invalid character (") + ch + ") in hexstring";
this->state = st_token_ready;
}
}
@@ -698,8 +694,7 @@ QPDFTokenizer::inHexstring2nd(char ch)
} else {
this->type = tt_bad;
QTC::TC("qpdf", "QPDFTokenizer bad hexstring 2nd character");
- this->error_message =
- std::string("invalid character (") + ch + ") in hexstring";
+ this->error_message = std::string("invalid character (") + ch + ") in hexstring";
this->state = st_token_ready;
}
}
@@ -846,14 +841,13 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input)
bool found_non_printable = false;
bool found_other = false;
for (char ch: t.getValue()) {
- if (((ch >= 'a') && (ch <= 'z')) ||
- ((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) {
+ if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) ||
+ (ch == '*')) {
// Treat '*' as alpha since there are valid
// PDF operators that contain * along with
// alphabetic characters.
found_alpha = true;
- } else if (
- (static_cast<signed char>(ch) < 32) && (!isSpace(ch))) {
+ } else if ((static_cast<signed char>(ch) < 32) && (!isSpace(ch))) {
// Compare ch as a signed char so characters
// outside of 7-bit will be < 0.
found_non_printable = true;
@@ -893,8 +887,7 @@ QPDFTokenizer::getToken(Token& token, bool& unread_char, char& ch)
ch = this->char_to_unread;
if (ready) {
token = (!(this->type == tt_name || this->type == tt_string))
- ? Token(
- this->type, this->raw_val, this->raw_val, this->error_message)
+ ? Token(this->type, this->raw_val, this->raw_val, this->error_message)
: Token(this->type, this->val, this->raw_val, this->error_message);
this->reset();
@@ -910,10 +903,7 @@ QPDFTokenizer::betweenTokens()
QPDFTokenizer::Token
QPDFTokenizer::readToken(
- std::shared_ptr<InputSource> input,
- std::string const& context,
- bool allow_bad,
- size_t max_len)
+ std::shared_ptr<InputSource> input, std::string const& context, bool allow_bad, size_t max_len)
{
nextToken(*input, context, max_len);
@@ -938,8 +928,7 @@ QPDFTokenizer::readToken(
}
bool
-QPDFTokenizer::nextToken(
- InputSource& input, std::string const& context, size_t max_len)
+QPDFTokenizer::nextToken(InputSource& input, std::string const& context, size_t max_len)
{
if (this->state != st_inline_image) {
reset();
@@ -967,14 +956,12 @@ QPDFTokenizer::nextToken(
if (this->in_token) {
this->raw_val += ch;
}
- if (max_len && (this->raw_val.length() >= max_len) &&
- (this->state != st_token_ready)) {
+ if (max_len && (this->raw_val.length() >= max_len) && (this->state != st_token_ready)) {
// terminate this token now
QTC::TC("qpdf", "QPDFTokenizer block long token");
this->type = tt_bad;
this->state = st_token_ready;
- this->error_message =
- "exceeded allowable length while reading token";
+ this->error_message = "exceeded allowable length while reading token";
}
}
}
diff --git a/libqpdf/QPDFValue.cc b/libqpdf/QPDFValue.cc
index 30d534dc..34412231 100644
--- a/libqpdf/QPDFValue.cc
+++ b/libqpdf/QPDFValue.cc
@@ -20,18 +20,15 @@ QPDFValue::getDescription()
// Simple template string
auto description = std::get<0>(*object_description);
- if (auto pos = description.find("$OG");
- pos != std::string::npos) {
+ if (auto pos = description.find("$OG"); pos != std::string::npos) {
description.replace(pos, 3, og.unparse(' '));
}
- if (auto pos = description.find("$PO");
- pos != std::string::npos) {
+ if (auto pos = description.find("$PO"); pos != std::string::npos) {
qpdf_offset_t shift = (type_code == ::ot_dictionary) ? 2
: (type_code == ::ot_array) ? 1
: 0;
- description.replace(
- pos, 3, std::to_string(parsed_offset + shift));
+ description.replace(pos, 3, std::to_string(parsed_offset + shift));
}
return description;
}
@@ -40,8 +37,7 @@ QPDFValue::getDescription()
// QPDF::JSONReactor generated description
auto j_descr = std::get<1>(*object_description);
return (
- *j_descr.input +
- (j_descr.object.empty() ? "" : ", " + j_descr.object) +
+ *j_descr.input + (j_descr.object.empty() ? "" : ", " + j_descr.object) +
" at offset " + std::to_string(parsed_offset));
}
case 2:
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index cad91d7c..782a0c49 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -32,8 +32,7 @@ QPDFWriter::ProgressReporter::~ProgressReporter()
// README-maintainer
}
-QPDFWriter::FunctionProgressReporter::FunctionProgressReporter(
- std::function<void(int)> handler) :
+QPDFWriter::FunctionProgressReporter::FunctionProgressReporter(std::function<void(int)> handler) :
handler(handler)
{
}
@@ -52,9 +51,7 @@ QPDFWriter::FunctionProgressReporter::reportProgress(int progress)
QPDFWriter::Members::Members(QPDF& pdf) :
pdf(pdf),
- root_og(
- pdf.getRoot().getObjGen().isIndirect() ? pdf.getRoot().getObjGen()
- : QPDFObjGen(-1, 0))
+ root_og(pdf.getRoot().getObjGen().isIndirect() ? pdf.getRoot().getObjGen() : QPDFObjGen(-1, 0))
{
}
@@ -77,8 +74,7 @@ QPDFWriter::QPDFWriter(QPDF& pdf, char const* filename) :
setOutputFilename(filename);
}
-QPDFWriter::QPDFWriter(
- QPDF& pdf, char const* description, FILE* file, bool close_file) :
+QPDFWriter::QPDFWriter(QPDF& pdf, char const* description, FILE* file, bool close_file) :
m(new Members(pdf))
{
setOutputFile(description, file, close_file);
@@ -109,8 +105,7 @@ QPDFWriter::setOutputFile(char const* description, FILE* file, bool close_file)
m->filename = description;
m->file = file;
m->close_file = close_file;
- std::shared_ptr<Pipeline> p =
- std::make_shared<Pl_StdioFile>("qpdf output", file);
+ std::shared_ptr<Pipeline> p = std::make_shared<Pl_StdioFile>("qpdf output", file);
m->to_delete.push_back(p);
initializePipelineStack(p.get());
}
@@ -156,8 +151,7 @@ QPDFWriter::setStreamDataMode(qpdf_stream_data_e mode)
{
switch (mode) {
case qpdf_s_uncompress:
- m->stream_decode_level =
- std::max(qpdf_dl_generalized, m->stream_decode_level);
+ m->stream_decode_level = std::max(qpdf_dl_generalized, m->stream_decode_level);
m->compress_streams = false;
break;
@@ -167,8 +161,7 @@ QPDFWriter::setStreamDataMode(qpdf_stream_data_e mode)
break;
case qpdf_s_compress:
- m->stream_decode_level =
- std::max(qpdf_dl_generalized, m->stream_decode_level);
+ m->stream_decode_level = std::max(qpdf_dl_generalized, m->stream_decode_level);
m->compress_streams = true;
break;
}
@@ -222,8 +215,7 @@ QPDFWriter::setNewlineBeforeEndstream(bool val)
}
void
-QPDFWriter::setMinimumPDFVersion(
- std::string const& version, int extension_level)
+QPDFWriter::setMinimumPDFVersion(std::string const& version, int extension_level)
{
bool set_version = false;
bool set_extension_level = false;
@@ -237,13 +229,9 @@ QPDFWriter::setMinimumPDFVersion(
int min_minor = 0;
parseVersion(version, old_major, old_minor);
parseVersion(m->min_pdf_version, min_major, min_minor);
- int compare =
- compareVersions(old_major, old_minor, min_major, min_minor);
+ int compare = compareVersions(old_major, old_minor, min_major, min_minor);
if (compare > 0) {
- QTC::TC(
- "qpdf",
- "QPDFWriter increasing minimum version",
- extension_level == 0 ? 0 : 1);
+ QTC::TC("qpdf", "QPDFWriter increasing minimum version", extension_level == 0 ? 0 : 1);
set_version = true;
set_extension_level = true;
} else if (compare == 0) {
@@ -282,8 +270,7 @@ void
QPDFWriter::setExtraHeaderText(std::string const& text)
{
m->extra_header_text = text;
- if ((m->extra_header_text.length() > 0) &&
- (*(m->extra_header_text.rbegin()) != '\n')) {
+ if ((m->extra_header_text.length() > 0) && (*(m->extra_header_text.rbegin()) != '\n')) {
QTC::TC("qpdf", "QPDFWriter extra header text add newline");
m->extra_header_text += "\n";
} else {
@@ -642,16 +629,7 @@ QPDFWriter::setEncryptionParameters(
std::string encryption_key;
if (V < 5) {
QPDF::compute_encryption_O_U(
- user_password,
- owner_password,
- V,
- R,
- key_len,
- P,
- m->encrypt_metadata,
- m->id1,
- O,
- U);
+ user_password, owner_password, V, R, key_len, P, m->encrypt_metadata, m->id1, O, U);
} else {
QPDF::compute_encryption_parameters_V5(
user_password,
@@ -670,18 +648,7 @@ QPDFWriter::setEncryptionParameters(
Perms);
}
setEncryptionParametersInternal(
- V,
- R,
- key_len,
- P,
- O,
- U,
- OE,
- UE,
- Perms,
- m->id1,
- user_password,
- encryption_key);
+ V, R, key_len, P, O, U, OE, UE, Perms, m->id1, user_password, encryption_key);
}
void
@@ -698,10 +665,8 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf)
if (V > 1) {
key_len = encrypt.getKey("/Length").getIntValueAsInt() / 8;
}
- if (encrypt.hasKey("/EncryptMetadata") &&
- encrypt.getKey("/EncryptMetadata").isBool()) {
- m->encrypt_metadata =
- encrypt.getKey("/EncryptMetadata").getBoolValue();
+ if (encrypt.hasKey("/EncryptMetadata") && encrypt.getKey("/EncryptMetadata").isBool()) {
+ m->encrypt_metadata = encrypt.getKey("/EncryptMetadata").getBoolValue();
}
if (V >= 4) {
// When copying encryption parameters, use AES even if the
@@ -712,10 +677,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf)
// different values.
m->encrypt_use_aes = true;
}
- QTC::TC(
- "qpdf",
- "QPDFWriter copy encrypt metadata",
- m->encrypt_metadata ? 0 : 1);
+ QTC::TC("qpdf", "QPDFWriter copy encrypt metadata", m->encrypt_metadata ? 0 : 1);
QTC::TC("qpdf", "QPDFWriter copy use_aes", m->encrypt_use_aes ? 0 : 1);
std::string OE;
std::string UE;
@@ -746,8 +708,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf)
}
void
-QPDFWriter::disableIncompatibleEncryption(
- int major, int minor, int extension_level)
+QPDFWriter::disableIncompatibleEncryption(int major, int minor, int extension_level)
{
if (!m->encrypted) {
return;
@@ -773,8 +734,7 @@ QPDFWriter::disableIncompatibleEncryption(
}
} else if (
(compareVersions(major, minor, 1, 7) < 0) ||
- ((compareVersions(major, minor, 1, 7) == 0) &&
- extension_level < 3)) {
+ ((compareVersions(major, minor, 1, 7) == 0) && extension_level < 3)) {
if ((V >= 5) || (R >= 5)) {
disable = true;
}
@@ -787,8 +747,7 @@ QPDFWriter::disableIncompatibleEncryption(
}
void
-QPDFWriter::parseVersion(
- std::string const& version, int& major, int& minor) const
+QPDFWriter::parseVersion(std::string const& version, int& major, int& minor) const
{
major = QUtil::string_to_int(version.c_str());
minor = 0;
@@ -807,8 +766,7 @@ QPDFWriter::parseVersion(
}
int
-QPDFWriter::compareVersions(
- int major1, int minor1, int major2, int minor2) const
+QPDFWriter::compareVersions(int major1, int minor1, int major2, int minor2) const
{
if (major1 < major2) {
return -1;
@@ -873,22 +831,19 @@ QPDFWriter::setEncryptionParametersInternal(
// won't open our files unless we use /StdCF.
m->encryption_dictionary["/StmF"] = "/StdCF";
m->encryption_dictionary["/StrF"] = "/StdCF";
- std::string method =
- (m->encrypt_use_aes ? ((V < 5) ? "/AESV2" : "/AESV3") : "/V2");
+ std::string method = (m->encrypt_use_aes ? ((V < 5) ? "/AESV2" : "/AESV3") : "/V2");
// The PDF spec says the /Length key is optional, but the PDF
// previewer on some versions of MacOS won't open encrypted
// files without it.
- m->encryption_dictionary["/CF"] =
- "<< /StdCF << /AuthEvent /DocOpen /CFM " + method + " /Length " +
- std::string((V < 5) ? "16" : "32") + " >> >>";
+ m->encryption_dictionary["/CF"] = "<< /StdCF << /AuthEvent /DocOpen /CFM " + method +
+ " /Length " + std::string((V < 5) ? "16" : "32") + " >> >>";
}
m->encrypted = true;
QPDF::EncryptionData encryption_data(
V, R, key_len, P, O, U, OE, UE, Perms, id1, m->encrypt_metadata);
if (V < 5) {
- m->encryption_key =
- QPDF::compute_encryption_key(user_password, encryption_data);
+ m->encryption_key = QPDF::compute_encryption_key(user_password, encryption_data);
} else {
m->encryption_key = encryption_key;
}
@@ -898,12 +853,7 @@ void
QPDFWriter::setDataKey(int objid)
{
m->cur_data_key = QPDF::compute_data_key(
- m->encryption_key,
- objid,
- 0,
- m->encrypt_use_aes,
- m->encryption_V,
- m->encryption_R);
+ m->encryption_key, objid, 0, m->encrypt_use_aes, m->encryption_V, m->encryption_R);
}
unsigned int
@@ -921,8 +871,7 @@ void
QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes)
{
if (bytes > sizeof(unsigned long long)) {
- throw std::logic_error(
- "QPDFWriter::writeBinary called with too many bytes");
+ throw std::logic_error("QPDFWriter::writeBinary called with too many bytes");
}
unsigned char data[sizeof(unsigned long long)];
for (unsigned int i = 0; i < bytes; ++i) {
@@ -935,8 +884,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes)
void
QPDFWriter::writeString(std::string_view str)
{
- m->pipeline->write(
- reinterpret_cast<unsigned char const*>(str.data()), str.size());
+ m->pipeline->write(reinterpret_cast<unsigned char const*>(str.data()), str.size());
}
void
@@ -949,8 +897,7 @@ void
QPDFWriter::writeStringQDF(std::string_view str)
{
if (m->qdf_mode) {
- m->pipeline->write(
- reinterpret_cast<unsigned char const*>(str.data()), str.size());
+ m->pipeline->write(reinterpret_cast<unsigned char const*>(str.data()), str.size());
}
}
@@ -958,8 +905,7 @@ void
QPDFWriter::writeStringNoQDF(std::string_view str)
{
if (!m->qdf_mode) {
- m->pipeline->write(
- reinterpret_cast<unsigned char const*>(str.data()), str.size());
+ m->pipeline->write(reinterpret_cast<unsigned char const*>(str.data()), str.size());
}
}
@@ -1003,9 +949,7 @@ QPDFWriter::PipelinePopper::~PipelinePopper()
}
qpdf_assert_debug(qw->m->pipeline_stack.size() >= 2);
qw->m->pipeline->finish();
- qpdf_assert_debug(
- dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back()) ==
- qw->m->pipeline);
+ qpdf_assert_debug(dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back()) == qw->m->pipeline);
// It might be possible for this assertion to fail if
// writeLinearized exits by exception when deterministic ID, but I
// don't think so. As of this writing, this is the only case in
@@ -1152,10 +1096,9 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
// which just disconnects the QPDFObjectHandle from its owner.
if (object.getOwningQPDF() != &(m->pdf)) {
QTC::TC("qpdf", "QPDFWriter foreign object");
- throw std::logic_error(
- "QPDFObjectHandle from different QPDF found while writing."
- " Use QPDF::copyForeignObject to add objects from"
- " another file.");
+ throw std::logic_error("QPDFObjectHandle from different QPDF found while writing."
+ " Use QPDF::copyForeignObject to add objects from"
+ " another file.");
}
if (m->qdf_mode && object.isStreamOfType("/XRef")) {
@@ -1186,8 +1129,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
m->object_queue.push_back(object);
m->obj_renumber[og] = m->next_objid++;
- if ((og.getGen() == 0) &&
- m->object_stream_to_objects.count(og.getObj())) {
+ if ((og.getGen() == 0) && m->object_stream_to_objects.count(og.getObj())) {
// For linearized files, uncompressed objects go
// at end, and we take care of assigning numbers
// to them elsewhere.
@@ -1240,11 +1182,7 @@ QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags)
void
QPDFWriter::writeTrailer(
- trailer_e which,
- int size,
- bool xref_stream,
- qpdf_offset_t prev,
- int linearization_pass)
+ trailer_e which, int size, bool xref_stream, qpdf_offset_t prev, int linearization_pass)
{
QPDFObjectHandle trailer = getTrimmedTrailer();
if (xref_stream) {
@@ -1268,8 +1206,7 @@ QPDFWriter::writeTrailer(
writeString(" /Prev ");
qpdf_offset_t pos = m->pipeline->getCount();
writeString(std::to_string(prev));
- writePad(
- QIntC::to_size(pos - m->pipeline->getCount() + 21));
+ writePad(QIntC::to_size(pos - m->pipeline->getCount() + 21));
}
} else {
unparseChild(trailer.getKey(key), 1, 0);
@@ -1340,9 +1277,7 @@ QPDFWriter::willFilterStream(
if (stream_dict.isDictionaryOfType("/Metadata")) {
is_metadata = true;
}
- bool filter =
- (stream.isDataModified() || m->compress_streams ||
- m->stream_decode_level);
+ bool filter = (stream.isDataModified() || m->compress_streams || m->stream_decode_level);
bool filter_on_write = stream.getFilterOnWrite();
if (!filter_on_write) {
QTC::TC("qpdf", "QPDFWriter getFilterOnWrite false");
@@ -1356,25 +1291,20 @@ QPDFWriter::willFilterStream(
// recompressing stuff. This can be overridden with
// setRecompressFlate(true).
QPDFObjectHandle filter_obj = stream_dict.getKey("/Filter");
- if ((!m->recompress_flate) && (!stream.isDataModified()) &&
- filter_obj.isName() &&
- ((filter_obj.getName() == "/FlateDecode") ||
- (filter_obj.getName() == "/Fl"))) {
+ if ((!m->recompress_flate) && (!stream.isDataModified()) && filter_obj.isName() &&
+ ((filter_obj.getName() == "/FlateDecode") || (filter_obj.getName() == "/Fl"))) {
QTC::TC("qpdf", "QPDFWriter not recompressing /FlateDecode");
filter = false;
}
}
bool normalize = false;
bool uncompress = false;
- if (filter_on_write && is_metadata &&
- ((!m->encrypted) || (m->encrypt_metadata == false))) {
+ if (filter_on_write && is_metadata && ((!m->encrypted) || (m->encrypt_metadata == false))) {
QTC::TC("qpdf", "QPDFWriter not compressing metadata");
filter = true;
compress_stream = false;
uncompress = true;
- } else if (
- filter_on_write && m->normalize_content &&
- m->normalized_streams.count(old_og)) {
+ } else if (filter_on_write && m->normalize_content && m->normalized_streams.count(old_og)) {
normalize = true;
filter = true;
} else if (filter_on_write && filter && m->compress_streams) {
@@ -1392,14 +1322,12 @@ QPDFWriter::willFilterStream(
m->pipeline,
(((filter && normalize) ? qpdf_ef_normalize : 0) |
((filter && compress_stream) ? qpdf_ef_compress : 0)),
- (filter ? (uncompress ? qpdf_dl_all : m->stream_decode_level)
- : qpdf_dl_none),
+ (filter ? (uncompress ? qpdf_dl_all : m->stream_decode_level) : qpdf_dl_none),
false,
(attempt == 1));
} catch (std::runtime_error& e) {
throw std::runtime_error(
- "error while getting stream data for " + stream.unparse() +
- ": " + e.what());
+ "error while getting stream data for " + stream.unparse() + ": " + e.what());
}
if (filter && (!filtered)) {
// Try again
@@ -1416,11 +1344,7 @@ QPDFWriter::willFilterStream(
void
QPDFWriter::unparseObject(
- QPDFObjectHandle object,
- int level,
- int flags,
- size_t stream_length,
- bool compress)
+ QPDFObjectHandle object, int level, int flags, size_t stream_length, bool compress)
{
QPDFObjGen old_og = object.getObjGen();
int child_flags = flags & ~f_stream;
@@ -1486,8 +1410,7 @@ QPDFWriter::unparseObject(
QPDFObjectHandle extensions;
if (is_root) {
- if (object.hasKey("/Extensions") &&
- object.getKey("/Extensions").isDictionary()) {
+ if (object.hasKey("/Extensions") && object.getKey("/Extensions").isDictionary()) {
extensions = object.getKey("/Extensions");
}
}
@@ -1510,10 +1433,7 @@ QPDFWriter::unparseObject(
if (!(have_extensions_other || have_extensions_adbe)) {
// We need Extensions and don't have it. Create
// it here.
- QTC::TC(
- "qpdf",
- "QPDFWriter create Extensions",
- m->qdf_mode ? 0 : 1);
+ QTC::TC("qpdf", "QPDFWriter create Extensions", m->qdf_mode ? 0 : 1);
extensions = object.replaceKeyAndGetNew(
"/Extensions", QPDFObjectHandle::newDictionary());
}
@@ -1531,19 +1451,16 @@ QPDFWriter::unparseObject(
QTC::TC("qpdf", "QPDFWriter preserve Extensions");
QPDFObjectHandle adbe = extensions.getKey("/ADBE");
if (adbe.isDictionary() &&
- adbe.getKey("/BaseVersion")
- .isNameAndEquals("/" + m->final_pdf_version) &&
+ adbe.getKey("/BaseVersion").isNameAndEquals("/" + m->final_pdf_version) &&
adbe.getKey("/ExtensionLevel").isInteger() &&
- (adbe.getKey("/ExtensionLevel").getIntValue() ==
- m->final_extension_level)) {
+ (adbe.getKey("/ExtensionLevel").getIntValue() == m->final_extension_level)) {
QTC::TC("qpdf", "QPDFWriter preserve ADBE");
} else {
if (need_extensions_adbe) {
extensions.replaceKey(
"/ADBE",
QPDFObjectHandle::parse(
- "<< /BaseVersion /" + m->final_pdf_version +
- " /ExtensionLevel " +
+ "<< /BaseVersion /" + m->final_pdf_version + " /ExtensionLevel " +
std::to_string(m->final_extension_level) + " >>"));
} else {
QTC::TC("qpdf", "QPDFWriter remove ADBE");
@@ -1617,9 +1534,7 @@ QPDFWriter::unparseObject(
object.hasKey("/ByteRange")) {
QTC::TC("qpdf", "QPDFWriter no encryption sig contents");
unparseChild(
- item.second,
- level + 1,
- child_flags | f_hex_string | f_no_encryption);
+ item.second, level + 1, child_flags | f_hex_string | f_no_encryption);
} else {
unparseChild(item.second, level + 1, child_flags);
}
@@ -1657,8 +1572,7 @@ QPDFWriter::unparseObject(
bool compress_stream = false;
bool is_metadata = false;
std::shared_ptr<Buffer> stream_data;
- if (willFilterStream(
- object, compress_stream, is_metadata, &stream_data)) {
+ if (willFilterStream(object, compress_stream, is_metadata, &stream_data)) {
flags |= f_filtered;
}
QPDFObjectHandle stream_dict = object.getDict();
@@ -1669,8 +1583,7 @@ QPDFWriter::unparseObject(
m->cur_data_key.clear();
}
adjustAESStreamLength(m->cur_stream_length);
- unparseObject(
- stream_dict, 0, flags, m->cur_stream_length, compress_stream);
+ unparseObject(stream_dict, 0, flags, m->cur_stream_length, compress_stream);
unsigned char last_char = '\0';
writeString("\nstream\n");
{
@@ -1680,8 +1593,7 @@ QPDFWriter::unparseObject(
last_char = m->pipeline->getLastChar();
}
- if (m->newline_before_endstream ||
- (m->qdf_mode && (last_char != '\n'))) {
+ if (m->newline_before_endstream || (m->qdf_mode && (last_char != '\n'))) {
writeString("\n");
m->added_newline = true;
} else {
@@ -1690,8 +1602,8 @@ QPDFWriter::unparseObject(
writeString("endstream");
} else if (tc == ::ot_string) {
std::string val;
- if (m->encrypted && (!(flags & f_in_ostream)) &&
- (!(flags & f_no_encryption)) && (!m->cur_data_key.empty())) {
+ if (m->encrypted && (!(flags & f_in_ostream)) && (!(flags & f_no_encryption)) &&
+ (!m->cur_data_key.empty())) {
val = object.getStringValue();
if (m->encrypt_use_aes) {
Pl_Buffer bufpl("encrypted string");
@@ -1704,9 +1616,8 @@ QPDFWriter::unparseObject(
pl.writeString(val);
pl.finish();
auto buf = bufpl.getBufferSharedPointer();
- val = QPDF_String(std::string(
- reinterpret_cast<char*>(buf->getBuffer()),
- buf->getSize()))
+ val = QPDF_String(
+ std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize()))
.unparse(true);
} else {
auto tmp_ph = QUtil::make_unique_cstr(val);
@@ -1731,8 +1642,7 @@ QPDFWriter::unparseObject(
}
void
-QPDFWriter::writeObjectStreamOffsets(
- std::vector<qpdf_offset_t>& offsets, int first_obj)
+QPDFWriter::writeObjectStreamOffsets(std::vector<qpdf_offset_t>& offsets, int first_obj)
{
for (size_t i = 0; i < offsets.size(); ++i) {
if (i != 0) {
@@ -1788,12 +1698,11 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
// Set up a stream to write the stream data into a buffer.
Pipeline* next = pushPipeline(new Pl_Buffer("object stream"));
- if ((m->compress_streams ||
- (m->stream_decode_level == qpdf_dl_none)) &&
+ if ((m->compress_streams || (m->stream_decode_level == qpdf_dl_none)) &&
(!m->qdf_mode)) {
compressed = true;
- next = pushPipeline(new Pl_Flate(
- "compress object stream", next, Pl_Flate::a_deflate));
+ next =
+ pushPipeline(new Pl_Flate("compress object stream", next, Pl_Flate::a_deflate));
}
activatePipelineStack(pp_ostream);
writeObjectStreamOffsets(offsets, first_obj);
@@ -1808,12 +1717,10 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
}
if (m->qdf_mode) {
writeString(
- "%% Object stream: object " + std::to_string(new_obj) +
- ", index " + std::to_string(count));
+ "%% Object stream: object " + std::to_string(new_obj) + ", index " +
+ std::to_string(count));
if (!m->suppress_original_object_ids) {
- writeString(
- "; original object ID: " +
- std::to_string(obj.getObj()));
+ writeString("; original object ID: " + std::to_string(obj.getObj()));
// For compatibility, only write the generation if
// non-zero. While object streams only allow
// objects with generation 0, if we are generating
@@ -1839,8 +1746,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
// should block it at at parse time, but it's not
// clear to me how to construct a case for this.
QTC::TC("qpdf", "QPDFWriter stream in ostream");
- obj_to_write.warnIfPossible(
- "stream found inside object stream; treating as null");
+ obj_to_write.warnIfPossible("stream found inside object stream; treating as null");
obj_to_write = QPDFObjectHandle::newNull();
}
writeObject(obj_to_write, count);
@@ -1923,9 +1829,7 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index)
}
if (object_stream_index == -1) {
if (m->qdf_mode && (!m->suppress_original_object_ids)) {
- writeString(
- "%% Original object ID: " + object.getObjGen().unparse(' ') +
- "\n");
+ writeString("%% Original object ID: " + object.getObjGen().unparse(' ') + "\n");
}
openObject(new_id);
setDataKey(new_id);
@@ -2013,11 +1917,10 @@ QPDFWriter::generateID()
if (m->deterministic_id) {
if (m->deterministic_id_data.empty()) {
QTC::TC("qpdf", "QPDFWriter deterministic with no data");
- throw std::logic_error(
- "INTERNAL ERROR: QPDFWriter::generateID has no"
- " data for deterministic ID. This may happen if"
- " deterministic ID and file encryption are requested"
- " together.");
+ throw std::logic_error("INTERNAL ERROR: QPDFWriter::generateID has no"
+ " data for deterministic ID. This may happen if"
+ " deterministic ID and file encryption are requested"
+ " together.");
}
seed += m->deterministic_id_data;
} else {
@@ -2041,8 +1944,7 @@ QPDFWriter::generateID()
m.encodeString(seed.c_str());
MD5::Digest digest;
m.digest(digest);
- result =
- std::string(reinterpret_cast<char*>(digest), sizeof(MD5::Digest));
+ result = std::string(reinterpret_cast<char*>(digest), sizeof(MD5::Digest));
}
// If /ID already exists, follow the spec: use the original first
@@ -2071,8 +1973,7 @@ QPDFWriter::initializeSpecialStreams()
if (contents.isArray()) {
int n = contents.getArrayNItems();
for (int i = 0; i < n; ++i) {
- contents_objects.push_back(
- contents.getArrayItem(i).getObjGen());
+ contents_objects.push_back(contents.getArrayItem(i).getObjGen());
}
} else if (contents.isStream()) {
contents_objects.push_back(contents.getObjGen());
@@ -2105,14 +2006,10 @@ QPDFWriter::preserveObjectStreams()
// included.
std::set<QPDFObjGen> eligible;
if (!m->preserve_unreferenced_objects) {
- std::vector<QPDFObjGen> eligible_v =
- QPDF::Writer::getCompressibleObjGens(m->pdf);
+ std::vector<QPDFObjGen> eligible_v = QPDF::Writer::getCompressibleObjGens(m->pdf);
eligible = std::set<QPDFObjGen>(eligible_v.begin(), eligible_v.end());
}
- QTC::TC(
- "qpdf",
- "QPDFWriter preserve object streams",
- m->preserve_unreferenced_objects ? 0 : 1);
+ QTC::TC("qpdf", "QPDFWriter preserve object streams", m->preserve_unreferenced_objects ? 0 : 1);
for (auto iter: omap) {
QPDFObjGen og(iter.first, 0);
if (eligible.count(og) || m->preserve_unreferenced_objects) {
@@ -2136,8 +2033,7 @@ QPDFWriter::generateObjectStreams()
// This code doesn't do anything with /Extends.
- std::vector<QPDFObjGen> eligible =
- QPDF::Writer::getCompressibleObjGens(m->pdf);
+ std::vector<QPDFObjGen> eligible = QPDF::Writer::getCompressibleObjGens(m->pdf);
size_t n_object_streams = (eligible.size() + 99U) / 100U;
if (n_object_streams == 0) {
return;
@@ -2159,8 +2055,7 @@ QPDFWriter::generateObjectStreams()
// Construct a new null object as the "original" object
// stream. The rest of the code knows that this means
// we're creating the object stream from scratch.
- cur_ostream = m->pdf.makeIndirectObject(QPDFObjectHandle::newNull())
- .getObjectID();
+ cur_ostream = m->pdf.makeIndirectObject(QPDFObjectHandle::newNull()).getObjectID();
}
m->object_to_object_stream[iter] = cur_ostream;
++n;
@@ -2215,10 +2110,7 @@ QPDFWriter::prepareFileForWrite()
if (oh.hasKey("/ADBE")) {
QPDFObjectHandle adbe = oh.getKey("/ADBE");
if (adbe.isIndirect()) {
- QTC::TC(
- "qpdf",
- "QPDFWriter make ADBE direct",
- extensions_indirect ? 0 : 1);
+ QTC::TC("qpdf", "QPDFWriter make ADBE direct", extensions_indirect ? 0 : 1);
adbe.makeDirect();
oh.replaceKey("/ADBE", adbe);
}
@@ -2262,9 +2154,7 @@ QPDFWriter::doWriteSetup()
if (m->encrypted) {
// Encryption has been explicitly set
m->preserve_encryption = false;
- } else if (
- m->normalize_content || m->stream_decode_level || m->pclm ||
- m->qdf_mode) {
+ } else if (m->normalize_content || m->stream_decode_level || m->pclm || m->qdf_mode) {
// Encryption makes looking at contents pretty useless. If
// the user explicitly encrypted though, we still obey that.
m->preserve_encryption = false;
@@ -2342,8 +2232,7 @@ QPDFWriter::doWriteSetup()
int stream = iter.second;
m->object_stream_to_objects[stream].insert(obj);
m->max_ostream_index = std::max(
- m->max_ostream_index,
- QIntC::to_int(m->object_stream_to_objects[stream].size()) - 1);
+ m->max_ostream_index, QIntC::to_int(m->object_stream_to_objects[stream].size()) - 1);
}
if (!m->object_stream_to_objects.empty()) {
@@ -2368,8 +2257,7 @@ QPDFWriter::write()
// Set up progress reporting. For linearized files, we write two
// passes. events_expected is an approximation, but it's good
// enough for progress reporting, which is mostly a guess anyway.
- m->events_expected =
- QIntC::to_int(m->pdf.getObjectCount() * (m->linearized ? 2 : 1));
+ m->events_expected = QIntC::to_int(m->pdf.getObjectCount() * (m->linearized ? 2 : 1));
prepareFileForWrite();
@@ -2541,8 +2429,7 @@ QPDFWriter::writeXRefTable(
qpdf_offset_t offset = 0;
if (!suppress_offsets) {
offset = m->xref[i].getOffset();
- if ((hint_id != 0) && (i != hint_id) &&
- (offset >= hint_offset)) {
+ if ((hint_id != 0) && (i != hint_id) && (offset >= hint_offset)) {
offset += hint_length;
}
}
@@ -2557,31 +2444,13 @@ QPDFWriter::writeXRefTable(
qpdf_offset_t
QPDFWriter::writeXRefStream(
- int objid,
- int max_id,
- qpdf_offset_t max_offset,
- trailer_e which,
- int first,
- int last,
- int size)
+ int objid, int max_id, qpdf_offset_t max_offset, trailer_e which, int first, int last, int size)
{
// There are too many extra arguments to replace overloaded
// function with defaults in the header file...too much risk of
// leaving something off.
return writeXRefStream(
- objid,
- max_id,
- max_offset,
- which,
- first,
- last,
- size,
- 0,
- 0,
- 0,
- 0,
- false,
- 0);
+ objid, max_id, max_offset, which, first, last, size, 0, 0, 0, 0, false, 0);
}
qpdf_offset_t
@@ -2604,8 +2473,7 @@ QPDFWriter::writeXRefStream(
qpdf_offset_t space_before_zero = xref_offset - 1;
// field 1 contains offsets and object stream identifiers
- unsigned int f1_size =
- std::max(bytesNeeded(max_offset + hint_length), bytesNeeded(max_id));
+ unsigned int f1_size = std::max(bytesNeeded(max_offset + hint_length), bytesNeeded(max_id));
// field 2 contains object stream indices
unsigned int f2_size = bytesNeeded(m->max_ostream_index);
@@ -2618,18 +2486,15 @@ QPDFWriter::writeXRefStream(
Pipeline* p = pushPipeline(new Pl_Buffer("xref stream"));
bool compressed = false;
- if ((m->compress_streams || (m->stream_decode_level == qpdf_dl_none)) &&
- (!m->qdf_mode)) {
+ if ((m->compress_streams || (m->stream_decode_level == qpdf_dl_none)) && (!m->qdf_mode)) {
compressed = true;
if (!skip_compression) {
// Write the stream dictionary for compression but don't
// actually compress. This helps us with computation of
// padding for pass 1 of linearization.
- p = pushPipeline(
- new Pl_Flate("compress xref", p, Pl_Flate::a_deflate));
+ p = pushPipeline(new Pl_Flate("compress xref", p, Pl_Flate::a_deflate));
}
- p = pushPipeline(
- new Pl_PNGFilter("pngify xref", p, Pl_PNGFilter::a_encode, esize));
+ p = pushPipeline(new Pl_PNGFilter("pngify xref", p, Pl_PNGFilter::a_encode, esize));
}
std::shared_ptr<Buffer> xref_data;
{
@@ -2647,8 +2512,7 @@ QPDFWriter::writeXRefStream(
case 1:
{
qpdf_offset_t offset = e.getOffset();
- if ((hint_id != 0) && (i != hint_id) &&
- (offset >= hint_offset)) {
+ if ((hint_id != 0) && (i != hint_id) && (offset >= hint_offset)) {
offset += hint_length;
}
writeBinary(1, 1);
@@ -2659,10 +2523,8 @@ QPDFWriter::writeXRefStream(
case 2:
writeBinary(2, 1);
- writeBinary(
- QIntC::to_ulonglong(e.getObjStreamNumber()), f1_size);
- writeBinary(
- QIntC::to_ulonglong(e.getObjStreamIndex()), f2_size);
+ writeBinary(QIntC::to_ulonglong(e.getObjStreamNumber()), f1_size);
+ writeBinary(QIntC::to_ulonglong(e.getObjStreamIndex()), f2_size);
break;
default:
@@ -2682,18 +2544,13 @@ QPDFWriter::writeXRefStream(
writeStringQDF("\n ");
writeString(" /Filter /FlateDecode");
writeStringQDF("\n ");
- writeString(
- " /DecodeParms << /Columns " + std::to_string(esize) +
- " /Predictor 12 >>");
+ writeString(" /DecodeParms << /Columns " + std::to_string(esize) + " /Predictor 12 >>");
}
writeStringQDF("\n ");
- writeString(
- " /W [ 1 " + std::to_string(f1_size) + " " + std::to_string(f2_size) +
- " ]");
+ writeString(" /W [ 1 " + std::to_string(f1_size) + " " + std::to_string(f2_size) + " ]");
if (!((first == 0) && (last == size - 1))) {
writeString(
- " /Index [ " + std::to_string(first) + " " +
- std::to_string(last - first + 1) + " ]");
+ " /Index [ " + std::to_string(first) + " " + std::to_string(last - first + 1) + " ]");
}
writeTrailer(which, size, true, prev, linearization_pass);
writeString("\nstream\n");
@@ -2718,8 +2575,7 @@ QPDFWriter::calculateXrefStreamPadding(qpdf_offset_t xref_bytes)
}
void
-QPDFWriter::discardGeneration(
- std::map<QPDFObjGen, int> const& in, std::map<int, int>& out)
+QPDFWriter::discardGeneration(std::map<QPDFObjGen, int> const& in, std::map<int, int>& out)
{
// There are deep assumptions in the linearization code in QPDF
// that there is only one object with each object number; i.e.,
@@ -2736,14 +2592,13 @@ QPDFWriter::discardGeneration(
out.clear();
for (auto const& iter: in) {
if (out.count(iter.first.getObj())) {
- throw std::runtime_error(
- "QPDF cannot currently linearize files that contain"
- " multiple objects with the same object ID and different"
- " generations. If you see this error message, please file"
- " a bug report and attach the file if possible. As a"
- " workaround, first convert the file with qpdf without"
- " linearizing, and then linearize the result of that"
- " conversion.");
+ throw std::runtime_error("QPDF cannot currently linearize files that contain"
+ " multiple objects with the same object ID and different"
+ " generations. If you see this error message, please file"
+ " a bug report and attach the file if possible. As a"
+ " workaround, first convert the file with qpdf without"
+ " linearizing, and then linearize the result of that"
+ " conversion.");
}
out[iter.first.getObj()] = iter.second;
}
@@ -2754,8 +2609,7 @@ QPDFWriter::writeLinearized()
{
// Optimize file and enqueue objects in order
- discardGeneration(
- m->object_to_object_stream, m->object_to_object_stream_no_gen);
+ discardGeneration(m->object_to_object_stream, m->object_to_object_stream_no_gen);
auto skip_stream_parameters = [this](QPDFObjectHandle& stream) {
bool compress_stream;
@@ -2767,8 +2621,7 @@ QPDFWriter::writeLinearized()
}
};
- m->pdf.optimize(
- m->object_to_object_stream_no_gen, true, skip_stream_parameters);
+ m->pdf.optimize(m->object_to_object_stream_no_gen, true, skip_stream_parameters);
std::vector<QPDFObjectHandle> part4;
std::vector<QPDFObjectHandle> part6;
@@ -2776,13 +2629,7 @@ QPDFWriter::writeLinearized()
std::vector<QPDFObjectHandle> part8;
std::vector<QPDFObjectHandle> part9;
QPDF::Writer::getLinearizedParts(
- m->pdf,
- m->object_to_object_stream_no_gen,
- part4,
- part6,
- part7,
- part8,
- part9);
+ m->pdf, m->object_to_object_stream_no_gen, part4, part6, part7, part8, part9);
// Object number sequence:
//
@@ -2801,8 +2648,7 @@ QPDFWriter::writeLinearized()
//
// Second half objects
- int second_half_uncompressed =
- QIntC::to_int(part7.size() + part8.size() + part9.size());
+ int second_half_uncompressed = QIntC::to_int(part7.size() + part8.size() + part9.size());
int second_half_first_obj = 1;
int after_second_half = 1 + second_half_uncompressed;
m->next_objid = after_second_half;
@@ -2893,10 +2739,8 @@ QPDFWriter::writeLinearized()
for (int pass = 1; pass <= 2; ++pass) {
if (pass == 1) {
if (!m->lin_pass1_filename.empty()) {
- lin_pass1_file =
- QUtil::safe_fopen(m->lin_pass1_filename.c_str(), "wb");
- pushPipeline(
- new Pl_StdioFile("linearization pass1", lin_pass1_file));
+ lin_pass1_file = QUtil::safe_fopen(m->lin_pass1_filename.c_str(), "wb");
+ pushPipeline(new Pl_StdioFile("linearization pass1", lin_pass1_file));
activatePipelineStack(*pp_pass1);
} else {
pushDiscardFilter(*pp_pass1);
@@ -3003,8 +2847,7 @@ QPDFWriter::writeLinearized()
throw std::logic_error(
"insufficient padding for first pass xref stream; "
"first_xref_end=" +
- std::to_string(first_xref_end) +
- "; endpos=" + std::to_string(endpos));
+ std::to_string(first_xref_end) + "; endpos=" + std::to_string(endpos));
}
}
writeString("\n");
@@ -3078,9 +2921,8 @@ QPDFWriter::writeLinearized()
second_xref_end = m->pipeline->getCount();
} else {
// Make the file size the same.
- writePad(QIntC::to_size(
- second_xref_end + hint_length - 1 -
- m->pipeline->getCount()));
+ writePad(
+ QIntC::to_size(second_xref_end + hint_length - 1 - m->pipeline->getCount()));
writeString("\n");
// If this assertion fails, maybe we didn't have
@@ -3092,16 +2934,7 @@ QPDFWriter::writeLinearized()
}
} else {
space_before_zero = writeXRefTable(
- t_lin_second,
- 0,
- second_half_end,
- second_trailer_size,
- 0,
- false,
- 0,
- 0,
- 0,
- pass);
+ t_lin_second, 0, second_half_end, second_trailer_size, 0, false, 0, 0, 0, pass);
}
writeString("startxref\n");
writeString(std::to_string(first_xref_offset));
@@ -3111,10 +2944,7 @@ QPDFWriter::writeLinearized()
if (pass == 1) {
if (m->deterministic_id) {
- QTC::TC(
- "qpdf",
- "QPDFWriter linearized deterministic ID",
- need_xref_stream ? 0 : 1);
+ QTC::TC("qpdf", "QPDFWriter linearized deterministic ID", need_xref_stream ? 0 : 1);
computeDeterministicIDData();
pp_md5 = nullptr;
qpdf_assert_debug(m->md5_pipeline == nullptr);
@@ -3142,13 +2972,8 @@ QPDFWriter::writeLinearized()
if (lin_pass1_file) {
// Write some debugging information
fprintf(
- lin_pass1_file,
- "%% hint_offset=%s\n",
- std::to_string(hint_offset1).c_str());
- fprintf(
- lin_pass1_file,
- "%% hint_length=%s\n",
- std::to_string(hint_length).c_str());
+ lin_pass1_file, "%% hint_offset=%s\n", std::to_string(hint_offset1).c_str());
+ fprintf(lin_pass1_file, "%% hint_length=%s\n", std::to_string(hint_length).c_str());
fprintf(
lin_pass1_file,
"%% second_xref_offset=%s\n",
@@ -3208,8 +3033,7 @@ QPDFWriter::enqueueObjectsPCLm()
QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject");
for (auto const& image: strips.getKeys()) {
enqueueObject(strips.getKey(image));
- enqueueObject(
- QPDFObjectHandle::newStream(&m->pdf, image_transform_content));
+ enqueueObject(QPDFObjectHandle::newStream(&m->pdf, image_transform_content));
}
}
@@ -3237,8 +3061,7 @@ QPDFWriter::indicateProgress(bool decrement, bool finished)
(finished ? 100
: m->next_progress_report == 0
? 0
- : std::min(
- 99, 1 + ((100 * m->events_seen) / m->events_expected)));
+ : std::min(99, 1 + ((100 * m->events_seen) / m->events_expected)));
m->progress_reporter->reportProgress(percentage);
}
int increment = std::max(1, (m->events_expected / 100));
@@ -3293,13 +3116,7 @@ QPDFWriter::writeStandard()
// Write cross-reference stream.
int xref_id = m->next_objid++;
writeXRefStream(
- xref_id,
- xref_id,
- xref_offset,
- t_normal,
- 0,
- m->next_objid - 1,
- m->next_objid);
+ xref_id, xref_id, xref_offset, t_normal, 0, m->next_objid - 1, m->next_objid);
}
writeString("startxref\n");
writeString(std::to_string(xref_offset));
diff --git a/libqpdf/QPDFXRefEntry.cc b/libqpdf/QPDFXRefEntry.cc
index 0d66028c..7be98b2a 100644
--- a/libqpdf/QPDFXRefEntry.cc
+++ b/libqpdf/QPDFXRefEntry.cc
@@ -36,8 +36,7 @@ int
QPDFXRefEntry::getObjStreamNumber() const
{
if (this->type != 2) {
- throw std::logic_error(
- "getObjStreamNumber called for xref entry of type != 2");
+ throw std::logic_error("getObjStreamNumber called for xref entry of type != 2");
}
return QIntC::to_int(this->field1);
}
@@ -46,8 +45,7 @@ int
QPDFXRefEntry::getObjStreamIndex() const
{
if (this->type != 2) {
- throw std::logic_error(
- "getObjStreamIndex called for xref entry of type != 2");
+ throw std::logic_error("getObjStreamIndex called for xref entry of type != 2");
}
return this->field2;
}
diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc
index d0228361..760db2e2 100644
--- a/libqpdf/QPDF_Array.cc
+++ b/libqpdf/QPDF_Array.cc
@@ -12,16 +12,14 @@ QPDF_Array::checkOwnership(QPDFObjectHandle const& item) const
if (qpdf) {
if (auto item_qpdf = obj->getQPDF()) {
if (qpdf != item_qpdf) {
- throw std::logic_error(
- "Attempting to add an object from a different QPDF. "
- "Use QPDF::copyForeignObject to add objects from "
- "another file.");
+ throw std::logic_error("Attempting to add an object from a different QPDF. "
+ "Use QPDF::copyForeignObject to add objects from "
+ "another file.");
}
}
}
} else {
- throw std::logic_error(
- "Attempting to add an uninitialized object to a QPDF_Array.");
+ throw std::logic_error("Attempting to add an uninitialized object to a QPDF_Array.");
}
}
@@ -45,15 +43,13 @@ QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v) :
setFromVector(v);
}
-QPDF_Array::QPDF_Array(
- std::vector<std::shared_ptr<QPDFObject>>&& v, bool sparse) :
+QPDF_Array::QPDF_Array(std::vector<std::shared_ptr<QPDFObject>>&& v, bool sparse) :
QPDFValue(::ot_array, "array"),
sparse(sparse)
{
if (sparse) {
for (auto&& item: v) {
- if (item->getTypeCode() != ::ot_null ||
- item->getObjGen().isIndirect()) {
+ if (item->getTypeCode() != ::ot_null || item->getObjGen().isIndirect()) {
sp_elements[sp_size] = std::move(item);
}
++sp_size;
@@ -70,8 +66,7 @@ QPDF_Array::create(std::vector<QPDFObjectHandle> const& items)
}
std::shared_ptr<QPDFObject>
-QPDF_Array::create(
- std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse)
+QPDF_Array::create(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse)
{
return do_create(new QPDF_Array(std::move(items), sparse));
}
@@ -96,10 +91,8 @@ QPDF_Array::copy(bool shallow)
result.reserve(elements.size());
for (auto const& element: elements) {
result.push_back(
- element
- ? (element->getObjGen().isIndirect() ? element
- : element->copy())
- : element);
+ element ? (element->getObjGen().isIndirect() ? element : element->copy())
+ : element);
}
return create(std::move(result), false);
}
@@ -138,8 +131,7 @@ QPDF_Array::unparse()
}
item.second->resolve();
auto og = item.second->getObjGen();
- result += og.isIndirect() ? og.unparse(' ') + " R "
- : item.second->unparse() + " ";
+ result += og.isIndirect() ? og.unparse(' ') + " R " : item.second->unparse() + " ";
next = ++key;
}
for (int j = next; j < sp_size; ++j) {
@@ -149,8 +141,7 @@ QPDF_Array::unparse()
for (auto const& item: elements) {
item->resolve();
auto og = item->getObjGen();
- result += og.isIndirect() ? og.unparse(' ') + " R "
- : item->unparse() + " ";
+ result += og.isIndirect() ? og.unparse(' ') + " R " : item->unparse() + " ";
}
}
result += "]";
diff --git a/libqpdf/QPDF_Destroyed.cc b/libqpdf/QPDF_Destroyed.cc
index eb84f3aa..4e34b508 100644
--- a/libqpdf/QPDF_Destroyed.cc
+++ b/libqpdf/QPDF_Destroyed.cc
@@ -17,23 +17,20 @@ QPDF_Destroyed::getInstance()
std::shared_ptr<QPDFObject>
QPDF_Destroyed::copy(bool shallow)
{
- throw std::logic_error(
- "attempted to shallow copy QPDFObjectHandle from destroyed QPDF");
+ throw std::logic_error("attempted to shallow copy QPDFObjectHandle from destroyed QPDF");
return nullptr;
}
std::string
QPDF_Destroyed::unparse()
{
- throw std::logic_error(
- "attempted to unparse a QPDFObjectHandle from a destroyed QPDF");
+ throw std::logic_error("attempted to unparse a QPDFObjectHandle from a destroyed QPDF");
return "";
}
JSON
QPDF_Destroyed::getJSON(int json_version)
{
- throw std::logic_error(
- "attempted to get JSON from a QPDFObjectHandle from a destroyed QPDF");
+ throw std::logic_error("attempted to get JSON from a QPDFObjectHandle from a destroyed QPDF");
return JSON::makeNull();
}
diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc
index 43ad8a85..6d259ef5 100644
--- a/libqpdf/QPDF_Dictionary.cc
+++ b/libqpdf/QPDF_Dictionary.cc
@@ -6,15 +6,13 @@
using namespace std::literals;
-QPDF_Dictionary::QPDF_Dictionary(
- std::map<std::string, QPDFObjectHandle> const& items) :
+QPDF_Dictionary::QPDF_Dictionary(std::map<std::string, QPDFObjectHandle> const& items) :
QPDFValue(::ot_dictionary, "dictionary"),
items(items)
{
}
-QPDF_Dictionary::QPDF_Dictionary(
- std::map<std::string, QPDFObjectHandle>&& items) :
+QPDF_Dictionary::QPDF_Dictionary(std::map<std::string, QPDFObjectHandle>&& items) :
QPDFValue(::ot_dictionary, "dictionary"),
items(items)
{
@@ -41,8 +39,7 @@ QPDF_Dictionary::copy(bool shallow)
std::map<std::string, QPDFObjectHandle> new_items;
for (auto const& item: this->items) {
auto value = item.second;
- new_items[item.first] =
- value.isIndirect() ? value : value.shallowCopy();
+ new_items[item.first] = value.isIndirect() ? value : value.shallowCopy();
}
return create(new_items);
}
@@ -62,8 +59,7 @@ QPDF_Dictionary::unparse()
std::string result = "<< ";
for (auto& iter: this->items) {
if (!iter.second.isNull()) {
- result += QPDF_Name::normalizeName(iter.first) + " " +
- iter.second.unparse() + " ";
+ result += QPDF_Name::normalizeName(iter.first) + " " + iter.second.unparse() + " ";
}
}
result += ">>";
@@ -77,8 +73,7 @@ QPDF_Dictionary::getJSON(int json_version)
for (auto& iter: this->items) {
if (!iter.second.isNull()) {
std::string key =
- (json_version == 1 ? QPDF_Name::normalizeName(iter.first)
- : iter.first);
+ (json_version == 1 ? QPDF_Name::normalizeName(iter.first) : iter.first);
j.addDictionaryMember(key, iter.second.getJSON(json_version));
}
}
diff --git a/libqpdf/QPDF_Name.cc b/libqpdf/QPDF_Name.cc
index 11b30086..8e439213 100644
--- a/libqpdf/QPDF_Name.cc
+++ b/libqpdf/QPDF_Name.cc
@@ -36,9 +36,8 @@ QPDF_Name::normalizeName(std::string const& name)
// invalid #.
result += "#";
} else if (
- ch < 33 || ch == '#' || ch == '/' || ch == '(' || ch == ')' ||
- ch == '{' || ch == '}' || ch == '<' || ch == '>' || ch == '[' ||
- ch == ']' || ch == '%' || ch > 126) {
+ ch < 33 || ch == '#' || ch == '/' || ch == '(' || ch == ')' || ch == '{' || ch == '}' ||
+ ch == '<' || ch == '>' || ch == '[' || ch == ']' || ch == '%' || ch > 126) {
result += QUtil::hex_encode_char(ch);
} else {
result += ch;
diff --git a/libqpdf/QPDF_Null.cc b/libqpdf/QPDF_Null.cc
index 0b59f5c9..fdabdfa7 100644
--- a/libqpdf/QPDF_Null.cc
+++ b/libqpdf/QPDF_Null.cc
@@ -15,9 +15,7 @@ QPDF_Null::create()
std::shared_ptr<QPDFObject>
QPDF_Null::create(
- std::shared_ptr<QPDFObject> parent,
- std::string_view const& static_descr,
- std::string var_descr)
+ std::shared_ptr<QPDFObject> parent, std::string_view const& static_descr, std::string var_descr)
{
auto n = do_create(new QPDF_Null());
n->setChildDescription(parent, static_descr, var_descr);
@@ -26,9 +24,7 @@ QPDF_Null::create(
std::shared_ptr<QPDFObject>
QPDF_Null::create(
- std::shared_ptr<QPDFValue> parent,
- std::string_view const& static_descr,
- std::string var_descr)
+ std::shared_ptr<QPDFValue> parent, std::string_view const& static_descr, std::string var_descr)
{
auto n = do_create(new QPDF_Null());
n->setChildDescription(parent, static_descr, var_descr);
diff --git a/libqpdf/QPDF_Real.cc b/libqpdf/QPDF_Real.cc
index b5e78595..19b65a7e 100644
--- a/libqpdf/QPDF_Real.cc
+++ b/libqpdf/QPDF_Real.cc
@@ -8,8 +8,7 @@ QPDF_Real::QPDF_Real(std::string const& val) :
{
}
-QPDF_Real::QPDF_Real(
- double value, int decimal_places, bool trim_trailing_zeroes) :
+QPDF_Real::QPDF_Real(double value, int decimal_places, bool trim_trailing_zeroes) :
QPDFValue(::ot_real, "real"),
val(QUtil::double_to_string(value, decimal_places, trim_trailing_zeroes))
{
@@ -24,8 +23,7 @@ QPDF_Real::create(std::string const& val)
std::shared_ptr<QPDFObject>
QPDF_Real::create(double value, int decimal_places, bool trim_trailing_zeroes)
{
- return do_create(
- new QPDF_Real(value, decimal_places, trim_trailing_zeroes));
+ return do_create(new QPDF_Real(value, decimal_places, trim_trailing_zeroes));
}
std::shared_ptr<QPDFObject>
@@ -52,9 +50,7 @@ QPDF_Real::getJSON(int json_version)
result = "0";
} else if (this->val.at(0) == '.') {
result = "0" + this->val;
- } else if (
- (this->val.length() >= 2) && (this->val.at(0) == '-') &&
- (this->val.at(1) == '.')) {
+ } else if ((this->val.length() >= 2) && (this->val.at(0) == '-') && (this->val.at(1) == '.')) {
result = "-0." + this->val.substr(2);
} else {
result = this->val;
diff --git a/libqpdf/QPDF_Reserved.cc b/libqpdf/QPDF_Reserved.cc
index c675ec7d..845d6ebc 100644
--- a/libqpdf/QPDF_Reserved.cc
+++ b/libqpdf/QPDF_Reserved.cc
@@ -22,15 +22,13 @@ QPDF_Reserved::copy(bool shallow)
std::string
QPDF_Reserved::unparse()
{
- throw std::logic_error(
- "QPDFObjectHandle: attempting to unparse a reserved object");
+ throw std::logic_error("QPDFObjectHandle: attempting to unparse a reserved object");
return "";
}
JSON
QPDF_Reserved::getJSON(int json_version)
{
- throw std::logic_error(
- "QPDFObjectHandle: attempting to get JSON from a reserved object");
+ throw std::logic_error("QPDFObjectHandle: attempting to get JSON from a reserved object");
return JSON::makeNull();
}
diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc
index 9cfb3ac4..165b216f 100644
--- a/libqpdf/QPDF_Stream.cc
+++ b/libqpdf/QPDF_Stream.cc
@@ -39,8 +39,7 @@ namespace
for (auto const& key: decode_parms.getKeys()) {
if (((key == "/Type") || (key == "/Name")) &&
((!decode_parms.hasKey("/Type")) ||
- decode_parms.isDictionaryOfType(
- "/CryptFilterDecodeParms"))) {
+ decode_parms.isDictionaryOfType("/CryptFilterDecodeParms"))) {
// we handle this in decryptStream
} else {
filterable = false;
@@ -60,8 +59,7 @@ namespace
class StreamBlobProvider
{
public:
- StreamBlobProvider(
- QPDF_Stream* stream, qpdf_stream_decode_level_e decode_level);
+ StreamBlobProvider(QPDF_Stream* stream, qpdf_stream_decode_level_e decode_level);
void operator()(Pipeline*);
private:
@@ -148,8 +146,7 @@ QPDF_Stream::copy(bool shallow)
void
QPDF_Stream::registerStreamFilter(
- std::string const& filter_name,
- std::function<std::shared_ptr<QPDFStreamFilter>()> factory)
+ std::string const& filter_name, std::function<std::shared_ptr<QPDFStreamFilter>()> factory)
{
filter_factories[filter_name] = factory;
}
@@ -201,9 +198,8 @@ QPDF_Stream::getStreamJSON(
case qpdf_sj_none:
case qpdf_sj_inline:
if (p != nullptr) {
- throw std::logic_error(
- "QPDF_Stream::getStreamJSON: pipeline should "
- "only be supplied when json_data is file");
+ throw std::logic_error("QPDF_Stream::getStreamJSON: pipeline should "
+ "only be supplied when json_data is file");
}
break;
case qpdf_sj_file:
@@ -235,13 +231,8 @@ QPDF_Stream::getStreamJSON(
} else {
data_pipeline = &discard;
}
- bool succeeded = pipeStreamData(
- data_pipeline,
- &filtered,
- 0,
- decode_level,
- false,
- (attempt == 1));
+ bool succeeded =
+ pipeStreamData(data_pipeline, &filtered, 0, decode_level, false, (attempt == 1));
if ((!succeeded) || (filter && (!filtered))) {
// Try again
filter = false;
@@ -262,19 +253,16 @@ QPDF_Stream::getStreamJSON(
dict.removeKey("/DecodeParms");
}
if (json_data == qpdf_sj_file) {
- result.addDictionaryMember(
- "datafile", JSON::makeString(data_filename));
+ result.addDictionaryMember("datafile", JSON::makeString(data_filename));
if (!buf.get()) {
- throw std::logic_error(
- "QPDF_Stream: failed to get stream data in json file mode");
+ throw std::logic_error("QPDF_Stream: failed to get stream data in json file mode");
}
p->write(buf->getBuffer(), buf->getSize());
} else if (json_data == qpdf_sj_inline) {
result.addDictionaryMember(
"data", JSON::makeBlob(StreamBlobProvider(this, decode_level)));
} else {
- throw std::logic_error(
- "QPDF_Stream: unexpected value of json_data");
+ throw std::logic_error("QPDF_Stream: unexpected value of json_data");
}
}
result.addDictionaryMember("dict", dict.getJSON(json_version));
@@ -283,9 +271,7 @@ QPDF_Stream::getStreamJSON(
void
QPDF_Stream::setDescription(
- QPDF* qpdf,
- std::shared_ptr<QPDFValue::Description>& description,
- qpdf_offset_t offset)
+ QPDF* qpdf, std::shared_ptr<QPDFValue::Description>& description, qpdf_offset_t offset)
{
this->QPDFValue::setDescription(qpdf, description, offset);
setDictDescription();
@@ -295,8 +281,7 @@ void
QPDF_Stream::setDictDescription()
{
if (!this->stream_dict.hasObjectDescription()) {
- this->stream_dict.setObjectDescription(
- qpdf, getDescription() + " -> stream dictionary");
+ this->stream_dict.setObjectDescription(qpdf, getDescription() + " -> stream dictionary");
}
}
@@ -495,8 +480,7 @@ QPDF_Stream::pipeStreamData(
filter = (!((encode_flags == 0) && (decode_level == qpdf_dl_none)));
bool success = true;
if (filter) {
- filter =
- filterable(filters, specialized_compression, lossy_compression);
+ filter = filterable(filters, specialized_compression, lossy_compression);
if ((decode_level < qpdf_dl_all) && lossy_compression) {
filter = false;
}
@@ -528,47 +512,42 @@ QPDF_Stream::pipeStreamData(
std::shared_ptr<Pipeline> new_pipeline;
if (filter) {
if (encode_flags & qpdf_ef_compress) {
- new_pipeline = std::make_shared<Pl_Flate>(
- "compress stream", pipeline, Pl_Flate::a_deflate);
+ new_pipeline =
+ std::make_shared<Pl_Flate>("compress stream", pipeline, Pl_Flate::a_deflate);
to_delete.push_back(new_pipeline);
pipeline = new_pipeline.get();
}
if (encode_flags & qpdf_ef_normalize) {
normalizer = std::make_shared<ContentNormalizer>();
- new_pipeline = std::make_shared<Pl_QPDFTokenizer>(
- "normalizer", normalizer.get(), pipeline);
+ new_pipeline =
+ std::make_shared<Pl_QPDFTokenizer>("normalizer", normalizer.get(), pipeline);
to_delete.push_back(new_pipeline);
pipeline = new_pipeline.get();
}
- for (auto iter = this->token_filters.rbegin();
- iter != this->token_filters.rend();
- ++iter) {
- new_pipeline = std::make_shared<Pl_QPDFTokenizer>(
- "token filter", (*iter).get(), pipeline);
+ for (auto iter = this->token_filters.rbegin(); iter != this->token_filters.rend(); ++iter) {
+ new_pipeline =
+ std::make_shared<Pl_QPDFTokenizer>("token filter", (*iter).get(), pipeline);
to_delete.push_back(new_pipeline);
pipeline = new_pipeline.get();
}
- for (auto f_iter = filters.rbegin(); f_iter != filters.rend();
- ++f_iter) {
+ for (auto f_iter = filters.rbegin(); f_iter != filters.rend(); ++f_iter) {
auto decode_pipeline = (*f_iter)->getDecodePipeline(pipeline);
if (decode_pipeline) {
pipeline = decode_pipeline;
}
auto* flate = dynamic_cast<Pl_Flate*>(pipeline);
if (flate != nullptr) {
- flate->setWarnCallback(
- [this](char const* msg, int code) { warn(msg); });
+ flate->setWarnCallback([this](char const* msg, int code) { warn(msg); });
}
}
}
if (this->stream_data.get()) {
QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data");
- pipeline->write(
- this->stream_data->getBuffer(), this->stream_data->getSize());
+ pipeline->write(this->stream_data->getBuffer(), this->stream_data->getSize());
pipeline->finish();
} else if (this->stream_provider.get()) {
Pl_Count count("stream provider count", pipeline);
@@ -592,15 +571,13 @@ QPDF_Stream::pipeStreamData(
// This would be caused by programmer error on the
// part of a library user, not by invalid input data.
throw std::runtime_error(
- "stream data provider for " + og.unparse(' ') +
- " provided " + std::to_string(actual_length) +
- " bytes instead of expected " +
+ "stream data provider for " + og.unparse(' ') + " provided " +
+ std::to_string(actual_length) + " bytes instead of expected " +
std::to_string(desired_length) + " bytes");
}
} else if (success) {
QTC::TC("qpdf", "QPDF_Stream provider length not provided");
- this->stream_dict.replaceKey(
- "/Length", QPDFObjectHandle::newInteger(actual_length));
+ this->stream_dict.replaceKey("/Length", QPDFObjectHandle::newInteger(actual_length));
}
} else if (this->parsed_offset == 0) {
QTC::TC("qpdf", "QPDF_Stream pipe no stream data");
@@ -621,8 +598,7 @@ QPDF_Stream::pipeStreamData(
}
}
- if (filter && (!suppress_warnings) && normalizer.get() &&
- normalizer->anyBadTokens()) {
+ if (filter && (!suppress_warnings) && normalizer.get() && normalizer->anyBadTokens()) {
warn("content normalization encountered bad tokens");
if (normalizer->lastTokenWasBad()) {
QTC::TC("qpdf", "QPDF_Stream bad token at end during normalize");
@@ -662,17 +638,14 @@ QPDF_Stream::replaceStreamData(
}
void
-QPDF_Stream::addTokenFilter(
- std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter)
+QPDF_Stream::addTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter)
{
this->token_filters.push_back(token_filter);
}
void
QPDF_Stream::replaceFilterData(
- QPDFObjectHandle const& filter,
- QPDFObjectHandle const& decode_parms,
- size_t length)
+ QPDFObjectHandle const& filter, QPDFObjectHandle const& decode_parms, size_t length)
{
if (filter.isInitialized()) {
this->stream_dict.replaceKey("/Filter", filter);
@@ -685,8 +658,7 @@ QPDF_Stream::replaceFilterData(
this->stream_dict.removeKey("/Length");
} else {
this->stream_dict.replaceKey(
- "/Length",
- QPDFObjectHandle::newInteger(QIntC::to_longlong(length)));
+ "/Length", QPDFObjectHandle::newInteger(QIntC::to_longlong(length)));
}
}
diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc
index 51742bdd..386d7672 100644
--- a/libqpdf/QPDF_String.cc
+++ b/libqpdf/QPDF_String.cc
@@ -9,8 +9,7 @@
static bool
is_iso_latin1_printable(char ch)
{
- return (
- ((ch >= 32) && (ch <= 126)) || (static_cast<unsigned char>(ch) >= 160));
+ return (((ch >= 32) && (ch <= 126)) || (static_cast<unsigned char>(ch) >= 160));
}
QPDF_String::QPDF_String(std::string const& val) :
@@ -62,8 +61,7 @@ QPDF_String::getJSON(int json_version)
result = candidate;
} else if (!useHexString()) {
std::string test;
- if (QUtil::utf8_to_pdf_doc(candidate, test, '?') &&
- (test == this->val)) {
+ if (QUtil::utf8_to_pdf_doc(candidate, test, '?') && (test == this->val)) {
// This is a PDF-doc string that can be losslessly encoded
// as Unicode.
is_unicode = true;
@@ -93,8 +91,7 @@ QPDF_String::useHexString() const
continue;
} else if (ch < 0 || ch >= 24) {
++non_ascii;
- } else if (!(ch == '\n' || ch == '\r' || ch == '\t' || ch == '\b' ||
- ch == '\f')) {
+ } else if (!(ch == '\n' || ch == '\r' || ch == '\t' || ch == '\b' || ch == '\f')) {
return true;
}
}
@@ -156,12 +153,9 @@ QPDF_String::unparse(bool force_binary)
if (is_iso_latin1_printable(ch)) {
result += this->val.at(i);
} else {
- result +=
- "\\" +
+ result += "\\" +
QUtil::int_to_string_base(
- static_cast<int>(static_cast<unsigned char>(ch)),
- 8,
- 3);
+ static_cast<int>(static_cast<unsigned char>(ch)), 8, 3);
}
break;
}
diff --git a/libqpdf/QPDF_Unresolved.cc b/libqpdf/QPDF_Unresolved.cc
index bef292ce..fbf5e15f 100644
--- a/libqpdf/QPDF_Unresolved.cc
+++ b/libqpdf/QPDF_Unresolved.cc
@@ -16,23 +16,20 @@ QPDF_Unresolved::create(QPDF* qpdf, QPDFObjGen const& og)
std::shared_ptr<QPDFObject>
QPDF_Unresolved::copy(bool shallow)
{
- throw std::logic_error(
- "attempted to shallow copy an unresolved QPDFObjectHandle");
+ throw std::logic_error("attempted to shallow copy an unresolved QPDFObjectHandle");
return nullptr;
}
std::string
QPDF_Unresolved::unparse()
{
- throw std::logic_error(
- "attempted to unparse an unresolved QPDFObjectHandle");
+ throw std::logic_error("attempted to unparse an unresolved QPDFObjectHandle");
return "";
}
JSON
QPDF_Unresolved::getJSON(int json_version)
{
- throw std::logic_error(
- "attempted to get JSON from an unresolved QPDFObjectHandle");
+ throw std::logic_error("attempted to get JSON from an unresolved QPDFObjectHandle");
return JSON::makeNull();
}
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
index 78b9da20..74136060 100644
--- a/libqpdf/QPDF_encryption.cc
+++ b/libqpdf/QPDF_encryption.cc
@@ -20,9 +20,8 @@
#include <cstring>
static unsigned char const padding_string[] = {
- 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e,
- 0x56, 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68,
- 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a};
+ 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08,
+ 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a};
static unsigned int const key_bytes = 32;
@@ -129,8 +128,7 @@ QPDF::EncryptionData::setV5EncryptionParameters(
static void
pad_or_truncate_password_V4(std::string const& password, char k1[key_bytes])
{
- size_t password_bytes =
- std::min(QIntC::to_size(key_bytes), password.length());
+ size_t password_bytes = std::min(QIntC::to_size(key_bytes), password.length());
size_t pad_bytes = key_bytes - password_bytes;
memcpy(k1, password.c_str(), password_bytes);
memcpy(k1 + password_bytes, padding_string, pad_bytes);
@@ -173,8 +171,7 @@ pad_or_truncate_password_V4(std::string const& password)
static std::string
truncate_password_V5(std::string const& password)
{
- return password.substr(
- 0, std::min(static_cast<size_t>(127), password.length()));
+ return password.substr(0, std::min(static_cast<size_t>(127), password.length()));
}
static void
@@ -184,8 +181,7 @@ iterate_md5_digest(MD5& md5, MD5::Digest& digest, int iterations, int key_len)
for (int i = 0; i < iterations; ++i) {
MD5 m;
- m.encodeDataIncrementally(
- reinterpret_cast<char*>(digest), QIntC::to_size(key_len));
+ m.encodeDataIncrementally(reinterpret_cast<char*>(digest), QIntC::to_size(key_len));
m.digest(digest);
}
}
@@ -223,11 +219,7 @@ process_with_aes(
{
Pl_Buffer buffer("buffer");
Pl_AES_PDF aes(
- "aes",
- &buffer,
- encrypt,
- QUtil::unsigned_char_pointer(key),
- QIntC::to_uint(key.length()));
+ "aes", &buffer, encrypt, QUtil::unsigned_char_pointer(key), QIntC::to_uint(key.length()));
if (iv) {
aes.setIV(iv, iv_length);
} else {
@@ -371,13 +363,11 @@ QPDF::compute_data_key(
md5.encodeDataIncrementally(result.c_str(), result.length());
MD5::Digest digest;
md5.digest(digest);
- return std::string(
- reinterpret_cast<char*>(digest), std::min(result.length(), toS(16)));
+ return std::string(reinterpret_cast<char*>(digest), std::min(result.length(), toS(16)));
}
std::string
-QPDF::compute_encryption_key(
- std::string const& password, EncryptionData const& data)
+QPDF::compute_encryption_key(std::string const& password, EncryptionData const& data)
{
if (data.getV() >= 5) {
// For V >= 5, the encryption key is generated and stored in
@@ -392,8 +382,7 @@ QPDF::compute_encryption_key(
}
std::string
-QPDF::compute_encryption_key_from_password(
- std::string const& password, EncryptionData const& data)
+QPDF::compute_encryption_key_from_password(std::string const& password, EncryptionData const& data)
{
// Algorithm 3.2 from the PDF 1.7 Reference Manual
@@ -405,8 +394,7 @@ QPDF::compute_encryption_key_from_password(
// presented in its final form.
MD5 md5;
- md5.encodeDataIncrementally(
- pad_or_truncate_password_V4(password).c_str(), key_bytes);
+ md5.encodeDataIncrementally(pad_or_truncate_password_V4(password).c_str(), key_bytes);
md5.encodeDataIncrementally(data.getO().c_str(), key_bytes);
char pbytes[4];
int P = data.getP();
@@ -442,11 +430,9 @@ compute_O_rc4_key(
password = user_password;
}
MD5 md5;
- md5.encodeDataIncrementally(
- pad_or_truncate_password_V4(password).c_str(), key_bytes);
+ md5.encodeDataIncrementally(pad_or_truncate_password_V4(password).c_str(), key_bytes);
MD5::Digest digest;
- int key_len =
- std::min(QIntC::to_int(sizeof(digest)), data.getLengthBytes());
+ int key_len = std::min(QIntC::to_int(sizeof(digest)), data.getLengthBytes());
iterate_md5_digest(md5, digest, ((data.getR() >= 3) ? 50 : 0), key_len);
memcpy(key, digest, OU_key_bytes_V4);
}
@@ -477,8 +463,7 @@ compute_O_value(
}
static std::string
-compute_U_value_R2(
- std::string const& user_password, QPDF::EncryptionData const& data)
+compute_U_value_R2(std::string const& user_password, QPDF::EncryptionData const& data)
{
// Algorithm 3.4 from the PDF 1.7 Reference Manual
@@ -497,15 +482,13 @@ compute_U_value_R2(
}
static std::string
-compute_U_value_R3(
- std::string const& user_password, QPDF::EncryptionData const& data)
+compute_U_value_R3(std::string const& user_password, QPDF::EncryptionData const& data)
{
// Algorithm 3.5 from the PDF 1.7 Reference Manual
std::string k1 = QPDF::compute_encryption_key(user_password, data);
MD5 md5;
- md5.encodeDataIncrementally(
- pad_or_truncate_password_V4("").c_str(), key_bytes);
+ md5.encodeDataIncrementally(pad_or_truncate_password_V4("").c_str(), key_bytes);
md5.encodeDataIncrementally(data.getId1().c_str(), data.getId1().length());
MD5::Digest digest;
md5.digest(digest);
@@ -528,8 +511,7 @@ compute_U_value_R3(
}
static std::string
-compute_U_value(
- std::string const& user_password, QPDF::EncryptionData const& data)
+compute_U_value(std::string const& user_password, QPDF::EncryptionData const& data)
{
if (data.getR() >= 3) {
return compute_U_value_R3(user_password, data);
@@ -539,8 +521,7 @@ compute_U_value(
}
static bool
-check_user_password_V4(
- std::string const& user_password, QPDF::EncryptionData const& data)
+check_user_password_V4(std::string const& user_password, QPDF::EncryptionData const& data)
{
// Algorithm 3.6 from the PDF 1.7 Reference Manual
@@ -550,8 +531,7 @@ check_user_password_V4(
}
static bool
-check_user_password_V5(
- std::string const& user_password, QPDF::EncryptionData const& data)
+check_user_password_V5(std::string const& user_password, QPDF::EncryptionData const& data)
{
// Algorithm 3.11 from the PDF 1.7 extension level 3
@@ -562,8 +542,7 @@ check_user_password_V5(
}
static bool
-check_user_password(
- std::string const& user_password, QPDF::EncryptionData const& data)
+check_user_password(std::string const& user_password, QPDF::EncryptionData const& data)
{
if (data.getV() < 5) {
return check_user_password_V4(user_password, data);
@@ -574,9 +553,7 @@ check_user_password(
static bool
check_owner_password_V4(
- std::string& user_password,
- std::string const& owner_password,
- QPDF::EncryptionData const& data)
+ std::string& user_password, std::string const& owner_password, QPDF::EncryptionData const& data)
{
// Algorithm 3.7 from the PDF 1.7 Reference Manual
@@ -593,8 +570,7 @@ check_owner_password_V4(
data.getLengthBytes(),
(data.getR() >= 3) ? 20 : 1,
true);
- std::string new_user_password =
- std::string(reinterpret_cast<char*>(O_data), key_bytes);
+ std::string new_user_password = std::string(reinterpret_cast<char*>(O_data), key_bytes);
bool result = false;
if (check_user_password(new_user_password, data)) {
result = true;
@@ -604,8 +580,7 @@ check_owner_password_V4(
}
static bool
-check_owner_password_V5(
- std::string const& owner_password, QPDF::EncryptionData const& data)
+check_owner_password_V5(std::string const& owner_password, QPDF::EncryptionData const& data)
{
// Algorithm 3.12 from the PDF 1.7 extension level 3
@@ -618,9 +593,7 @@ check_owner_password_V5(
static bool
check_owner_password(
- std::string& user_password,
- std::string const& owner_password,
- QPDF::EncryptionData const& data)
+ std::string& user_password, std::string const& owner_password, QPDF::EncryptionData const& data)
{
if (data.getV() < 5) {
return check_owner_password_V4(user_password, owner_password, data);
@@ -630,8 +603,7 @@ check_owner_password(
}
std::string
-QPDF::recover_encryption_key_with_password(
- std::string const& password, EncryptionData const& data)
+QPDF::recover_encryption_key_with_password(std::string const& password, EncryptionData const& data)
{
// Disregard whether Perms is valid.
bool disregard;
@@ -648,12 +620,10 @@ compute_U_UE_value_V5(
{
// Algorithm 3.8 from the PDF 1.7 extension level 3
char k[16];
- QUtil::initializeWithRandomBytes(
- reinterpret_cast<unsigned char*>(k), sizeof(k));
+ QUtil::initializeWithRandomBytes(reinterpret_cast<unsigned char*>(k), sizeof(k));
std::string validation_salt(k, 8);
std::string key_salt(k + 8, 8);
- U = hash_V5(user_password, validation_salt, "", data) + validation_salt +
- key_salt;
+ U = hash_V5(user_password, validation_salt, "", data) + validation_salt + key_salt;
std::string intermediate_key = hash_V5(user_password, key_salt, "", data);
UE = process_with_aes(intermediate_key, true, encryption_key);
}
@@ -669,21 +639,17 @@ compute_O_OE_value_V5(
{
// Algorithm 3.9 from the PDF 1.7 extension level 3
char k[16];
- QUtil::initializeWithRandomBytes(
- reinterpret_cast<unsigned char*>(k), sizeof(k));
+ QUtil::initializeWithRandomBytes(reinterpret_cast<unsigned char*>(k), sizeof(k));
std::string validation_salt(k, 8);
std::string key_salt(k + 8, 8);
- O = hash_V5(owner_password, validation_salt, U, data) + validation_salt +
- key_salt;
+ O = hash_V5(owner_password, validation_salt, U, data) + validation_salt + key_salt;
std::string intermediate_key = hash_V5(owner_password, key_salt, U, data);
OE = process_with_aes(intermediate_key, true, encryption_key);
}
void
compute_Perms_value_V5_clear(
- std::string const& encryption_key,
- QPDF::EncryptionData const& data,
- unsigned char k[16])
+ std::string const& encryption_key, QPDF::EncryptionData const& data, unsigned char k[16])
{
// From algorithm 3.10 from the PDF 1.7 extension level 3
unsigned long long extended_perms =
@@ -700,16 +666,13 @@ compute_Perms_value_V5_clear(
}
static std::string
-compute_Perms_value_V5(
- std::string const& encryption_key, QPDF::EncryptionData const& data)
+compute_Perms_value_V5(std::string const& encryption_key, QPDF::EncryptionData const& data)
{
// Algorithm 3.10 from the PDF 1.7 extension level 3
unsigned char k[16];
compute_Perms_value_V5_clear(encryption_key, data, k);
return process_with_aes(
- encryption_key,
- true,
- std::string(reinterpret_cast<char*>(k), sizeof(k)));
+ encryption_key, true, std::string(reinterpret_cast<char*>(k), sizeof(k)));
}
std::string
@@ -737,14 +700,11 @@ QPDF::recover_encryption_key_with_password(
key_salt = data.getU().substr(40, 8);
encrypted_file_key = data.getUE().substr(0, 32);
}
- std::string intermediate_key =
- hash_V5(key_password, key_salt, user_data, data);
- std::string file_key =
- process_with_aes(intermediate_key, false, encrypted_file_key);
+ std::string intermediate_key = hash_V5(key_password, key_salt, user_data, data);
+ std::string file_key = process_with_aes(intermediate_key, false, encrypted_file_key);
// Decrypt Perms and check against expected value
- std::string perms_check =
- process_with_aes(file_key, false, data.getPerms(), 12);
+ std::string perms_check = process_with_aes(file_key, false, data.getPerms(), 12);
unsigned char k[16];
compute_Perms_value_V5_clear(file_key, data, k);
perms_valid = (memcmp(perms_check.c_str(), k, 12) == 0);
@@ -753,8 +713,7 @@ QPDF::recover_encryption_key_with_password(
}
QPDF::encryption_method_e
-QPDF::interpretCF(
- std::shared_ptr<EncryptionParameters> encp, QPDFObjectHandle cf)
+QPDF::interpretCF(std::shared_ptr<EncryptionParameters> encp, QPDFObjectHandle cf)
{
if (cf.isName()) {
std::string filter = cf.getName();
@@ -795,8 +754,7 @@ QPDF::initializeEncryption()
std::string id1;
QPDFObjectHandle id_obj = m->trailer.getKey("/ID");
- if ((id_obj.isArray() && (id_obj.getArrayNItems() == 2) &&
- id_obj.getArrayItem(0).isString())) {
+ if ((id_obj.isArray() && (id_obj.getArrayNItems() == 2) && id_obj.getArrayItem(0).isString())) {
id1 = id_obj.getArrayItem(0).getStringValue();
} else {
// Treating a missing ID as the empty string enables qpdf to
@@ -827,10 +785,8 @@ QPDF::initializeEncryption()
"file uses encryption SubFilters, which qpdf does not support");
}
- if (!(encryption_dict.getKey("/V").isInteger() &&
- encryption_dict.getKey("/R").isInteger() &&
- encryption_dict.getKey("/O").isString() &&
- encryption_dict.getKey("/U").isString() &&
+ if (!(encryption_dict.getKey("/V").isInteger() && encryption_dict.getKey("/R").isInteger() &&
+ encryption_dict.getKey("/O").isString() && encryption_dict.getKey("/U").isString() &&
encryption_dict.getKey("/P").isInteger())) {
throw damagedPDF(
"encryption dictionary",
@@ -846,16 +802,14 @@ QPDF::initializeEncryption()
// If supporting new encryption R/V values, remember to update
// error message inside this if statement.
- if (!(((R >= 2) && (R <= 6)) &&
- ((V == 1) || (V == 2) || (V == 4) || (V == 5)))) {
+ if (!(((R >= 2) && (R <= 6)) && ((V == 1) || (V == 2) || (V == 4) || (V == 5)))) {
throw QPDFExc(
qpdf_e_unsupported,
m->file->getName(),
"encryption dictionary",
m->file->getLastOffset(),
- "Unsupported /R or /V in encryption dictionary; R = " +
- std::to_string(R) + " (max 6), V = " + std::to_string(V) +
- " (max 5)");
+ "Unsupported /R or /V in encryption dictionary; R = " + std::to_string(R) +
+ " (max 6), V = " + std::to_string(V) + " (max 5)");
}
m->encp->encryption_V = V;
@@ -918,8 +872,7 @@ QPDF::initializeEncryption()
m->encp->encrypt_metadata = true;
if ((V >= 4) && (encryption_dict.getKey("/EncryptMetadata").isBool())) {
- m->encp->encrypt_metadata =
- encryption_dict.getKey("/EncryptMetadata").getBoolValue();
+ m->encp->encrypt_metadata = encryption_dict.getKey("/EncryptMetadata").getBoolValue();
}
if ((V == 4) || (V == 5)) {
@@ -975,23 +928,12 @@ QPDF::initializeEncryption()
}
}
- EncryptionData data(
- V,
- R,
- Length / 8,
- P,
- O,
- U,
- OE,
- UE,
- Perms,
- id1,
- m->encp->encrypt_metadata);
+ EncryptionData data(V, R, Length / 8, P, O, U, OE, UE, Perms, id1, m->encp->encrypt_metadata);
if (m->provided_password_is_hex_key) {
// ignore passwords in file
} else {
- m->encp->owner_password_matched = check_owner_password(
- m->encp->user_password, m->encp->provided_password, data);
+ m->encp->owner_password_matched =
+ check_owner_password(m->encp->user_password, m->encp->provided_password, data);
if (m->encp->owner_password_matched && (V < 5)) {
// password supplied was owner password; user_password has
// been initialized for V < 5
@@ -1000,8 +942,7 @@ QPDF::initializeEncryption()
QTC::TC("qpdf", "QPDF_encryption user matches owner V < 5");
}
} else {
- m->encp->user_password_matched =
- check_user_password(m->encp->provided_password, data);
+ m->encp->user_password_matched = check_user_password(m->encp->provided_password, data);
if (m->encp->user_password_matched) {
m->encp->user_password = m->encp->provided_password;
}
@@ -1009,10 +950,8 @@ QPDF::initializeEncryption()
if (m->encp->user_password_matched && m->encp->owner_password_matched) {
QTC::TC("qpdf", "QPDF_encryption same password", (V < 5) ? 0 : 1);
}
- if (!(m->encp->owner_password_matched ||
- m->encp->user_password_matched)) {
- throw QPDFExc(
- qpdf_e_password, m->file->getName(), "", 0, "invalid password");
+ if (!(m->encp->owner_password_matched || m->encp->user_password_matched)) {
+ throw QPDFExc(qpdf_e_password, m->file->getName(), "", 0, "invalid password");
}
}
@@ -1022,15 +961,14 @@ QPDF::initializeEncryption()
// For V < 5, the user password is encrypted with the owner
// password, and the user password is always used for
// computing the encryption key.
- m->encp->encryption_key =
- compute_encryption_key(m->encp->user_password, data);
+ m->encp->encryption_key = compute_encryption_key(m->encp->user_password, data);
} else {
// For V >= 5, either password can be used independently to
// compute the encryption key, and neither password can be
// used to recover the other.
bool perms_valid;
- m->encp->encryption_key = recover_encryption_key_with_password(
- m->encp->provided_password, data, perms_valid);
+ m->encp->encryption_key =
+ recover_encryption_key_with_password(m->encp->provided_password, data, perms_valid);
if (!perms_valid) {
warn(damagedPDF(
"encryption dictionary",
@@ -1042,13 +980,10 @@ QPDF::initializeEncryption()
std::string
QPDF::getKeyForObject(
- std::shared_ptr<EncryptionParameters> encp,
- QPDFObjGen const& og,
- bool use_aes)
+ std::shared_ptr<EncryptionParameters> encp, QPDFObjGen const& og, bool use_aes)
{
if (!encp->encrypted) {
- throw std::logic_error(
- "request for encryption key in non-encrypted PDF");
+ throw std::logic_error("request for encryption key in non-encrypted PDF");
}
if (og != encp->cached_key_og) {
@@ -1089,9 +1024,8 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og)
break;
default:
- warn(damagedPDF(
- "unknown encryption filter for strings (check /StrF in "
- "/Encrypt dictionary); strings may be decrypted improperly"));
+ warn(damagedPDF("unknown encryption filter for strings (check /StrF in "
+ "/Encrypt dictionary); strings may be decrypted improperly"));
// To avoid repeated warnings, reset cf_string. Assume
// we'd want to use AES if V == 4.
m->encp->cf_string = e_aes;
@@ -1114,8 +1048,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og)
pl.writeString(str);
pl.finish();
auto buf = bufpl.getBufferSharedPointer();
- str = std::string(
- reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
+ str = std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
} else {
QTC::TC("qpdf", "QPDF_encryption rc4 decode string");
size_t vlen = str.length();
@@ -1130,9 +1063,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og)
} catch (QPDFExc&) {
throw;
} catch (std::runtime_error& e) {
- throw damagedPDF(
- "error decrypting string for object " + og.unparse() + ": " +
- e.what());
+ throw damagedPDF("error decrypting string for object " + og.unparse() + ": " + e.what());
}
}
@@ -1161,10 +1092,8 @@ QPDF::decryptStream(
if (stream_dict.getKey("/Filter").isOrHasName("/Crypt")) {
if (stream_dict.getKey("/DecodeParms").isDictionary()) {
- QPDFObjectHandle decode_parms =
- stream_dict.getKey("/DecodeParms");
- if (decode_parms.isDictionaryOfType(
- "/CryptFilterDecodeParms")) {
+ QPDFObjectHandle decode_parms = stream_dict.getKey("/DecodeParms");
+ if (decode_parms.isDictionaryOfType("/CryptFilterDecodeParms")) {
QTC::TC("qpdf", "QPDF_encryption stream crypt filter");
method = interpretCF(encp, decode_parms.getKey("/Name"));
method_source = "stream's Crypt decode parameters";
@@ -1177,13 +1106,11 @@ QPDF::decryptStream(
if (filter.getArrayNItems() == decode.getArrayNItems()) {
for (int i = 0; i < filter.getArrayNItems(); ++i) {
if (filter.getArrayItem(i).isNameAndEquals("/Crypt")) {
- QPDFObjectHandle crypt_params =
- decode.getArrayItem(i);
+ QPDFObjectHandle crypt_params = decode.getArrayItem(i);
if (crypt_params.isDictionary() &&
crypt_params.getKey("/Name").isName()) {
QTC::TC("qpdf", "QPDF_encrypt crypt array");
- method = interpretCF(
- encp, crypt_params.getKey("/Name"));
+ method = interpretCF(encp, crypt_params.getKey("/Name"));
method_source = "stream's Crypt "
"decode parameters (array)";
}
@@ -1225,8 +1152,8 @@ QPDF::decryptStream(
file->getName(),
"",
file->getLastOffset(),
- "unknown encryption filter for streams (check " +
- method_source + "); streams may be decrypted improperly"));
+ "unknown encryption filter for streams (check " + method_source +
+ "); streams may be decrypted improperly"));
// To avoid repeated warnings, reset cf_stream. Assume
// we'd want to use AES if V == 4.
encp->cf_stream = e_aes;
@@ -1270,11 +1197,9 @@ QPDF::compute_encryption_O_U(
std::string& U)
{
if (V >= 5) {
- throw std::logic_error(
- "compute_encryption_O_U called for file with V >= 5");
+ throw std::logic_error("compute_encryption_O_U called for file with V >= 5");
}
- EncryptionData data(
- V, R, key_len, P, "", "", "", "", "", id1, encrypt_metadata);
+ EncryptionData data(V, R, key_len, P, "", "", "", "", "", id1, encrypt_metadata);
data.setO(compute_O_value(user_password, owner_password, data));
O = data.getO();
data.setU(compute_U_value(user_password, data));
@@ -1298,8 +1223,7 @@ QPDF::compute_encryption_parameters_V5(
std::string& UE,
std::string& Perms)
{
- EncryptionData data(
- V, R, key_len, P, "", "", "", "", "", id1, encrypt_metadata);
+ EncryptionData data(V, R, key_len, P, "", "", "", "", "", id1, encrypt_metadata);
unsigned char k[key_bytes];
QUtil::initializeWithRandomBytes(k, key_bytes);
encryption_key = std::string(reinterpret_cast<char*>(k), key_bytes);
diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc
index 3a05ae5c..66d4b314 100644
--- a/libqpdf/QPDF_json.cc
+++ b/libqpdf/QPDF_json.cc
@@ -203,8 +203,7 @@ QPDF::test_json_validators()
}
static std::function<void(Pipeline*)>
-provide_data(
- std::shared_ptr<InputSource> is, qpdf_offset_t start, qpdf_offset_t end)
+provide_data(std::shared_ptr<InputSource> is, qpdf_offset_t start, qpdf_offset_t end)
{
return [is, start, end](Pipeline* p) {
Pl_Base64 decode("base64-decode", p, Pl_Base64::a_decode);
@@ -227,13 +226,12 @@ provide_data(
class QPDF::JSONReactor: public JSON::Reactor
{
public:
- JSONReactor(
- QPDF& pdf, std::shared_ptr<InputSource> is, bool must_be_complete) :
+ JSONReactor(QPDF& pdf, std::shared_ptr<InputSource> is, bool must_be_complete) :
pdf(pdf),
is(is),
must_be_complete(must_be_complete),
- descr(std::make_shared<QPDFValue::Description>(QPDFValue::JSON_Descr(
- std::make_shared<std::string>(is->getName()), "")))
+ descr(std::make_shared<QPDFValue::Description>(
+ QPDFValue::JSON_Descr(std::make_shared<std::string>(is->getName()), "")))
{
for (auto& oc: pdf.m->obj_cache) {
if (oc.second.object->getTypeCode() == ::ot_reserved) {
@@ -270,10 +268,8 @@ class QPDF::JSONReactor: public JSON::Reactor
void setObjectDescription(QPDFObjectHandle& oh, JSON const& value);
QPDFObjectHandle makeObject(JSON const& value);
void error(qpdf_offset_t offset, std::string const& message);
- void replaceObject(
- QPDFObjectHandle to_replace,
- QPDFObjectHandle replacement,
- JSON const& value);
+ void
+ replaceObject(QPDFObjectHandle to_replace, QPDFObjectHandle replacement, JSON const& value);
QPDF& pdf;
std::shared_ptr<InputSource> is;
@@ -380,9 +376,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value)
}
} else if (saw_value == saw_stream) {
QTC::TC("qpdf", "QPDF_json value stream both or neither");
- error(
- value.getStart(),
- "object must have exactly one of \"value\" or \"stream\"");
+ error(value.getStart(), "object must have exactly one of \"value\" or \"stream\"");
}
object_stack.clear();
this->cur_object = "";
@@ -424,8 +418,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value)
// treat as nulls. It's tempting to make this an error, but that would
// be wrong since valid input files may have these.
for (auto& oc: pdf.m->obj_cache) {
- if (oc.second.object->getTypeCode() == ::ot_reserved &&
- reserved.count(oc.first) == 0) {
+ if (oc.second.object->getTypeCode() == ::ot_reserved && reserved.count(oc.first) == 0) {
QTC::TC("qpdf", "QPDF_json non-trivial null reserved");
pdf.updateCache(oc.first, QPDF_Null::create(), -1, -1);
}
@@ -435,9 +428,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value)
void
QPDF::JSONReactor::replaceObject(
- QPDFObjectHandle to_replace,
- QPDFObjectHandle replacement,
- JSON const& value)
+ QPDFObjectHandle to_replace, QPDFObjectHandle replacement, JSON const& value)
{
auto og = to_replace.getObjGen();
this->pdf.replaceObject(og, replacement);
@@ -453,8 +444,7 @@ QPDF::JSONReactor::topLevelScalar()
}
void
-QPDF::JSONReactor::nestedState(
- std::string const& key, JSON const& value, state_e next)
+QPDF::JSONReactor::nestedState(std::string const& key, JSON const& value, state_e next)
{
// Use this method when the next state is for processing a nested
// dictionary.
@@ -528,9 +518,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
}
} else {
QTC::TC("qpdf", "QPDF_json bad pushedinheritedpageresources");
- error(
- value.getStart(),
- "pushedinheritedpageresources must be a boolean");
+ error(value.getStart(), "pushedinheritedpageresources must be a boolean");
}
} else if (key == "calledgetallpages") {
bool v;
@@ -562,9 +550,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
nestedState(key, value, st_object_top);
} else {
QTC::TC("qpdf", "QPDF_json bad object key");
- error(
- value.getStart(),
- "object key should be \"trailer\" or \"obj:n n R\"");
+ error(value.getStart(), "object key should be \"trailer\" or \"obj:n n R\"");
next_state = st_ignore;
parse_error = true;
}
@@ -653,17 +639,13 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
if (end < start) {
throw std::logic_error("QPDF_json: JSON string length < 0");
}
- tos.replaceStreamData(
- provide_data(is, start, end), uninitialized, uninitialized);
+ tos.replaceStreamData(provide_data(is, start, end), uninitialized, uninitialized);
}
} else if (key == "datafile") {
this->saw_datafile = true;
std::string filename;
if (value.getString(filename)) {
- tos.replaceStreamData(
- QUtil::file_provider(filename),
- uninitialized,
- uninitialized);
+ tos.replaceStreamData(QUtil::file_provider(filename), uninitialized, uninitialized);
} else {
error(
value.getStart(),
@@ -684,8 +666,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value)
dict.replaceKey(key, makeObject(value));
}
} else {
- throw std::logic_error(
- "QPDF_json: unknown state " + std::to_string(state));
+ throw std::logic_error("QPDF_json: unknown state " + std::to_string(state));
}
return true;
}
@@ -746,8 +727,7 @@ QPDF::JSONReactor::makeObject(JSON const& value)
result = QPDFObjectHandle::newBool(bool_v);
} else if (value.getNumber(str_v)) {
if (QUtil::is_long_long(str_v.c_str())) {
- result = QPDFObjectHandle::newInteger(
- QUtil::string_to_ll(str_v.c_str()));
+ result = QPDFObjectHandle::newInteger(QUtil::string_to_ll(str_v.c_str()));
} else {
result = QPDFObjectHandle::newReal(str_v);
}
@@ -770,8 +750,7 @@ QPDF::JSONReactor::makeObject(JSON const& value)
}
}
if (!result.isInitialized()) {
- throw std::logic_error(
- "JSONReactor::makeObject didn't initialize the object");
+ throw std::logic_error("JSONReactor::makeObject didn't initialize the object");
}
if (!result.hasObjectDescription()) {
@@ -842,9 +821,7 @@ QPDF::writeJSONStream(
}
auto j = JSON::makeDictionary();
j.addDictionaryMember(
- "stream",
- obj.getStreamJSON(
- version, json_stream_data, decode_level, stream_p, filename));
+ "stream", obj.getStreamJSON(version, json_stream_data, decode_level, stream_p, filename));
JSON::writeDictionaryItem(p, first, key, j, 3);
if (f) {
@@ -856,11 +833,7 @@ QPDF::writeJSONStream(
void
QPDF::writeJSONObject(
- int version,
- Pipeline* p,
- bool& first,
- std::string const& key,
- QPDFObjectHandle& obj)
+ int version, Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj)
{
auto j = JSON::makeDictionary();
j.addDictionaryMember("value", obj.getJSON(version, true));
@@ -877,15 +850,7 @@ QPDF::writeJSON(
std::set<std::string> wanted_objects)
{
bool first = true;
- writeJSON(
- version,
- p,
- true,
- first,
- decode_level,
- json_stream_data,
- file_prefix,
- wanted_objects);
+ writeJSON(version, p, true, first, decode_level, json_stream_data, file_prefix, wanted_objects);
}
void
@@ -905,8 +870,7 @@ QPDF::writeJSON(
int const depth_qpdf_inner = 3;
if (version != 2) {
- throw std::runtime_error(
- "QPDF::writeJSON: only version 2 is supported");
+ throw std::runtime_error("QPDF::writeJSON: only version 2 is supported");
}
bool first = true;
if (complete) {
@@ -921,17 +885,9 @@ QPDF::writeJSON(
bool first_qpdf_inner = true;
JSON::writeDictionaryOpen(p, first_qpdf_inner, depth_qpdf);
JSON::writeDictionaryItem(
- p,
- first_qpdf_inner,
- "jsonversion",
- JSON::makeInt(version),
- depth_qpdf_inner);
+ p, first_qpdf_inner, "jsonversion", JSON::makeInt(version), depth_qpdf_inner);
JSON::writeDictionaryItem(
- p,
- first_qpdf_inner,
- "pdfversion",
- JSON::makeString(getPDFVersion()),
- depth_qpdf_inner);
+ p, first_qpdf_inner, "pdfversion", JSON::makeString(getPDFVersion()), depth_qpdf_inner);
JSON::writeDictionaryItem(
p,
first_qpdf_inner,
diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc
index d8742428..65357b9a 100644
--- a/libqpdf/QPDF_linearization.cc
+++ b/libqpdf/QPDF_linearization.cc
@@ -19,11 +19,7 @@
template <class T, class int_type>
static void
load_vector_int(
- BitStream& bit_stream,
- int nitems,
- std::vector<T>& vec,
- int bits_wanted,
- int_type T::*field)
+ BitStream& bit_stream, int nitems, std::vector<T>& vec, int bits_wanted, int_type T::*field)
{
bool append = vec.empty();
// nitems times, read bits_wanted from the given bit stream,
@@ -57,8 +53,7 @@ load_vector_vector(
// into the vec2 vector field of the ith item of vec1.
for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1) {
for (int i2 = 0; i2 < vec1.at(i1).*nitems2; ++i2) {
- (vec1.at(i1).*vec2)
- .push_back(bit_stream.getBitsInt(QIntC::to_size(bits_wanted)));
+ (vec1.at(i1).*vec2).push_back(bit_stream.getBitsInt(QIntC::to_size(bits_wanted)));
}
}
bit_stream.skipToNextByte();
@@ -80,8 +75,7 @@ QPDF::checkLinearization()
result = checkLinearizationInternal();
} catch (std::runtime_error& e) {
linearizationWarning(
- "error encountered while checking linearization data: " +
- std::string(e.what()));
+ "error encountered while checking linearization data: " + std::string(e.what()));
}
return result;
}
@@ -127,8 +121,7 @@ QPDF::isLinearized()
}
QPDFTokenizer::Token t1 = readToken(m->file);
- if (t1.isInteger() && readToken(m->file).isInteger() &&
- readToken(m->file).isWord("obj") &&
+ if (t1.isInteger() && readToken(m->file).isInteger() && readToken(m->file).isWord("obj") &&
(readToken(m->file).getType() == QPDFTokenizer::tt_dict_open)) {
lindict_obj = toI(QUtil::string_to_ll(t1.getValue().c_str()));
}
@@ -184,8 +177,8 @@ QPDF::readLinearizationData()
QPDFObjectHandle T = m->lindict.getKey("/T");
QPDFObjectHandle P = m->lindict.getKey("/P");
- if (!(H.isArray() && O.isInteger() && E.isInteger() && N.isInteger() &&
- T.isInteger() && (P.isInteger() || P.isNull()))) {
+ if (!(H.isArray() && O.isInteger() && E.isInteger() && N.isInteger() && T.isInteger() &&
+ (P.isInteger() || P.isNull()))) {
throw damagedPDF(
"linearization dictionary",
"some keys in linearization dictionary are of the wrong type");
@@ -194,8 +187,7 @@ QPDF::readLinearizationData()
// Hint table array: offset length [ offset length ]
size_t n_H_items = toS(H.getArrayNItems());
if (!((n_H_items == 2) || (n_H_items == 4))) {
- throw damagedPDF(
- "linearization dictionary", "H has the wrong number of items");
+ throw damagedPDF("linearization dictionary", "H has the wrong number of items");
}
std::vector<int> H_items;
@@ -204,9 +196,7 @@ QPDF::readLinearizationData()
if (oh.isInteger()) {
H_items.push_back(oh.getIntValueAsInt());
} else {
- throw damagedPDF(
- "linearization dictionary",
- "some H items are of the wrong type");
+ throw damagedPDF("linearization dictionary", "some H items are of the wrong type");
}
}
@@ -238,8 +228,7 @@ QPDF::readLinearizationData()
// initialized from N, to pre-allocate memory, so make sure it's
// accurate and bail right now if it's not.
if (N.getIntValue() != static_cast<long long>(getAllPages().size())) {
- throw damagedPDF(
- "linearization hint table", "/N does not match number of pages");
+ throw damagedPDF("linearization hint table", "/N does not match number of pages");
}
// file_size initialized by isLinearized()
@@ -282,21 +271,16 @@ QPDF::readLinearizationData()
int HSi = HS.getIntValueAsInt();
if ((HSi < 0) || (toS(HSi) >= h_size)) {
- throw damagedPDF(
- "linearization hint table",
- "/S (shared object) offset is out of bounds");
+ throw damagedPDF("linearization hint table", "/S (shared object) offset is out of bounds");
}
readHSharedObject(BitStream(h_buf + HSi, h_size - toS(HSi)));
if (HO.isInteger()) {
int HOi = HO.getIntValueAsInt();
if ((HOi < 0) || (toS(HOi) >= h_size)) {
- throw damagedPDF(
- "linearization hint table",
- "/O (outline) offset is out of bounds");
+ throw damagedPDF("linearization hint table", "/O (outline) offset is out of bounds");
}
- readHGeneric(
- BitStream(h_buf + HOi, h_size - toS(HOi)), m->outline_hints);
+ readHGeneric(BitStream(h_buf + HOi, h_size - toS(HOi)), m->outline_hints);
}
}
@@ -304,19 +288,13 @@ QPDFObjectHandle
QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length)
{
QPDFObjGen og;
- QPDFObjectHandle H = readObjectAtOffset(
- false,
- offset,
- "linearization hint stream",
- QPDFObjGen(0, 0),
- og,
- false);
+ QPDFObjectHandle H =
+ readObjectAtOffset(false, offset, "linearization hint stream", QPDFObjGen(0, 0), og, false);
ObjCache& oc = m->obj_cache[og];
qpdf_offset_t min_end_offset = oc.end_before_space;
qpdf_offset_t max_end_offset = oc.end_after_space;
if (!H.isStream()) {
- throw damagedPDF(
- "linearization dictionary", "hint table is not a stream");
+ throw damagedPDF("linearization dictionary", "hint table is not a stream");
}
QPDFObjectHandle Hdict = H.getDict();
@@ -341,10 +319,8 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length)
if ((computed_end < min_end_offset) || (computed_end > max_end_offset)) {
linearizationWarning(
"expected = " + std::to_string(computed_end) +
- "; actual = " + std::to_string(min_end_offset) + ".." +
- std::to_string(max_end_offset));
- throw damagedPDF(
- "linearization dictionary", "hint table length mismatch");
+ "; actual = " + std::to_string(min_end_offset) + ".." + std::to_string(max_end_offset));
+ throw damagedPDF("linearization dictionary", "hint table length mismatch");
}
H.pipeStreamData(&pl, 0, qpdf_dl_specialized);
return Hdict;
@@ -375,24 +351,11 @@ QPDF::readHPageOffset(BitStream h)
std::vector<HPageOffsetEntry>& entries = t.entries;
entries.clear();
int nitems = m->linp.npages;
+ load_vector_int(h, nitems, entries, t.nbits_delta_nobjects, &HPageOffsetEntry::delta_nobjects);
load_vector_int(
- h,
- nitems,
- entries,
- t.nbits_delta_nobjects,
- &HPageOffsetEntry::delta_nobjects);
- load_vector_int(
- h,
- nitems,
- entries,
- t.nbits_delta_page_length,
- &HPageOffsetEntry::delta_page_length);
+ h, nitems, entries, t.nbits_delta_page_length, &HPageOffsetEntry::delta_page_length);
load_vector_int(
- h,
- nitems,
- entries,
- t.nbits_nshared_objects,
- &HPageOffsetEntry::nshared_objects);
+ h, nitems, entries, t.nbits_nshared_objects, &HPageOffsetEntry::nshared_objects);
load_vector_vector(
h,
nitems,
@@ -408,17 +371,9 @@ QPDF::readHPageOffset(BitStream h)
t.nbits_shared_numerator,
&HPageOffsetEntry::shared_numerators);
load_vector_int(
- h,
- nitems,
- entries,
- t.nbits_delta_content_offset,
- &HPageOffsetEntry::delta_content_offset);
+ h, nitems, entries, t.nbits_delta_content_offset, &HPageOffsetEntry::delta_content_offset);
load_vector_int(
- h,
- nitems,
- entries,
- t.nbits_delta_content_length,
- &HPageOffsetEntry::delta_content_length);
+ h, nitems, entries, t.nbits_delta_content_length, &HPageOffsetEntry::delta_content_length);
}
void
@@ -443,13 +398,8 @@ QPDF::readHSharedObject(BitStream h)
entries.clear();
int nitems = t.nshared_total;
load_vector_int(
- h,
- nitems,
- entries,
- t.nbits_delta_group_length,
- &HSharedObjectEntry::delta_group_length);
- load_vector_int(
- h, nitems, entries, 1, &HSharedObjectEntry::signature_present);
+ h, nitems, entries, t.nbits_delta_group_length, &HSharedObjectEntry::delta_group_length);
+ load_vector_int(h, nitems, entries, 1, &HSharedObjectEntry::signature_present);
for (size_t i = 0; i < toS(nitems); ++i) {
if (entries.at(i).signature_present) {
// Skip 128-bit MD5 hash. These are not supported by
@@ -460,12 +410,7 @@ QPDF::readHSharedObject(BitStream h)
}
}
}
- load_vector_int(
- h,
- nitems,
- entries,
- t.nbits_nobjects,
- &HSharedObjectEntry::nobjects_minus_one);
+ load_vector_int(h, nitems, entries, t.nbits_nobjects, &HSharedObjectEntry::nobjects_minus_one);
}
void
@@ -508,8 +453,7 @@ QPDF::checkLinearizationInternal()
QPDFObjGen og(page.getObjGen());
if (m->xref_table[og].getType() == 2) {
linearizationWarning(
- "page dictionary for page " + std::to_string(i) +
- " is compressed");
+ "page dictionary for page " + std::to_string(i) + " is compressed");
}
}
@@ -541,9 +485,8 @@ QPDF::checkLinearizationInternal()
// are in use.
if (m->uncompressed_after_compressed) {
- linearizationWarning(
- "linearized file contains an uncompressed object"
- " after a compressed one in a cross-reference stream");
+ linearizationWarning("linearized file contains an uncompressed object"
+ " after a compressed one in a cross-reference stream");
}
// Further checking requires optimization and order calculation.
@@ -593,9 +536,8 @@ QPDF::checkLinearizationInternal()
if ((p.first_page_end < min_E) || (p.first_page_end > max_E)) {
QTC::TC("qpdf", "QPDF warn /E mismatch");
linearizationWarning(
- "end of first page section (/E) mismatch: /E = " +
- std::to_string(p.first_page_end) + "; computed = " +
- std::to_string(min_E) + ".." + std::to_string(max_E));
+ "end of first page section (/E) mismatch: /E = " + std::to_string(p.first_page_end) +
+ "; computed = " + std::to_string(min_E) + ".." + std::to_string(max_E));
}
// Check hint tables
@@ -637,21 +579,18 @@ QPDF::getLinearizationOffset(QPDFObjGen const& og)
case 2:
// For compressed objects, return the offset of the object
// stream that contains them.
- result =
- getLinearizationOffset(QPDFObjGen(entry.getObjStreamNumber(), 0));
+ result = getLinearizationOffset(QPDFObjGen(entry.getObjStreamNumber(), 0));
break;
default:
- stopOnError(
- "getLinearizationOffset called for xref entry not of type 1 or 2");
+ stopOnError("getLinearizationOffset called for xref entry not of type 1 or 2");
break;
}
return result;
}
QPDFObjectHandle
-QPDF::getUncompressedObject(
- QPDFObjectHandle& obj, std::map<int, int> const& object_stream_data)
+QPDF::getUncompressedObject(QPDFObjectHandle& obj, std::map<int, int> const& object_stream_data)
{
if (obj.isNull() || (object_stream_data.count(obj.getObjectID()) == 0)) {
return obj;
@@ -669,15 +608,13 @@ QPDF::lengthNextN(int first_object, int n)
QPDFObjGen og(first_object + i, 0);
if (m->xref_table.count(og) == 0) {
linearizationWarning(
- "no xref table entry for " + std::to_string(first_object + i) +
- " 0");
+ "no xref table entry for " + std::to_string(first_object + i) + " 0");
} else {
if (m->obj_cache.count(og) == 0) {
stopOnError("found unknown object while"
" calculating length for linearization data");
}
- length += toI(
- m->obj_cache[og].end_after_space - getLinearizationOffset(og));
+ length += toI(m->obj_cache[og].end_after_space - getLinearizationOffset(og));
}
}
return length;
@@ -685,8 +622,7 @@ QPDF::lengthNextN(int first_object, int n)
void
QPDF::checkHPageOffset(
- std::vector<QPDFObjectHandle> const& pages,
- std::map<int, int>& shared_idx_to_obj)
+ std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& shared_idx_to_obj)
{
// Implementation note 126 says Acrobat always sets
// delta_content_offset and delta_content_length in the page
@@ -706,8 +642,7 @@ QPDF::checkHPageOffset(
// even when they are private.
int npages = toI(pages.size());
- qpdf_offset_t table_offset =
- adjusted_offset(m->page_offset_hints.first_page_offset);
+ qpdf_offset_t table_offset = adjusted_offset(m->page_offset_hints.first_page_offset);
QPDFObjGen first_page_og(pages.at(0).getObjGen());
if (m->xref_table.count(first_page_og) == 0) {
stopOnError("supposed first page object is not known");
@@ -731,23 +666,20 @@ QPDF::checkHPageOffset(
if (h_nobjects != ce.nobjects) {
// This happens with pdlin when there are thumbnails.
linearizationWarning(
- "object count mismatch for page " + std::to_string(pageno) +
- ": hint table = " + std::to_string(h_nobjects) +
- "; computed = " + std::to_string(ce.nobjects));
+ "object count mismatch for page " + std::to_string(pageno) + ": hint table = " +
+ std::to_string(h_nobjects) + "; computed = " + std::to_string(ce.nobjects));
}
// Use value for number of objects in hint table rather than
// computed value if there is a discrepancy.
int length = lengthNextN(first_object, h_nobjects);
- int h_length =
- toI(he.delta_page_length + m->page_offset_hints.min_page_length);
+ int h_length = toI(he.delta_page_length + m->page_offset_hints.min_page_length);
if (length != h_length) {
// This condition almost certainly indicates a bad hint
// table or a bug in this code.
linearizationWarning(
- "page length mismatch for page " + std::to_string(pageno) +
- ": hint table = " + std::to_string(h_length) +
- "; computed length = " + std::to_string(length) +
+ "page length mismatch for page " + std::to_string(pageno) + ": hint table = " +
+ std::to_string(h_length) + "; computed length = " + std::to_string(length) +
" (offset = " + std::to_string(offset) + ")");
}
@@ -785,8 +717,7 @@ QPDF::checkHPageOffset(
if (!computed_shared.count(iter)) {
// pdlin puts thumbnails here even though it shouldn't
linearizationWarning(
- "page " + std::to_string(pageno) + ": shared object " +
- std::to_string(iter) +
+ "page " + std::to_string(pageno) + ": shared object " + std::to_string(iter) +
": in hint table but not computed list");
}
}
@@ -797,8 +728,7 @@ QPDF::checkHPageOffset(
// built-in fonts and procsets here, at least in some
// cases.
linearizationWarning(
- ("page " + std::to_string(pageno) + ": shared object " +
- std::to_string(iter) +
+ ("page " + std::to_string(pageno) + ": shared object " + std::to_string(iter) +
": in computed list but not hint table"));
}
}
@@ -806,8 +736,7 @@ QPDF::checkHPageOffset(
}
void
-QPDF::checkHSharedObject(
- std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& idx_to_obj)
+QPDF::checkHSharedObject(std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& idx_to_obj)
{
// Implementation note 125 says shared object groups always
// contain only one object. Implementation note 128 says that
@@ -859,13 +788,11 @@ QPDF::checkHSharedObject(
stopOnError("unknown object in shared object hint table");
}
qpdf_offset_t offset = getLinearizationOffset(og);
- qpdf_offset_t h_offset =
- adjusted_offset(so.first_shared_offset);
+ qpdf_offset_t h_offset = adjusted_offset(so.first_shared_offset);
if (offset != h_offset) {
linearizationWarning(
"first shared object offset mismatch: hint table = " +
- std::to_string(h_offset) +
- "; computed = " + std::to_string(offset));
+ std::to_string(h_offset) + "; computed = " + std::to_string(offset));
}
}
@@ -876,10 +803,8 @@ QPDF::checkHSharedObject(
int h_length = so.min_group_length + se.delta_group_length;
if (length != h_length) {
linearizationWarning(
- "shared object " + std::to_string(i) +
- " length mismatch: hint table = " +
- std::to_string(h_length) +
- "; computed = " + std::to_string(length));
+ "shared object " + std::to_string(i) + " length mismatch: hint table = " +
+ std::to_string(h_length) + "; computed = " + std::to_string(length));
}
cur_object += nobjects;
}
@@ -909,8 +834,7 @@ QPDF::checkHOutlines()
// This case is not exercised in test suite since not
// permitted by the spec, but if this does occur, the
// code below would fail.
- linearizationWarning(
- "/Outlines key of root dictionary is not indirect");
+ linearizationWarning("/Outlines key of root dictionary is not indirect");
return;
}
QPDFObjGen og(outlines.getObjGen());
@@ -920,20 +844,17 @@ QPDF::checkHOutlines()
qpdf_offset_t offset = getLinearizationOffset(og);
ObjUser ou(ObjUser::ou_root_key, "/Outlines");
int length = toI(maxEnd(ou) - offset);
- qpdf_offset_t table_offset =
- adjusted_offset(m->outline_hints.first_object_offset);
+ qpdf_offset_t table_offset = adjusted_offset(m->outline_hints.first_object_offset);
if (offset != table_offset) {
linearizationWarning(
"incorrect offset in outlines table: hint table = " +
- std::to_string(table_offset) +
- "; computed = " + std::to_string(offset));
+ std::to_string(table_offset) + "; computed = " + std::to_string(offset));
}
int table_length = m->outline_hints.group_length;
if (length != table_length) {
linearizationWarning(
"incorrect length in outlines table: hint table = " +
- std::to_string(table_length) +
- "; computed = " + std::to_string(length));
+ std::to_string(table_length) + "; computed = " + std::to_string(length));
}
} else {
linearizationWarning("incorrect first object number in outline "
@@ -962,12 +883,10 @@ QPDF::dumpLinearizationDataInternal()
*m->log->getInfo() << m->file->getName() << ": linearization data:\n\n";
*m->log->getInfo() << "file_size: " << m->linp.file_size << "\n"
- << "first_page_object: " << m->linp.first_page_object
- << "\n"
+ << "first_page_object: " << m->linp.first_page_object << "\n"
<< "first_page_end: " << m->linp.first_page_end << "\n"
<< "npages: " << m->linp.npages << "\n"
- << "xref_zero_offset: " << m->linp.xref_zero_offset
- << "\n"
+ << "xref_zero_offset: " << m->linp.xref_zero_offset << "\n"
<< "first_page: " << m->linp.first_page << "\n"
<< "H_offset: " << m->linp.H_offset << "\n"
<< "H_length: " << m->linp.H_length << "\n"
@@ -1000,41 +919,37 @@ void
QPDF::dumpHPageOffset()
{
HPageOffset& t = m->page_offset_hints;
- *m->log->getInfo()
- << "min_nobjects: " << t.min_nobjects << "\n"
- << "first_page_offset: " << adjusted_offset(t.first_page_offset) << "\n"
- << "nbits_delta_nobjects: " << t.nbits_delta_nobjects << "\n"
- << "min_page_length: " << t.min_page_length << "\n"
- << "nbits_delta_page_length: " << t.nbits_delta_page_length << "\n"
- << "min_content_offset: " << t.min_content_offset << "\n"
- << "nbits_delta_content_offset: " << t.nbits_delta_content_offset
- << "\n"
- << "min_content_length: " << t.min_content_length << "\n"
- << "nbits_delta_content_length: " << t.nbits_delta_content_length
- << "\n"
- << "nbits_nshared_objects: " << t.nbits_nshared_objects << "\n"
- << "nbits_shared_identifier: " << t.nbits_shared_identifier << "\n"
- << "nbits_shared_numerator: " << t.nbits_shared_numerator << "\n"
- << "shared_denominator: " << t.shared_denominator << "\n";
+ *m->log->getInfo() << "min_nobjects: " << t.min_nobjects << "\n"
+ << "first_page_offset: " << adjusted_offset(t.first_page_offset) << "\n"
+ << "nbits_delta_nobjects: " << t.nbits_delta_nobjects << "\n"
+ << "min_page_length: " << t.min_page_length << "\n"
+ << "nbits_delta_page_length: " << t.nbits_delta_page_length << "\n"
+ << "min_content_offset: " << t.min_content_offset << "\n"
+ << "nbits_delta_content_offset: " << t.nbits_delta_content_offset << "\n"
+ << "min_content_length: " << t.min_content_length << "\n"
+ << "nbits_delta_content_length: " << t.nbits_delta_content_length << "\n"
+ << "nbits_nshared_objects: " << t.nbits_nshared_objects << "\n"
+ << "nbits_shared_identifier: " << t.nbits_shared_identifier << "\n"
+ << "nbits_shared_numerator: " << t.nbits_shared_numerator << "\n"
+ << "shared_denominator: " << t.shared_denominator << "\n";
for (size_t i1 = 0; i1 < toS(m->linp.npages); ++i1) {
HPageOffsetEntry& pe = t.entries.at(i1);
- *m->log->getInfo()
- << "Page " << i1 << ":\n"
- << " nobjects: " << pe.delta_nobjects + t.min_nobjects << "\n"
- << " length: " << pe.delta_page_length + t.min_page_length
- << "\n"
- // content offset is relative to page, not file
- << " content_offset: "
- << pe.delta_content_offset + t.min_content_offset << "\n"
- << " content_length: "
- << pe.delta_content_length + t.min_content_length << "\n"
- << " nshared_objects: " << pe.nshared_objects << "\n";
+ *m->log->getInfo() << "Page " << i1 << ":\n"
+ << " nobjects: " << pe.delta_nobjects + t.min_nobjects << "\n"
+ << " length: " << pe.delta_page_length + t.min_page_length
+ << "\n"
+ // content offset is relative to page, not file
+ << " content_offset: " << pe.delta_content_offset + t.min_content_offset
+ << "\n"
+ << " content_length: " << pe.delta_content_length + t.min_content_length
+ << "\n"
+ << " nshared_objects: " << pe.nshared_objects << "\n";
for (size_t i2 = 0; i2 < toS(pe.nshared_objects); ++i2) {
- *m->log->getInfo() << " identifier " << i2 << ": "
- << pe.shared_identifiers.at(i2) << "\n";
- *m->log->getInfo() << " numerator " << i2 << ": "
- << pe.shared_numerators.at(i2) << "\n";
+ *m->log->getInfo() << " identifier " << i2 << ": " << pe.shared_identifiers.at(i2)
+ << "\n";
+ *m->log->getInfo() << " numerator " << i2 << ": " << pe.shared_numerators.at(i2)
+ << "\n";
}
}
}
@@ -1044,20 +959,17 @@ QPDF::dumpHSharedObject()
{
HSharedObject& t = m->shared_object_hints;
*m->log->getInfo() << "first_shared_obj: " << t.first_shared_obj << "\n"
- << "first_shared_offset: "
- << adjusted_offset(t.first_shared_offset) << "\n"
+ << "first_shared_offset: " << adjusted_offset(t.first_shared_offset) << "\n"
<< "nshared_first_page: " << t.nshared_first_page << "\n"
<< "nshared_total: " << t.nshared_total << "\n"
<< "nbits_nobjects: " << t.nbits_nobjects << "\n"
<< "min_group_length: " << t.min_group_length << "\n"
- << "nbits_delta_group_length: "
- << t.nbits_delta_group_length << "\n";
+ << "nbits_delta_group_length: " << t.nbits_delta_group_length << "\n";
for (size_t i = 0; i < toS(t.nshared_total); ++i) {
HSharedObjectEntry& se = t.entries.at(i);
*m->log->getInfo() << "Shared Object " << i << ":\n"
- << " group length: "
- << se.delta_group_length + t.min_group_length
+ << " group length: " << se.delta_group_length + t.min_group_length
<< "\n";
// PDF spec says signature present nobjects_minus_one are
// always 0, so print them only if they have a non-zero value.
@@ -1065,8 +977,7 @@ QPDF::dumpHSharedObject()
*m->log->getInfo() << " signature present\n";
}
if (se.nobjects_minus_one != 0) {
- *m->log->getInfo()
- << " nobjects: " << se.nobjects_minus_one + 1 << "\n";
+ *m->log->getInfo() << " nobjects: " << se.nobjects_minus_one + 1 << "\n";
}
}
}
@@ -1075,8 +986,7 @@ void
QPDF::dumpHGeneric(HGeneric& t)
{
*m->log->getInfo() << "first_object: " << t.first_object << "\n"
- << "first_object_offset: "
- << adjusted_offset(t.first_object_offset) << "\n"
+ << "first_object_offset: " << adjusted_offset(t.first_object_offset) << "\n"
<< "nobjects: " << t.nobjects << "\n"
<< "group_length: " << t.group_length << "\n";
}
@@ -1094,9 +1004,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
if (m->object_to_obj_users.empty()) {
// Note that we can't call optimize here because we don't know
// whether it should be called with or without allow changes.
- throw std::logic_error(
- "INTERNAL ERROR: QPDF::calculateLinearizationData "
- "called before optimize()");
+ throw std::logic_error("INTERNAL ERROR: QPDF::calculateLinearizationData "
+ "called before optimize()");
}
// Separate objects into the categories sufficient for us to
@@ -1159,8 +1068,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
QPDFObjectHandle root = getRoot();
bool outlines_in_first_page = false;
QPDFObjectHandle pagemode = root.getKey("/PageMode");
- QTC::TC(
- "qpdf", "QPDF categorize pagemode present", pagemode.isName() ? 1 : 0);
+ QTC::TC("qpdf", "QPDF categorize pagemode present", pagemode.isName() ? 1 : 0);
if (pagemode.isName()) {
if (pagemode.getName() == "/UseOutlines") {
if (root.hasKey("/Outlines")) {
@@ -1169,10 +1077,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
QTC::TC("qpdf", "QPDF UseOutlines but no Outlines");
}
}
- QTC::TC(
- "qpdf",
- "QPDF categorize pagemode outlines",
- outlines_in_first_page ? 1 : 0);
+ QTC::TC("qpdf", "QPDF categorize pagemode outlines", outlines_in_first_page ? 1 : 0);
}
std::set<std::string> open_document_keys;
@@ -1254,9 +1159,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
lc_outlines.insert(og);
} else if (in_open_document) {
lc_open_document.insert(og);
- } else if (
- (in_first_page) && (others == 0) && (other_pages == 0) &&
- (thumbs == 0)) {
+ } else if ((in_first_page) && (others == 0) && (other_pages == 0) && (thumbs == 0)) {
lc_first_page_private.insert(og);
} else if (in_first_page) {
lc_first_page_shared.insert(og);
@@ -1335,9 +1238,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
}
QPDFObjGen first_page_og(pages.at(0).getObjGen());
if (!lc_first_page_private.count(first_page_og)) {
- stopOnError(
- "INTERNAL ERROR: QPDF::calculateLinearizationData: first page "
- "object not in lc_first_page_private");
+ stopOnError("INTERNAL ERROR: QPDF::calculateLinearizationData: first page "
+ "object not in lc_first_page_private");
}
lc_first_page_private.erase(first_page_og);
m->c_linp.first_page_object = pages.at(0).getObjectID();
@@ -1405,10 +1307,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
}
// That should have covered all part7 objects.
if (!lc_other_page_private.empty()) {
- stopOnError(
- "INTERNAL ERROR:"
- " QPDF::calculateLinearizationData: lc_other_page_private is "
- "not empty after generation of part7");
+ stopOnError("INTERNAL ERROR:"
+ " QPDF::calculateLinearizationData: lc_other_page_private is "
+ "not empty after generation of part7");
}
// Part 8: other pages' shared objects
@@ -1461,8 +1362,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// having been in some set other than
// lc_thumbnail_private.
}
- std::set<QPDFObjGen>& ogs =
- m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))];
+ std::set<QPDFObjGen>& ogs = m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))];
for (auto const& og: ogs) {
if (lc_thumbnail_private.count(og)) {
lc_thumbnail_private.erase(og);
@@ -1494,15 +1394,14 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// Make sure we got everything exactly once.
- size_t num_placed = m->part4.size() + m->part6.size() + m->part7.size() +
- m->part8.size() + m->part9.size();
+ size_t num_placed =
+ m->part4.size() + m->part6.size() + m->part7.size() + m->part8.size() + m->part9.size();
size_t num_wanted = m->object_to_obj_users.size();
if (num_placed != num_wanted) {
stopOnError(
"INTERNAL ERROR: QPDF::calculateLinearizationData: wrong "
"number of objects placed (num_placed = " +
- std::to_string(num_placed) +
- "; number of objects: " + std::to_string(num_wanted));
+ std::to_string(num_placed) + "; number of objects: " + std::to_string(num_wanted));
}
// Calculate shared object hint table information including
@@ -1553,8 +1452,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
" calculating linearization data");
}
for (auto const& og: m->obj_user_to_objects[ou]) {
- if ((m->object_to_obj_users[og].size() > 1) &&
- (obj_to_index.count(og.getObj()) > 0)) {
+ if ((m->object_to_obj_users[og].size() > 1) && (obj_to_index.count(og.getObj()) > 0)) {
int idx = obj_to_index[og.getObj()];
++pe.nshared_objects;
pe.shared_identifiers.push_back(idx);
@@ -1663,8 +1561,8 @@ QPDF::calculateHPageOffset(
int min_nobjects = cphe.at(0).nobjects;
int max_nobjects = min_nobjects;
- int min_length = outputLengthNextN(
- pages.at(0).getObjectID(), min_nobjects, lengths, obj_renumber);
+ int min_length =
+ outputLengthNextN(pages.at(0).getObjectID(), min_nobjects, lengths, obj_renumber);
int max_length = min_length;
int max_shared = cphe.at(0).nshared_objects;
@@ -1681,8 +1579,7 @@ QPDF::calculateHPageOffset(
// without duplicating those assignments.
int nobjects = cphe.at(i).nobjects;
- int length = outputLengthNextN(
- pages.at(i).getObjectID(), nobjects, lengths, obj_renumber);
+ int length = outputLengthNextN(pages.at(i).getObjectID(), nobjects, lengths, obj_renumber);
int nshared = cphe.at(i).nshared_objects;
min_nobjects = std::min(min_nobjects, nobjects);
@@ -1727,8 +1624,7 @@ QPDF::calculateHPageOffset(
phe.at(i).delta_content_length = phe.at(i).delta_page_length;
for (size_t j = 0; j < toS(cphe.at(i).nshared_objects); ++j) {
- phe.at(i).shared_identifiers.push_back(
- cphe.at(i).shared_identifiers.at(j));
+ phe.at(i).shared_identifiers.push_back(cphe.at(i).shared_identifiers.at(j));
phe.at(i).shared_numerators.push_back(0);
}
}
@@ -1746,14 +1642,12 @@ QPDF::calculateHSharedObject(
std::vector<HSharedObjectEntry>& soe = so.entries;
soe.clear();
- int min_length =
- outputLengthNextN(csoe.at(0).object, 1, lengths, obj_renumber);
+ int min_length = outputLengthNextN(csoe.at(0).object, 1, lengths, obj_renumber);
int max_length = min_length;
for (size_t i = 0; i < toS(cso.nshared_total); ++i) {
// Assign absolute numbers to deltas; adjust later
- int length =
- outputLengthNextN(csoe.at(i).object, 1, lengths, obj_renumber);
+ int length = outputLengthNextN(csoe.at(i).object, 1, lengths, obj_renumber);
min_length = std::min(min_length, length);
max_length = std::max(max_length, length);
soe.push_back(HSharedObjectEntry());
@@ -1766,10 +1660,8 @@ QPDF::calculateHSharedObject(
so.nshared_total = cso.nshared_total;
so.nshared_first_page = cso.nshared_first_page;
if (so.nshared_total > so.nshared_first_page) {
- so.first_shared_obj =
- (*(obj_renumber.find(cso.first_shared_obj))).second;
- so.first_shared_offset =
- (*(xref.find(so.first_shared_obj))).second.getOffset();
+ so.first_shared_obj = (*(obj_renumber.find(cso.first_shared_obj))).second;
+ so.first_shared_offset = (*(xref.find(so.first_shared_obj))).second.getOffset();
}
so.min_group_length = min_length;
so.nbits_delta_group_length = nbits(max_length - min_length);
@@ -1801,21 +1693,18 @@ QPDF::calculateHOutline(
ho.first_object = (*(obj_renumber.find(cho.first_object))).second;
ho.first_object_offset = (*(xref.find(ho.first_object))).second.getOffset();
ho.nobjects = cho.nobjects;
- ho.group_length =
- outputLengthNextN(cho.first_object, ho.nobjects, lengths, obj_renumber);
+ ho.group_length = outputLengthNextN(cho.first_object, ho.nobjects, lengths, obj_renumber);
}
template <class T, class int_type>
static void
-write_vector_int(
- BitWriter& w, int nitems, std::vector<T>& vec, int bits, int_type T::*field)
+write_vector_int(BitWriter& w, int nitems, std::vector<T>& vec, int bits, int_type T::*field)
{
// nitems times, write bits bits from the given field of the ith
// vector to the given bit writer.
for (size_t i = 0; i < QIntC::to_size(nitems); ++i) {
- w.writeBits(
- QIntC::to_ulonglong(vec.at(i).*field), QIntC::to_size(bits));
+ w.writeBits(QIntC::to_ulonglong(vec.at(i).*field), QIntC::to_size(bits));
}
// The PDF spec says that each hint table starts at a byte
// boundary. Each "row" actually must start on a byte boundary.
@@ -1836,9 +1725,7 @@ write_vector_vector(
// from the vec2 vector field of the ith item of vec1.
for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1) {
for (size_t i2 = 0; i2 < QIntC::to_size(vec1.at(i1).*nitems2); ++i2) {
- w.writeBits(
- QIntC::to_ulonglong((vec1.at(i1).*vec2).at(i2)),
- QIntC::to_size(bits));
+ w.writeBits(QIntC::to_ulonglong((vec1.at(i1).*vec2).at(i2)), QIntC::to_size(bits));
}
}
w.flush();
@@ -1866,24 +1753,11 @@ QPDF::writeHPageOffset(BitWriter& w)
int nitems = toI(getAllPages().size());
std::vector<HPageOffsetEntry>& entries = t.entries;
+ write_vector_int(w, nitems, entries, t.nbits_delta_nobjects, &HPageOffsetEntry::delta_nobjects);
write_vector_int(
- w,
- nitems,
- entries,
- t.nbits_delta_nobjects,
- &HPageOffsetEntry::delta_nobjects);
- write_vector_int(
- w,
- nitems,
- entries,
- t.nbits_delta_page_length,
- &HPageOffsetEntry::delta_page_length);
+ w, nitems, entries, t.nbits_delta_page_length, &HPageOffsetEntry::delta_page_length);
write_vector_int(
- w,
- nitems,
- entries,
- t.nbits_nshared_objects,
- &HPageOffsetEntry::nshared_objects);
+ w, nitems, entries, t.nbits_nshared_objects, &HPageOffsetEntry::nshared_objects);
write_vector_vector(
w,
nitems,
@@ -1899,17 +1773,9 @@ QPDF::writeHPageOffset(BitWriter& w)
t.nbits_shared_numerator,
&HPageOffsetEntry::shared_numerators);
write_vector_int(
- w,
- nitems,
- entries,
- t.nbits_delta_content_offset,
- &HPageOffsetEntry::delta_content_offset);
+ w, nitems, entries, t.nbits_delta_content_offset, &HPageOffsetEntry::delta_content_offset);
write_vector_int(
- w,
- nitems,
- entries,
- t.nbits_delta_content_length,
- &HPageOffsetEntry::delta_content_length);
+ w, nitems, entries, t.nbits_delta_content_length, &HPageOffsetEntry::delta_content_length);
}
void
@@ -1934,13 +1800,8 @@ QPDF::writeHSharedObject(BitWriter& w)
std::vector<HSharedObjectEntry>& entries = t.entries;
write_vector_int(
- w,
- nitems,
- entries,
- t.nbits_delta_group_length,
- &HSharedObjectEntry::delta_group_length);
- write_vector_int(
- w, nitems, entries, 1, &HSharedObjectEntry::signature_present);
+ w, nitems, entries, t.nbits_delta_group_length, &HSharedObjectEntry::delta_group_length);
+ write_vector_int(w, nitems, entries, 1, &HSharedObjectEntry::signature_present);
for (size_t i = 0; i < toS(nitems); ++i) {
// If signature were present, we'd have to write a 128-bit hash.
if (entries.at(i).signature_present != 0) {
@@ -1948,12 +1809,7 @@ QPDF::writeHSharedObject(BitWriter& w)
" while writing linearization data");
}
}
- write_vector_int(
- w,
- nitems,
- entries,
- t.nbits_nobjects,
- &HSharedObjectEntry::nobjects_minus_one);
+ write_vector_int(w, nitems, entries, t.nbits_nobjects, &HSharedObjectEntry::nobjects_minus_one);
}
void
diff --git a/libqpdf/QPDF_optimization.cc b/libqpdf/QPDF_optimization.cc
index e1d08674..ab06f158 100644
--- a/libqpdf/QPDF_optimization.cc
+++ b/libqpdf/QPDF_optimization.cc
@@ -109,9 +109,7 @@ QPDF::optimize(
// time to time, so this is almost certain not to cause any
// problems.
updateObjectMaps(
- ObjUser(ObjUser::ou_root_key, key),
- root.getKey(key),
- skip_stream_parameters);
+ ObjUser(ObjUser::ou_root_key, key), root.getKey(key), skip_stream_parameters);
}
ObjUser root_ou = ObjUser(ObjUser::ou_root);
@@ -177,8 +175,8 @@ QPDF::pushInheritedAttributesToPageInternal(
std::set<std::string> inheritable_keys;
for (auto const& key: cur_pages.getKeys()) {
- if ((key == "/MediaBox") || (key == "/CropBox") ||
- (key == "/Resources") || (key == "/Rotate")) {
+ if ((key == "/MediaBox") || (key == "/CropBox") || (key == "/Resources") ||
+ (key == "/Rotate")) {
if (!allow_changes) {
throw QPDFExc(
qpdf_e_internal,
@@ -193,10 +191,7 @@ QPDF::pushInheritedAttributesToPageInternal(
// This is an inheritable resource
inheritable_keys.insert(key);
QPDFObjectHandle oh = cur_pages.getKey(key);
- QTC::TC(
- "qpdf",
- "QPDF opt direct pages resource",
- oh.isIndirect() ? 0 : 1);
+ QTC::TC("qpdf", "QPDF opt direct pages resource", oh.isIndirect() ? 0 : 1);
if (!oh.isIndirect()) {
if (!oh.isScalar()) {
// Replace shared direct object non-scalar
@@ -216,8 +211,8 @@ QPDF::pushInheritedAttributesToPageInternal(
// Remove this resource from this node. It will be
// reattached at the page level.
cur_pages.removeKey(key);
- } else if (!((key == "/Type") || (key == "/Parent") ||
- (key == "/Kids") || (key == "/Count"))) {
+ } else if (!((key == "/Type") || (key == "/Parent") || (key == "/Kids") ||
+ (key == "/Count"))) {
// Warn when flattening, but not if the key is at the top
// level (i.e. "/Parent" not set), as we don't change these;
// but flattening removes intermediate /Pages nodes.
@@ -349,17 +344,12 @@ QPDF::updateObjectMapsInternal(
// Don't traverse back up the page tree
} else if (
((ssp >= 1) && (key == "/Length")) ||
- ((ssp >= 2) &&
- ((key == "/Filter") || (key == "/DecodeParms")))) {
+ ((ssp >= 2) && ((key == "/Filter") || (key == "/DecodeParms")))) {
// Don't traverse into stream parameters that we are
// not going to write.
} else {
updateObjectMapsInternal(
- ou,
- dict.getKey(key),
- skip_stream_parameters,
- visited,
- false);
+ ou, dict.getKey(key), skip_stream_parameters, visited, false);
}
}
}
diff --git a/libqpdf/QPDF_pages.cc b/libqpdf/QPDF_pages.cc
index d12b4027..81fd11a3 100644
--- a/libqpdf/QPDF_pages.cc
+++ b/libqpdf/QPDF_pages.cc
@@ -69,9 +69,8 @@ QPDF::getAllPages()
// catalog points to the first page. Try to work around
// this and similar cases with this heuristic.
if (!warned) {
- getRoot().warnIfPossible(
- "document page tree root (root -> /Pages) doesn't point"
- " to the root of the page tree; attempting to correct");
+ getRoot().warnIfPossible("document page tree root (root -> /Pages) doesn't point"
+ " to the root of the page tree; attempting to correct");
warned = true;
}
changed_pages = true;
@@ -102,8 +101,7 @@ QPDF::getAllPagesInternal(
"Loop detected in /Pages structure (getAllPages)");
}
if (!cur_node.isDictionaryOfType("/Pages")) {
- cur_node.warnIfPossible(
- "/Type key should be /Pages but is not; overriding");
+ cur_node.warnIfPossible("/Type key should be /Pages but is not; overriding");
cur_node.replaceKey("/Type", "/Pages"_qpdf);
}
auto kids = cur_node.getKey("/Kids");
@@ -116,8 +114,7 @@ QPDF::getAllPagesInternal(
if (!kid.isIndirect()) {
QTC::TC("qpdf", "QPDF handle direct page object");
cur_node.warnIfPossible(
- "kid " + std::to_string(i) +
- " (from 0) is direct; converting to indirect");
+ "kid " + std::to_string(i) + " (from 0) is direct; converting to indirect");
kid = makeIndirectObject(kid);
kids.setArrayItem(i, kid);
} else if (!seen.add(kid)) {
@@ -133,8 +130,7 @@ QPDF::getAllPagesInternal(
kids.setArrayItem(i, kid);
}
if (!kid.isDictionaryOfType("/Page")) {
- kid.warnIfPossible(
- "/Type key should be /Page but is not; overriding");
+ kid.warnIfPossible("/Type key should be /Page but is not; overriding");
kid.replaceKey("/Type", "/Page"_qpdf);
}
m->all_pages.push_back(kid);
@@ -190,16 +186,14 @@ QPDF::flattenPagesTree()
}
void
-QPDF::insertPageobjToPage(
- QPDFObjectHandle const& obj, int pos, bool check_duplicate)
+QPDF::insertPageobjToPage(QPDFObjectHandle const& obj, int pos, bool check_duplicate)
{
QPDFObjGen og(obj.getObjGen());
if (check_duplicate) {
if (!m->pageobj_to_pages_pos.insert(std::make_pair(og, pos)).second) {
// The library never calls insertPageobjToPage in a way
// that causes this to happen.
- setLastObjectDescription(
- "page " + std::to_string(pos) + " (numbered from zero)", og);
+ setLastObjectDescription("page " + std::to_string(pos) + " (numbered from zero)", og);
throw QPDFExc(
qpdf_e_pages,
m->file->getName(),
@@ -233,8 +227,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
}
if ((pos < 0) || (toS(pos) > m->all_pages.size())) {
- throw std::runtime_error(
- "QPDF::insertPage called with pos out of range");
+ throw std::runtime_error("QPDF::insertPage called with pos out of range");
}
QTC::TC(
@@ -306,9 +299,7 @@ QPDF::addPage(QPDFObjectHandle newpage, bool first)
if (first) {
insertPage(newpage, 0);
} else {
- insertPage(
- newpage,
- getRoot().getKey("/Pages").getKey("/Count").getIntValueAsInt());
+ insertPage(newpage, getRoot().getKey("/Pages").getKey("/Count").getIntValueAsInt());
}
}
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index 57999185..5fa3c9ca 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -255,56 +255,41 @@ static unsigned short mac_roman_to_unicode[] = {
};
static std::map<unsigned long, unsigned char> unicode_to_win_ansi = {
- {0x20ac, 0x80}, {0x201a, 0x82}, {0x192, 0x83}, {0x201e, 0x84},
- {0x2026, 0x85}, {0x2020, 0x86}, {0x2021, 0x87}, {0x2c6, 0x88},
- {0x2030, 0x89}, {0x160, 0x8a}, {0x2039, 0x8b}, {0x152, 0x8c},
- {0x17d, 0x8e}, {0x2018, 0x91}, {0x2019, 0x92}, {0x201c, 0x93},
- {0x201d, 0x94}, {0x2022, 0x95}, {0x2013, 0x96}, {0x2014, 0x97},
- {0x303, 0x98}, {0x2122, 0x99}, {0x161, 0x9a}, {0x203a, 0x9b},
+ {0x20ac, 0x80}, {0x201a, 0x82}, {0x192, 0x83}, {0x201e, 0x84}, {0x2026, 0x85}, {0x2020, 0x86},
+ {0x2021, 0x87}, {0x2c6, 0x88}, {0x2030, 0x89}, {0x160, 0x8a}, {0x2039, 0x8b}, {0x152, 0x8c},
+ {0x17d, 0x8e}, {0x2018, 0x91}, {0x2019, 0x92}, {0x201c, 0x93}, {0x201d, 0x94}, {0x2022, 0x95},
+ {0x2013, 0x96}, {0x2014, 0x97}, {0x303, 0x98}, {0x2122, 0x99}, {0x161, 0x9a}, {0x203a, 0x9b},
{0x153, 0x9c}, {0x17e, 0x9e}, {0x178, 0x9f}, {0xa0, 0xa0},
};
static std::map<unsigned long, unsigned char> unicode_to_mac_roman = {
- {0xc4, 0x80}, {0xc5, 0x81}, {0xc7, 0x82}, {0xc9, 0x83},
- {0xd1, 0x84}, {0xd6, 0x85}, {0xdc, 0x86}, {0xe1, 0x87},
- {0xe0, 0x88}, {0xe2, 0x89}, {0xe4, 0x8a}, {0xe3, 0x8b},
- {0xe5, 0x8c}, {0xe7, 0x8d}, {0xe9, 0x8e}, {0xe8, 0x8f},
- {0xea, 0x90}, {0xeb, 0x91}, {0xed, 0x92}, {0xec, 0x93},
- {0xee, 0x94}, {0xef, 0x95}, {0xf1, 0x96}, {0xf3, 0x97},
- {0xf2, 0x98}, {0xf4, 0x99}, {0xf6, 0x9a}, {0xf5, 0x9b},
- {0xfa, 0x9c}, {0xf9, 0x9d}, {0xfb, 0x9e}, {0xfc, 0x9f},
- {0x2020, 0xa0}, {0xb0, 0xa1}, {0xa2, 0xa2}, {0xa3, 0xa3},
- {0xa7, 0xa4}, {0x2022, 0xa5}, {0xb6, 0xa6}, {0xdf, 0xa7},
- {0xae, 0xa8}, {0xa9, 0xa9}, {0x2122, 0xaa}, {0x301, 0xab},
- {0x308, 0xac}, {0xc6, 0xae}, {0xd8, 0xaf}, {0xb1, 0xb1},
- {0xa5, 0xb4}, {0x3bc, 0xb5}, {0x1d43, 0xbb}, {0x1d52, 0xbc},
- {0xe6, 0xbe}, {0xf8, 0xbf}, {0xbf, 0xc0}, {0xa1, 0xc1},
- {0xac, 0xc2}, {0x192, 0xc4}, {0xab, 0xc7}, {0xbb, 0xc8},
- {0x2026, 0xc9}, {0xc0, 0xcb}, {0xc3, 0xcc}, {0xd5, 0xcd},
- {0x152, 0xce}, {0x153, 0xcf}, {0x2013, 0xd0}, {0x2014, 0xd1},
- {0x201c, 0xd2}, {0x201d, 0xd3}, {0x2018, 0xd4}, {0x2019, 0xd5},
- {0xf7, 0xd6}, {0xff, 0xd8}, {0x178, 0xd9}, {0x2044, 0xda},
- {0xa4, 0xdb}, {0x2039, 0xdc}, {0x203a, 0xdd}, {0xfb01, 0xde},
- {0xfb02, 0xdf}, {0x2021, 0xe0}, {0xb7, 0xe1}, {0x201a, 0xe2},
- {0x201e, 0xe3}, {0x2030, 0xe4}, {0xc2, 0xe5}, {0xca, 0xe6},
- {0xc1, 0xe7}, {0xcb, 0xe8}, {0xc8, 0xe9}, {0xcd, 0xea},
- {0xce, 0xeb}, {0xcf, 0xec}, {0xcc, 0xed}, {0xd3, 0xee},
- {0xd4, 0xef}, {0xd2, 0xf1}, {0xda, 0xf2}, {0xdb, 0xf3},
- {0xd9, 0xf4}, {0x131, 0xf5}, {0x2c6, 0xf6}, {0x303, 0xf7},
- {0x304, 0xf8}, {0x306, 0xf9}, {0x307, 0xfa}, {0x30a, 0xfb},
+ {0xc4, 0x80}, {0xc5, 0x81}, {0xc7, 0x82}, {0xc9, 0x83}, {0xd1, 0x84}, {0xd6, 0x85},
+ {0xdc, 0x86}, {0xe1, 0x87}, {0xe0, 0x88}, {0xe2, 0x89}, {0xe4, 0x8a}, {0xe3, 0x8b},
+ {0xe5, 0x8c}, {0xe7, 0x8d}, {0xe9, 0x8e}, {0xe8, 0x8f}, {0xea, 0x90}, {0xeb, 0x91},
+ {0xed, 0x92}, {0xec, 0x93}, {0xee, 0x94}, {0xef, 0x95}, {0xf1, 0x96}, {0xf3, 0x97},
+ {0xf2, 0x98}, {0xf4, 0x99}, {0xf6, 0x9a}, {0xf5, 0x9b}, {0xfa, 0x9c}, {0xf9, 0x9d},
+ {0xfb, 0x9e}, {0xfc, 0x9f}, {0x2020, 0xa0}, {0xb0, 0xa1}, {0xa2, 0xa2}, {0xa3, 0xa3},
+ {0xa7, 0xa4}, {0x2022, 0xa5}, {0xb6, 0xa6}, {0xdf, 0xa7}, {0xae, 0xa8}, {0xa9, 0xa9},
+ {0x2122, 0xaa}, {0x301, 0xab}, {0x308, 0xac}, {0xc6, 0xae}, {0xd8, 0xaf}, {0xb1, 0xb1},
+ {0xa5, 0xb4}, {0x3bc, 0xb5}, {0x1d43, 0xbb}, {0x1d52, 0xbc}, {0xe6, 0xbe}, {0xf8, 0xbf},
+ {0xbf, 0xc0}, {0xa1, 0xc1}, {0xac, 0xc2}, {0x192, 0xc4}, {0xab, 0xc7}, {0xbb, 0xc8},
+ {0x2026, 0xc9}, {0xc0, 0xcb}, {0xc3, 0xcc}, {0xd5, 0xcd}, {0x152, 0xce}, {0x153, 0xcf},
+ {0x2013, 0xd0}, {0x2014, 0xd1}, {0x201c, 0xd2}, {0x201d, 0xd3}, {0x2018, 0xd4}, {0x2019, 0xd5},
+ {0xf7, 0xd6}, {0xff, 0xd8}, {0x178, 0xd9}, {0x2044, 0xda}, {0xa4, 0xdb}, {0x2039, 0xdc},
+ {0x203a, 0xdd}, {0xfb01, 0xde}, {0xfb02, 0xdf}, {0x2021, 0xe0}, {0xb7, 0xe1}, {0x201a, 0xe2},
+ {0x201e, 0xe3}, {0x2030, 0xe4}, {0xc2, 0xe5}, {0xca, 0xe6}, {0xc1, 0xe7}, {0xcb, 0xe8},
+ {0xc8, 0xe9}, {0xcd, 0xea}, {0xce, 0xeb}, {0xcf, 0xec}, {0xcc, 0xed}, {0xd3, 0xee},
+ {0xd4, 0xef}, {0xd2, 0xf1}, {0xda, 0xf2}, {0xdb, 0xf3}, {0xd9, 0xf4}, {0x131, 0xf5},
+ {0x2c6, 0xf6}, {0x303, 0xf7}, {0x304, 0xf8}, {0x306, 0xf9}, {0x307, 0xfa}, {0x30a, 0xfb},
{0x327, 0xfc}, {0x30b, 0xfd}, {0x328, 0xfe}, {0x2c7, 0xff},
};
static std::map<unsigned long, unsigned char> unicode_to_pdf_doc = {
- {0x02d8, 0x18}, {0x02c7, 0x19}, {0x02c6, 0x1a}, {0x02d9, 0x1b},
- {0x02dd, 0x1c}, {0x02db, 0x1d}, {0x02da, 0x1e}, {0x02dc, 0x1f},
- {0x2022, 0x80}, {0x2020, 0x81}, {0x2021, 0x82}, {0x2026, 0x83},
- {0x2014, 0x84}, {0x2013, 0x85}, {0x0192, 0x86}, {0x2044, 0x87},
- {0x2039, 0x88}, {0x203a, 0x89}, {0x2212, 0x8a}, {0x2030, 0x8b},
- {0x201e, 0x8c}, {0x201c, 0x8d}, {0x201d, 0x8e}, {0x2018, 0x8f},
- {0x2019, 0x90}, {0x201a, 0x91}, {0x2122, 0x92}, {0xfb01, 0x93},
- {0xfb02, 0x94}, {0x0141, 0x95}, {0x0152, 0x96}, {0x0160, 0x97},
- {0x0178, 0x98}, {0x017d, 0x99}, {0x0131, 0x9a}, {0x0142, 0x9b},
- {0x0153, 0x9c}, {0x0161, 0x9d}, {0x017e, 0x9e}, {0xfffd, 0x9f},
- {0x20ac, 0xa0},
+ {0x02d8, 0x18}, {0x02c7, 0x19}, {0x02c6, 0x1a}, {0x02d9, 0x1b}, {0x02dd, 0x1c}, {0x02db, 0x1d},
+ {0x02da, 0x1e}, {0x02dc, 0x1f}, {0x2022, 0x80}, {0x2020, 0x81}, {0x2021, 0x82}, {0x2026, 0x83},
+ {0x2014, 0x84}, {0x2013, 0x85}, {0x0192, 0x86}, {0x2044, 0x87}, {0x2039, 0x88}, {0x203a, 0x89},
+ {0x2212, 0x8a}, {0x2030, 0x8b}, {0x201e, 0x8c}, {0x201c, 0x8d}, {0x201d, 0x8e}, {0x2018, 0x8f},
+ {0x2019, 0x90}, {0x201a, 0x91}, {0x2122, 0x92}, {0xfb01, 0x93}, {0xfb02, 0x94}, {0x0141, 0x95},
+ {0x0152, 0x96}, {0x0160, 0x97}, {0x0178, 0x98}, {0x017d, 0x99}, {0x0131, 0x9a}, {0x0142, 0x9b},
+ {0x0153, 0x9c}, {0x0161, 0x9d}, {0x017e, 0x9e}, {0xfffd, 0x9f}, {0x20ac, 0xa0},
};
template <typename T>
@@ -316,8 +301,7 @@ int_to_string_base_internal(T num, int base, int length)
// such that a negative value appends spaces and a positive value
// prepends zeroes.
if (!((base == 8) || (base == 10) || (base == 16))) {
- throw std::logic_error(
- "int_to_string_base called with unsupported base");
+ throw std::logic_error("int_to_string_base called with unsupported base");
}
std::string cvt;
if (base == 10) {
@@ -366,8 +350,7 @@ QUtil::uint_to_string_base(unsigned long long num, int base, int length)
}
std::string
-QUtil::double_to_string(
- double num, int decimal_places, bool trim_trailing_zeroes)
+QUtil::double_to_string(double num, int decimal_places, bool trim_trailing_zeroes)
{
// Backward compatibility -- this code used to use sprintf and
// treated decimal_places <= 0 to mean to use the default, which
@@ -402,8 +385,7 @@ QUtil::string_to_ll(char const* str)
#endif
if (errno == ERANGE) {
throw std::range_error(
- std::string("overflow/underflow converting ") + str +
- " to 64-bit integer");
+ std::string("overflow/underflow converting ") + str + " to 64-bit integer");
}
return result;
}
@@ -424,8 +406,7 @@ QUtil::string_to_ull(char const* str)
}
if (*p == '-') {
throw std::runtime_error(
- std::string("underflow converting ") + str +
- " to 64-bit unsigned integer");
+ std::string("underflow converting ") + str + " to 64-bit unsigned integer");
}
errno = 0;
@@ -436,8 +417,7 @@ QUtil::string_to_ull(char const* str)
#endif
if (errno == ERANGE) {
throw std::runtime_error(
- std::string("overflow converting ") + str +
- " to 64-bit unsigned integer");
+ std::string("overflow converting ") + str + " to 64-bit unsigned integer");
}
return result;
}
@@ -567,10 +547,7 @@ int
QUtil::seek(FILE* stream, qpdf_offset_t offset, int whence)
{
#if HAVE_FSEEKO
- return fseeko(
- stream,
- QIntC::IntConverter<qpdf_offset_t, off_t>::convert(offset),
- whence);
+ return fseeko(stream, QIntC::IntConverter<qpdf_offset_t, off_t>::convert(offset), whence);
#elif HAVE_FSEEKO64
return fseeko64(stream, offset, whence);
#else
@@ -601,37 +578,22 @@ QUtil::tell(FILE* stream)
bool
QUtil::same_file(char const* name1, char const* name2)
{
- if ((name1 == nullptr) || (strlen(name1) == 0) || (name2 == nullptr) ||
- (strlen(name2) == 0)) {
+ if ((name1 == nullptr) || (strlen(name1) == 0) || (name2 == nullptr) || (strlen(name2) == 0)) {
return false;
}
#ifdef _WIN32
bool same = false;
# ifndef AVOID_WINDOWS_HANDLE
HANDLE fh1 = CreateFile(
- name1,
- GENERIC_READ,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
+ name1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE fh2 = CreateFile(
- name2,
- GENERIC_READ,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
+ name2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
BY_HANDLE_FILE_INFORMATION fi1;
BY_HANDLE_FILE_INFORMATION fi2;
if ((fh1 != INVALID_HANDLE_VALUE) && (fh2 != INVALID_HANDLE_VALUE) &&
- GetFileInformationByHandle(fh1, &fi1) &&
- GetFileInformationByHandle(fh2, &fi2) &&
+ GetFileInformationByHandle(fh1, &fi1) && GetFileInformationByHandle(fh2, &fi2) &&
(fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber) &&
- (fi1.nFileIndexLow == fi2.nFileIndexLow) &&
- (fi1.nFileIndexHigh == fi2.nFileIndexHigh)) {
+ (fi1.nFileIndexLow == fi2.nFileIndexLow) && (fi1.nFileIndexHigh == fi2.nFileIndexHigh)) {
same = true;
}
if (fh1 != INVALID_HANDLE_VALUE) {
@@ -645,8 +607,8 @@ QUtil::same_file(char const* name1, char const* name2)
#else
struct stat st1;
struct stat st2;
- if ((stat(name1, &st1) == 0) && (stat(name2, &st2) == 0) &&
- (st1.st_ino == st2.st_ino) && (st1.st_dev == st2.st_dev)) {
+ if ((stat(name1, &st1) == 0) && (stat(name2, &st2) == 0) && (st1.st_ino == st2.st_ino) &&
+ (st1.st_dev == st2.st_dev)) {
return true;
}
#endif
@@ -675,13 +637,9 @@ QUtil::rename_file(char const* oldname, char const* newname)
}
std::shared_ptr<wchar_t> wold = win_convert_filename(oldname);
std::shared_ptr<wchar_t> wnew = win_convert_filename(newname);
- os_wrapper(
- std::string("rename ") + oldname + " " + newname,
- _wrename(wold.get(), wnew.get()));
+ os_wrapper(std::string("rename ") + oldname + " " + newname, _wrename(wold.get(), wnew.get()));
#else
- os_wrapper(
- std::string("rename ") + oldname + " " + newname,
- rename(oldname, newname));
+ os_wrapper(std::string("rename ") + oldname + " " + newname, rename(oldname, newname));
#endif
}
@@ -699,8 +657,7 @@ QUtil::pipe_file(char const* filename, Pipeline* p)
}
p->finish();
if (ferror(f)) {
- throw std::runtime_error(
- std::string("failure reading file ") + filename);
+ throw std::runtime_error(std::string("failure reading file ") + filename);
}
}
@@ -843,8 +800,7 @@ QUtil::getWhoami(char* argv0)
++whoami;
}
- if ((strlen(whoami) > 4) &&
- (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0)) {
+ if ((strlen(whoami) > 4) && (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0)) {
whoami[strlen(whoami) - 4] = '\0';
}
@@ -974,15 +930,12 @@ QUtil::qpdf_time_to_pdf_time(QPDFTime const& qtm)
} else {
tz_offset += "-";
}
- tz_offset += QUtil::int_to_string(t / 60, 2) + "'" +
- QUtil::int_to_string(t % 60, 2) + "'";
+ tz_offset += QUtil::int_to_string(t / 60, 2) + "'" + QUtil::int_to_string(t % 60, 2) + "'";
}
return (
- "D:" + QUtil::int_to_string(qtm.year, 4) +
- QUtil::int_to_string(qtm.month, 2) + QUtil::int_to_string(qtm.day, 2) +
- QUtil::int_to_string(qtm.hour, 2) +
- QUtil::int_to_string(qtm.minute, 2) +
- QUtil::int_to_string(qtm.second, 2) + tz_offset);
+ "D:" + QUtil::int_to_string(qtm.year, 4) + QUtil::int_to_string(qtm.month, 2) +
+ QUtil::int_to_string(qtm.day, 2) + QUtil::int_to_string(qtm.hour, 2) +
+ QUtil::int_to_string(qtm.minute, 2) + QUtil::int_to_string(qtm.second, 2) + tz_offset);
}
std::string
@@ -999,16 +952,13 @@ QUtil::qpdf_time_to_iso8601(QPDFTime const& qtm)
} else {
tz_offset += "-";
}
- tz_offset += QUtil::int_to_string(t / 60, 2) + ":" +
- QUtil::int_to_string(t % 60, 2);
+ tz_offset += QUtil::int_to_string(t / 60, 2) + ":" + QUtil::int_to_string(t % 60, 2);
}
return (
- QUtil::int_to_string(qtm.year, 4) + "-" +
- QUtil::int_to_string(qtm.month, 2) + "-" +
- QUtil::int_to_string(qtm.day, 2) + "T" +
- QUtil::int_to_string(qtm.hour, 2) + ":" +
- QUtil::int_to_string(qtm.minute, 2) + ":" +
- QUtil::int_to_string(qtm.second, 2) + tz_offset);
+ QUtil::int_to_string(qtm.year, 4) + "-" + QUtil::int_to_string(qtm.month, 2) + "-" +
+ QUtil::int_to_string(qtm.day, 2) + "T" + QUtil::int_to_string(qtm.hour, 2) + ":" +
+ QUtil::int_to_string(qtm.minute, 2) + ":" + QUtil::int_to_string(qtm.second, 2) +
+ tz_offset);
}
bool
@@ -1022,9 +972,7 @@ QUtil::pdf_time_to_qpdf_time(std::string const& str, QPDFTime* qtm)
return false;
}
int tz_delta = 0;
- auto to_i = [](std::string const& s) {
- return QUtil::string_to_int(s.c_str());
- };
+ auto to_i = [](std::string const& s) { return QUtil::string_to_int(s.c_str()); };
if (m[8] != "") {
tz_delta = ((to_i(m[9]) * 60) + to_i(m[10]));
@@ -1034,13 +982,7 @@ QUtil::pdf_time_to_qpdf_time(std::string const& str, QPDFTime* qtm)
}
if (qtm) {
*qtm = QPDFTime(
- to_i(m[1]),
- to_i(m[2]),
- to_i(m[3]),
- to_i(m[4]),
- to_i(m[5]),
- to_i(m[6]),
- tz_delta);
+ to_i(m[1]), to_i(m[2]), to_i(m[3]), to_i(m[4]), to_i(m[5]), to_i(m[6]), tz_delta);
}
return true;
}
@@ -1098,8 +1040,7 @@ QUtil::toUTF8(unsigned long uval)
}
// If maxval is k bits long, the high (7 - k) bits of the
// resulting byte must be high.
- *cur_byte = static_cast<unsigned char>(
- QIntC::to_ulong(0xff - (1 + (maxval << 1))) + uval);
+ *cur_byte = static_cast<unsigned char>(QIntC::to_ulong(0xff - (1 + (maxval << 1))) + uval);
result += reinterpret_cast<char*>(cur_byte);
}
@@ -1121,10 +1062,8 @@ QUtil::toUTF16(unsigned long uval)
} else if (uval <= 0x10ffff) {
char out[4];
uval -= 0x10000;
- unsigned short high =
- static_cast<unsigned short>(((uval & 0xffc00) >> 10) + 0xd800);
- unsigned short low =
- static_cast<unsigned short>((uval & 0x3ff) + 0xdc00);
+ unsigned short high = static_cast<unsigned short>(((uval & 0xffc00) >> 10) + 0xd800);
+ unsigned short low = static_cast<unsigned short>((uval & 0x3ff) + 0xdc00);
out[0] = static_cast<char>((high & 0xff00) >> 8);
out[1] = static_cast<char>(high & 0xff);
out[2] = static_cast<char>((low & 0xff00) >> 8);
@@ -1203,14 +1142,12 @@ long
QUtil::random()
{
long result = 0L;
- initializeWithRandomBytes(
- reinterpret_cast<unsigned char*>(&result), sizeof(result));
+ initializeWithRandomBytes(reinterpret_cast<unsigned char*>(&result), sizeof(result));
return result;
}
void
-QUtil::read_file_into_memory(
- char const* filename, std::shared_ptr<char>& file_buf, size_t& size)
+QUtil::read_file_into_memory(char const* filename, std::shared_ptr<char>& file_buf, size_t& size)
{
FILE* f = safe_fopen(filename, "rb");
FileCloser fc(f);
@@ -1227,14 +1164,12 @@ QUtil::read_file_into_memory(
if (bytes_read != size) {
if (ferror(f)) {
throw std::runtime_error(
- std::string("failure reading file ") + filename +
- " into memory: read " + uint_to_string(bytes_read) +
- "; wanted " + uint_to_string(size));
+ std::string("failure reading file ") + filename + " into memory: read " +
+ uint_to_string(bytes_read) + "; wanted " + uint_to_string(size));
} else {
throw std::runtime_error(
- std::string("premature eof reading file ") + filename +
- " into memory: read " + uint_to_string(bytes_read) +
- "; wanted " + uint_to_string(size));
+ std::string("premature eof reading file ") + filename + " into memory: read " +
+ uint_to_string(bytes_read) + "; wanted " + uint_to_string(size));
}
}
}
@@ -1258,13 +1193,11 @@ QUtil::read_file_into_string(FILE* f, std::string_view filename)
if (ferror(f)) {
throw std::runtime_error(
std::string("failure reading file ") + std::string(filename) +
- " into memory: read " + uint_to_string(read) + "; wanted " +
- uint_to_string(size));
+ " into memory: read " + uint_to_string(read) + "; wanted " + uint_to_string(size));
} else {
throw std::runtime_error(
- std::string("premature eof reading file ") +
- std::string(filename) + " into memory: read " +
- uint_to_string(read) + "; wanted " + uint_to_string(size));
+ std::string("premature eof reading file ") + std::string(filename) +
+ " into memory: read " + uint_to_string(read) + "; wanted " + uint_to_string(size));
}
}
return result;
@@ -1314,9 +1247,7 @@ QUtil::read_lines_from_file(FILE* f, bool preserve_eol)
void
QUtil::read_lines_from_file(
- std::function<bool(char&)> next_char,
- std::list<std::string>& lines,
- bool preserve_eol)
+ std::function<bool(char&)> next_char, std::list<std::string>& lines, bool preserve_eol)
{
std::string* buf = nullptr;
char c;
@@ -1463,8 +1394,7 @@ QUtil::parse_numrange(char const* range, int max)
// max == 0 means we don't know the max and are just
// testing for valid syntax.
if ((max > 0) && ((num < 1) || (num > max))) {
- throw std::runtime_error(
- "number " + QUtil::int_to_string(num) + " out of range");
+ throw std::runtime_error("number " + QUtil::int_to_string(num) + " out of range");
}
if (i == 0) {
result.push_back(work.at(i));
@@ -1484,8 +1414,7 @@ QUtil::parse_numrange(char const* range, int max)
}
}
} else {
- throw std::logic_error(
- "INTERNAL ERROR parsing numeric range");
+ throw std::logic_error("INTERNAL ERROR parsing numeric range");
}
}
}
@@ -1500,11 +1429,9 @@ QUtil::parse_numrange(char const* range, int max)
std::string message;
if (p) {
message = "error at * in numeric range " +
- std::string(range, QIntC::to_size(p - range)) + "*" + p + ": " +
- e.what();
+ std::string(range, QIntC::to_size(p - range)) + "*" + p + ": " + e.what();
} else {
- message = "error in numeric range " + std::string(range) + ": " +
- e.what();
+ message = "error in numeric range " + std::string(range) + ": " + e.what();
}
throw std::runtime_error(message);
}
@@ -1544,8 +1471,7 @@ encode_pdfdoc(unsigned long codepoint)
}
unsigned long
-QUtil::get_next_utf8_codepoint(
- std::string const& utf8_val, size_t& pos, bool& error)
+QUtil::get_next_utf8_codepoint(std::string const& utf8_val, size_t& pos, bool& error)
{
size_t len = utf8_val.length();
unsigned char ch = static_cast<unsigned char>(utf8_val.at(pos++));
@@ -1562,8 +1488,7 @@ QUtil::get_next_utf8_codepoint(
to_clear = static_cast<unsigned char>(to_clear | bit_check);
bit_check >>= 1;
}
- if (((bytes_needed > 5) || (bytes_needed < 1)) ||
- ((pos + bytes_needed) > len)) {
+ if (((bytes_needed > 5) || (bytes_needed < 1)) || ((pos + bytes_needed) > len)) {
error = true;
return 0xfffd;
}
@@ -1584,11 +1509,7 @@ QUtil::get_next_utf8_codepoint(
}
static bool
-transcode_utf8(
- std::string const& utf8_val,
- std::string& result,
- encoding_e encoding,
- char unknown)
+transcode_utf8(std::string const& utf8_val, std::string& result, encoding_e encoding, char unknown)
{
bool okay = true;
result.clear();
@@ -1613,8 +1534,7 @@ transcode_utf8(
static std::string ef_bb_bf("\xaf\xc2\xbb\xc2\xbf");
// C++-20 has starts_with, but when this was written, qpdf
// had a minimum supported version of C++-17.
- if ((utf8_val.compare(1, 3, fe_ff) == 0) ||
- (utf8_val.compare(1, 3, ff_fe) == 0) ||
+ if ((utf8_val.compare(1, 3, fe_ff) == 0) || (utf8_val.compare(1, 3, ff_fe) == 0) ||
(utf8_val.compare(1, 5, ef_bb_bf) == 0)) {
result += unknown;
okay = false;
@@ -1627,8 +1547,7 @@ transcode_utf8(
size_t pos = 0;
while (pos < len) {
bool error = false;
- unsigned long codepoint =
- QUtil::get_next_utf8_codepoint(utf8_val, pos, error);
+ unsigned long codepoint = QUtil::get_next_utf8_codepoint(utf8_val, pos, error);
if (error) {
okay = false;
if (encoding == e_utf16) {
@@ -1640,9 +1559,7 @@ transcode_utf8(
char ch = static_cast<char>(codepoint);
if (encoding == e_utf16) {
result += QUtil::toUTF16(QIntC::to_ulong(ch));
- } else if (
- (encoding == e_pdfdoc) &&
- (((ch >= 0x18) && (ch <= 0x1f)) || (ch == 127))) {
+ } else if ((encoding == e_pdfdoc) && (((ch >= 0x18) && (ch <= 0x1f)) || (ch == 127))) {
// PDFDocEncoding maps some low characters to Unicode,
// so if we encounter those invalid UTF-8 code points,
// map them to unknown so reversing the mapping
@@ -1720,29 +1637,25 @@ QUtil::utf8_to_pdf_doc(std::string const& utf8, char unknown_char)
}
bool
-QUtil::utf8_to_ascii(
- std::string const& utf8, std::string& ascii, char unknown_char)
+QUtil::utf8_to_ascii(std::string const& utf8, std::string& ascii, char unknown_char)
{
return transcode_utf8(utf8, ascii, e_ascii, unknown_char);
}
bool
-QUtil::utf8_to_win_ansi(
- std::string const& utf8, std::string& win, char unknown_char)
+QUtil::utf8_to_win_ansi(std::string const& utf8, std::string& win, char unknown_char)
{
return transcode_utf8(utf8, win, e_winansi, unknown_char);
}
bool
-QUtil::utf8_to_mac_roman(
- std::string const& utf8, std::string& mac, char unknown_char)
+QUtil::utf8_to_mac_roman(std::string const& utf8, std::string& mac, char unknown_char)
{
return transcode_utf8(utf8, mac, e_macroman, unknown_char);
}
bool
-QUtil::utf8_to_pdf_doc(
- std::string const& utf8, std::string& pdfdoc, char unknown_char)
+QUtil::utf8_to_pdf_doc(std::string const& utf8, std::string& pdfdoc, char unknown_char)
{
return transcode_utf8(utf8, pdfdoc, e_pdfdoc, unknown_char);
}
@@ -1869,10 +1782,7 @@ QUtil::pdf_doc_to_utf8(std::string const& val)
void
QUtil::analyze_encoding(
- std::string const& val,
- bool& has_8bit_chars,
- bool& is_valid_utf8,
- bool& is_utf16)
+ std::string const& val, bool& has_8bit_chars, bool& is_valid_utf8, bool& is_utf16)
{
has_8bit_chars = is_utf16 = is_valid_utf8 = false;
if (QUtil::is_utf16(val)) {
@@ -1976,10 +1886,7 @@ QUtil::possible_repaired_encodings(std::string supplied)
#ifndef QPDF_NO_WCHAR_T
static int
call_main_from_wmain(
- bool,
- int argc,
- wchar_t const* const argv[],
- std::function<int(int, char*[])> realmain)
+ bool, int argc, wchar_t const* const argv[], std::function<int(int, char*[])> realmain)
{
// argv contains UTF-16-encoded strings with a 16-bit wchar_t.
// Convert this to UTF-8-encoded strings for compatibility with
@@ -1992,8 +1899,7 @@ call_main_from_wmain(
for (size_t j = 0; j < std::wcslen(argv[i]); ++j) {
unsigned short codepoint = static_cast<unsigned short>(argv[i][j]);
utf16.append(1, static_cast<char>(QIntC::to_uchar(codepoint >> 8)));
- utf16.append(
- 1, static_cast<char>(QIntC::to_uchar(codepoint & 0xff)));
+ utf16.append(1, static_cast<char>(QIntC::to_uchar(codepoint & 0xff)));
}
std::string utf8 = QUtil::utf16_to_utf8(utf16);
utf8_argv.push_back(QUtil::make_unique_cstr(utf8));
@@ -2009,22 +1915,18 @@ call_main_from_wmain(
}
int
-QUtil::call_main_from_wmain(
- int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain)
+QUtil::call_main_from_wmain(int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain)
{
return ::call_main_from_wmain(true, argc, argv, realmain);
}
int
QUtil::call_main_from_wmain(
- int argc,
- wchar_t const* const argv[],
- std::function<int(int, char const* const[])> realmain)
+ int argc, wchar_t const* const argv[], std::function<int(int, char const* const[])> realmain)
{
- return ::call_main_from_wmain(
- true, argc, argv, [realmain](int new_argc, char* new_argv[]) {
- return realmain(new_argc, new_argv);
- });
+ return ::call_main_from_wmain(true, argc, argv, [realmain](int new_argc, char* new_argv[]) {
+ return realmain(new_argc, new_argv);
+ });
}
#endif // QPDF_NO_WCHAR_T
@@ -2080,12 +1982,10 @@ QUtil::get_max_memory_usage()
}
if (tag == "total") {
if (attrs.count("size") > 0) {
- result += QIntC::to_size(
- QUtil::string_to_ull(attrs["size"].c_str()));
+ result += QIntC::to_size(QUtil::string_to_ull(attrs["size"].c_str()));
}
} else if (tag == "system" && attrs["type"] == "max") {
- result += QIntC::to_size(
- QUtil::string_to_ull(attrs["size"].c_str()));
+ result += QIntC::to_size(QUtil::string_to_ull(attrs["size"].c_str()));
}
}
}
diff --git a/libqpdf/RC4_native.cc b/libqpdf/RC4_native.cc
index a29e78e4..03c25fe2 100644
--- a/libqpdf/RC4_native.cc
+++ b/libqpdf/RC4_native.cc
@@ -17,8 +17,7 @@ swap_byte(unsigned char& a, unsigned char& b)
RC4_native::RC4_native(unsigned char const* key_data, int key_len)
{
if (key_len == -1) {
- key_len =
- QIntC::to_int(strlen(reinterpret_cast<char const*>(key_data)));
+ key_len = QIntC::to_int(strlen(reinterpret_cast<char const*>(key_data)));
}
for (int i = 0; i < 256; ++i) {
@@ -37,8 +36,7 @@ RC4_native::RC4_native(unsigned char const* key_data, int key_len)
}
void
-RC4_native::process(
- unsigned char const* in_data, size_t len, unsigned char* out_data)
+RC4_native::process(unsigned char const* in_data, size_t len, unsigned char* out_data)
{
for (size_t i = 0; i < len; ++i) {
key.x = static_cast<unsigned char>((key.x + 1) % 256);
diff --git a/libqpdf/SF_FlateLzwDecode.cc b/libqpdf/SF_FlateLzwDecode.cc
index dc76a329..db663429 100644
--- a/libqpdf/SF_FlateLzwDecode.cc
+++ b/libqpdf/SF_FlateLzwDecode.cc
@@ -39,9 +39,7 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms)
} else {
filterable = false;
}
- } else if (
- (key == "/Columns") || (key == "/Colors") ||
- (key == "/BitsPerComponent")) {
+ } else if ((key == "/Columns") || (key == "/Colors") || (key == "/BitsPerComponent")) {
if (value.isInteger()) {
int val = value.getIntValueAsInt();
if (key == "/Columns") {
@@ -103,11 +101,9 @@ SF_FlateLzwDecode::getDecodePipeline(Pipeline* next)
}
if (lzw) {
- pipeline = std::make_shared<Pl_LZWDecoder>(
- "lzw decode", next, early_code_change);
+ pipeline = std::make_shared<Pl_LZWDecoder>("lzw decode", next, early_code_change);
} else {
- pipeline = std::make_shared<Pl_Flate>(
- "stream inflate", next, Pl_Flate::a_inflate);
+ pipeline = std::make_shared<Pl_Flate>("stream inflate", next, Pl_Flate::a_inflate);
}
this->pipelines.push_back(pipeline);
return pipeline.get();
diff --git a/libqpdf/SHA2_native.cc b/libqpdf/SHA2_native.cc
index ac7d6135..7386751e 100644
--- a/libqpdf/SHA2_native.cc
+++ b/libqpdf/SHA2_native.cc
@@ -73,16 +73,13 @@ SHA2_native::getRawDigest()
std::string result;
switch (bits) {
case 256:
- result = std::string(
- reinterpret_cast<char*>(this->sha256sum), sizeof(this->sha256sum));
+ result = std::string(reinterpret_cast<char*>(this->sha256sum), sizeof(this->sha256sum));
break;
case 384:
- result = std::string(
- reinterpret_cast<char*>(this->sha384sum), sizeof(this->sha384sum));
+ result = std::string(reinterpret_cast<char*>(this->sha384sum), sizeof(this->sha384sum));
break;
case 512:
- result = std::string(
- reinterpret_cast<char*>(this->sha512sum), sizeof(this->sha512sum));
+ result = std::string(reinterpret_cast<char*>(this->sha512sum), sizeof(this->sha512sum));
break;
default:
badBits();
diff --git a/libqpdf/SecureRandomDataProvider.cc b/libqpdf/SecureRandomDataProvider.cc
index f6ee559f..c47c8707 100644
--- a/libqpdf/SecureRandomDataProvider.cc
+++ b/libqpdf/SecureRandomDataProvider.cc
@@ -39,13 +39,8 @@ namespace
WindowsCryptProvider()
{
if (!CryptAcquireContextW(
- &crypt_prov,
- NULL,
- NULL,
- PROV_RSA_FULL,
- CRYPT_VERIFYCONTEXT)) {
- throw std::runtime_error(
- "unable to acquire crypt context: " + getErrorMessage());
+ &crypt_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
+ throw std::runtime_error("unable to acquire crypt context: " + getErrorMessage());
}
}
~WindowsCryptProvider()
@@ -74,8 +69,7 @@ namespace
std::string message(messageBuffer, size);
LocalFree(messageBuffer);
return (
- "error number " +
- QUtil::int_to_string_base(errorMessageID, 16) + ": " + message);
+ "error number " + QUtil::int_to_string_base(errorMessageID, 16) + ": " + message);
}
};
} // namespace
@@ -89,10 +83,7 @@ SecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len)
// Optimization: make the WindowsCryptProvider static as long as
// it can be done in a thread-safe fashion.
WindowsCryptProvider c;
- if (!CryptGenRandom(
- c.crypt_prov,
- static_cast<DWORD>(len),
- reinterpret_cast<BYTE*>(data))) {
+ if (!CryptGenRandom(c.crypt_prov, static_cast<DWORD>(len), reinterpret_cast<BYTE*>(data))) {
throw std::runtime_error("unable to generate secure random data");
}
@@ -107,8 +98,7 @@ SecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len)
fclose(f);
if (fr != len) {
throw std::runtime_error(
- "unable to read " + std::to_string(len) + " bytes from " +
- std::string(RANDOM_DEVICE));
+ "unable to read " + std::to_string(len) + " bytes from " + std::string(RANDOM_DEVICE));
}
# else
diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc
index 8f36195a..05568558 100644
--- a/libqpdf/qpdf-c.cc
+++ b/libqpdf/qpdf-c.cc
@@ -32,18 +32,14 @@ static void
call_read_memory(qpdf_data qpdf)
{
qpdf->qpdf->processMemoryFile(
- qpdf->filename,
- qpdf->buffer,
- QIntC::to_size(qpdf->size),
- qpdf->password);
+ qpdf->filename, qpdf->buffer, QIntC::to_size(qpdf->size), qpdf->password);
}
// must set qpdf->filename
static void
call_init_write(qpdf_data qpdf)
{
- qpdf->qpdf_writer =
- std::make_shared<QPDFWriter>(*(qpdf->qpdf), qpdf->filename);
+ qpdf->qpdf_writer = std::make_shared<QPDFWriter>(*(qpdf->qpdf), qpdf->filename);
}
static void
@@ -79,12 +75,10 @@ trap_errors(qpdf_data qpdf, std::function<void(qpdf_data)> fn)
qpdf->error = std::make_shared<QPDFExc>(e);
status |= QPDF_ERRORS;
} catch (std::runtime_error& e) {
- qpdf->error =
- std::make_shared<QPDFExc>(qpdf_e_system, "", "", 0, e.what());
+ qpdf->error = std::make_shared<QPDFExc>(qpdf_e_system, "", "", 0, e.what());
status |= QPDF_ERRORS;
} catch (std::exception& e) {
- qpdf->error =
- std::make_shared<QPDFExc>(qpdf_e_internal, "", "", 0, e.what());
+ qpdf->error = std::make_shared<QPDFExc>(qpdf_e_internal, "", "", 0, e.what());
status |= QPDF_ERRORS;
}
@@ -119,8 +113,7 @@ qpdf_cleanup(qpdf_data* qpdf)
if ((*qpdf)->error.get()) {
QTC::TC("qpdf", "qpdf-c cleanup warned about unhandled error");
*QPDFLogger::defaultLogger()->getWarn()
- << "WARNING: application did not handle error: "
- << (*qpdf)->error->what() << "\n";
+ << "WARNING: application did not handle error: " << (*qpdf)->error->what() << "\n";
}
delete *qpdf;
*qpdf = nullptr;
@@ -377,8 +370,7 @@ qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value)
if (!trailer.hasKey("/Info")) {
QTC::TC("qpdf", "qpdf-c add info to trailer");
trailer.replaceKey(
- "/Info",
- qpdf->qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary()));
+ "/Info", qpdf->qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary()));
} else {
QTC::TC("qpdf", "qpdf-c set-info-key use existing info");
}
@@ -765,8 +757,7 @@ qpdf_set_minimum_pdf_version(qpdf_data qpdf, char const* version)
}
void
-qpdf_set_minimum_pdf_version_and_extension(
- qpdf_data qpdf, char const* version, int extension_level)
+qpdf_set_minimum_pdf_version_and_extension(qpdf_data qpdf, char const* version, int extension_level)
{
QTC::TC("qpdf", "qpdf-c called qpdf_set_minimum_pdf_version");
qpdf->qpdf_writer->setMinimumPDFVersion(version, extension_level);
@@ -779,8 +770,7 @@ qpdf_force_pdf_version(qpdf_data qpdf, char const* version)
}
void
-qpdf_force_pdf_version_and_extension(
- qpdf_data qpdf, char const* version, int extension_level)
+qpdf_force_pdf_version_and_extension(qpdf_data qpdf, char const* version, int extension_level)
{
QTC::TC("qpdf", "qpdf-c called qpdf_force_pdf_version");
qpdf->qpdf_writer->forcePDFVersion(version, extension_level);
@@ -788,15 +778,12 @@ qpdf_force_pdf_version_and_extension(
void
qpdf_register_progress_reporter(
- qpdf_data qpdf,
- void (*report_progress)(int percent, void* data),
- void* data)
+ qpdf_data qpdf, void (*report_progress)(int percent, void* data), void* data)
{
QTC::TC("qpdf", "qpdf-c registered progress reporter");
qpdf->qpdf_writer->registerProgressReporter(
- std::shared_ptr<QPDFWriter::ProgressReporter>(
- new QPDFWriter::FunctionProgressReporter(
- std::bind(report_progress, std::placeholders::_1, data))));
+ std::shared_ptr<QPDFWriter::ProgressReporter>(new QPDFWriter::FunctionProgressReporter(
+ std::bind(report_progress, std::placeholders::_1, data))));
}
QPDF_ERROR_CODE
@@ -817,23 +804,16 @@ qpdf_silence_errors(qpdf_data qpdf)
template <class RET>
static RET
-trap_oh_errors(
- qpdf_data qpdf,
- std::function<RET()> fallback,
- std::function<RET(qpdf_data)> fn)
+trap_oh_errors(qpdf_data qpdf, std::function<RET()> fallback, std::function<RET(qpdf_data)> fn)
{
// Note: fallback is a function so we don't have to evaluate it
// unless needed. This is important because sometimes the fallback
// creates an object.
RET ret;
- QPDF_ERROR_CODE status =
- trap_errors(qpdf, [&ret, fn](qpdf_data q) { ret = fn(q); });
+ QPDF_ERROR_CODE status = trap_errors(qpdf, [&ret, fn](qpdf_data q) { ret = fn(q); });
if (status & QPDF_ERRORS) {
if (!qpdf->silence_errors) {
- QTC::TC(
- "qpdf",
- "qpdf-c warn about oh error",
- qpdf->oh_error_occurred ? 0 : 1);
+ QTC::TC("qpdf", "qpdf-c warn about oh error", qpdf->oh_error_occurred ? 0 : 1);
if (!qpdf->oh_error_occurred) {
qpdf->warnings.push_back(QPDFExc(
qpdf_e_internal,
@@ -845,8 +825,7 @@ trap_oh_errors(
" to ERROR HANDLING in qpdf-c.h"));
qpdf->oh_error_occurred = true;
}
- *QPDFLogger::defaultLogger()->getError()
- << qpdf->error->what() << "\n";
+ *QPDFLogger::defaultLogger()->getError() << qpdf->error->what() << "\n";
}
return fallback();
}
@@ -911,20 +890,18 @@ qpdf_oh
qpdf_get_trailer(qpdf_data qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_get_trailer");
- return trap_oh_errors<qpdf_oh>(
- qpdf, return_uninitialized(qpdf), [](qpdf_data q) {
- return new_object(q, q->qpdf->getTrailer());
- });
+ return trap_oh_errors<qpdf_oh>(qpdf, return_uninitialized(qpdf), [](qpdf_data q) {
+ return new_object(q, q->qpdf->getTrailer());
+ });
}
qpdf_oh
qpdf_get_root(qpdf_data qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_get_root");
- return trap_oh_errors<qpdf_oh>(
- qpdf, return_uninitialized(qpdf), [](qpdf_data q) {
- return new_object(q, q->qpdf->getRoot());
- });
+ return trap_oh_errors<qpdf_oh>(qpdf, return_uninitialized(qpdf), [](qpdf_data q) {
+ return new_object(q, q->qpdf->getRoot());
+ });
}
qpdf_oh
@@ -959,14 +936,12 @@ do_with_oh(
}
static void
-do_with_oh_void(
- qpdf_data qpdf, qpdf_oh oh, std::function<void(QPDFObjectHandle&)> fn)
+do_with_oh_void(qpdf_data qpdf, qpdf_oh oh, std::function<void(QPDFObjectHandle&)> fn)
{
- do_with_oh<bool>(
- qpdf, oh, return_T<bool>(false), [fn](QPDFObjectHandle& o) {
- fn(o);
- return true; // unused
- });
+ do_with_oh<bool>(qpdf, oh, return_T<bool>(false), [fn](QPDFObjectHandle& o) {
+ fn(o);
+ return true; // unused
+ });
}
void
@@ -983,9 +958,7 @@ qpdf_oh_is_initialized(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_initialized");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isInitialized();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isInitialized(); });
}
QPDF_BOOL
@@ -1009,9 +982,7 @@ qpdf_oh_is_integer(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_integer");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isInteger();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isInteger(); });
}
QPDF_BOOL
@@ -1035,9 +1006,7 @@ qpdf_oh_is_string(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_string");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isString();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isString(); });
}
QPDF_BOOL
@@ -1045,9 +1014,7 @@ qpdf_oh_is_operator(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_operator");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isOperator();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isOperator(); });
}
QPDF_BOOL
@@ -1055,9 +1022,7 @@ qpdf_oh_is_inline_image(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_inline_image");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isInlineImage();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isInlineImage(); });
}
QPDF_BOOL
@@ -1065,9 +1030,7 @@ qpdf_oh_is_array(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_array");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isArray();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isArray(); });
}
QPDF_BOOL
@@ -1075,9 +1038,7 @@ qpdf_oh_is_dictionary(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_dictionary");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isDictionary();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isDictionary(); });
}
QPDF_BOOL
@@ -1085,9 +1046,7 @@ qpdf_oh_is_stream(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_stream");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isStream();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isStream(); });
}
QPDF_BOOL
@@ -1095,9 +1054,7 @@ qpdf_oh_is_indirect(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_indirect");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isIndirect();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isIndirect(); });
}
QPDF_BOOL
@@ -1105,51 +1062,42 @@ qpdf_oh_is_scalar(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_scalar");
return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- return o.isScalar();
- });
+ qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isScalar(); });
}
QPDF_BOOL
qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_number");
- return o.isNumber();
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_number");
+ return o.isNumber();
+ });
}
QPDF_BOOL
qpdf_oh_is_name_and_equals(qpdf_data qpdf, qpdf_oh oh, char const* name)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [name](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_name_and_equals");
- return o.isNameAndEquals(name);
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [name](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_name_and_equals");
+ return o.isNameAndEquals(name);
+ });
}
QPDF_BOOL
-qpdf_oh_is_dictionary_of_type(
- qpdf_data qpdf, qpdf_oh oh, char const* type, char const* subtype)
+qpdf_oh_is_dictionary_of_type(qpdf_data qpdf, qpdf_oh oh, char const* type, char const* subtype)
{
auto stype = (subtype == nullptr) ? "" : subtype;
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [type, stype](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_dictionary_of_type");
- return o.isDictionaryOfType(type, stype);
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [type, stype](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_dictionary_of_type");
+ return o.isDictionaryOfType(type, stype);
+ });
}
qpdf_object_type_e
qpdf_oh_get_type_code(qpdf_data qpdf, qpdf_oh oh)
{
return do_with_oh<qpdf_object_type_e>(
- qpdf,
- oh,
- return_T<qpdf_object_type_e>(ot_uninitialized),
- [](QPDFObjectHandle& o) {
+ qpdf, oh, return_T<qpdf_object_type_e>(ot_uninitialized), [](QPDFObjectHandle& o) {
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_type_code");
return o.getTypeCode();
});
@@ -1180,9 +1128,7 @@ qpdf_oh_wrap_in_array(qpdf_data qpdf, qpdf_oh oh)
} else {
QTC::TC("qpdf", "qpdf-c non-array to wrap_in_array");
return new_object(
- qpdf,
- QPDFObjectHandle::newArray(
- std::vector<QPDFObjectHandle>{qoh}));
+ qpdf, QPDFObjectHandle::newArray(std::vector<QPDFObjectHandle>{qoh}));
}
});
}
@@ -1191,55 +1137,50 @@ qpdf_oh
qpdf_oh_parse(qpdf_data qpdf, char const* object_str)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_parse");
- return trap_oh_errors<qpdf_oh>(
- qpdf, return_uninitialized(qpdf), [object_str](qpdf_data q) {
- return new_object(q, QPDFObjectHandle::parse(object_str));
- });
+ return trap_oh_errors<qpdf_oh>(qpdf, return_uninitialized(qpdf), [object_str](qpdf_data q) {
+ return new_object(q, QPDFObjectHandle::parse(object_str));
+ });
}
QPDF_BOOL
qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_bool_value");
- return o.getBoolValue();
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_bool_value");
+ return o.getBoolValue();
+ });
}
QPDF_BOOL
qpdf_oh_get_value_as_bool(qpdf_data qpdf, qpdf_oh oh, QPDF_BOOL* value)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_bool");
- bool v = *value;
- QPDF_BOOL result = o.getValueAsBool(v);
- if (result) {
- *value = v;
- }
- return result;
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_bool");
+ bool v = *value;
+ QPDF_BOOL result = o.getValueAsBool(v);
+ if (result) {
+ *value = v;
+ }
+ return result;
+ });
}
long long
qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh)
{
- return do_with_oh<long long>(
- qpdf, oh, return_T<long long>(0LL), [](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_int_value");
- return o.getIntValue();
- });
+ return do_with_oh<long long>(qpdf, oh, return_T<long long>(0LL), [](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_int_value");
+ return o.getIntValue();
+ });
}
QPDF_BOOL
qpdf_oh_get_value_as_longlong(qpdf_data qpdf, qpdf_oh oh, long long* value)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_longlong");
- return o.getValueAsInt(*value);
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_longlong");
+ return o.getValueAsInt(*value);
+ });
}
int
@@ -1254,11 +1195,10 @@ qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh)
QPDF_BOOL
qpdf_oh_get_value_as_int(qpdf_data qpdf, qpdf_oh oh, int* value)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_int");
- return o.getValueAsInt(*value);
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_int");
+ return o.getValueAsInt(*value);
+ });
}
unsigned long long
@@ -1272,34 +1212,30 @@ qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh)
}
QPDF_BOOL
-qpdf_oh_get_value_as_ulonglong(
- qpdf_data qpdf, qpdf_oh oh, unsigned long long* value)
+qpdf_oh_get_value_as_ulonglong(qpdf_data qpdf, qpdf_oh oh, unsigned long long* value)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_ulonglong");
- return o.getValueAsUInt(*value);
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_ulonglong");
+ return o.getValueAsUInt(*value);
+ });
}
unsigned int
qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh)
{
- return do_with_oh<unsigned int>(
- qpdf, oh, return_T<unsigned int>(0U), [](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_uint_value_as_uint");
- return o.getUIntValueAsUInt();
- });
+ return do_with_oh<unsigned int>(qpdf, oh, return_T<unsigned int>(0U), [](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_uint_value_as_uint");
+ return o.getUIntValueAsUInt();
+ });
}
QPDF_BOOL
qpdf_oh_get_value_as_uint(qpdf_data qpdf, qpdf_oh oh, unsigned int* value)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_uint");
- return o.getValueAsUInt(*value);
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_uint");
+ return o.getValueAsUInt(*value);
+ });
}
char const*
@@ -1314,8 +1250,7 @@ qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh)
}
QPDF_BOOL
-qpdf_oh_get_value_as_real(
- qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
+qpdf_oh_get_value_as_real(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
{
return do_with_oh<QPDF_BOOL>(
qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
@@ -1332,21 +1267,19 @@ qpdf_oh_get_value_as_real(
double
qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh)
{
- return do_with_oh<double>(
- qpdf, oh, return_T<double>(0.0), [](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_numeric_value");
- return o.getNumericValue();
- });
+ return do_with_oh<double>(qpdf, oh, return_T<double>(0.0), [](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_numeric_value");
+ return o.getNumericValue();
+ });
}
QPDF_BOOL
qpdf_oh_get_value_as_number(qpdf_data qpdf, qpdf_oh oh, double* value)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_number");
- return o.getValueAsNumber(*value);
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_number");
+ return o.getValueAsNumber(*value);
+ });
}
char const*
@@ -1361,8 +1294,7 @@ qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh)
}
QPDF_BOOL
-qpdf_oh_get_value_as_name(
- qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
+qpdf_oh_get_value_as_name(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
{
return do_with_oh<QPDF_BOOL>(
qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
@@ -1388,8 +1320,7 @@ qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh)
}
QPDF_BOOL
-qpdf_oh_get_value_as_string(
- qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
+qpdf_oh_get_value_as_string(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
{
return do_with_oh<QPDF_BOOL>(
qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
@@ -1415,8 +1346,7 @@ qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh)
}
QPDF_BOOL
-qpdf_oh_get_value_as_utf8(
- qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
+qpdf_oh_get_value_as_utf8(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
{
return do_with_oh<QPDF_BOOL>(
qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
@@ -1434,10 +1364,7 @@ char const*
qpdf_oh_get_binary_string_value(qpdf_data qpdf, qpdf_oh oh, size_t* length)
{
return do_with_oh<char const*>(
- qpdf,
- oh,
- return_T<char const*>(""),
- [qpdf, length](QPDFObjectHandle& o) {
+ qpdf, oh, return_T<char const*>(""), [qpdf, length](QPDFObjectHandle& o) {
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_binary_string_value");
qpdf->tmp_string = o.getStringValue();
*length = qpdf->tmp_string.length();
@@ -1449,10 +1376,7 @@ char const*
qpdf_oh_get_binary_utf8_value(qpdf_data qpdf, qpdf_oh oh, size_t* length)
{
return do_with_oh<char const*>(
- qpdf,
- oh,
- return_T<char const*>(""),
- [qpdf, length](QPDFObjectHandle& o) {
+ qpdf, oh, return_T<char const*>(""), [qpdf, length](QPDFObjectHandle& o) {
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_binary_utf8_value");
qpdf->tmp_string = o.getUTF8Value();
*length = qpdf->tmp_string.length();
@@ -1472,11 +1396,10 @@ qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh)
qpdf_oh
qpdf_oh_get_array_item(qpdf_data qpdf, qpdf_oh oh, int n)
{
- return do_with_oh<qpdf_oh>(
- qpdf, oh, return_null(qpdf), [qpdf, n](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_array_item");
- return new_object(qpdf, o.getArrayItem(n));
- });
+ return do_with_oh<qpdf_oh>(qpdf, oh, return_null(qpdf), [qpdf, n](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_array_item");
+ return new_object(qpdf, o.getArrayItem(n));
+ });
}
void
@@ -1516,41 +1439,37 @@ qpdf_oh_dict_next_key(qpdf_data qpdf)
QPDF_BOOL
qpdf_oh_has_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [key](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_has_key");
- return o.hasKey(key);
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [key](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_has_key");
+ return o.hasKey(key);
+ });
}
qpdf_oh
qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
{
- return do_with_oh<qpdf_oh>(
- qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key");
- return new_object(qpdf, o.getKey(key));
- });
+ return do_with_oh<qpdf_oh>(qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key");
+ return new_object(qpdf, o.getKey(key));
+ });
}
qpdf_oh
qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key)
{
- return do_with_oh<qpdf_oh>(
- qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key_if_dict");
- return new_object(qpdf, o.getKeyIfDict(key));
- });
+ return do_with_oh<qpdf_oh>(qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key_if_dict");
+ return new_object(qpdf, o.getKeyIfDict(key));
+ });
}
QPDF_BOOL
qpdf_oh_is_or_has_name(qpdf_data qpdf, qpdf_oh oh, char const* key)
{
- return do_with_oh<QPDF_BOOL>(
- qpdf, oh, return_false, [key](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_or_has_name");
- return o.isOrHasName(key);
- });
+ return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [key](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_or_has_name");
+ return o.isOrHasName(key);
+ });
}
qpdf_oh
@@ -1620,18 +1539,14 @@ qpdf_oh
qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_binary_string");
- return new_object(
- qpdf, QPDFObjectHandle::newString(std::string(str, length)));
+ return new_object(qpdf, QPDFObjectHandle::newString(std::string(str, length)));
}
qpdf_oh
-qpdf_oh_new_binary_unicode_string(
- qpdf_data qpdf, char const* utf8_str, size_t length)
+qpdf_oh_new_binary_unicode_string(qpdf_data qpdf, char const* utf8_str, size_t length)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_binary_unicode_string");
- return new_object(
- qpdf,
- QPDFObjectHandle::newUnicodeString(std::string(utf8_str, length)));
+ return new_object(qpdf, QPDFObjectHandle::newUnicodeString(std::string(utf8_str, length)));
}
qpdf_oh
@@ -1667,10 +1582,9 @@ qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh)
qpdf_oh
qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh)
{
- return do_with_oh<qpdf_oh>(
- qpdf, oh, return_uninitialized(qpdf), [qpdf](QPDFObjectHandle& o) {
- return new_object(qpdf, qpdf->qpdf->makeIndirectObject(o));
- });
+ return do_with_oh<qpdf_oh>(qpdf, oh, return_uninitialized(qpdf), [qpdf](QPDFObjectHandle& o) {
+ return new_object(qpdf, qpdf->qpdf->makeIndirectObject(o));
+ });
}
static QPDFObjectHandle
@@ -1738,8 +1652,7 @@ qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
}
void
-qpdf_oh_replace_or_remove_key(
- qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item)
+qpdf_oh_replace_or_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item)
{
do_with_oh_void(qpdf, oh, [qpdf, key, item](QPDFObjectHandle& o) {
QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_or_remove_key");
@@ -1750,11 +1663,10 @@ qpdf_oh_replace_or_remove_key(
qpdf_oh
qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh)
{
- return do_with_oh<qpdf_oh>(
- qpdf, oh, return_null(qpdf), [qpdf](QPDFObjectHandle& o) {
- QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_dict");
- return new_object(qpdf, o.getDict());
- });
+ return do_with_oh<qpdf_oh>(qpdf, oh, return_null(qpdf), [qpdf](QPDFObjectHandle& o) {
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_dict");
+ return new_object(qpdf, o.getDict());
+ });
}
int
@@ -1809,14 +1721,10 @@ qpdf_oh_unparse_binary(qpdf_data qpdf, qpdf_oh oh)
}
qpdf_oh
-qpdf_oh_copy_foreign_object(
- qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh)
+qpdf_oh_copy_foreign_object(qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh)
{
return do_with_oh<qpdf_oh>(
- other_qpdf,
- foreign_oh,
- return_uninitialized(qpdf),
- [qpdf](QPDFObjectHandle& o) {
+ other_qpdf, foreign_oh, return_uninitialized(qpdf), [qpdf](QPDFObjectHandle& o) {
QTC::TC("qpdf", "qpdf-c called qpdf_oh_copy_foreign_object");
return new_object(qpdf, qpdf->qpdf->copyForeignObject(o));
});
@@ -1831,39 +1739,31 @@ qpdf_oh_get_stream_data(
unsigned char** bufp,
size_t* len)
{
- return trap_errors(
- qpdf, [stream_oh, decode_level, filtered, bufp, len](qpdf_data q) {
- auto stream = qpdf_oh_item_internal(q, stream_oh);
- Pipeline* p = nullptr;
- Pl_Buffer buf("stream data");
- if (bufp) {
- p = &buf;
+ return trap_errors(qpdf, [stream_oh, decode_level, filtered, bufp, len](qpdf_data q) {
+ auto stream = qpdf_oh_item_internal(q, stream_oh);
+ Pipeline* p = nullptr;
+ Pl_Buffer buf("stream data");
+ if (bufp) {
+ p = &buf;
+ }
+ bool was_filtered = false;
+ if (stream.pipeStreamData(p, &was_filtered, 0, decode_level, false, false)) {
+ QTC::TC("qpdf", "qpdf-c stream data buf set", bufp ? 0 : 1);
+ if (p && bufp && len) {
+ buf.getMallocBuffer(bufp, len);
}
- bool was_filtered = false;
- if (stream.pipeStreamData(
- p, &was_filtered, 0, decode_level, false, false)) {
- QTC::TC("qpdf", "qpdf-c stream data buf set", bufp ? 0 : 1);
- if (p && bufp && len) {
- buf.getMallocBuffer(bufp, len);
- }
- QTC::TC(
- "qpdf",
- "qpdf-c stream data filtered set",
- filtered ? 0 : 1);
- if (filtered) {
- *filtered = was_filtered ? QPDF_TRUE : QPDF_FALSE;
- }
- } else {
- throw std::runtime_error(
- "unable to access stream data for stream " +
- stream.unparse());
+ QTC::TC("qpdf", "qpdf-c stream data filtered set", filtered ? 0 : 1);
+ if (filtered) {
+ *filtered = was_filtered ? QPDF_TRUE : QPDF_FALSE;
}
- });
+ } else {
+ throw std::runtime_error("unable to access stream data for stream " + stream.unparse());
+ }
+ });
}
QPDF_ERROR_CODE
-qpdf_oh_get_page_content_data(
- qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len)
+qpdf_oh_get_page_content_data(qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len)
{
return trap_errors(qpdf, [page_oh, bufp, len](qpdf_data q) {
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_page_content_data");
@@ -1884,17 +1784,13 @@ qpdf_oh_replace_stream_data(
qpdf_oh decode_parms_oh)
{
do_with_oh_void(
- qpdf,
- stream_oh,
- [qpdf, buf, len, filter_oh, decode_parms_oh](QPDFObjectHandle& o) {
+ qpdf, stream_oh, [qpdf, buf, len, filter_oh, decode_parms_oh](QPDFObjectHandle& o) {
QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_stream_data");
auto filter = qpdf_oh_item_internal(qpdf, filter_oh);
auto decode_parms = qpdf_oh_item_internal(qpdf, decode_parms_oh);
// XXX test with binary data with null
o.replaceStreamData(
- std::string(reinterpret_cast<char const*>(buf), len),
- filter,
- decode_parms);
+ std::string(reinterpret_cast<char const*>(buf), len), filter, decode_parms);
});
}
@@ -1903,9 +1799,8 @@ qpdf_get_num_pages(qpdf_data qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_num_pages");
int n = -1;
- QPDF_ERROR_CODE code = trap_errors(qpdf, [&n](qpdf_data q) {
- n = QIntC::to_int(q->qpdf->getAllPages().size());
- });
+ QPDF_ERROR_CODE code =
+ trap_errors(qpdf, [&n](qpdf_data q) { n = QIntC::to_int(q->qpdf->getAllPages().size()); });
if (code & QPDF_ERRORS) {
return -1;
}
@@ -1917,9 +1812,8 @@ qpdf_get_page_n(qpdf_data qpdf, size_t i)
{
QTC::TC("qpdf", "qpdf-c called qpdf_get_page_n");
qpdf_oh result = 0;
- QPDF_ERROR_CODE code = trap_errors(qpdf, [&result, i](qpdf_data q) {
- result = new_object(q, q->qpdf->getAllPages().at(i));
- });
+ QPDF_ERROR_CODE code = trap_errors(
+ qpdf, [&result, i](qpdf_data q) { result = new_object(q, q->qpdf->getAllPages().at(i)); });
if ((code & QPDF_ERRORS) || (result == 0)) {
return qpdf_oh_new_uninitialized(qpdf);
}
@@ -1930,8 +1824,7 @@ QPDF_ERROR_CODE
qpdf_update_all_pages_cache(qpdf_data qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_update_all_pages_cache");
- return trap_errors(
- qpdf, [](qpdf_data q) { q->qpdf->updateAllPagesCache(); });
+ return trap_errors(qpdf, [](qpdf_data q) { q->qpdf->updateAllPagesCache(); });
}
int
@@ -1940,9 +1833,8 @@ qpdf_find_page_by_id(qpdf_data qpdf, int objid, int generation)
QTC::TC("qpdf", "qpdf-c called qpdf_find_page_by_id");
int n = -1;
QPDFObjGen og(objid, generation);
- QPDF_ERROR_CODE code = trap_errors(qpdf, [&n, &og](qpdf_data q) {
- n = QIntC::to_int(q->qpdf->findPage(og));
- });
+ QPDF_ERROR_CODE code =
+ trap_errors(qpdf, [&n, &og](qpdf_data q) { n = QIntC::to_int(q->qpdf->findPage(og)); });
if (code & QPDF_ERRORS) {
return -1;
}
@@ -1953,44 +1845,35 @@ int
qpdf_find_page_by_oh(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_find_page_by_oh");
- return do_with_oh<int>(
- qpdf, oh, return_T<int>(-1), [qpdf](QPDFObjectHandle& o) {
- return qpdf->qpdf->findPage(o);
- });
+ return do_with_oh<int>(qpdf, oh, return_T<int>(-1), [qpdf](QPDFObjectHandle& o) {
+ return qpdf->qpdf->findPage(o);
+ });
}
QPDF_ERROR_CODE
qpdf_push_inherited_attributes_to_page(qpdf_data qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_push_inherited_attributes_to_page");
- return trap_errors(
- qpdf, [](qpdf_data q) { q->qpdf->pushInheritedAttributesToPage(); });
+ return trap_errors(qpdf, [](qpdf_data q) { q->qpdf->pushInheritedAttributesToPage(); });
}
QPDF_ERROR_CODE
-qpdf_add_page(
- qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL first)
+qpdf_add_page(qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL first)
{
QTC::TC("qpdf", "qpdf-c called qpdf_add_page");
auto page = qpdf_oh_item_internal(newpage_qpdf, newpage);
- return trap_errors(
- qpdf, [&page, first](qpdf_data q) { q->qpdf->addPage(page, first); });
+ return trap_errors(qpdf, [&page, first](qpdf_data q) { q->qpdf->addPage(page, first); });
}
QPDF_ERROR_CODE
qpdf_add_page_at(
- qpdf_data qpdf,
- qpdf_data newpage_qpdf,
- qpdf_oh newpage,
- QPDF_BOOL before,
- qpdf_oh refpage)
+ qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL before, qpdf_oh refpage)
{
QTC::TC("qpdf", "qpdf-c called qpdf_add_page_at");
auto page = qpdf_oh_item_internal(newpage_qpdf, newpage);
auto ref = qpdf_oh_item_internal(qpdf, refpage);
- return trap_errors(qpdf, [&page, before, &ref](qpdf_data q) {
- q->qpdf->addPageAt(page, before, ref);
- });
+ return trap_errors(
+ qpdf, [&page, before, &ref](qpdf_data q) { q->qpdf->addPageAt(page, before, ref); });
}
QPDF_ERROR_CODE
@@ -2006,24 +1889,20 @@ qpdf_create_from_json_file(qpdf_data qpdf, char const* filename)
{
QPDF_ERROR_CODE status = QPDF_SUCCESS;
qpdf->filename = filename;
- status = trap_errors(
- qpdf, [](qpdf_data q) { q->qpdf->createFromJSON(q->filename); });
+ status = trap_errors(qpdf, [](qpdf_data q) { q->qpdf->createFromJSON(q->filename); });
return status;
}
QPDF_ERROR_CODE
-qpdf_create_from_json_data(
- qpdf_data qpdf, char const* buffer, unsigned long long size)
+qpdf_create_from_json_data(qpdf_data qpdf, char const* buffer, unsigned long long size)
{
QPDF_ERROR_CODE status = QPDF_SUCCESS;
qpdf->filename = "json buffer";
qpdf->buffer = buffer;
qpdf->size = size;
- auto b =
- new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size));
+ auto b = new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size));
auto is = std::make_shared<BufferInputSource>(qpdf->filename, b, true);
- status =
- trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->createFromJSON(is); });
+ status = trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->createFromJSON(is); });
return status;
}
@@ -2031,21 +1910,17 @@ QPDF_ERROR_CODE
qpdf_update_from_json_file(qpdf_data qpdf, char const* filename)
{
QPDF_ERROR_CODE status = QPDF_SUCCESS;
- status = trap_errors(
- qpdf, [filename](qpdf_data q) { q->qpdf->updateFromJSON(filename); });
+ status = trap_errors(qpdf, [filename](qpdf_data q) { q->qpdf->updateFromJSON(filename); });
return status;
}
QPDF_ERROR_CODE
-qpdf_update_from_json_data(
- qpdf_data qpdf, char const* buffer, unsigned long long size)
+qpdf_update_from_json_data(qpdf_data qpdf, char const* buffer, unsigned long long size)
{
QPDF_ERROR_CODE status = QPDF_SUCCESS;
- auto b =
- new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size));
+ auto b = new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size));
auto is = std::make_shared<BufferInputSource>(qpdf->filename, b, true);
- status =
- trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->updateFromJSON(is); });
+ status = trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->updateFromJSON(is); });
return status;
}
@@ -2070,19 +1945,10 @@ qpdf_write_json(
}
status = trap_errors(
qpdf,
- [version,
- p,
- decode_level,
- json_stream_data,
- file_prefix,
- &wanted_objects_set](qpdf_data q) {
+ [version, p, decode_level, json_stream_data, file_prefix, &wanted_objects_set](
+ qpdf_data q) {
q->qpdf->writeJSON(
- version,
- p.get(),
- decode_level,
- json_stream_data,
- file_prefix,
- wanted_objects_set);
+ version, p.get(), decode_level, json_stream_data, file_prefix, wanted_objects_set);
});
return status;
}
diff --git a/libqpdf/qpdf/JSONHandler.hh b/libqpdf/qpdf/JSONHandler.hh
index 9a53e028..e4a76af5 100644
--- a/libqpdf/qpdf/JSONHandler.hh
+++ b/libqpdf/qpdf/JSONHandler.hh
@@ -27,14 +27,10 @@ class JSONHandler
// called. There is no "final" handler -- if the top-level is a
// dictionary or array, just use its end handler.
- typedef std::function<void(std::string const& path, JSON value)>
- json_handler_t;
+ typedef std::function<void(std::string const& path, JSON value)> json_handler_t;
typedef std::function<void(std::string const& path)> void_handler_t;
- typedef std::function<void(
- std::string const& path, std::string const& value)>
- string_handler_t;
- typedef std::function<void(std::string const& path, bool value)>
- bool_handler_t;
+ typedef std::function<void(std::string const& path, std::string const& value)> string_handler_t;
+ typedef std::function<void(std::string const& path, bool value)> bool_handler_t;
// If an any handler is added, it will be called for any value
// including null, and no other handler will be called.
@@ -48,14 +44,11 @@ class JSONHandler
void addBoolHandler(bool_handler_t fn);
void addDictHandlers(json_handler_t start_fn, void_handler_t end_fn);
- void
- addDictKeyHandler(std::string const& key, std::shared_ptr<JSONHandler>);
+ void addDictKeyHandler(std::string const& key, std::shared_ptr<JSONHandler>);
void addFallbackDictHandler(std::shared_ptr<JSONHandler>);
void addArrayHandlers(
- json_handler_t start_fn,
- void_handler_t end_fn,
- std::shared_ptr<JSONHandler> item_handlers);
+ json_handler_t start_fn, void_handler_t end_fn, std::shared_ptr<JSONHandler> item_handlers);
// Apply handlers recursively to a JSON object.
void handle(std::string const& path, JSON j);
diff --git a/libqpdf/qpdf/MD5.hh b/libqpdf/qpdf/MD5.hh
index f2c2fdfe..977cd4b5 100644
--- a/libqpdf/qpdf/MD5.hh
+++ b/libqpdf/qpdf/MD5.hh
@@ -38,14 +38,10 @@ class MD5
// Convenience functions
static std::string getDataChecksum(char const* buf, size_t len);
- static std::string
- getFileChecksum(char const* filename, qpdf_offset_t up_to_offset = -1);
- static bool
- checkDataChecksum(char const* const checksum, char const* buf, size_t len);
+ static std::string getFileChecksum(char const* filename, qpdf_offset_t up_to_offset = -1);
+ static bool checkDataChecksum(char const* const checksum, char const* buf, size_t len);
static bool checkFileChecksum(
- char const* const checksum,
- char const* filename,
- qpdf_offset_t up_to_offset = -1);
+ char const* const checksum, char const* filename, qpdf_offset_t up_to_offset = -1);
private:
void init();
diff --git a/libqpdf/qpdf/NNTree.hh b/libqpdf/qpdf/NNTree.hh
index 09ce3313..6345b105 100644
--- a/libqpdf/qpdf/NNTree.hh
+++ b/libqpdf/qpdf/NNTree.hh
@@ -76,11 +76,9 @@ class NNTreeIterator
void addPathElement(QPDFObjectHandle const& node, int kid_number);
QPDFObjectHandle getNextKid(PathElement& element, bool backward);
void increment(bool backward);
- void
- resetLimits(QPDFObjectHandle node, std::list<PathElement>::iterator parent);
+ void resetLimits(QPDFObjectHandle node, std::list<PathElement>::iterator parent);
- void
- split(QPDFObjectHandle to_split, std::list<PathElement>::iterator parent);
+ void split(QPDFObjectHandle to_split, std::list<PathElement>::iterator parent);
std::list<PathElement>::iterator lastPathElement();
NNTreeImpl& impl;
@@ -97,11 +95,7 @@ class NNTreeImpl
public:
typedef NNTreeIterator iterator;
- NNTreeImpl(
- NNTreeDetails const&,
- QPDF&,
- QPDFObjectHandle&,
- bool auto_repair = true);
+ NNTreeImpl(NNTreeDetails const&, QPDF&, QPDFObjectHandle&, bool auto_repair = true);
iterator begin();
iterator end();
iterator last();
@@ -117,16 +111,14 @@ class NNTreeImpl
private:
void repair();
- iterator
- findInternal(QPDFObjectHandle key, bool return_prev_if_not_found = false);
+ iterator findInternal(QPDFObjectHandle key, bool return_prev_if_not_found = false);
int withinLimits(QPDFObjectHandle key, QPDFObjectHandle node);
int binarySearch(
QPDFObjectHandle key,
QPDFObjectHandle items,
int num_items,
bool return_prev_if_not_found,
- int (NNTreeImpl::*compare)(
- QPDFObjectHandle& key, QPDFObjectHandle& arr, int item));
+ int (NNTreeImpl::*compare)(QPDFObjectHandle& key, QPDFObjectHandle& arr, int item));
int compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx);
int compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx);
diff --git a/libqpdf/qpdf/OffsetInputSource.hh b/libqpdf/qpdf/OffsetInputSource.hh
index fdc1a404..2d506f80 100644
--- a/libqpdf/qpdf/OffsetInputSource.hh
+++ b/libqpdf/qpdf/OffsetInputSource.hh
@@ -9,8 +9,7 @@
class OffsetInputSource: public InputSource
{
public:
- OffsetInputSource(
- std::shared_ptr<InputSource>, qpdf_offset_t global_offset);
+ OffsetInputSource(std::shared_ptr<InputSource>, qpdf_offset_t global_offset);
~OffsetInputSource() override = default;
qpdf_offset_t findAndSkipNextEOL() override;
diff --git a/libqpdf/qpdf/Pl_LZWDecoder.hh b/libqpdf/qpdf/Pl_LZWDecoder.hh
index 46cce7ba..b2135aa9 100644
--- a/libqpdf/qpdf/Pl_LZWDecoder.hh
+++ b/libqpdf/qpdf/Pl_LZWDecoder.hh
@@ -9,8 +9,7 @@
class Pl_LZWDecoder: public Pipeline
{
public:
- Pl_LZWDecoder(
- char const* identifier, Pipeline* next, bool early_code_change);
+ Pl_LZWDecoder(char const* identifier, Pipeline* next, bool early_code_change);
virtual ~Pl_LZWDecoder() = default;
virtual void write(unsigned char const* buf, size_t len);
virtual void finish();
diff --git a/libqpdf/qpdf/QPDFArgParser.hh b/libqpdf/qpdf/QPDFArgParser.hh
index 759ad148..d9e33b5a 100644
--- a/libqpdf/qpdf/QPDFArgParser.hh
+++ b/libqpdf/qpdf/QPDFArgParser.hh
@@ -53,23 +53,17 @@ class QPDFArgParser
void selectOptionTable(std::string const& name);
// Register a new options table. This also selects the option table.
- void registerOptionTable(
- std::string const& name, bare_arg_handler_t end_handler);
+ void registerOptionTable(std::string const& name, bare_arg_handler_t end_handler);
// Add handlers for options in the current table
void addPositional(param_arg_handler_t);
void addBare(std::string const& arg, bare_arg_handler_t);
- void addRequiredParameter(
- std::string const& arg,
- param_arg_handler_t,
- char const* parameter_name);
+ void
+ addRequiredParameter(std::string const& arg, param_arg_handler_t, char const* parameter_name);
void addOptionalParameter(std::string const& arg, param_arg_handler_t);
- void addChoices(
- std::string const& arg,
- param_arg_handler_t,
- bool required,
- char const** choices);
+ void
+ addChoices(std::string const& arg, param_arg_handler_t, bool required, char const** choices);
// The default behavior when an invalid choice is specified with
// an option that takes choices is to list all the choices. This
@@ -123,9 +117,7 @@ class QPDFArgParser
// Add a help topic along with the text for that topic
void addHelpTopic(
- std::string const& topic,
- std::string const& short_text,
- std::string const& long_text);
+ std::string const& topic, std::string const& short_text, std::string const& long_text);
// Add help for an option, and associate it with a topic.
void addOptionHelp(
@@ -220,16 +212,13 @@ class QPDFArgParser
void readArgsFromFile(std::string const& filename);
void doFinalChecks();
void addOptionsToCompletions(option_table_t&);
- void addChoicesToCompletions(
- option_table_t&, std::string const&, std::string const&);
- void
- insertCompletions(option_table_t&, std::string const&, std::string const&);
+ void addChoicesToCompletions(option_table_t&, std::string const&, std::string const&);
+ void insertCompletions(option_table_t&, std::string const&, std::string const&);
void handleCompletion();
void getTopHelp(std::ostringstream&);
void getAllHelp(std::ostringstream&);
- void getTopicHelp(
- std::string const& name, HelpTopic const&, std::ostringstream&);
+ void getTopicHelp(std::string const& name, HelpTopic const&, std::ostringstream&);
class Members
{
diff --git a/libqpdf/qpdf/QPDFCrypto_gnutls.hh b/libqpdf/qpdf/QPDFCrypto_gnutls.hh
index 05c94bfc..efec1bbf 100644
--- a/libqpdf/qpdf/QPDFCrypto_gnutls.hh
+++ b/libqpdf/qpdf/QPDFCrypto_gnutls.hh
@@ -25,8 +25,7 @@ class QPDFCrypto_gnutls: public QPDFCryptoImpl
virtual void MD5_digest(MD5_Digest);
virtual void RC4_init(unsigned char const* key_data, int key_len = -1);
- virtual void RC4_process(
- unsigned char const* in_data, size_t len, unsigned char* out_data = 0);
+ virtual void RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0);
virtual void RC4_finalize();
virtual void SHA2_init(int bits);
@@ -40,8 +39,7 @@ class QPDFCrypto_gnutls: public QPDFCryptoImpl
size_t key_len,
bool cbc_mode,
unsigned char* cbc_block);
- virtual void
- rijndael_process(unsigned char* in_data, unsigned char* out_data);
+ virtual void rijndael_process(unsigned char* in_data, unsigned char* out_data);
virtual void rijndael_finalize();
private:
diff --git a/libqpdf/qpdf/QPDFCrypto_native.hh b/libqpdf/qpdf/QPDFCrypto_native.hh
index 0beca395..4dd63622 100644
--- a/libqpdf/qpdf/QPDFCrypto_native.hh
+++ b/libqpdf/qpdf/QPDFCrypto_native.hh
@@ -23,8 +23,7 @@ class QPDFCrypto_native: public QPDFCryptoImpl
virtual void MD5_digest(MD5_Digest);
virtual void RC4_init(unsigned char const* key_data, int key_len = -1);
- virtual void RC4_process(
- unsigned char const* in_data, size_t len, unsigned char* out_data = 0);
+ virtual void RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0);
virtual void RC4_finalize();
virtual void SHA2_init(int bits);
@@ -38,8 +37,7 @@ class QPDFCrypto_native: public QPDFCryptoImpl
size_t key_len,
bool cbc_mode,
unsigned char* cbc_block);
- virtual void
- rijndael_process(unsigned char* in_data, unsigned char* out_data);
+ virtual void rijndael_process(unsigned char* in_data, unsigned char* out_data);
virtual void rijndael_finalize();
private:
diff --git a/libqpdf/qpdf/QPDFCrypto_openssl.hh b/libqpdf/qpdf/QPDFCrypto_openssl.hh
index 0d07b99b..cbff84c3 100644
--- a/libqpdf/qpdf/QPDFCrypto_openssl.hh
+++ b/libqpdf/qpdf/QPDFCrypto_openssl.hh
@@ -37,9 +37,7 @@ class QPDFCrypto_openssl: public QPDFCryptoImpl
void RC4_init(unsigned char const* key_data, int key_len = -1) override;
void RC4_process(
- unsigned char const* in_data,
- size_t len,
- unsigned char* out_data = nullptr) override;
+ unsigned char const* in_data, size_t len, unsigned char* out_data = nullptr) override;
void RC4_finalize() override;
void SHA2_init(int bits) override;
@@ -53,8 +51,7 @@ class QPDFCrypto_openssl: public QPDFCryptoImpl
size_t key_len,
bool cbc_mode,
unsigned char* cbc_block) override;
- void
- rijndael_process(unsigned char* in_data, unsigned char* out_data) override;
+ void rijndael_process(unsigned char* in_data, unsigned char* out_data) override;
void rijndael_finalize() override;
private:
diff --git a/libqpdf/qpdf/QPDFObject_private.hh b/libqpdf/qpdf/QPDFObject_private.hh
index 0dc04699..bbd6ccf1 100644
--- a/libqpdf/qpdf/QPDFObject_private.hh
+++ b/libqpdf/qpdf/QPDFObject_private.hh
@@ -71,9 +71,7 @@ class QPDFObject
}
void
setDescription(
- QPDF* qpdf,
- std::shared_ptr<QPDFValue::Description>& description,
- qpdf_offset_t offset = -1)
+ QPDF* qpdf, std::shared_ptr<QPDFValue::Description>& description, qpdf_offset_t offset = -1)
{
return value->setDescription(qpdf, description, offset);
}
@@ -84,8 +82,7 @@ class QPDFObject
std::string var_descr)
{
auto qpdf = parent ? parent->value->qpdf : nullptr;
- value->setChildDescription(
- qpdf, parent->value, static_descr, var_descr);
+ value->setChildDescription(qpdf, parent->value, static_descr, var_descr);
}
void
setChildDescription(
diff --git a/libqpdf/qpdf/QPDFParser.hh b/libqpdf/qpdf/QPDFParser.hh
index c2bf6bbe..35f9f603 100644
--- a/libqpdf/qpdf/QPDFParser.hh
+++ b/libqpdf/qpdf/QPDFParser.hh
@@ -22,8 +22,8 @@ class QPDFParser
tokenizer(tokenizer),
decrypter(decrypter),
context(context),
- description(std::make_shared<QPDFValue::Description>(std::string(
- input->getName() + ", " + object_description + " at offset $PO")))
+ description(std::make_shared<QPDFValue::Description>(
+ std::string(input->getName() + ", " + object_description + " at offset $PO")))
{
}
virtual ~QPDFParser() = default;
@@ -31,20 +31,12 @@ class QPDFParser
QPDFObjectHandle parse(bool& empty, bool content_stream);
private:
- enum parser_state_e {
- st_top,
- st_start,
- st_stop,
- st_eof,
- st_dictionary,
- st_array
- };
+ enum parser_state_e { st_top, st_start, st_stop, st_eof, st_dictionary, st_array };
void warn(qpdf_offset_t offset, std::string const& msg) const;
void warn(std::string const& msg) const;
void warn(QPDFExc const&) const;
- void setDescription(
- std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset);
+ void setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset);
std::shared_ptr<InputSource> input;
std::string const& object_description;
QPDFTokenizer& tokenizer;
diff --git a/libqpdf/qpdf/QPDFValue.hh b/libqpdf/qpdf/QPDFValue.hh
index e8a1834f..db8fb923 100644
--- a/libqpdf/qpdf/QPDFValue.hh
+++ b/libqpdf/qpdf/QPDFValue.hh
@@ -28,8 +28,7 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue>
struct JSON_Descr
{
- JSON_Descr(
- std::shared_ptr<std::string> input, std::string const& object) :
+ JSON_Descr(std::shared_ptr<std::string> input, std::string const& object) :
input(input),
object(object)
{
@@ -59,10 +58,7 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue>
using Description = std::variant<std::string, JSON_Descr, ChildDescr>;
virtual void
- setDescription(
- QPDF* qpdf_p,
- std::shared_ptr<Description>& description,
- qpdf_offset_t offset)
+ setDescription(QPDF* qpdf_p, std::shared_ptr<Description>& description, qpdf_offset_t offset)
{
qpdf = qpdf_p;
object_description = description;
@@ -81,8 +77,8 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue>
std::string_view const& static_descr,
std::string var_descr)
{
- object_description = std::make_shared<Description>(
- ChildDescr(parent, static_descr, var_descr));
+ object_description =
+ std::make_shared<Description>(ChildDescr(parent, static_descr, var_descr));
qpdf = a_qpdf;
}
std::string getDescription();
@@ -132,10 +128,7 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue>
{
}
QPDFValue(
- qpdf_object_type_e type_code,
- char const* type_name,
- QPDF* qpdf,
- QPDFObjGen const& og) :
+ qpdf_object_type_e type_code, char const* type_name, QPDF* qpdf, QPDFObjGen const& og) :
type_code(type_code),
type_name(type_name),
qpdf(qpdf),
diff --git a/libqpdf/qpdf/QPDF_Array.hh b/libqpdf/qpdf/QPDF_Array.hh
index 4762bb6e..51a366a6 100644
--- a/libqpdf/qpdf/QPDF_Array.hh
+++ b/libqpdf/qpdf/QPDF_Array.hh
@@ -10,8 +10,7 @@ class QPDF_Array: public QPDFValue
{
public:
virtual ~QPDF_Array() = default;
- static std::shared_ptr<QPDFObject>
- create(std::vector<QPDFObjectHandle> const& items);
+ static std::shared_ptr<QPDFObject> create(std::vector<QPDFObjectHandle> const& items);
static std::shared_ptr<QPDFObject>
create(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse);
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
diff --git a/libqpdf/qpdf/QPDF_Dictionary.hh b/libqpdf/qpdf/QPDF_Dictionary.hh
index bc025403..bf3dfb2d 100644
--- a/libqpdf/qpdf/QPDF_Dictionary.hh
+++ b/libqpdf/qpdf/QPDF_Dictionary.hh
@@ -12,10 +12,8 @@ class QPDF_Dictionary: public QPDFValue
{
public:
virtual ~QPDF_Dictionary() = default;
- static std::shared_ptr<QPDFObject>
- create(std::map<std::string, QPDFObjectHandle> const& items);
- static std::shared_ptr<QPDFObject>
- create(std::map<std::string, QPDFObjectHandle>&& items);
+ static std::shared_ptr<QPDFObject> create(std::map<std::string, QPDFObjectHandle> const& items);
+ static std::shared_ptr<QPDFObject> create(std::map<std::string, QPDFObjectHandle>&& items);
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse();
virtual JSON getJSON(int json_version);
diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh
index cf0a2288..88331201 100644
--- a/libqpdf/qpdf/QPDF_Stream.hh
+++ b/libqpdf/qpdf/QPDF_Stream.hh
@@ -27,9 +27,7 @@ class QPDF_Stream: public QPDFValue
virtual std::string unparse();
virtual JSON getJSON(int json_version);
virtual void setDescription(
- QPDF*,
- std::shared_ptr<QPDFValue::Description>& description,
- qpdf_offset_t offset);
+ QPDF*, std::shared_ptr<QPDFValue::Description>& description, qpdf_offset_t offset);
virtual void disconnect();
QPDFObjectHandle getDict() const;
bool isDataModified() const;
@@ -39,8 +37,7 @@ class QPDF_Stream: public QPDFValue
// Methods to help QPDF copy foreign streams
size_t getLength() const;
std::shared_ptr<Buffer> getStreamDataBuffer() const;
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider>
- getStreamDataProvider() const;
+ std::shared_ptr<QPDFObjectHandle::StreamDataProvider> getStreamDataProvider() const;
// See comments in QPDFObjectHandle.hh for these methods.
bool pipeStreamData(
@@ -60,8 +57,7 @@ class QPDF_Stream: public QPDFValue
std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider,
QPDFObjectHandle const& filter,
QPDFObjectHandle const& decode_parms);
- void
- addTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter);
+ void addTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter);
JSON getStreamJSON(
int json_version,
qpdf_json_stream_data_e json_data,
@@ -72,8 +68,7 @@ class QPDF_Stream: public QPDFValue
void replaceDict(QPDFObjectHandle const& new_dict);
static void registerStreamFilter(
- std::string const& filter_name,
- std::function<std::shared_ptr<QPDFStreamFilter>()> factory);
+ std::string const& filter_name, std::function<std::shared_ptr<QPDFStreamFilter>()> factory);
private:
QPDF_Stream(
@@ -83,14 +78,11 @@ class QPDF_Stream: public QPDFValue
qpdf_offset_t offset,
size_t length);
static std::map<std::string, std::string> filter_abbreviations;
- static std::
- map<std::string, std::function<std::shared_ptr<QPDFStreamFilter>()>>
- filter_factories;
+ static std::map<std::string, std::function<std::shared_ptr<QPDFStreamFilter>()>>
+ filter_factories;
void replaceFilterData(
- QPDFObjectHandle const& filter,
- QPDFObjectHandle const& decode_parms,
- size_t length);
+ QPDFObjectHandle const& filter, QPDFObjectHandle const& decode_parms, size_t length);
bool filterable(
std::vector<std::shared_ptr<QPDFStreamFilter>>& filters,
bool& specialized_compression,
diff --git a/libqpdf/qpdf/QPDF_String.hh b/libqpdf/qpdf/QPDF_String.hh
index 32a05a6c..d4a1bfd4 100644
--- a/libqpdf/qpdf/QPDF_String.hh
+++ b/libqpdf/qpdf/QPDF_String.hh
@@ -12,8 +12,7 @@ class QPDF_String: public QPDFValue
public:
virtual ~QPDF_String() = default;
static std::shared_ptr<QPDFObject> create(std::string const& val);
- static std::shared_ptr<QPDFObject>
- create_utf16(std::string const& utf8_val);
+ static std::shared_ptr<QPDFObject> create_utf16(std::string const& utf8_val);
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse();
std::string unparse(bool force_binary);
diff --git a/libqpdf/qpdf/RC4.hh b/libqpdf/qpdf/RC4.hh
index 00de3905..257e6980 100644
--- a/libqpdf/qpdf/RC4.hh
+++ b/libqpdf/qpdf/RC4.hh
@@ -13,8 +13,7 @@ class RC4
// It is safe to pass the same pointer to in_data and out_data to
// encrypt/decrypt in place
- void
- process(unsigned char const* in_data, size_t len, unsigned char* out_data);
+ void process(unsigned char const* in_data, size_t len, unsigned char* out_data);
private:
std::shared_ptr<QPDFCryptoImpl> crypto;
diff --git a/libqpdf/qpdf/RC4_native.hh b/libqpdf/qpdf/RC4_native.hh
index e7404085..7607c0c2 100644
--- a/libqpdf/qpdf/RC4_native.hh
+++ b/libqpdf/qpdf/RC4_native.hh
@@ -10,8 +10,7 @@ class RC4_native
RC4_native(unsigned char const* key_data, int key_len = -1);
// out_data = 0 means to encrypt/decrypt in place
- void process(
- unsigned char const* in_data, size_t len, unsigned char* out_data = 0);
+ void process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0);
private:
class RC4Key
diff --git a/libqpdf/qpdf/ResourceFinder.hh b/libqpdf/qpdf/ResourceFinder.hh
index c4f5673b..d8cb32e6 100644
--- a/libqpdf/qpdf/ResourceFinder.hh
+++ b/libqpdf/qpdf/ResourceFinder.hh
@@ -18,8 +18,7 @@ class ResourceFinder: public QPDFObjectHandle::ParserCallbacks
std::string last_name;
size_t last_name_offset;
std::set<std::string> names;
- std::map<std::string, std::map<std::string, std::set<size_t>>>
- names_by_resource_type;
+ std::map<std::string, std::map<std::string, std::set<size_t>>> names_by_resource_type;
};
#endif // RESOURCEFINDER_HH
diff --git a/libqpdf/qpdf/SF_ASCII85Decode.hh b/libqpdf/qpdf/SF_ASCII85Decode.hh
index f383364a..8cf85e66 100644
--- a/libqpdf/qpdf/SF_ASCII85Decode.hh
+++ b/libqpdf/qpdf/SF_ASCII85Decode.hh
@@ -14,8 +14,7 @@ class SF_ASCII85Decode: public QPDFStreamFilter
Pipeline*
getDecodePipeline(Pipeline* next) override
{
- this->pipeline =
- std::make_shared<Pl_ASCII85Decoder>("ascii85 decode", next);
+ this->pipeline = std::make_shared<Pl_ASCII85Decoder>("ascii85 decode", next);
return this->pipeline.get();
}
diff --git a/libqpdf/qpdf/SF_ASCIIHexDecode.hh b/libqpdf/qpdf/SF_ASCIIHexDecode.hh
index 911f7370..cd87761e 100644
--- a/libqpdf/qpdf/SF_ASCIIHexDecode.hh
+++ b/libqpdf/qpdf/SF_ASCIIHexDecode.hh
@@ -14,8 +14,7 @@ class SF_ASCIIHexDecode: public QPDFStreamFilter
Pipeline*
getDecodePipeline(Pipeline* next) override
{
- this->pipeline =
- std::make_shared<Pl_ASCIIHexDecoder>("asciiHex decode", next);
+ this->pipeline = std::make_shared<Pl_ASCIIHexDecoder>("asciiHex decode", next);
return this->pipeline.get();
}
diff --git a/libqpdf/qpdf/SF_RunLengthDecode.hh b/libqpdf/qpdf/SF_RunLengthDecode.hh
index 9dec379d..83c498dc 100644
--- a/libqpdf/qpdf/SF_RunLengthDecode.hh
+++ b/libqpdf/qpdf/SF_RunLengthDecode.hh
@@ -14,8 +14,8 @@ class SF_RunLengthDecode: public QPDFStreamFilter
Pipeline*
getDecodePipeline(Pipeline* next) override
{
- this->pipeline = std::make_shared<Pl_RunLength>(
- "runlength decode", next, Pl_RunLength::a_decode);
+ this->pipeline =
+ std::make_shared<Pl_RunLength>("runlength decode", next, Pl_RunLength::a_decode);
return this->pipeline.get();
}
diff --git a/libqpdf/qpdf/bits_functions.hh b/libqpdf/qpdf/bits_functions.hh
index 632136f4..09c09b2b 100644
--- a/libqpdf/qpdf/bits_functions.hh
+++ b/libqpdf/qpdf/bits_functions.hh
@@ -17,11 +17,7 @@
#ifdef BITS_READ
static unsigned long long
-read_bits(
- unsigned char const*& p,
- size_t& bit_offset,
- size_t& bits_available,
- size_t bits_wanted)
+read_bits(unsigned char const*& p, size_t& bit_offset, size_t& bits_available, size_t bits_wanted)
{
// View p as a stream of bits:
@@ -32,8 +28,7 @@ read_bits(
if (bits_wanted > bits_available) {
throw std::runtime_error(
- "overflow reading bit stream: wanted = " +
- std::to_string(bits_wanted) +
+ "overflow reading bit stream: wanted = " + std::to_string(bits_wanted) +
"; available = " + std::to_string(bits_available));
}
if (bits_wanted > 32) {
@@ -49,20 +44,14 @@ read_bits(
while (bits_wanted > 0) {
// Grab bits from the first byte clearing anything before
// bit_offset.
- unsigned char byte =
- static_cast<unsigned char>(*p & ((1U << (bit_offset + 1U)) - 1U));
+ unsigned char byte = static_cast<unsigned char>(*p & ((1U << (bit_offset + 1U)) - 1U));
// There are bit_offset + 1 bits available in the first byte.
size_t to_copy = std::min(bits_wanted, bit_offset + 1);
size_t leftover = (bit_offset + 1) - to_copy;
# ifdef BITS_TESTING
- QTC::TC(
- "libtests",
- "bits bit_offset",
- ((bit_offset == 0) ? 0
- : (bit_offset == 7) ? 1
- : 2));
+ QTC::TC("libtests", "bits bit_offset", ((bit_offset == 0) ? 0 : (bit_offset == 7) ? 1 : 2));
QTC::TC("libtests", "bits leftover", (leftover > 0) ? 1 : 0);
# endif
@@ -84,12 +73,7 @@ read_bits(
bits_available -= to_copy;
# ifdef BITS_TESTING
- QTC::TC(
- "libtests",
- "bits iterations",
- ((bits_wanted > 8) ? 0
- : (bits_wanted > 0) ? 1
- : 2));
+ QTC::TC("libtests", "bits iterations", ((bits_wanted > 8) ? 0 : (bits_wanted > 0) ? 1 : 2));
# endif
}
@@ -100,11 +84,7 @@ read_bits(
#ifdef BITS_WRITE
static void
write_bits(
- unsigned char& ch,
- size_t& bit_offset,
- unsigned long long val,
- size_t bits,
- Pipeline* pipeline)
+ unsigned char& ch, size_t& bit_offset, unsigned long long val, size_t bits, Pipeline* pipeline)
{
if (bits > 32) {
throw std::out_of_range("write_bits: too many bits requested");
@@ -138,12 +118,7 @@ write_bits(
}
bits -= bits_to_write;
# ifdef BITS_TESTING
- QTC::TC(
- "libtests",
- "bits write iterations",
- ((bits > 8) ? 0
- : (bits > 0) ? 1
- : 2));
+ QTC::TC("libtests", "bits write iterations", ((bits > 8) ? 0 : (bits > 0) ? 1 : 2));
# endif
}
}
diff --git a/libqpdf/qpdf/rijndael.h b/libqpdf/qpdf/rijndael.h
index 5e059491..57fa2027 100644
--- a/libqpdf/qpdf/rijndael.h
+++ b/libqpdf/qpdf/rijndael.h
@@ -10,10 +10,8 @@
#endif
#include <stddef.h>
-unsigned int
-rijndaelSetupEncrypt(uint32_t* rk, const unsigned char* key, size_t keybits);
-unsigned int
-rijndaelSetupDecrypt(uint32_t* rk, const unsigned char* key, size_t keybits);
+unsigned int rijndaelSetupEncrypt(uint32_t* rk, const unsigned char* key, size_t keybits);
+unsigned int rijndaelSetupDecrypt(uint32_t* rk, const unsigned char* key, size_t keybits);
void rijndaelEncrypt(
const uint32_t* rk,
unsigned int nrounds,
diff --git a/libqpdf/qpdfjob-c.cc b/libqpdf/qpdfjob-c.cc
index 2e78672f..3040bbd0 100644
--- a/libqpdf/qpdfjob-c.cc
+++ b/libqpdf/qpdfjob-c.cc
@@ -35,8 +35,7 @@ wrap_qpdfjob(qpdfjob_handle j, std::function<int(qpdfjob_handle j)> fn)
try {
return fn(j);
} catch (std::exception& e) {
- *j->j.getLogger()->getError()
- << j->j.getMessagePrefix() << ": " << e.what() << "\n";
+ *j->j.getLogger()->getError() << j->j.getMessagePrefix() << ": " << e.what() << "\n";
}
return QPDFJob::EXIT_ERROR;
}
@@ -70,10 +69,9 @@ qpdfjob_initialize_from_wide_argv(qpdfjob_handle j, wchar_t const* const argv[])
for (auto k = argv; *k; ++k) {
++argc;
}
- return QUtil::call_main_from_wmain(
- argc, argv, [j](int, char const* const new_argv[]) {
- return qpdfjob_initialize_from_argv(j, new_argv);
- });
+ return QUtil::call_main_from_wmain(argc, argv, [j](int, char const* const new_argv[]) {
+ return qpdfjob_initialize_from_argv(j, new_argv);
+ });
}
#endif // QPDF_NO_WCHAR_T
@@ -105,8 +103,7 @@ qpdfjob_create_qpdf(qpdfjob_handle j)
auto qpdf = j->j.createQPDF();
return qpdf ? new _qpdf_data(std::move(qpdf)) : nullptr;
} catch (std::exception& e) {
- *j->j.getLogger()->getError()
- << j->j.getMessagePrefix() << ": " << e.what() << "\n";
+ *j->j.getLogger()->getError() << j->j.getMessagePrefix() << ": " << e.what() << "\n";
}
return nullptr;
}
@@ -136,35 +133,29 @@ run_with_handle(std::function<int(qpdfjob_handle)> fn)
int
qpdfjob_run_from_argv(char const* const argv[])
{
- return run_with_handle([argv](qpdfjob_handle j) {
- return qpdfjob_initialize_from_argv(j, argv);
- });
+ return run_with_handle(
+ [argv](qpdfjob_handle j) { return qpdfjob_initialize_from_argv(j, argv); });
}
#ifndef QPDF_NO_WCHAR_T
int
qpdfjob_run_from_wide_argv(wchar_t const* const argv[])
{
- return run_with_handle([argv](qpdfjob_handle j) {
- return qpdfjob_initialize_from_wide_argv(j, argv);
- });
+ return run_with_handle(
+ [argv](qpdfjob_handle j) { return qpdfjob_initialize_from_wide_argv(j, argv); });
}
#endif /* QPDF_NO_WCHAR_T */
int
qpdfjob_run_from_json(char const* json)
{
- return run_with_handle([json](qpdfjob_handle j) {
- return qpdfjob_initialize_from_json(j, json);
- });
+ return run_with_handle(
+ [json](qpdfjob_handle j) { return qpdfjob_initialize_from_json(j, json); });
}
void
qpdfjob_register_progress_reporter(
- qpdfjob_handle j,
- void (*report_progress)(int percent, void* data),
- void* data)
+ qpdfjob_handle j, void (*report_progress)(int percent, void* data), void* data)
{
- j->j.registerProgressReporter(
- std::bind(report_progress, std::placeholders::_1, data));
+ j->j.registerProgressReporter(std::bind(report_progress, std::placeholders::_1, data));
}
diff --git a/libqpdf/qpdflogger-c.cc b/libqpdf/qpdflogger-c.cc
index c713dfb4..00081b33 100644
--- a/libqpdf/qpdflogger-c.cc
+++ b/libqpdf/qpdflogger-c.cc
@@ -70,59 +70,40 @@ set_log_dest(
void* udata)
{
set_log_dest(
- l,
- std::bind(std::mem_fn(method), l, std::placeholders::_1),
- dest,
- identifier,
- fn,
- udata);
+ l, std::bind(std::mem_fn(method), l, std::placeholders::_1), dest, identifier, fn, udata);
}
void
-qpdflogger_set_info(
- qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata)
+qpdflogger_set_info(qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata)
{
- set_log_dest(
- l->l.get(), &QPDFLogger::setInfo, dest, "info logger", fn, udata);
+ set_log_dest(l->l.get(), &QPDFLogger::setInfo, dest, "info logger", fn, udata);
}
void
-qpdflogger_set_warn(
- qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata)
+qpdflogger_set_warn(qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata)
{
- set_log_dest(
- l->l.get(), &QPDFLogger::setWarn, dest, "warn logger", fn, udata);
+ set_log_dest(l->l.get(), &QPDFLogger::setWarn, dest, "warn logger", fn, udata);
}
void
-qpdflogger_set_error(
- qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata)
+qpdflogger_set_error(qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata)
{
- set_log_dest(
- l->l.get(), &QPDFLogger::setError, dest, "error logger", fn, udata);
+ set_log_dest(l->l.get(), &QPDFLogger::setError, dest, "error logger", fn, udata);
}
void
qpdflogger_set_save(
- qpdflogger_handle l,
- qpdf_log_dest_e dest,
- qpdf_log_fn_t fn,
- void* udata,
- int only_if_not_set)
+ qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata, int only_if_not_set)
{
auto method = std::bind(
- std::mem_fn(&QPDFLogger::setSave),
- l->l.get(),
- std::placeholders::_1,
- only_if_not_set);
+ std::mem_fn(&QPDFLogger::setSave), l->l.get(), std::placeholders::_1, only_if_not_set);
set_log_dest(l->l.get(), method, dest, "save logger", fn, udata);
}
void
qpdflogger_save_to_standard_output(qpdflogger_handle l, int only_if_not_set)
{
- qpdflogger_set_save(
- l, qpdf_log_dest_stdout, nullptr, nullptr, only_if_not_set);
+ qpdflogger_set_save(l, qpdf_log_dest_stdout, nullptr, nullptr, only_if_not_set);
}
int
diff --git a/libtests/aes.cc b/libtests/aes.cc
index 7368b44e..370cd65e 100644
--- a/libtests/aes.cc
+++ b/libtests/aes.cc
@@ -17,8 +17,7 @@ usage()
<< " -encrypt -- encrypt" << std::endl
<< " -decrypt -- decrypt CBC mode" << std::endl
<< " -zero-iv -- use zero initialization vector" << std::endl
- << " -static-iv -- use static initialization vector"
- << std::endl
+ << " -static-iv -- use static initialization vector" << std::endl
<< " -no-padding -- disable padding" << std::endl
<< "Options must precede key and file names." << std::endl;
exit(2);
diff --git a/libtests/arg_parser.cc b/libtests/arg_parser.cc
index c9474d55..fde00520 100644
--- a/libtests/arg_parser.cc
+++ b/libtests/arg_parser.cc
@@ -41,9 +41,7 @@ ArgParser::ArgParser(int argc, char* argv[]) :
void
ArgParser::initOptions()
{
- auto b = [this](void (ArgParser::*f)()) {
- return QPDFArgParser::bindBare(f, this);
- };
+ auto b = [this](void (ArgParser::*f)()) { return QPDFArgParser::bindBare(f, this); };
auto p = [this](void (ArgParser::*f)(std::string const&)) {
return QPDFArgParser::bindParam(f, this);
};
@@ -71,9 +69,7 @@ ArgParser::initOptions()
ap.addHelpFooter("For more help, read the manual.\n");
ap.addHelpTopic(
- "quack",
- "Quack Options",
- "Just put stuff after quack to get a count at the end.\n");
+ "quack", "Quack Options", "Just put stuff after quack to get a count at the end.\n");
ap.addHelpTopic(
"baaa",
"Baaa Options",
@@ -139,8 +135,7 @@ ArgParser::getQuack(std::string const& p)
{
++this->quacks;
if (this->ap.isCompleting() && (this->ap.argsLeft() == 0)) {
- this->ap.insertCompletion(
- std::string("thing-") + std::to_string(this->quacks));
+ this->ap.insertCompletion(std::string("thing-") + std::to_string(this->quacks));
return;
}
output(std::string("got quack: ") + p);
@@ -178,24 +173,17 @@ ArgParser::test_exceptions()
ap.selectOptionTable("baaa");
ap.addBare("ram", []() {});
});
- err("duplicate table",
- [this]() { ap.registerOptionTable("baaa", nullptr); });
+ err("duplicate table", [this]() { ap.registerOptionTable("baaa", nullptr); });
err("unknown table", [this]() { ap.selectOptionTable("aardvark"); });
- err("add existing help topic",
- [this]() { ap.addHelpTopic("baaa", "potato", "salad"); });
- err("add reserved help topic",
- [this]() { ap.addHelpTopic("all", "potato", "salad"); });
- err("add to unknown topic",
- [this]() { ap.addOptionHelp("--new", "oops", "potato", "salad"); });
- err("bad option for help",
- [this]() { ap.addOptionHelp("nodash", "baaa", "potato", "salad"); });
- err("bad topic for help",
- [this]() { ap.addHelpTopic("--dashes", "potato", "salad"); });
+ err("add existing help topic", [this]() { ap.addHelpTopic("baaa", "potato", "salad"); });
+ err("add reserved help topic", [this]() { ap.addHelpTopic("all", "potato", "salad"); });
+ err("add to unknown topic", [this]() { ap.addOptionHelp("--new", "oops", "potato", "salad"); });
+ err("bad option for help", [this]() { ap.addOptionHelp("nodash", "baaa", "potato", "salad"); });
+ err("bad topic for help", [this]() { ap.addHelpTopic("--dashes", "potato", "salad"); });
err("duplicate option help",
[this]() { ap.addOptionHelp("--ewe", "baaa", "potato", "salad"); });
- err("invalid choice handler to unknown", [this]() {
- ap.addInvalidChoiceHandler("elephant", [](std::string const&) {});
- });
+ err("invalid choice handler to unknown",
+ [this]() { ap.addInvalidChoiceHandler("elephant", [](std::string const&) {}); });
}
int
diff --git a/libtests/bits.cc b/libtests/bits.cc
index e8c8a5c1..96c9ff02 100644
--- a/libtests/bits.cc
+++ b/libtests/bits.cc
@@ -28,25 +28,19 @@ test_read_bits(
size_t& bits_available,
size_t bits_wanted)
{
- unsigned long result =
- QIntC::to_ulong(read_bits(p, bit_offset, bits_available, bits_wanted));
+ unsigned long result = QIntC::to_ulong(read_bits(p, bit_offset, bits_available, bits_wanted));
- std::cout << "bits read: " << bits_wanted << ", result = " << result
- << std::endl;
+ std::cout << "bits read: " << bits_wanted << ", result = " << result << std::endl;
print_values(p - buf, bit_offset, bits_available);
}
static void
test_write_bits(
- unsigned char& ch,
- size_t& bit_offset,
- unsigned long val,
- size_t bits,
- Pl_Buffer* bp)
+ unsigned char& ch, size_t& bit_offset, unsigned long val, size_t bits, Pl_Buffer* bp)
{
write_bits(ch, bit_offset, val, bits, bp);
- std::cout << "ch = " << QUtil::uint_to_string_base(ch, 16, 2)
- << ", bit_offset = " << bit_offset << std::endl;
+ std::cout << "ch = " << QUtil::uint_to_string_base(ch, 16, 2) << ", bit_offset = " << bit_offset
+ << std::endl;
}
static void
@@ -57,8 +51,7 @@ print_buffer(Pl_Buffer* bp)
unsigned char const* p = b->getBuffer();
size_t l = b->getSize();
for (unsigned long i = 0; i < l; ++i) {
- std::cout << QUtil::uint_to_string_base(p[i], 16, 2)
- << ((i == l - 1) ? "\n" : " ");
+ std::cout << QUtil::uint_to_string_base(p[i], 16, 2) << ((i == l - 1) ? "\n" : " ");
}
std::cout << std::endl;
delete b;
@@ -72,8 +65,7 @@ test()
// Read tests
- static unsigned char const buf[] = {
- 0xF5, 0x15, 0x65, 0x79, 0x12, 0x89, 0x75, 0x4B};
+ static unsigned char const buf[] = {0xF5, 0x15, 0x65, 0x79, 0x12, 0x89, 0x75, 0x4B};
unsigned char const* p = buf;
size_t bit_offset = 7;
diff --git a/libtests/concatenate.cc b/libtests/concatenate.cc
index 9bc0fd04..380d8cd3 100644
--- a/libtests/concatenate.cc
+++ b/libtests/concatenate.cc
@@ -29,8 +29,7 @@ main(int argc, char* argv[])
inflate.write(b1_buf->getBuffer(), b1_buf->getSize());
inflate.finish();
auto b2_buf = b2.getBufferSharedPointer();
- std::string result(
- reinterpret_cast<char*>(b2_buf->getBuffer()), b2_buf->getSize());
+ std::string result(reinterpret_cast<char*>(b2_buf->getBuffer()), b2_buf->getSize());
if (result == "-one--two-") {
std::cout << "concatenate test passed" << std::endl;
} else {
diff --git a/libtests/cxx11.cc b/libtests/cxx11.cc
index 5f0dcc9a..59c74fa8 100644
--- a/libtests/cxx11.cc
+++ b/libtests/cxx11.cc
@@ -33,8 +33,7 @@ do_functional()
x = 7; // change not seen by lambda
assert(by_value(1) == 6);
// Also >> at end of template
- assert((std::is_convertible<decltype(by_value), std::function<int(int)>>::
- value));
+ assert((std::is_convertible<decltype(by_value), std::function<int(int)>>::value));
// Capture by reference
auto by_reference = [&x](int a) { return a + x; };
diff --git a/libtests/input_source.cc b/libtests/input_source.cc
index 9ab41b5d..4111fd65 100644
--- a/libtests/input_source.cc
+++ b/libtests/input_source.cc
@@ -47,8 +47,7 @@ Finder::check()
void
check(char const* description, bool expected, bool actual)
{
- std::cout << description << ": " << ((actual == expected) ? "PASS" : "FAIL")
- << std::endl;
+ std::cout << description << ": " << ((actual == expected) ? "PASS" : "FAIL") << std::endl;
}
int
@@ -61,28 +60,15 @@ main()
// Overlap so that the first check() would advance past the start
// of the next match
memcpy(b + 2037, "potato potato salad ", 20);
- auto is = std::shared_ptr<InputSource>(
- new BufferInputSource("test buffer input source", b1.get()));
+ auto is =
+ std::shared_ptr<InputSource>(new BufferInputSource("test buffer input source", b1.get()));
Finder f1(is, "salad");
check("find potato salad", true, is->findFirst("potato", 0, 0, f1));
- check(
- "barely find potato salad",
- true,
- is->findFirst("potato", 1100, 945, f1));
- check(
- "barely find potato salad",
- true,
- is->findFirst("potato", 2000, 45, f1));
- check(
- "potato salad is too late",
- false,
- is->findFirst("potato", 1100, 944, f1));
- check(
- "potato salad is too late",
- false,
- is->findFirst("potato", 2000, 44, f1));
- check(
- "potato salad not found", false, is->findFirst("potato", 2045, 0, f1));
+ check("barely find potato salad", true, is->findFirst("potato", 1100, 945, f1));
+ check("barely find potato salad", true, is->findFirst("potato", 2000, 45, f1));
+ check("potato salad is too late", false, is->findFirst("potato", 1100, 944, f1));
+ check("potato salad is too late", false, is->findFirst("potato", 2000, 44, f1));
+ check("potato salad not found", false, is->findFirst("potato", 2045, 0, f1));
check("potato salad not found", false, is->findFirst("potato", 0, 1, f1));
// Put one more right at EOF
@@ -91,18 +77,13 @@ main()
is->findFirst("potato", 0, 0, f1);
check("findFirst found first", true, is->tell() == 2056);
- check(
- "findLast found potato salad", true, is->findLast("potato", 0, 0, f1));
+ check("findLast found potato salad", true, is->findLast("potato", 0, 0, f1));
check("findLast found at EOF", true, is->tell() == 3172);
// Make check() bump into EOF
memcpy(b + b1->getSize() - 6, "potato", 6);
- check(
- "potato but not salad salad at EOF",
- false,
- is->findFirst("potato", 3000, 0, f1));
- check(
- "findLast found potato salad", true, is->findLast("potato", 0, 0, f1));
+ check("potato but not salad salad at EOF", false, is->findFirst("potato", 3000, 0, f1));
+ check("findLast found potato salad", true, is->findLast("potato", 0, 0, f1));
check("findLast found first one", true, is->tell() == 2056);
return 0;
diff --git a/libtests/json.cc b/libtests/json.cc
index ef9188c5..98e332e7 100644
--- a/libtests/json.cc
+++ b/libtests/json.cc
@@ -17,8 +17,7 @@ check(JSON const& j, std::string const& exp)
static void
test_main()
{
- JSON jstr = JSON::makeString(
- "<1>\xcf\x80<2>\xf0\x9f\xa5\x94\\\"<3>\x03\t\b\r\n<4>");
+ JSON jstr = JSON::makeString("<1>\xcf\x80<2>\xf0\x9f\xa5\x94\\\"<3>\x03\t\b\r\n<4>");
check(
jstr,
"\"<1>\xcf\x80<2>\xf0\x9f\xa5\x94\\\\\\\"<3>"
@@ -60,8 +59,7 @@ test_main()
" 2.1e5\n"
"]");
std::vector<std::string> avalue;
- assert(jarr.forEachArrayItem(
- [&avalue](JSON j) { avalue.push_back(j.unparse()); }));
+ assert(jarr.forEachArrayItem([&avalue](JSON j) { avalue.push_back(j.unparse()); }));
std::vector<std::string> xavalue = {
"\"a\\tb\"",
"null",
@@ -79,8 +77,7 @@ test_main()
jmap.addDictionaryMember("no", JSON::makeBool(true));
jmap.addDictionaryMember("empty_dict", JSON::makeDictionary());
jmap.addDictionaryMember("empty_list", JSON::makeArray());
- jmap.addDictionaryMember("single", JSON::makeArray())
- .addArrayElement(JSON::makeInt(12));
+ jmap.addDictionaryMember("single", JSON::makeArray()).addArrayElement(JSON::makeInt(12));
check(
jmap,
"{\n"
@@ -117,9 +114,7 @@ test_main()
{"c", "[\n true\n]"},
};
assert(dvalue == xdvalue);
- auto blob_data = [](Pipeline* p) {
- *p << "\x01\x02\x03\x04\x05\xff\xfe\xfd\xfc\xfb";
- };
+ auto blob_data = [](Pipeline* p) { *p << "\x01\x02\x03\x04\x05\xff\xfe\xfd\xfc\xfb"; };
JSON jblob = JSON::makeDictionary();
jblob.addDictionaryMember("normal", JSON::parse(R"("string")"));
jblob.addDictionaryMember("blob", JSON::makeBlob(blob_data));
@@ -133,12 +128,7 @@ test_main()
}
static void
-check_schema(
- JSON& obj,
- JSON& schema,
- unsigned long flags,
- bool exp,
- std::string const& description)
+check_schema(JSON& obj, JSON& schema, unsigned long flags, bool exp, std::string const& description)
{
std::list<std::string> errors;
std::cout << "--- " << description << std::endl;
diff --git a/libtests/json_handler.cc b/libtests/json_handler.cc
index 4e610b08..57185c98 100644
--- a/libtests/json_handler.cc
+++ b/libtests/json_handler.cc
@@ -38,9 +38,7 @@ print_json(std::string const& path, JSON value)
static JSONHandler::void_handler_t
make_print_message(std::string msg)
{
- return [msg](std::string const& path) {
- std::cout << path << ": json: " << msg << std::endl;
- };
+ return [msg](std::string const& path) { std::cout << path << ": json: " << msg << std::endl; };
}
static void
diff --git a/libtests/json_parse.cc b/libtests/json_parse.cc
index bd2d49d1..35abb68f 100644
--- a/libtests/json_parse.cc
+++ b/libtests/json_parse.cc
@@ -74,8 +74,7 @@ Reactor::arrayItem(JSON const& value)
void
Reactor::printItem(JSON const& j)
{
- std::cout << "[" << j.getStart() << ", " << j.getEnd()
- << "): " << j.unparse() << std::endl;
+ std::cout << "[" << j.getStart() << ", " << j.getEnd() << "): " << j.unparse() << std::endl;
}
static void
diff --git a/libtests/logger.cc b/libtests/logger.cc
index 987e15d3..e17d450d 100644
--- a/libtests/logger.cc
+++ b/libtests/logger.cc
@@ -25,8 +25,7 @@ test1()
logger->saveToStandardOutput(true);
assert(false);
} catch (std::logic_error& e) {
- *(logger->getInfo())
- << "saveToStandardOutput exception: " << e.what() << "\n";
+ *(logger->getInfo()) << "saveToStandardOutput exception: " << e.what() << "\n";
}
logger->setWarn(logger->discard());
logger->warn("warning not seen\n");
diff --git a/libtests/logger_c.c b/libtests/logger_c.c
index c3fa0d8c..4e9883a7 100644
--- a/libtests/logger_c.c
+++ b/libtests/logger_c.c
@@ -54,15 +54,9 @@ main()
qpdflogger_set_error(l, qpdf_log_dest_custom, fn, (void*)error);
qpdflogger_set_save(l, qpdf_log_dest_custom, fn, (void*)save, 0);
- do_run(
- "{\"inputFile\": \"normal.pdf\", \"showNpages\": \"\"}",
- qpdf_exit_success);
- do_run(
- "{\"inputFile\": \"warning.pdf\", \"showNpages\": \"\"}",
- qpdf_exit_warning);
- do_run(
- "{\"inputFile\": \"missing.pdf\", \"showNpages\": \"\"}",
- qpdf_exit_error);
+ do_run("{\"inputFile\": \"normal.pdf\", \"showNpages\": \"\"}", qpdf_exit_success);
+ do_run("{\"inputFile\": \"warning.pdf\", \"showNpages\": \"\"}", qpdf_exit_warning);
+ do_run("{\"inputFile\": \"missing.pdf\", \"showNpages\": \"\"}", qpdf_exit_error);
do_run(
"{\"inputFile\": \"normal.pdf\","
" \"staticId\": \"\","
@@ -79,16 +73,11 @@ main()
qpdflogger_set_error(l, qpdf_log_dest_default, NULL, NULL);
qpdflogger_set_save(l, qpdf_log_dest_custom, fn, (void*)save2, 0);
- do_run(
- "{\"inputFile\": \"2pages.pdf\", \"showNpages\": \"\"}",
- qpdf_exit_success);
- do_run(
- "{\"inputFile\": \"warning.pdf\", \"showNpages\": \"\"}",
- qpdf_exit_warning);
+ do_run("{\"inputFile\": \"2pages.pdf\", \"showNpages\": \"\"}", qpdf_exit_success);
+ do_run("{\"inputFile\": \"warning.pdf\", \"showNpages\": \"\"}", qpdf_exit_warning);
do_run(
- "{\"inputFile\": \"missing.pdf\", \"showNpages\": \"\"}",
- qpdf_exit_error);
+ "{\"inputFile\": \"missing.pdf\", \"showNpages\": \"\"}", qpdf_exit_error);
do_run(
"{\"inputFile\": \"attach.pdf\","
" \"showAttachment\": \"a\"}",
diff --git a/libtests/lzw.cc b/libtests/lzw.cc
index 3a7d003c..3d255b24 100644
--- a/libtests/lzw.cc
+++ b/libtests/lzw.cc
@@ -15,8 +15,7 @@ main(int argc, char* argv[])
}
if (argc < 3) {
- std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]"
- << std::endl;
+ std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]" << std::endl;
exit(2);
}
diff --git a/libtests/matrix.cc b/libtests/matrix.cc
index f69d270c..70380f0e 100644
--- a/libtests/matrix.cc
+++ b/libtests/matrix.cc
@@ -16,31 +16,21 @@ check(QPDFMatrix const& m, std::string const& exp)
static void
check_xy(double x, double y, std::string const& exp)
{
- std::string u =
- (QUtil::double_to_string(x, 2) + " " + QUtil::double_to_string(y, 2));
+ std::string u = (QUtil::double_to_string(x, 2) + " " + QUtil::double_to_string(y, 2));
if (u != exp) {
std::cout << "got " << u << ", wanted " << exp << std::endl;
}
}
static void
-check_rect(
- QPDFObjectHandle::Rectangle const& r,
- double llx,
- double lly,
- double urx,
- double ury)
+check_rect(QPDFObjectHandle::Rectangle const& r, double llx, double lly, double urx, double ury)
{
std::string actual =
- (QUtil::double_to_string(r.llx, 2) + " " +
- QUtil::double_to_string(r.lly, 2) + " " +
- QUtil::double_to_string(r.urx, 2) + " " +
- QUtil::double_to_string(r.ury, 2));
+ (QUtil::double_to_string(r.llx, 2) + " " + QUtil::double_to_string(r.lly, 2) + " " +
+ QUtil::double_to_string(r.urx, 2) + " " + QUtil::double_to_string(r.ury, 2));
std::string wanted =
- (QUtil::double_to_string(llx, 2) + " " +
- QUtil::double_to_string(lly, 2) + " " +
- QUtil::double_to_string(urx, 2) + " " +
- QUtil::double_to_string(ury, 2));
+ (QUtil::double_to_string(llx, 2) + " " + QUtil::double_to_string(lly, 2) + " " +
+ QUtil::double_to_string(urx, 2) + " " + QUtil::double_to_string(ury, 2));
if (actual != wanted) {
std::cout << "got " << actual << ", wanted " << wanted << std::endl;
}
@@ -80,19 +70,13 @@ main()
check_xy(xp, yp, "2582.5 4912");
check(
- QPDFMatrix(
- QPDFObjectHandle::parse("[3 1 4 1 5 9.26535]").getArrayAsMatrix()),
+ QPDFMatrix(QPDFObjectHandle::parse("[3 1 4 1 5 9.26535]").getArrayAsMatrix()),
"3 1 4 1 5 9.26535");
m = QPDFMatrix();
m.rotatex90(90);
m.translate(200, -100);
- check_rect(
- m.transformRectangle(QPDFObjectHandle::Rectangle(10, 20, 30, 50)),
- 50,
- 210,
- 80,
- 230);
+ check_rect(m.transformRectangle(QPDFObjectHandle::Rectangle(10, 20, 30, 50)), 50, 210, 80, 230);
std::cout << "matrix tests done" << std::endl;
return 0;
diff --git a/libtests/md5.cc b/libtests/md5.cc
index 9aed832d..baa59a41 100644
--- a/libtests/md5.cc
+++ b/libtests/md5.cc
@@ -32,17 +32,11 @@ main(int, char*[])
b.encodeFile("md5.in", 100);
std::cout << b.unparse() << std::endl;
- std::cout
- << MD5::checkDataChecksum("900150983cd24fb0d6963f7d28e17f72", "abc", 3)
- << std::endl
- << MD5::checkFileChecksum("5f4b4321873433daae578f85c72f9e74", "md5.in")
- << std::endl
- << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "md5.in")
- << std::endl
- << MD5::checkDataChecksum("000150983cd24fb0d6963f7d28e17f72", "abc", 3)
- << std::endl
- << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "glerbl")
- << std::endl;
+ std::cout << MD5::checkDataChecksum("900150983cd24fb0d6963f7d28e17f72", "abc", 3) << std::endl
+ << MD5::checkFileChecksum("5f4b4321873433daae578f85c72f9e74", "md5.in") << std::endl
+ << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "md5.in") << std::endl
+ << MD5::checkDataChecksum("000150983cd24fb0d6963f7d28e17f72", "abc", 3) << std::endl
+ << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "glerbl") << std::endl;
Pl_Discard d;
Pl_MD5 p("MD5", &d);
diff --git a/libtests/nntree.cc b/libtests/nntree.cc
index 335da857..c2b35dc0 100644
--- a/libtests/nntree.cc
+++ b/libtests/nntree.cc
@@ -20,15 +20,12 @@ report(QPDF& q, QPDFObjectHandle oh, long long item, long long exp_item)
auto show = [&failed, &oh, &item]() {
if (!failed) {
failed = true;
- std::cout << "key = " << item << ", oh = " << oh.unparseResolved()
- << std::endl;
+ std::cout << "key = " << item << ", oh = " << oh.unparseResolved() << std::endl;
}
};
auto mk_wanted = [](long long i) {
- return (
- (i == -1) ? "end"
- : (std::to_string(i) + "/(-" + std::to_string(i) + "-)"));
+ return ((i == -1) ? "end" : (std::to_string(i) + "/(-" + std::to_string(i) + "-)"));
};
std::string i1_wanted = mk_wanted(exp_item);
std::string i2_wanted = mk_wanted(item == exp_item ? item : -1);
@@ -40,13 +37,11 @@ report(QPDF& q, QPDFObjectHandle oh, long long item, long long exp_item)
if (i1_wanted != i1_actual) {
show();
- std::cout << "i1: wanted " << i1_wanted << ", got " << i1_actual
- << std::endl;
+ std::cout << "i1: wanted " << i1_wanted << ", got " << i1_actual << std::endl;
}
if (i2_wanted != i2_actual) {
show();
- std::cout << "i2: wanted " << i2_wanted << ", got " << i2_actual
- << std::endl;
+ std::cout << "i2: wanted " << i2_wanted << ", got " << i2_actual << std::endl;
}
return failed;
@@ -62,8 +57,7 @@ test_bsearch()
auto nums = QPDFObjectHandle::newArray();
for (auto i: v) {
nums.appendItem(QPDFObjectHandle::newInteger(i));
- nums.appendItem(
- QPDFObjectHandle::newString("-" + std::to_string(i) + "-"));
+ nums.appendItem(QPDFObjectHandle::newString("-" + std::to_string(i) + "-"));
}
auto limits = QPDFObjectHandle::newArray();
limits.appendItem(QPDFObjectHandle::newInteger(v.at(0)));
@@ -125,10 +119,7 @@ new_node(QPDF& q, std::string const& key)
}
static void
-check_find(
- QPDFNameTreeObjectHelper& nh,
- std::string const& key,
- bool prev_if_not_found)
+check_find(QPDFNameTreeObjectHelper& nh, std::string const& key, bool prev_if_not_found)
{
auto i = nh.find(key, prev_if_not_found);
std::cout << "find " << key << " (" << prev_if_not_found << "): ";
@@ -165,8 +156,7 @@ test_depth()
std::string first;
std::string last;
for (int i4 = 0; i4 < NITEMS; ++i4) {
- int val =
- (((((i1 * NITEMS) + i2) * NITEMS) + i3) * NITEMS) + i4;
+ int val = (((((i1 * NITEMS) + i2) * NITEMS) + i3) * NITEMS) + i4;
std::string str = QUtil::int_to_string(10 * val, 6);
items.appendItem(QPDFObjectHandle::newString(str));
items.appendItem(QPDFObjectHandle::newString("val " + str));
@@ -183,16 +173,13 @@ test_depth()
}
auto limits = QPDFObjectHandle::newArray();
n2.replaceKey("/Limits", limits);
- limits.appendItem(
- k2.getArrayItem(0).getKey("/Limits").getArrayItem(0));
- limits.appendItem(
- k2.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1));
+ limits.appendItem(k2.getArrayItem(0).getKey("/Limits").getArrayItem(0));
+ limits.appendItem(k2.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1));
}
auto limits = QPDFObjectHandle::newArray();
n1.replaceKey("/Limits", limits);
limits.appendItem(k1.getArrayItem(0).getKey("/Limits").getArrayItem(0));
- limits.appendItem(
- k1.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1));
+ limits.appendItem(k1.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1));
}
QPDFNameTreeObjectHelper nh(n0, q);
diff --git a/libtests/pointer_holder.cc b/libtests/pointer_holder.cc
index 4b9d43cb..641cd0bb 100644
--- a/libtests/pointer_holder.cc
+++ b/libtests/pointer_holder.cc
@@ -185,8 +185,7 @@ ph_sp_compat()
PointerHolder<Object> arr1_ph;
{
std::cout << "initialize ph array from shared_ptr" << std::endl;
- std::shared_ptr<Object> arr1(
- new Object[2], std::default_delete<Object[]>());
+ std::shared_ptr<Object> arr1(new Object[2], std::default_delete<Object[]>());
arr1_ph = arr1;
}
std::cout << "delete ph array" << std::endl;
diff --git a/libtests/qintc.cc b/libtests/qintc.cc
index 52a1e91e..d360dd45 100644
--- a/libtests/qintc.cc
+++ b/libtests/qintc.cc
@@ -3,16 +3,11 @@
#include <qpdf/QIntC.hh>
#include <cstdint>
-#define try_convert(exp_pass, fn, i) \
- try_convert_real(#fn "(" #i ")", exp_pass, fn, i)
+#define try_convert(exp_pass, fn, i) try_convert_real(#fn "(" #i ")", exp_pass, fn, i)
template <typename From, typename To>
static void
-try_convert_real(
- char const* description,
- bool exp_pass,
- To (*fn)(From const&),
- From const& i)
+try_convert_real(char const* description, bool exp_pass, To (*fn)(From const&), From const& i)
{
bool passed = false;
try {
@@ -26,13 +21,11 @@ try_convert_real(
std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << std::endl;
}
-#define try_range_check(exp_pass, a, b) \
- try_range_check_real(#a " + " #b, exp_pass, a, b)
+#define try_range_check(exp_pass, a, b) try_range_check_real(#a " + " #b, exp_pass, a, b)
template <typename T>
static void
-try_range_check_real(
- char const* description, bool exp_pass, T const& a, T const& b)
+try_range_check_real(char const* description, bool exp_pass, T const& a, T const& b)
{
bool passed = false;
try {
@@ -51,8 +44,7 @@ try_range_check_real(
template <typename T>
static void
-try_range_check_subtract_real(
- char const* description, bool exp_pass, T const& a, T const& b)
+try_range_check_subtract_real(char const* description, bool exp_pass, T const& a, T const& b)
{
bool passed = false;
try {
@@ -75,7 +67,7 @@ main()
uint64_t ul2 = 12345; // Fits into 32-bit
int32_t i2 = 81; // Fits in char and uchar
auto c1 = static_cast<signed char>('\xf7'); // Signed value when char
- char c2 = 'W'; // char; may be signed or unsigned
+ char c2 = 'W'; // char; may be signed or unsigned
// Verify i1 and u1 have same bit pattern
assert(static_cast<uint32_t>(i1) == u1);
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index a1bbb905..e882a33a 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -17,8 +17,7 @@
template <class int_T>
void
-test_to_number(
- char const* str, int_T wanted, bool error, int_T (*fn)(char const*))
+test_to_number(char const* str, int_T wanted, bool error, int_T (*fn)(char const*))
{
bool threw = false;
bool worked = false;
@@ -33,11 +32,9 @@ test_to_number(
}
if (threw) {
if (error) {
- std::cout << str << " to int threw (" << msg << "): PASSED"
- << std::endl;
+ std::cout << str << " to int threw (" << msg << "): PASSED" << std::endl;
} else {
- std::cout << str << " to int threw but wanted " << wanted
- << std::endl;
+ std::cout << str << " to int threw but wanted " << wanted << std::endl;
}
} else {
if (worked) {
@@ -203,11 +200,10 @@ void
getenv_test()
{
std::string val;
- std::cout << "IN_TESTSUITE: " << QUtil::get_env("IN_TESTSUITE", &val)
- << ": " << val << std::endl;
- // Hopefully this environment variable is not defined.
- std::cout << "HAGOOGAMAGOOGLE: " << QUtil::get_env("HAGOOGAMAGOOGLE")
+ std::cout << "IN_TESTSUITE: " << QUtil::get_env("IN_TESTSUITE", &val) << ": " << val
<< std::endl;
+ // Hopefully this environment variable is not defined.
+ std::cout << "HAGOOGAMAGOOGLE: " << QUtil::get_env("HAGOOGAMAGOOGLE") << std::endl;
}
static void
@@ -224,9 +220,7 @@ print_utf8(unsigned long val)
for (auto const& ch: result) {
std::cout << " "
<< QUtil::int_to_string_base(
- static_cast<int>(static_cast<unsigned char>(ch)),
- 16,
- 2);
+ static_cast<int>(static_cast<unsigned char>(ch)), 16, 2);
}
}
std::cout << std::endl;
@@ -282,9 +276,7 @@ print_utf16(unsigned long val)
for (auto const& ch: result) {
std::cout << " "
<< QUtil::int_to_string_base(
- static_cast<int>(static_cast<unsigned char>(ch)),
- 16,
- 2);
+ static_cast<int>(static_cast<unsigned char>(ch)), 16, 2);
}
std::cout << std::endl;
}
@@ -303,8 +295,7 @@ to_utf16_test()
std::string s(QUtil::utf8_to_utf16("\xcf\x80"));
std::cout << QUtil::utf16_to_utf8(s) << std::endl;
std::cout << QUtil::utf16_to_utf8(s + ".") << std::endl;
- std::cout << "LE: " << QUtil::utf16_to_utf8("\xff\xfe\xc0\x03")
- << std::endl;
+ std::cout << "LE: " << QUtil::utf16_to_utf8("\xff\xfe\xc0\x03") << std::endl;
}
void
@@ -316,13 +307,10 @@ utf8_to_ascii_test()
<< QUtil::utf8_to_ascii(input, '*') << std::endl;
std::string a = QUtil::utf8_to_win_ansi(input, '*');
std::string b = QUtil::utf8_to_mac_roman(input, '*');
- std::cout
- << "<"
- << QUtil::int_to_string_base(static_cast<unsigned char>(a.at(0)), 16, 2)
- << ">" << a.substr(1) << std::endl
- << "<"
- << QUtil::int_to_string_base(static_cast<unsigned char>(b.at(0)), 16, 2)
- << ">" << b.substr(1) << std::endl;
+ std::cout << "<" << QUtil::int_to_string_base(static_cast<unsigned char>(a.at(0)), 16, 2) << ">"
+ << a.substr(1) << std::endl
+ << "<" << QUtil::int_to_string_base(static_cast<unsigned char>(b.at(0)), 16, 2) << ">"
+ << b.substr(1) << std::endl;
}
void
@@ -342,8 +330,8 @@ transcoding_test(
std::string wanted = (out == "\xef\xbf\xbd") ? unknown : in;
back = (*from_utf8)(out, '?');
if (back != wanted) {
- std::cout << i << ": " << in << " -> " << out << " -> " << back
- << " (wanted " << wanted << ")" << std::endl;
+ std::cout << i << ": " << in << " -> " << out << " -> " << back << " (wanted " << wanted
+ << ")" << std::endl;
}
}
}
@@ -355,8 +343,7 @@ check_analyze(std::string const& str, bool has8bit, bool utf8, bool utf16)
bool is_valid_utf8 = false;
bool is_utf16 = false;
QUtil::analyze_encoding(str, has_8bit_chars, is_valid_utf8, is_utf16);
- if (!((has_8bit_chars == has8bit) && (is_valid_utf8 == utf8) &&
- (is_utf16 == utf16))) {
+ if (!((has_8bit_chars == has8bit) && (is_valid_utf8 == utf8) && (is_utf16 == utf16))) {
std::cout << "analysis failed: " << str << std::endl;
}
}
@@ -374,17 +361,13 @@ print_alternatives(std::string const& str)
void
transcoding_test()
{
- transcoding_test(
- &QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 127, 160, "\x9f");
+ transcoding_test(&QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 127, 160, "\x9f");
std::cout << "bidirectional pdf doc done" << std::endl;
- transcoding_test(
- &QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 24, 31, "?");
+ transcoding_test(&QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 24, 31, "?");
std::cout << "bidirectional pdf doc low done" << std::endl;
- transcoding_test(
- &QUtil::win_ansi_to_utf8, &QUtil::utf8_to_win_ansi, 128, 160, "?");
+ transcoding_test(&QUtil::win_ansi_to_utf8, &QUtil::utf8_to_win_ansi, 128, 160, "?");
std::cout << "bidirectional win ansi done" << std::endl;
- transcoding_test(
- &QUtil::mac_roman_to_utf8, &QUtil::utf8_to_mac_roman, 128, 255, "?");
+ transcoding_test(&QUtil::mac_roman_to_utf8, &QUtil::utf8_to_mac_roman, 128, 255, "?");
std::cout << "bidirectional mac roman done" << std::endl;
check_analyze("pi = \317\200", true, true, false);
check_analyze("pi != \317", true, false, false);
@@ -426,8 +409,7 @@ transcoding_test()
// cSpell: ignore xadw
std::string other_doc = other + "\x9fw\xadw";
std::cout << QUtil::pdf_doc_to_utf8(other_doc) << std::endl;
- std::string other_utf8 =
- other + QUtil::toUTF8(0x9f) + "w" + QUtil::toUTF8(0xad) + "w";
+ std::string other_utf8 = other + QUtil::toUTF8(0x9f) + "w" + QUtil::toUTF8(0xad) + "w";
std::string other_to_utf8;
assert(!QUtil::utf8_to_pdf_doc(other_utf8, other_to_utf8));
std::cout << other_to_utf8 << std::endl;
@@ -533,8 +515,7 @@ read_from_file_test()
}
// Test with EOL preservation
- std::list<std::string> lines2 =
- QUtil::read_lines_from_file("other-file", true);
+ std::list<std::string> lines2 = QUtil::read_lines_from_file("other-file", true);
auto line = lines2.begin();
assert(37 == (*line).length());
assert('.' == (*line).at(35));
@@ -693,8 +674,8 @@ timestamp_test()
// Round trip on the current time without actually printing it.
// Manual testing was done to ensure that we are actually getting
// back the current time in various time zones.
- assert(QUtil::pdf_time_to_qpdf_time(
- QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time())));
+ assert(
+ QUtil::pdf_time_to_qpdf_time(QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time())));
}
void
diff --git a/libtests/runlength.cc b/libtests/runlength.cc
index e034deda..293aee2e 100644
--- a/libtests/runlength.cc
+++ b/libtests/runlength.cc
@@ -11,8 +11,7 @@ int
main(int argc, char* argv[])
{
if (argc != 4) {
- std::cerr << "Usage: runlength {-encode|-decode} infile outfile"
- << std::endl;
+ std::cerr << "Usage: runlength {-encode|-decode} infile outfile" << std::endl;
exit(2);
}
@@ -25,10 +24,7 @@ main(int argc, char* argv[])
Pl_StdioFile out("stdout", outfile);
unsigned char buf[100];
bool done = false;
- Pl_RunLength rl(
- "runlength",
- &out,
- (encode ? Pl_RunLength::a_encode : Pl_RunLength::a_decode));
+ Pl_RunLength rl("runlength", &out, (encode ? Pl_RunLength::a_encode : Pl_RunLength::a_decode));
while (!done) {
size_t len = fread(buf, 1, sizeof(buf), infile);
if (len <= 0) {
diff --git a/libtests/sha2.cc b/libtests/sha2.cc
index 22303da2..3d8675a9 100644
--- a/libtests/sha2.cc
+++ b/libtests/sha2.cc
@@ -4,12 +4,7 @@
#include <iostream>
static void
-test(
- Pl_SHA2& sha2,
- char const* description,
- int bits,
- char const* input,
- std::string const& output)
+test(Pl_SHA2& sha2, char const* description, int bits, char const* input, std::string const& output)
{
sha2.resetBits(bits);
sha2.write(QUtil::unsigned_char_pointer(input), strlen(input));
diff --git a/qpdf/fix-qdf.cc b/qpdf/fix-qdf.cc
index 1d46971c..60163b4f 100644
--- a/qpdf/fix-qdf.cc
+++ b/qpdf/fix-qdf.cc
@@ -103,9 +103,7 @@ QdfFixer::processLines(std::string const& input)
static const std::regex re_num("^\\d+\n$");
static const std::regex re_size_n("^ /Size \\d+\n$");
- auto sv_diff = [](size_t i) {
- return static_cast<std::string_view::difference_type>(i);
- };
+ auto sv_diff = [](size_t i) { return static_cast<std::string_view::difference_type>(i); };
lineno = 0;
bool more = true;
@@ -170,8 +168,7 @@ QdfFixer::processLines(std::string const& input)
// there are no object streams.
int max_objects = 1;
for (auto const& e: xref) {
- if ((e.getType() == 2) &&
- (e.getObjStreamIndex() > max_objects)) {
+ if ((e.getType() == 2) && (e.getObjStreamIndex() > max_objects)) {
max_objects = e.getObjStreamIndex();
}
}
@@ -183,8 +180,7 @@ QdfFixer::processLines(std::string const& input)
xref_size = 1 + xref.size();
auto length = xref_size * esize;
std::cout << " /Length " << length << "\n"
- << " /W [ 1 " << xref_f1_nbytes << " "
- << xref_f2_nbytes << " ]"
+ << " /W [ 1 " << xref_f1_nbytes << " " << xref_f2_nbytes << " ]"
<< "\n";
state = st_in_xref_stream_dict;
}
@@ -224,8 +220,7 @@ QdfFixer::processLines(std::string const& input)
state = st_in_obj;
}
} else if (state == st_in_xref_stream_dict) {
- if ((line.find("/Length"sv) != line.npos) ||
- (line.find("/W"sv) != line.npos)) {
+ if ((line.find("/Length"sv) != line.npos) || (line.find("/W"sv) != line.npos)) {
// already printed
} else if (line.find("/Size"sv) != line.npos) {
auto xref_size = 1 + xref.size();
@@ -274,9 +269,7 @@ QdfFixer::processLines(std::string const& input)
std::cout << line;
} else if (state == st_in_length) {
if (!matches(re_num)) {
- fatal(
- filename + ":" + std::to_string(lineno) +
- ": expected integer");
+ fatal(filename + ":" + std::to_string(lineno) + ": expected integer");
}
std::string new_length = std::to_string(stream_length) + "\n";
offset -= QIntC::to_offset(line.length());
@@ -287,8 +280,7 @@ QdfFixer::processLines(std::string const& input)
auto n = xref.size();
std::cout << "0 " << 1 + n << "\n0000000000 65535 f \n";
for (auto const& e: xref) {
- std::cout << QUtil::int_to_string(e.getOffset(), 10)
- << " 00000 n \n";
+ std::cout << QUtil::int_to_string(e.getOffset(), 10) << " 00000 n \n";
}
state = st_before_trailer;
} else if (state == st_before_trailer) {
@@ -376,8 +368,7 @@ void
QdfFixer::writeBinary(unsigned long long val, size_t bytes)
{
if (bytes > sizeof(unsigned long long)) {
- throw std::logic_error(
- "fix-qdf::writeBinary called with too many bytes");
+ throw std::logic_error("fix-qdf::writeBinary called with too many bytes");
}
std::string data(bytes, '\0');
for (auto i = bytes; i > 0; --i) {
@@ -396,8 +387,7 @@ realmain(int argc, char* argv[])
if (argc > 2) {
usage();
} else if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) {
- std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion()
- << std::endl;
+ std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl;
return 0;
} else if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
usage();
diff --git a/qpdf/pdf_from_scratch.cc b/qpdf/pdf_from_scratch.cc
index 05e5594d..cc0c6ea2 100644
--- a/qpdf/pdf_from_scratch.cc
+++ b/qpdf/pdf_from_scratch.cc
@@ -38,17 +38,16 @@ runtest(int n)
if (n == 0) {
// Create a minimal PDF from scratch.
- QPDFObjectHandle font = pdf.makeIndirectObject(
- QPDFObjectHandle::parse("<<"
- " /Type /Font"
- " /Subtype /Type1"
- " /Name /F1"
- " /BaseFont /Helvetica"
- " /Encoding /WinAnsiEncoding"
- ">>"));
-
- QPDFObjectHandle procset =
- pdf.makeIndirectObject(QPDFObjectHandle::parse("[/PDF /Text]"));
+ QPDFObjectHandle font =
+ pdf.makeIndirectObject(QPDFObjectHandle::parse("<<"
+ " /Type /Font"
+ " /Subtype /Type1"
+ " /Name /F1"
+ " /BaseFont /Helvetica"
+ " /Encoding /WinAnsiEncoding"
+ ">>"));
+
+ QPDFObjectHandle procset = pdf.makeIndirectObject(QPDFObjectHandle::parse("[/PDF /Text]"));
QPDFObjectHandle contents = createPageContents(pdf, "First Page");
@@ -61,8 +60,7 @@ runtest(int n)
resources.replaceKey("/ProcSet", procset);
resources.replaceKey("/Font", rfont);
- QPDFObjectHandle page =
- pdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
+ QPDFObjectHandle page = pdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
page.replaceKey("/Type", newName("/Page"));
page.replaceKey("/MediaBox", mediabox);
page.replaceKey("/Contents", contents);
@@ -75,8 +73,7 @@ runtest(int n)
w.setStreamDataMode(qpdf_s_preserve);
w.write();
} else {
- throw std::runtime_error(
- std::string("invalid test ") + std::to_string(n));
+ throw std::runtime_error(std::string("invalid test ") + std::to_string(n));
}
std::cout << "test " << n << " done" << std::endl;
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index ec671d37..ba177444 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -25,12 +25,7 @@ safe_fopen(char const* filename, char const* mode)
#else
f = fopen(filename, mode);
if (f == NULL) {
- fprintf(
- stderr,
- "%s: unable to open %s: %s\n",
- whoami,
- filename,
- strerror(errno));
+ fprintf(stderr, "%s: unable to open %s: %s\n", whoami, filename, strerror(errno));
exit(2);
}
#endif
@@ -105,20 +100,11 @@ read_file_into_memory(char const* filename, char** buf, unsigned long* size)
}
if (bytes_read != *size) {
if (ferror(f)) {
- fprintf(
- stderr,
- "%s: failure reading file %s into memory:",
- whoami,
- filename);
+ fprintf(stderr, "%s: failure reading file %s into memory:", whoami, filename);
} else {
- fprintf(
- stderr, "%s: premature EOF reading file %s:", whoami, filename);
+ fprintf(stderr, "%s: premature EOF reading file %s:", whoami, filename);
}
- fprintf(
- stderr,
- " read %lu, wanted %lu\n",
- (unsigned long)bytes_read,
- (unsigned long)*size);
+ fprintf(stderr, " read %lu, wanted %lu\n", (unsigned long)bytes_read, (unsigned long)*size);
exit(2);
}
fclose(f);
@@ -147,11 +133,7 @@ custom_log(char const* data, size_t size, void* udata)
}
static void
-test01(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test01(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
printf("version: %s\n", qpdf_get_pdf_version(qpdf));
@@ -162,13 +144,11 @@ test01(
printf("encrypted: %d\n", qpdf_is_encrypted(qpdf));
if (qpdf_is_encrypted(qpdf)) {
printf("user password: %s\n", qpdf_get_user_password(qpdf));
- printf(
- "extract for accessibility: %d\n", qpdf_allow_accessibility(qpdf));
+ printf("extract for accessibility: %d\n", qpdf_allow_accessibility(qpdf));
printf("extract for any purpose: %d\n", qpdf_allow_extract_all(qpdf));
printf("print low resolution: %d\n", qpdf_allow_print_low_res(qpdf));
printf("print high resolution: %d\n", qpdf_allow_print_high_res(qpdf));
- printf(
- "modify document assembly: %d\n", qpdf_allow_modify_assembly(qpdf));
+ printf("modify document assembly: %d\n", qpdf_allow_modify_assembly(qpdf));
printf("modify forms: %d\n", qpdf_allow_modify_form(qpdf));
printf("modify annotations: %d\n", qpdf_allow_modify_annotation(qpdf));
printf("modify other: %d\n", qpdf_allow_modify_other(qpdf));
@@ -178,11 +158,7 @@ test01(
}
static void
-test02(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test02(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_set_suppress_warnings(qpdf, QPDF_TRUE);
if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
@@ -194,11 +170,7 @@ test02(
}
static void
-test03(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test03(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -209,11 +181,7 @@ test03(
}
static void
-test04(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test04(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_set_ignore_xref_streams(qpdf, QPDF_TRUE);
qpdf_read(qpdf, infile, password);
@@ -224,11 +192,7 @@ test04(
}
static void
-test05(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test05(char const* infile, char const* password, char const* outfile, char const* xarg)
{
int count = 0;
qpdf_read(qpdf, infile, password);
@@ -243,11 +207,7 @@ test05(
}
static void
-test06(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test06(char const* infile, char const* password, char const* outfile, char const* xarg)
{
char* buf = NULL;
unsigned long size = 0;
@@ -262,11 +222,7 @@ test06(
}
static void
-test07(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test07(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -277,11 +233,7 @@ test07(
}
static void
-test08(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test08(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -293,11 +245,7 @@ test08(
}
static void
-test09(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test09(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -308,11 +256,7 @@ test09(
}
static void
-test10(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test10(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_set_attempt_recovery(qpdf, QPDF_FALSE);
qpdf_read(qpdf, infile, password);
@@ -320,11 +264,7 @@ test10(
}
static void
-test11(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test11(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -336,11 +276,7 @@ test11(
}
static void
-test12(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test12(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -361,11 +297,7 @@ test12(
}
static void
-test13(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test13(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
printf("user password: %s\n", qpdf_get_user_password(qpdf));
@@ -377,11 +309,7 @@ test13(
}
static void
-test14(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test14(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -396,11 +324,7 @@ test14(
}
static void
-test15(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test15(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -431,11 +355,7 @@ print_info(char const* key)
}
static void
-test16(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test16(char const* infile, char const* password, char const* outfile, char const* xarg)
{
unsigned long buflen = 0L;
unsigned char const* buf = 0;
@@ -465,11 +385,7 @@ test16(
}
static void
-test17(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test17(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -492,11 +408,7 @@ test17(
}
static void
-test18(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test18(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -519,11 +431,7 @@ test18(
}
static void
-test19(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test19(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -533,11 +441,7 @@ test19(
}
static void
-test20(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test20(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -550,11 +454,7 @@ test20(
}
static void
-test21(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test21(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -566,11 +466,7 @@ test21(
}
static void
-test22(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test22(char const* infile, char const* password, char const* outfile, char const* xarg)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
@@ -583,11 +479,7 @@ test22(
}
static void
-test23(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test23(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Test check and also exercise custom logger */
qpdflogger_handle l1 = qpdf_get_logger(qpdf);
@@ -611,11 +503,7 @@ test23(
}
static void
-test24(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test24(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. Pull objects out of
* minimal.pdf to make sure all our accessors work as expected.
@@ -630,9 +518,7 @@ test24(
qpdf_oh root = qpdf_get_root(qpdf);
assert(qpdf_oh_get_generation(qpdf, root) == 0);
qpdf_oh root_from_trailer = qpdf_oh_get_key(qpdf, trailer, "/Root");
- assert(
- qpdf_oh_get_object_id(qpdf, root) ==
- qpdf_oh_get_object_id(qpdf, root_from_trailer));
+ assert(qpdf_oh_get_object_id(qpdf, root) == qpdf_oh_get_object_id(qpdf, root_from_trailer));
/* Go to the first page and look at all the keys */
qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages");
@@ -686,8 +572,7 @@ test24(
qpdf,
qpdf_oh_get_key(
qpdf,
- qpdf_oh_get_key(
- qpdf, qpdf_oh_get_key(qpdf, page1, "/Resources"), "/Font"),
+ qpdf_oh_get_key(qpdf, qpdf_oh_get_key(qpdf, page1, "/Resources"), "/Font"),
"/F1"),
"/Encoding");
assert(strcmp(qpdf_oh_get_name(qpdf, encoding), "/WinAnsiEncoding") == 0);
@@ -698,8 +583,7 @@ test24(
while (qpdf_more_warnings(qpdf)) {
qpdf_next_warning(qpdf);
}
- res = qpdf_oh_get_key_if_dict(
- qpdf, qpdf_oh_get_key_if_dict(qpdf, page1, "/Missing"), "/Font");
+ res = qpdf_oh_get_key_if_dict(qpdf, qpdf_oh_get_key_if_dict(qpdf, page1, "/Missing"), "/Font");
assert(!qpdf_more_warnings(qpdf));
/* Look at page contents to exercise stream functions */
@@ -713,31 +597,26 @@ test24(
qpdf_oh contents_length = qpdf_oh_get_key(qpdf, contents_dict, "/Length");
assert(qpdf_oh_is_integer(qpdf, contents_length));
assert(qpdf_oh_get_type_code(qpdf, contents_length) == ot_integer);
- assert(
- strcmp(qpdf_oh_get_type_name(qpdf, contents_length), "integer") == 0);
+ assert(strcmp(qpdf_oh_get_type_name(qpdf, contents_length), "integer") == 0);
assert(qpdf_oh_is_scalar(qpdf, contents_length));
assert(qpdf_oh_is_number(qpdf, contents_length));
qpdf_oh contents_array = qpdf_oh_wrap_in_array(qpdf, contents);
assert(qpdf_oh_get_array_n_items(qpdf, contents_array) == 1);
assert(
- qpdf_oh_get_object_id(
- qpdf, qpdf_oh_get_array_item(qpdf, contents_array, 0)) ==
+ qpdf_oh_get_object_id(qpdf, qpdf_oh_get_array_item(qpdf, contents_array, 0)) ==
qpdf_oh_get_object_id(qpdf, contents));
/* Wrap in array for a non-trivial case */
- qpdf_oh wrapped_contents_array =
- qpdf_oh_wrap_in_array(qpdf, contents_array);
+ qpdf_oh wrapped_contents_array = qpdf_oh_wrap_in_array(qpdf, contents_array);
assert(qpdf_oh_get_array_n_items(qpdf, wrapped_contents_array) == 1);
assert(
- qpdf_oh_get_object_id(
- qpdf, qpdf_oh_get_array_item(qpdf, wrapped_contents_array, 0)) ==
+ qpdf_oh_get_object_id(qpdf, qpdf_oh_get_array_item(qpdf, wrapped_contents_array, 0)) ==
qpdf_oh_get_object_id(qpdf, contents));
/* Exercise functions that work with indirect objects */
qpdf_oh resources = qpdf_oh_get_key(qpdf, page1, "/Resources");
qpdf_oh procset = qpdf_oh_get_key(qpdf, resources, "/ProcSet");
assert(strcmp(qpdf_oh_unparse(qpdf, procset), "5 0 R") == 0);
- assert(
- strcmp(qpdf_oh_unparse_resolved(qpdf, procset), "[ /PDF /Text ]") == 0);
+ assert(strcmp(qpdf_oh_unparse_resolved(qpdf, procset), "[ /PDF /Text ]") == 0);
qpdf_oh_make_direct(qpdf, procset);
assert(strcmp(qpdf_oh_unparse(qpdf, procset), "[ /PDF /Text ]") == 0);
/* The replaced /ProcSet can be seen to be a direct object in the
@@ -774,19 +653,15 @@ test24(
}
static void
-test25(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test25(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. */
qpdf_read(qpdf, infile, password);
qpdf_oh root = qpdf_get_root(qpdf);
/* Parse objects from a string */
- qpdf_oh parsed = qpdf_oh_parse(
- qpdf, "[ 1 2.0 (3\xf7) << /Four [/Five] >> null true false /Six]");
+ qpdf_oh parsed =
+ qpdf_oh_parse(qpdf, "[ 1 2.0 (3\xf7) << /Four [/Five] >> null true false /Six]");
qpdf_oh p_int = qpdf_oh_get_array_item(qpdf, parsed, 0);
qpdf_oh p_real = qpdf_oh_get_array_item(qpdf, parsed, 1);
qpdf_oh p_string = qpdf_oh_get_array_item(qpdf, parsed, 2);
@@ -795,32 +670,24 @@ test25(
qpdf_oh p_bool = qpdf_oh_get_array_item(qpdf, parsed, 5);
qpdf_oh p_bool_f = qpdf_oh_get_array_item(qpdf, parsed, 6);
qpdf_oh p_name = qpdf_oh_get_array_item(qpdf, parsed, 7);
- assert(
- qpdf_oh_is_integer(qpdf, p_int) &&
- qpdf_oh_get_int_value_as_int(qpdf, p_int) == 1);
+ assert(qpdf_oh_is_integer(qpdf, p_int) && qpdf_oh_get_int_value_as_int(qpdf, p_int) == 1);
long long l = 0;
assert(qpdf_oh_get_value_as_longlong(qpdf, p_bool, &l) == QPDF_FALSE);
- assert(
- (qpdf_oh_get_value_as_longlong(qpdf, p_int, &l) == QPDF_TRUE) &&
- (l == 1));
+ assert((qpdf_oh_get_value_as_longlong(qpdf, p_int, &l) == QPDF_TRUE) && (l == 1));
int i = 0;
assert(qpdf_oh_get_value_as_int(qpdf, p_bool, &i) == QPDF_FALSE);
- assert(
- (qpdf_oh_get_value_as_int(qpdf, p_int, &i) == QPDF_TRUE) && (i == 1));
+ assert((qpdf_oh_get_value_as_int(qpdf, p_int, &i) == QPDF_TRUE) && (i == 1));
unsigned long long ul = 0u;
assert(qpdf_oh_get_value_as_ulonglong(qpdf, p_bool, &ul) == QPDF_FALSE);
- assert(
- (qpdf_oh_get_value_as_ulonglong(qpdf, p_int, &ul) == QPDF_TRUE) &&
- (ul == 1u));
+ assert((qpdf_oh_get_value_as_ulonglong(qpdf, p_int, &ul) == QPDF_TRUE) && (ul == 1u));
unsigned int u = 0u;
assert(qpdf_oh_get_value_as_uint(qpdf, p_bool, &u) == QPDF_FALSE);
- assert(
- (qpdf_oh_get_value_as_uint(qpdf, p_int, &u) == QPDF_TRUE) && (u == 1u));
+ assert((qpdf_oh_get_value_as_uint(qpdf, p_int, &u) == QPDF_TRUE) && (u == 1u));
double d = 0.0;
assert(qpdf_oh_get_value_as_number(qpdf, p_bool, &d) == QPDF_FALSE);
assert(
- (qpdf_oh_get_value_as_number(qpdf, p_int, &d) == QPDF_TRUE) &&
- ((d - 1.0) < 1e-6) && ((d - 1.0) > -1e-6));
+ (qpdf_oh_get_value_as_number(qpdf, p_int, &d) == QPDF_TRUE) && ((d - 1.0) < 1e-6) &&
+ ((d - 1.0) > -1e-6));
assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0);
assert(
@@ -845,22 +712,18 @@ test25(
const char* str = "";
length = 0;
assert(
- (qpdf_oh_get_value_as_string(qpdf, p_name, &str, &length) ==
- QPDF_FALSE) &&
+ (qpdf_oh_get_value_as_string(qpdf, p_name, &str, &length) == QPDF_FALSE) &&
(strcmp(str, "") == 0) && (length == 0));
assert(
- (qpdf_oh_get_value_as_string(qpdf, p_string, &str, &length) ==
- QPDF_TRUE) &&
+ (qpdf_oh_get_value_as_string(qpdf, p_string, &str, &length) == QPDF_TRUE) &&
(strcmp(str, "3\xf7") == 0) && (length == 2));
const char* utf8 = "";
length = 0;
assert(
- (qpdf_oh_get_value_as_utf8(qpdf, p_name, &utf8, &length) ==
- QPDF_FALSE) &&
+ (qpdf_oh_get_value_as_utf8(qpdf, p_name, &utf8, &length) == QPDF_FALSE) &&
(strcmp(utf8, "") == 0) && (length == 0));
assert(
- (qpdf_oh_get_value_as_utf8(qpdf, p_string, &utf8, &length) ==
- QPDF_TRUE) &&
+ (qpdf_oh_get_value_as_utf8(qpdf, p_string, &utf8, &length) == QPDF_TRUE) &&
(strcmp(utf8, "3\xc3\xb7") == 0) && (length == 3));
assert(qpdf_oh_get_type_code(qpdf, p_string) == ot_string);
assert(!qpdf_oh_is_name_and_equals(qpdf, p_string, "3\xf7"));
@@ -869,33 +732,22 @@ test25(
qpdf_oh p_five = qpdf_oh_get_key(qpdf, p_dict, "/Four");
assert(qpdf_oh_is_or_has_name(qpdf, p_five, "/Five"));
assert(!qpdf_oh_is_name_and_equals(qpdf, p_five, "/Five"));
- assert(qpdf_oh_is_or_has_name(
- qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five"));
- assert(qpdf_oh_is_name_and_equals(
- qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five"));
+ assert(qpdf_oh_is_or_has_name(qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five"));
+ assert(qpdf_oh_is_name_and_equals(qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five"));
assert(qpdf_oh_is_null(qpdf, p_null));
assert(qpdf_oh_get_type_code(qpdf, p_null) == ot_null);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_null), "null") == 0);
- assert(
- qpdf_oh_is_bool(qpdf, p_bool) &&
- (qpdf_oh_get_bool_value(qpdf, p_bool) == QPDF_TRUE));
+ assert(qpdf_oh_is_bool(qpdf, p_bool) && (qpdf_oh_get_bool_value(qpdf, p_bool) == QPDF_TRUE));
QPDF_BOOL b = QPDF_FALSE;
- assert(
- (qpdf_oh_get_value_as_bool(qpdf, p_int, &b) == QPDF_FALSE) &&
- b == QPDF_FALSE);
- assert(
- (qpdf_oh_get_value_as_bool(qpdf, p_bool, &b) == QPDF_TRUE) &&
- b == QPDF_TRUE);
- assert(
- (qpdf_oh_get_value_as_bool(qpdf, p_bool_f, &b) == QPDF_TRUE) &&
- b == QPDF_FALSE);
+ assert((qpdf_oh_get_value_as_bool(qpdf, p_int, &b) == QPDF_FALSE) && b == QPDF_FALSE);
+ assert((qpdf_oh_get_value_as_bool(qpdf, p_bool, &b) == QPDF_TRUE) && b == QPDF_TRUE);
+ assert((qpdf_oh_get_value_as_bool(qpdf, p_bool_f, &b) == QPDF_TRUE) && b == QPDF_FALSE);
assert(qpdf_oh_get_type_code(qpdf, p_bool) == ot_boolean);
assert(strcmp(qpdf_oh_get_type_name(qpdf, p_bool), "boolean") == 0);
const char* n = "";
length = 0;
assert(
- (qpdf_oh_get_value_as_name(qpdf, p_string, &n, &length) ==
- QPDF_FALSE) &&
+ (qpdf_oh_get_value_as_name(qpdf, p_string, &n, &length) == QPDF_FALSE) &&
(strcmp(n, "") == 0) && (length == 0));
assert(
(qpdf_oh_get_value_as_name(qpdf, p_name, &n, &length) == QPDF_TRUE) &&
@@ -905,8 +757,7 @@ test25(
qpdf,
parsed,
2,
- qpdf_oh_parse(
- qpdf, "<</A 1 /B 2 /C 3 /D 4 /Type /Test /Subtype /Marvin>>"));
+ qpdf_oh_parse(qpdf, "<</A 1 /B 2 /C 3 /D 4 /Type /Test /Subtype /Marvin>>"));
qpdf_oh new_dict = qpdf_oh_get_array_item(qpdf, parsed, 2);
assert(qpdf_oh_has_key(qpdf, new_dict, "/A"));
assert(qpdf_oh_has_key(qpdf, new_dict, "/D"));
@@ -924,22 +775,14 @@ test25(
assert(!qpdf_oh_has_key(qpdf, new_dict, "/A"));
assert(!qpdf_oh_has_key(qpdf, new_dict, "/D"));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_string(qpdf, "potato"));
+ qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_unicode_string(qpdf, "qww\xc3\xb7\xcf\x80"));
qpdf_oh_append_item(
- qpdf,
- new_array,
- qpdf_oh_new_unicode_string(qpdf, "qww\xc3\xb7\xcf\x80"));
- qpdf_oh_append_item(
- qpdf,
- new_array,
- qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8));
+ qpdf, new_array, qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_null(qpdf)); /* 2 */
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_null(qpdf)); /* 3 */
- qpdf_oh_set_array_item(
- qpdf, new_array, 3, qpdf_oh_new_name(qpdf, "/Quack"));
- qpdf_oh_append_item(
- qpdf, new_array, qpdf_oh_new_real_from_double(qpdf, 4.123, 2));
- qpdf_oh_append_item(
- qpdf, new_array, qpdf_oh_new_real_from_string(qpdf, "5.0"));
+ qpdf_oh_set_array_item(qpdf, new_array, 3, qpdf_oh_new_name(qpdf, "/Quack"));
+ qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_real_from_double(qpdf, 4.123, 2));
+ qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_real_from_string(qpdf, "5.0"));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_integer(qpdf, 6));
qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_bool(qpdf, QPDF_TRUE));
qpdf_oh_replace_key(qpdf, root, "/QTest", new_dict);
@@ -952,11 +795,7 @@ test25(
report_errors();
}
static void
-test26(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test26(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Make sure we detect uninitialized objects */
qpdf_data qpdf2 = qpdf_init();
@@ -967,11 +806,7 @@ test26(
}
static void
-test27(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test27(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Exercise a string with a null. Since the regular methods return
* char*, we can't see past the null character without looking
@@ -979,15 +814,10 @@ test27(
*/
qpdf_oh p_string_with_null = qpdf_oh_parse(qpdf, "<6f6e650074776f>");
assert(qpdf_oh_is_string(qpdf, p_string_with_null));
- assert(
- strcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), "one") == 0);
+ assert(strcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), "one") == 0);
assert(qpdf_get_last_string_length(qpdf) == 7);
/* memcmp adds a character to verify the trailing null */
- assert(
- memcmp(
- qpdf_oh_get_string_value(qpdf, p_string_with_null),
- "one\000two",
- 8) == 0);
+ assert(memcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), "one\000two", 8) == 0);
size_t length = 0;
p_string_with_null = qpdf_oh_new_binary_string(qpdf, "potato\000salad", 12);
/* memcmp adds a character to verify the trailing null */
@@ -999,27 +829,22 @@ test27(
assert(qpdf_get_last_string_length(qpdf) == 12);
assert(length == 12);
/* repeat for UTF8 string */
- qpdf_oh p_utf8_string_with_null =
- qpdf_oh_parse(qpdf, "<feff007100770000007700f703c0>");
+ qpdf_oh p_utf8_string_with_null = qpdf_oh_parse(qpdf, "<feff007100770000007700f703c0>");
assert(qpdf_oh_is_string(qpdf, p_utf8_string_with_null));
assert(
- strcmp(
- qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null),
- "qw\x00w\xc3\xb7\xcf\x80") == 0);
+ strcmp(qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null), "qw\x00w\xc3\xb7\xcf\x80") ==
+ 0);
assert(qpdf_get_last_string_length(qpdf) == 8);
/* memcmp adds a character to verify the trailing null */
assert(
memcmp(
- qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null),
- "qw\x00w\xc3\xb7\xcf\x80",
- 8) == 0);
- p_utf8_string_with_null =
- qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8);
+ qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null), "qw\x00w\xc3\xb7\xcf\x80", 8) ==
+ 0);
+ p_utf8_string_with_null = qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8);
/* memcmp adds a character to verify the trailing null */
assert(
memcmp(
- qpdf_oh_get_binary_utf8_value(
- qpdf, p_utf8_string_with_null, &length),
+ qpdf_oh_get_binary_utf8_value(qpdf, p_utf8_string_with_null, &length),
"qw\x00w\xc3\xb7\xcf\x80",
9) == 0);
assert(qpdf_get_last_string_length(qpdf) == 8);
@@ -1027,11 +852,7 @@ test27(
}
static void
-test28(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test28(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. */
@@ -1062,21 +883,15 @@ test28(
: i == 3 ? 792
: -1));
assert(
- qpdf_oh_get_int_value_as_int(qpdf, item) ==
- qpdf_oh_get_int_value_as_int(qpdf, item2));
+ qpdf_oh_get_int_value_as_int(qpdf, item) == qpdf_oh_get_int_value_as_int(qpdf, item2));
assert(
- qpdf_oh_get_int_value_as_int(qpdf, item) ==
- qpdf_oh_get_int_value_as_int(qpdf, item3));
+ qpdf_oh_get_int_value_as_int(qpdf, item) == qpdf_oh_get_int_value_as_int(qpdf, item3));
qpdf_oh_release(qpdf, item);
}
}
static void
-test29(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test29(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Trap exceptions thrown by object accessors. Type mismatches are
* errors rather than warnings when they don't have an owning QPDF
@@ -1094,8 +909,7 @@ test29(
handle_oh_error(qpdf, "bad parse");
report_errors();
- assert(
- qpdf_oh_get_int_value_as_int(qpdf, qpdf_oh_new_string(qpdf, "x")) == 0);
+ assert(qpdf_oh_get_int_value_as_int(qpdf, qpdf_oh_new_string(qpdf, "x")) == 0);
handle_oh_error(qpdf, "type mismatch (int operation on string)");
qpdf_oh int_oh = qpdf_oh_new_integer(qpdf, 12);
assert(strlen(qpdf_oh_get_string_value(qpdf, int_oh)) == 0);
@@ -1125,22 +939,14 @@ test29(
}
static void
-test30(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test30(char const* infile, char const* password, char const* outfile, char const* xarg)
{
assert(qpdf_read(qpdf, infile, password) & QPDF_ERRORS);
/* Fail to handle error */
}
static void
-test31(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test31(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Make sure type warnings have a specific error code. This test
* case is designed for minimal.pdf.
@@ -1156,11 +962,7 @@ test31(
}
static void
-test32(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test32(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. */
assert(qpdf_read(qpdf, infile, password) == 0);
@@ -1171,11 +973,7 @@ test32(
}
static void
-test33(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test33(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test case is designed for minimal.pdf. */
@@ -1210,11 +1008,7 @@ test33(
}
static void
-test34(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test34(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test expects 11-pages.pdf as file1 and minimal.pdf as xarg. */
@@ -1233,8 +1027,7 @@ test34(
assert(qpdf_oh_get_object_id(qpdf, qpdf_get_page_n(qpdf, 10)) == 14);
qpdf_oh page3 = qpdf_get_page_n(qpdf, 3);
assert(qpdf_find_page_by_oh(qpdf, page3) == 3);
- assert(
- qpdf_find_page_by_id(qpdf, qpdf_oh_get_object_id(qpdf, page3), 0) == 3);
+ assert(qpdf_find_page_by_id(qpdf, qpdf_oh_get_object_id(qpdf, page3), 0) == 3);
/* Add other page to the end */
qpdf_oh opage0 = qpdf_get_page_n(qpdf2, 0);
@@ -1256,11 +1049,7 @@ test34(
}
static void
-test35(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test35(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test uses 11-pages.pdf */
@@ -1306,11 +1095,7 @@ test35(
}
static void
-test36(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test36(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test uses inherited-rotate.pdf */
@@ -1332,11 +1117,7 @@ test36(
}
static void
-test37(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test37(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test uses 11-pages.pdf */
@@ -1353,11 +1134,7 @@ test37(
}
static void
-test38(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test38(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test expects 11-pages.pdf. */
@@ -1366,35 +1143,24 @@ test38(
assert(qpdf_read(qpdf, infile, password) == 0);
qpdf_oh stream = qpdf_get_object_by_id(qpdf, 17, 0);
qpdf_oh dict = qpdf_oh_get_dict(qpdf, stream);
- assert(
- qpdf_oh_get_int_value_as_int(
- qpdf, qpdf_oh_get_key(qpdf, dict, "/Length")) == 53);
+ assert(qpdf_oh_get_int_value_as_int(qpdf, qpdf_oh_get_key(qpdf, dict, "/Length")) == 53);
/* Get raw data */
unsigned char* buf = 0;
size_t len = 0;
- assert(
- qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_none, 0, &buf, &len) ==
- 0);
+ assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_none, 0, &buf, &len) == 0);
assert(len == 53);
assert(((int)buf[0] == 'x') && ((int)buf[1] == 0234));
free(buf);
/* Test whether filterable */
QPDF_BOOL filtered = QPDF_FALSE;
- assert(
- qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, &filtered, 0, 0) ==
- 0);
+ assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, &filtered, 0, 0) == 0);
assert(filtered == QPDF_TRUE);
/* Get filtered data */
- assert(
- qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, 0, &buf, &len) == 0);
+ assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, 0, &buf, &len) == 0);
assert(len == 47);
- assert(
- memcmp(
- (char const*)buf,
- "BT /F1 15 Tf 72 720 Td (Original page 2) Tj ET\n",
- len) == 0);
+ assert(memcmp((char const*)buf, "BT /F1 15 Tf 72 720 Td (Original page 2) Tj ET\n", len) == 0);
/* Get page data */
qpdf_oh page2 = qpdf_get_page_n(qpdf, 1); /* 0-based index */
@@ -1419,11 +1185,7 @@ test38(
}
static void
-test39(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test39(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test expects 11-pages.pdf as file1 and minimal.pdf as xarg. */
@@ -1448,11 +1210,7 @@ test39(
}
static void
-test40(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test40(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* This test expects minimal.pdf. */
@@ -1479,11 +1237,7 @@ test40(
}
static void
-test41(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test41(char const* infile, char const* password, char const* outfile, char const* xarg)
{
/* Empty PDF -- infile is ignored */
assert(qpdf_empty_pdf(qpdf) == 0);
@@ -1494,11 +1248,7 @@ test41(
}
static void
-test42(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test42(char const* infile, char const* password, char const* outfile, char const* xarg)
{
assert(qpdf_create_from_json_file(qpdf, infile) == QPDF_SUCCESS);
qpdf_init_write(qpdf, outfile);
@@ -1508,11 +1258,7 @@ test42(
}
static void
-test43(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test43(char const* infile, char const* password, char const* outfile, char const* xarg)
{
char* buf = NULL;
unsigned long size = 0;
@@ -1526,11 +1272,7 @@ test43(
}
static void
-test44(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test44(char const* infile, char const* password, char const* outfile, char const* xarg)
{
assert(qpdf_read(qpdf, infile, password) == 0);
assert(qpdf_update_from_json_file(qpdf, xarg) == QPDF_SUCCESS);
@@ -1541,11 +1283,7 @@ test44(
}
static void
-test45(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test45(char const* infile, char const* password, char const* outfile, char const* xarg)
{
char* buf = NULL;
unsigned long size = 0;
@@ -1560,39 +1298,23 @@ test45(
}
static void
-test46(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test46(char const* infile, char const* password, char const* outfile, char const* xarg)
{
FILE* f = safe_fopen(outfile, "wb");
assert(qpdf_read(qpdf, infile, password) == 0);
- qpdf_write_json(
- qpdf, 2, write_to_file, f, qpdf_dl_none, qpdf_sj_inline, "", NULL);
+ qpdf_write_json(qpdf, 2, write_to_file, f, qpdf_dl_none, qpdf_sj_inline, "", NULL);
fclose(f);
report_errors();
}
static void
-test47(
- char const* infile,
- char const* password,
- char const* outfile,
- char const* xarg)
+test47(char const* infile, char const* password, char const* outfile, char const* xarg)
{
FILE* f = safe_fopen(outfile, "wb");
assert(qpdf_read(qpdf, infile, password) == 0);
char const* wanted_objects[] = {"obj:4 0 R", "trailer", NULL};
qpdf_write_json(
- qpdf,
- 2,
- write_to_file,
- f,
- qpdf_dl_specialized,
- qpdf_sj_file,
- xarg,
- wanted_objects);
+ qpdf, 2, write_to_file, f, qpdf_dl_specialized, qpdf_sj_file, xarg, wanted_objects);
fclose(f);
report_errors();
}
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc
index 08e94d38..dc9c6f29 100644
--- a/qpdf/qpdf.cc
+++ b/qpdf/qpdf.cc
@@ -15,15 +15,10 @@ usageExit(std::string const& msg)
<< whoami << ": " << msg << std::endl
<< std::endl
<< "For help:" << std::endl
- << " " << whoami << " --help=usage usage information"
- << std::endl
- << " " << whoami << " --help=topic help on a topic"
- << std::endl
- << " " << whoami << " --help=--option help on an option"
- << std::endl
- << " " << whoami
- << " --help general help and a topic list"
- << std::endl
+ << " " << whoami << " --help=usage usage information" << std::endl
+ << " " << whoami << " --help=topic help on a topic" << std::endl
+ << " " << whoami << " --help=--option help on an option" << std::endl
+ << " " << whoami << " --help general help and a topic list" << std::endl
<< std::endl;
exit(QPDFJob::EXIT_ERROR);
}
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index 8bdd8bd0..655f480b 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -112,15 +112,13 @@ ParserCallbacks::contentSize(size_t size)
}
void
-ParserCallbacks::handleObject(
- QPDFObjectHandle obj, size_t offset, size_t length)
+ParserCallbacks::handleObject(QPDFObjectHandle obj, size_t offset, size_t length)
{
if (obj.isName() && (obj.getName() == "/Abort")) {
std::cout << "test suite: terminating parsing" << std::endl;
terminateParsing();
}
- std::cout << obj.getTypeName() << ", offset=" << offset
- << ", length=" << length << ": ";
+ std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": ";
if (obj.isInlineImage()) {
// Exercise getTypeCode
assert(obj.getTypeCode() == ::ot_inlineimage);
@@ -163,9 +161,7 @@ static std::string
getPageContents(QPDFObjectHandle page)
{
std::shared_ptr<Buffer> b1 = page.getKey("/Contents").getStreamData();
- return std::string(
- reinterpret_cast<char*>(b1->getBuffer()), b1->getSize()) +
- "\0";
+ return std::string(reinterpret_cast<char*>(b1->getBuffer()), b1->getSize()) + "\0";
}
static void
@@ -173,8 +169,7 @@ checkPageContents(QPDFObjectHandle page, std::string const& wanted_string)
{
std::string contents = getPageContents(page);
if (contents.find(wanted_string) == std::string::npos) {
- std::cout << "didn't find " << wanted_string << " in " << contents
- << std::endl;
+ std::cout << "didn't find " << wanted_string << " in " << contents << std::endl;
}
}
@@ -188,20 +183,18 @@ createPageContents(QPDF& pdf, std::string const& text)
static void
print_rect(std::ostream& out, QPDFObjectHandle::Rectangle const& r)
{
- out << "[" << r.llx << ", " << r.lly << ", " << r.urx << ", " << r.ury
- << "]";
+ out << "[" << r.llx << ", " << r.lly << ", " << r.urx << ", " << r.ury << "]";
}
-#define assert_compare_numbers(expected, expr) \
- compare_numbers(#expr, expected, expr)
+#define assert_compare_numbers(expected, expr) compare_numbers(#expr, expected, expr)
template <typename T1, typename T2>
static void
compare_numbers(char const* description, T1 const& expected, T2 const& actual)
{
if (expected != actual) {
- std::cerr << description << ": expected = " << expected
- << "; actual = " << actual << std::endl;
+ std::cerr << description << ": expected = " << expected << "; actual = " << actual
+ << std::endl;
}
}
@@ -222,43 +215,35 @@ test_0_1(QPDF& pdf, char const* arg2)
}
QTC::TC("qpdf", "main QTest indirect", qtest.isIndirect() ? 1 : 0);
- std::cout << "/QTest is " << (qtest.isIndirect() ? "in" : "")
- << "direct and has type " << qtest.getTypeName() << " ("
- << qtest.getTypeCode() << ")" << std::endl;
+ std::cout << "/QTest is " << (qtest.isIndirect() ? "in" : "") << "direct and has type "
+ << qtest.getTypeName() << " (" << qtest.getTypeCode() << ")" << std::endl;
if (qtest.isNull()) {
QTC::TC("qpdf", "main QTest null");
std::cout << "/QTest is null" << std::endl;
} else if (qtest.isBool()) {
QTC::TC("qpdf", "main QTest bool", qtest.getBoolValue() ? 1 : 0);
- std::cout << "/QTest is Boolean with value "
- << (qtest.getBoolValue() ? "true" : "false") << std::endl;
+ std::cout << "/QTest is Boolean with value " << (qtest.getBoolValue() ? "true" : "false")
+ << std::endl;
} else if (qtest.isInteger()) {
QTC::TC("qpdf", "main QTest int");
- std::cout << "/QTest is an integer with value " << qtest.getIntValue()
- << std::endl;
+ std::cout << "/QTest is an integer with value " << qtest.getIntValue() << std::endl;
} else if (qtest.isReal()) {
QTC::TC("qpdf", "main QTest real");
- std::cout << "/QTest is a real number with value "
- << qtest.getRealValue() << std::endl;
+ std::cout << "/QTest is a real number with value " << qtest.getRealValue() << std::endl;
} else if (qtest.isName()) {
QTC::TC("qpdf", "main QTest name");
- std::cout << "/QTest is a name with value " << qtest.getName()
- << std::endl;
+ std::cout << "/QTest is a name with value " << qtest.getName() << std::endl;
} else if (qtest.isString()) {
QTC::TC("qpdf", "main QTest string");
- std::cout << "/QTest is a string with value " << qtest.getStringValue()
- << std::endl;
+ std::cout << "/QTest is a string with value " << qtest.getStringValue() << std::endl;
} else if (qtest.isArray()) {
QTC::TC("qpdf", "main QTest array");
- std::cout << "/QTest is an array with " << qtest.getArrayNItems()
- << " items" << std::endl;
+ std::cout << "/QTest is an array with " << qtest.getArrayNItems() << " items" << std::endl;
int i = 0;
for (auto& iter: qtest.aitems()) {
- QTC::TC(
- "qpdf", "main QTest array indirect", iter.isIndirect() ? 1 : 0);
- std::cout << " item " << i << " is "
- << (iter.isIndirect() ? "in" : "") << "direct"
+ QTC::TC("qpdf", "main QTest array indirect", iter.isIndirect() ? 1 : 0);
+ std::cout << " item " << i << " is " << (iter.isIndirect() ? "in" : "") << "direct"
<< std::endl;
++i;
}
@@ -266,18 +251,13 @@ test_0_1(QPDF& pdf, char const* arg2)
QTC::TC("qpdf", "main QTest dictionary");
std::cout << "/QTest is a dictionary" << std::endl;
for (auto& iter: qtest.ditems()) {
- QTC::TC(
- "qpdf",
- "main QTest dictionary indirect",
- iter.second.isIndirect() ? 1 : 0);
- std::cout << " " << iter.first << " is "
- << (iter.second.isIndirect() ? "in" : "") << "direct"
- << std::endl;
+ QTC::TC("qpdf", "main QTest dictionary indirect", iter.second.isIndirect() ? 1 : 0);
+ std::cout << " " << iter.first << " is " << (iter.second.isIndirect() ? "in" : "")
+ << "direct" << std::endl;
}
} else if (qtest.isStream()) {
QTC::TC("qpdf", "main QTest stream");
- std::cout << "/QTest is a stream. Dictionary: "
- << qtest.getDict().unparse() << std::endl;
+ std::cout << "/QTest is a stream. Dictionary: " << qtest.getDict().unparse() << std::endl;
std::cout << "Raw stream data:" << std::endl;
std::cout.flush();
@@ -311,11 +291,8 @@ test_2(QPDF& pdf, char const* arg2)
// PDF file.
QPDFObjectHandle trailer = pdf.getTrailer();
- std::cout
- << trailer.getKey("/Info").getKey("/CreationDate").getStringValue()
- << std::endl;
- std::cout << trailer.getKey("/Info").getKey("/Producer").getStringValue()
- << std::endl;
+ std::cout << trailer.getKey("/Info").getKey("/CreationDate").getStringValue() << std::endl;
+ std::cout << trailer.getKey("/Info").getKey("/Producer").getStringValue() << std::endl;
QPDFObjectHandle encrypt = trailer.getKey("/Encrypt");
std::cout << encrypt.getKey("/O").unparse() << std::endl;
@@ -341,8 +318,7 @@ test_3(QPDF& pdf, char const* arg2)
std::cout.flush();
QUtil::binary_stdout();
auto out = std::make_shared<Pl_StdioFile>("tokenized stream", stdout);
- stream.pipeStreamData(
- out.get(), qpdf_ef_normalize, qpdf_dl_generalized);
+ stream.pipeStreamData(out.get(), qpdf_ef_normalize, qpdf_dl_generalized);
}
}
@@ -410,8 +386,7 @@ test_5(QPDF& pdf, char const* arg2)
QPDFObjectHandle dict = image.getDict();
long long width = dict.getKey("/Width").getIntValue();
long long height = dict.getKey("/Height").getIntValue();
- std::cout << " " << name << ": " << width << " x " << height
- << std::endl;
+ std::cout << " " << name << ": " << width << " x " << height << std::endl;
}
std::cout << " content:" << std::endl;
@@ -439,9 +414,7 @@ test_5(QPDF& pdf, char const* arg2)
int nitems = qnumbers.getArrayNItems();
for (int i = 0; i < nitems; ++i) {
std::cout << QUtil::double_to_string(
- qnumbers.getArrayItem(i).getNumericValue(),
- 3,
- false)
+ qnumbers.getArrayItem(i).getNumericValue(), 3, false)
<< std::endl;
}
}
@@ -475,9 +448,7 @@ test_7(QPDF& pdf, char const* arg2)
throw std::logic_error("test 7 run on file with no QStream");
}
qstream.replaceStreamData(
- "new data for stream\n",
- QPDFObjectHandle::newNull(),
- QPDFObjectHandle::newNull());
+ "new data for stream\n", QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
QPDFWriter w(pdf, "a.pdf");
w.setStaticID(true);
w.setStreamDataMode(qpdf_s_preserve);
@@ -502,9 +473,7 @@ test_8(QPDF& pdf, char const* arg2)
auto* provider = new Provider(b);
auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(provider);
qstream.replaceStreamData(
- p,
- QPDFObjectHandle::newName("/FlateDecode"),
- QPDFObjectHandle::newNull());
+ p, QPDFObjectHandle::newName("/FlateDecode"), QPDFObjectHandle::newNull());
provider->badLength(false);
QPDFWriter w(pdf, "a.pdf");
w.setStaticID(true);
@@ -541,9 +510,7 @@ test_9(QPDF& pdf, char const* arg2)
std::cout << "exception: " << e.what() << std::endl;
}
rstream.replaceStreamData(
- "data for other stream\n",
- QPDFObjectHandle::newNull(),
- QPDFObjectHandle::newNull());
+ "data for other stream\n", QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
root.replaceKey("/QStream", qstream);
root.replaceKey("/RStream", rstream);
QPDFWriter w(pdf, "a.pdf");
@@ -555,17 +522,12 @@ test_9(QPDF& pdf, char const* arg2)
static void
test_10(QPDF& pdf, char const* arg2)
{
- std::vector<QPDFPageObjectHelper> pages =
- QPDFPageDocumentHelper(pdf).getAllPages();
+ std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(pdf).getAllPages();
QPDFPageObjectHelper& ph(pages.at(0));
ph.addPageContents(
- QPDFObjectHandle::newStream(
- &pdf, "BT /F1 12 Tf 72 620 Td (Baked) Tj ET\n"),
- true);
+ QPDFObjectHandle::newStream(&pdf, "BT /F1 12 Tf 72 620 Td (Baked) Tj ET\n"), true);
ph.addPageContents(
- QPDFObjectHandle::newStream(
- &pdf, "BT /F1 18 Tf 72 520 Td (Mashed) Tj ET\n"),
- false);
+ QPDFObjectHandle::newStream(&pdf, "BT /F1 18 Tf 72 520 Td (Mashed) Tj ET\n"), false);
QPDFWriter w(pdf, "a.pdf");
w.setStaticID(true);
@@ -583,8 +545,7 @@ test_11(QPDF& pdf, char const* arg2)
if ((b1->getSize() == 7) && (memcmp(b1->getBuffer(), "potato\n", 7) == 0)) {
std::cout << "filtered stream data okay" << std::endl;
}
- if ((b2->getSize() == 15) &&
- (memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0)) {
+ if ((b2->getSize() == 15) && (memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0)) {
std::cout << "raw stream data okay" << std::endl;
}
}
@@ -661,28 +622,22 @@ test_14(QPDF& pdf, char const* arg2)
}
pdf.replaceObject(qdict.getObjGen(), new_dict);
// Now qdict points to the new dictionary
- std::cout << "old dict: " << qdict.getKey("/NewDict").getIntValue()
- << std::endl;
+ std::cout << "old dict: " << qdict.getKey("/NewDict").getIntValue() << std::endl;
// Swap dict and array
pdf.swapObjects(qdict.getObjGen(), qarray.getObjGen());
// Now qarray will resolve to new object and qdict resolves to
// the array
- std::cout << "swapped array: " << qdict.getArrayItem(0).getName()
- << std::endl;
- std::cout << "new dict: " << qarray.getKey("/NewDict").getIntValue()
- << std::endl;
+ std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << std::endl;
+ std::cout << "new dict: " << qarray.getKey("/NewDict").getIntValue() << std::endl;
// Reread qdict, still pointing to an array
qdict = pdf.getObjectByObjGen(qdict.getObjGen());
- std::cout << "swapped array: " << qdict.getArrayItem(0).getName()
- << std::endl;
+ std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << std::endl;
// Exercise getAsMap and getAsArray
std::vector<QPDFObjectHandle> array_elements = qdict.getArrayAsVector();
std::map<std::string, QPDFObjectHandle> dict_items = qarray.getDictAsMap();
- if ((array_elements.size() == 1) &&
- (array_elements.at(0).getName() == "/Array") &&
- (dict_items.size() == 1) &&
- (dict_items["/NewDict"].getIntValue() == 2)) {
+ if ((array_elements.size() == 1) && (array_elements.at(0).getName() == "/Array") &&
+ (dict_items.size() == 1) && (dict_items["/NewDict"].getIntValue() == 2)) {
std::cout << "array and dictionary contents are correct" << std::endl;
}
@@ -796,8 +751,7 @@ test_16(QPDF& pdf, char const* arg2)
assert(pdf.everCalledGetAllPages());
QPDFObjectHandle contents = createPageContents(pdf, "New page 10");
- QPDFObjectHandle page =
- pdf.makeIndirectObject(QPDFObjectHandle(all_pages.at(0)).shallowCopy());
+ QPDFObjectHandle page = pdf.makeIndirectObject(QPDFObjectHandle(all_pages.at(0)).shallowCopy());
page.replaceKey("/Contents", contents);
// Insert the page manually.
@@ -806,8 +760,7 @@ test_16(QPDF& pdf, char const* arg2)
QPDFObjectHandle kids = pages.getKey("/Kids");
page.replaceKey("/Parent", pages);
pages.replaceKey(
- "/Count",
- QPDFObjectHandle::newInteger(1 + QIntC::to_longlong(all_pages.size())));
+ "/Count", QPDFObjectHandle::newInteger(1 + QIntC::to_longlong(all_pages.size())));
kids.appendItem(page);
assert(all_pages.size() == 10);
pdf.updateAllPagesCache();
@@ -826,9 +779,7 @@ test_17(QPDF& pdf, char const* arg2)
{
// The input file to this test case has a duplicated page.
QPDFObjectHandle page_kids = pdf.getRoot().getKey("/Pages").getKey("/Kids");
- assert(
- page_kids.getArrayItem(0).getObjGen() ==
- page_kids.getArrayItem(1).getObjGen());
+ assert(page_kids.getArrayItem(0).getObjGen() == page_kids.getArrayItem(1).getObjGen());
std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
assert(pages.size() == 3);
assert(!(pages.at(0).getObjGen() == pages.at(1).getObjGen()));
@@ -837,10 +788,8 @@ test_17(QPDF& pdf, char const* arg2)
QPDFObjectHandle(pages.at(1)).getKey("/Contents").getObjGen());
pdf.removePage(pages.at(0));
assert(pages.size() == 2);
- std::shared_ptr<Buffer> b =
- QPDFObjectHandle(pages.at(0)).getKey("/Contents").getStreamData();
- std::string contents = std::string(
- reinterpret_cast<char const*>(b->getBuffer()), b->getSize());
+ std::shared_ptr<Buffer> b = QPDFObjectHandle(pages.at(0)).getKey("/Contents").getStreamData();
+ std::string contents = std::string(reinterpret_cast<char const*>(b->getBuffer()), b->getSize());
assert(contents.find("page 0") != std::string::npos);
}
@@ -880,9 +829,7 @@ test_19(QPDF& pdf, char const* arg2)
auto last = pages.back();
assert(pages.size() == count + 1);
assert(!(last.getObjGen() == newpage.getObjGen()));
- assert(
- last.getKey("/Contents").getObjGen() ==
- newpage.getKey("/Contents").getObjGen());
+ assert(last.getKey("/Contents").getObjGen() == newpage.getKey("/Contents").getObjGen());
}
static void
@@ -955,8 +902,7 @@ test_24(QPDF& pdf, char const* arg2)
std::cout << "oops -- res1 is an array" << std::endl;
}
if (res1.isReserved()) {
- std::cout << "res1 is still reserved after checking if array"
- << std::endl;
+ std::cout << "res1 is still reserved after checking if array" << std::endl;
}
pdf.replaceReserved(res1, array1);
if (res1.isReserved()) {
@@ -1076,8 +1022,7 @@ test_27(QPDF& pdf, char const* arg2)
QPDF empty1;
empty1.emptyPDF();
QPDFObjectHandle s1 = QPDFObjectHandle::newStream(&empty1);
- s1.replaceStreamData(
- p1, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
+ s1.replaceStreamData(p1, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
QPDF empty2;
empty2.emptyPDF();
s1 = empty2.copyForeignObject(s1);
@@ -1102,8 +1047,7 @@ test_27(QPDF& pdf, char const* arg2)
empty3.emptyPDF();
empty3.setImmediateCopyFrom(true);
QPDFObjectHandle s3 = QPDFObjectHandle::newStream(&empty3);
- s3.replaceStreamData(
- p2, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
+ s3.replaceStreamData(p2, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
assert(arg2 != nullptr);
QPDF oldpdf;
oldpdf.processFile(arg2);
@@ -1115,8 +1059,7 @@ test_27(QPDF& pdf, char const* arg2)
QPDFObjectHandle s2 = QPDFObjectHandle::newStream(&oldpdf, "potato\n");
auto trailer = pdf.getTrailer();
trailer.replaceKey("/QTest", pdf.copyForeignObject(qtest));
- auto qtest2 = trailer.replaceKeyAndGetNew(
- "/QTest2", QPDFObjectHandle::newArray());
+ auto qtest2 = trailer.replaceKeyAndGetNew("/QTest2", QPDFObjectHandle::newArray());
qtest2.appendItem(pdf.copyForeignObject(s1));
qtest2.appendItem(pdf.copyForeignObject(s2));
qtest2.appendItem(pdf.copyForeignObject(s3));
@@ -1244,16 +1187,11 @@ test_31(QPDF& pdf, char const* arg2)
} catch (std::runtime_error const& e) {
std::cout << "trailing data: " << e.what() << std::endl;
}
- assert(
- QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isInteger());
+ assert(QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isInteger());
// Make sure an indirect integer followed by "0 R" is not
// mistakenly parsed as an indirect object.
- assert(
- QPDFObjectHandle::parse(&pdf, "[5 0 R 0 R /X]").unparse() ==
- "[ 5 0 R 0 (R) /X ]");
- assert(
- QPDFObjectHandle::parse(&pdf, "[1 0 R]", "indirect test").unparse() ==
- "[ 1 0 R ]");
+ assert(QPDFObjectHandle::parse(&pdf, "[5 0 R 0 R /X]").unparse() == "[ 5 0 R 0 (R) /X ]");
+ assert(QPDFObjectHandle::parse(&pdf, "[1 0 R]", "indirect test").unparse() == "[ 1 0 R ]");
}
static void
@@ -1270,8 +1208,7 @@ test_32(QPDF& pdf, char const* arg2)
<< "linearized: " << (linearized ? "yes" : "no") << std::endl
<< "newline: " << (newline ? "yes" : "no") << std::endl;
w.setLinearization(linearized);
- w.setExtraHeaderText(
- newline ? "%% Comment with newline\n" : "%% Comment\n% No newline");
+ w.setExtraHeaderText(newline ? "%% Comment with newline\n" : "%% Comment\n% No newline");
w.write();
}
}
@@ -1302,8 +1239,7 @@ test_34(QPDF& pdf, char const* arg2)
std::string v_string;
int extension_level;
v.getVersion(v_string, extension_level);
- std::cout << "As PDFVersion: " << v_string << "/" << extension_level
- << std::endl;
+ std::cout << "As PDFVersion: " << v_string << "/" << extension_level << std::endl;
}
static void
@@ -1319,8 +1255,7 @@ test_35(QPDF& pdf, char const* arg2)
for (int i = 0; i < names.getArrayNItems(); ++i) {
QPDFObjectHandle item = names.getArrayItem(i);
if (item.isDictionary() && item.getKey("/Type").isName() &&
- (item.getKey("/Type").getName() == "/Filespec") &&
- item.getKey("/EF").isDictionary() &&
+ (item.getKey("/Type").getName() == "/Filespec") && item.getKey("/EF").isDictionary() &&
item.getKey("/EF").getKey("/F").isStream()) {
std::string filename = item.getKey("/F").getStringValue();
QPDFObjectHandle stream = item.getKey("/EF").getKey("/F");
@@ -1330,8 +1265,7 @@ test_35(QPDF& pdf, char const* arg2)
for (auto const& iter: attachments) {
std::string const& filename = iter.first;
std::string data = std::string(
- reinterpret_cast<char const*>(iter.second->getBuffer()),
- iter.second->getSize());
+ reinterpret_cast<char const*>(iter.second->getBuffer()), iter.second->getSize());
bool is_binary = false;
for (size_t i = 0; i < data.size(); ++i) {
if ((data.at(i) < 0) || (data.at(i) > 126)) {
@@ -1341,8 +1275,7 @@ test_35(QPDF& pdf, char const* arg2)
}
if (is_binary) {
std::string t;
- for (size_t i = 0; i < std::min(data.size(), QIntC::to_size(20));
- ++i) {
+ for (size_t i = 0; i < std::min(data.size(), QIntC::to_size(20)); ++i) {
if ((data.at(i) >= 32) && (data.at(i) <= 126)) {
t += data.at(i);
} else {
@@ -1368,8 +1301,7 @@ test_36(QPDF& pdf, char const* arg2)
for (int i = 0; i < names.getArrayNItems(); ++i) {
QPDFObjectHandle item = names.getArrayItem(i);
if (item.isDictionary() && item.getKey("/Type").isName() &&
- (item.getKey("/Type").getName() == "/Filespec") &&
- item.getKey("/EF").isDictionary() &&
+ (item.getKey("/Type").getName() == "/Filespec") && item.getKey("/EF").isDictionary() &&
item.getKey("/EF").getKey("/F").isStream() &&
(item.getKey("/F").getStringValue() == "attachment1.txt")) {
std::string filename = item.getKey("/F").getStringValue();
@@ -1378,11 +1310,9 @@ test_36(QPDF& pdf, char const* arg2)
Pl_Flate p2("compress", &p1, Pl_Flate::a_inflate);
stream.pipeStreamData(&p2, 0, qpdf_dl_none);
auto buf = p1.getBufferSharedPointer();
- std::string data = std::string(
- reinterpret_cast<char const*>(buf->getBuffer()),
- buf->getSize());
- std::cout << stream.getDict().unparse() << filename << ":\n"
- << data << "--END--\n";
+ std::string data =
+ std::string(reinterpret_cast<char const*>(buf->getBuffer()), buf->getSize());
+ std::cout << stream.getDict().unparse() << filename << ":\n" << data << "--END--\n";
}
}
}
@@ -1417,10 +1347,8 @@ test_39(QPDF& pdf, char const* arg2)
std::map<std::string, QPDFObjectHandle> images = page.getImages();
for (auto& i_iter: images) {
QPDFObjectHandle image_dict = i_iter.second.getDict();
- std::cout << "filter: "
- << image_dict.getKey("/Filter").unparseResolved()
- << ", color space: "
- << image_dict.getKey("/ColorSpace").unparseResolved()
+ std::cout << "filter: " << image_dict.getKey("/Filter").unparseResolved()
+ << ", color space: " << image_dict.getKey("/ColorSpace").unparseResolved()
<< std::endl;
}
}
@@ -1540,27 +1468,23 @@ test_42(QPDF& pdf, char const* arg2)
assert(array.getArrayItem(1).isDictionary());
assert(array.getArrayItem(1).getKey("/K").isArray());
assert(array.getArrayItem(1).getKey("/K").getArrayItem(0).isName());
- assert(
- "/V" == array.getArrayItem(1).getKey("/K").getArrayItem(0).getName());
+ assert("/V" == array.getArrayItem(1).getKey("/K").getArrayItem(0).getName());
std::cerr << "Two errors\n";
assert(array.getArrayItem(16059).getStringValue().empty());
std::cerr << "One error\n";
array.getArrayItem(1).getKey("/K").getArrayItem(0).getStringValue();
// Stream dictionary
QPDFObjectHandle page = pdf.getAllPages().at(0);
- assert(
- "/QPDFFakeName" ==
- page.getKey("/Contents").getDict().getKey("/Potato").getName());
+ assert("/QPDFFakeName" == page.getKey("/Contents").getDict().getKey("/Potato").getName());
// Rectangles
QPDFObjectHandle::Rectangle r0 = integer.getArrayAsRectangle();
assert((r0.llx == 0) && (r0.lly == 0) && (r0.urx == 0) && (r0.ury == 0));
- QPDFObjectHandle rect = QPDFObjectHandle::newFromRectangle(
- QPDFObjectHandle::Rectangle(1.2, 3.4, 5.6, 7.8));
+ QPDFObjectHandle rect =
+ QPDFObjectHandle::newFromRectangle(QPDFObjectHandle::Rectangle(1.2, 3.4, 5.6, 7.8));
QPDFObjectHandle::Rectangle r1 = rect.getArrayAsRectangle();
assert(
- (r1.llx > 1.19) && (r1.llx < 1.21) && (r1.lly > 3.39) &&
- (r1.lly < 3.41) && (r1.urx > 5.59) && (r1.urx < 5.61) &&
- (r1.ury > 7.79) && (r1.ury < 7.81));
+ (r1.llx > 1.19) && (r1.llx < 1.21) && (r1.lly > 3.39) && (r1.lly < 3.41) &&
+ (r1.urx > 5.59) && (r1.urx < 5.61) && (r1.ury > 7.79) && (r1.ury < 7.81));
QPDFObjectHandle uninitialized;
assert(!uninitialized.isInitialized());
assert(!uninitialized.isInteger());
@@ -1589,40 +1513,29 @@ test_43(QPDF& pdf, char const* arg2)
<< std::endl;
node = parent;
}
- std::cout << " Fully qualified name: " << ffh.getFullyQualifiedName()
- << std::endl;
+ std::cout << " Fully qualified name: " << ffh.getFullyQualifiedName() << std::endl;
std::cout << " Partial name: " << ffh.getPartialName() << std::endl;
- std::cout << " Alternative name: " << ffh.getAlternativeName()
- << std::endl;
+ std::cout << " Alternative name: " << ffh.getAlternativeName() << std::endl;
std::cout << " Mapping name: " << ffh.getMappingName() << std::endl;
std::cout << " Field type: " << ffh.getFieldType() << std::endl;
std::cout << " Value: " << ffh.getValue().unparse() << std::endl;
- std::cout << " Value as string: " << ffh.getValueAsString()
- << std::endl;
- std::cout << " Default value: " << ffh.getDefaultValue().unparse()
- << std::endl;
- std::cout << " Default value as string: "
- << ffh.getDefaultValueAsString() << std::endl;
- std::cout << " Default appearance: " << ffh.getDefaultAppearance()
- << std::endl;
+ std::cout << " Value as string: " << ffh.getValueAsString() << std::endl;
+ std::cout << " Default value: " << ffh.getDefaultValue().unparse() << std::endl;
+ std::cout << " Default value as string: " << ffh.getDefaultValueAsString() << std::endl;
+ std::cout << " Default appearance: " << ffh.getDefaultAppearance() << std::endl;
std::cout << " Quadding: " << ffh.getQuadding() << std::endl;
- std::vector<QPDFAnnotationObjectHelper> annotations =
- afdh.getAnnotationsForField(ffh);
+ std::vector<QPDFAnnotationObjectHelper> annotations = afdh.getAnnotationsForField(ffh);
for (auto& aoh: annotations) {
- std::cout << " Annotation: " << aoh.getObjectHandle().unparse()
- << std::endl;
+ std::cout << " Annotation: " << aoh.getObjectHandle().unparse() << std::endl;
}
}
std::cout << "iterating over annotations per page\n";
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl;
for (auto& ah: afdh.getWidgetAnnotationsForPage(page)) {
- std::cout << " Annotation: " << ah.getObjectHandle().unparse()
- << std::endl;
- std::cout
- << " Field: "
- << (afdh.getFieldForAnnotation(ah).getObjectHandle().unparse())
- << std::endl;
+ std::cout << " Annotation: " << ah.getObjectHandle().unparse() << std::endl;
+ std::cout << " Field: "
+ << (afdh.getFieldForAnnotation(ah).getObjectHandle().unparse()) << std::endl;
std::cout << " Subtype: " << ah.getSubtype() << std::endl;
std::cout << " Rect: ";
print_rect(std::cout, ah.getRect());
@@ -1631,11 +1544,10 @@ test_43(QPDF& pdf, char const* arg2)
if (!state.empty()) {
std::cout << " Appearance state: " << state << std::endl;
}
- std::cout << " Appearance stream (/N): "
- << ah.getAppearanceStream("/N").unparse() << std::endl;
- std::cout << " Appearance stream (/N, /3): "
- << ah.getAppearanceStream("/N", "/3").unparse()
+ std::cout << " Appearance stream (/N): " << ah.getAppearanceStream("/N").unparse()
<< std::endl;
+ std::cout << " Appearance stream (/N, /3): "
+ << ah.getAppearanceStream("/N", "/3").unparse() << std::endl;
}
}
}
@@ -1649,8 +1561,8 @@ test_44(QPDF& pdf, char const* arg2)
if (ft.isName() && (ft.getName() == "/Tx")) {
// \xc3\xb7 is utf-8 for U+00F7 (divided by)
field.setV("3.14 \xc3\xb7 0");
- std::cout << "Set field value: " << field.getFullyQualifiedName()
- << " -> " << field.getValueAsString() << std::endl;
+ std::cout << "Set field value: " << field.getFullyQualifiedName() << " -> "
+ << field.getValueAsString() << std::endl;
}
}
QPDFWriter w(pdf, "a.pdf");
@@ -1682,13 +1594,11 @@ test_46(QPDF& pdf, char const* arg2)
QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest");
QPDFNumberTreeObjectHelper ntoh(qtest, pdf);
for (auto& iter: ntoh) {
- std::cout << iter.first << " " << iter.second.getStringValue()
- << std::endl;
+ std::cout << iter.first << " " << iter.second.getStringValue() << std::endl;
}
QPDFNumberTreeObjectHelper::idx_map ntoh_map = ntoh.getAsMap();
for (auto& iter: ntoh_map) {
- std::cout << iter.first << " " << iter.second.getStringValue()
- << std::endl;
+ std::cout << iter.first << " " << iter.second.getStringValue() << std::endl;
}
assert(1 == ntoh.getMin());
assert(29 == ntoh.getMax());
@@ -1747,14 +1657,12 @@ test_46(QPDF& pdf, char const* arg2)
}
std::cout << "/Bad1" << std::endl;
- auto bad1 =
- QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad1"), pdf);
+ auto bad1 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad1"), pdf);
assert(bad1.begin() == bad1.end());
assert(bad1.last() == bad1.end());
std::cout << "/Bad2" << std::endl;
- auto bad2 =
- QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad2"), pdf);
+ auto bad2 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad2"), pdf);
for (auto& i: bad2) {
std::cout << i.first << " " << i.second.unparse() << std::endl;
}
@@ -1762,8 +1670,7 @@ test_46(QPDF& pdf, char const* arg2)
std::vector<std::string> empties = {"/Empty1", "/Empty2"};
for (auto const& k: empties) {
std::cout << k << std::endl;
- auto empty =
- QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey(k), pdf);
+ auto empty = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey(k), pdf);
assert(empty.begin() == empty.end());
assert(empty.last() == empty.end());
auto i = empty.insert(5, QPDFObjectHandle::newString("5"));
@@ -1784,8 +1691,7 @@ test_46(QPDF& pdf, char const* arg2)
assert(empty.last()->second.getStringValue() == "6");
}
std::cout << "Insert into invalid" << std::endl;
- auto invalid1 =
- QPDFNumberTreeObjectHelper(QPDFObjectHandle::newDictionary(), pdf);
+ auto invalid1 = QPDFNumberTreeObjectHelper(QPDFObjectHandle::newDictionary(), pdf);
try {
invalid1.insert(1, QPDFObjectHandle::newNull());
} catch (QPDFExc& e) {
@@ -1808,16 +1714,14 @@ test_46(QPDF& pdf, char const* arg2)
assert(bad3_oh.getKey("/Kids").getArrayItem(0).isIndirect());
std::cout << "/Bad4 -- missing limits" << std::endl;
- auto bad4 =
- QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad4"), pdf);
+ auto bad4 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad4"), pdf);
bad4.insert(5, QPDFObjectHandle::newString("5"));
for (auto& i: bad4) {
std::cout << i.first << " " << i.second.unparse() << std::endl;
}
std::cout << "/Bad5 -- limit errors" << std::endl;
- auto bad5 =
- QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad5"), pdf);
+ auto bad5 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad5"), pdf);
assert(bad5.find(10) == bad5.end());
}
@@ -1826,14 +1730,12 @@ test_47(QPDF& pdf, char const* arg2)
{
// Test page labels.
QPDFPageLabelDocumentHelper pldh(pdf);
- long long npages =
- pdf.getRoot().getKey("/Pages").getKey("/Count").getIntValue();
+ long long npages = pdf.getRoot().getKey("/Pages").getKey("/Count").getIntValue();
std::vector<QPDFObjectHandle> labels;
pldh.getLabelsForPageRange(0, npages - 1, 1, labels);
assert(labels.size() % 2 == 0);
for (size_t i = 0; i < labels.size(); i += 2) {
- std::cout << labels.at(i).getIntValue() << " "
- << labels.at(i + 1).unparse() << std::endl;
+ std::cout << labels.at(i).getIntValue() << " " << labels.at(i + 1).unparse() << std::endl;
}
}
@@ -1845,13 +1747,11 @@ test_48(QPDF& pdf, char const* arg2)
QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest");
QPDFNameTreeObjectHelper ntoh(qtest, pdf);
for (auto& iter: ntoh) {
- std::cout << iter.first << " -> " << iter.second.getStringValue()
- << std::endl;
+ std::cout << iter.first << " -> " << iter.second.getStringValue() << std::endl;
}
std::map<std::string, QPDFObjectHandle> ntoh_map = ntoh.getAsMap();
for (auto& iter: ntoh_map) {
- std::cout << iter.first << " -> " << iter.second.getStringValue()
- << std::endl;
+ std::cout << iter.first << " -> " << iter.second.getStringValue() << std::endl;
}
assert(ntoh.hasName("11 elephant"));
assert(ntoh.hasName("07 sev\xe2\x80\xa2n"));
@@ -1971,8 +1871,7 @@ test_49(QPDF& pdf, char const* arg2)
QPDFOutlineDocumentHelper odh(pdf);
int pageno = 0;
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
- auto outlines =
- odh.getOutlinesForPage(page.getObjectHandle().getObjGen());
+ auto outlines = odh.getOutlinesForPage(page.getObjectHandle().getObjGen());
for (auto& ol: outlines) {
std::cout << "page " << pageno << ": " << ol.getTitle() << " -> "
<< ol.getDest().unparseResolved() << std::endl;
@@ -2069,8 +1968,7 @@ test_53(QPDF& pdf, char const* arg2)
{
// Test get all objects and dangling ref handling
QPDFObjectHandle root = pdf.getRoot();
- auto new_obj =
- pdf.makeIndirectObject(QPDFObjectHandle::newString("potato"));
+ auto new_obj = pdf.makeIndirectObject(QPDFObjectHandle::newString("potato"));
root.replaceKey("/Q1", new_obj);
std::cout << "new object: " << new_obj.unparse() << std::endl;
std::cout << "all objects" << std::endl;
@@ -2101,8 +1999,7 @@ static void
test_55(QPDF& pdf, char const* arg2)
{
// Form XObjects
- std::vector<QPDFPageObjectHelper> pages =
- QPDFPageDocumentHelper(pdf).getAllPages();
+ std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(pdf).getAllPages();
QPDFObjectHandle qtest = QPDFObjectHandle::newArray();
for (auto& ph: pages) {
qtest.appendItem(ph.getFormXObjectForPage());
@@ -2117,10 +2014,7 @@ test_55(QPDF& pdf, char const* arg2)
static void
test_56_59(
- QPDF& pdf,
- char const* arg2,
- bool handle_from_transformation,
- bool invert_to_transformation)
+ QPDF& pdf, char const* arg2, bool handle_from_transformation, bool invert_to_transformation)
{
// red pages are from pdf, blue pages are from pdf2
// red pages always have stated rotation absolutely
@@ -2134,32 +2028,24 @@ test_56_59(
QPDF pdf2;
pdf2.processFile(arg2);
- std::vector<QPDFPageObjectHelper> pages1 =
- QPDFPageDocumentHelper(pdf).getAllPages();
- std::vector<QPDFPageObjectHelper> pages2 =
- QPDFPageDocumentHelper(pdf2).getAllPages();
- size_t npages =
- (pages1.size() < pages2.size() ? pages1.size() : pages2.size());
+ std::vector<QPDFPageObjectHelper> pages1 = QPDFPageDocumentHelper(pdf).getAllPages();
+ std::vector<QPDFPageObjectHelper> pages2 = QPDFPageDocumentHelper(pdf2).getAllPages();
+ size_t npages = (pages1.size() < pages2.size() ? pages1.size() : pages2.size());
for (size_t i = 0; i < npages; ++i) {
QPDFPageObjectHelper& ph1 = pages1.at(i);
QPDFPageObjectHelper& ph2 = pages2.at(i);
- QPDFObjectHandle fo = pdf.copyForeignObject(
- ph2.getFormXObjectForPage(handle_from_transformation));
+ QPDFObjectHandle fo =
+ pdf.copyForeignObject(ph2.getFormXObjectForPage(handle_from_transformation));
int min_suffix = 1;
QPDFObjectHandle resources = ph1.getAttribute("/Resources", true);
std::string name = resources.getUniqueResourceName("/Fx", min_suffix);
std::string content = ph1.placeFormXObject(
- fo,
- name,
- ph1.getTrimBox().getArrayAsRectangle(),
- invert_to_transformation);
+ fo, name, ph1.getTrimBox().getArrayAsRectangle(), invert_to_transformation);
if (!content.empty()) {
- resources.mergeResources(
- QPDFObjectHandle::parse("<< /XObject << >> >>"));
+ resources.mergeResources(QPDFObjectHandle::parse("<< /XObject << >> >>"));
resources.getKey("/XObject").replaceKey(name, fo);
ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "q\n"), true);
- ph1.addPageContents(
- QPDFObjectHandle::newStream(&pdf, "\nQ\n" + content), false);
+ ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "\nQ\n" + content), false);
}
}
QPDFWriter w(pdf, "a.pdf");
@@ -2205,13 +2091,12 @@ test_60(QPDF& pdf, char const* arg2)
r1.mergeResources(QPDFObjectHandle::parse("<< /Z << >> >>"));
r1.getKey("/Z").replaceKey(name, QPDFObjectHandle::newString("moo"));
}
- auto make_resource = [&](QPDFObjectHandle& dict,
- std::string const& key,
- std::string const& str) {
- auto o1 = QPDFObjectHandle::newArray();
- o1.appendItem(QPDFObjectHandle::newString(str));
- dict.replaceKey(key, pdf.makeIndirectObject(o1));
- };
+ auto make_resource =
+ [&](QPDFObjectHandle& dict, std::string const& key, std::string const& str) {
+ auto o1 = QPDFObjectHandle::newArray();
+ o1.appendItem(QPDFObjectHandle::newString(str));
+ dict.replaceKey(key, pdf.makeIndirectObject(o1));
+ };
auto z = r1.getKey("/Z");
r1.replaceKey("/Y", QPDFObjectHandle::newDictionary());
@@ -2235,8 +2120,7 @@ test_60(QPDF& pdf, char const* arg2)
for (auto const& i1: conflicts) {
std::cout << i1.first << ":" << std::endl;
for (auto const& i2: i1.second) {
- std::cout << " " << i2.first << " -> " << i2.second
- << std::endl;
+ std::cout << " " << i2.first << " -> " << i2.second << std::endl;
}
}
};
@@ -2313,8 +2197,7 @@ test_61(QPDF& pdf, char const* arg2)
// For some reason, QPDFNameTreeObjectHelper's vtable seems to
// like to not make it into the shared library with mingw. Try to
// make sure this is really fixed.
- QPDFNameTreeObjectHelper* n =
- new ExtendNameTree(QPDFObjectHandle::newNull(), pdf);
+ QPDFNameTreeObjectHelper* n = new ExtendNameTree(QPDFObjectHandle::newNull(), pdf);
delete n;
}
@@ -2354,8 +2237,7 @@ test_63(QPDF& pdf, char const* arg2)
// or deterministic ID is used because the filename is not
// used as part of the input data for ID generation in those
// cases.
- w.setR6EncryptionParameters(
- "u", "o", true, true, true, true, true, true, qpdf_r3p_full, true);
+ w.setR6EncryptionParameters("u", "o", true, true, true, true, true, true, qpdf_r3p_full, true);
w.setOutputFilename("a.pdf");
w.write();
}
@@ -2374,34 +2256,23 @@ test_64_67(QPDF& pdf, char const* arg2, bool allow_shrink, bool allow_expand)
QPDF pdf2;
pdf2.processFile(arg2);
- std::vector<QPDFPageObjectHelper> pages1 =
- QPDFPageDocumentHelper(pdf).getAllPages();
- std::vector<QPDFPageObjectHelper> pages2 =
- QPDFPageDocumentHelper(pdf2).getAllPages();
- size_t npages =
- (pages1.size() < pages2.size() ? pages1.size() : pages2.size());
+ std::vector<QPDFPageObjectHelper> pages1 = QPDFPageDocumentHelper(pdf).getAllPages();
+ std::vector<QPDFPageObjectHelper> pages2 = QPDFPageDocumentHelper(pdf2).getAllPages();
+ size_t npages = (pages1.size() < pages2.size() ? pages1.size() : pages2.size());
for (size_t i = 0; i < npages; ++i) {
QPDFPageObjectHelper& ph1 = pages1.at(i);
QPDFPageObjectHelper& ph2 = pages2.at(i);
- QPDFObjectHandle fo =
- pdf.copyForeignObject(ph2.getFormXObjectForPage());
+ QPDFObjectHandle fo = pdf.copyForeignObject(ph2.getFormXObjectForPage());
int min_suffix = 1;
QPDFObjectHandle resources = ph1.getAttribute("/Resources", true);
std::string name = resources.getUniqueResourceName("/Fx", min_suffix);
std::string content = ph1.placeFormXObject(
- fo,
- name,
- ph1.getTrimBox().getArrayAsRectangle(),
- false,
- allow_shrink,
- allow_expand);
+ fo, name, ph1.getTrimBox().getArrayAsRectangle(), false, allow_shrink, allow_expand);
if (!content.empty()) {
- resources.mergeResources(
- QPDFObjectHandle::parse("<< /XObject << >> >>"));
+ resources.mergeResources(QPDFObjectHandle::parse("<< /XObject << >> >>"));
resources.getKey("/XObject").replaceKey(name, fo);
ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "q\n"), true);
- ph1.addPageContents(
- QPDFObjectHandle::newStream(&pdf, "\nQ\n" + content), false);
+ ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "\nQ\n" + content), false);
}
}
QPDFWriter w(pdf, "a.pdf");
@@ -2446,15 +2317,12 @@ test_68(QPDF& pdf, char const* arg2)
std::cout << "get unfilterable stream: " << e.what() << std::endl;
}
std::shared_ptr<Buffer> b1 = qstream.getStreamData(qpdf_dl_all);
- if ((b1->getSize() > 10) &&
- (memcmp(b1->getBuffer(), "wwwwwwwww", 9) == 0)) {
+ if ((b1->getSize() > 10) && (memcmp(b1->getBuffer(), "wwwwwwwww", 9) == 0)) {
std::cout << "filtered stream data okay" << std::endl;
}
std::shared_ptr<Buffer> b2 = qstream.getRawStreamData();
if ((b2->getSize() > 10) &&
- (memcmp(
- b2->getBuffer(), "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46", 10) ==
- 0)) {
+ (memcmp(b2->getBuffer(), "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46", 10) == 0)) {
std::cout << "raw stream data okay" << std::endl;
}
}
@@ -2468,8 +2336,7 @@ test_69(QPDF& pdf, char const* arg2)
QPDF out;
out.emptyPDF();
out.addPage(pages.at(i), false);
- std::string outname =
- std::string("auto-") + QUtil::uint_to_string(i) + ".pdf";
+ std::string outname = std::string("auto-") + QUtil::uint_to_string(i) + ".pdf";
QPDFWriter w(out, outname.c_str());
w.setStaticID(true);
w.write();
@@ -2491,11 +2358,8 @@ test_70(QPDF& pdf, char const* arg2)
static void
test_71(QPDF& pdf, char const* arg2)
{
- auto show = [](QPDFObjectHandle& obj,
- QPDFObjectHandle& xobj_dict,
- std::string const& key) {
- std::cout << xobj_dict.unparse() << " -> " << key << " -> "
- << obj.unparse() << std::endl;
+ auto show = [](QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key) {
+ std::cout << xobj_dict.unparse() << " -> " << key << " -> " << obj.unparse() << std::endl;
};
auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0);
std::cout << "--- recursive, all ---" << std::endl;
@@ -2510,10 +2374,8 @@ test_71(QPDF& pdf, char const* arg2)
page.forEachFormXObject(true, show);
std::cout << "--- non-recursive, form XObjects ---" << std::endl;
page.forEachFormXObject(false, show);
- auto fx1 = QPDFPageObjectHelper(page.getObjectHandle()
- .getKey("/Resources")
- .getKey("/XObject")
- .getKey("/Fx1"));
+ auto fx1 = QPDFPageObjectHelper(
+ page.getObjectHandle().getKey("/Resources").getKey("/XObject").getKey("/Fx1"));
std::cout << "--- recursive, all, from fx1 ---" << std::endl;
fx1.forEachXObject(true, show);
std::cout << "--- non-recursive, all, from fx1 ---" << std::endl;
@@ -2541,10 +2403,8 @@ test_72(QPDF& pdf, char const* arg2)
{
// Call some QPDFPageObjectHelper methods on form XObjects.
auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0);
- auto fx1 = QPDFPageObjectHelper(page.getObjectHandle()
- .getKey("/Resources")
- .getKey("/XObject")
- .getKey("/Fx1"));
+ auto fx1 = QPDFPageObjectHelper(
+ page.getObjectHandle().getKey("/Resources").getKey("/XObject").getKey("/Fx1"));
std::cout << "--- parseContents ---" << std::endl;
ParserCallbacks cb;
fx1.parseContents(&cb);
@@ -2555,17 +2415,14 @@ test_72(QPDF& pdf, char const* arg2)
Pl_Buffer b("buffer");
if (i == 0) {
fx1.addContentTokenFilter(
- std::shared_ptr<QPDFObjectHandle::TokenFilter>(
- new TokenFilter()));
+ std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter()));
} else {
fx1.getObjectHandle().addTokenFilter(
- std::shared_ptr<QPDFObjectHandle::TokenFilter>(
- new TokenFilter()));
+ std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter()));
}
fx1.pipeContents(&b);
std::unique_ptr<Buffer> buf(b.getBuffer());
- std::string s(
- reinterpret_cast<char const*>(buf->getBuffer()), buf->getSize());
+ std::string s(reinterpret_cast<char const*>(buf->getBuffer()), buf->getSize());
assert(s.find("/bye") != std::string::npos);
}
}
@@ -2589,12 +2446,10 @@ test_74(QPDF& pdf, char const* arg2)
{
// This test is crafted to work with split-nntree.pdf
std::cout << "/Split1" << std::endl;
- auto split1 =
- QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Split1"), pdf);
+ auto split1 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Split1"), pdf);
split1.setSplitThreshold(4);
auto check_split1 = [&split1](int k) {
- auto i = split1.insert(
- k, QPDFObjectHandle::newString(QUtil::int_to_string(k)));
+ auto i = split1.insert(k, QPDFObjectHandle::newString(QUtil::int_to_string(k)));
assert(i->first == k);
};
check_split1(15);
@@ -2605,11 +2460,9 @@ test_74(QPDF& pdf, char const* arg2)
}
std::cout << "/Split2" << std::endl;
- auto split2 =
- QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split2"), pdf);
+ auto split2 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split2"), pdf);
split2.setSplitThreshold(4);
- auto check_split2 = [](QPDFNameTreeObjectHelper& noh,
- std::string const& k) {
+ auto check_split2 = [](QPDFNameTreeObjectHelper& noh, std::string const& k) {
auto i = noh.insert(k, QPDFObjectHandle::newUnicodeString(k));
assert(i->first == k);
};
@@ -2619,8 +2472,7 @@ test_74(QPDF& pdf, char const* arg2)
}
std::cout << "/Split3" << std::endl;
- auto split3 =
- QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split3"), pdf);
+ auto split3 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split3"), pdf);
split3.setSplitThreshold(4);
check_split2(split3, "P");
check_split2(split3, "\xcf\x80");
@@ -2638,8 +2490,7 @@ static void
test_75(QPDF& pdf, char const* arg2)
{
// This test is crafted to work with erase-nntree.pdf
- auto erase1 =
- QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Erase1"), pdf);
+ auto erase1 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Erase1"), pdf);
QPDFObjectHandle value;
assert(!erase1.remove("1X"));
assert(erase1.remove("1C", &value));
@@ -2675,16 +2526,14 @@ test_75(QPDF& pdf, char const* arg2)
k1 = k1.getKey("/Kids");
assert(k1.getArrayNItems() == 1);
- auto erase3 =
- QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Erase3"), pdf);
+ auto erase3 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Erase3"), pdf);
iter2 = erase3.find(320);
iter2.remove();
assert(iter2 == erase3.end());
erase3.remove(310);
assert(erase3.begin() == erase3.end());
- auto erase4 =
- QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Erase4"), pdf);
+ auto erase4 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Erase4"), pdf);
iter2 = erase4.find(420);
iter2.remove();
assert(iter2->first == 430);
@@ -2714,12 +2563,10 @@ test_76(QPDF& pdf, char const* arg2)
// exercise Pipeline::operator<<(std::string const&)
p << std::string("from buffer");
p.finish();
- auto efs3 = QPDFEFStreamObjectHelper::createEFStream(
- pdf, p.getBufferSharedPointer());
+ auto efs3 = QPDFEFStreamObjectHelper::createEFStream(pdf, p.getBufferSharedPointer());
efs3.setSubtype("text/plain");
efdh.replaceEmbeddedFile(
- "att2",
- QPDFFileSpecObjectHelper::createFileSpec(pdf, "att2.txt", efs2));
+ "att2", QPDFFileSpecObjectHelper::createFileSpec(pdf, "att2.txt", efs2));
auto fs3 = QPDFFileSpecObjectHelper::createFileSpec(pdf, "att3.txt", efs3);
efdh.replaceEmbeddedFile("att3", fs3);
fs3.setFilename("\xcf\x80.txt", "att3.txt");
@@ -2728,13 +2575,10 @@ test_76(QPDF& pdf, char const* arg2)
assert(efs1.getModDate() == "D:20210208001122Z");
assert(efs2.getSize() == 11);
assert(efs2.getSubtype() == "text/plain");
- assert(
- QUtil::hex_encode(efs2.getChecksum()) ==
- "2fce9c8228e360ba9b04a1bd1bf63d6b");
+ assert(QUtil::hex_encode(efs2.getChecksum()) == "2fce9c8228e360ba9b04a1bd1bf63d6b");
for (auto iter: efdh.getEmbeddedFiles()) {
- std::cout << iter.first << " -> " << iter.second->getFilename()
- << std::endl;
+ std::cout << iter.first << " -> " << iter.second->getFilename() << std::endl;
}
assert(efdh.getEmbeddedFile("att1")->getFilename() == "att1.txt");
assert(!efdh.getEmbeddedFile("potato"));
@@ -2787,8 +2631,7 @@ test_78(QPDF& pdf, char const* arg2)
s1.replaceStreamData(f1, null, null);
auto s2 = QPDFObjectHandle::newStream(&pdf);
s2.replaceStreamData(f2, null, null);
- pdf.getTrailer().replaceKey(
- "/Streams", QPDFObjectHandle::newArray({s1, s2}));
+ pdf.getTrailer().replaceKey("/Streams", QPDFObjectHandle::newArray({s1, s2}));
std::cout << "piping with warning suppression" << std::endl;
Pl_Discard d;
s2.pipeStreamData(&d, nullptr, 0, qpdf_dl_all, true, false);
@@ -2823,11 +2666,8 @@ test_79(QPDF& pdf, char const* arg2)
QPDFObjectHandle::parse(
&pdf,
"<< /Direct 3 /Indirect " +
- pdf.makeIndirectObject(QPDFObjectHandle::newInteger(16059))
- .unparse() +
- ">>"));
- s2.getDict().replaceKey(
- "/Other", QPDFObjectHandle::newString("other stuff"));
+ pdf.makeIndirectObject(QPDFObjectHandle::newInteger(16059)).unparse() + ">>"));
+ s2.getDict().replaceKey("/Other", QPDFObjectHandle::newString("other stuff"));
// Use a provider
Pl_Buffer b("buffer");
@@ -2837,8 +2677,7 @@ test_79(QPDF& pdf, char const* arg2)
auto s3 = QPDFObjectHandle::newStream(&pdf, bp);
std::vector<QPDFObjectHandle> streams = {s1, s2, s3};
- pdf.getTrailer().replaceKey(
- "/Originals", QPDFObjectHandle::newArray(streams));
+ pdf.getTrailer().replaceKey("/Originals", QPDFObjectHandle::newArray(streams));
int i = 0;
for (auto orig: streams) {
@@ -2846,16 +2685,11 @@ test_79(QPDF& pdf, char const* arg2)
auto istr = QUtil::int_to_string(i);
auto orig_data = orig.getStreamData();
auto copy = orig.copyStream();
- copy.getDict().replaceKey(
- "/Other", QPDFObjectHandle::newString("other: " + istr));
+ copy.getDict().replaceKey("/Other", QPDFObjectHandle::newString("other: " + istr));
orig.replaceStreamData("something new " + istr, null, null);
auto copy_data = copy.getStreamData();
assert(orig_data->getSize() == copy_data->getSize());
- assert(
- memcmp(
- orig_data->getBuffer(),
- copy_data->getBuffer(),
- orig_data->getSize()) == 0);
+ assert(memcmp(orig_data->getBuffer(), copy_data->getBuffer(), orig_data->getSize()) == 0);
copies.appendItem(copy);
}
@@ -2887,8 +2721,7 @@ test_80(QPDF& pdf, char const* arg2)
std::set<QPDFObjGen> old_fields;
QPDFAcroFormDocumentHelper afdh(pdf);
// Use defaults for from_qpdf and from_afdh.
- afdh.transformAnnotations(
- old_annots, new_annots, new_fields, old_fields, m);
+ afdh.transformAnnotations(old_annots, new_annots, new_fields, old_fields, m);
for (auto const& annot: new_annots) {
old_annots.appendItem(annot);
}
@@ -2935,8 +2768,7 @@ test_82(QPDF& pdf, char const* arg2)
assert(name.isNameAndEquals("/Marvin"));
assert(!name.isNameAndEquals("Marvin"));
assert(!str.isNameAndEquals("/Marvin"));
- auto dict =
- QPDFObjectHandle::parse("<</A 1 /Type /Test /Subtype /Marvin>>");
+ auto dict = QPDFObjectHandle::parse("<</A 1 /Type /Test /Subtype /Marvin>>");
assert(dict.isDictionaryOfType("/Test", ""));
assert(dict.isDictionaryOfType("/Test"));
assert(dict.isDictionaryOfType("/Test", "/Marvin"));
@@ -3016,9 +2848,8 @@ test_84(QPDF& pdf, char const* arg2)
std::cout << "custom progress reporter" << std::endl;
{
QPDFJob j;
- j.registerProgressReporter([](int p) {
- std::cout << "custom write progress: " << p << "%" << std::endl;
- });
+ j.registerProgressReporter(
+ [](int p) { std::cout << "custom write progress: " << p << "%" << std::endl; });
j.config()
->inputFile("minimal.pdf")
->outputFile("a.pdf")
@@ -3071,10 +2902,7 @@ test_84(QPDF& pdf, char const* arg2)
#if (defined(__GNUC__) || defined(__clang__))
# pragma GCC diagnostic pop
#endif
- j.config()
- ->inputFile("bad2.pdf")
- ->showObject("4,0")
- ->checkConfiguration();
+ j.config()->inputFile("bad2.pdf")->showObject("4,0")->checkConfiguration();
std::cout << "calling run" << std::endl;
j.run();
std::cout << "captured stdout" << std::endl;
@@ -3091,12 +2919,9 @@ test_85(QPDF& pdf, char const* arg2)
auto oh_b = QPDFObjectHandle::newBool(false);
auto oh_i = QPDFObjectHandle::newInteger(1);
- auto oh_i_maxplus =
- QPDFObjectHandle::newInteger(QIntC::to_longlong(INT_MAX) + 1LL);
- auto oh_i_umaxplus =
- QPDFObjectHandle::newInteger(QIntC::to_longlong(UINT_MAX) + 1LL);
- auto oh_i_minminus =
- QPDFObjectHandle::newInteger(QIntC::to_longlong(INT_MIN) - 1LL);
+ auto oh_i_maxplus = QPDFObjectHandle::newInteger(QIntC::to_longlong(INT_MAX) + 1LL);
+ auto oh_i_umaxplus = QPDFObjectHandle::newInteger(QIntC::to_longlong(UINT_MAX) + 1LL);
+ auto oh_i_minminus = QPDFObjectHandle::newInteger(QIntC::to_longlong(INT_MIN) - 1LL);
auto oh_i_neg = QPDFObjectHandle::newInteger(-1);
auto oh_r = QPDFObjectHandle::newReal("42.0");
auto oh_n = QPDFObjectHandle::newName("/Test");
@@ -3226,8 +3051,7 @@ test_88(QPDF& pdf, char const* arg2)
auto dict = QPDFObjectHandle::newDictionary();
dict.replaceKey("/One", QPDFObjectHandle::newInteger(1));
dict.replaceKey("/Two", QPDFObjectHandle::newInteger(2));
- auto three =
- dict.replaceKeyAndGetNew("/Three", QPDFObjectHandle::newArray());
+ auto three = dict.replaceKeyAndGetNew("/Three", QPDFObjectHandle::newArray());
three.appendItem("(a)"_qpdf);
three.appendItem("(b)"_qpdf);
auto newdict = three.appendItemAndGetNew(QPDFObjectHandle::newDictionary());
@@ -3236,8 +3060,7 @@ test_88(QPDF& pdf, char const* arg2)
dict.replaceKey("/Quack", "[1 2 3]"_qpdf);
auto quack = dict.replaceKeyAndGetOld("/Quack", "/Moo"_qpdf);
assert(quack.unparse() == "[ 1 2 3 ]");
- auto nothing =
- dict.replaceKeyAndGetOld("/NotThere", QPDFObjectHandle::newNull());
+ auto nothing = dict.replaceKeyAndGetOld("/NotThere", QPDFObjectHandle::newNull());
assert(nothing.isNull());
assert(dict.unparse() == R"(
<<
@@ -3250,15 +3073,11 @@ test_88(QPDF& pdf, char const* arg2)
auto arr = dict.getKey("/Three");
arr.insertItem(0, QPDFObjectHandle::newString("0"));
arr.insertItem(0, QPDFObjectHandle::newString("00"));
- assert(
- arr.unparse() ==
- "[ (00) (0) (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse());
+ assert(arr.unparse() == "[ (00) (0) (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse());
auto new_dict = arr.insertItemAndGetNew(1, "<< /P /Q /R /S >>"_qpdf);
arr.eraseItem(2);
arr.eraseItem(0);
- assert(
- arr.unparse() ==
- "[ << /P /Q /R /S >> (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse());
+ assert(arr.unparse() == "[ << /P /Q /R /S >> (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse());
// new_dict shares internals with the one in the array. It has
// always been this way, and there is code that relies on this
@@ -3266,14 +3085,10 @@ test_88(QPDF& pdf, char const* arg2)
// again...
new_dict.removeKey("/R");
new_dict.replaceKey("/T", "/U"_qpdf);
- assert(
- arr.unparse() ==
- "[ << /P /Q /T /U >> (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse());
+ assert(arr.unparse() == "[ << /P /Q /T /U >> (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse());
auto s = arr.eraseItemAndGetOld(1);
assert(s.unparse() == "(a)");
- assert(
- arr.unparse() ==
- "[ << /P /Q /T /U >> (b) << /Z /Y /X /W >> ]"_qpdf.unparse());
+ assert(arr.unparse() == "[ << /P /Q /T /U >> (b) << /Z /Y /X /W >> ]"_qpdf.unparse());
assert(new_dict.removeKeyAndGetOld("/M").isNull());
assert(new_dict.removeKeyAndGetOld("/P").unparse() == "/Q");
@@ -3316,8 +3131,7 @@ test_91(QPDF& pdf, char const* arg2)
{
// Exercise the simpler version of writeJSON.
Pl_StdioFile p("stdout", stdout);
- pdf.writeJSON(
- 2, &p, qpdf_dl_none, qpdf_sj_inline, "", std::set<std::string>());
+ pdf.writeJSON(2, &p, qpdf_dl_none, qpdf_sj_inline, "", std::set<std::string>());
}
static void
@@ -3587,8 +3401,7 @@ runtest(int n, char const* filename1, char const* arg2)
for (size_t i = 0; i < size; ++i) {
p[i] = static_cast<char>(p[i] ^ 0xcc);
}
- pdf.processMemoryFile(
- (std::string(filename1) + ".pdf").c_str(), p, size);
+ pdf.processMemoryFile((std::string(filename1) + ".pdf").c_str(), p, size);
} else if (ignore_filename.count(n)) {
// Ignore filename argument entirely
} else if (n == 89) {
@@ -3610,35 +3423,26 @@ runtest(int n, char const* filename1, char const* arg2)
}
std::map<int, void (*)(QPDF&, char const*)> test_functions = {
- {0, test_0_1}, {1, test_0_1}, {2, test_2}, {3, test_3},
- {4, test_4}, {5, test_5}, {6, test_6}, {7, test_7},
- {8, test_8}, {9, test_9}, {10, test_10}, {11, test_11},
- {12, test_12}, {13, test_13}, {14, test_14}, {15, test_15},
- {16, test_16}, {17, test_17}, {18, test_18}, {19, test_19},
- {20, test_20}, {21, test_21}, {22, test_22}, {23, test_23},
- {24, test_24}, {25, test_25}, {26, test_26}, {27, test_27},
- {28, test_28}, {29, test_29}, {30, test_30}, {31, test_31},
- {32, test_32}, {33, test_33}, {34, test_34}, {35, test_35},
- {36, test_36}, {37, test_37}, {38, test_38}, {39, test_39},
- {40, test_40}, {41, test_41}, {42, test_42}, {43, test_43},
- {44, test_44}, {45, test_45}, {46, test_46}, {47, test_47},
- {48, test_48}, {49, test_49}, {50, test_50}, {51, test_51},
- {52, test_52}, {53, test_53}, {54, test_54}, {55, test_55},
- {56, test_56}, {57, test_57}, {58, test_58}, {59, test_59},
- {60, test_60}, {61, test_61}, {62, test_62}, {63, test_63},
- {64, test_64}, {65, test_65}, {66, test_66}, {67, test_67},
- {68, test_68}, {69, test_69}, {70, test_70}, {71, test_71},
- {72, test_72}, {73, test_73}, {74, test_74}, {75, test_75},
- {76, test_76}, {77, test_77}, {78, test_78}, {79, test_79},
- {80, test_80}, {81, test_81}, {82, test_82}, {83, test_83},
- {84, test_84}, {85, test_85}, {86, test_86}, {87, test_87},
- {88, test_88}, {89, test_89}, {90, test_90}, {91, test_91},
- {92, test_92}, {93, test_93}, {94, test_94}, {95, test_95}};
+ {0, test_0_1}, {1, test_0_1}, {2, test_2}, {3, test_3}, {4, test_4}, {5, test_5},
+ {6, test_6}, {7, test_7}, {8, test_8}, {9, test_9}, {10, test_10}, {11, test_11},
+ {12, test_12}, {13, test_13}, {14, test_14}, {15, test_15}, {16, test_16}, {17, test_17},
+ {18, test_18}, {19, test_19}, {20, test_20}, {21, test_21}, {22, test_22}, {23, test_23},
+ {24, test_24}, {25, test_25}, {26, test_26}, {27, test_27}, {28, test_28}, {29, test_29},
+ {30, test_30}, {31, test_31}, {32, test_32}, {33, test_33}, {34, test_34}, {35, test_35},
+ {36, test_36}, {37, test_37}, {38, test_38}, {39, test_39}, {40, test_40}, {41, test_41},
+ {42, test_42}, {43, test_43}, {44, test_44}, {45, test_45}, {46, test_46}, {47, test_47},
+ {48, test_48}, {49, test_49}, {50, test_50}, {51, test_51}, {52, test_52}, {53, test_53},
+ {54, test_54}, {55, test_55}, {56, test_56}, {57, test_57}, {58, test_58}, {59, test_59},
+ {60, test_60}, {61, test_61}, {62, test_62}, {63, test_63}, {64, test_64}, {65, test_65},
+ {66, test_66}, {67, test_67}, {68, test_68}, {69, test_69}, {70, test_70}, {71, test_71},
+ {72, test_72}, {73, test_73}, {74, test_74}, {75, test_75}, {76, test_76}, {77, test_77},
+ {78, test_78}, {79, test_79}, {80, test_80}, {81, test_81}, {82, test_82}, {83, test_83},
+ {84, test_84}, {85, test_85}, {86, test_86}, {87, test_87}, {88, test_88}, {89, test_89},
+ {90, test_90}, {91, test_91}, {92, test_92}, {93, test_93}, {94, test_94}, {95, test_95}};
auto fn = test_functions.find(n);
if (fn == test_functions.end()) {
- throw std::runtime_error(
- std::string("invalid test ") + QUtil::int_to_string(n));
+ throw std::runtime_error(std::string("invalid test ") + QUtil::int_to_string(n));
}
(fn->second)(pdf, arg2);
diff --git a/qpdf/test_large_file.cc b/qpdf/test_large_file.cc
index fb69ce28..12a75a84 100644
--- a/qpdf/test_large_file.cc
+++ b/qpdf/test_large_file.cc
@@ -53,9 +53,8 @@ static inline unsigned char
get_pixel_color(size_t n, size_t row)
{
return (
- (n & (1LLU << (nstripes - 1LLU - row)))
- ? static_cast<unsigned char>('\xc0')
- : static_cast<unsigned char>('\x40'));
+ (n & (1LLU << (nstripes - 1LLU - row))) ? static_cast<unsigned char>('\xc0')
+ : static_cast<unsigned char>('\x40'));
}
class ImageChecker: public Pipeline
@@ -97,8 +96,7 @@ void
ImageChecker::finish()
{
if (!okay) {
- std::cout << "errors found checking image data for page " << n
- << std::endl;
+ std::cout << "errors found checking image data for page " << n << std::endl;
}
}
@@ -107,8 +105,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider
public:
ImageProvider(size_t n);
virtual ~ImageProvider() = default;
- virtual void
- provideStreamData(int objid, int generation, Pipeline* pipeline);
+ virtual void provideStreamData(int objid, int generation, Pipeline* pipeline);
private:
size_t n;
@@ -137,8 +134,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline)
void
usage()
{
- std::cerr << "Usage: " << whoami << " {read|write} {large|small} outfile"
- << std::endl;
+ std::cerr << "Usage: " << whoami << " {read|write} {large|small} outfile" << std::endl;
exit(2);
}
@@ -153,8 +149,7 @@ set_parameters(bool large)
std::string
generate_page_contents(size_t pageno)
{
- std::string contents = "BT /F1 24 Tf 72 720 Td (page " +
- QUtil::uint_to_string(pageno) +
+ std::string contents = "BT /F1 24 Tf 72 720 Td (page " + QUtil::uint_to_string(pageno) +
") Tj ET\n"
"q 468 0 0 468 72 72 cm /Im1 Do Q\n";
return contents;
@@ -185,16 +180,14 @@ create_pdf(char const* filename)
pdf.emptyPDF();
- QPDFObjectHandle font =
- pdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
+ QPDFObjectHandle font = pdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
font.replaceKey("/Type", newName("/Font"));
font.replaceKey("/Subtype", newName("/Type1"));
font.replaceKey("/Name", newName("/F1"));
font.replaceKey("/BaseFont", newName("/Helvetica"));
font.replaceKey("/Encoding", newName("/WinAnsiEncoding"));
- QPDFObjectHandle procset =
- pdf.makeIndirectObject(QPDFObjectHandle::newArray());
+ QPDFObjectHandle procset = pdf.makeIndirectObject(QPDFObjectHandle::newArray());
procset.appendItem(newName("/PDF"));
procset.appendItem(newName("/Text"));
procset.appendItem(newName("/ImageC"));
@@ -220,8 +213,7 @@ create_pdf(char const* filename)
image_dict.replaceKey("/Height", newInteger(height));
auto* p = new ImageProvider(pageno);
std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p);
- image.replaceStreamData(
- provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
+ image.replaceStreamData(provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
QPDFObjectHandle xobject = QPDFObjectHandle::newDictionary();
xobject.replaceKey("/Im1", image);
@@ -233,8 +225,7 @@ create_pdf(char const* filename)
QPDFObjectHandle contents = create_page_contents(pdf, pageno);
- QPDFObjectHandle page =
- pdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
+ QPDFObjectHandle page = pdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
page.replaceKey("/Type", newName("/Page"));
page.replaceKey("/MediaBox", mediabox);
page.replaceKey("/Contents", contents);
@@ -259,16 +250,14 @@ check_page_contents(size_t pageno, QPDFObjectHandle page)
std::string expected_contents = generate_page_contents(pageno);
if (expected_contents != actual_contents) {
std::cout << "page contents wrong for page " << pageno << std::endl
- << "ACTUAL: " << actual_contents
- << "EXPECTED: " << expected_contents << "----\n";
+ << "ACTUAL: " << actual_contents << "EXPECTED: " << expected_contents << "----\n";
}
}
static void
check_image(size_t pageno, QPDFObjectHandle page)
{
- QPDFObjectHandle image =
- page.getKey("/Resources").getKey("/XObject").getKey("/Im1");
+ QPDFObjectHandle image = page.getKey("/Resources").getKey("/XObject").getKey("/Im1");
ImageChecker ic(pageno);
image.pipeStreamData(&ic, 0, qpdf_dl_specialized);
}
diff --git a/qpdf/test_parsedoffset.cc b/qpdf/test_parsedoffset.cc
index b822b0e3..0978bfce 100644
--- a/qpdf/test_parsedoffset.cc
+++ b/qpdf/test_parsedoffset.cc
@@ -20,12 +20,10 @@ std::string
make_objdesc(qpdf_offset_t offset, QPDFObjectHandle obj)
{
std::stringstream ss;
- ss << "offset = " << offset << " (0x" << std::hex << offset << std::dec
- << "), ";
+ ss << "offset = " << offset << " (0x" << std::hex << offset << std::dec << "), ";
if (obj.isIndirect()) {
- ss << "indirect " << obj.getObjectID() << "/" << obj.getGeneration()
- << ", ";
+ ss << "indirect " << obj.getObjectID() << "/" << obj.getGeneration() << ", ";
} else {
ss << "direct, ";
}
@@ -42,8 +40,7 @@ walk(
std::vector<std::vector<std::pair<qpdf_offset_t, std::string>>>& result)
{
qpdf_offset_t offset = obj.getParsedOffset();
- std::pair<qpdf_offset_t, std::string> p =
- std::make_pair(offset, make_objdesc(offset, obj));
+ std::pair<qpdf_offset_t, std::string> p = std::make_pair(offset, make_objdesc(offset, obj));
if (result.size() < stream_number + 1) {
result.resize(stream_number + 1);
@@ -73,9 +70,7 @@ walk(
}
void
-process(
- std::string fn,
- std::vector<std::vector<std::pair<qpdf_offset_t, std::string>>>& result)
+process(std::string fn, std::vector<std::vector<std::pair<qpdf_offset_t, std::string>>>& result)
{
QPDF qpdf;
qpdf.processFile(fn.c_str());
@@ -93,8 +88,8 @@ process(
switch (xref.getType()) {
case 0:
- std::cerr << oh.getObjectID() << "/" << oh.getGeneration()
- << " xref entry is free" << std::endl;
+ std::cerr << oh.getObjectID() << "/" << oh.getGeneration() << " xref entry is free"
+ << std::endl;
std::exit(2);
case 1:
stream_number = 0;
@@ -133,8 +128,7 @@ main(int argc, char* argv[])
if (i == 0) {
std::cout << "--- objects not in streams ---" << std::endl;
} else {
- std::cout << "--- objects in stream " << i << " ---"
- << std::endl;
+ std::cout << "--- objects in stream " << i << " ---" << std::endl;
}
for (auto const& iter: table[i]) {
diff --git a/qpdf/test_pdf_unicode.cc b/qpdf/test_pdf_unicode.cc
index e1e9f909..a4593691 100644
--- a/qpdf/test_pdf_unicode.cc
+++ b/qpdf/test_pdf_unicode.cc
@@ -28,8 +28,7 @@ main(int argc, char* argv[])
char const* infilename = argv[1];
for (auto const& line: QUtil::read_lines_from_file(infilename)) {
QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line);
- std::cout << str.getUTF8Value() << " // " << str.unparseBinary()
- << std::endl;
+ std::cout << str.getUTF8Value() << " // " << str.unparseBinary() << std::endl;
}
return 0;
}
diff --git a/qpdf/test_renumber.cc b/qpdf/test_renumber.cc
index 1b828128..3eaa8890 100644
--- a/qpdf/test_renumber.cc
+++ b/qpdf/test_renumber.cc
@@ -117,9 +117,7 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b)
}
bool
-compare_xref_table(
- std::map<QPDFObjGen, QPDFXRefEntry> a,
- std::map<QPDFObjGen, QPDFXRefEntry> b)
+compare_xref_table(std::map<QPDFObjGen, QPDFXRefEntry> a, std::map<QPDFObjGen, QPDFXRefEntry> b)
{
if (a.size() != b.size()) {
std::cerr << "different size" << std::endl;
@@ -127,8 +125,8 @@ compare_xref_table(
}
for (auto const& iter: a) {
- std::cout << "xref entry for " << iter.first.getObj() << "/"
- << iter.first.getGen() << std::endl;
+ std::cout << "xref entry for " << iter.first.getObj() << "/" << iter.first.getGen()
+ << std::endl;
if (b.count(iter.first) == 0) {
std::cerr << "not found" << std::endl;
@@ -222,20 +220,16 @@ main(int argc, char* argv[])
QPDF qpdf_ren;
qpdf_ren.processMemoryFile(
- "renumbered",
- reinterpret_cast<char*>(buf->getBuffer()),
- buf->getSize());
+ "renumbered", reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
std::map<QPDFObjGen, QPDFXRefEntry> xrefs_ren = qpdf_ren.getXRefTable();
- std::cout << "--- compare between input and renumbered objects ---"
- << std::endl;
+ std::cout << "--- compare between input and renumbered objects ---" << std::endl;
for (auto const& iter: objs_in) {
QPDFObjGen og_in = iter.getObjGen();
QPDFObjGen og_ren = w.getRenumberedObjGen(og_in);
- std::cout << "input " << og_in.getObj() << "/" << og_in.getGen()
- << " -> renumbered " << og_ren.getObj() << "/"
- << og_ren.getGen() << std::endl;
+ std::cout << "input " << og_in.getObj() << "/" << og_in.getGen() << " -> renumbered "
+ << og_ren.getObj() << "/" << og_ren.getGen() << std::endl;
if (og_ren.getObj() == 0) {
std::cout << "deleted" << std::endl;
@@ -249,8 +243,7 @@ main(int argc, char* argv[])
}
std::cout << "complete" << std::endl;
- std::cout << "--- compare between written and reloaded xref tables ---"
- << std::endl;
+ std::cout << "--- compare between written and reloaded xref tables ---" << std::endl;
if (!compare_xref_table(xrefs_w, xrefs_ren)) {
std::cerr << "different" << std::endl;
std::exit(2);
diff --git a/qpdf/test_tokenizer.cc b/qpdf/test_tokenizer.cc
index 25239426..c0d13054 100644
--- a/qpdf/test_tokenizer.cc
+++ b/qpdf/test_tokenizer.cc
@@ -16,8 +16,7 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami
- << " [-maxlen len | -no-ignorable] filename" << std::endl;
+ std::cerr << "Usage: " << whoami << " [-maxlen len | -no-ignorable] filename" << std::endl;
exit(2);
}
@@ -102,9 +101,7 @@ sanitize(std::string const& value)
if ((iter >= 32) && (iter <= 126)) {
result.append(1, iter);
} else {
- result += "\\x" +
- QUtil::int_to_string_base(
- static_cast<unsigned char>(iter), 16, 2);
+ result += "\\x" + QUtil::int_to_string_base(static_cast<unsigned char>(iter), 16, 2);
}
}
return result;
@@ -145,8 +142,8 @@ dump_tokens(
}
qpdf_offset_t inline_image_offset = 0;
while (!done) {
- QPDFTokenizer::Token token = tokenizer.readToken(
- is, "test", true, inline_image_offset ? 0 : max_len);
+ QPDFTokenizer::Token token =
+ tokenizer.readToken(is, "test", true, inline_image_offset ? 0 : max_len);
if (inline_image_offset && (token.getType() == QPDFTokenizer::tt_bad)) {
std::cout << "EI not found; resuming normal scanning" << std::endl;
is->seek(inline_image_offset, SEEK_SET);
@@ -167,12 +164,10 @@ dump_tokens(
std::cout << " (" << token.getErrorMessage() << ")";
}
std::cout << std::endl;
- if (skip_streams &&
- (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream"))) {
+ if (skip_streams && (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream"))) {
try_skipping(tokenizer, is, max_len, "endstream", f1);
} else if (
- skip_inline_images &&
- (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "ID"))) {
+ skip_inline_images && (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "ID"))) {
char ch;
is->read(&ch, 1);
tokenizer.expectInlineImage(is);
@@ -206,12 +201,7 @@ process(char const* filename, bool include_ignorable, size_t max_len)
auto* bis = new BufferInputSource("content data", content_data.get());
is = std::shared_ptr<InputSource>(bis);
dump_tokens(
- is,
- "PAGE " + QUtil::int_to_string(pageno),
- max_len,
- include_ignorable,
- false,
- true);
+ is, "PAGE " + QUtil::int_to_string(pageno), max_len, include_ignorable, false, true);
}
// Tokenize object streams
diff --git a/qpdf/test_xref.cc b/qpdf/test_xref.cc
index 6ecb9a00..bc733de8 100644
--- a/qpdf/test_xref.cc
+++ b/qpdf/test_xref.cc
@@ -17,23 +17,18 @@ main(int argc, char* argv[])
qpdf.processFile(argv[1]);
for (auto const& iter: qpdf.getXRefTable()) {
- std::cout << iter.first.getObj() << "/" << iter.first.getGen()
- << ", ";
+ std::cout << iter.first.getObj() << "/" << iter.first.getGen() << ", ";
switch (iter.second.getType()) {
case 0:
std::cout << "free entry" << std::endl;
break;
case 1:
- std::cout << "uncompressed, offset = "
- << iter.second.getOffset() << " (0x" << std::hex
- << iter.second.getOffset() << std::dec << ")"
- << std::endl;
+ std::cout << "uncompressed, offset = " << iter.second.getOffset() << " (0x"
+ << std::hex << iter.second.getOffset() << std::dec << ")" << std::endl;
break;
case 2:
- std::cout << "compressed, stream number = "
- << iter.second.getObjStreamNumber()
- << ", stream index = "
- << iter.second.getObjStreamIndex() << std::endl;
+ std::cout << "compressed, stream number = " << iter.second.getObjStreamNumber()
+ << ", stream index = " << iter.second.getObjStreamIndex() << std::endl;
break;
default:
std::cerr << "unknown" << std::endl;
diff --git a/zlib-flate/zlib-flate.cc b/zlib-flate/zlib-flate.cc
index bc076194..1b1743b0 100644
--- a/zlib-flate/zlib-flate.cc
+++ b/zlib-flate/zlib-flate.cc
@@ -14,8 +14,7 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami << " { -uncompress | -compress[=n] }"
- << std::endl
+ std::cerr << "Usage: " << whoami << " { -uncompress | -compress[=n] }" << std::endl
<< "If n is specified with -compress, it is a"
<< " zlib compression level from" << std::endl
<< "1 to 9 where lower numbers are faster and"
@@ -34,8 +33,7 @@ main(int argc, char* argv[])
}
if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) {
- std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion()
- << std::endl;
+ std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl;
exit(0);
}
@@ -64,8 +62,7 @@ main(int argc, char* argv[])
bool warn = false;
flate->setWarnCallback([&warn](char const* msg, int code) {
warn = true;
- std::cerr << whoami << ": WARNING: zlib code " << code
- << ", msg = " << msg << std::endl;
+ std::cerr << whoami << ": WARNING: zlib code " << code << ", msg = " << msg << std::endl;
});
try {