summaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
Diffstat (limited to 'libqpdf')
-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
111 files changed, 1790 insertions, 3762 deletions
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