diff options
Diffstat (limited to 'libqpdf/QPDFObjectHandle.cc')
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 286 |
1 files changed, 91 insertions, 195 deletions
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"); } |