diff --git a/examples/pdf-attach-file.cc b/examples/pdf-attach-file.cc index eb12a002..0d15122f 100644 --- a/examples/pdf-attach-file.cc +++ b/examples/pdf-attach-file.cc @@ -106,10 +106,10 @@ process( // apdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); // apdict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")); // apdict.replaceKey("/BBox", QPDFObjectHandle::parse("[ 0 0 20 20 ]")); - apdict.replaceKey("/Resources", "<< >>"_qpdf); - apdict.replaceKey("/Type", "/XObject"_qpdf); - apdict.replaceKey("/Subtype", "/Form"_qpdf); - apdict.replaceKey("/BBox", "[ 0 0 20 20 ]"_qpdf); + apdict.replaceKey("/Resources", "<< >>"_qpdf) + .replaceKey("/Type", "/XObject"_qpdf) + .replaceKey("/Subtype", "/Form"_qpdf) + .replaceKey("/BBox", "[ 0 0 20 20 ]"_qpdf); auto annot = q.makeIndirectObject(QPDFObjectHandle::parse( &q, ("<<" diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc index b5adb01a..ea315a49 100644 --- a/examples/pdf-create.cc +++ b/examples/pdf-create.cc @@ -183,9 +183,9 @@ add_page( " /Subtype /Image" " /BitsPerComponent 8" ">>"_qpdf; - image_dict.replaceKey("/ColorSpace", newName(color_space)); - image_dict.replaceKey("/Width", newInteger(width)); - image_dict.replaceKey("/Height", newInteger(height)); + image_dict.replaceKey("/ColorSpace", newName(color_space)) + .replaceKey("/Width", newInteger(width)) + .replaceKey("/Height", newInteger(height)); image.replaceDict(image_dict); // Provide the stream data. @@ -202,9 +202,9 @@ add_page( xobject.replaceKey("/Im1", image); QPDFObjectHandle resources = QPDFObjectHandle::newDictionary(); - resources.replaceKey("/ProcSet", procset); - resources.replaceKey("/Font", rfont); - resources.replaceKey("/XObject", xobject); + resources.replaceKey("/ProcSet", procset) + .replaceKey("/Font", rfont) + .replaceKey("/XObject", xobject); // Create the page content stream QPDFObjectHandle contents = @@ -215,8 +215,7 @@ add_page( " /Type /Page" " /MediaBox [0 0 612 392]" ">>"_qpdf); - page.replaceKey("/Contents", contents); - page.replaceKey("/Resources", resources); + page.replaceKey("/Contents", contents).replaceKey("/Resources", resources); // Add the page to the PDF file dh.addPage(page, false); diff --git a/libqpdf/NNTree.cc b/libqpdf/NNTree.cc index 9d4e8ec7..a888f42f 100644 --- a/libqpdf/NNTree.cc +++ b/libqpdf/NNTree.cc @@ -341,9 +341,10 @@ NNTreeIterator::split( first_node.replaceKey(key, first_half); QPDFObjectHandle new_kids = QPDFObjectHandle::newArray(); new_kids.appendItem(first_node); - to_split.removeKey("/Limits"); // already shouldn't be there for root - to_split.removeKey(impl.details.itemsKey()); - to_split.replaceKey("/Kids", new_kids); + to_split + .removeKey("/Limits") // already shouldn't be there for root + .removeKey(impl.details.itemsKey()) + .replaceKey("/Kids", new_kids); if (is_leaf) { QTC::TC("qpdf", "NNTree split root + leaf"); this->node = first_node; @@ -884,9 +885,8 @@ NNTreeImpl::repair() for (auto const& i : *this) { 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("/Kids", new_node.getKey("/Kids")) + .replaceKey(details.itemsKey(), new_node.getKey(details.itemsKey())); } NNTreeImpl::iterator diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 309e3461..63feb461 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2436,13 +2436,11 @@ QPDF::replaceForeignIndirectObjects( QTC::TC("qpdf", "QPDF replace dictionary"); result = QPDFObjectHandle::newDictionary(); std::set keys = foreign.getKeys(); - for (std::set::iterator iter = keys.begin(); - iter != keys.end(); - ++iter) { + for (auto const& iter : keys) { result.replaceKey( - *iter, + iter, replaceForeignIndirectObjects( - foreign.getKey(*iter), obj_copier, false)); + foreign.getKey(iter), obj_copier, false)); } } else if (foreign.isStream()) { QTC::TC("qpdf", "QPDF replace stream"); @@ -2452,13 +2450,11 @@ QPDF::replaceForeignIndirectObjects( QPDFObjectHandle dict = result.getDict(); QPDFObjectHandle old_dict = foreign.getDict(); std::set keys = old_dict.getKeys(); - for (std::set::iterator iter = keys.begin(); - iter != keys.end(); - ++iter) { + for (auto const& iter : keys) { dict.replaceKey( - *iter, + iter, replaceForeignIndirectObjects( - old_dict.getKey(*iter), obj_copier, false)); + old_dict.getKey(iter), obj_copier, false)); } copyStreamData(result, foreign); } else { diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index 2bb52f44..811570b5 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -748,8 +748,7 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream( auto existing_old = subdict.getKey(old_key); if (!existing_old.isNull()) { QTC::TC("qpdf", "QPDFAcroFormDocumentHelper ap rename"); - subdict.replaceKey(new_key, existing_old); - subdict.removeKey(old_key); + subdict.replaceKey(new_key, existing_old).removeKey(old_key); } } } diff --git a/libqpdf/QPDFFileSpecObjectHelper.cc b/libqpdf/QPDFFileSpecObjectHelper.cc index 0c7653b6..446ff131 100644 --- a/libqpdf/QPDFFileSpecObjectHelper.cc +++ b/libqpdf/QPDFFileSpecObjectHelper.cc @@ -103,8 +103,8 @@ QPDFFileSpecObjectHelper::createFileSpec( QPDFFileSpecObjectHelper result(oh); result.setFilename(filename); auto ef = QPDFObjectHandle::newDictionary(); - ef.replaceKey("/F", efsoh.getObjectHandle()); - ef.replaceKey("/UF", efsoh.getObjectHandle()); + ef.replaceKey("/F", efsoh.getObjectHandle()) + .replaceKey("/UF", efsoh.getObjectHandle()); oh.replaceKey("/EF", ef); return result; } diff --git a/libqpdf/QPDFPageLabelDocumentHelper.cc b/libqpdf/QPDFPageLabelDocumentHelper.cc index babfd5aa..8f3472c1 100644 --- a/libqpdf/QPDFPageLabelDocumentHelper.cc +++ b/libqpdf/QPDFPageLabelDocumentHelper.cc @@ -44,9 +44,8 @@ QPDFPageLabelDocumentHelper::getLabelForPage(long long page_idx) QIntC::range_check(start, offset); start += offset; result = QPDFObjectHandle::newDictionary(); - result.replaceKey("/S", S); - result.replaceKey("/P", P); - result.replaceKey("/St", QPDFObjectHandle::newInteger(start)); + result.replaceKey("/S", S).replaceKey("/P", P).replaceKey( + "/St", QPDFObjectHandle::newInteger(start)); return result; } diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index a6773e70..ce0bcc38 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -78,8 +78,8 @@ QPDFObjectHandle InlineImageTracker::convertIIDict(QPDFObjectHandle odict) { QPDFObjectHandle dict = QPDFObjectHandle::newDictionary(); - dict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); - dict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Image")); + dict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")) + .replaceKey("/Subtype", QPDFObjectHandle::newName("/Image")); std::set keys = odict.getKeys(); for (auto key : keys) { QPDFObjectHandle value = odict.getKey(key); @@ -752,11 +752,11 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) } QPDFObjectHandle result = QPDFObjectHandle::newStream(qpdf); 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("/Group", getAttribute("/Group", false).shallowCopy()); + newdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")) + .replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")) + .replaceKey( + "/Resources", getAttribute("/Resources", false).shallowCopy()) + .replaceKey("/Group", getAttribute("/Group", false).shallowCopy()); QPDFObjectHandle bbox = getTrimBox(false).shallowCopy(); if (!bbox.isRectangle()) { this->oh.warnIfPossible("bounding box is invalid; form" diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 2d0554b9..9e1c1ca6 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -604,8 +604,8 @@ QPDF_Stream::replaceFilterData( QPDFObjectHandle const& decode_parms, size_t length) { - this->stream_dict.replaceKey("/Filter", filter); - this->stream_dict.replaceKey("/DecodeParms", decode_parms); + this->stream_dict.replaceKey("/Filter", filter) + .replaceKey("/DecodeParms", decode_parms); if (length == 0) { QTC::TC("qpdf", "QPDF_Stream unknown stream length"); this->stream_dict.removeKey("/Length"); diff --git a/libtests/nntree.cc b/libtests/nntree.cc index 4a874578..31b1bd42 100644 --- a/libtests/nntree.cc +++ b/libtests/nntree.cc @@ -70,8 +70,7 @@ test_bsearch() limits.appendItem(QPDFObjectHandle::newInteger(v.at(0))); limits.appendItem(QPDFObjectHandle::newInteger(v.at(v.size() - 1))); auto node = q.makeIndirectObject(QPDFObjectHandle::newDictionary()); - node.replaceKey("/Nums", nums); - node.replaceKey("/Limits", limits); + node.replaceKey("/Nums", nums).replaceKey("/Limits", limits); return node; }; diff --git a/qpdf/pdf_from_scratch.cc b/qpdf/pdf_from_scratch.cc index c401e9af..2af5d437 100644 --- a/qpdf/pdf_from_scratch.cc +++ b/qpdf/pdf_from_scratch.cc @@ -60,15 +60,14 @@ runtest(int n) rfont.replaceKey("/F1", font); QPDFObjectHandle resources = QPDFObjectHandle::newDictionary(); - resources.replaceKey("/ProcSet", procset); - resources.replaceKey("/Font", rfont); + resources.replaceKey("/ProcSet", procset).replaceKey("/Font", rfont); QPDFObjectHandle page = pdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); - page.replaceKey("/Type", newName("/Page")); - page.replaceKey("/MediaBox", mediabox); - page.replaceKey("/Contents", contents); - page.replaceKey("/Resources", resources); + page.replaceKey("/Type", newName("/Page")) + .replaceKey("/MediaBox", mediabox) + .replaceKey("/Contents", contents) + .replaceKey("/Resources", resources); QPDFPageDocumentHelper(pdf).addPage(page, true); diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 1268adb9..03d5d57d 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -538,8 +538,7 @@ test_9(QPDF& pdf, char const* arg2) "data for other stream\n", QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); - root.replaceKey("/QStream", qstream); - root.replaceKey("/RStream", rstream); + root.replaceKey("/QStream", qstream).replaceKey("/RStream", rstream); QPDFWriter w(pdf, "a.pdf"); w.setStaticID(true); w.setStreamDataMode(qpdf_s_preserve); @@ -909,8 +908,7 @@ test_24(QPDF& pdf, char const* arg2) QPDFObjectHandle res1 = QPDFObjectHandle::newReserved(&pdf); QPDFObjectHandle res2 = QPDFObjectHandle::newReserved(&pdf); QPDFObjectHandle trailer = pdf.getTrailer(); - trailer.replaceKey("Array1", res1); - trailer.replaceKey("Array2", res2); + trailer.replaceKey("Array1", res1).replaceKey("Array2", res2); QPDFObjectHandle array1 = QPDFObjectHandle::newArray(); QPDFObjectHandle array2 = QPDFObjectHandle::newArray(); @@ -1086,8 +1084,9 @@ test_27(QPDF& pdf, char const* arg2) dh.addPage(O3.getKey("/OtherPage"), false); dh.addPage(O3, false); QPDFObjectHandle s2 = QPDFObjectHandle::newStream(&oldpdf, "potato\n"); - pdf.getTrailer().replaceKey("/QTest", pdf.copyForeignObject(qtest)); - pdf.getTrailer().replaceKey("/QTest2", QPDFObjectHandle::newArray()); + pdf.getTrailer() + .replaceKey("/QTest", pdf.copyForeignObject(qtest)) + .replaceKey("/QTest2", QPDFObjectHandle::newArray()); pdf.getTrailer().getKey("/QTest2").appendItem( pdf.copyForeignObject(s1)); pdf.getTrailer().getKey("/QTest2").appendItem( @@ -2259,9 +2258,10 @@ test_60(QPDF& pdf, char const* arg2) // The only differences between /QTest and /QTest3 should be // the direct objects merged from r2. - pdf.getTrailer().replaceKey("/QTest1", r1); - pdf.getTrailer().replaceKey("/QTest2", r2); - pdf.getTrailer().replaceKey("/QTest3", r3); + pdf.getTrailer() + .replaceKey("/QTest1", r1) + .replaceKey("/QTest2", r2) + .replaceKey("/QTest3", r3); QPDFWriter w(pdf, "a.pdf"); w.setQDFMode(true); w.setStaticID(true); @@ -2321,9 +2321,9 @@ test_62(QPDF& pdf, char const* arg2) long long q2 = QIntC::to_longlong(q2_l); unsigned int q3_i = UINT_MAX; long long q3 = QIntC::to_longlong(q3_i); - t.replaceKey("/Q1", QPDFObjectHandle::newInteger(q1)); - t.replaceKey("/Q2", QPDFObjectHandle::newInteger(q2)); - t.replaceKey("/Q3", QPDFObjectHandle::newInteger(q3)); + t.replaceKey("/Q1", QPDFObjectHandle::newInteger(q1)) + .replaceKey("/Q2", QPDFObjectHandle::newInteger(q2)) + .replaceKey("/Q3", QPDFObjectHandle::newInteger(q3)); assert_compare_numbers(q1, t.getKey("/Q1").getIntValue()); assert_compare_numbers(q1_l, t.getKey("/Q1").getUIntValue()); assert_compare_numbers(INT_MAX, t.getKey("/Q1").getIntValueAsInt()); diff --git a/qpdf/test_large_file.cc b/qpdf/test_large_file.cc index df442882..e264e831 100644 --- a/qpdf/test_large_file.cc +++ b/qpdf/test_large_file.cc @@ -191,11 +191,11 @@ create_pdf(char const* filename) QPDFObjectHandle font = pdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); - font.replaceKey("/Type", newName("/Font")); - font.replaceKey("/Subtype", newName("/Type1")); - font.replaceKey("/Name", newName("/F1")); - font.replaceKey("/BaseFont", newName("/Helvetica")); - font.replaceKey("/Encoding", newName("/WinAnsiEncoding")); + font.replaceKey("/Type", newName("/Font")) + .replaceKey("/Subtype", newName("/Type1")) + .replaceKey("/Name", newName("/F1")) + .replaceKey("/BaseFont", newName("/Helvetica")) + .replaceKey("/Encoding", newName("/WinAnsiEncoding")); QPDFObjectHandle procset = pdf.makeIndirectObject(QPDFObjectHandle::newArray()); @@ -216,12 +216,12 @@ create_pdf(char const* filename) for (size_t pageno = 1; pageno <= npages; ++pageno) { QPDFObjectHandle image = QPDFObjectHandle::newStream(&pdf); QPDFObjectHandle image_dict = image.getDict(); - image_dict.replaceKey("/Type", newName("/XObject")); - image_dict.replaceKey("/Subtype", newName("/Image")); - image_dict.replaceKey("/ColorSpace", newName("/DeviceGray")); - image_dict.replaceKey("/BitsPerComponent", newInteger(8)); - image_dict.replaceKey("/Width", newInteger(width)); - image_dict.replaceKey("/Height", newInteger(height)); + image_dict.replaceKey("/Type", newName("/XObject")) + .replaceKey("/Subtype", newName("/Image")) + .replaceKey("/ColorSpace", newName("/DeviceGray")) + .replaceKey("/BitsPerComponent", newInteger(8)) + .replaceKey("/Width", newInteger(width)) + .replaceKey("/Height", newInteger(height)); ImageProvider* p = new ImageProvider(pageno); std::shared_ptr provider(p); image.replaceStreamData( @@ -231,18 +231,18 @@ create_pdf(char const* filename) xobject.replaceKey("/Im1", image); QPDFObjectHandle resources = QPDFObjectHandle::newDictionary(); - resources.replaceKey("/ProcSet", procset); - resources.replaceKey("/Font", rfont); - resources.replaceKey("/XObject", xobject); + resources.replaceKey("/ProcSet", procset) + .replaceKey("/Font", rfont) + .replaceKey("/XObject", xobject); QPDFObjectHandle contents = create_page_contents(pdf, pageno); QPDFObjectHandle page = pdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); - page.replaceKey("/Type", newName("/Page")); - page.replaceKey("/MediaBox", mediabox); - page.replaceKey("/Contents", contents); - page.replaceKey("/Resources", resources); + page.replaceKey("/Type", newName("/Page")) + .replaceKey("/MediaBox", mediabox) + .replaceKey("/Contents", contents) + .replaceKey("/Resources", resources); dh.addPage(page, false); }