Commit 60965d5f4d608bdccc2ffd4e8753e12cbbbd71d2
1 parent
6b077332
Rerun clang-format
Showing
196 changed files
with
2596 additions
and
5616 deletions
examples/pdf-attach-file.cc
| @@ -71,8 +71,7 @@ process( | @@ -71,8 +71,7 @@ process( | ||
| 71 | 71 | ||
| 72 | // Create a file spec. | 72 | // Create a file spec. |
| 73 | std::string key = QUtil::path_basename(attachment); | 73 | std::string key = QUtil::path_basename(attachment); |
| 74 | - std::cout << whoami << ": attaching " << attachment << " as " << key | ||
| 75 | - << std::endl; | 74 | + std::cout << whoami << ": attaching " << attachment << " as " << key << std::endl; |
| 76 | auto fs = QPDFFileSpecObjectHelper::createFileSpec(q, key, attachment); | 75 | auto fs = QPDFFileSpecObjectHelper::createFileSpec(q, key, attachment); |
| 77 | 76 | ||
| 78 | if (mimetype) { | 77 | if (mimetype) { |
examples/pdf-bookmarks.cc
| @@ -23,16 +23,12 @@ static std::map<QPDFObjGen, int> page_map; | @@ -23,16 +23,12 @@ static std::map<QPDFObjGen, int> page_map; | ||
| 23 | void | 23 | void |
| 24 | usage() | 24 | usage() |
| 25 | { | 25 | { |
| 26 | - std::cerr | ||
| 27 | - << "Usage: " << whoami << " [options] file.pdf [password]" << std::endl | ||
| 28 | - << "Options:" << std::endl | ||
| 29 | - << " --numbers give bookmarks outline-style numbers" | ||
| 30 | - << std::endl | ||
| 31 | - << " --lines draw lines to show bookmark hierarchy" | ||
| 32 | - << std::endl | ||
| 33 | - << " --show-open indicate whether a bookmark is initially open" | ||
| 34 | - << std::endl | ||
| 35 | - << " --show-targets show target if possible" << std::endl; | 26 | + std::cerr << "Usage: " << whoami << " [options] file.pdf [password]" << std::endl |
| 27 | + << "Options:" << std::endl | ||
| 28 | + << " --numbers give bookmarks outline-style numbers" << std::endl | ||
| 29 | + << " --lines draw lines to show bookmark hierarchy" << std::endl | ||
| 30 | + << " --show-open indicate whether a bookmark is initially open" << std::endl | ||
| 31 | + << " --show-targets show target if possible" << std::endl; | ||
| 36 | exit(2); | 32 | exit(2); |
| 37 | } | 33 | } |
| 38 | 34 | ||
| @@ -120,16 +116,14 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector<int> numbers) | @@ -120,16 +116,14 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector<int> numbers) | ||
| 120 | } | 116 | } |
| 121 | 117 | ||
| 122 | void | 118 | void |
| 123 | -extract_bookmarks( | ||
| 124 | - std::vector<QPDFOutlineObjectHelper> outlines, std::vector<int>& numbers) | 119 | +extract_bookmarks(std::vector<QPDFOutlineObjectHelper> outlines, std::vector<int>& numbers) |
| 125 | { | 120 | { |
| 126 | // For style == st_numbers, numbers.at(n) contains the numerical | 121 | // For style == st_numbers, numbers.at(n) contains the numerical |
| 127 | // label for the outline, so we count up from 1. | 122 | // label for the outline, so we count up from 1. |
| 128 | // For style == st_lines, numbers.at(n) == 0 indicates the last | 123 | // For style == st_lines, numbers.at(n) == 0 indicates the last |
| 129 | // outline at level n, and we don't otherwise care what the value | 124 | // outline at level n, and we don't otherwise care what the value |
| 130 | // is, so we count up to zero. | 125 | // is, so we count up to zero. |
| 131 | - numbers.push_back( | ||
| 132 | - (style == st_lines) ? -QIntC::to_int(outlines.size()) : 0); | 126 | + numbers.push_back((style == st_lines) ? -QIntC::to_int(outlines.size()) : 0); |
| 133 | for (auto& outline: outlines) { | 127 | for (auto& outline: outlines) { |
| 134 | ++(numbers.back()); | 128 | ++(numbers.back()); |
| 135 | show_bookmark_details(outline, numbers); | 129 | show_bookmark_details(outline, numbers); |
| @@ -196,8 +190,7 @@ main(int argc, char* argv[]) | @@ -196,8 +190,7 @@ main(int argc, char* argv[]) | ||
| 196 | std::cout << filename << " has no bookmarks" << std::endl; | 190 | std::cout << filename << " has no bookmarks" << std::endl; |
| 197 | } | 191 | } |
| 198 | } catch (std::exception& e) { | 192 | } catch (std::exception& e) { |
| 199 | - std::cerr << whoami << " processing file " << filename << ": " | ||
| 200 | - << e.what() << std::endl; | 193 | + std::cerr << whoami << " processing file " << filename << ": " << e.what() << std::endl; |
| 201 | exit(2); | 194 | exit(2); |
| 202 | } | 195 | } |
| 203 | 196 |
examples/pdf-c-objects.c
| @@ -33,8 +33,7 @@ modify_file(qpdf_data qpdf) | @@ -33,8 +33,7 @@ modify_file(qpdf_data qpdf) | ||
| 33 | qpdf_oh_remove_key(qpdf, root, "/OpenAction"); | 33 | qpdf_oh_remove_key(qpdf, root, "/OpenAction"); |
| 34 | /* 0 is never a valid qpdf_oh */ | 34 | /* 0 is never a valid qpdf_oh */ |
| 35 | qpdf_oh pagemode = 0; | 35 | qpdf_oh pagemode = 0; |
| 36 | - if (qpdf_oh_is_dictionary( | ||
| 37 | - qpdf, qpdf_oh_get_key(qpdf, root, "/PageLabels"))) { | 36 | + if (qpdf_oh_is_dictionary(qpdf, qpdf_oh_get_key(qpdf, root, "/PageLabels"))) { |
| 38 | pagemode = qpdf_oh_new_name(qpdf, "/UseOutlines"); | 37 | pagemode = qpdf_oh_new_name(qpdf, "/UseOutlines"); |
| 39 | } else { | 38 | } else { |
| 40 | pagemode = qpdf_oh_new_null(qpdf); | 39 | pagemode = qpdf_oh_new_null(qpdf); |
| @@ -71,8 +70,7 @@ main(int argc, char* argv[]) | @@ -71,8 +70,7 @@ main(int argc, char* argv[]) | ||
| 71 | password = argv[2]; | 70 | password = argv[2]; |
| 72 | outfile = argv[3]; | 71 | outfile = argv[3]; |
| 73 | 72 | ||
| 74 | - if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && | ||
| 75 | - modify_file(qpdf) && | 73 | + if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && modify_file(qpdf) && |
| 76 | ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) { | 74 | ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) { |
| 77 | /* Use static ID for testing only. For production, a | 75 | /* Use static ID for testing only. For production, a |
| 78 | * non-static ID is used. See also | 76 | * non-static ID is used. See also |
| @@ -82,15 +80,11 @@ main(int argc, char* argv[]) | @@ -82,15 +80,11 @@ main(int argc, char* argv[]) | ||
| 82 | } | 80 | } |
| 83 | while (qpdf_more_warnings(qpdf)) { | 81 | while (qpdf_more_warnings(qpdf)) { |
| 84 | warnings = 1; | 82 | warnings = 1; |
| 85 | - printf( | ||
| 86 | - "warning: %s\n", | ||
| 87 | - qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); | 83 | + printf("warning: %s\n", qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); |
| 88 | } | 84 | } |
| 89 | if (qpdf_has_error(qpdf)) { | 85 | if (qpdf_has_error(qpdf)) { |
| 90 | errors = 1; | 86 | errors = 1; |
| 91 | - printf( | ||
| 92 | - "error: %s\n", | ||
| 93 | - qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf))); | 87 | + printf("error: %s\n", qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf))); |
| 94 | } | 88 | } |
| 95 | qpdf_cleanup(&qpdf); | 89 | qpdf_cleanup(&qpdf); |
| 96 | if (errors) { | 90 | if (errors) { |
examples/pdf-count-strings.cc
| @@ -97,8 +97,7 @@ main(int argc, char* argv[]) | @@ -97,8 +97,7 @@ main(int argc, char* argv[]) | ||
| 97 | page.filterContents(&counter, &out); | 97 | page.filterContents(&counter, &out); |
| 98 | std::cout << "\n% end " << pageno << std::endl; | 98 | std::cout << "\n% end " << pageno << std::endl; |
| 99 | } | 99 | } |
| 100 | - std::cout << "Page " << pageno | ||
| 101 | - << ": strings = " << counter.getCount() << std::endl; | 100 | + std::cout << "Page " << pageno << ": strings = " << counter.getCount() << std::endl; |
| 102 | } | 101 | } |
| 103 | } catch (std::exception& e) { | 102 | } catch (std::exception& e) { |
| 104 | std::cerr << whoami << ": " << e.what() << std::endl; | 103 | std::cerr << whoami << ": " << e.what() << std::endl; |
examples/pdf-create.cc
| @@ -41,8 +41,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider | @@ -41,8 +41,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider | ||
| 41 | J_COLOR_SPACE j_color_space; | 41 | J_COLOR_SPACE j_color_space; |
| 42 | }; | 42 | }; |
| 43 | 43 | ||
| 44 | -ImageProvider::ImageProvider( | ||
| 45 | - std::string const& color_space, std::string const& filter) : | 44 | +ImageProvider::ImageProvider(std::string const& color_space, std::string const& filter) : |
| 46 | width(400), | 45 | width(400), |
| 47 | stripe_height(80), | 46 | stripe_height(80), |
| 48 | color_space(color_space), | 47 | color_space(color_space), |
| @@ -107,8 +106,7 @@ ImageProvider::provideStreamData(QPDFObjGen const&, Pipeline* pipeline) | @@ -107,8 +106,7 @@ ImageProvider::provideStreamData(QPDFObjGen const&, Pipeline* pipeline) | ||
| 107 | to_delete.push_back(p_new); | 106 | to_delete.push_back(p_new); |
| 108 | p = p_new.get(); | 107 | p = p_new.get(); |
| 109 | } else if (filter == "/RunLengthDecode") { | 108 | } else if (filter == "/RunLengthDecode") { |
| 110 | - p_new = std::make_shared<Pl_RunLength>( | ||
| 111 | - "image encoder", pipeline, Pl_RunLength::a_encode); | 109 | + p_new = std::make_shared<Pl_RunLength>("image encoder", pipeline, Pl_RunLength::a_encode); |
| 112 | to_delete.push_back(p_new); | 110 | to_delete.push_back(p_new); |
| 113 | p = p_new.get(); | 111 | p = p_new.get(); |
| 114 | } | 112 | } |
| @@ -184,8 +182,7 @@ add_page( | @@ -184,8 +182,7 @@ add_page( | ||
| 184 | image.replaceDict(image_dict); | 182 | image.replaceDict(image_dict); |
| 185 | 183 | ||
| 186 | // Provide the stream data. | 184 | // Provide the stream data. |
| 187 | - image.replaceStreamData( | ||
| 188 | - provider, QPDFObjectHandle::parse(filter), QPDFObjectHandle::newNull()); | 185 | + image.replaceStreamData(provider, QPDFObjectHandle::parse(filter), QPDFObjectHandle::newNull()); |
| 189 | 186 | ||
| 190 | // Create direct objects as needed by the page dictionary. | 187 | // Create direct objects as needed by the page dictionary. |
| 191 | QPDFObjectHandle procset = "[/PDF /Text /ImageC]"_qpdf; | 188 | QPDFObjectHandle procset = "[/PDF /Text /ImageC]"_qpdf; |
| @@ -202,8 +199,7 @@ add_page( | @@ -202,8 +199,7 @@ add_page( | ||
| 202 | resources.replaceKey("/XObject", xobject); | 199 | resources.replaceKey("/XObject", xobject); |
| 203 | 200 | ||
| 204 | // Create the page content stream | 201 | // Create the page content stream |
| 205 | - QPDFObjectHandle contents = | ||
| 206 | - createPageContents(pdf, color_space + " with filter " + filter); | 202 | + QPDFObjectHandle contents = createPageContents(pdf, color_space + " with filter " + filter); |
| 207 | 203 | ||
| 208 | // Create the page dictionary | 204 | // Create the page dictionary |
| 209 | QPDFObjectHandle page = pdf.makeIndirectObject("<<" | 205 | QPDFObjectHandle page = pdf.makeIndirectObject("<<" |
| @@ -256,8 +252,7 @@ check( | @@ -256,8 +252,7 @@ check( | ||
| 256 | } | 252 | } |
| 257 | 253 | ||
| 258 | // Check filter and color space. | 254 | // Check filter and color space. |
| 259 | - std::string desired_color_space = | ||
| 260 | - color_spaces[(pageno - 1) / n_color_spaces]; | 255 | + std::string desired_color_space = color_spaces[(pageno - 1) / n_color_spaces]; |
| 261 | std::string desired_filter = filters[(pageno - 1) % n_filters]; | 256 | std::string desired_filter = filters[(pageno - 1) % n_filters]; |
| 262 | // In the default mode, QPDFWriter will compress with | 257 | // In the default mode, QPDFWriter will compress with |
| 263 | // /FlateDecode if no filters are provided. | 258 | // /FlateDecode if no filters are provided. |
| @@ -271,16 +266,13 @@ check( | @@ -271,16 +266,13 @@ check( | ||
| 271 | bool this_errors = false; | 266 | bool this_errors = false; |
| 272 | if (!filter.isNameAndEquals(desired_filter)) { | 267 | if (!filter.isNameAndEquals(desired_filter)) { |
| 273 | this_errors = errors = true; | 268 | this_errors = errors = true; |
| 274 | - std::cout << "page " << pageno << ": expected filter " | ||
| 275 | - << desired_filter | 269 | + std::cout << "page " << pageno << ": expected filter " << desired_filter |
| 276 | << "; actual filter = " << filter.unparse() << std::endl; | 270 | << "; actual filter = " << filter.unparse() << std::endl; |
| 277 | } | 271 | } |
| 278 | if (!color_space.isNameAndEquals(desired_color_space)) { | 272 | if (!color_space.isNameAndEquals(desired_color_space)) { |
| 279 | this_errors = errors = true; | 273 | this_errors = errors = true; |
| 280 | - std::cout << "page " << pageno << ": expected color space " | ||
| 281 | - << desired_color_space | ||
| 282 | - << "; actual color space = " << color_space.unparse() | ||
| 283 | - << std::endl; | 274 | + std::cout << "page " << pageno << ": expected color space " << desired_color_space |
| 275 | + << "; actual color space = " << color_space.unparse() << std::endl; | ||
| 284 | } | 276 | } |
| 285 | 277 | ||
| 286 | if (!this_errors) { | 278 | if (!this_errors) { |
| @@ -293,8 +285,7 @@ check( | @@ -293,8 +285,7 @@ check( | ||
| 293 | std::shared_ptr<Buffer> desired_data(b_p.getBuffer()); | 285 | std::shared_ptr<Buffer> desired_data(b_p.getBuffer()); |
| 294 | 286 | ||
| 295 | if (desired_data->getSize() != actual_data->getSize()) { | 287 | if (desired_data->getSize() != actual_data->getSize()) { |
| 296 | - std::cout << "page " << pageno << ": image data length mismatch" | ||
| 297 | - << std::endl; | 288 | + std::cout << "page " << pageno << ": image data length mismatch" << std::endl; |
| 298 | this_errors = errors = true; | 289 | this_errors = errors = true; |
| 299 | } else { | 290 | } else { |
| 300 | // Compare bytes. For JPEG, allow a certain number of | 291 | // Compare bytes. For JPEG, allow a certain number of |
| @@ -308,8 +299,7 @@ check( | @@ -308,8 +299,7 @@ check( | ||
| 308 | size_t len = actual_data->getSize(); | 299 | size_t len = actual_data->getSize(); |
| 309 | unsigned int mismatches = 0; | 300 | unsigned int mismatches = 0; |
| 310 | int tolerance = (desired_filter == "/DCTDecode" ? 10 : 0); | 301 | int tolerance = (desired_filter == "/DCTDecode" ? 10 : 0); |
| 311 | - size_t threshold = | ||
| 312 | - (desired_filter == "/DCTDecode" ? len / 40U : 0); | 302 | + size_t threshold = (desired_filter == "/DCTDecode" ? len / 40U : 0); |
| 313 | for (size_t i = 0; i < len; ++i) { | 303 | for (size_t i = 0; i < len; ++i) { |
| 314 | int delta = actual_bytes[i] - desired_bytes[i]; | 304 | int delta = actual_bytes[i] - desired_bytes[i]; |
| 315 | if ((delta > tolerance) || (delta < -tolerance)) { | 305 | if ((delta > tolerance) || (delta < -tolerance)) { |
| @@ -317,9 +307,8 @@ check( | @@ -317,9 +307,8 @@ check( | ||
| 317 | } | 307 | } |
| 318 | } | 308 | } |
| 319 | if (mismatches > threshold) { | 309 | if (mismatches > threshold) { |
| 320 | - std::cout << "page " << pageno << ": " | ||
| 321 | - << desired_color_space << ", " << desired_filter | ||
| 322 | - << ": mismatches: " << mismatches << " of " << len | 310 | + std::cout << "page " << pageno << ": " << desired_color_space << ", " |
| 311 | + << desired_filter << ": mismatches: " << mismatches << " of " << len | ||
| 323 | << std::endl; | 312 | << std::endl; |
| 324 | this_errors = errors = true; | 313 | this_errors = errors = true; |
| 325 | } | 314 | } |
examples/pdf-custom-filter.cc
| @@ -132,8 +132,7 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms) | @@ -132,8 +132,7 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms) | ||
| 132 | this->key = buf->getBuffer()[0]; | 132 | this->key = buf->getBuffer()[0]; |
| 133 | return true; | 133 | return true; |
| 134 | } catch (std::exception& e) { | 134 | } catch (std::exception& e) { |
| 135 | - std::cerr << "Error extracting key for /XORDecode: " << e.what() | ||
| 136 | - << std::endl; | 135 | + std::cerr << "Error extracting key for /XORDecode: " << e.what() << std::endl; |
| 137 | } | 136 | } |
| 138 | return false; | 137 | return false; |
| 139 | } | 138 | } |
| @@ -203,8 +202,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider | @@ -203,8 +202,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider | ||
| 203 | void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override; | 202 | void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override; |
| 204 | 203 | ||
| 205 | void registerStream( | 204 | void registerStream( |
| 206 | - QPDFObjectHandle stream, | ||
| 207 | - std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self); | 205 | + QPDFObjectHandle stream, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self); |
| 208 | 206 | ||
| 209 | private: | 207 | private: |
| 210 | bool maybeReplace( | 208 | bool maybeReplace( |
| @@ -300,12 +298,10 @@ StreamReplacer::maybeReplace( | @@ -300,12 +298,10 @@ StreamReplacer::maybeReplace( | ||
| 300 | // changes. For example, an image resampler might change the | 298 | // changes. For example, an image resampler might change the |
| 301 | // dimensions or other properties of the image. | 299 | // dimensions or other properties of the image. |
| 302 | dict_updates->replaceKey( | 300 | dict_updates->replaceKey( |
| 303 | - "/OrigLength", | ||
| 304 | - QPDFObjectHandle::newInteger(QIntC::to_longlong(out->getSize()))); | 301 | + "/OrigLength", QPDFObjectHandle::newInteger(QIntC::to_longlong(out->getSize()))); |
| 305 | // We are also storing the "key" that we will access when | 302 | // We are also storing the "key" that we will access when |
| 306 | // writing the data. | 303 | // writing the data. |
| 307 | - this->keys[og] = QIntC::to_uchar( | ||
| 308 | - (og.getObj() * QIntC::to_int(out->getSize())) & 0xff); | 304 | + this->keys[og] = QIntC::to_uchar((og.getObj() * QIntC::to_int(out->getSize())) & 0xff); |
| 309 | } | 305 | } |
| 310 | 306 | ||
| 311 | if (pipeline) { | 307 | if (pipeline) { |
| @@ -319,8 +315,7 @@ StreamReplacer::maybeReplace( | @@ -319,8 +315,7 @@ StreamReplacer::maybeReplace( | ||
| 319 | 315 | ||
| 320 | void | 316 | void |
| 321 | StreamReplacer::registerStream( | 317 | StreamReplacer::registerStream( |
| 322 | - QPDFObjectHandle stream, | ||
| 323 | - std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self) | 318 | + QPDFObjectHandle stream, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self) |
| 324 | { | 319 | { |
| 325 | QPDFObjGen og(stream.getObjGen()); | 320 | QPDFObjGen og(stream.getObjGen()); |
| 326 | 321 | ||
| @@ -344,8 +339,7 @@ StreamReplacer::registerStream( | @@ -344,8 +339,7 @@ StreamReplacer::registerStream( | ||
| 344 | try { | 339 | try { |
| 345 | should_replace = maybeReplace(og, stream, nullptr, &dict_updates); | 340 | should_replace = maybeReplace(og, stream, nullptr, &dict_updates); |
| 346 | } catch (std::exception& e) { | 341 | } catch (std::exception& e) { |
| 347 | - stream.warnIfPossible( | ||
| 348 | - std::string("exception while attempting to replace: ") + e.what()); | 342 | + stream.warnIfPossible(std::string("exception while attempting to replace: ") + e.what()); |
| 349 | } | 343 | } |
| 350 | 344 | ||
| 351 | if (should_replace) { | 345 | if (should_replace) { |
| @@ -369,8 +363,7 @@ StreamReplacer::registerStream( | @@ -369,8 +363,7 @@ StreamReplacer::registerStream( | ||
| 369 | // /XORDecode filter. | 363 | // /XORDecode filter. |
| 370 | QPDFObjectHandle decode_parms = | 364 | QPDFObjectHandle decode_parms = |
| 371 | QPDFObjectHandle::newDictionary({{"/KeyStream", dp_stream}}); | 365 | QPDFObjectHandle::newDictionary({{"/KeyStream", dp_stream}}); |
| 372 | - stream.replaceStreamData( | ||
| 373 | - self, QPDFObjectHandle::newName("/XORDecode"), decode_parms); | 366 | + stream.replaceStreamData(self, QPDFObjectHandle::newName("/XORDecode"), decode_parms); |
| 374 | // Further, if /ProtectXOR = true, we disable filtering on write | 367 | // Further, if /ProtectXOR = true, we disable filtering on write |
| 375 | // so that QPDFWriter will not decode the stream even though we | 368 | // so that QPDFWriter will not decode the stream even though we |
| 376 | // have registered a stream filter for /XORDecode. | 369 | // have registered a stream filter for /XORDecode. |
| @@ -393,14 +386,12 @@ StreamReplacer::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) | @@ -393,14 +386,12 @@ StreamReplacer::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) | ||
| 393 | // Since this only gets called for streams we already | 386 | // Since this only gets called for streams we already |
| 394 | // determined we are replacing, a false return would indicate | 387 | // determined we are replacing, a false return would indicate |
| 395 | // a logic error. | 388 | // a logic error. |
| 396 | - throw std::logic_error( | ||
| 397 | - "should_replace return false in provideStreamData"); | 389 | + throw std::logic_error("should_replace return false in provideStreamData"); |
| 398 | } | 390 | } |
| 399 | } | 391 | } |
| 400 | 392 | ||
| 401 | static void | 393 | static void |
| 402 | -process( | ||
| 403 | - char const* infilename, char const* outfilename, bool decode_specialized) | 394 | +process(char const* infilename, char const* outfilename, bool decode_specialized) |
| 404 | { | 395 | { |
| 405 | QPDF qpdf; | 396 | QPDF qpdf; |
| 406 | qpdf.processFile(infilename); | 397 | qpdf.processFile(infilename); |
| @@ -434,8 +425,7 @@ static void | @@ -434,8 +425,7 @@ static void | ||
| 434 | usage() | 425 | usage() |
| 435 | { | 426 | { |
| 436 | std::cerr << "\n" | 427 | std::cerr << "\n" |
| 437 | - << "Usage: " << whoami | ||
| 438 | - << " [--decode-specialized] infile outfile\n" | 428 | + << "Usage: " << whoami << " [--decode-specialized] infile outfile\n" |
| 439 | << std::endl; | 429 | << std::endl; |
| 440 | exit(2); | 430 | exit(2); |
| 441 | } | 431 | } |
| @@ -468,8 +458,7 @@ main(int argc, char* argv[]) | @@ -468,8 +458,7 @@ main(int argc, char* argv[]) | ||
| 468 | // decode our streams. This is not a real filter, so no real | 458 | // decode our streams. This is not a real filter, so no real |
| 469 | // PDF reading application would be able to interpret it. This | 459 | // PDF reading application would be able to interpret it. This |
| 470 | // is just for illustrative purposes. | 460 | // is just for illustrative purposes. |
| 471 | - QPDF::registerStreamFilter( | ||
| 472 | - "/XORDecode", [] { return std::make_shared<SF_XORDecode>(); }); | 461 | + QPDF::registerStreamFilter("/XORDecode", [] { return std::make_shared<SF_XORDecode>(); }); |
| 473 | // Do the actual processing. | 462 | // Do the actual processing. |
| 474 | process(infilename, outfilename, decode_specialized); | 463 | process(infilename, outfilename, decode_specialized); |
| 475 | } catch (std::exception& e) { | 464 | } catch (std::exception& e) { |
examples/pdf-double-page-size.cc
| @@ -13,8 +13,7 @@ static char const* whoami = nullptr; | @@ -13,8 +13,7 @@ static char const* whoami = nullptr; | ||
| 13 | void | 13 | void |
| 14 | usage() | 14 | usage() |
| 15 | { | 15 | { |
| 16 | - std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" | ||
| 17 | - << std::endl | 16 | + std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl |
| 18 | << "Double size of all pages in infile.pdf;" | 17 | << "Double size of all pages in infile.pdf;" |
| 19 | << " write output to outfile.pdf" << std::endl; | 18 | << " write output to outfile.pdf" << std::endl; |
| 20 | exit(2); | 19 | exit(2); |
| @@ -33,16 +32,13 @@ doubleBoxSize(QPDFPageObjectHelper& page, char const* box_name) | @@ -33,16 +32,13 @@ doubleBoxSize(QPDFPageObjectHelper& page, char const* box_name) | ||
| 33 | } | 32 | } |
| 34 | if (!box.isRectangle()) { | 33 | if (!box.isRectangle()) { |
| 35 | throw std::runtime_error( | 34 | throw std::runtime_error( |
| 36 | - std::string("box ") + box_name + | ||
| 37 | - " is not an array of four elements"); | 35 | + std::string("box ") + box_name + " is not an array of four elements"); |
| 38 | } | 36 | } |
| 39 | std::vector<QPDFObjectHandle> doubled; | 37 | std::vector<QPDFObjectHandle> doubled; |
| 40 | for (auto& item: box.aitems()) { | 38 | for (auto& item: box.aitems()) { |
| 41 | - doubled.push_back( | ||
| 42 | - QPDFObjectHandle::newReal(item.getNumericValue() * 2.0, 2)); | 39 | + doubled.push_back(QPDFObjectHandle::newReal(item.getNumericValue() * 2.0, 2)); |
| 43 | } | 40 | } |
| 44 | - page.getObjectHandle().replaceKey( | ||
| 45 | - box_name, QPDFObjectHandle::newArray(doubled)); | 41 | + page.getObjectHandle().replaceKey(box_name, QPDFObjectHandle::newArray(doubled)); |
| 46 | } | 42 | } |
| 47 | 43 | ||
| 48 | int | 44 | int |
| @@ -93,11 +89,9 @@ main(int argc, char* argv[]) | @@ -93,11 +89,9 @@ main(int argc, char* argv[]) | ||
| 93 | w.setStreamDataMode(qpdf_s_uncompress); | 89 | w.setStreamDataMode(qpdf_s_uncompress); |
| 94 | } | 90 | } |
| 95 | w.write(); | 91 | w.write(); |
| 96 | - std::cout << whoami << ": new file written to " << outfilename | ||
| 97 | - << std::endl; | 92 | + std::cout << whoami << ": new file written to " << outfilename << std::endl; |
| 98 | } catch (std::exception& e) { | 93 | } catch (std::exception& e) { |
| 99 | - std::cerr << whoami << " processing file " << infilename << ": " | ||
| 100 | - << e.what() << std::endl; | 94 | + std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl; |
| 101 | exit(2); | 95 | exit(2); |
| 102 | } | 96 | } |
| 103 | 97 |
examples/pdf-filter-tokens.cc
| @@ -22,8 +22,7 @@ void | @@ -22,8 +22,7 @@ void | ||
| 22 | usage() | 22 | usage() |
| 23 | { | 23 | { |
| 24 | std::cerr << "Usage: " << whoami << " infile outfile" << std::endl | 24 | std::cerr << "Usage: " << whoami << " infile outfile" << std::endl |
| 25 | - << "Applies token filters to infile and writes outfile" | ||
| 26 | - << std::endl; | 25 | + << "Applies token filters to infile and writes outfile" << std::endl; |
| 27 | exit(2); | 26 | exit(2); |
| 28 | } | 27 | } |
| 29 | 28 | ||
| @@ -82,17 +81,13 @@ class ColorToGray: public QPDFObjectHandle::TokenFilter | @@ -82,17 +81,13 @@ class ColorToGray: public QPDFObjectHandle::TokenFilter | ||
| 82 | bool | 81 | bool |
| 83 | ColorToGray::isNumeric(QPDFTokenizer::token_type_e token_type) | 82 | ColorToGray::isNumeric(QPDFTokenizer::token_type_e token_type) |
| 84 | { | 83 | { |
| 85 | - return ( | ||
| 86 | - (token_type == QPDFTokenizer::tt_integer) || | ||
| 87 | - (token_type == QPDFTokenizer::tt_real)); | 84 | + return ((token_type == QPDFTokenizer::tt_integer) || (token_type == QPDFTokenizer::tt_real)); |
| 88 | } | 85 | } |
| 89 | 86 | ||
| 90 | bool | 87 | bool |
| 91 | ColorToGray::isIgnorable(QPDFTokenizer::token_type_e token_type) | 88 | ColorToGray::isIgnorable(QPDFTokenizer::token_type_e token_type) |
| 92 | { | 89 | { |
| 93 | - return ( | ||
| 94 | - (token_type == QPDFTokenizer::tt_space) || | ||
| 95 | - (token_type == QPDFTokenizer::tt_comment)); | 90 | + return ((token_type == QPDFTokenizer::tt_space) || (token_type == QPDFTokenizer::tt_comment)); |
| 96 | } | 91 | } |
| 97 | 92 | ||
| 98 | double | 93 | double |
| @@ -128,8 +123,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const& token) | @@ -128,8 +123,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const& token) | ||
| 128 | // kinds of operands, replace the command. Flush any additional | 123 | // kinds of operands, replace the command. Flush any additional |
| 129 | // accumulated tokens to keep the stack only four tokens deep. | 124 | // accumulated tokens to keep the stack only four tokens deep. |
| 130 | 125 | ||
| 131 | - while ((!this->all_stack.empty()) && | ||
| 132 | - isIgnorable(this->all_stack.at(0).getType())) { | 126 | + while ((!this->all_stack.empty()) && isIgnorable(this->all_stack.at(0).getType())) { |
| 133 | writeToken(this->all_stack.at(0)); | 127 | writeToken(this->all_stack.at(0)); |
| 134 | this->all_stack.pop_front(); | 128 | this->all_stack.pop_front(); |
| 135 | } | 129 | } |
| @@ -138,8 +132,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const& token) | @@ -138,8 +132,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const& token) | ||
| 138 | if (!isIgnorable(token_type)) { | 132 | if (!isIgnorable(token_type)) { |
| 139 | this->stack.push_back(token); | 133 | this->stack.push_back(token); |
| 140 | if ((this->stack.size() == 4) && token.isWord("rg") && | 134 | if ((this->stack.size() == 4) && token.isWord("rg") && |
| 141 | - (isNumeric(this->stack.at(0).getType())) && | ||
| 142 | - (isNumeric(this->stack.at(1).getType())) && | 135 | + (isNumeric(this->stack.at(0).getType())) && (isNumeric(this->stack.at(1).getType())) && |
| 143 | (isNumeric(this->stack.at(2).getType()))) { | 136 | (isNumeric(this->stack.at(2).getType()))) { |
| 144 | double r = numericValue(this->stack.at(0)); | 137 | double r = numericValue(this->stack.at(0)); |
| 145 | double g = numericValue(this->stack.at(1)); | 138 | double g = numericValue(this->stack.at(1)); |
| @@ -195,11 +188,9 @@ main(int argc, char* argv[]) | @@ -195,11 +188,9 @@ main(int argc, char* argv[]) | ||
| 195 | // applied. See comments on the filters for additional | 188 | // applied. See comments on the filters for additional |
| 196 | // details. | 189 | // details. |
| 197 | page.addContentTokenFilter( | 190 | page.addContentTokenFilter( |
| 198 | - std::shared_ptr<QPDFObjectHandle::TokenFilter>( | ||
| 199 | - new StringReverser)); | 191 | + std::shared_ptr<QPDFObjectHandle::TokenFilter>(new StringReverser)); |
| 200 | page.addContentTokenFilter( | 192 | page.addContentTokenFilter( |
| 201 | - std::shared_ptr<QPDFObjectHandle::TokenFilter>( | ||
| 202 | - new ColorToGray)); | 193 | + std::shared_ptr<QPDFObjectHandle::TokenFilter>(new ColorToGray)); |
| 203 | } | 194 | } |
| 204 | 195 | ||
| 205 | QPDFWriter w(pdf, outfilename); | 196 | QPDFWriter w(pdf, outfilename); |
examples/pdf-invert-images.cc
| @@ -14,8 +14,7 @@ static char const* whoami = nullptr; | @@ -14,8 +14,7 @@ static char const* whoami = nullptr; | ||
| 14 | void | 14 | void |
| 15 | usage() | 15 | usage() |
| 16 | { | 16 | { |
| 17 | - std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" | ||
| 18 | - << std::endl | 17 | + std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl |
| 19 | << "Invert some images in infile.pdf;" | 18 | << "Invert some images in infile.pdf;" |
| 20 | << " write output to outfile.pdf" << std::endl; | 19 | << " write output to outfile.pdf" << std::endl; |
| 21 | exit(2); | 20 | exit(2); |
| @@ -37,8 +36,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider | @@ -37,8 +36,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider | ||
| 37 | void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override; | 36 | void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override; |
| 38 | 37 | ||
| 39 | void registerImage( | 38 | void registerImage( |
| 40 | - QPDFObjectHandle image, | ||
| 41 | - std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self); | 39 | + QPDFObjectHandle image, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self); |
| 42 | 40 | ||
| 43 | private: | 41 | private: |
| 44 | std::map<QPDFObjGen, QPDFObjectHandle> copied_images; | 42 | std::map<QPDFObjGen, QPDFObjectHandle> copied_images; |
| @@ -46,8 +44,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider | @@ -46,8 +44,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider | ||
| 46 | 44 | ||
| 47 | void | 45 | void |
| 48 | ImageInverter::registerImage( | 46 | ImageInverter::registerImage( |
| 49 | - QPDFObjectHandle image, | ||
| 50 | - std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self) | 47 | + QPDFObjectHandle image, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self) |
| 51 | { | 48 | { |
| 52 | // replaceStreamData requires a pointer holder to the stream data | 49 | // replaceStreamData requires a pointer holder to the stream data |
| 53 | // provider, but there's no way for us to generate one ourselves, | 50 | // provider, but there's no way for us to generate one ourselves, |
| @@ -76,8 +73,7 @@ ImageInverter::registerImage( | @@ -76,8 +73,7 @@ ImageInverter::registerImage( | ||
| 76 | // filterable in the input QPDF object, so we don't have to deal | 73 | // filterable in the input QPDF object, so we don't have to deal |
| 77 | // with it explicitly here. We could explicitly use /DCTDecode and | 74 | // with it explicitly here. We could explicitly use /DCTDecode and |
| 78 | // write through a DCT filter if we wanted. | 75 | // write through a DCT filter if we wanted. |
| 79 | - image.replaceStreamData( | ||
| 80 | - self, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | 76 | + image.replaceStreamData(self, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 81 | } | 77 | } |
| 82 | 78 | ||
| 83 | void | 79 | void |
| @@ -86,8 +82,7 @@ ImageInverter::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) | @@ -86,8 +82,7 @@ ImageInverter::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) | ||
| 86 | // Use the object and generation number supplied to look up the | 82 | // Use the object and generation number supplied to look up the |
| 87 | // image data. Then invert the image data and write the inverted | 83 | // image data. Then invert the image data and write the inverted |
| 88 | // data to the pipeline. | 84 | // data to the pipeline. |
| 89 | - std::shared_ptr<Buffer> data = | ||
| 90 | - this->copied_images[og].getStreamData(qpdf_dl_all); | 85 | + std::shared_ptr<Buffer> data = this->copied_images[og].getStreamData(qpdf_dl_all); |
| 91 | size_t size = data->getSize(); | 86 | size_t size = data->getSize(); |
| 92 | unsigned char* buf = data->getBuffer(); | 87 | unsigned char* buf = data->getBuffer(); |
| 93 | unsigned char ch; | 88 | unsigned char ch; |
| @@ -133,18 +128,15 @@ main(int argc, char* argv[]) | @@ -133,18 +128,15 @@ main(int argc, char* argv[]) | ||
| 133 | QPDFObjectHandle& image = iter.second; | 128 | QPDFObjectHandle& image = iter.second; |
| 134 | QPDFObjectHandle image_dict = image.getDict(); | 129 | QPDFObjectHandle image_dict = image.getDict(); |
| 135 | QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace"); | 130 | QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace"); |
| 136 | - QPDFObjectHandle bits_per_component = | ||
| 137 | - image_dict.getKey("/BitsPerComponent"); | 131 | + QPDFObjectHandle bits_per_component = image_dict.getKey("/BitsPerComponent"); |
| 138 | 132 | ||
| 139 | // For our example, we can only work with images 8-bit | 133 | // For our example, we can only work with images 8-bit |
| 140 | // grayscale images that we can fully decode. Use | 134 | // grayscale images that we can fully decode. Use |
| 141 | // pipeStreamData with a null pipeline to determine | 135 | // pipeStreamData with a null pipeline to determine |
| 142 | // whether the image is filterable. Directly inspect | 136 | // whether the image is filterable. Directly inspect |
| 143 | // keys to determine the image type. | 137 | // keys to determine the image type. |
| 144 | - if (image.pipeStreamData( | ||
| 145 | - nullptr, qpdf_ef_compress, qpdf_dl_all) && | ||
| 146 | - color_space.isNameAndEquals("/DeviceGray") && | ||
| 147 | - bits_per_component.isInteger() && | 138 | + if (image.pipeStreamData(nullptr, qpdf_ef_compress, qpdf_dl_all) && |
| 139 | + color_space.isNameAndEquals("/DeviceGray") && bits_per_component.isInteger() && | ||
| 148 | (bits_per_component.getIntValue() == 8)) { | 140 | (bits_per_component.getIntValue() == 8)) { |
| 149 | inv->registerImage(image, p); | 141 | inv->registerImage(image, p); |
| 150 | } | 142 | } |
| @@ -159,11 +151,9 @@ main(int argc, char* argv[]) | @@ -159,11 +151,9 @@ main(int argc, char* argv[]) | ||
| 159 | w.setStaticID(true); // for testing only | 151 | w.setStaticID(true); // for testing only |
| 160 | } | 152 | } |
| 161 | w.write(); | 153 | w.write(); |
| 162 | - std::cout << whoami << ": new file written to " << outfilename | ||
| 163 | - << std::endl; | 154 | + std::cout << whoami << ": new file written to " << outfilename << std::endl; |
| 164 | } catch (std::exception& e) { | 155 | } catch (std::exception& e) { |
| 165 | - std::cerr << whoami << " processing file " << infilename << ": " | ||
| 166 | - << e.what() << std::endl; | 156 | + std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl; |
| 167 | exit(2); | 157 | exit(2); |
| 168 | } | 158 | } |
| 169 | 159 |
examples/pdf-linearize.c
| @@ -61,15 +61,11 @@ main(int argc, char* argv[]) | @@ -61,15 +61,11 @@ main(int argc, char* argv[]) | ||
| 61 | } | 61 | } |
| 62 | while (qpdf_more_warnings(qpdf)) { | 62 | while (qpdf_more_warnings(qpdf)) { |
| 63 | warnings = 1; | 63 | warnings = 1; |
| 64 | - printf( | ||
| 65 | - "warning: %s\n", | ||
| 66 | - qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); | 64 | + printf("warning: %s\n", qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); |
| 67 | } | 65 | } |
| 68 | if (qpdf_has_error(qpdf)) { | 66 | if (qpdf_has_error(qpdf)) { |
| 69 | errors = 1; | 67 | errors = 1; |
| 70 | - printf( | ||
| 71 | - "error: %s\n", | ||
| 72 | - qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf))); | 68 | + printf("error: %s\n", qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf))); |
| 73 | } | 69 | } |
| 74 | qpdf_cleanup(&qpdf); | 70 | qpdf_cleanup(&qpdf); |
| 75 | if (errors) { | 71 | if (errors) { |
examples/pdf-mod-info.cc
| @@ -16,8 +16,7 @@ static char const* whoami = nullptr; | @@ -16,8 +16,7 @@ static char const* whoami = nullptr; | ||
| 16 | void | 16 | void |
| 17 | usage() | 17 | usage() |
| 18 | { | 18 | { |
| 19 | - std::cerr << "Usage: " << whoami | ||
| 20 | - << " --in in_file [--out out_file] [--key key [--val val]?]+\n" | 19 | + std::cerr << "Usage: " << whoami << " --in in_file [--out out_file] [--key key [--val val]?]+\n" |
| 21 | << "Modifies/Adds/Removes PDF /Info entries in the in_file\n" | 20 | << "Modifies/Adds/Removes PDF /Info entries in the in_file\n" |
| 22 | << "and stores the result in out_file\n" | 21 | << "and stores the result in out_file\n" |
| 23 | << "Special mode: " << whoami << " --dump file\n" | 22 | << "Special mode: " << whoami << " --dump file\n" |
| @@ -26,8 +25,7 @@ usage() | @@ -26,8 +25,7 @@ usage() | ||
| 26 | } | 25 | } |
| 27 | 26 | ||
| 28 | void | 27 | void |
| 29 | -dumpInfoDict( | ||
| 30 | - QPDF& pdf, std::ostream& os = std::cout, std::string const& sep = ":\t") | 28 | +dumpInfoDict(QPDF& pdf, std::ostream& os = std::cout, std::string const& sep = ":\t") |
| 31 | { | 29 | { |
| 32 | QPDFObjectHandle trailer = pdf.getTrailer(); | 30 | QPDFObjectHandle trailer = pdf.getTrailer(); |
| 33 | if (trailer.hasKey("/Info")) { | 31 | if (trailer.hasKey("/Info")) { |
| @@ -164,8 +162,7 @@ main(int argc, char* argv[]) | @@ -164,8 +162,7 @@ main(int argc, char* argv[]) | ||
| 164 | try { | 162 | try { |
| 165 | (void)remove(fl_out); | 163 | (void)remove(fl_out); |
| 166 | QUtil::os_wrapper( | 164 | QUtil::os_wrapper( |
| 167 | - "rename " + fl_tmp + " " + std::string(fl_out), | ||
| 168 | - rename(fl_tmp.c_str(), fl_out)); | 165 | + "rename " + fl_tmp + " " + std::string(fl_out), rename(fl_tmp.c_str(), fl_out)); |
| 169 | } catch (std::exception& e) { | 166 | } catch (std::exception& e) { |
| 170 | std::cerr << e.what() << std::endl; | 167 | std::cerr << e.what() << std::endl; |
| 171 | exit(2); | 168 | exit(2); |
examples/pdf-name-number-tree.cc
| @@ -11,8 +11,7 @@ void | @@ -11,8 +11,7 @@ void | ||
| 11 | usage() | 11 | usage() |
| 12 | { | 12 | { |
| 13 | std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl | 13 | std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl |
| 14 | - << "Create some name/number trees and write to a file" | ||
| 15 | - << std::endl; | 14 | + << "Create some name/number trees and write to a file" << std::endl; |
| 16 | exit(2); | 15 | exit(2); |
| 17 | } | 16 | } |
| 18 | 17 | ||
| @@ -61,24 +60,19 @@ main(int argc, char* argv[]) | @@ -61,24 +60,19 @@ main(int argc, char* argv[]) | ||
| 61 | name_tree.insert("R", QPDFObjectHandle::newUnicodeString("rook")); | 60 | name_tree.insert("R", QPDFObjectHandle::newUnicodeString("rook")); |
| 62 | name_tree.insert("B", QPDFObjectHandle::newUnicodeString("bishop")); | 61 | name_tree.insert("B", QPDFObjectHandle::newUnicodeString("bishop")); |
| 63 | name_tree.insert("N", QPDFObjectHandle::newUnicodeString("knight")); | 62 | name_tree.insert("N", QPDFObjectHandle::newUnicodeString("knight")); |
| 64 | - auto iter = | ||
| 65 | - name_tree.insert("P", QPDFObjectHandle::newUnicodeString("pawn")); | 63 | + auto iter = name_tree.insert("P", QPDFObjectHandle::newUnicodeString("pawn")); |
| 66 | // Look at the iterator | 64 | // Look at the iterator |
| 67 | - std::cout << "just inserted " << iter->first << " -> " | ||
| 68 | - << iter->second.unparse() << std::endl; | 65 | + std::cout << "just inserted " << iter->first << " -> " << iter->second.unparse() << std::endl; |
| 69 | --iter; | 66 | --iter; |
| 70 | - std::cout << "predecessor: " << iter->first << " -> " | ||
| 71 | - << iter->second.unparse() << std::endl; | 67 | + std::cout << "predecessor: " << iter->first << " -> " << iter->second.unparse() << std::endl; |
| 72 | ++iter; | 68 | ++iter; |
| 73 | ++iter; | 69 | ++iter; |
| 74 | - std::cout << "successor: " << iter->first << " -> " | ||
| 75 | - << iter->second.unparse() << std::endl; | 70 | + std::cout << "successor: " << iter->first << " -> " << iter->second.unparse() << std::endl; |
| 76 | 71 | ||
| 77 | // Use range-for iteration | 72 | // Use range-for iteration |
| 78 | std::cout << "Name tree items:" << std::endl; | 73 | std::cout << "Name tree items:" << std::endl; |
| 79 | for (auto i: name_tree) { | 74 | for (auto i: name_tree) { |
| 80 | - std::cout << " " << i.first << " -> " << i.second.unparse() | ||
| 81 | - << std::endl; | 75 | + std::cout << " " << i.first << " -> " << i.second.unparse() << std::endl; |
| 82 | } | 76 | } |
| 83 | 77 | ||
| 84 | // This is a small tree, so everything will be at the root. We can | 78 | // This is a small tree, so everything will be at the root. We can |
| @@ -107,14 +101,13 @@ main(int argc, char* argv[]) | @@ -107,14 +101,13 @@ main(int argc, char* argv[]) | ||
| 107 | 101 | ||
| 108 | // 10.2 API | 102 | // 10.2 API |
| 109 | iter = name_tree.find("Q"); | 103 | iter = name_tree.find("Q"); |
| 110 | - std::cout << "Q: " << iter->first << " -> " << iter->second.unparse() | ||
| 111 | - << std::endl; | 104 | + std::cout << "Q: " << iter->first << " -> " << iter->second.unparse() << std::endl; |
| 112 | iter = name_tree.find("W"); | 105 | iter = name_tree.find("W"); |
| 113 | std::cout << "W found: " << (iter != name_tree.end()) << std::endl; | 106 | std::cout << "W found: " << (iter != name_tree.end()) << std::endl; |
| 114 | // Allow find to return predecessor | 107 | // Allow find to return predecessor |
| 115 | iter = name_tree.find("W", true); | 108 | iter = name_tree.find("W", true); |
| 116 | - std::cout << "W's predecessor: " << iter->first << " -> " | ||
| 117 | - << iter->second.unparse() << std::endl; | 109 | + std::cout << "W's predecessor: " << iter->first << " -> " << iter->second.unparse() |
| 110 | + << std::endl; | ||
| 118 | 111 | ||
| 119 | // We can also remove items | 112 | // We can also remove items |
| 120 | std::cout << "Remove P: " << name_tree.remove("P", &obj) << std::endl; | 113 | std::cout << "Remove P: " << name_tree.remove("P", &obj) << std::endl; |
| @@ -124,8 +117,8 @@ main(int argc, char* argv[]) | @@ -124,8 +117,8 @@ main(int argc, char* argv[]) | ||
| 124 | iter = name_tree.find("K"); | 117 | iter = name_tree.find("K"); |
| 125 | std::cout << "Find K: " << iter->second.unparse() << std::endl; | 118 | std::cout << "Find K: " << iter->second.unparse() << std::endl; |
| 126 | iter.remove(); | 119 | iter.remove(); |
| 127 | - std::cout << "Iter after removing K: " << iter->first << " -> " | ||
| 128 | - << iter->second.unparse() << std::endl; | 120 | + std::cout << "Iter after removing K: " << iter->first << " -> " << iter->second.unparse() |
| 121 | + << std::endl; | ||
| 129 | std::cout << "Has K?: " << name_tree.hasName("K") << std::endl; | 122 | std::cout << "Has K?: " << name_tree.hasName("K") << std::endl; |
| 130 | 123 | ||
| 131 | // Illustrate some more advanced usage using number trees. These | 124 | // Illustrate some more advanced usage using number trees. These |
| @@ -142,8 +135,7 @@ main(int argc, char* argv[]) | @@ -142,8 +135,7 @@ main(int argc, char* argv[]) | ||
| 142 | example.replaceKey("/NumberTree", number_tree_oh); | 135 | example.replaceKey("/NumberTree", number_tree_oh); |
| 143 | auto iter2 = number_tree.begin(); | 136 | auto iter2 = number_tree.begin(); |
| 144 | for (int i = 7; i <= 350; i += 7) { | 137 | for (int i = 7; i <= 350; i += 7) { |
| 145 | - iter2.insertAfter( | ||
| 146 | - i, QPDFObjectHandle::newString("-" + std::to_string(i) + "-")); | 138 | + iter2.insertAfter(i, QPDFObjectHandle::newString("-" + std::to_string(i) + "-")); |
| 147 | } | 139 | } |
| 148 | std::cout << "Numbers:" << std::endl; | 140 | std::cout << "Numbers:" << std::endl; |
| 149 | int n = 1; | 141 | int n = 1; |
examples/pdf-overlay-page.cc
| @@ -31,8 +31,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile) | @@ -31,8 +31,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile) | ||
| 31 | stamppdf.processFile(stampfile); | 31 | stamppdf.processFile(stampfile); |
| 32 | 32 | ||
| 33 | // Get first page from other file | 33 | // Get first page from other file |
| 34 | - QPDFPageObjectHelper stamp_page_1 = | ||
| 35 | - QPDFPageDocumentHelper(stamppdf).getAllPages().at(0); | 34 | + QPDFPageObjectHelper stamp_page_1 = QPDFPageDocumentHelper(stamppdf).getAllPages().at(0); |
| 36 | // Convert page to a form XObject | 35 | // Convert page to a form XObject |
| 37 | QPDFObjectHandle foreign_fo = stamp_page_1.getFormXObjectForPage(); | 36 | QPDFObjectHandle foreign_fo = stamp_page_1.getFormXObjectForPage(); |
| 38 | // Copy form XObject to the input file | 37 | // Copy form XObject to the input file |
| @@ -48,8 +47,8 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile) | @@ -48,8 +47,8 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile) | ||
| 48 | // Generate content to place the form XObject centered within | 47 | // Generate content to place the form XObject centered within |
| 49 | // destination page's trim box. | 48 | // destination page's trim box. |
| 50 | QPDFMatrix m; | 49 | QPDFMatrix m; |
| 51 | - std::string content = ph.placeFormXObject( | ||
| 52 | - stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m); | 50 | + std::string content = |
| 51 | + ph.placeFormXObject(stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m); | ||
| 53 | if (!content.empty()) { | 52 | if (!content.empty()) { |
| 54 | // Append the content to the page's content. Surround the | 53 | // Append the content to the page's content. Surround the |
| 55 | // original content with q...Q to the new content from the | 54 | // original content with q...Q to the new content from the |
examples/pdf-parse-content.cc
| @@ -35,11 +35,9 @@ ParserCallbacks::contentSize(size_t size) | @@ -35,11 +35,9 @@ ParserCallbacks::contentSize(size_t size) | ||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | void | 37 | void |
| 38 | -ParserCallbacks::handleObject( | ||
| 39 | - QPDFObjectHandle obj, size_t offset, size_t length) | 38 | +ParserCallbacks::handleObject(QPDFObjectHandle obj, size_t offset, size_t length) |
| 40 | { | 39 | { |
| 41 | - std::cout << obj.getTypeName() << ", offset=" << offset | ||
| 42 | - << ", length=" << length << ": "; | 40 | + std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": "; |
| 43 | if (obj.isInlineImage()) { | 41 | if (obj.isInlineImage()) { |
| 44 | std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl; | 42 | std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl; |
| 45 | } else { | 43 | } else { |
| @@ -67,8 +65,7 @@ main(int argc, char* argv[]) | @@ -67,8 +65,7 @@ main(int argc, char* argv[]) | ||
| 67 | try { | 65 | try { |
| 68 | QPDF pdf; | 66 | QPDF pdf; |
| 69 | pdf.processFile(filename); | 67 | pdf.processFile(filename); |
| 70 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 71 | - QPDFPageDocumentHelper(pdf).getAllPages(); | 68 | + std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(pdf).getAllPages(); |
| 72 | if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size())) { | 69 | if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size())) { |
| 73 | usage(); | 70 | usage(); |
| 74 | } | 71 | } |
examples/pdf-set-form-values.cc
| @@ -11,10 +11,8 @@ static char const* whoami = nullptr; | @@ -11,10 +11,8 @@ static char const* whoami = nullptr; | ||
| 11 | void | 11 | void |
| 12 | usage() | 12 | usage() |
| 13 | { | 13 | { |
| 14 | - std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value" | ||
| 15 | - << std::endl | ||
| 16 | - << "Set the value of all text fields to a specified value" | ||
| 17 | - << std::endl; | 14 | + std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value" << std::endl |
| 15 | + << "Set the value of all text fields to a specified value" << std::endl; | ||
| 18 | exit(2); | 16 | exit(2); |
| 19 | } | 17 | } |
| 20 | 18 | ||
| @@ -55,8 +53,7 @@ main(int argc, char* argv[]) | @@ -55,8 +53,7 @@ main(int argc, char* argv[]) | ||
| 55 | for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) { | 53 | for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) { |
| 56 | // For each annotation, find its associated field. If | 54 | // For each annotation, find its associated field. If |
| 57 | // it's a text field, set its value. | 55 | // it's a text field, set its value. |
| 58 | - QPDFFormFieldObjectHelper ffh = | ||
| 59 | - afdh.getFieldForAnnotation(annot); | 56 | + QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(annot); |
| 60 | if (ffh.getFieldType() == "/Tx") { | 57 | if (ffh.getFieldType() == "/Tx") { |
| 61 | // Set the value. Passing false as the second | 58 | // Set the value. Passing false as the second |
| 62 | // value prevents qpdf from setting | 59 | // value prevents qpdf from setting |
| @@ -79,8 +76,7 @@ main(int argc, char* argv[]) | @@ -79,8 +76,7 @@ main(int argc, char* argv[]) | ||
| 79 | w.setStaticID(true); // for testing only | 76 | w.setStaticID(true); // for testing only |
| 80 | w.write(); | 77 | w.write(); |
| 81 | } catch (std::exception& e) { | 78 | } catch (std::exception& e) { |
| 82 | - std::cerr << whoami << " processing file " << infilename << ": " | ||
| 83 | - << e.what() << std::endl; | 79 | + std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl; |
| 84 | exit(2); | 80 | exit(2); |
| 85 | } | 81 | } |
| 86 | 82 |
examples/pdf-split-pages.cc
| @@ -22,13 +22,11 @@ process(char const* whoami, char const* infile, std::string outprefix) | @@ -22,13 +22,11 @@ process(char const* whoami, char const* infile, std::string outprefix) | ||
| 22 | { | 22 | { |
| 23 | QPDF inpdf; | 23 | QPDF inpdf; |
| 24 | inpdf.processFile(infile); | 24 | inpdf.processFile(infile); |
| 25 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 26 | - QPDFPageDocumentHelper(inpdf).getAllPages(); | 25 | + std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(inpdf).getAllPages(); |
| 27 | int pageno_len = QIntC::to_int(std::to_string(pages.size()).length()); | 26 | int pageno_len = QIntC::to_int(std::to_string(pages.size()).length()); |
| 28 | int pageno = 0; | 27 | int pageno = 0; |
| 29 | for (auto& page: pages) { | 28 | for (auto& page: pages) { |
| 30 | - std::string outfile = | ||
| 31 | - outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf"; | 29 | + std::string outfile = outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf"; |
| 32 | QPDF outpdf; | 30 | QPDF outpdf; |
| 33 | outpdf.emptyPDF(); | 31 | outpdf.emptyPDF(); |
| 34 | QPDFPageDocumentHelper(outpdf).addPage(page, false); | 32 | QPDFPageDocumentHelper(outpdf).addPage(page, false); |
examples/qpdfjob-c-save-attachment.c
| @@ -83,8 +83,7 @@ main(int argc, char* argv[]) | @@ -83,8 +83,7 @@ main(int argc, char* argv[]) | ||
| 83 | * saved data. You can use other qpdf logger functions to capture | 83 | * saved data. You can use other qpdf logger functions to capture |
| 84 | * informational output, warnings, and errors. | 84 | * informational output, warnings, and errors. |
| 85 | */ | 85 | */ |
| 86 | - qpdflogger_set_save( | ||
| 87 | - l, qpdf_log_dest_custom, save_to_file, (void*)outfile, 0); | 86 | + qpdflogger_set_save(l, qpdf_log_dest_custom, save_to_file, (void*)outfile, 0); |
| 88 | qpdflogger_cleanup(&l); | 87 | qpdflogger_cleanup(&l); |
| 89 | j = qpdfjob_init(); | 88 | j = qpdfjob_init(); |
| 90 | status = (qpdfjob_initialize_from_argv(j, j_argv) || qpdfjob_run(j)); | 89 | status = (qpdfjob_initialize_from_argv(j, j_argv) || qpdfjob_run(j)); |
examples/qpdfjob-remove-annotations.cc
| @@ -20,15 +20,10 @@ usageExit(std::string const& msg) | @@ -20,15 +20,10 @@ usageExit(std::string const& msg) | ||
| 20 | << whoami << ": " << msg << std::endl | 20 | << whoami << ": " << msg << std::endl |
| 21 | << std::endl | 21 | << std::endl |
| 22 | << "For help:" << std::endl | 22 | << "For help:" << std::endl |
| 23 | - << " " << whoami << " --help=usage usage information" | ||
| 24 | - << std::endl | ||
| 25 | - << " " << whoami << " --help=topic help on a topic" | ||
| 26 | - << std::endl | ||
| 27 | - << " " << whoami << " --help=--option help on an option" | ||
| 28 | - << std::endl | ||
| 29 | - << " " << whoami | ||
| 30 | - << " --help general help and a topic list" | ||
| 31 | - << std::endl | 23 | + << " " << whoami << " --help=usage usage information" << std::endl |
| 24 | + << " " << whoami << " --help=topic help on a topic" << std::endl | ||
| 25 | + << " " << whoami << " --help=--option help on an option" << std::endl | ||
| 26 | + << " " << whoami << " --help general help and a topic list" << std::endl | ||
| 32 | << std::endl; | 27 | << std::endl; |
| 33 | exit(QPDFJob::EXIT_ERROR); | 28 | exit(QPDFJob::EXIT_ERROR); |
| 34 | } | 29 | } |
examples/qpdfjob-save-attachment.cc
| @@ -14,8 +14,7 @@ main(int argc, char* argv[]) | @@ -14,8 +14,7 @@ main(int argc, char* argv[]) | ||
| 14 | auto whoami = QUtil::getWhoami(argv[0]); | 14 | auto whoami = QUtil::getWhoami(argv[0]); |
| 15 | 15 | ||
| 16 | if (argc != 4) { | 16 | if (argc != 4) { |
| 17 | - std::cerr << "Usage: " << whoami << " file attachment-key outfile" | ||
| 18 | - << std::endl; | 17 | + std::cerr << "Usage: " << whoami << " file attachment-key outfile" << std::endl; |
| 19 | exit(2); | 18 | exit(2); |
| 20 | } | 19 | } |
| 21 | 20 |
fuzz/qpdf_fuzzer.cc
| @@ -53,8 +53,8 @@ FuzzHelper::FuzzHelper(unsigned char const* data, size_t size) : | @@ -53,8 +53,8 @@ FuzzHelper::FuzzHelper(unsigned char const* data, size_t size) : | ||
| 53 | std::shared_ptr<QPDF> | 53 | std::shared_ptr<QPDF> |
| 54 | FuzzHelper::getQpdf() | 54 | FuzzHelper::getQpdf() |
| 55 | { | 55 | { |
| 56 | - auto is = std::shared_ptr<InputSource>( | ||
| 57 | - new BufferInputSource("fuzz input", &this->input_buffer)); | 56 | + auto is = |
| 57 | + std::shared_ptr<InputSource>(new BufferInputSource("fuzz input", &this->input_buffer)); | ||
| 58 | auto qpdf = QPDF::create(); | 58 | auto qpdf = QPDF::create(); |
| 59 | qpdf->processInputSource(is); | 59 | qpdf->processInputSource(is); |
| 60 | return qpdf; | 60 | return qpdf; |
| @@ -99,8 +99,7 @@ FuzzHelper::testWrite() | @@ -99,8 +99,7 @@ FuzzHelper::testWrite() | ||
| 99 | w = getWriter(q); | 99 | w = getWriter(q); |
| 100 | w->setStaticID(true); | 100 | w->setStaticID(true); |
| 101 | w->setLinearization(true); | 101 | w->setLinearization(true); |
| 102 | - w->setR6EncryptionParameters( | ||
| 103 | - "u", "o", true, true, true, true, true, true, qpdf_r3p_full, true); | 102 | + w->setR6EncryptionParameters("u", "o", true, true, true, true, true, true, qpdf_r3p_full, true); |
| 104 | doWrite(w); | 103 | doWrite(w); |
| 105 | 104 | ||
| 106 | q = getQpdf(); | 105 | q = getQpdf(); |
fuzz/standalone_fuzz_target_runner.cc
| @@ -11,8 +11,7 @@ main(int argc, char** argv) | @@ -11,8 +11,7 @@ main(int argc, char** argv) | ||
| 11 | std::shared_ptr<char> file_buf; | 11 | std::shared_ptr<char> file_buf; |
| 12 | size_t size = 0; | 12 | size_t size = 0; |
| 13 | QUtil::read_file_into_memory(argv[i], file_buf, size); | 13 | QUtil::read_file_into_memory(argv[i], file_buf, size); |
| 14 | - LLVMFuzzerTestOneInput( | ||
| 15 | - reinterpret_cast<unsigned char*>(file_buf.get()), size); | 14 | + LLVMFuzzerTestOneInput(reinterpret_cast<unsigned char*>(file_buf.get()), size); |
| 16 | std::cout << argv[i] << " successful" << std::endl; | 15 | std::cout << argv[i] << " successful" << std::endl; |
| 17 | } | 16 | } |
| 18 | return 0; | 17 | return 0; |
fuzz/tiffpredictor_fuzzer.cc
| @@ -26,8 +26,7 @@ void | @@ -26,8 +26,7 @@ void | ||
| 26 | FuzzHelper::doChecks() | 26 | FuzzHelper::doChecks() |
| 27 | { | 27 | { |
| 28 | Pl_Discard discard; | 28 | Pl_Discard discard; |
| 29 | - Pl_TIFFPredictor p( | ||
| 30 | - "decoder", &discard, Pl_TIFFPredictor::a_decode, 16, 1, 8); | 29 | + Pl_TIFFPredictor p("decoder", &discard, Pl_TIFFPredictor::a_decode, 16, 1, 8); |
| 31 | p.write(const_cast<unsigned char*>(data), size); | 30 | p.write(const_cast<unsigned char*>(data), size); |
| 32 | p.finish(); | 31 | p.finish(); |
| 33 | } | 32 | } |
include/qpdf/BufferInputSource.hh
| @@ -31,11 +31,9 @@ class QPDF_DLL_CLASS BufferInputSource: public InputSource | @@ -31,11 +31,9 @@ class QPDF_DLL_CLASS BufferInputSource: public InputSource | ||
| 31 | // If own_memory is true, BufferInputSource will delete the buffer | 31 | // If own_memory is true, BufferInputSource will delete the buffer |
| 32 | // when finished with it. Otherwise, the caller owns the memory. | 32 | // when finished with it. Otherwise, the caller owns the memory. |
| 33 | QPDF_DLL | 33 | QPDF_DLL |
| 34 | - BufferInputSource( | ||
| 35 | - std::string const& description, Buffer* buf, bool own_memory = false); | 34 | + BufferInputSource(std::string const& description, Buffer* buf, bool own_memory = false); |
| 36 | QPDF_DLL | 35 | QPDF_DLL |
| 37 | - BufferInputSource( | ||
| 38 | - std::string const& description, std::string const& contents); | 36 | + BufferInputSource(std::string const& description, std::string const& contents); |
| 39 | QPDF_DLL | 37 | QPDF_DLL |
| 40 | virtual ~BufferInputSource(); | 38 | virtual ~BufferInputSource(); |
| 41 | QPDF_DLL | 39 | QPDF_DLL |
include/qpdf/Constants.h
| @@ -230,9 +230,6 @@ enum pdf_annotation_flag_e { | @@ -230,9 +230,6 @@ enum pdf_annotation_flag_e { | ||
| 230 | }; | 230 | }; |
| 231 | 231 | ||
| 232 | /* Encryption/password status for QPDFJob */ | 232 | /* Encryption/password status for QPDFJob */ |
| 233 | -enum qpdf_encryption_status_e { | ||
| 234 | - qpdf_es_encrypted = 1 << 0, | ||
| 235 | - qpdf_es_password_incorrect = 1 << 1 | ||
| 236 | -}; | 233 | +enum qpdf_encryption_status_e { qpdf_es_encrypted = 1 << 0, qpdf_es_password_incorrect = 1 << 1 }; |
| 237 | 234 | ||
| 238 | #endif /* QPDFCONSTANTS_H */ | 235 | #endif /* QPDFCONSTANTS_H */ |
include/qpdf/InputSource.hh
| @@ -69,17 +69,9 @@ class QPDF_DLL_CLASS InputSource | @@ -69,17 +69,9 @@ class QPDF_DLL_CLASS InputSource | ||
| 69 | // methods return true and leave the input source positioned | 69 | // methods return true and leave the input source positioned |
| 70 | // wherever check() left it at the end of the matching pattern. | 70 | // wherever check() left it at the end of the matching pattern. |
| 71 | QPDF_DLL | 71 | QPDF_DLL |
| 72 | - bool findFirst( | ||
| 73 | - char const* start_chars, | ||
| 74 | - qpdf_offset_t offset, | ||
| 75 | - size_t len, | ||
| 76 | - Finder& finder); | 72 | + bool findFirst(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder); |
| 77 | QPDF_DLL | 73 | QPDF_DLL |
| 78 | - bool findLast( | ||
| 79 | - char const* start_chars, | ||
| 80 | - qpdf_offset_t offset, | ||
| 81 | - size_t len, | ||
| 82 | - Finder& finder); | 74 | + bool findLast(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder); |
| 83 | 75 | ||
| 84 | virtual qpdf_offset_t findAndSkipNextEOL() = 0; | 76 | virtual qpdf_offset_t findAndSkipNextEOL() = 0; |
| 85 | virtual std::string const& getName() const = 0; | 77 | virtual std::string const& getName() const = 0; |
| @@ -144,8 +136,7 @@ InputSource::fastTell() | @@ -144,8 +136,7 @@ InputSource::fastTell() | ||
| 144 | loadBuffer(); | 136 | loadBuffer(); |
| 145 | } else { | 137 | } else { |
| 146 | auto curr = tell(); | 138 | auto curr = tell(); |
| 147 | - if (curr < this->buf_start || | ||
| 148 | - curr >= (this->buf_start + this->buf_len)) { | 139 | + if (curr < this->buf_start || curr >= (this->buf_start + this->buf_len)) { |
| 149 | loadBuffer(); | 140 | loadBuffer(); |
| 150 | } else { | 141 | } else { |
| 151 | this->last_offset = curr; | 142 | this->last_offset = curr; |
include/qpdf/JSON.hh
| @@ -104,19 +104,14 @@ class JSON | @@ -104,19 +104,14 @@ class JSON | ||
| 104 | // the first item and always set it to false. | 104 | // the first item and always set it to false. |
| 105 | QPDF_DLL | 105 | QPDF_DLL |
| 106 | static void writeDictionaryItem( | 106 | static void writeDictionaryItem( |
| 107 | - Pipeline*, | ||
| 108 | - bool& first, | ||
| 109 | - std::string const& key, | ||
| 110 | - JSON const& value, | ||
| 111 | - size_t depth = 0); | 107 | + Pipeline*, bool& first, std::string const& key, JSON const& value, size_t depth = 0); |
| 112 | // Write just the key of a new dictionary item, useful if writing | 108 | // Write just the key of a new dictionary item, useful if writing |
| 113 | // nested structures. Calls writeNext. | 109 | // nested structures. Calls writeNext. |
| 114 | QPDF_DLL | 110 | QPDF_DLL |
| 115 | - static void writeDictionaryKey( | ||
| 116 | - Pipeline* p, bool& first, std::string const& key, size_t depth = 0); | 111 | + static void |
| 112 | + writeDictionaryKey(Pipeline* p, bool& first, std::string const& key, size_t depth = 0); | ||
| 117 | QPDF_DLL | 113 | QPDF_DLL |
| 118 | - static void writeArrayItem( | ||
| 119 | - Pipeline*, bool& first, JSON const& element, size_t depth = 0); | 114 | + static void writeArrayItem(Pipeline*, bool& first, JSON const& element, size_t depth = 0); |
| 120 | // If writing nested structures incrementally, call writeNext | 115 | // If writing nested structures incrementally, call writeNext |
| 121 | // before opening a new array or container in the midst of an | 116 | // before opening a new array or container in the midst of an |
| 122 | // existing one. The `first` you pass to writeNext should be the | 117 | // existing one. The `first` you pass to writeNext should be the |
| @@ -188,8 +183,7 @@ class JSON | @@ -188,8 +183,7 @@ class JSON | ||
| 188 | QPDF_DLL | 183 | QPDF_DLL |
| 189 | bool isNull() const; | 184 | bool isNull() const; |
| 190 | QPDF_DLL | 185 | QPDF_DLL |
| 191 | - bool forEachDictItem( | ||
| 192 | - std::function<void(std::string const& key, JSON value)> fn) const; | 186 | + bool forEachDictItem(std::function<void(std::string const& key, JSON value)> fn) const; |
| 193 | QPDF_DLL | 187 | QPDF_DLL |
| 194 | bool forEachArrayItem(std::function<void(JSON value)> fn) const; | 188 | bool forEachArrayItem(std::function<void(JSON value)> fn) const; |
| 195 | 189 | ||
| @@ -239,8 +233,7 @@ class JSON | @@ -239,8 +233,7 @@ class JSON | ||
| 239 | f_optional = 1 << 0, | 233 | f_optional = 1 << 0, |
| 240 | }; | 234 | }; |
| 241 | QPDF_DLL | 235 | QPDF_DLL |
| 242 | - bool checkSchema( | ||
| 243 | - JSON schema, unsigned long flags, std::list<std::string>& errors); | 236 | + bool checkSchema(JSON schema, unsigned long flags, std::list<std::string>& errors); |
| 244 | 237 | ||
| 245 | // Same as passing 0 for flags | 238 | // Same as passing 0 for flags |
| 246 | QPDF_DLL | 239 | QPDF_DLL |
| @@ -311,8 +304,7 @@ class JSON | @@ -311,8 +304,7 @@ class JSON | ||
| 311 | // methods and decrementing on end methods. | 304 | // methods and decrementing on end methods. |
| 312 | 305 | ||
| 313 | QPDF_DLL | 306 | QPDF_DLL |
| 314 | - virtual bool | ||
| 315 | - dictionaryItem(std::string const& key, JSON const& value) = 0; | 307 | + virtual bool dictionaryItem(std::string const& key, JSON const& value) = 0; |
| 316 | QPDF_DLL | 308 | QPDF_DLL |
| 317 | virtual bool arrayItem(JSON const& value) = 0; | 309 | virtual bool arrayItem(JSON const& value) = 0; |
| 318 | }; | 310 | }; |
| @@ -339,8 +331,7 @@ class JSON | @@ -339,8 +331,7 @@ class JSON | ||
| 339 | 331 | ||
| 340 | private: | 332 | private: |
| 341 | static std::string encode_string(std::string const& utf8); | 333 | static std::string encode_string(std::string const& utf8); |
| 342 | - static void | ||
| 343 | - writeClose(Pipeline* p, bool first, size_t depth, char const* delimeter); | 334 | + static void writeClose(Pipeline* p, bool first, size_t depth, char const* delimeter); |
| 344 | 335 | ||
| 345 | enum value_type_e { | 336 | enum value_type_e { |
| 346 | vt_none, | 337 | vt_none, |
include/qpdf/Pl_Function.hh
| @@ -54,15 +54,10 @@ class QPDF_DLL_CLASS Pl_Function: public Pipeline | @@ -54,15 +54,10 @@ class QPDF_DLL_CLASS Pl_Function: public Pipeline | ||
| 54 | // is thrown. | 54 | // is thrown. |
| 55 | typedef int (*writer_c_t)(unsigned char const*, size_t, void*); | 55 | typedef int (*writer_c_t)(unsigned char const*, size_t, void*); |
| 56 | QPDF_DLL | 56 | QPDF_DLL |
| 57 | - Pl_Function( | ||
| 58 | - char const* identifier, Pipeline* next, writer_c_t fn, void* udata); | 57 | + Pl_Function(char const* identifier, Pipeline* next, writer_c_t fn, void* udata); |
| 59 | typedef int (*writer_c_char_t)(char const*, size_t, void*); | 58 | typedef int (*writer_c_char_t)(char const*, size_t, void*); |
| 60 | QPDF_DLL | 59 | QPDF_DLL |
| 61 | - Pl_Function( | ||
| 62 | - char const* identifier, | ||
| 63 | - Pipeline* next, | ||
| 64 | - writer_c_char_t fn, | ||
| 65 | - void* udata); | 60 | + Pl_Function(char const* identifier, Pipeline* next, writer_c_char_t fn, void* udata); |
| 66 | 61 | ||
| 67 | QPDF_DLL | 62 | QPDF_DLL |
| 68 | virtual ~Pl_Function(); | 63 | virtual ~Pl_Function(); |
include/qpdf/Pl_QPDFTokenizer.hh
| @@ -49,9 +49,7 @@ class QPDF_DLL_CLASS Pl_QPDFTokenizer: public Pipeline | @@ -49,9 +49,7 @@ class QPDF_DLL_CLASS Pl_QPDFTokenizer: public Pipeline | ||
| 49 | // provided, any output written by the filter will be discarded. | 49 | // provided, any output written by the filter will be discarded. |
| 50 | QPDF_DLL | 50 | QPDF_DLL |
| 51 | Pl_QPDFTokenizer( | 51 | Pl_QPDFTokenizer( |
| 52 | - char const* identifier, | ||
| 53 | - QPDFObjectHandle::TokenFilter* filter, | ||
| 54 | - Pipeline* next = nullptr); | 52 | + char const* identifier, QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr); |
| 55 | QPDF_DLL | 53 | QPDF_DLL |
| 56 | virtual ~Pl_QPDFTokenizer(); | 54 | virtual ~Pl_QPDFTokenizer(); |
| 57 | QPDF_DLL | 55 | QPDF_DLL |
include/qpdf/QIntC.hh
| @@ -78,9 +78,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion | @@ -78,9 +78,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion | ||
| 78 | { | 78 | { |
| 79 | std::ostringstream msg; | 79 | std::ostringstream msg; |
| 80 | msg.imbue(std::locale::classic()); | 80 | msg.imbue(std::locale::classic()); |
| 81 | - msg << "integer out of range converting " << i << " from a " | ||
| 82 | - << sizeof(From) << "-byte unsigned type to a " << sizeof(To) | ||
| 83 | - << "-byte unsigned type"; | 81 | + msg << "integer out of range converting " << i << " from a " << sizeof(From) |
| 82 | + << "-byte unsigned type to a " << sizeof(To) << "-byte unsigned type"; | ||
| 84 | throw std::range_error(msg.str()); | 83 | throw std::range_error(msg.str()); |
| 85 | } | 84 | } |
| 86 | }; | 85 | }; |
| @@ -93,8 +92,7 @@ namespace QIntC // QIntC = qpdf Integer Conversion | @@ -93,8 +92,7 @@ namespace QIntC // QIntC = qpdf Integer Conversion | ||
| 93 | convert(From const& i) | 92 | convert(From const& i) |
| 94 | { | 93 | { |
| 95 | // From and To are both signed. | 94 | // From and To are both signed. |
| 96 | - if ((i < std::numeric_limits<To>::min()) || | ||
| 97 | - (i > std::numeric_limits<To>::max())) { | 95 | + if ((i < std::numeric_limits<To>::min()) || (i > std::numeric_limits<To>::max())) { |
| 98 | error(i); | 96 | error(i); |
| 99 | } | 97 | } |
| 100 | return static_cast<To>(i); | 98 | return static_cast<To>(i); |
| @@ -105,9 +103,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion | @@ -105,9 +103,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion | ||
| 105 | { | 103 | { |
| 106 | std::ostringstream msg; | 104 | std::ostringstream msg; |
| 107 | msg.imbue(std::locale::classic()); | 105 | msg.imbue(std::locale::classic()); |
| 108 | - msg << "integer out of range converting " << i << " from a " | ||
| 109 | - << sizeof(From) << "-byte signed type to a " << sizeof(To) | ||
| 110 | - << "-byte signed type"; | 106 | + msg << "integer out of range converting " << i << " from a " << sizeof(From) |
| 107 | + << "-byte signed type to a " << sizeof(To) << "-byte signed type"; | ||
| 111 | throw std::range_error(msg.str()); | 108 | throw std::range_error(msg.str()); |
| 112 | } | 109 | } |
| 113 | }; | 110 | }; |
| @@ -134,9 +131,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion | @@ -134,9 +131,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion | ||
| 134 | { | 131 | { |
| 135 | std::ostringstream msg; | 132 | std::ostringstream msg; |
| 136 | msg.imbue(std::locale::classic()); | 133 | msg.imbue(std::locale::classic()); |
| 137 | - msg << "integer out of range converting " << i << " from a " | ||
| 138 | - << sizeof(From) << "-byte signed type to a " << sizeof(To) | ||
| 139 | - << "-byte unsigned type"; | 134 | + msg << "integer out of range converting " << i << " from a " << sizeof(From) |
| 135 | + << "-byte signed type to a " << sizeof(To) << "-byte unsigned type"; | ||
| 140 | throw std::range_error(msg.str()); | 136 | throw std::range_error(msg.str()); |
| 141 | } | 137 | } |
| 142 | }; | 138 | }; |
| @@ -150,8 +146,7 @@ namespace QIntC // QIntC = qpdf Integer Conversion | @@ -150,8 +146,7 @@ namespace QIntC // QIntC = qpdf Integer Conversion | ||
| 150 | { | 146 | { |
| 151 | // From is unsigned, and to is signed. Convert To's max to the | 147 | // From is unsigned, and to is signed. Convert To's max to the |
| 152 | // unsigned version of To and compare i against that. | 148 | // unsigned version of To and compare i against that. |
| 153 | - auto maxval = static_cast<typename to_u<To>::type>( | ||
| 154 | - std::numeric_limits<To>::max()); | 149 | + auto maxval = static_cast<typename to_u<To>::type>(std::numeric_limits<To>::max()); |
| 155 | if (i > maxval) { | 150 | if (i > maxval) { |
| 156 | error(i); | 151 | error(i); |
| 157 | } | 152 | } |
| @@ -163,9 +158,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion | @@ -163,9 +158,8 @@ namespace QIntC // QIntC = qpdf Integer Conversion | ||
| 163 | { | 158 | { |
| 164 | std::ostringstream msg; | 159 | std::ostringstream msg; |
| 165 | msg.imbue(std::locale::classic()); | 160 | msg.imbue(std::locale::classic()); |
| 166 | - msg << "integer out of range converting " << i << " from a " | ||
| 167 | - << sizeof(From) << "-byte unsigned type to a " << sizeof(To) | ||
| 168 | - << "-byte signed type"; | 161 | + msg << "integer out of range converting " << i << " from a " << sizeof(From) |
| 162 | + << "-byte unsigned type to a " << sizeof(To) << "-byte signed type"; | ||
| 169 | throw std::range_error(msg.str()); | 163 | throw std::range_error(msg.str()); |
| 170 | } | 164 | } |
| 171 | }; | 165 | }; |
| @@ -263,15 +257,12 @@ namespace QIntC // QIntC = qpdf Integer Conversion | @@ -263,15 +257,12 @@ namespace QIntC // QIntC = qpdf Integer Conversion | ||
| 263 | if ((delta > 0) && ((std::numeric_limits<T>::max() - cur) < delta)) { | 257 | if ((delta > 0) && ((std::numeric_limits<T>::max() - cur) < delta)) { |
| 264 | std::ostringstream msg; | 258 | std::ostringstream msg; |
| 265 | msg.imbue(std::locale::classic()); | 259 | msg.imbue(std::locale::classic()); |
| 266 | - msg << "adding " << delta << " to " << cur | ||
| 267 | - << " would cause an integer overflow"; | 260 | + msg << "adding " << delta << " to " << cur << " would cause an integer overflow"; |
| 268 | throw std::range_error(msg.str()); | 261 | throw std::range_error(msg.str()); |
| 269 | - } else if ( | ||
| 270 | - (delta < 0) && ((std::numeric_limits<T>::min() - cur) > delta)) { | 262 | + } else if ((delta < 0) && ((std::numeric_limits<T>::min() - cur) > delta)) { |
| 271 | std::ostringstream msg; | 263 | std::ostringstream msg; |
| 272 | msg.imbue(std::locale::classic()); | 264 | msg.imbue(std::locale::classic()); |
| 273 | - msg << "adding " << delta << " to " << cur | ||
| 274 | - << " would cause an integer underflow"; | 265 | + msg << "adding " << delta << " to " << cur << " would cause an integer underflow"; |
| 275 | throw std::range_error(msg.str()); | 266 | throw std::range_error(msg.str()); |
| 276 | } | 267 | } |
| 277 | } | 268 | } |
| @@ -296,12 +287,10 @@ namespace QIntC // QIntC = qpdf Integer Conversion | @@ -296,12 +287,10 @@ namespace QIntC // QIntC = qpdf Integer Conversion | ||
| 296 | msg << "subtracting " << delta << " from " << cur | 287 | msg << "subtracting " << delta << " from " << cur |
| 297 | << " would cause an integer underflow"; | 288 | << " would cause an integer underflow"; |
| 298 | throw std::range_error(msg.str()); | 289 | throw std::range_error(msg.str()); |
| 299 | - } else if ( | ||
| 300 | - (delta < 0) && ((std::numeric_limits<T>::max() + delta) < cur)) { | 290 | + } else if ((delta < 0) && ((std::numeric_limits<T>::max() + delta) < cur)) { |
| 301 | std::ostringstream msg; | 291 | std::ostringstream msg; |
| 302 | msg.imbue(std::locale::classic()); | 292 | msg.imbue(std::locale::classic()); |
| 303 | - msg << "subtracting " << delta << " from " << cur | ||
| 304 | - << " would cause an integer overflow"; | 293 | + msg << "subtracting " << delta << " from " << cur << " would cause an integer overflow"; |
| 305 | throw std::range_error(msg.str()); | 294 | throw std::range_error(msg.str()); |
| 306 | } | 295 | } |
| 307 | } | 296 | } |
include/qpdf/QPDF.hh
| @@ -93,10 +93,7 @@ class QPDF | @@ -93,10 +93,7 @@ class QPDF | ||
| 93 | // responsible for closing the file. | 93 | // responsible for closing the file. |
| 94 | QPDF_DLL | 94 | QPDF_DLL |
| 95 | void processFile( | 95 | void processFile( |
| 96 | - char const* description, | ||
| 97 | - FILE* file, | ||
| 98 | - bool close_file, | ||
| 99 | - char const* password = nullptr); | 96 | + char const* description, FILE* file, bool close_file, char const* password = nullptr); |
| 100 | 97 | ||
| 101 | // Parse a PDF file loaded into a memory buffer. This works | 98 | // Parse a PDF file loaded into a memory buffer. This works |
| 102 | // exactly like processFile except that the PDF file is in memory | 99 | // exactly like processFile except that the PDF file is in memory |
| @@ -104,17 +101,13 @@ class QPDF | @@ -104,17 +101,13 @@ class QPDF | ||
| 104 | // error message in place of the file name. | 101 | // error message in place of the file name. |
| 105 | QPDF_DLL | 102 | QPDF_DLL |
| 106 | void processMemoryFile( | 103 | void processMemoryFile( |
| 107 | - char const* description, | ||
| 108 | - char const* buf, | ||
| 109 | - size_t length, | ||
| 110 | - char const* password = nullptr); | 104 | + char const* description, char const* buf, size_t length, char const* password = nullptr); |
| 111 | 105 | ||
| 112 | // Parse a PDF file loaded from a custom InputSource. If you have | 106 | // Parse a PDF file loaded from a custom InputSource. If you have |
| 113 | // your own method of retrieving a PDF file, you can subclass | 107 | // your own method of retrieving a PDF file, you can subclass |
| 114 | // InputSource and use this method. | 108 | // InputSource and use this method. |
| 115 | QPDF_DLL | 109 | QPDF_DLL |
| 116 | - void processInputSource( | ||
| 117 | - std::shared_ptr<InputSource>, char const* password = nullptr); | 110 | + void processInputSource(std::shared_ptr<InputSource>, char const* password = nullptr); |
| 118 | 111 | ||
| 119 | // Create a PDF from an input source that contains JSON as written | 112 | // Create a PDF from an input source that contains JSON as written |
| 120 | // by writeJSON (or qpdf --json-output, version 2 or higher). The | 113 | // by writeJSON (or qpdf --json-output, version 2 or higher). The |
| @@ -234,8 +227,7 @@ class QPDF | @@ -234,8 +227,7 @@ class QPDF | ||
| 234 | // QPDFStreamFilter classes. | 227 | // QPDFStreamFilter classes. |
| 235 | QPDF_DLL | 228 | QPDF_DLL |
| 236 | static void registerStreamFilter( | 229 | static void registerStreamFilter( |
| 237 | - std::string const& filter_name, | ||
| 238 | - std::function<std::shared_ptr<QPDFStreamFilter>()> factory); | 230 | + std::string const& filter_name, std::function<std::shared_ptr<QPDFStreamFilter>()> factory); |
| 239 | 231 | ||
| 240 | // Parameter settings | 232 | // Parameter settings |
| 241 | 233 | ||
| @@ -260,8 +252,7 @@ class QPDF | @@ -260,8 +252,7 @@ class QPDF | ||
| 260 | // configures a private logger, separating this object from the | 252 | // configures a private logger, separating this object from the |
| 261 | // default logger, and calls setOutputStreams on that logger. See | 253 | // default logger, and calls setOutputStreams on that logger. See |
| 262 | // QPDFLogger.hh for additional details. | 254 | // QPDFLogger.hh for additional details. |
| 263 | - [[deprecated( | ||
| 264 | - "configure logger from getLogger() or call setLogger()")]] QPDF_DLL void | 255 | + [[deprecated("configure logger from getLogger() or call setLogger()")]] QPDF_DLL void |
| 265 | setOutputStreams(std::ostream* out_stream, std::ostream* err_stream); | 256 | setOutputStreams(std::ostream* out_stream, std::ostream* err_stream); |
| 266 | 257 | ||
| 267 | // If true, ignore any cross-reference streams in a hybrid file | 258 | // If true, ignore any cross-reference streams in a hybrid file |
| @@ -481,8 +472,7 @@ class QPDF | @@ -481,8 +472,7 @@ class QPDF | ||
| 481 | // reserved object. After this call, reserved will be a reference | 472 | // reserved object. After this call, reserved will be a reference |
| 482 | // to replacement. | 473 | // to replacement. |
| 483 | QPDF_DLL | 474 | QPDF_DLL |
| 484 | - void | ||
| 485 | - replaceReserved(QPDFObjectHandle reserved, QPDFObjectHandle replacement); | 475 | + void replaceReserved(QPDFObjectHandle reserved, QPDFObjectHandle replacement); |
| 486 | 476 | ||
| 487 | // Copy an object from another QPDF to this one. Starting with | 477 | // Copy an object from another QPDF to this one. Starting with |
| 488 | // qpdf version 8.3.0, it is no longer necessary to keep the | 478 | // qpdf version 8.3.0, it is no longer necessary to keep the |
| @@ -657,8 +647,8 @@ class QPDF | @@ -657,8 +647,8 @@ class QPDF | ||
| 657 | int encryption_V, | 647 | int encryption_V, |
| 658 | int encryption_R); | 648 | int encryption_R); |
| 659 | QPDF_DLL | 649 | QPDF_DLL |
| 660 | - static std::string compute_encryption_key( | ||
| 661 | - std::string const& password, EncryptionData const& data); | 650 | + static std::string |
| 651 | + compute_encryption_key(std::string const& password, EncryptionData const& data); | ||
| 662 | 652 | ||
| 663 | QPDF_DLL | 653 | QPDF_DLL |
| 664 | static void compute_encryption_O_U( | 654 | static void compute_encryption_O_U( |
| @@ -843,8 +833,7 @@ class QPDF | @@ -843,8 +833,7 @@ class QPDF | ||
| 843 | QPDF_DLL | 833 | QPDF_DLL |
| 844 | void addPage(QPDFObjectHandle newpage, bool first); | 834 | void addPage(QPDFObjectHandle newpage, bool first); |
| 845 | QPDF_DLL | 835 | QPDF_DLL |
| 846 | - void | ||
| 847 | - addPageAt(QPDFObjectHandle newpage, bool before, QPDFObjectHandle refpage); | 836 | + void addPageAt(QPDFObjectHandle newpage, bool before, QPDFObjectHandle refpage); |
| 848 | QPDF_DLL | 837 | QPDF_DLL |
| 849 | void removePage(QPDFObjectHandle page); | 838 | void removePage(QPDFObjectHandle page); |
| 850 | // End legacy page helpers | 839 | // End legacy page helpers |
| @@ -866,8 +855,7 @@ class QPDF | @@ -866,8 +855,7 @@ class QPDF | ||
| 866 | std::vector<QPDFObjectHandle>& part8, | 855 | std::vector<QPDFObjectHandle>& part8, |
| 867 | std::vector<QPDFObjectHandle>& part9) | 856 | std::vector<QPDFObjectHandle>& part9) |
| 868 | { | 857 | { |
| 869 | - qpdf.getLinearizedParts( | ||
| 870 | - object_stream_data, part4, part6, part7, part8, part9); | 858 | + qpdf.getLinearizedParts(object_stream_data, part4, part6, part7, part8, part9); |
| 871 | } | 859 | } |
| 872 | 860 | ||
| 873 | static void | 861 | static void |
| @@ -880,8 +868,7 @@ class QPDF | @@ -880,8 +868,7 @@ class QPDF | ||
| 880 | int& S, | 868 | int& S, |
| 881 | int& O) | 869 | int& O) |
| 882 | { | 870 | { |
| 883 | - return qpdf.generateHintStream( | ||
| 884 | - xref, lengths, obj_renumber, hint_stream, S, O); | 871 | + return qpdf.generateHintStream(xref, lengths, obj_renumber, hint_stream, S, O); |
| 885 | } | 872 | } |
| 886 | 873 | ||
| 887 | static void | 874 | static void |
| @@ -919,10 +906,7 @@ class QPDF | @@ -919,10 +906,7 @@ class QPDF | ||
| 919 | 906 | ||
| 920 | private: | 907 | private: |
| 921 | static void | 908 | static void |
| 922 | - copyStreamData( | ||
| 923 | - QPDF* qpdf, | ||
| 924 | - QPDFObjectHandle const& dest, | ||
| 925 | - QPDFObjectHandle const& src) | 909 | + copyStreamData(QPDF* qpdf, QPDFObjectHandle const& dest, QPDFObjectHandle const& src) |
| 926 | { | 910 | { |
| 927 | qpdf->copyStreamData(dest, src); | 911 | qpdf->copyStreamData(dest, src); |
| 928 | } | 912 | } |
| @@ -968,13 +952,7 @@ class QPDF | @@ -968,13 +952,7 @@ class QPDF | ||
| 968 | bool will_retry) | 952 | bool will_retry) |
| 969 | { | 953 | { |
| 970 | return qpdf->pipeStreamData( | 954 | return qpdf->pipeStreamData( |
| 971 | - og, | ||
| 972 | - offset, | ||
| 973 | - length, | ||
| 974 | - dict, | ||
| 975 | - pipeline, | ||
| 976 | - suppress_warnings, | ||
| 977 | - will_retry); | 955 | + og, offset, length, dict, pipeline, suppress_warnings, will_retry); |
| 978 | } | 956 | } |
| 979 | }; | 957 | }; |
| 980 | 958 | ||
| @@ -1096,16 +1074,13 @@ class QPDF | @@ -1096,16 +1074,13 @@ class QPDF | ||
| 1096 | Pipeline* pipeline, | 1074 | Pipeline* pipeline, |
| 1097 | bool suppress_warnings, | 1075 | bool suppress_warnings, |
| 1098 | bool will_retry) override; | 1076 | bool will_retry) override; |
| 1099 | - void registerForeignStream( | ||
| 1100 | - QPDFObjGen const& local_og, QPDFObjectHandle foreign_stream); | ||
| 1101 | - void registerForeignStream( | ||
| 1102 | - QPDFObjGen const& local_og, std::shared_ptr<ForeignStreamData>); | 1077 | + void registerForeignStream(QPDFObjGen const& local_og, QPDFObjectHandle foreign_stream); |
| 1078 | + void registerForeignStream(QPDFObjGen const& local_og, std::shared_ptr<ForeignStreamData>); | ||
| 1103 | 1079 | ||
| 1104 | private: | 1080 | private: |
| 1105 | QPDF& destination_qpdf; | 1081 | QPDF& destination_qpdf; |
| 1106 | std::map<QPDFObjGen, QPDFObjectHandle> foreign_streams; | 1082 | std::map<QPDFObjGen, QPDFObjectHandle> foreign_streams; |
| 1107 | - std::map<QPDFObjGen, std::shared_ptr<ForeignStreamData>> | ||
| 1108 | - foreign_stream_data; | 1083 | + std::map<QPDFObjGen, std::shared_ptr<ForeignStreamData>> foreign_stream_data; |
| 1109 | }; | 1084 | }; |
| 1110 | 1085 | ||
| 1111 | class StringDecrypter: public QPDFObjectHandle::StringDecrypter | 1086 | class StringDecrypter: public QPDFObjectHandle::StringDecrypter |
| @@ -1148,29 +1123,21 @@ class QPDF | @@ -1148,29 +1123,21 @@ class QPDF | ||
| 1148 | void read_xref(qpdf_offset_t offset); | 1123 | void read_xref(qpdf_offset_t offset); |
| 1149 | bool resolveXRefTable(); | 1124 | bool resolveXRefTable(); |
| 1150 | void reconstruct_xref(QPDFExc& e); | 1125 | void reconstruct_xref(QPDFExc& e); |
| 1151 | - bool | ||
| 1152 | - parse_xrefFirst(std::string const& line, int& obj, int& num, int& bytes); | ||
| 1153 | - bool parse_xrefEntry( | ||
| 1154 | - std::string const& line, qpdf_offset_t& f1, int& f2, char& type); | 1126 | + bool parse_xrefFirst(std::string const& line, int& obj, int& num, int& bytes); |
| 1127 | + bool parse_xrefEntry(std::string const& line, qpdf_offset_t& f1, int& f2, char& type); | ||
| 1155 | qpdf_offset_t read_xrefTable(qpdf_offset_t offset); | 1128 | qpdf_offset_t read_xrefTable(qpdf_offset_t offset); |
| 1156 | qpdf_offset_t read_xrefStream(qpdf_offset_t offset); | 1129 | qpdf_offset_t read_xrefStream(qpdf_offset_t offset); |
| 1157 | - qpdf_offset_t | ||
| 1158 | - processXRefStream(qpdf_offset_t offset, QPDFObjectHandle& xref_stream); | ||
| 1159 | - void insertXrefEntry( | ||
| 1160 | - int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite = false); | ||
| 1161 | - void setLastObjectDescription( | ||
| 1162 | - std::string const& description, QPDFObjGen const& og); | 1130 | + qpdf_offset_t processXRefStream(qpdf_offset_t offset, QPDFObjectHandle& xref_stream); |
| 1131 | + void insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite = false); | ||
| 1132 | + void setLastObjectDescription(std::string const& description, QPDFObjGen const& og); | ||
| 1163 | QPDFObjectHandle readObject( | 1133 | QPDFObjectHandle readObject( |
| 1164 | std::shared_ptr<InputSource>, | 1134 | std::shared_ptr<InputSource>, |
| 1165 | std::string const& description, | 1135 | std::string const& description, |
| 1166 | QPDFObjGen const& og, | 1136 | QPDFObjGen const& og, |
| 1167 | bool in_object_stream); | 1137 | bool in_object_stream); |
| 1168 | size_t recoverStreamLength( | 1138 | size_t recoverStreamLength( |
| 1169 | - std::shared_ptr<InputSource> input, | ||
| 1170 | - QPDFObjGen const& og, | ||
| 1171 | - qpdf_offset_t stream_offset); | ||
| 1172 | - QPDFTokenizer::Token | ||
| 1173 | - readToken(std::shared_ptr<InputSource>, size_t max_len = 0); | 1139 | + std::shared_ptr<InputSource> input, QPDFObjGen const& og, qpdf_offset_t stream_offset); |
| 1140 | + QPDFTokenizer::Token readToken(std::shared_ptr<InputSource>, size_t max_len = 0); | ||
| 1174 | 1141 | ||
| 1175 | QPDFObjectHandle readObjectAtOffset( | 1142 | QPDFObjectHandle readObjectAtOffset( |
| 1176 | bool attempt_recovery, | 1143 | bool attempt_recovery, |
| @@ -1185,10 +1152,8 @@ class QPDF | @@ -1185,10 +1152,8 @@ class QPDF | ||
| 1185 | QPDFObjectHandle reserveObjectIfNotExists(QPDFObjGen const& og); | 1152 | QPDFObjectHandle reserveObjectIfNotExists(QPDFObjGen const& og); |
| 1186 | QPDFObjectHandle reserveStream(QPDFObjGen const& og); | 1153 | QPDFObjectHandle reserveStream(QPDFObjGen const& og); |
| 1187 | QPDFObjGen nextObjGen(); | 1154 | QPDFObjGen nextObjGen(); |
| 1188 | - QPDFObjectHandle | ||
| 1189 | - newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&); | ||
| 1190 | - QPDFObjectHandle | ||
| 1191 | - makeIndirectFromQPDFObject(std::shared_ptr<QPDFObject> const& obj); | 1155 | + QPDFObjectHandle newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&); |
| 1156 | + QPDFObjectHandle makeIndirectFromQPDFObject(std::shared_ptr<QPDFObject> const& obj); | ||
| 1192 | bool isCached(QPDFObjGen const& og); | 1157 | bool isCached(QPDFObjGen const& og); |
| 1193 | bool isUnresolved(QPDFObjGen const& og); | 1158 | bool isUnresolved(QPDFObjGen const& og); |
| 1194 | void updateCache( | 1159 | void updateCache( |
| @@ -1205,10 +1170,7 @@ class QPDF | @@ -1205,10 +1170,7 @@ class QPDF | ||
| 1205 | std::shared_ptr<InputSource> const& input, | 1170 | std::shared_ptr<InputSource> const& input, |
| 1206 | qpdf_offset_t offset, | 1171 | qpdf_offset_t offset, |
| 1207 | std::string const& message); | 1172 | std::string const& message); |
| 1208 | - QPDFExc damagedPDF( | ||
| 1209 | - std::string const& object, | ||
| 1210 | - qpdf_offset_t offset, | ||
| 1211 | - std::string const& message); | 1173 | + QPDFExc damagedPDF(std::string const& object, qpdf_offset_t offset, std::string const& message); |
| 1212 | QPDFExc damagedPDF(std::string const& object, std::string const& message); | 1174 | QPDFExc damagedPDF(std::string const& object, std::string const& message); |
| 1213 | QPDFExc damagedPDF(qpdf_offset_t offset, std::string const& message); | 1175 | QPDFExc damagedPDF(qpdf_offset_t offset, std::string const& message); |
| 1214 | QPDFExc damagedPDF(std::string const& message); | 1176 | QPDFExc damagedPDF(std::string const& message); |
| @@ -1223,10 +1185,7 @@ class QPDF | @@ -1223,10 +1185,7 @@ class QPDF | ||
| 1223 | bool suppress_warnings, | 1185 | bool suppress_warnings, |
| 1224 | bool will_retry); | 1186 | bool will_retry); |
| 1225 | bool pipeForeignStreamData( | 1187 | bool pipeForeignStreamData( |
| 1226 | - std::shared_ptr<ForeignStreamData>, | ||
| 1227 | - Pipeline*, | ||
| 1228 | - bool suppress_warnings, | ||
| 1229 | - bool will_retry); | 1188 | + std::shared_ptr<ForeignStreamData>, Pipeline*, bool suppress_warnings, bool will_retry); |
| 1230 | static bool pipeStreamData( | 1189 | static bool pipeStreamData( |
| 1231 | std::shared_ptr<QPDF::EncryptionParameters> encp, | 1190 | std::shared_ptr<QPDF::EncryptionParameters> encp, |
| 1232 | std::shared_ptr<InputSource> file, | 1191 | std::shared_ptr<InputSource> file, |
| @@ -1269,31 +1228,24 @@ class QPDF | @@ -1269,31 +1228,24 @@ class QPDF | ||
| 1269 | // methods to support page handling | 1228 | // methods to support page handling |
| 1270 | 1229 | ||
| 1271 | void getAllPagesInternal( | 1230 | void getAllPagesInternal( |
| 1272 | - QPDFObjectHandle cur_pages, | ||
| 1273 | - QPDFObjGen::set& visited, | ||
| 1274 | - QPDFObjGen::set& seen); | 1231 | + QPDFObjectHandle cur_pages, QPDFObjGen::set& visited, QPDFObjGen::set& seen); |
| 1275 | void insertPage(QPDFObjectHandle newpage, int pos); | 1232 | void insertPage(QPDFObjectHandle newpage, int pos); |
| 1276 | void flattenPagesTree(); | 1233 | void flattenPagesTree(); |
| 1277 | - void insertPageobjToPage( | ||
| 1278 | - QPDFObjectHandle const& obj, int pos, bool check_duplicate); | 1234 | + void insertPageobjToPage(QPDFObjectHandle const& obj, int pos, bool check_duplicate); |
| 1279 | 1235 | ||
| 1280 | // methods to support encryption -- implemented in QPDF_encryption.cc | 1236 | // methods to support encryption -- implemented in QPDF_encryption.cc |
| 1281 | static encryption_method_e | 1237 | static encryption_method_e |
| 1282 | interpretCF(std::shared_ptr<EncryptionParameters> encp, QPDFObjectHandle); | 1238 | interpretCF(std::shared_ptr<EncryptionParameters> encp, QPDFObjectHandle); |
| 1283 | void initializeEncryption(); | 1239 | void initializeEncryption(); |
| 1284 | - static std::string getKeyForObject( | ||
| 1285 | - std::shared_ptr<EncryptionParameters> encp, | ||
| 1286 | - QPDFObjGen const& og, | ||
| 1287 | - bool use_aes); | 1240 | + static std::string |
| 1241 | + getKeyForObject(std::shared_ptr<EncryptionParameters> encp, QPDFObjGen const& og, bool use_aes); | ||
| 1288 | void decryptString(std::string&, QPDFObjGen const& og); | 1242 | void decryptString(std::string&, QPDFObjGen const& og); |
| 1289 | - static std::string compute_encryption_key_from_password( | ||
| 1290 | - std::string const& password, EncryptionData const& data); | ||
| 1291 | - static std::string recover_encryption_key_with_password( | ||
| 1292 | - std::string const& password, EncryptionData const& data); | 1243 | + static std::string |
| 1244 | + compute_encryption_key_from_password(std::string const& password, EncryptionData const& data); | ||
| 1245 | + static std::string | ||
| 1246 | + recover_encryption_key_with_password(std::string const& password, EncryptionData const& data); | ||
| 1293 | static std::string recover_encryption_key_with_password( | 1247 | static std::string recover_encryption_key_with_password( |
| 1294 | - std::string const& password, | ||
| 1295 | - EncryptionData const& data, | ||
| 1296 | - bool& perms_valid); | 1248 | + std::string const& password, EncryptionData const& data, bool& perms_valid); |
| 1297 | static void decryptStream( | 1249 | static void decryptStream( |
| 1298 | std::shared_ptr<EncryptionParameters> encp, | 1250 | std::shared_ptr<EncryptionParameters> encp, |
| 1299 | std::shared_ptr<InputSource> file, | 1251 | std::shared_ptr<InputSource> file, |
| @@ -1304,12 +1256,10 @@ class QPDF | @@ -1304,12 +1256,10 @@ class QPDF | ||
| 1304 | std::vector<std::shared_ptr<Pipeline>>& heap); | 1256 | std::vector<std::shared_ptr<Pipeline>>& heap); |
| 1305 | 1257 | ||
| 1306 | // Methods to support object copying | 1258 | // Methods to support object copying |
| 1307 | - void | ||
| 1308 | - reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top); | ||
| 1309 | - QPDFObjectHandle replaceForeignIndirectObjects( | ||
| 1310 | - QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top); | ||
| 1311 | - void | ||
| 1312 | - copyStreamData(QPDFObjectHandle dest_stream, QPDFObjectHandle src_stream); | 1259 | + void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top); |
| 1260 | + QPDFObjectHandle | ||
| 1261 | + replaceForeignIndirectObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top); | ||
| 1262 | + void copyStreamData(QPDFObjectHandle dest_stream, QPDFObjectHandle src_stream); | ||
| 1313 | 1263 | ||
| 1314 | // Linearization Hint table structures. | 1264 | // Linearization Hint table structures. |
| 1315 | // Naming conventions: | 1265 | // Naming conventions: |
| @@ -1538,14 +1488,7 @@ class QPDF | @@ -1538,14 +1488,7 @@ class QPDF | ||
| 1538 | class ObjUser | 1488 | class ObjUser |
| 1539 | { | 1489 | { |
| 1540 | public: | 1490 | public: |
| 1541 | - enum user_e { | ||
| 1542 | - ou_bad, | ||
| 1543 | - ou_page, | ||
| 1544 | - ou_thumb, | ||
| 1545 | - ou_trailer_key, | ||
| 1546 | - ou_root_key, | ||
| 1547 | - ou_root | ||
| 1548 | - }; | 1491 | + enum user_e { ou_bad, ou_page, ou_thumb, ou_trailer_key, ou_root_key, ou_root }; |
| 1549 | 1492 | ||
| 1550 | // type is set to ou_bad | 1493 | // type is set to ou_bad |
| 1551 | ObjUser(); | 1494 | ObjUser(); |
| @@ -1598,29 +1541,25 @@ class QPDF | @@ -1598,29 +1541,25 @@ class QPDF | ||
| 1598 | bool checkLinearizationInternal(); | 1541 | bool checkLinearizationInternal(); |
| 1599 | void dumpLinearizationDataInternal(); | 1542 | void dumpLinearizationDataInternal(); |
| 1600 | void linearizationWarning(std::string_view); | 1543 | void linearizationWarning(std::string_view); |
| 1601 | - QPDFObjectHandle | ||
| 1602 | - readHintStream(Pipeline&, qpdf_offset_t offset, size_t length); | 1544 | + QPDFObjectHandle readHintStream(Pipeline&, qpdf_offset_t offset, size_t length); |
| 1603 | void readHPageOffset(BitStream); | 1545 | void readHPageOffset(BitStream); |
| 1604 | void readHSharedObject(BitStream); | 1546 | void readHSharedObject(BitStream); |
| 1605 | void readHGeneric(BitStream, HGeneric&); | 1547 | void readHGeneric(BitStream, HGeneric&); |
| 1606 | qpdf_offset_t maxEnd(ObjUser const& ou); | 1548 | qpdf_offset_t maxEnd(ObjUser const& ou); |
| 1607 | qpdf_offset_t getLinearizationOffset(QPDFObjGen const&); | 1549 | qpdf_offset_t getLinearizationOffset(QPDFObjGen const&); |
| 1608 | - QPDFObjectHandle getUncompressedObject( | ||
| 1609 | - QPDFObjectHandle&, std::map<int, int> const& object_stream_data); | 1550 | + QPDFObjectHandle |
| 1551 | + getUncompressedObject(QPDFObjectHandle&, std::map<int, int> const& object_stream_data); | ||
| 1610 | int lengthNextN(int first_object, int n); | 1552 | int lengthNextN(int first_object, int n); |
| 1611 | - void checkHPageOffset( | ||
| 1612 | - std::vector<QPDFObjectHandle> const& pages, | ||
| 1613 | - std::map<int, int>& idx_to_obj); | ||
| 1614 | - void checkHSharedObject( | ||
| 1615 | - std::vector<QPDFObjectHandle> const& pages, | ||
| 1616 | - std::map<int, int>& idx_to_obj); | 1553 | + void |
| 1554 | + checkHPageOffset(std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& idx_to_obj); | ||
| 1555 | + void | ||
| 1556 | + checkHSharedObject(std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& idx_to_obj); | ||
| 1617 | void checkHOutlines(); | 1557 | void checkHOutlines(); |
| 1618 | void dumpHPageOffset(); | 1558 | void dumpHPageOffset(); |
| 1619 | void dumpHSharedObject(); | 1559 | void dumpHSharedObject(); |
| 1620 | void dumpHGeneric(HGeneric&); | 1560 | void dumpHGeneric(HGeneric&); |
| 1621 | qpdf_offset_t adjusted_offset(qpdf_offset_t offset); | 1561 | qpdf_offset_t adjusted_offset(qpdf_offset_t offset); |
| 1622 | - void | ||
| 1623 | - calculateLinearizationData(std::map<int, int> const& object_stream_data); | 1562 | + void calculateLinearizationData(std::map<int, int> const& object_stream_data); |
| 1624 | void pushOutlinesToPart( | 1563 | void pushOutlinesToPart( |
| 1625 | std::vector<QPDFObjectHandle>& part, | 1564 | std::vector<QPDFObjectHandle>& part, |
| 1626 | std::set<QPDFObjGen>& lc_outlines, | 1565 | std::set<QPDFObjGen>& lc_outlines, |
| @@ -1648,8 +1587,7 @@ class QPDF | @@ -1648,8 +1587,7 @@ class QPDF | ||
| 1648 | 1587 | ||
| 1649 | // Methods to support optimization | 1588 | // Methods to support optimization |
| 1650 | 1589 | ||
| 1651 | - void | ||
| 1652 | - pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys); | 1590 | + void pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys); |
| 1653 | void pushInheritedAttributesToPageInternal( | 1591 | void pushInheritedAttributesToPageInternal( |
| 1654 | QPDFObjectHandle, | 1592 | QPDFObjectHandle, |
| 1655 | std::map<std::string, std::vector<QPDFObjectHandle>>&, | 1593 | std::map<std::string, std::vector<QPDFObjectHandle>>&, |
| @@ -1681,11 +1619,7 @@ class QPDF | @@ -1681,11 +1619,7 @@ class QPDF | ||
| 1681 | qpdf_json_stream_data_e, | 1619 | qpdf_json_stream_data_e, |
| 1682 | std::string const& file_prefix); | 1620 | std::string const& file_prefix); |
| 1683 | void writeJSONObject( | 1621 | void writeJSONObject( |
| 1684 | - int version, | ||
| 1685 | - Pipeline* p, | ||
| 1686 | - bool& first, | ||
| 1687 | - std::string const& key, | ||
| 1688 | - QPDFObjectHandle&); | 1622 | + int version, Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle&); |
| 1689 | 1623 | ||
| 1690 | // Type conversion helper methods | 1624 | // Type conversion helper methods |
| 1691 | template <typename T> | 1625 | template <typename T> |
include/qpdf/QPDFAcroFormDocumentHelper.hh
| @@ -148,18 +148,15 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | @@ -148,18 +148,15 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | ||
| 148 | // underlying object will typically be the same as the underlying | 148 | // underlying object will typically be the same as the underlying |
| 149 | // object for the field. | 149 | // object for the field. |
| 150 | QPDF_DLL | 150 | QPDF_DLL |
| 151 | - std::vector<QPDFAnnotationObjectHelper> | ||
| 152 | - getAnnotationsForField(QPDFFormFieldObjectHelper); | 151 | + std::vector<QPDFAnnotationObjectHelper> getAnnotationsForField(QPDFFormFieldObjectHelper); |
| 153 | 152 | ||
| 154 | // Return annotations of subtype /Widget for a page. | 153 | // Return annotations of subtype /Widget for a page. |
| 155 | QPDF_DLL | 154 | QPDF_DLL |
| 156 | - std::vector<QPDFAnnotationObjectHelper> | ||
| 157 | - getWidgetAnnotationsForPage(QPDFPageObjectHelper); | 155 | + std::vector<QPDFAnnotationObjectHelper> getWidgetAnnotationsForPage(QPDFPageObjectHelper); |
| 158 | 156 | ||
| 159 | // Return top-level form fields for a page. | 157 | // Return top-level form fields for a page. |
| 160 | QPDF_DLL | 158 | QPDF_DLL |
| 161 | - std::vector<QPDFFormFieldObjectHelper> | ||
| 162 | - getFormFieldsForPage(QPDFPageObjectHelper); | 159 | + std::vector<QPDFFormFieldObjectHelper> getFormFieldsForPage(QPDFPageObjectHelper); |
| 163 | 160 | ||
| 164 | // Return the terminal field that is associated with this | 161 | // Return the terminal field that is associated with this |
| 165 | // annotation. If the annotation dictionary is merged with the | 162 | // annotation. If the annotation dictionary is merged with the |
| @@ -251,10 +248,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | @@ -251,10 +248,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | ||
| 251 | private: | 248 | private: |
| 252 | void analyze(); | 249 | void analyze(); |
| 253 | void traverseField( | 250 | void traverseField( |
| 254 | - QPDFObjectHandle field, | ||
| 255 | - QPDFObjectHandle parent, | ||
| 256 | - int depth, | ||
| 257 | - QPDFObjGen::set& visited); | 251 | + QPDFObjectHandle field, QPDFObjectHandle parent, int depth, QPDFObjGen::set& visited); |
| 258 | QPDFObjectHandle getOrCreateAcroForm(); | 252 | QPDFObjectHandle getOrCreateAcroForm(); |
| 259 | void adjustInheritedFields( | 253 | void adjustInheritedFields( |
| 260 | QPDFObjectHandle obj, | 254 | QPDFObjectHandle obj, |
| @@ -264,11 +258,9 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | @@ -264,11 +258,9 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | ||
| 264 | int from_default_q); | 258 | int from_default_q); |
| 265 | void adjustDefaultAppearances( | 259 | void adjustDefaultAppearances( |
| 266 | QPDFObjectHandle obj, | 260 | QPDFObjectHandle obj, |
| 267 | - std::map<std::string, std::map<std::string, std::string>> const& | ||
| 268 | - dr_map); | 261 | + std::map<std::string, std::map<std::string, std::string>> const& dr_map); |
| 269 | void adjustAppearanceStream( | 262 | void adjustAppearanceStream( |
| 270 | - QPDFObjectHandle stream, | ||
| 271 | - std::map<std::string, std::map<std::string, std::string>> dr_map); | 263 | + QPDFObjectHandle stream, std::map<std::string, std::map<std::string, std::string>> dr_map); |
| 272 | 264 | ||
| 273 | class Members | 265 | class Members |
| 274 | { | 266 | { |
| @@ -283,8 +275,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | @@ -283,8 +275,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper | ||
| 283 | Members(Members const&) = delete; | 275 | Members(Members const&) = delete; |
| 284 | 276 | ||
| 285 | bool cache_valid; | 277 | bool cache_valid; |
| 286 | - std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>> | ||
| 287 | - field_to_annotations; | 278 | + std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>> field_to_annotations; |
| 288 | std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field; | 279 | std::map<QPDFObjGen, QPDFFormFieldObjectHelper> annotation_to_field; |
| 289 | std::map<QPDFObjGen, std::string> field_to_name; | 280 | std::map<QPDFObjGen, std::string> field_to_name; |
| 290 | std::map<std::string, std::set<QPDFObjGen>> name_to_fields; | 281 | std::map<std::string, std::set<QPDFObjGen>> name_to_fields; |
include/qpdf/QPDFAnnotationObjectHelper.hh
| @@ -76,8 +76,7 @@ class QPDFAnnotationObjectHelper: public QPDFObjectHelper | @@ -76,8 +76,7 @@ class QPDFAnnotationObjectHelper: public QPDFObjectHelper | ||
| 76 | // which appearance stream is desired. If not specified, the | 76 | // which appearance stream is desired. If not specified, the |
| 77 | // appearance state in "/AS" will used. | 77 | // appearance state in "/AS" will used. |
| 78 | QPDF_DLL | 78 | QPDF_DLL |
| 79 | - QPDFObjectHandle getAppearanceStream( | ||
| 80 | - std::string const& which, std::string const& state = ""); | 79 | + QPDFObjectHandle getAppearanceStream(std::string const& which, std::string const& state = ""); |
| 81 | 80 | ||
| 82 | // Generate text suitable for addition to the containing page's | 81 | // Generate text suitable for addition to the containing page's |
| 83 | // content stream that draws this annotation's appearance stream | 82 | // content stream that draws this annotation's appearance stream |
include/qpdf/QPDFCryptoImpl.hh
| @@ -77,10 +77,8 @@ class QPDF_DLL_CLASS QPDFCryptoImpl | @@ -77,10 +77,8 @@ class QPDF_DLL_CLASS QPDFCryptoImpl | ||
| 77 | virtual void RC4_init(unsigned char const* key_data, int key_len = -1) = 0; | 77 | virtual void RC4_init(unsigned char const* key_data, int key_len = -1) = 0; |
| 78 | // out_data = 0 means to encrypt/decrypt in place | 78 | // out_data = 0 means to encrypt/decrypt in place |
| 79 | QPDF_DLL | 79 | QPDF_DLL |
| 80 | - virtual void RC4_process( | ||
| 81 | - unsigned char const* in_data, | ||
| 82 | - size_t len, | ||
| 83 | - unsigned char* out_data = nullptr) = 0; | 80 | + virtual void |
| 81 | + RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = nullptr) = 0; | ||
| 84 | QPDF_DLL | 82 | QPDF_DLL |
| 85 | virtual void RC4_finalize() = 0; | 83 | virtual void RC4_finalize() = 0; |
| 86 | 84 | ||
| @@ -93,8 +91,7 @@ class QPDF_DLL_CLASS QPDFCryptoImpl | @@ -93,8 +91,7 @@ class QPDF_DLL_CLASS QPDFCryptoImpl | ||
| 93 | bool cbc_mode, | 91 | bool cbc_mode, |
| 94 | unsigned char* cbc_block) = 0; | 92 | unsigned char* cbc_block) = 0; |
| 95 | QPDF_DLL | 93 | QPDF_DLL |
| 96 | - virtual void | ||
| 97 | - rijndael_process(unsigned char* in_data, unsigned char* out_data) = 0; | 94 | + virtual void rijndael_process(unsigned char* in_data, unsigned char* out_data) = 0; |
| 98 | QPDF_DLL | 95 | QPDF_DLL |
| 99 | virtual void rijndael_finalize() = 0; | 96 | virtual void rijndael_finalize() = 0; |
| 100 | }; | 97 | }; |
include/qpdf/QPDFCryptoProvider.hh
| @@ -78,8 +78,7 @@ class QPDFCryptoProvider | @@ -78,8 +78,7 @@ class QPDFCryptoProvider | ||
| 78 | 78 | ||
| 79 | static QPDFCryptoProvider& getInstance(); | 79 | static QPDFCryptoProvider& getInstance(); |
| 80 | 80 | ||
| 81 | - std::shared_ptr<QPDFCryptoImpl> | ||
| 82 | - getImpl_internal(std::string const& name) const; | 81 | + std::shared_ptr<QPDFCryptoImpl> getImpl_internal(std::string const& name) const; |
| 83 | template <typename T> | 82 | template <typename T> |
| 84 | void registerImpl_internal(std::string const& name); | 83 | void registerImpl_internal(std::string const& name); |
| 85 | void setDefaultProvider_internal(std::string const& name); | 84 | void setDefaultProvider_internal(std::string const& name); |
include/qpdf/QPDFEFStreamObjectHelper.hh
| @@ -75,11 +75,9 @@ class QPDFEFStreamObjectHelper: public QPDFObjectHelper | @@ -75,11 +75,9 @@ class QPDFEFStreamObjectHelper: public QPDFObjectHelper | ||
| 75 | // checksum and size are computed automatically and stored. Other | 75 | // checksum and size are computed automatically and stored. Other |
| 76 | // parameters may be supplied using setters defined below. | 76 | // parameters may be supplied using setters defined below. |
| 77 | QPDF_DLL | 77 | QPDF_DLL |
| 78 | - static QPDFEFStreamObjectHelper | ||
| 79 | - createEFStream(QPDF& qpdf, std::shared_ptr<Buffer> data); | 78 | + static QPDFEFStreamObjectHelper createEFStream(QPDF& qpdf, std::shared_ptr<Buffer> data); |
| 80 | QPDF_DLL | 79 | QPDF_DLL |
| 81 | - static QPDFEFStreamObjectHelper | ||
| 82 | - createEFStream(QPDF& qpdf, std::string const& data); | 80 | + static QPDFEFStreamObjectHelper createEFStream(QPDF& qpdf, std::string const& data); |
| 83 | // The provider function must write the data to the given | 81 | // The provider function must write the data to the given |
| 84 | // pipeline. The function may be called multiple times by the qpdf | 82 | // pipeline. The function may be called multiple times by the qpdf |
| 85 | // library. You can pass QUtil::file_provider(filename) as the | 83 | // library. You can pass QUtil::file_provider(filename) as the |
include/qpdf/QPDFEmbeddedFileDocumentHelper.hh
| @@ -48,19 +48,16 @@ class QPDFEmbeddedFileDocumentHelper: public QPDFDocumentHelper | @@ -48,19 +48,16 @@ class QPDFEmbeddedFileDocumentHelper: public QPDFDocumentHelper | ||
| 48 | bool hasEmbeddedFiles() const; | 48 | bool hasEmbeddedFiles() const; |
| 49 | 49 | ||
| 50 | QPDF_DLL | 50 | QPDF_DLL |
| 51 | - std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> | ||
| 52 | - getEmbeddedFiles(); | 51 | + std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> getEmbeddedFiles(); |
| 53 | 52 | ||
| 54 | // If an embedded file with the given name exists, return a | 53 | // If an embedded file with the given name exists, return a |
| 55 | // (shared) pointer to it. Otherwise, return nullptr. | 54 | // (shared) pointer to it. Otherwise, return nullptr. |
| 56 | QPDF_DLL | 55 | QPDF_DLL |
| 57 | - std::shared_ptr<QPDFFileSpecObjectHelper> | ||
| 58 | - getEmbeddedFile(std::string const& name); | 56 | + std::shared_ptr<QPDFFileSpecObjectHelper> getEmbeddedFile(std::string const& name); |
| 59 | 57 | ||
| 60 | // Add or replace an attachment | 58 | // Add or replace an attachment |
| 61 | QPDF_DLL | 59 | QPDF_DLL |
| 62 | - void replaceEmbeddedFile( | ||
| 63 | - std::string const& name, QPDFFileSpecObjectHelper const&); | 60 | + void replaceEmbeddedFile(std::string const& name, QPDFFileSpecObjectHelper const&); |
| 64 | 61 | ||
| 65 | // Remove an embedded file if present. Return value is true if the | 62 | // Remove an embedded file if present. Return value is true if the |
| 66 | // file was present and was removed. This method not only removes | 63 | // file was present and was removed. This method not only removes |
include/qpdf/QPDFFileSpecObjectHelper.hh
| @@ -77,16 +77,16 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper | @@ -77,16 +77,16 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper | ||
| 77 | // filename, and attach the contents of the specified file as data | 77 | // filename, and attach the contents of the specified file as data |
| 78 | // in an embedded file stream. | 78 | // in an embedded file stream. |
| 79 | QPDF_DLL | 79 | QPDF_DLL |
| 80 | - static QPDFFileSpecObjectHelper createFileSpec( | ||
| 81 | - QPDF& qpdf, std::string const& filename, std::string const& fullpath); | 80 | + static QPDFFileSpecObjectHelper |
| 81 | + createFileSpec(QPDF& qpdf, std::string const& filename, std::string const& fullpath); | ||
| 82 | 82 | ||
| 83 | // Create a new filespec as an indirect object with the given | 83 | // Create a new filespec as an indirect object with the given |
| 84 | // unicode filename and embedded file stream. The file name will | 84 | // unicode filename and embedded file stream. The file name will |
| 85 | // be used as both /UF and /F. If you need to override, call | 85 | // be used as both /UF and /F. If you need to override, call |
| 86 | // setFilename. | 86 | // setFilename. |
| 87 | QPDF_DLL | 87 | QPDF_DLL |
| 88 | - static QPDFFileSpecObjectHelper createFileSpec( | ||
| 89 | - QPDF& qpdf, std::string const& filename, QPDFEFStreamObjectHelper); | 88 | + static QPDFFileSpecObjectHelper |
| 89 | + createFileSpec(QPDF& qpdf, std::string const& filename, QPDFEFStreamObjectHelper); | ||
| 90 | 90 | ||
| 91 | QPDF_DLL | 91 | QPDF_DLL |
| 92 | QPDFFileSpecObjectHelper& setDescription(std::string const&); | 92 | QPDFFileSpecObjectHelper& setDescription(std::string const&); |
| @@ -96,8 +96,8 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper | @@ -96,8 +96,8 @@ class QPDFFileSpecObjectHelper: public QPDFObjectHelper | ||
| 96 | // QPDFObjectHandle literally, preserving whatever encoding it | 96 | // QPDFObjectHandle literally, preserving whatever encoding it |
| 97 | // might happen to have. | 97 | // might happen to have. |
| 98 | QPDF_DLL | 98 | QPDF_DLL |
| 99 | - QPDFFileSpecObjectHelper& setFilename( | ||
| 100 | - std::string const& unicode_name, std::string const& compat_name = ""); | 99 | + QPDFFileSpecObjectHelper& |
| 100 | + setFilename(std::string const& unicode_name, std::string const& compat_name = ""); | ||
| 101 | 101 | ||
| 102 | private: | 102 | private: |
| 103 | class Members | 103 | class Members |
include/qpdf/QPDFFormFieldObjectHelper.hh
| @@ -183,8 +183,7 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper | @@ -183,8 +183,7 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper | ||
| 183 | // of a field, use QPDFAcroFormDocumentHelper::setFormFieldName | 183 | // of a field, use QPDFAcroFormDocumentHelper::setFormFieldName |
| 184 | // instead. | 184 | // instead. |
| 185 | QPDF_DLL | 185 | QPDF_DLL |
| 186 | - void | ||
| 187 | - setFieldAttribute(std::string const& key, std::string const& utf8_value); | 186 | + void setFieldAttribute(std::string const& key, std::string const& utf8_value); |
| 188 | 187 | ||
| 189 | // Set /V (field value) to the given value. If need_appearances is | 188 | // Set /V (field value) to the given value. If need_appearances is |
| 190 | // true and the field type is either /Tx (text) or /Ch (choice), | 189 | // true and the field type is either /Tx (text) or /Ch (choice), |
| @@ -218,8 +217,7 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper | @@ -218,8 +217,7 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper | ||
| 218 | void setRadioButtonValue(QPDFObjectHandle name); | 217 | void setRadioButtonValue(QPDFObjectHandle name); |
| 219 | void setCheckBoxValue(bool value); | 218 | void setCheckBoxValue(bool value); |
| 220 | void generateTextAppearance(QPDFAnnotationObjectHelper&); | 219 | void generateTextAppearance(QPDFAnnotationObjectHelper&); |
| 221 | - QPDFObjectHandle getFontFromResource( | ||
| 222 | - QPDFObjectHandle resources, std::string const& font_name); | 220 | + QPDFObjectHandle getFontFromResource(QPDFObjectHandle resources, std::string const& font_name); |
| 223 | 221 | ||
| 224 | class Members | 222 | class Members |
| 225 | { | 223 | { |
include/qpdf/QPDFJob.hh
| @@ -83,8 +83,7 @@ class QPDFJob | @@ -83,8 +83,7 @@ class QPDFJob | ||
| 83 | // about converting arguments to UTF-8. This method will mutate | 83 | // about converting arguments to UTF-8. This method will mutate |
| 84 | // arguments that are passed to it. | 84 | // arguments that are passed to it. |
| 85 | QPDF_DLL | 85 | QPDF_DLL |
| 86 | - void initializeFromArgv( | ||
| 87 | - char const* const argv[], char const* progname_env = nullptr); | 86 | + void initializeFromArgv(char const* const argv[], char const* progname_env = nullptr); |
| 88 | 87 | ||
| 89 | // Initialize a QPDFJob from json. Passing partial = true prevents | 88 | // Initialize a QPDFJob from json. Passing partial = true prevents |
| 90 | // this method from doing the final checks (calling | 89 | // this method from doing the final checks (calling |
| @@ -132,8 +131,7 @@ class QPDFJob | @@ -132,8 +131,7 @@ class QPDFJob | ||
| 132 | // configures a private logger, separating this object from the | 131 | // configures a private logger, separating this object from the |
| 133 | // default logger, and calls setOutputStreams on that logger. See | 132 | // default logger, and calls setOutputStreams on that logger. See |
| 134 | // QPDFLogger.hh for additional details. | 133 | // QPDFLogger.hh for additional details. |
| 135 | - [[deprecated( | ||
| 136 | - "configure logger from getLogger() or call setLogger()")]] QPDF_DLL void | 134 | + [[deprecated("configure logger from getLogger() or call setLogger()")]] QPDF_DLL void |
| 137 | setOutputStreams(std::ostream* out_stream, std::ostream* err_stream); | 135 | setOutputStreams(std::ostream* out_stream, std::ostream* err_stream); |
| 138 | 136 | ||
| 139 | // You can register a custom progress reporter to be called by | 137 | // You can register a custom progress reporter to be called by |
| @@ -187,10 +185,7 @@ class QPDFJob | @@ -187,10 +185,7 @@ class QPDFJob | ||
| 187 | 185 | ||
| 188 | struct PageSpec | 186 | struct PageSpec |
| 189 | { | 187 | { |
| 190 | - PageSpec( | ||
| 191 | - std::string const& filename, | ||
| 192 | - char const* password, | ||
| 193 | - std::string const& range); | 188 | + PageSpec(std::string const& filename, char const* password, std::string const& range); |
| 194 | 189 | ||
| 195 | std::string filename; | 190 | std::string filename; |
| 196 | std::shared_ptr<char> password; | 191 | std::shared_ptr<char> password; |
| @@ -284,9 +279,7 @@ class QPDFJob | @@ -284,9 +279,7 @@ class QPDFJob | ||
| 284 | Config* endPages(); | 279 | Config* endPages(); |
| 285 | QPDF_DLL | 280 | QPDF_DLL |
| 286 | PagesConfig* pageSpec( | 281 | PagesConfig* pageSpec( |
| 287 | - std::string const& filename, | ||
| 288 | - std::string const& range, | ||
| 289 | - char const* password = nullptr); | 282 | + std::string const& filename, std::string const& range, char const* password = nullptr); |
| 290 | 283 | ||
| 291 | #include <qpdf/auto_job_c_pages.hh> | 284 | #include <qpdf/auto_job_c_pages.hh> |
| 292 | 285 | ||
| @@ -366,10 +359,8 @@ class QPDFJob | @@ -366,10 +359,8 @@ class QPDFJob | ||
| 366 | QPDF_DLL | 359 | QPDF_DLL |
| 367 | std::shared_ptr<UOConfig> underlay(); | 360 | std::shared_ptr<UOConfig> underlay(); |
| 368 | QPDF_DLL | 361 | QPDF_DLL |
| 369 | - std::shared_ptr<EncConfig> encrypt( | ||
| 370 | - int keylen, | ||
| 371 | - std::string const& user_password, | ||
| 372 | - std::string const& owner_password); | 362 | + std::shared_ptr<EncConfig> |
| 363 | + encrypt(int keylen, std::string const& user_password, std::string const& owner_password); | ||
| 373 | 364 | ||
| 374 | #include <qpdf/auto_job_c_main.hh> | 365 | #include <qpdf/auto_job_c_main.hh> |
| 375 | 366 | ||
| @@ -438,8 +429,7 @@ class QPDFJob | @@ -438,8 +429,7 @@ class QPDFJob | ||
| 438 | // If in verbose mode, call the given function, passing in the | 429 | // If in verbose mode, call the given function, passing in the |
| 439 | // output stream and message prefix. | 430 | // output stream and message prefix. |
| 440 | QPDF_DLL | 431 | QPDF_DLL |
| 441 | - void | ||
| 442 | - doIfVerbose(std::function<void(Pipeline&, std::string const& prefix)> fn); | 432 | + void doIfVerbose(std::function<void(Pipeline&, std::string const& prefix)> fn); |
| 443 | 433 | ||
| 444 | // Provide a string that is the help information ("schema" for the | 434 | // Provide a string that is the help information ("schema" for the |
| 445 | // qpdf-specific JSON object) for the specified version of JSON | 435 | // qpdf-specific JSON object) for the specified version of JSON |
| @@ -447,16 +437,14 @@ class QPDFJob | @@ -447,16 +437,14 @@ class QPDFJob | ||
| 447 | QPDF_DLL | 437 | QPDF_DLL |
| 448 | static std::string json_out_schema(int version); | 438 | static std::string json_out_schema(int version); |
| 449 | 439 | ||
| 450 | - [[deprecated("use json_out_schema(version)")]] static std::string QPDF_DLL | ||
| 451 | - json_out_schema_v1(); | 440 | + [[deprecated("use json_out_schema(version)")]] static std::string QPDF_DLL json_out_schema_v1(); |
| 452 | 441 | ||
| 453 | // Provide a string that is the help information for specified | 442 | // Provide a string that is the help information for specified |
| 454 | // version of JSON format for QPDFJob. | 443 | // version of JSON format for QPDFJob. |
| 455 | QPDF_DLL | 444 | QPDF_DLL |
| 456 | static std::string job_json_schema(int version); | 445 | static std::string job_json_schema(int version); |
| 457 | 446 | ||
| 458 | - [[deprecated("use job_json_schema(version)")]] static std::string QPDF_DLL | ||
| 459 | - job_json_schema_v1(); | 447 | + [[deprecated("use job_json_schema(version)")]] static std::string QPDF_DLL job_json_schema_v1(); |
| 460 | 448 | ||
| 461 | private: | 449 | private: |
| 462 | struct RotationSpec | 450 | struct RotationSpec |
| @@ -497,10 +485,8 @@ class QPDFJob | @@ -497,10 +485,8 @@ class QPDFJob | ||
| 497 | 485 | ||
| 498 | // Helper functions | 486 | // Helper functions |
| 499 | static void usage(std::string const& msg); | 487 | static void usage(std::string const& msg); |
| 500 | - static JSON | ||
| 501 | - json_schema(int json_version, std::set<std::string>* keys = nullptr); | ||
| 502 | - static void parse_object_id( | ||
| 503 | - std::string const& objspec, bool& trailer, int& obj, int& gen); | 488 | + static JSON json_schema(int json_version, std::set<std::string>* keys = nullptr); |
| 489 | + static void parse_object_id(std::string const& objspec, bool& trailer, int& obj, int& gen); | ||
| 504 | void parseRotationParameter(std::string const&); | 490 | void parseRotationParameter(std::string const&); |
| 505 | std::vector<int> parseNumrange(char const* range, int max); | 491 | std::vector<int> parseNumrange(char const* range, int max); |
| 506 | 492 | ||
| @@ -533,12 +519,10 @@ class QPDFJob | @@ -533,12 +519,10 @@ class QPDFJob | ||
| 533 | 519 | ||
| 534 | // Transformations | 520 | // Transformations |
| 535 | void setQPDFOptions(QPDF& pdf); | 521 | void setQPDFOptions(QPDF& pdf); |
| 536 | - void | ||
| 537 | - handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_heap); | 522 | + void handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_heap); |
| 538 | bool shouldRemoveUnreferencedResources(QPDF& pdf); | 523 | bool shouldRemoveUnreferencedResources(QPDF& pdf); |
| 539 | void handleRotations(QPDF& pdf); | 524 | void handleRotations(QPDF& pdf); |
| 540 | - void | ||
| 541 | - getUOPagenos(UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos); | 525 | + void getUOPagenos(UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos); |
| 542 | void handleUnderOverlay(QPDF& pdf); | 526 | void handleUnderOverlay(QPDF& pdf); |
| 543 | std::string doUnderOverlayForPage( | 527 | std::string doUnderOverlayForPage( |
| 544 | QPDF& pdf, | 528 | QPDF& pdf, |
| @@ -573,8 +557,7 @@ class QPDFJob | @@ -573,8 +557,7 @@ class QPDFJob | ||
| 573 | // JSON | 557 | // JSON |
| 574 | void doJSON(QPDF& pdf, Pipeline*); | 558 | void doJSON(QPDF& pdf, Pipeline*); |
| 575 | QPDFObjGen::set getWantedJSONObjects(); | 559 | QPDFObjGen::set getWantedJSONObjects(); |
| 576 | - void doJSONObject( | ||
| 577 | - Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle&); | 560 | + void doJSONObject(Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle&); |
| 578 | void doJSONObjects(Pipeline* p, bool& first, QPDF& pdf); | 561 | void doJSONObjects(Pipeline* p, bool& first, QPDF& pdf); |
| 579 | void doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf); | 562 | void doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf); |
| 580 | void doJSONPages(Pipeline* p, bool& first, QPDF& pdf); | 563 | void doJSONPages(Pipeline* p, bool& first, QPDF& pdf); |
include/qpdf/QPDFLogger.hh
| @@ -153,8 +153,7 @@ class QPDFLogger | @@ -153,8 +153,7 @@ class QPDFLogger | ||
| 153 | 153 | ||
| 154 | private: | 154 | private: |
| 155 | QPDFLogger(); | 155 | QPDFLogger(); |
| 156 | - std::shared_ptr<Pipeline> | ||
| 157 | - throwIfNull(std::shared_ptr<Pipeline>, bool null_okay); | 156 | + std::shared_ptr<Pipeline> throwIfNull(std::shared_ptr<Pipeline>, bool null_okay); |
| 158 | 157 | ||
| 159 | class Members | 158 | class Members |
| 160 | { | 159 | { |
include/qpdf/QPDFMatrix.hh
| @@ -79,8 +79,7 @@ class QPDFMatrix | @@ -79,8 +79,7 @@ class QPDFMatrix | ||
| 79 | // bounds the polygon resulting from transforming the four | 79 | // bounds the polygon resulting from transforming the four |
| 80 | // corners. | 80 | // corners. |
| 81 | QPDF_DLL | 81 | QPDF_DLL |
| 82 | - QPDFObjectHandle::Rectangle | ||
| 83 | - transformRectangle(QPDFObjectHandle::Rectangle r) const; | 82 | + QPDFObjectHandle::Rectangle transformRectangle(QPDFObjectHandle::Rectangle r) const; |
| 84 | 83 | ||
| 85 | // operator== tests for exact equality, not considering deltas for | 84 | // operator== tests for exact equality, not considering deltas for |
| 86 | // floating point. | 85 | // floating point. |
include/qpdf/QPDFNameTreeObjectHelper.hh
| @@ -156,8 +156,7 @@ class QPDF_DLL_CLASS QPDFNameTreeObjectHelper: public QPDFObjectHelper | @@ -156,8 +156,7 @@ class QPDF_DLL_CLASS QPDFNameTreeObjectHelper: public QPDFObjectHelper | ||
| 156 | // Find the entry with the given key. If return_prev_if_not_found | 156 | // Find the entry with the given key. If return_prev_if_not_found |
| 157 | // is true and the item is not found, return the next lower item. | 157 | // is true and the item is not found, return the next lower item. |
| 158 | QPDF_DLL | 158 | QPDF_DLL |
| 159 | - iterator | ||
| 160 | - find(std::string const& key, bool return_prev_if_not_found = false); | 159 | + iterator find(std::string const& key, bool return_prev_if_not_found = false); |
| 161 | 160 | ||
| 162 | // Insert a new item. If the key already exists, it is replaced. | 161 | // Insert a new item. If the key already exists, it is replaced. |
| 163 | QPDF_DLL | 162 | QPDF_DLL |
include/qpdf/QPDFNumberTreeObjectHelper.hh
| @@ -45,8 +45,7 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper | @@ -45,8 +45,7 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper | ||
| 45 | // The qpdf object is required so that this class can issue | 45 | // The qpdf object is required so that this class can issue |
| 46 | // warnings, attempt repairs, and add indirect objects. | 46 | // warnings, attempt repairs, and add indirect objects. |
| 47 | QPDF_DLL | 47 | QPDF_DLL |
| 48 | - QPDFNumberTreeObjectHelper( | ||
| 49 | - QPDFObjectHandle, QPDF&, bool auto_repair = true); | 48 | + QPDFNumberTreeObjectHelper(QPDFObjectHandle, QPDF&, bool auto_repair = true); |
| 50 | 49 | ||
| 51 | QPDF_DLL | 50 | QPDF_DLL |
| 52 | virtual ~QPDFNumberTreeObjectHelper(); | 51 | virtual ~QPDFNumberTreeObjectHelper(); |
| @@ -82,8 +81,7 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper | @@ -82,8 +81,7 @@ class QPDF_DLL_CLASS QPDFNumberTreeObjectHelper: public QPDFObjectHelper | ||
| 82 | // oh to the value with index 3, and set offset to 2 (5 - 3). See | 81 | // oh to the value with index 3, and set offset to 2 (5 - 3). See |
| 83 | // also find(). | 82 | // also find(). |
| 84 | QPDF_DLL | 83 | QPDF_DLL |
| 85 | - bool findObjectAtOrBelow( | ||
| 86 | - numtree_number idx, QPDFObjectHandle& oh, numtree_number& offset); | 84 | + bool findObjectAtOrBelow(numtree_number idx, QPDFObjectHandle& oh, numtree_number& offset); |
| 87 | 85 | ||
| 88 | class QPDF_DLL_PRIVATE iterator | 86 | class QPDF_DLL_PRIVATE iterator |
| 89 | { | 87 | { |
include/qpdf/QPDFObjectHandle.hh
| @@ -128,22 +128,13 @@ class QPDFObjectHandle | @@ -128,22 +128,13 @@ class QPDFObjectHandle | ||
| 128 | // version of the method, which should also return a boolean | 128 | // version of the method, which should also return a boolean |
| 129 | // indicating whether it ran without errors. | 129 | // indicating whether it ran without errors. |
| 130 | QPDF_DLL | 130 | QPDF_DLL |
| 131 | - virtual void | ||
| 132 | - provideStreamData(QPDFObjGen const& og, Pipeline* pipeline); | 131 | + virtual void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline); |
| 133 | QPDF_DLL | 132 | QPDF_DLL |
| 134 | virtual bool provideStreamData( | 133 | virtual bool provideStreamData( |
| 135 | - QPDFObjGen const& og, | ||
| 136 | - Pipeline* pipeline, | ||
| 137 | - bool suppress_warnings, | ||
| 138 | - bool will_retry); | ||
| 139 | - QPDF_DLL virtual void | ||
| 140 | - provideStreamData(int objid, int generation, Pipeline* pipeline); | 134 | + QPDFObjGen const& og, Pipeline* pipeline, bool suppress_warnings, bool will_retry); |
| 135 | + QPDF_DLL virtual void provideStreamData(int objid, int generation, Pipeline* pipeline); | ||
| 141 | QPDF_DLL virtual bool provideStreamData( | 136 | QPDF_DLL virtual bool provideStreamData( |
| 142 | - int objid, | ||
| 143 | - int generation, | ||
| 144 | - Pipeline* pipeline, | ||
| 145 | - bool suppress_warnings, | ||
| 146 | - bool will_retry); | 137 | + int objid, int generation, Pipeline* pipeline, bool suppress_warnings, bool will_retry); |
| 147 | QPDF_DLL | 138 | QPDF_DLL |
| 148 | bool supportsRetry(); | 139 | bool supportsRetry(); |
| 149 | 140 | ||
| @@ -246,8 +237,7 @@ class QPDFObjectHandle | @@ -246,8 +237,7 @@ class QPDFObjectHandle | ||
| 246 | QPDF_DLL | 237 | QPDF_DLL |
| 247 | virtual void handleObject(QPDFObjectHandle); | 238 | virtual void handleObject(QPDFObjectHandle); |
| 248 | QPDF_DLL | 239 | QPDF_DLL |
| 249 | - virtual void | ||
| 250 | - handleObject(QPDFObjectHandle, size_t offset, size_t length); | 240 | + virtual void handleObject(QPDFObjectHandle, size_t offset, size_t length); |
| 251 | 241 | ||
| 252 | virtual void handleEOF() = 0; | 242 | virtual void handleEOF() = 0; |
| 253 | 243 | ||
| @@ -408,14 +398,12 @@ class QPDFObjectHandle | @@ -408,14 +398,12 @@ class QPDFObjectHandle | ||
| 408 | // True if the object is a dictionary of the specified type and | 398 | // True if the object is a dictionary of the specified type and |
| 409 | // subtype, if any. | 399 | // subtype, if any. |
| 410 | QPDF_DLL | 400 | QPDF_DLL |
| 411 | - bool isDictionaryOfType( | ||
| 412 | - std::string const& type, std::string const& subtype = ""); | 401 | + bool isDictionaryOfType(std::string const& type, std::string const& subtype = ""); |
| 413 | 402 | ||
| 414 | // True if the object is a stream of the specified type and | 403 | // True if the object is a stream of the specified type and |
| 415 | // subtype, if any. | 404 | // subtype, if any. |
| 416 | QPDF_DLL | 405 | QPDF_DLL |
| 417 | - bool | ||
| 418 | - isStreamOfType(std::string const& type, std::string const& subtype = ""); | 406 | + bool isStreamOfType(std::string const& type, std::string const& subtype = ""); |
| 419 | 407 | ||
| 420 | // Public factory methods | 408 | // Public factory methods |
| 421 | 409 | ||
| @@ -433,9 +421,8 @@ class QPDFObjectHandle | @@ -433,9 +421,8 @@ class QPDFObjectHandle | ||
| 433 | // in the message of any QPDFExc exception thrown for invalid | 421 | // in the message of any QPDFExc exception thrown for invalid |
| 434 | // syntax. See also the global `operator ""_qpdf` defined below. | 422 | // syntax. See also the global `operator ""_qpdf` defined below. |
| 435 | QPDF_DLL | 423 | QPDF_DLL |
| 436 | - static QPDFObjectHandle parse( | ||
| 437 | - std::string const& object_str, | ||
| 438 | - std::string const& object_description = ""); | 424 | + static QPDFObjectHandle |
| 425 | + parse(std::string const& object_str, std::string const& object_description = ""); | ||
| 439 | 426 | ||
| 440 | // Construct an object of any type from a string representation of | 427 | // Construct an object of any type from a string representation of |
| 441 | // the object. Indirect object syntax (obj gen R) is allowed and | 428 | // the object. Indirect object syntax (obj gen R) is allowed and |
| @@ -447,10 +434,8 @@ class QPDFObjectHandle | @@ -447,10 +434,8 @@ class QPDFObjectHandle | ||
| 447 | // object, which will just be the first number and will report | 434 | // object, which will just be the first number and will report |
| 448 | // that there is trailing data at the end of the string. | 435 | // that there is trailing data at the end of the string. |
| 449 | QPDF_DLL | 436 | QPDF_DLL |
| 450 | - static QPDFObjectHandle parse( | ||
| 451 | - QPDF* context, | ||
| 452 | - std::string const& object_str, | ||
| 453 | - std::string const& object_description = ""); | 437 | + static QPDFObjectHandle |
| 438 | + parse(QPDF* context, std::string const& object_str, std::string const& object_description = ""); | ||
| 454 | 439 | ||
| 455 | // Construct an object as above by reading from the given | 440 | // Construct an object as above by reading from the given |
| 456 | // InputSource at its current position and using the tokenizer you | 441 | // InputSource at its current position and using the tokenizer you |
| @@ -480,8 +465,7 @@ class QPDFObjectHandle | @@ -480,8 +465,7 @@ class QPDFObjectHandle | ||
| 480 | // error messages will also be more useful because the page object | 465 | // error messages will also be more useful because the page object |
| 481 | // information will be known. | 466 | // information will be known. |
| 482 | QPDF_DLL | 467 | QPDF_DLL |
| 483 | - static void parseContentStream( | ||
| 484 | - QPDFObjectHandle stream_or_array, ParserCallbacks* callbacks); | 468 | + static void parseContentStream(QPDFObjectHandle stream_or_array, ParserCallbacks* callbacks); |
| 485 | 469 | ||
| 486 | // When called on a stream or stream array that is some page's | 470 | // When called on a stream or stream array that is some page's |
| 487 | // content streams, do the same as pipePageContents. This method | 471 | // content streams, do the same as pipePageContents. This method |
| @@ -500,10 +484,8 @@ class QPDFObjectHandle | @@ -500,10 +484,8 @@ class QPDFObjectHandle | ||
| 500 | // Pl_Concatenate and then call manualFinish() on the | 484 | // Pl_Concatenate and then call manualFinish() on the |
| 501 | // Pl_Concatenate pipeline at the end. | 485 | // Pl_Concatenate pipeline at the end. |
| 502 | QPDF_DLL | 486 | QPDF_DLL |
| 503 | - void pipeContentStreams( | ||
| 504 | - Pipeline* p, | ||
| 505 | - std::string const& description, | ||
| 506 | - std::string& all_description); | 487 | + void |
| 488 | + pipeContentStreams(Pipeline* p, std::string const& description, std::string& all_description); | ||
| 507 | 489 | ||
| 508 | // As of qpdf 8, it is possible to add custom token filters to a | 490 | // As of qpdf 8, it is possible to add custom token filters to a |
| 509 | // stream. The tokenized stream data is passed through the token | 491 | // stream. The tokenized stream data is passed through the token |
| @@ -554,8 +536,8 @@ class QPDFObjectHandle | @@ -554,8 +536,8 @@ class QPDFObjectHandle | ||
| 554 | QPDF_DLL | 536 | QPDF_DLL |
| 555 | static QPDFObjectHandle newReal(std::string const& value); | 537 | static QPDFObjectHandle newReal(std::string const& value); |
| 556 | QPDF_DLL | 538 | QPDF_DLL |
| 557 | - static QPDFObjectHandle newReal( | ||
| 558 | - double value, int decimal_places = 0, bool trim_trailing_zeroes = true); | 539 | + static QPDFObjectHandle |
| 540 | + newReal(double value, int decimal_places = 0, bool trim_trailing_zeroes = true); | ||
| 559 | // Note about name objects: qpdf's internal representation of a | 541 | // Note about name objects: qpdf's internal representation of a |
| 560 | // PDF name is a sequence of bytes, excluding the NUL character, | 542 | // PDF name is a sequence of bytes, excluding the NUL character, |
| 561 | // and starting with a slash. Name objects as represented in the | 543 | // and starting with a slash. Name objects as represented in the |
| @@ -591,8 +573,7 @@ class QPDFObjectHandle | @@ -591,8 +573,7 @@ class QPDFObjectHandle | ||
| 591 | QPDF_DLL | 573 | QPDF_DLL |
| 592 | static QPDFObjectHandle newArray(); | 574 | static QPDFObjectHandle newArray(); |
| 593 | QPDF_DLL | 575 | QPDF_DLL |
| 594 | - static QPDFObjectHandle | ||
| 595 | - newArray(std::vector<QPDFObjectHandle> const& items); | 576 | + static QPDFObjectHandle newArray(std::vector<QPDFObjectHandle> const& items); |
| 596 | QPDF_DLL | 577 | QPDF_DLL |
| 597 | static QPDFObjectHandle newArray(Rectangle const&); | 578 | static QPDFObjectHandle newArray(Rectangle const&); |
| 598 | QPDF_DLL | 579 | QPDF_DLL |
| @@ -602,8 +583,7 @@ class QPDFObjectHandle | @@ -602,8 +583,7 @@ class QPDFObjectHandle | ||
| 602 | QPDF_DLL | 583 | QPDF_DLL |
| 603 | static QPDFObjectHandle newDictionary(); | 584 | static QPDFObjectHandle newDictionary(); |
| 604 | QPDF_DLL | 585 | QPDF_DLL |
| 605 | - static QPDFObjectHandle | ||
| 606 | - newDictionary(std::map<std::string, QPDFObjectHandle> const& items); | 586 | + static QPDFObjectHandle newDictionary(std::map<std::string, QPDFObjectHandle> const& items); |
| 607 | 587 | ||
| 608 | // Create an array from a rectangle. Equivalent to the rectangle | 588 | // Create an array from a rectangle. Equivalent to the rectangle |
| 609 | // form of newArray. | 589 | // form of newArray. |
| @@ -686,8 +666,7 @@ class QPDFObjectHandle | @@ -686,8 +666,7 @@ class QPDFObjectHandle | ||
| 686 | // else. To add objects from another qpdf, use copyForeignObject | 666 | // else. To add objects from another qpdf, use copyForeignObject |
| 687 | // instead. | 667 | // instead. |
| 688 | QPDF_DLL | 668 | QPDF_DLL |
| 689 | - void setObjectDescription( | ||
| 690 | - QPDF* owning_qpdf, std::string const& object_description); | 669 | + void setObjectDescription(QPDF* owning_qpdf, std::string const& object_description); |
| 691 | QPDF_DLL | 670 | QPDF_DLL |
| 692 | bool hasObjectDescription(); | 671 | bool hasObjectDescription(); |
| 693 | 672 | ||
| @@ -964,8 +943,7 @@ class QPDFObjectHandle | @@ -964,8 +943,7 @@ class QPDFObjectHandle | ||
| 964 | QPDF_DLL | 943 | QPDF_DLL |
| 965 | void mergeResources( | 944 | void mergeResources( |
| 966 | QPDFObjectHandle other, | 945 | QPDFObjectHandle other, |
| 967 | - std::map<std::string, std::map<std::string, std::string>>* conflicts = | ||
| 968 | - nullptr); | 946 | + std::map<std::string, std::map<std::string, std::string>>* conflicts = nullptr); |
| 969 | 947 | ||
| 970 | // Get all resource names from a resource dictionary. If this | 948 | // Get all resource names from a resource dictionary. If this |
| 971 | // object is a dictionary, this method returns a set of all the | 949 | // object is a dictionary, this method returns a set of all the |
| @@ -1118,13 +1096,11 @@ class QPDFObjectHandle | @@ -1118,13 +1096,11 @@ class QPDFObjectHandle | ||
| 1118 | void replaceKey(std::string const& key, QPDFObjectHandle const& value); | 1096 | void replaceKey(std::string const& key, QPDFObjectHandle const& value); |
| 1119 | // Replace value of key and return the value. | 1097 | // Replace value of key and return the value. |
| 1120 | QPDF_DLL | 1098 | QPDF_DLL |
| 1121 | - QPDFObjectHandle | ||
| 1122 | - replaceKeyAndGetNew(std::string const& key, QPDFObjectHandle const& value); | 1099 | + QPDFObjectHandle replaceKeyAndGetNew(std::string const& key, QPDFObjectHandle const& value); |
| 1123 | // Replace value of key and return the old value, or null if the | 1100 | // Replace value of key and return the old value, or null if the |
| 1124 | // key was previously not present. | 1101 | // key was previously not present. |
| 1125 | QPDF_DLL | 1102 | QPDF_DLL |
| 1126 | - QPDFObjectHandle | ||
| 1127 | - replaceKeyAndGetOld(std::string const& key, QPDFObjectHandle const& value); | 1103 | + QPDFObjectHandle replaceKeyAndGetOld(std::string const& key, QPDFObjectHandle const& value); |
| 1128 | // Remove key, doing nothing if key does not exist. | 1104 | // Remove key, doing nothing if key does not exist. |
| 1129 | QPDF_DLL | 1105 | QPDF_DLL |
| 1130 | void removeKey(std::string const& key); | 1106 | void removeKey(std::string const& key); |
| @@ -1167,8 +1143,7 @@ class QPDFObjectHandle | @@ -1167,8 +1143,7 @@ class QPDFObjectHandle | ||
| 1167 | // Returns filtered (uncompressed) stream data. Throws an | 1143 | // Returns filtered (uncompressed) stream data. Throws an |
| 1168 | // exception if the stream is filtered and we can't decode it. | 1144 | // exception if the stream is filtered and we can't decode it. |
| 1169 | QPDF_DLL | 1145 | QPDF_DLL |
| 1170 | - std::shared_ptr<Buffer> | ||
| 1171 | - getStreamData(qpdf_stream_decode_level_e level = qpdf_dl_generalized); | 1146 | + std::shared_ptr<Buffer> getStreamData(qpdf_stream_decode_level_e level = qpdf_dl_generalized); |
| 1172 | 1147 | ||
| 1173 | // Returns unfiltered (raw) stream data. | 1148 | // Returns unfiltered (raw) stream data. |
| 1174 | QPDF_DLL | 1149 | QPDF_DLL |
| @@ -1347,8 +1322,7 @@ class QPDFObjectHandle | @@ -1347,8 +1322,7 @@ class QPDFObjectHandle | ||
| 1347 | // returning true if it succeeded without errors. | 1322 | // returning true if it succeeded without errors. |
| 1348 | QPDF_DLL | 1323 | QPDF_DLL |
| 1349 | void replaceStreamData( | 1324 | void replaceStreamData( |
| 1350 | - std::function<bool(Pipeline*, bool suppress_warnings, bool will_retry)> | ||
| 1351 | - provider, | 1325 | + std::function<bool(Pipeline*, bool suppress_warnings, bool will_retry)> provider, |
| 1352 | QPDFObjectHandle const& filter, | 1326 | QPDFObjectHandle const& filter, |
| 1353 | QPDFObjectHandle const& decode_parms); | 1327 | QPDFObjectHandle const& decode_parms); |
| 1354 | 1328 | ||
| @@ -1615,15 +1589,14 @@ class QPDFObjectHandle | @@ -1615,15 +1589,14 @@ class QPDFObjectHandle | ||
| 1615 | void makeDirect(QPDFObjGen::set& visited, bool stop_at_streams); | 1589 | void makeDirect(QPDFObjGen::set& visited, bool stop_at_streams); |
| 1616 | void disconnect(); | 1590 | void disconnect(); |
| 1617 | void setParsedOffset(qpdf_offset_t offset); | 1591 | void setParsedOffset(qpdf_offset_t offset); |
| 1618 | - void parseContentStream_internal( | ||
| 1619 | - std::string const& description, ParserCallbacks* callbacks); | 1592 | + void parseContentStream_internal(std::string const& description, ParserCallbacks* callbacks); |
| 1620 | static void parseContentStream_data( | 1593 | static void parseContentStream_data( |
| 1621 | std::shared_ptr<Buffer>, | 1594 | std::shared_ptr<Buffer>, |
| 1622 | std::string const& description, | 1595 | std::string const& description, |
| 1623 | ParserCallbacks* callbacks, | 1596 | ParserCallbacks* callbacks, |
| 1624 | QPDF* context); | 1597 | QPDF* context); |
| 1625 | - std::vector<QPDFObjectHandle> arrayOrStreamToStreamArray( | ||
| 1626 | - std::string const& description, std::string& all_description); | 1598 | + std::vector<QPDFObjectHandle> |
| 1599 | + arrayOrStreamToStreamArray(std::string const& description, std::string& all_description); | ||
| 1627 | static void warn(QPDF*, QPDFExc const&); | 1600 | static void warn(QPDF*, QPDFExc const&); |
| 1628 | void checkOwnership(QPDFObjectHandle const&) const; | 1601 | void checkOwnership(QPDFObjectHandle const&) const; |
| 1629 | 1602 |
include/qpdf/QPDFPageDocumentHelper.hh
| @@ -104,10 +104,7 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper | @@ -104,10 +104,7 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper | ||
| 104 | // Add new page before or after refpage. See comments for addPage | 104 | // Add new page before or after refpage. See comments for addPage |
| 105 | // for details about what newpage should be. | 105 | // for details about what newpage should be. |
| 106 | QPDF_DLL | 106 | QPDF_DLL |
| 107 | - void addPageAt( | ||
| 108 | - QPDFPageObjectHelper newpage, | ||
| 109 | - bool before, | ||
| 110 | - QPDFPageObjectHelper refpage); | 107 | + void addPageAt(QPDFPageObjectHelper newpage, bool before, QPDFPageObjectHelper refpage); |
| 111 | 108 | ||
| 112 | // Remove page from the pdf. | 109 | // Remove page from the pdf. |
| 113 | QPDF_DLL | 110 | QPDF_DLL |
| @@ -125,8 +122,7 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper | @@ -125,8 +122,7 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper | ||
| 125 | // comments there in QPDFAnnotationObjectHelper.hh for meanings of | 122 | // comments there in QPDFAnnotationObjectHelper.hh for meanings of |
| 126 | // those flags. | 123 | // those flags. |
| 127 | QPDF_DLL | 124 | QPDF_DLL |
| 128 | - void flattenAnnotations( | ||
| 129 | - int required_flags = 0, int forbidden_flags = an_invisible | an_hidden); | 125 | + void flattenAnnotations(int required_flags = 0, int forbidden_flags = an_invisible | an_hidden); |
| 130 | 126 | ||
| 131 | private: | 127 | private: |
| 132 | void flattenAnnotationsForPage( | 128 | void flattenAnnotationsForPage( |
include/qpdf/QPDFPageObjectHelper.hh
| @@ -170,26 +170,22 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | @@ -170,26 +170,22 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | ||
| 170 | // Return the effective CropBox. If not defined, fall back to | 170 | // Return the effective CropBox. If not defined, fall back to |
| 171 | // MediaBox | 171 | // MediaBox |
| 172 | QPDF_DLL | 172 | QPDF_DLL |
| 173 | - QPDFObjectHandle | ||
| 174 | - getCropBox(bool copy_if_shared = false, bool copy_if_fallback = false); | 173 | + QPDFObjectHandle getCropBox(bool copy_if_shared = false, bool copy_if_fallback = false); |
| 175 | 174 | ||
| 176 | // Return the effective BleedBox. If not defined, fall back to | 175 | // Return the effective BleedBox. If not defined, fall back to |
| 177 | // CropBox. | 176 | // CropBox. |
| 178 | QPDF_DLL | 177 | QPDF_DLL |
| 179 | - QPDFObjectHandle | ||
| 180 | - getBleedBox(bool copy_if_shared = false, bool copy_if_fallback = false); | 178 | + QPDFObjectHandle getBleedBox(bool copy_if_shared = false, bool copy_if_fallback = false); |
| 181 | 179 | ||
| 182 | // Return the effective TrimBox. If not defined, fall back to | 180 | // Return the effective TrimBox. If not defined, fall back to |
| 183 | // CropBox. | 181 | // CropBox. |
| 184 | QPDF_DLL | 182 | QPDF_DLL |
| 185 | - QPDFObjectHandle | ||
| 186 | - getTrimBox(bool copy_if_shared = false, bool copy_if_fallback = false); | 183 | + QPDFObjectHandle getTrimBox(bool copy_if_shared = false, bool copy_if_fallback = false); |
| 187 | 184 | ||
| 188 | // Return the effective ArtBox. If not defined, fall back to | 185 | // Return the effective ArtBox. If not defined, fall back to |
| 189 | // CropBox. | 186 | // CropBox. |
| 190 | QPDF_DLL | 187 | QPDF_DLL |
| 191 | - QPDFObjectHandle | ||
| 192 | - getArtBox(bool copy_if_shared = false, bool copy_if_fallback = false); | 188 | + QPDFObjectHandle getArtBox(bool copy_if_shared = false, bool copy_if_fallback = false); |
| 193 | 189 | ||
| 194 | // Iterate through XObjects, possibly recursing into form | 190 | // Iterate through XObjects, possibly recursing into form |
| 195 | // XObjects. This works with pages or form XObjects. Call action | 191 | // XObjects. This works with pages or form XObjects. Call action |
| @@ -203,26 +199,20 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | @@ -203,26 +199,20 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | ||
| 203 | void forEachXObject( | 199 | void forEachXObject( |
| 204 | bool recursive, | 200 | bool recursive, |
| 205 | std::function<void( | 201 | std::function<void( |
| 206 | - QPDFObjectHandle& obj, | ||
| 207 | - QPDFObjectHandle& xobj_dict, | ||
| 208 | - std::string const& key)> action, | 202 | + QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)> action, |
| 209 | std::function<bool(QPDFObjectHandle)> selector = nullptr); | 203 | std::function<bool(QPDFObjectHandle)> selector = nullptr); |
| 210 | // Only call action for images | 204 | // Only call action for images |
| 211 | QPDF_DLL | 205 | QPDF_DLL |
| 212 | void forEachImage( | 206 | void forEachImage( |
| 213 | bool recursive, | 207 | bool recursive, |
| 214 | std::function<void( | 208 | std::function<void( |
| 215 | - QPDFObjectHandle& obj, | ||
| 216 | - QPDFObjectHandle& xobj_dict, | ||
| 217 | - std::string const& key)> action); | 209 | + QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)> action); |
| 218 | // Only call action for form XObjects | 210 | // Only call action for form XObjects |
| 219 | QPDF_DLL | 211 | QPDF_DLL |
| 220 | void forEachFormXObject( | 212 | void forEachFormXObject( |
| 221 | bool recursive, | 213 | bool recursive, |
| 222 | std::function<void( | 214 | std::function<void( |
| 223 | - QPDFObjectHandle& obj, | ||
| 224 | - QPDFObjectHandle& xobj_dict, | ||
| 225 | - std::string const& key)> action); | 215 | + QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)> action); |
| 226 | 216 | ||
| 227 | // Returns an empty map if there are no images or no resources. | 217 | // Returns an empty map if there are no images or no resources. |
| 228 | // Prior to qpdf 8.4.0, this function did not support inherited | 218 | // Prior to qpdf 8.4.0, this function did not support inherited |
| @@ -258,8 +248,7 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | @@ -258,8 +248,7 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | ||
| 258 | // only_subtype is non-empty, only include annotations of the | 248 | // only_subtype is non-empty, only include annotations of the |
| 259 | // given subtype. | 249 | // given subtype. |
| 260 | QPDF_DLL | 250 | QPDF_DLL |
| 261 | - std::vector<QPDFAnnotationObjectHelper> | ||
| 262 | - getAnnotations(std::string const& only_subtype = ""); | 251 | + std::vector<QPDFAnnotationObjectHelper> getAnnotations(std::string const& only_subtype = ""); |
| 263 | 252 | ||
| 264 | // Returns a vector of stream objects representing the content | 253 | // Returns a vector of stream objects representing the content |
| 265 | // streams for the given page. This routine allows the caller to | 254 | // streams for the given page. This routine allows the caller to |
| @@ -319,13 +308,11 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | @@ -319,13 +308,11 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | ||
| 319 | // contents, as happens with addContentTokenFilter. See | 308 | // contents, as happens with addContentTokenFilter. See |
| 320 | // examples/pdf-count-strings.cc for an example. | 309 | // examples/pdf-count-strings.cc for an example. |
| 321 | QPDF_DLL | 310 | QPDF_DLL |
| 322 | - void filterContents( | ||
| 323 | - QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr); | 311 | + void filterContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr); |
| 324 | 312 | ||
| 325 | // Old name -- calls filterContents() | 313 | // Old name -- calls filterContents() |
| 326 | QPDF_DLL | 314 | QPDF_DLL |
| 327 | - void filterPageContents( | ||
| 328 | - QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr); | 315 | + void filterPageContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next = nullptr); |
| 329 | 316 | ||
| 330 | // Pipe a page's contents through the given pipeline. This method | 317 | // Pipe a page's contents through the given pipeline. This method |
| 331 | // works whether the contents are a single stream or an array of | 318 | // works whether the contents are a single stream or an array of |
| @@ -341,8 +328,7 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | @@ -341,8 +328,7 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | ||
| 341 | // The token filter is applied to the page's contents as a single | 328 | // The token filter is applied to the page's contents as a single |
| 342 | // stream. Also works on form XObjects. | 329 | // stream. Also works on form XObjects. |
| 343 | QPDF_DLL | 330 | QPDF_DLL |
| 344 | - void addContentTokenFilter( | ||
| 345 | - std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter); | 331 | + void addContentTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter); |
| 346 | 332 | ||
| 347 | // A page's resources dictionary maps names to objects elsewhere | 333 | // A page's resources dictionary maps names to objects elsewhere |
| 348 | // in the file. This method walks through a page's contents and | 334 | // in the file. This method walks through a page's contents and |
| @@ -500,8 +486,8 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | @@ -500,8 +486,8 @@ class QPDFPageObjectHelper: public QPDFObjectHelper | ||
| 500 | bool copy_if_shared, | 486 | bool copy_if_shared, |
| 501 | std::function<QPDFObjectHandle()> get_fallback, | 487 | std::function<QPDFObjectHandle()> get_fallback, |
| 502 | bool copy_if_fallback); | 488 | bool copy_if_fallback); |
| 503 | - static bool removeUnreferencedResourcesHelper( | ||
| 504 | - QPDFPageObjectHelper ph, std::set<std::string>& unresolved); | 489 | + static bool |
| 490 | + removeUnreferencedResourcesHelper(QPDFPageObjectHelper ph, std::set<std::string>& unresolved); | ||
| 505 | 491 | ||
| 506 | class Members | 492 | class Members |
| 507 | { | 493 | { |
include/qpdf/QPDFSystemError.hh
| @@ -48,8 +48,7 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error | @@ -48,8 +48,7 @@ class QPDF_DLL_CLASS QPDFSystemError: public std::runtime_error | ||
| 48 | 48 | ||
| 49 | private: | 49 | private: |
| 50 | QPDF_DLL_PRIVATE | 50 | QPDF_DLL_PRIVATE |
| 51 | - static std::string | ||
| 52 | - createWhat(std::string const& description, int system_errno); | 51 | + static std::string createWhat(std::string const& description, int system_errno); |
| 53 | 52 | ||
| 54 | // This class does not use the Members pattern to avoid needless | 53 | // This class does not use the Members pattern to avoid needless |
| 55 | // memory allocations during exception handling. | 54 | // memory allocations during exception handling. |
include/qpdf/QPDFTokenizer.hh
| @@ -104,8 +104,7 @@ class QPDFTokenizer | @@ -104,8 +104,7 @@ class QPDFTokenizer | ||
| 104 | { | 104 | { |
| 105 | // Ignore fields other than type and value | 105 | // Ignore fields other than type and value |
| 106 | return ( | 106 | return ( |
| 107 | - (this->type != tt_bad) && (this->type == rhs.type) && | ||
| 108 | - (this->value == rhs.value)); | 107 | + (this->type != tt_bad) && (this->type == rhs.type) && (this->value == rhs.value)); |
| 109 | } | 108 | } |
| 110 | bool | 109 | bool |
| 111 | isInteger() const | 110 | isInteger() const |
| @@ -216,8 +215,7 @@ class QPDFTokenizer | @@ -216,8 +215,7 @@ class QPDFTokenizer | ||
| 216 | // beginning of the token. Returns false if the token is bad | 215 | // beginning of the token. Returns false if the token is bad |
| 217 | // or if scanning produced an error message for any reason. | 216 | // or if scanning produced an error message for any reason. |
| 218 | 217 | ||
| 219 | - bool nextToken( | ||
| 220 | - InputSource& input, std::string const& context, size_t max_len = 0); | 218 | + bool nextToken(InputSource& input, std::string const& context, size_t max_len = 0); |
| 221 | 219 | ||
| 222 | // The following methods are only valid after nextToken has been called | 220 | // The following methods are only valid after nextToken has been called |
| 223 | // and until another QPDFTokenizer method is called. They allow the results | 221 | // and until another QPDFTokenizer method is called. They allow the results |
| @@ -317,8 +315,7 @@ QPDFTokenizer::getType() const noexcept | @@ -317,8 +315,7 @@ QPDFTokenizer::getType() const noexcept | ||
| 317 | inline std::string const& | 315 | inline std::string const& |
| 318 | QPDFTokenizer::getValue() const noexcept | 316 | QPDFTokenizer::getValue() const noexcept |
| 319 | { | 317 | { |
| 320 | - return (this->type == tt_name || this->type == tt_string) ? this->val | ||
| 321 | - : this->raw_val; | 318 | + return (this->type == tt_name || this->type == tt_string) ? this->val : this->raw_val; |
| 322 | } | 319 | } |
| 323 | inline std::string const& | 320 | inline std::string const& |
| 324 | QPDFTokenizer::getRawValue() const noexcept | 321 | QPDFTokenizer::getRawValue() const noexcept |
include/qpdf/QPDFWriter.hh
| @@ -561,16 +561,11 @@ class QPDFWriter | @@ -561,16 +561,11 @@ class QPDFWriter | ||
| 561 | void writePad(size_t nspaces); | 561 | void writePad(size_t nspaces); |
| 562 | void assignCompressedObjectNumbers(QPDFObjGen const& og); | 562 | void assignCompressedObjectNumbers(QPDFObjGen const& og); |
| 563 | void enqueueObject(QPDFObjectHandle object); | 563 | void enqueueObject(QPDFObjectHandle object); |
| 564 | - void writeObjectStreamOffsets( | ||
| 565 | - std::vector<qpdf_offset_t>& offsets, int first_obj); | 564 | + void writeObjectStreamOffsets(std::vector<qpdf_offset_t>& offsets, int first_obj); |
| 566 | void writeObjectStream(QPDFObjectHandle object); | 565 | void writeObjectStream(QPDFObjectHandle object); |
| 567 | void writeObject(QPDFObjectHandle object, int object_stream_index = -1); | 566 | void writeObject(QPDFObjectHandle object, int object_stream_index = -1); |
| 568 | void writeTrailer( | 567 | void writeTrailer( |
| 569 | - trailer_e which, | ||
| 570 | - int size, | ||
| 571 | - bool xref_stream, | ||
| 572 | - qpdf_offset_t prev, | ||
| 573 | - int linearization_pass); | 568 | + trailer_e which, int size, bool xref_stream, qpdf_offset_t prev, int linearization_pass); |
| 574 | bool willFilterStream( | 569 | bool willFilterStream( |
| 575 | QPDFObjectHandle stream, | 570 | QPDFObjectHandle stream, |
| 576 | bool& compress_stream, | 571 | bool& compress_stream, |
| @@ -601,8 +596,7 @@ class QPDFWriter | @@ -601,8 +596,7 @@ class QPDFWriter | ||
| 601 | bool allow_modify_other, | 596 | bool allow_modify_other, |
| 602 | qpdf_r3_print_e print, | 597 | qpdf_r3_print_e print, |
| 603 | qpdf_r3_modify_e modify); | 598 | qpdf_r3_modify_e modify); |
| 604 | - void | ||
| 605 | - disableIncompatibleEncryption(int major, int minor, int extension_level); | 599 | + void disableIncompatibleEncryption(int major, int minor, int extension_level); |
| 606 | void parseVersion(std::string const& version, int& major, int& minor) const; | 600 | void parseVersion(std::string const& version, int& major, int& minor) const; |
| 607 | int compareVersions(int major1, int minor1, int major2, int minor2) const; | 601 | int compareVersions(int major1, int minor1, int major2, int minor2) const; |
| 608 | void setEncryptionParameters( | 602 | void setEncryptionParameters( |
| @@ -640,8 +634,7 @@ class QPDFWriter | @@ -640,8 +634,7 @@ class QPDFWriter | ||
| 640 | void doWriteSetup(); | 634 | void doWriteSetup(); |
| 641 | void writeHeader(); | 635 | void writeHeader(); |
| 642 | void writeHintStream(int hint_id); | 636 | void writeHintStream(int hint_id); |
| 643 | - qpdf_offset_t | ||
| 644 | - writeXRefTable(trailer_e which, int first, int last, int size); | 637 | + qpdf_offset_t writeXRefTable(trailer_e which, int first, int last, int size); |
| 645 | qpdf_offset_t writeXRefTable( | 638 | qpdf_offset_t writeXRefTable( |
| 646 | trailer_e which, | 639 | trailer_e which, |
| 647 | int first, | 640 | int first, |
| @@ -693,8 +686,7 @@ class QPDFWriter | @@ -693,8 +686,7 @@ class QPDFWriter | ||
| 693 | void pushMD5Pipeline(PipelinePopper&); | 686 | void pushMD5Pipeline(PipelinePopper&); |
| 694 | void computeDeterministicIDData(); | 687 | void computeDeterministicIDData(); |
| 695 | 688 | ||
| 696 | - void discardGeneration( | ||
| 697 | - std::map<QPDFObjGen, int> const& in, std::map<int, int>& out); | 689 | + void discardGeneration(std::map<QPDFObjGen, int> const& in, std::map<int, int>& out); |
| 698 | 690 | ||
| 699 | class Members | 691 | class Members |
| 700 | { | 692 | { |
include/qpdf/QUtil.hh
| @@ -49,11 +49,9 @@ namespace QUtil | @@ -49,11 +49,9 @@ namespace QUtil | ||
| 49 | QPDF_DLL | 49 | QPDF_DLL |
| 50 | std::string int_to_string_base(long long, int base, int length = 0); | 50 | std::string int_to_string_base(long long, int base, int length = 0); |
| 51 | QPDF_DLL | 51 | QPDF_DLL |
| 52 | - std::string | ||
| 53 | - uint_to_string_base(unsigned long long, int base, int length = 0); | 52 | + std::string uint_to_string_base(unsigned long long, int base, int length = 0); |
| 54 | QPDF_DLL | 53 | QPDF_DLL |
| 55 | - std::string double_to_string( | ||
| 56 | - double, int decimal_places = 0, bool trim_trailing_zeroes = true); | 54 | + std::string double_to_string(double, int decimal_places = 0, bool trim_trailing_zeroes = true); |
| 57 | 55 | ||
| 58 | // These string to number methods throw std::runtime_error on | 56 | // These string to number methods throw std::runtime_error on |
| 59 | // underflow/overflow. | 57 | // underflow/overflow. |
| @@ -257,14 +255,7 @@ namespace QUtil | @@ -257,14 +255,7 @@ namespace QUtil | ||
| 257 | QPDFTime() = default; | 255 | QPDFTime() = default; |
| 258 | QPDFTime(QPDFTime const&) = default; | 256 | QPDFTime(QPDFTime const&) = default; |
| 259 | QPDFTime& operator=(QPDFTime const&) = default; | 257 | QPDFTime& operator=(QPDFTime const&) = default; |
| 260 | - QPDFTime( | ||
| 261 | - int year, | ||
| 262 | - int month, | ||
| 263 | - int day, | ||
| 264 | - int hour, | ||
| 265 | - int minute, | ||
| 266 | - int second, | ||
| 267 | - int tz_delta) : | 258 | + QPDFTime(int year, int month, int day, int hour, int minute, int second, int tz_delta) : |
| 268 | year(year), | 259 | year(year), |
| 269 | month(month), | 260 | month(month), |
| 270 | day(day), | 261 | day(day), |
| @@ -331,8 +322,7 @@ namespace QUtil | @@ -331,8 +322,7 @@ namespace QUtil | ||
| 331 | // to pass a value of pos that is greater than or equal to the | 322 | // to pass a value of pos that is greater than or equal to the |
| 332 | // length of the string. | 323 | // length of the string. |
| 333 | QPDF_DLL | 324 | QPDF_DLL |
| 334 | - unsigned long get_next_utf8_codepoint( | ||
| 335 | - std::string const& utf8_val, size_t& pos, bool& error); | 325 | + unsigned long get_next_utf8_codepoint(std::string const& utf8_val, size_t& pos, bool& error); |
| 336 | 326 | ||
| 337 | // Test whether this is a UTF-16 string. This is indicated by | 327 | // Test whether this is a UTF-16 string. This is indicated by |
| 338 | // first two bytes being 0xFE 0xFF (big-endian) or 0xFF 0xFE | 328 | // first two bytes being 0xFE 0xFF (big-endian) or 0xFF 0xFE |
| @@ -360,30 +350,23 @@ namespace QUtil | @@ -360,30 +350,23 @@ namespace QUtil | ||
| 360 | QPDF_DLL | 350 | QPDF_DLL |
| 361 | std::string utf8_to_ascii(std::string const& utf8, char unknown_char = '?'); | 351 | std::string utf8_to_ascii(std::string const& utf8, char unknown_char = '?'); |
| 362 | QPDF_DLL | 352 | QPDF_DLL |
| 363 | - std::string | ||
| 364 | - utf8_to_win_ansi(std::string const& utf8, char unknown_char = '?'); | 353 | + std::string utf8_to_win_ansi(std::string const& utf8, char unknown_char = '?'); |
| 365 | QPDF_DLL | 354 | QPDF_DLL |
| 366 | - std::string | ||
| 367 | - utf8_to_mac_roman(std::string const& utf8, char unknown_char = '?'); | 355 | + std::string utf8_to_mac_roman(std::string const& utf8, char unknown_char = '?'); |
| 368 | QPDF_DLL | 356 | QPDF_DLL |
| 369 | - std::string | ||
| 370 | - utf8_to_pdf_doc(std::string const& utf8, char unknown_char = '?'); | 357 | + std::string utf8_to_pdf_doc(std::string const& utf8, char unknown_char = '?'); |
| 371 | 358 | ||
| 372 | // These versions return true if the conversion was successful and | 359 | // These versions return true if the conversion was successful and |
| 373 | // false if any unrepresentable characters were found and had to | 360 | // false if any unrepresentable characters were found and had to |
| 374 | // be substituted with the unknown character. | 361 | // be substituted with the unknown character. |
| 375 | QPDF_DLL | 362 | QPDF_DLL |
| 376 | - bool utf8_to_ascii( | ||
| 377 | - std::string const& utf8, std::string& ascii, char unknown_char = '?'); | 363 | + bool utf8_to_ascii(std::string const& utf8, std::string& ascii, char unknown_char = '?'); |
| 378 | QPDF_DLL | 364 | QPDF_DLL |
| 379 | - bool utf8_to_win_ansi( | ||
| 380 | - std::string const& utf8, std::string& win, char unknown_char = '?'); | 365 | + bool utf8_to_win_ansi(std::string const& utf8, std::string& win, char unknown_char = '?'); |
| 381 | QPDF_DLL | 366 | QPDF_DLL |
| 382 | - bool utf8_to_mac_roman( | ||
| 383 | - std::string const& utf8, std::string& mac, char unknown_char = '?'); | 367 | + bool utf8_to_mac_roman(std::string const& utf8, std::string& mac, char unknown_char = '?'); |
| 384 | QPDF_DLL | 368 | QPDF_DLL |
| 385 | - bool utf8_to_pdf_doc( | ||
| 386 | - std::string const& utf8, std::string& pdfdoc, char unknown_char = '?'); | 369 | + bool utf8_to_pdf_doc(std::string const& utf8, std::string& pdfdoc, char unknown_char = '?'); |
| 387 | 370 | ||
| 388 | // Convert a UTF-16 encoded string to UTF-8. Unrepresentable code | 371 | // Convert a UTF-16 encoded string to UTF-8. Unrepresentable code |
| 389 | // points are converted to U+FFFD. | 372 | // points are converted to U+FFFD. |
| @@ -412,10 +395,7 @@ namespace QUtil | @@ -412,10 +395,7 @@ namespace QUtil | ||
| 412 | // about everything else) accepts UTF-16LE (as of 10.6.2). | 395 | // about everything else) accepts UTF-16LE (as of 10.6.2). |
| 413 | QPDF_DLL | 396 | QPDF_DLL |
| 414 | void analyze_encoding( | 397 | void analyze_encoding( |
| 415 | - std::string const& str, | ||
| 416 | - bool& has_8bit_chars, | ||
| 417 | - bool& is_valid_utf8, | ||
| 418 | - bool& is_utf16); | 398 | + std::string const& str, bool& has_8bit_chars, bool& is_valid_utf8, bool& is_utf16); |
| 419 | 399 | ||
| 420 | // Try to compensate for previously incorrectly encoded strings. | 400 | // Try to compensate for previously incorrectly encoded strings. |
| 421 | // We want to compensate for the following errors: | 401 | // We want to compensate for the following errors: |
| @@ -472,14 +452,11 @@ namespace QUtil | @@ -472,14 +452,11 @@ namespace QUtil | ||
| 472 | // Filename is UTF-8 encoded, even on Windows, as described in the | 452 | // Filename is UTF-8 encoded, even on Windows, as described in the |
| 473 | // comments for safe_fopen. | 453 | // comments for safe_fopen. |
| 474 | QPDF_DLL | 454 | QPDF_DLL |
| 475 | - std::list<std::string> | ||
| 476 | - read_lines_from_file(char const* filename, bool preserve_eol = false); | 455 | + std::list<std::string> read_lines_from_file(char const* filename, bool preserve_eol = false); |
| 477 | QPDF_DLL | 456 | QPDF_DLL |
| 478 | - std::list<std::string> | ||
| 479 | - read_lines_from_file(std::istream&, bool preserve_eol = false); | 457 | + std::list<std::string> read_lines_from_file(std::istream&, bool preserve_eol = false); |
| 480 | QPDF_DLL | 458 | QPDF_DLL |
| 481 | - std::list<std::string> | ||
| 482 | - read_lines_from_file(FILE*, bool preserve_eol = false); | 459 | + std::list<std::string> read_lines_from_file(FILE*, bool preserve_eol = false); |
| 483 | QPDF_DLL | 460 | QPDF_DLL |
| 484 | void read_lines_from_file( | 461 | void read_lines_from_file( |
| 485 | std::function<bool(char&)> next_char, | 462 | std::function<bool(char&)> next_char, |
| @@ -487,8 +464,7 @@ namespace QUtil | @@ -487,8 +464,7 @@ namespace QUtil | ||
| 487 | bool preserve_eol = false); | 464 | bool preserve_eol = false); |
| 488 | 465 | ||
| 489 | QPDF_DLL | 466 | QPDF_DLL |
| 490 | - void read_file_into_memory( | ||
| 491 | - char const* filename, std::shared_ptr<char>& file_buf, size_t& size); | 467 | + void read_file_into_memory(char const* filename, std::shared_ptr<char>& file_buf, size_t& size); |
| 492 | 468 | ||
| 493 | QPDF_DLL | 469 | QPDF_DLL |
| 494 | std::string read_file_into_string(char const* filename); | 470 | std::string read_file_into_string(char const* filename); |
| @@ -532,8 +508,7 @@ namespace QUtil | @@ -532,8 +508,7 @@ namespace QUtil | ||
| 532 | // invoked, convert all UTF-16 encoded strings to UTF-8, and call | 508 | // invoked, convert all UTF-16 encoded strings to UTF-8, and call |
| 533 | // another main. | 509 | // another main. |
| 534 | QPDF_DLL | 510 | QPDF_DLL |
| 535 | - int call_main_from_wmain( | ||
| 536 | - int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain); | 511 | + int call_main_from_wmain(int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain); |
| 537 | QPDF_DLL | 512 | QPDF_DLL |
| 538 | int call_main_from_wmain( | 513 | int call_main_from_wmain( |
| 539 | int argc, | 514 | int argc, |
| @@ -561,8 +536,7 @@ QUtil::is_hex_digit(char ch) | @@ -561,8 +536,7 @@ QUtil::is_hex_digit(char ch) | ||
| 561 | inline bool | 536 | inline bool |
| 562 | QUtil::is_space(char ch) | 537 | QUtil::is_space(char ch) |
| 563 | { | 538 | { |
| 564 | - return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f' || | ||
| 565 | - ch == '\v'; | 539 | + return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f' || ch == '\v'; |
| 566 | } | 540 | } |
| 567 | 541 | ||
| 568 | inline bool | 542 | inline bool |
| @@ -603,8 +577,7 @@ inline std::string | @@ -603,8 +577,7 @@ inline std::string | ||
| 603 | QUtil::hex_encode_char(char c) | 577 | QUtil::hex_encode_char(char c) |
| 604 | { | 578 | { |
| 605 | static auto constexpr hexchars = "0123456789abcdef"; | 579 | static auto constexpr hexchars = "0123456789abcdef"; |
| 606 | - return { | ||
| 607 | - '#', hexchars[static_cast<unsigned char>(c) >> 4], hexchars[c & 0x0f]}; | 580 | + return {'#', hexchars[static_cast<unsigned char>(c) >> 4], hexchars[c & 0x0f]}; |
| 608 | } | 581 | } |
| 609 | 582 | ||
| 610 | inline constexpr char | 583 | inline constexpr char |
| @@ -612,8 +585,7 @@ QUtil::hex_decode_char(char digit) noexcept | @@ -612,8 +585,7 @@ QUtil::hex_decode_char(char digit) noexcept | ||
| 612 | { | 585 | { |
| 613 | return digit <= '9' && digit >= '0' | 586 | return digit <= '9' && digit >= '0' |
| 614 | ? char(digit - '0') | 587 | ? char(digit - '0') |
| 615 | - : (digit >= 'a' ? char(digit - 'a' + 10) | ||
| 616 | - : (digit >= 'A' ? char(digit - 'A' + 10) : '\20')); | 588 | + : (digit >= 'a' ? char(digit - 'a' + 10) : (digit >= 'A' ? char(digit - 'A' + 10) : '\20')); |
| 617 | } | 589 | } |
| 618 | 590 | ||
| 619 | #endif // QUTIL_HH | 591 | #endif // QUTIL_HH |
include/qpdf/qpdf-c.h
| @@ -326,8 +326,7 @@ extern "C" { | @@ -326,8 +326,7 @@ extern "C" { | ||
| 326 | */ | 326 | */ |
| 327 | QPDF_DLL | 327 | QPDF_DLL |
| 328 | QPDF_ERROR_CODE | 328 | QPDF_ERROR_CODE |
| 329 | - qpdf_create_from_json_data( | ||
| 330 | - qpdf_data qpdf, char const* buffer, unsigned long long size); | 329 | + qpdf_create_from_json_data(qpdf_data qpdf, char const* buffer, unsigned long long size); |
| 331 | 330 | ||
| 332 | /* JSON UPDATE FUNCTIONS */ | 331 | /* JSON UPDATE FUNCTIONS */ |
| 333 | 332 | ||
| @@ -341,8 +340,7 @@ extern "C" { | @@ -341,8 +340,7 @@ extern "C" { | ||
| 341 | qpdf_update_from_json_file(qpdf_data qpdf, char const* filename); | 340 | qpdf_update_from_json_file(qpdf_data qpdf, char const* filename); |
| 342 | QPDF_DLL | 341 | QPDF_DLL |
| 343 | QPDF_ERROR_CODE | 342 | QPDF_ERROR_CODE |
| 344 | - qpdf_update_from_json_data( | ||
| 345 | - qpdf_data qpdf, char const* buffer, unsigned long long size); | 343 | + qpdf_update_from_json_data(qpdf_data qpdf, char const* buffer, unsigned long long size); |
| 346 | 344 | ||
| 347 | /* READ FUNCTIONS */ | 345 | /* READ FUNCTIONS */ |
| 348 | 346 | ||
| @@ -492,23 +490,19 @@ extern "C" { | @@ -492,23 +490,19 @@ extern "C" { | ||
| 492 | unsigned char const* qpdf_get_buffer(qpdf_data qpdf); | 490 | unsigned char const* qpdf_get_buffer(qpdf_data qpdf); |
| 493 | 491 | ||
| 494 | QPDF_DLL | 492 | QPDF_DLL |
| 495 | - void | ||
| 496 | - qpdf_set_object_stream_mode(qpdf_data qpdf, enum qpdf_object_stream_e mode); | 493 | + void qpdf_set_object_stream_mode(qpdf_data qpdf, enum qpdf_object_stream_e mode); |
| 497 | 494 | ||
| 498 | QPDF_DLL | 495 | QPDF_DLL |
| 499 | - void | ||
| 500 | - qpdf_set_stream_data_mode(qpdf_data qpdf, enum qpdf_stream_data_e mode); | 496 | + void qpdf_set_stream_data_mode(qpdf_data qpdf, enum qpdf_stream_data_e mode); |
| 501 | 497 | ||
| 502 | QPDF_DLL | 498 | QPDF_DLL |
| 503 | void qpdf_set_compress_streams(qpdf_data qpdf, QPDF_BOOL value); | 499 | void qpdf_set_compress_streams(qpdf_data qpdf, QPDF_BOOL value); |
| 504 | 500 | ||
| 505 | QPDF_DLL | 501 | QPDF_DLL |
| 506 | - void qpdf_set_decode_level( | ||
| 507 | - qpdf_data qpdf, enum qpdf_stream_decode_level_e level); | 502 | + void qpdf_set_decode_level(qpdf_data qpdf, enum qpdf_stream_decode_level_e level); |
| 508 | 503 | ||
| 509 | QPDF_DLL | 504 | QPDF_DLL |
| 510 | - void | ||
| 511 | - qpdf_set_preserve_unreferenced_objects(qpdf_data qpdf, QPDF_BOOL value); | 505 | + void qpdf_set_preserve_unreferenced_objects(qpdf_data qpdf, QPDF_BOOL value); |
| 512 | 506 | ||
| 513 | QPDF_DLL | 507 | QPDF_DLL |
| 514 | void qpdf_set_newline_before_endstream(qpdf_data qpdf, QPDF_BOOL value); | 508 | void qpdf_set_newline_before_endstream(qpdf_data qpdf, QPDF_BOOL value); |
| @@ -625,8 +619,8 @@ extern "C" { | @@ -625,8 +619,8 @@ extern "C" { | ||
| 625 | void qpdf_force_pdf_version(qpdf_data qpdf, char const* version); | 619 | void qpdf_force_pdf_version(qpdf_data qpdf, char const* version); |
| 626 | 620 | ||
| 627 | QPDF_DLL | 621 | QPDF_DLL |
| 628 | - void qpdf_force_pdf_version_and_extension( | ||
| 629 | - qpdf_data qpdf, char const* version, int extension_level); | 622 | + void |
| 623 | + qpdf_force_pdf_version_and_extension(qpdf_data qpdf, char const* version, int extension_level); | ||
| 630 | 624 | ||
| 631 | /* During write, your report_progress function will be called with | 625 | /* During write, your report_progress function will be called with |
| 632 | * a value between 0 and 100 representing the approximate write | 626 | * a value between 0 and 100 representing the approximate write |
| @@ -640,9 +634,7 @@ extern "C" { | @@ -640,9 +634,7 @@ extern "C" { | ||
| 640 | */ | 634 | */ |
| 641 | QPDF_DLL | 635 | QPDF_DLL |
| 642 | void qpdf_register_progress_reporter( | 636 | void qpdf_register_progress_reporter( |
| 643 | - qpdf_data qpdf, | ||
| 644 | - void (*report_progress)(int percent, void* data), | ||
| 645 | - void* data); | 637 | + qpdf_data qpdf, void (*report_progress)(int percent, void* data), void* data); |
| 646 | 638 | ||
| 647 | /* Do actual write operation. */ | 639 | /* Do actual write operation. */ |
| 648 | QPDF_DLL | 640 | QPDF_DLL |
| @@ -733,8 +725,7 @@ extern "C" { | @@ -733,8 +725,7 @@ extern "C" { | ||
| 733 | QPDF_DLL | 725 | QPDF_DLL |
| 734 | qpdf_oh qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh); | 726 | qpdf_oh qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh); |
| 735 | QPDF_DLL | 727 | QPDF_DLL |
| 736 | - void | ||
| 737 | - qpdf_replace_object(qpdf_data qpdf, int objid, int generation, qpdf_oh oh); | 728 | + void qpdf_replace_object(qpdf_data qpdf, int objid, int generation, qpdf_oh oh); |
| 738 | 729 | ||
| 739 | /* Wrappers around QPDFObjectHandle methods. Be sure to read | 730 | /* Wrappers around QPDFObjectHandle methods. Be sure to read |
| 740 | * corresponding comments in QPDFObjectHandle.hh to understand | 731 | * corresponding comments in QPDFObjectHandle.hh to understand |
| @@ -811,8 +802,7 @@ extern "C" { | @@ -811,8 +802,7 @@ extern "C" { | ||
| 811 | QPDF_DLL | 802 | QPDF_DLL |
| 812 | unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh); | 803 | unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh); |
| 813 | QPDF_DLL | 804 | QPDF_DLL |
| 814 | - QPDF_BOOL qpdf_oh_get_value_as_ulonglong( | ||
| 815 | - qpdf_data qpdf, qpdf_oh oh, unsigned long long* value); | 805 | + QPDF_BOOL qpdf_oh_get_value_as_ulonglong(qpdf_data qpdf, qpdf_oh oh, unsigned long long* value); |
| 816 | QPDF_DLL | 806 | QPDF_DLL |
| 817 | unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh); | 807 | unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh); |
| 818 | QPDF_DLL | 808 | QPDF_DLL |
| @@ -822,8 +812,8 @@ extern "C" { | @@ -822,8 +812,8 @@ extern "C" { | ||
| 822 | QPDF_DLL | 812 | QPDF_DLL |
| 823 | char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh); | 813 | char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh); |
| 824 | QPDF_DLL | 814 | QPDF_DLL |
| 825 | - QPDF_BOOL qpdf_oh_get_value_as_real( | ||
| 826 | - qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); | 815 | + QPDF_BOOL |
| 816 | + qpdf_oh_get_value_as_real(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); | ||
| 827 | 817 | ||
| 828 | QPDF_DLL | 818 | QPDF_DLL |
| 829 | QPDF_BOOL qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh); | 819 | QPDF_BOOL qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh); |
| @@ -836,8 +826,8 @@ extern "C" { | @@ -836,8 +826,8 @@ extern "C" { | ||
| 836 | QPDF_DLL | 826 | QPDF_DLL |
| 837 | char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh); | 827 | char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh); |
| 838 | QPDF_DLL | 828 | QPDF_DLL |
| 839 | - QPDF_BOOL qpdf_oh_get_value_as_name( | ||
| 840 | - qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); | 829 | + QPDF_BOOL |
| 830 | + qpdf_oh_get_value_as_name(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); | ||
| 841 | 831 | ||
| 842 | /* Return the length of the last string returned. This enables you | 832 | /* Return the length of the last string returned. This enables you |
| 843 | * to retrieve the entire string for cases in which a char* | 833 | * to retrieve the entire string for cases in which a char* |
| @@ -858,19 +848,17 @@ extern "C" { | @@ -858,19 +848,17 @@ extern "C" { | ||
| 858 | QPDF_DLL | 848 | QPDF_DLL |
| 859 | char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh); | 849 | char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh); |
| 860 | QPDF_DLL | 850 | QPDF_DLL |
| 861 | - QPDF_BOOL qpdf_oh_get_value_as_string( | ||
| 862 | - qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); | 851 | + QPDF_BOOL |
| 852 | + qpdf_oh_get_value_as_string(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); | ||
| 863 | QPDF_DLL | 853 | QPDF_DLL |
| 864 | char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh); | 854 | char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh); |
| 865 | QPDF_DLL | 855 | QPDF_DLL |
| 866 | - QPDF_BOOL qpdf_oh_get_value_as_utf8( | ||
| 867 | - qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); | 856 | + QPDF_BOOL |
| 857 | + qpdf_oh_get_value_as_utf8(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length); | ||
| 868 | QPDF_DLL | 858 | QPDF_DLL |
| 869 | - char const* | ||
| 870 | - qpdf_oh_get_binary_string_value(qpdf_data qpdf, qpdf_oh oh, size_t* length); | 859 | + char const* qpdf_oh_get_binary_string_value(qpdf_data qpdf, qpdf_oh oh, size_t* length); |
| 871 | QPDF_DLL | 860 | QPDF_DLL |
| 872 | - char const* | ||
| 873 | - qpdf_oh_get_binary_utf8_value(qpdf_data qpdf, qpdf_oh oh, size_t* length); | 861 | + char const* qpdf_oh_get_binary_utf8_value(qpdf_data qpdf, qpdf_oh oh, size_t* length); |
| 874 | 862 | ||
| 875 | QPDF_DLL | 863 | QPDF_DLL |
| 876 | int qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh); | 864 | int qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh); |
| @@ -906,8 +894,7 @@ extern "C" { | @@ -906,8 +894,7 @@ extern "C" { | ||
| 906 | QPDF_DLL | 894 | QPDF_DLL |
| 907 | qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key); | 895 | qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key); |
| 908 | QPDF_DLL | 896 | QPDF_DLL |
| 909 | - qpdf_oh | ||
| 910 | - qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key); | 897 | + qpdf_oh qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key); |
| 911 | 898 | ||
| 912 | QPDF_DLL | 899 | QPDF_DLL |
| 913 | QPDF_BOOL | 900 | QPDF_BOOL |
| @@ -924,8 +911,7 @@ extern "C" { | @@ -924,8 +911,7 @@ extern "C" { | ||
| 924 | QPDF_DLL | 911 | QPDF_DLL |
| 925 | qpdf_oh qpdf_oh_new_real_from_string(qpdf_data qpdf, char const* value); | 912 | qpdf_oh qpdf_oh_new_real_from_string(qpdf_data qpdf, char const* value); |
| 926 | QPDF_DLL | 913 | QPDF_DLL |
| 927 | - qpdf_oh qpdf_oh_new_real_from_double( | ||
| 928 | - qpdf_data qpdf, double value, int decimal_places); | 914 | + qpdf_oh qpdf_oh_new_real_from_double(qpdf_data qpdf, double value, int decimal_places); |
| 929 | QPDF_DLL | 915 | QPDF_DLL |
| 930 | qpdf_oh qpdf_oh_new_name(qpdf_data qpdf, char const* name); | 916 | qpdf_oh qpdf_oh_new_name(qpdf_data qpdf, char const* name); |
| 931 | QPDF_DLL | 917 | QPDF_DLL |
| @@ -936,11 +922,9 @@ extern "C" { | @@ -936,11 +922,9 @@ extern "C" { | ||
| 936 | * contain atrbitary binary data including embedded null characters. | 922 | * contain atrbitary binary data including embedded null characters. |
| 937 | */ | 923 | */ |
| 938 | QPDF_DLL | 924 | QPDF_DLL |
| 939 | - qpdf_oh | ||
| 940 | - qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length); | 925 | + qpdf_oh qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length); |
| 941 | QPDF_DLL | 926 | QPDF_DLL |
| 942 | - qpdf_oh qpdf_oh_new_binary_unicode_string( | ||
| 943 | - qpdf_data qpdf, char const* str, size_t length); | 927 | + qpdf_oh qpdf_oh_new_binary_unicode_string(qpdf_data qpdf, char const* str, size_t length); |
| 944 | QPDF_DLL | 928 | QPDF_DLL |
| 945 | qpdf_oh qpdf_oh_new_array(qpdf_data qpdf); | 929 | qpdf_oh qpdf_oh_new_array(qpdf_data qpdf); |
| 946 | QPDF_DLL | 930 | QPDF_DLL |
| @@ -959,8 +943,7 @@ extern "C" { | @@ -959,8 +943,7 @@ extern "C" { | ||
| 959 | void qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh); | 943 | void qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh); |
| 960 | 944 | ||
| 961 | QPDF_DLL | 945 | QPDF_DLL |
| 962 | - void | ||
| 963 | - qpdf_oh_set_array_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item); | 946 | + void qpdf_oh_set_array_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item); |
| 964 | QPDF_DLL | 947 | QPDF_DLL |
| 965 | void qpdf_oh_insert_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item); | 948 | void qpdf_oh_insert_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item); |
| 966 | QPDF_DLL | 949 | QPDF_DLL |
| @@ -969,13 +952,11 @@ extern "C" { | @@ -969,13 +952,11 @@ extern "C" { | ||
| 969 | void qpdf_oh_erase_item(qpdf_data qpdf, qpdf_oh oh, int at); | 952 | void qpdf_oh_erase_item(qpdf_data qpdf, qpdf_oh oh, int at); |
| 970 | 953 | ||
| 971 | QPDF_DLL | 954 | QPDF_DLL |
| 972 | - void qpdf_oh_replace_key( | ||
| 973 | - qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item); | 955 | + void qpdf_oh_replace_key(qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item); |
| 974 | QPDF_DLL | 956 | QPDF_DLL |
| 975 | void qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key); | 957 | void qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key); |
| 976 | QPDF_DLL | 958 | QPDF_DLL |
| 977 | - void qpdf_oh_replace_or_remove_key( | ||
| 978 | - qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item); | 959 | + void qpdf_oh_replace_or_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item); |
| 979 | 960 | ||
| 980 | QPDF_DLL | 961 | QPDF_DLL |
| 981 | qpdf_oh qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh); | 962 | qpdf_oh qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh); |
| @@ -1005,8 +986,7 @@ extern "C" { | @@ -1005,8 +986,7 @@ extern "C" { | ||
| 1005 | * while `foreign_oh` belongs to `other_qpdf`. | 986 | * while `foreign_oh` belongs to `other_qpdf`. |
| 1006 | */ | 987 | */ |
| 1007 | QPDF_DLL | 988 | QPDF_DLL |
| 1008 | - qpdf_oh qpdf_oh_copy_foreign_object( | ||
| 1009 | - qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh); | 989 | + qpdf_oh qpdf_oh_copy_foreign_object(qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh); |
| 1010 | 990 | ||
| 1011 | /* STREAM FUNCTIONS */ | 991 | /* STREAM FUNCTIONS */ |
| 1012 | 992 | ||
| @@ -1105,19 +1085,12 @@ extern "C" { | @@ -1105,19 +1085,12 @@ extern "C" { | ||
| 1105 | 1085 | ||
| 1106 | /* addPage() */ | 1086 | /* addPage() */ |
| 1107 | QPDF_DLL | 1087 | QPDF_DLL |
| 1108 | - QPDF_ERROR_CODE qpdf_add_page( | ||
| 1109 | - qpdf_data qpdf, | ||
| 1110 | - qpdf_data newpage_qpdf, | ||
| 1111 | - qpdf_oh newpage, | ||
| 1112 | - QPDF_BOOL first); | 1088 | + QPDF_ERROR_CODE |
| 1089 | + qpdf_add_page(qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL first); | ||
| 1113 | /* addPageAt() */ | 1090 | /* addPageAt() */ |
| 1114 | QPDF_DLL | 1091 | QPDF_DLL |
| 1115 | QPDF_ERROR_CODE qpdf_add_page_at( | 1092 | QPDF_ERROR_CODE qpdf_add_page_at( |
| 1116 | - qpdf_data qpdf, | ||
| 1117 | - qpdf_data newpage_qpdf, | ||
| 1118 | - qpdf_oh newpage, | ||
| 1119 | - QPDF_BOOL before, | ||
| 1120 | - qpdf_oh refpage); | 1093 | + qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL before, qpdf_oh refpage); |
| 1121 | /* removePage() */ | 1094 | /* removePage() */ |
| 1122 | QPDF_DLL | 1095 | QPDF_DLL |
| 1123 | QPDF_ERROR_CODE qpdf_remove_page(qpdf_data qpdf, qpdf_oh page); | 1096 | QPDF_ERROR_CODE qpdf_remove_page(qpdf_data qpdf, qpdf_oh page); |
include/qpdf/qpdfjob-c.h
| @@ -111,8 +111,7 @@ extern "C" { | @@ -111,8 +111,7 @@ extern "C" { | ||
| 111 | * is invalid to call any other functions this job handle. | 111 | * is invalid to call any other functions this job handle. |
| 112 | */ | 112 | */ |
| 113 | QPDF_DLL | 113 | QPDF_DLL |
| 114 | - int | ||
| 115 | - qpdfjob_initialize_from_argv(qpdfjob_handle j, char const* const argv[]); | 114 | + int qpdfjob_initialize_from_argv(qpdfjob_handle j, char const* const argv[]); |
| 116 | 115 | ||
| 117 | #ifndef QPDF_NO_WCHAR_T | 116 | #ifndef QPDF_NO_WCHAR_T |
| 118 | /* This function is the same as qpdfjob_initialize_from_argv | 117 | /* This function is the same as qpdfjob_initialize_from_argv |
| @@ -120,8 +119,7 @@ extern "C" { | @@ -120,8 +119,7 @@ extern "C" { | ||
| 120 | * suitable for calling from a Windows wmain function. | 119 | * suitable for calling from a Windows wmain function. |
| 121 | */ | 120 | */ |
| 122 | QPDF_DLL | 121 | QPDF_DLL |
| 123 | - int qpdfjob_initialize_from_wide_argv( | ||
| 124 | - qpdfjob_handle j, wchar_t const* const argv[]); | 122 | + int qpdfjob_initialize_from_wide_argv(qpdfjob_handle j, wchar_t const* const argv[]); |
| 125 | #endif /* QPDF_NO_WCHAR_T */ | 123 | #endif /* QPDF_NO_WCHAR_T */ |
| 126 | 124 | ||
| 127 | /* This function wraps QPDFJob::initializeFromJson. The return | 125 | /* This function wraps QPDFJob::initializeFromJson. The return |
| @@ -167,9 +165,7 @@ extern "C" { | @@ -167,9 +165,7 @@ extern "C" { | ||
| 167 | */ | 165 | */ |
| 168 | QPDF_DLL | 166 | QPDF_DLL |
| 169 | void qpdfjob_register_progress_reporter( | 167 | void qpdfjob_register_progress_reporter( |
| 170 | - qpdfjob_handle j, | ||
| 171 | - void (*report_progress)(int percent, void* data), | ||
| 172 | - void* data); | 168 | + qpdfjob_handle j, void (*report_progress)(int percent, void* data), void* data); |
| 173 | 169 | ||
| 174 | #ifdef __cplusplus | 170 | #ifdef __cplusplus |
| 175 | } | 171 | } |
include/qpdf/qpdflogger-c.h
| @@ -76,22 +76,13 @@ extern "C" { | @@ -76,22 +76,13 @@ extern "C" { | ||
| 76 | 76 | ||
| 77 | QPDF_DLL | 77 | QPDF_DLL |
| 78 | void qpdflogger_set_info( | 78 | void qpdflogger_set_info( |
| 79 | - qpdflogger_handle l, | ||
| 80 | - enum qpdf_log_dest_e dest, | ||
| 81 | - qpdf_log_fn_t fn, | ||
| 82 | - void* udata); | 79 | + qpdflogger_handle l, enum qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata); |
| 83 | QPDF_DLL | 80 | QPDF_DLL |
| 84 | void qpdflogger_set_warn( | 81 | void qpdflogger_set_warn( |
| 85 | - qpdflogger_handle l, | ||
| 86 | - enum qpdf_log_dest_e dest, | ||
| 87 | - qpdf_log_fn_t fn, | ||
| 88 | - void* udata); | 82 | + qpdflogger_handle l, enum qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata); |
| 89 | QPDF_DLL | 83 | QPDF_DLL |
| 90 | void qpdflogger_set_error( | 84 | void qpdflogger_set_error( |
| 91 | - qpdflogger_handle l, | ||
| 92 | - enum qpdf_log_dest_e dest, | ||
| 93 | - qpdf_log_fn_t fn, | ||
| 94 | - void* udata); | 85 | + qpdflogger_handle l, enum qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata); |
| 95 | 86 | ||
| 96 | /* A non-zero value for only_if_not_set means that the save | 87 | /* A non-zero value for only_if_not_set means that the save |
| 97 | * pipeline will only be changed if it is not already set. | 88 | * pipeline will only be changed if it is not already set. |
| @@ -104,8 +95,7 @@ extern "C" { | @@ -104,8 +95,7 @@ extern "C" { | ||
| 104 | void* udata, | 95 | void* udata, |
| 105 | int only_if_not_set); | 96 | int only_if_not_set); |
| 106 | QPDF_DLL | 97 | QPDF_DLL |
| 107 | - void qpdflogger_save_to_standard_output( | ||
| 108 | - qpdflogger_handle l, int only_if_not_set); | 98 | + void qpdflogger_save_to_standard_output(qpdflogger_handle l, int only_if_not_set); |
| 109 | 99 | ||
| 110 | /* For testing */ | 100 | /* For testing */ |
| 111 | QPDF_DLL | 101 | QPDF_DLL |
libqpdf/AES_PDF_native.cc
| @@ -27,11 +27,9 @@ AES_PDF_native::AES_PDF_native( | @@ -27,11 +27,9 @@ AES_PDF_native::AES_PDF_native( | ||
| 27 | std::memcpy(this->key.get(), key, key_bytes); | 27 | std::memcpy(this->key.get(), key, key_bytes); |
| 28 | std::memset(this->rk.get(), 0, rk_bytes); | 28 | std::memset(this->rk.get(), 0, rk_bytes); |
| 29 | if (encrypt) { | 29 | if (encrypt) { |
| 30 | - this->nrounds = | ||
| 31 | - rijndaelSetupEncrypt(this->rk.get(), this->key.get(), keybits); | 30 | + this->nrounds = rijndaelSetupEncrypt(this->rk.get(), this->key.get(), keybits); |
| 32 | } else { | 31 | } else { |
| 33 | - this->nrounds = | ||
| 34 | - rijndaelSetupDecrypt(this->rk.get(), this->key.get(), keybits); | 32 | + this->nrounds = rijndaelSetupDecrypt(this->rk.get(), this->key.get(), keybits); |
| 35 | } | 33 | } |
| 36 | } | 34 | } |
| 37 | 35 | ||
| @@ -46,8 +44,7 @@ AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data) | @@ -46,8 +44,7 @@ AES_PDF_native::update(unsigned char* in_data, unsigned char* out_data) | ||
| 46 | } | 44 | } |
| 47 | rijndaelEncrypt(this->rk.get(), this->nrounds, in_data, out_data); | 45 | rijndaelEncrypt(this->rk.get(), this->nrounds, in_data, out_data); |
| 48 | if (this->cbc_mode) { | 46 | if (this->cbc_mode) { |
| 49 | - memcpy( | ||
| 50 | - this->cbc_block, out_data, QPDFCryptoImpl::rijndael_buf_size); | 47 | + memcpy(this->cbc_block, out_data, QPDFCryptoImpl::rijndael_buf_size); |
| 51 | } | 48 | } |
| 52 | } else { | 49 | } else { |
| 53 | rijndaelDecrypt(this->rk.get(), this->nrounds, in_data, out_data); | 50 | rijndaelDecrypt(this->rk.get(), this->nrounds, in_data, out_data); |
libqpdf/BitStream.cc
| @@ -33,8 +33,7 @@ BitStream::getBits(size_t nbits) | @@ -33,8 +33,7 @@ BitStream::getBits(size_t nbits) | ||
| 33 | long long | 33 | long long |
| 34 | BitStream::getBitsSigned(size_t nbits) | 34 | BitStream::getBitsSigned(size_t nbits) |
| 35 | { | 35 | { |
| 36 | - unsigned long long bits = | ||
| 37 | - read_bits(this->p, this->bit_offset, this->bits_available, nbits); | 36 | + unsigned long long bits = read_bits(this->p, this->bit_offset, this->bits_available, nbits); |
| 38 | long long result = 0; | 37 | long long result = 0; |
| 39 | if (static_cast<long long>(bits) > 1LL << (nbits - 1)) { | 38 | if (static_cast<long long>(bits) > 1LL << (nbits - 1)) { |
| 40 | result = static_cast<long long>(bits - (1ULL << nbits)); | 39 | result = static_cast<long long>(bits - (1ULL << nbits)); |
| @@ -49,8 +48,7 @@ BitStream::getBitsInt(size_t nbits) | @@ -49,8 +48,7 @@ BitStream::getBitsInt(size_t nbits) | ||
| 49 | { | 48 | { |
| 50 | return static_cast<int>( | 49 | return static_cast<int>( |
| 51 | // line-break | 50 | // line-break |
| 52 | - QIntC::to_uint( | ||
| 53 | - read_bits(this->p, this->bit_offset, this->bits_available, nbits))); | 51 | + QIntC::to_uint(read_bits(this->p, this->bit_offset, this->bits_available, nbits))); |
| 54 | } | 52 | } |
| 55 | 53 | ||
| 56 | void | 54 | void |
| @@ -59,8 +57,7 @@ BitStream::skipToNextByte() | @@ -59,8 +57,7 @@ BitStream::skipToNextByte() | ||
| 59 | if (bit_offset != 7) { | 57 | if (bit_offset != 7) { |
| 60 | size_t bits_to_skip = bit_offset + 1; | 58 | size_t bits_to_skip = bit_offset + 1; |
| 61 | if (bits_available < bits_to_skip) { | 59 | if (bits_available < bits_to_skip) { |
| 62 | - throw std::logic_error( | ||
| 63 | - "INTERNAL ERROR: overflow skipping to next byte in bitstream"); | 60 | + throw std::logic_error("INTERNAL ERROR: overflow skipping to next byte in bitstream"); |
| 64 | } | 61 | } |
| 65 | bit_offset = 7; | 62 | bit_offset = 7; |
| 66 | ++p; | 63 | ++p; |
libqpdf/BufferInputSource.cc
| @@ -5,8 +5,7 @@ | @@ -5,8 +5,7 @@ | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include <sstream> | 6 | #include <sstream> |
| 7 | 7 | ||
| 8 | -BufferInputSource::BufferInputSource( | ||
| 9 | - std::string const& description, Buffer* buf, bool own_memory) : | 8 | +BufferInputSource::BufferInputSource(std::string const& description, Buffer* buf, bool own_memory) : |
| 10 | own_memory(own_memory), | 9 | own_memory(own_memory), |
| 11 | description(description), | 10 | description(description), |
| 12 | buf(buf), | 11 | buf(buf), |
| @@ -15,8 +14,7 @@ BufferInputSource::BufferInputSource( | @@ -15,8 +14,7 @@ BufferInputSource::BufferInputSource( | ||
| 15 | { | 14 | { |
| 16 | } | 15 | } |
| 17 | 16 | ||
| 18 | -BufferInputSource::BufferInputSource( | ||
| 19 | - std::string const& description, std::string const& contents) : | 17 | +BufferInputSource::BufferInputSource(std::string const& description, std::string const& contents) : |
| 20 | own_memory(true), | 18 | own_memory(true), |
| 21 | description(description), | 19 | description(description), |
| 22 | buf(new Buffer(contents.length())), | 20 | buf(new Buffer(contents.length())), |
| @@ -100,14 +98,12 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) | @@ -100,14 +98,12 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) | ||
| 100 | break; | 98 | break; |
| 101 | 99 | ||
| 102 | default: | 100 | default: |
| 103 | - throw std::logic_error( | ||
| 104 | - "INTERNAL ERROR: invalid argument to BufferInputSource::seek"); | 101 | + throw std::logic_error("INTERNAL ERROR: invalid argument to BufferInputSource::seek"); |
| 105 | break; | 102 | break; |
| 106 | } | 103 | } |
| 107 | 104 | ||
| 108 | if (this->cur_offset < 0) { | 105 | if (this->cur_offset < 0) { |
| 109 | - throw std::runtime_error( | ||
| 110 | - this->description + ": seek before beginning of buffer"); | 106 | + throw std::runtime_error(this->description + ": seek before beginning of buffer"); |
| 111 | } | 107 | } |
| 112 | } | 108 | } |
| 113 | 109 |
libqpdf/ContentNormalizer.cc
| @@ -44,13 +44,11 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) | @@ -44,13 +44,11 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) | ||
| 44 | // Replacing string and name tokens in this way normalizes | 44 | // Replacing string and name tokens in this way normalizes |
| 45 | // their representation as this will automatically handle | 45 | // their representation as this will automatically handle |
| 46 | // quoting of unprintable characters, etc. | 46 | // quoting of unprintable characters, etc. |
| 47 | - writeToken( | ||
| 48 | - QPDFTokenizer::Token(QPDFTokenizer::tt_string, token.getValue())); | 47 | + writeToken(QPDFTokenizer::Token(QPDFTokenizer::tt_string, token.getValue())); |
| 49 | break; | 48 | break; |
| 50 | 49 | ||
| 51 | case QPDFTokenizer::tt_name: | 50 | case QPDFTokenizer::tt_name: |
| 52 | - writeToken( | ||
| 53 | - QPDFTokenizer::Token(QPDFTokenizer::tt_name, token.getValue())); | 51 | + writeToken(QPDFTokenizer::Token(QPDFTokenizer::tt_name, token.getValue())); |
| 54 | break; | 52 | break; |
| 55 | 53 | ||
| 56 | default: | 54 | default: |
| @@ -59,10 +57,8 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) | @@ -59,10 +57,8 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) | ||
| 59 | } | 57 | } |
| 60 | 58 | ||
| 61 | value = token.getRawValue(); | 59 | value = token.getRawValue(); |
| 62 | - if (((token_type == QPDFTokenizer::tt_string) || | ||
| 63 | - (token_type == QPDFTokenizer::tt_name)) && | ||
| 64 | - ((value.find('\r') != std::string::npos) || | ||
| 65 | - (value.find('\n') != std::string::npos))) { | 60 | + if (((token_type == QPDFTokenizer::tt_string) || (token_type == QPDFTokenizer::tt_name)) && |
| 61 | + ((value.find('\r') != std::string::npos) || (value.find('\n') != std::string::npos))) { | ||
| 66 | write("\n"); | 62 | write("\n"); |
| 67 | } | 63 | } |
| 68 | } | 64 | } |
libqpdf/FileInputSource.cc
| @@ -18,8 +18,7 @@ FileInputSource::FileInputSource(char const* filename) : | @@ -18,8 +18,7 @@ FileInputSource::FileInputSource(char const* filename) : | ||
| 18 | { | 18 | { |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | -FileInputSource::FileInputSource( | ||
| 22 | - char const* description, FILE* filep, bool close_file) : | 21 | +FileInputSource::FileInputSource(char const* description, FILE* filep, bool close_file) : |
| 23 | close_file(close_file), | 22 | close_file(close_file), |
| 24 | filename(description), | 23 | filename(description), |
| 25 | file(filep) | 24 | file(filep) |
| @@ -104,8 +103,8 @@ FileInputSource::seek(qpdf_offset_t offset, int whence) | @@ -104,8 +103,8 @@ FileInputSource::seek(qpdf_offset_t offset, int whence) | ||
| 104 | { | 103 | { |
| 105 | if (QUtil::seek(this->file, offset, whence) == -1) { | 104 | if (QUtil::seek(this->file, offset, whence) == -1) { |
| 106 | QUtil::throw_system_error( | 105 | QUtil::throw_system_error( |
| 107 | - std::string("seek to ") + this->filename + ", offset " + | ||
| 108 | - std::to_string(offset) + " (" + std::to_string(whence) + ")"); | 106 | + std::string("seek to ") + this->filename + ", offset " + std::to_string(offset) + " (" + |
| 107 | + std::to_string(whence) + ")"); | ||
| 109 | } | 108 | } |
| 110 | } | 109 | } |
| 111 | 110 |
libqpdf/InputSource.cc
| @@ -43,8 +43,7 @@ InputSource::readLine(size_t max_line_length) | @@ -43,8 +43,7 @@ InputSource::readLine(size_t max_line_length) | ||
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | bool | 45 | bool |
| 46 | -InputSource::findFirst( | ||
| 47 | - char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder) | 46 | +InputSource::findFirst(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder) |
| 48 | { | 47 | { |
| 49 | // Basic approach: search for the first character of start_chars | 48 | // Basic approach: search for the first character of start_chars |
| 50 | // starting from offset but not going past len (if len != 0). Once | 49 | // starting from offset but not going past len (if len != 0). Once |
| @@ -64,9 +63,8 @@ InputSource::findFirst( | @@ -64,9 +63,8 @@ InputSource::findFirst( | ||
| 64 | // so that buf[size] is valid memory. | 63 | // so that buf[size] is valid memory. |
| 65 | size_t size = sizeof(buf) - 1; | 64 | size_t size = sizeof(buf) - 1; |
| 66 | if ((strlen(start_chars) < 1) || (strlen(start_chars) > size)) { | 65 | if ((strlen(start_chars) < 1) || (strlen(start_chars) > size)) { |
| 67 | - throw std::logic_error( | ||
| 68 | - "InputSource::findSource called with" | ||
| 69 | - " too small or too large of a character sequence"); | 66 | + throw std::logic_error("InputSource::findSource called with" |
| 67 | + " too small or too large of a character sequence"); | ||
| 70 | } | 68 | } |
| 71 | 69 | ||
| 72 | char* p = nullptr; | 70 | char* p = nullptr; |
| @@ -86,13 +84,10 @@ InputSource::findFirst( | @@ -86,13 +84,10 @@ InputSource::findFirst( | ||
| 86 | // If p points to buf[size], since strlen(start_chars) is | 84 | // If p points to buf[size], since strlen(start_chars) is |
| 87 | // always >= 1, this overflow test will be correct for that | 85 | // always >= 1, this overflow test will be correct for that |
| 88 | // case regardless of start_chars. | 86 | // case regardless of start_chars. |
| 89 | - if ((p == nullptr) || | ||
| 90 | - ((p + strlen(start_chars)) > (buf + bytes_read))) { | 87 | + if ((p == nullptr) || ((p + strlen(start_chars)) > (buf + bytes_read))) { |
| 91 | if (p) { | 88 | if (p) { |
| 92 | QTC::TC( | 89 | QTC::TC( |
| 93 | - "libtests", | ||
| 94 | - "InputSource read next block", | ||
| 95 | - ((p == buf + bytes_read) ? 0 : 1)); | 90 | + "libtests", "InputSource read next block", ((p == buf + bytes_read) ? 0 : 1)); |
| 96 | buf_offset += (p - buf); | 91 | buf_offset += (p - buf); |
| 97 | } | 92 | } |
| 98 | this->seek(buf_offset, SEEK_SET); | 93 | this->seek(buf_offset, SEEK_SET); |
| @@ -102,10 +97,7 @@ InputSource::findFirst( | @@ -102,10 +97,7 @@ InputSource::findFirst( | ||
| 102 | // protection against overrun when using string functions. | 97 | // protection against overrun when using string functions. |
| 103 | bytes_read = this->read(buf, size); | 98 | bytes_read = this->read(buf, size); |
| 104 | if (bytes_read < strlen(start_chars)) { | 99 | if (bytes_read < strlen(start_chars)) { |
| 105 | - QTC::TC( | ||
| 106 | - "libtests", | ||
| 107 | - "InputSource find EOF", | ||
| 108 | - bytes_read == 0 ? 0 : 1); | 100 | + QTC::TC("libtests", "InputSource find EOF", bytes_read == 0 ? 0 : 1); |
| 109 | return false; | 101 | return false; |
| 110 | } | 102 | } |
| 111 | memset(buf + bytes_read, '\0', 1 + (size - bytes_read)); | 103 | memset(buf + bytes_read, '\0', 1 + (size - bytes_read)); |
| @@ -115,18 +107,14 @@ InputSource::findFirst( | @@ -115,18 +107,14 @@ InputSource::findFirst( | ||
| 115 | // Search for the first character. | 107 | // Search for the first character. |
| 116 | if ((p = static_cast<char*>( | 108 | if ((p = static_cast<char*>( |
| 117 | // line-break | 109 | // line-break |
| 118 | - memchr( | ||
| 119 | - p, | ||
| 120 | - start_chars[0], | ||
| 121 | - bytes_read - QIntC::to_size(p - buf)))) != nullptr) { | 110 | + memchr(p, start_chars[0], bytes_read - QIntC::to_size(p - buf)))) != nullptr) { |
| 122 | if (p == buf) { | 111 | if (p == buf) { |
| 123 | QTC::TC("libtests", "InputSource found match at buf[0]"); | 112 | QTC::TC("libtests", "InputSource found match at buf[0]"); |
| 124 | } | 113 | } |
| 125 | // Found first letter. | 114 | // Found first letter. |
| 126 | if (len != 0) { | 115 | if (len != 0) { |
| 127 | // Make sure it's in range. | 116 | // Make sure it's in range. |
| 128 | - size_t p_relative_offset = | ||
| 129 | - QIntC::to_size((p - buf) + (buf_offset - offset)); | 117 | + size_t p_relative_offset = QIntC::to_size((p - buf) + (buf_offset - offset)); |
| 130 | if (p_relative_offset >= len) { | 118 | if (p_relative_offset >= len) { |
| 131 | // out of range | 119 | // out of range |
| 132 | QTC::TC("libtests", "InputSource out of range"); | 120 | QTC::TC("libtests", "InputSource out of range"); |
| @@ -151,14 +139,10 @@ InputSource::findFirst( | @@ -151,14 +139,10 @@ InputSource::findFirst( | ||
| 151 | if (finder.check()) { | 139 | if (finder.check()) { |
| 152 | return true; | 140 | return true; |
| 153 | } else { | 141 | } else { |
| 154 | - QTC::TC( | ||
| 155 | - "libtests", | ||
| 156 | - "InputSource start_chars matched but not check"); | 142 | + QTC::TC("libtests", "InputSource start_chars matched but not check"); |
| 157 | } | 143 | } |
| 158 | } else { | 144 | } else { |
| 159 | - QTC::TC( | ||
| 160 | - "libtests", | ||
| 161 | - "InputSource first char matched but not string"); | 145 | + QTC::TC("libtests", "InputSource first char matched but not string"); |
| 162 | } | 146 | } |
| 163 | // This occurrence of the first character wasn't a match. | 147 | // This occurrence of the first character wasn't a match. |
| 164 | // Skip over it and keep searching. | 148 | // Skip over it and keep searching. |
| @@ -172,8 +156,7 @@ InputSource::findFirst( | @@ -172,8 +156,7 @@ InputSource::findFirst( | ||
| 172 | } | 156 | } |
| 173 | 157 | ||
| 174 | bool | 158 | bool |
| 175 | -InputSource::findLast( | ||
| 176 | - char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder) | 159 | +InputSource::findLast(char const* start_chars, qpdf_offset_t offset, size_t len, Finder& finder) |
| 177 | { | 160 | { |
| 178 | bool found = false; | 161 | bool found = false; |
| 179 | qpdf_offset_t after_found_offset = 0; | 162 | qpdf_offset_t after_found_offset = 0; |
libqpdf/InsecureRandomDataProvider.cc
| @@ -24,8 +24,7 @@ InsecureRandomDataProvider::random() | @@ -24,8 +24,7 @@ InsecureRandomDataProvider::random() | ||
| 24 | // Seed the random number generator with something simple, but | 24 | // Seed the random number generator with something simple, but |
| 25 | // just to be interesting, don't use the unmodified current | 25 | // just to be interesting, don't use the unmodified current |
| 26 | // time. It would be better if this were a more secure seed. | 26 | // time. It would be better if this were a more secure seed. |
| 27 | - auto seed = | ||
| 28 | - static_cast<unsigned int>(QUtil::get_current_time() ^ 0xcccc); | 27 | + auto seed = static_cast<unsigned int>(QUtil::get_current_time() ^ 0xcccc); |
| 29 | #ifdef HAVE_RANDOM | 28 | #ifdef HAVE_RANDOM |
| 30 | ::srandom(seed); | 29 | ::srandom(seed); |
| 31 | #else | 30 | #else |
libqpdf/JSON.cc
| @@ -73,8 +73,7 @@ JSON::writeArrayClose(Pipeline* p, bool first, size_t depth) | @@ -73,8 +73,7 @@ JSON::writeArrayClose(Pipeline* p, bool first, size_t depth) | ||
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | void | 75 | void |
| 76 | -JSON::writeDictionaryKey( | ||
| 77 | - Pipeline* p, bool& first, std::string const& key, size_t depth) | 76 | +JSON::writeDictionaryKey(Pipeline* p, bool& first, std::string const& key, size_t depth) |
| 78 | { | 77 | { |
| 79 | writeNext(p, first, depth); | 78 | writeNext(p, first, depth); |
| 80 | *p << std::string("\"") + key + "\": "; | 79 | *p << std::string("\"") + key + "\": "; |
| @@ -82,19 +81,14 @@ JSON::writeDictionaryKey( | @@ -82,19 +81,14 @@ JSON::writeDictionaryKey( | ||
| 82 | 81 | ||
| 83 | void | 82 | void |
| 84 | JSON::writeDictionaryItem( | 83 | JSON::writeDictionaryItem( |
| 85 | - Pipeline* p, | ||
| 86 | - bool& first, | ||
| 87 | - std::string const& key, | ||
| 88 | - JSON const& value, | ||
| 89 | - size_t depth) | 84 | + Pipeline* p, bool& first, std::string const& key, JSON const& value, size_t depth) |
| 90 | { | 85 | { |
| 91 | writeDictionaryKey(p, first, key, depth); | 86 | writeDictionaryKey(p, first, key, depth); |
| 92 | value.write(p, depth); | 87 | value.write(p, depth); |
| 93 | } | 88 | } |
| 94 | 89 | ||
| 95 | void | 90 | void |
| 96 | -JSON::writeArrayItem( | ||
| 97 | - Pipeline* p, bool& first, JSON const& element, size_t depth) | 91 | +JSON::writeArrayItem(Pipeline* p, bool& first, JSON const& element, size_t depth) |
| 98 | { | 92 | { |
| 99 | writeNext(p, first, depth); | 93 | writeNext(p, first, depth); |
| 100 | element.write(p, depth); | 94 | element.write(p, depth); |
| @@ -283,11 +277,9 @@ JSON | @@ -283,11 +277,9 @@ JSON | ||
| 283 | JSON::addDictionaryMember(std::string const& key, JSON const& val) | 277 | JSON::addDictionaryMember(std::string const& key, JSON const& val) |
| 284 | { | 278 | { |
| 285 | if (auto* obj = dynamic_cast<JSON_dictionary*>(m->value.get())) { | 279 | if (auto* obj = dynamic_cast<JSON_dictionary*>(m->value.get())) { |
| 286 | - return obj->members[encode_string(key)] = | ||
| 287 | - val.m->value ? val : makeNull(); | 280 | + return obj->members[encode_string(key)] = val.m->value ? val : makeNull(); |
| 288 | } else { | 281 | } else { |
| 289 | - throw std::runtime_error( | ||
| 290 | - "JSON::addDictionaryMember called on non-dictionary"); | 282 | + throw std::runtime_error("JSON::addDictionaryMember called on non-dictionary"); |
| 291 | } | 283 | } |
| 292 | } | 284 | } |
| 293 | 285 | ||
| @@ -296,8 +288,7 @@ JSON::checkDictionaryKeySeen(std::string const& key) | @@ -296,8 +288,7 @@ JSON::checkDictionaryKeySeen(std::string const& key) | ||
| 296 | { | 288 | { |
| 297 | auto* obj = dynamic_cast<JSON_dictionary*>(m->value.get()); | 289 | auto* obj = dynamic_cast<JSON_dictionary*>(m->value.get()); |
| 298 | if (nullptr == obj) { | 290 | if (nullptr == obj) { |
| 299 | - throw std::logic_error( | ||
| 300 | - "JSON::checkDictionaryKey called on non-dictionary"); | 291 | + throw std::logic_error("JSON::checkDictionaryKey called on non-dictionary"); |
| 301 | } | 292 | } |
| 302 | if (obj->parsed_keys.count(key)) { | 293 | if (obj->parsed_keys.count(key)) { |
| 303 | return true; | 294 | return true; |
| @@ -421,8 +412,7 @@ JSON::isNull() const | @@ -421,8 +412,7 @@ JSON::isNull() const | ||
| 421 | } | 412 | } |
| 422 | 413 | ||
| 423 | bool | 414 | bool |
| 424 | -JSON::forEachDictItem( | ||
| 425 | - std::function<void(std::string const& key, JSON value)> fn) const | 415 | +JSON::forEachDictItem(std::function<void(std::string const& key, JSON value)> fn) const |
| 426 | { | 416 | { |
| 427 | auto v = dynamic_cast<JSON_dictionary const*>(m->value.get()); | 417 | auto v = dynamic_cast<JSON_dictionary const*>(m->value.get()); |
| 428 | if (v == nullptr) { | 418 | if (v == nullptr) { |
| @@ -450,16 +440,13 @@ JSON::forEachArrayItem(std::function<void(JSON value)> fn) const | @@ -450,16 +440,13 @@ JSON::forEachArrayItem(std::function<void(JSON value)> fn) const | ||
| 450 | bool | 440 | bool |
| 451 | JSON::checkSchema(JSON schema, std::list<std::string>& errors) | 441 | JSON::checkSchema(JSON schema, std::list<std::string>& errors) |
| 452 | { | 442 | { |
| 453 | - return checkSchemaInternal( | ||
| 454 | - m->value.get(), schema.m->value.get(), 0, errors, ""); | 443 | + return checkSchemaInternal(m->value.get(), schema.m->value.get(), 0, errors, ""); |
| 455 | } | 444 | } |
| 456 | 445 | ||
| 457 | bool | 446 | bool |
| 458 | -JSON::checkSchema( | ||
| 459 | - JSON schema, unsigned long flags, std::list<std::string>& errors) | 447 | +JSON::checkSchema(JSON schema, unsigned long flags, std::list<std::string>& errors) |
| 460 | { | 448 | { |
| 461 | - return checkSchemaInternal( | ||
| 462 | - m->value.get(), schema.m->value.get(), flags, errors, ""); | 449 | + return checkSchemaInternal(m->value.get(), schema.m->value.get(), flags, errors, ""); |
| 463 | } | 450 | } |
| 464 | 451 | ||
| 465 | bool | 452 | bool |
| @@ -495,8 +482,8 @@ JSON::checkSchemaInternal( | @@ -495,8 +482,8 @@ JSON::checkSchemaInternal( | ||
| 495 | auto members = sch_dict->members; | 482 | auto members = sch_dict->members; |
| 496 | std::string key; | 483 | std::string key; |
| 497 | if ((members.size() == 1) && | 484 | if ((members.size() == 1) && |
| 498 | - ((key = members.begin()->first, key.length() > 2) && | ||
| 499 | - (key.at(0) == '<') && (key.at(key.length() - 1) == '>'))) { | 485 | + ((key = members.begin()->first, key.length() > 2) && (key.at(0) == '<') && |
| 486 | + (key.at(key.length() - 1) == '>'))) { | ||
| 500 | pattern_key = key; | 487 | pattern_key = key; |
| 501 | } | 488 | } |
| 502 | } | 489 | } |
| @@ -565,17 +552,12 @@ JSON::checkSchemaInternal( | @@ -565,17 +552,12 @@ JSON::checkSchemaInternal( | ||
| 565 | } else { | 552 | } else { |
| 566 | QTC::TC("libtests", "JSON schema array for single item"); | 553 | QTC::TC("libtests", "JSON schema array for single item"); |
| 567 | checkSchemaInternal( | 554 | checkSchemaInternal( |
| 568 | - this_v, | ||
| 569 | - sch_arr->elements.at(0).m->value.get(), | ||
| 570 | - flags, | ||
| 571 | - errors, | ||
| 572 | - prefix); | 555 | + this_v, sch_arr->elements.at(0).m->value.get(), flags, errors, prefix); |
| 573 | } | 556 | } |
| 574 | } else if (!this_arr || (this_arr->elements.size() != n_elements)) { | 557 | } else if (!this_arr || (this_arr->elements.size() != n_elements)) { |
| 575 | QTC::TC("libtests", "JSON schema array length mismatch"); | 558 | QTC::TC("libtests", "JSON schema array length mismatch"); |
| 576 | errors.push_back( | 559 | errors.push_back( |
| 577 | - err_prefix + " is supposed to be an array of length " + | ||
| 578 | - std::to_string(n_elements)); | 560 | + err_prefix + " is supposed to be an array of length " + std::to_string(n_elements)); |
| 579 | return false; | 561 | return false; |
| 580 | } else { | 562 | } else { |
| 581 | // A multi-element array in the schema must correspond to | 563 | // A multi-element array in the schema must correspond to |
| @@ -595,8 +577,7 @@ JSON::checkSchemaInternal( | @@ -595,8 +577,7 @@ JSON::checkSchemaInternal( | ||
| 595 | } | 577 | } |
| 596 | } else if (!sch_str) { | 578 | } else if (!sch_str) { |
| 597 | QTC::TC("libtests", "JSON schema other type"); | 579 | QTC::TC("libtests", "JSON schema other type"); |
| 598 | - errors.push_back( | ||
| 599 | - err_prefix + " schema value is not dictionary, array, or string"); | 580 | + errors.push_back(err_prefix + " schema value is not dictionary, array, or string"); |
| 600 | return false; | 581 | return false; |
| 601 | } | 582 | } |
| 602 | 583 | ||
| @@ -736,8 +717,7 @@ JSONParser::handle_u_code( | @@ -736,8 +717,7 @@ JSONParser::handle_u_code( | ||
| 736 | " surrogate"); | 717 | " surrogate"); |
| 737 | } | 718 | } |
| 738 | high_offset = 0; | 719 | high_offset = 0; |
| 739 | - codepoint = | ||
| 740 | - 0x10000U + ((high_surrogate & 0x3FFU) << 10U) + (codepoint & 0x3FF); | 720 | + codepoint = 0x10000U + ((high_surrogate & 0x3FFU) << 10U) + (codepoint & 0x3FF); |
| 741 | result += QUtil::toUTF8(codepoint); | 721 | result += QUtil::toUTF8(codepoint); |
| 742 | } else { | 722 | } else { |
| 743 | result += QUtil::toUTF8(codepoint); | 723 | result += QUtil::toUTF8(codepoint); |
| @@ -760,8 +740,8 @@ JSONParser::tokenError() | @@ -760,8 +740,8 @@ JSONParser::tokenError() | ||
| 760 | } else if (lex_state == ls_alpha) { | 740 | } else if (lex_state == ls_alpha) { |
| 761 | QTC::TC("libtests", "JSON parse keyword bad character"); | 741 | QTC::TC("libtests", "JSON parse keyword bad character"); |
| 762 | throw std::runtime_error( | 742 | throw std::runtime_error( |
| 763 | - "JSON: offset " + std::to_string(offset) + | ||
| 764 | - ": keyword: unexpected character " + std::string(p, 1)); | 743 | + "JSON: offset " + std::to_string(offset) + ": keyword: unexpected character " + |
| 744 | + std::string(p, 1)); | ||
| 765 | } else if (lex_state == ls_string) { | 745 | } else if (lex_state == ls_string) { |
| 766 | QTC::TC("libtests", "JSON parse control char in string"); | 746 | QTC::TC("libtests", "JSON parse control char in string"); |
| 767 | throw std::runtime_error( | 747 | throw std::runtime_error( |
| @@ -775,8 +755,7 @@ JSONParser::tokenError() | @@ -775,8 +755,7 @@ JSONParser::tokenError() | ||
| 775 | } | 755 | } |
| 776 | 756 | ||
| 777 | if (*p == '.') { | 757 | if (*p == '.') { |
| 778 | - if (lex_state == ls_number || lex_state == ls_number_e || | ||
| 779 | - lex_state == ls_number_e_sign) { | 758 | + if (lex_state == ls_number || lex_state == ls_number_e || lex_state == ls_number_e_sign) { |
| 780 | QTC::TC("libtests", "JSON parse point after e"); | 759 | QTC::TC("libtests", "JSON parse point after e"); |
| 781 | throw std::runtime_error( | 760 | throw std::runtime_error( |
| 782 | "JSON: offset " + std::to_string(offset) + | 761 | "JSON: offset " + std::to_string(offset) + |
| @@ -790,24 +769,21 @@ JSONParser::tokenError() | @@ -790,24 +769,21 @@ JSONParser::tokenError() | ||
| 790 | } else if (*p == 'e' || *p == 'E') { | 769 | } else if (*p == 'e' || *p == 'E') { |
| 791 | QTC::TC("libtests", "JSON parse duplicate e"); | 770 | QTC::TC("libtests", "JSON parse duplicate e"); |
| 792 | throw std::runtime_error( | 771 | throw std::runtime_error( |
| 793 | - "JSON: offset " + std::to_string(offset) + | ||
| 794 | - ": numeric literal: e already seen"); | 772 | + "JSON: offset " + std::to_string(offset) + ": numeric literal: e already seen"); |
| 795 | } else if ((*p == '+') || (*p == '-')) { | 773 | } else if ((*p == '+') || (*p == '-')) { |
| 796 | QTC::TC("libtests", "JSON parse unexpected sign"); | 774 | QTC::TC("libtests", "JSON parse unexpected sign"); |
| 797 | throw std::runtime_error( | 775 | throw std::runtime_error( |
| 798 | - "JSON: offset " + std::to_string(offset) + | ||
| 799 | - ": numeric literal: unexpected sign"); | 776 | + "JSON: offset " + std::to_string(offset) + ": numeric literal: unexpected sign"); |
| 800 | } else if (QUtil::is_space(*p) || strchr("{}[]:,", *p)) { | 777 | } else if (QUtil::is_space(*p) || strchr("{}[]:,", *p)) { |
| 801 | QTC::TC("libtests", "JSON parse incomplete number"); | 778 | QTC::TC("libtests", "JSON parse incomplete number"); |
| 802 | throw std::runtime_error( | 779 | throw std::runtime_error( |
| 803 | - "JSON: offset " + std::to_string(offset) + | ||
| 804 | - ": numeric literal: incomplete number"); | 780 | + "JSON: offset " + std::to_string(offset) + ": numeric literal: incomplete number"); |
| 805 | 781 | ||
| 806 | } else { | 782 | } else { |
| 807 | QTC::TC("libtests", "JSON parse numeric bad character"); | 783 | QTC::TC("libtests", "JSON parse numeric bad character"); |
| 808 | throw std::runtime_error( | 784 | throw std::runtime_error( |
| 809 | - "JSON: offset " + std::to_string(offset) + | ||
| 810 | - ": numeric literal: unexpected character " + std::string(p, 1)); | 785 | + "JSON: offset " + std::to_string(offset) + ": numeric literal: unexpected character " + |
| 786 | + std::string(p, 1)); | ||
| 811 | } | 787 | } |
| 812 | throw std::logic_error("JSON::tokenError : unhandled error"); | 788 | throw std::logic_error("JSON::tokenError : unhandled error"); |
| 813 | } | 789 | } |
| @@ -884,8 +860,7 @@ JSONParser::getToken() | @@ -884,8 +860,7 @@ JSONParser::getToken() | ||
| 884 | } else { | 860 | } else { |
| 885 | QTC::TC("libtests", "JSON parse null character"); | 861 | QTC::TC("libtests", "JSON parse null character"); |
| 886 | throw std::runtime_error( | 862 | throw std::runtime_error( |
| 887 | - "JSON: control or null character at offset " + | ||
| 888 | - std::to_string(offset)); | 863 | + "JSON: control or null character at offset " + std::to_string(offset)); |
| 889 | } | 864 | } |
| 890 | } else if (*p == ',') { | 865 | } else if (*p == ',') { |
| 891 | if (lex_state == ls_top) { | 866 | if (lex_state == ls_top) { |
| @@ -968,8 +943,8 @@ JSONParser::getToken() | @@ -968,8 +943,8 @@ JSONParser::getToken() | ||
| 968 | } else { | 943 | } else { |
| 969 | QTC::TC("libtests", "JSON parse bad character"); | 944 | QTC::TC("libtests", "JSON parse bad character"); |
| 970 | throw std::runtime_error( | 945 | throw std::runtime_error( |
| 971 | - "JSON: offset " + std::to_string(offset) + | ||
| 972 | - ": unexpected character " + std::string(p, 1)); | 946 | + "JSON: offset " + std::to_string(offset) + ": unexpected character " + |
| 947 | + std::string(p, 1)); | ||
| 973 | } | 948 | } |
| 974 | break; | 949 | break; |
| 975 | 950 | ||
| @@ -994,8 +969,7 @@ JSONParser::getToken() | @@ -994,8 +969,7 @@ JSONParser::getToken() | ||
| 994 | } else { | 969 | } else { |
| 995 | QTC::TC("libtests", "JSON parse leading zero"); | 970 | QTC::TC("libtests", "JSON parse leading zero"); |
| 996 | throw std::runtime_error( | 971 | throw std::runtime_error( |
| 997 | - "JSON: offset " + std::to_string(offset) + | ||
| 998 | - ": number with leading zero"); | 972 | + "JSON: offset " + std::to_string(offset) + ": number with leading zero"); |
| 999 | } | 973 | } |
| 1000 | break; | 974 | break; |
| 1001 | 975 | ||
| @@ -1127,20 +1101,14 @@ JSONParser::getToken() | @@ -1127,20 +1101,14 @@ JSONParser::getToken() | ||
| 1127 | tokenError(); | 1101 | tokenError(); |
| 1128 | } | 1102 | } |
| 1129 | if (++u_count == 4) { | 1103 | if (++u_count == 4) { |
| 1130 | - handle_u_code( | ||
| 1131 | - u_value, | ||
| 1132 | - offset - 5, | ||
| 1133 | - high_surrogate, | ||
| 1134 | - high_offset, | ||
| 1135 | - token); | 1104 | + handle_u_code(u_value, offset - 5, high_surrogate, high_offset, token); |
| 1136 | lex_state = ls_string; | 1105 | lex_state = ls_string; |
| 1137 | } | 1106 | } |
| 1138 | ignore(); | 1107 | ignore(); |
| 1139 | break; | 1108 | break; |
| 1140 | 1109 | ||
| 1141 | default: | 1110 | default: |
| 1142 | - throw std::logic_error( | ||
| 1143 | - "JSONParser::getToken : trying to handle delimiter state"); | 1111 | + throw std::logic_error("JSONParser::getToken : trying to handle delimiter state"); |
| 1144 | } | 1112 | } |
| 1145 | } | 1113 | } |
| 1146 | } | 1114 | } |
| @@ -1205,19 +1173,16 @@ JSONParser::handleToken() | @@ -1205,19 +1173,16 @@ JSONParser::handleToken() | ||
| 1205 | if (parser_state != ps_dict_after_key) { | 1173 | if (parser_state != ps_dict_after_key) { |
| 1206 | QTC::TC("libtests", "JSON parse unexpected :"); | 1174 | QTC::TC("libtests", "JSON parse unexpected :"); |
| 1207 | throw std::runtime_error( | 1175 | throw std::runtime_error( |
| 1208 | - "JSON: offset " + std::to_string(offset) + | ||
| 1209 | - ": unexpected colon"); | 1176 | + "JSON: offset " + std::to_string(offset) + ": unexpected colon"); |
| 1210 | } | 1177 | } |
| 1211 | parser_state = ps_dict_after_colon; | 1178 | parser_state = ps_dict_after_colon; |
| 1212 | return; | 1179 | return; |
| 1213 | 1180 | ||
| 1214 | case ls_comma: | 1181 | case ls_comma: |
| 1215 | - if (!((parser_state == ps_dict_after_item) || | ||
| 1216 | - (parser_state == ps_array_after_item))) { | 1182 | + if (!((parser_state == ps_dict_after_item) || (parser_state == ps_array_after_item))) { |
| 1217 | QTC::TC("libtests", "JSON parse unexpected ,"); | 1183 | QTC::TC("libtests", "JSON parse unexpected ,"); |
| 1218 | throw std::runtime_error( | 1184 | throw std::runtime_error( |
| 1219 | - "JSON: offset " + std::to_string(offset) + | ||
| 1220 | - ": unexpected comma"); | 1185 | + "JSON: offset " + std::to_string(offset) + ": unexpected comma"); |
| 1221 | } | 1186 | } |
| 1222 | if (parser_state == ps_dict_after_item) { | 1187 | if (parser_state == ps_dict_after_item) { |
| 1223 | parser_state = ps_dict_after_comma; | 1188 | parser_state = ps_dict_after_comma; |
| @@ -1230,12 +1195,10 @@ JSONParser::handleToken() | @@ -1230,12 +1195,10 @@ JSONParser::handleToken() | ||
| 1230 | return; | 1195 | return; |
| 1231 | 1196 | ||
| 1232 | case ls_end_array: | 1197 | case ls_end_array: |
| 1233 | - if (!(parser_state == ps_array_begin || | ||
| 1234 | - parser_state == ps_array_after_item)) { | 1198 | + if (!(parser_state == ps_array_begin || parser_state == ps_array_after_item)) { |
| 1235 | QTC::TC("libtests", "JSON parse unexpected ]"); | 1199 | QTC::TC("libtests", "JSON parse unexpected ]"); |
| 1236 | throw std::runtime_error( | 1200 | throw std::runtime_error( |
| 1237 | - "JSON: offset " + std::to_string(offset) + | ||
| 1238 | - ": unexpected array end delimiter"); | 1201 | + "JSON: offset " + std::to_string(offset) + ": unexpected array end delimiter"); |
| 1239 | } | 1202 | } |
| 1240 | parser_state = stack.back().state; | 1203 | parser_state = stack.back().state; |
| 1241 | tos.setEnd(offset); | 1204 | tos.setEnd(offset); |
| @@ -1248,12 +1211,10 @@ JSONParser::handleToken() | @@ -1248,12 +1211,10 @@ JSONParser::handleToken() | ||
| 1248 | return; | 1211 | return; |
| 1249 | 1212 | ||
| 1250 | case ls_end_dict: | 1213 | case ls_end_dict: |
| 1251 | - if (!((parser_state == ps_dict_begin) || | ||
| 1252 | - (parser_state == ps_dict_after_item))) { | 1214 | + if (!((parser_state == ps_dict_begin) || (parser_state == ps_dict_after_item))) { |
| 1253 | QTC::TC("libtests", "JSON parse unexpected }"); | 1215 | QTC::TC("libtests", "JSON parse unexpected }"); |
| 1254 | throw std::runtime_error( | 1216 | throw std::runtime_error( |
| 1255 | - "JSON: offset " + std::to_string(offset) + | ||
| 1256 | - ": unexpected dictionary end delimiter"); | 1217 | + "JSON: offset " + std::to_string(offset) + ": unexpected dictionary end delimiter"); |
| 1257 | } | 1218 | } |
| 1258 | parser_state = stack.back().state; | 1219 | parser_state = stack.back().state; |
| 1259 | tos.setEnd(offset); | 1220 | tos.setEnd(offset); |
| @@ -1279,14 +1240,12 @@ JSONParser::handleToken() | @@ -1279,14 +1240,12 @@ JSONParser::handleToken() | ||
| 1279 | } else { | 1240 | } else { |
| 1280 | QTC::TC("libtests", "JSON parse invalid keyword"); | 1241 | QTC::TC("libtests", "JSON parse invalid keyword"); |
| 1281 | throw std::runtime_error( | 1242 | throw std::runtime_error( |
| 1282 | - "JSON: offset " + std::to_string(offset) + | ||
| 1283 | - ": invalid keyword " + token); | 1243 | + "JSON: offset " + std::to_string(offset) + ": invalid keyword " + token); |
| 1284 | } | 1244 | } |
| 1285 | break; | 1245 | break; |
| 1286 | 1246 | ||
| 1287 | case ls_string: | 1247 | case ls_string: |
| 1288 | - if (parser_state == ps_dict_begin || | ||
| 1289 | - parser_state == ps_dict_after_comma) { | 1248 | + if (parser_state == ps_dict_begin || parser_state == ps_dict_after_comma) { |
| 1290 | dict_key = token; | 1249 | dict_key = token; |
| 1291 | dict_key_offset = token_start; | 1250 | dict_key_offset = token_start; |
| 1292 | parser_state = ps_dict_after_key; | 1251 | parser_state = ps_dict_after_key; |
| @@ -1297,8 +1256,7 @@ JSONParser::handleToken() | @@ -1297,8 +1256,7 @@ JSONParser::handleToken() | ||
| 1297 | break; | 1256 | break; |
| 1298 | 1257 | ||
| 1299 | default: | 1258 | default: |
| 1300 | - throw std::logic_error( | ||
| 1301 | - "JSONParser::handleToken : non-terminal lexer state encountered"); | 1259 | + throw std::logic_error("JSONParser::handleToken : non-terminal lexer state encountered"); |
| 1302 | break; | 1260 | break; |
| 1303 | } | 1261 | } |
| 1304 | 1262 | ||
| @@ -1310,16 +1268,14 @@ JSONParser::handleToken() | @@ -1310,16 +1268,14 @@ JSONParser::handleToken() | ||
| 1310 | case ps_dict_after_comma: | 1268 | case ps_dict_after_comma: |
| 1311 | QTC::TC("libtests", "JSON parse string as dict key"); | 1269 | QTC::TC("libtests", "JSON parse string as dict key"); |
| 1312 | throw std::runtime_error( | 1270 | throw std::runtime_error( |
| 1313 | - "JSON: offset " + std::to_string(offset) + | ||
| 1314 | - ": expect string as dictionary key"); | 1271 | + "JSON: offset " + std::to_string(offset) + ": expect string as dictionary key"); |
| 1315 | break; | 1272 | break; |
| 1316 | 1273 | ||
| 1317 | case ps_dict_after_colon: | 1274 | case ps_dict_after_colon: |
| 1318 | if (tos.checkDictionaryKeySeen(dict_key)) { | 1275 | if (tos.checkDictionaryKeySeen(dict_key)) { |
| 1319 | QTC::TC("libtests", "JSON parse duplicate key"); | 1276 | QTC::TC("libtests", "JSON parse duplicate key"); |
| 1320 | throw std::runtime_error( | 1277 | throw std::runtime_error( |
| 1321 | - "JSON: offset " + std::to_string(dict_key_offset) + | ||
| 1322 | - ": duplicated dictionary key"); | 1278 | + "JSON: offset " + std::to_string(dict_key_offset) + ": duplicated dictionary key"); |
| 1323 | } | 1279 | } |
| 1324 | if (!reactor || !reactor->dictionaryItem(dict_key, item)) { | 1280 | if (!reactor || !reactor->dictionaryItem(dict_key, item)) { |
| 1325 | tos.addDictionaryMember(dict_key, item); | 1281 | tos.addDictionaryMember(dict_key, item); |
| @@ -1346,8 +1302,7 @@ JSONParser::handleToken() | @@ -1346,8 +1302,7 @@ JSONParser::handleToken() | ||
| 1346 | 1302 | ||
| 1347 | case ps_dict_after_key: | 1303 | case ps_dict_after_key: |
| 1348 | QTC::TC("libtests", "JSON parse expected colon"); | 1304 | QTC::TC("libtests", "JSON parse expected colon"); |
| 1349 | - throw std::runtime_error( | ||
| 1350 | - "JSON: offset " + std::to_string(offset) + ": expected ':'"); | 1305 | + throw std::runtime_error("JSON: offset " + std::to_string(offset) + ": expected ':'"); |
| 1351 | break; | 1306 | break; |
| 1352 | 1307 | ||
| 1353 | case ps_dict_after_item: | 1308 | case ps_dict_after_item: |
| @@ -1363,8 +1318,7 @@ JSONParser::handleToken() | @@ -1363,8 +1318,7 @@ JSONParser::handleToken() | ||
| 1363 | break; | 1318 | break; |
| 1364 | 1319 | ||
| 1365 | case ps_done: | 1320 | case ps_done: |
| 1366 | - throw std::logic_error( | ||
| 1367 | - "JSONParser::handleToken: unexpected parser state"); | 1321 | + throw std::logic_error("JSONParser::handleToken: unexpected parser state"); |
| 1368 | } | 1322 | } |
| 1369 | 1323 | ||
| 1370 | if (item.isDictionary() || item.isArray()) { | 1324 | if (item.isDictionary() || item.isArray()) { |
| @@ -1387,8 +1341,7 @@ JSONParser::handleToken() | @@ -1387,8 +1341,7 @@ JSONParser::handleToken() | ||
| 1387 | 1341 | ||
| 1388 | if (stack.size() > 500) { | 1342 | if (stack.size() > 500) { |
| 1389 | throw std::runtime_error( | 1343 | throw std::runtime_error( |
| 1390 | - "JSON: offset " + std::to_string(offset) + | ||
| 1391 | - ": maximum object depth exceeded"); | 1344 | + "JSON: offset " + std::to_string(offset) + ": maximum object depth exceeded"); |
| 1392 | } | 1345 | } |
| 1393 | } | 1346 | } |
| 1394 | } | 1347 | } |
libqpdf/JSONHandler.cc
| @@ -53,8 +53,7 @@ JSONHandler::addDictHandlers(json_handler_t start_fn, void_handler_t end_fn) | @@ -53,8 +53,7 @@ JSONHandler::addDictHandlers(json_handler_t start_fn, void_handler_t end_fn) | ||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | void | 55 | void |
| 56 | -JSONHandler::addDictKeyHandler( | ||
| 57 | - std::string const& key, std::shared_ptr<JSONHandler> dkh) | 56 | +JSONHandler::addDictKeyHandler(std::string const& key, std::shared_ptr<JSONHandler> dkh) |
| 58 | { | 57 | { |
| 59 | m->h.dict_handlers[key] = dkh; | 58 | m->h.dict_handlers[key] = dkh; |
| 60 | } | 59 | } |
| @@ -67,9 +66,7 @@ JSONHandler::addFallbackDictHandler(std::shared_ptr<JSONHandler> fdh) | @@ -67,9 +66,7 @@ JSONHandler::addFallbackDictHandler(std::shared_ptr<JSONHandler> fdh) | ||
| 67 | 66 | ||
| 68 | void | 67 | void |
| 69 | JSONHandler::addArrayHandlers( | 68 | JSONHandler::addArrayHandlers( |
| 70 | - json_handler_t start_fn, | ||
| 71 | - void_handler_t end_fn, | ||
| 72 | - std::shared_ptr<JSONHandler> ah) | 69 | + json_handler_t start_fn, void_handler_t end_fn, std::shared_ptr<JSONHandler> ah) |
| 73 | { | 70 | { |
| 74 | m->h.array_start_handler = start_fn; | 71 | m->h.array_start_handler = start_fn; |
| 75 | m->h.array_end_handler = end_fn; | 72 | m->h.array_end_handler = end_fn; |
| @@ -108,22 +105,19 @@ JSONHandler::handle(std::string const& path, JSON j) | @@ -108,22 +105,19 @@ JSONHandler::handle(std::string const& path, JSON j) | ||
| 108 | if (path_base != ".") { | 105 | if (path_base != ".") { |
| 109 | path_base += "."; | 106 | path_base += "."; |
| 110 | } | 107 | } |
| 111 | - j.forEachDictItem( | ||
| 112 | - [&path, &path_base, this](std::string const& k, JSON v) { | ||
| 113 | - auto i = m->h.dict_handlers.find(k); | ||
| 114 | - if (i == m->h.dict_handlers.end()) { | ||
| 115 | - if (m->h.fallback_dict_handler.get()) { | ||
| 116 | - m->h.fallback_dict_handler->handle(path_base + k, v); | ||
| 117 | - } else { | ||
| 118 | - QTC::TC("libtests", "JSONHandler unexpected key"); | ||
| 119 | - usage( | ||
| 120 | - "JSON handler found unexpected key " + k + | ||
| 121 | - " in object at " + path); | ||
| 122 | - } | 108 | + j.forEachDictItem([&path, &path_base, this](std::string const& k, JSON v) { |
| 109 | + auto i = m->h.dict_handlers.find(k); | ||
| 110 | + if (i == m->h.dict_handlers.end()) { | ||
| 111 | + if (m->h.fallback_dict_handler.get()) { | ||
| 112 | + m->h.fallback_dict_handler->handle(path_base + k, v); | ||
| 123 | } else { | 113 | } else { |
| 124 | - i->second->handle(path_base + k, v); | 114 | + QTC::TC("libtests", "JSONHandler unexpected key"); |
| 115 | + usage("JSON handler found unexpected key " + k + " in object at " + path); | ||
| 125 | } | 116 | } |
| 126 | - }); | 117 | + } else { |
| 118 | + i->second->handle(path_base + k, v); | ||
| 119 | + } | ||
| 120 | + }); | ||
| 127 | m->h.dict_end_handler(path); | 121 | m->h.dict_end_handler(path); |
| 128 | handled = true; | 122 | handled = true; |
| 129 | } | 123 | } |
| @@ -131,8 +125,7 @@ JSONHandler::handle(std::string const& path, JSON j) | @@ -131,8 +125,7 @@ JSONHandler::handle(std::string const& path, JSON j) | ||
| 131 | m->h.array_start_handler(path, j); | 125 | m->h.array_start_handler(path, j); |
| 132 | size_t i = 0; | 126 | size_t i = 0; |
| 133 | j.forEachArrayItem([&i, &path, this](JSON v) { | 127 | j.forEachArrayItem([&i, &path, this](JSON v) { |
| 134 | - m->h.array_item_handler->handle( | ||
| 135 | - path + "[" + std::to_string(i) + "]", v); | 128 | + m->h.array_item_handler->handle(path + "[" + std::to_string(i) + "]", v); |
| 136 | ++i; | 129 | ++i; |
| 137 | }); | 130 | }); |
| 138 | m->h.array_end_handler(path); | 131 | m->h.array_end_handler(path); |
libqpdf/MD5.cc
| @@ -81,8 +81,7 @@ MD5::encodeFile(char const* filename, qpdf_offset_t up_to_offset) | @@ -81,8 +81,7 @@ MD5::encodeFile(char const* filename, qpdf_offset_t up_to_offset) | ||
| 81 | // Assume, perhaps incorrectly, that errno was set by the | 81 | // Assume, perhaps incorrectly, that errno was set by the |
| 82 | // underlying call to read.... | 82 | // underlying call to read.... |
| 83 | (void)fclose(file); | 83 | (void)fclose(file); |
| 84 | - QUtil::throw_system_error( | ||
| 85 | - std::string("MD5: read error on ") + filename); | 84 | + QUtil::throw_system_error(std::string("MD5: read error on ") + filename); |
| 86 | } | 85 | } |
| 87 | (void)fclose(file); | 86 | (void)fclose(file); |
| 88 | 87 | ||
| @@ -115,8 +114,7 @@ MD5::unparse() | @@ -115,8 +114,7 @@ MD5::unparse() | ||
| 115 | this->crypto->MD5_finalize(); | 114 | this->crypto->MD5_finalize(); |
| 116 | Digest digest_val; | 115 | Digest digest_val; |
| 117 | digest(digest_val); | 116 | digest(digest_val); |
| 118 | - return QUtil::hex_encode( | ||
| 119 | - std::string(reinterpret_cast<char*>(digest_val), 16)); | 117 | + return QUtil::hex_encode(std::string(reinterpret_cast<char*>(digest_val), 16)); |
| 120 | } | 118 | } |
| 121 | 119 | ||
| 122 | std::string | 120 | std::string |
| @@ -143,10 +141,7 @@ MD5::checkDataChecksum(char const* const checksum, char const* buf, size_t len) | @@ -143,10 +141,7 @@ MD5::checkDataChecksum(char const* const checksum, char const* buf, size_t len) | ||
| 143 | } | 141 | } |
| 144 | 142 | ||
| 145 | bool | 143 | bool |
| 146 | -MD5::checkFileChecksum( | ||
| 147 | - char const* const checksum, | ||
| 148 | - char const* filename, | ||
| 149 | - qpdf_offset_t up_to_offset) | 144 | +MD5::checkFileChecksum(char const* const checksum, char const* filename, qpdf_offset_t up_to_offset) |
| 150 | { | 145 | { |
| 151 | bool result = false; | 146 | bool result = false; |
| 152 | try { | 147 | try { |
libqpdf/NNTree.cc
| @@ -24,8 +24,7 @@ warn(QPDF& qpdf, QPDFObjectHandle& node, std::string const& msg) | @@ -24,8 +24,7 @@ warn(QPDF& qpdf, QPDFObjectHandle& node, std::string const& msg) | ||
| 24 | static void | 24 | static void |
| 25 | error(QPDF& qpdf, QPDFObjectHandle& node, std::string const& msg) | 25 | error(QPDF& qpdf, QPDFObjectHandle& node, std::string const& msg) |
| 26 | { | 26 | { |
| 27 | - throw QPDFExc( | ||
| 28 | - qpdf_e_damaged_pdf, qpdf.getFilename(), get_description(node), 0, msg); | 27 | + throw QPDFExc(qpdf_e_damaged_pdf, qpdf.getFilename(), get_description(node), 0, msg); |
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | NNTreeIterator::NNTreeIterator(NNTreeImpl& impl) : | 30 | NNTreeIterator::NNTreeIterator(NNTreeImpl& impl) : |
| @@ -76,8 +75,7 @@ NNTreeIterator::updateIValue(bool allow_invalid) | @@ -76,8 +75,7 @@ NNTreeIterator::updateIValue(bool allow_invalid) | ||
| 76 | } | 75 | } |
| 77 | } | 76 | } |
| 78 | 77 | ||
| 79 | -NNTreeIterator::PathElement::PathElement( | ||
| 80 | - QPDFObjectHandle const& node, int kid_number) : | 78 | +NNTreeIterator::PathElement::PathElement(QPDFObjectHandle const& node, int kid_number) : |
| 81 | node(node), | 79 | node(node), |
| 82 | kid_number(kid_number) | 80 | kid_number(kid_number) |
| 83 | { | 81 | { |
| @@ -94,16 +92,14 @@ NNTreeIterator::getNextKid(PathElement& pe, bool backward) | @@ -94,16 +92,14 @@ NNTreeIterator::getNextKid(PathElement& pe, bool backward) | ||
| 94 | if ((pe.kid_number >= 0) && (pe.kid_number < kids.getArrayNItems())) { | 92 | if ((pe.kid_number >= 0) && (pe.kid_number < kids.getArrayNItems())) { |
| 95 | result = kids.getArrayItem(pe.kid_number); | 93 | result = kids.getArrayItem(pe.kid_number); |
| 96 | if (result.isDictionary() && | 94 | if (result.isDictionary() && |
| 97 | - (result.hasKey("/Kids") || | ||
| 98 | - result.hasKey(impl.details.itemsKey()))) { | 95 | + (result.hasKey("/Kids") || result.hasKey(impl.details.itemsKey()))) { |
| 99 | found = true; | 96 | found = true; |
| 100 | } else { | 97 | } else { |
| 101 | QTC::TC("qpdf", "NNTree skip invalid kid"); | 98 | QTC::TC("qpdf", "NNTree skip invalid kid"); |
| 102 | warn( | 99 | warn( |
| 103 | impl.qpdf, | 100 | impl.qpdf, |
| 104 | pe.node, | 101 | pe.node, |
| 105 | - ("skipping over invalid kid at index " + | ||
| 106 | - std::to_string(pe.kid_number))); | 102 | + ("skipping over invalid kid at index " + std::to_string(pe.kid_number))); |
| 107 | } | 103 | } |
| 108 | } else { | 104 | } else { |
| 109 | result = QPDFObjectHandle::newNull(); | 105 | result = QPDFObjectHandle::newNull(); |
| @@ -131,8 +127,7 @@ NNTreeIterator::increment(bool backward) | @@ -131,8 +127,7 @@ NNTreeIterator::increment(bool backward) | ||
| 131 | while (valid() && (!found_valid_key)) { | 127 | while (valid() && (!found_valid_key)) { |
| 132 | this->item_number += backward ? -2 : 2; | 128 | this->item_number += backward ? -2 : 2; |
| 133 | auto items = this->node.getKey(impl.details.itemsKey()); | 129 | auto items = this->node.getKey(impl.details.itemsKey()); |
| 134 | - if ((this->item_number < 0) || | ||
| 135 | - (this->item_number >= items.getArrayNItems())) { | 130 | + if ((this->item_number < 0) || (this->item_number >= items.getArrayNItems())) { |
| 136 | bool found = false; | 131 | bool found = false; |
| 137 | setItemNumber(QPDFObjectHandle(), -1); | 132 | setItemNumber(QPDFObjectHandle(), -1); |
| 138 | while (!(found || this->path.empty())) { | 133 | while (!(found || this->path.empty())) { |
| @@ -149,18 +144,13 @@ NNTreeIterator::increment(bool backward) | @@ -149,18 +144,13 @@ NNTreeIterator::increment(bool backward) | ||
| 149 | items = this->node.getKey(impl.details.itemsKey()); | 144 | items = this->node.getKey(impl.details.itemsKey()); |
| 150 | if (this->item_number + 1 >= items.getArrayNItems()) { | 145 | if (this->item_number + 1 >= items.getArrayNItems()) { |
| 151 | QTC::TC("qpdf", "NNTree skip item at end of short items"); | 146 | QTC::TC("qpdf", "NNTree skip item at end of short items"); |
| 152 | - warn( | ||
| 153 | - impl.qpdf, | ||
| 154 | - this->node, | ||
| 155 | - "items array doesn't have enough elements"); | ||
| 156 | - } else if (!impl.details.keyValid( | ||
| 157 | - items.getArrayItem(this->item_number))) { | 147 | + warn(impl.qpdf, this->node, "items array doesn't have enough elements"); |
| 148 | + } else if (!impl.details.keyValid(items.getArrayItem(this->item_number))) { | ||
| 158 | QTC::TC("qpdf", "NNTree skip invalid key"); | 149 | QTC::TC("qpdf", "NNTree skip invalid key"); |
| 159 | warn( | 150 | warn( |
| 160 | impl.qpdf, | 151 | impl.qpdf, |
| 161 | this->node, | 152 | this->node, |
| 162 | - ("item " + std::to_string(this->item_number) + | ||
| 163 | - " has the wrong type")); | 153 | + ("item " + std::to_string(this->item_number) + " has the wrong type")); |
| 164 | } else { | 154 | } else { |
| 165 | found_valid_key = true; | 155 | found_valid_key = true; |
| 166 | } | 156 | } |
| @@ -169,8 +159,7 @@ NNTreeIterator::increment(bool backward) | @@ -169,8 +159,7 @@ NNTreeIterator::increment(bool backward) | ||
| 169 | } | 159 | } |
| 170 | 160 | ||
| 171 | void | 161 | void |
| 172 | -NNTreeIterator::resetLimits( | ||
| 173 | - QPDFObjectHandle node, std::list<PathElement>::iterator parent) | 162 | +NNTreeIterator::resetLimits(QPDFObjectHandle node, std::list<PathElement>::iterator parent) |
| 174 | { | 163 | { |
| 175 | bool done = false; | 164 | bool done = false; |
| 176 | while (!done) { | 165 | while (!done) { |
| @@ -197,10 +186,8 @@ NNTreeIterator::resetLimits( | @@ -197,10 +186,8 @@ NNTreeIterator::resetLimits( | ||
| 197 | if (first_kid.isDictionary() && last_kid.isDictionary()) { | 186 | if (first_kid.isDictionary() && last_kid.isDictionary()) { |
| 198 | auto first_limits = first_kid.getKey("/Limits"); | 187 | auto first_limits = first_kid.getKey("/Limits"); |
| 199 | auto last_limits = last_kid.getKey("/Limits"); | 188 | auto last_limits = last_kid.getKey("/Limits"); |
| 200 | - if (first_limits.isArray() && | ||
| 201 | - (first_limits.getArrayNItems() >= 2) && | ||
| 202 | - last_limits.isArray() && | ||
| 203 | - (last_limits.getArrayNItems() >= 2)) { | 189 | + if (first_limits.isArray() && (first_limits.getArrayNItems() >= 2) && |
| 190 | + last_limits.isArray() && (last_limits.getArrayNItems() >= 2)) { | ||
| 204 | first = first_limits.getArrayItem(0); | 191 | first = first_limits.getArrayItem(0); |
| 205 | last = last_limits.getArrayItem(1); | 192 | last = last_limits.getArrayItem(1); |
| 206 | } | 193 | } |
| @@ -214,8 +201,7 @@ NNTreeIterator::resetLimits( | @@ -214,8 +201,7 @@ NNTreeIterator::resetLimits( | ||
| 214 | if (olimits.isArray() && (olimits.getArrayNItems() == 2)) { | 201 | if (olimits.isArray() && (olimits.getArrayNItems() == 2)) { |
| 215 | auto ofirst = olimits.getArrayItem(0); | 202 | auto ofirst = olimits.getArrayItem(0); |
| 216 | auto olast = olimits.getArrayItem(1); | 203 | auto olast = olimits.getArrayItem(1); |
| 217 | - if (impl.details.keyValid(ofirst) && | ||
| 218 | - impl.details.keyValid(olast) && | 204 | + if (impl.details.keyValid(ofirst) && impl.details.keyValid(olast) && |
| 219 | (impl.details.compareKeys(first, ofirst) == 0) && | 205 | (impl.details.compareKeys(first, ofirst) == 0) && |
| 220 | (impl.details.compareKeys(last, olast) == 0)) { | 206 | (impl.details.compareKeys(last, olast) == 0)) { |
| 221 | QTC::TC("qpdf", "NNTree limits didn't change"); | 207 | QTC::TC("qpdf", "NNTree limits didn't change"); |
| @@ -240,8 +226,7 @@ NNTreeIterator::resetLimits( | @@ -240,8 +226,7 @@ NNTreeIterator::resetLimits( | ||
| 240 | } | 226 | } |
| 241 | 227 | ||
| 242 | void | 228 | void |
| 243 | -NNTreeIterator::split( | ||
| 244 | - QPDFObjectHandle to_split, std::list<PathElement>::iterator parent) | 229 | +NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterator parent) |
| 245 | { | 230 | { |
| 246 | // Split some node along the path to the item pointed to by this | 231 | // Split some node along the path to the item pointed to by this |
| 247 | // iterator, and adjust the iterator so it points to the same | 232 | // iterator, and adjust the iterator so it points to the same |
| @@ -272,8 +257,7 @@ NNTreeIterator::split( | @@ -272,8 +257,7 @@ NNTreeIterator::split( | ||
| 272 | // item_number: 0 | 257 | // item_number: 0 |
| 273 | 258 | ||
| 274 | if (!valid()) { | 259 | if (!valid()) { |
| 275 | - throw std::logic_error( | ||
| 276 | - "NNTreeIterator::split called an invalid iterator"); | 260 | + throw std::logic_error("NNTreeIterator::split called an invalid iterator"); |
| 277 | } | 261 | } |
| 278 | 262 | ||
| 279 | // Find the array we actually need to split, which is either this | 263 | // Find the array we actually need to split, which is either this |
| @@ -335,8 +319,7 @@ NNTreeIterator::split( | @@ -335,8 +319,7 @@ NNTreeIterator::split( | ||
| 335 | // non-root case so remaining logic can handle them in the | 319 | // non-root case so remaining logic can handle them in the |
| 336 | // same way. | 320 | // same way. |
| 337 | 321 | ||
| 338 | - auto first_node = | ||
| 339 | - impl.qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); | 322 | + auto first_node = impl.qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); |
| 340 | first_node.replaceKey(key, first_half); | 323 | first_node.replaceKey(key, first_half); |
| 341 | QPDFObjectHandle new_kids = QPDFObjectHandle::newArray(); | 324 | QPDFObjectHandle new_kids = QPDFObjectHandle::newArray(); |
| 342 | new_kids.appendItem(first_node); | 325 | new_kids.appendItem(first_node); |
| @@ -371,8 +354,7 @@ NNTreeIterator::split( | @@ -371,8 +354,7 @@ NNTreeIterator::split( | ||
| 371 | resetLimits(to_split, parent); | 354 | resetLimits(to_split, parent); |
| 372 | 355 | ||
| 373 | // Create a new node to contain the second half | 356 | // Create a new node to contain the second half |
| 374 | - QPDFObjectHandle second_node = | ||
| 375 | - impl.qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); | 357 | + QPDFObjectHandle second_node = impl.qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); |
| 376 | second_node.replaceKey(key, second_half); | 358 | second_node.replaceKey(key, second_half); |
| 377 | resetLimits(second_node, parent); | 359 | resetLimits(second_node, parent); |
| 378 | 360 | ||
| @@ -457,10 +439,7 @@ NNTreeIterator::remove() | @@ -457,10 +439,7 @@ NNTreeIterator::remove() | ||
| 457 | auto items = this->node.getKey(impl.details.itemsKey()); | 439 | auto items = this->node.getKey(impl.details.itemsKey()); |
| 458 | int nitems = items.getArrayNItems(); | 440 | int nitems = items.getArrayNItems(); |
| 459 | if (this->item_number + 2 > nitems) { | 441 | if (this->item_number + 2 > nitems) { |
| 460 | - error( | ||
| 461 | - impl.qpdf, | ||
| 462 | - this->node, | ||
| 463 | - "found short items array while removing an item"); | 442 | + error(impl.qpdf, this->node, "found short items array while removing an item"); |
| 464 | } | 443 | } |
| 465 | 444 | ||
| 466 | items.eraseItem(this->item_number); | 445 | items.eraseItem(this->item_number); |
| @@ -491,8 +470,7 @@ NNTreeIterator::remove() | @@ -491,8 +470,7 @@ NNTreeIterator::remove() | ||
| 491 | } else { | 470 | } else { |
| 492 | // We already checked to ensure this condition would not | 471 | // We already checked to ensure this condition would not |
| 493 | // happen. | 472 | // happen. |
| 494 | - throw std::logic_error( | ||
| 495 | - "NNTreeIterator::remove: item_number > nitems after erase"); | 473 | + throw std::logic_error("NNTreeIterator::remove: item_number > nitems after erase"); |
| 496 | } | 474 | } |
| 497 | return; | 475 | return; |
| 498 | } | 476 | } |
| @@ -549,8 +527,7 @@ NNTreeIterator::remove() | @@ -549,8 +527,7 @@ NNTreeIterator::remove() | ||
| 549 | // empty items array. | 527 | // empty items array. |
| 550 | QTC::TC("qpdf", "NNTree non-flat tree is empty after remove"); | 528 | QTC::TC("qpdf", "NNTree non-flat tree is empty after remove"); |
| 551 | element->node.removeKey("/Kids"); | 529 | element->node.removeKey("/Kids"); |
| 552 | - element->node.replaceKey( | ||
| 553 | - impl.details.itemsKey(), QPDFObjectHandle::newArray()); | 530 | + element->node.replaceKey(impl.details.itemsKey(), QPDFObjectHandle::newArray()); |
| 554 | this->path.clear(); | 531 | this->path.clear(); |
| 555 | setItemNumber(impl.oh, -1); | 532 | setItemNumber(impl.oh, -1); |
| 556 | done = true; | 533 | done = true; |
| @@ -645,20 +622,14 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | @@ -645,20 +622,14 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | ||
| 645 | while (!failed) { | 622 | while (!failed) { |
| 646 | if (!seen.add(node)) { | 623 | if (!seen.add(node)) { |
| 647 | QTC::TC("qpdf", "NNTree deepen: loop"); | 624 | QTC::TC("qpdf", "NNTree deepen: loop"); |
| 648 | - warn( | ||
| 649 | - impl.qpdf, | ||
| 650 | - node, | ||
| 651 | - "loop detected while traversing name/number tree"); | 625 | + warn(impl.qpdf, node, "loop detected while traversing name/number tree"); |
| 652 | failed = true; | 626 | failed = true; |
| 653 | break; | 627 | break; |
| 654 | } | 628 | } |
| 655 | 629 | ||
| 656 | if (!node.isDictionary()) { | 630 | if (!node.isDictionary()) { |
| 657 | QTC::TC("qpdf", "NNTree node is not a dictionary"); | 631 | QTC::TC("qpdf", "NNTree node is not a dictionary"); |
| 658 | - warn( | ||
| 659 | - impl.qpdf, | ||
| 660 | - node, | ||
| 661 | - "non-dictionary node while traversing name/number tree"); | 632 | + warn(impl.qpdf, node, "non-dictionary node while traversing name/number tree"); |
| 662 | failed = true; | 633 | failed = true; |
| 663 | break; | 634 | break; |
| 664 | } | 635 | } |
| @@ -703,8 +674,8 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | @@ -703,8 +674,8 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | ||
| 703 | warn( | 674 | warn( |
| 704 | impl.qpdf, | 675 | impl.qpdf, |
| 705 | node, | 676 | node, |
| 706 | - ("name/number tree node has neither non-empty " + | ||
| 707 | - impl.details.itemsKey() + " nor /Kids")); | 677 | + ("name/number tree node has neither non-empty " + impl.details.itemsKey() + |
| 678 | + " nor /Kids")); | ||
| 708 | failed = true; | 679 | failed = true; |
| 709 | break; | 680 | break; |
| 710 | } | 681 | } |
| @@ -717,10 +688,7 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | @@ -717,10 +688,7 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) | ||
| 717 | } | 688 | } |
| 718 | 689 | ||
| 719 | NNTreeImpl::NNTreeImpl( | 690 | NNTreeImpl::NNTreeImpl( |
| 720 | - NNTreeDetails const& details, | ||
| 721 | - QPDF& qpdf, | ||
| 722 | - QPDFObjectHandle& oh, | ||
| 723 | - bool auto_repair) : | 691 | + NNTreeDetails const& details, QPDF& qpdf, QPDFObjectHandle& oh, bool auto_repair) : |
| 724 | details(details), | 692 | details(details), |
| 725 | qpdf(qpdf), | 693 | qpdf(qpdf), |
| 726 | split_threshold(32), | 694 | split_threshold(32), |
| @@ -763,8 +731,7 @@ NNTreeImpl::withinLimits(QPDFObjectHandle key, QPDFObjectHandle node) | @@ -763,8 +731,7 @@ NNTreeImpl::withinLimits(QPDFObjectHandle key, QPDFObjectHandle node) | ||
| 763 | int result = 0; | 731 | int result = 0; |
| 764 | auto limits = node.getKey("/Limits"); | 732 | auto limits = node.getKey("/Limits"); |
| 765 | if (limits.isArray() && (limits.getArrayNItems() >= 2) && | 733 | if (limits.isArray() && (limits.getArrayNItems() >= 2) && |
| 766 | - details.keyValid(limits.getArrayItem(0)) && | ||
| 767 | - details.keyValid(limits.getArrayItem(1))) { | 734 | + details.keyValid(limits.getArrayItem(0)) && details.keyValid(limits.getArrayItem(1))) { |
| 768 | if (details.compareKeys(key, limits.getArrayItem(0)) < 0) { | 735 | if (details.compareKeys(key, limits.getArrayItem(0)) < 0) { |
| 769 | result = -1; | 736 | result = -1; |
| 770 | } else if (details.compareKeys(key, limits.getArrayItem(1)) > 0) { | 737 | } else if (details.compareKeys(key, limits.getArrayItem(1)) > 0) { |
| @@ -783,8 +750,7 @@ NNTreeImpl::binarySearch( | @@ -783,8 +750,7 @@ NNTreeImpl::binarySearch( | ||
| 783 | QPDFObjectHandle items, | 750 | QPDFObjectHandle items, |
| 784 | int num_items, | 751 | int num_items, |
| 785 | bool return_prev_if_not_found, | 752 | bool return_prev_if_not_found, |
| 786 | - int (NNTreeImpl::*compare)( | ||
| 787 | - QPDFObjectHandle& key, QPDFObjectHandle& arr, int item)) | 753 | + int (NNTreeImpl::*compare)(QPDFObjectHandle& key, QPDFObjectHandle& arr, int item)) |
| 788 | { | 754 | { |
| 789 | int max_idx = 1; | 755 | int max_idx = 1; |
| 790 | while (max_idx < num_items) { | 756 | while (max_idx < num_items) { |
| @@ -838,8 +804,7 @@ NNTreeImpl::binarySearch( | @@ -838,8 +804,7 @@ NNTreeImpl::binarySearch( | ||
| 838 | } | 804 | } |
| 839 | 805 | ||
| 840 | int | 806 | int |
| 841 | -NNTreeImpl::compareKeyItem( | ||
| 842 | - QPDFObjectHandle& key, QPDFObjectHandle& items, int idx) | 807 | +NNTreeImpl::compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx) |
| 843 | { | 808 | { |
| 844 | if (!((items.isArray() && (items.getArrayNItems() > (2 * idx)) && | 809 | if (!((items.isArray() && (items.getArrayNItems() > (2 * idx)) && |
| 845 | details.keyValid(items.getArrayItem(2 * idx))))) { | 810 | details.keyValid(items.getArrayItem(2 * idx))))) { |
| @@ -847,15 +812,13 @@ NNTreeImpl::compareKeyItem( | @@ -847,15 +812,13 @@ NNTreeImpl::compareKeyItem( | ||
| 847 | error( | 812 | error( |
| 848 | qpdf, | 813 | qpdf, |
| 849 | this->oh, | 814 | this->oh, |
| 850 | - ("item at index " + std::to_string(2 * idx) + | ||
| 851 | - " is not the right type")); | 815 | + ("item at index " + std::to_string(2 * idx) + " is not the right type")); |
| 852 | } | 816 | } |
| 853 | return details.compareKeys(key, items.getArrayItem(2 * idx)); | 817 | return details.compareKeys(key, items.getArrayItem(2 * idx)); |
| 854 | } | 818 | } |
| 855 | 819 | ||
| 856 | int | 820 | int |
| 857 | -NNTreeImpl::compareKeyKid( | ||
| 858 | - QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx) | 821 | +NNTreeImpl::compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx) |
| 859 | { | 822 | { |
| 860 | if (!(kids.isArray() && (idx < kids.getArrayNItems()) && | 823 | if (!(kids.isArray() && (idx < kids.getArrayNItems()) && |
| 861 | kids.getArrayItem(idx).isDictionary())) { | 824 | kids.getArrayItem(idx).isDictionary())) { |
| @@ -875,8 +838,7 @@ NNTreeImpl::repair() | @@ -875,8 +838,7 @@ NNTreeImpl::repair() | ||
| 875 | repl.insert(i.first, i.second); | 838 | repl.insert(i.first, i.second); |
| 876 | } | 839 | } |
| 877 | this->oh.replaceKey("/Kids", new_node.getKey("/Kids")); | 840 | this->oh.replaceKey("/Kids", new_node.getKey("/Kids")); |
| 878 | - this->oh.replaceKey( | ||
| 879 | - details.itemsKey(), new_node.getKey(details.itemsKey())); | 841 | + this->oh.replaceKey(details.itemsKey(), new_node.getKey(details.itemsKey())); |
| 880 | } | 842 | } |
| 881 | 843 | ||
| 882 | NNTreeImpl::iterator | 844 | NNTreeImpl::iterator |
| @@ -887,10 +849,7 @@ NNTreeImpl::find(QPDFObjectHandle key, bool return_prev_if_not_found) | @@ -887,10 +849,7 @@ NNTreeImpl::find(QPDFObjectHandle key, bool return_prev_if_not_found) | ||
| 887 | } catch (QPDFExc& e) { | 849 | } catch (QPDFExc& e) { |
| 888 | if (this->auto_repair) { | 850 | if (this->auto_repair) { |
| 889 | QTC::TC("qpdf", "NNTree repair"); | 851 | QTC::TC("qpdf", "NNTree repair"); |
| 890 | - warn( | ||
| 891 | - qpdf, | ||
| 892 | - this->oh, | ||
| 893 | - std::string("attempting to repair after error: ") + e.what()); | 852 | + warn(qpdf, this->oh, std::string("attempting to repair after error: ") + e.what()); |
| 894 | repair(); | 853 | repair(); |
| 895 | return findInternal(key, return_prev_if_not_found); | 854 | return findInternal(key, return_prev_if_not_found); |
| 896 | } else { | 855 | } else { |
| @@ -939,18 +898,13 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found) | @@ -939,18 +898,13 @@ NNTreeImpl::findInternal(QPDFObjectHandle key, bool return_prev_if_not_found) | ||
| 939 | int nitems = items.isArray() ? items.getArrayNItems() : 0; | 898 | int nitems = items.isArray() ? items.getArrayNItems() : 0; |
| 940 | if (nitems > 0) { | 899 | if (nitems > 0) { |
| 941 | int idx = binarySearch( | 900 | int idx = binarySearch( |
| 942 | - key, | ||
| 943 | - items, | ||
| 944 | - nitems / 2, | ||
| 945 | - return_prev_if_not_found, | ||
| 946 | - &NNTreeImpl::compareKeyItem); | 901 | + key, items, nitems / 2, return_prev_if_not_found, &NNTreeImpl::compareKeyItem); |
| 947 | if (idx >= 0) { | 902 | if (idx >= 0) { |
| 948 | result.setItemNumber(node, 2 * idx); | 903 | result.setItemNumber(node, 2 * idx); |
| 949 | } | 904 | } |
| 950 | break; | 905 | break; |
| 951 | } else if (nkids > 0) { | 906 | } else if (nkids > 0) { |
| 952 | - int idx = binarySearch( | ||
| 953 | - key, kids, nkids, true, &NNTreeImpl::compareKeyKid); | 907 | + int idx = binarySearch(key, kids, nkids, true, &NNTreeImpl::compareKeyKid); |
| 954 | if (idx == -1) { | 908 | if (idx == -1) { |
| 955 | QTC::TC("qpdf", "NNTree -1 in binary search"); | 909 | QTC::TC("qpdf", "NNTree -1 in binary search"); |
| 956 | error( | 910 | error( |
libqpdf/OffsetInputSource.cc
| @@ -10,11 +10,9 @@ OffsetInputSource::OffsetInputSource( | @@ -10,11 +10,9 @@ OffsetInputSource::OffsetInputSource( | ||
| 10 | global_offset(global_offset) | 10 | global_offset(global_offset) |
| 11 | { | 11 | { |
| 12 | if (global_offset < 0) { | 12 | if (global_offset < 0) { |
| 13 | - throw std::logic_error( | ||
| 14 | - "OffsetInputSource constructed with negative offset"); | 13 | + throw std::logic_error("OffsetInputSource constructed with negative offset"); |
| 15 | } | 14 | } |
| 16 | - this->max_safe_offset = | ||
| 17 | - std::numeric_limits<qpdf_offset_t>::max() - global_offset; | 15 | + this->max_safe_offset = std::numeric_limits<qpdf_offset_t>::max() - global_offset; |
| 18 | } | 16 | } |
| 19 | 17 | ||
| 20 | qpdf_offset_t | 18 | qpdf_offset_t |
| @@ -51,8 +49,7 @@ OffsetInputSource::seek(qpdf_offset_t offset, int whence) | @@ -51,8 +49,7 @@ OffsetInputSource::seek(qpdf_offset_t offset, int whence) | ||
| 51 | this->proxied->seek(offset, whence); | 49 | this->proxied->seek(offset, whence); |
| 52 | } | 50 | } |
| 53 | if (tell() < 0) { | 51 | if (tell() < 0) { |
| 54 | - throw std::runtime_error( | ||
| 55 | - "offset input source: seek before beginning of file"); | 52 | + throw std::runtime_error("offset input source: seek before beginning of file"); |
| 56 | } | 53 | } |
| 57 | } | 54 | } |
| 58 | 55 |
libqpdf/PDFVersion.cc
| @@ -7,8 +7,7 @@ PDFVersion::PDFVersion() : | @@ -7,8 +7,7 @@ PDFVersion::PDFVersion() : | ||
| 7 | { | 7 | { |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | -PDFVersion::PDFVersion( | ||
| 11 | - int major_version, int minor_version, int extension_level) : | 10 | +PDFVersion::PDFVersion(int major_version, int minor_version, int extension_level) : |
| 12 | major_version(major_version), | 11 | major_version(major_version), |
| 13 | minor_version(minor_version), | 12 | minor_version(minor_version), |
| 14 | extension_level(extension_level) | 13 | extension_level(extension_level) |
| @@ -31,8 +30,7 @@ bool | @@ -31,8 +30,7 @@ bool | ||
| 31 | PDFVersion::operator==(PDFVersion const& rhs) const | 30 | PDFVersion::operator==(PDFVersion const& rhs) const |
| 32 | { | 31 | { |
| 33 | return ( | 32 | return ( |
| 34 | - (this->major_version == rhs.major_version) && | ||
| 35 | - (this->minor_version == rhs.minor_version) && | 33 | + (this->major_version == rhs.major_version) && (this->minor_version == rhs.minor_version) && |
| 36 | (this->extension_level == rhs.extension_level)); | 34 | (this->extension_level == rhs.extension_level)); |
| 37 | } | 35 | } |
| 38 | 36 | ||
| @@ -48,8 +46,7 @@ void | @@ -48,8 +46,7 @@ void | ||
| 48 | PDFVersion::getVersion(std::string& version, int& extension_level) const | 46 | PDFVersion::getVersion(std::string& version, int& extension_level) const |
| 49 | { | 47 | { |
| 50 | extension_level = this->extension_level; | 48 | extension_level = this->extension_level; |
| 51 | - version = std::to_string(this->major_version) + "." + | ||
| 52 | - std::to_string(this->minor_version); | 49 | + version = std::to_string(this->major_version) + "." + std::to_string(this->minor_version); |
| 53 | } | 50 | } |
| 54 | 51 | ||
| 55 | int | 52 | int |
libqpdf/Pipeline.cc
| @@ -14,8 +14,7 @@ Pipeline::getNext(bool allow_null) | @@ -14,8 +14,7 @@ Pipeline::getNext(bool allow_null) | ||
| 14 | { | 14 | { |
| 15 | if ((this->next == nullptr) && (!allow_null)) { | 15 | if ((this->next == nullptr) && (!allow_null)) { |
| 16 | throw std::logic_error( | 16 | throw std::logic_error( |
| 17 | - this->identifier + | ||
| 18 | - ": Pipeline::getNext() called on pipeline with no next"); | 17 | + this->identifier + ": Pipeline::getNext() called on pipeline with no next"); |
| 19 | } | 18 | } |
| 20 | return this->next; | 19 | return this->next; |
| 21 | } | 20 | } |
libqpdf/Pl_AES_PDF.cc
| @@ -117,8 +117,7 @@ Pl_AES_PDF::finish() | @@ -117,8 +117,7 @@ Pl_AES_PDF::finish() | ||
| 117 | throw std::logic_error("buffer overflow in AES encryption" | 117 | throw std::logic_error("buffer overflow in AES encryption" |
| 118 | " pipeline"); | 118 | " pipeline"); |
| 119 | } | 119 | } |
| 120 | - std::memset( | ||
| 121 | - this->inbuf + this->offset, 0, this->buf_size - this->offset); | 120 | + std::memset(this->inbuf + this->offset, 0, this->buf_size - this->offset); |
| 122 | this->offset = this->buf_size; | 121 | this->offset = this->buf_size; |
| 123 | } | 122 | } |
| 124 | flush(!this->disable_padding); | 123 | flush(!this->disable_padding); |
| @@ -149,8 +148,7 @@ void | @@ -149,8 +148,7 @@ void | ||
| 149 | Pl_AES_PDF::flush(bool strip_padding) | 148 | Pl_AES_PDF::flush(bool strip_padding) |
| 150 | { | 149 | { |
| 151 | if (this->offset != this->buf_size) { | 150 | if (this->offset != this->buf_size) { |
| 152 | - throw std::logic_error( | ||
| 153 | - "AES pipeline: flush called when buffer was not full"); | 151 | + throw std::logic_error("AES pipeline: flush called when buffer was not full"); |
| 154 | } | 152 | } |
| 155 | 153 | ||
| 156 | if (first) { | 154 | if (first) { |
| @@ -177,11 +175,7 @@ Pl_AES_PDF::flush(bool strip_padding) | @@ -177,11 +175,7 @@ Pl_AES_PDF::flush(bool strip_padding) | ||
| 177 | } | 175 | } |
| 178 | } | 176 | } |
| 179 | this->crypto->rijndael_init( | 177 | this->crypto->rijndael_init( |
| 180 | - encrypt, | ||
| 181 | - this->key.get(), | ||
| 182 | - key_bytes, | ||
| 183 | - this->cbc_mode, | ||
| 184 | - this->cbc_block); | 178 | + encrypt, this->key.get(), key_bytes, this->cbc_mode, this->cbc_block); |
| 185 | if (return_after_init) { | 179 | if (return_after_init) { |
| 186 | return; | 180 | return; |
| 187 | } | 181 | } |
libqpdf/Pl_ASCII85Decoder.cc
| @@ -26,8 +26,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) | @@ -26,8 +26,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) | ||
| 26 | flush(); | 26 | flush(); |
| 27 | eod = 2; | 27 | eod = 2; |
| 28 | } else { | 28 | } else { |
| 29 | - throw std::runtime_error( | ||
| 30 | - "broken end-of-data sequence in base 85 data"); | 29 | + throw std::runtime_error("broken end-of-data sequence in base 85 data"); |
| 31 | } | 30 | } |
| 32 | } else { | 31 | } else { |
| 33 | switch (buf[i]) { | 32 | switch (buf[i]) { |
| @@ -47,8 +46,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) | @@ -47,8 +46,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) | ||
| 47 | 46 | ||
| 48 | case 'z': | 47 | case 'z': |
| 49 | if (pos != 0) { | 48 | if (pos != 0) { |
| 50 | - throw std::runtime_error( | ||
| 51 | - "unexpected z during base 85 decode"); | 49 | + throw std::runtime_error("unexpected z during base 85 decode"); |
| 52 | } else { | 50 | } else { |
| 53 | QTC::TC("libtests", "Pl_ASCII85Decoder read z"); | 51 | QTC::TC("libtests", "Pl_ASCII85Decoder read z"); |
| 54 | unsigned char zeroes[4]; | 52 | unsigned char zeroes[4]; |
| @@ -59,8 +57,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) | @@ -59,8 +57,7 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) | ||
| 59 | 57 | ||
| 60 | default: | 58 | default: |
| 61 | if ((buf[i] < 33) || (buf[i] > 117)) { | 59 | if ((buf[i] < 33) || (buf[i] > 117)) { |
| 62 | - throw std::runtime_error( | ||
| 63 | - "character out of range during base 85 decode"); | 60 | + throw std::runtime_error("character out of range during base 85 decode"); |
| 64 | } else { | 61 | } else { |
| 65 | this->inbuf[this->pos++] = buf[i]; | 62 | this->inbuf[this->pos++] = buf[i]; |
| 66 | if (pos == 5) { | 63 | if (pos == 5) { |
| @@ -93,10 +90,7 @@ Pl_ASCII85Decoder::flush() | @@ -93,10 +90,7 @@ Pl_ASCII85Decoder::flush() | ||
| 93 | lval >>= 8; | 90 | lval >>= 8; |
| 94 | } | 91 | } |
| 95 | 92 | ||
| 96 | - QTC::TC( | ||
| 97 | - "libtests", | ||
| 98 | - "Pl_ASCII85Decoder partial flush", | ||
| 99 | - (this->pos == 5) ? 0 : 1); | 93 | + QTC::TC("libtests", "Pl_ASCII85Decoder partial flush", (this->pos == 5) ? 0 : 1); |
| 100 | // Reset before calling getNext()->write in case that throws an | 94 | // Reset before calling getNext()->write in case that throws an |
| 101 | // exception. | 95 | // exception. |
| 102 | auto t = this->pos - 1; | 96 | auto t = this->pos - 1; |
libqpdf/Pl_ASCIIHexDecoder.cc
| @@ -78,10 +78,7 @@ Pl_ASCIIHexDecoder::flush() | @@ -78,10 +78,7 @@ Pl_ASCIIHexDecoder::flush() | ||
| 78 | } | 78 | } |
| 79 | auto ch = static_cast<unsigned char>((b[0] << 4) + b[1]); | 79 | auto ch = static_cast<unsigned char>((b[0] << 4) + b[1]); |
| 80 | 80 | ||
| 81 | - QTC::TC( | ||
| 82 | - "libtests", | ||
| 83 | - "Pl_ASCIIHexDecoder partial flush", | ||
| 84 | - (this->pos == 2) ? 0 : 1); | 81 | + QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", (this->pos == 2) ? 0 : 1); |
| 85 | // Reset before calling getNext()->write in case that throws an | 82 | // Reset before calling getNext()->write in case that throws an |
| 86 | // exception. | 83 | // exception. |
| 87 | this->pos = 0; | 84 | this->pos = 0; |
libqpdf/Pl_Base64.cc
| @@ -91,8 +91,7 @@ void | @@ -91,8 +91,7 @@ void | ||
| 91 | Pl_Base64::flush_decode() | 91 | Pl_Base64::flush_decode() |
| 92 | { | 92 | { |
| 93 | if (this->end_of_data) { | 93 | if (this->end_of_data) { |
| 94 | - throw std::runtime_error( | ||
| 95 | - getIdentifier() + ": base64 decode: data follows pad characters"); | 94 | + throw std::runtime_error(getIdentifier() + ": base64 decode: data follows pad characters"); |
| 96 | } | 95 | } |
| 97 | int pad = 0; | 96 | int pad = 0; |
| 98 | int shift = 18; | 97 | int shift = 18; |
| @@ -110,14 +109,12 @@ Pl_Base64::flush_decode() | @@ -110,14 +109,12 @@ Pl_Base64::flush_decode() | ||
| 110 | v = 62; | 109 | v = 62; |
| 111 | } else if ((ch == '/') || (ch == '_')) { | 110 | } else if ((ch == '/') || (ch == '_')) { |
| 112 | v = 63; | 111 | v = 63; |
| 113 | - } else if ( | ||
| 114 | - (ch == '=') && ((i == 3) || ((i == 2) && (this->buf[3] == '=')))) { | 112 | + } else if ((ch == '=') && ((i == 3) || ((i == 2) && (this->buf[3] == '=')))) { |
| 115 | ++pad; | 113 | ++pad; |
| 116 | this->end_of_data = true; | 114 | this->end_of_data = true; |
| 117 | v = 0; | 115 | v = 0; |
| 118 | } else { | 116 | } else { |
| 119 | - throw std::runtime_error( | ||
| 120 | - getIdentifier() + ": base64 decode: invalid input"); | 117 | + throw std::runtime_error(getIdentifier() + ": base64 decode: invalid input"); |
| 121 | } | 118 | } |
| 122 | outval |= v << shift; | 119 | outval |= v << shift; |
| 123 | shift -= 6; | 120 | shift -= 6; |
libqpdf/Pl_Buffer.cc
| @@ -64,8 +64,7 @@ void | @@ -64,8 +64,7 @@ void | ||
| 64 | Pl_Buffer::getMallocBuffer(unsigned char** buf, size_t* len) | 64 | Pl_Buffer::getMallocBuffer(unsigned char** buf, size_t* len) |
| 65 | { | 65 | { |
| 66 | if (!m->ready) { | 66 | if (!m->ready) { |
| 67 | - throw std::logic_error( | ||
| 68 | - "Pl_Buffer::getMallocBuffer() called when not ready"); | 67 | + throw std::logic_error("Pl_Buffer::getMallocBuffer() called when not ready"); |
| 69 | } | 68 | } |
| 70 | auto size = m->data.length(); | 69 | auto size = m->data.length(); |
| 71 | *len = size; | 70 | *len = size; |
libqpdf/Pl_DCT.cc
| @@ -182,15 +182,12 @@ term_pipeline_destination(j_compress_ptr cinfo) | @@ -182,15 +182,12 @@ term_pipeline_destination(j_compress_ptr cinfo) | ||
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | static void | 184 | static void |
| 185 | -jpeg_pipeline_dest( | ||
| 186 | - j_compress_ptr cinfo, unsigned char* outbuffer, size_t size, Pipeline* next) | 185 | +jpeg_pipeline_dest(j_compress_ptr cinfo, unsigned char* outbuffer, size_t size, Pipeline* next) |
| 187 | { | 186 | { |
| 188 | cinfo->dest = static_cast<struct jpeg_destination_mgr*>( | 187 | cinfo->dest = static_cast<struct jpeg_destination_mgr*>( |
| 189 | // line-break | 188 | // line-break |
| 190 | (*cinfo->mem->alloc_small)( | 189 | (*cinfo->mem->alloc_small)( |
| 191 | - reinterpret_cast<j_common_ptr>(cinfo), | ||
| 192 | - JPOOL_PERMANENT, | ||
| 193 | - sizeof(dct_pipeline_dest))); | 190 | + reinterpret_cast<j_common_ptr>(cinfo), JPOOL_PERMANENT, sizeof(dct_pipeline_dest))); |
| 194 | auto* dest = reinterpret_cast<dct_pipeline_dest*>(cinfo->dest); | 191 | auto* dest = reinterpret_cast<dct_pipeline_dest*>(cinfo->dest); |
| 195 | dest->pub.init_destination = init_pipeline_destination; | 192 | dest->pub.init_destination = init_pipeline_destination; |
| 196 | dest->pub.empty_output_buffer = empty_pipeline_output_buffer; | 193 | dest->pub.empty_output_buffer = empty_pipeline_output_buffer; |
| @@ -243,9 +240,7 @@ jpeg_buffer_src(j_decompress_ptr cinfo, Buffer* buffer) | @@ -243,9 +240,7 @@ jpeg_buffer_src(j_decompress_ptr cinfo, Buffer* buffer) | ||
| 243 | cinfo->src = reinterpret_cast<jpeg_source_mgr*>( | 240 | cinfo->src = reinterpret_cast<jpeg_source_mgr*>( |
| 244 | // line-break | 241 | // line-break |
| 245 | (*cinfo->mem->alloc_small)( | 242 | (*cinfo->mem->alloc_small)( |
| 246 | - reinterpret_cast<j_common_ptr>(cinfo), | ||
| 247 | - JPOOL_PERMANENT, | ||
| 248 | - sizeof(jpeg_source_mgr))); | 243 | + reinterpret_cast<j_common_ptr>(cinfo), JPOOL_PERMANENT, sizeof(jpeg_source_mgr))); |
| 249 | 244 | ||
| 250 | jpeg_source_mgr* src = cinfo->src; | 245 | jpeg_source_mgr* src = cinfo->src; |
| 251 | src->init_source = init_buffer_source; | 246 | src->init_source = init_buffer_source; |
| @@ -262,16 +257,12 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) | @@ -262,16 +257,12 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) | ||
| 262 | { | 257 | { |
| 263 | auto* cinfo = reinterpret_cast<jpeg_compress_struct*>(cinfo_p); | 258 | auto* cinfo = reinterpret_cast<jpeg_compress_struct*>(cinfo_p); |
| 264 | 259 | ||
| 265 | -#if ( \ | ||
| 266 | - (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ | ||
| 267 | - defined(__clang__)) | 260 | +#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)) |
| 268 | # pragma GCC diagnostic push | 261 | # pragma GCC diagnostic push |
| 269 | # pragma GCC diagnostic ignored "-Wold-style-cast" | 262 | # pragma GCC diagnostic ignored "-Wold-style-cast" |
| 270 | #endif | 263 | #endif |
| 271 | jpeg_create_compress(cinfo); | 264 | jpeg_create_compress(cinfo); |
| 272 | -#if ( \ | ||
| 273 | - (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ | ||
| 274 | - defined(__clang__)) | 265 | +#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)) |
| 275 | # pragma GCC diagnostic pop | 266 | # pragma GCC diagnostic pop |
| 276 | #endif | 267 | #endif |
| 277 | static int const BUF_SIZE = 65536; | 268 | static int const BUF_SIZE = 65536; |
| @@ -290,11 +281,9 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) | @@ -290,11 +281,9 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) | ||
| 290 | 281 | ||
| 291 | jpeg_start_compress(cinfo, TRUE); | 282 | jpeg_start_compress(cinfo, TRUE); |
| 292 | 283 | ||
| 293 | - unsigned int width = | ||
| 294 | - cinfo->image_width * QIntC::to_uint(cinfo->input_components); | 284 | + unsigned int width = cinfo->image_width * QIntC::to_uint(cinfo->input_components); |
| 295 | size_t expected_size = QIntC::to_size(cinfo->image_height) * | 285 | size_t expected_size = QIntC::to_size(cinfo->image_height) * |
| 296 | - QIntC::to_size(cinfo->image_width) * | ||
| 297 | - QIntC::to_size(cinfo->input_components); | 286 | + QIntC::to_size(cinfo->image_width) * QIntC::to_size(cinfo->input_components); |
| 298 | if (b->getSize() != expected_size) { | 287 | if (b->getSize() != expected_size) { |
| 299 | throw std::runtime_error( | 288 | throw std::runtime_error( |
| 300 | "Pl_DCT: image buffer size = " + std::to_string(b->getSize()) + | 289 | "Pl_DCT: image buffer size = " + std::to_string(b->getSize()) + |
| @@ -316,16 +305,12 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b) | @@ -316,16 +305,12 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b) | ||
| 316 | { | 305 | { |
| 317 | auto* cinfo = reinterpret_cast<jpeg_decompress_struct*>(cinfo_p); | 306 | auto* cinfo = reinterpret_cast<jpeg_decompress_struct*>(cinfo_p); |
| 318 | 307 | ||
| 319 | -#if ( \ | ||
| 320 | - (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ | ||
| 321 | - defined(__clang__)) | 308 | +#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)) |
| 322 | # pragma GCC diagnostic push | 309 | # pragma GCC diagnostic push |
| 323 | # pragma GCC diagnostic ignored "-Wold-style-cast" | 310 | # pragma GCC diagnostic ignored "-Wold-style-cast" |
| 324 | #endif | 311 | #endif |
| 325 | jpeg_create_decompress(cinfo); | 312 | jpeg_create_decompress(cinfo); |
| 326 | -#if ( \ | ||
| 327 | - (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ | ||
| 328 | - defined(__clang__)) | 313 | +#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)) |
| 329 | # pragma GCC diagnostic pop | 314 | # pragma GCC diagnostic pop |
| 330 | #endif | 315 | #endif |
| 331 | jpeg_buffer_src(cinfo, b); | 316 | jpeg_buffer_src(cinfo, b); |
| @@ -333,10 +318,9 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b) | @@ -333,10 +318,9 @@ Pl_DCT::decompress(void* cinfo_p, Buffer* b) | ||
| 333 | (void)jpeg_read_header(cinfo, TRUE); | 318 | (void)jpeg_read_header(cinfo, TRUE); |
| 334 | (void)jpeg_calc_output_dimensions(cinfo); | 319 | (void)jpeg_calc_output_dimensions(cinfo); |
| 335 | 320 | ||
| 336 | - unsigned int width = | ||
| 337 | - cinfo->output_width * QIntC::to_uint(cinfo->output_components); | ||
| 338 | - JSAMPARRAY buffer = (*cinfo->mem->alloc_sarray)( | ||
| 339 | - reinterpret_cast<j_common_ptr>(cinfo), JPOOL_IMAGE, width, 1); | 321 | + unsigned int width = cinfo->output_width * QIntC::to_uint(cinfo->output_components); |
| 322 | + JSAMPARRAY buffer = | ||
| 323 | + (*cinfo->mem->alloc_sarray)(reinterpret_cast<j_common_ptr>(cinfo), JPOOL_IMAGE, width, 1); | ||
| 340 | 324 | ||
| 341 | (void)jpeg_start_decompress(cinfo); | 325 | (void)jpeg_start_decompress(cinfo); |
| 342 | while (cinfo->output_scanline < cinfo->output_height) { | 326 | while (cinfo->output_scanline < cinfo->output_height) { |
libqpdf/Pl_Flate.cc
| @@ -54,10 +54,7 @@ Pl_Flate::Members::~Members() | @@ -54,10 +54,7 @@ Pl_Flate::Members::~Members() | ||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | Pl_Flate::Pl_Flate( | 56 | Pl_Flate::Pl_Flate( |
| 57 | - char const* identifier, | ||
| 58 | - Pipeline* next, | ||
| 59 | - action_e action, | ||
| 60 | - unsigned int out_bufsize_int) : | 57 | + char const* identifier, Pipeline* next, action_e action, unsigned int out_bufsize_int) : |
| 61 | Pipeline(identifier, next), | 58 | Pipeline(identifier, next), |
| 62 | m(new Members(QIntC::to_size(out_bufsize_int), action)) | 59 | m(new Members(QIntC::to_size(out_bufsize_int), action)) |
| 63 | { | 60 | { |
| @@ -88,8 +85,7 @@ Pl_Flate::write(unsigned char const* data, size_t len) | @@ -88,8 +85,7 @@ Pl_Flate::write(unsigned char const* data, size_t len) | ||
| 88 | { | 85 | { |
| 89 | if (m->outbuf == nullptr) { | 86 | if (m->outbuf == nullptr) { |
| 90 | throw std::logic_error( | 87 | throw std::logic_error( |
| 91 | - this->identifier + | ||
| 92 | - ": Pl_Flate: write() called after finish() called"); | 88 | + this->identifier + ": Pl_Flate: write() called after finish() called"); |
| 93 | } | 89 | } |
| 94 | 90 | ||
| 95 | // Write in chunks in case len is too big to fit in an int. | 91 | // 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) | @@ -99,8 +95,7 @@ Pl_Flate::write(unsigned char const* data, size_t len) | ||
| 99 | unsigned char const* buf = data; | 95 | unsigned char const* buf = data; |
| 100 | while (bytes_left > 0) { | 96 | while (bytes_left > 0) { |
| 101 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); | 97 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); |
| 102 | - handleData( | ||
| 103 | - buf, bytes, (m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH)); | 98 | + handleData(buf, bytes, (m->action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH)); |
| 104 | bytes_left -= bytes; | 99 | bytes_left -= bytes; |
| 105 | buf += bytes; | 100 | buf += bytes; |
| 106 | } | 101 | } |
| @@ -124,9 +119,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | @@ -124,9 +119,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | ||
| 124 | 119 | ||
| 125 | // deflateInit and inflateInit are macros that use old-style | 120 | // deflateInit and inflateInit are macros that use old-style |
| 126 | // casts. | 121 | // casts. |
| 127 | -#if ( \ | ||
| 128 | - (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ | ||
| 129 | - defined(__clang__)) | 122 | +#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)) |
| 130 | # pragma GCC diagnostic push | 123 | # pragma GCC diagnostic push |
| 131 | # pragma GCC diagnostic ignored "-Wold-style-cast" | 124 | # pragma GCC diagnostic ignored "-Wold-style-cast" |
| 132 | #endif | 125 | #endif |
| @@ -135,9 +128,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | @@ -135,9 +128,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | ||
| 135 | } else { | 128 | } else { |
| 136 | err = inflateInit(&zstream); | 129 | err = inflateInit(&zstream); |
| 137 | } | 130 | } |
| 138 | -#if ( \ | ||
| 139 | - (defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ | ||
| 140 | - defined(__clang__)) | 131 | +#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__)) |
| 141 | # pragma GCC diagnostic pop | 132 | # pragma GCC diagnostic pop |
| 142 | #endif | 133 | #endif |
| 143 | 134 | ||
| @@ -171,8 +162,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | @@ -171,8 +162,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | ||
| 171 | // least one in qpdf's test suite). In some cases, we want | 162 | // least one in qpdf's test suite). In some cases, we want |
| 172 | // to know about this, because it indicates incorrect | 163 | // to know about this, because it indicates incorrect |
| 173 | // compression, so call a callback if provided. | 164 | // compression, so call a callback if provided. |
| 174 | - this->warn( | ||
| 175 | - "input stream is complete but output may still be valid", err); | 165 | + this->warn("input stream is complete but output may still be valid", err); |
| 176 | done = true; | 166 | done = true; |
| 177 | break; | 167 | break; |
| 178 | 168 | ||
| @@ -188,8 +178,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | @@ -188,8 +178,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush) | ||
| 188 | // needed, so we're done for now. | 178 | // needed, so we're done for now. |
| 189 | done = true; | 179 | done = true; |
| 190 | } | 180 | } |
| 191 | - uLong ready = | ||
| 192 | - QIntC::to_ulong(m->out_bufsize - zstream.avail_out); | 181 | + uLong ready = QIntC::to_ulong(m->out_bufsize - zstream.avail_out); |
| 193 | if (ready > 0) { | 182 | if (ready > 0) { |
| 194 | this->getNext()->write(m->outbuf.get(), ready); | 183 | this->getNext()->write(m->outbuf.get(), ready); |
| 195 | zstream.next_out = m->outbuf.get(); | 184 | zstream.next_out = m->outbuf.get(); |
| @@ -249,10 +238,8 @@ Pl_Flate::checkError(char const* prefix, int error_code) | @@ -249,10 +238,8 @@ Pl_Flate::checkError(char const* prefix, int error_code) | ||
| 249 | { | 238 | { |
| 250 | z_stream& zstream = *(static_cast<z_stream*>(m->zdata)); | 239 | z_stream& zstream = *(static_cast<z_stream*>(m->zdata)); |
| 251 | if (error_code != Z_OK) { | 240 | if (error_code != Z_OK) { |
| 252 | - char const* action_str = | ||
| 253 | - (m->action == a_deflate ? "deflate" : "inflate"); | ||
| 254 | - std::string msg = | ||
| 255 | - this->identifier + ": " + action_str + ": " + prefix + ": "; | 241 | + char const* action_str = (m->action == a_deflate ? "deflate" : "inflate"); |
| 242 | + std::string msg = this->identifier + ": " + action_str + ": " + prefix + ": "; | ||
| 256 | 243 | ||
| 257 | if (zstream.msg) { | 244 | if (zstream.msg) { |
| 258 | msg += zstream.msg; | 245 | msg += zstream.msg; |
| @@ -283,8 +270,7 @@ Pl_Flate::checkError(char const* prefix, int error_code) | @@ -283,8 +270,7 @@ Pl_Flate::checkError(char const* prefix, int error_code) | ||
| 283 | break; | 270 | break; |
| 284 | 271 | ||
| 285 | default: | 272 | default: |
| 286 | - msg += std::string("zlib unknown error (") + | ||
| 287 | - std::to_string(error_code) + ")"; | 273 | + msg += std::string("zlib unknown error (") + std::to_string(error_code) + ")"; |
| 288 | break; | 274 | break; |
| 289 | } | 275 | } |
| 290 | } | 276 | } |
libqpdf/Pl_Function.cc
| @@ -13,8 +13,7 @@ Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_t fn) : | @@ -13,8 +13,7 @@ Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_t fn) : | ||
| 13 | { | 13 | { |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | -Pl_Function::Pl_Function( | ||
| 17 | - char const* identifier, Pipeline* next, writer_c_t fn, void* udata) : | 16 | +Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_c_t fn, void* udata) : |
| 18 | Pipeline(identifier, next), | 17 | Pipeline(identifier, next), |
| 19 | m(new Members(nullptr)) | 18 | m(new Members(nullptr)) |
| 20 | { | 19 | { |
| @@ -22,14 +21,12 @@ Pl_Function::Pl_Function( | @@ -22,14 +21,12 @@ Pl_Function::Pl_Function( | ||
| 22 | int code = fn(data, len, udata); | 21 | int code = fn(data, len, udata); |
| 23 | if (code != 0) { | 22 | if (code != 0) { |
| 24 | throw std::runtime_error( | 23 | throw std::runtime_error( |
| 25 | - std::string(identifier) + " function returned code " + | ||
| 26 | - std::to_string(code)); | 24 | + std::string(identifier) + " function returned code " + std::to_string(code)); |
| 27 | } | 25 | } |
| 28 | }; | 26 | }; |
| 29 | } | 27 | } |
| 30 | 28 | ||
| 31 | -Pl_Function::Pl_Function( | ||
| 32 | - char const* identifier, Pipeline* next, writer_c_char_t fn, void* udata) : | 29 | +Pl_Function::Pl_Function(char const* identifier, Pipeline* next, writer_c_char_t fn, void* udata) : |
| 33 | Pipeline(identifier, next), | 30 | Pipeline(identifier, next), |
| 34 | m(new Members(nullptr)) | 31 | m(new Members(nullptr)) |
| 35 | { | 32 | { |
| @@ -37,8 +34,7 @@ Pl_Function::Pl_Function( | @@ -37,8 +34,7 @@ Pl_Function::Pl_Function( | ||
| 37 | int code = fn(reinterpret_cast<char const*>(data), len, udata); | 34 | int code = fn(reinterpret_cast<char const*>(data), len, udata); |
| 38 | if (code != 0) { | 35 | if (code != 0) { |
| 39 | throw std::runtime_error( | 36 | throw std::runtime_error( |
| 40 | - std::string(identifier) + " function returned code " + | ||
| 41 | - std::to_string(code)); | 37 | + std::string(identifier) + " function returned code " + std::to_string(code)); |
| 42 | } | 38 | } |
| 43 | }; | 39 | }; |
| 44 | } | 40 | } |
libqpdf/Pl_LZWDecoder.cc
| @@ -6,8 +6,7 @@ | @@ -6,8 +6,7 @@ | ||
| 6 | #include <cstring> | 6 | #include <cstring> |
| 7 | #include <stdexcept> | 7 | #include <stdexcept> |
| 8 | 8 | ||
| 9 | -Pl_LZWDecoder::Pl_LZWDecoder( | ||
| 10 | - char const* identifier, Pipeline* next, bool early_code_change) : | 9 | +Pl_LZWDecoder::Pl_LZWDecoder(char const* identifier, Pipeline* next, bool early_code_change) : |
| 11 | Pipeline(identifier, next), | 10 | Pipeline(identifier, next), |
| 12 | code_size(9), | 11 | code_size(9), |
| 13 | next(0), | 12 | next(0), |
| @@ -90,15 +89,13 @@ Pl_LZWDecoder::getFirstChar(unsigned int code) | @@ -90,15 +89,13 @@ Pl_LZWDecoder::getFirstChar(unsigned int code) | ||
| 90 | } else if (code > 257) { | 89 | } else if (code > 257) { |
| 91 | unsigned int idx = code - 258; | 90 | unsigned int idx = code - 258; |
| 92 | if (idx >= table.size()) { | 91 | if (idx >= table.size()) { |
| 93 | - throw std::runtime_error( | ||
| 94 | - "Pl_LZWDecoder::getFirstChar: table overflow"); | 92 | + throw std::runtime_error("Pl_LZWDecoder::getFirstChar: table overflow"); |
| 95 | } | 93 | } |
| 96 | Buffer& b = table.at(idx); | 94 | Buffer& b = table.at(idx); |
| 97 | result = b.getBuffer()[0]; | 95 | result = b.getBuffer()[0]; |
| 98 | } else { | 96 | } else { |
| 99 | throw std::runtime_error( | 97 | throw std::runtime_error( |
| 100 | - "Pl_LZWDecoder::getFirstChar called with invalid code (" + | ||
| 101 | - std::to_string(code) + ")"); | 98 | + "Pl_LZWDecoder::getFirstChar called with invalid code (" + std::to_string(code) + ")"); |
| 102 | } | 99 | } |
| 103 | return result; | 100 | return result; |
| 104 | } | 101 | } |
| @@ -117,8 +114,7 @@ Pl_LZWDecoder::addToTable(unsigned char next) | @@ -117,8 +114,7 @@ Pl_LZWDecoder::addToTable(unsigned char next) | ||
| 117 | } else if (this->last_code > 257) { | 114 | } else if (this->last_code > 257) { |
| 118 | unsigned int idx = this->last_code - 258; | 115 | unsigned int idx = this->last_code - 258; |
| 119 | if (idx >= table.size()) { | 116 | if (idx >= table.size()) { |
| 120 | - throw std::runtime_error( | ||
| 121 | - "Pl_LZWDecoder::addToTable: table overflow"); | 117 | + throw std::runtime_error("Pl_LZWDecoder::addToTable: table overflow"); |
| 122 | } | 118 | } |
| 123 | Buffer& b = table.at(idx); | 119 | Buffer& b = table.at(idx); |
| 124 | last_data = b.getBuffer(); | 120 | last_data = b.getBuffer(); |
| @@ -182,8 +178,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) | @@ -182,8 +178,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) | ||
| 182 | } | 178 | } |
| 183 | addToTable(next); | 179 | addToTable(next); |
| 184 | unsigned int change_idx = new_idx + code_change_delta; | 180 | unsigned int change_idx = new_idx + code_change_delta; |
| 185 | - if ((change_idx == 511) || (change_idx == 1023) || | ||
| 186 | - (change_idx == 2047)) { | 181 | + if ((change_idx == 511) || (change_idx == 1023) || (change_idx == 2047)) { |
| 187 | ++this->code_size; | 182 | ++this->code_size; |
| 188 | } | 183 | } |
| 189 | } | 184 | } |
| @@ -194,8 +189,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) | @@ -194,8 +189,7 @@ Pl_LZWDecoder::handleCode(unsigned int code) | ||
| 194 | } else { | 189 | } else { |
| 195 | unsigned int idx = code - 258; | 190 | unsigned int idx = code - 258; |
| 196 | if (idx >= table.size()) { | 191 | if (idx >= table.size()) { |
| 197 | - throw std::runtime_error( | ||
| 198 | - "Pl_LZWDecoder::handleCode: table overflow"); | 192 | + throw std::runtime_error("Pl_LZWDecoder::handleCode: table overflow"); |
| 199 | } | 193 | } |
| 200 | Buffer& b = table.at(idx); | 194 | Buffer& b = table.at(idx); |
| 201 | getNext()->write(b.getBuffer(), b.getSize()); | 195 | getNext()->write(b.getBuffer(), b.getSize()); |
libqpdf/Pl_MD5.cc
| @@ -26,8 +26,7 @@ Pl_MD5::write(unsigned char const* buf, size_t len) | @@ -26,8 +26,7 @@ Pl_MD5::write(unsigned char const* buf, size_t len) | ||
| 26 | unsigned char const* data = buf; | 26 | unsigned char const* data = buf; |
| 27 | while (bytes_left > 0) { | 27 | while (bytes_left > 0) { |
| 28 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); | 28 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); |
| 29 | - this->md5.encodeDataIncrementally( | ||
| 30 | - reinterpret_cast<char const*>(data), bytes); | 29 | + this->md5.encodeDataIncrementally(reinterpret_cast<char const*>(data), bytes); |
| 31 | bytes_left -= bytes; | 30 | bytes_left -= bytes; |
| 32 | data += bytes; | 31 | data += bytes; |
| 33 | } | 32 | } |
libqpdf/Pl_OStream.cc
| @@ -22,8 +22,7 @@ Pl_OStream::~Pl_OStream() | @@ -22,8 +22,7 @@ Pl_OStream::~Pl_OStream() | ||
| 22 | void | 22 | void |
| 23 | Pl_OStream::write(unsigned char const* buf, size_t len) | 23 | Pl_OStream::write(unsigned char const* buf, size_t len) |
| 24 | { | 24 | { |
| 25 | - m->os.write( | ||
| 26 | - reinterpret_cast<char const*>(buf), static_cast<std::streamsize>(len)); | 25 | + m->os.write(reinterpret_cast<char const*>(buf), static_cast<std::streamsize>(len)); |
| 27 | } | 26 | } |
| 28 | 27 | ||
| 29 | void | 28 | void |
libqpdf/Pl_PNGFilter.cc
| @@ -29,36 +29,28 @@ Pl_PNGFilter::Pl_PNGFilter( | @@ -29,36 +29,28 @@ Pl_PNGFilter::Pl_PNGFilter( | ||
| 29 | pos(0) | 29 | pos(0) |
| 30 | { | 30 | { |
| 31 | if (samples_per_pixel < 1) { | 31 | if (samples_per_pixel < 1) { |
| 32 | - throw std::runtime_error( | ||
| 33 | - "PNGFilter created with invalid samples_per_pixel"); | 32 | + throw std::runtime_error("PNGFilter created with invalid samples_per_pixel"); |
| 34 | } | 33 | } |
| 35 | - if (!((bits_per_sample == 1) || (bits_per_sample == 2) || | ||
| 36 | - (bits_per_sample == 4) || (bits_per_sample == 8) || | ||
| 37 | - (bits_per_sample == 16))) { | ||
| 38 | - throw std::runtime_error( | ||
| 39 | - "PNGFilter created with invalid bits_per_sample not" | ||
| 40 | - " 1, 2, 4, 8, or 16"); | 34 | + if (!((bits_per_sample == 1) || (bits_per_sample == 2) || (bits_per_sample == 4) || |
| 35 | + (bits_per_sample == 8) || (bits_per_sample == 16))) { | ||
| 36 | + throw std::runtime_error("PNGFilter created with invalid bits_per_sample not" | ||
| 37 | + " 1, 2, 4, 8, or 16"); | ||
| 41 | } | 38 | } |
| 42 | this->bytes_per_pixel = ((bits_per_sample * samples_per_pixel) + 7) / 8; | 39 | this->bytes_per_pixel = ((bits_per_sample * samples_per_pixel) + 7) / 8; |
| 43 | - unsigned long long bpr = | ||
| 44 | - ((columns * bits_per_sample * samples_per_pixel) + 7) / 8; | 40 | + unsigned long long bpr = ((columns * bits_per_sample * samples_per_pixel) + 7) / 8; |
| 45 | if ((bpr == 0) || (bpr > (UINT_MAX - 1))) { | 41 | if ((bpr == 0) || (bpr > (UINT_MAX - 1))) { |
| 46 | - throw std::runtime_error( | ||
| 47 | - "PNGFilter created with invalid columns value"); | 42 | + throw std::runtime_error("PNGFilter created with invalid columns value"); |
| 48 | } | 43 | } |
| 49 | this->bytes_per_row = bpr & UINT_MAX; | 44 | this->bytes_per_row = bpr & UINT_MAX; |
| 50 | - this->buf1 = | ||
| 51 | - QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1); | ||
| 52 | - this->buf2 = | ||
| 53 | - QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1); | 45 | + this->buf1 = QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1); |
| 46 | + this->buf2 = QUtil::make_shared_array<unsigned char>(this->bytes_per_row + 1); | ||
| 54 | memset(this->buf1.get(), 0, this->bytes_per_row + 1); | 47 | memset(this->buf1.get(), 0, this->bytes_per_row + 1); |
| 55 | memset(this->buf2.get(), 0, this->bytes_per_row + 1); | 48 | memset(this->buf2.get(), 0, this->bytes_per_row + 1); |
| 56 | this->cur_row = this->buf1.get(); | 49 | this->cur_row = this->buf1.get(); |
| 57 | this->prev_row = this->buf2.get(); | 50 | this->prev_row = this->buf2.get(); |
| 58 | 51 | ||
| 59 | // number of bytes per incoming row | 52 | // number of bytes per incoming row |
| 60 | - this->incoming = | ||
| 61 | - (action == a_encode ? this->bytes_per_row : this->bytes_per_row + 1); | 53 | + this->incoming = (action == a_encode ? this->bytes_per_row : this->bytes_per_row + 1); |
| 62 | } | 54 | } |
| 63 | 55 | ||
| 64 | void | 56 | void |
| @@ -197,8 +189,8 @@ Pl_PNGFilter::decodePaeth() | @@ -197,8 +189,8 @@ Pl_PNGFilter::decodePaeth() | ||
| 197 | upper_left = above_buffer[i - bpp]; | 189 | upper_left = above_buffer[i - bpp]; |
| 198 | } | 190 | } |
| 199 | 191 | ||
| 200 | - buffer[i] = static_cast<unsigned char>( | ||
| 201 | - buffer[i] + this->PaethPredictor(left, up, upper_left)); | 192 | + buffer[i] = |
| 193 | + static_cast<unsigned char>(buffer[i] + this->PaethPredictor(left, up, upper_left)); | ||
| 202 | } | 194 | } |
| 203 | } | 195 | } |
| 204 | 196 | ||
| @@ -227,8 +219,7 @@ Pl_PNGFilter::encodeRow() | @@ -227,8 +219,7 @@ Pl_PNGFilter::encodeRow() | ||
| 227 | getNext()->write(&ch, 1); | 219 | getNext()->write(&ch, 1); |
| 228 | if (this->prev_row) { | 220 | if (this->prev_row) { |
| 229 | for (unsigned int i = 0; i < this->bytes_per_row; ++i) { | 221 | for (unsigned int i = 0; i < this->bytes_per_row; ++i) { |
| 230 | - ch = static_cast<unsigned char>( | ||
| 231 | - this->cur_row[i] - this->prev_row[i]); | 222 | + ch = static_cast<unsigned char>(this->cur_row[i] - this->prev_row[i]); |
| 232 | getNext()->write(&ch, 1); | 223 | getNext()->write(&ch, 1); |
| 233 | } | 224 | } |
| 234 | } else { | 225 | } else { |
libqpdf/Pl_QPDFTokenizer.cc
| @@ -11,15 +11,12 @@ Pl_QPDFTokenizer::Members::Members() : | @@ -11,15 +11,12 @@ Pl_QPDFTokenizer::Members::Members() : | ||
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | Pl_QPDFTokenizer::Pl_QPDFTokenizer( | 13 | Pl_QPDFTokenizer::Pl_QPDFTokenizer( |
| 14 | - char const* identifier, | ||
| 15 | - QPDFObjectHandle::TokenFilter* filter, | ||
| 16 | - Pipeline* next) : | 14 | + char const* identifier, QPDFObjectHandle::TokenFilter* filter, Pipeline* next) : |
| 17 | Pipeline(identifier, next), | 15 | Pipeline(identifier, next), |
| 18 | m(new Members) | 16 | m(new Members) |
| 19 | { | 17 | { |
| 20 | m->filter = filter; | 18 | m->filter = filter; |
| 21 | - QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline( | ||
| 22 | - m->filter, next); | 19 | + QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(m->filter, next); |
| 23 | m->tokenizer.allowEOF(); | 20 | m->tokenizer.allowEOF(); |
| 24 | m->tokenizer.includeIgnorable(); | 21 | m->tokenizer.includeIgnorable(); |
| 25 | } | 22 | } |
| @@ -45,8 +42,8 @@ Pl_QPDFTokenizer::finish() | @@ -45,8 +42,8 @@ Pl_QPDFTokenizer::finish() | ||
| 45 | new BufferInputSource("tokenizer data", m->buf.getBuffer(), true)); | 42 | new BufferInputSource("tokenizer data", m->buf.getBuffer(), true)); |
| 46 | 43 | ||
| 47 | while (true) { | 44 | while (true) { |
| 48 | - QPDFTokenizer::Token token = m->tokenizer.readToken( | ||
| 49 | - input, "offset " + std::to_string(input->tell()), true); | 45 | + QPDFTokenizer::Token token = |
| 46 | + m->tokenizer.readToken(input, "offset " + std::to_string(input->tell()), true); | ||
| 50 | m->filter->handleToken(token); | 47 | m->filter->handleToken(token); |
| 51 | if (token.getType() == QPDFTokenizer::tt_eof) { | 48 | if (token.getType() == QPDFTokenizer::tt_eof) { |
| 52 | break; | 49 | break; |
| @@ -56,15 +53,13 @@ Pl_QPDFTokenizer::finish() | @@ -56,15 +53,13 @@ Pl_QPDFTokenizer::finish() | ||
| 56 | input->read(&ch, 1); | 53 | input->read(&ch, 1); |
| 57 | m->filter->handleToken( | 54 | m->filter->handleToken( |
| 58 | // line-break | 55 | // line-break |
| 59 | - QPDFTokenizer::Token( | ||
| 60 | - QPDFTokenizer::tt_space, std::string(1, ch))); | 56 | + QPDFTokenizer::Token(QPDFTokenizer::tt_space, std::string(1, ch))); |
| 61 | QTC::TC("qpdf", "Pl_QPDFTokenizer found ID"); | 57 | QTC::TC("qpdf", "Pl_QPDFTokenizer found ID"); |
| 62 | m->tokenizer.expectInlineImage(input); | 58 | m->tokenizer.expectInlineImage(input); |
| 63 | } | 59 | } |
| 64 | } | 60 | } |
| 65 | m->filter->handleEOF(); | 61 | m->filter->handleEOF(); |
| 66 | - QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline( | ||
| 67 | - m->filter, nullptr); | 62 | + QPDFObjectHandle::TokenFilter::PipelineAccessor::setPipeline(m->filter, nullptr); |
| 68 | Pipeline* next = this->getNext(true); | 63 | Pipeline* next = this->getNext(true); |
| 69 | if (next) { | 64 | if (next) { |
| 70 | next->finish(); | 65 | next->finish(); |
libqpdf/Pl_RC4.cc
| @@ -19,17 +19,14 @@ void | @@ -19,17 +19,14 @@ void | ||
| 19 | Pl_RC4::write(unsigned char const* data, size_t len) | 19 | Pl_RC4::write(unsigned char const* data, size_t len) |
| 20 | { | 20 | { |
| 21 | if (this->outbuf == nullptr) { | 21 | if (this->outbuf == nullptr) { |
| 22 | - throw std::logic_error( | ||
| 23 | - this->identifier + | ||
| 24 | - ": Pl_RC4: write() called after finish() called"); | 22 | + throw std::logic_error(this->identifier + ": Pl_RC4: write() called after finish() called"); |
| 25 | } | 23 | } |
| 26 | 24 | ||
| 27 | size_t bytes_left = len; | 25 | size_t bytes_left = len; |
| 28 | unsigned char const* p = data; | 26 | unsigned char const* p = data; |
| 29 | 27 | ||
| 30 | while (bytes_left > 0) { | 28 | while (bytes_left > 0) { |
| 31 | - size_t bytes = | ||
| 32 | - (bytes_left < this->out_bufsize ? bytes_left : out_bufsize); | 29 | + size_t bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize); |
| 33 | bytes_left -= bytes; | 30 | bytes_left -= bytes; |
| 34 | // lgtm[cpp/weak-cryptographic-algorithm] | 31 | // lgtm[cpp/weak-cryptographic-algorithm] |
| 35 | rc4.process(p, bytes, outbuf.get()); | 32 | rc4.process(p, bytes, outbuf.get()); |
libqpdf/Pl_RunLength.cc
| @@ -10,8 +10,7 @@ Pl_RunLength::Members::Members(action_e action) : | @@ -10,8 +10,7 @@ Pl_RunLength::Members::Members(action_e action) : | ||
| 10 | { | 10 | { |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | -Pl_RunLength::Pl_RunLength( | ||
| 14 | - char const* identifier, Pipeline* next, action_e action) : | 13 | +Pl_RunLength::Pl_RunLength(char const* identifier, Pipeline* next, action_e action) : |
| 15 | Pipeline(identifier, next), | 14 | Pipeline(identifier, next), |
| 16 | m(new Members(action)) | 15 | m(new Members(action)) |
| 17 | { | 16 | { |
| @@ -38,17 +37,12 @@ Pl_RunLength::encode(unsigned char const* data, size_t len) | @@ -38,17 +37,12 @@ Pl_RunLength::encode(unsigned char const* data, size_t len) | ||
| 38 | { | 37 | { |
| 39 | for (size_t i = 0; i < len; ++i) { | 38 | for (size_t i = 0; i < len; ++i) { |
| 40 | if ((m->state == st_top) != (m->length <= 1)) { | 39 | if ((m->state == st_top) != (m->length <= 1)) { |
| 41 | - throw std::logic_error( | ||
| 42 | - "Pl_RunLength::encode: state/length inconsistency"); | 40 | + throw std::logic_error("Pl_RunLength::encode: state/length inconsistency"); |
| 43 | } | 41 | } |
| 44 | unsigned char ch = data[i]; | 42 | unsigned char ch = data[i]; |
| 45 | - if ((m->length > 0) && | ||
| 46 | - ((m->state == st_copying) || (m->length < 128)) && | 43 | + if ((m->length > 0) && ((m->state == st_copying) || (m->length < 128)) && |
| 47 | (ch == m->buf[m->length - 1])) { | 44 | (ch == m->buf[m->length - 1])) { |
| 48 | - QTC::TC( | ||
| 49 | - "libtests", | ||
| 50 | - "Pl_RunLength: switch to run", | ||
| 51 | - (m->length == 128) ? 0 : 1); | 45 | + QTC::TC("libtests", "Pl_RunLength: switch to run", (m->length == 128) ? 0 : 1); |
| 52 | if (m->state == st_copying) { | 46 | if (m->state == st_copying) { |
| 53 | --m->length; | 47 | --m->length; |
| 54 | flush_encode(); | 48 | flush_encode(); |
| @@ -124,8 +118,7 @@ Pl_RunLength::flush_encode() | @@ -124,8 +118,7 @@ Pl_RunLength::flush_encode() | ||
| 124 | } | 118 | } |
| 125 | if (m->state == st_run) { | 119 | if (m->state == st_run) { |
| 126 | if ((m->length < 2) || (m->length > 128)) { | 120 | if ((m->length < 2) || (m->length > 128)) { |
| 127 | - throw std::logic_error( | ||
| 128 | - "Pl_RunLength: invalid length in flush_encode for run"); | 121 | + throw std::logic_error("Pl_RunLength: invalid length in flush_encode for run"); |
| 129 | } | 122 | } |
| 130 | auto ch = static_cast<unsigned char>(257 - m->length); | 123 | auto ch = static_cast<unsigned char>(257 - m->length); |
| 131 | this->getNext()->write(&ch, 1); | 124 | this->getNext()->write(&ch, 1); |
libqpdf/Pl_SHA2.cc
| @@ -51,8 +51,7 @@ void | @@ -51,8 +51,7 @@ void | ||
| 51 | Pl_SHA2::resetBits(int bits) | 51 | Pl_SHA2::resetBits(int bits) |
| 52 | { | 52 | { |
| 53 | if (this->in_progress) { | 53 | if (this->in_progress) { |
| 54 | - throw std::logic_error( | ||
| 55 | - "bit reset requested for in-progress SHA2 Pipeline"); | 54 | + throw std::logic_error("bit reset requested for in-progress SHA2 Pipeline"); |
| 56 | } | 55 | } |
| 57 | this->crypto = QPDFCryptoProvider::getImpl(); | 56 | this->crypto = QPDFCryptoProvider::getImpl(); |
| 58 | this->crypto->SHA2_init(bits); | 57 | this->crypto->SHA2_init(bits); |
| @@ -62,8 +61,7 @@ std::string | @@ -62,8 +61,7 @@ std::string | ||
| 62 | Pl_SHA2::getRawDigest() | 61 | Pl_SHA2::getRawDigest() |
| 63 | { | 62 | { |
| 64 | if (this->in_progress) { | 63 | if (this->in_progress) { |
| 65 | - throw std::logic_error( | ||
| 66 | - "digest requested for in-progress SHA2 Pipeline"); | 64 | + throw std::logic_error("digest requested for in-progress SHA2 Pipeline"); |
| 67 | } | 65 | } |
| 68 | return this->crypto->SHA2_digest(); | 66 | return this->crypto->SHA2_digest(); |
| 69 | } | 67 | } |
| @@ -72,8 +70,7 @@ std::string | @@ -72,8 +70,7 @@ std::string | ||
| 72 | Pl_SHA2::getHexDigest() | 70 | Pl_SHA2::getHexDigest() |
| 73 | { | 71 | { |
| 74 | if (this->in_progress) { | 72 | if (this->in_progress) { |
| 75 | - throw std::logic_error( | ||
| 76 | - "digest requested for in-progress SHA2 Pipeline"); | 73 | + throw std::logic_error("digest requested for in-progress SHA2 Pipeline"); |
| 77 | } | 74 | } |
| 78 | return QUtil::hex_encode(getRawDigest()); | 75 | return QUtil::hex_encode(getRawDigest()); |
| 79 | } | 76 | } |
libqpdf/Pl_StdioFile.cc
| @@ -30,8 +30,7 @@ Pl_StdioFile::write(unsigned char const* buf, size_t len) | @@ -30,8 +30,7 @@ Pl_StdioFile::write(unsigned char const* buf, size_t len) | ||
| 30 | while (len > 0) { | 30 | while (len > 0) { |
| 31 | so_far = fwrite(buf, 1, len, m->file); | 31 | so_far = fwrite(buf, 1, len, m->file); |
| 32 | if (so_far == 0) { | 32 | if (so_far == 0) { |
| 33 | - QUtil::throw_system_error( | ||
| 34 | - this->identifier + ": Pl_StdioFile::write"); | 33 | + QUtil::throw_system_error(this->identifier + ": Pl_StdioFile::write"); |
| 35 | } else { | 34 | } else { |
| 36 | buf += so_far; | 35 | buf += so_far; |
| 37 | len -= so_far; | 36 | len -= so_far; |
| @@ -43,7 +42,6 @@ void | @@ -43,7 +42,6 @@ void | ||
| 43 | Pl_StdioFile::finish() | 42 | Pl_StdioFile::finish() |
| 44 | { | 43 | { |
| 45 | if ((fflush(m->file) == -1) && (errno == EBADF)) { | 44 | if ((fflush(m->file) == -1) && (errno == EBADF)) { |
| 46 | - throw std::logic_error( | ||
| 47 | - this->identifier + ": Pl_StdioFile::finish: stream already closed"); | 45 | + throw std::logic_error(this->identifier + ": Pl_StdioFile::finish: stream already closed"); |
| 48 | } | 46 | } |
| 49 | } | 47 | } |
libqpdf/Pl_TIFFPredictor.cc
| @@ -25,23 +25,17 @@ Pl_TIFFPredictor::Pl_TIFFPredictor( | @@ -25,23 +25,17 @@ Pl_TIFFPredictor::Pl_TIFFPredictor( | ||
| 25 | pos(0) | 25 | pos(0) |
| 26 | { | 26 | { |
| 27 | if (samples_per_pixel < 1) { | 27 | if (samples_per_pixel < 1) { |
| 28 | - throw std::runtime_error( | ||
| 29 | - "TIFFPredictor created with invalid samples_per_pixel"); | 28 | + throw std::runtime_error("TIFFPredictor created with invalid samples_per_pixel"); |
| 30 | } | 29 | } |
| 31 | - if ((bits_per_sample < 1) || | ||
| 32 | - (bits_per_sample > (8 * (sizeof(unsigned long long))))) { | ||
| 33 | - throw std::runtime_error( | ||
| 34 | - "TIFFPredictor created with invalid bits_per_sample"); | 30 | + if ((bits_per_sample < 1) || (bits_per_sample > (8 * (sizeof(unsigned long long))))) { |
| 31 | + throw std::runtime_error("TIFFPredictor created with invalid bits_per_sample"); | ||
| 35 | } | 32 | } |
| 36 | - unsigned long long bpr = | ||
| 37 | - ((columns * bits_per_sample * samples_per_pixel) + 7) / 8; | 33 | + unsigned long long bpr = ((columns * bits_per_sample * samples_per_pixel) + 7) / 8; |
| 38 | if ((bpr == 0) || (bpr > (UINT_MAX - 1))) { | 34 | if ((bpr == 0) || (bpr > (UINT_MAX - 1))) { |
| 39 | - throw std::runtime_error( | ||
| 40 | - "TIFFPredictor created with invalid columns value"); | 35 | + throw std::runtime_error("TIFFPredictor created with invalid columns value"); |
| 41 | } | 36 | } |
| 42 | this->bytes_per_row = bpr & UINT_MAX; | 37 | this->bytes_per_row = bpr & UINT_MAX; |
| 43 | - this->cur_row = | ||
| 44 | - QUtil::make_shared_array<unsigned char>(this->bytes_per_row); | 38 | + this->cur_row = QUtil::make_shared_array<unsigned char>(this->bytes_per_row); |
| 45 | memset(this->cur_row.get(), 0, this->bytes_per_row); | 39 | memset(this->cur_row.get(), 0, this->bytes_per_row); |
| 46 | } | 40 | } |
| 47 | 41 | ||
| @@ -72,10 +66,7 @@ Pl_TIFFPredictor::write(unsigned char const* data, size_t len) | @@ -72,10 +66,7 @@ Pl_TIFFPredictor::write(unsigned char const* data, size_t len) | ||
| 72 | void | 66 | void |
| 73 | Pl_TIFFPredictor::processRow() | 67 | Pl_TIFFPredictor::processRow() |
| 74 | { | 68 | { |
| 75 | - QTC::TC( | ||
| 76 | - "libtests", | ||
| 77 | - "Pl_TIFFPredictor processRow", | ||
| 78 | - (action == a_decode ? 0 : 1)); | 69 | + QTC::TC("libtests", "Pl_TIFFPredictor processRow", (action == a_decode ? 0 : 1)); |
| 79 | BitWriter bw(this->getNext()); | 70 | BitWriter bw(this->getNext()); |
| 80 | BitStream in(this->cur_row.get(), this->bytes_per_row); | 71 | BitStream in(this->cur_row.get(), this->bytes_per_row); |
| 81 | std::vector<long long> prev; | 72 | std::vector<long long> prev; |
libqpdf/QPDF.cc
| @@ -105,11 +105,10 @@ namespace | @@ -105,11 +105,10 @@ namespace | ||
| 105 | void | 105 | void |
| 106 | throwException() | 106 | throwException() |
| 107 | { | 107 | { |
| 108 | - throw std::logic_error( | ||
| 109 | - "QPDF operation attempted on a QPDF object with no input " | ||
| 110 | - "source." | ||
| 111 | - " QPDF operations are invalid before processFile (or another" | ||
| 112 | - " process method) or after closeInputSource"); | 108 | + throw std::logic_error("QPDF operation attempted on a QPDF object with no input " |
| 109 | + "source." | ||
| 110 | + " QPDF operations are invalid before processFile (or another" | ||
| 111 | + " process method) or after closeInputSource"); | ||
| 113 | } | 112 | } |
| 114 | }; | 113 | }; |
| 115 | } // namespace | 114 | } // namespace |
| @@ -130,8 +129,7 @@ QPDF::ForeignStreamData::ForeignStreamData( | @@ -130,8 +129,7 @@ QPDF::ForeignStreamData::ForeignStreamData( | ||
| 130 | { | 129 | { |
| 131 | } | 130 | } |
| 132 | 131 | ||
| 133 | -QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider( | ||
| 134 | - QPDF& destination_qpdf) : | 132 | +QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider(QPDF& destination_qpdf) : |
| 135 | QPDFObjectHandle::StreamDataProvider(true), | 133 | QPDFObjectHandle::StreamDataProvider(true), |
| 136 | destination_qpdf(destination_qpdf) | 134 | destination_qpdf(destination_qpdf) |
| 137 | { | 135 | { |
| @@ -139,10 +137,7 @@ QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider( | @@ -139,10 +137,7 @@ QPDF::CopiedStreamDataProvider::CopiedStreamDataProvider( | ||
| 139 | 137 | ||
| 140 | bool | 138 | bool |
| 141 | QPDF::CopiedStreamDataProvider::provideStreamData( | 139 | QPDF::CopiedStreamDataProvider::provideStreamData( |
| 142 | - QPDFObjGen const& og, | ||
| 143 | - Pipeline* pipeline, | ||
| 144 | - bool suppress_warnings, | ||
| 145 | - bool will_retry) | 140 | + QPDFObjGen const& og, Pipeline* pipeline, bool suppress_warnings, bool will_retry) |
| 146 | { | 141 | { |
| 147 | std::shared_ptr<ForeignStreamData> foreign_data = foreign_stream_data[og]; | 142 | std::shared_ptr<ForeignStreamData> foreign_data = foreign_stream_data[og]; |
| 148 | bool result = false; | 143 | bool result = false; |
| @@ -154,8 +149,7 @@ QPDF::CopiedStreamDataProvider::provideStreamData( | @@ -154,8 +149,7 @@ QPDF::CopiedStreamDataProvider::provideStreamData( | ||
| 154 | auto foreign_stream = foreign_streams[og]; | 149 | auto foreign_stream = foreign_streams[og]; |
| 155 | result = foreign_stream.pipeStreamData( | 150 | result = foreign_stream.pipeStreamData( |
| 156 | pipeline, nullptr, 0, qpdf_dl_none, suppress_warnings, will_retry); | 151 | pipeline, nullptr, 0, qpdf_dl_none, suppress_warnings, will_retry); |
| 157 | - QTC::TC( | ||
| 158 | - "qpdf", "QPDF copy foreign with foreign_stream", result ? 0 : 1); | 152 | + QTC::TC("qpdf", "QPDF copy foreign with foreign_stream", result ? 0 : 1); |
| 159 | } | 153 | } |
| 160 | return result; | 154 | return result; |
| 161 | } | 155 | } |
| @@ -169,8 +163,7 @@ QPDF::CopiedStreamDataProvider::registerForeignStream( | @@ -169,8 +163,7 @@ QPDF::CopiedStreamDataProvider::registerForeignStream( | ||
| 169 | 163 | ||
| 170 | void | 164 | void |
| 171 | QPDF::CopiedStreamDataProvider::registerForeignStream( | 165 | QPDF::CopiedStreamDataProvider::registerForeignStream( |
| 172 | - QPDFObjGen const& local_og, | ||
| 173 | - std::shared_ptr<ForeignStreamData> foreign_stream) | 166 | + QPDFObjGen const& local_og, std::shared_ptr<ForeignStreamData> foreign_stream) |
| 174 | { | 167 | { |
| 175 | this->foreign_stream_data[local_og] = foreign_stream; | 168 | this->foreign_stream_data[local_og] = foreign_stream; |
| 176 | } | 169 | } |
| @@ -269,8 +262,7 @@ QPDF::processFile(char const* filename, char const* password) | @@ -269,8 +262,7 @@ QPDF::processFile(char const* filename, char const* password) | ||
| 269 | } | 262 | } |
| 270 | 263 | ||
| 271 | void | 264 | void |
| 272 | -QPDF::processFile( | ||
| 273 | - char const* description, FILE* filep, bool close_file, char const* password) | 265 | +QPDF::processFile(char const* description, FILE* filep, bool close_file, char const* password) |
| 274 | { | 266 | { |
| 275 | auto* fi = new FileInputSource(description, filep, close_file); | 267 | auto* fi = new FileInputSource(description, filep, close_file); |
| 276 | processInputSource(std::shared_ptr<InputSource>(fi), password); | 268 | processInputSource(std::shared_ptr<InputSource>(fi), password); |
| @@ -278,24 +270,18 @@ QPDF::processFile( | @@ -278,24 +270,18 @@ QPDF::processFile( | ||
| 278 | 270 | ||
| 279 | void | 271 | void |
| 280 | QPDF::processMemoryFile( | 272 | QPDF::processMemoryFile( |
| 281 | - char const* description, | ||
| 282 | - char const* buf, | ||
| 283 | - size_t length, | ||
| 284 | - char const* password) | 273 | + char const* description, char const* buf, size_t length, char const* password) |
| 285 | { | 274 | { |
| 286 | processInputSource( | 275 | processInputSource( |
| 287 | std::shared_ptr<InputSource>( | 276 | std::shared_ptr<InputSource>( |
| 288 | // line-break | 277 | // line-break |
| 289 | new BufferInputSource( | 278 | new BufferInputSource( |
| 290 | - description, | ||
| 291 | - new Buffer(QUtil::unsigned_char_pointer(buf), length), | ||
| 292 | - true)), | 279 | + description, new Buffer(QUtil::unsigned_char_pointer(buf), length), true)), |
| 293 | password); | 280 | password); |
| 294 | } | 281 | } |
| 295 | 282 | ||
| 296 | void | 283 | void |
| 297 | -QPDF::processInputSource( | ||
| 298 | - std::shared_ptr<InputSource> source, char const* password) | 284 | +QPDF::processInputSource(std::shared_ptr<InputSource> source, char const* password) |
| 299 | { | 285 | { |
| 300 | m->file = source; | 286 | m->file = source; |
| 301 | parse(password); | 287 | parse(password); |
| @@ -321,8 +307,7 @@ QPDF::emptyPDF() | @@ -321,8 +307,7 @@ QPDF::emptyPDF() | ||
| 321 | 307 | ||
| 322 | void | 308 | void |
| 323 | QPDF::registerStreamFilter( | 309 | QPDF::registerStreamFilter( |
| 324 | - std::string const& filter_name, | ||
| 325 | - std::function<std::shared_ptr<QPDFStreamFilter>()> factory) | 310 | + std::string const& filter_name, std::function<std::shared_ptr<QPDFStreamFilter>()> factory) |
| 326 | { | 311 | { |
| 327 | QPDF_Stream::registerStreamFilter(filter_name, factory); | 312 | QPDF_Stream::registerStreamFilter(filter_name, factory); |
| 328 | } | 313 | } |
| @@ -434,8 +419,7 @@ QPDF::findHeader() | @@ -434,8 +419,7 @@ QPDF::findHeader() | ||
| 434 | // offsets in the file are such that 0 points to the | 419 | // offsets in the file are such that 0 points to the |
| 435 | // beginning of the header. | 420 | // beginning of the header. |
| 436 | QTC::TC("qpdf", "QPDF global offset"); | 421 | QTC::TC("qpdf", "QPDF global offset"); |
| 437 | - m->file = std::shared_ptr<InputSource>( | ||
| 438 | - new OffsetInputSource(m->file, global_offset)); | 422 | + m->file = std::shared_ptr<InputSource>(new OffsetInputSource(m->file, global_offset)); |
| 439 | } | 423 | } |
| 440 | } | 424 | } |
| 441 | return valid; | 425 | return valid; |
| @@ -444,8 +428,7 @@ QPDF::findHeader() | @@ -444,8 +428,7 @@ QPDF::findHeader() | ||
| 444 | bool | 428 | bool |
| 445 | QPDF::findStartxref() | 429 | QPDF::findStartxref() |
| 446 | { | 430 | { |
| 447 | - if (readToken(m->file).isWord("startxref") && | ||
| 448 | - readToken(m->file).isInteger()) { | 431 | + if (readToken(m->file).isWord("startxref") && readToken(m->file).isInteger()) { |
| 449 | // Position in front of offset token | 432 | // Position in front of offset token |
| 450 | m->file->seek(m->file->getLastOffset(), SEEK_SET); | 433 | m->file->seek(m->file->getLastOffset(), SEEK_SET); |
| 451 | return true; | 434 | return true; |
| @@ -479,8 +462,7 @@ QPDF::parse(char const* password) | @@ -479,8 +462,7 @@ QPDF::parse(char const* password) | ||
| 479 | PatternFinder sf(*this, &QPDF::findStartxref); | 462 | PatternFinder sf(*this, &QPDF::findStartxref); |
| 480 | qpdf_offset_t xref_offset = 0; | 463 | qpdf_offset_t xref_offset = 0; |
| 481 | if (m->file->findLast("startxref", start_offset, 0, sf)) { | 464 | if (m->file->findLast("startxref", start_offset, 0, sf)) { |
| 482 | - xref_offset = | ||
| 483 | - QUtil::string_to_ll(readToken(m->file).getValue().c_str()); | 465 | + xref_offset = QUtil::string_to_ll(readToken(m->file).getValue().c_str()); |
| 484 | } | 466 | } |
| 485 | 467 | ||
| 486 | try { | 468 | try { |
| @@ -493,8 +475,7 @@ QPDF::parse(char const* password) | @@ -493,8 +475,7 @@ QPDF::parse(char const* password) | ||
| 493 | } catch (QPDFExc&) { | 475 | } catch (QPDFExc&) { |
| 494 | throw; | 476 | throw; |
| 495 | } catch (std::exception& e) { | 477 | } catch (std::exception& e) { |
| 496 | - throw damagedPDF( | ||
| 497 | - "", 0, std::string("error reading xref: ") + e.what()); | 478 | + throw damagedPDF("", 0, std::string("error reading xref: ") + e.what()); |
| 498 | } | 479 | } |
| 499 | } catch (QPDFExc& e) { | 480 | } catch (QPDFExc& e) { |
| 500 | if (m->attempt_recovery) { | 481 | if (m->attempt_recovery) { |
| @@ -515,9 +496,8 @@ QPDF::inParse(bool v) | @@ -515,9 +496,8 @@ QPDF::inParse(bool v) | ||
| 515 | if (m->in_parse == v) { | 496 | if (m->in_parse == v) { |
| 516 | // This happens if QPDFParser::parse tries to | 497 | // This happens if QPDFParser::parse tries to |
| 517 | // resolve an indirect object while it is parsing. | 498 | // resolve an indirect object while it is parsing. |
| 518 | - throw std::logic_error( | ||
| 519 | - "QPDF: re-entrant parsing detected. This is a qpdf bug." | ||
| 520 | - " Please report at https://github.com/qpdf/qpdf/issues."); | 499 | + throw std::logic_error("QPDF: re-entrant parsing detected. This is a qpdf bug." |
| 500 | + " Please report at https://github.com/qpdf/qpdf/issues."); | ||
| 521 | } | 501 | } |
| 522 | m->in_parse = v; | 502 | m->in_parse = v; |
| 523 | } | 503 | } |
| @@ -590,22 +570,19 @@ QPDF::reconstruct_xref(QPDFExc& e) | @@ -590,22 +570,19 @@ QPDF::reconstruct_xref(QPDFExc& e) | ||
| 590 | qpdf_offset_t next_line_start = m->file->tell(); | 570 | qpdf_offset_t next_line_start = m->file->tell(); |
| 591 | m->file->seek(line_start, SEEK_SET); | 571 | m->file->seek(line_start, SEEK_SET); |
| 592 | QPDFTokenizer::Token t1 = readToken(m->file, MAX_LEN); | 572 | QPDFTokenizer::Token t1 = readToken(m->file, MAX_LEN); |
| 593 | - qpdf_offset_t token_start = | ||
| 594 | - m->file->tell() - toO(t1.getValue().length()); | 573 | + qpdf_offset_t token_start = m->file->tell() - toO(t1.getValue().length()); |
| 595 | if (token_start >= next_line_start) { | 574 | if (token_start >= next_line_start) { |
| 596 | // don't process yet -- wait until we get to the line | 575 | // don't process yet -- wait until we get to the line |
| 597 | // containing this token | 576 | // containing this token |
| 598 | } else if (t1.isInteger()) { | 577 | } else if (t1.isInteger()) { |
| 599 | QPDFTokenizer::Token t2 = readToken(m->file, MAX_LEN); | 578 | QPDFTokenizer::Token t2 = readToken(m->file, MAX_LEN); |
| 600 | - if ((t2.isInteger()) && | ||
| 601 | - (readToken(m->file, MAX_LEN).isWord("obj"))) { | 579 | + if ((t2.isInteger()) && (readToken(m->file, MAX_LEN).isWord("obj"))) { |
| 602 | int obj = QUtil::string_to_int(t1.getValue().c_str()); | 580 | int obj = QUtil::string_to_int(t1.getValue().c_str()); |
| 603 | int gen = QUtil::string_to_int(t2.getValue().c_str()); | 581 | int gen = QUtil::string_to_int(t2.getValue().c_str()); |
| 604 | insertXrefEntry(obj, 1, token_start, gen, true); | 582 | insertXrefEntry(obj, 1, token_start, gen, true); |
| 605 | } | 583 | } |
| 606 | } else if (!m->trailer.isInitialized() && t1.isWord("trailer")) { | 584 | } else if (!m->trailer.isInitialized() && t1.isWord("trailer")) { |
| 607 | - QPDFObjectHandle t = | ||
| 608 | - readObject(m->file, "trailer", QPDFObjGen(), false); | 585 | + QPDFObjectHandle t = readObject(m->file, "trailer", QPDFObjGen(), false); |
| 609 | if (!t.isDictionary()) { | 586 | if (!t.isDictionary()) { |
| 610 | // Oh well. It was worth a try. | 587 | // Oh well. It was worth a try. |
| 611 | } else { | 588 | } else { |
| @@ -623,10 +600,7 @@ QPDF::reconstruct_xref(QPDFExc& e) | @@ -623,10 +600,7 @@ QPDF::reconstruct_xref(QPDFExc& e) | ||
| 623 | // with bad startxref pointers even when they have object | 600 | // with bad startxref pointers even when they have object |
| 624 | // streams. | 601 | // streams. |
| 625 | 602 | ||
| 626 | - throw damagedPDF( | ||
| 627 | - "", | ||
| 628 | - 0, | ||
| 629 | - "unable to find trailer dictionary while recovering damaged file"); | 603 | + throw damagedPDF("", 0, "unable to find trailer dictionary while recovering damaged file"); |
| 630 | } | 604 | } |
| 631 | 605 | ||
| 632 | // We could iterate through the objects looking for streams and | 606 | // We could iterate through the objects looking for streams and |
| @@ -666,10 +640,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | @@ -666,10 +640,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | ||
| 666 | done = true; | 640 | done = true; |
| 667 | } | 641 | } |
| 668 | } else { | 642 | } else { |
| 669 | - QTC::TC( | ||
| 670 | - "qpdf", | ||
| 671 | - "QPDF eof skipping spaces before xref", | ||
| 672 | - skipped_space ? 0 : 1); | 643 | + QTC::TC("qpdf", "QPDF eof skipping spaces before xref", skipped_space ? 0 : 1); |
| 673 | done = true; | 644 | done = true; |
| 674 | } | 645 | } |
| 675 | } | 646 | } |
| @@ -681,8 +652,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | @@ -681,8 +652,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | ||
| 681 | if ((strncmp(buf, "xref", 4) == 0) && QUtil::is_space(buf[4])) { | 652 | if ((strncmp(buf, "xref", 4) == 0) && QUtil::is_space(buf[4])) { |
| 682 | if (skipped_space) { | 653 | if (skipped_space) { |
| 683 | QTC::TC("qpdf", "QPDF xref skipped space"); | 654 | QTC::TC("qpdf", "QPDF xref skipped space"); |
| 684 | - warn(damagedPDF( | ||
| 685 | - "", 0, "extraneous whitespace seen before xref")); | 655 | + warn(damagedPDF("", 0, "extraneous whitespace seen before xref")); |
| 686 | } | 656 | } |
| 687 | QTC::TC( | 657 | QTC::TC( |
| 688 | "qpdf", | 658 | "qpdf", |
| @@ -724,8 +694,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | @@ -724,8 +694,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset) | ||
| 724 | "", | 694 | "", |
| 725 | 0, | 695 | 0, |
| 726 | ("reported number of objects (" + std::to_string(size) + | 696 | ("reported number of objects (" + std::to_string(size) + |
| 727 | - ") is not one plus the highest object number (" + | ||
| 728 | - std::to_string(max_obj) + ")"))); | 697 | + ") is not one plus the highest object number (" + std::to_string(max_obj) + ")"))); |
| 729 | } | 698 | } |
| 730 | 699 | ||
| 731 | // We no longer need the deleted_objects table, so go ahead and | 700 | // 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) | @@ -782,8 +751,7 @@ QPDF::parse_xrefFirst(std::string const& line, int& obj, int& num, int& bytes) | ||
| 782 | } | 751 | } |
| 783 | 752 | ||
| 784 | bool | 753 | bool |
| 785 | -QPDF::parse_xrefEntry( | ||
| 786 | - std::string const& line, qpdf_offset_t& f1, int& f2, char& type) | 754 | +QPDF::parse_xrefEntry(std::string const& line, qpdf_offset_t& f1, int& f2, char& type) |
| 787 | { | 755 | { |
| 788 | // is_space and is_digit both return false on '\0', so this will | 756 | // is_space and is_digit both return false on '\0', so this will |
| 789 | // not overrun the null-terminated buffer. | 757 | // not overrun the null-terminated buffer. |
| @@ -891,8 +859,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -891,8 +859,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 891 | if (!parse_xrefEntry(xref_entry, f1, f2, type)) { | 859 | if (!parse_xrefEntry(xref_entry, f1, f2, type)) { |
| 892 | QTC::TC("qpdf", "QPDF invalid xref entry"); | 860 | QTC::TC("qpdf", "QPDF invalid xref entry"); |
| 893 | throw damagedPDF( | 861 | throw damagedPDF( |
| 894 | - "xref table", | ||
| 895 | - "invalid xref entry (obj=" + std::to_string(i) + ")"); | 862 | + "xref table", "invalid xref entry (obj=" + std::to_string(i) + ")"); |
| 896 | } | 863 | } |
| 897 | if (type == 'f') { | 864 | if (type == 'f') { |
| 898 | // Save deleted items until after we've checked the | 865 | // Save deleted items until after we've checked the |
| @@ -911,8 +878,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -911,8 +878,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 911 | } | 878 | } |
| 912 | 879 | ||
| 913 | // Set offset to previous xref table if any | 880 | // Set offset to previous xref table if any |
| 914 | - QPDFObjectHandle cur_trailer = | ||
| 915 | - readObject(m->file, "trailer", QPDFObjGen(), false); | 881 | + QPDFObjectHandle cur_trailer = readObject(m->file, "trailer", QPDFObjGen(), false); |
| 916 | if (!cur_trailer.isDictionary()) { | 882 | if (!cur_trailer.isDictionary()) { |
| 917 | QTC::TC("qpdf", "QPDF missing trailer"); | 883 | QTC::TC("qpdf", "QPDF missing trailer"); |
| 918 | throw damagedPDF("", "expected trailer dictionary"); | 884 | throw damagedPDF("", "expected trailer dictionary"); |
| @@ -927,8 +893,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -927,8 +893,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 927 | } | 893 | } |
| 928 | if (!m->trailer.getKey("/Size").isInteger()) { | 894 | if (!m->trailer.getKey("/Size").isInteger()) { |
| 929 | QTC::TC("qpdf", "QPDF trailer size not integer"); | 895 | QTC::TC("qpdf", "QPDF trailer size not integer"); |
| 930 | - throw damagedPDF( | ||
| 931 | - "trailer", "/Size key in trailer dictionary is not an integer"); | 896 | + throw damagedPDF("trailer", "/Size key in trailer dictionary is not an integer"); |
| 932 | } | 897 | } |
| 933 | } | 898 | } |
| 934 | 899 | ||
| @@ -940,11 +905,9 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -940,11 +905,9 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 940 | // Read the xref stream but disregard any return value | 905 | // Read the xref stream but disregard any return value |
| 941 | // -- we'll use our trailer's /Prev key instead of the | 906 | // -- we'll use our trailer's /Prev key instead of the |
| 942 | // xref stream's. | 907 | // xref stream's. |
| 943 | - (void)read_xrefStream( | ||
| 944 | - cur_trailer.getKey("/XRefStm").getIntValue()); | 908 | + (void)read_xrefStream(cur_trailer.getKey("/XRefStm").getIntValue()); |
| 945 | } else { | 909 | } else { |
| 946 | - throw damagedPDF( | ||
| 947 | - "xref stream", xref_offset, "invalid /XRefStm"); | 910 | + throw damagedPDF("xref stream", xref_offset, "invalid /XRefStm"); |
| 948 | } | 911 | } |
| 949 | } | 912 | } |
| 950 | } | 913 | } |
| @@ -957,8 +920,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | @@ -957,8 +920,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) | ||
| 957 | if (cur_trailer.hasKey("/Prev")) { | 920 | if (cur_trailer.hasKey("/Prev")) { |
| 958 | if (!cur_trailer.getKey("/Prev").isInteger()) { | 921 | if (!cur_trailer.getKey("/Prev").isInteger()) { |
| 959 | QTC::TC("qpdf", "QPDF trailer prev not integer"); | 922 | QTC::TC("qpdf", "QPDF trailer prev not integer"); |
| 960 | - throw damagedPDF( | ||
| 961 | - "trailer", "/Prev key in trailer dictionary is not an integer"); | 923 | + throw damagedPDF("trailer", "/Prev key in trailer dictionary is not an integer"); |
| 962 | } | 924 | } |
| 963 | QTC::TC("qpdf", "QPDF prev key in trailer dictionary"); | 925 | QTC::TC("qpdf", "QPDF prev key in trailer dictionary"); |
| 964 | xref_offset = cur_trailer.getKey("/Prev").getIntValue(); | 926 | xref_offset = cur_trailer.getKey("/Prev").getIntValue(); |
| @@ -977,13 +939,8 @@ QPDF::read_xrefStream(qpdf_offset_t xref_offset) | @@ -977,13 +939,8 @@ QPDF::read_xrefStream(qpdf_offset_t xref_offset) | ||
| 977 | QPDFObjGen x_og; | 939 | QPDFObjGen x_og; |
| 978 | QPDFObjectHandle xref_obj; | 940 | QPDFObjectHandle xref_obj; |
| 979 | try { | 941 | try { |
| 980 | - xref_obj = readObjectAtOffset( | ||
| 981 | - false, | ||
| 982 | - xref_offset, | ||
| 983 | - "xref stream", | ||
| 984 | - QPDFObjGen(0, 0), | ||
| 985 | - x_og, | ||
| 986 | - true); | 942 | + xref_obj = |
| 943 | + readObjectAtOffset(false, xref_offset, "xref stream", QPDFObjGen(0, 0), x_og, true); | ||
| 987 | } catch (QPDFExc&) { | 944 | } catch (QPDFExc&) { |
| 988 | // ignore -- report error below | 945 | // ignore -- report error below |
| 989 | } | 946 | } |
| @@ -1008,12 +965,9 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -1008,12 +965,9 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 1008 | QPDFObjectHandle dict = xref_obj.getDict(); | 965 | QPDFObjectHandle dict = xref_obj.getDict(); |
| 1009 | QPDFObjectHandle W_obj = dict.getKey("/W"); | 966 | QPDFObjectHandle W_obj = dict.getKey("/W"); |
| 1010 | QPDFObjectHandle Index_obj = dict.getKey("/Index"); | 967 | QPDFObjectHandle Index_obj = dict.getKey("/Index"); |
| 1011 | - if (!(W_obj.isArray() && (W_obj.getArrayNItems() >= 3) && | ||
| 1012 | - W_obj.getArrayItem(0).isInteger() && | ||
| 1013 | - W_obj.getArrayItem(1).isInteger() && | ||
| 1014 | - W_obj.getArrayItem(2).isInteger() && | ||
| 1015 | - dict.getKey("/Size").isInteger() && | ||
| 1016 | - (Index_obj.isArray() || Index_obj.isNull()))) { | 968 | + if (!(W_obj.isArray() && (W_obj.getArrayNItems() >= 3) && W_obj.getArrayItem(0).isInteger() && |
| 969 | + W_obj.getArrayItem(1).isInteger() && W_obj.getArrayItem(2).isInteger() && | ||
| 970 | + dict.getKey("/Size").isInteger() && (Index_obj.isArray() || Index_obj.isNull()))) { | ||
| 1017 | throw damagedPDF( | 971 | throw damagedPDF( |
| 1018 | "xref stream", | 972 | "xref stream", |
| 1019 | xref_offset, | 973 | xref_offset, |
| @@ -1035,12 +989,9 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -1035,12 +989,9 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 1035 | } | 989 | } |
| 1036 | if (entry_size == 0) { | 990 | if (entry_size == 0) { |
| 1037 | throw damagedPDF( | 991 | throw damagedPDF( |
| 1038 | - "xref stream", | ||
| 1039 | - xref_offset, | ||
| 1040 | - "Cross-reference stream's /W indicates entry size of 0"); | 992 | + "xref stream", xref_offset, "Cross-reference stream's /W indicates entry size of 0"); |
| 1041 | } | 993 | } |
| 1042 | - unsigned long long max_num_entries = | ||
| 1043 | - static_cast<unsigned long long>(-1) / entry_size; | 994 | + unsigned long long max_num_entries = static_cast<unsigned long long>(-1) / entry_size; |
| 1044 | 995 | ||
| 1045 | std::vector<long long> indx; | 996 | std::vector<long long> indx; |
| 1046 | if (Index_obj.isArray()) { | 997 | if (Index_obj.isArray()) { |
| @@ -1059,8 +1010,8 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -1059,8 +1010,8 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 1059 | throw damagedPDF( | 1010 | throw damagedPDF( |
| 1060 | "xref stream", | 1011 | "xref stream", |
| 1061 | xref_offset, | 1012 | xref_offset, |
| 1062 | - ("Cross-reference stream's /Index's item " + | ||
| 1063 | - std::to_string(i) + " is not an integer")); | 1013 | + ("Cross-reference stream's /Index's item " + std::to_string(i) + |
| 1014 | + " is not an integer")); | ||
| 1064 | } | 1015 | } |
| 1065 | } | 1016 | } |
| 1066 | QTC::TC("qpdf", "QPDF xref /Index is array", n_index == 2 ? 0 : 1); | 1017 | 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) | @@ -1078,8 +1029,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 1078 | "xref stream", | 1029 | "xref stream", |
| 1079 | xref_offset, | 1030 | xref_offset, |
| 1080 | ("Cross-reference stream claims to contain too many entries: " + | 1031 | ("Cross-reference stream claims to contain too many entries: " + |
| 1081 | - std::to_string(indx.at(i)) + " " + | ||
| 1082 | - std::to_string(max_num_entries) + " " + | 1032 | + std::to_string(indx.at(i)) + " " + std::to_string(max_num_entries) + " " + |
| 1083 | std::to_string(num_entries))); | 1033 | std::to_string(num_entries))); |
| 1084 | } | 1034 | } |
| 1085 | num_entries += toS(indx.at(i)); | 1035 | num_entries += toS(indx.at(i)); |
| @@ -1097,8 +1047,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -1097,8 +1047,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 1097 | "xref stream", | 1047 | "xref stream", |
| 1098 | xref_offset, | 1048 | xref_offset, |
| 1099 | ("Cross-reference stream data has the wrong size; expected = " + | 1049 | ("Cross-reference stream data has the wrong size; expected = " + |
| 1100 | - std::to_string(expected_size) + | ||
| 1101 | - "; actual = " + std::to_string(actual_size))); | 1050 | + std::to_string(expected_size) + "; actual = " + std::to_string(actual_size))); |
| 1102 | if (expected_size > actual_size) { | 1051 | if (expected_size > actual_size) { |
| 1103 | throw x; | 1052 | throw x; |
| 1104 | } else { | 1053 | } else { |
| @@ -1137,8 +1086,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -1137,8 +1086,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 1137 | // an uncompressed object record, in which case the generation | 1086 | // an uncompressed object record, in which case the generation |
| 1138 | // number appears as the third field. | 1087 | // number appears as the third field. |
| 1139 | int obj = toI(indx.at(cur_chunk)); | 1088 | int obj = toI(indx.at(cur_chunk)); |
| 1140 | - if ((obj < 0) || | ||
| 1141 | - ((std::numeric_limits<int>::max() - obj) < chunk_count)) { | 1089 | + if ((obj < 0) || ((std::numeric_limits<int>::max() - obj) < chunk_count)) { |
| 1142 | std::ostringstream msg; | 1090 | std::ostringstream msg; |
| 1143 | msg.imbue(std::locale::classic()); | 1091 | msg.imbue(std::locale::classic()); |
| 1144 | msg << "adding " << chunk_count << " to " << obj | 1092 | msg << "adding " << chunk_count << " to " << obj |
| @@ -1181,8 +1129,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -1181,8 +1129,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 1181 | if (dict.hasKey("/Prev")) { | 1129 | if (dict.hasKey("/Prev")) { |
| 1182 | if (!dict.getKey("/Prev").isInteger()) { | 1130 | if (!dict.getKey("/Prev").isInteger()) { |
| 1183 | throw damagedPDF( | 1131 | throw damagedPDF( |
| 1184 | - "xref stream", | ||
| 1185 | - "/Prev key in xref stream dictionary is not an integer"); | 1132 | + "xref stream", "/Prev key in xref stream dictionary is not an integer"); |
| 1186 | } | 1133 | } |
| 1187 | QTC::TC("qpdf", "QPDF prev key in xref stream dictionary"); | 1134 | QTC::TC("qpdf", "QPDF prev key in xref stream dictionary"); |
| 1188 | xref_offset = dict.getKey("/Prev").getIntValue(); | 1135 | xref_offset = dict.getKey("/Prev").getIntValue(); |
| @@ -1241,9 +1188,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | @@ -1241,9 +1188,7 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite) | ||
| 1241 | break; | 1188 | break; |
| 1242 | 1189 | ||
| 1243 | default: | 1190 | default: |
| 1244 | - throw damagedPDF( | ||
| 1245 | - "xref stream", | ||
| 1246 | - "unknown xref stream entry type " + std::to_string(f0)); | 1191 | + throw damagedPDF("xref stream", "unknown xref stream entry type " + std::to_string(f0)); |
| 1247 | break; | 1192 | break; |
| 1248 | } | 1193 | } |
| 1249 | } | 1194 | } |
| @@ -1262,9 +1207,8 @@ QPDF::showXRefTable() | @@ -1262,9 +1207,8 @@ QPDF::showXRefTable() | ||
| 1262 | break; | 1207 | break; |
| 1263 | 1208 | ||
| 1264 | case 2: | 1209 | case 2: |
| 1265 | - *m->log->getInfo() | ||
| 1266 | - << "compressed; stream = " << entry.getObjStreamNumber() | ||
| 1267 | - << ", index = " << entry.getObjStreamIndex(); | 1210 | + *m->log->getInfo() << "compressed; stream = " << entry.getObjStreamNumber() |
| 1211 | + << ", index = " << entry.getObjStreamIndex(); | ||
| 1268 | break; | 1212 | break; |
| 1269 | 1213 | ||
| 1270 | default: | 1214 | default: |
| @@ -1337,8 +1281,7 @@ QPDF::getAllObjects() | @@ -1337,8 +1281,7 @@ QPDF::getAllObjects() | ||
| 1337 | } | 1281 | } |
| 1338 | 1282 | ||
| 1339 | void | 1283 | void |
| 1340 | -QPDF::setLastObjectDescription( | ||
| 1341 | - std::string const& description, QPDFObjGen const& og) | 1284 | +QPDF::setLastObjectDescription(std::string const& description, QPDFObjGen const& og) |
| 1342 | { | 1285 | { |
| 1343 | m->last_object_description.clear(); | 1286 | m->last_object_description.clear(); |
| 1344 | if (!description.empty()) { | 1287 | if (!description.empty()) { |
| @@ -1369,16 +1312,13 @@ QPDF::readObject( | @@ -1369,16 +1312,13 @@ QPDF::readObject( | ||
| 1369 | decrypter_ph = std::make_shared<StringDecrypter>(this, og); | 1312 | decrypter_ph = std::make_shared<StringDecrypter>(this, og); |
| 1370 | decrypter = decrypter_ph.get(); | 1313 | decrypter = decrypter_ph.get(); |
| 1371 | } | 1314 | } |
| 1372 | - auto object = | ||
| 1373 | - QPDFParser( | ||
| 1374 | - input, m->last_object_description, m->tokenizer, decrypter, this) | ||
| 1375 | - .parse(empty, false); | 1315 | + auto object = QPDFParser(input, m->last_object_description, m->tokenizer, decrypter, this) |
| 1316 | + .parse(empty, false); | ||
| 1376 | if (empty) { | 1317 | if (empty) { |
| 1377 | // Nothing in the PDF spec appears to allow empty objects, but | 1318 | // Nothing in the PDF spec appears to allow empty objects, but |
| 1378 | // they have been encountered in actual PDF files and Adobe | 1319 | // they have been encountered in actual PDF files and Adobe |
| 1379 | // Reader appears to ignore them. | 1320 | // Reader appears to ignore them. |
| 1380 | - warn(damagedPDF( | ||
| 1381 | - input, input->getLastOffset(), "empty object treated as null")); | 1321 | + warn(damagedPDF(input, input->getLastOffset(), "empty object treated as null")); |
| 1382 | } else if (object.isDictionary() && (!in_object_stream)) { | 1322 | } else if (object.isDictionary() && (!in_object_stream)) { |
| 1383 | // check for stream | 1323 | // check for stream |
| 1384 | qpdf_offset_t cur_offset = input->tell(); | 1324 | qpdf_offset_t cur_offset = input->tell(); |
| @@ -1428,9 +1368,7 @@ QPDF::readObject( | @@ -1428,9 +1368,7 @@ QPDF::readObject( | ||
| 1428 | } | 1368 | } |
| 1429 | } else if (QUtil::is_space(ch)) { | 1369 | } else if (QUtil::is_space(ch)) { |
| 1430 | warn(damagedPDF( | 1370 | warn(damagedPDF( |
| 1431 | - input, | ||
| 1432 | - input->tell(), | ||
| 1433 | - "stream keyword followed by extraneous whitespace")); | 1371 | + input, input->tell(), "stream keyword followed by extraneous whitespace")); |
| 1434 | done = false; | 1372 | done = false; |
| 1435 | } else { | 1373 | } else { |
| 1436 | QTC::TC("qpdf", "QPDF stream without newline"); | 1374 | QTC::TC("qpdf", "QPDF stream without newline"); |
| @@ -1450,13 +1388,11 @@ QPDF::readObject( | @@ -1450,13 +1388,11 @@ QPDF::readObject( | ||
| 1450 | size_t length = 0; | 1388 | size_t length = 0; |
| 1451 | 1389 | ||
| 1452 | try { | 1390 | try { |
| 1453 | - std::map<std::string, QPDFObjectHandle> dict = | ||
| 1454 | - object.getDictAsMap(); | 1391 | + std::map<std::string, QPDFObjectHandle> dict = object.getDictAsMap(); |
| 1455 | 1392 | ||
| 1456 | if (dict.count("/Length") == 0) { | 1393 | if (dict.count("/Length") == 0) { |
| 1457 | QTC::TC("qpdf", "QPDF stream without length"); | 1394 | QTC::TC("qpdf", "QPDF stream without length"); |
| 1458 | - throw damagedPDF( | ||
| 1459 | - input, offset, "stream dictionary lacks /Length key"); | 1395 | + throw damagedPDF(input, offset, "stream dictionary lacks /Length key"); |
| 1460 | } | 1396 | } |
| 1461 | 1397 | ||
| 1462 | QPDFObjectHandle length_obj = dict["/Length"]; | 1398 | QPDFObjectHandle length_obj = dict["/Length"]; |
| @@ -1475,8 +1411,7 @@ QPDF::readObject( | @@ -1475,8 +1411,7 @@ QPDF::readObject( | ||
| 1475 | input->seek(toO(length), SEEK_CUR); | 1411 | input->seek(toO(length), SEEK_CUR); |
| 1476 | if (!readToken(input).isWord("endstream")) { | 1412 | if (!readToken(input).isWord("endstream")) { |
| 1477 | QTC::TC("qpdf", "QPDF missing endstream"); | 1413 | QTC::TC("qpdf", "QPDF missing endstream"); |
| 1478 | - throw damagedPDF( | ||
| 1479 | - input, input->getLastOffset(), "expected endstream"); | 1414 | + throw damagedPDF(input, input->getLastOffset(), "expected endstream"); |
| 1480 | } | 1415 | } |
| 1481 | } catch (QPDFExc& e) { | 1416 | } catch (QPDFExc& e) { |
| 1482 | if (m->attempt_recovery) { | 1417 | if (m->attempt_recovery) { |
| @@ -1486,9 +1421,7 @@ QPDF::readObject( | @@ -1486,9 +1421,7 @@ QPDF::readObject( | ||
| 1486 | throw; | 1421 | throw; |
| 1487 | } | 1422 | } |
| 1488 | } | 1423 | } |
| 1489 | - object = newIndirect( | ||
| 1490 | - og, | ||
| 1491 | - QPDF_Stream::create(this, og, object, stream_offset, length)); | 1424 | + object = newIndirect(og, QPDF_Stream::create(this, og, object, stream_offset, length)); |
| 1492 | } else { | 1425 | } else { |
| 1493 | input->seek(cur_offset, SEEK_SET); | 1426 | input->seek(cur_offset, SEEK_SET); |
| 1494 | } | 1427 | } |
| @@ -1514,14 +1447,11 @@ QPDF::findEndstream() | @@ -1514,14 +1447,11 @@ QPDF::findEndstream() | ||
| 1514 | 1447 | ||
| 1515 | size_t | 1448 | size_t |
| 1516 | QPDF::recoverStreamLength( | 1449 | QPDF::recoverStreamLength( |
| 1517 | - std::shared_ptr<InputSource> input, | ||
| 1518 | - QPDFObjGen const& og, | ||
| 1519 | - qpdf_offset_t stream_offset) | 1450 | + std::shared_ptr<InputSource> input, QPDFObjGen const& og, qpdf_offset_t stream_offset) |
| 1520 | { | 1451 | { |
| 1521 | // Try to reconstruct stream length by looking for | 1452 | // Try to reconstruct stream length by looking for |
| 1522 | // endstream or endobj | 1453 | // endstream or endobj |
| 1523 | - warn(damagedPDF( | ||
| 1524 | - input, stream_offset, "attempting to recover stream length")); | 1454 | + warn(damagedPDF(input, stream_offset, "attempting to recover stream length")); |
| 1525 | 1455 | ||
| 1526 | PatternFinder ef(*this, &QPDF::findEndstream); | 1456 | PatternFinder ef(*this, &QPDF::findEndstream); |
| 1527 | size_t length = 0; | 1457 | size_t length = 0; |
| @@ -1544,8 +1474,7 @@ QPDF::recoverStreamLength( | @@ -1544,8 +1474,7 @@ QPDF::recoverStreamLength( | ||
| 1544 | if (entry.getType() == 1) { | 1474 | if (entry.getType() == 1) { |
| 1545 | qpdf_offset_t obj_offset = entry.getOffset(); | 1475 | qpdf_offset_t obj_offset = entry.getOffset(); |
| 1546 | if ((obj_offset > stream_offset) && | 1476 | if ((obj_offset > stream_offset) && |
| 1547 | - ((this_obj_offset == 0) || | ||
| 1548 | - (this_obj_offset > obj_offset))) { | 1477 | + ((this_obj_offset == 0) || (this_obj_offset > obj_offset))) { |
| 1549 | this_obj_offset = obj_offset; | 1478 | this_obj_offset = obj_offset; |
| 1550 | this_og = iter.first; | 1479 | this_og = iter.first; |
| 1551 | } | 1480 | } |
| @@ -1562,14 +1491,10 @@ QPDF::recoverStreamLength( | @@ -1562,14 +1491,10 @@ QPDF::recoverStreamLength( | ||
| 1562 | 1491 | ||
| 1563 | if (length == 0) { | 1492 | if (length == 0) { |
| 1564 | warn(damagedPDF( | 1493 | warn(damagedPDF( |
| 1565 | - input, | ||
| 1566 | - stream_offset, | ||
| 1567 | - "unable to recover stream data; treating stream as empty")); | 1494 | + input, stream_offset, "unable to recover stream data; treating stream as empty")); |
| 1568 | } else { | 1495 | } else { |
| 1569 | - warn(damagedPDF( | ||
| 1570 | - input, | ||
| 1571 | - stream_offset, | ||
| 1572 | - "recovered stream length: " + std::to_string(length))); | 1496 | + warn( |
| 1497 | + damagedPDF(input, stream_offset, "recovered stream length: " + std::to_string(length))); | ||
| 1573 | } | 1498 | } |
| 1574 | 1499 | ||
| 1575 | QTC::TC("qpdf", "QPDF recovered stream length"); | 1500 | QTC::TC("qpdf", "QPDF recovered stream length"); |
| @@ -1579,8 +1504,7 @@ QPDF::recoverStreamLength( | @@ -1579,8 +1504,7 @@ QPDF::recoverStreamLength( | ||
| 1579 | QPDFTokenizer::Token | 1504 | QPDFTokenizer::Token |
| 1580 | QPDF::readToken(std::shared_ptr<InputSource> input, size_t max_len) | 1505 | QPDF::readToken(std::shared_ptr<InputSource> input, size_t max_len) |
| 1581 | { | 1506 | { |
| 1582 | - return m->tokenizer.readToken( | ||
| 1583 | - input, m->last_object_description, true, max_len); | 1507 | + return m->tokenizer.readToken(input, m->last_object_description, true, max_len); |
| 1584 | } | 1508 | } |
| 1585 | 1509 | ||
| 1586 | QPDFObjectHandle | 1510 | QPDFObjectHandle |
| @@ -1650,8 +1574,7 @@ QPDF::readObjectAtOffset( | @@ -1650,8 +1574,7 @@ QPDF::readObjectAtOffset( | ||
| 1650 | } | 1574 | } |
| 1651 | if (check_og && (exp_og != og)) { | 1575 | if (check_og && (exp_og != og)) { |
| 1652 | QTC::TC("qpdf", "QPDF err wrong objid/generation"); | 1576 | QTC::TC("qpdf", "QPDF err wrong objid/generation"); |
| 1653 | - QPDFExc e = | ||
| 1654 | - damagedPDF(offset, "expected " + exp_og.unparse(' ') + " obj"); | 1577 | + QPDFExc e = damagedPDF(offset, "expected " + exp_og.unparse(' ') + " obj"); |
| 1655 | if (try_recovery) { | 1578 | if (try_recovery) { |
| 1656 | // Will be retried below | 1579 | // Will be retried below |
| 1657 | throw e; | 1580 | throw e; |
| @@ -1665,11 +1588,10 @@ QPDF::readObjectAtOffset( | @@ -1665,11 +1588,10 @@ QPDF::readObjectAtOffset( | ||
| 1665 | if (try_recovery) { | 1588 | if (try_recovery) { |
| 1666 | // Try again after reconstructing xref table | 1589 | // Try again after reconstructing xref table |
| 1667 | reconstruct_xref(e); | 1590 | reconstruct_xref(e); |
| 1668 | - if (m->xref_table.count(exp_og) && | ||
| 1669 | - (m->xref_table[exp_og].getType() == 1)) { | 1591 | + if (m->xref_table.count(exp_og) && (m->xref_table[exp_og].getType() == 1)) { |
| 1670 | qpdf_offset_t new_offset = m->xref_table[exp_og].getOffset(); | 1592 | qpdf_offset_t new_offset = m->xref_table[exp_og].getOffset(); |
| 1671 | - QPDFObjectHandle result = readObjectAtOffset( | ||
| 1672 | - false, new_offset, description, exp_og, og, false); | 1593 | + QPDFObjectHandle result = |
| 1594 | + readObjectAtOffset(false, new_offset, description, exp_og, og, false); | ||
| 1673 | QTC::TC("qpdf", "QPDF recovered in readObjectAtOffset"); | 1595 | QTC::TC("qpdf", "QPDF recovered in readObjectAtOffset"); |
| 1674 | return result; | 1596 | return result; |
| 1675 | } else { | 1597 | } else { |
| @@ -1777,8 +1699,7 @@ QPDF::resolve(QPDFObjGen og) | @@ -1777,8 +1699,7 @@ QPDF::resolve(QPDFObjGen og) | ||
| 1777 | // indirectly in some key that has to be resolved during | 1699 | // indirectly in some key that has to be resolved during |
| 1778 | // object parsing, such as stream length. | 1700 | // object parsing, such as stream length. |
| 1779 | QTC::TC("qpdf", "QPDF recursion loop in resolve"); | 1701 | QTC::TC("qpdf", "QPDF recursion loop in resolve"); |
| 1780 | - warn(damagedPDF( | ||
| 1781 | - "", "loop detected resolving object " + og.unparse(' '))); | 1702 | + warn(damagedPDF("", "loop detected resolving object " + og.unparse(' '))); |
| 1782 | updateCache(og, QPDF_Null::create(), -1, -1); | 1703 | updateCache(og, QPDF_Null::create(), -1, -1); |
| 1783 | return; | 1704 | return; |
| 1784 | } | 1705 | } |
| @@ -1793,8 +1714,7 @@ QPDF::resolve(QPDFObjGen og) | @@ -1793,8 +1714,7 @@ QPDF::resolve(QPDFObjGen og) | ||
| 1793 | qpdf_offset_t offset = entry.getOffset(); | 1714 | qpdf_offset_t offset = entry.getOffset(); |
| 1794 | // Object stored in cache by readObjectAtOffset | 1715 | // Object stored in cache by readObjectAtOffset |
| 1795 | QPDFObjGen a_og; | 1716 | QPDFObjGen a_og; |
| 1796 | - QPDFObjectHandle oh = | ||
| 1797 | - readObjectAtOffset(true, offset, "", og, a_og, false); | 1717 | + QPDFObjectHandle oh = readObjectAtOffset(true, offset, "", og, a_og, false); |
| 1798 | } | 1718 | } |
| 1799 | break; | 1719 | break; |
| 1800 | 1720 | ||
| @@ -1804,19 +1724,13 @@ QPDF::resolve(QPDFObjGen og) | @@ -1804,19 +1724,13 @@ QPDF::resolve(QPDFObjGen og) | ||
| 1804 | 1724 | ||
| 1805 | default: | 1725 | default: |
| 1806 | throw damagedPDF( | 1726 | throw damagedPDF( |
| 1807 | - "", | ||
| 1808 | - 0, | ||
| 1809 | - ("object " + og.unparse('/') + | ||
| 1810 | - " has unexpected xref entry type")); | 1727 | + "", 0, ("object " + og.unparse('/') + " has unexpected xref entry type")); |
| 1811 | } | 1728 | } |
| 1812 | } catch (QPDFExc& e) { | 1729 | } catch (QPDFExc& e) { |
| 1813 | warn(e); | 1730 | warn(e); |
| 1814 | } catch (std::exception& e) { | 1731 | } catch (std::exception& e) { |
| 1815 | warn(damagedPDF( | 1732 | warn(damagedPDF( |
| 1816 | - "", | ||
| 1817 | - 0, | ||
| 1818 | - ("object " + og.unparse('/') + | ||
| 1819 | - ": error reading object: " + e.what()))); | 1733 | + "", 0, ("object " + og.unparse('/') + ": error reading object: " + e.what()))); |
| 1820 | } | 1734 | } |
| 1821 | } | 1735 | } |
| 1822 | 1736 | ||
| @@ -1841,8 +1755,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1841,8 +1755,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1841 | QPDFObjectHandle obj_stream = getObjectByID(obj_stream_number, 0); | 1755 | QPDFObjectHandle obj_stream = getObjectByID(obj_stream_number, 0); |
| 1842 | if (!obj_stream.isStream()) { | 1756 | if (!obj_stream.isStream()) { |
| 1843 | throw damagedPDF( | 1757 | throw damagedPDF( |
| 1844 | - "supposed object stream " + std::to_string(obj_stream_number) + | ||
| 1845 | - " is not a stream"); | 1758 | + "supposed object stream " + std::to_string(obj_stream_number) + " is not a stream"); |
| 1846 | } | 1759 | } |
| 1847 | 1760 | ||
| 1848 | // For linearization data in the object, use the data from the | 1761 | // For linearization data in the object, use the data from the |
| @@ -1855,14 +1768,12 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1855,14 +1768,12 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1855 | if (!dict.isDictionaryOfType("/ObjStm")) { | 1768 | if (!dict.isDictionaryOfType("/ObjStm")) { |
| 1856 | QTC::TC("qpdf", "QPDF ERR object stream with wrong type"); | 1769 | QTC::TC("qpdf", "QPDF ERR object stream with wrong type"); |
| 1857 | warn(damagedPDF( | 1770 | warn(damagedPDF( |
| 1858 | - "supposed object stream " + std::to_string(obj_stream_number) + | ||
| 1859 | - " has wrong type")); | 1771 | + "supposed object stream " + std::to_string(obj_stream_number) + " has wrong type")); |
| 1860 | } | 1772 | } |
| 1861 | 1773 | ||
| 1862 | if (!(dict.getKey("/N").isInteger() && dict.getKey("/First").isInteger())) { | 1774 | if (!(dict.getKey("/N").isInteger() && dict.getKey("/First").isInteger())) { |
| 1863 | throw damagedPDF( | 1775 | throw damagedPDF( |
| 1864 | - ("object stream " + std::to_string(obj_stream_number) + | ||
| 1865 | - " has incorrect keys")); | 1776 | + ("object stream " + std::to_string(obj_stream_number) + " has incorrect keys")); |
| 1866 | } | 1777 | } |
| 1867 | 1778 | ||
| 1868 | int n = dict.getKey("/N").getIntValueAsInt(); | 1779 | int n = dict.getKey("/N").getIntValueAsInt(); |
| @@ -1874,8 +1785,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1874,8 +1785,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1874 | auto input = std::shared_ptr<InputSource>( | 1785 | auto input = std::shared_ptr<InputSource>( |
| 1875 | // line-break | 1786 | // line-break |
| 1876 | new BufferInputSource( | 1787 | new BufferInputSource( |
| 1877 | - (m->file->getName() + " object stream " + | ||
| 1878 | - std::to_string(obj_stream_number)), | 1788 | + (m->file->getName() + " object stream " + std::to_string(obj_stream_number)), |
| 1879 | bp.get())); | 1789 | bp.get())); |
| 1880 | 1790 | ||
| 1881 | for (int i = 0; i < n; ++i) { | 1791 | for (int i = 0; i < n; ++i) { |
| @@ -1902,8 +1812,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1902,8 +1812,7 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1902 | for (auto const& iter: offsets) { | 1812 | for (auto const& iter: offsets) { |
| 1903 | QPDFObjGen og(iter.first, 0); | 1813 | QPDFObjGen og(iter.first, 0); |
| 1904 | QPDFXRefEntry const& entry = m->xref_table[og]; | 1814 | QPDFXRefEntry const& entry = m->xref_table[og]; |
| 1905 | - if ((entry.getType() == 2) && | ||
| 1906 | - (entry.getObjStreamNumber() == obj_stream_number)) { | 1815 | + if ((entry.getType() == 2) && (entry.getObjStreamNumber() == obj_stream_number)) { |
| 1907 | int offset = iter.second; | 1816 | int offset = iter.second; |
| 1908 | input->seek(offset, SEEK_SET); | 1817 | input->seek(offset, SEEK_SET); |
| 1909 | QPDFObjectHandle oh = readObject(input, "", og, true); | 1818 | QPDFObjectHandle oh = readObject(input, "", og, true); |
| @@ -1956,8 +1865,7 @@ QPDF::nextObjGen() | @@ -1956,8 +1865,7 @@ QPDF::nextObjGen() | ||
| 1956 | { | 1865 | { |
| 1957 | int max_objid = toI(getObjectCount()); | 1866 | int max_objid = toI(getObjectCount()); |
| 1958 | if (max_objid == std::numeric_limits<int>::max()) { | 1867 | if (max_objid == std::numeric_limits<int>::max()) { |
| 1959 | - throw std::range_error( | ||
| 1960 | - "max object id is too high to create new objects"); | 1868 | + throw std::range_error("max object id is too high to create new objects"); |
| 1961 | } | 1869 | } |
| 1962 | return QPDFObjGen(max_objid + 1, 0); | 1870 | return QPDFObjGen(max_objid + 1, 0); |
| 1963 | } | 1871 | } |
| @@ -1974,8 +1882,7 @@ QPDFObjectHandle | @@ -1974,8 +1882,7 @@ QPDFObjectHandle | ||
| 1974 | QPDF::makeIndirectObject(QPDFObjectHandle oh) | 1882 | QPDF::makeIndirectObject(QPDFObjectHandle oh) |
| 1975 | { | 1883 | { |
| 1976 | if (!oh.isInitialized()) { | 1884 | if (!oh.isInitialized()) { |
| 1977 | - throw std::logic_error( | ||
| 1978 | - "attempted to make an uninitialized QPDFObjectHandle indirect"); | 1885 | + throw std::logic_error("attempted to make an uninitialized QPDFObjectHandle indirect"); |
| 1979 | } | 1886 | } |
| 1980 | return makeIndirectFromQPDFObject(oh.getObj()); | 1887 | return makeIndirectFromQPDFObject(oh.getObj()); |
| 1981 | } | 1888 | } |
| @@ -1989,16 +1896,15 @@ QPDF::newReserved() | @@ -1989,16 +1896,15 @@ QPDF::newReserved() | ||
| 1989 | QPDFObjectHandle | 1896 | QPDFObjectHandle |
| 1990 | QPDF::newStream() | 1897 | QPDF::newStream() |
| 1991 | { | 1898 | { |
| 1992 | - return makeIndirectFromQPDFObject(QPDF_Stream::create( | ||
| 1993 | - this, nextObjGen(), QPDFObjectHandle::newDictionary(), 0, 0)); | 1899 | + return makeIndirectFromQPDFObject( |
| 1900 | + QPDF_Stream::create(this, nextObjGen(), QPDFObjectHandle::newDictionary(), 0, 0)); | ||
| 1994 | } | 1901 | } |
| 1995 | 1902 | ||
| 1996 | QPDFObjectHandle | 1903 | QPDFObjectHandle |
| 1997 | QPDF::newStream(std::shared_ptr<Buffer> data) | 1904 | QPDF::newStream(std::shared_ptr<Buffer> data) |
| 1998 | { | 1905 | { |
| 1999 | auto result = newStream(); | 1906 | auto result = newStream(); |
| 2000 | - result.replaceStreamData( | ||
| 2001 | - data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | 1907 | + result.replaceStreamData(data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 2002 | return result; | 1908 | return result; |
| 2003 | } | 1909 | } |
| 2004 | 1910 | ||
| @@ -2006,8 +1912,7 @@ QPDFObjectHandle | @@ -2006,8 +1912,7 @@ QPDFObjectHandle | ||
| 2006 | QPDF::newStream(std::string const& data) | 1912 | QPDF::newStream(std::string const& data) |
| 2007 | { | 1913 | { |
| 2008 | auto result = newStream(); | 1914 | auto result = newStream(); |
| 2009 | - result.replaceStreamData( | ||
| 2010 | - data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | 1915 | + result.replaceStreamData(data, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 2011 | return result; | 1916 | return result; |
| 2012 | } | 1917 | } |
| 2013 | 1918 | ||
| @@ -2025,8 +1930,7 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const& og) | @@ -2025,8 +1930,7 @@ QPDF::reserveObjectIfNotExists(QPDFObjGen const& og) | ||
| 2025 | QPDFObjectHandle | 1930 | QPDFObjectHandle |
| 2026 | QPDF::reserveStream(QPDFObjGen const& og) | 1931 | QPDF::reserveStream(QPDFObjGen const& og) |
| 2027 | { | 1932 | { |
| 2028 | - return { | ||
| 2029 | - QPDF_Stream::create(this, og, QPDFObjectHandle::newDictionary(), 0, 0)}; | 1933 | + return {QPDF_Stream::create(this, og, QPDFObjectHandle::newDictionary(), 0, 0)}; |
| 2030 | } | 1934 | } |
| 2031 | 1935 | ||
| 2032 | QPDFObjectHandle | 1936 | QPDFObjectHandle |
| @@ -2069,8 +1973,7 @@ QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh) | @@ -2069,8 +1973,7 @@ QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh) | ||
| 2069 | { | 1973 | { |
| 2070 | if (oh.isIndirect() || !oh.isInitialized()) { | 1974 | if (oh.isIndirect() || !oh.isInitialized()) { |
| 2071 | QTC::TC("qpdf", "QPDF replaceObject called with indirect object"); | 1975 | QTC::TC("qpdf", "QPDF replaceObject called with indirect object"); |
| 2072 | - throw std::logic_error( | ||
| 2073 | - "QPDF::replaceObject called with indirect object handle"); | 1976 | + throw std::logic_error("QPDF::replaceObject called with indirect object handle"); |
| 2074 | } | 1977 | } |
| 2075 | updateCache(og, oh.getObj(), -1, -1); | 1978 | updateCache(og, oh.getObj(), -1, -1); |
| 2076 | } | 1979 | } |
| @@ -2132,14 +2035,12 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) | @@ -2132,14 +2035,12 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) | ||
| 2132 | // the intention is to not update the pages tree. | 2035 | // the intention is to not update the pages tree. |
| 2133 | if (!foreign.isIndirect()) { | 2036 | if (!foreign.isIndirect()) { |
| 2134 | QTC::TC("qpdf", "QPDF copyForeign direct"); | 2037 | QTC::TC("qpdf", "QPDF copyForeign direct"); |
| 2135 | - throw std::logic_error( | ||
| 2136 | - "QPDF::copyForeign called with direct object handle"); | 2038 | + throw std::logic_error("QPDF::copyForeign called with direct object handle"); |
| 2137 | } | 2039 | } |
| 2138 | QPDF& other = foreign.getQPDF(); | 2040 | QPDF& other = foreign.getQPDF(); |
| 2139 | if (&other == this) { | 2041 | if (&other == this) { |
| 2140 | QTC::TC("qpdf", "QPDF copyForeign not foreign"); | 2042 | QTC::TC("qpdf", "QPDF copyForeign not foreign"); |
| 2141 | - throw std::logic_error( | ||
| 2142 | - "QPDF::copyForeign called with object from this QPDF"); | 2043 | + throw std::logic_error("QPDF::copyForeign called with object from this QPDF"); |
| 2143 | } | 2044 | } |
| 2144 | 2045 | ||
| 2145 | ObjCopier& obj_copier = m->object_copiers[other.m->unique_id]; | 2046 | ObjCopier& obj_copier = m->object_copiers[other.m->unique_id]; |
| @@ -2163,8 +2064,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) | @@ -2163,8 +2064,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign) | ||
| 2163 | 2064 | ||
| 2164 | // Copy any new objects and replace the reservations. | 2065 | // Copy any new objects and replace the reservations. |
| 2165 | for (auto& to_copy: obj_copier.to_copy) { | 2066 | for (auto& to_copy: obj_copier.to_copy) { |
| 2166 | - QPDFObjectHandle copy = | ||
| 2167 | - replaceForeignIndirectObjects(to_copy, obj_copier, true); | 2067 | + QPDFObjectHandle copy = replaceForeignIndirectObjects(to_copy, obj_copier, true); |
| 2168 | if (!to_copy.isStream()) { | 2068 | if (!to_copy.isStream()) { |
| 2169 | QPDFObjGen og(to_copy.getObjGen()); | 2069 | QPDFObjGen og(to_copy.getObjGen()); |
| 2170 | replaceReserved(obj_copier.object_map[og], copy); | 2070 | replaceReserved(obj_copier.object_map[og], copy); |
| @@ -2180,8 +2080,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | @@ -2180,8 +2080,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | ||
| 2180 | { | 2080 | { |
| 2181 | auto foreign_tc = foreign.getTypeCode(); | 2081 | auto foreign_tc = foreign.getTypeCode(); |
| 2182 | if (foreign_tc == ::ot_reserved) { | 2082 | if (foreign_tc == ::ot_reserved) { |
| 2183 | - throw std::logic_error( | ||
| 2184 | - "QPDF: attempting to copy a foreign reserved object"); | 2083 | + throw std::logic_error("QPDF: attempting to copy a foreign reserved object"); |
| 2185 | } | 2084 | } |
| 2186 | 2085 | ||
| 2187 | if (foreign.isPagesObject()) { | 2086 | if (foreign.isPagesObject()) { |
| @@ -2209,8 +2108,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | @@ -2209,8 +2108,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | ||
| 2209 | QTC::TC("qpdf", "QPDF copy indirect"); | 2108 | QTC::TC("qpdf", "QPDF copy indirect"); |
| 2210 | if (obj_copier.object_map.count(foreign_og) == 0) { | 2109 | if (obj_copier.object_map.count(foreign_og) == 0) { |
| 2211 | obj_copier.to_copy.push_back(foreign); | 2110 | obj_copier.to_copy.push_back(foreign); |
| 2212 | - obj_copier.object_map[foreign_og] = | ||
| 2213 | - foreign.isStream() ? newStream() : newReserved(); | 2111 | + obj_copier.object_map[foreign_og] = foreign.isStream() ? newStream() : newReserved(); |
| 2214 | } | 2112 | } |
| 2215 | } | 2113 | } |
| 2216 | 2114 | ||
| @@ -2234,8 +2132,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | @@ -2234,8 +2132,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | ||
| 2234 | } | 2132 | } |
| 2235 | 2133 | ||
| 2236 | QPDFObjectHandle | 2134 | QPDFObjectHandle |
| 2237 | -QPDF::replaceForeignIndirectObjects( | ||
| 2238 | - QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | 2135 | +QPDF::replaceForeignIndirectObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) |
| 2239 | { | 2136 | { |
| 2240 | auto foreign_tc = foreign.getTypeCode(); | 2137 | auto foreign_tc = foreign.getTypeCode(); |
| 2241 | QPDFObjectHandle result; | 2138 | QPDFObjectHandle result; |
| @@ -2257,8 +2154,7 @@ QPDF::replaceForeignIndirectObjects( | @@ -2257,8 +2154,7 @@ QPDF::replaceForeignIndirectObjects( | ||
| 2257 | for (int i = 0; i < n; ++i) { | 2154 | for (int i = 0; i < n; ++i) { |
| 2258 | result.appendItem( | 2155 | result.appendItem( |
| 2259 | // line-break | 2156 | // line-break |
| 2260 | - replaceForeignIndirectObjects( | ||
| 2261 | - foreign.getArrayItem(i), obj_copier, false)); | 2157 | + replaceForeignIndirectObjects(foreign.getArrayItem(i), obj_copier, false)); |
| 2262 | } | 2158 | } |
| 2263 | } else if (foreign_tc == ::ot_dictionary) { | 2159 | } else if (foreign_tc == ::ot_dictionary) { |
| 2264 | QTC::TC("qpdf", "QPDF replace dictionary"); | 2160 | QTC::TC("qpdf", "QPDF replace dictionary"); |
| @@ -2266,9 +2162,7 @@ QPDF::replaceForeignIndirectObjects( | @@ -2266,9 +2162,7 @@ QPDF::replaceForeignIndirectObjects( | ||
| 2266 | std::set<std::string> keys = foreign.getKeys(); | 2162 | std::set<std::string> keys = foreign.getKeys(); |
| 2267 | for (auto const& iter: keys) { | 2163 | for (auto const& iter: keys) { |
| 2268 | result.replaceKey( | 2164 | result.replaceKey( |
| 2269 | - iter, | ||
| 2270 | - replaceForeignIndirectObjects( | ||
| 2271 | - foreign.getKey(iter), obj_copier, false)); | 2165 | + iter, replaceForeignIndirectObjects(foreign.getKey(iter), obj_copier, false)); |
| 2272 | } | 2166 | } |
| 2273 | } else if (foreign_tc == ::ot_stream) { | 2167 | } else if (foreign_tc == ::ot_stream) { |
| 2274 | QTC::TC("qpdf", "QPDF replace stream"); | 2168 | QTC::TC("qpdf", "QPDF replace stream"); |
| @@ -2279,9 +2173,7 @@ QPDF::replaceForeignIndirectObjects( | @@ -2279,9 +2173,7 @@ QPDF::replaceForeignIndirectObjects( | ||
| 2279 | std::set<std::string> keys = old_dict.getKeys(); | 2173 | std::set<std::string> keys = old_dict.getKeys(); |
| 2280 | for (auto const& iter: keys) { | 2174 | for (auto const& iter: keys) { |
| 2281 | dict.replaceKey( | 2175 | dict.replaceKey( |
| 2282 | - iter, | ||
| 2283 | - replaceForeignIndirectObjects( | ||
| 2284 | - old_dict.getKey(iter), obj_copier, false)); | 2176 | + iter, replaceForeignIndirectObjects(old_dict.getKey(iter), obj_copier, false)); |
| 2285 | } | 2177 | } |
| 2286 | copyStreamData(result, foreign); | 2178 | copyStreamData(result, foreign); |
| 2287 | } else { | 2179 | } else { |
| @@ -2309,8 +2201,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | @@ -2309,8 +2201,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | ||
| 2309 | if (m->copied_stream_data_provider == nullptr) { | 2201 | if (m->copied_stream_data_provider == nullptr) { |
| 2310 | m->copied_stream_data_provider = new CopiedStreamDataProvider(*this); | 2202 | m->copied_stream_data_provider = new CopiedStreamDataProvider(*this); |
| 2311 | m->copied_streams = | 2203 | m->copied_streams = |
| 2312 | - std::shared_ptr<QPDFObjectHandle::StreamDataProvider>( | ||
| 2313 | - m->copied_stream_data_provider); | 2204 | + std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(m->copied_stream_data_provider); |
| 2314 | } | 2205 | } |
| 2315 | QPDFObjGen local_og(result.getObjGen()); | 2206 | QPDFObjGen local_og(result.getObjGen()); |
| 2316 | // Copy information from the foreign stream so we can pipe its | 2207 | // Copy information from the foreign stream so we can pipe its |
| @@ -2325,8 +2216,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | @@ -2325,8 +2216,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | ||
| 2325 | " stream object from foreign stream"); | 2216 | " stream object from foreign stream"); |
| 2326 | } | 2217 | } |
| 2327 | std::shared_ptr<Buffer> stream_buffer = stream->getStreamDataBuffer(); | 2218 | std::shared_ptr<Buffer> stream_buffer = stream->getStreamDataBuffer(); |
| 2328 | - if ((foreign_stream_qpdf.m->immediate_copy_from) && | ||
| 2329 | - (stream_buffer == nullptr)) { | 2219 | + if ((foreign_stream_qpdf.m->immediate_copy_from) && (stream_buffer == nullptr)) { |
| 2330 | // Pull the stream data into a buffer before attempting | 2220 | // Pull the stream data into a buffer before attempting |
| 2331 | // the copy operation. Do it on the source stream so that | 2221 | // the copy operation. Do it on the source stream so that |
| 2332 | // if the source stream is copied multiple times, we don't | 2222 | // if the source stream is copied multiple times, we don't |
| @@ -2347,12 +2237,9 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | @@ -2347,12 +2237,9 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | ||
| 2347 | } else if (stream_provider.get()) { | 2237 | } else if (stream_provider.get()) { |
| 2348 | // In this case, the remote stream's QPDF must stay in scope. | 2238 | // In this case, the remote stream's QPDF must stay in scope. |
| 2349 | QTC::TC("qpdf", "QPDF copy foreign stream with provider"); | 2239 | QTC::TC("qpdf", "QPDF copy foreign stream with provider"); |
| 2350 | - m->copied_stream_data_provider->registerForeignStream( | ||
| 2351 | - local_og, foreign); | 2240 | + m->copied_stream_data_provider->registerForeignStream(local_og, foreign); |
| 2352 | result.replaceStreamData( | 2241 | result.replaceStreamData( |
| 2353 | - m->copied_streams, | ||
| 2354 | - dict.getKey("/Filter"), | ||
| 2355 | - dict.getKey("/DecodeParms")); | 2242 | + m->copied_streams, dict.getKey("/Filter"), dict.getKey("/DecodeParms")); |
| 2356 | } else { | 2243 | } else { |
| 2357 | auto foreign_stream_data = std::make_shared<ForeignStreamData>( | 2244 | auto foreign_stream_data = std::make_shared<ForeignStreamData>( |
| 2358 | foreign_stream_qpdf.m->encp, | 2245 | foreign_stream_qpdf.m->encp, |
| @@ -2361,20 +2248,16 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | @@ -2361,20 +2248,16 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) | ||
| 2361 | stream->getParsedOffset(), | 2248 | stream->getParsedOffset(), |
| 2362 | stream->getLength(), | 2249 | stream->getLength(), |
| 2363 | dict); | 2250 | dict); |
| 2364 | - m->copied_stream_data_provider->registerForeignStream( | ||
| 2365 | - local_og, foreign_stream_data); | 2251 | + m->copied_stream_data_provider->registerForeignStream(local_og, foreign_stream_data); |
| 2366 | result.replaceStreamData( | 2252 | result.replaceStreamData( |
| 2367 | - m->copied_streams, | ||
| 2368 | - dict.getKey("/Filter"), | ||
| 2369 | - dict.getKey("/DecodeParms")); | 2253 | + m->copied_streams, dict.getKey("/Filter"), dict.getKey("/DecodeParms")); |
| 2370 | } | 2254 | } |
| 2371 | } | 2255 | } |
| 2372 | 2256 | ||
| 2373 | void | 2257 | void |
| 2374 | QPDF::swapObjects(int objid1, int generation1, int objid2, int generation2) | 2258 | QPDF::swapObjects(int objid1, int generation1, int objid2, int generation2) |
| 2375 | { | 2259 | { |
| 2376 | - swapObjects( | ||
| 2377 | - QPDFObjGen(objid1, generation1), QPDFObjGen(objid2, generation2)); | 2260 | + swapObjects(QPDFObjGen(objid1, generation1), QPDFObjGen(objid2, generation2)); |
| 2378 | } | 2261 | } |
| 2379 | 2262 | ||
| 2380 | void | 2263 | void |
| @@ -2519,8 +2402,7 @@ QPDF::getCompressibleObjGens() | @@ -2519,8 +2402,7 @@ QPDF::getCompressibleObjGens() | ||
| 2519 | if (og == encryption_dict_og) { | 2402 | if (og == encryption_dict_og) { |
| 2520 | QTC::TC("qpdf", "QPDF exclude encryption dictionary"); | 2403 | QTC::TC("qpdf", "QPDF exclude encryption dictionary"); |
| 2521 | } else if (!(obj.isStream() || | 2404 | } else if (!(obj.isStream() || |
| 2522 | - (obj.isDictionaryOfType("/Sig") && | ||
| 2523 | - obj.hasKey("/ByteRange") && | 2405 | + (obj.isDictionaryOfType("/Sig") && obj.hasKey("/ByteRange") && |
| 2524 | obj.hasKey("/Contents")))) { | 2406 | obj.hasKey("/Contents")))) { |
| 2525 | result.push_back(og); | 2407 | result.push_back(og); |
| 2526 | } | 2408 | } |
| @@ -2571,8 +2453,7 @@ QPDF::pipeStreamData( | @@ -2571,8 +2453,7 @@ QPDF::pipeStreamData( | ||
| 2571 | { | 2453 | { |
| 2572 | std::vector<std::shared_ptr<Pipeline>> to_delete; | 2454 | std::vector<std::shared_ptr<Pipeline>> to_delete; |
| 2573 | if (encp->encrypted) { | 2455 | if (encp->encrypted) { |
| 2574 | - decryptStream( | ||
| 2575 | - encp, file, qpdf_for_warning, pipeline, og, stream_dict, to_delete); | 2456 | + decryptStream(encp, file, qpdf_for_warning, pipeline, og, stream_dict, to_delete); |
| 2576 | } | 2457 | } |
| 2577 | 2458 | ||
| 2578 | bool success = false; | 2459 | bool success = false; |
| @@ -2584,10 +2465,7 @@ QPDF::pipeStreamData( | @@ -2584,10 +2465,7 @@ QPDF::pipeStreamData( | ||
| 2584 | size_t len = file->read(buf, to_read); | 2465 | size_t len = file->read(buf, to_read); |
| 2585 | if (len == 0) { | 2466 | if (len == 0) { |
| 2586 | throw damagedPDF( | 2467 | throw damagedPDF( |
| 2587 | - file, | ||
| 2588 | - "", | ||
| 2589 | - file->getLastOffset(), | ||
| 2590 | - "unexpected EOF reading stream data"); | 2468 | + file, "", file->getLastOffset(), "unexpected EOF reading stream data"); |
| 2591 | } | 2469 | } |
| 2592 | length -= len; | 2470 | length -= len; |
| 2593 | pipeline->write(buf, len); | 2471 | pipeline->write(buf, len); |
| @@ -2607,8 +2485,8 @@ QPDF::pipeStreamData( | @@ -2607,8 +2485,8 @@ QPDF::pipeStreamData( | ||
| 2607 | file, | 2485 | file, |
| 2608 | "", | 2486 | "", |
| 2609 | file->getLastOffset(), | 2487 | file->getLastOffset(), |
| 2610 | - ("error decoding stream data for object " + | ||
| 2611 | - og.unparse(' ') + ": " + e.what()))); | 2488 | + ("error decoding stream data for object " + og.unparse(' ') + ": " + |
| 2489 | + e.what()))); | ||
| 2612 | if (will_retry) { | 2490 | if (will_retry) { |
| 2613 | qpdf_for_warning.warn( | 2491 | qpdf_for_warning.warn( |
| 2614 | // line-break | 2492 | // line-break |
| @@ -2694,17 +2572,14 @@ QPDF::damagedPDF( | @@ -2694,17 +2572,14 @@ QPDF::damagedPDF( | ||
| 2694 | qpdf_offset_t offset, | 2572 | qpdf_offset_t offset, |
| 2695 | std::string const& message) | 2573 | std::string const& message) |
| 2696 | { | 2574 | { |
| 2697 | - return QPDFExc( | ||
| 2698 | - qpdf_e_damaged_pdf, input->getName(), object, offset, message); | 2575 | + return QPDFExc(qpdf_e_damaged_pdf, input->getName(), object, offset, message); |
| 2699 | } | 2576 | } |
| 2700 | 2577 | ||
| 2701 | // Return an exception of type qpdf_e_damaged_pdf. The object is taken from | 2578 | // Return an exception of type qpdf_e_damaged_pdf. The object is taken from |
| 2702 | // m->last_object_description. | 2579 | // m->last_object_description. |
| 2703 | QPDFExc | 2580 | QPDFExc |
| 2704 | QPDF::damagedPDF( | 2581 | QPDF::damagedPDF( |
| 2705 | - std::shared_ptr<InputSource> const& input, | ||
| 2706 | - qpdf_offset_t offset, | ||
| 2707 | - std::string const& message) | 2582 | + std::shared_ptr<InputSource> const& input, qpdf_offset_t offset, std::string const& message) |
| 2708 | { | 2583 | { |
| 2709 | return damagedPDF(input, m->last_object_description, offset, message); | 2584 | return damagedPDF(input, m->last_object_description, offset, message); |
| 2710 | } | 2585 | } |
| @@ -2712,11 +2587,9 @@ QPDF::damagedPDF( | @@ -2712,11 +2587,9 @@ QPDF::damagedPDF( | ||
| 2712 | // Return an exception of type qpdf_e_damaged_pdf. The filename is taken from | 2587 | // Return an exception of type qpdf_e_damaged_pdf. The filename is taken from |
| 2713 | // m->file. | 2588 | // m->file. |
| 2714 | QPDFExc | 2589 | QPDFExc |
| 2715 | -QPDF::damagedPDF( | ||
| 2716 | - std::string const& object, qpdf_offset_t offset, std::string const& message) | 2590 | +QPDF::damagedPDF(std::string const& object, qpdf_offset_t offset, std::string const& message) |
| 2717 | { | 2591 | { |
| 2718 | - return QPDFExc( | ||
| 2719 | - qpdf_e_damaged_pdf, m->file->getName(), object, offset, message); | 2592 | + return QPDFExc(qpdf_e_damaged_pdf, m->file->getName(), object, offset, message); |
| 2720 | } | 2593 | } |
| 2721 | 2594 | ||
| 2722 | // Return an exception of type qpdf_e_damaged_pdf. The filename is taken from | 2595 | // 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) | @@ -2741,8 +2614,7 @@ QPDF::damagedPDF(qpdf_offset_t offset, std::string const& message) | ||
| 2741 | QPDFExc | 2614 | QPDFExc |
| 2742 | QPDF::damagedPDF(std::string const& message) | 2615 | QPDF::damagedPDF(std::string const& message) |
| 2743 | { | 2616 | { |
| 2744 | - return damagedPDF( | ||
| 2745 | - m->last_object_description, m->file->getLastOffset(), message); | 2617 | + return damagedPDF(m->last_object_description, m->file->getLastOffset(), message); |
| 2746 | } | 2618 | } |
| 2747 | 2619 | ||
| 2748 | bool | 2620 | bool |
libqpdf/QPDFAcroFormDocumentHelper.cc
| @@ -41,8 +41,7 @@ QPDFAcroFormDocumentHelper::getOrCreateAcroForm() | @@ -41,8 +41,7 @@ QPDFAcroFormDocumentHelper::getOrCreateAcroForm() | ||
| 41 | auto acroform = this->qpdf.getRoot().getKey("/AcroForm"); | 41 | auto acroform = this->qpdf.getRoot().getKey("/AcroForm"); |
| 42 | if (!acroform.isDictionary()) { | 42 | if (!acroform.isDictionary()) { |
| 43 | acroform = this->qpdf.getRoot().replaceKeyAndGetNew( | 43 | acroform = this->qpdf.getRoot().replaceKeyAndGetNew( |
| 44 | - "/AcroForm", | ||
| 45 | - this->qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary())); | 44 | + "/AcroForm", this->qpdf.makeIndirectObject(QPDFObjectHandle::newDictionary())); |
| 46 | } | 45 | } |
| 47 | return acroform; | 46 | return acroform; |
| 48 | } | 47 | } |
| @@ -53,24 +52,20 @@ QPDFAcroFormDocumentHelper::addFormField(QPDFFormFieldObjectHelper ff) | @@ -53,24 +52,20 @@ QPDFAcroFormDocumentHelper::addFormField(QPDFFormFieldObjectHelper ff) | ||
| 53 | auto acroform = getOrCreateAcroForm(); | 52 | auto acroform = getOrCreateAcroForm(); |
| 54 | auto fields = acroform.getKey("/Fields"); | 53 | auto fields = acroform.getKey("/Fields"); |
| 55 | if (!fields.isArray()) { | 54 | if (!fields.isArray()) { |
| 56 | - fields = acroform.replaceKeyAndGetNew( | ||
| 57 | - "/Fields", QPDFObjectHandle::newArray()); | 55 | + fields = acroform.replaceKeyAndGetNew("/Fields", QPDFObjectHandle::newArray()); |
| 58 | } | 56 | } |
| 59 | fields.appendItem(ff.getObjectHandle()); | 57 | fields.appendItem(ff.getObjectHandle()); |
| 60 | QPDFObjGen::set visited; | 58 | QPDFObjGen::set visited; |
| 61 | - traverseField( | ||
| 62 | - ff.getObjectHandle(), QPDFObjectHandle::newNull(), 0, visited); | 59 | + traverseField(ff.getObjectHandle(), QPDFObjectHandle::newNull(), 0, visited); |
| 63 | } | 60 | } |
| 64 | 61 | ||
| 65 | void | 62 | void |
| 66 | -QPDFAcroFormDocumentHelper::addAndRenameFormFields( | ||
| 67 | - std::vector<QPDFObjectHandle> fields) | 63 | +QPDFAcroFormDocumentHelper::addAndRenameFormFields(std::vector<QPDFObjectHandle> fields) |
| 68 | { | 64 | { |
| 69 | analyze(); | 65 | analyze(); |
| 70 | std::map<std::string, std::string> renames; | 66 | std::map<std::string, std::string> renames; |
| 71 | QPDFObjGen::set seen; | 67 | QPDFObjGen::set seen; |
| 72 | - for (std::list<QPDFObjectHandle> queue{fields.begin(), fields.end()}; | ||
| 73 | - !queue.empty(); | 68 | + for (std::list<QPDFObjectHandle> queue{fields.begin(), fields.end()}; !queue.empty(); |
| 74 | queue.pop_front()) { | 69 | queue.pop_front()) { |
| 75 | auto& obj = queue.front(); | 70 | auto& obj = queue.front(); |
| 76 | if (seen.add(obj)) { | 71 | if (seen.add(obj)) { |
| @@ -90,8 +85,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields( | @@ -90,8 +85,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields( | ||
| 90 | // at the end of the fully qualified name, appending to /T | 85 | // at the end of the fully qualified name, appending to /T |
| 91 | // has the effect of appending the same thing to the fully | 86 | // has the effect of appending the same thing to the fully |
| 92 | // qualified name. | 87 | // qualified name. |
| 93 | - std::string old_name = | ||
| 94 | - QPDFFormFieldObjectHelper(obj).getFullyQualifiedName(); | 88 | + std::string old_name = QPDFFormFieldObjectHelper(obj).getFullyQualifiedName(); |
| 95 | if (renames.count(old_name) == 0) { | 89 | if (renames.count(old_name) == 0) { |
| 96 | std::string new_name = old_name; | 90 | std::string new_name = old_name; |
| 97 | int suffix = 0; | 91 | int suffix = 0; |
| @@ -120,8 +114,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields( | @@ -120,8 +114,7 @@ QPDFAcroFormDocumentHelper::addAndRenameFormFields( | ||
| 120 | } | 114 | } |
| 121 | 115 | ||
| 122 | void | 116 | void |
| 123 | -QPDFAcroFormDocumentHelper::removeFormFields( | ||
| 124 | - std::set<QPDFObjGen> const& to_remove) | 117 | +QPDFAcroFormDocumentHelper::removeFormFields(std::set<QPDFObjGen> const& to_remove) |
| 125 | { | 118 | { |
| 126 | auto acroform = this->qpdf.getRoot().getKey("/AcroForm"); | 119 | auto acroform = this->qpdf.getRoot().getKey("/AcroForm"); |
| 127 | if (!acroform.isDictionary()) { | 120 | if (!acroform.isDictionary()) { |
| @@ -162,8 +155,7 @@ QPDFAcroFormDocumentHelper::removeFormFields( | @@ -162,8 +155,7 @@ QPDFAcroFormDocumentHelper::removeFormFields( | ||
| 162 | } | 155 | } |
| 163 | 156 | ||
| 164 | void | 157 | void |
| 165 | -QPDFAcroFormDocumentHelper::setFormFieldName( | ||
| 166 | - QPDFFormFieldObjectHelper ff, std::string const& name) | 158 | +QPDFAcroFormDocumentHelper::setFormFieldName(QPDFFormFieldObjectHelper ff, std::string const& name) |
| 167 | { | 159 | { |
| 168 | ff.setFieldAttribute("/T", name); | 160 | ff.setFieldAttribute("/T", name); |
| 169 | QPDFObjGen::set visited; | 161 | QPDFObjGen::set visited; |
| @@ -257,8 +249,7 @@ QPDFAcroFormDocumentHelper::analyze() | @@ -257,8 +249,7 @@ QPDFAcroFormDocumentHelper::analyze() | ||
| 257 | QPDFObjectHandle fields = acroform.getKey("/Fields"); | 249 | QPDFObjectHandle fields = acroform.getKey("/Fields"); |
| 258 | if (!fields.isArray()) { | 250 | if (!fields.isArray()) { |
| 259 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper fields not array"); | 251 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper fields not array"); |
| 260 | - acroform.warnIfPossible( | ||
| 261 | - "/Fields key of /AcroForm dictionary is not an array; ignoring"); | 252 | + acroform.warnIfPossible("/Fields key of /AcroForm dictionary is not an array; ignoring"); |
| 262 | fields = QPDFObjectHandle::newArray(); | 253 | fields = QPDFObjectHandle::newArray(); |
| 263 | } | 254 | } |
| 264 | 255 | ||
| @@ -294,12 +285,10 @@ QPDFAcroFormDocumentHelper::analyze() | @@ -294,12 +285,10 @@ QPDFAcroFormDocumentHelper::analyze() | ||
| 294 | // adding a self-contained annotation (merged with the | 285 | // adding a self-contained annotation (merged with the |
| 295 | // field dictionary) to the page's /Annots array and | 286 | // field dictionary) to the page's /Annots array and |
| 296 | // forgetting to also put it in /AcroForm. | 287 | // forgetting to also put it in /AcroForm. |
| 297 | - annot.warnIfPossible( | ||
| 298 | - "this widget annotation is not" | ||
| 299 | - " reachable from /AcroForm in the document catalog"); | 288 | + annot.warnIfPossible("this widget annotation is not" |
| 289 | + " reachable from /AcroForm in the document catalog"); | ||
| 300 | m->annotation_to_field[og] = QPDFFormFieldObjectHelper(annot); | 290 | m->annotation_to_field[og] = QPDFFormFieldObjectHelper(annot); |
| 301 | - m->field_to_annotations[og].push_back( | ||
| 302 | - QPDFAnnotationObjectHelper(annot)); | 291 | + m->field_to_annotations[og].push_back(QPDFAnnotationObjectHelper(annot)); |
| 303 | } | 292 | } |
| 304 | } | 293 | } |
| 305 | } | 294 | } |
| @@ -307,10 +296,7 @@ QPDFAcroFormDocumentHelper::analyze() | @@ -307,10 +296,7 @@ QPDFAcroFormDocumentHelper::analyze() | ||
| 307 | 296 | ||
| 308 | void | 297 | void |
| 309 | QPDFAcroFormDocumentHelper::traverseField( | 298 | QPDFAcroFormDocumentHelper::traverseField( |
| 310 | - QPDFObjectHandle field, | ||
| 311 | - QPDFObjectHandle parent, | ||
| 312 | - int depth, | ||
| 313 | - QPDFObjGen::set& visited) | 299 | + QPDFObjectHandle field, QPDFObjectHandle parent, int depth, QPDFObjGen::set& visited) |
| 314 | { | 300 | { |
| 315 | if (depth > 100) { | 301 | if (depth > 100) { |
| 316 | // Arbitrarily cut off recursion at a fixed depth to avoid | 302 | // Arbitrarily cut off recursion at a fixed depth to avoid |
| @@ -319,16 +305,14 @@ QPDFAcroFormDocumentHelper::traverseField( | @@ -319,16 +305,14 @@ QPDFAcroFormDocumentHelper::traverseField( | ||
| 319 | } | 305 | } |
| 320 | if (!field.isIndirect()) { | 306 | if (!field.isIndirect()) { |
| 321 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper direct field"); | 307 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper direct field"); |
| 322 | - field.warnIfPossible( | ||
| 323 | - "encountered a direct object as a field or annotation while" | ||
| 324 | - " traversing /AcroForm; ignoring field or annotation"); | 308 | + field.warnIfPossible("encountered a direct object as a field or annotation while" |
| 309 | + " traversing /AcroForm; ignoring field or annotation"); | ||
| 325 | return; | 310 | return; |
| 326 | } | 311 | } |
| 327 | if (!field.isDictionary()) { | 312 | if (!field.isDictionary()) { |
| 328 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper non-dictionary field"); | 313 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper non-dictionary field"); |
| 329 | - field.warnIfPossible( | ||
| 330 | - "encountered a non-dictionary as a field or annotation while" | ||
| 331 | - " traversing /AcroForm; ignoring field or annotation"); | 314 | + field.warnIfPossible("encountered a non-dictionary as a field or annotation while" |
| 315 | + " traversing /AcroForm; ignoring field or annotation"); | ||
| 332 | return; | 316 | return; |
| 333 | } | 317 | } |
| 334 | QPDFObjGen og(field.getObjGen()); | 318 | QPDFObjGen og(field.getObjGen()); |
| @@ -359,23 +343,17 @@ QPDFAcroFormDocumentHelper::traverseField( | @@ -359,23 +343,17 @@ QPDFAcroFormDocumentHelper::traverseField( | ||
| 359 | if (field.hasKey("/Parent")) { | 343 | if (field.hasKey("/Parent")) { |
| 360 | is_field = true; | 344 | is_field = true; |
| 361 | } | 345 | } |
| 362 | - if (field.hasKey("/Subtype") || field.hasKey("/Rect") || | ||
| 363 | - field.hasKey("/AP")) { | 346 | + if (field.hasKey("/Subtype") || field.hasKey("/Rect") || field.hasKey("/AP")) { |
| 364 | is_annotation = true; | 347 | is_annotation = true; |
| 365 | } | 348 | } |
| 366 | } | 349 | } |
| 367 | 350 | ||
| 368 | - QTC::TC( | ||
| 369 | - "qpdf", "QPDFAcroFormDocumentHelper field found", (depth == 0) ? 0 : 1); | ||
| 370 | - QTC::TC( | ||
| 371 | - "qpdf", | ||
| 372 | - "QPDFAcroFormDocumentHelper annotation found", | ||
| 373 | - (is_field ? 0 : 1)); | 351 | + QTC::TC("qpdf", "QPDFAcroFormDocumentHelper field found", (depth == 0) ? 0 : 1); |
| 352 | + QTC::TC("qpdf", "QPDFAcroFormDocumentHelper annotation found", (is_field ? 0 : 1)); | ||
| 374 | 353 | ||
| 375 | if (is_annotation) { | 354 | if (is_annotation) { |
| 376 | QPDFObjectHandle our_field = (is_field ? field : parent); | 355 | QPDFObjectHandle our_field = (is_field ? field : parent); |
| 377 | - m->field_to_annotations[our_field.getObjGen()].push_back( | ||
| 378 | - QPDFAnnotationObjectHelper(field)); | 356 | + m->field_to_annotations[our_field.getObjGen()].push_back(QPDFAnnotationObjectHelper(field)); |
| 379 | m->annotation_to_field[og] = QPDFFormFieldObjectHelper(our_field); | 357 | m->annotation_to_field[og] = QPDFFormFieldObjectHelper(our_field); |
| 380 | } | 358 | } |
| 381 | 359 | ||
| @@ -400,8 +378,7 @@ QPDFAcroFormDocumentHelper::getNeedAppearances() | @@ -400,8 +378,7 @@ QPDFAcroFormDocumentHelper::getNeedAppearances() | ||
| 400 | { | 378 | { |
| 401 | bool result = false; | 379 | bool result = false; |
| 402 | QPDFObjectHandle acroform = this->qpdf.getRoot().getKey("/AcroForm"); | 380 | QPDFObjectHandle acroform = this->qpdf.getRoot().getKey("/AcroForm"); |
| 403 | - if (acroform.isDictionary() && | ||
| 404 | - acroform.getKey("/NeedAppearances").isBool()) { | 381 | + if (acroform.isDictionary() && acroform.getKey("/NeedAppearances").isBool()) { |
| 405 | result = acroform.getKey("/NeedAppearances").getBoolValue(); | 382 | result = acroform.getKey("/NeedAppearances").getBoolValue(); |
| 406 | } | 383 | } |
| 407 | return result; | 384 | return result; |
| @@ -418,8 +395,7 @@ QPDFAcroFormDocumentHelper::setNeedAppearances(bool val) | @@ -418,8 +395,7 @@ QPDFAcroFormDocumentHelper::setNeedAppearances(bool val) | ||
| 418 | return; | 395 | return; |
| 419 | } | 396 | } |
| 420 | if (val) { | 397 | if (val) { |
| 421 | - acroform.replaceKey( | ||
| 422 | - "/NeedAppearances", QPDFObjectHandle::newBool(true)); | 398 | + acroform.replaceKey("/NeedAppearances", QPDFObjectHandle::newBool(true)); |
| 423 | } else { | 399 | } else { |
| 424 | acroform.removeKey("/NeedAppearances"); | 400 | acroform.removeKey("/NeedAppearances"); |
| 425 | } | 401 | } |
| @@ -472,8 +448,7 @@ QPDFAcroFormDocumentHelper::adjustInheritedFields( | @@ -472,8 +448,7 @@ QPDFAcroFormDocumentHelper::adjustInheritedFields( | ||
| 472 | // we may be put a value on the field that is unused. This is | 448 | // we may be put a value on the field that is unused. This is |
| 473 | // harmless, so it's not worth trying to work around. | 449 | // harmless, so it's not worth trying to work around. |
| 474 | 450 | ||
| 475 | - auto has_explicit = [](QPDFFormFieldObjectHelper& field, | ||
| 476 | - std::string const& key) { | 451 | + auto has_explicit = [](QPDFFormFieldObjectHelper& field, std::string const& key) { |
| 477 | if (field.getObjectHandle().hasKey(key)) { | 452 | if (field.getObjectHandle().hasKey(key)) { |
| 478 | return true; | 453 | return true; |
| 479 | } | 454 | } |
| @@ -490,16 +465,14 @@ QPDFAcroFormDocumentHelper::adjustInheritedFields( | @@ -490,16 +465,14 @@ QPDFAcroFormDocumentHelper::adjustInheritedFields( | ||
| 490 | std::string da = cur_field.getDefaultAppearance(); | 465 | std::string da = cur_field.getDefaultAppearance(); |
| 491 | if (da != from_default_da) { | 466 | if (da != from_default_da) { |
| 492 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper override da"); | 467 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper override da"); |
| 493 | - obj.replaceKey( | ||
| 494 | - "/DA", QPDFObjectHandle::newUnicodeString(from_default_da)); | 468 | + obj.replaceKey("/DA", QPDFObjectHandle::newUnicodeString(from_default_da)); |
| 495 | } | 469 | } |
| 496 | } | 470 | } |
| 497 | if (override_q && (!has_explicit(cur_field, "/Q"))) { | 471 | if (override_q && (!has_explicit(cur_field, "/Q"))) { |
| 498 | int q = cur_field.getQuadding(); | 472 | int q = cur_field.getQuadding(); |
| 499 | if (q != from_default_q) { | 473 | if (q != from_default_q) { |
| 500 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper override q"); | 474 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper override q"); |
| 501 | - obj.replaceKey( | ||
| 502 | - "/Q", QPDFObjectHandle::newInteger(from_default_q)); | 475 | + obj.replaceKey("/Q", QPDFObjectHandle::newInteger(from_default_q)); |
| 503 | } | 476 | } |
| 504 | } | 477 | } |
| 505 | } | 478 | } |
| @@ -511,11 +484,8 @@ namespace | @@ -511,11 +484,8 @@ namespace | ||
| 511 | { | 484 | { |
| 512 | public: | 485 | public: |
| 513 | ResourceReplacer( | 486 | ResourceReplacer( |
| 514 | - std::map<std::string, std::map<std::string, std::string>> const& | ||
| 515 | - dr_map, | ||
| 516 | - std::map< | ||
| 517 | - std::string, | ||
| 518 | - std::map<std::string, std::set<size_t>>> const& rnames); | 487 | + std::map<std::string, std::map<std::string, std::string>> const& dr_map, |
| 488 | + std::map<std::string, std::map<std::string, std::set<size_t>>> const& rnames); | ||
| 519 | virtual ~ResourceReplacer() = default; | 489 | virtual ~ResourceReplacer() = default; |
| 520 | virtual void handleToken(QPDFTokenizer::Token const&) override; | 490 | virtual void handleToken(QPDFTokenizer::Token const&) override; |
| 521 | 491 | ||
| @@ -527,8 +497,7 @@ namespace | @@ -527,8 +497,7 @@ namespace | ||
| 527 | 497 | ||
| 528 | ResourceReplacer::ResourceReplacer( | 498 | ResourceReplacer::ResourceReplacer( |
| 529 | std::map<std::string, std::map<std::string, std::string>> const& dr_map, | 499 | std::map<std::string, std::map<std::string, std::string>> const& dr_map, |
| 530 | - std::map<std::string, std::map<std::string, std::set<size_t>>> const& | ||
| 531 | - rnames) : | 500 | + std::map<std::string, std::map<std::string, std::set<size_t>>> const& rnames) : |
| 532 | offset(0) | 501 | offset(0) |
| 533 | { | 502 | { |
| 534 | // We have: | 503 | // We have: |
| @@ -564,8 +533,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const& token) | @@ -564,8 +533,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const& token) | ||
| 564 | { | 533 | { |
| 565 | bool wrote = false; | 534 | bool wrote = false; |
| 566 | if (token.getType() == QPDFTokenizer::tt_name) { | 535 | if (token.getType() == QPDFTokenizer::tt_name) { |
| 567 | - std::string name = | ||
| 568 | - QPDFObjectHandle::newName(token.getValue()).getName(); | 536 | + std::string name = QPDFObjectHandle::newName(token.getValue()).getName(); |
| 569 | if (to_replace.count(name) && to_replace[name].count(offset)) { | 537 | if (to_replace.count(name) && to_replace[name].count(offset)) { |
| 570 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper replaced DA token"); | 538 | QTC::TC("qpdf", "QPDFAcroFormDocumentHelper replaced DA token"); |
| 571 | write(to_replace[name][offset]); | 539 | write(to_replace[name][offset]); |
| @@ -580,8 +548,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const& token) | @@ -580,8 +548,7 @@ ResourceReplacer::handleToken(QPDFTokenizer::Token const& token) | ||
| 580 | 548 | ||
| 581 | void | 549 | void |
| 582 | QPDFAcroFormDocumentHelper::adjustDefaultAppearances( | 550 | QPDFAcroFormDocumentHelper::adjustDefaultAppearances( |
| 583 | - QPDFObjectHandle obj, | ||
| 584 | - std::map<std::string, std::map<std::string, std::string>> const& dr_map) | 551 | + QPDFObjectHandle obj, std::map<std::string, std::map<std::string, std::string>> const& dr_map) |
| 585 | { | 552 | { |
| 586 | // This method is called on a field that has been copied from | 553 | // This method is called on a field that has been copied from |
| 587 | // another file but whose /DA still refers to resources in the | 554 | // another file but whose /DA still refers to resources in the |
| @@ -624,8 +591,7 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances( | @@ -624,8 +591,7 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances( | ||
| 624 | // then filter it. We don't attach the stream to anything, so it | 591 | // then filter it. We don't attach the stream to anything, so it |
| 625 | // will get discarded. | 592 | // will get discarded. |
| 626 | ResourceFinder rf; | 593 | ResourceFinder rf; |
| 627 | - auto da_stream = | ||
| 628 | - QPDFObjectHandle::newStream(&this->qpdf, DA.getUTF8Value()); | 594 | + auto da_stream = QPDFObjectHandle::newStream(&this->qpdf, DA.getUTF8Value()); |
| 629 | try { | 595 | try { |
| 630 | auto nwarnings = this->qpdf.numWarnings(); | 596 | auto nwarnings = this->qpdf.numWarnings(); |
| 631 | da_stream.parseAsContents(&rf); | 597 | da_stream.parseAsContents(&rf); |
| @@ -646,15 +612,13 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances( | @@ -646,15 +612,13 @@ QPDFAcroFormDocumentHelper::adjustDefaultAppearances( | ||
| 646 | Pl_Buffer buf_pl("filtered DA"); | 612 | Pl_Buffer buf_pl("filtered DA"); |
| 647 | da_stream.filterAsContents(&rr, &buf_pl); | 613 | da_stream.filterAsContents(&rr, &buf_pl); |
| 648 | auto buf = buf_pl.getBufferSharedPointer(); | 614 | auto buf = buf_pl.getBufferSharedPointer(); |
| 649 | - std::string new_da( | ||
| 650 | - reinterpret_cast<char*>(buf->getBuffer()), buf->getSize()); | 615 | + std::string new_da(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize()); |
| 651 | obj.replaceKey("/DA", QPDFObjectHandle::newString(new_da)); | 616 | obj.replaceKey("/DA", QPDFObjectHandle::newString(new_da)); |
| 652 | } | 617 | } |
| 653 | 618 | ||
| 654 | void | 619 | void |
| 655 | QPDFAcroFormDocumentHelper::adjustAppearanceStream( | 620 | QPDFAcroFormDocumentHelper::adjustAppearanceStream( |
| 656 | - QPDFObjectHandle stream, | ||
| 657 | - std::map<std::string, std::map<std::string, std::string>> dr_map) | 621 | + QPDFObjectHandle stream, std::map<std::string, std::map<std::string, std::string>> dr_map) |
| 658 | { | 622 | { |
| 659 | // We don't have to modify appearance streams or their resource | 623 | // We don't have to modify appearance streams or their resource |
| 660 | // dictionaries for them to display properly, but we need to do so | 624 | // dictionaries for them to display properly, but we need to do so |
| @@ -740,8 +704,7 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream( | @@ -740,8 +704,7 @@ QPDFAcroFormDocumentHelper::adjustAppearanceStream( | ||
| 740 | } catch (std::exception& e) { | 704 | } catch (std::exception& e) { |
| 741 | // No way to reproduce in test suite right now since error | 705 | // No way to reproduce in test suite right now since error |
| 742 | // conditions are converted to warnings. | 706 | // conditions are converted to warnings. |
| 743 | - stream.warnIfPossible( | ||
| 744 | - std::string("Unable to parse appearance stream: ") + e.what()); | 707 | + stream.warnIfPossible(std::string("Unable to parse appearance stream: ") + e.what()); |
| 745 | } | 708 | } |
| 746 | } | 709 | } |
| 747 | 710 | ||
| @@ -839,8 +802,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | @@ -839,8 +802,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | ||
| 839 | } | 802 | } |
| 840 | dr.makeResourcesIndirect(this->qpdf); | 803 | dr.makeResourcesIndirect(this->qpdf); |
| 841 | if (!dr.isIndirect()) { | 804 | if (!dr.isIndirect()) { |
| 842 | - dr = acroform.replaceKeyAndGetNew( | ||
| 843 | - "/DR", this->qpdf.makeIndirectObject(dr)); | 805 | + dr = acroform.replaceKeyAndGetNew("/DR", this->qpdf.makeIndirectObject(dr)); |
| 844 | } | 806 | } |
| 845 | // Merge the other document's /DR, creating a conflict | 807 | // Merge the other document's /DR, creating a conflict |
| 846 | // map. mergeResources checks to make sure both objects | 808 | // map. mergeResources checks to make sure both objects |
| @@ -969,8 +931,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | @@ -969,8 +931,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | ||
| 969 | obj.replaceKey("/Parent", orig_to_copy[parent_og]); | 931 | obj.replaceKey("/Parent", orig_to_copy[parent_og]); |
| 970 | } else { | 932 | } else { |
| 971 | parent.warnIfPossible( | 933 | parent.warnIfPossible( |
| 972 | - "while traversing field " + | ||
| 973 | - obj.getObjGen().unparse(',') + | 934 | + "while traversing field " + obj.getObjGen().unparse(',') + |
| 974 | ", found parent (" + parent_og.unparse(',') + | 935 | ", found parent (" + parent_og.unparse(',') + |
| 975 | ") that had not been seen, indicating likely" | 936 | ") that had not been seen, indicating likely" |
| 976 | " invalid field structure"); | 937 | " invalid field structure"); |
| @@ -989,11 +950,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | @@ -989,11 +950,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | ||
| 989 | 950 | ||
| 990 | if (override_da || override_q) { | 951 | if (override_da || override_q) { |
| 991 | adjustInheritedFields( | 952 | adjustInheritedFields( |
| 992 | - obj, | ||
| 993 | - override_da, | ||
| 994 | - from_default_da, | ||
| 995 | - override_q, | ||
| 996 | - from_default_q); | 953 | + obj, override_da, from_default_da, override_q, from_default_q); |
| 997 | } | 954 | } |
| 998 | if (foreign) { | 955 | if (foreign) { |
| 999 | // Lazily initialize our /DR and the conflict map. | 956 | // Lazily initialize our /DR and the conflict map. |
| @@ -1013,8 +970,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | @@ -1013,8 +970,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | ||
| 1013 | obj.replaceKey("/DR", dr); | 970 | obj.replaceKey("/DR", dr); |
| 1014 | } | 971 | } |
| 1015 | } | 972 | } |
| 1016 | - if (foreign && obj.getKey("/DA").isString() && | ||
| 1017 | - (!dr_map.empty())) { | 973 | + if (foreign && obj.getKey("/DA").isString() && (!dr_map.empty())) { |
| 1018 | adjustDefaultAppearances(obj, dr_map); | 974 | adjustDefaultAppearances(obj, dr_map); |
| 1019 | } | 975 | } |
| 1020 | } | 976 | } |
| @@ -1060,15 +1016,13 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | @@ -1060,15 +1016,13 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | ||
| 1060 | if (apdict.isDictionary()) { | 1016 | if (apdict.isDictionary()) { |
| 1061 | for (auto& ap: apdict.ditems()) { | 1017 | for (auto& ap: apdict.ditems()) { |
| 1062 | if (ap.second.isStream()) { | 1018 | if (ap.second.isStream()) { |
| 1063 | - streams.push_back( | ||
| 1064 | - replace_stream(apdict, ap.first, ap.second)); | 1019 | + streams.push_back(replace_stream(apdict, ap.first, ap.second)); |
| 1065 | } else if (ap.second.isDictionary()) { | 1020 | } else if (ap.second.isDictionary()) { |
| 1066 | for (auto& ap2: ap.second.ditems()) { | 1021 | for (auto& ap2: ap.second.ditems()) { |
| 1067 | if (ap2.second.isStream()) { | 1022 | if (ap2.second.isStream()) { |
| 1068 | streams.push_back( | 1023 | streams.push_back( |
| 1069 | // line-break | 1024 | // line-break |
| 1070 | - replace_stream( | ||
| 1071 | - ap.second, ap2.first, ap2.second)); | 1025 | + replace_stream(ap.second, ap2.first, ap2.second)); |
| 1072 | } | 1026 | } |
| 1073 | } | 1027 | } |
| 1074 | } | 1028 | } |
| @@ -1096,8 +1050,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | @@ -1096,8 +1050,7 @@ QPDFAcroFormDocumentHelper::transformAnnotations( | ||
| 1096 | adjustAppearanceStream(stream, dr_map); | 1050 | adjustAppearanceStream(stream, dr_map); |
| 1097 | } | 1051 | } |
| 1098 | } | 1052 | } |
| 1099 | - auto rect = | ||
| 1100 | - cm.transformRectangle(annot.getKey("/Rect").getArrayAsRectangle()); | 1053 | + auto rect = cm.transformRectangle(annot.getKey("/Rect").getArrayAsRectangle()); |
| 1101 | annot.replaceKey("/Rect", QPDFObjectHandle::newFromRectangle(rect)); | 1054 | annot.replaceKey("/Rect", QPDFObjectHandle::newFromRectangle(rect)); |
| 1102 | } | 1055 | } |
| 1103 | } | 1056 | } |
libqpdf/QPDFAnnotationObjectHelper.cc
| @@ -47,8 +47,7 @@ QPDFAnnotationObjectHelper::getFlags() | @@ -47,8 +47,7 @@ QPDFAnnotationObjectHelper::getFlags() | ||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | QPDFObjectHandle | 49 | QPDFObjectHandle |
| 50 | -QPDFAnnotationObjectHelper::getAppearanceStream( | ||
| 51 | - std::string const& which, std::string const& state) | 50 | +QPDFAnnotationObjectHelper::getAppearanceStream(std::string const& which, std::string const& state) |
| 52 | { | 51 | { |
| 53 | QPDFObjectHandle ap = getAppearanceDictionary(); | 52 | QPDFObjectHandle ap = getAppearanceDictionary(); |
| 54 | std::string desired_state = state.empty() ? getAppearanceState() : state; | 53 | std::string desired_state = state.empty() ? getAppearanceState() : state; |
| @@ -80,10 +79,7 @@ QPDFAnnotationObjectHelper::getAppearanceStream( | @@ -80,10 +79,7 @@ QPDFAnnotationObjectHelper::getAppearanceStream( | ||
| 80 | 79 | ||
| 81 | std::string | 80 | std::string |
| 82 | QPDFAnnotationObjectHelper::getPageContentForAppearance( | 81 | QPDFAnnotationObjectHelper::getPageContentForAppearance( |
| 83 | - std::string const& name, | ||
| 84 | - int rotate, | ||
| 85 | - int required_flags, | ||
| 86 | - int forbidden_flags) | 82 | + std::string const& name, int rotate, int required_flags, int forbidden_flags) |
| 87 | { | 83 | { |
| 88 | if (!getAppearanceStream("/N").isStream()) { | 84 | if (!getAppearanceStream("/N").isStream()) { |
| 89 | return ""; | 85 | return ""; |
| @@ -242,9 +238,7 @@ QPDFAnnotationObjectHelper::getPageContentForAppearance( | @@ -242,9 +238,7 @@ QPDFAnnotationObjectHelper::getPageContentForAppearance( | ||
| 242 | // Compute a matrix to transform the appearance box to the rectangle | 238 | // Compute a matrix to transform the appearance box to the rectangle |
| 243 | QPDFMatrix AA; | 239 | QPDFMatrix AA; |
| 244 | AA.translate(rect.llx, rect.lly); | 240 | AA.translate(rect.llx, rect.lly); |
| 245 | - AA.scale( | ||
| 246 | - (rect.urx - rect.llx) / (T.urx - T.llx), | ||
| 247 | - (rect.ury - rect.lly) / (T.ury - T.lly)); | 241 | + AA.scale((rect.urx - rect.llx) / (T.urx - T.llx), (rect.ury - rect.lly) / (T.ury - T.lly)); |
| 248 | AA.translate(-T.llx, -T.lly); | 242 | AA.translate(-T.llx, -T.lly); |
| 249 | if (do_rotate) { | 243 | if (do_rotate) { |
| 250 | AA.rotatex90(rotate); | 244 | AA.rotatex90(rotate); |
libqpdf/QPDFArgParser.cc
| @@ -9,8 +9,7 @@ | @@ -9,8 +9,7 @@ | ||
| 9 | #include <cstring> | 9 | #include <cstring> |
| 10 | #include <iostream> | 10 | #include <iostream> |
| 11 | 11 | ||
| 12 | -QPDFArgParser::Members::Members( | ||
| 13 | - int argc, char const* const argv[], char const* progname_env) : | 12 | +QPDFArgParser::Members::Members(int argc, char const* const argv[], char const* progname_env) : |
| 14 | 13 | ||
| 15 | argc(argc), | 14 | argc(argc), |
| 16 | argv(argv), | 15 | argv(argv), |
| @@ -25,19 +24,15 @@ QPDFArgParser::Members::Members( | @@ -25,19 +24,15 @@ QPDFArgParser::Members::Members( | ||
| 25 | whoami = QUtil::getWhoami(tmp.get()); | 24 | whoami = QUtil::getWhoami(tmp.get()); |
| 26 | } | 25 | } |
| 27 | 26 | ||
| 28 | -QPDFArgParser::QPDFArgParser( | ||
| 29 | - int argc, char const* const argv[], char const* progname_env) : | 27 | +QPDFArgParser::QPDFArgParser(int argc, char const* const argv[], char const* progname_env) : |
| 30 | m(new Members(argc, argv, progname_env)) | 28 | m(new Members(argc, argv, progname_env)) |
| 31 | { | 29 | { |
| 32 | selectHelpOptionTable(); | 30 | selectHelpOptionTable(); |
| 33 | char const* help_choices[] = {"all", nullptr}; | 31 | char const* help_choices[] = {"all", nullptr}; |
| 34 | // More help choices are added dynamically. | 32 | // More help choices are added dynamically. |
| 35 | - addChoices( | ||
| 36 | - "help", bindParam(&QPDFArgParser::argHelp, this), false, help_choices); | ||
| 37 | - addInvalidChoiceHandler( | ||
| 38 | - "help", bindParam(&QPDFArgParser::invalidHelpArg, this)); | ||
| 39 | - addBare( | ||
| 40 | - "completion-bash", bindBare(&QPDFArgParser::argCompletionBash, this)); | 33 | + addChoices("help", bindParam(&QPDFArgParser::argHelp, this), false, help_choices); |
| 34 | + addInvalidChoiceHandler("help", bindParam(&QPDFArgParser::invalidHelpArg, this)); | ||
| 35 | + addBare("completion-bash", bindBare(&QPDFArgParser::argCompletionBash, this)); | ||
| 41 | addBare("completion-zsh", bindBare(&QPDFArgParser::argCompletionZsh, this)); | 36 | addBare("completion-zsh", bindBare(&QPDFArgParser::argCompletionZsh, this)); |
| 42 | selectMainOptionTable(); | 37 | selectMainOptionTable(); |
| 43 | } | 38 | } |
| @@ -62,22 +57,19 @@ QPDFArgParser::selectOptionTable(std::string const& name) | @@ -62,22 +57,19 @@ QPDFArgParser::selectOptionTable(std::string const& name) | ||
| 62 | auto t = m->option_tables.find(name); | 57 | auto t = m->option_tables.find(name); |
| 63 | if (t == m->option_tables.end()) { | 58 | if (t == m->option_tables.end()) { |
| 64 | QTC::TC("libtests", "QPDFArgParser select unregistered table"); | 59 | QTC::TC("libtests", "QPDFArgParser select unregistered table"); |
| 65 | - throw std::logic_error( | ||
| 66 | - "QPDFArgParser: selecting unregistered option table " + name); | 60 | + throw std::logic_error("QPDFArgParser: selecting unregistered option table " + name); |
| 67 | } | 61 | } |
| 68 | m->option_table = &(t->second); | 62 | m->option_table = &(t->second); |
| 69 | m->option_table_name = name; | 63 | m->option_table_name = name; |
| 70 | } | 64 | } |
| 71 | 65 | ||
| 72 | void | 66 | void |
| 73 | -QPDFArgParser::registerOptionTable( | ||
| 74 | - std::string const& name, bare_arg_handler_t end_handler) | 67 | +QPDFArgParser::registerOptionTable(std::string const& name, bare_arg_handler_t end_handler) |
| 75 | { | 68 | { |
| 76 | if (0 != m->option_tables.count(name)) { | 69 | if (0 != m->option_tables.count(name)) { |
| 77 | QTC::TC("libtests", "QPDFArgParser register registered table"); | 70 | QTC::TC("libtests", "QPDFArgParser register registered table"); |
| 78 | throw std::logic_error( | 71 | throw std::logic_error( |
| 79 | - "QPDFArgParser: registering already registered option table " + | ||
| 80 | - name); | 72 | + "QPDFArgParser: registering already registered option table " + name); |
| 81 | } | 73 | } |
| 82 | m->option_tables[name]; | 74 | m->option_tables[name]; |
| 83 | selectOptionTable(name); | 75 | selectOptionTable(name); |
| @@ -90,8 +82,8 @@ QPDFArgParser::registerArg(std::string const& arg) | @@ -90,8 +82,8 @@ QPDFArgParser::registerArg(std::string const& arg) | ||
| 90 | if (0 != m->option_table->count(arg)) { | 82 | if (0 != m->option_table->count(arg)) { |
| 91 | QTC::TC("libtests", "QPDFArgParser duplicate handler"); | 83 | QTC::TC("libtests", "QPDFArgParser duplicate handler"); |
| 92 | throw std::logic_error( | 84 | throw std::logic_error( |
| 93 | - "QPDFArgParser: adding a duplicate handler for option " + arg + | ||
| 94 | - " in " + m->option_table_name + " option table"); | 85 | + "QPDFArgParser: adding a duplicate handler for option " + arg + " in " + |
| 86 | + m->option_table_name + " option table"); | ||
| 95 | } | 87 | } |
| 96 | return ((*m->option_table)[arg]); | 88 | return ((*m->option_table)[arg]); |
| 97 | } | 89 | } |
| @@ -113,9 +105,7 @@ QPDFArgParser::addBare(std::string const& arg, bare_arg_handler_t handler) | @@ -113,9 +105,7 @@ QPDFArgParser::addBare(std::string const& arg, bare_arg_handler_t handler) | ||
| 113 | 105 | ||
| 114 | void | 106 | void |
| 115 | QPDFArgParser::addRequiredParameter( | 107 | QPDFArgParser::addRequiredParameter( |
| 116 | - std::string const& arg, | ||
| 117 | - param_arg_handler_t handler, | ||
| 118 | - char const* parameter_name) | 108 | + std::string const& arg, param_arg_handler_t handler, char const* parameter_name) |
| 119 | { | 109 | { |
| 120 | OptionEntry& oe = registerArg(arg); | 110 | OptionEntry& oe = registerArg(arg); |
| 121 | oe.parameter_needed = true; | 111 | oe.parameter_needed = true; |
| @@ -124,8 +114,7 @@ QPDFArgParser::addRequiredParameter( | @@ -124,8 +114,7 @@ QPDFArgParser::addRequiredParameter( | ||
| 124 | } | 114 | } |
| 125 | 115 | ||
| 126 | void | 116 | void |
| 127 | -QPDFArgParser::addOptionalParameter( | ||
| 128 | - std::string const& arg, param_arg_handler_t handler) | 117 | +QPDFArgParser::addOptionalParameter(std::string const& arg, param_arg_handler_t handler) |
| 129 | { | 118 | { |
| 130 | OptionEntry& oe = registerArg(arg); | 119 | OptionEntry& oe = registerArg(arg); |
| 131 | oe.parameter_needed = false; | 120 | oe.parameter_needed = false; |
| @@ -134,10 +123,7 @@ QPDFArgParser::addOptionalParameter( | @@ -134,10 +123,7 @@ QPDFArgParser::addOptionalParameter( | ||
| 134 | 123 | ||
| 135 | void | 124 | void |
| 136 | QPDFArgParser::addChoices( | 125 | QPDFArgParser::addChoices( |
| 137 | - std::string const& arg, | ||
| 138 | - param_arg_handler_t handler, | ||
| 139 | - bool required, | ||
| 140 | - char const** choices) | 126 | + std::string const& arg, param_arg_handler_t handler, bool required, char const** choices) |
| 141 | { | 127 | { |
| 142 | OptionEntry& oe = registerArg(arg); | 128 | OptionEntry& oe = registerArg(arg); |
| 143 | oe.parameter_needed = required; | 129 | oe.parameter_needed = required; |
| @@ -148,15 +134,13 @@ QPDFArgParser::addChoices( | @@ -148,15 +134,13 @@ QPDFArgParser::addChoices( | ||
| 148 | } | 134 | } |
| 149 | 135 | ||
| 150 | void | 136 | void |
| 151 | -QPDFArgParser::addInvalidChoiceHandler( | ||
| 152 | - std::string const& arg, param_arg_handler_t handler) | 137 | +QPDFArgParser::addInvalidChoiceHandler(std::string const& arg, param_arg_handler_t handler) |
| 153 | { | 138 | { |
| 154 | auto i = m->option_table->find(arg); | 139 | auto i = m->option_table->find(arg); |
| 155 | if (i == m->option_table->end()) { | 140 | if (i == m->option_table->end()) { |
| 156 | QTC::TC("libtests", "QPDFArgParser invalid choice handler to unknown"); | 141 | QTC::TC("libtests", "QPDFArgParser invalid choice handler to unknown"); |
| 157 | - throw std::logic_error( | ||
| 158 | - "QPDFArgParser: attempt to add invalid choice handler" | ||
| 159 | - " to unknown argument"); | 142 | + throw std::logic_error("QPDFArgParser: attempt to add invalid choice handler" |
| 143 | + " to unknown argument"); | ||
| 160 | } | 144 | } |
| 161 | auto& oe = i->second; | 145 | auto& oe = i->second; |
| 162 | oe.invalid_choice_handler = handler; | 146 | oe.invalid_choice_handler = handler; |
| @@ -195,9 +179,7 @@ QPDFArgParser::completionCommon(bool zsh) | @@ -195,9 +179,7 @@ QPDFArgParser::completionCommon(bool zsh) | ||
| 195 | std::string appimage; | 179 | std::string appimage; |
| 196 | if (QUtil::get_env(m->progname_env.c_str(), &executable)) { | 180 | if (QUtil::get_env(m->progname_env.c_str(), &executable)) { |
| 197 | progname = executable; | 181 | progname = executable; |
| 198 | - } else if ( | ||
| 199 | - QUtil::get_env("APPDIR", &appdir) && | ||
| 200 | - QUtil::get_env("APPIMAGE", &appimage)) { | 182 | + } else if (QUtil::get_env("APPDIR", &appdir) && QUtil::get_env("APPIMAGE", &appimage)) { |
| 201 | // Detect if we're in an AppImage and adjust | 183 | // Detect if we're in an AppImage and adjust |
| 202 | if ((appdir.length() < strlen(m->argv[0])) && | 184 | if ((appdir.length() < strlen(m->argv[0])) && |
| 203 | (strncmp(appdir.c_str(), m->argv[0], appdir.length()) == 0)) { | 185 | (strncmp(appdir.c_str(), m->argv[0], appdir.length()) == 0)) { |
| @@ -345,8 +327,7 @@ QPDFArgParser::handleBashArguments() | @@ -345,8 +327,7 @@ QPDFArgParser::handleBashArguments() | ||
| 345 | } | 327 | } |
| 346 | // Explicitly discard any non-space-terminated word. The "current | 328 | // Explicitly discard any non-space-terminated word. The "current |
| 347 | // word" is handled specially. | 329 | // word" is handled specially. |
| 348 | - m->bash_argv_ph = | ||
| 349 | - QUtil::make_shared_array<char const*>(1 + m->bash_argv.size()); | 330 | + m->bash_argv_ph = QUtil::make_shared_array<char const*>(1 + m->bash_argv.size()); |
| 350 | for (size_t i = 0; i < m->bash_argv.size(); ++i) { | 331 | for (size_t i = 0; i < m->bash_argv.size(); ++i) { |
| 351 | m->bash_argv_ph.get()[i] = m->bash_argv.at(i).get(); | 332 | m->bash_argv_ph.get()[i] = m->bash_argv.at(i).get(); |
| 352 | } | 333 | } |
| @@ -479,8 +460,7 @@ QPDFArgParser::parseArgs() | @@ -479,8 +460,7 @@ QPDFArgParser::parseArgs() | ||
| 479 | end_option = true; | 460 | end_option = true; |
| 480 | if (oep == m->option_table->end()) { | 461 | if (oep == m->option_table->end()) { |
| 481 | // This is registered automatically, so this can't happen. | 462 | // This is registered automatically, so this can't happen. |
| 482 | - throw std::logic_error( | ||
| 483 | - "QPDFArgParser: -- handler not registered"); | 463 | + throw std::logic_error("QPDFArgParser: -- handler not registered"); |
| 484 | } | 464 | } |
| 485 | } else if ((arg[0] == '-') && (strcmp(arg, "-") != 0)) { | 465 | } else if ((arg[0] == '-') && (strcmp(arg, "-") != 0)) { |
| 486 | ++arg; | 466 | ++arg; |
| @@ -531,18 +511,15 @@ QPDFArgParser::parseArgs() | @@ -531,18 +511,15 @@ QPDFArgParser::parseArgs() | ||
| 531 | QTC::TC("libtests", "QPDFArgParser unrecognized"); | 511 | QTC::TC("libtests", "QPDFArgParser unrecognized"); |
| 532 | std::string message = "unrecognized argument " + o_arg; | 512 | std::string message = "unrecognized argument " + o_arg; |
| 533 | if (m->option_table != &m->main_option_table) { | 513 | if (m->option_table != &m->main_option_table) { |
| 534 | - message += " (" + m->option_table_name + | ||
| 535 | - " options must be terminated with --)"; | 514 | + message += " (" + m->option_table_name + " options must be terminated with --)"; |
| 536 | } | 515 | } |
| 537 | usage(message); | 516 | usage(message); |
| 538 | } | 517 | } |
| 539 | 518 | ||
| 540 | OptionEntry& oe = oep->second; | 519 | OptionEntry& oe = oep->second; |
| 541 | if ((oe.parameter_needed && (!have_parameter)) || | 520 | if ((oe.parameter_needed && (!have_parameter)) || |
| 542 | - ((!oe.choices.empty() && have_parameter && | ||
| 543 | - (0 == oe.choices.count(parameter))))) { | ||
| 544 | - std::string message = | ||
| 545 | - "--" + arg_s + " must be given as --" + arg_s + "="; | 521 | + ((!oe.choices.empty() && have_parameter && (0 == oe.choices.count(parameter))))) { |
| 522 | + std::string message = "--" + arg_s + " must be given as --" + arg_s + "="; | ||
| 546 | if (oe.invalid_choice_handler) { | 523 | if (oe.invalid_choice_handler) { |
| 547 | oe.invalid_choice_handler(parameter); | 524 | oe.invalid_choice_handler(parameter); |
| 548 | // Method should call usage() or exit. Just in case it | 525 | // Method should call usage() or exit. Just in case it |
| @@ -609,9 +586,7 @@ QPDFArgParser::doFinalChecks() | @@ -609,9 +586,7 @@ QPDFArgParser::doFinalChecks() | ||
| 609 | 586 | ||
| 610 | void | 587 | void |
| 611 | QPDFArgParser::addChoicesToCompletions( | 588 | QPDFArgParser::addChoicesToCompletions( |
| 612 | - option_table_t& option_table, | ||
| 613 | - std::string const& option, | ||
| 614 | - std::string const& extra_prefix) | 589 | + option_table_t& option_table, std::string const& option, std::string const& extra_prefix) |
| 615 | { | 590 | { |
| 616 | if (option_table.count(option) != 0) { | 591 | if (option_table.count(option) != 0) { |
| 617 | OptionEntry& oe = option_table[option]; | 592 | OptionEntry& oe = option_table[option]; |
| @@ -648,9 +623,7 @@ QPDFArgParser::addOptionsToCompletions(option_table_t& option_table) | @@ -648,9 +623,7 @@ QPDFArgParser::addOptionsToCompletions(option_table_t& option_table) | ||
| 648 | 623 | ||
| 649 | void | 624 | void |
| 650 | QPDFArgParser::insertCompletions( | 625 | QPDFArgParser::insertCompletions( |
| 651 | - option_table_t& option_table, | ||
| 652 | - std::string const& choice_option, | ||
| 653 | - std::string const& extra_prefix) | 626 | + option_table_t& option_table, std::string const& choice_option, std::string const& extra_prefix) |
| 654 | { | 627 | { |
| 655 | if (!choice_option.empty()) { | 628 | if (!choice_option.empty()) { |
| 656 | addChoicesToCompletions(option_table, choice_option, extra_prefix); | 629 | addChoicesToCompletions(option_table, choice_option, extra_prefix); |
| @@ -666,21 +639,17 @@ QPDFArgParser::handleCompletion() | @@ -666,21 +639,17 @@ QPDFArgParser::handleCompletion() | ||
| 666 | if (m->completions.empty()) { | 639 | if (m->completions.empty()) { |
| 667 | // Detect --option=... Bash treats the = as a word separator. | 640 | // Detect --option=... Bash treats the = as a word separator. |
| 668 | std::string choice_option; | 641 | std::string choice_option; |
| 669 | - if (m->bash_cur.empty() && (m->bash_prev.length() > 2) && | ||
| 670 | - (m->bash_prev.at(0) == '-') && (m->bash_prev.at(1) == '-') && | ||
| 671 | - (m->bash_line.at(m->bash_line.length() - 1) == '=')) { | 642 | + if (m->bash_cur.empty() && (m->bash_prev.length() > 2) && (m->bash_prev.at(0) == '-') && |
| 643 | + (m->bash_prev.at(1) == '-') && (m->bash_line.at(m->bash_line.length() - 1) == '=')) { | ||
| 672 | choice_option = m->bash_prev.substr(2, std::string::npos); | 644 | choice_option = m->bash_prev.substr(2, std::string::npos); |
| 673 | - } else if ( | ||
| 674 | - (m->bash_prev == "=") && | ||
| 675 | - (m->bash_line.length() > (m->bash_cur.length() + 1))) { | 645 | + } else if ((m->bash_prev == "=") && (m->bash_line.length() > (m->bash_cur.length() + 1))) { |
| 676 | // We're sitting at --option=x. Find previous option. | 646 | // We're sitting at --option=x. Find previous option. |
| 677 | size_t end_mark = m->bash_line.length() - m->bash_cur.length() - 1; | 647 | size_t end_mark = m->bash_line.length() - m->bash_cur.length() - 1; |
| 678 | char before_cur = m->bash_line.at(end_mark); | 648 | char before_cur = m->bash_line.at(end_mark); |
| 679 | if (before_cur == '=') { | 649 | if (before_cur == '=') { |
| 680 | size_t space = m->bash_line.find_last_of(' ', end_mark); | 650 | size_t space = m->bash_line.find_last_of(' ', end_mark); |
| 681 | if (space != std::string::npos) { | 651 | if (space != std::string::npos) { |
| 682 | - std::string candidate = | ||
| 683 | - m->bash_line.substr(space + 1, end_mark - space - 1); | 652 | + std::string candidate = m->bash_line.substr(space + 1, end_mark - space - 1); |
| 684 | if ((candidate.length() > 2) && (candidate.at(0) == '-') && | 653 | if ((candidate.length() > 2) && (candidate.at(0) == '-') && |
| 685 | (candidate.at(1) == '-')) { | 654 | (candidate.at(1) == '-')) { |
| 686 | choice_option = candidate.substr(2, std::string::npos); | 655 | choice_option = candidate.substr(2, std::string::npos); |
| @@ -695,8 +664,7 @@ QPDFArgParser::handleCompletion() | @@ -695,8 +664,7 @@ QPDFArgParser::handleCompletion() | ||
| 695 | insertCompletions(*m->option_table, choice_option, extra_prefix); | 664 | insertCompletions(*m->option_table, choice_option, extra_prefix); |
| 696 | if (m->argc == 1) { | 665 | if (m->argc == 1) { |
| 697 | // Help options are valid only by themselves. | 666 | // Help options are valid only by themselves. |
| 698 | - insertCompletions( | ||
| 699 | - m->help_option_table, choice_option, extra_prefix); | 667 | + insertCompletions(m->help_option_table, choice_option, extra_prefix); |
| 700 | } | 668 | } |
| 701 | } | 669 | } |
| 702 | std::string prefix = extra_prefix + m->bash_cur; | 670 | std::string prefix = extra_prefix + m->bash_cur; |
| @@ -716,24 +684,19 @@ QPDFArgParser::addHelpFooter(std::string const& text) | @@ -716,24 +684,19 @@ QPDFArgParser::addHelpFooter(std::string const& text) | ||
| 716 | 684 | ||
| 717 | void | 685 | void |
| 718 | QPDFArgParser::addHelpTopic( | 686 | QPDFArgParser::addHelpTopic( |
| 719 | - std::string const& topic, | ||
| 720 | - std::string const& short_text, | ||
| 721 | - std::string const& long_text) | 687 | + std::string const& topic, std::string const& short_text, std::string const& long_text) |
| 722 | { | 688 | { |
| 723 | if (topic == "all") { | 689 | if (topic == "all") { |
| 724 | QTC::TC("libtests", "QPDFArgParser add reserved help topic"); | 690 | QTC::TC("libtests", "QPDFArgParser add reserved help topic"); |
| 725 | - throw std::logic_error( | ||
| 726 | - "QPDFArgParser: can't register reserved help topic " + topic); | 691 | + throw std::logic_error("QPDFArgParser: can't register reserved help topic " + topic); |
| 727 | } | 692 | } |
| 728 | if (!((topic.length() > 0) && (topic.at(0) != '-'))) { | 693 | if (!((topic.length() > 0) && (topic.at(0) != '-'))) { |
| 729 | QTC::TC("libtests", "QPDFArgParser bad topic for help"); | 694 | QTC::TC("libtests", "QPDFArgParser bad topic for help"); |
| 730 | - throw std::logic_error( | ||
| 731 | - "QPDFArgParser: help topics must not start with -"); | 695 | + throw std::logic_error("QPDFArgParser: help topics must not start with -"); |
| 732 | } | 696 | } |
| 733 | if (m->help_topics.count(topic)) { | 697 | if (m->help_topics.count(topic)) { |
| 734 | QTC::TC("libtests", "QPDFArgParser add existing topic"); | 698 | QTC::TC("libtests", "QPDFArgParser add existing topic"); |
| 735 | - throw std::logic_error( | ||
| 736 | - "QPDFArgParser: topic " + topic + " has already been added"); | 699 | + throw std::logic_error("QPDFArgParser: topic " + topic + " has already been added"); |
| 737 | } | 700 | } |
| 738 | 701 | ||
| 739 | m->help_topics[topic] = HelpTopic(short_text, long_text); | 702 | m->help_topics[topic] = HelpTopic(short_text, long_text); |
| @@ -747,23 +710,20 @@ QPDFArgParser::addOptionHelp( | @@ -747,23 +710,20 @@ QPDFArgParser::addOptionHelp( | ||
| 747 | std::string const& short_text, | 710 | std::string const& short_text, |
| 748 | std::string const& long_text) | 711 | std::string const& long_text) |
| 749 | { | 712 | { |
| 750 | - if (!((option_name.length() > 2) && (option_name.at(0) == '-') && | ||
| 751 | - (option_name.at(1) == '-'))) { | 713 | + if (!((option_name.length() > 2) && (option_name.at(0) == '-') && (option_name.at(1) == '-'))) { |
| 752 | QTC::TC("libtests", "QPDFArgParser bad option for help"); | 714 | QTC::TC("libtests", "QPDFArgParser bad option for help"); |
| 753 | - throw std::logic_error( | ||
| 754 | - "QPDFArgParser: options for help must start with --"); | 715 | + throw std::logic_error("QPDFArgParser: options for help must start with --"); |
| 755 | } | 716 | } |
| 756 | if (m->option_help.count(option_name)) { | 717 | if (m->option_help.count(option_name)) { |
| 757 | QTC::TC("libtests", "QPDFArgParser duplicate option help"); | 718 | QTC::TC("libtests", "QPDFArgParser duplicate option help"); |
| 758 | - throw std::logic_error( | ||
| 759 | - "QPDFArgParser: option " + option_name + " already has help"); | 719 | + throw std::logic_error("QPDFArgParser: option " + option_name + " already has help"); |
| 760 | } | 720 | } |
| 761 | auto ht = m->help_topics.find(topic); | 721 | auto ht = m->help_topics.find(topic); |
| 762 | if (ht == m->help_topics.end()) { | 722 | if (ht == m->help_topics.end()) { |
| 763 | QTC::TC("libtests", "QPDFArgParser add to unknown topic"); | 723 | QTC::TC("libtests", "QPDFArgParser add to unknown topic"); |
| 764 | throw std::logic_error( | 724 | throw std::logic_error( |
| 765 | - "QPDFArgParser: unable to add option " + option_name + | ||
| 766 | - " to unknown help topic " + topic); | 725 | + "QPDFArgParser: unable to add option " + option_name + " to unknown help topic " + |
| 726 | + topic); | ||
| 767 | } | 727 | } |
| 768 | m->option_help[option_name] = HelpTopic(short_text, long_text); | 728 | m->option_help[option_name] = HelpTopic(short_text, long_text); |
| 769 | ht->second.options.insert(option_name); | 729 | ht->second.options.insert(option_name); |
| @@ -773,12 +733,9 @@ QPDFArgParser::addOptionHelp( | @@ -773,12 +733,9 @@ QPDFArgParser::addOptionHelp( | ||
| 773 | void | 733 | void |
| 774 | QPDFArgParser::getTopHelp(std::ostringstream& msg) | 734 | QPDFArgParser::getTopHelp(std::ostringstream& msg) |
| 775 | { | 735 | { |
| 776 | - msg << "Run \"" << m->whoami << " --help=topic\" for help on a topic." | ||
| 777 | - << std::endl | ||
| 778 | - << "Run \"" << m->whoami << " --help=--option\" for help on an option." | ||
| 779 | - << std::endl | ||
| 780 | - << "Run \"" << m->whoami << " --help=all\" to see all available help." | ||
| 781 | - << std::endl | 736 | + msg << "Run \"" << m->whoami << " --help=topic\" for help on a topic." << std::endl |
| 737 | + << "Run \"" << m->whoami << " --help=--option\" for help on an option." << std::endl | ||
| 738 | + << "Run \"" << m->whoami << " --help=all\" to see all available help." << std::endl | ||
| 782 | << std::endl | 739 | << std::endl |
| 783 | << "Topics:" << std::endl; | 740 | << "Topics:" << std::endl; |
| 784 | for (auto const& i: m->help_topics) { | 741 | for (auto const& i: m->help_topics) { |
| @@ -794,8 +751,7 @@ QPDFArgParser::getAllHelp(std::ostringstream& msg) | @@ -794,8 +751,7 @@ QPDFArgParser::getAllHelp(std::ostringstream& msg) | ||
| 794 | for (auto const& i: topics) { | 751 | for (auto const& i: topics) { |
| 795 | auto const& topic = i.first; | 752 | auto const& topic = i.first; |
| 796 | msg << std::endl | 753 | msg << std::endl |
| 797 | - << "== " << topic << " (" << i.second.short_text | ||
| 798 | - << ") ==" << std::endl | 754 | + << "== " << topic << " (" << i.second.short_text << ") ==" << std::endl |
| 799 | << std::endl; | 755 | << std::endl; |
| 800 | getTopicHelp(topic, i.second, msg); | 756 | getTopicHelp(topic, i.second, msg); |
| 801 | } | 757 | } |
| @@ -806,8 +762,7 @@ QPDFArgParser::getAllHelp(std::ostringstream& msg) | @@ -806,8 +762,7 @@ QPDFArgParser::getAllHelp(std::ostringstream& msg) | ||
| 806 | } | 762 | } |
| 807 | 763 | ||
| 808 | void | 764 | void |
| 809 | -QPDFArgParser::getTopicHelp( | ||
| 810 | - std::string const& name, HelpTopic const& ht, std::ostringstream& msg) | 765 | +QPDFArgParser::getTopicHelp(std::string const& name, HelpTopic const& ht, std::ostringstream& msg) |
| 811 | { | 766 | { |
| 812 | if (ht.long_text.empty()) { | 767 | if (ht.long_text.empty()) { |
| 813 | msg << ht.short_text << std::endl; | 768 | msg << ht.short_text << std::endl; |
| @@ -817,8 +772,7 @@ QPDFArgParser::getTopicHelp( | @@ -817,8 +772,7 @@ QPDFArgParser::getTopicHelp( | ||
| 817 | if (!ht.options.empty()) { | 772 | if (!ht.options.empty()) { |
| 818 | msg << std::endl << "Related options:" << std::endl; | 773 | msg << std::endl << "Related options:" << std::endl; |
| 819 | for (auto const& i: ht.options) { | 774 | for (auto const& i: ht.options) { |
| 820 | - msg << " " << i << ": " << m->option_help[i].short_text | ||
| 821 | - << std::endl; | 775 | + msg << " " << i << ": " << m->option_help[i].short_text << std::endl; |
| 822 | } | 776 | } |
| 823 | } | 777 | } |
| 824 | } | 778 | } |
libqpdf/QPDFCryptoProvider.cc
| @@ -19,8 +19,7 @@ QPDFCryptoProvider::getImpl() | @@ -19,8 +19,7 @@ QPDFCryptoProvider::getImpl() | ||
| 19 | { | 19 | { |
| 20 | QPDFCryptoProvider& p = getInstance(); | 20 | QPDFCryptoProvider& p = getInstance(); |
| 21 | if (p.m->default_provider.empty()) { | 21 | if (p.m->default_provider.empty()) { |
| 22 | - throw std::logic_error( | ||
| 23 | - "QPDFCryptoProvider::getImpl called with no default provider."); | 22 | + throw std::logic_error("QPDFCryptoProvider::getImpl called with no default provider."); |
| 24 | } | 23 | } |
| 25 | return p.getImpl_internal(p.m->default_provider); | 24 | return p.getImpl_internal(p.m->default_provider); |
| 26 | } | 25 | } |
| @@ -76,8 +75,7 @@ QPDFCryptoProvider::getImpl_internal(std::string const& name) const | @@ -76,8 +75,7 @@ QPDFCryptoProvider::getImpl_internal(std::string const& name) const | ||
| 76 | auto iter = m->providers.find(name); | 75 | auto iter = m->providers.find(name); |
| 77 | if (iter == m->providers.end()) { | 76 | if (iter == m->providers.end()) { |
| 78 | throw std::logic_error( | 77 | throw std::logic_error( |
| 79 | - "QPDFCryptoProvider requested unknown implementation \"" + name + | ||
| 80 | - "\""); | 78 | + "QPDFCryptoProvider requested unknown implementation \"" + name + "\""); |
| 81 | } | 79 | } |
| 82 | return m->providers[name](); | 80 | return m->providers[name](); |
| 83 | } | 81 | } |
libqpdf/QPDFCrypto_gnutls.cc
| @@ -47,8 +47,7 @@ QPDFCrypto_gnutls::MD5_init() | @@ -47,8 +47,7 @@ QPDFCrypto_gnutls::MD5_init() | ||
| 47 | if (code < 0) { | 47 | if (code < 0) { |
| 48 | this->hash_ctx = nullptr; | 48 | this->hash_ctx = nullptr; |
| 49 | throw std::runtime_error( | 49 | throw std::runtime_error( |
| 50 | - std::string("gnutls: MD5 error: ") + | ||
| 51 | - std::string(gnutls_strerror(code))); | 50 | + std::string("gnutls: MD5 error: ") + std::string(gnutls_strerror(code))); |
| 52 | } | 51 | } |
| 53 | } | 52 | } |
| 54 | 53 | ||
| @@ -78,26 +77,22 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) | @@ -78,26 +77,22 @@ QPDFCrypto_gnutls::RC4_init(unsigned char const* key_data, int key_len) | ||
| 78 | { | 77 | { |
| 79 | RC4_finalize(); | 78 | RC4_finalize(); |
| 80 | if (key_len == -1) { | 79 | if (key_len == -1) { |
| 81 | - key_len = | ||
| 82 | - QIntC::to_int(strlen(reinterpret_cast<char const*>(key_data))); | 80 | + key_len = QIntC::to_int(strlen(reinterpret_cast<char const*>(key_data))); |
| 83 | } | 81 | } |
| 84 | gnutls_datum_t key; | 82 | gnutls_datum_t key; |
| 85 | key.data = const_cast<unsigned char*>(key_data); | 83 | key.data = const_cast<unsigned char*>(key_data); |
| 86 | key.size = QIntC::to_uint(key_len); | 84 | key.size = QIntC::to_uint(key_len); |
| 87 | 85 | ||
| 88 | - int code = gnutls_cipher_init( | ||
| 89 | - &this->cipher_ctx, GNUTLS_CIPHER_ARCFOUR_128, &key, nullptr); | 86 | + int code = gnutls_cipher_init(&this->cipher_ctx, GNUTLS_CIPHER_ARCFOUR_128, &key, nullptr); |
| 90 | if (code < 0) { | 87 | if (code < 0) { |
| 91 | this->cipher_ctx = nullptr; | 88 | this->cipher_ctx = nullptr; |
| 92 | throw std::runtime_error( | 89 | throw std::runtime_error( |
| 93 | - std::string("gnutls: RC4 error: ") + | ||
| 94 | - std::string(gnutls_strerror(code))); | 90 | + std::string("gnutls: RC4 error: ") + std::string(gnutls_strerror(code))); |
| 95 | } | 91 | } |
| 96 | } | 92 | } |
| 97 | 93 | ||
| 98 | void | 94 | void |
| 99 | -QPDFCrypto_gnutls::RC4_process( | ||
| 100 | - unsigned char const* in_data, size_t len, unsigned char* out_data) | 95 | +QPDFCrypto_gnutls::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data) |
| 101 | { | 96 | { |
| 102 | gnutls_cipher_encrypt2(this->cipher_ctx, in_data, len, out_data, len); | 97 | gnutls_cipher_encrypt2(this->cipher_ctx, in_data, len, out_data, len); |
| 103 | } | 98 | } |
| @@ -223,29 +218,19 @@ QPDFCrypto_gnutls::rijndael_init( | @@ -223,29 +218,19 @@ QPDFCrypto_gnutls::rijndael_init( | ||
| 223 | if (code < 0) { | 218 | if (code < 0) { |
| 224 | this->cipher_ctx = nullptr; | 219 | this->cipher_ctx = nullptr; |
| 225 | throw std::runtime_error( | 220 | throw std::runtime_error( |
| 226 | - std::string("gnutls: AES error: ") + | ||
| 227 | - std::string(gnutls_strerror(code))); | 221 | + std::string("gnutls: AES error: ") + std::string(gnutls_strerror(code))); |
| 228 | } | 222 | } |
| 229 | } | 223 | } |
| 230 | 224 | ||
| 231 | void | 225 | void |
| 232 | -QPDFCrypto_gnutls::rijndael_process( | ||
| 233 | - unsigned char* in_data, unsigned char* out_data) | 226 | +QPDFCrypto_gnutls::rijndael_process(unsigned char* in_data, unsigned char* out_data) |
| 234 | { | 227 | { |
| 235 | if (this->encrypt) { | 228 | if (this->encrypt) { |
| 236 | gnutls_cipher_encrypt2( | 229 | gnutls_cipher_encrypt2( |
| 237 | - this->cipher_ctx, | ||
| 238 | - in_data, | ||
| 239 | - rijndael_buf_size, | ||
| 240 | - out_data, | ||
| 241 | - rijndael_buf_size); | 230 | + this->cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); |
| 242 | } else { | 231 | } else { |
| 243 | gnutls_cipher_decrypt2( | 232 | gnutls_cipher_decrypt2( |
| 244 | - this->cipher_ctx, | ||
| 245 | - in_data, | ||
| 246 | - rijndael_buf_size, | ||
| 247 | - out_data, | ||
| 248 | - rijndael_buf_size); | 233 | + this->cipher_ctx, in_data, rijndael_buf_size, out_data, rijndael_buf_size); |
| 249 | } | 234 | } |
| 250 | 235 | ||
| 251 | // Gnutls doesn't support AES in ECB (non-CBC) mode, but the | 236 | // Gnutls doesn't support AES in ECB (non-CBC) mode, but the |
| @@ -253,14 +238,8 @@ QPDFCrypto_gnutls::rijndael_process( | @@ -253,14 +238,8 @@ QPDFCrypto_gnutls::rijndael_process( | ||
| 253 | // zeroes each time. We jump through a few hoops here to make this | 238 | // zeroes each time. We jump through a few hoops here to make this |
| 254 | // work. | 239 | // work. |
| 255 | if (!this->cbc_mode) { | 240 | if (!this->cbc_mode) { |
| 256 | - static unsigned char zeroes[16] = { | ||
| 257 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
| 258 | - rijndael_init( | ||
| 259 | - this->encrypt, | ||
| 260 | - this->aes_key_data, | ||
| 261 | - this->aes_key_len, | ||
| 262 | - false, | ||
| 263 | - zeroes); | 241 | + static unsigned char zeroes[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 242 | + rijndael_init(this->encrypt, this->aes_key_data, this->aes_key_len, false, zeroes); | ||
| 264 | } | 243 | } |
| 265 | } | 244 | } |
| 266 | 245 |
libqpdf/QPDFCrypto_native.cc
| @@ -68,8 +68,7 @@ QPDFCrypto_native::RC4_init(unsigned char const* key_data, int key_len) | @@ -68,8 +68,7 @@ QPDFCrypto_native::RC4_init(unsigned char const* key_data, int key_len) | ||
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | void | 70 | void |
| 71 | -QPDFCrypto_native::RC4_process( | ||
| 72 | - unsigned char const* in_data, size_t len, unsigned char* out_data) | 71 | +QPDFCrypto_native::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data) |
| 73 | { | 72 | { |
| 74 | this->rc4->process(in_data, len, out_data); | 73 | this->rc4->process(in_data, len, out_data); |
| 75 | } | 74 | } |
| @@ -112,13 +111,12 @@ QPDFCrypto_native::rijndael_init( | @@ -112,13 +111,12 @@ QPDFCrypto_native::rijndael_init( | ||
| 112 | unsigned char* cbc_block) | 111 | unsigned char* cbc_block) |
| 113 | 112 | ||
| 114 | { | 113 | { |
| 115 | - this->aes_pdf = std::make_shared<AES_PDF_native>( | ||
| 116 | - encrypt, key_data, key_len, cbc_mode, cbc_block); | 114 | + this->aes_pdf = |
| 115 | + std::make_shared<AES_PDF_native>(encrypt, key_data, key_len, cbc_mode, cbc_block); | ||
| 117 | } | 116 | } |
| 118 | 117 | ||
| 119 | void | 118 | void |
| 120 | -QPDFCrypto_native::rijndael_process( | ||
| 121 | - unsigned char* in_data, unsigned char* out_data) | 119 | +QPDFCrypto_native::rijndael_process(unsigned char* in_data, unsigned char* out_data) |
| 122 | { | 120 | { |
| 123 | this->aes_pdf->update(in_data, out_data); | 121 | this->aes_pdf->update(in_data, out_data); |
| 124 | } | 122 | } |
libqpdf/QPDFCrypto_openssl.cc
| @@ -76,8 +76,7 @@ RC4Loader::~RC4Loader() | @@ -76,8 +76,7 @@ RC4Loader::~RC4Loader() | ||
| 76 | static void | 76 | static void |
| 77 | bad_bits(int bits) | 77 | bad_bits(int bits) |
| 78 | { | 78 | { |
| 79 | - throw std::logic_error( | ||
| 80 | - std::string("unsupported key length: ") + std::to_string(bits)); | 79 | + throw std::logic_error(std::string("unsupported key length: ") + std::to_string(bits)); |
| 81 | } | 80 | } |
| 82 | 81 | ||
| 83 | static void | 82 | static void |
| @@ -208,14 +207,11 @@ QPDFCrypto_openssl::RC4_init(unsigned char const* key_data, int key_len) | @@ -208,14 +207,11 @@ QPDFCrypto_openssl::RC4_init(unsigned char const* key_data, int key_len) | ||
| 208 | #endif | 207 | #endif |
| 209 | check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx)); | 208 | check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx)); |
| 210 | if (key_len == -1) { | 209 | if (key_len == -1) { |
| 211 | - key_len = | ||
| 212 | - QIntC::to_int(strlen(reinterpret_cast<const char*>(key_data))); | 210 | + key_len = QIntC::to_int(strlen(reinterpret_cast<const char*>(key_data))); |
| 213 | } | 211 | } |
| 214 | - check_openssl( | ||
| 215 | - EVP_EncryptInit_ex(cipher_ctx, rc4, nullptr, nullptr, nullptr)); | 212 | + check_openssl(EVP_EncryptInit_ex(cipher_ctx, rc4, nullptr, nullptr, nullptr)); |
| 216 | check_openssl(EVP_CIPHER_CTX_set_key_length(cipher_ctx, key_len)); | 213 | check_openssl(EVP_CIPHER_CTX_set_key_length(cipher_ctx, key_len)); |
| 217 | - check_openssl( | ||
| 218 | - EVP_EncryptInit_ex(cipher_ctx, nullptr, nullptr, key_data, nullptr)); | 214 | + check_openssl(EVP_EncryptInit_ex(cipher_ctx, nullptr, nullptr, key_data, nullptr)); |
| 219 | } | 215 | } |
| 220 | 216 | ||
| 221 | void | 217 | void |
| @@ -242,23 +238,19 @@ QPDFCrypto_openssl::rijndael_init( | @@ -242,23 +238,19 @@ QPDFCrypto_openssl::rijndael_init( | ||
| 242 | check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx)); | 238 | check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx)); |
| 243 | check_openssl( | 239 | check_openssl( |
| 244 | // line-break | 240 | // line-break |
| 245 | - EVP_CipherInit_ex( | ||
| 246 | - cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt)); | 241 | + EVP_CipherInit_ex(cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt)); |
| 247 | check_openssl(EVP_CIPHER_CTX_set_padding(cipher_ctx, 0)); | 242 | check_openssl(EVP_CIPHER_CTX_set_padding(cipher_ctx, 0)); |
| 248 | } | 243 | } |
| 249 | 244 | ||
| 250 | void | 245 | void |
| 251 | -QPDFCrypto_openssl::RC4_process( | ||
| 252 | - unsigned char const* in_data, size_t len, unsigned char* out_data) | 246 | +QPDFCrypto_openssl::RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data) |
| 253 | { | 247 | { |
| 254 | int out_len = static_cast<int>(len); | 248 | int out_len = static_cast<int>(len); |
| 255 | - check_openssl( | ||
| 256 | - EVP_EncryptUpdate(cipher_ctx, out_data, &out_len, in_data, out_len)); | 249 | + check_openssl(EVP_EncryptUpdate(cipher_ctx, out_data, &out_len, in_data, out_len)); |
| 257 | } | 250 | } |
| 258 | 251 | ||
| 259 | void | 252 | void |
| 260 | -QPDFCrypto_openssl::rijndael_process( | ||
| 261 | - unsigned char* in_data, unsigned char* out_data) | 253 | +QPDFCrypto_openssl::rijndael_process(unsigned char* in_data, unsigned char* out_data) |
| 262 | { | 254 | { |
| 263 | int len = QPDFCryptoImpl::rijndael_buf_size; | 255 | int len = QPDFCryptoImpl::rijndael_buf_size; |
| 264 | check_openssl(EVP_CipherUpdate(cipher_ctx, out_data, &len, in_data, len)); | 256 | check_openssl(EVP_CipherUpdate(cipher_ctx, out_data, &len, in_data, len)); |
libqpdf/QPDFEFStreamObjectHelper.cc
| @@ -24,13 +24,12 @@ QPDFEFStreamObjectHelper::getParam(std::string const& pkey) | @@ -24,13 +24,12 @@ QPDFEFStreamObjectHelper::getParam(std::string const& pkey) | ||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | void | 26 | void |
| 27 | -QPDFEFStreamObjectHelper::setParam( | ||
| 28 | - std::string const& pkey, QPDFObjectHandle const& pval) | 27 | +QPDFEFStreamObjectHelper::setParam(std::string const& pkey, QPDFObjectHandle const& pval) |
| 29 | { | 28 | { |
| 30 | auto params = this->oh.getDict().getKey("/Params"); | 29 | auto params = this->oh.getDict().getKey("/Params"); |
| 31 | if (!params.isDictionary()) { | 30 | if (!params.isDictionary()) { |
| 32 | - params = this->oh.getDict().replaceKeyAndGetNew( | ||
| 33 | - "/Params", QPDFObjectHandle::newDictionary()); | 31 | + params = |
| 32 | + this->oh.getDict().replaceKeyAndGetNew("/Params", QPDFObjectHandle::newDictionary()); | ||
| 34 | } | 33 | } |
| 35 | params.replaceKey(pkey, pval); | 34 | params.replaceKey(pkey, pval); |
| 36 | } | 35 | } |
| @@ -89,8 +88,7 @@ QPDFEFStreamObjectHelper::getChecksum() | @@ -89,8 +88,7 @@ QPDFEFStreamObjectHelper::getChecksum() | ||
| 89 | } | 88 | } |
| 90 | 89 | ||
| 91 | QPDFEFStreamObjectHelper | 90 | QPDFEFStreamObjectHelper |
| 92 | -QPDFEFStreamObjectHelper::createEFStream( | ||
| 93 | - QPDF& qpdf, std::shared_ptr<Buffer> data) | 91 | +QPDFEFStreamObjectHelper::createEFStream(QPDF& qpdf, std::shared_ptr<Buffer> data) |
| 94 | { | 92 | { |
| 95 | return newFromStream(qpdf.newStream(data)); | 93 | return newFromStream(qpdf.newStream(data)); |
| 96 | } | 94 | } |
| @@ -102,12 +100,10 @@ QPDFEFStreamObjectHelper::createEFStream(QPDF& qpdf, std::string const& data) | @@ -102,12 +100,10 @@ QPDFEFStreamObjectHelper::createEFStream(QPDF& qpdf, std::string const& data) | ||
| 102 | } | 100 | } |
| 103 | 101 | ||
| 104 | QPDFEFStreamObjectHelper | 102 | QPDFEFStreamObjectHelper |
| 105 | -QPDFEFStreamObjectHelper::createEFStream( | ||
| 106 | - QPDF& qpdf, std::function<void(Pipeline*)> provider) | 103 | +QPDFEFStreamObjectHelper::createEFStream(QPDF& qpdf, std::function<void(Pipeline*)> provider) |
| 107 | { | 104 | { |
| 108 | auto stream = qpdf.newStream(); | 105 | auto stream = qpdf.newStream(); |
| 109 | - stream.replaceStreamData( | ||
| 110 | - provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | 106 | + stream.replaceStreamData(provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 111 | return newFromStream(stream); | 107 | return newFromStream(stream); |
| 112 | } | 108 | } |
| 113 | 109 | ||
| @@ -128,8 +124,7 @@ QPDFEFStreamObjectHelper::setModDate(std::string const& date) | @@ -128,8 +124,7 @@ QPDFEFStreamObjectHelper::setModDate(std::string const& date) | ||
| 128 | QPDFEFStreamObjectHelper& | 124 | QPDFEFStreamObjectHelper& |
| 129 | QPDFEFStreamObjectHelper::setSubtype(std::string const& subtype) | 125 | QPDFEFStreamObjectHelper::setSubtype(std::string const& subtype) |
| 130 | { | 126 | { |
| 131 | - this->oh.getDict().replaceKey( | ||
| 132 | - "/Subtype", QPDFObjectHandle::newName("/" + subtype)); | 127 | + this->oh.getDict().replaceKey("/Subtype", QPDFObjectHandle::newName("/" + subtype)); |
| 133 | return *this; | 128 | return *this; |
| 134 | } | 129 | } |
| 135 | 130 | ||
| @@ -137,22 +132,18 @@ QPDFEFStreamObjectHelper | @@ -137,22 +132,18 @@ QPDFEFStreamObjectHelper | ||
| 137 | QPDFEFStreamObjectHelper::newFromStream(QPDFObjectHandle stream) | 132 | QPDFEFStreamObjectHelper::newFromStream(QPDFObjectHandle stream) |
| 138 | { | 133 | { |
| 139 | QPDFEFStreamObjectHelper result(stream); | 134 | QPDFEFStreamObjectHelper result(stream); |
| 140 | - stream.getDict().replaceKey( | ||
| 141 | - "/Type", QPDFObjectHandle::newName("/EmbeddedFile")); | 135 | + stream.getDict().replaceKey("/Type", QPDFObjectHandle::newName("/EmbeddedFile")); |
| 142 | Pl_Discard discard; | 136 | Pl_Discard discard; |
| 143 | // The PDF spec specifies use of MD5 here and notes that it is not | 137 | // The PDF spec specifies use of MD5 here and notes that it is not |
| 144 | // to be used for security. MD5 is known to be insecure. | 138 | // to be used for security. MD5 is known to be insecure. |
| 145 | Pl_MD5 md5("EF md5", &discard); | 139 | Pl_MD5 md5("EF md5", &discard); |
| 146 | Pl_Count count("EF size", &md5); | 140 | Pl_Count count("EF size", &md5); |
| 147 | if (!stream.pipeStreamData(&count, nullptr, 0, qpdf_dl_all)) { | 141 | if (!stream.pipeStreamData(&count, nullptr, 0, qpdf_dl_all)) { |
| 148 | - stream.warnIfPossible( | ||
| 149 | - "unable to get stream data for new embedded file stream"); | 142 | + stream.warnIfPossible("unable to get stream data for new embedded file stream"); |
| 150 | } else { | 143 | } else { |
| 144 | + result.setParam("/Size", QPDFObjectHandle::newInteger(count.getCount())); | ||
| 151 | result.setParam( | 145 | result.setParam( |
| 152 | - "/Size", QPDFObjectHandle::newInteger(count.getCount())); | ||
| 153 | - result.setParam( | ||
| 154 | - "/CheckSum", | ||
| 155 | - QPDFObjectHandle::newString(QUtil::hex_decode(md5.getHexDigest()))); | 146 | + "/CheckSum", QPDFObjectHandle::newString(QUtil::hex_decode(md5.getHexDigest()))); |
| 156 | } | 147 | } |
| 157 | return result; | 148 | return result; |
| 158 | } | 149 | } |
libqpdf/QPDFEmbeddedFileDocumentHelper.cc
| @@ -40,8 +40,7 @@ QPDFEmbeddedFileDocumentHelper::QPDFEmbeddedFileDocumentHelper(QPDF& qpdf) : | @@ -40,8 +40,7 @@ QPDFEmbeddedFileDocumentHelper::QPDFEmbeddedFileDocumentHelper(QPDF& qpdf) : | ||
| 40 | if (names.isDictionary()) { | 40 | if (names.isDictionary()) { |
| 41 | auto embedded_files = names.getKey("/EmbeddedFiles"); | 41 | auto embedded_files = names.getKey("/EmbeddedFiles"); |
| 42 | if (embedded_files.isDictionary()) { | 42 | if (embedded_files.isDictionary()) { |
| 43 | - m->embedded_files = std::make_shared<QPDFNameTreeObjectHelper>( | ||
| 44 | - embedded_files, qpdf); | 43 | + m->embedded_files = std::make_shared<QPDFNameTreeObjectHelper>(embedded_files, qpdf); |
| 45 | } | 44 | } |
| 46 | } | 45 | } |
| 47 | } | 46 | } |
| @@ -61,8 +60,7 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles() | @@ -61,8 +60,7 @@ QPDFEmbeddedFileDocumentHelper::initEmbeddedFiles() | ||
| 61 | auto root = qpdf.getRoot(); | 60 | auto root = qpdf.getRoot(); |
| 62 | auto names = root.getKey("/Names"); | 61 | auto names = root.getKey("/Names"); |
| 63 | if (!names.isDictionary()) { | 62 | if (!names.isDictionary()) { |
| 64 | - names = root.replaceKeyAndGetNew( | ||
| 65 | - "/Names", QPDFObjectHandle::newDictionary()); | 63 | + names = root.replaceKeyAndGetNew("/Names", QPDFObjectHandle::newDictionary()); |
| 66 | } | 64 | } |
| 67 | auto embedded_files = names.getKey("/EmbeddedFiles"); | 65 | auto embedded_files = names.getKey("/EmbeddedFiles"); |
| 68 | if (!embedded_files.isDictionary()) { | 66 | if (!embedded_files.isDictionary()) { |
| @@ -91,8 +89,7 @@ QPDFEmbeddedFileDocumentHelper::getEmbeddedFiles() | @@ -91,8 +89,7 @@ QPDFEmbeddedFileDocumentHelper::getEmbeddedFiles() | ||
| 91 | std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> result; | 89 | std::map<std::string, std::shared_ptr<QPDFFileSpecObjectHelper>> result; |
| 92 | if (m->embedded_files) { | 90 | if (m->embedded_files) { |
| 93 | for (auto const& i: *(m->embedded_files)) { | 91 | for (auto const& i: *(m->embedded_files)) { |
| 94 | - result[i.first] = | ||
| 95 | - std::make_shared<QPDFFileSpecObjectHelper>(i.second); | 92 | + result[i.first] = std::make_shared<QPDFFileSpecObjectHelper>(i.second); |
| 96 | } | 93 | } |
| 97 | } | 94 | } |
| 98 | return result; | 95 | return result; |
libqpdf/QPDFFileSpecObjectHelper.cc
| @@ -19,8 +19,7 @@ QPDFFileSpecObjectHelper::QPDFFileSpecObjectHelper(QPDFObjectHandle oh) : | @@ -19,8 +19,7 @@ QPDFFileSpecObjectHelper::QPDFFileSpecObjectHelper(QPDFObjectHandle oh) : | ||
| 19 | } | 19 | } |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | -static std::vector<std::string> name_keys = { | ||
| 23 | - "/UF", "/F", "/Unix", "/DOS", "/Mac"}; | 22 | +static std::vector<std::string> name_keys = {"/UF", "/F", "/Unix", "/DOS", "/Mac"}; |
| 24 | 23 | ||
| 25 | std::string | 24 | std::string |
| 26 | QPDFFileSpecObjectHelper::getDescription() | 25 | QPDFFileSpecObjectHelper::getDescription() |
| @@ -90,8 +89,7 @@ QPDFFileSpecObjectHelper::createFileSpec( | @@ -90,8 +89,7 @@ QPDFFileSpecObjectHelper::createFileSpec( | ||
| 90 | return createFileSpec( | 89 | return createFileSpec( |
| 91 | qpdf, | 90 | qpdf, |
| 92 | filename, | 91 | filename, |
| 93 | - QPDFEFStreamObjectHelper::createEFStream( | ||
| 94 | - qpdf, QUtil::file_provider(fullpath))); | 92 | + QPDFEFStreamObjectHelper::createEFStream(qpdf, QUtil::file_provider(fullpath))); |
| 95 | } | 93 | } |
| 96 | 94 | ||
| 97 | QPDFFileSpecObjectHelper | 95 | QPDFFileSpecObjectHelper |
libqpdf/QPDFFormFieldObjectHelper.cc
| @@ -76,9 +76,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name) | @@ -76,9 +76,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name) | ||
| 76 | node = node.getKey("/Parent"); | 76 | node = node.getKey("/Parent"); |
| 77 | result = node.getKey(name); | 77 | result = node.getKey(name); |
| 78 | if (!result.isNull()) { | 78 | if (!result.isNull()) { |
| 79 | - QTC::TC( | ||
| 80 | - "qpdf", | ||
| 81 | - "QPDFFormFieldObjectHelper non-trivial inheritance"); | 79 | + QTC::TC("qpdf", "QPDFFormFieldObjectHelper non-trivial inheritance"); |
| 82 | return result; | 80 | return result; |
| 83 | } | 81 | } |
| 84 | } | 82 | } |
| @@ -87,8 +85,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name) | @@ -87,8 +85,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name) | ||
| 87 | } | 85 | } |
| 88 | 86 | ||
| 89 | std::string | 87 | std::string |
| 90 | -QPDFFormFieldObjectHelper::getInheritableFieldValueAsString( | ||
| 91 | - std::string const& name) | 88 | +QPDFFormFieldObjectHelper::getInheritableFieldValueAsString(std::string const& name) |
| 92 | { | 89 | { |
| 93 | QPDFObjectHandle fv = getInheritableFieldValue(name); | 90 | QPDFObjectHandle fv = getInheritableFieldValue(name); |
| 94 | std::string result; | 91 | std::string result; |
| @@ -99,8 +96,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValueAsString( | @@ -99,8 +96,7 @@ QPDFFormFieldObjectHelper::getInheritableFieldValueAsString( | ||
| 99 | } | 96 | } |
| 100 | 97 | ||
| 101 | std::string | 98 | std::string |
| 102 | -QPDFFormFieldObjectHelper::getInheritableFieldValueAsName( | ||
| 103 | - std::string const& name) | 99 | +QPDFFormFieldObjectHelper::getInheritableFieldValueAsName(std::string const& name) |
| 104 | { | 100 | { |
| 105 | QPDFObjectHandle fv = getInheritableFieldValue(name); | 101 | QPDFObjectHandle fv = getInheritableFieldValue(name); |
| 106 | std::string result; | 102 | std::string result; |
| @@ -125,9 +121,7 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName() | @@ -125,9 +121,7 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName() | ||
| 125 | while (!node.isNull() && seen.add(node)) { | 121 | while (!node.isNull() && seen.add(node)) { |
| 126 | if (node.getKey("/T").isString()) { | 122 | if (node.getKey("/T").isString()) { |
| 127 | if (!result.empty()) { | 123 | if (!result.empty()) { |
| 128 | - QTC::TC( | ||
| 129 | - "qpdf", | ||
| 130 | - "QPDFFormFieldObjectHelper non-trivial qualified name"); | 124 | + QTC::TC("qpdf", "QPDFFormFieldObjectHelper non-trivial qualified name"); |
| 131 | result = "." + result; | 125 | result = "." + result; |
| 132 | } | 126 | } |
| 133 | result = node.getKey("/T").getUTF8Value() + result; | 127 | result = node.getKey("/T").getUTF8Value() + result; |
| @@ -210,10 +204,7 @@ QPDFFormFieldObjectHelper::getDefaultAppearance() | @@ -210,10 +204,7 @@ QPDFFormFieldObjectHelper::getDefaultAppearance() | ||
| 210 | } | 204 | } |
| 211 | std::string result; | 205 | std::string result; |
| 212 | if (value.isString()) { | 206 | if (value.isString()) { |
| 213 | - QTC::TC( | ||
| 214 | - "qpdf", | ||
| 215 | - "QPDFFormFieldObjectHelper DA present", | ||
| 216 | - looked_in_acroform ? 0 : 1); | 207 | + QTC::TC("qpdf", "QPDFFormFieldObjectHelper DA present", looked_in_acroform ? 0 : 1); |
| 217 | result = value.getUTF8Value(); | 208 | result = value.getUTF8Value(); |
| 218 | } | 209 | } |
| 219 | return result; | 210 | return result; |
| @@ -230,10 +221,7 @@ QPDFFormFieldObjectHelper::getQuadding() | @@ -230,10 +221,7 @@ QPDFFormFieldObjectHelper::getQuadding() | ||
| 230 | } | 221 | } |
| 231 | int result = 0; | 222 | int result = 0; |
| 232 | if (fv.isInteger()) { | 223 | if (fv.isInteger()) { |
| 233 | - QTC::TC( | ||
| 234 | - "qpdf", | ||
| 235 | - "QPDFFormFieldObjectHelper Q present", | ||
| 236 | - looked_in_acroform ? 0 : 1); | 224 | + QTC::TC("qpdf", "QPDFFormFieldObjectHelper Q present", looked_in_acroform ? 0 : 1); |
| 237 | result = QIntC::to_int(fv.getIntValue()); | 225 | result = QIntC::to_int(fv.getIntValue()); |
| 238 | } | 226 | } |
| 239 | return result; | 227 | return result; |
| @@ -255,25 +243,19 @@ QPDFFormFieldObjectHelper::isText() | @@ -255,25 +243,19 @@ QPDFFormFieldObjectHelper::isText() | ||
| 255 | bool | 243 | bool |
| 256 | QPDFFormFieldObjectHelper::isCheckbox() | 244 | QPDFFormFieldObjectHelper::isCheckbox() |
| 257 | { | 245 | { |
| 258 | - return ( | ||
| 259 | - (getFieldType() == "/Btn") && | ||
| 260 | - ((getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0)); | 246 | + return ((getFieldType() == "/Btn") && ((getFlags() & (ff_btn_radio | ff_btn_pushbutton)) == 0)); |
| 261 | } | 247 | } |
| 262 | 248 | ||
| 263 | bool | 249 | bool |
| 264 | QPDFFormFieldObjectHelper::isRadioButton() | 250 | QPDFFormFieldObjectHelper::isRadioButton() |
| 265 | { | 251 | { |
| 266 | - return ( | ||
| 267 | - (getFieldType() == "/Btn") && | ||
| 268 | - ((getFlags() & ff_btn_radio) == ff_btn_radio)); | 252 | + return ((getFieldType() == "/Btn") && ((getFlags() & ff_btn_radio) == ff_btn_radio)); |
| 269 | } | 253 | } |
| 270 | 254 | ||
| 271 | bool | 255 | bool |
| 272 | QPDFFormFieldObjectHelper::isPushbutton() | 256 | QPDFFormFieldObjectHelper::isPushbutton() |
| 273 | { | 257 | { |
| 274 | - return ( | ||
| 275 | - (getFieldType() == "/Btn") && | ||
| 276 | - ((getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton)); | 258 | + return ((getFieldType() == "/Btn") && ((getFlags() & ff_btn_pushbutton) == ff_btn_pushbutton)); |
| 277 | } | 259 | } |
| 278 | 260 | ||
| 279 | bool | 261 | bool |
| @@ -303,15 +285,13 @@ QPDFFormFieldObjectHelper::getChoices() | @@ -303,15 +285,13 @@ QPDFFormFieldObjectHelper::getChoices() | ||
| 303 | } | 285 | } |
| 304 | 286 | ||
| 305 | void | 287 | void |
| 306 | -QPDFFormFieldObjectHelper::setFieldAttribute( | ||
| 307 | - std::string const& key, QPDFObjectHandle value) | 288 | +QPDFFormFieldObjectHelper::setFieldAttribute(std::string const& key, QPDFObjectHandle value) |
| 308 | { | 289 | { |
| 309 | this->oh.replaceKey(key, value); | 290 | this->oh.replaceKey(key, value); |
| 310 | } | 291 | } |
| 311 | 292 | ||
| 312 | void | 293 | void |
| 313 | -QPDFFormFieldObjectHelper::setFieldAttribute( | ||
| 314 | - std::string const& key, std::string const& utf8_value) | 294 | +QPDFFormFieldObjectHelper::setFieldAttribute(std::string const& key, std::string const& utf8_value) |
| 315 | { | 295 | { |
| 316 | this->oh.replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value)); | 296 | this->oh.replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value)); |
| 317 | } | 297 | } |
| @@ -330,41 +310,36 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances) | @@ -330,41 +310,36 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances) | ||
| 330 | } | 310 | } |
| 331 | } | 311 | } |
| 332 | if (!okay) { | 312 | if (!okay) { |
| 333 | - this->oh.warnIfPossible( | ||
| 334 | - "ignoring attempt to set a checkbox field to a" | ||
| 335 | - " value of other than /Yes or /Off"); | 313 | + this->oh.warnIfPossible("ignoring attempt to set a checkbox field to a" |
| 314 | + " value of other than /Yes or /Off"); | ||
| 336 | } | 315 | } |
| 337 | } else if (isRadioButton()) { | 316 | } else if (isRadioButton()) { |
| 338 | if (value.isName()) { | 317 | if (value.isName()) { |
| 339 | setRadioButtonValue(value); | 318 | setRadioButtonValue(value); |
| 340 | } else { | 319 | } else { |
| 341 | - this->oh.warnIfPossible( | ||
| 342 | - "ignoring attempt to set a radio button field to" | ||
| 343 | - " an object that is not a name"); | 320 | + this->oh.warnIfPossible("ignoring attempt to set a radio button field to" |
| 321 | + " an object that is not a name"); | ||
| 344 | } | 322 | } |
| 345 | } else if (isPushbutton()) { | 323 | } else if (isPushbutton()) { |
| 346 | - this->oh.warnIfPossible( | ||
| 347 | - "ignoring attempt set the value of a pushbutton field"); | 324 | + this->oh.warnIfPossible("ignoring attempt set the value of a pushbutton field"); |
| 348 | } | 325 | } |
| 349 | return; | 326 | return; |
| 350 | } | 327 | } |
| 351 | if (value.isString()) { | 328 | if (value.isString()) { |
| 352 | - setFieldAttribute( | ||
| 353 | - "/V", QPDFObjectHandle::newUnicodeString(value.getUTF8Value())); | 329 | + setFieldAttribute("/V", QPDFObjectHandle::newUnicodeString(value.getUTF8Value())); |
| 354 | } else { | 330 | } else { |
| 355 | setFieldAttribute("/V", value); | 331 | setFieldAttribute("/V", value); |
| 356 | } | 332 | } |
| 357 | if (need_appearances) { | 333 | if (need_appearances) { |
| 358 | - QPDF& qpdf = this->oh.getQPDF( | ||
| 359 | - "QPDFFormFieldObjectHelper::setV called with need_appearances = " | ||
| 360 | - "true on an object that is not associated with an owning QPDF"); | 334 | + QPDF& qpdf = |
| 335 | + this->oh.getQPDF("QPDFFormFieldObjectHelper::setV called with need_appearances = " | ||
| 336 | + "true on an object that is not associated with an owning QPDF"); | ||
| 361 | QPDFAcroFormDocumentHelper(qpdf).setNeedAppearances(true); | 337 | QPDFAcroFormDocumentHelper(qpdf).setNeedAppearances(true); |
| 362 | } | 338 | } |
| 363 | } | 339 | } |
| 364 | 340 | ||
| 365 | void | 341 | void |
| 366 | -QPDFFormFieldObjectHelper::setV( | ||
| 367 | - std::string const& utf8_value, bool need_appearances) | 342 | +QPDFFormFieldObjectHelper::setV(std::string const& utf8_value, bool need_appearances) |
| 368 | { | 343 | { |
| 369 | setV(QPDFObjectHandle::newUnicodeString(utf8_value), need_appearances); | 344 | setV(QPDFObjectHandle::newUnicodeString(utf8_value), need_appearances); |
| 370 | } | 345 | } |
| @@ -390,8 +365,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | @@ -390,8 +365,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | ||
| 390 | if (ph.isRadioButton()) { | 365 | if (ph.isRadioButton()) { |
| 391 | // This is most likely one of the individual buttons. Try | 366 | // This is most likely one of the individual buttons. Try |
| 392 | // calling on the parent. | 367 | // calling on the parent. |
| 393 | - QTC::TC( | ||
| 394 | - "qpdf", "QPDFFormFieldObjectHelper set parent radio button"); | 368 | + QTC::TC("qpdf", "QPDFFormFieldObjectHelper set parent radio button"); |
| 395 | ph.setRadioButtonValue(name); | 369 | ph.setRadioButtonValue(name); |
| 396 | return; | 370 | return; |
| 397 | } | 371 | } |
| @@ -419,9 +393,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | @@ -419,9 +393,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | ||
| 419 | QPDFObjectHandle grandkid = grandkids.getArrayItem(j); | 393 | QPDFObjectHandle grandkid = grandkids.getArrayItem(j); |
| 420 | AP = grandkid.getKey("/AP"); | 394 | AP = grandkid.getKey("/AP"); |
| 421 | if (!AP.isNull()) { | 395 | if (!AP.isNull()) { |
| 422 | - QTC::TC( | ||
| 423 | - "qpdf", | ||
| 424 | - "QPDFFormFieldObjectHelper radio button grandkid"); | 396 | + QTC::TC("qpdf", "QPDFFormFieldObjectHelper radio button grandkid"); |
| 425 | annot = grandkid; | 397 | annot = grandkid; |
| 426 | break; | 398 | break; |
| 427 | } | 399 | } |
| @@ -432,8 +404,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | @@ -432,8 +404,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) | ||
| 432 | } | 404 | } |
| 433 | if (!annot.isInitialized()) { | 405 | if (!annot.isInitialized()) { |
| 434 | QTC::TC("qpdf", "QPDFObjectHandle broken radio button"); | 406 | QTC::TC("qpdf", "QPDFObjectHandle broken radio button"); |
| 435 | - this->oh.warnIfPossible( | ||
| 436 | - "unable to set the value of this radio button"); | 407 | + this->oh.warnIfPossible("unable to set the value of this radio button"); |
| 437 | continue; | 408 | continue; |
| 438 | } | 409 | } |
| 439 | if (AP.isDictionary() && AP.getKey("/N").isDictionary() && | 410 | if (AP.isDictionary() && AP.getKey("/N").isDictionary() && |
| @@ -465,9 +436,7 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value) | @@ -465,9 +436,7 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value) | ||
| 465 | QPDFObjectHandle kid = kids.getArrayItem(i); | 436 | QPDFObjectHandle kid = kids.getArrayItem(i); |
| 466 | AP = kid.getKey("/AP"); | 437 | AP = kid.getKey("/AP"); |
| 467 | if (!AP.isNull()) { | 438 | if (!AP.isNull()) { |
| 468 | - QTC::TC( | ||
| 469 | - "qpdf", | ||
| 470 | - "QPDFFormFieldObjectHelper checkbox kid widget"); | 439 | + QTC::TC("qpdf", "QPDFFormFieldObjectHelper checkbox kid widget"); |
| 471 | annot = kid; | 440 | annot = kid; |
| 472 | break; | 441 | break; |
| 473 | } | 442 | } |
| @@ -555,8 +524,7 @@ ValueSetter::handleToken(QPDFTokenizer::Token const& token) | @@ -555,8 +524,7 @@ ValueSetter::handleToken(QPDFTokenizer::Token const& token) | ||
| 555 | break; | 524 | break; |
| 556 | 525 | ||
| 557 | case st_bmc: | 526 | case st_bmc: |
| 558 | - if ((ttype == QPDFTokenizer::tt_space) || | ||
| 559 | - (ttype == QPDFTokenizer::tt_comment)) { | 527 | + if ((ttype == QPDFTokenizer::tt_space) || (ttype == QPDFTokenizer::tt_comment)) { |
| 560 | writeToken(token); | 528 | writeToken(token); |
| 561 | } else { | 529 | } else { |
| 562 | state = st_emc; | 530 | state = st_emc; |
| @@ -642,9 +610,7 @@ ValueSetter::writeAppearance() | @@ -642,9 +610,7 @@ ValueSetter::writeAppearance() | ||
| 642 | } | 610 | } |
| 643 | highlight = true; | 611 | highlight = true; |
| 644 | highlight_idx = found_idx - QIntC::to_size(wanted_first); | 612 | highlight_idx = found_idx - QIntC::to_size(wanted_first); |
| 645 | - for (size_t i = QIntC::to_size(wanted_first); | ||
| 646 | - i <= QIntC::to_size(wanted_last); | ||
| 647 | - ++i) { | 613 | + for (size_t i = QIntC::to_size(wanted_first); i <= QIntC::to_size(wanted_last); ++i) { |
| 648 | lines.push_back(opt.at(i)); | 614 | lines.push_back(opt.at(i)); |
| 649 | } | 615 | } |
| 650 | } else { | 616 | } else { |
| @@ -661,14 +627,12 @@ ValueSetter::writeAppearance() | @@ -661,14 +627,12 @@ ValueSetter::writeAppearance() | ||
| 661 | 627 | ||
| 662 | // Write the lines centered vertically, highlighting if needed | 628 | // Write the lines centered vertically, highlighting if needed |
| 663 | size_t nlines = lines.size(); | 629 | size_t nlines = lines.size(); |
| 664 | - double dy = bbox.ury - | ||
| 665 | - ((bbox.ury - bbox.lly - (static_cast<double>(nlines) * tfh)) / 2.0); | 630 | + double dy = bbox.ury - ((bbox.ury - bbox.lly - (static_cast<double>(nlines) * tfh)) / 2.0); |
| 666 | if (highlight) { | 631 | if (highlight) { |
| 667 | write( | 632 | write( |
| 668 | "q\n0.85 0.85 0.85 rg\n" + QUtil::double_to_string(bbox.llx) + " " + | 633 | "q\n0.85 0.85 0.85 rg\n" + QUtil::double_to_string(bbox.llx) + " " + |
| 669 | QUtil::double_to_string( | 634 | QUtil::double_to_string( |
| 670 | - bbox.lly + dy - | ||
| 671 | - (tfh * (static_cast<double>(highlight_idx + 1)))) + | 635 | + bbox.lly + dy - (tfh * (static_cast<double>(highlight_idx + 1)))) + |
| 672 | " " + QUtil::double_to_string(bbox.urx - bbox.llx) + " " + | 636 | " " + QUtil::double_to_string(bbox.urx - bbox.llx) + " " + |
| 673 | QUtil::double_to_string(tfh) + " re f\nQ\n"); | 637 | QUtil::double_to_string(tfh) + " re f\nQ\n"); |
| 674 | } | 638 | } |
| @@ -681,10 +645,8 @@ ValueSetter::writeAppearance() | @@ -681,10 +645,8 @@ ValueSetter::writeAppearance() | ||
| 681 | // which doesn't seem really worth the effort. | 645 | // which doesn't seem really worth the effort. |
| 682 | if (i == 0) { | 646 | if (i == 0) { |
| 683 | write( | 647 | write( |
| 684 | - QUtil::double_to_string(bbox.llx + static_cast<double>(dx)) + | ||
| 685 | - " " + | ||
| 686 | - QUtil::double_to_string(bbox.lly + static_cast<double>(dy)) + | ||
| 687 | - " Td\n"); | 648 | + QUtil::double_to_string(bbox.llx + static_cast<double>(dx)) + " " + |
| 649 | + QUtil::double_to_string(bbox.lly + static_cast<double>(dy)) + " Td\n"); | ||
| 688 | } else { | 650 | } else { |
| 689 | write("0 " + QUtil::double_to_string(-tfh) + " Td\n"); | 651 | write("0 " + QUtil::double_to_string(-tfh) + " Td\n"); |
| 690 | } | 652 | } |
| @@ -794,8 +756,7 @@ TfFinder::getFontName() | @@ -794,8 +756,7 @@ TfFinder::getFontName() | ||
| 794 | } | 756 | } |
| 795 | 757 | ||
| 796 | QPDFObjectHandle | 758 | QPDFObjectHandle |
| 797 | -QPDFFormFieldObjectHelper::getFontFromResource( | ||
| 798 | - QPDFObjectHandle resources, std::string const& name) | 759 | +QPDFFormFieldObjectHelper::getFontFromResource(QPDFObjectHandle resources, std::string const& name) |
| 799 | { | 760 | { |
| 800 | QPDFObjectHandle result; | 761 | QPDFObjectHandle result; |
| 801 | if (resources.isDictionary() && resources.getKey("/Font").isDictionary() && | 762 | if (resources.isDictionary() && resources.getKey("/Font").isDictionary() && |
| @@ -806,40 +767,34 @@ QPDFFormFieldObjectHelper::getFontFromResource( | @@ -806,40 +767,34 @@ QPDFFormFieldObjectHelper::getFontFromResource( | ||
| 806 | } | 767 | } |
| 807 | 768 | ||
| 808 | void | 769 | void |
| 809 | -QPDFFormFieldObjectHelper::generateTextAppearance( | ||
| 810 | - QPDFAnnotationObjectHelper& aoh) | 770 | +QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& aoh) |
| 811 | { | 771 | { |
| 812 | QPDFObjectHandle AS = aoh.getAppearanceStream("/N"); | 772 | QPDFObjectHandle AS = aoh.getAppearanceStream("/N"); |
| 813 | if (AS.isNull()) { | 773 | if (AS.isNull()) { |
| 814 | QTC::TC("qpdf", "QPDFFormFieldObjectHelper create AS from scratch"); | 774 | QTC::TC("qpdf", "QPDFFormFieldObjectHelper create AS from scratch"); |
| 815 | QPDFObjectHandle::Rectangle rect = aoh.getRect(); | 775 | QPDFObjectHandle::Rectangle rect = aoh.getRect(); |
| 816 | - QPDFObjectHandle::Rectangle bbox( | ||
| 817 | - 0, 0, rect.urx - rect.llx, rect.ury - rect.lly); | ||
| 818 | - QPDFObjectHandle dict = QPDFObjectHandle::parse( | ||
| 819 | - "<< /Resources << /ProcSet [ /PDF /Text ] >>" | ||
| 820 | - " /Type /XObject /Subtype /Form >>"); | 776 | + QPDFObjectHandle::Rectangle bbox(0, 0, rect.urx - rect.llx, rect.ury - rect.lly); |
| 777 | + QPDFObjectHandle dict = | ||
| 778 | + QPDFObjectHandle::parse("<< /Resources << /ProcSet [ /PDF /Text ] >>" | ||
| 779 | + " /Type /XObject /Subtype /Form >>"); | ||
| 821 | dict.replaceKey("/BBox", QPDFObjectHandle::newFromRectangle(bbox)); | 780 | dict.replaceKey("/BBox", QPDFObjectHandle::newFromRectangle(bbox)); |
| 822 | - AS = QPDFObjectHandle::newStream( | ||
| 823 | - this->oh.getOwningQPDF(), "/Tx BMC\nEMC\n"); | 781 | + AS = QPDFObjectHandle::newStream(this->oh.getOwningQPDF(), "/Tx BMC\nEMC\n"); |
| 824 | AS.replaceDict(dict); | 782 | AS.replaceDict(dict); |
| 825 | QPDFObjectHandle AP = aoh.getAppearanceDictionary(); | 783 | QPDFObjectHandle AP = aoh.getAppearanceDictionary(); |
| 826 | if (AP.isNull()) { | 784 | if (AP.isNull()) { |
| 827 | QTC::TC("qpdf", "QPDFFormFieldObjectHelper create AP from scratch"); | 785 | QTC::TC("qpdf", "QPDFFormFieldObjectHelper create AP from scratch"); |
| 828 | - aoh.getObjectHandle().replaceKey( | ||
| 829 | - "/AP", QPDFObjectHandle::newDictionary()); | 786 | + aoh.getObjectHandle().replaceKey("/AP", QPDFObjectHandle::newDictionary()); |
| 830 | AP = aoh.getAppearanceDictionary(); | 787 | AP = aoh.getAppearanceDictionary(); |
| 831 | } | 788 | } |
| 832 | AP.replaceKey("/N", AS); | 789 | AP.replaceKey("/N", AS); |
| 833 | } | 790 | } |
| 834 | if (!AS.isStream()) { | 791 | if (!AS.isStream()) { |
| 835 | - aoh.getObjectHandle().warnIfPossible( | ||
| 836 | - "unable to get normal appearance stream for update"); | 792 | + aoh.getObjectHandle().warnIfPossible("unable to get normal appearance stream for update"); |
| 837 | return; | 793 | return; |
| 838 | } | 794 | } |
| 839 | QPDFObjectHandle bbox_obj = AS.getDict().getKey("/BBox"); | 795 | QPDFObjectHandle bbox_obj = AS.getDict().getKey("/BBox"); |
| 840 | if (!bbox_obj.isRectangle()) { | 796 | if (!bbox_obj.isRectangle()) { |
| 841 | - aoh.getObjectHandle().warnIfPossible( | ||
| 842 | - "unable to get appearance stream bounding box"); | 797 | + aoh.getObjectHandle().warnIfPossible("unable to get appearance stream bounding box"); |
| 843 | return; | 798 | return; |
| 844 | } | 799 | } |
| 845 | QPDFObjectHandle::Rectangle bbox = bbox_obj.getArrayAsRectangle(); | 800 | QPDFObjectHandle::Rectangle bbox = bbox_obj.getArrayAsRectangle(); |
| @@ -872,8 +827,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance( | @@ -872,8 +827,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance( | ||
| 872 | if (found_font_in_dr && resources.isDictionary()) { | 827 | if (found_font_in_dr && resources.isDictionary()) { |
| 873 | QTC::TC("qpdf", "QPDFFormFieldObjectHelper get font from /DR"); | 828 | QTC::TC("qpdf", "QPDFFormFieldObjectHelper get font from /DR"); |
| 874 | if (resources.isIndirect()) { | 829 | if (resources.isIndirect()) { |
| 875 | - resources = resources.getQPDF().makeIndirectObject( | ||
| 876 | - resources.shallowCopy()); | 830 | + resources = resources.getQPDF().makeIndirectObject(resources.shallowCopy()); |
| 877 | AS.getDict().replaceKey("/Resources", resources); | 831 | AS.getDict().replaceKey("/Resources", resources); |
| 878 | } | 832 | } |
| 879 | // Use mergeResources to force /Font to be local | 833 | // Use mergeResources to force /Font to be local |
| @@ -899,6 +853,5 @@ QPDFFormFieldObjectHelper::generateTextAppearance( | @@ -899,6 +853,5 @@ QPDFFormFieldObjectHelper::generateTextAppearance( | ||
| 899 | 853 | ||
| 900 | AS.addTokenFilter( | 854 | AS.addTokenFilter( |
| 901 | // line-break | 855 | // line-break |
| 902 | - std::shared_ptr<QPDFObjectHandle::TokenFilter>( | ||
| 903 | - new ValueSetter(DA, V, opt, tf, bbox))); | 856 | + std::shared_ptr<QPDFObjectHandle::TokenFilter>(new ValueSetter(DA, V, opt, tf, bbox))); |
| 904 | } | 857 | } |
libqpdf/QPDFJob.cc
| @@ -50,8 +50,7 @@ namespace | @@ -50,8 +50,7 @@ namespace | ||
| 50 | QPDFObjectHandle& image); | 50 | QPDFObjectHandle& image); |
| 51 | ~ImageOptimizer() override = default; | 51 | ~ImageOptimizer() override = default; |
| 52 | void provideStreamData(QPDFObjGen const&, Pipeline* pipeline) override; | 52 | void provideStreamData(QPDFObjGen const&, Pipeline* pipeline) override; |
| 53 | - std::shared_ptr<Pipeline> | ||
| 54 | - makePipeline(std::string const& description, Pipeline* next); | 53 | + std::shared_ptr<Pipeline> makePipeline(std::string const& description, Pipeline* next); |
| 55 | bool evaluate(std::string const& description); | 54 | bool evaluate(std::string const& description); |
| 56 | 55 | ||
| 57 | private: | 56 | private: |
| @@ -78,8 +77,7 @@ namespace | @@ -78,8 +77,7 @@ namespace | ||
| 78 | 77 | ||
| 79 | struct QPDFPageData | 78 | struct QPDFPageData |
| 80 | { | 79 | { |
| 81 | - QPDFPageData( | ||
| 82 | - std::string const& filename, QPDF* qpdf, std::string const& range); | 80 | + QPDFPageData(std::string const& filename, QPDF* qpdf, std::string const& range); |
| 83 | QPDFPageData(QPDFPageData const& other, int page); | 81 | QPDFPageData(QPDFPageData const& other, int page); |
| 84 | 82 | ||
| 85 | std::string filename; | 83 | std::string filename; |
| @@ -91,8 +89,7 @@ namespace | @@ -91,8 +89,7 @@ namespace | ||
| 91 | class ProgressReporter: public QPDFWriter::ProgressReporter | 89 | class ProgressReporter: public QPDFWriter::ProgressReporter |
| 92 | { | 90 | { |
| 93 | public: | 91 | public: |
| 94 | - ProgressReporter( | ||
| 95 | - Pipeline& p, std::string const& prefix, char const* filename) : | 92 | + ProgressReporter(Pipeline& p, std::string const& prefix, char const* filename) : |
| 96 | p(p), | 93 | p(p), |
| 97 | prefix(prefix), | 94 | prefix(prefix), |
| 98 | filename(filename) | 95 | filename(filename) |
| @@ -133,8 +130,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | @@ -133,8 +130,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | ||
| 133 | if (!(w_obj.isNumber() && h_obj.isNumber())) { | 130 | if (!(w_obj.isNumber() && h_obj.isNumber())) { |
| 134 | if (!description.empty()) { | 131 | if (!description.empty()) { |
| 135 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 132 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 136 | - v << prefix << ": " << description | ||
| 137 | - << ": not optimizing because image dictionary" | 133 | + v << prefix << ": " << description << ": not optimizing because image dictionary" |
| 138 | << " is missing required keys\n"; | 134 | << " is missing required keys\n"; |
| 139 | }); | 135 | }); |
| 140 | } | 136 | } |
| @@ -166,8 +162,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | @@ -166,8 +162,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | ||
| 166 | } else { | 162 | } else { |
| 167 | h = static_cast<JDIMENSION>(h_obj.getNumericValue()); | 163 | h = static_cast<JDIMENSION>(h_obj.getNumericValue()); |
| 168 | } | 164 | } |
| 169 | - std::string colorspace = | ||
| 170 | - (colorspace_obj.isName() ? colorspace_obj.getName() : std::string()); | 165 | + std::string colorspace = (colorspace_obj.isName() ? colorspace_obj.getName() : std::string()); |
| 171 | int components = 0; | 166 | int components = 0; |
| 172 | J_COLOR_SPACE cs = JCS_UNKNOWN; | 167 | J_COLOR_SPACE cs = JCS_UNKNOWN; |
| 173 | if (colorspace == "/DeviceRGB") { | 168 | if (colorspace == "/DeviceRGB") { |
| @@ -183,8 +178,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | @@ -183,8 +178,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | ||
| 183 | QTC::TC("qpdf", "QPDFJob image optimize colorspace"); | 178 | QTC::TC("qpdf", "QPDFJob image optimize colorspace"); |
| 184 | if (!description.empty()) { | 179 | if (!description.empty()) { |
| 185 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 180 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 186 | - v << prefix << ": " << description | ||
| 187 | - << ": not optimizing because qpdf can't optimize" | 181 | + v << prefix << ": " << description << ": not optimizing because qpdf can't optimize" |
| 188 | << " images with this colorspace\n"; | 182 | << " images with this colorspace\n"; |
| 189 | }); | 183 | }); |
| 190 | } | 184 | } |
| @@ -196,8 +190,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | @@ -196,8 +190,7 @@ ImageOptimizer::makePipeline(std::string const& description, Pipeline* next) | ||
| 196 | QTC::TC("qpdf", "QPDFJob image optimize too small"); | 190 | QTC::TC("qpdf", "QPDFJob image optimize too small"); |
| 197 | if (!description.empty()) { | 191 | if (!description.empty()) { |
| 198 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 192 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 199 | - v << prefix << ": " << description | ||
| 200 | - << ": not optimizing because image" | 193 | + v << prefix << ": " << description << ": not optimizing because image" |
| 201 | << " is smaller than requested minimum dimensions\n"; | 194 | << " is smaller than requested minimum dimensions\n"; |
| 202 | }); | 195 | }); |
| 203 | } | 196 | } |
| @@ -214,8 +207,7 @@ ImageOptimizer::evaluate(std::string const& description) | @@ -214,8 +207,7 @@ ImageOptimizer::evaluate(std::string const& description) | ||
| 214 | if (!image.pipeStreamData(nullptr, 0, qpdf_dl_specialized, true)) { | 207 | if (!image.pipeStreamData(nullptr, 0, qpdf_dl_specialized, true)) { |
| 215 | QTC::TC("qpdf", "QPDFJob image optimize no pipeline"); | 208 | QTC::TC("qpdf", "QPDFJob image optimize no pipeline"); |
| 216 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 209 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 217 | - v << prefix << ": " << description | ||
| 218 | - << ": not optimizing because unable to decode data" | 210 | + v << prefix << ": " << description << ": not optimizing because unable to decode data" |
| 219 | << " or data already uses DCT\n"; | 211 | << " or data already uses DCT\n"; |
| 220 | }); | 212 | }); |
| 221 | return false; | 213 | return false; |
| @@ -241,9 +233,8 @@ ImageOptimizer::evaluate(std::string const& description) | @@ -241,9 +233,8 @@ ImageOptimizer::evaluate(std::string const& description) | ||
| 241 | return false; | 233 | return false; |
| 242 | } | 234 | } |
| 243 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 235 | o.doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 244 | - v << prefix << ": " << description | ||
| 245 | - << ": optimizing image reduces size from " << orig_length << " to " | ||
| 246 | - << c.getCount() << "\n"; | 236 | + v << prefix << ": " << description << ": optimizing image reduces size from " << orig_length |
| 237 | + << " to " << c.getCount() << "\n"; | ||
| 247 | }); | 238 | }); |
| 248 | return true; | 239 | return true; |
| 249 | } | 240 | } |
| @@ -263,9 +254,7 @@ ImageOptimizer::provideStreamData(QPDFObjGen const&, Pipeline* pipeline) | @@ -263,9 +254,7 @@ ImageOptimizer::provideStreamData(QPDFObjGen const&, Pipeline* pipeline) | ||
| 263 | } | 254 | } |
| 264 | 255 | ||
| 265 | QPDFJob::PageSpec::PageSpec( | 256 | QPDFJob::PageSpec::PageSpec( |
| 266 | - std::string const& filename, | ||
| 267 | - char const* password, | ||
| 268 | - std::string const& range) : | 257 | + std::string const& filename, char const* password, std::string const& range) : |
| 269 | filename(filename), | 258 | filename(filename), |
| 270 | range(range) | 259 | range(range) |
| 271 | { | 260 | { |
| @@ -274,18 +263,16 @@ QPDFJob::PageSpec::PageSpec( | @@ -274,18 +263,16 @@ QPDFJob::PageSpec::PageSpec( | ||
| 274 | } | 263 | } |
| 275 | } | 264 | } |
| 276 | 265 | ||
| 277 | -QPDFPageData::QPDFPageData( | ||
| 278 | - std::string const& filename, QPDF* qpdf, std::string const& range) : | 266 | +QPDFPageData::QPDFPageData(std::string const& filename, QPDF* qpdf, std::string const& range) : |
| 279 | filename(filename), | 267 | filename(filename), |
| 280 | qpdf(qpdf), | 268 | qpdf(qpdf), |
| 281 | orig_pages(qpdf->getAllPages()) | 269 | orig_pages(qpdf->getAllPages()) |
| 282 | { | 270 | { |
| 283 | try { | 271 | try { |
| 284 | - this->selected_pages = QUtil::parse_numrange( | ||
| 285 | - range.c_str(), QIntC::to_int(this->orig_pages.size())); | 272 | + this->selected_pages = |
| 273 | + QUtil::parse_numrange(range.c_str(), QIntC::to_int(this->orig_pages.size())); | ||
| 286 | } catch (std::runtime_error& e) { | 274 | } catch (std::runtime_error& e) { |
| 287 | - throw std::runtime_error( | ||
| 288 | - "parsing numeric range for " + filename + ": " + e.what()); | 275 | + throw std::runtime_error("parsing numeric range for " + filename + ": " + e.what()); |
| 289 | } | 276 | } |
| 290 | } | 277 | } |
| 291 | 278 | ||
| @@ -300,8 +287,7 @@ QPDFPageData::QPDFPageData(QPDFPageData const& other, int page) : | @@ -300,8 +287,7 @@ QPDFPageData::QPDFPageData(QPDFPageData const& other, int page) : | ||
| 300 | void | 287 | void |
| 301 | ProgressReporter::reportProgress(int percentage) | 288 | ProgressReporter::reportProgress(int percentage) |
| 302 | { | 289 | { |
| 303 | - this->p << prefix << ": " << filename << ": write progress: " << percentage | ||
| 304 | - << "%\n"; | 290 | + this->p << prefix << ": " << filename << ": write progress: " << percentage << "%\n"; |
| 305 | } | 291 | } |
| 306 | 292 | ||
| 307 | QPDFJob::Members::Members() : | 293 | QPDFJob::Members::Members() : |
| @@ -358,8 +344,7 @@ QPDFJob::registerProgressReporter(std::function<void(int)> handler) | @@ -358,8 +344,7 @@ QPDFJob::registerProgressReporter(std::function<void(int)> handler) | ||
| 358 | } | 344 | } |
| 359 | 345 | ||
| 360 | void | 346 | void |
| 361 | -QPDFJob::doIfVerbose( | ||
| 362 | - std::function<void(Pipeline&, std::string const& prefix)> fn) | 347 | +QPDFJob::doIfVerbose(std::function<void(Pipeline&, std::string const& prefix)> fn) |
| 363 | { | 348 | { |
| 364 | if (m->verbose) { | 349 | if (m->verbose) { |
| 365 | fn(*m->log->getInfo(), m->message_prefix); | 350 | fn(*m->log->getInfo(), m->message_prefix); |
| @@ -459,8 +444,7 @@ QPDFJob::createQPDF() | @@ -459,8 +444,7 @@ QPDFJob::createQPDF() | ||
| 459 | // Allow certain operations to work when an incorrect | 444 | // Allow certain operations to work when an incorrect |
| 460 | // password is supplied. | 445 | // password is supplied. |
| 461 | if (m->check_is_encrypted || m->check_requires_password) { | 446 | if (m->check_is_encrypted || m->check_requires_password) { |
| 462 | - m->encryption_status = | ||
| 463 | - qpdf_es_encrypted | qpdf_es_password_incorrect; | 447 | + m->encryption_status = qpdf_es_encrypted | qpdf_es_password_incorrect; |
| 464 | return nullptr; | 448 | return nullptr; |
| 465 | } | 449 | } |
| 466 | if (m->show_encryption && pdf_sp) { | 450 | if (m->show_encryption && pdf_sp) { |
| @@ -513,12 +497,10 @@ QPDFJob::writeQPDF(QPDF& pdf) | @@ -513,12 +497,10 @@ QPDFJob::writeQPDF(QPDF& pdf) | ||
| 513 | } | 497 | } |
| 514 | if (m->warnings && (!m->suppress_warnings)) { | 498 | if (m->warnings && (!m->suppress_warnings)) { |
| 515 | if (createsOutput()) { | 499 | if (createsOutput()) { |
| 516 | - *m->log->getWarn() | ||
| 517 | - << m->message_prefix << ": operation succeeded with warnings;" | ||
| 518 | - << " resulting file may have some problems\n"; | 500 | + *m->log->getWarn() << m->message_prefix << ": operation succeeded with warnings;" |
| 501 | + << " resulting file may have some problems\n"; | ||
| 519 | } else { | 502 | } else { |
| 520 | - *m->log->getWarn() | ||
| 521 | - << m->message_prefix << ": operation succeeded with warnings\n"; | 503 | + *m->log->getWarn() << m->message_prefix << ": operation succeeded with warnings\n"; |
| 522 | } | 504 | } |
| 523 | } | 505 | } |
| 524 | if (m->report_mem_usage) { | 506 | if (m->report_mem_usage) { |
| @@ -611,13 +593,9 @@ QPDFJob::checkConfiguration() | @@ -611,13 +593,9 @@ QPDFJob::checkConfiguration() | ||
| 611 | usage("an input file name is required"); | 593 | usage("an input file name is required"); |
| 612 | } else if (m->replace_input && (strlen(m->infilename.get()) == 0)) { | 594 | } else if (m->replace_input && (strlen(m->infilename.get()) == 0)) { |
| 613 | usage("--replace-input may not be used with --empty"); | 595 | usage("--replace-input may not be used with --empty"); |
| 614 | - } else if ( | ||
| 615 | - m->require_outfile && (m->outfilename == nullptr) && | ||
| 616 | - (!m->replace_input)) { | 596 | + } else if (m->require_outfile && (m->outfilename == nullptr) && (!m->replace_input)) { |
| 617 | usage("an output file name is required; use - for standard output"); | 597 | usage("an output file name is required; use - for standard output"); |
| 618 | - } else if ( | ||
| 619 | - (!m->require_outfile) && | ||
| 620 | - ((m->outfilename != nullptr) || m->replace_input)) { | 598 | + } else if ((!m->require_outfile) && ((m->outfilename != nullptr) || m->replace_input)) { |
| 621 | usage("no output file may be given for this option"); | 599 | usage("no output file may be given for this option"); |
| 622 | } | 600 | } |
| 623 | if (m->check_requires_password && m->check_is_encrypted) { | 601 | if (m->check_requires_password && m->check_is_encrypted) { |
| @@ -626,8 +604,7 @@ QPDFJob::checkConfiguration() | @@ -626,8 +604,7 @@ QPDFJob::checkConfiguration() | ||
| 626 | } | 604 | } |
| 627 | 605 | ||
| 628 | if (m->encrypt && (!m->allow_insecure) && | 606 | if (m->encrypt && (!m->allow_insecure) && |
| 629 | - (m->owner_password.empty() && (!m->user_password.empty()) && | ||
| 630 | - (m->keylen == 256))) { | 607 | + (m->owner_password.empty() && (!m->user_password.empty()) && (m->keylen == 256))) { |
| 631 | // Note that empty owner passwords for R < 5 are copied from | 608 | // Note that empty owner passwords for R < 5 are copied from |
| 632 | // the user password, so this lack of security is not an issue | 609 | // the user password, so this lack of security is not an issue |
| 633 | // for those files. Also we are consider only the ability to | 610 | // for those files. Also we are consider only the ability to |
| @@ -642,8 +619,7 @@ QPDFJob::checkConfiguration() | @@ -642,8 +619,7 @@ QPDFJob::checkConfiguration() | ||
| 642 | } | 619 | } |
| 643 | 620 | ||
| 644 | bool save_to_stdout = false; | 621 | bool save_to_stdout = false; |
| 645 | - if (m->require_outfile && m->outfilename && | ||
| 646 | - (strcmp(m->outfilename.get(), "-") == 0)) { | 622 | + if (m->require_outfile && m->outfilename && (strcmp(m->outfilename.get(), "-") == 0)) { |
| 647 | if (m->split_pages) { | 623 | if (m->split_pages) { |
| 648 | usage("--split-pages may not be used when" | 624 | usage("--split-pages may not be used when" |
| 649 | " writing to standard output"); | 625 | " writing to standard output"); |
| @@ -656,8 +632,7 @@ QPDFJob::checkConfiguration() | @@ -656,8 +632,7 @@ QPDFJob::checkConfiguration() | ||
| 656 | if (save_to_stdout) { | 632 | if (save_to_stdout) { |
| 657 | m->log->saveToStandardOutput(true); | 633 | m->log->saveToStandardOutput(true); |
| 658 | } | 634 | } |
| 659 | - if ((!m->split_pages) && | ||
| 660 | - QUtil::same_file(m->infilename.get(), m->outfilename.get())) { | 635 | + if ((!m->split_pages) && QUtil::same_file(m->infilename.get(), m->outfilename.get())) { |
| 661 | QTC::TC("qpdf", "QPDFJob same file error"); | 636 | QTC::TC("qpdf", "QPDFJob same file error"); |
| 662 | usage("input file and output file are the same;" | 637 | usage("input file and output file are the same;" |
| 663 | " use --replace-input to intentionally" | 638 | " use --replace-input to intentionally" |
| @@ -751,8 +726,7 @@ QPDFJob::showEncryption(QPDF& pdf) | @@ -751,8 +726,7 @@ QPDFJob::showEncryption(QPDF& pdf) | ||
| 751 | std::string encryption_key = pdf.getEncryptionKey(); | 726 | std::string encryption_key = pdf.getEncryptionKey(); |
| 752 | cout << "User password = " << user_password << "\n"; | 727 | cout << "User password = " << user_password << "\n"; |
| 753 | if (m->show_encryption_key) { | 728 | if (m->show_encryption_key) { |
| 754 | - cout << "Encryption key = " << QUtil::hex_encode(encryption_key) | ||
| 755 | - << "\n"; | 729 | + cout << "Encryption key = " << QUtil::hex_encode(encryption_key) << "\n"; |
| 756 | } | 730 | } |
| 757 | if (pdf.ownerPasswordMatched()) { | 731 | if (pdf.ownerPasswordMatched()) { |
| 758 | cout << "Supplied password is owner password\n"; | 732 | cout << "Supplied password is owner password\n"; |
| @@ -760,28 +734,19 @@ QPDFJob::showEncryption(QPDF& pdf) | @@ -760,28 +734,19 @@ QPDFJob::showEncryption(QPDF& pdf) | ||
| 760 | if (pdf.userPasswordMatched()) { | 734 | if (pdf.userPasswordMatched()) { |
| 761 | cout << "Supplied password is user password\n"; | 735 | cout << "Supplied password is user password\n"; |
| 762 | } | 736 | } |
| 763 | - cout << "extract for accessibility: " | ||
| 764 | - << show_bool(pdf.allowAccessibility()) << "\n" | ||
| 765 | - << "extract for any purpose: " << show_bool(pdf.allowExtractAll()) | ||
| 766 | - << "\n" | ||
| 767 | - << "print low resolution: " << show_bool(pdf.allowPrintLowRes()) | ||
| 768 | - << "\n" | ||
| 769 | - << "print high resolution: " << show_bool(pdf.allowPrintHighRes()) | ||
| 770 | - << "\n" | ||
| 771 | - << "modify document assembly: " | ||
| 772 | - << show_bool(pdf.allowModifyAssembly()) << "\n" | 737 | + cout << "extract for accessibility: " << show_bool(pdf.allowAccessibility()) << "\n" |
| 738 | + << "extract for any purpose: " << show_bool(pdf.allowExtractAll()) << "\n" | ||
| 739 | + << "print low resolution: " << show_bool(pdf.allowPrintLowRes()) << "\n" | ||
| 740 | + << "print high resolution: " << show_bool(pdf.allowPrintHighRes()) << "\n" | ||
| 741 | + << "modify document assembly: " << show_bool(pdf.allowModifyAssembly()) << "\n" | ||
| 773 | << "modify forms: " << show_bool(pdf.allowModifyForm()) << "\n" | 742 | << "modify forms: " << show_bool(pdf.allowModifyForm()) << "\n" |
| 774 | - << "modify annotations: " << show_bool(pdf.allowModifyAnnotation()) | ||
| 775 | - << "\n" | 743 | + << "modify annotations: " << show_bool(pdf.allowModifyAnnotation()) << "\n" |
| 776 | << "modify other: " << show_bool(pdf.allowModifyOther()) << "\n" | 744 | << "modify other: " << show_bool(pdf.allowModifyOther()) << "\n" |
| 777 | << "modify anything: " << show_bool(pdf.allowModifyAll()) << "\n"; | 745 | << "modify anything: " << show_bool(pdf.allowModifyAll()) << "\n"; |
| 778 | if (V >= 4) { | 746 | if (V >= 4) { |
| 779 | - cout << "stream encryption method: " | ||
| 780 | - << show_encryption_method(stream_method) << "\n" | ||
| 781 | - << "string encryption method: " | ||
| 782 | - << show_encryption_method(string_method) << "\n" | ||
| 783 | - << "file encryption method: " | ||
| 784 | - << show_encryption_method(file_method) << "\n"; | 747 | + cout << "stream encryption method: " << show_encryption_method(stream_method) << "\n" |
| 748 | + << "string encryption method: " << show_encryption_method(string_method) << "\n" | ||
| 749 | + << "file encryption method: " << show_encryption_method(file_method) << "\n"; | ||
| 785 | } | 750 | } |
| 786 | } | 751 | } |
| 787 | } | 752 | } |
| @@ -830,8 +795,7 @@ QPDFJob::doCheck(QPDF& pdf) | @@ -830,8 +795,7 @@ QPDFJob::doCheck(QPDF& pdf) | ||
| 830 | page.parseContents(&discard_contents); | 795 | page.parseContents(&discard_contents); |
| 831 | } catch (QPDFExc& e) { | 796 | } catch (QPDFExc& e) { |
| 832 | okay = false; | 797 | okay = false; |
| 833 | - *m->log->getError() | ||
| 834 | - << "ERROR: page " << pageno << ": " << e.what() << "\n"; | 798 | + *m->log->getError() << "ERROR: page " << pageno << ": " << e.what() << "\n"; |
| 835 | } | 799 | } |
| 836 | } | 800 | } |
| 837 | } catch (std::exception& e) { | 801 | } catch (std::exception& e) { |
| @@ -885,8 +849,7 @@ QPDFJob::doShowObj(QPDF& pdf) | @@ -885,8 +849,7 @@ QPDFJob::doShowObj(QPDF& pdf) | ||
| 885 | *m->log->getInfo() << obj.unparseResolved() << "\n"; | 849 | *m->log->getInfo() << obj.unparseResolved() << "\n"; |
| 886 | } | 850 | } |
| 887 | if (error) { | 851 | if (error) { |
| 888 | - throw std::runtime_error( | ||
| 889 | - "unable to get object " + obj.getObjGen().unparse(',')); | 852 | + throw std::runtime_error("unable to get object " + obj.getObjGen().unparse(',')); |
| 890 | } | 853 | } |
| 891 | } | 854 | } |
| 892 | 855 | ||
| @@ -899,8 +862,8 @@ QPDFJob::doShowPages(QPDF& pdf) | @@ -899,8 +862,8 @@ QPDFJob::doShowPages(QPDF& pdf) | ||
| 899 | QPDFObjectHandle page = ph.getObjectHandle(); | 862 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 900 | ++pageno; | 863 | ++pageno; |
| 901 | 864 | ||
| 902 | - cout << "page " << pageno << ": " << page.getObjectID() << " " | ||
| 903 | - << page.getGeneration() << " R\n"; | 865 | + cout << "page " << pageno << ": " << page.getObjectID() << " " << page.getGeneration() |
| 866 | + << " R\n"; | ||
| 904 | if (m->show_page_images) { | 867 | if (m->show_page_images) { |
| 905 | std::map<std::string, QPDFObjectHandle> images = ph.getImages(); | 868 | std::map<std::string, QPDFObjectHandle> images = ph.getImages(); |
| 906 | if (!images.empty()) { | 869 | if (!images.empty()) { |
| @@ -911,8 +874,8 @@ QPDFJob::doShowPages(QPDF& pdf) | @@ -911,8 +874,8 @@ QPDFJob::doShowPages(QPDF& pdf) | ||
| 911 | QPDFObjectHandle dict = image.getDict(); | 874 | QPDFObjectHandle dict = image.getDict(); |
| 912 | int width = dict.getKey("/Width").getIntValueAsInt(); | 875 | int width = dict.getKey("/Width").getIntValueAsInt(); |
| 913 | int height = dict.getKey("/Height").getIntValueAsInt(); | 876 | int height = dict.getKey("/Height").getIntValueAsInt(); |
| 914 | - cout << " " << name << ": " << image.unparse() << ", " | ||
| 915 | - << width << " x " << height << "\n"; | 877 | + cout << " " << name << ": " << image.unparse() << ", " << width << " x " |
| 878 | + << height << "\n"; | ||
| 916 | } | 879 | } |
| 917 | } | 880 | } |
| 918 | } | 881 | } |
| @@ -932,10 +895,8 @@ QPDFJob::doListAttachments(QPDF& pdf) | @@ -932,10 +895,8 @@ QPDFJob::doListAttachments(QPDF& pdf) | ||
| 932 | for (auto const& i: efdh.getEmbeddedFiles()) { | 895 | for (auto const& i: efdh.getEmbeddedFiles()) { |
| 933 | std::string const& key = i.first; | 896 | std::string const& key = i.first; |
| 934 | auto efoh = i.second; | 897 | auto efoh = i.second; |
| 935 | - *m->log->getInfo() | ||
| 936 | - << key << " -> " | ||
| 937 | - << efoh->getEmbeddedFileStream().getObjGen().unparse(',') | ||
| 938 | - << "\n"; | 898 | + *m->log->getInfo() << key << " -> " |
| 899 | + << efoh->getEmbeddedFileStream().getObjGen().unparse(',') << "\n"; | ||
| 939 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 900 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 940 | auto desc = efoh->getDescription(); | 901 | auto desc = efoh->getDescription(); |
| 941 | if (!desc.empty()) { | 902 | if (!desc.empty()) { |
| @@ -951,12 +912,10 @@ QPDFJob::doListAttachments(QPDF& pdf) | @@ -951,12 +912,10 @@ QPDFJob::doListAttachments(QPDF& pdf) | ||
| 951 | auto efs = QPDFEFStreamObjectHelper(i2.second); | 912 | auto efs = QPDFEFStreamObjectHelper(i2.second); |
| 952 | v << " " << i2.first << " -> " | 913 | v << " " << i2.first << " -> " |
| 953 | << efs.getObjectHandle().getObjGen().unparse(',') << "\n"; | 914 | << efs.getObjectHandle().getObjGen().unparse(',') << "\n"; |
| 954 | - v << " creation date: " << efs.getCreationDate() | ||
| 955 | - << "\n" | 915 | + v << " creation date: " << efs.getCreationDate() << "\n" |
| 956 | << " modification date: " << efs.getModDate() << "\n" | 916 | << " modification date: " << efs.getModDate() << "\n" |
| 957 | << " mime type: " << efs.getSubtype() << "\n" | 917 | << " mime type: " << efs.getSubtype() << "\n" |
| 958 | - << " checksum: " | ||
| 959 | - << QUtil::hex_encode(efs.getChecksum()) << "\n"; | 918 | + << " checksum: " << QUtil::hex_encode(efs.getChecksum()) << "\n"; |
| 960 | } | 919 | } |
| 961 | }); | 920 | }); |
| 962 | } | 921 | } |
| @@ -971,8 +930,7 @@ QPDFJob::doShowAttachment(QPDF& pdf) | @@ -971,8 +930,7 @@ QPDFJob::doShowAttachment(QPDF& pdf) | ||
| 971 | QPDFEmbeddedFileDocumentHelper efdh(pdf); | 930 | QPDFEmbeddedFileDocumentHelper efdh(pdf); |
| 972 | auto fs = efdh.getEmbeddedFile(m->attachment_to_show); | 931 | auto fs = efdh.getEmbeddedFile(m->attachment_to_show); |
| 973 | if (!fs) { | 932 | if (!fs) { |
| 974 | - throw std::runtime_error( | ||
| 975 | - "attachment " + m->attachment_to_show + " not found"); | 933 | + throw std::runtime_error("attachment " + m->attachment_to_show + " not found"); |
| 976 | } | 934 | } |
| 977 | auto efs = fs->getEmbeddedFileStream(); | 935 | auto efs = fs->getEmbeddedFileStream(); |
| 978 | // saveToStandardOutput has already been called, but it's harmless | 936 | // saveToStandardOutput has already been called, but it's harmless |
| @@ -982,8 +940,7 @@ QPDFJob::doShowAttachment(QPDF& pdf) | @@ -982,8 +940,7 @@ QPDFJob::doShowAttachment(QPDF& pdf) | ||
| 982 | } | 940 | } |
| 983 | 941 | ||
| 984 | void | 942 | void |
| 985 | -QPDFJob::parse_object_id( | ||
| 986 | - std::string const& objspec, bool& trailer, int& obj, int& gen) | 943 | +QPDFJob::parse_object_id(std::string const& objspec, bool& trailer, int& obj, int& gen) |
| 987 | { | 944 | { |
| 988 | if (objspec == "trailer") { | 945 | if (objspec == "trailer") { |
| 989 | trailer = true; | 946 | trailer = true; |
| @@ -992,8 +949,7 @@ QPDFJob::parse_object_id( | @@ -992,8 +949,7 @@ QPDFJob::parse_object_id( | ||
| 992 | obj = QUtil::string_to_int(objspec.c_str()); | 949 | obj = QUtil::string_to_int(objspec.c_str()); |
| 993 | size_t comma = objspec.find(','); | 950 | size_t comma = objspec.find(','); |
| 994 | if ((comma != std::string::npos) && (comma + 1 < objspec.length())) { | 951 | if ((comma != std::string::npos) && (comma + 1 < objspec.length())) { |
| 995 | - gen = QUtil::string_to_int( | ||
| 996 | - objspec.substr(1 + comma, std::string::npos).c_str()); | 952 | + gen = QUtil::string_to_int(objspec.substr(1 + comma, std::string::npos).c_str()); |
| 997 | } | 953 | } |
| 998 | } | 954 | } |
| 999 | } | 955 | } |
| @@ -1013,8 +969,7 @@ QPDFJob::getWantedJSONObjects() | @@ -1013,8 +969,7 @@ QPDFJob::getWantedJSONObjects() | ||
| 1013 | } | 969 | } |
| 1014 | 970 | ||
| 1015 | void | 971 | void |
| 1016 | -QPDFJob::doJSONObject( | ||
| 1017 | - Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj) | 972 | +QPDFJob::doJSONObject(Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj) |
| 1018 | { | 973 | { |
| 1019 | if (m->json_version == 1) { | 974 | if (m->json_version == 1) { |
| 1020 | JSON::writeDictionaryItem(p, first, key, obj.getJSON(1, true), 2); | 975 | JSON::writeDictionaryItem(p, first, key, obj.getJSON(1, true), 2); |
| @@ -1022,8 +977,7 @@ QPDFJob::doJSONObject( | @@ -1022,8 +977,7 @@ QPDFJob::doJSONObject( | ||
| 1022 | auto j = JSON::makeDictionary(); | 977 | auto j = JSON::makeDictionary(); |
| 1023 | if (obj.isStream()) { | 978 | if (obj.isStream()) { |
| 1024 | j.addDictionaryMember("stream", JSON::makeDictionary()) | 979 | j.addDictionaryMember("stream", JSON::makeDictionary()) |
| 1025 | - .addDictionaryMember( | ||
| 1026 | - "dict", obj.getDict().getJSON(m->json_version, true)); | 980 | + .addDictionaryMember("dict", obj.getDict().getJSON(m->json_version, true)); |
| 1027 | } else { | 981 | } else { |
| 1028 | j.addDictionaryMember("value", obj.getJSON(m->json_version, true)); | 982 | j.addDictionaryMember("value", obj.getJSON(m->json_version, true)); |
| 1029 | } | 983 | } |
| @@ -1085,22 +1039,18 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf) | @@ -1085,22 +1039,18 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1085 | for (auto& obj: pdf.getAllObjects()) { | 1039 | for (auto& obj: pdf.getAllObjects()) { |
| 1086 | if (all_objects || wanted_og.count(obj.getObjGen())) { | 1040 | if (all_objects || wanted_og.count(obj.getObjGen())) { |
| 1087 | auto j_details = JSON::makeDictionary(); | 1041 | auto j_details = JSON::makeDictionary(); |
| 1088 | - auto j_stream = | ||
| 1089 | - j_details.addDictionaryMember("stream", JSON::makeDictionary()); | 1042 | + auto j_stream = j_details.addDictionaryMember("stream", JSON::makeDictionary()); |
| 1090 | bool is_stream = obj.isStream(); | 1043 | bool is_stream = obj.isStream(); |
| 1091 | j_stream.addDictionaryMember("is", JSON::makeBool(is_stream)); | 1044 | j_stream.addDictionaryMember("is", JSON::makeBool(is_stream)); |
| 1092 | j_stream.addDictionaryMember( | 1045 | j_stream.addDictionaryMember( |
| 1093 | "length", | 1046 | "length", |
| 1094 | - (is_stream ? obj.getDict().getKey("/Length").getJSON( | ||
| 1095 | - m->json_version, true) | 1047 | + (is_stream ? obj.getDict().getKey("/Length").getJSON(m->json_version, true) |
| 1096 | : JSON::makeNull())); | 1048 | : JSON::makeNull())); |
| 1097 | j_stream.addDictionaryMember( | 1049 | j_stream.addDictionaryMember( |
| 1098 | "filter", | 1050 | "filter", |
| 1099 | - (is_stream ? obj.getDict().getKey("/Filter").getJSON( | ||
| 1100 | - m->json_version, true) | 1051 | + (is_stream ? obj.getDict().getKey("/Filter").getJSON(m->json_version, true) |
| 1101 | : JSON::makeNull())); | 1052 | : JSON::makeNull())); |
| 1102 | - JSON::writeDictionaryItem( | ||
| 1103 | - p, first_object, obj.unparse(), j_details, 2); | 1053 | + JSON::writeDictionaryItem(p, first_object, obj.unparse(), j_details, 2); |
| 1104 | } | 1054 | } |
| 1105 | } | 1055 | } |
| 1106 | JSON::writeDictionaryClose(p, first_object, 1); | 1056 | JSON::writeDictionaryClose(p, first_object, 1); |
| @@ -1126,21 +1076,15 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | @@ -1126,21 +1076,15 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1126 | j_image.addDictionaryMember("name", JSON::makeString(iter2.first)); | 1076 | j_image.addDictionaryMember("name", JSON::makeString(iter2.first)); |
| 1127 | QPDFObjectHandle image = iter2.second; | 1077 | QPDFObjectHandle image = iter2.second; |
| 1128 | QPDFObjectHandle dict = image.getDict(); | 1078 | QPDFObjectHandle dict = image.getDict(); |
| 1079 | + j_image.addDictionaryMember("object", image.getJSON(m->json_version)); | ||
| 1080 | + j_image.addDictionaryMember("width", dict.getKey("/Width").getJSON(m->json_version)); | ||
| 1081 | + j_image.addDictionaryMember("height", dict.getKey("/Height").getJSON(m->json_version)); | ||
| 1129 | j_image.addDictionaryMember( | 1082 | j_image.addDictionaryMember( |
| 1130 | - "object", image.getJSON(m->json_version)); | ||
| 1131 | - j_image.addDictionaryMember( | ||
| 1132 | - "width", dict.getKey("/Width").getJSON(m->json_version)); | ||
| 1133 | - j_image.addDictionaryMember( | ||
| 1134 | - "height", dict.getKey("/Height").getJSON(m->json_version)); | ||
| 1135 | - j_image.addDictionaryMember( | ||
| 1136 | - "colorspace", | ||
| 1137 | - dict.getKey("/ColorSpace").getJSON(m->json_version)); | 1083 | + "colorspace", dict.getKey("/ColorSpace").getJSON(m->json_version)); |
| 1138 | j_image.addDictionaryMember( | 1084 | j_image.addDictionaryMember( |
| 1139 | - "bitspercomponent", | ||
| 1140 | - dict.getKey("/BitsPerComponent").getJSON(m->json_version)); | 1085 | + "bitspercomponent", dict.getKey("/BitsPerComponent").getJSON(m->json_version)); |
| 1141 | QPDFObjectHandle filters = dict.getKey("/Filter").wrapInArray(); | 1086 | QPDFObjectHandle filters = dict.getKey("/Filter").wrapInArray(); |
| 1142 | - j_image.addDictionaryMember( | ||
| 1143 | - "filter", filters.getJSON(m->json_version)); | 1087 | + j_image.addDictionaryMember("filter", filters.getJSON(m->json_version)); |
| 1144 | QPDFObjectHandle decode_parms = dict.getKey("/DecodeParms"); | 1088 | QPDFObjectHandle decode_parms = dict.getKey("/DecodeParms"); |
| 1145 | QPDFObjectHandle dp_array; | 1089 | QPDFObjectHandle dp_array; |
| 1146 | if (decode_parms.isArray()) { | 1090 | if (decode_parms.isArray()) { |
| @@ -1151,33 +1095,25 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | @@ -1151,33 +1095,25 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1151 | dp_array.appendItem(decode_parms); | 1095 | dp_array.appendItem(decode_parms); |
| 1152 | } | 1096 | } |
| 1153 | } | 1097 | } |
| 1154 | - j_image.addDictionaryMember( | ||
| 1155 | - "decodeparms", dp_array.getJSON(m->json_version)); | 1098 | + j_image.addDictionaryMember("decodeparms", dp_array.getJSON(m->json_version)); |
| 1156 | j_image.addDictionaryMember( | 1099 | j_image.addDictionaryMember( |
| 1157 | "filterable", | 1100 | "filterable", |
| 1158 | - JSON::makeBool( | ||
| 1159 | - image.pipeStreamData(nullptr, 0, m->decode_level, true))); | 1101 | + JSON::makeBool(image.pipeStreamData(nullptr, 0, m->decode_level, true))); |
| 1160 | } | 1102 | } |
| 1161 | j_page.addDictionaryMember("images", j_images); | 1103 | j_page.addDictionaryMember("images", j_images); |
| 1162 | - JSON j_contents = | ||
| 1163 | - j_page.addDictionaryMember("contents", JSON::makeArray()); | 1104 | + JSON j_contents = j_page.addDictionaryMember("contents", JSON::makeArray()); |
| 1164 | for (auto& iter2: ph.getPageContents()) { | 1105 | for (auto& iter2: ph.getPageContents()) { |
| 1165 | j_contents.addArrayElement(iter2.getJSON(m->json_version)); | 1106 | j_contents.addArrayElement(iter2.getJSON(m->json_version)); |
| 1166 | } | 1107 | } |
| 1167 | - j_page.addDictionaryMember( | ||
| 1168 | - "label", pldh.getLabelForPage(pageno).getJSON(m->json_version)); | ||
| 1169 | - JSON j_outlines = | ||
| 1170 | - j_page.addDictionaryMember("outlines", JSON::makeArray()); | ||
| 1171 | - std::vector<QPDFOutlineObjectHelper> outlines = | ||
| 1172 | - odh.getOutlinesForPage(page.getObjGen()); | 1108 | + j_page.addDictionaryMember("label", pldh.getLabelForPage(pageno).getJSON(m->json_version)); |
| 1109 | + JSON j_outlines = j_page.addDictionaryMember("outlines", JSON::makeArray()); | ||
| 1110 | + std::vector<QPDFOutlineObjectHelper> outlines = odh.getOutlinesForPage(page.getObjGen()); | ||
| 1173 | for (auto& oiter: outlines) { | 1111 | for (auto& oiter: outlines) { |
| 1174 | JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary()); | 1112 | JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary()); |
| 1175 | j_outline.addDictionaryMember( | 1113 | j_outline.addDictionaryMember( |
| 1176 | "object", oiter.getObjectHandle().getJSON(m->json_version)); | 1114 | "object", oiter.getObjectHandle().getJSON(m->json_version)); |
| 1177 | - j_outline.addDictionaryMember( | ||
| 1178 | - "title", JSON::makeString(oiter.getTitle())); | ||
| 1179 | - j_outline.addDictionaryMember( | ||
| 1180 | - "dest", oiter.getDest().getJSON(m->json_version, true)); | 1115 | + j_outline.addDictionaryMember("title", JSON::makeString(oiter.getTitle())); |
| 1116 | + j_outline.addDictionaryMember("dest", oiter.getDest().getJSON(m->json_version, true)); | ||
| 1181 | } | 1117 | } |
| 1182 | j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno)); | 1118 | j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno)); |
| 1183 | JSON::writeArrayItem(p, first_page, j_page, 2); | 1119 | JSON::writeArrayItem(p, first_page, j_page, 2); |
| @@ -1190,8 +1126,7 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf) | @@ -1190,8 +1126,7 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1190 | { | 1126 | { |
| 1191 | JSON j_labels = JSON::makeArray(); | 1127 | JSON j_labels = JSON::makeArray(); |
| 1192 | QPDFPageLabelDocumentHelper pldh(pdf); | 1128 | QPDFPageLabelDocumentHelper pldh(pdf); |
| 1193 | - long long npages = | ||
| 1194 | - QIntC::to_longlong(QPDFPageDocumentHelper(pdf).getAllPages().size()); | 1129 | + long long npages = QIntC::to_longlong(QPDFPageDocumentHelper(pdf).getAllPages().size()); |
| 1195 | if (pldh.hasPageLabels()) { | 1130 | if (pldh.hasPageLabels()) { |
| 1196 | std::vector<QPDFObjectHandle> labels; | 1131 | std::vector<QPDFObjectHandle> labels; |
| 1197 | pldh.getLabelsForPageRange(0, npages - 1, 0, labels); | 1132 | pldh.getLabelsForPageRange(0, npages - 1, 0, labels); |
| @@ -1203,11 +1138,9 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf) | @@ -1203,11 +1138,9 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1203 | break; | 1138 | break; |
| 1204 | } | 1139 | } |
| 1205 | JSON j_label = j_labels.addArrayElement(JSON::makeDictionary()); | 1140 | JSON j_label = j_labels.addArrayElement(JSON::makeDictionary()); |
| 1206 | - j_label.addDictionaryMember( | ||
| 1207 | - "index", (*iter).getJSON(m->json_version)); | 1141 | + j_label.addDictionaryMember("index", (*iter).getJSON(m->json_version)); |
| 1208 | ++iter; | 1142 | ++iter; |
| 1209 | - j_label.addDictionaryMember( | ||
| 1210 | - "label", (*iter).getJSON(m->json_version)); | 1143 | + j_label.addDictionaryMember("label", (*iter).getJSON(m->json_version)); |
| 1211 | } | 1144 | } |
| 1212 | } | 1145 | } |
| 1213 | JSON::writeDictionaryItem(p, first, "pagelabels", j_labels, 1); | 1146 | JSON::writeDictionaryItem(p, first, "pagelabels", j_labels, 1); |
| @@ -1215,17 +1148,13 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf) | @@ -1215,17 +1148,13 @@ QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1215 | 1148 | ||
| 1216 | void | 1149 | void |
| 1217 | QPDFJob::addOutlinesToJson( | 1150 | QPDFJob::addOutlinesToJson( |
| 1218 | - std::vector<QPDFOutlineObjectHelper> outlines, | ||
| 1219 | - JSON& j, | ||
| 1220 | - std::map<QPDFObjGen, int>& page_numbers) | 1151 | + std::vector<QPDFOutlineObjectHelper> outlines, JSON& j, std::map<QPDFObjGen, int>& page_numbers) |
| 1221 | { | 1152 | { |
| 1222 | for (auto& ol: outlines) { | 1153 | for (auto& ol: outlines) { |
| 1223 | JSON jo = j.addArrayElement(JSON::makeDictionary()); | 1154 | JSON jo = j.addArrayElement(JSON::makeDictionary()); |
| 1224 | - jo.addDictionaryMember( | ||
| 1225 | - "object", ol.getObjectHandle().getJSON(m->json_version)); | 1155 | + jo.addDictionaryMember("object", ol.getObjectHandle().getJSON(m->json_version)); |
| 1226 | jo.addDictionaryMember("title", JSON::makeString(ol.getTitle())); | 1156 | jo.addDictionaryMember("title", JSON::makeString(ol.getTitle())); |
| 1227 | - jo.addDictionaryMember( | ||
| 1228 | - "dest", ol.getDest().getJSON(m->json_version, true)); | 1157 | + jo.addDictionaryMember("dest", ol.getDest().getJSON(m->json_version, true)); |
| 1229 | jo.addDictionaryMember("open", JSON::makeBool(ol.getCount() >= 0)); | 1158 | jo.addDictionaryMember("open", JSON::makeBool(ol.getCount() >= 0)); |
| 1230 | QPDFObjectHandle page = ol.getDestPage(); | 1159 | QPDFObjectHandle page = ol.getDestPage(); |
| 1231 | JSON j_destpage = JSON::makeNull(); | 1160 | JSON j_destpage = JSON::makeNull(); |
| @@ -1262,10 +1191,8 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | @@ -1262,10 +1191,8 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1262 | { | 1191 | { |
| 1263 | JSON j_acroform = JSON::makeDictionary(); | 1192 | JSON j_acroform = JSON::makeDictionary(); |
| 1264 | QPDFAcroFormDocumentHelper afdh(pdf); | 1193 | QPDFAcroFormDocumentHelper afdh(pdf); |
| 1265 | - j_acroform.addDictionaryMember( | ||
| 1266 | - "hasacroform", JSON::makeBool(afdh.hasAcroForm())); | ||
| 1267 | - j_acroform.addDictionaryMember( | ||
| 1268 | - "needappearances", JSON::makeBool(afdh.getNeedAppearances())); | 1194 | + j_acroform.addDictionaryMember("hasacroform", JSON::makeBool(afdh.hasAcroForm())); |
| 1195 | + j_acroform.addDictionaryMember("needappearances", JSON::makeBool(afdh.getNeedAppearances())); | ||
| 1269 | JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray()); | 1196 | JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray()); |
| 1270 | int pagepos1 = 0; | 1197 | int pagepos1 = 0; |
| 1271 | for (auto const& page: QPDFPageDocumentHelper(pdf).getAllPages()) { | 1198 | for (auto const& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| @@ -1273,52 +1200,34 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | @@ -1273,52 +1200,34 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1273 | for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) { | 1200 | for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) { |
| 1274 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh); | 1201 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh); |
| 1275 | JSON j_field = j_fields.addArrayElement(JSON::makeDictionary()); | 1202 | JSON j_field = j_fields.addArrayElement(JSON::makeDictionary()); |
| 1203 | + j_field.addDictionaryMember("object", ffh.getObjectHandle().getJSON(m->json_version)); | ||
| 1276 | j_field.addDictionaryMember( | 1204 | j_field.addDictionaryMember( |
| 1277 | - "object", ffh.getObjectHandle().getJSON(m->json_version)); | ||
| 1278 | - j_field.addDictionaryMember( | ||
| 1279 | - "parent", | ||
| 1280 | - ffh.getObjectHandle().getKey("/Parent").getJSON( | ||
| 1281 | - m->json_version)); | ||
| 1282 | - j_field.addDictionaryMember( | ||
| 1283 | - "pageposfrom1", JSON::makeInt(pagepos1)); | ||
| 1284 | - j_field.addDictionaryMember( | ||
| 1285 | - "fieldtype", JSON::makeString(ffh.getFieldType())); | ||
| 1286 | - j_field.addDictionaryMember( | ||
| 1287 | - "fieldflags", JSON::makeInt(ffh.getFlags())); | ||
| 1288 | - j_field.addDictionaryMember( | ||
| 1289 | - "fullname", JSON::makeString(ffh.getFullyQualifiedName())); | ||
| 1290 | - j_field.addDictionaryMember( | ||
| 1291 | - "partialname", JSON::makeString(ffh.getPartialName())); | 1205 | + "parent", ffh.getObjectHandle().getKey("/Parent").getJSON(m->json_version)); |
| 1206 | + j_field.addDictionaryMember("pageposfrom1", JSON::makeInt(pagepos1)); | ||
| 1207 | + j_field.addDictionaryMember("fieldtype", JSON::makeString(ffh.getFieldType())); | ||
| 1208 | + j_field.addDictionaryMember("fieldflags", JSON::makeInt(ffh.getFlags())); | ||
| 1209 | + j_field.addDictionaryMember("fullname", JSON::makeString(ffh.getFullyQualifiedName())); | ||
| 1210 | + j_field.addDictionaryMember("partialname", JSON::makeString(ffh.getPartialName())); | ||
| 1292 | j_field.addDictionaryMember( | 1211 | j_field.addDictionaryMember( |
| 1293 | "alternativename", JSON::makeString(ffh.getAlternativeName())); | 1212 | "alternativename", JSON::makeString(ffh.getAlternativeName())); |
| 1294 | - j_field.addDictionaryMember( | ||
| 1295 | - "mappingname", JSON::makeString(ffh.getMappingName())); | ||
| 1296 | - j_field.addDictionaryMember( | ||
| 1297 | - "value", ffh.getValue().getJSON(m->json_version)); | 1213 | + j_field.addDictionaryMember("mappingname", JSON::makeString(ffh.getMappingName())); |
| 1214 | + j_field.addDictionaryMember("value", ffh.getValue().getJSON(m->json_version)); | ||
| 1298 | j_field.addDictionaryMember( | 1215 | j_field.addDictionaryMember( |
| 1299 | "defaultvalue", ffh.getDefaultValue().getJSON(m->json_version)); | 1216 | "defaultvalue", ffh.getDefaultValue().getJSON(m->json_version)); |
| 1300 | - j_field.addDictionaryMember( | ||
| 1301 | - "quadding", JSON::makeInt(ffh.getQuadding())); | ||
| 1302 | - j_field.addDictionaryMember( | ||
| 1303 | - "ischeckbox", JSON::makeBool(ffh.isCheckbox())); | ||
| 1304 | - j_field.addDictionaryMember( | ||
| 1305 | - "isradiobutton", JSON::makeBool(ffh.isRadioButton())); | ||
| 1306 | - j_field.addDictionaryMember( | ||
| 1307 | - "ischoice", JSON::makeBool(ffh.isChoice())); | 1217 | + j_field.addDictionaryMember("quadding", JSON::makeInt(ffh.getQuadding())); |
| 1218 | + j_field.addDictionaryMember("ischeckbox", JSON::makeBool(ffh.isCheckbox())); | ||
| 1219 | + j_field.addDictionaryMember("isradiobutton", JSON::makeBool(ffh.isRadioButton())); | ||
| 1220 | + j_field.addDictionaryMember("ischoice", JSON::makeBool(ffh.isChoice())); | ||
| 1308 | j_field.addDictionaryMember("istext", JSON::makeBool(ffh.isText())); | 1221 | j_field.addDictionaryMember("istext", JSON::makeBool(ffh.isText())); |
| 1309 | - JSON j_choices = | ||
| 1310 | - j_field.addDictionaryMember("choices", JSON::makeArray()); | 1222 | + JSON j_choices = j_field.addDictionaryMember("choices", JSON::makeArray()); |
| 1311 | for (auto const& choice: ffh.getChoices()) { | 1223 | for (auto const& choice: ffh.getChoices()) { |
| 1312 | j_choices.addArrayElement(JSON::makeString(choice)); | 1224 | j_choices.addArrayElement(JSON::makeString(choice)); |
| 1313 | } | 1225 | } |
| 1314 | - JSON j_annot = j_field.addDictionaryMember( | ||
| 1315 | - "annotation", JSON::makeDictionary()); | ||
| 1316 | - j_annot.addDictionaryMember( | ||
| 1317 | - "object", aoh.getObjectHandle().getJSON(m->json_version)); | 1226 | + JSON j_annot = j_field.addDictionaryMember("annotation", JSON::makeDictionary()); |
| 1227 | + j_annot.addDictionaryMember("object", aoh.getObjectHandle().getJSON(m->json_version)); | ||
| 1318 | j_annot.addDictionaryMember( | 1228 | j_annot.addDictionaryMember( |
| 1319 | "appearancestate", JSON::makeString(aoh.getAppearanceState())); | 1229 | "appearancestate", JSON::makeString(aoh.getAppearanceState())); |
| 1320 | - j_annot.addDictionaryMember( | ||
| 1321 | - "annotationflags", JSON::makeInt(aoh.getFlags())); | 1230 | + j_annot.addDictionaryMember("annotationflags", JSON::makeInt(aoh.getFlags())); |
| 1322 | } | 1231 | } |
| 1323 | } | 1232 | } |
| 1324 | JSON::writeDictionaryItem(p, first, "acroform", j_acroform, 1); | 1233 | JSON::writeDictionaryItem(p, first, "acroform", j_acroform, 1); |
| @@ -1333,50 +1242,34 @@ QPDFJob::doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf) | @@ -1333,50 +1242,34 @@ QPDFJob::doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1333 | QPDF::encryption_method_e stream_method = QPDF::e_none; | 1242 | QPDF::encryption_method_e stream_method = QPDF::e_none; |
| 1334 | QPDF::encryption_method_e string_method = QPDF::e_none; | 1243 | QPDF::encryption_method_e string_method = QPDF::e_none; |
| 1335 | QPDF::encryption_method_e file_method = QPDF::e_none; | 1244 | QPDF::encryption_method_e file_method = QPDF::e_none; |
| 1336 | - bool is_encrypted = | ||
| 1337 | - pdf.isEncrypted(R, P, V, stream_method, string_method, file_method); | 1245 | + bool is_encrypted = pdf.isEncrypted(R, P, V, stream_method, string_method, file_method); |
| 1338 | JSON j_encrypt = JSON::makeDictionary(); | 1246 | JSON j_encrypt = JSON::makeDictionary(); |
| 1339 | j_encrypt.addDictionaryMember("encrypted", JSON::makeBool(is_encrypted)); | 1247 | j_encrypt.addDictionaryMember("encrypted", JSON::makeBool(is_encrypted)); |
| 1340 | j_encrypt.addDictionaryMember( | 1248 | j_encrypt.addDictionaryMember( |
| 1341 | - "userpasswordmatched", | ||
| 1342 | - JSON::makeBool(is_encrypted && pdf.userPasswordMatched())); | 1249 | + "userpasswordmatched", JSON::makeBool(is_encrypted && pdf.userPasswordMatched())); |
| 1343 | j_encrypt.addDictionaryMember( | 1250 | j_encrypt.addDictionaryMember( |
| 1344 | - "ownerpasswordmatched", | ||
| 1345 | - JSON::makeBool(is_encrypted && pdf.ownerPasswordMatched())); | ||
| 1346 | - if (is_encrypted && (V < 5) && pdf.ownerPasswordMatched() && | ||
| 1347 | - (!pdf.userPasswordMatched())) { | 1251 | + "ownerpasswordmatched", JSON::makeBool(is_encrypted && pdf.ownerPasswordMatched())); |
| 1252 | + if (is_encrypted && (V < 5) && pdf.ownerPasswordMatched() && (!pdf.userPasswordMatched())) { | ||
| 1348 | std::string user_password = pdf.getTrimmedUserPassword(); | 1253 | std::string user_password = pdf.getTrimmedUserPassword(); |
| 1349 | - j_encrypt.addDictionaryMember( | ||
| 1350 | - "recovereduserpassword", JSON::makeString(user_password)); | 1254 | + j_encrypt.addDictionaryMember("recovereduserpassword", JSON::makeString(user_password)); |
| 1351 | } else { | 1255 | } else { |
| 1352 | - j_encrypt.addDictionaryMember( | ||
| 1353 | - "recovereduserpassword", JSON::makeNull()); | ||
| 1354 | - } | ||
| 1355 | - JSON j_capabilities = | ||
| 1356 | - j_encrypt.addDictionaryMember("capabilities", JSON::makeDictionary()); | ||
| 1357 | - j_capabilities.addDictionaryMember( | ||
| 1358 | - "accessibility", JSON::makeBool(pdf.allowAccessibility())); | ||
| 1359 | - j_capabilities.addDictionaryMember( | ||
| 1360 | - "extract", JSON::makeBool(pdf.allowExtractAll())); | ||
| 1361 | - j_capabilities.addDictionaryMember( | ||
| 1362 | - "printlow", JSON::makeBool(pdf.allowPrintLowRes())); | ||
| 1363 | - j_capabilities.addDictionaryMember( | ||
| 1364 | - "printhigh", JSON::makeBool(pdf.allowPrintHighRes())); | ||
| 1365 | - j_capabilities.addDictionaryMember( | ||
| 1366 | - "modifyassembly", JSON::makeBool(pdf.allowModifyAssembly())); | ||
| 1367 | - j_capabilities.addDictionaryMember( | ||
| 1368 | - "modifyforms", JSON::makeBool(pdf.allowModifyForm())); | 1256 | + j_encrypt.addDictionaryMember("recovereduserpassword", JSON::makeNull()); |
| 1257 | + } | ||
| 1258 | + JSON j_capabilities = j_encrypt.addDictionaryMember("capabilities", JSON::makeDictionary()); | ||
| 1259 | + j_capabilities.addDictionaryMember("accessibility", JSON::makeBool(pdf.allowAccessibility())); | ||
| 1260 | + j_capabilities.addDictionaryMember("extract", JSON::makeBool(pdf.allowExtractAll())); | ||
| 1261 | + j_capabilities.addDictionaryMember("printlow", JSON::makeBool(pdf.allowPrintLowRes())); | ||
| 1262 | + j_capabilities.addDictionaryMember("printhigh", JSON::makeBool(pdf.allowPrintHighRes())); | ||
| 1263 | + j_capabilities.addDictionaryMember("modifyassembly", JSON::makeBool(pdf.allowModifyAssembly())); | ||
| 1264 | + j_capabilities.addDictionaryMember("modifyforms", JSON::makeBool(pdf.allowModifyForm())); | ||
| 1369 | /* cSpell:ignore moddifyannotations */ | 1265 | /* cSpell:ignore moddifyannotations */ |
| 1370 | std::string MODIFY_ANNOTATIONS = | 1266 | std::string MODIFY_ANNOTATIONS = |
| 1371 | (m->json_version == 1 ? "moddifyannotations" : "modifyannotations"); | 1267 | (m->json_version == 1 ? "moddifyannotations" : "modifyannotations"); |
| 1372 | j_capabilities.addDictionaryMember( | 1268 | j_capabilities.addDictionaryMember( |
| 1373 | MODIFY_ANNOTATIONS, JSON::makeBool(pdf.allowModifyAnnotation())); | 1269 | MODIFY_ANNOTATIONS, JSON::makeBool(pdf.allowModifyAnnotation())); |
| 1374 | - j_capabilities.addDictionaryMember( | ||
| 1375 | - "modifyother", JSON::makeBool(pdf.allowModifyOther())); | ||
| 1376 | - j_capabilities.addDictionaryMember( | ||
| 1377 | - "modify", JSON::makeBool(pdf.allowModifyAll())); | ||
| 1378 | - JSON j_parameters = | ||
| 1379 | - j_encrypt.addDictionaryMember("parameters", JSON::makeDictionary()); | 1270 | + j_capabilities.addDictionaryMember("modifyother", JSON::makeBool(pdf.allowModifyOther())); |
| 1271 | + j_capabilities.addDictionaryMember("modify", JSON::makeBool(pdf.allowModifyAll())); | ||
| 1272 | + JSON j_parameters = j_encrypt.addDictionaryMember("parameters", JSON::makeDictionary()); | ||
| 1380 | j_parameters.addDictionaryMember("R", JSON::makeInt(R)); | 1273 | j_parameters.addDictionaryMember("R", JSON::makeInt(R)); |
| 1381 | j_parameters.addDictionaryMember("V", JSON::makeInt(V)); | 1274 | j_parameters.addDictionaryMember("V", JSON::makeInt(V)); |
| 1382 | j_parameters.addDictionaryMember("P", JSON::makeInt(P)); | 1275 | j_parameters.addDictionaryMember("P", JSON::makeInt(P)); |
| @@ -1408,14 +1301,10 @@ QPDFJob::doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf) | @@ -1408,14 +1301,10 @@ QPDFJob::doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1408 | } else { | 1301 | } else { |
| 1409 | s_overall_method = "mixed"; | 1302 | s_overall_method = "mixed"; |
| 1410 | } | 1303 | } |
| 1411 | - j_parameters.addDictionaryMember( | ||
| 1412 | - "method", JSON::makeString(s_overall_method)); | ||
| 1413 | - j_parameters.addDictionaryMember( | ||
| 1414 | - "streammethod", JSON::makeString(s_stream_method)); | ||
| 1415 | - j_parameters.addDictionaryMember( | ||
| 1416 | - "stringmethod", JSON::makeString(s_string_method)); | ||
| 1417 | - j_parameters.addDictionaryMember( | ||
| 1418 | - "filemethod", JSON::makeString(s_file_method)); | 1304 | + j_parameters.addDictionaryMember("method", JSON::makeString(s_overall_method)); |
| 1305 | + j_parameters.addDictionaryMember("streammethod", JSON::makeString(s_stream_method)); | ||
| 1306 | + j_parameters.addDictionaryMember("stringmethod", JSON::makeString(s_string_method)); | ||
| 1307 | + j_parameters.addDictionaryMember("filemethod", JSON::makeString(s_file_method)); | ||
| 1419 | JSON::writeDictionaryItem(p, first, "encrypt", j_encrypt, 1); | 1308 | JSON::writeDictionaryItem(p, first, "encrypt", j_encrypt, 1); |
| 1420 | } | 1309 | } |
| 1421 | 1310 | ||
| @@ -1443,39 +1332,28 @@ QPDFJob::doJSONAttachments(Pipeline* p, bool& first, QPDF& pdf) | @@ -1443,39 +1332,28 @@ QPDFJob::doJSONAttachments(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1443 | for (auto const& iter: efdh.getEmbeddedFiles()) { | 1332 | for (auto const& iter: efdh.getEmbeddedFiles()) { |
| 1444 | std::string const& key = iter.first; | 1333 | std::string const& key = iter.first; |
| 1445 | auto fsoh = iter.second; | 1334 | auto fsoh = iter.second; |
| 1446 | - auto j_details = | ||
| 1447 | - j_attachments.addDictionaryMember(key, JSON::makeDictionary()); | 1335 | + auto j_details = j_attachments.addDictionaryMember(key, JSON::makeDictionary()); |
| 1448 | j_details.addDictionaryMember( | 1336 | j_details.addDictionaryMember( |
| 1449 | "filespec", JSON::makeString(fsoh->getObjectHandle().unparse())); | 1337 | "filespec", JSON::makeString(fsoh->getObjectHandle().unparse())); |
| 1338 | + j_details.addDictionaryMember("preferredname", JSON::makeString(fsoh->getFilename())); | ||
| 1450 | j_details.addDictionaryMember( | 1339 | j_details.addDictionaryMember( |
| 1451 | - "preferredname", JSON::makeString(fsoh->getFilename())); | ||
| 1452 | - j_details.addDictionaryMember( | ||
| 1453 | - "preferredcontents", | ||
| 1454 | - JSON::makeString(fsoh->getEmbeddedFileStream().unparse())); | ||
| 1455 | - j_details.addDictionaryMember( | ||
| 1456 | - "description", null_or_string(fsoh->getDescription())); | ||
| 1457 | - auto j_names = | ||
| 1458 | - j_details.addDictionaryMember("names", JSON::makeDictionary()); | 1340 | + "preferredcontents", JSON::makeString(fsoh->getEmbeddedFileStream().unparse())); |
| 1341 | + j_details.addDictionaryMember("description", null_or_string(fsoh->getDescription())); | ||
| 1342 | + auto j_names = j_details.addDictionaryMember("names", JSON::makeDictionary()); | ||
| 1459 | for (auto const& i2: fsoh->getFilenames()) { | 1343 | for (auto const& i2: fsoh->getFilenames()) { |
| 1460 | j_names.addDictionaryMember(i2.first, JSON::makeString(i2.second)); | 1344 | j_names.addDictionaryMember(i2.first, JSON::makeString(i2.second)); |
| 1461 | } | 1345 | } |
| 1462 | - auto j_streams = | ||
| 1463 | - j_details.addDictionaryMember("streams", JSON::makeDictionary()); | 1346 | + auto j_streams = j_details.addDictionaryMember("streams", JSON::makeDictionary()); |
| 1464 | for (auto i2: fsoh->getEmbeddedFileStreams().ditems()) { | 1347 | for (auto i2: fsoh->getEmbeddedFileStreams().ditems()) { |
| 1465 | auto efs = QPDFEFStreamObjectHelper(i2.second); | 1348 | auto efs = QPDFEFStreamObjectHelper(i2.second); |
| 1466 | - auto j_stream = | ||
| 1467 | - j_streams.addDictionaryMember(i2.first, JSON::makeDictionary()); | ||
| 1468 | - j_stream.addDictionaryMember( | ||
| 1469 | - "creationdate", | ||
| 1470 | - null_or_string(to_iso8601(efs.getCreationDate()))); | 1349 | + auto j_stream = j_streams.addDictionaryMember(i2.first, JSON::makeDictionary()); |
| 1471 | j_stream.addDictionaryMember( | 1350 | j_stream.addDictionaryMember( |
| 1472 | - "modificationdate", | ||
| 1473 | - null_or_string(to_iso8601(efs.getCreationDate()))); | 1351 | + "creationdate", null_or_string(to_iso8601(efs.getCreationDate()))); |
| 1474 | j_stream.addDictionaryMember( | 1352 | j_stream.addDictionaryMember( |
| 1475 | - "mimetype", null_or_string(efs.getSubtype())); | 1353 | + "modificationdate", null_or_string(to_iso8601(efs.getCreationDate()))); |
| 1354 | + j_stream.addDictionaryMember("mimetype", null_or_string(efs.getSubtype())); | ||
| 1476 | j_stream.addDictionaryMember( | 1355 | j_stream.addDictionaryMember( |
| 1477 | - "checksum", | ||
| 1478 | - null_or_string(QUtil::hex_encode(efs.getChecksum()))); | 1356 | + "checksum", null_or_string(QUtil::hex_encode(efs.getChecksum()))); |
| 1479 | } | 1357 | } |
| 1480 | } | 1358 | } |
| 1481 | JSON::writeDictionaryItem(p, first, "attachments", j_attachments, 1); | 1359 | JSON::writeDictionaryItem(p, first, "attachments", j_attachments, 1); |
| @@ -1503,8 +1381,7 @@ QPDFJob::json_schema(int json_version, std::set<std::string>* keys) | @@ -1503,8 +1381,7 @@ QPDFJob::json_schema(int json_version, std::set<std::string>* keys) | ||
| 1503 | JSON schema = JSON::makeDictionary(); | 1381 | JSON schema = JSON::makeDictionary(); |
| 1504 | schema.addDictionaryMember( | 1382 | schema.addDictionaryMember( |
| 1505 | "version", | 1383 | "version", |
| 1506 | - JSON::makeString( | ||
| 1507 | - "JSON format serial number; increased for non-compatible changes")); | 1384 | + JSON::makeString("JSON format serial number; increased for non-compatible changes")); |
| 1508 | JSON j_params = schema.addDictionaryMember("parameters", JSON::parse(R"({ | 1385 | JSON j_params = schema.addDictionaryMember("parameters", JSON::parse(R"({ |
| 1509 | "decodelevel": "decode level used to determine stream filterability" | 1386 | "decodelevel": "decode level used to determine stream filterability" |
| 1510 | })")); | 1387 | })")); |
| @@ -1521,8 +1398,7 @@ QPDFJob::json_schema(int json_version, std::set<std::string>* keys) | @@ -1521,8 +1398,7 @@ QPDFJob::json_schema(int json_version, std::set<std::string>* keys) | ||
| 1521 | })")); | 1398 | })")); |
| 1522 | } | 1399 | } |
| 1523 | if (all_keys || keys->count("objectinfo")) { | 1400 | if (all_keys || keys->count("objectinfo")) { |
| 1524 | - JSON objectinfo = | ||
| 1525 | - schema.addDictionaryMember("objectinfo", JSON::parse(R"({ | 1401 | + JSON objectinfo = schema.addDictionaryMember("objectinfo", JSON::parse(R"({ |
| 1526 | "<object-id>": { | 1402 | "<object-id>": { |
| 1527 | "stream": { | 1403 | "stream": { |
| 1528 | "filter": "if stream, its filters, otherwise null", | 1404 | "filter": "if stream, its filters, otherwise null", |
| @@ -1667,8 +1543,7 @@ QPDFJob::json_schema(int json_version, std::set<std::string>* keys) | @@ -1667,8 +1543,7 @@ QPDFJob::json_schema(int json_version, std::set<std::string>* keys) | ||
| 1667 | })")); | 1543 | })")); |
| 1668 | } | 1544 | } |
| 1669 | if (all_keys || keys->count("attachments")) { | 1545 | if (all_keys || keys->count("attachments")) { |
| 1670 | - JSON attachments = | ||
| 1671 | - schema.addDictionaryMember("attachments", JSON::parse(R"({ | 1546 | + JSON attachments = schema.addDictionaryMember("attachments", JSON::parse(R"({ |
| 1672 | "<attachment-key>": { | 1547 | "<attachment-key>": { |
| 1673 | "filespec": "object containing the file spec", | 1548 | "filespec": "object containing the file spec", |
| 1674 | "preferredcontents": "most preferred embedded file stream", | 1549 | "preferredcontents": "most preferred embedded file stream", |
| @@ -1728,8 +1603,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | @@ -1728,8 +1603,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | ||
| 1728 | // change is made to the JSON format. Clients of the JSON are to | 1603 | // change is made to the JSON format. Clients of the JSON are to |
| 1729 | // ignore unrecognized keys, so we only update the version of a | 1604 | // ignore unrecognized keys, so we only update the version of a |
| 1730 | // key disappears or if its value changes meaning. | 1605 | // key disappears or if its value changes meaning. |
| 1731 | - JSON::writeDictionaryItem( | ||
| 1732 | - p, first, "version", JSON::makeInt(m->json_version), 1); | 1606 | + JSON::writeDictionaryItem(p, first, "version", JSON::makeInt(m->json_version), 1); |
| 1733 | JSON j_params = JSON::makeDictionary(); | 1607 | JSON j_params = JSON::makeDictionary(); |
| 1734 | std::string decode_level_str; | 1608 | std::string decode_level_str; |
| 1735 | switch (m->decode_level) { | 1609 | switch (m->decode_level) { |
| @@ -1746,8 +1620,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | @@ -1746,8 +1620,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | ||
| 1746 | decode_level_str = "all"; | 1620 | decode_level_str = "all"; |
| 1747 | break; | 1621 | break; |
| 1748 | } | 1622 | } |
| 1749 | - j_params.addDictionaryMember( | ||
| 1750 | - "decodelevel", JSON::makeString(decode_level_str)); | 1623 | + j_params.addDictionaryMember("decodelevel", JSON::makeString(decode_level_str)); |
| 1751 | JSON::writeDictionaryItem(p, first, "parameters", j_params, 1); | 1624 | JSON::writeDictionaryItem(p, first, "parameters", j_params, 1); |
| 1752 | } | 1625 | } |
| 1753 | bool all_keys = m->json_keys.empty(); | 1626 | bool all_keys = m->json_keys.empty(); |
| @@ -1784,8 +1657,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | @@ -1784,8 +1657,7 @@ QPDFJob::doJSON(QPDF& pdf, Pipeline* p) | ||
| 1784 | // repairing the page tree. To see the original file with any page | 1657 | // repairing the page tree. To see the original file with any page |
| 1785 | // tree problems and the page tree not flattened, select | 1658 | // tree problems and the page tree not flattened, select |
| 1786 | // qpdf/objects/objectinfo without other keys. | 1659 | // qpdf/objects/objectinfo without other keys. |
| 1787 | - if (all_keys || m->json_keys.count("objects") || | ||
| 1788 | - m->json_keys.count("qpdf")) { | 1660 | + if (all_keys || m->json_keys.count("objects") || m->json_keys.count("qpdf")) { |
| 1789 | doJSONObjects(p, first, pdf); | 1661 | doJSONObjects(p, first, pdf); |
| 1790 | } | 1662 | } |
| 1791 | if (m->json_version == 1) { | 1663 | if (m->json_version == 1) { |
| @@ -1823,8 +1695,7 @@ QPDFJob::doInspection(QPDF& pdf) | @@ -1823,8 +1695,7 @@ QPDFJob::doInspection(QPDF& pdf) | ||
| 1823 | } | 1695 | } |
| 1824 | if (m->show_npages) { | 1696 | if (m->show_npages) { |
| 1825 | QTC::TC("qpdf", "QPDFJob npages"); | 1697 | QTC::TC("qpdf", "QPDFJob npages"); |
| 1826 | - cout << pdf.getRoot().getKey("/Pages").getKey("/Count").getIntValue() | ||
| 1827 | - << "\n"; | 1698 | + cout << pdf.getRoot().getKey("/Pages").getKey("/Count").getIntValue() << "\n"; |
| 1828 | } | 1699 | } |
| 1829 | if (m->show_encryption) { | 1700 | if (m->show_encryption) { |
| 1830 | showEncryption(pdf); | 1701 | showEncryption(pdf); |
| @@ -1917,8 +1788,7 @@ QPDFJob::doProcess( | @@ -1917,8 +1788,7 @@ QPDFJob::doProcess( | ||
| 1917 | password = ptemp.c_str(); | 1788 | password = ptemp.c_str(); |
| 1918 | } | 1789 | } |
| 1919 | } | 1790 | } |
| 1920 | - if ((password == nullptr) || empty || m->password_is_hex_key || | ||
| 1921 | - m->suppress_password_recovery) { | 1791 | + if ((password == nullptr) || empty || m->password_is_hex_key || m->suppress_password_recovery) { |
| 1922 | // There is no password, or we're not doing recovery, so just | 1792 | // There is no password, or we're not doing recovery, so just |
| 1923 | // do the normal processing with the supplied password. | 1793 | // do the normal processing with the supplied password. |
| 1924 | doProcessOnce(pdf, fn, password, empty, used_for_input, main_input); | 1794 | doProcessOnce(pdf, fn, password, empty, used_for_input, main_input); |
| @@ -1927,8 +1797,7 @@ QPDFJob::doProcess( | @@ -1927,8 +1797,7 @@ QPDFJob::doProcess( | ||
| 1927 | 1797 | ||
| 1928 | // Get a list of otherwise encoded strings. Keep in scope for this | 1798 | // Get a list of otherwise encoded strings. Keep in scope for this |
| 1929 | // method. | 1799 | // method. |
| 1930 | - std::vector<std::string> passwords_str = | ||
| 1931 | - QUtil::possible_repaired_encodings(password); | 1800 | + std::vector<std::string> passwords_str = QUtil::possible_repaired_encodings(password); |
| 1932 | // Represent to char const*, as required by the QPDF class. | 1801 | // Represent to char const*, as required by the QPDF class. |
| 1933 | std::vector<char const*> passwords; | 1802 | std::vector<char const*> passwords; |
| 1934 | for (auto const& iter: passwords_str) { | 1803 | for (auto const& iter: passwords_str) { |
| @@ -1981,15 +1850,8 @@ QPDFJob::processFile( | @@ -1981,15 +1850,8 @@ QPDFJob::processFile( | ||
| 1981 | bool main_input) | 1850 | bool main_input) |
| 1982 | { | 1851 | { |
| 1983 | auto f1 = std::mem_fn<void(char const*, char const*)>(&QPDF::processFile); | 1852 | auto f1 = std::mem_fn<void(char const*, char const*)>(&QPDF::processFile); |
| 1984 | - auto fn = | ||
| 1985 | - std::bind(f1, std::placeholders::_1, filename, std::placeholders::_2); | ||
| 1986 | - doProcess( | ||
| 1987 | - pdf, | ||
| 1988 | - fn, | ||
| 1989 | - password, | ||
| 1990 | - strcmp(filename, "") == 0, | ||
| 1991 | - used_for_input, | ||
| 1992 | - main_input); | 1853 | + auto fn = std::bind(f1, std::placeholders::_1, filename, std::placeholders::_2); |
| 1854 | + doProcess(pdf, fn, password, strcmp(filename, "") == 0, used_for_input, main_input); | ||
| 1993 | } | 1855 | } |
| 1994 | 1856 | ||
| 1995 | void | 1857 | void |
| @@ -2019,32 +1881,26 @@ QPDFJob::validateUnderOverlay(QPDF& pdf, UnderOverlay* uo) | @@ -2019,32 +1881,26 @@ QPDFJob::validateUnderOverlay(QPDF& pdf, UnderOverlay* uo) | ||
| 2019 | uo->to_pagenos = QUtil::parse_numrange(uo->to_nr.c_str(), main_npages); | 1881 | uo->to_pagenos = QUtil::parse_numrange(uo->to_nr.c_str(), main_npages); |
| 2020 | } catch (std::runtime_error& e) { | 1882 | } catch (std::runtime_error& e) { |
| 2021 | throw std::runtime_error( | 1883 | throw std::runtime_error( |
| 2022 | - "parsing numeric range for " + uo->which + | ||
| 2023 | - " \"to\" pages: " + e.what()); | 1884 | + "parsing numeric range for " + uo->which + " \"to\" pages: " + e.what()); |
| 2024 | } | 1885 | } |
| 2025 | try { | 1886 | try { |
| 2026 | if (uo->from_nr.empty()) { | 1887 | if (uo->from_nr.empty()) { |
| 2027 | QTC::TC("qpdf", "QPDFJob from_nr from repeat_nr"); | 1888 | QTC::TC("qpdf", "QPDFJob from_nr from repeat_nr"); |
| 2028 | uo->from_nr = uo->repeat_nr; | 1889 | uo->from_nr = uo->repeat_nr; |
| 2029 | } | 1890 | } |
| 2030 | - uo->from_pagenos = | ||
| 2031 | - QUtil::parse_numrange(uo->from_nr.c_str(), uo_npages); | 1891 | + uo->from_pagenos = QUtil::parse_numrange(uo->from_nr.c_str(), uo_npages); |
| 2032 | if (!uo->repeat_nr.empty()) { | 1892 | if (!uo->repeat_nr.empty()) { |
| 2033 | - uo->repeat_pagenos = | ||
| 2034 | - QUtil::parse_numrange(uo->repeat_nr.c_str(), uo_npages); | 1893 | + uo->repeat_pagenos = QUtil::parse_numrange(uo->repeat_nr.c_str(), uo_npages); |
| 2035 | } | 1894 | } |
| 2036 | } catch (std::runtime_error& e) { | 1895 | } catch (std::runtime_error& e) { |
| 2037 | throw std::runtime_error( | 1896 | throw std::runtime_error( |
| 2038 | - "parsing numeric range for " + uo->which + " file " + uo->filename + | ||
| 2039 | - ": " + e.what()); | 1897 | + "parsing numeric range for " + uo->which + " file " + uo->filename + ": " + e.what()); |
| 2040 | } | 1898 | } |
| 2041 | } | 1899 | } |
| 2042 | 1900 | ||
| 2043 | static QPDFAcroFormDocumentHelper* | 1901 | static QPDFAcroFormDocumentHelper* |
| 2044 | get_afdh_for_qpdf( | 1902 | get_afdh_for_qpdf( |
| 2045 | - std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>>& | ||
| 2046 | - afdh_map, | ||
| 2047 | - QPDF* q) | 1903 | + std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>>& afdh_map, QPDF* q) |
| 2048 | { | 1904 | { |
| 2049 | auto uid = q->getUniqueId(); | 1905 | auto uid = q->getUniqueId(); |
| 2050 | if (!afdh_map.count(uid)) { | 1906 | if (!afdh_map.count(uid)) { |
| @@ -2068,8 +1924,7 @@ QPDFJob::doUnderOverlayForPage( | @@ -2068,8 +1924,7 @@ QPDFJob::doUnderOverlayForPage( | ||
| 2068 | return ""; | 1924 | return ""; |
| 2069 | } | 1925 | } |
| 2070 | 1926 | ||
| 2071 | - std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>> | ||
| 2072 | - afdh; | 1927 | + std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>> afdh; |
| 2073 | auto make_afdh = [&](QPDFPageObjectHelper& ph) { | 1928 | auto make_afdh = [&](QPDFPageObjectHelper& ph) { |
| 2074 | QPDF& q = ph.getObjectHandle().getQPDF(); | 1929 | QPDF& q = ph.getObjectHandle().getQPDF(); |
| 2075 | return get_afdh_for_qpdf(afdh, &q); | 1930 | return get_afdh_for_qpdf(afdh, &q); |
| @@ -2085,8 +1940,7 @@ QPDFJob::doUnderOverlayForPage( | @@ -2085,8 +1940,7 @@ QPDFJob::doUnderOverlayForPage( | ||
| 2085 | }); | 1940 | }); |
| 2086 | auto from_page = pages.at(QIntC::to_size(from_pageno - 1)); | 1941 | auto from_page = pages.at(QIntC::to_size(from_pageno - 1)); |
| 2087 | if (0 == fo.count(from_pageno)) { | 1942 | if (0 == fo.count(from_pageno)) { |
| 2088 | - fo[from_pageno] = | ||
| 2089 | - pdf.copyForeignObject(from_page.getFormXObjectForPage()); | 1943 | + fo[from_pageno] = pdf.copyForeignObject(from_page.getFormXObjectForPage()); |
| 2090 | } | 1944 | } |
| 2091 | 1945 | ||
| 2092 | // If the same page is overlaid or underlaid multiple times, | 1946 | // If the same page is overlaid or underlaid multiple times, |
| @@ -2096,12 +1950,8 @@ QPDFJob::doUnderOverlayForPage( | @@ -2096,12 +1950,8 @@ QPDFJob::doUnderOverlayForPage( | ||
| 2096 | std::string name = resources.getUniqueResourceName("/Fx", min_suffix); | 1950 | std::string name = resources.getUniqueResourceName("/Fx", min_suffix); |
| 2097 | QPDFMatrix cm; | 1951 | QPDFMatrix cm; |
| 2098 | std::string new_content = dest_page.placeFormXObject( | 1952 | std::string new_content = dest_page.placeFormXObject( |
| 2099 | - fo[from_pageno], | ||
| 2100 | - name, | ||
| 2101 | - dest_page.getTrimBox().getArrayAsRectangle(), | ||
| 2102 | - cm); | ||
| 2103 | - dest_page.copyAnnotations( | ||
| 2104 | - from_page, cm, dest_afdh, make_afdh(from_page)); | 1953 | + fo[from_pageno], name, dest_page.getTrimBox().getArrayAsRectangle(), cm); |
| 1954 | + dest_page.copyAnnotations(from_page, cm, dest_afdh, make_afdh(from_page)); | ||
| 2105 | if (!new_content.empty()) { | 1955 | if (!new_content.empty()) { |
| 2106 | resources.mergeResources("<< /XObject << >> >>"_qpdf); | 1956 | resources.mergeResources("<< /XObject << >> >>"_qpdf); |
| 2107 | auto xobject = resources.getKey("/XObject"); | 1957 | auto xobject = resources.getKey("/XObject"); |
| @@ -2116,8 +1966,7 @@ QPDFJob::doUnderOverlayForPage( | @@ -2116,8 +1966,7 @@ QPDFJob::doUnderOverlayForPage( | ||
| 2116 | } | 1966 | } |
| 2117 | 1967 | ||
| 2118 | void | 1968 | void |
| 2119 | -QPDFJob::getUOPagenos( | ||
| 2120 | - QPDFJob::UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos) | 1969 | +QPDFJob::getUOPagenos(QPDFJob::UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos) |
| 2121 | { | 1970 | { |
| 2122 | size_t idx = 0; | 1971 | size_t idx = 0; |
| 2123 | size_t from_size = uo.from_pagenos.size(); | 1972 | size_t from_size = uo.from_pagenos.size(); |
| @@ -2126,8 +1975,7 @@ QPDFJob::getUOPagenos( | @@ -2126,8 +1975,7 @@ QPDFJob::getUOPagenos( | ||
| 2126 | if (idx < from_size) { | 1975 | if (idx < from_size) { |
| 2127 | pagenos[to_pageno].push_back(uo.from_pagenos.at(idx)); | 1976 | pagenos[to_pageno].push_back(uo.from_pagenos.at(idx)); |
| 2128 | } else if (repeat_size) { | 1977 | } else if (repeat_size) { |
| 2129 | - pagenos[to_pageno].push_back( | ||
| 2130 | - uo.repeat_pagenos.at((idx - from_size) % repeat_size)); | 1978 | + pagenos[to_pageno].push_back(uo.repeat_pagenos.at((idx - from_size) % repeat_size)); |
| 2131 | } | 1979 | } |
| 2132 | ++idx; | 1980 | ++idx; |
| 2133 | } | 1981 | } |
| @@ -2163,12 +2011,10 @@ QPDFJob::handleUnderOverlay(QPDF& pdf) | @@ -2163,12 +2011,10 @@ QPDFJob::handleUnderOverlay(QPDF& pdf) | ||
| 2163 | v << prefix << ": processing underlay/overlay\n"; | 2011 | v << prefix << ": processing underlay/overlay\n"; |
| 2164 | }); | 2012 | }); |
| 2165 | for (size_t i = 0; i < main_npages; ++i) { | 2013 | for (size_t i = 0; i < main_npages; ++i) { |
| 2166 | - doIfVerbose([&](Pipeline& v, std::string const& prefix) { | ||
| 2167 | - v << " page " << 1 + i << "\n"; | ||
| 2168 | - }); | 2014 | + doIfVerbose( |
| 2015 | + [&](Pipeline& v, std::string const& prefix) { v << " page " << 1 + i << "\n"; }); | ||
| 2169 | auto pageno = QIntC::to_int(i) + 1; | 2016 | auto pageno = QIntC::to_int(i) + 1; |
| 2170 | - if (!(underlay_pagenos.count(pageno) || | ||
| 2171 | - overlay_pagenos.count(pageno))) { | 2017 | + if (!(underlay_pagenos.count(pageno) || overlay_pagenos.count(pageno))) { |
| 2172 | continue; | 2018 | continue; |
| 2173 | } | 2019 | } |
| 2174 | // This code converts the original page, any underlays, and | 2020 | // This code converts the original page, any underlays, and |
| @@ -2184,19 +2030,12 @@ QPDFJob::handleUnderOverlay(QPDF& pdf) | @@ -2184,19 +2030,12 @@ QPDFJob::handleUnderOverlay(QPDF& pdf) | ||
| 2184 | // the original page, which we are going to replace. Therefore | 2030 | // the original page, which we are going to replace. Therefore |
| 2185 | // we have to explicitly copy it. | 2031 | // we have to explicitly copy it. |
| 2186 | auto content_data = this_page_fo.getRawStreamData(); | 2032 | auto content_data = this_page_fo.getRawStreamData(); |
| 2187 | - this_page_fo.replaceStreamData( | ||
| 2188 | - content_data, QPDFObjectHandle(), QPDFObjectHandle()); | ||
| 2189 | - auto resources = dest_page_oh.replaceKeyAndGetNew( | ||
| 2190 | - "/Resources", "<< /XObject << >> >>"_qpdf); | 2033 | + this_page_fo.replaceStreamData(content_data, QPDFObjectHandle(), QPDFObjectHandle()); |
| 2034 | + auto resources = | ||
| 2035 | + dest_page_oh.replaceKeyAndGetNew("/Resources", "<< /XObject << >> >>"_qpdf); | ||
| 2191 | resources.getKey("/XObject").replaceKeyAndGetNew("/Fx0", this_page_fo); | 2036 | resources.getKey("/XObject").replaceKeyAndGetNew("/Fx0", this_page_fo); |
| 2192 | auto content = doUnderOverlayForPage( | 2037 | auto content = doUnderOverlayForPage( |
| 2193 | - pdf, | ||
| 2194 | - m->underlay, | ||
| 2195 | - underlay_pagenos, | ||
| 2196 | - i, | ||
| 2197 | - underlay_fo, | ||
| 2198 | - upages, | ||
| 2199 | - dest_page); | 2038 | + pdf, m->underlay, underlay_pagenos, i, underlay_fo, upages, dest_page); |
| 2200 | content += dest_page.placeFormXObject( | 2039 | content += dest_page.placeFormXObject( |
| 2201 | this_page_fo, | 2040 | this_page_fo, |
| 2202 | "/Fx0", | 2041 | "/Fx0", |
| @@ -2231,8 +2070,7 @@ QPDFJob::addAttachments(QPDF& pdf) | @@ -2231,8 +2070,7 @@ QPDFJob::addAttachments(QPDF& pdf) | ||
| 2231 | continue; | 2070 | continue; |
| 2232 | } | 2071 | } |
| 2233 | 2072 | ||
| 2234 | - auto fs = QPDFFileSpecObjectHelper::createFileSpec( | ||
| 2235 | - pdf, to_add.filename, to_add.path); | 2073 | + auto fs = QPDFFileSpecObjectHelper::createFileSpec(pdf, to_add.filename, to_add.path); |
| 2236 | if (!to_add.description.empty()) { | 2074 | if (!to_add.description.empty()) { |
| 2237 | fs.setDescription(to_add.description); | 2075 | fs.setDescription(to_add.description); |
| 2238 | } | 2076 | } |
| @@ -2244,8 +2082,8 @@ QPDFJob::addAttachments(QPDF& pdf) | @@ -2244,8 +2082,8 @@ QPDFJob::addAttachments(QPDF& pdf) | ||
| 2244 | 2082 | ||
| 2245 | efdh.replaceEmbeddedFile(to_add.key, fs); | 2083 | efdh.replaceEmbeddedFile(to_add.key, fs); |
| 2246 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 2084 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2247 | - v << prefix << ": attached " << to_add.path << " as " | ||
| 2248 | - << to_add.filename << " with key " << to_add.key << "\n"; | 2085 | + v << prefix << ": attached " << to_add.path << " as " << to_add.filename << " with key " |
| 2086 | + << to_add.key << "\n"; | ||
| 2249 | }); | 2087 | }); |
| 2250 | } | 2088 | } |
| 2251 | 2089 | ||
| @@ -2273,28 +2111,19 @@ QPDFJob::copyAttachments(QPDF& pdf) | @@ -2273,28 +2111,19 @@ QPDFJob::copyAttachments(QPDF& pdf) | ||
| 2273 | std::vector<std::string> duplicates; | 2111 | std::vector<std::string> duplicates; |
| 2274 | for (auto const& to_copy: m->attachments_to_copy) { | 2112 | for (auto const& to_copy: m->attachments_to_copy) { |
| 2275 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 2113 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2276 | - v << prefix << ": copying attachments from " << to_copy.path | ||
| 2277 | - << "\n"; | 2114 | + v << prefix << ": copying attachments from " << to_copy.path << "\n"; |
| 2278 | }); | 2115 | }); |
| 2279 | std::unique_ptr<QPDF> other; | 2116 | std::unique_ptr<QPDF> other; |
| 2280 | - processFile( | ||
| 2281 | - other, | ||
| 2282 | - to_copy.path.c_str(), | ||
| 2283 | - to_copy.password.c_str(), | ||
| 2284 | - false, | ||
| 2285 | - false); | 2117 | + processFile(other, to_copy.path.c_str(), to_copy.password.c_str(), false, false); |
| 2286 | QPDFEmbeddedFileDocumentHelper other_efdh(*other); | 2118 | QPDFEmbeddedFileDocumentHelper other_efdh(*other); |
| 2287 | auto other_attachments = other_efdh.getEmbeddedFiles(); | 2119 | auto other_attachments = other_efdh.getEmbeddedFiles(); |
| 2288 | for (auto const& iter: other_attachments) { | 2120 | for (auto const& iter: other_attachments) { |
| 2289 | std::string new_key = to_copy.prefix + iter.first; | 2121 | std::string new_key = to_copy.prefix + iter.first; |
| 2290 | if (efdh.getEmbeddedFile(new_key)) { | 2122 | if (efdh.getEmbeddedFile(new_key)) { |
| 2291 | - duplicates.push_back( | ||
| 2292 | - "file: " + to_copy.path + ", key: " + new_key); | 2123 | + duplicates.push_back("file: " + to_copy.path + ", key: " + new_key); |
| 2293 | } else { | 2124 | } else { |
| 2294 | - auto new_fs_oh = | ||
| 2295 | - pdf.copyForeignObject(iter.second->getObjectHandle()); | ||
| 2296 | - efdh.replaceEmbeddedFile( | ||
| 2297 | - new_key, QPDFFileSpecObjectHelper(new_fs_oh)); | 2125 | + auto new_fs_oh = pdf.copyForeignObject(iter.second->getObjectHandle()); |
| 2126 | + efdh.replaceEmbeddedFile(new_key, QPDFFileSpecObjectHelper(new_fs_oh)); | ||
| 2298 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 2127 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2299 | v << " " << iter.first << " -> " << new_key << "\n"; | 2128 | v << " " << iter.first << " -> " << new_key << "\n"; |
| 2300 | }); | 2129 | }); |
| @@ -2337,8 +2166,7 @@ QPDFJob::handleTransformations(QPDF& pdf) | @@ -2337,8 +2166,7 @@ QPDFJob::handleTransformations(QPDF& pdf) | ||
| 2337 | if (m->remove_restrictions) { | 2166 | if (m->remove_restrictions) { |
| 2338 | pdf.removeSecurityRestrictions(); | 2167 | pdf.removeSecurityRestrictions(); |
| 2339 | } | 2168 | } |
| 2340 | - if (m->externalize_inline_images || | ||
| 2341 | - (m->optimize_images && (!m->keep_inline_images))) { | 2169 | + if (m->externalize_inline_images || (m->optimize_images && (!m->keep_inline_images))) { |
| 2342 | for (auto& ph: dh.getAllPages()) { | 2170 | for (auto& ph: dh.getAllPages()) { |
| 2343 | ph.externalizeInlineImages(m->ii_min_bytes); | 2171 | ph.externalizeInlineImages(m->ii_min_bytes); |
| 2344 | } | 2172 | } |
| @@ -2350,18 +2178,10 @@ QPDFJob::handleTransformations(QPDF& pdf) | @@ -2350,18 +2178,10 @@ QPDFJob::handleTransformations(QPDF& pdf) | ||
| 2350 | ph.forEachImage( | 2178 | ph.forEachImage( |
| 2351 | true, | 2179 | true, |
| 2352 | [this, pageno, &pdf]( | 2180 | [this, pageno, &pdf]( |
| 2353 | - QPDFObjectHandle& obj, | ||
| 2354 | - QPDFObjectHandle& xobj_dict, | ||
| 2355 | - std::string const& key) { | 2181 | + QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key) { |
| 2356 | auto io = std::make_unique<ImageOptimizer>( | 2182 | auto io = std::make_unique<ImageOptimizer>( |
| 2357 | - *this, | ||
| 2358 | - m->oi_min_width, | ||
| 2359 | - m->oi_min_height, | ||
| 2360 | - m->oi_min_area, | ||
| 2361 | - obj); | ||
| 2362 | - if (io->evaluate( | ||
| 2363 | - "image " + key + " on page " + | ||
| 2364 | - std::to_string(pageno))) { | 2183 | + *this, m->oi_min_width, m->oi_min_height, m->oi_min_area, obj); |
| 2184 | + if (io->evaluate("image " + key + " on page " + std::to_string(pageno))) { | ||
| 2365 | QPDFObjectHandle new_image = pdf.newStream(); | 2185 | QPDFObjectHandle new_image = pdf.newStream(); |
| 2366 | new_image.replaceDict(obj.getDict().shallowCopy()); | 2186 | new_image.replaceDict(obj.getDict().shallowCopy()); |
| 2367 | new_image.replaceStreamData( | 2187 | new_image.replaceStreamData( |
| @@ -2378,8 +2198,7 @@ QPDFJob::handleTransformations(QPDF& pdf) | @@ -2378,8 +2198,7 @@ QPDFJob::handleTransformations(QPDF& pdf) | ||
| 2378 | afdh->generateAppearancesIfNeeded(); | 2198 | afdh->generateAppearancesIfNeeded(); |
| 2379 | } | 2199 | } |
| 2380 | if (m->flatten_annotations) { | 2200 | if (m->flatten_annotations) { |
| 2381 | - dh.flattenAnnotations( | ||
| 2382 | - m->flatten_annotations_required, m->flatten_annotations_forbidden); | 2201 | + dh.flattenAnnotations(m->flatten_annotations_required, m->flatten_annotations_forbidden); |
| 2383 | } | 2202 | } |
| 2384 | if (m->coalesce_contents) { | 2203 | if (m->coalesce_contents) { |
| 2385 | for (auto& page: dh.getAllPages()) { | 2204 | for (auto& page: dh.getAllPages()) { |
| @@ -2438,8 +2257,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) | @@ -2438,8 +2257,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) | ||
| 2438 | QPDFObjGen::set nodes_seen; // loop detection | 2257 | QPDFObjGen::set nodes_seen; // loop detection |
| 2439 | 2258 | ||
| 2440 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 2259 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2441 | - v << prefix << ": " << pdf.getFilename() | ||
| 2442 | - << ": checking for shared resources\n"; | 2260 | + v << prefix << ": " << pdf.getFilename() << ": checking for shared resources\n"; |
| 2443 | }); | 2261 | }); |
| 2444 | 2262 | ||
| 2445 | std::list<QPDFObjectHandle> queue; | 2263 | std::list<QPDFObjectHandle> queue; |
| @@ -2458,8 +2276,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) | @@ -2458,8 +2276,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) | ||
| 2458 | if (dict.hasKey("/Resources")) { | 2276 | if (dict.hasKey("/Resources")) { |
| 2459 | QTC::TC("qpdf", "QPDFJob found resources in non-leaf"); | 2277 | QTC::TC("qpdf", "QPDFJob found resources in non-leaf"); |
| 2460 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 2278 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2461 | - v << " found resources in non-leaf page node " | ||
| 2462 | - << og.unparse(' ') << "\n"; | 2279 | + v << " found resources in non-leaf page node " << og.unparse(' ') << "\n"; |
| 2463 | }); | 2280 | }); |
| 2464 | return true; | 2281 | return true; |
| 2465 | } | 2282 | } |
| @@ -2474,8 +2291,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) | @@ -2474,8 +2291,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) | ||
| 2474 | if (!resources_seen.add(resources)) { | 2291 | if (!resources_seen.add(resources)) { |
| 2475 | QTC::TC("qpdf", "QPDFJob found shared resources in leaf"); | 2292 | QTC::TC("qpdf", "QPDFJob found shared resources in leaf"); |
| 2476 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 2293 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2477 | - v << " found shared resources in leaf node " | ||
| 2478 | - << og.unparse(' ') << ": " | 2294 | + v << " found shared resources in leaf node " << og.unparse(' ') << ": " |
| 2479 | << resources.getObjGen().unparse(' ') << "\n"; | 2295 | << resources.getObjGen().unparse(' ') << "\n"; |
| 2480 | }); | 2296 | }); |
| 2481 | return true; | 2297 | return true; |
| @@ -2488,8 +2304,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) | @@ -2488,8 +2304,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) | ||
| 2488 | if (!resources_seen.add(xobject)) { | 2304 | if (!resources_seen.add(xobject)) { |
| 2489 | QTC::TC("qpdf", "QPDFJob found shared xobject in leaf"); | 2305 | QTC::TC("qpdf", "QPDFJob found shared xobject in leaf"); |
| 2490 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 2306 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2491 | - v << " found shared xobject in leaf node " | ||
| 2492 | - << og.unparse(' ') << ": " | 2307 | + v << " found shared xobject in leaf node " << og.unparse(' ') << ": " |
| 2493 | << xobject.getObjGen().unparse(' ') << "\n"; | 2308 | << xobject.getObjGen().unparse(' ') << "\n"; |
| 2494 | }); | 2309 | }); |
| 2495 | return true; | 2310 | return true; |
| @@ -2531,8 +2346,7 @@ added_page(QPDF& pdf, QPDFPageObjectHelper page) | @@ -2531,8 +2346,7 @@ added_page(QPDF& pdf, QPDFPageObjectHelper page) | ||
| 2531 | } | 2346 | } |
| 2532 | 2347 | ||
| 2533 | void | 2348 | void |
| 2534 | -QPDFJob::handlePageSpecs( | ||
| 2535 | - QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_heap) | 2349 | +QPDFJob::handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_heap) |
| 2536 | { | 2350 | { |
| 2537 | // Parse all page specifications and translate them into lists of | 2351 | // Parse all page specifications and translate them into lists of |
| 2538 | // actual pages. | 2352 | // actual pages. |
| @@ -2554,13 +2368,10 @@ QPDFJob::handlePageSpecs( | @@ -2554,13 +2368,10 @@ QPDFJob::handlePageSpecs( | ||
| 2554 | filenames.insert(page_spec.filename); | 2368 | filenames.insert(page_spec.filename); |
| 2555 | } | 2369 | } |
| 2556 | m->keep_files_open = (filenames.size() <= m->keep_files_open_threshold); | 2370 | m->keep_files_open = (filenames.size() <= m->keep_files_open_threshold); |
| 2557 | - QTC::TC( | ||
| 2558 | - "qpdf", | ||
| 2559 | - "QPDFJob automatically set keep files open", | ||
| 2560 | - m->keep_files_open ? 0 : 1); | 2371 | + QTC::TC("qpdf", "QPDFJob automatically set keep files open", m->keep_files_open ? 0 : 1); |
| 2561 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { | 2372 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2562 | - v << prefix << ": selecting --keep-open-files=" | ||
| 2563 | - << (m->keep_files_open ? "y" : "n") << "\n"; | 2373 | + v << prefix << ": selecting --keep-open-files=" << (m->keep_files_open ? "y" : "n") |
| 2374 | + << "\n"; | ||
| 2564 | }); | 2375 | }); |
| 2565 | } | 2376 | } |
| 2566 | 2377 | ||
| @@ -2600,8 +2411,7 @@ QPDFJob::handlePageSpecs( | @@ -2600,8 +2411,7 @@ QPDFJob::handlePageSpecs( | ||
| 2600 | cis->stayOpen(true); | 2411 | cis->stayOpen(true); |
| 2601 | } else { | 2412 | } else { |
| 2602 | QTC::TC("qpdf", "QPDFJob keep files open y"); | 2413 | QTC::TC("qpdf", "QPDFJob keep files open y"); |
| 2603 | - FileInputSource* fis = | ||
| 2604 | - new FileInputSource(page_spec.filename.c_str()); | 2414 | + FileInputSource* fis = new FileInputSource(page_spec.filename.c_str()); |
| 2605 | is = std::shared_ptr<InputSource>(fis); | 2415 | is = std::shared_ptr<InputSource>(fis); |
| 2606 | } | 2416 | } |
| 2607 | std::unique_ptr<QPDF> qpdf_sp; | 2417 | std::unique_ptr<QPDF> qpdf_sp; |
| @@ -2618,10 +2428,7 @@ QPDFJob::handlePageSpecs( | @@ -2618,10 +2428,7 @@ QPDFJob::handlePageSpecs( | ||
| 2618 | // associated with this occurrence of the file. | 2428 | // associated with this occurrence of the file. |
| 2619 | parsed_specs.push_back( | 2429 | parsed_specs.push_back( |
| 2620 | // line-break | 2430 | // line-break |
| 2621 | - QPDFPageData( | ||
| 2622 | - page_spec.filename, | ||
| 2623 | - page_spec_qpdfs[page_spec.filename], | ||
| 2624 | - page_spec.range)); | 2431 | + QPDFPageData(page_spec.filename, page_spec_qpdfs[page_spec.filename], page_spec.range)); |
| 2625 | } | 2432 | } |
| 2626 | 2433 | ||
| 2627 | std::map<unsigned long long, bool> remove_unreferenced; | 2434 | std::map<unsigned long long, bool> remove_unreferenced; |
| @@ -2636,8 +2443,7 @@ QPDFJob::handlePageSpecs( | @@ -2636,8 +2443,7 @@ QPDFJob::handlePageSpecs( | ||
| 2636 | QPDF& other(*(iter.second)); | 2443 | QPDF& other(*(iter.second)); |
| 2637 | auto other_uuid = other.getUniqueId(); | 2444 | auto other_uuid = other.getUniqueId(); |
| 2638 | if (remove_unreferenced.count(other_uuid) == 0) { | 2445 | if (remove_unreferenced.count(other_uuid) == 0) { |
| 2639 | - remove_unreferenced[other_uuid] = | ||
| 2640 | - shouldRemoveUnreferencedResources(other); | 2446 | + remove_unreferenced[other_uuid] = shouldRemoveUnreferencedResources(other); |
| 2641 | } | 2447 | } |
| 2642 | if (cis) { | 2448 | if (cis) { |
| 2643 | cis->stayOpen(false); | 2449 | cis->stayOpen(false); |
| @@ -2676,9 +2482,7 @@ QPDFJob::handlePageSpecs( | @@ -2676,9 +2482,7 @@ QPDFJob::handlePageSpecs( | ||
| 2676 | got_pages = true; | 2482 | got_pages = true; |
| 2677 | new_parsed_specs.push_back( | 2483 | new_parsed_specs.push_back( |
| 2678 | // line-break | 2484 | // line-break |
| 2679 | - QPDFPageData( | ||
| 2680 | - page_data, | ||
| 2681 | - page_data.selected_pages.at(cur_page + j))); | 2485 | + QPDFPageData(page_data, page_data.selected_pages.at(cur_page + j))); |
| 2682 | } | 2486 | } |
| 2683 | } | 2487 | } |
| 2684 | } | 2488 | } |
| @@ -2694,8 +2498,7 @@ QPDFJob::handlePageSpecs( | @@ -2694,8 +2498,7 @@ QPDFJob::handlePageSpecs( | ||
| 2694 | std::vector<QPDFObjectHandle> new_labels; | 2498 | std::vector<QPDFObjectHandle> new_labels; |
| 2695 | bool any_page_labels = false; | 2499 | bool any_page_labels = false; |
| 2696 | int out_pageno = 0; | 2500 | int out_pageno = 0; |
| 2697 | - std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>> | ||
| 2698 | - afdh_map; | 2501 | + std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>> afdh_map; |
| 2699 | auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf); | 2502 | auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf); |
| 2700 | std::set<QPDFObjGen> referenced_fields; | 2503 | std::set<QPDFObjGen> referenced_fields; |
| 2701 | for (auto& page_data: parsed_specs) { | 2504 | for (auto& page_data: parsed_specs) { |
| @@ -2716,10 +2519,8 @@ QPDFJob::handlePageSpecs( | @@ -2716,10 +2519,8 @@ QPDFJob::handlePageSpecs( | ||
| 2716 | // Pages are specified from 1 but numbered from 0 in the | 2519 | // Pages are specified from 1 but numbered from 0 in the |
| 2717 | // vector | 2520 | // vector |
| 2718 | int pageno = pageno_iter - 1; | 2521 | int pageno = pageno_iter - 1; |
| 2719 | - pldh.getLabelsForPageRange( | ||
| 2720 | - pageno, pageno, out_pageno++, new_labels); | ||
| 2721 | - QPDFPageObjectHelper to_copy = | ||
| 2722 | - page_data.orig_pages.at(QIntC::to_size(pageno)); | 2522 | + pldh.getLabelsForPageRange(pageno, pageno, out_pageno++, new_labels); |
| 2523 | + QPDFPageObjectHelper to_copy = page_data.orig_pages.at(QIntC::to_size(pageno)); | ||
| 2723 | QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen(); | 2524 | QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen(); |
| 2724 | unsigned long long from_uuid = page_data.qpdf->getUniqueId(); | 2525 | unsigned long long from_uuid = page_data.qpdf->getUniqueId(); |
| 2725 | if (copied_pages[from_uuid].count(to_copy_og)) { | 2526 | if (copied_pages[from_uuid].count(to_copy_og)) { |
| @@ -2754,8 +2555,7 @@ QPDFJob::handlePageSpecs( | @@ -2754,8 +2555,7 @@ QPDFJob::handlePageSpecs( | ||
| 2754 | // adjusted. If we copy any page from the original file | 2555 | // adjusted. If we copy any page from the original file |
| 2755 | // more than once, that page would be in conflict with the | 2556 | // more than once, that page would be in conflict with the |
| 2756 | // previous copy of itself. | 2557 | // previous copy of itself. |
| 2757 | - if (other_afdh->hasAcroForm() && | ||
| 2758 | - ((!this_file) || (!first_copy_from_orig))) { | 2558 | + if (other_afdh->hasAcroForm() && ((!this_file) || (!first_copy_from_orig))) { |
| 2759 | if (!this_file) { | 2559 | if (!this_file) { |
| 2760 | QTC::TC("qpdf", "QPDFJob copy fields not this file"); | 2560 | QTC::TC("qpdf", "QPDFJob copy fields not this file"); |
| 2761 | } else if (!first_copy_from_orig) { | 2561 | } else if (!first_copy_from_orig) { |
| @@ -2763,10 +2563,7 @@ QPDFJob::handlePageSpecs( | @@ -2763,10 +2563,7 @@ QPDFJob::handlePageSpecs( | ||
| 2763 | } | 2563 | } |
| 2764 | try { | 2564 | try { |
| 2765 | this_afdh->fixCopiedAnnotations( | 2565 | this_afdh->fixCopiedAnnotations( |
| 2766 | - new_page, | ||
| 2767 | - to_copy.getObjectHandle(), | ||
| 2768 | - *other_afdh, | ||
| 2769 | - &referenced_fields); | 2566 | + new_page, to_copy.getObjectHandle(), *other_afdh, &referenced_fields); |
| 2770 | } catch (std::exception& e) { | 2567 | } catch (std::exception& e) { |
| 2771 | pdf.warn( | 2568 | pdf.warn( |
| 2772 | qpdf_e_damaged_pdf, | 2569 | qpdf_e_damaged_pdf, |
| @@ -2800,9 +2597,7 @@ QPDFJob::handlePageSpecs( | @@ -2800,9 +2597,7 @@ QPDFJob::handlePageSpecs( | ||
| 2800 | referenced_fields.insert(field.getObjectHandle().getObjGen()); | 2597 | referenced_fields.insert(field.getObjectHandle().getObjGen()); |
| 2801 | } | 2598 | } |
| 2802 | } else { | 2599 | } else { |
| 2803 | - pdf.replaceObject( | ||
| 2804 | - page.getObjectHandle().getObjGen(), | ||
| 2805 | - QPDFObjectHandle::newNull()); | 2600 | + pdf.replaceObject(page.getObjectHandle().getObjGen(), QPDFObjectHandle::newNull()); |
| 2806 | } | 2601 | } |
| 2807 | } | 2602 | } |
| 2808 | // Remove unreferenced form fields | 2603 | // Remove unreferenced form fields |
| @@ -2843,8 +2638,7 @@ QPDFJob::handleRotations(QPDF& pdf) | @@ -2843,8 +2638,7 @@ QPDFJob::handleRotations(QPDF& pdf) | ||
| 2843 | for (int pageno_iter: QUtil::parse_numrange(range.c_str(), npages)) { | 2638 | for (int pageno_iter: QUtil::parse_numrange(range.c_str(), npages)) { |
| 2844 | int pageno = pageno_iter - 1; | 2639 | int pageno = pageno_iter - 1; |
| 2845 | if ((pageno >= 0) && (pageno < npages)) { | 2640 | if ((pageno >= 0) && (pageno < npages)) { |
| 2846 | - pages.at(QIntC::to_size(pageno)) | ||
| 2847 | - .rotatePage(rspec.angle, rspec.relative); | 2641 | + pages.at(QIntC::to_size(pageno)).rotatePage(rspec.angle, rspec.relative); |
| 2848 | } | 2642 | } |
| 2849 | } | 2643 | } |
| 2850 | } | 2644 | } |
| @@ -2869,24 +2663,21 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password) | @@ -2869,24 +2663,21 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password) | ||
| 2869 | bool has_8bit_chars; | 2663 | bool has_8bit_chars; |
| 2870 | bool is_valid_utf8; | 2664 | bool is_valid_utf8; |
| 2871 | bool is_utf16; | 2665 | bool is_utf16; |
| 2872 | - QUtil::analyze_encoding( | ||
| 2873 | - password, has_8bit_chars, is_valid_utf8, is_utf16); | 2666 | + QUtil::analyze_encoding(password, has_8bit_chars, is_valid_utf8, is_utf16); |
| 2874 | if (!has_8bit_chars) { | 2667 | if (!has_8bit_chars) { |
| 2875 | return; | 2668 | return; |
| 2876 | } | 2669 | } |
| 2877 | if (m->password_mode == QPDFJob::pm_unicode) { | 2670 | if (m->password_mode == QPDFJob::pm_unicode) { |
| 2878 | if (!is_valid_utf8) { | 2671 | if (!is_valid_utf8) { |
| 2879 | QTC::TC("qpdf", "QPDFJob password not unicode"); | 2672 | QTC::TC("qpdf", "QPDFJob password not unicode"); |
| 2880 | - throw std::runtime_error( | ||
| 2881 | - "supplied password is not valid UTF-8"); | 2673 | + throw std::runtime_error("supplied password is not valid UTF-8"); |
| 2882 | } | 2674 | } |
| 2883 | if (R < 5) { | 2675 | if (R < 5) { |
| 2884 | std::string encoded; | 2676 | std::string encoded; |
| 2885 | if (!QUtil::utf8_to_pdf_doc(password, encoded)) { | 2677 | if (!QUtil::utf8_to_pdf_doc(password, encoded)) { |
| 2886 | QTC::TC("qpdf", "QPDFJob password not encodable"); | 2678 | QTC::TC("qpdf", "QPDFJob password not encodable"); |
| 2887 | - throw std::runtime_error( | ||
| 2888 | - "supplied password cannot be encoded for" | ||
| 2889 | - " 40-bit or 128-bit encryption formats"); | 2679 | + throw std::runtime_error("supplied password cannot be encoded for" |
| 2680 | + " 40-bit or 128-bit encryption formats"); | ||
| 2890 | } | 2681 | } |
| 2891 | password = encoded; | 2682 | password = encoded; |
| 2892 | } | 2683 | } |
| @@ -2895,8 +2686,7 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password) | @@ -2895,8 +2686,7 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password) | ||
| 2895 | std::string encoded; | 2686 | std::string encoded; |
| 2896 | if (QUtil::utf8_to_pdf_doc(password, encoded)) { | 2687 | if (QUtil::utf8_to_pdf_doc(password, encoded)) { |
| 2897 | QTC::TC("qpdf", "QPDFJob auto-encode password"); | 2688 | QTC::TC("qpdf", "QPDFJob auto-encode password"); |
| 2898 | - doIfVerbose([&](Pipeline& v, | ||
| 2899 | - std::string const& prefix) { | 2689 | + doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2900 | v << prefix << ": automatically converting Unicode" | 2690 | v << prefix << ": automatically converting Unicode" |
| 2901 | << " password to single-byte encoding as" | 2691 | << " password to single-byte encoding as" |
| 2902 | << " required for 40-bit or 128-bit" | 2692 | << " required for 40-bit or 128-bit" |
| @@ -2905,25 +2695,23 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password) | @@ -2905,25 +2695,23 @@ QPDFJob::maybeFixWritePassword(int R, std::string& password) | ||
| 2905 | password = encoded; | 2695 | password = encoded; |
| 2906 | } else { | 2696 | } else { |
| 2907 | QTC::TC("qpdf", "QPDFJob bytes fallback warning"); | 2697 | QTC::TC("qpdf", "QPDFJob bytes fallback warning"); |
| 2908 | - *m->log->getError() | ||
| 2909 | - << m->message_prefix << ": WARNING: " | ||
| 2910 | - << "supplied password looks like a Unicode" | ||
| 2911 | - << " password with characters not allowed in" | ||
| 2912 | - << " passwords for 40-bit and 128-bit " | ||
| 2913 | - "encryption;" | ||
| 2914 | - << " most readers will not be able to open this" | ||
| 2915 | - << " file with the supplied password." | ||
| 2916 | - << " (Use --password-mode=bytes to suppress " | ||
| 2917 | - "this" | ||
| 2918 | - << " warning and use the password anyway.)\n"; | 2698 | + *m->log->getError() << m->message_prefix << ": WARNING: " |
| 2699 | + << "supplied password looks like a Unicode" | ||
| 2700 | + << " password with characters not allowed in" | ||
| 2701 | + << " passwords for 40-bit and 128-bit " | ||
| 2702 | + "encryption;" | ||
| 2703 | + << " most readers will not be able to open this" | ||
| 2704 | + << " file with the supplied password." | ||
| 2705 | + << " (Use --password-mode=bytes to suppress " | ||
| 2706 | + "this" | ||
| 2707 | + << " warning and use the password anyway.)\n"; | ||
| 2919 | } | 2708 | } |
| 2920 | } else if ((R >= 5) && (!is_valid_utf8)) { | 2709 | } else if ((R >= 5) && (!is_valid_utf8)) { |
| 2921 | QTC::TC("qpdf", "QPDFJob invalid utf-8 in auto"); | 2710 | QTC::TC("qpdf", "QPDFJob invalid utf-8 in auto"); |
| 2922 | - throw std::runtime_error( | ||
| 2923 | - "supplied password is not a valid Unicode password," | ||
| 2924 | - " which is required for 256-bit encryption; to" | ||
| 2925 | - " really use this password, rerun with the" | ||
| 2926 | - " --password-mode=bytes option"); | 2711 | + throw std::runtime_error("supplied password is not a valid Unicode password," |
| 2712 | + " which is required for 256-bit encryption; to" | ||
| 2713 | + " really use this password, rerun with the" | ||
| 2714 | + " --password-mode=bytes option"); | ||
| 2927 | } | 2715 | } |
| 2928 | } | 2716 | } |
| 2929 | } | 2717 | } |
| @@ -2953,28 +2741,25 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w) | @@ -2953,28 +2741,25 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w) | ||
| 2953 | throw std::logic_error("bad encryption keylen"); | 2741 | throw std::logic_error("bad encryption keylen"); |
| 2954 | } | 2742 | } |
| 2955 | if ((R > 3) && (m->r3_accessibility == false)) { | 2743 | if ((R > 3) && (m->r3_accessibility == false)) { |
| 2956 | - *m->log->getError() | ||
| 2957 | - << m->message_prefix << ": -accessibility=n is ignored for modern" | ||
| 2958 | - << " encryption formats\n"; | 2744 | + *m->log->getError() << m->message_prefix << ": -accessibility=n is ignored for modern" |
| 2745 | + << " encryption formats\n"; | ||
| 2959 | } | 2746 | } |
| 2960 | maybeFixWritePassword(R, m->user_password); | 2747 | maybeFixWritePassword(R, m->user_password); |
| 2961 | maybeFixWritePassword(R, m->owner_password); | 2748 | maybeFixWritePassword(R, m->owner_password); |
| 2962 | if ((R < 4) || ((R == 4) && (!m->use_aes))) { | 2749 | if ((R < 4) || ((R == 4) && (!m->use_aes))) { |
| 2963 | if (!m->allow_weak_crypto) { | 2750 | if (!m->allow_weak_crypto) { |
| 2964 | QTC::TC("qpdf", "QPDFJob weak crypto error"); | 2751 | QTC::TC("qpdf", "QPDFJob weak crypto error"); |
| 2965 | - *m->log->getError() | ||
| 2966 | - << m->message_prefix | ||
| 2967 | - << ": refusing to write a file with RC4, a weak " | ||
| 2968 | - "cryptographic " | ||
| 2969 | - "algorithm\n" | ||
| 2970 | - << "Please use 256-bit keys for better security.\n" | ||
| 2971 | - << "Pass --allow-weak-crypto to enable writing insecure " | ||
| 2972 | - "files.\n" | ||
| 2973 | - << "See also " | ||
| 2974 | - "https://qpdf.readthedocs.io/en/stable/" | ||
| 2975 | - "weak-crypto.html\n"; | ||
| 2976 | - throw std::runtime_error( | ||
| 2977 | - "refusing to write a file with weak crypto"); | 2752 | + *m->log->getError() << m->message_prefix |
| 2753 | + << ": refusing to write a file with RC4, a weak " | ||
| 2754 | + "cryptographic " | ||
| 2755 | + "algorithm\n" | ||
| 2756 | + << "Please use 256-bit keys for better security.\n" | ||
| 2757 | + << "Pass --allow-weak-crypto to enable writing insecure " | ||
| 2758 | + "files.\n" | ||
| 2759 | + << "See also " | ||
| 2760 | + "https://qpdf.readthedocs.io/en/stable/" | ||
| 2761 | + "weak-crypto.html\n"; | ||
| 2762 | + throw std::runtime_error("refusing to write a file with weak crypto"); | ||
| 2978 | } | 2763 | } |
| 2979 | } | 2764 | } |
| 2980 | switch (R) { | 2765 | switch (R) { |
| @@ -3046,10 +2831,7 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w) | @@ -3046,10 +2831,7 @@ QPDFJob::setEncryptionOptions(QPDF& pdf, QPDFWriter& w) | ||
| 3046 | } | 2831 | } |
| 3047 | 2832 | ||
| 3048 | static void | 2833 | static void |
| 3049 | -parse_version( | ||
| 3050 | - std::string const& full_version_string, | ||
| 3051 | - std::string& version, | ||
| 3052 | - int& extension_level) | 2834 | +parse_version(std::string const& full_version_string, std::string& version, int& extension_level) |
| 3053 | { | 2835 | { |
| 3054 | auto vp = QUtil::make_unique_cstr(full_version_string); | 2836 | auto vp = QUtil::make_unique_cstr(full_version_string); |
| 3055 | char* v = vp.get(); | 2837 | char* v = vp.get(); |
| @@ -3144,18 +2926,13 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w) | @@ -3144,18 +2926,13 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w) | ||
| 3144 | } | 2926 | } |
| 3145 | if (m->progress) { | 2927 | if (m->progress) { |
| 3146 | if (m->progress_handler) { | 2928 | if (m->progress_handler) { |
| 3147 | - w.registerProgressReporter( | ||
| 3148 | - std::shared_ptr<QPDFWriter::ProgressReporter>( | ||
| 3149 | - new QPDFWriter::FunctionProgressReporter( | ||
| 3150 | - m->progress_handler))); | 2929 | + w.registerProgressReporter(std::shared_ptr<QPDFWriter::ProgressReporter>( |
| 2930 | + new QPDFWriter::FunctionProgressReporter(m->progress_handler))); | ||
| 3151 | } else { | 2931 | } else { |
| 3152 | - char const* outfilename = | ||
| 3153 | - m->outfilename ? m->outfilename.get() : "standard output"; | ||
| 3154 | - w.registerProgressReporter( | ||
| 3155 | - std::shared_ptr<QPDFWriter::ProgressReporter>( | ||
| 3156 | - // line-break | ||
| 3157 | - new ProgressReporter( | ||
| 3158 | - *m->log->getInfo(), m->message_prefix, outfilename))); | 2932 | + char const* outfilename = m->outfilename ? m->outfilename.get() : "standard output"; |
| 2933 | + w.registerProgressReporter(std::shared_ptr<QPDFWriter::ProgressReporter>( | ||
| 2934 | + // line-break | ||
| 2935 | + new ProgressReporter(*m->log->getInfo(), m->message_prefix, outfilename))); | ||
| 3159 | } | 2936 | } |
| 3160 | } | 2937 | } |
| 3161 | } | 2938 | } |
| @@ -3170,14 +2947,10 @@ QPDFJob::doSplitPages(QPDF& pdf) | @@ -3170,14 +2947,10 @@ QPDFJob::doSplitPages(QPDF& pdf) | ||
| 3170 | char* num_spot = strstr(const_cast<char*>(m->outfilename.get()), "%d"); | 2947 | char* num_spot = strstr(const_cast<char*>(m->outfilename.get()), "%d"); |
| 3171 | if (num_spot != nullptr) { | 2948 | if (num_spot != nullptr) { |
| 3172 | QTC::TC("qpdf", "QPDFJob split-pages %d"); | 2949 | QTC::TC("qpdf", "QPDFJob split-pages %d"); |
| 3173 | - before = std::string( | ||
| 3174 | - m->outfilename.get(), | ||
| 3175 | - QIntC::to_size(num_spot - m->outfilename.get())); | 2950 | + before = std::string(m->outfilename.get(), QIntC::to_size(num_spot - m->outfilename.get())); |
| 3176 | after = num_spot + 2; | 2951 | after = num_spot + 2; |
| 3177 | } else if ( | 2952 | } else if ( |
| 3178 | - (len >= 4) && | ||
| 3179 | - (QUtil::str_compare_nocase(m->outfilename.get() + len - 4, ".pdf") == | ||
| 3180 | - 0)) { | 2953 | + (len >= 4) && (QUtil::str_compare_nocase(m->outfilename.get() + len - 4, ".pdf") == 0)) { |
| 3181 | QTC::TC("qpdf", "QPDFJob split-pages .pdf"); | 2954 | QTC::TC("qpdf", "QPDFJob split-pages .pdf"); |
| 3182 | before = std::string(m->outfilename.get(), len - 4) + "-"; | 2955 | before = std::string(m->outfilename.get(), len - 4) + "-"; |
| 3183 | after = m->outfilename.get() + len - 4; | 2956 | after = m->outfilename.get() + len - 4; |
| @@ -3232,24 +3005,18 @@ QPDFJob::doSplitPages(QPDF& pdf) | @@ -3232,24 +3005,18 @@ QPDFJob::doSplitPages(QPDF& pdf) | ||
| 3232 | if (pldh.hasPageLabels()) { | 3005 | if (pldh.hasPageLabels()) { |
| 3233 | std::vector<QPDFObjectHandle> labels; | 3006 | std::vector<QPDFObjectHandle> labels; |
| 3234 | pldh.getLabelsForPageRange( | 3007 | pldh.getLabelsForPageRange( |
| 3235 | - QIntC::to_longlong(first - 1), | ||
| 3236 | - QIntC::to_longlong(last - 1), | ||
| 3237 | - 0, | ||
| 3238 | - labels); | 3008 | + QIntC::to_longlong(first - 1), QIntC::to_longlong(last - 1), 0, labels); |
| 3239 | QPDFObjectHandle page_labels = QPDFObjectHandle::newDictionary(); | 3009 | QPDFObjectHandle page_labels = QPDFObjectHandle::newDictionary(); |
| 3240 | page_labels.replaceKey("/Nums", QPDFObjectHandle::newArray(labels)); | 3010 | page_labels.replaceKey("/Nums", QPDFObjectHandle::newArray(labels)); |
| 3241 | outpdf.getRoot().replaceKey("/PageLabels", page_labels); | 3011 | outpdf.getRoot().replaceKey("/PageLabels", page_labels); |
| 3242 | } | 3012 | } |
| 3243 | - std::string page_range = | ||
| 3244 | - QUtil::uint_to_string(first, QIntC::to_int(pageno_len)); | 3013 | + std::string page_range = QUtil::uint_to_string(first, QIntC::to_int(pageno_len)); |
| 3245 | if (m->split_pages > 1) { | 3014 | if (m->split_pages > 1) { |
| 3246 | - page_range += | ||
| 3247 | - "-" + QUtil::uint_to_string(last, QIntC::to_int(pageno_len)); | 3015 | + page_range += "-" + QUtil::uint_to_string(last, QIntC::to_int(pageno_len)); |
| 3248 | } | 3016 | } |
| 3249 | std::string outfile = before + page_range + after; | 3017 | std::string outfile = before + page_range + after; |
| 3250 | if (QUtil::same_file(m->infilename.get(), outfile.c_str())) { | 3018 | if (QUtil::same_file(m->infilename.get(), outfile.c_str())) { |
| 3251 | - throw std::runtime_error( | ||
| 3252 | - "split pages would overwrite input file with " + outfile); | 3019 | + throw std::runtime_error("split pages would overwrite input file with " + outfile); |
| 3253 | } | 3020 | } |
| 3254 | QPDFWriter w(outpdf, outfile.c_str()); | 3021 | QPDFWriter w(outpdf, outfile.c_str()); |
| 3255 | setWriterOptions(outpdf, w); | 3022 | setWriterOptions(outpdf, w); |
| @@ -3268,8 +3035,7 @@ QPDFJob::writeOutfile(QPDF& pdf) | @@ -3268,8 +3035,7 @@ QPDFJob::writeOutfile(QPDF& pdf) | ||
| 3268 | // Append but don't prepend to the path to generate a | 3035 | // Append but don't prepend to the path to generate a |
| 3269 | // temporary name. This saves us from having to split the path | 3036 | // temporary name. This saves us from having to split the path |
| 3270 | // by directory and non-directory. | 3037 | // by directory and non-directory. |
| 3271 | - temp_out = QUtil::make_shared_cstr( | ||
| 3272 | - std::string(m->infilename.get()) + ".~qpdf-temp#"); | 3038 | + temp_out = QUtil::make_shared_cstr(std::string(m->infilename.get()) + ".~qpdf-temp#"); |
| 3273 | // m->outfilename will be restored to 0 before temp_out | 3039 | // m->outfilename will be restored to 0 before temp_out |
| 3274 | // goes out of scope. | 3040 | // goes out of scope. |
| 3275 | m->outfilename = temp_out; | 3041 | m->outfilename = temp_out; |
| @@ -3312,17 +3078,14 @@ QPDFJob::writeOutfile(QPDF& pdf) | @@ -3312,17 +3078,14 @@ QPDFJob::writeOutfile(QPDF& pdf) | ||
| 3312 | QUtil::rename_file(m->infilename.get(), backup.c_str()); | 3078 | QUtil::rename_file(m->infilename.get(), backup.c_str()); |
| 3313 | QUtil::rename_file(temp_out.get(), m->infilename.get()); | 3079 | QUtil::rename_file(temp_out.get(), m->infilename.get()); |
| 3314 | if (warnings) { | 3080 | if (warnings) { |
| 3315 | - *m->log->getError() | ||
| 3316 | - << m->message_prefix | ||
| 3317 | - << ": there are warnings; original file kept in " << backup | ||
| 3318 | - << "\n"; | 3081 | + *m->log->getError() << m->message_prefix |
| 3082 | + << ": there are warnings; original file kept in " << backup << "\n"; | ||
| 3319 | } else { | 3083 | } else { |
| 3320 | try { | 3084 | try { |
| 3321 | QUtil::remove_file(backup.c_str()); | 3085 | QUtil::remove_file(backup.c_str()); |
| 3322 | } catch (QPDFSystemError& e) { | 3086 | } catch (QPDFSystemError& e) { |
| 3323 | *m->log->getError() | 3087 | *m->log->getError() |
| 3324 | - << m->message_prefix << ": unable to delete original file (" | ||
| 3325 | - << e.what() << ");" | 3088 | + << m->message_prefix << ": unable to delete original file (" << e.what() << ");" |
| 3326 | << " original file left in " << backup | 3089 | << " original file left in " << backup |
| 3327 | << ", but the input was successfully replaced\n"; | 3090 | << ", but the input was successfully replaced\n"; |
| 3328 | } | 3091 | } |
| @@ -3342,12 +3105,9 @@ QPDFJob::writeJSON(QPDF& pdf) | @@ -3342,12 +3105,9 @@ QPDFJob::writeJSON(QPDF& pdf) | ||
| 3342 | if (m->json_stream_prefix.empty()) { | 3105 | if (m->json_stream_prefix.empty()) { |
| 3343 | m->json_stream_prefix = m->outfilename.get(); | 3106 | m->json_stream_prefix = m->outfilename.get(); |
| 3344 | } | 3107 | } |
| 3345 | - fc = std::make_shared<QUtil::FileCloser>( | ||
| 3346 | - QUtil::safe_fopen(m->outfilename.get(), "w")); | 3108 | + fc = std::make_shared<QUtil::FileCloser>(QUtil::safe_fopen(m->outfilename.get(), "w")); |
| 3347 | fp = std::make_shared<Pl_StdioFile>("json output", fc->f); | 3109 | fp = std::make_shared<Pl_StdioFile>("json output", fc->f); |
| 3348 | - } else if ( | ||
| 3349 | - (m->json_stream_data == qpdf_sj_file) && | ||
| 3350 | - m->json_stream_prefix.empty()) { | 3110 | + } else if ((m->json_stream_data == qpdf_sj_file) && m->json_stream_prefix.empty()) { |
| 3351 | QTC::TC("qpdf", "QPDFJob need json-stream-prefix for stdout"); | 3111 | QTC::TC("qpdf", "QPDFJob need json-stream-prefix for stdout"); |
| 3352 | usage("please specify --json-stream-prefix since the input file " | 3112 | usage("please specify --json-stream-prefix since the input file " |
| 3353 | "name is unknown"); | 3113 | "name is unknown"); |
libqpdf/QPDFJob_argv.cc
| @@ -46,8 +46,7 @@ namespace | @@ -46,8 +46,7 @@ namespace | ||
| 46 | }; | 46 | }; |
| 47 | } // namespace | 47 | } // namespace |
| 48 | 48 | ||
| 49 | -ArgParser::ArgParser( | ||
| 50 | - QPDFArgParser& ap, std::shared_ptr<QPDFJob::Config> c_main) : | 49 | +ArgParser::ArgParser(QPDFArgParser& ap, std::shared_ptr<QPDFJob::Config> c_main) : |
| 51 | ap(ap), | 50 | ap(ap), |
| 52 | c_main(c_main), | 51 | c_main(c_main), |
| 53 | pages_password(nullptr), | 52 | pages_password(nullptr), |
| @@ -107,8 +106,7 @@ ArgParser::argVersion() | @@ -107,8 +106,7 @@ ArgParser::argVersion() | ||
| 107 | auto whoami = this->ap.getProgname(); | 106 | auto whoami = this->ap.getProgname(); |
| 108 | *QPDFLogger::defaultLogger()->getInfo() | 107 | *QPDFLogger::defaultLogger()->getInfo() |
| 109 | << whoami << " version " << QPDF::QPDFVersion() << "\n" | 108 | << whoami << " version " << QPDF::QPDFVersion() << "\n" |
| 110 | - << "Run " << whoami | ||
| 111 | - << " --copyright to see copyright and license information.\n"; | 109 | + << "Run " << whoami << " --copyright to see copyright and license information.\n"; |
| 112 | } | 110 | } |
| 113 | 111 | ||
| 114 | void | 112 | void |
| @@ -152,8 +150,7 @@ ArgParser::argJsonHelp(std::string const& parameter) | @@ -152,8 +150,7 @@ ArgParser::argJsonHelp(std::string const& parameter) | ||
| 152 | if ((version < 1) || (version > JSON::LATEST)) { | 150 | if ((version < 1) || (version > JSON::LATEST)) { |
| 153 | usage(std::string("unsupported json version ") + parameter); | 151 | usage(std::string("unsupported json version ") + parameter); |
| 154 | } | 152 | } |
| 155 | - *QPDFLogger::defaultLogger()->getInfo() | ||
| 156 | - << QPDFJob::json_out_schema(version) << "\n"; | 153 | + *QPDFLogger::defaultLogger()->getInfo() << QPDFJob::json_out_schema(version) << "\n"; |
| 157 | } | 154 | } |
| 158 | 155 | ||
| 159 | void | 156 | void |
| @@ -263,10 +260,7 @@ ArgParser::argPagesPositional(std::string const& arg) | @@ -263,10 +260,7 @@ ArgParser::argPagesPositional(std::string const& arg) | ||
| 263 | if (range_p == nullptr) { | 260 | if (range_p == nullptr) { |
| 264 | if (arg.empty()) { | 261 | if (arg.empty()) { |
| 265 | // The filename or password was the last argument | 262 | // The filename or password was the last argument |
| 266 | - QTC::TC( | ||
| 267 | - "qpdf", | ||
| 268 | - "QPDFJob pages range omitted at end", | ||
| 269 | - this->pages_password ? 0 : 1); | 263 | + QTC::TC("qpdf", "QPDFJob pages range omitted at end", this->pages_password ? 0 : 1); |
| 270 | } else { | 264 | } else { |
| 271 | // We need to accumulate some more arguments | 265 | // We need to accumulate some more arguments |
| 272 | return; | 266 | return; |
libqpdf/QPDFJob_config.cc
| @@ -658,8 +658,7 @@ QPDFJob::Config::passwordFile(std::string const& parameter) | @@ -658,8 +658,7 @@ QPDFJob::Config::passwordFile(std::string const& parameter) | ||
| 658 | 658 | ||
| 659 | if (lines.size() > 1) { | 659 | if (lines.size() > 1) { |
| 660 | *QPDFLogger::defaultLogger()->getError() | 660 | *QPDFLogger::defaultLogger()->getError() |
| 661 | - << this->o.m->message_prefix | ||
| 662 | - << ": WARNING: all but the first line of" | 661 | + << this->o.m->message_prefix << ": WARNING: all but the first line of" |
| 663 | << " the password file are ignored\n"; | 662 | << " the password file are ignored\n"; |
| 664 | } | 663 | } |
| 665 | } | 664 | } |
| @@ -751,8 +750,7 @@ QPDFJob::Config::removeUnreferencedResources(std::string const& parameter) | @@ -751,8 +750,7 @@ QPDFJob::Config::removeUnreferencedResources(std::string const& parameter) | ||
| 751 | QPDFJob::Config* | 750 | QPDFJob::Config* |
| 752 | QPDFJob::Config::showObject(std::string const& parameter) | 751 | QPDFJob::Config::showObject(std::string const& parameter) |
| 753 | { | 752 | { |
| 754 | - QPDFJob::parse_object_id( | ||
| 755 | - parameter, o.m->show_trailer, o.m->show_obj, o.m->show_gen); | 753 | + QPDFJob::parse_object_id(parameter, o.m->show_trailer, o.m->show_obj, o.m->show_gen); |
| 756 | o.m->require_outfile = false; | 754 | o.m->require_outfile = false; |
| 757 | return this; | 755 | return this; |
| 758 | } | 756 | } |
| @@ -761,13 +759,11 @@ QPDFJob::Config* | @@ -761,13 +759,11 @@ QPDFJob::Config* | ||
| 761 | QPDFJob::Config::jobJsonFile(std::string const& parameter) | 759 | QPDFJob::Config::jobJsonFile(std::string const& parameter) |
| 762 | { | 760 | { |
| 763 | try { | 761 | try { |
| 764 | - o.initializeFromJson( | ||
| 765 | - QUtil::read_file_into_string(parameter.c_str()), true); | 762 | + o.initializeFromJson(QUtil::read_file_into_string(parameter.c_str()), true); |
| 766 | } catch (std::exception& e) { | 763 | } catch (std::exception& e) { |
| 767 | throw std::runtime_error( | 764 | throw std::runtime_error( |
| 768 | - "error with job-json file " + std::string(parameter) + ": " + | ||
| 769 | - e.what() + "\nRun " + this->o.m->message_prefix + | ||
| 770 | - " --job-json-help for information on the file format."); | 765 | + "error with job-json file " + std::string(parameter) + ": " + e.what() + "\nRun " + |
| 766 | + this->o.m->message_prefix + " --job-json-help for information on the file format."); | ||
| 771 | } | 767 | } |
| 772 | return this; | 768 | return this; |
| 773 | } | 769 | } |
| @@ -900,8 +896,7 @@ QPDFJob::AttConfig::replace() | @@ -900,8 +896,7 @@ QPDFJob::AttConfig::replace() | ||
| 900 | QPDFJob::Config* | 896 | QPDFJob::Config* |
| 901 | QPDFJob::AttConfig::endAddAttachment() | 897 | QPDFJob::AttConfig::endAddAttachment() |
| 902 | { | 898 | { |
| 903 | - static std::string now = | ||
| 904 | - QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time()); | 899 | + static std::string now = QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time()); |
| 905 | if (this->att.path.empty()) { | 900 | if (this->att.path.empty()) { |
| 906 | usage("add attachment: no file specified"); | 901 | usage("add attachment: no file specified"); |
| 907 | } | 902 | } |
| @@ -953,8 +948,7 @@ QPDFJob::PagesConfig* | @@ -953,8 +948,7 @@ QPDFJob::PagesConfig* | ||
| 953 | QPDFJob::PagesConfig::pageSpec( | 948 | QPDFJob::PagesConfig::pageSpec( |
| 954 | std::string const& filename, std::string const& range, char const* password) | 949 | std::string const& filename, std::string const& range, char const* password) |
| 955 | { | 950 | { |
| 956 | - this->config->o.m->page_specs.push_back( | ||
| 957 | - QPDFJob::PageSpec(filename, password, range)); | 951 | + this->config->o.m->page_specs.push_back(QPDFJob::PageSpec(filename, password, range)); |
| 958 | return this; | 952 | return this; |
| 959 | } | 953 | } |
| 960 | 954 | ||
| @@ -1035,9 +1029,7 @@ QPDFJob::UOConfig::password(std::string const& parameter) | @@ -1035,9 +1029,7 @@ QPDFJob::UOConfig::password(std::string const& parameter) | ||
| 1035 | 1029 | ||
| 1036 | std::shared_ptr<QPDFJob::EncConfig> | 1030 | std::shared_ptr<QPDFJob::EncConfig> |
| 1037 | QPDFJob::Config::encrypt( | 1031 | QPDFJob::Config::encrypt( |
| 1038 | - int keylen, | ||
| 1039 | - std::string const& user_password, | ||
| 1040 | - std::string const& owner_password) | 1032 | + int keylen, std::string const& user_password, std::string const& owner_password) |
| 1041 | { | 1033 | { |
| 1042 | o.m->keylen = keylen; | 1034 | o.m->keylen = keylen; |
| 1043 | if (keylen == 256) { | 1035 | if (keylen == 256) { |
libqpdf/QPDFJob_json.cc
| @@ -125,32 +125,28 @@ Handlers::initHandlers() | @@ -125,32 +125,28 @@ Handlers::initHandlers() | ||
| 125 | void | 125 | void |
| 126 | Handlers::addBare(bare_handler_t fn) | 126 | Handlers::addBare(bare_handler_t fn) |
| 127 | { | 127 | { |
| 128 | - jh->addStringHandler( | ||
| 129 | - [this, fn](std::string const& path, std::string const& parameter) { | ||
| 130 | - if (!parameter.empty()) { | ||
| 131 | - QTC::TC("qpdf", "QPDFJob json bare not empty"); | ||
| 132 | - usage(path + ": value must be the empty string"); | ||
| 133 | - } else { | ||
| 134 | - fn(); | ||
| 135 | - } | ||
| 136 | - }); | 128 | + jh->addStringHandler([this, fn](std::string const& path, std::string const& parameter) { |
| 129 | + if (!parameter.empty()) { | ||
| 130 | + QTC::TC("qpdf", "QPDFJob json bare not empty"); | ||
| 131 | + usage(path + ": value must be the empty string"); | ||
| 132 | + } else { | ||
| 133 | + fn(); | ||
| 134 | + } | ||
| 135 | + }); | ||
| 137 | } | 136 | } |
| 138 | 137 | ||
| 139 | void | 138 | void |
| 140 | Handlers::addParameter(param_handler_t fn) | 139 | Handlers::addParameter(param_handler_t fn) |
| 141 | { | 140 | { |
| 142 | jh->addStringHandler( | 141 | jh->addStringHandler( |
| 143 | - [fn](std::string const& path, std::string const& parameter) { | ||
| 144 | - fn(parameter.c_str()); | ||
| 145 | - }); | 142 | + [fn](std::string const& path, std::string const& parameter) { fn(parameter.c_str()); }); |
| 146 | } | 143 | } |
| 147 | 144 | ||
| 148 | void | 145 | void |
| 149 | Handlers::addChoices(char const** choices, bool required, param_handler_t fn) | 146 | Handlers::addChoices(char const** choices, bool required, param_handler_t fn) |
| 150 | { | 147 | { |
| 151 | jh->addStringHandler( | 148 | jh->addStringHandler( |
| 152 | - [fn, choices, required, this]( | ||
| 153 | - std::string const& path, std::string const& parameter) { | 149 | + [fn, choices, required, this](std::string const& path, std::string const& parameter) { |
| 154 | char const* p = parameter.c_str(); | 150 | char const* p = parameter.c_str(); |
| 155 | bool matches = false; | 151 | bool matches = false; |
| 156 | if ((!required) && (parameter.empty())) { | 152 | if ((!required) && (parameter.empty())) { |
| @@ -494,8 +490,7 @@ Handlers::beginPages(JSON j) | @@ -494,8 +490,7 @@ Handlers::beginPages(JSON j) | ||
| 494 | QTC::TC("qpdf", "QPDFJob json pages no file"); | 490 | QTC::TC("qpdf", "QPDFJob json pages no file"); |
| 495 | usage("file is required in page specification"); | 491 | usage("file is required in page specification"); |
| 496 | } | 492 | } |
| 497 | - this->c_pages->pageSpec( | ||
| 498 | - file, range, password_seen ? password.c_str() : nullptr); | 493 | + this->c_pages->pageSpec(file, range, password_seen ? password.c_str() : nullptr); |
| 499 | } | 494 | } |
| 500 | 495 | ||
| 501 | void | 496 | void |
libqpdf/QPDFLogger.cc
| @@ -198,9 +198,8 @@ QPDFLogger::setSave(std::shared_ptr<Pipeline> p, bool only_if_not_set) | @@ -198,9 +198,8 @@ QPDFLogger::setSave(std::shared_ptr<Pipeline> p, bool only_if_not_set) | ||
| 198 | if (p == m->p_stdout) { | 198 | if (p == m->p_stdout) { |
| 199 | auto pt = dynamic_cast<Pl_Track*>(p.get()); | 199 | auto pt = dynamic_cast<Pl_Track*>(p.get()); |
| 200 | if (pt->getUsed()) { | 200 | if (pt->getUsed()) { |
| 201 | - throw std::logic_error( | ||
| 202 | - "QPDFLogger: called setSave on standard output after standard" | ||
| 203 | - " output has already been used"); | 201 | + throw std::logic_error("QPDFLogger: called setSave on standard output after standard" |
| 202 | + " output has already been used"); | ||
| 204 | } | 203 | } |
| 205 | if (m->p_info == m->p_stdout) { | 204 | if (m->p_info == m->p_stdout) { |
| 206 | m->p_info = m->p_stderr; | 205 | m->p_info = m->p_stderr; |
| @@ -251,8 +250,7 @@ std::shared_ptr<Pipeline> | @@ -251,8 +250,7 @@ std::shared_ptr<Pipeline> | ||
| 251 | QPDFLogger::throwIfNull(std::shared_ptr<Pipeline> p, bool null_okay) | 250 | QPDFLogger::throwIfNull(std::shared_ptr<Pipeline> p, bool null_okay) |
| 252 | { | 251 | { |
| 253 | if (!(null_okay || p)) { | 252 | if (!(null_okay || p)) { |
| 254 | - throw std::logic_error( | ||
| 255 | - "QPDFLogger: requested a null pipeline without null_okay == true"); | 253 | + throw std::logic_error("QPDFLogger: requested a null pipeline without null_okay == true"); |
| 256 | } | 254 | } |
| 257 | return p; | 255 | return p; |
| 258 | } | 256 | } |
libqpdf/QPDFMatrix.cc
| @@ -13,8 +13,7 @@ QPDFMatrix::QPDFMatrix() : | @@ -13,8 +13,7 @@ QPDFMatrix::QPDFMatrix() : | ||
| 13 | { | 13 | { |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | -QPDFMatrix::QPDFMatrix( | ||
| 17 | - double a, double b, double c, double d, double e, double f) : | 16 | +QPDFMatrix::QPDFMatrix(double a, double b, double c, double d, double e, double f) : |
| 18 | a(a), | 17 | a(a), |
| 19 | b(b), | 18 | b(b), |
| 20 | c(c), | 19 | c(c), |
| @@ -136,6 +135,6 @@ bool | @@ -136,6 +135,6 @@ bool | ||
| 136 | QPDFMatrix::operator==(QPDFMatrix const& rhs) const | 135 | QPDFMatrix::operator==(QPDFMatrix const& rhs) const |
| 137 | { | 136 | { |
| 138 | return ( | 137 | return ( |
| 139 | - (this->a == rhs.a) && (this->b == rhs.b) && (this->c == rhs.c) && | ||
| 140 | - (this->d == rhs.d) && (this->e == rhs.e) && (this->f == rhs.f)); | 138 | + (this->a == rhs.a) && (this->b == rhs.b) && (this->c == rhs.c) && (this->d == rhs.d) && |
| 139 | + (this->e == rhs.e) && (this->f == rhs.f)); | ||
| 141 | } | 140 | } |
libqpdf/QPDFNameTreeObjectHelper.cc
| @@ -41,14 +41,12 @@ QPDFNameTreeObjectHelper::~QPDFNameTreeObjectHelper() | @@ -41,14 +41,12 @@ QPDFNameTreeObjectHelper::~QPDFNameTreeObjectHelper() | ||
| 41 | // #745. | 41 | // #745. |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | -QPDFNameTreeObjectHelper::Members::Members( | ||
| 45 | - QPDFObjectHandle& oh, QPDF& q, bool auto_repair) : | 44 | +QPDFNameTreeObjectHelper::Members::Members(QPDFObjectHandle& oh, QPDF& q, bool auto_repair) : |
| 46 | impl(std::make_shared<NNTreeImpl>(name_tree_details, q, oh, auto_repair)) | 45 | impl(std::make_shared<NNTreeImpl>(name_tree_details, q, oh, auto_repair)) |
| 47 | { | 46 | { |
| 48 | } | 47 | } |
| 49 | 48 | ||
| 50 | -QPDFNameTreeObjectHelper::QPDFNameTreeObjectHelper( | ||
| 51 | - QPDFObjectHandle oh, QPDF& q, bool auto_repair) : | 49 | +QPDFNameTreeObjectHelper::QPDFNameTreeObjectHelper(QPDFObjectHandle oh, QPDF& q, bool auto_repair) : |
| 52 | QPDFObjectHelper(oh), | 50 | QPDFObjectHelper(oh), |
| 53 | m(new Members(oh, q, auto_repair)) | 51 | m(new Members(oh, q, auto_repair)) |
| 54 | { | 52 | { |
| @@ -61,8 +59,7 @@ QPDFNameTreeObjectHelper::newEmpty(QPDF& qpdf, bool auto_repair) | @@ -61,8 +59,7 @@ QPDFNameTreeObjectHelper::newEmpty(QPDF& qpdf, bool auto_repair) | ||
| 61 | qpdf.makeIndirectObject("<< /Names [] >>"_qpdf), qpdf, auto_repair); | 59 | qpdf.makeIndirectObject("<< /Names [] >>"_qpdf), qpdf, auto_repair); |
| 62 | } | 60 | } |
| 63 | 61 | ||
| 64 | -QPDFNameTreeObjectHelper::iterator::iterator( | ||
| 65 | - std::shared_ptr<NNTreeIterator> const& i) : | 62 | +QPDFNameTreeObjectHelper::iterator::iterator(std::shared_ptr<NNTreeIterator> const& i) : |
| 66 | impl(i) | 63 | impl(i) |
| 67 | { | 64 | { |
| 68 | } | 65 | } |
| @@ -123,8 +120,7 @@ QPDFNameTreeObjectHelper::iterator::operator==(iterator const& other) const | @@ -123,8 +120,7 @@ QPDFNameTreeObjectHelper::iterator::operator==(iterator const& other) const | ||
| 123 | } | 120 | } |
| 124 | 121 | ||
| 125 | void | 122 | void |
| 126 | -QPDFNameTreeObjectHelper::iterator::insertAfter( | ||
| 127 | - std::string const& key, QPDFObjectHandle value) | 123 | +QPDFNameTreeObjectHelper::iterator::insertAfter(std::string const& key, QPDFObjectHandle value) |
| 128 | { | 124 | { |
| 129 | impl->insertAfter(QPDFObjectHandle::newUnicodeString(key), value); | 125 | impl->insertAfter(QPDFObjectHandle::newUnicodeString(key), value); |
| 130 | updateIValue(); | 126 | updateIValue(); |
| @@ -156,11 +152,9 @@ QPDFNameTreeObjectHelper::last() const | @@ -156,11 +152,9 @@ QPDFNameTreeObjectHelper::last() const | ||
| 156 | } | 152 | } |
| 157 | 153 | ||
| 158 | QPDFNameTreeObjectHelper::iterator | 154 | QPDFNameTreeObjectHelper::iterator |
| 159 | -QPDFNameTreeObjectHelper::find( | ||
| 160 | - std::string const& key, bool return_prev_if_not_found) | 155 | +QPDFNameTreeObjectHelper::find(std::string const& key, bool return_prev_if_not_found) |
| 161 | { | 156 | { |
| 162 | - auto i = m->impl->find( | ||
| 163 | - QPDFObjectHandle::newUnicodeString(key), return_prev_if_not_found); | 157 | + auto i = m->impl->find(QPDFObjectHandle::newUnicodeString(key), return_prev_if_not_found); |
| 164 | return iterator(std::make_shared<NNTreeIterator>(i)); | 158 | return iterator(std::make_shared<NNTreeIterator>(i)); |
| 165 | } | 159 | } |
| 166 | 160 | ||
| @@ -172,8 +166,7 @@ QPDFNameTreeObjectHelper::insert(std::string const& key, QPDFObjectHandle value) | @@ -172,8 +166,7 @@ QPDFNameTreeObjectHelper::insert(std::string const& key, QPDFObjectHandle value) | ||
| 172 | } | 166 | } |
| 173 | 167 | ||
| 174 | bool | 168 | bool |
| 175 | -QPDFNameTreeObjectHelper::remove( | ||
| 176 | - std::string const& key, QPDFObjectHandle* value) | 169 | +QPDFNameTreeObjectHelper::remove(std::string const& key, QPDFObjectHandle* value) |
| 177 | { | 170 | { |
| 178 | return m->impl->remove(QPDFObjectHandle::newUnicodeString(key), value); | 171 | return m->impl->remove(QPDFObjectHandle::newUnicodeString(key), value); |
| 179 | } | 172 | } |
| @@ -186,8 +179,7 @@ QPDFNameTreeObjectHelper::hasName(std::string const& name) | @@ -186,8 +179,7 @@ QPDFNameTreeObjectHelper::hasName(std::string const& name) | ||
| 186 | } | 179 | } |
| 187 | 180 | ||
| 188 | bool | 181 | bool |
| 189 | -QPDFNameTreeObjectHelper::findObject( | ||
| 190 | - std::string const& name, QPDFObjectHandle& oh) | 182 | +QPDFNameTreeObjectHelper::findObject(std::string const& name, QPDFObjectHandle& oh) |
| 191 | { | 183 | { |
| 192 | auto i = find(name); | 184 | auto i = find(name); |
| 193 | if (i == end()) { | 185 | if (i == end()) { |
libqpdf/QPDFNumberTreeObjectHelper.cc
| @@ -42,8 +42,7 @@ QPDFNumberTreeObjectHelper::~QPDFNumberTreeObjectHelper() | @@ -42,8 +42,7 @@ QPDFNumberTreeObjectHelper::~QPDFNumberTreeObjectHelper() | ||
| 42 | // #745. | 42 | // #745. |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | -QPDFNumberTreeObjectHelper::Members::Members( | ||
| 46 | - QPDFObjectHandle& oh, QPDF& q, bool auto_repair) : | 45 | +QPDFNumberTreeObjectHelper::Members::Members(QPDFObjectHandle& oh, QPDF& q, bool auto_repair) : |
| 47 | impl(std::make_shared<NNTreeImpl>(number_tree_details, q, oh, auto_repair)) | 46 | impl(std::make_shared<NNTreeImpl>(number_tree_details, q, oh, auto_repair)) |
| 48 | { | 47 | { |
| 49 | } | 48 | } |
| @@ -62,8 +61,7 @@ QPDFNumberTreeObjectHelper::newEmpty(QPDF& qpdf, bool auto_repair) | @@ -62,8 +61,7 @@ QPDFNumberTreeObjectHelper::newEmpty(QPDF& qpdf, bool auto_repair) | ||
| 62 | qpdf.makeIndirectObject("<< /Nums [] >>"_qpdf), qpdf, auto_repair); | 61 | qpdf.makeIndirectObject("<< /Nums [] >>"_qpdf), qpdf, auto_repair); |
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | -QPDFNumberTreeObjectHelper::iterator::iterator( | ||
| 66 | - std::shared_ptr<NNTreeIterator> const& i) : | 64 | +QPDFNumberTreeObjectHelper::iterator::iterator(std::shared_ptr<NNTreeIterator> const& i) : |
| 67 | impl(i) | 65 | impl(i) |
| 68 | { | 66 | { |
| 69 | } | 67 | } |
| @@ -124,8 +122,7 @@ QPDFNumberTreeObjectHelper::iterator::operator==(iterator const& other) const | @@ -124,8 +122,7 @@ QPDFNumberTreeObjectHelper::iterator::operator==(iterator const& other) const | ||
| 124 | } | 122 | } |
| 125 | 123 | ||
| 126 | void | 124 | void |
| 127 | -QPDFNumberTreeObjectHelper::iterator::insertAfter( | ||
| 128 | - numtree_number key, QPDFObjectHandle value) | 125 | +QPDFNumberTreeObjectHelper::iterator::insertAfter(numtree_number key, QPDFObjectHandle value) |
| 129 | { | 126 | { |
| 130 | impl->insertAfter(QPDFObjectHandle::newInteger(key), value); | 127 | impl->insertAfter(QPDFObjectHandle::newInteger(key), value); |
| 131 | updateIValue(); | 128 | updateIValue(); |
| @@ -157,11 +154,9 @@ QPDFNumberTreeObjectHelper::last() const | @@ -157,11 +154,9 @@ QPDFNumberTreeObjectHelper::last() const | ||
| 157 | } | 154 | } |
| 158 | 155 | ||
| 159 | QPDFNumberTreeObjectHelper::iterator | 156 | QPDFNumberTreeObjectHelper::iterator |
| 160 | -QPDFNumberTreeObjectHelper::find( | ||
| 161 | - numtree_number key, bool return_prev_if_not_found) | 157 | +QPDFNumberTreeObjectHelper::find(numtree_number key, bool return_prev_if_not_found) |
| 162 | { | 158 | { |
| 163 | - auto i = m->impl->find( | ||
| 164 | - QPDFObjectHandle::newInteger(key), return_prev_if_not_found); | 159 | + auto i = m->impl->find(QPDFObjectHandle::newInteger(key), return_prev_if_not_found); |
| 165 | return iterator(std::make_shared<NNTreeIterator>(i)); | 160 | return iterator(std::make_shared<NNTreeIterator>(i)); |
| 166 | } | 161 | } |
| 167 | 162 |
libqpdf/QPDFObjectHandle.cc
| @@ -56,41 +56,30 @@ QPDFObjectHandle::StreamDataProvider::~StreamDataProvider() | @@ -56,41 +56,30 @@ QPDFObjectHandle::StreamDataProvider::~StreamDataProvider() | ||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | void | 58 | void |
| 59 | -QPDFObjectHandle::StreamDataProvider::provideStreamData( | ||
| 60 | - QPDFObjGen const& og, Pipeline* pipeline) | 59 | +QPDFObjectHandle::StreamDataProvider::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) |
| 61 | { | 60 | { |
| 62 | return provideStreamData(og.getObj(), og.getGen(), pipeline); | 61 | return provideStreamData(og.getObj(), og.getGen(), pipeline); |
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | bool | 64 | bool |
| 66 | QPDFObjectHandle::StreamDataProvider::provideStreamData( | 65 | QPDFObjectHandle::StreamDataProvider::provideStreamData( |
| 67 | - QPDFObjGen const& og, | ||
| 68 | - Pipeline* pipeline, | ||
| 69 | - bool suppress_warnings, | ||
| 70 | - bool will_retry) | 66 | + QPDFObjGen const& og, Pipeline* pipeline, bool suppress_warnings, bool will_retry) |
| 71 | { | 67 | { |
| 72 | - return provideStreamData( | ||
| 73 | - og.getObj(), og.getGen(), pipeline, suppress_warnings, will_retry); | 68 | + return provideStreamData(og.getObj(), og.getGen(), pipeline, suppress_warnings, will_retry); |
| 74 | } | 69 | } |
| 75 | 70 | ||
| 76 | void | 71 | void |
| 77 | QPDFObjectHandle::StreamDataProvider::provideStreamData( | 72 | QPDFObjectHandle::StreamDataProvider::provideStreamData( |
| 78 | int objid, int generation, Pipeline* pipeline) | 73 | int objid, int generation, Pipeline* pipeline) |
| 79 | { | 74 | { |
| 80 | - throw std::logic_error( | ||
| 81 | - "you must override provideStreamData -- see QPDFObjectHandle.hh"); | 75 | + throw std::logic_error("you must override provideStreamData -- see QPDFObjectHandle.hh"); |
| 82 | } | 76 | } |
| 83 | 77 | ||
| 84 | bool | 78 | bool |
| 85 | QPDFObjectHandle::StreamDataProvider::provideStreamData( | 79 | QPDFObjectHandle::StreamDataProvider::provideStreamData( |
| 86 | - int objid, | ||
| 87 | - int generation, | ||
| 88 | - Pipeline* pipeline, | ||
| 89 | - bool suppress_warnings, | ||
| 90 | - bool will_retry) | 80 | + int objid, int generation, Pipeline* pipeline, bool suppress_warnings, bool will_retry) |
| 91 | { | 81 | { |
| 92 | - throw std::logic_error( | ||
| 93 | - "you must override provideStreamData -- see QPDFObjectHandle.hh"); | 82 | + throw std::logic_error("you must override provideStreamData -- see QPDFObjectHandle.hh"); |
| 94 | return false; | 83 | return false; |
| 95 | } | 84 | } |
| 96 | 85 | ||
| @@ -105,8 +94,7 @@ namespace | @@ -105,8 +94,7 @@ namespace | ||
| 105 | class CoalesceProvider: public QPDFObjectHandle::StreamDataProvider | 94 | class CoalesceProvider: public QPDFObjectHandle::StreamDataProvider |
| 106 | { | 95 | { |
| 107 | public: | 96 | public: |
| 108 | - CoalesceProvider( | ||
| 109 | - QPDFObjectHandle containing_page, QPDFObjectHandle old_contents) : | 97 | + CoalesceProvider(QPDFObjectHandle containing_page, QPDFObjectHandle old_contents) : |
| 110 | containing_page(containing_page), | 98 | containing_page(containing_page), |
| 111 | old_contents(old_contents) | 99 | old_contents(old_contents) |
| 112 | { | 100 | { |
| @@ -124,8 +112,7 @@ void | @@ -124,8 +112,7 @@ void | ||
| 124 | CoalesceProvider::provideStreamData(QPDFObjGen const&, Pipeline* p) | 112 | CoalesceProvider::provideStreamData(QPDFObjGen const&, Pipeline* p) |
| 125 | { | 113 | { |
| 126 | QTC::TC("qpdf", "QPDFObjectHandle coalesce provide stream data"); | 114 | QTC::TC("qpdf", "QPDFObjectHandle coalesce provide stream data"); |
| 127 | - std::string description = | ||
| 128 | - "page object " + containing_page.getObjGen().unparse(' '); | 115 | + std::string description = "page object " + containing_page.getObjGen().unparse(' '); |
| 129 | std::string all_description; | 116 | std::string all_description; |
| 130 | old_contents.pipeContentStreams(p, description, all_description); | 117 | old_contents.pipeContentStreams(p, description, all_description); |
| 131 | } | 118 | } |
| @@ -173,8 +160,7 @@ QPDFObjectHandle::ParserCallbacks::handleObject(QPDFObjectHandle) | @@ -173,8 +160,7 @@ QPDFObjectHandle::ParserCallbacks::handleObject(QPDFObjectHandle) | ||
| 173 | } | 160 | } |
| 174 | 161 | ||
| 175 | void | 162 | void |
| 176 | -QPDFObjectHandle::ParserCallbacks::handleObject( | ||
| 177 | - QPDFObjectHandle oh, size_t, size_t) | 163 | +QPDFObjectHandle::ParserCallbacks::handleObject(QPDFObjectHandle oh, size_t, size_t) |
| 178 | { | 164 | { |
| 179 | // This version of handleObject was added in qpdf 9. If the | 165 | // This version of handleObject was added in qpdf 9. If the |
| 180 | // developer did not override it, fall back to the older | 166 | // developer did not override it, fall back to the older |
| @@ -365,9 +351,7 @@ QPDFObjectHandle::isDirectNull() const | @@ -365,9 +351,7 @@ QPDFObjectHandle::isDirectNull() const | ||
| 365 | { | 351 | { |
| 366 | // Don't call dereference() -- this is a const method, and we know | 352 | // Don't call dereference() -- this is a const method, and we know |
| 367 | // objid == 0, so there's nothing to resolve. | 353 | // objid == 0, so there's nothing to resolve. |
| 368 | - return ( | ||
| 369 | - isInitialized() && (getObjectID() == 0) && | ||
| 370 | - (obj->getTypeCode() == ::ot_null)); | 354 | + return (isInitialized() && (getObjectID() == 0) && (obj->getTypeCode() == ::ot_null)); |
| 371 | } | 355 | } |
| 372 | 356 | ||
| 373 | bool | 357 | bool |
| @@ -470,8 +454,7 @@ QPDFObjectHandle::isReserved() | @@ -470,8 +454,7 @@ QPDFObjectHandle::isReserved() | ||
| 470 | bool | 454 | bool |
| 471 | QPDFObjectHandle::isScalar() | 455 | QPDFObjectHandle::isScalar() |
| 472 | { | 456 | { |
| 473 | - return isBool() || isInteger() || isName() || isNull() || isReal() || | ||
| 474 | - isString(); | 457 | + return isBool() || isInteger() || isName() || isNull() || isReal() || isString(); |
| 475 | } | 458 | } |
| 476 | 459 | ||
| 477 | bool | 460 | bool |
| @@ -481,17 +464,14 @@ QPDFObjectHandle::isNameAndEquals(std::string const& name) | @@ -481,17 +464,14 @@ QPDFObjectHandle::isNameAndEquals(std::string const& name) | ||
| 481 | } | 464 | } |
| 482 | 465 | ||
| 483 | bool | 466 | bool |
| 484 | -QPDFObjectHandle::isDictionaryOfType( | ||
| 485 | - std::string const& type, std::string const& subtype) | 467 | +QPDFObjectHandle::isDictionaryOfType(std::string const& type, std::string const& subtype) |
| 486 | { | 468 | { |
| 487 | - return isDictionary() && | ||
| 488 | - (type.empty() || getKey("/Type").isNameAndEquals(type)) && | 469 | + return isDictionary() && (type.empty() || getKey("/Type").isNameAndEquals(type)) && |
| 489 | (subtype.empty() || getKey("/Subtype").isNameAndEquals(subtype)); | 470 | (subtype.empty() || getKey("/Subtype").isNameAndEquals(subtype)); |
| 490 | } | 471 | } |
| 491 | 472 | ||
| 492 | bool | 473 | bool |
| 493 | -QPDFObjectHandle::isStreamOfType( | ||
| 494 | - std::string const& type, std::string const& subtype) | 474 | +QPDFObjectHandle::isStreamOfType(std::string const& type, std::string const& subtype) |
| 495 | { | 475 | { |
| 496 | return isStream() && getDict().isDictionaryOfType(type, subtype); | 476 | return isStream() && getDict().isDictionaryOfType(type, subtype); |
| 497 | } | 477 | } |
| @@ -555,13 +535,11 @@ QPDFObjectHandle::getIntValueAsInt() | @@ -555,13 +535,11 @@ QPDFObjectHandle::getIntValueAsInt() | ||
| 555 | long long v = getIntValue(); | 535 | long long v = getIntValue(); |
| 556 | if (v < INT_MIN) { | 536 | if (v < INT_MIN) { |
| 557 | QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MIN"); | 537 | QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MIN"); |
| 558 | - warnIfPossible( | ||
| 559 | - "requested value of integer is too small; returning INT_MIN"); | 538 | + warnIfPossible("requested value of integer is too small; returning INT_MIN"); |
| 560 | result = INT_MIN; | 539 | result = INT_MIN; |
| 561 | } else if (v > INT_MAX) { | 540 | } else if (v > INT_MAX) { |
| 562 | QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MAX"); | 541 | QTC::TC("qpdf", "QPDFObjectHandle int returning INT_MAX"); |
| 563 | - warnIfPossible( | ||
| 564 | - "requested value of integer is too big; returning INT_MAX"); | 542 | + warnIfPossible("requested value of integer is too big; returning INT_MAX"); |
| 565 | result = INT_MAX; | 543 | result = INT_MAX; |
| 566 | } else { | 544 | } else { |
| 567 | result = static_cast<int>(v); | 545 | result = static_cast<int>(v); |
| @@ -586,8 +564,7 @@ QPDFObjectHandle::getUIntValue() | @@ -586,8 +564,7 @@ QPDFObjectHandle::getUIntValue() | ||
| 586 | long long v = getIntValue(); | 564 | long long v = getIntValue(); |
| 587 | if (v < 0) { | 565 | if (v < 0) { |
| 588 | QTC::TC("qpdf", "QPDFObjectHandle uint returning 0"); | 566 | QTC::TC("qpdf", "QPDFObjectHandle uint returning 0"); |
| 589 | - warnIfPossible( | ||
| 590 | - "unsigned value request for negative number; returning 0"); | 567 | + warnIfPossible("unsigned value request for negative number; returning 0"); |
| 591 | } else { | 568 | } else { |
| 592 | result = static_cast<unsigned long long>(v); | 569 | result = static_cast<unsigned long long>(v); |
| 593 | } | 570 | } |
| @@ -611,8 +588,7 @@ QPDFObjectHandle::getUIntValueAsUInt() | @@ -611,8 +588,7 @@ QPDFObjectHandle::getUIntValueAsUInt() | ||
| 611 | long long v = getIntValue(); | 588 | long long v = getIntValue(); |
| 612 | if (v < 0) { | 589 | if (v < 0) { |
| 613 | QTC::TC("qpdf", "QPDFObjectHandle uint uint returning 0"); | 590 | QTC::TC("qpdf", "QPDFObjectHandle uint uint returning 0"); |
| 614 | - warnIfPossible( | ||
| 615 | - "unsigned integer value request for negative number; returning 0"); | 591 | + warnIfPossible("unsigned integer value request for negative number; returning 0"); |
| 616 | result = 0; | 592 | result = 0; |
| 617 | } else if (v > UINT_MAX) { | 593 | } else if (v > UINT_MAX) { |
| 618 | QTC::TC("qpdf", "QPDFObjectHandle uint returning UINT_MAX"); | 594 | QTC::TC("qpdf", "QPDFObjectHandle uint returning UINT_MAX"); |
| @@ -878,8 +854,7 @@ QPDFObjectHandle::getArrayAsMatrix() | @@ -878,8 +854,7 @@ QPDFObjectHandle::getArrayAsMatrix() | ||
| 878 | return {}; | 854 | return {}; |
| 879 | } | 855 | } |
| 880 | } | 856 | } |
| 881 | - return Matrix( | ||
| 882 | - items[0], items[1], items[2], items[3], items[4], items[5]); | 857 | + return Matrix(items[0], items[1], items[2], items[3], items[4], items[5]); |
| 883 | } | 858 | } |
| 884 | return {}; | 859 | return {}; |
| 885 | } | 860 | } |
| @@ -928,8 +903,7 @@ QPDFObjectHandle::insertItem(int at, QPDFObjectHandle const& item) | @@ -928,8 +903,7 @@ QPDFObjectHandle::insertItem(int at, QPDFObjectHandle const& item) | ||
| 928 | { | 903 | { |
| 929 | if (auto array = asArray()) { | 904 | if (auto array = asArray()) { |
| 930 | if (!array->insert(at, item)) { | 905 | if (!array->insert(at, item)) { |
| 931 | - objectWarning( | ||
| 932 | - "ignoring attempt to insert out of bounds array item"); | 906 | + objectWarning("ignoring attempt to insert out of bounds array item"); |
| 933 | QTC::TC("qpdf", "QPDFObjectHandle insert array bounds"); | 907 | QTC::TC("qpdf", "QPDFObjectHandle insert array bounds"); |
| 934 | } | 908 | } |
| 935 | } else { | 909 | } else { |
| @@ -981,8 +955,7 @@ QPDFObjectHandle | @@ -981,8 +955,7 @@ QPDFObjectHandle | ||
| 981 | QPDFObjectHandle::eraseItemAndGetOld(int at) | 955 | QPDFObjectHandle::eraseItemAndGetOld(int at) |
| 982 | { | 956 | { |
| 983 | auto array = asArray(); | 957 | auto array = asArray(); |
| 984 | - auto result = | ||
| 985 | - (array && at < array->size() && at >= 0) ? array->at(at) : newNull(); | 958 | + auto result = (array && at < array->size() && at >= 0) ? array->at(at) : newNull(); |
| 986 | eraseItem(at); | 959 | eraseItem(at); |
| 987 | return result; | 960 | return result; |
| 988 | } | 961 | } |
| @@ -1002,8 +975,7 @@ QPDFObjectHandle::hasKey(std::string const& key) | @@ -1002,8 +975,7 @@ QPDFObjectHandle::hasKey(std::string const& key) | ||
| 1002 | if (dict) { | 975 | if (dict) { |
| 1003 | return dict->hasKey(key); | 976 | return dict->hasKey(key); |
| 1004 | } else { | 977 | } else { |
| 1005 | - typeWarning( | ||
| 1006 | - "dictionary", "returning false for a key containment request"); | 978 | + typeWarning("dictionary", "returning false for a key containment request"); |
| 1007 | QTC::TC("qpdf", "QPDFObjectHandle dictionary false for hasKey"); | 979 | QTC::TC("qpdf", "QPDFObjectHandle dictionary false for hasKey"); |
| 1008 | return false; | 980 | return false; |
| 1009 | } | 981 | } |
| @@ -1017,8 +989,7 @@ QPDFObjectHandle::getKey(std::string const& key) | @@ -1017,8 +989,7 @@ QPDFObjectHandle::getKey(std::string const& key) | ||
| 1017 | } else { | 989 | } else { |
| 1018 | typeWarning("dictionary", "returning null for attempted key retrieval"); | 990 | typeWarning("dictionary", "returning null for attempted key retrieval"); |
| 1019 | QTC::TC("qpdf", "QPDFObjectHandle dictionary null for getKey"); | 991 | QTC::TC("qpdf", "QPDFObjectHandle dictionary null for getKey"); |
| 1020 | - static auto constexpr msg = | ||
| 1021 | - " -> null returned from getting key $VD from non-Dictionary"sv; | 992 | + static auto constexpr msg = " -> null returned from getting key $VD from non-Dictionary"sv; |
| 1022 | return QPDF_Null::create(obj, msg, ""); | 993 | return QPDF_Null::create(obj, msg, ""); |
| 1023 | } | 994 | } |
| 1024 | } | 995 | } |
| @@ -1096,8 +1067,7 @@ QPDFObjectHandle::makeResourcesIndirect(QPDF& owning_qpdf) | @@ -1096,8 +1067,7 @@ QPDFObjectHandle::makeResourcesIndirect(QPDF& owning_qpdf) | ||
| 1096 | 1067 | ||
| 1097 | void | 1068 | void |
| 1098 | QPDFObjectHandle::mergeResources( | 1069 | QPDFObjectHandle::mergeResources( |
| 1099 | - QPDFObjectHandle other, | ||
| 1100 | - std::map<std::string, std::map<std::string, std::string>>* conflicts) | 1070 | + QPDFObjectHandle other, std::map<std::string, std::map<std::string, std::string>>* conflicts) |
| 1101 | { | 1071 | { |
| 1102 | if (!(isDictionary() && other.isDictionary())) { | 1072 | if (!(isDictionary() && other.isDictionary())) { |
| 1103 | QTC::TC("qpdf", "QPDFObjectHandle merge top type mismatch"); | 1073 | QTC::TC("qpdf", "QPDFObjectHandle merge top type mismatch"); |
| @@ -1128,8 +1098,7 @@ QPDFObjectHandle::mergeResources( | @@ -1128,8 +1098,7 @@ QPDFObjectHandle::mergeResources( | ||
| 1128 | // subdictionaries just to get this shallow copy | 1098 | // subdictionaries just to get this shallow copy |
| 1129 | // functionality. | 1099 | // functionality. |
| 1130 | QTC::TC("qpdf", "QPDFObjectHandle replace with copy"); | 1100 | QTC::TC("qpdf", "QPDFObjectHandle replace with copy"); |
| 1131 | - this_val = | ||
| 1132 | - replaceKeyAndGetNew(rtype, this_val.shallowCopy()); | 1101 | + this_val = replaceKeyAndGetNew(rtype, this_val.shallowCopy()); |
| 1133 | } | 1102 | } |
| 1134 | std::map<QPDFObjGen, std::string> og_to_name; | 1103 | std::map<QPDFObjGen, std::string> og_to_name; |
| 1135 | std::set<std::string> rnames; | 1104 | std::set<std::string> rnames; |
| @@ -1140,8 +1109,7 @@ QPDFObjectHandle::mergeResources( | @@ -1140,8 +1109,7 @@ QPDFObjectHandle::mergeResources( | ||
| 1140 | QPDFObjectHandle rval = ov_iter.second; | 1109 | QPDFObjectHandle rval = ov_iter.second; |
| 1141 | if (!this_val.hasKey(key)) { | 1110 | if (!this_val.hasKey(key)) { |
| 1142 | if (!rval.isIndirect()) { | 1111 | if (!rval.isIndirect()) { |
| 1143 | - QTC::TC( | ||
| 1144 | - "qpdf", "QPDFObjectHandle merge shallow copy"); | 1112 | + QTC::TC("qpdf", "QPDFObjectHandle merge shallow copy"); |
| 1145 | rval = rval.shallowCopy(); | 1113 | rval = rval.shallowCopy(); |
| 1146 | } | 1114 | } |
| 1147 | this_val.replaceKey(key, rval); | 1115 | this_val.replaceKey(key, rval); |
| @@ -1160,8 +1128,8 @@ QPDFObjectHandle::mergeResources( | @@ -1160,8 +1128,8 @@ QPDFObjectHandle::mergeResources( | ||
| 1160 | } | 1128 | } |
| 1161 | } else { | 1129 | } else { |
| 1162 | QTC::TC("qpdf", "QPDFObjectHandle merge generate"); | 1130 | QTC::TC("qpdf", "QPDFObjectHandle merge generate"); |
| 1163 | - std::string new_key = getUniqueResourceName( | ||
| 1164 | - key + "_", min_suffix, &rnames); | 1131 | + std::string new_key = |
| 1132 | + getUniqueResourceName(key + "_", min_suffix, &rnames); | ||
| 1165 | (*conflicts)[rtype][key] = new_key; | 1133 | (*conflicts)[rtype][key] = new_key; |
| 1166 | this_val.replaceKey(new_key, rval); | 1134 | this_val.replaceKey(new_key, rval); |
| 1167 | } | 1135 | } |
| @@ -1237,8 +1205,7 @@ QPDFObjectHandle::getUniqueResourceName( | @@ -1237,8 +1205,7 @@ QPDFObjectHandle::getUniqueResourceName( | ||
| 1237 | // Dictionary mutators | 1205 | // Dictionary mutators |
| 1238 | 1206 | ||
| 1239 | void | 1207 | void |
| 1240 | -QPDFObjectHandle::replaceKey( | ||
| 1241 | - std::string const& key, QPDFObjectHandle const& value) | 1208 | +QPDFObjectHandle::replaceKey(std::string const& key, QPDFObjectHandle const& value) |
| 1242 | { | 1209 | { |
| 1243 | auto dict = asDictionary(); | 1210 | auto dict = asDictionary(); |
| 1244 | if (dict) { | 1211 | if (dict) { |
| @@ -1251,16 +1218,14 @@ QPDFObjectHandle::replaceKey( | @@ -1251,16 +1218,14 @@ QPDFObjectHandle::replaceKey( | ||
| 1251 | } | 1218 | } |
| 1252 | 1219 | ||
| 1253 | QPDFObjectHandle | 1220 | QPDFObjectHandle |
| 1254 | -QPDFObjectHandle::replaceKeyAndGetNew( | ||
| 1255 | - std::string const& key, QPDFObjectHandle const& value) | 1221 | +QPDFObjectHandle::replaceKeyAndGetNew(std::string const& key, QPDFObjectHandle const& value) |
| 1256 | { | 1222 | { |
| 1257 | replaceKey(key, value); | 1223 | replaceKey(key, value); |
| 1258 | return value; | 1224 | return value; |
| 1259 | } | 1225 | } |
| 1260 | 1226 | ||
| 1261 | QPDFObjectHandle | 1227 | QPDFObjectHandle |
| 1262 | -QPDFObjectHandle::replaceKeyAndGetOld( | ||
| 1263 | - std::string const& key, QPDFObjectHandle const& value) | 1228 | +QPDFObjectHandle::replaceKeyAndGetOld(std::string const& key, QPDFObjectHandle const& value) |
| 1264 | { | 1229 | { |
| 1265 | QPDFObjectHandle old = removeKeyAndGetOld(key); | 1230 | QPDFObjectHandle old = removeKeyAndGetOld(key); |
| 1266 | replaceKey(key, value); | 1231 | replaceKey(key, value); |
| @@ -1292,8 +1257,7 @@ QPDFObjectHandle::removeKeyAndGetOld(std::string const& key) | @@ -1292,8 +1257,7 @@ QPDFObjectHandle::removeKeyAndGetOld(std::string const& key) | ||
| 1292 | } | 1257 | } |
| 1293 | 1258 | ||
| 1294 | void | 1259 | void |
| 1295 | -QPDFObjectHandle::replaceOrRemoveKey( | ||
| 1296 | - std::string const& key, QPDFObjectHandle const& value) | 1260 | +QPDFObjectHandle::replaceOrRemoveKey(std::string const& key, QPDFObjectHandle const& value) |
| 1297 | { | 1261 | { |
| 1298 | replaceKey(key, value); | 1262 | replaceKey(key, value); |
| 1299 | } | 1263 | } |
| @@ -1351,12 +1315,7 @@ QPDFObjectHandle::pipeStreamData( | @@ -1351,12 +1315,7 @@ QPDFObjectHandle::pipeStreamData( | ||
| 1351 | bool will_retry) | 1315 | bool will_retry) |
| 1352 | { | 1316 | { |
| 1353 | return asStreamWithAssert()->pipeStreamData( | 1317 | return asStreamWithAssert()->pipeStreamData( |
| 1354 | - p, | ||
| 1355 | - filtering_attempted, | ||
| 1356 | - encode_flags, | ||
| 1357 | - decode_level, | ||
| 1358 | - suppress_warnings, | ||
| 1359 | - will_retry); | 1318 | + p, filtering_attempted, encode_flags, decode_level, suppress_warnings, will_retry); |
| 1360 | } | 1319 | } |
| 1361 | 1320 | ||
| 1362 | bool | 1321 | bool |
| @@ -1369,18 +1328,12 @@ QPDFObjectHandle::pipeStreamData( | @@ -1369,18 +1328,12 @@ QPDFObjectHandle::pipeStreamData( | ||
| 1369 | { | 1328 | { |
| 1370 | bool filtering_attempted; | 1329 | bool filtering_attempted; |
| 1371 | asStreamWithAssert()->pipeStreamData( | 1330 | asStreamWithAssert()->pipeStreamData( |
| 1372 | - p, | ||
| 1373 | - &filtering_attempted, | ||
| 1374 | - encode_flags, | ||
| 1375 | - decode_level, | ||
| 1376 | - suppress_warnings, | ||
| 1377 | - will_retry); | 1331 | + p, &filtering_attempted, encode_flags, decode_level, suppress_warnings, will_retry); |
| 1378 | return filtering_attempted; | 1332 | return filtering_attempted; |
| 1379 | } | 1333 | } |
| 1380 | 1334 | ||
| 1381 | bool | 1335 | bool |
| 1382 | -QPDFObjectHandle::pipeStreamData( | ||
| 1383 | - Pipeline* p, bool filter, bool normalize, bool compress) | 1336 | +QPDFObjectHandle::pipeStreamData(Pipeline* p, bool filter, bool normalize, bool compress) |
| 1384 | { | 1337 | { |
| 1385 | int encode_flags = 0; | 1338 | int encode_flags = 0; |
| 1386 | qpdf_stream_decode_level_e decode_level = qpdf_dl_none; | 1339 | qpdf_stream_decode_level_e decode_level = qpdf_dl_none; |
| @@ -1407,9 +1360,7 @@ QPDFObjectHandle::replaceStreamData( | @@ -1407,9 +1360,7 @@ QPDFObjectHandle::replaceStreamData( | ||
| 1407 | 1360 | ||
| 1408 | void | 1361 | void |
| 1409 | QPDFObjectHandle::replaceStreamData( | 1362 | QPDFObjectHandle::replaceStreamData( |
| 1410 | - std::string const& data, | ||
| 1411 | - QPDFObjectHandle const& filter, | ||
| 1412 | - QPDFObjectHandle const& decode_parms) | 1363 | + std::string const& data, QPDFObjectHandle const& filter, QPDFObjectHandle const& decode_parms) |
| 1413 | { | 1364 | { |
| 1414 | auto b = std::make_shared<Buffer>(data.length()); | 1365 | auto b = std::make_shared<Buffer>(data.length()); |
| 1415 | unsigned char* bp = b->getBuffer(); | 1366 | unsigned char* bp = b->getBuffer(); |
| @@ -1454,10 +1405,7 @@ namespace | @@ -1454,10 +1405,7 @@ namespace | ||
| 1454 | 1405 | ||
| 1455 | bool | 1406 | bool |
| 1456 | provideStreamData( | 1407 | provideStreamData( |
| 1457 | - QPDFObjGen const&, | ||
| 1458 | - Pipeline* pipeline, | ||
| 1459 | - bool suppress_warnings, | ||
| 1460 | - bool will_retry) override | 1408 | + QPDFObjGen const&, Pipeline* pipeline, bool suppress_warnings, bool will_retry) override |
| 1461 | { | 1409 | { |
| 1462 | return p2(pipeline, suppress_warnings, will_retry); | 1410 | return p2(pipeline, suppress_warnings, will_retry); |
| 1463 | } | 1411 | } |
| @@ -1474,8 +1422,7 @@ QPDFObjectHandle::replaceStreamData( | @@ -1474,8 +1422,7 @@ QPDFObjectHandle::replaceStreamData( | ||
| 1474 | QPDFObjectHandle const& filter, | 1422 | QPDFObjectHandle const& filter, |
| 1475 | QPDFObjectHandle const& decode_parms) | 1423 | QPDFObjectHandle const& decode_parms) |
| 1476 | { | 1424 | { |
| 1477 | - auto sdp = | ||
| 1478 | - std::shared_ptr<StreamDataProvider>(new FunctionProvider(provider)); | 1425 | + auto sdp = std::shared_ptr<StreamDataProvider>(new FunctionProvider(provider)); |
| 1479 | asStreamWithAssert()->replaceStreamData(sdp, filter, decode_parms); | 1426 | asStreamWithAssert()->replaceStreamData(sdp, filter, decode_parms); |
| 1480 | } | 1427 | } |
| 1481 | 1428 | ||
| @@ -1485,8 +1432,7 @@ QPDFObjectHandle::replaceStreamData( | @@ -1485,8 +1432,7 @@ QPDFObjectHandle::replaceStreamData( | ||
| 1485 | QPDFObjectHandle const& filter, | 1432 | QPDFObjectHandle const& filter, |
| 1486 | QPDFObjectHandle const& decode_parms) | 1433 | QPDFObjectHandle const& decode_parms) |
| 1487 | { | 1434 | { |
| 1488 | - auto sdp = | ||
| 1489 | - std::shared_ptr<StreamDataProvider>(new FunctionProvider(provider)); | 1435 | + auto sdp = std::shared_ptr<StreamDataProvider>(new FunctionProvider(provider)); |
| 1490 | asStreamWithAssert()->replaceStreamData(sdp, filter, decode_parms); | 1436 | asStreamWithAssert()->replaceStreamData(sdp, filter, decode_parms); |
| 1491 | } | 1437 | } |
| 1492 | 1438 | ||
| @@ -1515,8 +1461,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( | @@ -1515,8 +1461,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( | ||
| 1515 | QPDFExc( | 1461 | QPDFExc( |
| 1516 | qpdf_e_damaged_pdf, | 1462 | qpdf_e_damaged_pdf, |
| 1517 | "", | 1463 | "", |
| 1518 | - description + ": item index " + std::to_string(i) + | ||
| 1519 | - " (from 0)", | 1464 | + description + ": item index " + std::to_string(i) + " (from 0)", |
| 1520 | 0, | 1465 | 0, |
| 1521 | "ignoring non-stream in an array of streams")); | 1466 | "ignoring non-stream in an array of streams")); |
| 1522 | } | 1467 | } |
| @@ -1553,8 +1498,7 @@ QPDFObjectHandle::getPageContents() | @@ -1553,8 +1498,7 @@ QPDFObjectHandle::getPageContents() | ||
| 1553 | { | 1498 | { |
| 1554 | std::string description = "page object " + getObjGen().unparse(' '); | 1499 | std::string description = "page object " + getObjGen().unparse(' '); |
| 1555 | std::string all_description; | 1500 | std::string all_description; |
| 1556 | - return this->getKey("/Contents") | ||
| 1557 | - .arrayOrStreamToStreamArray(description, all_description); | 1501 | + return this->getKey("/Contents").arrayOrStreamToStreamArray(description, all_description); |
| 1558 | } | 1502 | } |
| 1559 | 1503 | ||
| 1560 | void | 1504 | void |
| @@ -1600,10 +1544,7 @@ QPDFObjectHandle::rotatePage(int angle, bool relative) | @@ -1600,10 +1544,7 @@ QPDFObjectHandle::rotatePage(int angle, bool relative) | ||
| 1600 | break; | 1544 | break; |
| 1601 | } | 1545 | } |
| 1602 | } | 1546 | } |
| 1603 | - QTC::TC( | ||
| 1604 | - "qpdf", | ||
| 1605 | - "QPDFObjectHandle found old angle", | ||
| 1606 | - visited.size() > 1 ? 0 : 1); | 1547 | + QTC::TC("qpdf", "QPDFObjectHandle found old angle", visited.size() > 1 ? 0 : 1); |
| 1607 | if ((old_angle % 90) != 0) { | 1548 | if ((old_angle % 90) != 0) { |
| 1608 | old_angle = 0; | 1549 | old_angle = 0; |
| 1609 | } | 1550 | } |
| @@ -1632,14 +1573,12 @@ QPDFObjectHandle::coalesceContentStreams() | @@ -1632,14 +1573,12 @@ QPDFObjectHandle::coalesceContentStreams() | ||
| 1632 | // incorrect way. However, it can happen in a PDF file whose | 1573 | // incorrect way. However, it can happen in a PDF file whose |
| 1633 | // page structure is direct, which is against spec but still | 1574 | // page structure is direct, which is against spec but still |
| 1634 | // possible to hand construct, as in fuzz issue 27393. | 1575 | // possible to hand construct, as in fuzz issue 27393. |
| 1635 | - QPDF& qpdf = getQPDF( | ||
| 1636 | - "coalesceContentStreams called on object with no associated PDF file"); | 1576 | + QPDF& qpdf = getQPDF("coalesceContentStreams called on object with no associated PDF file"); |
| 1637 | 1577 | ||
| 1638 | QPDFObjectHandle new_contents = newStream(&qpdf); | 1578 | QPDFObjectHandle new_contents = newStream(&qpdf); |
| 1639 | this->replaceKey("/Contents", new_contents); | 1579 | this->replaceKey("/Contents", new_contents); |
| 1640 | 1580 | ||
| 1641 | - auto provider = std::shared_ptr<StreamDataProvider>( | ||
| 1642 | - new CoalesceProvider(*this, contents)); | 1581 | + auto provider = std::shared_ptr<StreamDataProvider>(new CoalesceProvider(*this, contents)); |
| 1643 | new_contents.replaceStreamData(provider, newNull(), newNull()); | 1582 | new_contents.replaceStreamData(provider, newNull(), newNull()); |
| 1644 | } | 1583 | } |
| 1645 | 1584 | ||
| @@ -1659,8 +1598,7 @@ std::string | @@ -1659,8 +1598,7 @@ std::string | ||
| 1659 | QPDFObjectHandle::unparseResolved() | 1598 | QPDFObjectHandle::unparseResolved() |
| 1660 | { | 1599 | { |
| 1661 | if (!dereference()) { | 1600 | if (!dereference()) { |
| 1662 | - throw std::logic_error( | ||
| 1663 | - "attempted to dereference an uninitialized QPDFObjectHandle"); | 1601 | + throw std::logic_error("attempted to dereference an uninitialized QPDFObjectHandle"); |
| 1664 | } | 1602 | } |
| 1665 | return obj->unparse(); | 1603 | return obj->unparse(); |
| 1666 | } | 1604 | } |
| @@ -1689,8 +1627,7 @@ QPDFObjectHandle::getJSON(int json_version, bool dereference_indirect) | @@ -1689,8 +1627,7 @@ QPDFObjectHandle::getJSON(int json_version, bool dereference_indirect) | ||
| 1689 | if ((!dereference_indirect) && isIndirect()) { | 1627 | if ((!dereference_indirect) && isIndirect()) { |
| 1690 | return JSON::makeString(unparse()); | 1628 | return JSON::makeString(unparse()); |
| 1691 | } else if (!dereference()) { | 1629 | } else if (!dereference()) { |
| 1692 | - throw std::logic_error( | ||
| 1693 | - "attempted to dereference an uninitialized QPDFObjectHandle"); | 1630 | + throw std::logic_error("attempted to dereference an uninitialized QPDFObjectHandle"); |
| 1694 | } else { | 1631 | } else { |
| 1695 | return obj->getJSON(json_version); | 1632 | return obj->getJSON(json_version); |
| 1696 | } | 1633 | } |
| @@ -1720,24 +1657,19 @@ QPDFObjectHandle::wrapInArray() | @@ -1720,24 +1657,19 @@ QPDFObjectHandle::wrapInArray() | ||
| 1720 | } | 1657 | } |
| 1721 | 1658 | ||
| 1722 | QPDFObjectHandle | 1659 | QPDFObjectHandle |
| 1723 | -QPDFObjectHandle::parse( | ||
| 1724 | - std::string const& object_str, std::string const& object_description) | 1660 | +QPDFObjectHandle::parse(std::string const& object_str, std::string const& object_description) |
| 1725 | { | 1661 | { |
| 1726 | return parse(nullptr, object_str, object_description); | 1662 | return parse(nullptr, object_str, object_description); |
| 1727 | } | 1663 | } |
| 1728 | 1664 | ||
| 1729 | QPDFObjectHandle | 1665 | QPDFObjectHandle |
| 1730 | QPDFObjectHandle::parse( | 1666 | QPDFObjectHandle::parse( |
| 1731 | - QPDF* context, | ||
| 1732 | - std::string const& object_str, | ||
| 1733 | - std::string const& object_description) | 1667 | + QPDF* context, std::string const& object_str, std::string const& object_description) |
| 1734 | { | 1668 | { |
| 1735 | - auto input = std::shared_ptr<InputSource>( | ||
| 1736 | - new BufferInputSource("parsed object", object_str)); | 1669 | + auto input = std::shared_ptr<InputSource>(new BufferInputSource("parsed object", object_str)); |
| 1737 | QPDFTokenizer tokenizer; | 1670 | QPDFTokenizer tokenizer; |
| 1738 | bool empty = false; | 1671 | bool empty = false; |
| 1739 | - QPDFObjectHandle result = | ||
| 1740 | - parse(input, object_description, tokenizer, empty, nullptr, context); | 1672 | + QPDFObjectHandle result = parse(input, object_description, tokenizer, empty, nullptr, context); |
| 1741 | size_t offset = QIntC::to_size(input->tell()); | 1673 | size_t offset = QIntC::to_size(input->tell()); |
| 1742 | while (offset < object_str.length()) { | 1674 | while (offset < object_str.length()) { |
| 1743 | if (!isspace(object_str.at(offset))) { | 1675 | if (!isspace(object_str.at(offset))) { |
| @@ -1759,8 +1691,7 @@ QPDFObjectHandle::pipePageContents(Pipeline* p) | @@ -1759,8 +1691,7 @@ QPDFObjectHandle::pipePageContents(Pipeline* p) | ||
| 1759 | { | 1691 | { |
| 1760 | std::string description = "page object " + getObjGen().unparse(' '); | 1692 | std::string description = "page object " + getObjGen().unparse(' '); |
| 1761 | std::string all_description; | 1693 | std::string all_description; |
| 1762 | - this->getKey("/Contents") | ||
| 1763 | - .pipeContentStreams(p, description, all_description); | 1694 | + this->getKey("/Contents").pipeContentStreams(p, description, all_description); |
| 1764 | } | 1695 | } |
| 1765 | 1696 | ||
| 1766 | void | 1697 | void |
| @@ -1798,8 +1729,7 @@ void | @@ -1798,8 +1729,7 @@ void | ||
| 1798 | QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks) | 1729 | QPDFObjectHandle::parsePageContents(ParserCallbacks* callbacks) |
| 1799 | { | 1730 | { |
| 1800 | std::string description = "page object " + getObjGen().unparse(' '); | 1731 | std::string description = "page object " + getObjGen().unparse(' '); |
| 1801 | - this->getKey("/Contents") | ||
| 1802 | - .parseContentStream_internal(description, callbacks); | 1732 | + this->getKey("/Contents").parseContentStream_internal(description, callbacks); |
| 1803 | } | 1733 | } |
| 1804 | 1734 | ||
| 1805 | void | 1735 | void |
| @@ -1812,8 +1742,7 @@ QPDFObjectHandle::parseAsContents(ParserCallbacks* callbacks) | @@ -1812,8 +1742,7 @@ QPDFObjectHandle::parseAsContents(ParserCallbacks* callbacks) | ||
| 1812 | void | 1742 | void |
| 1813 | QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next) | 1743 | QPDFObjectHandle::filterPageContents(TokenFilter* filter, Pipeline* next) |
| 1814 | { | 1744 | { |
| 1815 | - auto description = | ||
| 1816 | - "token filter for page object " + getObjGen().unparse(' '); | 1745 | + auto description = "token filter for page object " + getObjGen().unparse(' '); |
| 1817 | Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next); | 1746 | Pl_QPDFTokenizer token_pipeline(description.c_str(), filter, next); |
| 1818 | this->pipePageContents(&token_pipeline); | 1747 | this->pipePageContents(&token_pipeline); |
| 1819 | } | 1748 | } |
| @@ -1827,11 +1756,9 @@ QPDFObjectHandle::filterAsContents(TokenFilter* filter, Pipeline* next) | @@ -1827,11 +1756,9 @@ QPDFObjectHandle::filterAsContents(TokenFilter* filter, Pipeline* next) | ||
| 1827 | } | 1756 | } |
| 1828 | 1757 | ||
| 1829 | void | 1758 | void |
| 1830 | -QPDFObjectHandle::parseContentStream( | ||
| 1831 | - QPDFObjectHandle stream_or_array, ParserCallbacks* callbacks) | 1759 | +QPDFObjectHandle::parseContentStream(QPDFObjectHandle stream_or_array, ParserCallbacks* callbacks) |
| 1832 | { | 1760 | { |
| 1833 | - stream_or_array.parseContentStream_internal( | ||
| 1834 | - "content stream objects", callbacks); | 1761 | + stream_or_array.parseContentStream_internal("content stream objects", callbacks); |
| 1835 | } | 1762 | } |
| 1836 | 1763 | ||
| 1837 | void | 1764 | void |
| @@ -1844,8 +1771,7 @@ QPDFObjectHandle::parseContentStream_internal( | @@ -1844,8 +1771,7 @@ QPDFObjectHandle::parseContentStream_internal( | ||
| 1844 | auto stream_data = buf.getBufferSharedPointer(); | 1771 | auto stream_data = buf.getBufferSharedPointer(); |
| 1845 | callbacks->contentSize(stream_data->getSize()); | 1772 | callbacks->contentSize(stream_data->getSize()); |
| 1846 | try { | 1773 | try { |
| 1847 | - parseContentStream_data( | ||
| 1848 | - stream_data, all_description, callbacks, getOwningQPDF()); | 1774 | + parseContentStream_data(stream_data, all_description, callbacks, getOwningQPDF()); |
| 1849 | } catch (TerminateParsing&) { | 1775 | } catch (TerminateParsing&) { |
| 1850 | return; | 1776 | return; |
| 1851 | } | 1777 | } |
| @@ -1860,8 +1786,8 @@ QPDFObjectHandle::parseContentStream_data( | @@ -1860,8 +1786,8 @@ QPDFObjectHandle::parseContentStream_data( | ||
| 1860 | QPDF* context) | 1786 | QPDF* context) |
| 1861 | { | 1787 | { |
| 1862 | size_t stream_length = stream_data->getSize(); | 1788 | size_t stream_length = stream_data->getSize(); |
| 1863 | - auto input = std::shared_ptr<InputSource>( | ||
| 1864 | - new BufferInputSource(description, stream_data.get())); | 1789 | + auto input = |
| 1790 | + std::shared_ptr<InputSource>(new BufferInputSource(description, stream_data.get())); | ||
| 1865 | QPDFTokenizer tokenizer; | 1791 | QPDFTokenizer tokenizer; |
| 1866 | tokenizer.allowEOF(); | 1792 | tokenizer.allowEOF(); |
| 1867 | bool empty = false; | 1793 | bool empty = false; |
| @@ -1873,8 +1799,7 @@ QPDFObjectHandle::parseContentStream_data( | @@ -1873,8 +1799,7 @@ QPDFObjectHandle::parseContentStream_data( | ||
| 1873 | tokenizer.readToken(input, "content", true); | 1799 | tokenizer.readToken(input, "content", true); |
| 1874 | qpdf_offset_t offset = input->getLastOffset(); | 1800 | qpdf_offset_t offset = input->getLastOffset(); |
| 1875 | input->seek(offset, SEEK_SET); | 1801 | input->seek(offset, SEEK_SET); |
| 1876 | - auto obj = QPDFParser(input, "content", tokenizer, nullptr, context) | ||
| 1877 | - .parse(empty, true); | 1802 | + auto obj = QPDFParser(input, "content", tokenizer, nullptr, context).parse(empty, true); |
| 1878 | if (!obj.isInitialized()) { | 1803 | if (!obj.isInitialized()) { |
| 1879 | // EOF | 1804 | // EOF |
| 1880 | break; | 1805 | break; |
| @@ -1888,8 +1813,7 @@ QPDFObjectHandle::parseContentStream_data( | @@ -1888,8 +1813,7 @@ QPDFObjectHandle::parseContentStream_data( | ||
| 1888 | char ch; | 1813 | char ch; |
| 1889 | input->read(&ch, 1); | 1814 | input->read(&ch, 1); |
| 1890 | tokenizer.expectInlineImage(input); | 1815 | tokenizer.expectInlineImage(input); |
| 1891 | - QPDFTokenizer::Token t = | ||
| 1892 | - tokenizer.readToken(input, description, true); | 1816 | + QPDFTokenizer::Token t = tokenizer.readToken(input, description, true); |
| 1893 | offset = input->getLastOffset(); | 1817 | offset = input->getLastOffset(); |
| 1894 | length = QIntC::to_size(input->tell() - offset); | 1818 | length = QIntC::to_size(input->tell() - offset); |
| 1895 | if (t.getType() == QPDFTokenizer::tt_bad) { | 1819 | if (t.getType() == QPDFTokenizer::tt_bad) { |
| @@ -1906,9 +1830,7 @@ QPDFObjectHandle::parseContentStream_data( | @@ -1906,9 +1830,7 @@ QPDFObjectHandle::parseContentStream_data( | ||
| 1906 | std::string inline_image = t.getValue(); | 1830 | std::string inline_image = t.getValue(); |
| 1907 | QTC::TC("qpdf", "QPDFObjectHandle inline image token"); | 1831 | QTC::TC("qpdf", "QPDFObjectHandle inline image token"); |
| 1908 | callbacks->handleObject( | 1832 | callbacks->handleObject( |
| 1909 | - QPDFObjectHandle::newInlineImage(inline_image), | ||
| 1910 | - QIntC::to_size(offset), | ||
| 1911 | - length); | 1833 | + QPDFObjectHandle::newInlineImage(inline_image), QIntC::to_size(offset), length); |
| 1912 | } | 1834 | } |
| 1913 | } | 1835 | } |
| 1914 | } | 1836 | } |
| @@ -1936,8 +1858,7 @@ QPDFObjectHandle::parse( | @@ -1936,8 +1858,7 @@ QPDFObjectHandle::parse( | ||
| 1936 | StringDecrypter* decrypter, | 1858 | StringDecrypter* decrypter, |
| 1937 | QPDF* context) | 1859 | QPDF* context) |
| 1938 | { | 1860 | { |
| 1939 | - return QPDFParser(input, object_description, tokenizer, decrypter, context) | ||
| 1940 | - .parse(empty, false); | 1861 | + return QPDFParser(input, object_description, tokenizer, decrypter, context).parse(empty, false); |
| 1941 | } | 1862 | } |
| 1942 | 1863 | ||
| 1943 | qpdf_offset_t | 1864 | qpdf_offset_t |
| @@ -1975,11 +1896,9 @@ QPDFObjectHandle::newReal(std::string const& value) | @@ -1975,11 +1896,9 @@ QPDFObjectHandle::newReal(std::string const& value) | ||
| 1975 | } | 1896 | } |
| 1976 | 1897 | ||
| 1977 | QPDFObjectHandle | 1898 | QPDFObjectHandle |
| 1978 | -QPDFObjectHandle::newReal( | ||
| 1979 | - double value, int decimal_places, bool trim_trailing_zeroes) | 1899 | +QPDFObjectHandle::newReal(double value, int decimal_places, bool trim_trailing_zeroes) |
| 1980 | { | 1900 | { |
| 1981 | - return QPDFObjectHandle( | ||
| 1982 | - QPDF_Real::create(value, decimal_places, trim_trailing_zeroes)); | 1901 | + return QPDFObjectHandle(QPDF_Real::create(value, decimal_places, trim_trailing_zeroes)); |
| 1983 | } | 1902 | } |
| 1984 | 1903 | ||
| 1985 | QPDFObjectHandle | 1904 | QPDFObjectHandle |
| @@ -2086,8 +2005,7 @@ QPDFObjectHandle::newDictionary() | @@ -2086,8 +2005,7 @@ QPDFObjectHandle::newDictionary() | ||
| 2086 | } | 2005 | } |
| 2087 | 2006 | ||
| 2088 | QPDFObjectHandle | 2007 | QPDFObjectHandle |
| 2089 | -QPDFObjectHandle::newDictionary( | ||
| 2090 | - std::map<std::string, QPDFObjectHandle> const& items) | 2008 | +QPDFObjectHandle::newDictionary(std::map<std::string, QPDFObjectHandle> const& items) |
| 2091 | { | 2009 | { |
| 2092 | return QPDFObjectHandle(QPDF_Dictionary::create(items)); | 2010 | return QPDFObjectHandle(QPDF_Dictionary::create(items)); |
| 2093 | } | 2011 | } |
| @@ -2096,8 +2014,7 @@ QPDFObjectHandle | @@ -2096,8 +2014,7 @@ QPDFObjectHandle | ||
| 2096 | QPDFObjectHandle::newStream(QPDF* qpdf) | 2014 | QPDFObjectHandle::newStream(QPDF* qpdf) |
| 2097 | { | 2015 | { |
| 2098 | if (qpdf == nullptr) { | 2016 | if (qpdf == nullptr) { |
| 2099 | - throw std::runtime_error( | ||
| 2100 | - "attempt to create stream in null qpdf object"); | 2017 | + throw std::runtime_error("attempt to create stream in null qpdf object"); |
| 2101 | } | 2018 | } |
| 2102 | QTC::TC("qpdf", "QPDFObjectHandle newStream"); | 2019 | QTC::TC("qpdf", "QPDFObjectHandle newStream"); |
| 2103 | return qpdf->newStream(); | 2020 | return qpdf->newStream(); |
| @@ -2107,8 +2024,7 @@ QPDFObjectHandle | @@ -2107,8 +2024,7 @@ QPDFObjectHandle | ||
| 2107 | QPDFObjectHandle::newStream(QPDF* qpdf, std::shared_ptr<Buffer> data) | 2024 | QPDFObjectHandle::newStream(QPDF* qpdf, std::shared_ptr<Buffer> data) |
| 2108 | { | 2025 | { |
| 2109 | if (qpdf == nullptr) { | 2026 | if (qpdf == nullptr) { |
| 2110 | - throw std::runtime_error( | ||
| 2111 | - "attempt to create stream in null qpdf object"); | 2027 | + throw std::runtime_error("attempt to create stream in null qpdf object"); |
| 2112 | } | 2028 | } |
| 2113 | QTC::TC("qpdf", "QPDFObjectHandle newStream with data"); | 2029 | QTC::TC("qpdf", "QPDFObjectHandle newStream with data"); |
| 2114 | return qpdf->newStream(data); | 2030 | return qpdf->newStream(data); |
| @@ -2118,8 +2034,7 @@ QPDFObjectHandle | @@ -2118,8 +2034,7 @@ QPDFObjectHandle | ||
| 2118 | QPDFObjectHandle::newStream(QPDF* qpdf, std::string const& data) | 2034 | QPDFObjectHandle::newStream(QPDF* qpdf, std::string const& data) |
| 2119 | { | 2035 | { |
| 2120 | if (qpdf == nullptr) { | 2036 | if (qpdf == nullptr) { |
| 2121 | - throw std::runtime_error( | ||
| 2122 | - "attempt to create stream in null qpdf object"); | 2037 | + throw std::runtime_error("attempt to create stream in null qpdf object"); |
| 2123 | } | 2038 | } |
| 2124 | QTC::TC("qpdf", "QPDFObjectHandle newStream with string"); | 2039 | QTC::TC("qpdf", "QPDFObjectHandle newStream with string"); |
| 2125 | return qpdf->newStream(data); | 2040 | return qpdf->newStream(data); |
| @@ -2129,21 +2044,18 @@ QPDFObjectHandle | @@ -2129,21 +2044,18 @@ QPDFObjectHandle | ||
| 2129 | QPDFObjectHandle::newReserved(QPDF* qpdf) | 2044 | QPDFObjectHandle::newReserved(QPDF* qpdf) |
| 2130 | { | 2045 | { |
| 2131 | if (qpdf == nullptr) { | 2046 | if (qpdf == nullptr) { |
| 2132 | - throw std::runtime_error( | ||
| 2133 | - "attempt to create reserved object in null qpdf object"); | 2047 | + throw std::runtime_error("attempt to create reserved object in null qpdf object"); |
| 2134 | } | 2048 | } |
| 2135 | return qpdf->newReserved(); | 2049 | return qpdf->newReserved(); |
| 2136 | } | 2050 | } |
| 2137 | 2051 | ||
| 2138 | void | 2052 | void |
| 2139 | -QPDFObjectHandle::setObjectDescription( | ||
| 2140 | - QPDF* owning_qpdf, std::string const& object_description) | 2053 | +QPDFObjectHandle::setObjectDescription(QPDF* owning_qpdf, std::string const& object_description) |
| 2141 | { | 2054 | { |
| 2142 | // This is called during parsing on newly created direct objects, | 2055 | // This is called during parsing on newly created direct objects, |
| 2143 | // so we can't call dereference() here. | 2056 | // so we can't call dereference() here. |
| 2144 | if (isInitialized() && obj.get()) { | 2057 | if (isInitialized() && obj.get()) { |
| 2145 | - auto descr = | ||
| 2146 | - std::make_shared<QPDFValue::Description>(object_description); | 2058 | + auto descr = std::make_shared<QPDFValue::Description>(object_description); |
| 2147 | obj->setDescription(owning_qpdf, descr); | 2059 | obj->setDescription(owning_qpdf, descr); |
| 2148 | } | 2060 | } |
| 2149 | } | 2061 | } |
| @@ -2186,8 +2098,7 @@ QPDFObjectHandle::makeDirect(QPDFObjGen::set& visited, bool stop_at_streams) | @@ -2186,8 +2098,7 @@ QPDFObjectHandle::makeDirect(QPDFObjGen::set& visited, bool stop_at_streams) | ||
| 2186 | "indirect to direct"); | 2098 | "indirect to direct"); |
| 2187 | } | 2099 | } |
| 2188 | 2100 | ||
| 2189 | - if (isBool() || isInteger() || isName() || isNull() || isReal() || | ||
| 2190 | - isString()) { | 2101 | + if (isBool() || isInteger() || isName() || isNull() || isReal() || isString()) { |
| 2191 | this->obj = obj->copy(true); | 2102 | this->obj = obj->copy(true); |
| 2192 | } else if (isArray()) { | 2103 | } else if (isArray()) { |
| 2193 | std::vector<QPDFObjectHandle> items; | 2104 | std::vector<QPDFObjectHandle> items; |
| @@ -2207,11 +2118,9 @@ QPDFObjectHandle::makeDirect(QPDFObjGen::set& visited, bool stop_at_streams) | @@ -2207,11 +2118,9 @@ QPDFObjectHandle::makeDirect(QPDFObjGen::set& visited, bool stop_at_streams) | ||
| 2207 | } | 2118 | } |
| 2208 | this->obj = QPDF_Dictionary::create(items); | 2119 | this->obj = QPDF_Dictionary::create(items); |
| 2209 | } else if (isStream()) { | 2120 | } else if (isStream()) { |
| 2210 | - QTC::TC( | ||
| 2211 | - "qpdf", "QPDFObjectHandle copy stream", stop_at_streams ? 0 : 1); | 2121 | + QTC::TC("qpdf", "QPDFObjectHandle copy stream", stop_at_streams ? 0 : 1); |
| 2212 | if (!stop_at_streams) { | 2122 | if (!stop_at_streams) { |
| 2213 | - throw std::runtime_error( | ||
| 2214 | - "attempt to make a stream into a direct object"); | 2123 | + throw std::runtime_error("attempt to make a stream into a direct object"); |
| 2215 | } | 2124 | } |
| 2216 | } else if (isReserved()) { | 2125 | } else if (isReserved()) { |
| 2217 | throw std::logic_error("QPDFObjectHandle: attempting to make a" | 2126 | throw std::logic_error("QPDFObjectHandle: attempting to make a" |
| @@ -2259,16 +2168,14 @@ QPDFObjectHandle::assertInitialized() const | @@ -2259,16 +2168,14 @@ QPDFObjectHandle::assertInitialized() const | ||
| 2259 | } | 2168 | } |
| 2260 | 2169 | ||
| 2261 | void | 2170 | void |
| 2262 | -QPDFObjectHandle::typeWarning( | ||
| 2263 | - char const* expected_type, std::string const& warning) | 2171 | +QPDFObjectHandle::typeWarning(char const* expected_type, std::string const& warning) |
| 2264 | { | 2172 | { |
| 2265 | QPDF* context = nullptr; | 2173 | QPDF* context = nullptr; |
| 2266 | std::string description; | 2174 | std::string description; |
| 2267 | // Type checks above guarantee that the object has been dereferenced. | 2175 | // Type checks above guarantee that the object has been dereferenced. |
| 2268 | // Nevertheless, dereference throws exceptions in the test suite | 2176 | // Nevertheless, dereference throws exceptions in the test suite |
| 2269 | if (!dereference()) { | 2177 | if (!dereference()) { |
| 2270 | - throw std::logic_error( | ||
| 2271 | - "attempted to dereference an uninitialized QPDFObjectHandle"); | 2178 | + throw std::logic_error("attempted to dereference an uninitialized QPDFObjectHandle"); |
| 2272 | } | 2179 | } |
| 2273 | this->obj->getDescription(context, description); | 2180 | this->obj->getDescription(context, description); |
| 2274 | // Null context handled by warn | 2181 | // Null context handled by warn |
| @@ -2279,9 +2186,8 @@ QPDFObjectHandle::typeWarning( | @@ -2279,9 +2186,8 @@ QPDFObjectHandle::typeWarning( | ||
| 2279 | "", | 2186 | "", |
| 2280 | description, | 2187 | description, |
| 2281 | 0, | 2188 | 0, |
| 2282 | - std::string("operation for ") + expected_type + | ||
| 2283 | - " attempted on object of type " + getTypeName() + ": " + | ||
| 2284 | - warning)); | 2189 | + std::string("operation for ") + expected_type + " attempted on object of type " + |
| 2190 | + getTypeName() + ": " + warning)); | ||
| 2285 | } | 2191 | } |
| 2286 | 2192 | ||
| 2287 | void | 2193 | void |
| @@ -2312,8 +2218,8 @@ QPDFObjectHandle::assertType(char const* type_name, bool istype) | @@ -2312,8 +2218,8 @@ QPDFObjectHandle::assertType(char const* type_name, bool istype) | ||
| 2312 | { | 2218 | { |
| 2313 | if (!istype) { | 2219 | if (!istype) { |
| 2314 | throw std::runtime_error( | 2220 | throw std::runtime_error( |
| 2315 | - std::string("operation for ") + type_name + | ||
| 2316 | - " attempted on object of type " + getTypeName()); | 2221 | + std::string("operation for ") + type_name + " attempted on object of type " + |
| 2222 | + getTypeName()); | ||
| 2317 | } | 2223 | } |
| 2318 | } | 2224 | } |
| 2319 | 2225 | ||
| @@ -2393,8 +2299,7 @@ void | @@ -2393,8 +2299,7 @@ void | ||
| 2393 | QPDFObjectHandle::assertIndirect() | 2299 | QPDFObjectHandle::assertIndirect() |
| 2394 | { | 2300 | { |
| 2395 | if (!isIndirect()) { | 2301 | if (!isIndirect()) { |
| 2396 | - throw std::logic_error( | ||
| 2397 | - "operation for indirect object attempted on direct object"); | 2302 | + throw std::logic_error("operation for indirect object attempted on direct object"); |
| 2398 | } | 2303 | } |
| 2399 | } | 2304 | } |
| 2400 | 2305 | ||
| @@ -2471,9 +2376,8 @@ QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const | @@ -2471,9 +2376,8 @@ QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const | ||
| 2471 | auto item_qpdf = item.getOwningQPDF(); | 2376 | auto item_qpdf = item.getOwningQPDF(); |
| 2472 | if ((qpdf != nullptr) && (item_qpdf != nullptr) && (qpdf != item_qpdf)) { | 2377 | if ((qpdf != nullptr) && (item_qpdf != nullptr) && (qpdf != item_qpdf)) { |
| 2473 | QTC::TC("qpdf", "QPDFObjectHandle check ownership"); | 2378 | QTC::TC("qpdf", "QPDFObjectHandle check ownership"); |
| 2474 | - throw std::logic_error( | ||
| 2475 | - "Attempting to add an object from a different QPDF." | ||
| 2476 | - " Use QPDF::copyForeignObject to add objects from another file."); | 2379 | + throw std::logic_error("Attempting to add an object from a different QPDF." |
| 2380 | + " Use QPDF::copyForeignObject to add objects from another file."); | ||
| 2477 | } | 2381 | } |
| 2478 | } | 2382 | } |
| 2479 | 2383 | ||
| @@ -2545,8 +2449,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::operator->() | @@ -2545,8 +2449,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::operator->() | ||
| 2545 | } | 2449 | } |
| 2546 | 2450 | ||
| 2547 | bool | 2451 | bool |
| 2548 | -QPDFObjectHandle::QPDFDictItems::iterator::operator==( | ||
| 2549 | - iterator const& other) const | 2452 | +QPDFObjectHandle::QPDFDictItems::iterator::operator==(iterator const& other) const |
| 2550 | { | 2453 | { |
| 2551 | if (m->is_end && other.m->is_end) { | 2454 | if (m->is_end && other.m->is_end) { |
| 2552 | return true; | 2455 | return true; |
| @@ -2557,8 +2460,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::operator==( | @@ -2557,8 +2460,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::operator==( | ||
| 2557 | return (this->ivalue.first == other.ivalue.first); | 2460 | return (this->ivalue.first == other.ivalue.first); |
| 2558 | } | 2461 | } |
| 2559 | 2462 | ||
| 2560 | -QPDFObjectHandle::QPDFDictItems::iterator::iterator( | ||
| 2561 | - QPDFObjectHandle& oh, bool for_begin) : | 2463 | +QPDFObjectHandle::QPDFDictItems::iterator::iterator(QPDFObjectHandle& oh, bool for_begin) : |
| 2562 | m(new Members(oh, for_begin)) | 2464 | m(new Members(oh, for_begin)) |
| 2563 | { | 2465 | { |
| 2564 | updateIValue(); | 2466 | updateIValue(); |
| @@ -2577,8 +2479,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::updateIValue() | @@ -2577,8 +2479,7 @@ QPDFObjectHandle::QPDFDictItems::iterator::updateIValue() | ||
| 2577 | } | 2479 | } |
| 2578 | } | 2480 | } |
| 2579 | 2481 | ||
| 2580 | -QPDFObjectHandle::QPDFDictItems::iterator::Members::Members( | ||
| 2581 | - QPDFObjectHandle& oh, bool for_begin) : | 2482 | +QPDFObjectHandle::QPDFDictItems::iterator::Members::Members(QPDFObjectHandle& oh, bool for_begin) : |
| 2582 | oh(oh) | 2483 | oh(oh) |
| 2583 | { | 2484 | { |
| 2584 | this->keys = oh.getKeys(); | 2485 | this->keys = oh.getKeys(); |
| @@ -2637,14 +2538,12 @@ QPDFObjectHandle::QPDFArrayItems::iterator::operator->() | @@ -2637,14 +2538,12 @@ QPDFObjectHandle::QPDFArrayItems::iterator::operator->() | ||
| 2637 | } | 2538 | } |
| 2638 | 2539 | ||
| 2639 | bool | 2540 | bool |
| 2640 | -QPDFObjectHandle::QPDFArrayItems::iterator::operator==( | ||
| 2641 | - iterator const& other) const | 2541 | +QPDFObjectHandle::QPDFArrayItems::iterator::operator==(iterator const& other) const |
| 2642 | { | 2542 | { |
| 2643 | return (m->item_number == other.m->item_number); | 2543 | return (m->item_number == other.m->item_number); |
| 2644 | } | 2544 | } |
| 2645 | 2545 | ||
| 2646 | -QPDFObjectHandle::QPDFArrayItems::iterator::iterator( | ||
| 2647 | - QPDFObjectHandle& oh, bool for_begin) : | 2546 | +QPDFObjectHandle::QPDFArrayItems::iterator::iterator(QPDFObjectHandle& oh, bool for_begin) : |
| 2648 | m(new Members(oh, for_begin)) | 2547 | m(new Members(oh, for_begin)) |
| 2649 | { | 2548 | { |
| 2650 | updateIValue(); | 2549 | updateIValue(); |
| @@ -2661,8 +2560,7 @@ QPDFObjectHandle::QPDFArrayItems::iterator::updateIValue() | @@ -2661,8 +2560,7 @@ QPDFObjectHandle::QPDFArrayItems::iterator::updateIValue() | ||
| 2661 | } | 2560 | } |
| 2662 | } | 2561 | } |
| 2663 | 2562 | ||
| 2664 | -QPDFObjectHandle::QPDFArrayItems::iterator::Members::Members( | ||
| 2665 | - QPDFObjectHandle& oh, bool for_begin) : | 2563 | +QPDFObjectHandle::QPDFArrayItems::iterator::Members::Members(QPDFObjectHandle& oh, bool for_begin) : |
| 2666 | oh(oh) | 2564 | oh(oh) |
| 2667 | { | 2565 | { |
| 2668 | this->item_number = for_begin ? 0 : oh.getArrayNItems(); | 2566 | this->item_number = for_begin ? 0 : oh.getArrayNItems(); |
| @@ -2698,8 +2596,7 @@ QPDFObjectHandle::getQPDF(std::string const& error_msg) const | @@ -2698,8 +2596,7 @@ QPDFObjectHandle::getQPDF(std::string const& error_msg) const | ||
| 2698 | { | 2596 | { |
| 2699 | auto result = isInitialized() ? this->obj->getQPDF() : nullptr; | 2597 | auto result = isInitialized() ? this->obj->getQPDF() : nullptr; |
| 2700 | if (result == nullptr) { | 2598 | if (result == nullptr) { |
| 2701 | - throw std::runtime_error( | ||
| 2702 | - error_msg == "" ? "attempt to use a null qpdf object" : error_msg); | 2599 | + throw std::runtime_error(error_msg == "" ? "attempt to use a null qpdf object" : error_msg); |
| 2703 | } | 2600 | } |
| 2704 | return *result; | 2601 | return *result; |
| 2705 | } | 2602 | } |
| @@ -2717,6 +2614,5 @@ QPDFObjectHandle::setParsedOffset(qpdf_offset_t offset) | @@ -2717,6 +2614,5 @@ QPDFObjectHandle::setParsedOffset(qpdf_offset_t offset) | ||
| 2717 | QPDFObjectHandle | 2614 | QPDFObjectHandle |
| 2718 | operator""_qpdf(char const* v, size_t len) | 2615 | operator""_qpdf(char const* v, size_t len) |
| 2719 | { | 2616 | { |
| 2720 | - return QPDFObjectHandle::parse( | ||
| 2721 | - std::string(v, len), "QPDFObjectHandle literal"); | 2617 | + return QPDFObjectHandle::parse(std::string(v, len), "QPDFObjectHandle literal"); |
| 2722 | } | 2618 | } |
libqpdf/QPDFOutlineDocumentHelper.cc
| @@ -17,8 +17,7 @@ QPDFOutlineDocumentHelper::QPDFOutlineDocumentHelper(QPDF& qpdf) : | @@ -17,8 +17,7 @@ QPDFOutlineDocumentHelper::QPDFOutlineDocumentHelper(QPDF& qpdf) : | ||
| 17 | QPDFObjectHandle cur = outlines.getKey("/First"); | 17 | QPDFObjectHandle cur = outlines.getKey("/First"); |
| 18 | QPDFObjGen::set seen; | 18 | QPDFObjGen::set seen; |
| 19 | while (!cur.isNull() && seen.add(cur)) { | 19 | while (!cur.isNull() && seen.add(cur)) { |
| 20 | - m->outlines.push_back( | ||
| 21 | - QPDFOutlineObjectHelper::Accessor::create(cur, *this, 1)); | 20 | + m->outlines.push_back(QPDFOutlineObjectHelper::Accessor::create(cur, *this, 1)); |
| 22 | cur = cur.getKey("/Next"); | 21 | cur = cur.getKey("/Next"); |
| 23 | } | 22 | } |
| 24 | } | 23 | } |
| @@ -81,8 +80,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name) | @@ -81,8 +80,7 @@ QPDFOutlineDocumentHelper::resolveNamedDest(QPDFObjectHandle name) | ||
| 81 | if (names.isDictionary()) { | 80 | if (names.isDictionary()) { |
| 82 | QPDFObjectHandle dests = names.getKey("/Dests"); | 81 | QPDFObjectHandle dests = names.getKey("/Dests"); |
| 83 | if (dests.isDictionary()) { | 82 | if (dests.isDictionary()) { |
| 84 | - m->names_dest = std::make_shared<QPDFNameTreeObjectHelper>( | ||
| 85 | - dests, this->qpdf); | 83 | + m->names_dest = std::make_shared<QPDFNameTreeObjectHelper>(dests, this->qpdf); |
| 86 | } | 84 | } |
| 87 | } | 85 | } |
| 88 | } | 86 | } |
libqpdf/QPDFOutlineObjectHelper.cc
| @@ -18,8 +18,7 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( | @@ -18,8 +18,7 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( | ||
| 18 | // temporarily changing max depth to 1. | 18 | // temporarily changing max depth to 1. |
| 19 | return; | 19 | return; |
| 20 | } | 20 | } |
| 21 | - if (QPDFOutlineDocumentHelper::Accessor::checkSeen( | ||
| 22 | - m->dh, this->oh.getObjGen())) { | 21 | + if (QPDFOutlineDocumentHelper::Accessor::checkSeen(m->dh, this->oh.getObjGen())) { |
| 23 | QTC::TC("qpdf", "QPDFOutlineObjectHelper loop"); | 22 | QTC::TC("qpdf", "QPDFOutlineObjectHelper loop"); |
| 24 | return; | 23 | return; |
| 25 | } | 24 | } |
libqpdf/QPDFPageDocumentHelper.cc
| @@ -43,8 +43,7 @@ void | @@ -43,8 +43,7 @@ void | ||
| 43 | QPDFPageDocumentHelper::addPageAt( | 43 | QPDFPageDocumentHelper::addPageAt( |
| 44 | QPDFPageObjectHelper newpage, bool before, QPDFPageObjectHelper refpage) | 44 | QPDFPageObjectHelper newpage, bool before, QPDFPageObjectHelper refpage) |
| 45 | { | 45 | { |
| 46 | - this->qpdf.addPageAt( | ||
| 47 | - newpage.getObjectHandle(), before, refpage.getObjectHandle()); | 46 | + this->qpdf.addPageAt(newpage.getObjectHandle(), before, refpage.getObjectHandle()); |
| 48 | } | 47 | } |
| 49 | 48 | ||
| 50 | void | 49 | void |
| @@ -54,8 +53,7 @@ QPDFPageDocumentHelper::removePage(QPDFPageObjectHelper page) | @@ -54,8 +53,7 @@ QPDFPageDocumentHelper::removePage(QPDFPageObjectHelper page) | ||
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | void | 55 | void |
| 57 | -QPDFPageDocumentHelper::flattenAnnotations( | ||
| 58 | - int required_flags, int forbidden_flags) | 56 | +QPDFPageDocumentHelper::flattenAnnotations(int required_flags, int forbidden_flags) |
| 59 | { | 57 | { |
| 60 | QPDFAcroFormDocumentHelper afdh(this->qpdf); | 58 | QPDFAcroFormDocumentHelper afdh(this->qpdf); |
| 61 | if (afdh.getNeedAppearances()) { | 59 | if (afdh.getNeedAppearances()) { |
| @@ -67,14 +65,11 @@ QPDFPageDocumentHelper::flattenAnnotations( | @@ -67,14 +65,11 @@ QPDFPageDocumentHelper::flattenAnnotations( | ||
| 67 | for (auto& ph: getAllPages()) { | 65 | for (auto& ph: getAllPages()) { |
| 68 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); | 66 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); |
| 69 | if (!resources.isDictionary()) { | 67 | if (!resources.isDictionary()) { |
| 70 | - QTC::TC( | ||
| 71 | - "qpdf", | ||
| 72 | - "QPDFPageDocumentHelper flatten resources missing or invalid"); | 68 | + QTC::TC("qpdf", "QPDFPageDocumentHelper flatten resources missing or invalid"); |
| 73 | resources = ph.getObjectHandle().replaceKeyAndGetNew( | 69 | resources = ph.getObjectHandle().replaceKeyAndGetNew( |
| 74 | "/Resources", QPDFObjectHandle::newDictionary()); | 70 | "/Resources", QPDFObjectHandle::newDictionary()); |
| 75 | } | 71 | } |
| 76 | - flattenAnnotationsForPage( | ||
| 77 | - ph, resources, afdh, required_flags, forbidden_flags); | 72 | + flattenAnnotationsForPage(ph, resources, afdh, required_flags, forbidden_flags); |
| 78 | } | 73 | } |
| 79 | if (!afdh.getNeedAppearances()) { | 74 | if (!afdh.getNeedAppearances()) { |
| 80 | this->qpdf.getRoot().removeKey("/AcroForm"); | 75 | this->qpdf.getRoot().removeKey("/AcroForm"); |
| @@ -104,21 +99,17 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | @@ -104,21 +99,17 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | ||
| 104 | bool is_widget = (aoh.getSubtype() == "/Widget"); | 99 | bool is_widget = (aoh.getSubtype() == "/Widget"); |
| 105 | bool process = true; | 100 | bool process = true; |
| 106 | if (need_appearances && is_widget) { | 101 | if (need_appearances && is_widget) { |
| 107 | - QTC::TC( | ||
| 108 | - "qpdf", "QPDFPageDocumentHelper skip widget need appearances"); | 102 | + QTC::TC("qpdf", "QPDFPageDocumentHelper skip widget need appearances"); |
| 109 | process = false; | 103 | process = false; |
| 110 | } | 104 | } |
| 111 | if (process && as.isStream()) { | 105 | if (process && as.isStream()) { |
| 112 | if (is_widget) { | 106 | if (is_widget) { |
| 113 | QTC::TC("qpdf", "QPDFPageDocumentHelper merge DR"); | 107 | QTC::TC("qpdf", "QPDFPageDocumentHelper merge DR"); |
| 114 | QPDFFormFieldObjectHelper ff = afdh.getFieldForAnnotation(aoh); | 108 | QPDFFormFieldObjectHelper ff = afdh.getFieldForAnnotation(aoh); |
| 115 | - QPDFObjectHandle as_resources = | ||
| 116 | - as.getDict().getKey("/Resources"); | 109 | + QPDFObjectHandle as_resources = as.getDict().getKey("/Resources"); |
| 117 | if (as_resources.isIndirect()) { | 110 | if (as_resources.isIndirect()) { |
| 118 | - QTC::TC( | ||
| 119 | - "qpdf", "QPDFPageDocumentHelper indirect as resources"); | ||
| 120 | - as.getDict().replaceKey( | ||
| 121 | - "/Resources", as_resources.shallowCopy()); | 111 | + QTC::TC("qpdf", "QPDFPageDocumentHelper indirect as resources"); |
| 112 | + as.getDict().replaceKey("/Resources", as_resources.shallowCopy()); | ||
| 122 | as_resources = as.getDict().getKey("/Resources"); | 113 | as_resources = as.getDict().getKey("/Resources"); |
| 123 | } | 114 | } |
| 124 | as_resources.mergeResources(ff.getDefaultResources()); | 115 | as_resources.mergeResources(ff.getDefaultResources()); |
| @@ -126,8 +117,8 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | @@ -126,8 +117,8 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | ||
| 126 | QTC::TC("qpdf", "QPDFPageDocumentHelper non-widget annotation"); | 117 | QTC::TC("qpdf", "QPDFPageDocumentHelper non-widget annotation"); |
| 127 | } | 118 | } |
| 128 | std::string name = resources.getUniqueResourceName("/Fxo", next_fx); | 119 | std::string name = resources.getUniqueResourceName("/Fxo", next_fx); |
| 129 | - std::string content = aoh.getPageContentForAppearance( | ||
| 130 | - name, rotate, required_flags, forbidden_flags); | 120 | + std::string content = |
| 121 | + aoh.getPageContentForAppearance(name, rotate, required_flags, forbidden_flags); | ||
| 131 | if (!content.empty()) { | 122 | if (!content.empty()) { |
| 132 | resources.mergeResources("<< /XObject << >> >>"_qpdf); | 123 | resources.mergeResources("<< /XObject << >> >>"_qpdf); |
| 133 | resources.getKey("/XObject").replaceKey(name, as); | 124 | resources.getKey("/XObject").replaceKey(name, as); |
| @@ -140,9 +131,7 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | @@ -140,9 +131,7 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | ||
| 140 | // unchecked checkboxes and radio buttons, popup windows | 131 | // unchecked checkboxes and radio buttons, popup windows |
| 141 | // associated with comments that aren't visible, and other | 132 | // associated with comments that aren't visible, and other |
| 142 | // types of annotations that aren't visible. | 133 | // types of annotations that aren't visible. |
| 143 | - QTC::TC( | ||
| 144 | - "qpdf", | ||
| 145 | - "QPDFPageDocumentHelper ignore annotation with no appearance"); | 134 | + QTC::TC("qpdf", "QPDFPageDocumentHelper ignore annotation with no appearance"); |
| 146 | } else { | 135 | } else { |
| 147 | new_annots.push_back(aoh.getObjectHandle()); | 136 | new_annots.push_back(aoh.getObjectHandle()); |
| 148 | } | 137 | } |
| @@ -154,11 +143,9 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | @@ -154,11 +143,9 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( | ||
| 154 | page_oh.removeKey("/Annots"); | 143 | page_oh.removeKey("/Annots"); |
| 155 | } else { | 144 | } else { |
| 156 | QPDFObjectHandle old_annots = page_oh.getKey("/Annots"); | 145 | QPDFObjectHandle old_annots = page_oh.getKey("/Annots"); |
| 157 | - QPDFObjectHandle new_annots_oh = | ||
| 158 | - QPDFObjectHandle::newArray(new_annots); | 146 | + QPDFObjectHandle new_annots_oh = QPDFObjectHandle::newArray(new_annots); |
| 159 | if (old_annots.isIndirect()) { | 147 | if (old_annots.isIndirect()) { |
| 160 | - QTC::TC( | ||
| 161 | - "qpdf", "QPDFPageDocumentHelper replace indirect annots"); | 148 | + QTC::TC("qpdf", "QPDFPageDocumentHelper replace indirect annots"); |
| 162 | this->qpdf.replaceObject(old_annots.getObjGen(), new_annots_oh); | 149 | this->qpdf.replaceObject(old_annots.getObjGen(), new_annots_oh); |
| 163 | } else { | 150 | } else { |
| 164 | QTC::TC("qpdf", "QPDFPageDocumentHelper replace direct annots"); | 151 | QTC::TC("qpdf", "QPDFPageDocumentHelper replace direct annots"); |
libqpdf/QPDFPageLabelDocumentHelper.cc
| @@ -8,8 +8,8 @@ QPDFPageLabelDocumentHelper::QPDFPageLabelDocumentHelper(QPDF& qpdf) : | @@ -8,8 +8,8 @@ QPDFPageLabelDocumentHelper::QPDFPageLabelDocumentHelper(QPDF& qpdf) : | ||
| 8 | { | 8 | { |
| 9 | QPDFObjectHandle root = qpdf.getRoot(); | 9 | QPDFObjectHandle root = qpdf.getRoot(); |
| 10 | if (root.hasKey("/PageLabels")) { | 10 | if (root.hasKey("/PageLabels")) { |
| 11 | - m->labels = std::make_shared<QPDFNumberTreeObjectHelper>( | ||
| 12 | - root.getKey("/PageLabels"), this->qpdf); | 11 | + m->labels = |
| 12 | + std::make_shared<QPDFNumberTreeObjectHelper>(root.getKey("/PageLabels"), this->qpdf); | ||
| 13 | } | 13 | } |
| 14 | } | 14 | } |
| 15 | 15 | ||
| @@ -66,8 +66,7 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange( | @@ -66,8 +66,7 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange( | ||
| 66 | QPDFObjectHandle label = getLabelForPage(start_idx); | 66 | QPDFObjectHandle label = getLabelForPage(start_idx); |
| 67 | if (label.isNull()) { | 67 | if (label.isNull()) { |
| 68 | label = QPDFObjectHandle::newDictionary(); | 68 | label = QPDFObjectHandle::newDictionary(); |
| 69 | - label.replaceKey( | ||
| 70 | - "/St", QPDFObjectHandle::newInteger(1 + new_start_idx)); | 69 | + label.replaceKey("/St", QPDFObjectHandle::newInteger(1 + new_start_idx)); |
| 71 | } | 70 | } |
| 72 | // See if the new label is redundant based on the previous entry | 71 | // See if the new label is redundant based on the previous entry |
| 73 | // in the vector. If so, don't add it. | 72 | // in the vector. If so, don't add it. |
| @@ -80,8 +79,8 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange( | @@ -80,8 +79,8 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange( | ||
| 80 | (label.getKey("/S").unparse() == last.getKey("/S").unparse()) && | 79 | (label.getKey("/S").unparse() == last.getKey("/S").unparse()) && |
| 81 | (label.getKey("/P").unparse() == last.getKey("/P").unparse()) && | 80 | (label.getKey("/P").unparse() == last.getKey("/P").unparse()) && |
| 82 | label.getKey("/St").isInteger() && last.getKey("/St").isInteger()) { | 81 | label.getKey("/St").isInteger() && last.getKey("/St").isInteger()) { |
| 83 | - long long int st_delta = label.getKey("/St").getIntValue() - | ||
| 84 | - last.getKey("/St").getIntValue(); | 82 | + long long int st_delta = |
| 83 | + label.getKey("/St").getIntValue() - last.getKey("/St").getIntValue(); | ||
| 85 | long long int idx_delta = new_start_idx - last_idx.getIntValue(); | 84 | long long int idx_delta = new_start_idx - last_idx.getIntValue(); |
| 86 | if (st_delta == idx_delta) { | 85 | if (st_delta == idx_delta) { |
| 87 | QTC::TC("qpdf", "QPDFPageLabelDocumentHelper skip first"); | 86 | QTC::TC("qpdf", "QPDFPageLabelDocumentHelper skip first"); |
| @@ -96,8 +95,7 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange( | @@ -96,8 +95,7 @@ QPDFPageLabelDocumentHelper::getLabelsForPageRange( | ||
| 96 | 95 | ||
| 97 | long long int idx_offset = new_start_idx - start_idx; | 96 | long long int idx_offset = new_start_idx - start_idx; |
| 98 | for (long long i = start_idx + 1; i <= end_idx; ++i) { | 97 | for (long long i = start_idx + 1; i <= end_idx; ++i) { |
| 99 | - if (m->labels->hasIndex(i) && | ||
| 100 | - (label = getLabelForPage(i)).isDictionary()) { | 98 | + if (m->labels->hasIndex(i) && (label = getLabelForPage(i)).isDictionary()) { |
| 101 | new_labels.push_back(QPDFObjectHandle::newInteger(i + idx_offset)); | 99 | new_labels.push_back(QPDFObjectHandle::newInteger(i + idx_offset)); |
| 102 | new_labels.push_back(label); | 100 | new_labels.push_back(label); |
| 103 | } | 101 | } |
libqpdf/QPDFPageObjectHelper.cc
| @@ -32,11 +32,9 @@ void | @@ -32,11 +32,9 @@ void | ||
| 32 | ContentProvider::provideStreamData(QPDFObjGen const&, Pipeline* p) | 32 | ContentProvider::provideStreamData(QPDFObjGen const&, Pipeline* p) |
| 33 | { | 33 | { |
| 34 | Pl_Concatenate concat("concatenate", p); | 34 | Pl_Concatenate concat("concatenate", p); |
| 35 | - std::string description = | ||
| 36 | - "contents from page object " + from_page.getObjGen().unparse(' '); | 35 | + std::string description = "contents from page object " + from_page.getObjGen().unparse(' '); |
| 37 | std::string all_description; | 36 | std::string all_description; |
| 38 | - from_page.getKey("/Contents") | ||
| 39 | - .pipeContentStreams(&concat, description, all_description); | 37 | + from_page.getKey("/Contents").pipeContentStreams(&concat, description, all_description); |
| 40 | concat.manualFinish(); | 38 | concat.manualFinish(); |
| 41 | } | 39 | } |
| 42 | 40 | ||
| @@ -61,8 +59,7 @@ namespace | @@ -61,8 +59,7 @@ namespace | ||
| 61 | }; | 59 | }; |
| 62 | } // namespace | 60 | } // namespace |
| 63 | 61 | ||
| 64 | -InlineImageTracker::InlineImageTracker( | ||
| 65 | - QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) : | 62 | +InlineImageTracker::InlineImageTracker(QPDF* qpdf, size_t min_size, QPDFObjectHandle resources) : |
| 66 | qpdf(qpdf), | 63 | qpdf(qpdf), |
| 67 | min_size(min_size), | 64 | min_size(min_size), |
| 68 | resources(resources), | 65 | resources(resources), |
| @@ -117,15 +114,12 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict) | @@ -117,15 +114,12 @@ InlineImageTracker::convertIIDict(QPDFObjectHandle odict) | ||
| 117 | // /ColorSpace dictionary. We need to look it up | 114 | // /ColorSpace dictionary. We need to look it up |
| 118 | // and use its value as the color space for the | 115 | // and use its value as the color space for the |
| 119 | // image. | 116 | // image. |
| 120 | - QPDFObjectHandle colorspace = | ||
| 121 | - resources.getKey("/ColorSpace"); | 117 | + QPDFObjectHandle colorspace = resources.getKey("/ColorSpace"); |
| 122 | if (colorspace.isDictionary() && colorspace.hasKey(name)) { | 118 | if (colorspace.isDictionary() && colorspace.hasKey(name)) { |
| 123 | - QTC::TC( | ||
| 124 | - "qpdf", "QPDFPageObjectHelper colorspace lookup"); | 119 | + QTC::TC("qpdf", "QPDFPageObjectHelper colorspace lookup"); |
| 125 | value = colorspace.getKey(name); | 120 | value = colorspace.getKey(name); |
| 126 | } else { | 121 | } else { |
| 127 | - resources.warnIfPossible( | ||
| 128 | - "unable to resolve colorspace " + name); | 122 | + resources.warnIfPossible("unable to resolve colorspace " + name); |
| 129 | } | 123 | } |
| 130 | name.clear(); | 124 | name.clear(); |
| 131 | } | 125 | } |
| @@ -185,20 +179,15 @@ InlineImageTracker::handleToken(QPDFTokenizer::Token const& token) | @@ -185,20 +179,15 @@ InlineImageTracker::handleToken(QPDFTokenizer::Token const& token) | ||
| 185 | std::string image_data(token.getValue()); | 179 | std::string image_data(token.getValue()); |
| 186 | size_t len = image_data.length(); | 180 | size_t len = image_data.length(); |
| 187 | if (len >= this->min_size) { | 181 | if (len >= this->min_size) { |
| 188 | - QTC::TC( | ||
| 189 | - "qpdf", "QPDFPageObjectHelper externalize inline image"); | 182 | + QTC::TC("qpdf", "QPDFPageObjectHelper externalize inline image"); |
| 190 | Pl_Buffer b("image_data"); | 183 | Pl_Buffer b("image_data"); |
| 191 | b.writeString(image_data); | 184 | b.writeString(image_data); |
| 192 | b.finish(); | 185 | b.finish(); |
| 193 | - QPDFObjectHandle dict = | ||
| 194 | - convertIIDict(QPDFObjectHandle::parse(dict_str)); | ||
| 195 | - dict.replaceKey( | ||
| 196 | - "/Length", | ||
| 197 | - QPDFObjectHandle::newInteger(QIntC::to_longlong(len))); | ||
| 198 | - std::string name = | ||
| 199 | - resources.getUniqueResourceName("/IIm", this->min_suffix); | ||
| 200 | - QPDFObjectHandle image = QPDFObjectHandle::newStream( | ||
| 201 | - this->qpdf, b.getBufferSharedPointer()); | 186 | + QPDFObjectHandle dict = convertIIDict(QPDFObjectHandle::parse(dict_str)); |
| 187 | + dict.replaceKey("/Length", QPDFObjectHandle::newInteger(QIntC::to_longlong(len))); | ||
| 188 | + std::string name = resources.getUniqueResourceName("/IIm", this->min_suffix); | ||
| 189 | + QPDFObjectHandle image = | ||
| 190 | + QPDFObjectHandle::newStream(this->qpdf, b.getBufferSharedPointer()); | ||
| 202 | image.replaceDict(dict); | 191 | image.replaceDict(dict); |
| 203 | resources.getKey("/XObject").replaceKey(name, image); | 192 | resources.getKey("/XObject").replaceKey(name, image); |
| 204 | write(name); | 193 | write(name); |
| @@ -252,8 +241,7 @@ QPDFPageObjectHelper::getAttribute( | @@ -252,8 +241,7 @@ QPDFPageObjectHelper::getAttribute( | ||
| 252 | auto result = dict.getKey(name); | 241 | auto result = dict.getKey(name); |
| 253 | 242 | ||
| 254 | if (!is_form_xobject && result.isNull() && | 243 | if (!is_form_xobject && result.isNull() && |
| 255 | - (name == "/MediaBox" || name == "/CropBox" || name == "/Resources" || | ||
| 256 | - name == "/Rotate")) { | 244 | + (name == "/MediaBox" || name == "/CropBox" || name == "/Resources" || name == "/Rotate")) { |
| 257 | QPDFObjectHandle node = dict; | 245 | QPDFObjectHandle node = dict; |
| 258 | QPDFObjGen::set seen{}; | 246 | QPDFObjGen::set seen{}; |
| 259 | while (seen.add(node) && node.hasKey("/Parent")) { | 247 | while (seen.add(node) && node.hasKey("/Parent")) { |
| @@ -267,10 +255,7 @@ QPDFPageObjectHelper::getAttribute( | @@ -267,10 +255,7 @@ QPDFPageObjectHelper::getAttribute( | ||
| 267 | } | 255 | } |
| 268 | } | 256 | } |
| 269 | if (copy_if_shared && (inherited || result.isIndirect())) { | 257 | if (copy_if_shared && (inherited || result.isIndirect())) { |
| 270 | - QTC::TC( | ||
| 271 | - "qpdf", | ||
| 272 | - "QPDFPageObjectHelper copy shared attribute", | ||
| 273 | - is_form_xobject ? 0 : 1); | 258 | + QTC::TC("qpdf", "QPDFPageObjectHelper copy shared attribute", is_form_xobject ? 0 : 1); |
| 274 | result = dict.replaceKeyAndGetNew(name, result.shallowCopy()); | 259 | result = dict.replaceKeyAndGetNew(name, result.shallowCopy()); |
| 275 | } | 260 | } |
| 276 | if (result.isNull() && get_fallback) { | 261 | if (result.isNull() && get_fallback) { |
| @@ -279,8 +264,7 @@ QPDFPageObjectHelper::getAttribute( | @@ -279,8 +264,7 @@ QPDFPageObjectHelper::getAttribute( | ||
| 279 | QTC::TC("qpdf", "QPDFPageObjectHelper copied fallback"); | 264 | QTC::TC("qpdf", "QPDFPageObjectHelper copied fallback"); |
| 280 | result = dict.replaceKeyAndGetNew(name, result.shallowCopy()); | 265 | result = dict.replaceKeyAndGetNew(name, result.shallowCopy()); |
| 281 | } else { | 266 | } else { |
| 282 | - QTC::TC( | ||
| 283 | - "qpdf", "QPDFPageObjectHelper used fallback without copying"); | 267 | + QTC::TC("qpdf", "QPDFPageObjectHelper used fallback without copying"); |
| 284 | } | 268 | } |
| 285 | } | 269 | } |
| 286 | return result; | 270 | return result; |
| @@ -341,25 +325,21 @@ QPDFPageObjectHelper::getBleedBox(bool copy_if_shared, bool copy_if_fallback) | @@ -341,25 +325,21 @@ QPDFPageObjectHelper::getBleedBox(bool copy_if_shared, bool copy_if_fallback) | ||
| 341 | void | 325 | void |
| 342 | QPDFPageObjectHelper::forEachXObject( | 326 | QPDFPageObjectHelper::forEachXObject( |
| 343 | bool recursive, | 327 | bool recursive, |
| 344 | - std::function<void( | ||
| 345 | - QPDFObjectHandle& obj, | ||
| 346 | - QPDFObjectHandle& xobj_dict, | ||
| 347 | - std::string const& key)> action, | 328 | + std::function<void(QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)> |
| 329 | + action, | ||
| 348 | std::function<bool(QPDFObjectHandle)> selector) | 330 | std::function<bool(QPDFObjectHandle)> selector) |
| 349 | { | 331 | { |
| 350 | QTC::TC( | 332 | QTC::TC( |
| 351 | "qpdf", | 333 | "qpdf", |
| 352 | "QPDFPageObjectHelper::forEachXObject", | 334 | "QPDFPageObjectHelper::forEachXObject", |
| 353 | - recursive ? (this->oh.isFormXObject() ? 0 : 1) | ||
| 354 | - : (this->oh.isFormXObject() ? 2 : 3)); | 335 | + recursive ? (this->oh.isFormXObject() ? 0 : 1) : (this->oh.isFormXObject() ? 2 : 3)); |
| 355 | QPDFObjGen::set seen; | 336 | QPDFObjGen::set seen; |
| 356 | std::list<QPDFPageObjectHelper> queue; | 337 | std::list<QPDFPageObjectHelper> queue; |
| 357 | queue.push_back(*this); | 338 | queue.push_back(*this); |
| 358 | while (!queue.empty()) { | 339 | while (!queue.empty()) { |
| 359 | auto& ph = queue.front(); | 340 | auto& ph = queue.front(); |
| 360 | if (seen.add(ph)) { | 341 | if (seen.add(ph)) { |
| 361 | - auto xobj_dict = | ||
| 362 | - ph.getAttribute("/Resources", false).getKeyIfDict("/XObject"); | 342 | + auto xobj_dict = ph.getAttribute("/Resources", false).getKeyIfDict("/XObject"); |
| 363 | if (xobj_dict.isDictionary()) { | 343 | if (xobj_dict.isDictionary()) { |
| 364 | for (auto const& key: xobj_dict.getKeys()) { | 344 | for (auto const& key: xobj_dict.getKeys()) { |
| 365 | QPDFObjectHandle obj = xobj_dict.getKey(key); | 345 | QPDFObjectHandle obj = xobj_dict.getKey(key); |
| @@ -379,26 +359,19 @@ QPDFPageObjectHelper::forEachXObject( | @@ -379,26 +359,19 @@ QPDFPageObjectHelper::forEachXObject( | ||
| 379 | void | 359 | void |
| 380 | QPDFPageObjectHelper::forEachImage( | 360 | QPDFPageObjectHelper::forEachImage( |
| 381 | bool recursive, | 361 | bool recursive, |
| 382 | - std::function<void( | ||
| 383 | - QPDFObjectHandle& obj, | ||
| 384 | - QPDFObjectHandle& xobj_dict, | ||
| 385 | - std::string const& key)> action) | 362 | + std::function<void(QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)> |
| 363 | + action) | ||
| 386 | { | 364 | { |
| 387 | - forEachXObject( | ||
| 388 | - recursive, action, [](QPDFObjectHandle obj) { return obj.isImage(); }); | 365 | + forEachXObject(recursive, action, [](QPDFObjectHandle obj) { return obj.isImage(); }); |
| 389 | } | 366 | } |
| 390 | 367 | ||
| 391 | void | 368 | void |
| 392 | QPDFPageObjectHelper::forEachFormXObject( | 369 | QPDFPageObjectHelper::forEachFormXObject( |
| 393 | bool recursive, | 370 | bool recursive, |
| 394 | - std::function<void( | ||
| 395 | - QPDFObjectHandle& obj, | ||
| 396 | - QPDFObjectHandle& xobj_dict, | ||
| 397 | - std::string const& key)> action) | 371 | + std::function<void(QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key)> |
| 372 | + action) | ||
| 398 | { | 373 | { |
| 399 | - forEachXObject(recursive, action, [](QPDFObjectHandle obj) { | ||
| 400 | - return obj.isFormXObject(); | ||
| 401 | - }); | 374 | + forEachXObject(recursive, action, [](QPDFObjectHandle obj) { return obj.isFormXObject(); }); |
| 402 | } | 375 | } |
| 403 | 376 | ||
| 404 | std::map<std::string, QPDFObjectHandle> | 377 | std::map<std::string, QPDFObjectHandle> |
| @@ -412,9 +385,7 @@ QPDFPageObjectHelper::getImages() | @@ -412,9 +385,7 @@ QPDFPageObjectHelper::getImages() | ||
| 412 | { | 385 | { |
| 413 | std::map<std::string, QPDFObjectHandle> result; | 386 | std::map<std::string, QPDFObjectHandle> result; |
| 414 | forEachImage( | 387 | forEachImage( |
| 415 | - false, | ||
| 416 | - [&result]( | ||
| 417 | - QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const& key) { | 388 | + false, [&result](QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const& key) { |
| 418 | result[key] = obj; | 389 | result[key] = obj; |
| 419 | }); | 390 | }); |
| 420 | return result; | 391 | return result; |
| @@ -425,9 +396,7 @@ QPDFPageObjectHelper::getFormXObjects() | @@ -425,9 +396,7 @@ QPDFPageObjectHelper::getFormXObjects() | ||
| 425 | { | 396 | { |
| 426 | std::map<std::string, QPDFObjectHandle> result; | 397 | std::map<std::string, QPDFObjectHandle> result; |
| 427 | forEachFormXObject( | 398 | forEachFormXObject( |
| 428 | - false, | ||
| 429 | - [&result]( | ||
| 430 | - QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const& key) { | 399 | + false, [&result](QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const& key) { |
| 431 | result[key] = obj; | 400 | result[key] = obj; |
| 432 | }); | 401 | }); |
| 433 | return result; | 402 | return result; |
| @@ -462,18 +431,14 @@ QPDFPageObjectHelper::externalizeInlineImages(size_t min_size, bool shallow) | @@ -462,18 +431,14 @@ QPDFPageObjectHelper::externalizeInlineImages(size_t min_size, bool shallow) | ||
| 462 | } else { | 431 | } else { |
| 463 | this->oh.replaceKey( | 432 | this->oh.replaceKey( |
| 464 | "/Contents", | 433 | "/Contents", |
| 465 | - QPDFObjectHandle::newStream( | ||
| 466 | - &this->oh.getQPDF(), b.getBufferSharedPointer())); | 434 | + QPDFObjectHandle::newStream(&this->oh.getQPDF(), b.getBufferSharedPointer())); |
| 467 | } | 435 | } |
| 468 | } | 436 | } |
| 469 | } else { | 437 | } else { |
| 470 | externalizeInlineImages(min_size, true); | 438 | externalizeInlineImages(min_size, true); |
| 471 | forEachFormXObject( | 439 | forEachFormXObject( |
| 472 | - true, | ||
| 473 | - [min_size]( | ||
| 474 | - QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const&) { | ||
| 475 | - QPDFPageObjectHelper(obj).externalizeInlineImages( | ||
| 476 | - min_size, true); | 440 | + true, [min_size](QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const&) { |
| 441 | + QPDFPageObjectHelper(obj).externalizeInlineImages(min_size, true); | ||
| 477 | }); | 442 | }); |
| 478 | } | 443 | } |
| 479 | } | 444 | } |
| @@ -520,15 +485,13 @@ QPDFPageObjectHelper::coalesceContentStreams() | @@ -520,15 +485,13 @@ QPDFPageObjectHelper::coalesceContentStreams() | ||
| 520 | } | 485 | } |
| 521 | 486 | ||
| 522 | void | 487 | void |
| 523 | -QPDFPageObjectHelper::parsePageContents( | ||
| 524 | - QPDFObjectHandle::ParserCallbacks* callbacks) | 488 | +QPDFPageObjectHelper::parsePageContents(QPDFObjectHandle::ParserCallbacks* callbacks) |
| 525 | { | 489 | { |
| 526 | parseContents(callbacks); | 490 | parseContents(callbacks); |
| 527 | } | 491 | } |
| 528 | 492 | ||
| 529 | void | 493 | void |
| 530 | -QPDFPageObjectHelper::parseContents( | ||
| 531 | - QPDFObjectHandle::ParserCallbacks* callbacks) | 494 | +QPDFPageObjectHelper::parseContents(QPDFObjectHandle::ParserCallbacks* callbacks) |
| 532 | { | 495 | { |
| 533 | if (this->oh.isFormXObject()) { | 496 | if (this->oh.isFormXObject()) { |
| 534 | this->oh.parseAsContents(callbacks); | 497 | this->oh.parseAsContents(callbacks); |
| @@ -538,15 +501,13 @@ QPDFPageObjectHelper::parseContents( | @@ -538,15 +501,13 @@ QPDFPageObjectHelper::parseContents( | ||
| 538 | } | 501 | } |
| 539 | 502 | ||
| 540 | void | 503 | void |
| 541 | -QPDFPageObjectHelper::filterPageContents( | ||
| 542 | - QPDFObjectHandle::TokenFilter* filter, Pipeline* next) | 504 | +QPDFPageObjectHelper::filterPageContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next) |
| 543 | { | 505 | { |
| 544 | return filterContents(filter, next); | 506 | return filterContents(filter, next); |
| 545 | } | 507 | } |
| 546 | 508 | ||
| 547 | void | 509 | void |
| 548 | -QPDFPageObjectHelper::filterContents( | ||
| 549 | - QPDFObjectHandle::TokenFilter* filter, Pipeline* next) | 510 | +QPDFPageObjectHelper::filterContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next) |
| 550 | { | 511 | { |
| 551 | if (this->oh.isFormXObject()) { | 512 | if (this->oh.isFormXObject()) { |
| 552 | this->oh.filterAsContents(filter, next); | 513 | this->oh.filterAsContents(filter, next); |
| @@ -598,10 +559,9 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper( | @@ -598,10 +559,9 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper( | ||
| 598 | ph.parseContents(&rf); | 559 | ph.parseContents(&rf); |
| 599 | size_t after_nw = (q ? q->numWarnings() : 0); | 560 | size_t after_nw = (q ? q->numWarnings() : 0); |
| 600 | if (after_nw > before_nw) { | 561 | if (after_nw > before_nw) { |
| 601 | - ph.oh.warnIfPossible( | ||
| 602 | - "Bad token found while scanning content stream; " | ||
| 603 | - "not attempting to remove unreferenced objects from" | ||
| 604 | - " this object"); | 562 | + ph.oh.warnIfPossible("Bad token found while scanning content stream; " |
| 563 | + "not attempting to remove unreferenced objects from" | ||
| 564 | + " this object"); | ||
| 605 | return false; | 565 | return false; |
| 606 | } | 566 | } |
| 607 | } catch (std::exception& e) { | 567 | } catch (std::exception& e) { |
| @@ -699,10 +659,8 @@ QPDFPageObjectHelper::removeUnreferencedResources() | @@ -699,10 +659,8 @@ QPDFPageObjectHelper::removeUnreferencedResources() | ||
| 699 | bool any_failures = false; | 659 | bool any_failures = false; |
| 700 | forEachFormXObject( | 660 | forEachFormXObject( |
| 701 | true, | 661 | true, |
| 702 | - [&any_failures, &unresolved]( | ||
| 703 | - QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const&) { | ||
| 704 | - if (!removeUnreferencedResourcesHelper( | ||
| 705 | - QPDFPageObjectHelper(obj), unresolved)) { | 662 | + [&any_failures, &unresolved](QPDFObjectHandle& obj, QPDFObjectHandle&, std::string const&) { |
| 663 | + if (!removeUnreferencedResourcesHelper(QPDFPageObjectHelper(obj), unresolved)) { | ||
| 706 | any_failures = true; | 664 | any_failures = true; |
| 707 | } | 665 | } |
| 708 | }); | 666 | }); |
| @@ -714,8 +672,8 @@ QPDFPageObjectHelper::removeUnreferencedResources() | @@ -714,8 +672,8 @@ QPDFPageObjectHelper::removeUnreferencedResources() | ||
| 714 | QPDFPageObjectHelper | 672 | QPDFPageObjectHelper |
| 715 | QPDFPageObjectHelper::shallowCopyPage() | 673 | QPDFPageObjectHelper::shallowCopyPage() |
| 716 | { | 674 | { |
| 717 | - QPDF& qpdf = this->oh.getQPDF( | ||
| 718 | - "QPDFPageObjectHelper::shallowCopyPage called with a direct object"); | 675 | + QPDF& qpdf = |
| 676 | + this->oh.getQPDF("QPDFPageObjectHelper::shallowCopyPage called with a direct object"); | ||
| 719 | QPDFObjectHandle new_page = this->oh.shallowCopy(); | 677 | QPDFObjectHandle new_page = this->oh.shallowCopy(); |
| 720 | return QPDFPageObjectHelper(qpdf.makeIndirectObject(new_page)); | 678 | return QPDFPageObjectHelper(qpdf.makeIndirectObject(new_page)); |
| 721 | } | 679 | } |
| @@ -734,10 +692,8 @@ QPDFPageObjectHelper::getMatrixForTransformations(bool invert) | @@ -734,10 +692,8 @@ QPDFPageObjectHelper::getMatrixForTransformations(bool invert) | ||
| 734 | QPDFObjectHandle::Rectangle rect = bbox.getArrayAsRectangle(); | 692 | QPDFObjectHandle::Rectangle rect = bbox.getArrayAsRectangle(); |
| 735 | double width = rect.urx - rect.llx; | 693 | double width = rect.urx - rect.llx; |
| 736 | double height = rect.ury - rect.lly; | 694 | double height = rect.ury - rect.lly; |
| 737 | - double scale = | ||
| 738 | - (scale_obj.isNumber() ? scale_obj.getNumericValue() : 1.0); | ||
| 739 | - int rotate = | ||
| 740 | - (rotate_obj.isInteger() ? rotate_obj.getIntValueAsInt() : 0); | 695 | + double scale = (scale_obj.isNumber() ? scale_obj.getNumericValue() : 1.0); |
| 696 | + int rotate = (rotate_obj.isInteger() ? rotate_obj.getIntValueAsInt() : 0); | ||
| 741 | if (invert) { | 697 | if (invert) { |
| 742 | if (scale == 0.0) { | 698 | if (scale == 0.0) { |
| 743 | return matrix; | 699 | return matrix; |
| @@ -749,16 +705,13 @@ QPDFPageObjectHelper::getMatrixForTransformations(bool invert) | @@ -749,16 +705,13 @@ QPDFPageObjectHelper::getMatrixForTransformations(bool invert) | ||
| 749 | // Ignore invalid rotation angle | 705 | // Ignore invalid rotation angle |
| 750 | switch (rotate) { | 706 | switch (rotate) { |
| 751 | case 90: | 707 | case 90: |
| 752 | - matrix = | ||
| 753 | - QPDFObjectHandle::Matrix(0, -scale, scale, 0, 0, width * scale); | 708 | + matrix = QPDFObjectHandle::Matrix(0, -scale, scale, 0, 0, width * scale); |
| 754 | break; | 709 | break; |
| 755 | case 180: | 710 | case 180: |
| 756 | - matrix = QPDFObjectHandle::Matrix( | ||
| 757 | - -scale, 0, 0, -scale, width * scale, height * scale); | 711 | + matrix = QPDFObjectHandle::Matrix(-scale, 0, 0, -scale, width * scale, height * scale); |
| 758 | break; | 712 | break; |
| 759 | case 270: | 713 | case 270: |
| 760 | - matrix = QPDFObjectHandle::Matrix( | ||
| 761 | - 0, scale, -scale, 0, height * scale, 0); | 714 | + matrix = QPDFObjectHandle::Matrix(0, scale, -scale, 0, height * scale, 0); |
| 762 | break; | 715 | break; |
| 763 | default: | 716 | default: |
| 764 | matrix = QPDFObjectHandle::Matrix(scale, 0, 0, scale, 0, 0); | 717 | matrix = QPDFObjectHandle::Matrix(scale, 0, 0, scale, 0, 0); |
| @@ -778,8 +731,7 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) | @@ -778,8 +731,7 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) | ||
| 778 | QPDFObjectHandle newdict = result.getDict(); | 731 | QPDFObjectHandle newdict = result.getDict(); |
| 779 | newdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); | 732 | newdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); |
| 780 | newdict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")); | 733 | newdict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")); |
| 781 | - newdict.replaceKey( | ||
| 782 | - "/Resources", getAttribute("/Resources", false).shallowCopy()); | 734 | + newdict.replaceKey("/Resources", getAttribute("/Resources", false).shallowCopy()); |
| 783 | newdict.replaceKey("/Group", getAttribute("/Group", false).shallowCopy()); | 735 | newdict.replaceKey("/Group", getAttribute("/Group", false).shallowCopy()); |
| 784 | QPDFObjectHandle bbox = getTrimBox(false).shallowCopy(); | 736 | QPDFObjectHandle bbox = getTrimBox(false).shallowCopy(); |
| 785 | if (!bbox.isRectangle()) { | 737 | if (!bbox.isRectangle()) { |
| @@ -787,17 +739,13 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) | @@ -787,17 +739,13 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) | ||
| 787 | " XObject created from page will not work"); | 739 | " XObject created from page will not work"); |
| 788 | } | 740 | } |
| 789 | newdict.replaceKey("/BBox", bbox); | 741 | newdict.replaceKey("/BBox", bbox); |
| 790 | - auto provider = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>( | ||
| 791 | - new ContentProvider(this->oh)); | ||
| 792 | - result.replaceStreamData( | ||
| 793 | - provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | 742 | + auto provider = |
| 743 | + std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(new ContentProvider(this->oh)); | ||
| 744 | + result.replaceStreamData(provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | ||
| 794 | QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false); | 745 | QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false); |
| 795 | QPDFObjectHandle scale_obj = getAttribute("/UserUnit", false); | 746 | QPDFObjectHandle scale_obj = getAttribute("/UserUnit", false); |
| 796 | - if (handle_transformations && | ||
| 797 | - (!(rotate_obj.isNull() && scale_obj.isNull()))) { | ||
| 798 | - newdict.replaceKey( | ||
| 799 | - "/Matrix", | ||
| 800 | - QPDFObjectHandle::newArray(getMatrixForTransformations())); | 747 | + if (handle_transformations && (!(rotate_obj.isNull() && scale_obj.isNull()))) { |
| 748 | + newdict.replaceKey("/Matrix", QPDFObjectHandle::newArray(getMatrixForTransformations())); | ||
| 801 | } | 749 | } |
| 802 | 750 | ||
| 803 | return result; | 751 | return result; |
| @@ -921,8 +869,7 @@ QPDFPageObjectHelper::placeFormXObject( | @@ -921,8 +869,7 @@ QPDFPageObjectHelper::placeFormXObject( | ||
| 921 | bool allow_expand) | 869 | bool allow_expand) |
| 922 | { | 870 | { |
| 923 | QPDFMatrix cm; | 871 | QPDFMatrix cm; |
| 924 | - return placeFormXObject( | ||
| 925 | - fo, name, rect, cm, invert_transformations, allow_shrink, allow_expand); | 872 | + return placeFormXObject(fo, name, rect, cm, invert_transformations, allow_shrink, allow_expand); |
| 926 | } | 873 | } |
| 927 | 874 | ||
| 928 | std::string | 875 | std::string |
| @@ -943,8 +890,8 @@ QPDFPageObjectHelper::placeFormXObject( | @@ -943,8 +890,8 @@ QPDFPageObjectHelper::placeFormXObject( | ||
| 943 | void | 890 | void |
| 944 | QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) | 891 | QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) |
| 945 | { | 892 | { |
| 946 | - QPDF& qpdf = this->oh.getQPDF( | ||
| 947 | - "QPDFPageObjectHelper::flattenRotation called with a direct object"); | 893 | + QPDF& qpdf = |
| 894 | + this->oh.getQPDF("QPDFPageObjectHelper::flattenRotation called with a direct object"); | ||
| 948 | auto rotate_oh = this->oh.getKey("/Rotate"); | 895 | auto rotate_oh = this->oh.getKey("/Rotate"); |
| 949 | int rotate = 0; | 896 | int rotate = 0; |
| 950 | if (rotate_oh.isInteger()) { | 897 | if (rotate_oh.isInteger()) { |
| @@ -1013,8 +960,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) | @@ -1013,8 +960,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) | ||
| 1013 | break; | 960 | break; |
| 1014 | } | 961 | } |
| 1015 | 962 | ||
| 1016 | - this->oh.replaceKey( | ||
| 1017 | - boxkey, QPDFObjectHandle::newFromRectangle(new_rect)); | 963 | + this->oh.replaceKey(boxkey, QPDFObjectHandle::newFromRectangle(new_rect)); |
| 1018 | } | 964 | } |
| 1019 | 965 | ||
| 1020 | // When we rotate the page, pivot about the point 0, 0 and then | 966 | // When we rotate the page, pivot about the point 0, 0 and then |
| @@ -1066,8 +1012,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) | @@ -1066,8 +1012,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) | ||
| 1066 | afdhph = std::make_shared<QPDFAcroFormDocumentHelper>(qpdf); | 1012 | afdhph = std::make_shared<QPDFAcroFormDocumentHelper>(qpdf); |
| 1067 | afdh = afdhph.get(); | 1013 | afdh = afdhph.get(); |
| 1068 | } | 1014 | } |
| 1069 | - afdh->transformAnnotations( | ||
| 1070 | - annots, new_annots, new_fields, old_fields, cm); | 1015 | + afdh->transformAnnotations(annots, new_annots, new_fields, old_fields, cm); |
| 1071 | afdh->removeFormFields(old_fields); | 1016 | afdh->removeFormFields(old_fields); |
| 1072 | for (auto const& f: new_fields) { | 1017 | for (auto const& f: new_fields) { |
| 1073 | afdh->addFormField(QPDFFormFieldObjectHelper(f)); | 1018 | afdh->addFormField(QPDFFormFieldObjectHelper(f)); |
| @@ -1090,8 +1035,8 @@ QPDFPageObjectHelper::copyAnnotations( | @@ -1090,8 +1035,8 @@ QPDFPageObjectHelper::copyAnnotations( | ||
| 1090 | 1035 | ||
| 1091 | QPDF& from_qpdf = from_page.getObjectHandle().getQPDF( | 1036 | QPDF& from_qpdf = from_page.getObjectHandle().getQPDF( |
| 1092 | "QPDFPageObjectHelper::copyAnnotations: from page is a direct object"); | 1037 | "QPDFPageObjectHelper::copyAnnotations: from page is a direct object"); |
| 1093 | - QPDF& this_qpdf = this->oh.getQPDF( | ||
| 1094 | - "QPDFPageObjectHelper::copyAnnotations: this page is a direct object"); | 1038 | + QPDF& this_qpdf = |
| 1039 | + this->oh.getQPDF("QPDFPageObjectHelper::copyAnnotations: this page is a direct object"); | ||
| 1095 | 1040 | ||
| 1096 | std::vector<QPDFObjectHandle> new_annots; | 1041 | std::vector<QPDFObjectHandle> new_annots; |
| 1097 | std::vector<QPDFObjectHandle> new_fields; | 1042 | std::vector<QPDFObjectHandle> new_fields; |
| @@ -1106,9 +1051,8 @@ QPDFPageObjectHelper::copyAnnotations( | @@ -1106,9 +1051,8 @@ QPDFPageObjectHelper::copyAnnotations( | ||
| 1106 | from_afdh = afdh; | 1051 | from_afdh = afdh; |
| 1107 | } else if (from_afdh) { | 1052 | } else if (from_afdh) { |
| 1108 | if (from_afdh->getQPDF().getUniqueId() != from_qpdf.getUniqueId()) { | 1053 | if (from_afdh->getQPDF().getUniqueId() != from_qpdf.getUniqueId()) { |
| 1109 | - throw std::logic_error( | ||
| 1110 | - "QPDFAcroFormDocumentHelper::copyAnnotations: from_afdh" | ||
| 1111 | - " is not from the same QPDF as from_page"); | 1054 | + throw std::logic_error("QPDFAcroFormDocumentHelper::copyAnnotations: from_afdh" |
| 1055 | + " is not from the same QPDF as from_page"); | ||
| 1112 | } | 1056 | } |
| 1113 | } else { | 1057 | } else { |
| 1114 | from_afdhph = std::make_shared<QPDFAcroFormDocumentHelper>(from_qpdf); | 1058 | from_afdhph = std::make_shared<QPDFAcroFormDocumentHelper>(from_qpdf); |
| @@ -1116,18 +1060,11 @@ QPDFPageObjectHelper::copyAnnotations( | @@ -1116,18 +1060,11 @@ QPDFPageObjectHelper::copyAnnotations( | ||
| 1116 | } | 1060 | } |
| 1117 | 1061 | ||
| 1118 | afdh->transformAnnotations( | 1062 | afdh->transformAnnotations( |
| 1119 | - old_annots, | ||
| 1120 | - new_annots, | ||
| 1121 | - new_fields, | ||
| 1122 | - old_fields, | ||
| 1123 | - cm, | ||
| 1124 | - &from_qpdf, | ||
| 1125 | - from_afdh); | 1063 | + old_annots, new_annots, new_fields, old_fields, cm, &from_qpdf, from_afdh); |
| 1126 | afdh->addAndRenameFormFields(new_fields); | 1064 | afdh->addAndRenameFormFields(new_fields); |
| 1127 | auto annots = this->oh.getKey("/Annots"); | 1065 | auto annots = this->oh.getKey("/Annots"); |
| 1128 | if (!annots.isArray()) { | 1066 | if (!annots.isArray()) { |
| 1129 | - annots = this->oh.replaceKeyAndGetNew( | ||
| 1130 | - "/Annots", QPDFObjectHandle::newArray()); | 1067 | + annots = this->oh.replaceKeyAndGetNew("/Annots", QPDFObjectHandle::newArray()); |
| 1131 | } | 1068 | } |
| 1132 | for (auto const& annot: new_annots) { | 1069 | for (auto const& annot: new_annots) { |
| 1133 | annots.appendItem(annot); | 1070 | annots.appendItem(annot); |
libqpdf/QPDFParser.cc
| @@ -140,9 +140,8 @@ QPDFParser::parse(bool& empty, bool content_stream) | @@ -140,9 +140,8 @@ QPDFParser::parse(bool& empty, bool content_stream) | ||
| 140 | } else { | 140 | } else { |
| 141 | state = st_start; | 141 | state = st_start; |
| 142 | state_stack.push_back( | 142 | state_stack.push_back( |
| 143 | - (tokenizer.getType() == QPDFTokenizer::tt_array_open) | ||
| 144 | - ? st_array | ||
| 145 | - : st_dictionary); | 143 | + (tokenizer.getType() == QPDFTokenizer::tt_array_open) ? st_array |
| 144 | + : st_dictionary); | ||
| 146 | b_contents = false; | 145 | b_contents = false; |
| 147 | stack.push_back(StackFrame(input)); | 146 | stack.push_back(StackFrame(input)); |
| 148 | } | 147 | } |
| @@ -187,18 +186,15 @@ QPDFParser::parse(bool& empty, bool content_stream) | @@ -187,18 +186,15 @@ QPDFParser::parse(bool& empty, bool content_stream) | ||
| 187 | if (content_stream) { | 186 | if (content_stream) { |
| 188 | object = QPDF_Operator::create(value); | 187 | object = QPDF_Operator::create(value); |
| 189 | } else if ( | 188 | } else if ( |
| 190 | - value == "R" && state != st_top && size >= 2 && | ||
| 191 | - olist.back() && | 189 | + value == "R" && state != st_top && size >= 2 && olist.back() && |
| 192 | olist.back()->getTypeCode() == ::ot_integer && | 190 | olist.back()->getTypeCode() == ::ot_integer && |
| 193 | - !olist.back()->getObjGen().isIndirect() && | ||
| 194 | - olist.at(size - 2) && | 191 | + !olist.back()->getObjGen().isIndirect() && olist.at(size - 2) && |
| 195 | olist.at(size - 2)->getTypeCode() == ::ot_integer && | 192 | olist.at(size - 2)->getTypeCode() == ::ot_integer && |
| 196 | !olist.at(size - 2)->getObjGen().isIndirect()) { | 193 | !olist.at(size - 2)->getObjGen().isIndirect()) { |
| 197 | if (context == nullptr) { | 194 | if (context == nullptr) { |
| 198 | QTC::TC("qpdf", "QPDFParser indirect without context"); | 195 | QTC::TC("qpdf", "QPDFParser indirect without context"); |
| 199 | - throw std::logic_error( | ||
| 200 | - "QPDFObjectHandle::parse called without context" | ||
| 201 | - " on an object with indirect references"); | 196 | + throw std::logic_error("QPDFObjectHandle::parse called without context" |
| 197 | + " on an object with indirect references"); | ||
| 202 | } | 198 | } |
| 203 | auto ref_og = QPDFObjGen( | 199 | auto ref_og = QPDFObjGen( |
| 204 | QPDFObjectHandle(olist.at(size - 2)).getIntValueAsInt(), | 200 | QPDFObjectHandle(olist.at(size - 2)).getIntValueAsInt(), |
| @@ -262,8 +258,7 @@ QPDFParser::parse(bool& empty, bool content_stream) | @@ -262,8 +258,7 @@ QPDFParser::parse(bool& empty, bool content_stream) | ||
| 262 | } | 258 | } |
| 263 | 259 | ||
| 264 | if (object == nullptr && !is_null && | 260 | if (object == nullptr && !is_null && |
| 265 | - (!((state == st_start) || (state == st_stop) || | ||
| 266 | - (state == st_eof)))) { | 261 | + (!((state == st_start) || (state == st_stop) || (state == st_eof)))) { |
| 267 | throw std::logic_error("QPDFObjectHandle::parseInternal: " | 262 | throw std::logic_error("QPDFObjectHandle::parseInternal: " |
| 268 | "unexpected uninitialized object"); | 263 | "unexpected uninitialized object"); |
| 269 | is_null = true; | 264 | is_null = true; |
| @@ -321,15 +316,13 @@ QPDFParser::parse(bool& empty, bool content_stream) | @@ -321,15 +316,13 @@ QPDFParser::parse(bool& empty, bool content_stream) | ||
| 321 | 316 | ||
| 322 | case st_stop: | 317 | case st_stop: |
| 323 | if ((state_stack.size() < 2) || (stack.size() < 2)) { | 318 | if ((state_stack.size() < 2) || (stack.size() < 2)) { |
| 324 | - throw std::logic_error( | ||
| 325 | - "QPDFObjectHandle::parseInternal: st_stop encountered" | ||
| 326 | - " with insufficient elements in stack"); | 319 | + throw std::logic_error("QPDFObjectHandle::parseInternal: st_stop encountered" |
| 320 | + " with insufficient elements in stack"); | ||
| 327 | } | 321 | } |
| 328 | parser_state_e old_state = state_stack.back(); | 322 | parser_state_e old_state = state_stack.back(); |
| 329 | state_stack.pop_back(); | 323 | state_stack.pop_back(); |
| 330 | if (old_state == st_array) { | 324 | if (old_state == st_array) { |
| 331 | - object = QPDF_Array::create( | ||
| 332 | - std::move(olist), frame.null_count > 100); | 325 | + object = QPDF_Array::create(std::move(olist), frame.null_count > 100); |
| 333 | setDescription(object, offset - 1); | 326 | setDescription(object, offset - 1); |
| 334 | // The `offset` points to the next of "[". Set the rewind | 327 | // The `offset` points to the next of "[". Set the rewind |
| 335 | // offset to point to the beginning of "[". This has been | 328 | // offset to point to the beginning of "[". This has been |
| @@ -361,10 +354,7 @@ QPDFParser::parse(bool& empty, bool content_stream) | @@ -361,10 +354,7 @@ QPDFParser::parse(bool& empty, bool content_stream) | ||
| 361 | for (bool found_fake = false; !found_fake;) { | 354 | for (bool found_fake = false; !found_fake;) { |
| 362 | key = "/QPDFFake" + std::to_string(next_fake_key++); | 355 | key = "/QPDFFake" + std::to_string(next_fake_key++); |
| 363 | found_fake = (names.count(key) == 0); | 356 | found_fake = (names.count(key) == 0); |
| 364 | - QTC::TC( | ||
| 365 | - "qpdf", | ||
| 366 | - "QPDFParser found fake", | ||
| 367 | - (found_fake ? 0 : 1)); | 357 | + QTC::TC("qpdf", "QPDFParser found fake", (found_fake ? 0 : 1)); |
| 368 | } | 358 | } |
| 369 | warn( | 359 | warn( |
| 370 | offset, | 360 | offset, |
| @@ -398,11 +388,9 @@ QPDFParser::parse(bool& empty, bool content_stream) | @@ -398,11 +388,9 @@ QPDFParser::parse(bool& empty, bool content_stream) | ||
| 398 | dict[std::move(key)] = std::move(val); | 388 | dict[std::move(key)] = std::move(val); |
| 399 | } | 389 | } |
| 400 | if (!frame.contents_string.empty() && dict.count("/Type") && | 390 | if (!frame.contents_string.empty() && dict.count("/Type") && |
| 401 | - dict["/Type"].isNameAndEquals("/Sig") && | ||
| 402 | - dict.count("/ByteRange") && dict.count("/Contents") && | ||
| 403 | - dict["/Contents"].isString()) { | ||
| 404 | - dict["/Contents"] = | ||
| 405 | - QPDFObjectHandle::newString(frame.contents_string); | 391 | + dict["/Type"].isNameAndEquals("/Sig") && dict.count("/ByteRange") && |
| 392 | + dict.count("/Contents") && dict["/Contents"].isString()) { | ||
| 393 | + dict["/Contents"] = QPDFObjectHandle::newString(frame.contents_string); | ||
| 406 | dict["/Contents"].setParsedOffset(frame.contents_offset); | 394 | dict["/Contents"].setParsedOffset(frame.contents_offset); |
| 407 | } | 395 | } |
| 408 | object = QPDF_Dictionary::create(std::move(dict)); | 396 | object = QPDF_Dictionary::create(std::move(dict)); |
| @@ -433,8 +421,7 @@ QPDFParser::parse(bool& empty, bool content_stream) | @@ -433,8 +421,7 @@ QPDFParser::parse(bool& empty, bool content_stream) | ||
| 433 | } | 421 | } |
| 434 | 422 | ||
| 435 | void | 423 | void |
| 436 | -QPDFParser::setDescription( | ||
| 437 | - std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset) | 424 | +QPDFParser::setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset) |
| 438 | { | 425 | { |
| 439 | if (obj) { | 426 | if (obj) { |
| 440 | obj->setDescription(context, description, parsed_offset); | 427 | obj->setDescription(context, description, parsed_offset); |
| @@ -458,8 +445,7 @@ QPDFParser::warn(QPDFExc const& e) const | @@ -458,8 +445,7 @@ QPDFParser::warn(QPDFExc const& e) const | ||
| 458 | void | 445 | void |
| 459 | QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const | 446 | QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const |
| 460 | { | 447 | { |
| 461 | - warn(QPDFExc( | ||
| 462 | - qpdf_e_damaged_pdf, input->getName(), object_description, offset, msg)); | 448 | + warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(), object_description, offset, msg)); |
| 463 | } | 449 | } |
| 464 | 450 | ||
| 465 | void | 451 | void |
libqpdf/QPDFSystemError.cc
| @@ -2,8 +2,7 @@ | @@ -2,8 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | #include <cstring> | 3 | #include <cstring> |
| 4 | 4 | ||
| 5 | -QPDFSystemError::QPDFSystemError( | ||
| 6 | - std::string const& description, int system_errno) : | 5 | +QPDFSystemError::QPDFSystemError(std::string const& description, int system_errno) : |
| 7 | std::runtime_error(createWhat(description, system_errno)), | 6 | std::runtime_error(createWhat(description, system_errno)), |
| 8 | description(description), | 7 | description(description), |
| 9 | system_errno(system_errno) | 8 | system_errno(system_errno) |
libqpdf/QPDFTokenizer.cc
| @@ -18,10 +18,9 @@ static inline bool | @@ -18,10 +18,9 @@ static inline bool | ||
| 18 | is_delimiter(char ch) | 18 | is_delimiter(char ch) |
| 19 | { | 19 | { |
| 20 | return ( | 20 | return ( |
| 21 | - ch == ' ' || ch == '\n' || ch == '/' || ch == '(' || ch == ')' || | ||
| 22 | - ch == '{' || ch == '}' || ch == '<' || ch == '>' || ch == '[' || | ||
| 23 | - ch == ']' || ch == '%' || ch == '\t' || ch == '\r' || ch == '\v' || | ||
| 24 | - ch == '\f' || ch == 0); | 21 | + ch == ' ' || ch == '\n' || ch == '/' || ch == '(' || ch == ')' || ch == '{' || ch == '}' || |
| 22 | + ch == '<' || ch == '>' || ch == '[' || ch == ']' || ch == '%' || ch == '\t' || ch == '\r' || | ||
| 23 | + ch == '\v' || ch == '\f' || ch == 0); | ||
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | namespace | 26 | namespace |
| @@ -29,8 +28,7 @@ namespace | @@ -29,8 +28,7 @@ namespace | ||
| 29 | class QPDFWordTokenFinder: public InputSource::Finder | 28 | class QPDFWordTokenFinder: public InputSource::Finder |
| 30 | { | 29 | { |
| 31 | public: | 30 | public: |
| 32 | - QPDFWordTokenFinder( | ||
| 33 | - std::shared_ptr<InputSource> is, std::string const& str) : | 31 | + QPDFWordTokenFinder(std::shared_ptr<InputSource> is, std::string const& str) : |
| 34 | is(is), | 32 | is(is), |
| 35 | str(str) | 33 | str(str) |
| 36 | { | 34 | { |
| @@ -243,8 +241,7 @@ QPDFTokenizer::handleCharacter(char ch) | @@ -243,8 +241,7 @@ QPDFTokenizer::handleCharacter(char ch) | ||
| 243 | return; | 241 | return; |
| 244 | 242 | ||
| 245 | default: | 243 | default: |
| 246 | - throw std::logic_error( | ||
| 247 | - "INTERNAL ERROR: invalid state while reading token"); | 244 | + throw std::logic_error("INTERNAL ERROR: invalid state while reading token"); |
| 248 | } | 245 | } |
| 249 | } | 246 | } |
| 250 | 247 | ||
| @@ -673,8 +670,7 @@ QPDFTokenizer::inHexstring(char ch) | @@ -673,8 +670,7 @@ QPDFTokenizer::inHexstring(char ch) | ||
| 673 | } else { | 670 | } else { |
| 674 | this->type = tt_bad; | 671 | this->type = tt_bad; |
| 675 | QTC::TC("qpdf", "QPDFTokenizer bad hexstring character"); | 672 | QTC::TC("qpdf", "QPDFTokenizer bad hexstring character"); |
| 676 | - this->error_message = | ||
| 677 | - std::string("invalid character (") + ch + ") in hexstring"; | 673 | + this->error_message = std::string("invalid character (") + ch + ") in hexstring"; |
| 678 | this->state = st_token_ready; | 674 | this->state = st_token_ready; |
| 679 | } | 675 | } |
| 680 | } | 676 | } |
| @@ -698,8 +694,7 @@ QPDFTokenizer::inHexstring2nd(char ch) | @@ -698,8 +694,7 @@ QPDFTokenizer::inHexstring2nd(char ch) | ||
| 698 | } else { | 694 | } else { |
| 699 | this->type = tt_bad; | 695 | this->type = tt_bad; |
| 700 | QTC::TC("qpdf", "QPDFTokenizer bad hexstring 2nd character"); | 696 | QTC::TC("qpdf", "QPDFTokenizer bad hexstring 2nd character"); |
| 701 | - this->error_message = | ||
| 702 | - std::string("invalid character (") + ch + ") in hexstring"; | 697 | + this->error_message = std::string("invalid character (") + ch + ") in hexstring"; |
| 703 | this->state = st_token_ready; | 698 | this->state = st_token_ready; |
| 704 | } | 699 | } |
| 705 | } | 700 | } |
| @@ -846,14 +841,13 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input) | @@ -846,14 +841,13 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input) | ||
| 846 | bool found_non_printable = false; | 841 | bool found_non_printable = false; |
| 847 | bool found_other = false; | 842 | bool found_other = false; |
| 848 | for (char ch: t.getValue()) { | 843 | for (char ch: t.getValue()) { |
| 849 | - if (((ch >= 'a') && (ch <= 'z')) || | ||
| 850 | - ((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) { | 844 | + if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) || |
| 845 | + (ch == '*')) { | ||
| 851 | // Treat '*' as alpha since there are valid | 846 | // Treat '*' as alpha since there are valid |
| 852 | // PDF operators that contain * along with | 847 | // PDF operators that contain * along with |
| 853 | // alphabetic characters. | 848 | // alphabetic characters. |
| 854 | found_alpha = true; | 849 | found_alpha = true; |
| 855 | - } else if ( | ||
| 856 | - (static_cast<signed char>(ch) < 32) && (!isSpace(ch))) { | 850 | + } else if ((static_cast<signed char>(ch) < 32) && (!isSpace(ch))) { |
| 857 | // Compare ch as a signed char so characters | 851 | // Compare ch as a signed char so characters |
| 858 | // outside of 7-bit will be < 0. | 852 | // outside of 7-bit will be < 0. |
| 859 | found_non_printable = true; | 853 | found_non_printable = true; |
| @@ -893,8 +887,7 @@ QPDFTokenizer::getToken(Token& token, bool& unread_char, char& ch) | @@ -893,8 +887,7 @@ QPDFTokenizer::getToken(Token& token, bool& unread_char, char& ch) | ||
| 893 | ch = this->char_to_unread; | 887 | ch = this->char_to_unread; |
| 894 | if (ready) { | 888 | if (ready) { |
| 895 | token = (!(this->type == tt_name || this->type == tt_string)) | 889 | token = (!(this->type == tt_name || this->type == tt_string)) |
| 896 | - ? Token( | ||
| 897 | - this->type, this->raw_val, this->raw_val, this->error_message) | 890 | + ? Token(this->type, this->raw_val, this->raw_val, this->error_message) |
| 898 | : Token(this->type, this->val, this->raw_val, this->error_message); | 891 | : Token(this->type, this->val, this->raw_val, this->error_message); |
| 899 | 892 | ||
| 900 | this->reset(); | 893 | this->reset(); |
| @@ -910,10 +903,7 @@ QPDFTokenizer::betweenTokens() | @@ -910,10 +903,7 @@ QPDFTokenizer::betweenTokens() | ||
| 910 | 903 | ||
| 911 | QPDFTokenizer::Token | 904 | QPDFTokenizer::Token |
| 912 | QPDFTokenizer::readToken( | 905 | QPDFTokenizer::readToken( |
| 913 | - std::shared_ptr<InputSource> input, | ||
| 914 | - std::string const& context, | ||
| 915 | - bool allow_bad, | ||
| 916 | - size_t max_len) | 906 | + std::shared_ptr<InputSource> input, std::string const& context, bool allow_bad, size_t max_len) |
| 917 | { | 907 | { |
| 918 | nextToken(*input, context, max_len); | 908 | nextToken(*input, context, max_len); |
| 919 | 909 | ||
| @@ -938,8 +928,7 @@ QPDFTokenizer::readToken( | @@ -938,8 +928,7 @@ QPDFTokenizer::readToken( | ||
| 938 | } | 928 | } |
| 939 | 929 | ||
| 940 | bool | 930 | bool |
| 941 | -QPDFTokenizer::nextToken( | ||
| 942 | - InputSource& input, std::string const& context, size_t max_len) | 931 | +QPDFTokenizer::nextToken(InputSource& input, std::string const& context, size_t max_len) |
| 943 | { | 932 | { |
| 944 | if (this->state != st_inline_image) { | 933 | if (this->state != st_inline_image) { |
| 945 | reset(); | 934 | reset(); |
| @@ -967,14 +956,12 @@ QPDFTokenizer::nextToken( | @@ -967,14 +956,12 @@ QPDFTokenizer::nextToken( | ||
| 967 | if (this->in_token) { | 956 | if (this->in_token) { |
| 968 | this->raw_val += ch; | 957 | this->raw_val += ch; |
| 969 | } | 958 | } |
| 970 | - if (max_len && (this->raw_val.length() >= max_len) && | ||
| 971 | - (this->state != st_token_ready)) { | 959 | + if (max_len && (this->raw_val.length() >= max_len) && (this->state != st_token_ready)) { |
| 972 | // terminate this token now | 960 | // terminate this token now |
| 973 | QTC::TC("qpdf", "QPDFTokenizer block long token"); | 961 | QTC::TC("qpdf", "QPDFTokenizer block long token"); |
| 974 | this->type = tt_bad; | 962 | this->type = tt_bad; |
| 975 | this->state = st_token_ready; | 963 | this->state = st_token_ready; |
| 976 | - this->error_message = | ||
| 977 | - "exceeded allowable length while reading token"; | 964 | + this->error_message = "exceeded allowable length while reading token"; |
| 978 | } | 965 | } |
| 979 | } | 966 | } |
| 980 | } | 967 | } |
libqpdf/QPDFValue.cc
| @@ -20,18 +20,15 @@ QPDFValue::getDescription() | @@ -20,18 +20,15 @@ QPDFValue::getDescription() | ||
| 20 | // Simple template string | 20 | // Simple template string |
| 21 | auto description = std::get<0>(*object_description); | 21 | auto description = std::get<0>(*object_description); |
| 22 | 22 | ||
| 23 | - if (auto pos = description.find("$OG"); | ||
| 24 | - pos != std::string::npos) { | 23 | + if (auto pos = description.find("$OG"); pos != std::string::npos) { |
| 25 | description.replace(pos, 3, og.unparse(' ')); | 24 | description.replace(pos, 3, og.unparse(' ')); |
| 26 | } | 25 | } |
| 27 | - if (auto pos = description.find("$PO"); | ||
| 28 | - pos != std::string::npos) { | 26 | + if (auto pos = description.find("$PO"); pos != std::string::npos) { |
| 29 | qpdf_offset_t shift = (type_code == ::ot_dictionary) ? 2 | 27 | qpdf_offset_t shift = (type_code == ::ot_dictionary) ? 2 |
| 30 | : (type_code == ::ot_array) ? 1 | 28 | : (type_code == ::ot_array) ? 1 |
| 31 | : 0; | 29 | : 0; |
| 32 | 30 | ||
| 33 | - description.replace( | ||
| 34 | - pos, 3, std::to_string(parsed_offset + shift)); | 31 | + description.replace(pos, 3, std::to_string(parsed_offset + shift)); |
| 35 | } | 32 | } |
| 36 | return description; | 33 | return description; |
| 37 | } | 34 | } |
| @@ -40,8 +37,7 @@ QPDFValue::getDescription() | @@ -40,8 +37,7 @@ QPDFValue::getDescription() | ||
| 40 | // QPDF::JSONReactor generated description | 37 | // QPDF::JSONReactor generated description |
| 41 | auto j_descr = std::get<1>(*object_description); | 38 | auto j_descr = std::get<1>(*object_description); |
| 42 | return ( | 39 | return ( |
| 43 | - *j_descr.input + | ||
| 44 | - (j_descr.object.empty() ? "" : ", " + j_descr.object) + | 40 | + *j_descr.input + (j_descr.object.empty() ? "" : ", " + j_descr.object) + |
| 45 | " at offset " + std::to_string(parsed_offset)); | 41 | " at offset " + std::to_string(parsed_offset)); |
| 46 | } | 42 | } |
| 47 | case 2: | 43 | case 2: |
libqpdf/QPDFWriter.cc
| @@ -32,8 +32,7 @@ QPDFWriter::ProgressReporter::~ProgressReporter() | @@ -32,8 +32,7 @@ QPDFWriter::ProgressReporter::~ProgressReporter() | ||
| 32 | // README-maintainer | 32 | // README-maintainer |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | -QPDFWriter::FunctionProgressReporter::FunctionProgressReporter( | ||
| 36 | - std::function<void(int)> handler) : | 35 | +QPDFWriter::FunctionProgressReporter::FunctionProgressReporter(std::function<void(int)> handler) : |
| 37 | handler(handler) | 36 | handler(handler) |
| 38 | { | 37 | { |
| 39 | } | 38 | } |
| @@ -52,9 +51,7 @@ QPDFWriter::FunctionProgressReporter::reportProgress(int progress) | @@ -52,9 +51,7 @@ QPDFWriter::FunctionProgressReporter::reportProgress(int progress) | ||
| 52 | 51 | ||
| 53 | QPDFWriter::Members::Members(QPDF& pdf) : | 52 | QPDFWriter::Members::Members(QPDF& pdf) : |
| 54 | pdf(pdf), | 53 | pdf(pdf), |
| 55 | - root_og( | ||
| 56 | - pdf.getRoot().getObjGen().isIndirect() ? pdf.getRoot().getObjGen() | ||
| 57 | - : QPDFObjGen(-1, 0)) | 54 | + root_og(pdf.getRoot().getObjGen().isIndirect() ? pdf.getRoot().getObjGen() : QPDFObjGen(-1, 0)) |
| 58 | { | 55 | { |
| 59 | } | 56 | } |
| 60 | 57 | ||
| @@ -77,8 +74,7 @@ QPDFWriter::QPDFWriter(QPDF& pdf, char const* filename) : | @@ -77,8 +74,7 @@ QPDFWriter::QPDFWriter(QPDF& pdf, char const* filename) : | ||
| 77 | setOutputFilename(filename); | 74 | setOutputFilename(filename); |
| 78 | } | 75 | } |
| 79 | 76 | ||
| 80 | -QPDFWriter::QPDFWriter( | ||
| 81 | - QPDF& pdf, char const* description, FILE* file, bool close_file) : | 77 | +QPDFWriter::QPDFWriter(QPDF& pdf, char const* description, FILE* file, bool close_file) : |
| 82 | m(new Members(pdf)) | 78 | m(new Members(pdf)) |
| 83 | { | 79 | { |
| 84 | setOutputFile(description, file, close_file); | 80 | setOutputFile(description, file, close_file); |
| @@ -109,8 +105,7 @@ QPDFWriter::setOutputFile(char const* description, FILE* file, bool close_file) | @@ -109,8 +105,7 @@ QPDFWriter::setOutputFile(char const* description, FILE* file, bool close_file) | ||
| 109 | m->filename = description; | 105 | m->filename = description; |
| 110 | m->file = file; | 106 | m->file = file; |
| 111 | m->close_file = close_file; | 107 | m->close_file = close_file; |
| 112 | - std::shared_ptr<Pipeline> p = | ||
| 113 | - std::make_shared<Pl_StdioFile>("qpdf output", file); | 108 | + std::shared_ptr<Pipeline> p = std::make_shared<Pl_StdioFile>("qpdf output", file); |
| 114 | m->to_delete.push_back(p); | 109 | m->to_delete.push_back(p); |
| 115 | initializePipelineStack(p.get()); | 110 | initializePipelineStack(p.get()); |
| 116 | } | 111 | } |
| @@ -156,8 +151,7 @@ QPDFWriter::setStreamDataMode(qpdf_stream_data_e mode) | @@ -156,8 +151,7 @@ QPDFWriter::setStreamDataMode(qpdf_stream_data_e mode) | ||
| 156 | { | 151 | { |
| 157 | switch (mode) { | 152 | switch (mode) { |
| 158 | case qpdf_s_uncompress: | 153 | case qpdf_s_uncompress: |
| 159 | - m->stream_decode_level = | ||
| 160 | - std::max(qpdf_dl_generalized, m->stream_decode_level); | 154 | + m->stream_decode_level = std::max(qpdf_dl_generalized, m->stream_decode_level); |
| 161 | m->compress_streams = false; | 155 | m->compress_streams = false; |
| 162 | break; | 156 | break; |
| 163 | 157 | ||
| @@ -167,8 +161,7 @@ QPDFWriter::setStreamDataMode(qpdf_stream_data_e mode) | @@ -167,8 +161,7 @@ QPDFWriter::setStreamDataMode(qpdf_stream_data_e mode) | ||
| 167 | break; | 161 | break; |
| 168 | 162 | ||
| 169 | case qpdf_s_compress: | 163 | case qpdf_s_compress: |
| 170 | - m->stream_decode_level = | ||
| 171 | - std::max(qpdf_dl_generalized, m->stream_decode_level); | 164 | + m->stream_decode_level = std::max(qpdf_dl_generalized, m->stream_decode_level); |
| 172 | m->compress_streams = true; | 165 | m->compress_streams = true; |
| 173 | break; | 166 | break; |
| 174 | } | 167 | } |
| @@ -222,8 +215,7 @@ QPDFWriter::setNewlineBeforeEndstream(bool val) | @@ -222,8 +215,7 @@ QPDFWriter::setNewlineBeforeEndstream(bool val) | ||
| 222 | } | 215 | } |
| 223 | 216 | ||
| 224 | void | 217 | void |
| 225 | -QPDFWriter::setMinimumPDFVersion( | ||
| 226 | - std::string const& version, int extension_level) | 218 | +QPDFWriter::setMinimumPDFVersion(std::string const& version, int extension_level) |
| 227 | { | 219 | { |
| 228 | bool set_version = false; | 220 | bool set_version = false; |
| 229 | bool set_extension_level = false; | 221 | bool set_extension_level = false; |
| @@ -237,13 +229,9 @@ QPDFWriter::setMinimumPDFVersion( | @@ -237,13 +229,9 @@ QPDFWriter::setMinimumPDFVersion( | ||
| 237 | int min_minor = 0; | 229 | int min_minor = 0; |
| 238 | parseVersion(version, old_major, old_minor); | 230 | parseVersion(version, old_major, old_minor); |
| 239 | parseVersion(m->min_pdf_version, min_major, min_minor); | 231 | parseVersion(m->min_pdf_version, min_major, min_minor); |
| 240 | - int compare = | ||
| 241 | - compareVersions(old_major, old_minor, min_major, min_minor); | 232 | + int compare = compareVersions(old_major, old_minor, min_major, min_minor); |
| 242 | if (compare > 0) { | 233 | if (compare > 0) { |
| 243 | - QTC::TC( | ||
| 244 | - "qpdf", | ||
| 245 | - "QPDFWriter increasing minimum version", | ||
| 246 | - extension_level == 0 ? 0 : 1); | 234 | + QTC::TC("qpdf", "QPDFWriter increasing minimum version", extension_level == 0 ? 0 : 1); |
| 247 | set_version = true; | 235 | set_version = true; |
| 248 | set_extension_level = true; | 236 | set_extension_level = true; |
| 249 | } else if (compare == 0) { | 237 | } else if (compare == 0) { |
| @@ -282,8 +270,7 @@ void | @@ -282,8 +270,7 @@ void | ||
| 282 | QPDFWriter::setExtraHeaderText(std::string const& text) | 270 | QPDFWriter::setExtraHeaderText(std::string const& text) |
| 283 | { | 271 | { |
| 284 | m->extra_header_text = text; | 272 | m->extra_header_text = text; |
| 285 | - if ((m->extra_header_text.length() > 0) && | ||
| 286 | - (*(m->extra_header_text.rbegin()) != '\n')) { | 273 | + if ((m->extra_header_text.length() > 0) && (*(m->extra_header_text.rbegin()) != '\n')) { |
| 287 | QTC::TC("qpdf", "QPDFWriter extra header text add newline"); | 274 | QTC::TC("qpdf", "QPDFWriter extra header text add newline"); |
| 288 | m->extra_header_text += "\n"; | 275 | m->extra_header_text += "\n"; |
| 289 | } else { | 276 | } else { |
| @@ -642,16 +629,7 @@ QPDFWriter::setEncryptionParameters( | @@ -642,16 +629,7 @@ QPDFWriter::setEncryptionParameters( | ||
| 642 | std::string encryption_key; | 629 | std::string encryption_key; |
| 643 | if (V < 5) { | 630 | if (V < 5) { |
| 644 | QPDF::compute_encryption_O_U( | 631 | QPDF::compute_encryption_O_U( |
| 645 | - user_password, | ||
| 646 | - owner_password, | ||
| 647 | - V, | ||
| 648 | - R, | ||
| 649 | - key_len, | ||
| 650 | - P, | ||
| 651 | - m->encrypt_metadata, | ||
| 652 | - m->id1, | ||
| 653 | - O, | ||
| 654 | - U); | 632 | + user_password, owner_password, V, R, key_len, P, m->encrypt_metadata, m->id1, O, U); |
| 655 | } else { | 633 | } else { |
| 656 | QPDF::compute_encryption_parameters_V5( | 634 | QPDF::compute_encryption_parameters_V5( |
| 657 | user_password, | 635 | user_password, |
| @@ -670,18 +648,7 @@ QPDFWriter::setEncryptionParameters( | @@ -670,18 +648,7 @@ QPDFWriter::setEncryptionParameters( | ||
| 670 | Perms); | 648 | Perms); |
| 671 | } | 649 | } |
| 672 | setEncryptionParametersInternal( | 650 | setEncryptionParametersInternal( |
| 673 | - V, | ||
| 674 | - R, | ||
| 675 | - key_len, | ||
| 676 | - P, | ||
| 677 | - O, | ||
| 678 | - U, | ||
| 679 | - OE, | ||
| 680 | - UE, | ||
| 681 | - Perms, | ||
| 682 | - m->id1, | ||
| 683 | - user_password, | ||
| 684 | - encryption_key); | 651 | + V, R, key_len, P, O, U, OE, UE, Perms, m->id1, user_password, encryption_key); |
| 685 | } | 652 | } |
| 686 | 653 | ||
| 687 | void | 654 | void |
| @@ -698,10 +665,8 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | @@ -698,10 +665,8 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | ||
| 698 | if (V > 1) { | 665 | if (V > 1) { |
| 699 | key_len = encrypt.getKey("/Length").getIntValueAsInt() / 8; | 666 | key_len = encrypt.getKey("/Length").getIntValueAsInt() / 8; |
| 700 | } | 667 | } |
| 701 | - if (encrypt.hasKey("/EncryptMetadata") && | ||
| 702 | - encrypt.getKey("/EncryptMetadata").isBool()) { | ||
| 703 | - m->encrypt_metadata = | ||
| 704 | - encrypt.getKey("/EncryptMetadata").getBoolValue(); | 668 | + if (encrypt.hasKey("/EncryptMetadata") && encrypt.getKey("/EncryptMetadata").isBool()) { |
| 669 | + m->encrypt_metadata = encrypt.getKey("/EncryptMetadata").getBoolValue(); | ||
| 705 | } | 670 | } |
| 706 | if (V >= 4) { | 671 | if (V >= 4) { |
| 707 | // When copying encryption parameters, use AES even if the | 672 | // When copying encryption parameters, use AES even if the |
| @@ -712,10 +677,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | @@ -712,10 +677,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | ||
| 712 | // different values. | 677 | // different values. |
| 713 | m->encrypt_use_aes = true; | 678 | m->encrypt_use_aes = true; |
| 714 | } | 679 | } |
| 715 | - QTC::TC( | ||
| 716 | - "qpdf", | ||
| 717 | - "QPDFWriter copy encrypt metadata", | ||
| 718 | - m->encrypt_metadata ? 0 : 1); | 680 | + QTC::TC("qpdf", "QPDFWriter copy encrypt metadata", m->encrypt_metadata ? 0 : 1); |
| 719 | QTC::TC("qpdf", "QPDFWriter copy use_aes", m->encrypt_use_aes ? 0 : 1); | 681 | QTC::TC("qpdf", "QPDFWriter copy use_aes", m->encrypt_use_aes ? 0 : 1); |
| 720 | std::string OE; | 682 | std::string OE; |
| 721 | std::string UE; | 683 | std::string UE; |
| @@ -746,8 +708,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | @@ -746,8 +708,7 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | ||
| 746 | } | 708 | } |
| 747 | 709 | ||
| 748 | void | 710 | void |
| 749 | -QPDFWriter::disableIncompatibleEncryption( | ||
| 750 | - int major, int minor, int extension_level) | 711 | +QPDFWriter::disableIncompatibleEncryption(int major, int minor, int extension_level) |
| 751 | { | 712 | { |
| 752 | if (!m->encrypted) { | 713 | if (!m->encrypted) { |
| 753 | return; | 714 | return; |
| @@ -773,8 +734,7 @@ QPDFWriter::disableIncompatibleEncryption( | @@ -773,8 +734,7 @@ QPDFWriter::disableIncompatibleEncryption( | ||
| 773 | } | 734 | } |
| 774 | } else if ( | 735 | } else if ( |
| 775 | (compareVersions(major, minor, 1, 7) < 0) || | 736 | (compareVersions(major, minor, 1, 7) < 0) || |
| 776 | - ((compareVersions(major, minor, 1, 7) == 0) && | ||
| 777 | - extension_level < 3)) { | 737 | + ((compareVersions(major, minor, 1, 7) == 0) && extension_level < 3)) { |
| 778 | if ((V >= 5) || (R >= 5)) { | 738 | if ((V >= 5) || (R >= 5)) { |
| 779 | disable = true; | 739 | disable = true; |
| 780 | } | 740 | } |
| @@ -787,8 +747,7 @@ QPDFWriter::disableIncompatibleEncryption( | @@ -787,8 +747,7 @@ QPDFWriter::disableIncompatibleEncryption( | ||
| 787 | } | 747 | } |
| 788 | 748 | ||
| 789 | void | 749 | void |
| 790 | -QPDFWriter::parseVersion( | ||
| 791 | - std::string const& version, int& major, int& minor) const | 750 | +QPDFWriter::parseVersion(std::string const& version, int& major, int& minor) const |
| 792 | { | 751 | { |
| 793 | major = QUtil::string_to_int(version.c_str()); | 752 | major = QUtil::string_to_int(version.c_str()); |
| 794 | minor = 0; | 753 | minor = 0; |
| @@ -807,8 +766,7 @@ QPDFWriter::parseVersion( | @@ -807,8 +766,7 @@ QPDFWriter::parseVersion( | ||
| 807 | } | 766 | } |
| 808 | 767 | ||
| 809 | int | 768 | int |
| 810 | -QPDFWriter::compareVersions( | ||
| 811 | - int major1, int minor1, int major2, int minor2) const | 769 | +QPDFWriter::compareVersions(int major1, int minor1, int major2, int minor2) const |
| 812 | { | 770 | { |
| 813 | if (major1 < major2) { | 771 | if (major1 < major2) { |
| 814 | return -1; | 772 | return -1; |
| @@ -873,22 +831,19 @@ QPDFWriter::setEncryptionParametersInternal( | @@ -873,22 +831,19 @@ QPDFWriter::setEncryptionParametersInternal( | ||
| 873 | // won't open our files unless we use /StdCF. | 831 | // won't open our files unless we use /StdCF. |
| 874 | m->encryption_dictionary["/StmF"] = "/StdCF"; | 832 | m->encryption_dictionary["/StmF"] = "/StdCF"; |
| 875 | m->encryption_dictionary["/StrF"] = "/StdCF"; | 833 | m->encryption_dictionary["/StrF"] = "/StdCF"; |
| 876 | - std::string method = | ||
| 877 | - (m->encrypt_use_aes ? ((V < 5) ? "/AESV2" : "/AESV3") : "/V2"); | 834 | + std::string method = (m->encrypt_use_aes ? ((V < 5) ? "/AESV2" : "/AESV3") : "/V2"); |
| 878 | // The PDF spec says the /Length key is optional, but the PDF | 835 | // The PDF spec says the /Length key is optional, but the PDF |
| 879 | // previewer on some versions of MacOS won't open encrypted | 836 | // previewer on some versions of MacOS won't open encrypted |
| 880 | // files without it. | 837 | // files without it. |
| 881 | - m->encryption_dictionary["/CF"] = | ||
| 882 | - "<< /StdCF << /AuthEvent /DocOpen /CFM " + method + " /Length " + | ||
| 883 | - std::string((V < 5) ? "16" : "32") + " >> >>"; | 838 | + m->encryption_dictionary["/CF"] = "<< /StdCF << /AuthEvent /DocOpen /CFM " + method + |
| 839 | + " /Length " + std::string((V < 5) ? "16" : "32") + " >> >>"; | ||
| 884 | } | 840 | } |
| 885 | 841 | ||
| 886 | m->encrypted = true; | 842 | m->encrypted = true; |
| 887 | QPDF::EncryptionData encryption_data( | 843 | QPDF::EncryptionData encryption_data( |
| 888 | V, R, key_len, P, O, U, OE, UE, Perms, id1, m->encrypt_metadata); | 844 | V, R, key_len, P, O, U, OE, UE, Perms, id1, m->encrypt_metadata); |
| 889 | if (V < 5) { | 845 | if (V < 5) { |
| 890 | - m->encryption_key = | ||
| 891 | - QPDF::compute_encryption_key(user_password, encryption_data); | 846 | + m->encryption_key = QPDF::compute_encryption_key(user_password, encryption_data); |
| 892 | } else { | 847 | } else { |
| 893 | m->encryption_key = encryption_key; | 848 | m->encryption_key = encryption_key; |
| 894 | } | 849 | } |
| @@ -898,12 +853,7 @@ void | @@ -898,12 +853,7 @@ void | ||
| 898 | QPDFWriter::setDataKey(int objid) | 853 | QPDFWriter::setDataKey(int objid) |
| 899 | { | 854 | { |
| 900 | m->cur_data_key = QPDF::compute_data_key( | 855 | m->cur_data_key = QPDF::compute_data_key( |
| 901 | - m->encryption_key, | ||
| 902 | - objid, | ||
| 903 | - 0, | ||
| 904 | - m->encrypt_use_aes, | ||
| 905 | - m->encryption_V, | ||
| 906 | - m->encryption_R); | 856 | + m->encryption_key, objid, 0, m->encrypt_use_aes, m->encryption_V, m->encryption_R); |
| 907 | } | 857 | } |
| 908 | 858 | ||
| 909 | unsigned int | 859 | unsigned int |
| @@ -921,8 +871,7 @@ void | @@ -921,8 +871,7 @@ void | ||
| 921 | QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) | 871 | QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) |
| 922 | { | 872 | { |
| 923 | if (bytes > sizeof(unsigned long long)) { | 873 | if (bytes > sizeof(unsigned long long)) { |
| 924 | - throw std::logic_error( | ||
| 925 | - "QPDFWriter::writeBinary called with too many bytes"); | 874 | + throw std::logic_error("QPDFWriter::writeBinary called with too many bytes"); |
| 926 | } | 875 | } |
| 927 | unsigned char data[sizeof(unsigned long long)]; | 876 | unsigned char data[sizeof(unsigned long long)]; |
| 928 | for (unsigned int i = 0; i < bytes; ++i) { | 877 | for (unsigned int i = 0; i < bytes; ++i) { |
| @@ -935,8 +884,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) | @@ -935,8 +884,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) | ||
| 935 | void | 884 | void |
| 936 | QPDFWriter::writeString(std::string_view str) | 885 | QPDFWriter::writeString(std::string_view str) |
| 937 | { | 886 | { |
| 938 | - m->pipeline->write( | ||
| 939 | - reinterpret_cast<unsigned char const*>(str.data()), str.size()); | 887 | + m->pipeline->write(reinterpret_cast<unsigned char const*>(str.data()), str.size()); |
| 940 | } | 888 | } |
| 941 | 889 | ||
| 942 | void | 890 | void |
| @@ -949,8 +897,7 @@ void | @@ -949,8 +897,7 @@ void | ||
| 949 | QPDFWriter::writeStringQDF(std::string_view str) | 897 | QPDFWriter::writeStringQDF(std::string_view str) |
| 950 | { | 898 | { |
| 951 | if (m->qdf_mode) { | 899 | if (m->qdf_mode) { |
| 952 | - m->pipeline->write( | ||
| 953 | - reinterpret_cast<unsigned char const*>(str.data()), str.size()); | 900 | + m->pipeline->write(reinterpret_cast<unsigned char const*>(str.data()), str.size()); |
| 954 | } | 901 | } |
| 955 | } | 902 | } |
| 956 | 903 | ||
| @@ -958,8 +905,7 @@ void | @@ -958,8 +905,7 @@ void | ||
| 958 | QPDFWriter::writeStringNoQDF(std::string_view str) | 905 | QPDFWriter::writeStringNoQDF(std::string_view str) |
| 959 | { | 906 | { |
| 960 | if (!m->qdf_mode) { | 907 | if (!m->qdf_mode) { |
| 961 | - m->pipeline->write( | ||
| 962 | - reinterpret_cast<unsigned char const*>(str.data()), str.size()); | 908 | + m->pipeline->write(reinterpret_cast<unsigned char const*>(str.data()), str.size()); |
| 963 | } | 909 | } |
| 964 | } | 910 | } |
| 965 | 911 | ||
| @@ -1003,9 +949,7 @@ QPDFWriter::PipelinePopper::~PipelinePopper() | @@ -1003,9 +949,7 @@ QPDFWriter::PipelinePopper::~PipelinePopper() | ||
| 1003 | } | 949 | } |
| 1004 | qpdf_assert_debug(qw->m->pipeline_stack.size() >= 2); | 950 | qpdf_assert_debug(qw->m->pipeline_stack.size() >= 2); |
| 1005 | qw->m->pipeline->finish(); | 951 | qw->m->pipeline->finish(); |
| 1006 | - qpdf_assert_debug( | ||
| 1007 | - dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back()) == | ||
| 1008 | - qw->m->pipeline); | 952 | + qpdf_assert_debug(dynamic_cast<Pl_Count*>(qw->m->pipeline_stack.back()) == qw->m->pipeline); |
| 1009 | // It might be possible for this assertion to fail if | 953 | // It might be possible for this assertion to fail if |
| 1010 | // writeLinearized exits by exception when deterministic ID, but I | 954 | // writeLinearized exits by exception when deterministic ID, but I |
| 1011 | // don't think so. As of this writing, this is the only case in | 955 | // don't think so. As of this writing, this is the only case in |
| @@ -1152,10 +1096,9 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -1152,10 +1096,9 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 1152 | // which just disconnects the QPDFObjectHandle from its owner. | 1096 | // which just disconnects the QPDFObjectHandle from its owner. |
| 1153 | if (object.getOwningQPDF() != &(m->pdf)) { | 1097 | if (object.getOwningQPDF() != &(m->pdf)) { |
| 1154 | QTC::TC("qpdf", "QPDFWriter foreign object"); | 1098 | QTC::TC("qpdf", "QPDFWriter foreign object"); |
| 1155 | - throw std::logic_error( | ||
| 1156 | - "QPDFObjectHandle from different QPDF found while writing." | ||
| 1157 | - " Use QPDF::copyForeignObject to add objects from" | ||
| 1158 | - " another file."); | 1099 | + throw std::logic_error("QPDFObjectHandle from different QPDF found while writing." |
| 1100 | + " Use QPDF::copyForeignObject to add objects from" | ||
| 1101 | + " another file."); | ||
| 1159 | } | 1102 | } |
| 1160 | 1103 | ||
| 1161 | if (m->qdf_mode && object.isStreamOfType("/XRef")) { | 1104 | if (m->qdf_mode && object.isStreamOfType("/XRef")) { |
| @@ -1186,8 +1129,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -1186,8 +1129,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 1186 | m->object_queue.push_back(object); | 1129 | m->object_queue.push_back(object); |
| 1187 | m->obj_renumber[og] = m->next_objid++; | 1130 | m->obj_renumber[og] = m->next_objid++; |
| 1188 | 1131 | ||
| 1189 | - if ((og.getGen() == 0) && | ||
| 1190 | - m->object_stream_to_objects.count(og.getObj())) { | 1132 | + if ((og.getGen() == 0) && m->object_stream_to_objects.count(og.getObj())) { |
| 1191 | // For linearized files, uncompressed objects go | 1133 | // For linearized files, uncompressed objects go |
| 1192 | // at end, and we take care of assigning numbers | 1134 | // at end, and we take care of assigning numbers |
| 1193 | // to them elsewhere. | 1135 | // to them elsewhere. |
| @@ -1240,11 +1182,7 @@ QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags) | @@ -1240,11 +1182,7 @@ QPDFWriter::unparseChild(QPDFObjectHandle child, int level, int flags) | ||
| 1240 | 1182 | ||
| 1241 | void | 1183 | void |
| 1242 | QPDFWriter::writeTrailer( | 1184 | QPDFWriter::writeTrailer( |
| 1243 | - trailer_e which, | ||
| 1244 | - int size, | ||
| 1245 | - bool xref_stream, | ||
| 1246 | - qpdf_offset_t prev, | ||
| 1247 | - int linearization_pass) | 1185 | + trailer_e which, int size, bool xref_stream, qpdf_offset_t prev, int linearization_pass) |
| 1248 | { | 1186 | { |
| 1249 | QPDFObjectHandle trailer = getTrimmedTrailer(); | 1187 | QPDFObjectHandle trailer = getTrimmedTrailer(); |
| 1250 | if (xref_stream) { | 1188 | if (xref_stream) { |
| @@ -1268,8 +1206,7 @@ QPDFWriter::writeTrailer( | @@ -1268,8 +1206,7 @@ QPDFWriter::writeTrailer( | ||
| 1268 | writeString(" /Prev "); | 1206 | writeString(" /Prev "); |
| 1269 | qpdf_offset_t pos = m->pipeline->getCount(); | 1207 | qpdf_offset_t pos = m->pipeline->getCount(); |
| 1270 | writeString(std::to_string(prev)); | 1208 | writeString(std::to_string(prev)); |
| 1271 | - writePad( | ||
| 1272 | - QIntC::to_size(pos - m->pipeline->getCount() + 21)); | 1209 | + writePad(QIntC::to_size(pos - m->pipeline->getCount() + 21)); |
| 1273 | } | 1210 | } |
| 1274 | } else { | 1211 | } else { |
| 1275 | unparseChild(trailer.getKey(key), 1, 0); | 1212 | unparseChild(trailer.getKey(key), 1, 0); |
| @@ -1340,9 +1277,7 @@ QPDFWriter::willFilterStream( | @@ -1340,9 +1277,7 @@ QPDFWriter::willFilterStream( | ||
| 1340 | if (stream_dict.isDictionaryOfType("/Metadata")) { | 1277 | if (stream_dict.isDictionaryOfType("/Metadata")) { |
| 1341 | is_metadata = true; | 1278 | is_metadata = true; |
| 1342 | } | 1279 | } |
| 1343 | - bool filter = | ||
| 1344 | - (stream.isDataModified() || m->compress_streams || | ||
| 1345 | - m->stream_decode_level); | 1280 | + bool filter = (stream.isDataModified() || m->compress_streams || m->stream_decode_level); |
| 1346 | bool filter_on_write = stream.getFilterOnWrite(); | 1281 | bool filter_on_write = stream.getFilterOnWrite(); |
| 1347 | if (!filter_on_write) { | 1282 | if (!filter_on_write) { |
| 1348 | QTC::TC("qpdf", "QPDFWriter getFilterOnWrite false"); | 1283 | QTC::TC("qpdf", "QPDFWriter getFilterOnWrite false"); |
| @@ -1356,25 +1291,20 @@ QPDFWriter::willFilterStream( | @@ -1356,25 +1291,20 @@ QPDFWriter::willFilterStream( | ||
| 1356 | // recompressing stuff. This can be overridden with | 1291 | // recompressing stuff. This can be overridden with |
| 1357 | // setRecompressFlate(true). | 1292 | // setRecompressFlate(true). |
| 1358 | QPDFObjectHandle filter_obj = stream_dict.getKey("/Filter"); | 1293 | QPDFObjectHandle filter_obj = stream_dict.getKey("/Filter"); |
| 1359 | - if ((!m->recompress_flate) && (!stream.isDataModified()) && | ||
| 1360 | - filter_obj.isName() && | ||
| 1361 | - ((filter_obj.getName() == "/FlateDecode") || | ||
| 1362 | - (filter_obj.getName() == "/Fl"))) { | 1294 | + if ((!m->recompress_flate) && (!stream.isDataModified()) && filter_obj.isName() && |
| 1295 | + ((filter_obj.getName() == "/FlateDecode") || (filter_obj.getName() == "/Fl"))) { | ||
| 1363 | QTC::TC("qpdf", "QPDFWriter not recompressing /FlateDecode"); | 1296 | QTC::TC("qpdf", "QPDFWriter not recompressing /FlateDecode"); |
| 1364 | filter = false; | 1297 | filter = false; |
| 1365 | } | 1298 | } |
| 1366 | } | 1299 | } |
| 1367 | bool normalize = false; | 1300 | bool normalize = false; |
| 1368 | bool uncompress = false; | 1301 | bool uncompress = false; |
| 1369 | - if (filter_on_write && is_metadata && | ||
| 1370 | - ((!m->encrypted) || (m->encrypt_metadata == false))) { | 1302 | + if (filter_on_write && is_metadata && ((!m->encrypted) || (m->encrypt_metadata == false))) { |
| 1371 | QTC::TC("qpdf", "QPDFWriter not compressing metadata"); | 1303 | QTC::TC("qpdf", "QPDFWriter not compressing metadata"); |
| 1372 | filter = true; | 1304 | filter = true; |
| 1373 | compress_stream = false; | 1305 | compress_stream = false; |
| 1374 | uncompress = true; | 1306 | uncompress = true; |
| 1375 | - } else if ( | ||
| 1376 | - filter_on_write && m->normalize_content && | ||
| 1377 | - m->normalized_streams.count(old_og)) { | 1307 | + } else if (filter_on_write && m->normalize_content && m->normalized_streams.count(old_og)) { |
| 1378 | normalize = true; | 1308 | normalize = true; |
| 1379 | filter = true; | 1309 | filter = true; |
| 1380 | } else if (filter_on_write && filter && m->compress_streams) { | 1310 | } else if (filter_on_write && filter && m->compress_streams) { |
| @@ -1392,14 +1322,12 @@ QPDFWriter::willFilterStream( | @@ -1392,14 +1322,12 @@ QPDFWriter::willFilterStream( | ||
| 1392 | m->pipeline, | 1322 | m->pipeline, |
| 1393 | (((filter && normalize) ? qpdf_ef_normalize : 0) | | 1323 | (((filter && normalize) ? qpdf_ef_normalize : 0) | |
| 1394 | ((filter && compress_stream) ? qpdf_ef_compress : 0)), | 1324 | ((filter && compress_stream) ? qpdf_ef_compress : 0)), |
| 1395 | - (filter ? (uncompress ? qpdf_dl_all : m->stream_decode_level) | ||
| 1396 | - : qpdf_dl_none), | 1325 | + (filter ? (uncompress ? qpdf_dl_all : m->stream_decode_level) : qpdf_dl_none), |
| 1397 | false, | 1326 | false, |
| 1398 | (attempt == 1)); | 1327 | (attempt == 1)); |
| 1399 | } catch (std::runtime_error& e) { | 1328 | } catch (std::runtime_error& e) { |
| 1400 | throw std::runtime_error( | 1329 | throw std::runtime_error( |
| 1401 | - "error while getting stream data for " + stream.unparse() + | ||
| 1402 | - ": " + e.what()); | 1330 | + "error while getting stream data for " + stream.unparse() + ": " + e.what()); |
| 1403 | } | 1331 | } |
| 1404 | if (filter && (!filtered)) { | 1332 | if (filter && (!filtered)) { |
| 1405 | // Try again | 1333 | // Try again |
| @@ -1416,11 +1344,7 @@ QPDFWriter::willFilterStream( | @@ -1416,11 +1344,7 @@ QPDFWriter::willFilterStream( | ||
| 1416 | 1344 | ||
| 1417 | void | 1345 | void |
| 1418 | QPDFWriter::unparseObject( | 1346 | QPDFWriter::unparseObject( |
| 1419 | - QPDFObjectHandle object, | ||
| 1420 | - int level, | ||
| 1421 | - int flags, | ||
| 1422 | - size_t stream_length, | ||
| 1423 | - bool compress) | 1347 | + QPDFObjectHandle object, int level, int flags, size_t stream_length, bool compress) |
| 1424 | { | 1348 | { |
| 1425 | QPDFObjGen old_og = object.getObjGen(); | 1349 | QPDFObjGen old_og = object.getObjGen(); |
| 1426 | int child_flags = flags & ~f_stream; | 1350 | int child_flags = flags & ~f_stream; |
| @@ -1486,8 +1410,7 @@ QPDFWriter::unparseObject( | @@ -1486,8 +1410,7 @@ QPDFWriter::unparseObject( | ||
| 1486 | 1410 | ||
| 1487 | QPDFObjectHandle extensions; | 1411 | QPDFObjectHandle extensions; |
| 1488 | if (is_root) { | 1412 | if (is_root) { |
| 1489 | - if (object.hasKey("/Extensions") && | ||
| 1490 | - object.getKey("/Extensions").isDictionary()) { | 1413 | + if (object.hasKey("/Extensions") && object.getKey("/Extensions").isDictionary()) { |
| 1491 | extensions = object.getKey("/Extensions"); | 1414 | extensions = object.getKey("/Extensions"); |
| 1492 | } | 1415 | } |
| 1493 | } | 1416 | } |
| @@ -1510,10 +1433,7 @@ QPDFWriter::unparseObject( | @@ -1510,10 +1433,7 @@ QPDFWriter::unparseObject( | ||
| 1510 | if (!(have_extensions_other || have_extensions_adbe)) { | 1433 | if (!(have_extensions_other || have_extensions_adbe)) { |
| 1511 | // We need Extensions and don't have it. Create | 1434 | // We need Extensions and don't have it. Create |
| 1512 | // it here. | 1435 | // it here. |
| 1513 | - QTC::TC( | ||
| 1514 | - "qpdf", | ||
| 1515 | - "QPDFWriter create Extensions", | ||
| 1516 | - m->qdf_mode ? 0 : 1); | 1436 | + QTC::TC("qpdf", "QPDFWriter create Extensions", m->qdf_mode ? 0 : 1); |
| 1517 | extensions = object.replaceKeyAndGetNew( | 1437 | extensions = object.replaceKeyAndGetNew( |
| 1518 | "/Extensions", QPDFObjectHandle::newDictionary()); | 1438 | "/Extensions", QPDFObjectHandle::newDictionary()); |
| 1519 | } | 1439 | } |
| @@ -1531,19 +1451,16 @@ QPDFWriter::unparseObject( | @@ -1531,19 +1451,16 @@ QPDFWriter::unparseObject( | ||
| 1531 | QTC::TC("qpdf", "QPDFWriter preserve Extensions"); | 1451 | QTC::TC("qpdf", "QPDFWriter preserve Extensions"); |
| 1532 | QPDFObjectHandle adbe = extensions.getKey("/ADBE"); | 1452 | QPDFObjectHandle adbe = extensions.getKey("/ADBE"); |
| 1533 | if (adbe.isDictionary() && | 1453 | if (adbe.isDictionary() && |
| 1534 | - adbe.getKey("/BaseVersion") | ||
| 1535 | - .isNameAndEquals("/" + m->final_pdf_version) && | 1454 | + adbe.getKey("/BaseVersion").isNameAndEquals("/" + m->final_pdf_version) && |
| 1536 | adbe.getKey("/ExtensionLevel").isInteger() && | 1455 | adbe.getKey("/ExtensionLevel").isInteger() && |
| 1537 | - (adbe.getKey("/ExtensionLevel").getIntValue() == | ||
| 1538 | - m->final_extension_level)) { | 1456 | + (adbe.getKey("/ExtensionLevel").getIntValue() == m->final_extension_level)) { |
| 1539 | QTC::TC("qpdf", "QPDFWriter preserve ADBE"); | 1457 | QTC::TC("qpdf", "QPDFWriter preserve ADBE"); |
| 1540 | } else { | 1458 | } else { |
| 1541 | if (need_extensions_adbe) { | 1459 | if (need_extensions_adbe) { |
| 1542 | extensions.replaceKey( | 1460 | extensions.replaceKey( |
| 1543 | "/ADBE", | 1461 | "/ADBE", |
| 1544 | QPDFObjectHandle::parse( | 1462 | QPDFObjectHandle::parse( |
| 1545 | - "<< /BaseVersion /" + m->final_pdf_version + | ||
| 1546 | - " /ExtensionLevel " + | 1463 | + "<< /BaseVersion /" + m->final_pdf_version + " /ExtensionLevel " + |
| 1547 | std::to_string(m->final_extension_level) + " >>")); | 1464 | std::to_string(m->final_extension_level) + " >>")); |
| 1548 | } else { | 1465 | } else { |
| 1549 | QTC::TC("qpdf", "QPDFWriter remove ADBE"); | 1466 | QTC::TC("qpdf", "QPDFWriter remove ADBE"); |
| @@ -1617,9 +1534,7 @@ QPDFWriter::unparseObject( | @@ -1617,9 +1534,7 @@ QPDFWriter::unparseObject( | ||
| 1617 | object.hasKey("/ByteRange")) { | 1534 | object.hasKey("/ByteRange")) { |
| 1618 | QTC::TC("qpdf", "QPDFWriter no encryption sig contents"); | 1535 | QTC::TC("qpdf", "QPDFWriter no encryption sig contents"); |
| 1619 | unparseChild( | 1536 | unparseChild( |
| 1620 | - item.second, | ||
| 1621 | - level + 1, | ||
| 1622 | - child_flags | f_hex_string | f_no_encryption); | 1537 | + item.second, level + 1, child_flags | f_hex_string | f_no_encryption); |
| 1623 | } else { | 1538 | } else { |
| 1624 | unparseChild(item.second, level + 1, child_flags); | 1539 | unparseChild(item.second, level + 1, child_flags); |
| 1625 | } | 1540 | } |
| @@ -1657,8 +1572,7 @@ QPDFWriter::unparseObject( | @@ -1657,8 +1572,7 @@ QPDFWriter::unparseObject( | ||
| 1657 | bool compress_stream = false; | 1572 | bool compress_stream = false; |
| 1658 | bool is_metadata = false; | 1573 | bool is_metadata = false; |
| 1659 | std::shared_ptr<Buffer> stream_data; | 1574 | std::shared_ptr<Buffer> stream_data; |
| 1660 | - if (willFilterStream( | ||
| 1661 | - object, compress_stream, is_metadata, &stream_data)) { | 1575 | + if (willFilterStream(object, compress_stream, is_metadata, &stream_data)) { |
| 1662 | flags |= f_filtered; | 1576 | flags |= f_filtered; |
| 1663 | } | 1577 | } |
| 1664 | QPDFObjectHandle stream_dict = object.getDict(); | 1578 | QPDFObjectHandle stream_dict = object.getDict(); |
| @@ -1669,8 +1583,7 @@ QPDFWriter::unparseObject( | @@ -1669,8 +1583,7 @@ QPDFWriter::unparseObject( | ||
| 1669 | m->cur_data_key.clear(); | 1583 | m->cur_data_key.clear(); |
| 1670 | } | 1584 | } |
| 1671 | adjustAESStreamLength(m->cur_stream_length); | 1585 | adjustAESStreamLength(m->cur_stream_length); |
| 1672 | - unparseObject( | ||
| 1673 | - stream_dict, 0, flags, m->cur_stream_length, compress_stream); | 1586 | + unparseObject(stream_dict, 0, flags, m->cur_stream_length, compress_stream); |
| 1674 | unsigned char last_char = '\0'; | 1587 | unsigned char last_char = '\0'; |
| 1675 | writeString("\nstream\n"); | 1588 | writeString("\nstream\n"); |
| 1676 | { | 1589 | { |
| @@ -1680,8 +1593,7 @@ QPDFWriter::unparseObject( | @@ -1680,8 +1593,7 @@ QPDFWriter::unparseObject( | ||
| 1680 | last_char = m->pipeline->getLastChar(); | 1593 | last_char = m->pipeline->getLastChar(); |
| 1681 | } | 1594 | } |
| 1682 | 1595 | ||
| 1683 | - if (m->newline_before_endstream || | ||
| 1684 | - (m->qdf_mode && (last_char != '\n'))) { | 1596 | + if (m->newline_before_endstream || (m->qdf_mode && (last_char != '\n'))) { |
| 1685 | writeString("\n"); | 1597 | writeString("\n"); |
| 1686 | m->added_newline = true; | 1598 | m->added_newline = true; |
| 1687 | } else { | 1599 | } else { |
| @@ -1690,8 +1602,8 @@ QPDFWriter::unparseObject( | @@ -1690,8 +1602,8 @@ QPDFWriter::unparseObject( | ||
| 1690 | writeString("endstream"); | 1602 | writeString("endstream"); |
| 1691 | } else if (tc == ::ot_string) { | 1603 | } else if (tc == ::ot_string) { |
| 1692 | std::string val; | 1604 | std::string val; |
| 1693 | - if (m->encrypted && (!(flags & f_in_ostream)) && | ||
| 1694 | - (!(flags & f_no_encryption)) && (!m->cur_data_key.empty())) { | 1605 | + if (m->encrypted && (!(flags & f_in_ostream)) && (!(flags & f_no_encryption)) && |
| 1606 | + (!m->cur_data_key.empty())) { | ||
| 1695 | val = object.getStringValue(); | 1607 | val = object.getStringValue(); |
| 1696 | if (m->encrypt_use_aes) { | 1608 | if (m->encrypt_use_aes) { |
| 1697 | Pl_Buffer bufpl("encrypted string"); | 1609 | Pl_Buffer bufpl("encrypted string"); |
| @@ -1704,9 +1616,8 @@ QPDFWriter::unparseObject( | @@ -1704,9 +1616,8 @@ QPDFWriter::unparseObject( | ||
| 1704 | pl.writeString(val); | 1616 | pl.writeString(val); |
| 1705 | pl.finish(); | 1617 | pl.finish(); |
| 1706 | auto buf = bufpl.getBufferSharedPointer(); | 1618 | auto buf = bufpl.getBufferSharedPointer(); |
| 1707 | - val = QPDF_String(std::string( | ||
| 1708 | - reinterpret_cast<char*>(buf->getBuffer()), | ||
| 1709 | - buf->getSize())) | 1619 | + val = QPDF_String( |
| 1620 | + std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize())) | ||
| 1710 | .unparse(true); | 1621 | .unparse(true); |
| 1711 | } else { | 1622 | } else { |
| 1712 | auto tmp_ph = QUtil::make_unique_cstr(val); | 1623 | auto tmp_ph = QUtil::make_unique_cstr(val); |
| @@ -1731,8 +1642,7 @@ QPDFWriter::unparseObject( | @@ -1731,8 +1642,7 @@ QPDFWriter::unparseObject( | ||
| 1731 | } | 1642 | } |
| 1732 | 1643 | ||
| 1733 | void | 1644 | void |
| 1734 | -QPDFWriter::writeObjectStreamOffsets( | ||
| 1735 | - std::vector<qpdf_offset_t>& offsets, int first_obj) | 1645 | +QPDFWriter::writeObjectStreamOffsets(std::vector<qpdf_offset_t>& offsets, int first_obj) |
| 1736 | { | 1646 | { |
| 1737 | for (size_t i = 0; i < offsets.size(); ++i) { | 1647 | for (size_t i = 0; i < offsets.size(); ++i) { |
| 1738 | if (i != 0) { | 1648 | if (i != 0) { |
| @@ -1788,12 +1698,11 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1788,12 +1698,11 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1788 | 1698 | ||
| 1789 | // Set up a stream to write the stream data into a buffer. | 1699 | // Set up a stream to write the stream data into a buffer. |
| 1790 | Pipeline* next = pushPipeline(new Pl_Buffer("object stream")); | 1700 | Pipeline* next = pushPipeline(new Pl_Buffer("object stream")); |
| 1791 | - if ((m->compress_streams || | ||
| 1792 | - (m->stream_decode_level == qpdf_dl_none)) && | 1701 | + if ((m->compress_streams || (m->stream_decode_level == qpdf_dl_none)) && |
| 1793 | (!m->qdf_mode)) { | 1702 | (!m->qdf_mode)) { |
| 1794 | compressed = true; | 1703 | compressed = true; |
| 1795 | - next = pushPipeline(new Pl_Flate( | ||
| 1796 | - "compress object stream", next, Pl_Flate::a_deflate)); | 1704 | + next = |
| 1705 | + pushPipeline(new Pl_Flate("compress object stream", next, Pl_Flate::a_deflate)); | ||
| 1797 | } | 1706 | } |
| 1798 | activatePipelineStack(pp_ostream); | 1707 | activatePipelineStack(pp_ostream); |
| 1799 | writeObjectStreamOffsets(offsets, first_obj); | 1708 | writeObjectStreamOffsets(offsets, first_obj); |
| @@ -1808,12 +1717,10 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1808,12 +1717,10 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1808 | } | 1717 | } |
| 1809 | if (m->qdf_mode) { | 1718 | if (m->qdf_mode) { |
| 1810 | writeString( | 1719 | writeString( |
| 1811 | - "%% Object stream: object " + std::to_string(new_obj) + | ||
| 1812 | - ", index " + std::to_string(count)); | 1720 | + "%% Object stream: object " + std::to_string(new_obj) + ", index " + |
| 1721 | + std::to_string(count)); | ||
| 1813 | if (!m->suppress_original_object_ids) { | 1722 | if (!m->suppress_original_object_ids) { |
| 1814 | - writeString( | ||
| 1815 | - "; original object ID: " + | ||
| 1816 | - std::to_string(obj.getObj())); | 1723 | + writeString("; original object ID: " + std::to_string(obj.getObj())); |
| 1817 | // For compatibility, only write the generation if | 1724 | // For compatibility, only write the generation if |
| 1818 | // non-zero. While object streams only allow | 1725 | // non-zero. While object streams only allow |
| 1819 | // objects with generation 0, if we are generating | 1726 | // objects with generation 0, if we are generating |
| @@ -1839,8 +1746,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | @@ -1839,8 +1746,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) | ||
| 1839 | // should block it at at parse time, but it's not | 1746 | // should block it at at parse time, but it's not |
| 1840 | // clear to me how to construct a case for this. | 1747 | // clear to me how to construct a case for this. |
| 1841 | QTC::TC("qpdf", "QPDFWriter stream in ostream"); | 1748 | QTC::TC("qpdf", "QPDFWriter stream in ostream"); |
| 1842 | - obj_to_write.warnIfPossible( | ||
| 1843 | - "stream found inside object stream; treating as null"); | 1749 | + obj_to_write.warnIfPossible("stream found inside object stream; treating as null"); |
| 1844 | obj_to_write = QPDFObjectHandle::newNull(); | 1750 | obj_to_write = QPDFObjectHandle::newNull(); |
| 1845 | } | 1751 | } |
| 1846 | writeObject(obj_to_write, count); | 1752 | writeObject(obj_to_write, count); |
| @@ -1923,9 +1829,7 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) | @@ -1923,9 +1829,7 @@ QPDFWriter::writeObject(QPDFObjectHandle object, int object_stream_index) | ||
| 1923 | } | 1829 | } |
| 1924 | if (object_stream_index == -1) { | 1830 | if (object_stream_index == -1) { |
| 1925 | if (m->qdf_mode && (!m->suppress_original_object_ids)) { | 1831 | if (m->qdf_mode && (!m->suppress_original_object_ids)) { |
| 1926 | - writeString( | ||
| 1927 | - "%% Original object ID: " + object.getObjGen().unparse(' ') + | ||
| 1928 | - "\n"); | 1832 | + writeString("%% Original object ID: " + object.getObjGen().unparse(' ') + "\n"); |
| 1929 | } | 1833 | } |
| 1930 | openObject(new_id); | 1834 | openObject(new_id); |
| 1931 | setDataKey(new_id); | 1835 | setDataKey(new_id); |
| @@ -2013,11 +1917,10 @@ QPDFWriter::generateID() | @@ -2013,11 +1917,10 @@ QPDFWriter::generateID() | ||
| 2013 | if (m->deterministic_id) { | 1917 | if (m->deterministic_id) { |
| 2014 | if (m->deterministic_id_data.empty()) { | 1918 | if (m->deterministic_id_data.empty()) { |
| 2015 | QTC::TC("qpdf", "QPDFWriter deterministic with no data"); | 1919 | QTC::TC("qpdf", "QPDFWriter deterministic with no data"); |
| 2016 | - throw std::logic_error( | ||
| 2017 | - "INTERNAL ERROR: QPDFWriter::generateID has no" | ||
| 2018 | - " data for deterministic ID. This may happen if" | ||
| 2019 | - " deterministic ID and file encryption are requested" | ||
| 2020 | - " together."); | 1920 | + throw std::logic_error("INTERNAL ERROR: QPDFWriter::generateID has no" |
| 1921 | + " data for deterministic ID. This may happen if" | ||
| 1922 | + " deterministic ID and file encryption are requested" | ||
| 1923 | + " together."); | ||
| 2021 | } | 1924 | } |
| 2022 | seed += m->deterministic_id_data; | 1925 | seed += m->deterministic_id_data; |
| 2023 | } else { | 1926 | } else { |
| @@ -2041,8 +1944,7 @@ QPDFWriter::generateID() | @@ -2041,8 +1944,7 @@ QPDFWriter::generateID() | ||
| 2041 | m.encodeString(seed.c_str()); | 1944 | m.encodeString(seed.c_str()); |
| 2042 | MD5::Digest digest; | 1945 | MD5::Digest digest; |
| 2043 | m.digest(digest); | 1946 | m.digest(digest); |
| 2044 | - result = | ||
| 2045 | - std::string(reinterpret_cast<char*>(digest), sizeof(MD5::Digest)); | 1947 | + result = std::string(reinterpret_cast<char*>(digest), sizeof(MD5::Digest)); |
| 2046 | } | 1948 | } |
| 2047 | 1949 | ||
| 2048 | // If /ID already exists, follow the spec: use the original first | 1950 | // If /ID already exists, follow the spec: use the original first |
| @@ -2071,8 +1973,7 @@ QPDFWriter::initializeSpecialStreams() | @@ -2071,8 +1973,7 @@ QPDFWriter::initializeSpecialStreams() | ||
| 2071 | if (contents.isArray()) { | 1973 | if (contents.isArray()) { |
| 2072 | int n = contents.getArrayNItems(); | 1974 | int n = contents.getArrayNItems(); |
| 2073 | for (int i = 0; i < n; ++i) { | 1975 | for (int i = 0; i < n; ++i) { |
| 2074 | - contents_objects.push_back( | ||
| 2075 | - contents.getArrayItem(i).getObjGen()); | 1976 | + contents_objects.push_back(contents.getArrayItem(i).getObjGen()); |
| 2076 | } | 1977 | } |
| 2077 | } else if (contents.isStream()) { | 1978 | } else if (contents.isStream()) { |
| 2078 | contents_objects.push_back(contents.getObjGen()); | 1979 | contents_objects.push_back(contents.getObjGen()); |
| @@ -2105,14 +2006,10 @@ QPDFWriter::preserveObjectStreams() | @@ -2105,14 +2006,10 @@ QPDFWriter::preserveObjectStreams() | ||
| 2105 | // included. | 2006 | // included. |
| 2106 | std::set<QPDFObjGen> eligible; | 2007 | std::set<QPDFObjGen> eligible; |
| 2107 | if (!m->preserve_unreferenced_objects) { | 2008 | if (!m->preserve_unreferenced_objects) { |
| 2108 | - std::vector<QPDFObjGen> eligible_v = | ||
| 2109 | - QPDF::Writer::getCompressibleObjGens(m->pdf); | 2009 | + std::vector<QPDFObjGen> eligible_v = QPDF::Writer::getCompressibleObjGens(m->pdf); |
| 2110 | eligible = std::set<QPDFObjGen>(eligible_v.begin(), eligible_v.end()); | 2010 | eligible = std::set<QPDFObjGen>(eligible_v.begin(), eligible_v.end()); |
| 2111 | } | 2011 | } |
| 2112 | - QTC::TC( | ||
| 2113 | - "qpdf", | ||
| 2114 | - "QPDFWriter preserve object streams", | ||
| 2115 | - m->preserve_unreferenced_objects ? 0 : 1); | 2012 | + QTC::TC("qpdf", "QPDFWriter preserve object streams", m->preserve_unreferenced_objects ? 0 : 1); |
| 2116 | for (auto iter: omap) { | 2013 | for (auto iter: omap) { |
| 2117 | QPDFObjGen og(iter.first, 0); | 2014 | QPDFObjGen og(iter.first, 0); |
| 2118 | if (eligible.count(og) || m->preserve_unreferenced_objects) { | 2015 | if (eligible.count(og) || m->preserve_unreferenced_objects) { |
| @@ -2136,8 +2033,7 @@ QPDFWriter::generateObjectStreams() | @@ -2136,8 +2033,7 @@ QPDFWriter::generateObjectStreams() | ||
| 2136 | 2033 | ||
| 2137 | // This code doesn't do anything with /Extends. | 2034 | // This code doesn't do anything with /Extends. |
| 2138 | 2035 | ||
| 2139 | - std::vector<QPDFObjGen> eligible = | ||
| 2140 | - QPDF::Writer::getCompressibleObjGens(m->pdf); | 2036 | + std::vector<QPDFObjGen> eligible = QPDF::Writer::getCompressibleObjGens(m->pdf); |
| 2141 | size_t n_object_streams = (eligible.size() + 99U) / 100U; | 2037 | size_t n_object_streams = (eligible.size() + 99U) / 100U; |
| 2142 | if (n_object_streams == 0) { | 2038 | if (n_object_streams == 0) { |
| 2143 | return; | 2039 | return; |
| @@ -2159,8 +2055,7 @@ QPDFWriter::generateObjectStreams() | @@ -2159,8 +2055,7 @@ QPDFWriter::generateObjectStreams() | ||
| 2159 | // Construct a new null object as the "original" object | 2055 | // Construct a new null object as the "original" object |
| 2160 | // stream. The rest of the code knows that this means | 2056 | // stream. The rest of the code knows that this means |
| 2161 | // we're creating the object stream from scratch. | 2057 | // we're creating the object stream from scratch. |
| 2162 | - cur_ostream = m->pdf.makeIndirectObject(QPDFObjectHandle::newNull()) | ||
| 2163 | - .getObjectID(); | 2058 | + cur_ostream = m->pdf.makeIndirectObject(QPDFObjectHandle::newNull()).getObjectID(); |
| 2164 | } | 2059 | } |
| 2165 | m->object_to_object_stream[iter] = cur_ostream; | 2060 | m->object_to_object_stream[iter] = cur_ostream; |
| 2166 | ++n; | 2061 | ++n; |
| @@ -2215,10 +2110,7 @@ QPDFWriter::prepareFileForWrite() | @@ -2215,10 +2110,7 @@ QPDFWriter::prepareFileForWrite() | ||
| 2215 | if (oh.hasKey("/ADBE")) { | 2110 | if (oh.hasKey("/ADBE")) { |
| 2216 | QPDFObjectHandle adbe = oh.getKey("/ADBE"); | 2111 | QPDFObjectHandle adbe = oh.getKey("/ADBE"); |
| 2217 | if (adbe.isIndirect()) { | 2112 | if (adbe.isIndirect()) { |
| 2218 | - QTC::TC( | ||
| 2219 | - "qpdf", | ||
| 2220 | - "QPDFWriter make ADBE direct", | ||
| 2221 | - extensions_indirect ? 0 : 1); | 2113 | + QTC::TC("qpdf", "QPDFWriter make ADBE direct", extensions_indirect ? 0 : 1); |
| 2222 | adbe.makeDirect(); | 2114 | adbe.makeDirect(); |
| 2223 | oh.replaceKey("/ADBE", adbe); | 2115 | oh.replaceKey("/ADBE", adbe); |
| 2224 | } | 2116 | } |
| @@ -2262,9 +2154,7 @@ QPDFWriter::doWriteSetup() | @@ -2262,9 +2154,7 @@ QPDFWriter::doWriteSetup() | ||
| 2262 | if (m->encrypted) { | 2154 | if (m->encrypted) { |
| 2263 | // Encryption has been explicitly set | 2155 | // Encryption has been explicitly set |
| 2264 | m->preserve_encryption = false; | 2156 | m->preserve_encryption = false; |
| 2265 | - } else if ( | ||
| 2266 | - m->normalize_content || m->stream_decode_level || m->pclm || | ||
| 2267 | - m->qdf_mode) { | 2157 | + } else if (m->normalize_content || m->stream_decode_level || m->pclm || m->qdf_mode) { |
| 2268 | // Encryption makes looking at contents pretty useless. If | 2158 | // Encryption makes looking at contents pretty useless. If |
| 2269 | // the user explicitly encrypted though, we still obey that. | 2159 | // the user explicitly encrypted though, we still obey that. |
| 2270 | m->preserve_encryption = false; | 2160 | m->preserve_encryption = false; |
| @@ -2342,8 +2232,7 @@ QPDFWriter::doWriteSetup() | @@ -2342,8 +2232,7 @@ QPDFWriter::doWriteSetup() | ||
| 2342 | int stream = iter.second; | 2232 | int stream = iter.second; |
| 2343 | m->object_stream_to_objects[stream].insert(obj); | 2233 | m->object_stream_to_objects[stream].insert(obj); |
| 2344 | m->max_ostream_index = std::max( | 2234 | m->max_ostream_index = std::max( |
| 2345 | - m->max_ostream_index, | ||
| 2346 | - QIntC::to_int(m->object_stream_to_objects[stream].size()) - 1); | 2235 | + m->max_ostream_index, QIntC::to_int(m->object_stream_to_objects[stream].size()) - 1); |
| 2347 | } | 2236 | } |
| 2348 | 2237 | ||
| 2349 | if (!m->object_stream_to_objects.empty()) { | 2238 | if (!m->object_stream_to_objects.empty()) { |
| @@ -2368,8 +2257,7 @@ QPDFWriter::write() | @@ -2368,8 +2257,7 @@ QPDFWriter::write() | ||
| 2368 | // Set up progress reporting. For linearized files, we write two | 2257 | // Set up progress reporting. For linearized files, we write two |
| 2369 | // passes. events_expected is an approximation, but it's good | 2258 | // passes. events_expected is an approximation, but it's good |
| 2370 | // enough for progress reporting, which is mostly a guess anyway. | 2259 | // enough for progress reporting, which is mostly a guess anyway. |
| 2371 | - m->events_expected = | ||
| 2372 | - QIntC::to_int(m->pdf.getObjectCount() * (m->linearized ? 2 : 1)); | 2260 | + m->events_expected = QIntC::to_int(m->pdf.getObjectCount() * (m->linearized ? 2 : 1)); |
| 2373 | 2261 | ||
| 2374 | prepareFileForWrite(); | 2262 | prepareFileForWrite(); |
| 2375 | 2263 | ||
| @@ -2541,8 +2429,7 @@ QPDFWriter::writeXRefTable( | @@ -2541,8 +2429,7 @@ QPDFWriter::writeXRefTable( | ||
| 2541 | qpdf_offset_t offset = 0; | 2429 | qpdf_offset_t offset = 0; |
| 2542 | if (!suppress_offsets) { | 2430 | if (!suppress_offsets) { |
| 2543 | offset = m->xref[i].getOffset(); | 2431 | offset = m->xref[i].getOffset(); |
| 2544 | - if ((hint_id != 0) && (i != hint_id) && | ||
| 2545 | - (offset >= hint_offset)) { | 2432 | + if ((hint_id != 0) && (i != hint_id) && (offset >= hint_offset)) { |
| 2546 | offset += hint_length; | 2433 | offset += hint_length; |
| 2547 | } | 2434 | } |
| 2548 | } | 2435 | } |
| @@ -2557,31 +2444,13 @@ QPDFWriter::writeXRefTable( | @@ -2557,31 +2444,13 @@ QPDFWriter::writeXRefTable( | ||
| 2557 | 2444 | ||
| 2558 | qpdf_offset_t | 2445 | qpdf_offset_t |
| 2559 | QPDFWriter::writeXRefStream( | 2446 | QPDFWriter::writeXRefStream( |
| 2560 | - int objid, | ||
| 2561 | - int max_id, | ||
| 2562 | - qpdf_offset_t max_offset, | ||
| 2563 | - trailer_e which, | ||
| 2564 | - int first, | ||
| 2565 | - int last, | ||
| 2566 | - int size) | 2447 | + int objid, int max_id, qpdf_offset_t max_offset, trailer_e which, int first, int last, int size) |
| 2567 | { | 2448 | { |
| 2568 | // There are too many extra arguments to replace overloaded | 2449 | // There are too many extra arguments to replace overloaded |
| 2569 | // function with defaults in the header file...too much risk of | 2450 | // function with defaults in the header file...too much risk of |
| 2570 | // leaving something off. | 2451 | // leaving something off. |
| 2571 | return writeXRefStream( | 2452 | return writeXRefStream( |
| 2572 | - objid, | ||
| 2573 | - max_id, | ||
| 2574 | - max_offset, | ||
| 2575 | - which, | ||
| 2576 | - first, | ||
| 2577 | - last, | ||
| 2578 | - size, | ||
| 2579 | - 0, | ||
| 2580 | - 0, | ||
| 2581 | - 0, | ||
| 2582 | - 0, | ||
| 2583 | - false, | ||
| 2584 | - 0); | 2453 | + objid, max_id, max_offset, which, first, last, size, 0, 0, 0, 0, false, 0); |
| 2585 | } | 2454 | } |
| 2586 | 2455 | ||
| 2587 | qpdf_offset_t | 2456 | qpdf_offset_t |
| @@ -2604,8 +2473,7 @@ QPDFWriter::writeXRefStream( | @@ -2604,8 +2473,7 @@ QPDFWriter::writeXRefStream( | ||
| 2604 | qpdf_offset_t space_before_zero = xref_offset - 1; | 2473 | qpdf_offset_t space_before_zero = xref_offset - 1; |
| 2605 | 2474 | ||
| 2606 | // field 1 contains offsets and object stream identifiers | 2475 | // field 1 contains offsets and object stream identifiers |
| 2607 | - unsigned int f1_size = | ||
| 2608 | - std::max(bytesNeeded(max_offset + hint_length), bytesNeeded(max_id)); | 2476 | + unsigned int f1_size = std::max(bytesNeeded(max_offset + hint_length), bytesNeeded(max_id)); |
| 2609 | 2477 | ||
| 2610 | // field 2 contains object stream indices | 2478 | // field 2 contains object stream indices |
| 2611 | unsigned int f2_size = bytesNeeded(m->max_ostream_index); | 2479 | unsigned int f2_size = bytesNeeded(m->max_ostream_index); |
| @@ -2618,18 +2486,15 @@ QPDFWriter::writeXRefStream( | @@ -2618,18 +2486,15 @@ QPDFWriter::writeXRefStream( | ||
| 2618 | 2486 | ||
| 2619 | Pipeline* p = pushPipeline(new Pl_Buffer("xref stream")); | 2487 | Pipeline* p = pushPipeline(new Pl_Buffer("xref stream")); |
| 2620 | bool compressed = false; | 2488 | bool compressed = false; |
| 2621 | - if ((m->compress_streams || (m->stream_decode_level == qpdf_dl_none)) && | ||
| 2622 | - (!m->qdf_mode)) { | 2489 | + if ((m->compress_streams || (m->stream_decode_level == qpdf_dl_none)) && (!m->qdf_mode)) { |
| 2623 | compressed = true; | 2490 | compressed = true; |
| 2624 | if (!skip_compression) { | 2491 | if (!skip_compression) { |
| 2625 | // Write the stream dictionary for compression but don't | 2492 | // Write the stream dictionary for compression but don't |
| 2626 | // actually compress. This helps us with computation of | 2493 | // actually compress. This helps us with computation of |
| 2627 | // padding for pass 1 of linearization. | 2494 | // padding for pass 1 of linearization. |
| 2628 | - p = pushPipeline( | ||
| 2629 | - new Pl_Flate("compress xref", p, Pl_Flate::a_deflate)); | 2495 | + p = pushPipeline(new Pl_Flate("compress xref", p, Pl_Flate::a_deflate)); |
| 2630 | } | 2496 | } |
| 2631 | - p = pushPipeline( | ||
| 2632 | - new Pl_PNGFilter("pngify xref", p, Pl_PNGFilter::a_encode, esize)); | 2497 | + p = pushPipeline(new Pl_PNGFilter("pngify xref", p, Pl_PNGFilter::a_encode, esize)); |
| 2633 | } | 2498 | } |
| 2634 | std::shared_ptr<Buffer> xref_data; | 2499 | std::shared_ptr<Buffer> xref_data; |
| 2635 | { | 2500 | { |
| @@ -2647,8 +2512,7 @@ QPDFWriter::writeXRefStream( | @@ -2647,8 +2512,7 @@ QPDFWriter::writeXRefStream( | ||
| 2647 | case 1: | 2512 | case 1: |
| 2648 | { | 2513 | { |
| 2649 | qpdf_offset_t offset = e.getOffset(); | 2514 | qpdf_offset_t offset = e.getOffset(); |
| 2650 | - if ((hint_id != 0) && (i != hint_id) && | ||
| 2651 | - (offset >= hint_offset)) { | 2515 | + if ((hint_id != 0) && (i != hint_id) && (offset >= hint_offset)) { |
| 2652 | offset += hint_length; | 2516 | offset += hint_length; |
| 2653 | } | 2517 | } |
| 2654 | writeBinary(1, 1); | 2518 | writeBinary(1, 1); |
| @@ -2659,10 +2523,8 @@ QPDFWriter::writeXRefStream( | @@ -2659,10 +2523,8 @@ QPDFWriter::writeXRefStream( | ||
| 2659 | 2523 | ||
| 2660 | case 2: | 2524 | case 2: |
| 2661 | writeBinary(2, 1); | 2525 | writeBinary(2, 1); |
| 2662 | - writeBinary( | ||
| 2663 | - QIntC::to_ulonglong(e.getObjStreamNumber()), f1_size); | ||
| 2664 | - writeBinary( | ||
| 2665 | - QIntC::to_ulonglong(e.getObjStreamIndex()), f2_size); | 2526 | + writeBinary(QIntC::to_ulonglong(e.getObjStreamNumber()), f1_size); |
| 2527 | + writeBinary(QIntC::to_ulonglong(e.getObjStreamIndex()), f2_size); | ||
| 2666 | break; | 2528 | break; |
| 2667 | 2529 | ||
| 2668 | default: | 2530 | default: |
| @@ -2682,18 +2544,13 @@ QPDFWriter::writeXRefStream( | @@ -2682,18 +2544,13 @@ QPDFWriter::writeXRefStream( | ||
| 2682 | writeStringQDF("\n "); | 2544 | writeStringQDF("\n "); |
| 2683 | writeString(" /Filter /FlateDecode"); | 2545 | writeString(" /Filter /FlateDecode"); |
| 2684 | writeStringQDF("\n "); | 2546 | writeStringQDF("\n "); |
| 2685 | - writeString( | ||
| 2686 | - " /DecodeParms << /Columns " + std::to_string(esize) + | ||
| 2687 | - " /Predictor 12 >>"); | 2547 | + writeString(" /DecodeParms << /Columns " + std::to_string(esize) + " /Predictor 12 >>"); |
| 2688 | } | 2548 | } |
| 2689 | writeStringQDF("\n "); | 2549 | writeStringQDF("\n "); |
| 2690 | - writeString( | ||
| 2691 | - " /W [ 1 " + std::to_string(f1_size) + " " + std::to_string(f2_size) + | ||
| 2692 | - " ]"); | 2550 | + writeString(" /W [ 1 " + std::to_string(f1_size) + " " + std::to_string(f2_size) + " ]"); |
| 2693 | if (!((first == 0) && (last == size - 1))) { | 2551 | if (!((first == 0) && (last == size - 1))) { |
| 2694 | writeString( | 2552 | writeString( |
| 2695 | - " /Index [ " + std::to_string(first) + " " + | ||
| 2696 | - std::to_string(last - first + 1) + " ]"); | 2553 | + " /Index [ " + std::to_string(first) + " " + std::to_string(last - first + 1) + " ]"); |
| 2697 | } | 2554 | } |
| 2698 | writeTrailer(which, size, true, prev, linearization_pass); | 2555 | writeTrailer(which, size, true, prev, linearization_pass); |
| 2699 | writeString("\nstream\n"); | 2556 | writeString("\nstream\n"); |
| @@ -2718,8 +2575,7 @@ QPDFWriter::calculateXrefStreamPadding(qpdf_offset_t xref_bytes) | @@ -2718,8 +2575,7 @@ QPDFWriter::calculateXrefStreamPadding(qpdf_offset_t xref_bytes) | ||
| 2718 | } | 2575 | } |
| 2719 | 2576 | ||
| 2720 | void | 2577 | void |
| 2721 | -QPDFWriter::discardGeneration( | ||
| 2722 | - std::map<QPDFObjGen, int> const& in, std::map<int, int>& out) | 2578 | +QPDFWriter::discardGeneration(std::map<QPDFObjGen, int> const& in, std::map<int, int>& out) |
| 2723 | { | 2579 | { |
| 2724 | // There are deep assumptions in the linearization code in QPDF | 2580 | // There are deep assumptions in the linearization code in QPDF |
| 2725 | // that there is only one object with each object number; i.e., | 2581 | // that there is only one object with each object number; i.e., |
| @@ -2736,14 +2592,13 @@ QPDFWriter::discardGeneration( | @@ -2736,14 +2592,13 @@ QPDFWriter::discardGeneration( | ||
| 2736 | out.clear(); | 2592 | out.clear(); |
| 2737 | for (auto const& iter: in) { | 2593 | for (auto const& iter: in) { |
| 2738 | if (out.count(iter.first.getObj())) { | 2594 | if (out.count(iter.first.getObj())) { |
| 2739 | - throw std::runtime_error( | ||
| 2740 | - "QPDF cannot currently linearize files that contain" | ||
| 2741 | - " multiple objects with the same object ID and different" | ||
| 2742 | - " generations. If you see this error message, please file" | ||
| 2743 | - " a bug report and attach the file if possible. As a" | ||
| 2744 | - " workaround, first convert the file with qpdf without" | ||
| 2745 | - " linearizing, and then linearize the result of that" | ||
| 2746 | - " conversion."); | 2595 | + throw std::runtime_error("QPDF cannot currently linearize files that contain" |
| 2596 | + " multiple objects with the same object ID and different" | ||
| 2597 | + " generations. If you see this error message, please file" | ||
| 2598 | + " a bug report and attach the file if possible. As a" | ||
| 2599 | + " workaround, first convert the file with qpdf without" | ||
| 2600 | + " linearizing, and then linearize the result of that" | ||
| 2601 | + " conversion."); | ||
| 2747 | } | 2602 | } |
| 2748 | out[iter.first.getObj()] = iter.second; | 2603 | out[iter.first.getObj()] = iter.second; |
| 2749 | } | 2604 | } |
| @@ -2754,8 +2609,7 @@ QPDFWriter::writeLinearized() | @@ -2754,8 +2609,7 @@ QPDFWriter::writeLinearized() | ||
| 2754 | { | 2609 | { |
| 2755 | // Optimize file and enqueue objects in order | 2610 | // Optimize file and enqueue objects in order |
| 2756 | 2611 | ||
| 2757 | - discardGeneration( | ||
| 2758 | - m->object_to_object_stream, m->object_to_object_stream_no_gen); | 2612 | + discardGeneration(m->object_to_object_stream, m->object_to_object_stream_no_gen); |
| 2759 | 2613 | ||
| 2760 | auto skip_stream_parameters = [this](QPDFObjectHandle& stream) { | 2614 | auto skip_stream_parameters = [this](QPDFObjectHandle& stream) { |
| 2761 | bool compress_stream; | 2615 | bool compress_stream; |
| @@ -2767,8 +2621,7 @@ QPDFWriter::writeLinearized() | @@ -2767,8 +2621,7 @@ QPDFWriter::writeLinearized() | ||
| 2767 | } | 2621 | } |
| 2768 | }; | 2622 | }; |
| 2769 | 2623 | ||
| 2770 | - m->pdf.optimize( | ||
| 2771 | - m->object_to_object_stream_no_gen, true, skip_stream_parameters); | 2624 | + m->pdf.optimize(m->object_to_object_stream_no_gen, true, skip_stream_parameters); |
| 2772 | 2625 | ||
| 2773 | std::vector<QPDFObjectHandle> part4; | 2626 | std::vector<QPDFObjectHandle> part4; |
| 2774 | std::vector<QPDFObjectHandle> part6; | 2627 | std::vector<QPDFObjectHandle> part6; |
| @@ -2776,13 +2629,7 @@ QPDFWriter::writeLinearized() | @@ -2776,13 +2629,7 @@ QPDFWriter::writeLinearized() | ||
| 2776 | std::vector<QPDFObjectHandle> part8; | 2629 | std::vector<QPDFObjectHandle> part8; |
| 2777 | std::vector<QPDFObjectHandle> part9; | 2630 | std::vector<QPDFObjectHandle> part9; |
| 2778 | QPDF::Writer::getLinearizedParts( | 2631 | QPDF::Writer::getLinearizedParts( |
| 2779 | - m->pdf, | ||
| 2780 | - m->object_to_object_stream_no_gen, | ||
| 2781 | - part4, | ||
| 2782 | - part6, | ||
| 2783 | - part7, | ||
| 2784 | - part8, | ||
| 2785 | - part9); | 2632 | + m->pdf, m->object_to_object_stream_no_gen, part4, part6, part7, part8, part9); |
| 2786 | 2633 | ||
| 2787 | // Object number sequence: | 2634 | // Object number sequence: |
| 2788 | // | 2635 | // |
| @@ -2801,8 +2648,7 @@ QPDFWriter::writeLinearized() | @@ -2801,8 +2648,7 @@ QPDFWriter::writeLinearized() | ||
| 2801 | // | 2648 | // |
| 2802 | 2649 | ||
| 2803 | // Second half objects | 2650 | // Second half objects |
| 2804 | - int second_half_uncompressed = | ||
| 2805 | - QIntC::to_int(part7.size() + part8.size() + part9.size()); | 2651 | + int second_half_uncompressed = QIntC::to_int(part7.size() + part8.size() + part9.size()); |
| 2806 | int second_half_first_obj = 1; | 2652 | int second_half_first_obj = 1; |
| 2807 | int after_second_half = 1 + second_half_uncompressed; | 2653 | int after_second_half = 1 + second_half_uncompressed; |
| 2808 | m->next_objid = after_second_half; | 2654 | m->next_objid = after_second_half; |
| @@ -2893,10 +2739,8 @@ QPDFWriter::writeLinearized() | @@ -2893,10 +2739,8 @@ QPDFWriter::writeLinearized() | ||
| 2893 | for (int pass = 1; pass <= 2; ++pass) { | 2739 | for (int pass = 1; pass <= 2; ++pass) { |
| 2894 | if (pass == 1) { | 2740 | if (pass == 1) { |
| 2895 | if (!m->lin_pass1_filename.empty()) { | 2741 | if (!m->lin_pass1_filename.empty()) { |
| 2896 | - lin_pass1_file = | ||
| 2897 | - QUtil::safe_fopen(m->lin_pass1_filename.c_str(), "wb"); | ||
| 2898 | - pushPipeline( | ||
| 2899 | - new Pl_StdioFile("linearization pass1", lin_pass1_file)); | 2742 | + lin_pass1_file = QUtil::safe_fopen(m->lin_pass1_filename.c_str(), "wb"); |
| 2743 | + pushPipeline(new Pl_StdioFile("linearization pass1", lin_pass1_file)); | ||
| 2900 | activatePipelineStack(*pp_pass1); | 2744 | activatePipelineStack(*pp_pass1); |
| 2901 | } else { | 2745 | } else { |
| 2902 | pushDiscardFilter(*pp_pass1); | 2746 | pushDiscardFilter(*pp_pass1); |
| @@ -3003,8 +2847,7 @@ QPDFWriter::writeLinearized() | @@ -3003,8 +2847,7 @@ QPDFWriter::writeLinearized() | ||
| 3003 | throw std::logic_error( | 2847 | throw std::logic_error( |
| 3004 | "insufficient padding for first pass xref stream; " | 2848 | "insufficient padding for first pass xref stream; " |
| 3005 | "first_xref_end=" + | 2849 | "first_xref_end=" + |
| 3006 | - std::to_string(first_xref_end) + | ||
| 3007 | - "; endpos=" + std::to_string(endpos)); | 2850 | + std::to_string(first_xref_end) + "; endpos=" + std::to_string(endpos)); |
| 3008 | } | 2851 | } |
| 3009 | } | 2852 | } |
| 3010 | writeString("\n"); | 2853 | writeString("\n"); |
| @@ -3078,9 +2921,8 @@ QPDFWriter::writeLinearized() | @@ -3078,9 +2921,8 @@ QPDFWriter::writeLinearized() | ||
| 3078 | second_xref_end = m->pipeline->getCount(); | 2921 | second_xref_end = m->pipeline->getCount(); |
| 3079 | } else { | 2922 | } else { |
| 3080 | // Make the file size the same. | 2923 | // Make the file size the same. |
| 3081 | - writePad(QIntC::to_size( | ||
| 3082 | - second_xref_end + hint_length - 1 - | ||
| 3083 | - m->pipeline->getCount())); | 2924 | + writePad( |
| 2925 | + QIntC::to_size(second_xref_end + hint_length - 1 - m->pipeline->getCount())); | ||
| 3084 | writeString("\n"); | 2926 | writeString("\n"); |
| 3085 | 2927 | ||
| 3086 | // If this assertion fails, maybe we didn't have | 2928 | // If this assertion fails, maybe we didn't have |
| @@ -3092,16 +2934,7 @@ QPDFWriter::writeLinearized() | @@ -3092,16 +2934,7 @@ QPDFWriter::writeLinearized() | ||
| 3092 | } | 2934 | } |
| 3093 | } else { | 2935 | } else { |
| 3094 | space_before_zero = writeXRefTable( | 2936 | space_before_zero = writeXRefTable( |
| 3095 | - t_lin_second, | ||
| 3096 | - 0, | ||
| 3097 | - second_half_end, | ||
| 3098 | - second_trailer_size, | ||
| 3099 | - 0, | ||
| 3100 | - false, | ||
| 3101 | - 0, | ||
| 3102 | - 0, | ||
| 3103 | - 0, | ||
| 3104 | - pass); | 2937 | + t_lin_second, 0, second_half_end, second_trailer_size, 0, false, 0, 0, 0, pass); |
| 3105 | } | 2938 | } |
| 3106 | writeString("startxref\n"); | 2939 | writeString("startxref\n"); |
| 3107 | writeString(std::to_string(first_xref_offset)); | 2940 | writeString(std::to_string(first_xref_offset)); |
| @@ -3111,10 +2944,7 @@ QPDFWriter::writeLinearized() | @@ -3111,10 +2944,7 @@ QPDFWriter::writeLinearized() | ||
| 3111 | 2944 | ||
| 3112 | if (pass == 1) { | 2945 | if (pass == 1) { |
| 3113 | if (m->deterministic_id) { | 2946 | if (m->deterministic_id) { |
| 3114 | - QTC::TC( | ||
| 3115 | - "qpdf", | ||
| 3116 | - "QPDFWriter linearized deterministic ID", | ||
| 3117 | - need_xref_stream ? 0 : 1); | 2947 | + QTC::TC("qpdf", "QPDFWriter linearized deterministic ID", need_xref_stream ? 0 : 1); |
| 3118 | computeDeterministicIDData(); | 2948 | computeDeterministicIDData(); |
| 3119 | pp_md5 = nullptr; | 2949 | pp_md5 = nullptr; |
| 3120 | qpdf_assert_debug(m->md5_pipeline == nullptr); | 2950 | qpdf_assert_debug(m->md5_pipeline == nullptr); |
| @@ -3142,13 +2972,8 @@ QPDFWriter::writeLinearized() | @@ -3142,13 +2972,8 @@ QPDFWriter::writeLinearized() | ||
| 3142 | if (lin_pass1_file) { | 2972 | if (lin_pass1_file) { |
| 3143 | // Write some debugging information | 2973 | // Write some debugging information |
| 3144 | fprintf( | 2974 | fprintf( |
| 3145 | - lin_pass1_file, | ||
| 3146 | - "%% hint_offset=%s\n", | ||
| 3147 | - std::to_string(hint_offset1).c_str()); | ||
| 3148 | - fprintf( | ||
| 3149 | - lin_pass1_file, | ||
| 3150 | - "%% hint_length=%s\n", | ||
| 3151 | - std::to_string(hint_length).c_str()); | 2975 | + lin_pass1_file, "%% hint_offset=%s\n", std::to_string(hint_offset1).c_str()); |
| 2976 | + fprintf(lin_pass1_file, "%% hint_length=%s\n", std::to_string(hint_length).c_str()); | ||
| 3152 | fprintf( | 2977 | fprintf( |
| 3153 | lin_pass1_file, | 2978 | lin_pass1_file, |
| 3154 | "%% second_xref_offset=%s\n", | 2979 | "%% second_xref_offset=%s\n", |
| @@ -3208,8 +3033,7 @@ QPDFWriter::enqueueObjectsPCLm() | @@ -3208,8 +3033,7 @@ QPDFWriter::enqueueObjectsPCLm() | ||
| 3208 | QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject"); | 3033 | QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject"); |
| 3209 | for (auto const& image: strips.getKeys()) { | 3034 | for (auto const& image: strips.getKeys()) { |
| 3210 | enqueueObject(strips.getKey(image)); | 3035 | enqueueObject(strips.getKey(image)); |
| 3211 | - enqueueObject( | ||
| 3212 | - QPDFObjectHandle::newStream(&m->pdf, image_transform_content)); | 3036 | + enqueueObject(QPDFObjectHandle::newStream(&m->pdf, image_transform_content)); |
| 3213 | } | 3037 | } |
| 3214 | } | 3038 | } |
| 3215 | 3039 | ||
| @@ -3237,8 +3061,7 @@ QPDFWriter::indicateProgress(bool decrement, bool finished) | @@ -3237,8 +3061,7 @@ QPDFWriter::indicateProgress(bool decrement, bool finished) | ||
| 3237 | (finished ? 100 | 3061 | (finished ? 100 |
| 3238 | : m->next_progress_report == 0 | 3062 | : m->next_progress_report == 0 |
| 3239 | ? 0 | 3063 | ? 0 |
| 3240 | - : std::min( | ||
| 3241 | - 99, 1 + ((100 * m->events_seen) / m->events_expected))); | 3064 | + : std::min(99, 1 + ((100 * m->events_seen) / m->events_expected))); |
| 3242 | m->progress_reporter->reportProgress(percentage); | 3065 | m->progress_reporter->reportProgress(percentage); |
| 3243 | } | 3066 | } |
| 3244 | int increment = std::max(1, (m->events_expected / 100)); | 3067 | int increment = std::max(1, (m->events_expected / 100)); |
| @@ -3293,13 +3116,7 @@ QPDFWriter::writeStandard() | @@ -3293,13 +3116,7 @@ QPDFWriter::writeStandard() | ||
| 3293 | // Write cross-reference stream. | 3116 | // Write cross-reference stream. |
| 3294 | int xref_id = m->next_objid++; | 3117 | int xref_id = m->next_objid++; |
| 3295 | writeXRefStream( | 3118 | writeXRefStream( |
| 3296 | - xref_id, | ||
| 3297 | - xref_id, | ||
| 3298 | - xref_offset, | ||
| 3299 | - t_normal, | ||
| 3300 | - 0, | ||
| 3301 | - m->next_objid - 1, | ||
| 3302 | - m->next_objid); | 3119 | + xref_id, xref_id, xref_offset, t_normal, 0, m->next_objid - 1, m->next_objid); |
| 3303 | } | 3120 | } |
| 3304 | writeString("startxref\n"); | 3121 | writeString("startxref\n"); |
| 3305 | writeString(std::to_string(xref_offset)); | 3122 | writeString(std::to_string(xref_offset)); |
libqpdf/QPDFXRefEntry.cc
| @@ -36,8 +36,7 @@ int | @@ -36,8 +36,7 @@ int | ||
| 36 | QPDFXRefEntry::getObjStreamNumber() const | 36 | QPDFXRefEntry::getObjStreamNumber() const |
| 37 | { | 37 | { |
| 38 | if (this->type != 2) { | 38 | if (this->type != 2) { |
| 39 | - throw std::logic_error( | ||
| 40 | - "getObjStreamNumber called for xref entry of type != 2"); | 39 | + throw std::logic_error("getObjStreamNumber called for xref entry of type != 2"); |
| 41 | } | 40 | } |
| 42 | return QIntC::to_int(this->field1); | 41 | return QIntC::to_int(this->field1); |
| 43 | } | 42 | } |
| @@ -46,8 +45,7 @@ int | @@ -46,8 +45,7 @@ int | ||
| 46 | QPDFXRefEntry::getObjStreamIndex() const | 45 | QPDFXRefEntry::getObjStreamIndex() const |
| 47 | { | 46 | { |
| 48 | if (this->type != 2) { | 47 | if (this->type != 2) { |
| 49 | - throw std::logic_error( | ||
| 50 | - "getObjStreamIndex called for xref entry of type != 2"); | 48 | + throw std::logic_error("getObjStreamIndex called for xref entry of type != 2"); |
| 51 | } | 49 | } |
| 52 | return this->field2; | 50 | return this->field2; |
| 53 | } | 51 | } |
libqpdf/QPDF_Array.cc
| @@ -12,16 +12,14 @@ QPDF_Array::checkOwnership(QPDFObjectHandle const& item) const | @@ -12,16 +12,14 @@ QPDF_Array::checkOwnership(QPDFObjectHandle const& item) const | ||
| 12 | if (qpdf) { | 12 | if (qpdf) { |
| 13 | if (auto item_qpdf = obj->getQPDF()) { | 13 | if (auto item_qpdf = obj->getQPDF()) { |
| 14 | if (qpdf != item_qpdf) { | 14 | if (qpdf != item_qpdf) { |
| 15 | - throw std::logic_error( | ||
| 16 | - "Attempting to add an object from a different QPDF. " | ||
| 17 | - "Use QPDF::copyForeignObject to add objects from " | ||
| 18 | - "another file."); | 15 | + throw std::logic_error("Attempting to add an object from a different QPDF. " |
| 16 | + "Use QPDF::copyForeignObject to add objects from " | ||
| 17 | + "another file."); | ||
| 19 | } | 18 | } |
| 20 | } | 19 | } |
| 21 | } | 20 | } |
| 22 | } else { | 21 | } else { |
| 23 | - throw std::logic_error( | ||
| 24 | - "Attempting to add an uninitialized object to a QPDF_Array."); | 22 | + throw std::logic_error("Attempting to add an uninitialized object to a QPDF_Array."); |
| 25 | } | 23 | } |
| 26 | } | 24 | } |
| 27 | 25 | ||
| @@ -45,15 +43,13 @@ QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v) : | @@ -45,15 +43,13 @@ QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v) : | ||
| 45 | setFromVector(v); | 43 | setFromVector(v); |
| 46 | } | 44 | } |
| 47 | 45 | ||
| 48 | -QPDF_Array::QPDF_Array( | ||
| 49 | - std::vector<std::shared_ptr<QPDFObject>>&& v, bool sparse) : | 46 | +QPDF_Array::QPDF_Array(std::vector<std::shared_ptr<QPDFObject>>&& v, bool sparse) : |
| 50 | QPDFValue(::ot_array, "array"), | 47 | QPDFValue(::ot_array, "array"), |
| 51 | sparse(sparse) | 48 | sparse(sparse) |
| 52 | { | 49 | { |
| 53 | if (sparse) { | 50 | if (sparse) { |
| 54 | for (auto&& item: v) { | 51 | for (auto&& item: v) { |
| 55 | - if (item->getTypeCode() != ::ot_null || | ||
| 56 | - item->getObjGen().isIndirect()) { | 52 | + if (item->getTypeCode() != ::ot_null || item->getObjGen().isIndirect()) { |
| 57 | sp_elements[sp_size] = std::move(item); | 53 | sp_elements[sp_size] = std::move(item); |
| 58 | } | 54 | } |
| 59 | ++sp_size; | 55 | ++sp_size; |
| @@ -70,8 +66,7 @@ QPDF_Array::create(std::vector<QPDFObjectHandle> const& items) | @@ -70,8 +66,7 @@ QPDF_Array::create(std::vector<QPDFObjectHandle> const& items) | ||
| 70 | } | 66 | } |
| 71 | 67 | ||
| 72 | std::shared_ptr<QPDFObject> | 68 | std::shared_ptr<QPDFObject> |
| 73 | -QPDF_Array::create( | ||
| 74 | - std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse) | 69 | +QPDF_Array::create(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse) |
| 75 | { | 70 | { |
| 76 | return do_create(new QPDF_Array(std::move(items), sparse)); | 71 | return do_create(new QPDF_Array(std::move(items), sparse)); |
| 77 | } | 72 | } |
| @@ -96,10 +91,8 @@ QPDF_Array::copy(bool shallow) | @@ -96,10 +91,8 @@ QPDF_Array::copy(bool shallow) | ||
| 96 | result.reserve(elements.size()); | 91 | result.reserve(elements.size()); |
| 97 | for (auto const& element: elements) { | 92 | for (auto const& element: elements) { |
| 98 | result.push_back( | 93 | result.push_back( |
| 99 | - element | ||
| 100 | - ? (element->getObjGen().isIndirect() ? element | ||
| 101 | - : element->copy()) | ||
| 102 | - : element); | 94 | + element ? (element->getObjGen().isIndirect() ? element : element->copy()) |
| 95 | + : element); | ||
| 103 | } | 96 | } |
| 104 | return create(std::move(result), false); | 97 | return create(std::move(result), false); |
| 105 | } | 98 | } |
| @@ -138,8 +131,7 @@ QPDF_Array::unparse() | @@ -138,8 +131,7 @@ QPDF_Array::unparse() | ||
| 138 | } | 131 | } |
| 139 | item.second->resolve(); | 132 | item.second->resolve(); |
| 140 | auto og = item.second->getObjGen(); | 133 | auto og = item.second->getObjGen(); |
| 141 | - result += og.isIndirect() ? og.unparse(' ') + " R " | ||
| 142 | - : item.second->unparse() + " "; | 134 | + result += og.isIndirect() ? og.unparse(' ') + " R " : item.second->unparse() + " "; |
| 143 | next = ++key; | 135 | next = ++key; |
| 144 | } | 136 | } |
| 145 | for (int j = next; j < sp_size; ++j) { | 137 | for (int j = next; j < sp_size; ++j) { |
| @@ -149,8 +141,7 @@ QPDF_Array::unparse() | @@ -149,8 +141,7 @@ QPDF_Array::unparse() | ||
| 149 | for (auto const& item: elements) { | 141 | for (auto const& item: elements) { |
| 150 | item->resolve(); | 142 | item->resolve(); |
| 151 | auto og = item->getObjGen(); | 143 | auto og = item->getObjGen(); |
| 152 | - result += og.isIndirect() ? og.unparse(' ') + " R " | ||
| 153 | - : item->unparse() + " "; | 144 | + result += og.isIndirect() ? og.unparse(' ') + " R " : item->unparse() + " "; |
| 154 | } | 145 | } |
| 155 | } | 146 | } |
| 156 | result += "]"; | 147 | result += "]"; |
libqpdf/QPDF_Destroyed.cc
| @@ -17,23 +17,20 @@ QPDF_Destroyed::getInstance() | @@ -17,23 +17,20 @@ QPDF_Destroyed::getInstance() | ||
| 17 | std::shared_ptr<QPDFObject> | 17 | std::shared_ptr<QPDFObject> |
| 18 | QPDF_Destroyed::copy(bool shallow) | 18 | QPDF_Destroyed::copy(bool shallow) |
| 19 | { | 19 | { |
| 20 | - throw std::logic_error( | ||
| 21 | - "attempted to shallow copy QPDFObjectHandle from destroyed QPDF"); | 20 | + throw std::logic_error("attempted to shallow copy QPDFObjectHandle from destroyed QPDF"); |
| 22 | return nullptr; | 21 | return nullptr; |
| 23 | } | 22 | } |
| 24 | 23 | ||
| 25 | std::string | 24 | std::string |
| 26 | QPDF_Destroyed::unparse() | 25 | QPDF_Destroyed::unparse() |
| 27 | { | 26 | { |
| 28 | - throw std::logic_error( | ||
| 29 | - "attempted to unparse a QPDFObjectHandle from a destroyed QPDF"); | 27 | + throw std::logic_error("attempted to unparse a QPDFObjectHandle from a destroyed QPDF"); |
| 30 | return ""; | 28 | return ""; |
| 31 | } | 29 | } |
| 32 | 30 | ||
| 33 | JSON | 31 | JSON |
| 34 | QPDF_Destroyed::getJSON(int json_version) | 32 | QPDF_Destroyed::getJSON(int json_version) |
| 35 | { | 33 | { |
| 36 | - throw std::logic_error( | ||
| 37 | - "attempted to get JSON from a QPDFObjectHandle from a destroyed QPDF"); | 34 | + throw std::logic_error("attempted to get JSON from a QPDFObjectHandle from a destroyed QPDF"); |
| 38 | return JSON::makeNull(); | 35 | return JSON::makeNull(); |
| 39 | } | 36 | } |
libqpdf/QPDF_Dictionary.cc
| @@ -6,15 +6,13 @@ | @@ -6,15 +6,13 @@ | ||
| 6 | 6 | ||
| 7 | using namespace std::literals; | 7 | using namespace std::literals; |
| 8 | 8 | ||
| 9 | -QPDF_Dictionary::QPDF_Dictionary( | ||
| 10 | - std::map<std::string, QPDFObjectHandle> const& items) : | 9 | +QPDF_Dictionary::QPDF_Dictionary(std::map<std::string, QPDFObjectHandle> const& items) : |
| 11 | QPDFValue(::ot_dictionary, "dictionary"), | 10 | QPDFValue(::ot_dictionary, "dictionary"), |
| 12 | items(items) | 11 | items(items) |
| 13 | { | 12 | { |
| 14 | } | 13 | } |
| 15 | 14 | ||
| 16 | -QPDF_Dictionary::QPDF_Dictionary( | ||
| 17 | - std::map<std::string, QPDFObjectHandle>&& items) : | 15 | +QPDF_Dictionary::QPDF_Dictionary(std::map<std::string, QPDFObjectHandle>&& items) : |
| 18 | QPDFValue(::ot_dictionary, "dictionary"), | 16 | QPDFValue(::ot_dictionary, "dictionary"), |
| 19 | items(items) | 17 | items(items) |
| 20 | { | 18 | { |
| @@ -41,8 +39,7 @@ QPDF_Dictionary::copy(bool shallow) | @@ -41,8 +39,7 @@ QPDF_Dictionary::copy(bool shallow) | ||
| 41 | std::map<std::string, QPDFObjectHandle> new_items; | 39 | std::map<std::string, QPDFObjectHandle> new_items; |
| 42 | for (auto const& item: this->items) { | 40 | for (auto const& item: this->items) { |
| 43 | auto value = item.second; | 41 | auto value = item.second; |
| 44 | - new_items[item.first] = | ||
| 45 | - value.isIndirect() ? value : value.shallowCopy(); | 42 | + new_items[item.first] = value.isIndirect() ? value : value.shallowCopy(); |
| 46 | } | 43 | } |
| 47 | return create(new_items); | 44 | return create(new_items); |
| 48 | } | 45 | } |
| @@ -62,8 +59,7 @@ QPDF_Dictionary::unparse() | @@ -62,8 +59,7 @@ QPDF_Dictionary::unparse() | ||
| 62 | std::string result = "<< "; | 59 | std::string result = "<< "; |
| 63 | for (auto& iter: this->items) { | 60 | for (auto& iter: this->items) { |
| 64 | if (!iter.second.isNull()) { | 61 | if (!iter.second.isNull()) { |
| 65 | - result += QPDF_Name::normalizeName(iter.first) + " " + | ||
| 66 | - iter.second.unparse() + " "; | 62 | + result += QPDF_Name::normalizeName(iter.first) + " " + iter.second.unparse() + " "; |
| 67 | } | 63 | } |
| 68 | } | 64 | } |
| 69 | result += ">>"; | 65 | result += ">>"; |
| @@ -77,8 +73,7 @@ QPDF_Dictionary::getJSON(int json_version) | @@ -77,8 +73,7 @@ QPDF_Dictionary::getJSON(int json_version) | ||
| 77 | for (auto& iter: this->items) { | 73 | for (auto& iter: this->items) { |
| 78 | if (!iter.second.isNull()) { | 74 | if (!iter.second.isNull()) { |
| 79 | std::string key = | 75 | std::string key = |
| 80 | - (json_version == 1 ? QPDF_Name::normalizeName(iter.first) | ||
| 81 | - : iter.first); | 76 | + (json_version == 1 ? QPDF_Name::normalizeName(iter.first) : iter.first); |
| 82 | j.addDictionaryMember(key, iter.second.getJSON(json_version)); | 77 | j.addDictionaryMember(key, iter.second.getJSON(json_version)); |
| 83 | } | 78 | } |
| 84 | } | 79 | } |
libqpdf/QPDF_Name.cc
| @@ -36,9 +36,8 @@ QPDF_Name::normalizeName(std::string const& name) | @@ -36,9 +36,8 @@ QPDF_Name::normalizeName(std::string const& name) | ||
| 36 | // invalid #. | 36 | // invalid #. |
| 37 | result += "#"; | 37 | result += "#"; |
| 38 | } else if ( | 38 | } else if ( |
| 39 | - ch < 33 || ch == '#' || ch == '/' || ch == '(' || ch == ')' || | ||
| 40 | - ch == '{' || ch == '}' || ch == '<' || ch == '>' || ch == '[' || | ||
| 41 | - ch == ']' || ch == '%' || ch > 126) { | 39 | + ch < 33 || ch == '#' || ch == '/' || ch == '(' || ch == ')' || ch == '{' || ch == '}' || |
| 40 | + ch == '<' || ch == '>' || ch == '[' || ch == ']' || ch == '%' || ch > 126) { | ||
| 42 | result += QUtil::hex_encode_char(ch); | 41 | result += QUtil::hex_encode_char(ch); |
| 43 | } else { | 42 | } else { |
| 44 | result += ch; | 43 | result += ch; |
libqpdf/QPDF_Null.cc
| @@ -15,9 +15,7 @@ QPDF_Null::create() | @@ -15,9 +15,7 @@ QPDF_Null::create() | ||
| 15 | 15 | ||
| 16 | std::shared_ptr<QPDFObject> | 16 | std::shared_ptr<QPDFObject> |
| 17 | QPDF_Null::create( | 17 | QPDF_Null::create( |
| 18 | - std::shared_ptr<QPDFObject> parent, | ||
| 19 | - std::string_view const& static_descr, | ||
| 20 | - std::string var_descr) | 18 | + std::shared_ptr<QPDFObject> parent, std::string_view const& static_descr, std::string var_descr) |
| 21 | { | 19 | { |
| 22 | auto n = do_create(new QPDF_Null()); | 20 | auto n = do_create(new QPDF_Null()); |
| 23 | n->setChildDescription(parent, static_descr, var_descr); | 21 | n->setChildDescription(parent, static_descr, var_descr); |
| @@ -26,9 +24,7 @@ QPDF_Null::create( | @@ -26,9 +24,7 @@ QPDF_Null::create( | ||
| 26 | 24 | ||
| 27 | std::shared_ptr<QPDFObject> | 25 | std::shared_ptr<QPDFObject> |
| 28 | QPDF_Null::create( | 26 | QPDF_Null::create( |
| 29 | - std::shared_ptr<QPDFValue> parent, | ||
| 30 | - std::string_view const& static_descr, | ||
| 31 | - std::string var_descr) | 27 | + std::shared_ptr<QPDFValue> parent, std::string_view const& static_descr, std::string var_descr) |
| 32 | { | 28 | { |
| 33 | auto n = do_create(new QPDF_Null()); | 29 | auto n = do_create(new QPDF_Null()); |
| 34 | n->setChildDescription(parent, static_descr, var_descr); | 30 | n->setChildDescription(parent, static_descr, var_descr); |
libqpdf/QPDF_Real.cc
| @@ -8,8 +8,7 @@ QPDF_Real::QPDF_Real(std::string const& val) : | @@ -8,8 +8,7 @@ QPDF_Real::QPDF_Real(std::string const& val) : | ||
| 8 | { | 8 | { |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | -QPDF_Real::QPDF_Real( | ||
| 12 | - double value, int decimal_places, bool trim_trailing_zeroes) : | 11 | +QPDF_Real::QPDF_Real(double value, int decimal_places, bool trim_trailing_zeroes) : |
| 13 | QPDFValue(::ot_real, "real"), | 12 | QPDFValue(::ot_real, "real"), |
| 14 | val(QUtil::double_to_string(value, decimal_places, trim_trailing_zeroes)) | 13 | val(QUtil::double_to_string(value, decimal_places, trim_trailing_zeroes)) |
| 15 | { | 14 | { |
| @@ -24,8 +23,7 @@ QPDF_Real::create(std::string const& val) | @@ -24,8 +23,7 @@ QPDF_Real::create(std::string const& val) | ||
| 24 | std::shared_ptr<QPDFObject> | 23 | std::shared_ptr<QPDFObject> |
| 25 | QPDF_Real::create(double value, int decimal_places, bool trim_trailing_zeroes) | 24 | QPDF_Real::create(double value, int decimal_places, bool trim_trailing_zeroes) |
| 26 | { | 25 | { |
| 27 | - return do_create( | ||
| 28 | - new QPDF_Real(value, decimal_places, trim_trailing_zeroes)); | 26 | + return do_create(new QPDF_Real(value, decimal_places, trim_trailing_zeroes)); |
| 29 | } | 27 | } |
| 30 | 28 | ||
| 31 | std::shared_ptr<QPDFObject> | 29 | std::shared_ptr<QPDFObject> |
| @@ -52,9 +50,7 @@ QPDF_Real::getJSON(int json_version) | @@ -52,9 +50,7 @@ QPDF_Real::getJSON(int json_version) | ||
| 52 | result = "0"; | 50 | result = "0"; |
| 53 | } else if (this->val.at(0) == '.') { | 51 | } else if (this->val.at(0) == '.') { |
| 54 | result = "0" + this->val; | 52 | result = "0" + this->val; |
| 55 | - } else if ( | ||
| 56 | - (this->val.length() >= 2) && (this->val.at(0) == '-') && | ||
| 57 | - (this->val.at(1) == '.')) { | 53 | + } else if ((this->val.length() >= 2) && (this->val.at(0) == '-') && (this->val.at(1) == '.')) { |
| 58 | result = "-0." + this->val.substr(2); | 54 | result = "-0." + this->val.substr(2); |
| 59 | } else { | 55 | } else { |
| 60 | result = this->val; | 56 | result = this->val; |
libqpdf/QPDF_Reserved.cc
| @@ -22,15 +22,13 @@ QPDF_Reserved::copy(bool shallow) | @@ -22,15 +22,13 @@ QPDF_Reserved::copy(bool shallow) | ||
| 22 | std::string | 22 | std::string |
| 23 | QPDF_Reserved::unparse() | 23 | QPDF_Reserved::unparse() |
| 24 | { | 24 | { |
| 25 | - throw std::logic_error( | ||
| 26 | - "QPDFObjectHandle: attempting to unparse a reserved object"); | 25 | + throw std::logic_error("QPDFObjectHandle: attempting to unparse a reserved object"); |
| 27 | return ""; | 26 | return ""; |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | JSON | 29 | JSON |
| 31 | QPDF_Reserved::getJSON(int json_version) | 30 | QPDF_Reserved::getJSON(int json_version) |
| 32 | { | 31 | { |
| 33 | - throw std::logic_error( | ||
| 34 | - "QPDFObjectHandle: attempting to get JSON from a reserved object"); | 32 | + throw std::logic_error("QPDFObjectHandle: attempting to get JSON from a reserved object"); |
| 35 | return JSON::makeNull(); | 33 | return JSON::makeNull(); |
| 36 | } | 34 | } |
libqpdf/QPDF_Stream.cc
| @@ -39,8 +39,7 @@ namespace | @@ -39,8 +39,7 @@ namespace | ||
| 39 | for (auto const& key: decode_parms.getKeys()) { | 39 | for (auto const& key: decode_parms.getKeys()) { |
| 40 | if (((key == "/Type") || (key == "/Name")) && | 40 | if (((key == "/Type") || (key == "/Name")) && |
| 41 | ((!decode_parms.hasKey("/Type")) || | 41 | ((!decode_parms.hasKey("/Type")) || |
| 42 | - decode_parms.isDictionaryOfType( | ||
| 43 | - "/CryptFilterDecodeParms"))) { | 42 | + decode_parms.isDictionaryOfType("/CryptFilterDecodeParms"))) { |
| 44 | // we handle this in decryptStream | 43 | // we handle this in decryptStream |
| 45 | } else { | 44 | } else { |
| 46 | filterable = false; | 45 | filterable = false; |
| @@ -60,8 +59,7 @@ namespace | @@ -60,8 +59,7 @@ namespace | ||
| 60 | class StreamBlobProvider | 59 | class StreamBlobProvider |
| 61 | { | 60 | { |
| 62 | public: | 61 | public: |
| 63 | - StreamBlobProvider( | ||
| 64 | - QPDF_Stream* stream, qpdf_stream_decode_level_e decode_level); | 62 | + StreamBlobProvider(QPDF_Stream* stream, qpdf_stream_decode_level_e decode_level); |
| 65 | void operator()(Pipeline*); | 63 | void operator()(Pipeline*); |
| 66 | 64 | ||
| 67 | private: | 65 | private: |
| @@ -148,8 +146,7 @@ QPDF_Stream::copy(bool shallow) | @@ -148,8 +146,7 @@ QPDF_Stream::copy(bool shallow) | ||
| 148 | 146 | ||
| 149 | void | 147 | void |
| 150 | QPDF_Stream::registerStreamFilter( | 148 | QPDF_Stream::registerStreamFilter( |
| 151 | - std::string const& filter_name, | ||
| 152 | - std::function<std::shared_ptr<QPDFStreamFilter>()> factory) | 149 | + std::string const& filter_name, std::function<std::shared_ptr<QPDFStreamFilter>()> factory) |
| 153 | { | 150 | { |
| 154 | filter_factories[filter_name] = factory; | 151 | filter_factories[filter_name] = factory; |
| 155 | } | 152 | } |
| @@ -201,9 +198,8 @@ QPDF_Stream::getStreamJSON( | @@ -201,9 +198,8 @@ QPDF_Stream::getStreamJSON( | ||
| 201 | case qpdf_sj_none: | 198 | case qpdf_sj_none: |
| 202 | case qpdf_sj_inline: | 199 | case qpdf_sj_inline: |
| 203 | if (p != nullptr) { | 200 | if (p != nullptr) { |
| 204 | - throw std::logic_error( | ||
| 205 | - "QPDF_Stream::getStreamJSON: pipeline should " | ||
| 206 | - "only be supplied when json_data is file"); | 201 | + throw std::logic_error("QPDF_Stream::getStreamJSON: pipeline should " |
| 202 | + "only be supplied when json_data is file"); | ||
| 207 | } | 203 | } |
| 208 | break; | 204 | break; |
| 209 | case qpdf_sj_file: | 205 | case qpdf_sj_file: |
| @@ -235,13 +231,8 @@ QPDF_Stream::getStreamJSON( | @@ -235,13 +231,8 @@ QPDF_Stream::getStreamJSON( | ||
| 235 | } else { | 231 | } else { |
| 236 | data_pipeline = &discard; | 232 | data_pipeline = &discard; |
| 237 | } | 233 | } |
| 238 | - bool succeeded = pipeStreamData( | ||
| 239 | - data_pipeline, | ||
| 240 | - &filtered, | ||
| 241 | - 0, | ||
| 242 | - decode_level, | ||
| 243 | - false, | ||
| 244 | - (attempt == 1)); | 234 | + bool succeeded = |
| 235 | + pipeStreamData(data_pipeline, &filtered, 0, decode_level, false, (attempt == 1)); | ||
| 245 | if ((!succeeded) || (filter && (!filtered))) { | 236 | if ((!succeeded) || (filter && (!filtered))) { |
| 246 | // Try again | 237 | // Try again |
| 247 | filter = false; | 238 | filter = false; |
| @@ -262,19 +253,16 @@ QPDF_Stream::getStreamJSON( | @@ -262,19 +253,16 @@ QPDF_Stream::getStreamJSON( | ||
| 262 | dict.removeKey("/DecodeParms"); | 253 | dict.removeKey("/DecodeParms"); |
| 263 | } | 254 | } |
| 264 | if (json_data == qpdf_sj_file) { | 255 | if (json_data == qpdf_sj_file) { |
| 265 | - result.addDictionaryMember( | ||
| 266 | - "datafile", JSON::makeString(data_filename)); | 256 | + result.addDictionaryMember("datafile", JSON::makeString(data_filename)); |
| 267 | if (!buf.get()) { | 257 | if (!buf.get()) { |
| 268 | - throw std::logic_error( | ||
| 269 | - "QPDF_Stream: failed to get stream data in json file mode"); | 258 | + throw std::logic_error("QPDF_Stream: failed to get stream data in json file mode"); |
| 270 | } | 259 | } |
| 271 | p->write(buf->getBuffer(), buf->getSize()); | 260 | p->write(buf->getBuffer(), buf->getSize()); |
| 272 | } else if (json_data == qpdf_sj_inline) { | 261 | } else if (json_data == qpdf_sj_inline) { |
| 273 | result.addDictionaryMember( | 262 | result.addDictionaryMember( |
| 274 | "data", JSON::makeBlob(StreamBlobProvider(this, decode_level))); | 263 | "data", JSON::makeBlob(StreamBlobProvider(this, decode_level))); |
| 275 | } else { | 264 | } else { |
| 276 | - throw std::logic_error( | ||
| 277 | - "QPDF_Stream: unexpected value of json_data"); | 265 | + throw std::logic_error("QPDF_Stream: unexpected value of json_data"); |
| 278 | } | 266 | } |
| 279 | } | 267 | } |
| 280 | result.addDictionaryMember("dict", dict.getJSON(json_version)); | 268 | result.addDictionaryMember("dict", dict.getJSON(json_version)); |
| @@ -283,9 +271,7 @@ QPDF_Stream::getStreamJSON( | @@ -283,9 +271,7 @@ QPDF_Stream::getStreamJSON( | ||
| 283 | 271 | ||
| 284 | void | 272 | void |
| 285 | QPDF_Stream::setDescription( | 273 | QPDF_Stream::setDescription( |
| 286 | - QPDF* qpdf, | ||
| 287 | - std::shared_ptr<QPDFValue::Description>& description, | ||
| 288 | - qpdf_offset_t offset) | 274 | + QPDF* qpdf, std::shared_ptr<QPDFValue::Description>& description, qpdf_offset_t offset) |
| 289 | { | 275 | { |
| 290 | this->QPDFValue::setDescription(qpdf, description, offset); | 276 | this->QPDFValue::setDescription(qpdf, description, offset); |
| 291 | setDictDescription(); | 277 | setDictDescription(); |
| @@ -295,8 +281,7 @@ void | @@ -295,8 +281,7 @@ void | ||
| 295 | QPDF_Stream::setDictDescription() | 281 | QPDF_Stream::setDictDescription() |
| 296 | { | 282 | { |
| 297 | if (!this->stream_dict.hasObjectDescription()) { | 283 | if (!this->stream_dict.hasObjectDescription()) { |
| 298 | - this->stream_dict.setObjectDescription( | ||
| 299 | - qpdf, getDescription() + " -> stream dictionary"); | 284 | + this->stream_dict.setObjectDescription(qpdf, getDescription() + " -> stream dictionary"); |
| 300 | } | 285 | } |
| 301 | } | 286 | } |
| 302 | 287 | ||
| @@ -495,8 +480,7 @@ QPDF_Stream::pipeStreamData( | @@ -495,8 +480,7 @@ QPDF_Stream::pipeStreamData( | ||
| 495 | filter = (!((encode_flags == 0) && (decode_level == qpdf_dl_none))); | 480 | filter = (!((encode_flags == 0) && (decode_level == qpdf_dl_none))); |
| 496 | bool success = true; | 481 | bool success = true; |
| 497 | if (filter) { | 482 | if (filter) { |
| 498 | - filter = | ||
| 499 | - filterable(filters, specialized_compression, lossy_compression); | 483 | + filter = filterable(filters, specialized_compression, lossy_compression); |
| 500 | if ((decode_level < qpdf_dl_all) && lossy_compression) { | 484 | if ((decode_level < qpdf_dl_all) && lossy_compression) { |
| 501 | filter = false; | 485 | filter = false; |
| 502 | } | 486 | } |
| @@ -528,47 +512,42 @@ QPDF_Stream::pipeStreamData( | @@ -528,47 +512,42 @@ QPDF_Stream::pipeStreamData( | ||
| 528 | std::shared_ptr<Pipeline> new_pipeline; | 512 | std::shared_ptr<Pipeline> new_pipeline; |
| 529 | if (filter) { | 513 | if (filter) { |
| 530 | if (encode_flags & qpdf_ef_compress) { | 514 | if (encode_flags & qpdf_ef_compress) { |
| 531 | - new_pipeline = std::make_shared<Pl_Flate>( | ||
| 532 | - "compress stream", pipeline, Pl_Flate::a_deflate); | 515 | + new_pipeline = |
| 516 | + std::make_shared<Pl_Flate>("compress stream", pipeline, Pl_Flate::a_deflate); | ||
| 533 | to_delete.push_back(new_pipeline); | 517 | to_delete.push_back(new_pipeline); |
| 534 | pipeline = new_pipeline.get(); | 518 | pipeline = new_pipeline.get(); |
| 535 | } | 519 | } |
| 536 | 520 | ||
| 537 | if (encode_flags & qpdf_ef_normalize) { | 521 | if (encode_flags & qpdf_ef_normalize) { |
| 538 | normalizer = std::make_shared<ContentNormalizer>(); | 522 | normalizer = std::make_shared<ContentNormalizer>(); |
| 539 | - new_pipeline = std::make_shared<Pl_QPDFTokenizer>( | ||
| 540 | - "normalizer", normalizer.get(), pipeline); | 523 | + new_pipeline = |
| 524 | + std::make_shared<Pl_QPDFTokenizer>("normalizer", normalizer.get(), pipeline); | ||
| 541 | to_delete.push_back(new_pipeline); | 525 | to_delete.push_back(new_pipeline); |
| 542 | pipeline = new_pipeline.get(); | 526 | pipeline = new_pipeline.get(); |
| 543 | } | 527 | } |
| 544 | 528 | ||
| 545 | - for (auto iter = this->token_filters.rbegin(); | ||
| 546 | - iter != this->token_filters.rend(); | ||
| 547 | - ++iter) { | ||
| 548 | - new_pipeline = std::make_shared<Pl_QPDFTokenizer>( | ||
| 549 | - "token filter", (*iter).get(), pipeline); | 529 | + for (auto iter = this->token_filters.rbegin(); iter != this->token_filters.rend(); ++iter) { |
| 530 | + new_pipeline = | ||
| 531 | + std::make_shared<Pl_QPDFTokenizer>("token filter", (*iter).get(), pipeline); | ||
| 550 | to_delete.push_back(new_pipeline); | 532 | to_delete.push_back(new_pipeline); |
| 551 | pipeline = new_pipeline.get(); | 533 | pipeline = new_pipeline.get(); |
| 552 | } | 534 | } |
| 553 | 535 | ||
| 554 | - for (auto f_iter = filters.rbegin(); f_iter != filters.rend(); | ||
| 555 | - ++f_iter) { | 536 | + for (auto f_iter = filters.rbegin(); f_iter != filters.rend(); ++f_iter) { |
| 556 | auto decode_pipeline = (*f_iter)->getDecodePipeline(pipeline); | 537 | auto decode_pipeline = (*f_iter)->getDecodePipeline(pipeline); |
| 557 | if (decode_pipeline) { | 538 | if (decode_pipeline) { |
| 558 | pipeline = decode_pipeline; | 539 | pipeline = decode_pipeline; |
| 559 | } | 540 | } |
| 560 | auto* flate = dynamic_cast<Pl_Flate*>(pipeline); | 541 | auto* flate = dynamic_cast<Pl_Flate*>(pipeline); |
| 561 | if (flate != nullptr) { | 542 | if (flate != nullptr) { |
| 562 | - flate->setWarnCallback( | ||
| 563 | - [this](char const* msg, int code) { warn(msg); }); | 543 | + flate->setWarnCallback([this](char const* msg, int code) { warn(msg); }); |
| 564 | } | 544 | } |
| 565 | } | 545 | } |
| 566 | } | 546 | } |
| 567 | 547 | ||
| 568 | if (this->stream_data.get()) { | 548 | if (this->stream_data.get()) { |
| 569 | QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data"); | 549 | QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data"); |
| 570 | - pipeline->write( | ||
| 571 | - this->stream_data->getBuffer(), this->stream_data->getSize()); | 550 | + pipeline->write(this->stream_data->getBuffer(), this->stream_data->getSize()); |
| 572 | pipeline->finish(); | 551 | pipeline->finish(); |
| 573 | } else if (this->stream_provider.get()) { | 552 | } else if (this->stream_provider.get()) { |
| 574 | Pl_Count count("stream provider count", pipeline); | 553 | Pl_Count count("stream provider count", pipeline); |
| @@ -592,15 +571,13 @@ QPDF_Stream::pipeStreamData( | @@ -592,15 +571,13 @@ QPDF_Stream::pipeStreamData( | ||
| 592 | // This would be caused by programmer error on the | 571 | // This would be caused by programmer error on the |
| 593 | // part of a library user, not by invalid input data. | 572 | // part of a library user, not by invalid input data. |
| 594 | throw std::runtime_error( | 573 | throw std::runtime_error( |
| 595 | - "stream data provider for " + og.unparse(' ') + | ||
| 596 | - " provided " + std::to_string(actual_length) + | ||
| 597 | - " bytes instead of expected " + | 574 | + "stream data provider for " + og.unparse(' ') + " provided " + |
| 575 | + std::to_string(actual_length) + " bytes instead of expected " + | ||
| 598 | std::to_string(desired_length) + " bytes"); | 576 | std::to_string(desired_length) + " bytes"); |
| 599 | } | 577 | } |
| 600 | } else if (success) { | 578 | } else if (success) { |
| 601 | QTC::TC("qpdf", "QPDF_Stream provider length not provided"); | 579 | QTC::TC("qpdf", "QPDF_Stream provider length not provided"); |
| 602 | - this->stream_dict.replaceKey( | ||
| 603 | - "/Length", QPDFObjectHandle::newInteger(actual_length)); | 580 | + this->stream_dict.replaceKey("/Length", QPDFObjectHandle::newInteger(actual_length)); |
| 604 | } | 581 | } |
| 605 | } else if (this->parsed_offset == 0) { | 582 | } else if (this->parsed_offset == 0) { |
| 606 | QTC::TC("qpdf", "QPDF_Stream pipe no stream data"); | 583 | QTC::TC("qpdf", "QPDF_Stream pipe no stream data"); |
| @@ -621,8 +598,7 @@ QPDF_Stream::pipeStreamData( | @@ -621,8 +598,7 @@ QPDF_Stream::pipeStreamData( | ||
| 621 | } | 598 | } |
| 622 | } | 599 | } |
| 623 | 600 | ||
| 624 | - if (filter && (!suppress_warnings) && normalizer.get() && | ||
| 625 | - normalizer->anyBadTokens()) { | 601 | + if (filter && (!suppress_warnings) && normalizer.get() && normalizer->anyBadTokens()) { |
| 626 | warn("content normalization encountered bad tokens"); | 602 | warn("content normalization encountered bad tokens"); |
| 627 | if (normalizer->lastTokenWasBad()) { | 603 | if (normalizer->lastTokenWasBad()) { |
| 628 | QTC::TC("qpdf", "QPDF_Stream bad token at end during normalize"); | 604 | QTC::TC("qpdf", "QPDF_Stream bad token at end during normalize"); |
| @@ -662,17 +638,14 @@ QPDF_Stream::replaceStreamData( | @@ -662,17 +638,14 @@ QPDF_Stream::replaceStreamData( | ||
| 662 | } | 638 | } |
| 663 | 639 | ||
| 664 | void | 640 | void |
| 665 | -QPDF_Stream::addTokenFilter( | ||
| 666 | - std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter) | 641 | +QPDF_Stream::addTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter) |
| 667 | { | 642 | { |
| 668 | this->token_filters.push_back(token_filter); | 643 | this->token_filters.push_back(token_filter); |
| 669 | } | 644 | } |
| 670 | 645 | ||
| 671 | void | 646 | void |
| 672 | QPDF_Stream::replaceFilterData( | 647 | QPDF_Stream::replaceFilterData( |
| 673 | - QPDFObjectHandle const& filter, | ||
| 674 | - QPDFObjectHandle const& decode_parms, | ||
| 675 | - size_t length) | 648 | + QPDFObjectHandle const& filter, QPDFObjectHandle const& decode_parms, size_t length) |
| 676 | { | 649 | { |
| 677 | if (filter.isInitialized()) { | 650 | if (filter.isInitialized()) { |
| 678 | this->stream_dict.replaceKey("/Filter", filter); | 651 | this->stream_dict.replaceKey("/Filter", filter); |
| @@ -685,8 +658,7 @@ QPDF_Stream::replaceFilterData( | @@ -685,8 +658,7 @@ QPDF_Stream::replaceFilterData( | ||
| 685 | this->stream_dict.removeKey("/Length"); | 658 | this->stream_dict.removeKey("/Length"); |
| 686 | } else { | 659 | } else { |
| 687 | this->stream_dict.replaceKey( | 660 | this->stream_dict.replaceKey( |
| 688 | - "/Length", | ||
| 689 | - QPDFObjectHandle::newInteger(QIntC::to_longlong(length))); | 661 | + "/Length", QPDFObjectHandle::newInteger(QIntC::to_longlong(length))); |
| 690 | } | 662 | } |
| 691 | } | 663 | } |
| 692 | 664 |
libqpdf/QPDF_String.cc
| @@ -9,8 +9,7 @@ | @@ -9,8 +9,7 @@ | ||
| 9 | static bool | 9 | static bool |
| 10 | is_iso_latin1_printable(char ch) | 10 | is_iso_latin1_printable(char ch) |
| 11 | { | 11 | { |
| 12 | - return ( | ||
| 13 | - ((ch >= 32) && (ch <= 126)) || (static_cast<unsigned char>(ch) >= 160)); | 12 | + return (((ch >= 32) && (ch <= 126)) || (static_cast<unsigned char>(ch) >= 160)); |
| 14 | } | 13 | } |
| 15 | 14 | ||
| 16 | QPDF_String::QPDF_String(std::string const& val) : | 15 | QPDF_String::QPDF_String(std::string const& val) : |
| @@ -62,8 +61,7 @@ QPDF_String::getJSON(int json_version) | @@ -62,8 +61,7 @@ QPDF_String::getJSON(int json_version) | ||
| 62 | result = candidate; | 61 | result = candidate; |
| 63 | } else if (!useHexString()) { | 62 | } else if (!useHexString()) { |
| 64 | std::string test; | 63 | std::string test; |
| 65 | - if (QUtil::utf8_to_pdf_doc(candidate, test, '?') && | ||
| 66 | - (test == this->val)) { | 64 | + if (QUtil::utf8_to_pdf_doc(candidate, test, '?') && (test == this->val)) { |
| 67 | // This is a PDF-doc string that can be losslessly encoded | 65 | // This is a PDF-doc string that can be losslessly encoded |
| 68 | // as Unicode. | 66 | // as Unicode. |
| 69 | is_unicode = true; | 67 | is_unicode = true; |
| @@ -93,8 +91,7 @@ QPDF_String::useHexString() const | @@ -93,8 +91,7 @@ QPDF_String::useHexString() const | ||
| 93 | continue; | 91 | continue; |
| 94 | } else if (ch < 0 || ch >= 24) { | 92 | } else if (ch < 0 || ch >= 24) { |
| 95 | ++non_ascii; | 93 | ++non_ascii; |
| 96 | - } else if (!(ch == '\n' || ch == '\r' || ch == '\t' || ch == '\b' || | ||
| 97 | - ch == '\f')) { | 94 | + } else if (!(ch == '\n' || ch == '\r' || ch == '\t' || ch == '\b' || ch == '\f')) { |
| 98 | return true; | 95 | return true; |
| 99 | } | 96 | } |
| 100 | } | 97 | } |
| @@ -156,12 +153,9 @@ QPDF_String::unparse(bool force_binary) | @@ -156,12 +153,9 @@ QPDF_String::unparse(bool force_binary) | ||
| 156 | if (is_iso_latin1_printable(ch)) { | 153 | if (is_iso_latin1_printable(ch)) { |
| 157 | result += this->val.at(i); | 154 | result += this->val.at(i); |
| 158 | } else { | 155 | } else { |
| 159 | - result += | ||
| 160 | - "\\" + | 156 | + result += "\\" + |
| 161 | QUtil::int_to_string_base( | 157 | QUtil::int_to_string_base( |
| 162 | - static_cast<int>(static_cast<unsigned char>(ch)), | ||
| 163 | - 8, | ||
| 164 | - 3); | 158 | + static_cast<int>(static_cast<unsigned char>(ch)), 8, 3); |
| 165 | } | 159 | } |
| 166 | break; | 160 | break; |
| 167 | } | 161 | } |
libqpdf/QPDF_Unresolved.cc
| @@ -16,23 +16,20 @@ QPDF_Unresolved::create(QPDF* qpdf, QPDFObjGen const& og) | @@ -16,23 +16,20 @@ QPDF_Unresolved::create(QPDF* qpdf, QPDFObjGen const& og) | ||
| 16 | std::shared_ptr<QPDFObject> | 16 | std::shared_ptr<QPDFObject> |
| 17 | QPDF_Unresolved::copy(bool shallow) | 17 | QPDF_Unresolved::copy(bool shallow) |
| 18 | { | 18 | { |
| 19 | - throw std::logic_error( | ||
| 20 | - "attempted to shallow copy an unresolved QPDFObjectHandle"); | 19 | + throw std::logic_error("attempted to shallow copy an unresolved QPDFObjectHandle"); |
| 21 | return nullptr; | 20 | return nullptr; |
| 22 | } | 21 | } |
| 23 | 22 | ||
| 24 | std::string | 23 | std::string |
| 25 | QPDF_Unresolved::unparse() | 24 | QPDF_Unresolved::unparse() |
| 26 | { | 25 | { |
| 27 | - throw std::logic_error( | ||
| 28 | - "attempted to unparse an unresolved QPDFObjectHandle"); | 26 | + throw std::logic_error("attempted to unparse an unresolved QPDFObjectHandle"); |
| 29 | return ""; | 27 | return ""; |
| 30 | } | 28 | } |
| 31 | 29 | ||
| 32 | JSON | 30 | JSON |
| 33 | QPDF_Unresolved::getJSON(int json_version) | 31 | QPDF_Unresolved::getJSON(int json_version) |
| 34 | { | 32 | { |
| 35 | - throw std::logic_error( | ||
| 36 | - "attempted to get JSON from an unresolved QPDFObjectHandle"); | 33 | + throw std::logic_error("attempted to get JSON from an unresolved QPDFObjectHandle"); |
| 37 | return JSON::makeNull(); | 34 | return JSON::makeNull(); |
| 38 | } | 35 | } |
libqpdf/QPDF_encryption.cc
| @@ -20,9 +20,8 @@ | @@ -20,9 +20,8 @@ | ||
| 20 | #include <cstring> | 20 | #include <cstring> |
| 21 | 21 | ||
| 22 | static unsigned char const padding_string[] = { | 22 | static unsigned char const padding_string[] = { |
| 23 | - 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, | ||
| 24 | - 0x56, 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, | ||
| 25 | - 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a}; | 23 | + 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, |
| 24 | + 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a}; | ||
| 26 | 25 | ||
| 27 | static unsigned int const key_bytes = 32; | 26 | static unsigned int const key_bytes = 32; |
| 28 | 27 | ||
| @@ -129,8 +128,7 @@ QPDF::EncryptionData::setV5EncryptionParameters( | @@ -129,8 +128,7 @@ QPDF::EncryptionData::setV5EncryptionParameters( | ||
| 129 | static void | 128 | static void |
| 130 | pad_or_truncate_password_V4(std::string const& password, char k1[key_bytes]) | 129 | pad_or_truncate_password_V4(std::string const& password, char k1[key_bytes]) |
| 131 | { | 130 | { |
| 132 | - size_t password_bytes = | ||
| 133 | - std::min(QIntC::to_size(key_bytes), password.length()); | 131 | + size_t password_bytes = std::min(QIntC::to_size(key_bytes), password.length()); |
| 134 | size_t pad_bytes = key_bytes - password_bytes; | 132 | size_t pad_bytes = key_bytes - password_bytes; |
| 135 | memcpy(k1, password.c_str(), password_bytes); | 133 | memcpy(k1, password.c_str(), password_bytes); |
| 136 | memcpy(k1 + password_bytes, padding_string, pad_bytes); | 134 | memcpy(k1 + password_bytes, padding_string, pad_bytes); |
| @@ -173,8 +171,7 @@ pad_or_truncate_password_V4(std::string const& password) | @@ -173,8 +171,7 @@ pad_or_truncate_password_V4(std::string const& password) | ||
| 173 | static std::string | 171 | static std::string |
| 174 | truncate_password_V5(std::string const& password) | 172 | truncate_password_V5(std::string const& password) |
| 175 | { | 173 | { |
| 176 | - return password.substr( | ||
| 177 | - 0, std::min(static_cast<size_t>(127), password.length())); | 174 | + return password.substr(0, std::min(static_cast<size_t>(127), password.length())); |
| 178 | } | 175 | } |
| 179 | 176 | ||
| 180 | static void | 177 | static void |
| @@ -184,8 +181,7 @@ iterate_md5_digest(MD5& md5, MD5::Digest& digest, int iterations, int key_len) | @@ -184,8 +181,7 @@ iterate_md5_digest(MD5& md5, MD5::Digest& digest, int iterations, int key_len) | ||
| 184 | 181 | ||
| 185 | for (int i = 0; i < iterations; ++i) { | 182 | for (int i = 0; i < iterations; ++i) { |
| 186 | MD5 m; | 183 | MD5 m; |
| 187 | - m.encodeDataIncrementally( | ||
| 188 | - reinterpret_cast<char*>(digest), QIntC::to_size(key_len)); | 184 | + m.encodeDataIncrementally(reinterpret_cast<char*>(digest), QIntC::to_size(key_len)); |
| 189 | m.digest(digest); | 185 | m.digest(digest); |
| 190 | } | 186 | } |
| 191 | } | 187 | } |
| @@ -223,11 +219,7 @@ process_with_aes( | @@ -223,11 +219,7 @@ process_with_aes( | ||
| 223 | { | 219 | { |
| 224 | Pl_Buffer buffer("buffer"); | 220 | Pl_Buffer buffer("buffer"); |
| 225 | Pl_AES_PDF aes( | 221 | Pl_AES_PDF aes( |
| 226 | - "aes", | ||
| 227 | - &buffer, | ||
| 228 | - encrypt, | ||
| 229 | - QUtil::unsigned_char_pointer(key), | ||
| 230 | - QIntC::to_uint(key.length())); | 222 | + "aes", &buffer, encrypt, QUtil::unsigned_char_pointer(key), QIntC::to_uint(key.length())); |
| 231 | if (iv) { | 223 | if (iv) { |
| 232 | aes.setIV(iv, iv_length); | 224 | aes.setIV(iv, iv_length); |
| 233 | } else { | 225 | } else { |
| @@ -371,13 +363,11 @@ QPDF::compute_data_key( | @@ -371,13 +363,11 @@ QPDF::compute_data_key( | ||
| 371 | md5.encodeDataIncrementally(result.c_str(), result.length()); | 363 | md5.encodeDataIncrementally(result.c_str(), result.length()); |
| 372 | MD5::Digest digest; | 364 | MD5::Digest digest; |
| 373 | md5.digest(digest); | 365 | md5.digest(digest); |
| 374 | - return std::string( | ||
| 375 | - reinterpret_cast<char*>(digest), std::min(result.length(), toS(16))); | 366 | + return std::string(reinterpret_cast<char*>(digest), std::min(result.length(), toS(16))); |
| 376 | } | 367 | } |
| 377 | 368 | ||
| 378 | std::string | 369 | std::string |
| 379 | -QPDF::compute_encryption_key( | ||
| 380 | - std::string const& password, EncryptionData const& data) | 370 | +QPDF::compute_encryption_key(std::string const& password, EncryptionData const& data) |
| 381 | { | 371 | { |
| 382 | if (data.getV() >= 5) { | 372 | if (data.getV() >= 5) { |
| 383 | // For V >= 5, the encryption key is generated and stored in | 373 | // For V >= 5, the encryption key is generated and stored in |
| @@ -392,8 +382,7 @@ QPDF::compute_encryption_key( | @@ -392,8 +382,7 @@ QPDF::compute_encryption_key( | ||
| 392 | } | 382 | } |
| 393 | 383 | ||
| 394 | std::string | 384 | std::string |
| 395 | -QPDF::compute_encryption_key_from_password( | ||
| 396 | - std::string const& password, EncryptionData const& data) | 385 | +QPDF::compute_encryption_key_from_password(std::string const& password, EncryptionData const& data) |
| 397 | { | 386 | { |
| 398 | // Algorithm 3.2 from the PDF 1.7 Reference Manual | 387 | // Algorithm 3.2 from the PDF 1.7 Reference Manual |
| 399 | 388 | ||
| @@ -405,8 +394,7 @@ QPDF::compute_encryption_key_from_password( | @@ -405,8 +394,7 @@ QPDF::compute_encryption_key_from_password( | ||
| 405 | // presented in its final form. | 394 | // presented in its final form. |
| 406 | 395 | ||
| 407 | MD5 md5; | 396 | MD5 md5; |
| 408 | - md5.encodeDataIncrementally( | ||
| 409 | - pad_or_truncate_password_V4(password).c_str(), key_bytes); | 397 | + md5.encodeDataIncrementally(pad_or_truncate_password_V4(password).c_str(), key_bytes); |
| 410 | md5.encodeDataIncrementally(data.getO().c_str(), key_bytes); | 398 | md5.encodeDataIncrementally(data.getO().c_str(), key_bytes); |
| 411 | char pbytes[4]; | 399 | char pbytes[4]; |
| 412 | int P = data.getP(); | 400 | int P = data.getP(); |
| @@ -442,11 +430,9 @@ compute_O_rc4_key( | @@ -442,11 +430,9 @@ compute_O_rc4_key( | ||
| 442 | password = user_password; | 430 | password = user_password; |
| 443 | } | 431 | } |
| 444 | MD5 md5; | 432 | MD5 md5; |
| 445 | - md5.encodeDataIncrementally( | ||
| 446 | - pad_or_truncate_password_V4(password).c_str(), key_bytes); | 433 | + md5.encodeDataIncrementally(pad_or_truncate_password_V4(password).c_str(), key_bytes); |
| 447 | MD5::Digest digest; | 434 | MD5::Digest digest; |
| 448 | - int key_len = | ||
| 449 | - std::min(QIntC::to_int(sizeof(digest)), data.getLengthBytes()); | 435 | + int key_len = std::min(QIntC::to_int(sizeof(digest)), data.getLengthBytes()); |
| 450 | iterate_md5_digest(md5, digest, ((data.getR() >= 3) ? 50 : 0), key_len); | 436 | iterate_md5_digest(md5, digest, ((data.getR() >= 3) ? 50 : 0), key_len); |
| 451 | memcpy(key, digest, OU_key_bytes_V4); | 437 | memcpy(key, digest, OU_key_bytes_V4); |
| 452 | } | 438 | } |
| @@ -477,8 +463,7 @@ compute_O_value( | @@ -477,8 +463,7 @@ compute_O_value( | ||
| 477 | } | 463 | } |
| 478 | 464 | ||
| 479 | static std::string | 465 | static std::string |
| 480 | -compute_U_value_R2( | ||
| 481 | - std::string const& user_password, QPDF::EncryptionData const& data) | 466 | +compute_U_value_R2(std::string const& user_password, QPDF::EncryptionData const& data) |
| 482 | { | 467 | { |
| 483 | // Algorithm 3.4 from the PDF 1.7 Reference Manual | 468 | // Algorithm 3.4 from the PDF 1.7 Reference Manual |
| 484 | 469 | ||
| @@ -497,15 +482,13 @@ compute_U_value_R2( | @@ -497,15 +482,13 @@ compute_U_value_R2( | ||
| 497 | } | 482 | } |
| 498 | 483 | ||
| 499 | static std::string | 484 | static std::string |
| 500 | -compute_U_value_R3( | ||
| 501 | - std::string const& user_password, QPDF::EncryptionData const& data) | 485 | +compute_U_value_R3(std::string const& user_password, QPDF::EncryptionData const& data) |
| 502 | { | 486 | { |
| 503 | // Algorithm 3.5 from the PDF 1.7 Reference Manual | 487 | // Algorithm 3.5 from the PDF 1.7 Reference Manual |
| 504 | 488 | ||
| 505 | std::string k1 = QPDF::compute_encryption_key(user_password, data); | 489 | std::string k1 = QPDF::compute_encryption_key(user_password, data); |
| 506 | MD5 md5; | 490 | MD5 md5; |
| 507 | - md5.encodeDataIncrementally( | ||
| 508 | - pad_or_truncate_password_V4("").c_str(), key_bytes); | 491 | + md5.encodeDataIncrementally(pad_or_truncate_password_V4("").c_str(), key_bytes); |
| 509 | md5.encodeDataIncrementally(data.getId1().c_str(), data.getId1().length()); | 492 | md5.encodeDataIncrementally(data.getId1().c_str(), data.getId1().length()); |
| 510 | MD5::Digest digest; | 493 | MD5::Digest digest; |
| 511 | md5.digest(digest); | 494 | md5.digest(digest); |
| @@ -528,8 +511,7 @@ compute_U_value_R3( | @@ -528,8 +511,7 @@ compute_U_value_R3( | ||
| 528 | } | 511 | } |
| 529 | 512 | ||
| 530 | static std::string | 513 | static std::string |
| 531 | -compute_U_value( | ||
| 532 | - std::string const& user_password, QPDF::EncryptionData const& data) | 514 | +compute_U_value(std::string const& user_password, QPDF::EncryptionData const& data) |
| 533 | { | 515 | { |
| 534 | if (data.getR() >= 3) { | 516 | if (data.getR() >= 3) { |
| 535 | return compute_U_value_R3(user_password, data); | 517 | return compute_U_value_R3(user_password, data); |
| @@ -539,8 +521,7 @@ compute_U_value( | @@ -539,8 +521,7 @@ compute_U_value( | ||
| 539 | } | 521 | } |
| 540 | 522 | ||
| 541 | static bool | 523 | static bool |
| 542 | -check_user_password_V4( | ||
| 543 | - std::string const& user_password, QPDF::EncryptionData const& data) | 524 | +check_user_password_V4(std::string const& user_password, QPDF::EncryptionData const& data) |
| 544 | { | 525 | { |
| 545 | // Algorithm 3.6 from the PDF 1.7 Reference Manual | 526 | // Algorithm 3.6 from the PDF 1.7 Reference Manual |
| 546 | 527 | ||
| @@ -550,8 +531,7 @@ check_user_password_V4( | @@ -550,8 +531,7 @@ check_user_password_V4( | ||
| 550 | } | 531 | } |
| 551 | 532 | ||
| 552 | static bool | 533 | static bool |
| 553 | -check_user_password_V5( | ||
| 554 | - std::string const& user_password, QPDF::EncryptionData const& data) | 534 | +check_user_password_V5(std::string const& user_password, QPDF::EncryptionData const& data) |
| 555 | { | 535 | { |
| 556 | // Algorithm 3.11 from the PDF 1.7 extension level 3 | 536 | // Algorithm 3.11 from the PDF 1.7 extension level 3 |
| 557 | 537 | ||
| @@ -562,8 +542,7 @@ check_user_password_V5( | @@ -562,8 +542,7 @@ check_user_password_V5( | ||
| 562 | } | 542 | } |
| 563 | 543 | ||
| 564 | static bool | 544 | static bool |
| 565 | -check_user_password( | ||
| 566 | - std::string const& user_password, QPDF::EncryptionData const& data) | 545 | +check_user_password(std::string const& user_password, QPDF::EncryptionData const& data) |
| 567 | { | 546 | { |
| 568 | if (data.getV() < 5) { | 547 | if (data.getV() < 5) { |
| 569 | return check_user_password_V4(user_password, data); | 548 | return check_user_password_V4(user_password, data); |
| @@ -574,9 +553,7 @@ check_user_password( | @@ -574,9 +553,7 @@ check_user_password( | ||
| 574 | 553 | ||
| 575 | static bool | 554 | static bool |
| 576 | check_owner_password_V4( | 555 | check_owner_password_V4( |
| 577 | - std::string& user_password, | ||
| 578 | - std::string const& owner_password, | ||
| 579 | - QPDF::EncryptionData const& data) | 556 | + std::string& user_password, std::string const& owner_password, QPDF::EncryptionData const& data) |
| 580 | { | 557 | { |
| 581 | // Algorithm 3.7 from the PDF 1.7 Reference Manual | 558 | // Algorithm 3.7 from the PDF 1.7 Reference Manual |
| 582 | 559 | ||
| @@ -593,8 +570,7 @@ check_owner_password_V4( | @@ -593,8 +570,7 @@ check_owner_password_V4( | ||
| 593 | data.getLengthBytes(), | 570 | data.getLengthBytes(), |
| 594 | (data.getR() >= 3) ? 20 : 1, | 571 | (data.getR() >= 3) ? 20 : 1, |
| 595 | true); | 572 | true); |
| 596 | - std::string new_user_password = | ||
| 597 | - std::string(reinterpret_cast<char*>(O_data), key_bytes); | 573 | + std::string new_user_password = std::string(reinterpret_cast<char*>(O_data), key_bytes); |
| 598 | bool result = false; | 574 | bool result = false; |
| 599 | if (check_user_password(new_user_password, data)) { | 575 | if (check_user_password(new_user_password, data)) { |
| 600 | result = true; | 576 | result = true; |
| @@ -604,8 +580,7 @@ check_owner_password_V4( | @@ -604,8 +580,7 @@ check_owner_password_V4( | ||
| 604 | } | 580 | } |
| 605 | 581 | ||
| 606 | static bool | 582 | static bool |
| 607 | -check_owner_password_V5( | ||
| 608 | - std::string const& owner_password, QPDF::EncryptionData const& data) | 583 | +check_owner_password_V5(std::string const& owner_password, QPDF::EncryptionData const& data) |
| 609 | { | 584 | { |
| 610 | // Algorithm 3.12 from the PDF 1.7 extension level 3 | 585 | // Algorithm 3.12 from the PDF 1.7 extension level 3 |
| 611 | 586 | ||
| @@ -618,9 +593,7 @@ check_owner_password_V5( | @@ -618,9 +593,7 @@ check_owner_password_V5( | ||
| 618 | 593 | ||
| 619 | static bool | 594 | static bool |
| 620 | check_owner_password( | 595 | check_owner_password( |
| 621 | - std::string& user_password, | ||
| 622 | - std::string const& owner_password, | ||
| 623 | - QPDF::EncryptionData const& data) | 596 | + std::string& user_password, std::string const& owner_password, QPDF::EncryptionData const& data) |
| 624 | { | 597 | { |
| 625 | if (data.getV() < 5) { | 598 | if (data.getV() < 5) { |
| 626 | return check_owner_password_V4(user_password, owner_password, data); | 599 | return check_owner_password_V4(user_password, owner_password, data); |
| @@ -630,8 +603,7 @@ check_owner_password( | @@ -630,8 +603,7 @@ check_owner_password( | ||
| 630 | } | 603 | } |
| 631 | 604 | ||
| 632 | std::string | 605 | std::string |
| 633 | -QPDF::recover_encryption_key_with_password( | ||
| 634 | - std::string const& password, EncryptionData const& data) | 606 | +QPDF::recover_encryption_key_with_password(std::string const& password, EncryptionData const& data) |
| 635 | { | 607 | { |
| 636 | // Disregard whether Perms is valid. | 608 | // Disregard whether Perms is valid. |
| 637 | bool disregard; | 609 | bool disregard; |
| @@ -648,12 +620,10 @@ compute_U_UE_value_V5( | @@ -648,12 +620,10 @@ compute_U_UE_value_V5( | ||
| 648 | { | 620 | { |
| 649 | // Algorithm 3.8 from the PDF 1.7 extension level 3 | 621 | // Algorithm 3.8 from the PDF 1.7 extension level 3 |
| 650 | char k[16]; | 622 | char k[16]; |
| 651 | - QUtil::initializeWithRandomBytes( | ||
| 652 | - reinterpret_cast<unsigned char*>(k), sizeof(k)); | 623 | + QUtil::initializeWithRandomBytes(reinterpret_cast<unsigned char*>(k), sizeof(k)); |
| 653 | std::string validation_salt(k, 8); | 624 | std::string validation_salt(k, 8); |
| 654 | std::string key_salt(k + 8, 8); | 625 | std::string key_salt(k + 8, 8); |
| 655 | - U = hash_V5(user_password, validation_salt, "", data) + validation_salt + | ||
| 656 | - key_salt; | 626 | + U = hash_V5(user_password, validation_salt, "", data) + validation_salt + key_salt; |
| 657 | std::string intermediate_key = hash_V5(user_password, key_salt, "", data); | 627 | std::string intermediate_key = hash_V5(user_password, key_salt, "", data); |
| 658 | UE = process_with_aes(intermediate_key, true, encryption_key); | 628 | UE = process_with_aes(intermediate_key, true, encryption_key); |
| 659 | } | 629 | } |
| @@ -669,21 +639,17 @@ compute_O_OE_value_V5( | @@ -669,21 +639,17 @@ compute_O_OE_value_V5( | ||
| 669 | { | 639 | { |
| 670 | // Algorithm 3.9 from the PDF 1.7 extension level 3 | 640 | // Algorithm 3.9 from the PDF 1.7 extension level 3 |
| 671 | char k[16]; | 641 | char k[16]; |
| 672 | - QUtil::initializeWithRandomBytes( | ||
| 673 | - reinterpret_cast<unsigned char*>(k), sizeof(k)); | 642 | + QUtil::initializeWithRandomBytes(reinterpret_cast<unsigned char*>(k), sizeof(k)); |
| 674 | std::string validation_salt(k, 8); | 643 | std::string validation_salt(k, 8); |
| 675 | std::string key_salt(k + 8, 8); | 644 | std::string key_salt(k + 8, 8); |
| 676 | - O = hash_V5(owner_password, validation_salt, U, data) + validation_salt + | ||
| 677 | - key_salt; | 645 | + O = hash_V5(owner_password, validation_salt, U, data) + validation_salt + key_salt; |
| 678 | std::string intermediate_key = hash_V5(owner_password, key_salt, U, data); | 646 | std::string intermediate_key = hash_V5(owner_password, key_salt, U, data); |
| 679 | OE = process_with_aes(intermediate_key, true, encryption_key); | 647 | OE = process_with_aes(intermediate_key, true, encryption_key); |
| 680 | } | 648 | } |
| 681 | 649 | ||
| 682 | void | 650 | void |
| 683 | compute_Perms_value_V5_clear( | 651 | compute_Perms_value_V5_clear( |
| 684 | - std::string const& encryption_key, | ||
| 685 | - QPDF::EncryptionData const& data, | ||
| 686 | - unsigned char k[16]) | 652 | + std::string const& encryption_key, QPDF::EncryptionData const& data, unsigned char k[16]) |
| 687 | { | 653 | { |
| 688 | // From algorithm 3.10 from the PDF 1.7 extension level 3 | 654 | // From algorithm 3.10 from the PDF 1.7 extension level 3 |
| 689 | unsigned long long extended_perms = | 655 | unsigned long long extended_perms = |
| @@ -700,16 +666,13 @@ compute_Perms_value_V5_clear( | @@ -700,16 +666,13 @@ compute_Perms_value_V5_clear( | ||
| 700 | } | 666 | } |
| 701 | 667 | ||
| 702 | static std::string | 668 | static std::string |
| 703 | -compute_Perms_value_V5( | ||
| 704 | - std::string const& encryption_key, QPDF::EncryptionData const& data) | 669 | +compute_Perms_value_V5(std::string const& encryption_key, QPDF::EncryptionData const& data) |
| 705 | { | 670 | { |
| 706 | // Algorithm 3.10 from the PDF 1.7 extension level 3 | 671 | // Algorithm 3.10 from the PDF 1.7 extension level 3 |
| 707 | unsigned char k[16]; | 672 | unsigned char k[16]; |
| 708 | compute_Perms_value_V5_clear(encryption_key, data, k); | 673 | compute_Perms_value_V5_clear(encryption_key, data, k); |
| 709 | return process_with_aes( | 674 | return process_with_aes( |
| 710 | - encryption_key, | ||
| 711 | - true, | ||
| 712 | - std::string(reinterpret_cast<char*>(k), sizeof(k))); | 675 | + encryption_key, true, std::string(reinterpret_cast<char*>(k), sizeof(k))); |
| 713 | } | 676 | } |
| 714 | 677 | ||
| 715 | std::string | 678 | std::string |
| @@ -737,14 +700,11 @@ QPDF::recover_encryption_key_with_password( | @@ -737,14 +700,11 @@ QPDF::recover_encryption_key_with_password( | ||
| 737 | key_salt = data.getU().substr(40, 8); | 700 | key_salt = data.getU().substr(40, 8); |
| 738 | encrypted_file_key = data.getUE().substr(0, 32); | 701 | encrypted_file_key = data.getUE().substr(0, 32); |
| 739 | } | 702 | } |
| 740 | - std::string intermediate_key = | ||
| 741 | - hash_V5(key_password, key_salt, user_data, data); | ||
| 742 | - std::string file_key = | ||
| 743 | - process_with_aes(intermediate_key, false, encrypted_file_key); | 703 | + std::string intermediate_key = hash_V5(key_password, key_salt, user_data, data); |
| 704 | + std::string file_key = process_with_aes(intermediate_key, false, encrypted_file_key); | ||
| 744 | 705 | ||
| 745 | // Decrypt Perms and check against expected value | 706 | // Decrypt Perms and check against expected value |
| 746 | - std::string perms_check = | ||
| 747 | - process_with_aes(file_key, false, data.getPerms(), 12); | 707 | + std::string perms_check = process_with_aes(file_key, false, data.getPerms(), 12); |
| 748 | unsigned char k[16]; | 708 | unsigned char k[16]; |
| 749 | compute_Perms_value_V5_clear(file_key, data, k); | 709 | compute_Perms_value_V5_clear(file_key, data, k); |
| 750 | perms_valid = (memcmp(perms_check.c_str(), k, 12) == 0); | 710 | perms_valid = (memcmp(perms_check.c_str(), k, 12) == 0); |
| @@ -753,8 +713,7 @@ QPDF::recover_encryption_key_with_password( | @@ -753,8 +713,7 @@ QPDF::recover_encryption_key_with_password( | ||
| 753 | } | 713 | } |
| 754 | 714 | ||
| 755 | QPDF::encryption_method_e | 715 | QPDF::encryption_method_e |
| 756 | -QPDF::interpretCF( | ||
| 757 | - std::shared_ptr<EncryptionParameters> encp, QPDFObjectHandle cf) | 716 | +QPDF::interpretCF(std::shared_ptr<EncryptionParameters> encp, QPDFObjectHandle cf) |
| 758 | { | 717 | { |
| 759 | if (cf.isName()) { | 718 | if (cf.isName()) { |
| 760 | std::string filter = cf.getName(); | 719 | std::string filter = cf.getName(); |
| @@ -795,8 +754,7 @@ QPDF::initializeEncryption() | @@ -795,8 +754,7 @@ QPDF::initializeEncryption() | ||
| 795 | 754 | ||
| 796 | std::string id1; | 755 | std::string id1; |
| 797 | QPDFObjectHandle id_obj = m->trailer.getKey("/ID"); | 756 | QPDFObjectHandle id_obj = m->trailer.getKey("/ID"); |
| 798 | - if ((id_obj.isArray() && (id_obj.getArrayNItems() == 2) && | ||
| 799 | - id_obj.getArrayItem(0).isString())) { | 757 | + if ((id_obj.isArray() && (id_obj.getArrayNItems() == 2) && id_obj.getArrayItem(0).isString())) { |
| 800 | id1 = id_obj.getArrayItem(0).getStringValue(); | 758 | id1 = id_obj.getArrayItem(0).getStringValue(); |
| 801 | } else { | 759 | } else { |
| 802 | // Treating a missing ID as the empty string enables qpdf to | 760 | // Treating a missing ID as the empty string enables qpdf to |
| @@ -827,10 +785,8 @@ QPDF::initializeEncryption() | @@ -827,10 +785,8 @@ QPDF::initializeEncryption() | ||
| 827 | "file uses encryption SubFilters, which qpdf does not support"); | 785 | "file uses encryption SubFilters, which qpdf does not support"); |
| 828 | } | 786 | } |
| 829 | 787 | ||
| 830 | - if (!(encryption_dict.getKey("/V").isInteger() && | ||
| 831 | - encryption_dict.getKey("/R").isInteger() && | ||
| 832 | - encryption_dict.getKey("/O").isString() && | ||
| 833 | - encryption_dict.getKey("/U").isString() && | 788 | + if (!(encryption_dict.getKey("/V").isInteger() && encryption_dict.getKey("/R").isInteger() && |
| 789 | + encryption_dict.getKey("/O").isString() && encryption_dict.getKey("/U").isString() && | ||
| 834 | encryption_dict.getKey("/P").isInteger())) { | 790 | encryption_dict.getKey("/P").isInteger())) { |
| 835 | throw damagedPDF( | 791 | throw damagedPDF( |
| 836 | "encryption dictionary", | 792 | "encryption dictionary", |
| @@ -846,16 +802,14 @@ QPDF::initializeEncryption() | @@ -846,16 +802,14 @@ QPDF::initializeEncryption() | ||
| 846 | 802 | ||
| 847 | // If supporting new encryption R/V values, remember to update | 803 | // If supporting new encryption R/V values, remember to update |
| 848 | // error message inside this if statement. | 804 | // error message inside this if statement. |
| 849 | - if (!(((R >= 2) && (R <= 6)) && | ||
| 850 | - ((V == 1) || (V == 2) || (V == 4) || (V == 5)))) { | 805 | + if (!(((R >= 2) && (R <= 6)) && ((V == 1) || (V == 2) || (V == 4) || (V == 5)))) { |
| 851 | throw QPDFExc( | 806 | throw QPDFExc( |
| 852 | qpdf_e_unsupported, | 807 | qpdf_e_unsupported, |
| 853 | m->file->getName(), | 808 | m->file->getName(), |
| 854 | "encryption dictionary", | 809 | "encryption dictionary", |
| 855 | m->file->getLastOffset(), | 810 | m->file->getLastOffset(), |
| 856 | - "Unsupported /R or /V in encryption dictionary; R = " + | ||
| 857 | - std::to_string(R) + " (max 6), V = " + std::to_string(V) + | ||
| 858 | - " (max 5)"); | 811 | + "Unsupported /R or /V in encryption dictionary; R = " + std::to_string(R) + |
| 812 | + " (max 6), V = " + std::to_string(V) + " (max 5)"); | ||
| 859 | } | 813 | } |
| 860 | 814 | ||
| 861 | m->encp->encryption_V = V; | 815 | m->encp->encryption_V = V; |
| @@ -918,8 +872,7 @@ QPDF::initializeEncryption() | @@ -918,8 +872,7 @@ QPDF::initializeEncryption() | ||
| 918 | 872 | ||
| 919 | m->encp->encrypt_metadata = true; | 873 | m->encp->encrypt_metadata = true; |
| 920 | if ((V >= 4) && (encryption_dict.getKey("/EncryptMetadata").isBool())) { | 874 | if ((V >= 4) && (encryption_dict.getKey("/EncryptMetadata").isBool())) { |
| 921 | - m->encp->encrypt_metadata = | ||
| 922 | - encryption_dict.getKey("/EncryptMetadata").getBoolValue(); | 875 | + m->encp->encrypt_metadata = encryption_dict.getKey("/EncryptMetadata").getBoolValue(); |
| 923 | } | 876 | } |
| 924 | 877 | ||
| 925 | if ((V == 4) || (V == 5)) { | 878 | if ((V == 4) || (V == 5)) { |
| @@ -975,23 +928,12 @@ QPDF::initializeEncryption() | @@ -975,23 +928,12 @@ QPDF::initializeEncryption() | ||
| 975 | } | 928 | } |
| 976 | } | 929 | } |
| 977 | 930 | ||
| 978 | - EncryptionData data( | ||
| 979 | - V, | ||
| 980 | - R, | ||
| 981 | - Length / 8, | ||
| 982 | - P, | ||
| 983 | - O, | ||
| 984 | - U, | ||
| 985 | - OE, | ||
| 986 | - UE, | ||
| 987 | - Perms, | ||
| 988 | - id1, | ||
| 989 | - m->encp->encrypt_metadata); | 931 | + EncryptionData data(V, R, Length / 8, P, O, U, OE, UE, Perms, id1, m->encp->encrypt_metadata); |
| 990 | if (m->provided_password_is_hex_key) { | 932 | if (m->provided_password_is_hex_key) { |
| 991 | // ignore passwords in file | 933 | // ignore passwords in file |
| 992 | } else { | 934 | } else { |
| 993 | - m->encp->owner_password_matched = check_owner_password( | ||
| 994 | - m->encp->user_password, m->encp->provided_password, data); | 935 | + m->encp->owner_password_matched = |
| 936 | + check_owner_password(m->encp->user_password, m->encp->provided_password, data); | ||
| 995 | if (m->encp->owner_password_matched && (V < 5)) { | 937 | if (m->encp->owner_password_matched && (V < 5)) { |
| 996 | // password supplied was owner password; user_password has | 938 | // password supplied was owner password; user_password has |
| 997 | // been initialized for V < 5 | 939 | // been initialized for V < 5 |
| @@ -1000,8 +942,7 @@ QPDF::initializeEncryption() | @@ -1000,8 +942,7 @@ QPDF::initializeEncryption() | ||
| 1000 | QTC::TC("qpdf", "QPDF_encryption user matches owner V < 5"); | 942 | QTC::TC("qpdf", "QPDF_encryption user matches owner V < 5"); |
| 1001 | } | 943 | } |
| 1002 | } else { | 944 | } else { |
| 1003 | - m->encp->user_password_matched = | ||
| 1004 | - check_user_password(m->encp->provided_password, data); | 945 | + m->encp->user_password_matched = check_user_password(m->encp->provided_password, data); |
| 1005 | if (m->encp->user_password_matched) { | 946 | if (m->encp->user_password_matched) { |
| 1006 | m->encp->user_password = m->encp->provided_password; | 947 | m->encp->user_password = m->encp->provided_password; |
| 1007 | } | 948 | } |
| @@ -1009,10 +950,8 @@ QPDF::initializeEncryption() | @@ -1009,10 +950,8 @@ QPDF::initializeEncryption() | ||
| 1009 | if (m->encp->user_password_matched && m->encp->owner_password_matched) { | 950 | if (m->encp->user_password_matched && m->encp->owner_password_matched) { |
| 1010 | QTC::TC("qpdf", "QPDF_encryption same password", (V < 5) ? 0 : 1); | 951 | QTC::TC("qpdf", "QPDF_encryption same password", (V < 5) ? 0 : 1); |
| 1011 | } | 952 | } |
| 1012 | - if (!(m->encp->owner_password_matched || | ||
| 1013 | - m->encp->user_password_matched)) { | ||
| 1014 | - throw QPDFExc( | ||
| 1015 | - qpdf_e_password, m->file->getName(), "", 0, "invalid password"); | 953 | + if (!(m->encp->owner_password_matched || m->encp->user_password_matched)) { |
| 954 | + throw QPDFExc(qpdf_e_password, m->file->getName(), "", 0, "invalid password"); | ||
| 1016 | } | 955 | } |
| 1017 | } | 956 | } |
| 1018 | 957 | ||
| @@ -1022,15 +961,14 @@ QPDF::initializeEncryption() | @@ -1022,15 +961,14 @@ QPDF::initializeEncryption() | ||
| 1022 | // For V < 5, the user password is encrypted with the owner | 961 | // For V < 5, the user password is encrypted with the owner |
| 1023 | // password, and the user password is always used for | 962 | // password, and the user password is always used for |
| 1024 | // computing the encryption key. | 963 | // computing the encryption key. |
| 1025 | - m->encp->encryption_key = | ||
| 1026 | - compute_encryption_key(m->encp->user_password, data); | 964 | + m->encp->encryption_key = compute_encryption_key(m->encp->user_password, data); |
| 1027 | } else { | 965 | } else { |
| 1028 | // For V >= 5, either password can be used independently to | 966 | // For V >= 5, either password can be used independently to |
| 1029 | // compute the encryption key, and neither password can be | 967 | // compute the encryption key, and neither password can be |
| 1030 | // used to recover the other. | 968 | // used to recover the other. |
| 1031 | bool perms_valid; | 969 | bool perms_valid; |
| 1032 | - m->encp->encryption_key = recover_encryption_key_with_password( | ||
| 1033 | - m->encp->provided_password, data, perms_valid); | 970 | + m->encp->encryption_key = |
| 971 | + recover_encryption_key_with_password(m->encp->provided_password, data, perms_valid); | ||
| 1034 | if (!perms_valid) { | 972 | if (!perms_valid) { |
| 1035 | warn(damagedPDF( | 973 | warn(damagedPDF( |
| 1036 | "encryption dictionary", | 974 | "encryption dictionary", |
| @@ -1042,13 +980,10 @@ QPDF::initializeEncryption() | @@ -1042,13 +980,10 @@ QPDF::initializeEncryption() | ||
| 1042 | 980 | ||
| 1043 | std::string | 981 | std::string |
| 1044 | QPDF::getKeyForObject( | 982 | QPDF::getKeyForObject( |
| 1045 | - std::shared_ptr<EncryptionParameters> encp, | ||
| 1046 | - QPDFObjGen const& og, | ||
| 1047 | - bool use_aes) | 983 | + std::shared_ptr<EncryptionParameters> encp, QPDFObjGen const& og, bool use_aes) |
| 1048 | { | 984 | { |
| 1049 | if (!encp->encrypted) { | 985 | if (!encp->encrypted) { |
| 1050 | - throw std::logic_error( | ||
| 1051 | - "request for encryption key in non-encrypted PDF"); | 986 | + throw std::logic_error("request for encryption key in non-encrypted PDF"); |
| 1052 | } | 987 | } |
| 1053 | 988 | ||
| 1054 | if (og != encp->cached_key_og) { | 989 | if (og != encp->cached_key_og) { |
| @@ -1089,9 +1024,8 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | @@ -1089,9 +1024,8 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | ||
| 1089 | break; | 1024 | break; |
| 1090 | 1025 | ||
| 1091 | default: | 1026 | default: |
| 1092 | - warn(damagedPDF( | ||
| 1093 | - "unknown encryption filter for strings (check /StrF in " | ||
| 1094 | - "/Encrypt dictionary); strings may be decrypted improperly")); | 1027 | + warn(damagedPDF("unknown encryption filter for strings (check /StrF in " |
| 1028 | + "/Encrypt dictionary); strings may be decrypted improperly")); | ||
| 1095 | // To avoid repeated warnings, reset cf_string. Assume | 1029 | // To avoid repeated warnings, reset cf_string. Assume |
| 1096 | // we'd want to use AES if V == 4. | 1030 | // we'd want to use AES if V == 4. |
| 1097 | m->encp->cf_string = e_aes; | 1031 | m->encp->cf_string = e_aes; |
| @@ -1114,8 +1048,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | @@ -1114,8 +1048,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | ||
| 1114 | pl.writeString(str); | 1048 | pl.writeString(str); |
| 1115 | pl.finish(); | 1049 | pl.finish(); |
| 1116 | auto buf = bufpl.getBufferSharedPointer(); | 1050 | auto buf = bufpl.getBufferSharedPointer(); |
| 1117 | - str = std::string( | ||
| 1118 | - reinterpret_cast<char*>(buf->getBuffer()), buf->getSize()); | 1051 | + str = std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize()); |
| 1119 | } else { | 1052 | } else { |
| 1120 | QTC::TC("qpdf", "QPDF_encryption rc4 decode string"); | 1053 | QTC::TC("qpdf", "QPDF_encryption rc4 decode string"); |
| 1121 | size_t vlen = str.length(); | 1054 | size_t vlen = str.length(); |
| @@ -1130,9 +1063,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | @@ -1130,9 +1063,7 @@ QPDF::decryptString(std::string& str, QPDFObjGen const& og) | ||
| 1130 | } catch (QPDFExc&) { | 1063 | } catch (QPDFExc&) { |
| 1131 | throw; | 1064 | throw; |
| 1132 | } catch (std::runtime_error& e) { | 1065 | } catch (std::runtime_error& e) { |
| 1133 | - throw damagedPDF( | ||
| 1134 | - "error decrypting string for object " + og.unparse() + ": " + | ||
| 1135 | - e.what()); | 1066 | + throw damagedPDF("error decrypting string for object " + og.unparse() + ": " + e.what()); |
| 1136 | } | 1067 | } |
| 1137 | } | 1068 | } |
| 1138 | 1069 | ||
| @@ -1161,10 +1092,8 @@ QPDF::decryptStream( | @@ -1161,10 +1092,8 @@ QPDF::decryptStream( | ||
| 1161 | 1092 | ||
| 1162 | if (stream_dict.getKey("/Filter").isOrHasName("/Crypt")) { | 1093 | if (stream_dict.getKey("/Filter").isOrHasName("/Crypt")) { |
| 1163 | if (stream_dict.getKey("/DecodeParms").isDictionary()) { | 1094 | if (stream_dict.getKey("/DecodeParms").isDictionary()) { |
| 1164 | - QPDFObjectHandle decode_parms = | ||
| 1165 | - stream_dict.getKey("/DecodeParms"); | ||
| 1166 | - if (decode_parms.isDictionaryOfType( | ||
| 1167 | - "/CryptFilterDecodeParms")) { | 1095 | + QPDFObjectHandle decode_parms = stream_dict.getKey("/DecodeParms"); |
| 1096 | + if (decode_parms.isDictionaryOfType("/CryptFilterDecodeParms")) { | ||
| 1168 | QTC::TC("qpdf", "QPDF_encryption stream crypt filter"); | 1097 | QTC::TC("qpdf", "QPDF_encryption stream crypt filter"); |
| 1169 | method = interpretCF(encp, decode_parms.getKey("/Name")); | 1098 | method = interpretCF(encp, decode_parms.getKey("/Name")); |
| 1170 | method_source = "stream's Crypt decode parameters"; | 1099 | method_source = "stream's Crypt decode parameters"; |
| @@ -1177,13 +1106,11 @@ QPDF::decryptStream( | @@ -1177,13 +1106,11 @@ QPDF::decryptStream( | ||
| 1177 | if (filter.getArrayNItems() == decode.getArrayNItems()) { | 1106 | if (filter.getArrayNItems() == decode.getArrayNItems()) { |
| 1178 | for (int i = 0; i < filter.getArrayNItems(); ++i) { | 1107 | for (int i = 0; i < filter.getArrayNItems(); ++i) { |
| 1179 | if (filter.getArrayItem(i).isNameAndEquals("/Crypt")) { | 1108 | if (filter.getArrayItem(i).isNameAndEquals("/Crypt")) { |
| 1180 | - QPDFObjectHandle crypt_params = | ||
| 1181 | - decode.getArrayItem(i); | 1109 | + QPDFObjectHandle crypt_params = decode.getArrayItem(i); |
| 1182 | if (crypt_params.isDictionary() && | 1110 | if (crypt_params.isDictionary() && |
| 1183 | crypt_params.getKey("/Name").isName()) { | 1111 | crypt_params.getKey("/Name").isName()) { |
| 1184 | QTC::TC("qpdf", "QPDF_encrypt crypt array"); | 1112 | QTC::TC("qpdf", "QPDF_encrypt crypt array"); |
| 1185 | - method = interpretCF( | ||
| 1186 | - encp, crypt_params.getKey("/Name")); | 1113 | + method = interpretCF(encp, crypt_params.getKey("/Name")); |
| 1187 | method_source = "stream's Crypt " | 1114 | method_source = "stream's Crypt " |
| 1188 | "decode parameters (array)"; | 1115 | "decode parameters (array)"; |
| 1189 | } | 1116 | } |
| @@ -1225,8 +1152,8 @@ QPDF::decryptStream( | @@ -1225,8 +1152,8 @@ QPDF::decryptStream( | ||
| 1225 | file->getName(), | 1152 | file->getName(), |
| 1226 | "", | 1153 | "", |
| 1227 | file->getLastOffset(), | 1154 | file->getLastOffset(), |
| 1228 | - "unknown encryption filter for streams (check " + | ||
| 1229 | - method_source + "); streams may be decrypted improperly")); | 1155 | + "unknown encryption filter for streams (check " + method_source + |
| 1156 | + "); streams may be decrypted improperly")); | ||
| 1230 | // To avoid repeated warnings, reset cf_stream. Assume | 1157 | // To avoid repeated warnings, reset cf_stream. Assume |
| 1231 | // we'd want to use AES if V == 4. | 1158 | // we'd want to use AES if V == 4. |
| 1232 | encp->cf_stream = e_aes; | 1159 | encp->cf_stream = e_aes; |
| @@ -1270,11 +1197,9 @@ QPDF::compute_encryption_O_U( | @@ -1270,11 +1197,9 @@ QPDF::compute_encryption_O_U( | ||
| 1270 | std::string& U) | 1197 | std::string& U) |
| 1271 | { | 1198 | { |
| 1272 | if (V >= 5) { | 1199 | if (V >= 5) { |
| 1273 | - throw std::logic_error( | ||
| 1274 | - "compute_encryption_O_U called for file with V >= 5"); | 1200 | + throw std::logic_error("compute_encryption_O_U called for file with V >= 5"); |
| 1275 | } | 1201 | } |
| 1276 | - EncryptionData data( | ||
| 1277 | - V, R, key_len, P, "", "", "", "", "", id1, encrypt_metadata); | 1202 | + EncryptionData data(V, R, key_len, P, "", "", "", "", "", id1, encrypt_metadata); |
| 1278 | data.setO(compute_O_value(user_password, owner_password, data)); | 1203 | data.setO(compute_O_value(user_password, owner_password, data)); |
| 1279 | O = data.getO(); | 1204 | O = data.getO(); |
| 1280 | data.setU(compute_U_value(user_password, data)); | 1205 | data.setU(compute_U_value(user_password, data)); |
| @@ -1298,8 +1223,7 @@ QPDF::compute_encryption_parameters_V5( | @@ -1298,8 +1223,7 @@ QPDF::compute_encryption_parameters_V5( | ||
| 1298 | std::string& UE, | 1223 | std::string& UE, |
| 1299 | std::string& Perms) | 1224 | std::string& Perms) |
| 1300 | { | 1225 | { |
| 1301 | - EncryptionData data( | ||
| 1302 | - V, R, key_len, P, "", "", "", "", "", id1, encrypt_metadata); | 1226 | + EncryptionData data(V, R, key_len, P, "", "", "", "", "", id1, encrypt_metadata); |
| 1303 | unsigned char k[key_bytes]; | 1227 | unsigned char k[key_bytes]; |
| 1304 | QUtil::initializeWithRandomBytes(k, key_bytes); | 1228 | QUtil::initializeWithRandomBytes(k, key_bytes); |
| 1305 | encryption_key = std::string(reinterpret_cast<char*>(k), key_bytes); | 1229 | encryption_key = std::string(reinterpret_cast<char*>(k), key_bytes); |
libqpdf/QPDF_json.cc
| @@ -203,8 +203,7 @@ QPDF::test_json_validators() | @@ -203,8 +203,7 @@ QPDF::test_json_validators() | ||
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | static std::function<void(Pipeline*)> | 205 | static std::function<void(Pipeline*)> |
| 206 | -provide_data( | ||
| 207 | - std::shared_ptr<InputSource> is, qpdf_offset_t start, qpdf_offset_t end) | 206 | +provide_data(std::shared_ptr<InputSource> is, qpdf_offset_t start, qpdf_offset_t end) |
| 208 | { | 207 | { |
| 209 | return [is, start, end](Pipeline* p) { | 208 | return [is, start, end](Pipeline* p) { |
| 210 | Pl_Base64 decode("base64-decode", p, Pl_Base64::a_decode); | 209 | Pl_Base64 decode("base64-decode", p, Pl_Base64::a_decode); |
| @@ -227,13 +226,12 @@ provide_data( | @@ -227,13 +226,12 @@ provide_data( | ||
| 227 | class QPDF::JSONReactor: public JSON::Reactor | 226 | class QPDF::JSONReactor: public JSON::Reactor |
| 228 | { | 227 | { |
| 229 | public: | 228 | public: |
| 230 | - JSONReactor( | ||
| 231 | - QPDF& pdf, std::shared_ptr<InputSource> is, bool must_be_complete) : | 229 | + JSONReactor(QPDF& pdf, std::shared_ptr<InputSource> is, bool must_be_complete) : |
| 232 | pdf(pdf), | 230 | pdf(pdf), |
| 233 | is(is), | 231 | is(is), |
| 234 | must_be_complete(must_be_complete), | 232 | must_be_complete(must_be_complete), |
| 235 | - descr(std::make_shared<QPDFValue::Description>(QPDFValue::JSON_Descr( | ||
| 236 | - std::make_shared<std::string>(is->getName()), ""))) | 233 | + descr(std::make_shared<QPDFValue::Description>( |
| 234 | + QPDFValue::JSON_Descr(std::make_shared<std::string>(is->getName()), ""))) | ||
| 237 | { | 235 | { |
| 238 | for (auto& oc: pdf.m->obj_cache) { | 236 | for (auto& oc: pdf.m->obj_cache) { |
| 239 | if (oc.second.object->getTypeCode() == ::ot_reserved) { | 237 | if (oc.second.object->getTypeCode() == ::ot_reserved) { |
| @@ -270,10 +268,8 @@ class QPDF::JSONReactor: public JSON::Reactor | @@ -270,10 +268,8 @@ class QPDF::JSONReactor: public JSON::Reactor | ||
| 270 | void setObjectDescription(QPDFObjectHandle& oh, JSON const& value); | 268 | void setObjectDescription(QPDFObjectHandle& oh, JSON const& value); |
| 271 | QPDFObjectHandle makeObject(JSON const& value); | 269 | QPDFObjectHandle makeObject(JSON const& value); |
| 272 | void error(qpdf_offset_t offset, std::string const& message); | 270 | void error(qpdf_offset_t offset, std::string const& message); |
| 273 | - void replaceObject( | ||
| 274 | - QPDFObjectHandle to_replace, | ||
| 275 | - QPDFObjectHandle replacement, | ||
| 276 | - JSON const& value); | 271 | + void |
| 272 | + replaceObject(QPDFObjectHandle to_replace, QPDFObjectHandle replacement, JSON const& value); | ||
| 277 | 273 | ||
| 278 | QPDF& pdf; | 274 | QPDF& pdf; |
| 279 | std::shared_ptr<InputSource> is; | 275 | std::shared_ptr<InputSource> is; |
| @@ -380,9 +376,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value) | @@ -380,9 +376,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value) | ||
| 380 | } | 376 | } |
| 381 | } else if (saw_value == saw_stream) { | 377 | } else if (saw_value == saw_stream) { |
| 382 | QTC::TC("qpdf", "QPDF_json value stream both or neither"); | 378 | QTC::TC("qpdf", "QPDF_json value stream both or neither"); |
| 383 | - error( | ||
| 384 | - value.getStart(), | ||
| 385 | - "object must have exactly one of \"value\" or \"stream\""); | 379 | + error(value.getStart(), "object must have exactly one of \"value\" or \"stream\""); |
| 386 | } | 380 | } |
| 387 | object_stack.clear(); | 381 | object_stack.clear(); |
| 388 | this->cur_object = ""; | 382 | this->cur_object = ""; |
| @@ -424,8 +418,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value) | @@ -424,8 +418,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value) | ||
| 424 | // treat as nulls. It's tempting to make this an error, but that would | 418 | // treat as nulls. It's tempting to make this an error, but that would |
| 425 | // be wrong since valid input files may have these. | 419 | // be wrong since valid input files may have these. |
| 426 | for (auto& oc: pdf.m->obj_cache) { | 420 | for (auto& oc: pdf.m->obj_cache) { |
| 427 | - if (oc.second.object->getTypeCode() == ::ot_reserved && | ||
| 428 | - reserved.count(oc.first) == 0) { | 421 | + if (oc.second.object->getTypeCode() == ::ot_reserved && reserved.count(oc.first) == 0) { |
| 429 | QTC::TC("qpdf", "QPDF_json non-trivial null reserved"); | 422 | QTC::TC("qpdf", "QPDF_json non-trivial null reserved"); |
| 430 | pdf.updateCache(oc.first, QPDF_Null::create(), -1, -1); | 423 | pdf.updateCache(oc.first, QPDF_Null::create(), -1, -1); |
| 431 | } | 424 | } |
| @@ -435,9 +428,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value) | @@ -435,9 +428,7 @@ QPDF::JSONReactor::containerEnd(JSON const& value) | ||
| 435 | 428 | ||
| 436 | void | 429 | void |
| 437 | QPDF::JSONReactor::replaceObject( | 430 | QPDF::JSONReactor::replaceObject( |
| 438 | - QPDFObjectHandle to_replace, | ||
| 439 | - QPDFObjectHandle replacement, | ||
| 440 | - JSON const& value) | 431 | + QPDFObjectHandle to_replace, QPDFObjectHandle replacement, JSON const& value) |
| 441 | { | 432 | { |
| 442 | auto og = to_replace.getObjGen(); | 433 | auto og = to_replace.getObjGen(); |
| 443 | this->pdf.replaceObject(og, replacement); | 434 | this->pdf.replaceObject(og, replacement); |
| @@ -453,8 +444,7 @@ QPDF::JSONReactor::topLevelScalar() | @@ -453,8 +444,7 @@ QPDF::JSONReactor::topLevelScalar() | ||
| 453 | } | 444 | } |
| 454 | 445 | ||
| 455 | void | 446 | void |
| 456 | -QPDF::JSONReactor::nestedState( | ||
| 457 | - std::string const& key, JSON const& value, state_e next) | 447 | +QPDF::JSONReactor::nestedState(std::string const& key, JSON const& value, state_e next) |
| 458 | { | 448 | { |
| 459 | // Use this method when the next state is for processing a nested | 449 | // Use this method when the next state is for processing a nested |
| 460 | // dictionary. | 450 | // dictionary. |
| @@ -528,9 +518,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) | @@ -528,9 +518,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) | ||
| 528 | } | 518 | } |
| 529 | } else { | 519 | } else { |
| 530 | QTC::TC("qpdf", "QPDF_json bad pushedinheritedpageresources"); | 520 | QTC::TC("qpdf", "QPDF_json bad pushedinheritedpageresources"); |
| 531 | - error( | ||
| 532 | - value.getStart(), | ||
| 533 | - "pushedinheritedpageresources must be a boolean"); | 521 | + error(value.getStart(), "pushedinheritedpageresources must be a boolean"); |
| 534 | } | 522 | } |
| 535 | } else if (key == "calledgetallpages") { | 523 | } else if (key == "calledgetallpages") { |
| 536 | bool v; | 524 | bool v; |
| @@ -562,9 +550,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) | @@ -562,9 +550,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) | ||
| 562 | nestedState(key, value, st_object_top); | 550 | nestedState(key, value, st_object_top); |
| 563 | } else { | 551 | } else { |
| 564 | QTC::TC("qpdf", "QPDF_json bad object key"); | 552 | QTC::TC("qpdf", "QPDF_json bad object key"); |
| 565 | - error( | ||
| 566 | - value.getStart(), | ||
| 567 | - "object key should be \"trailer\" or \"obj:n n R\""); | 553 | + error(value.getStart(), "object key should be \"trailer\" or \"obj:n n R\""); |
| 568 | next_state = st_ignore; | 554 | next_state = st_ignore; |
| 569 | parse_error = true; | 555 | parse_error = true; |
| 570 | } | 556 | } |
| @@ -653,17 +639,13 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) | @@ -653,17 +639,13 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) | ||
| 653 | if (end < start) { | 639 | if (end < start) { |
| 654 | throw std::logic_error("QPDF_json: JSON string length < 0"); | 640 | throw std::logic_error("QPDF_json: JSON string length < 0"); |
| 655 | } | 641 | } |
| 656 | - tos.replaceStreamData( | ||
| 657 | - provide_data(is, start, end), uninitialized, uninitialized); | 642 | + tos.replaceStreamData(provide_data(is, start, end), uninitialized, uninitialized); |
| 658 | } | 643 | } |
| 659 | } else if (key == "datafile") { | 644 | } else if (key == "datafile") { |
| 660 | this->saw_datafile = true; | 645 | this->saw_datafile = true; |
| 661 | std::string filename; | 646 | std::string filename; |
| 662 | if (value.getString(filename)) { | 647 | if (value.getString(filename)) { |
| 663 | - tos.replaceStreamData( | ||
| 664 | - QUtil::file_provider(filename), | ||
| 665 | - uninitialized, | ||
| 666 | - uninitialized); | 648 | + tos.replaceStreamData(QUtil::file_provider(filename), uninitialized, uninitialized); |
| 667 | } else { | 649 | } else { |
| 668 | error( | 650 | error( |
| 669 | value.getStart(), | 651 | value.getStart(), |
| @@ -684,8 +666,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) | @@ -684,8 +666,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) | ||
| 684 | dict.replaceKey(key, makeObject(value)); | 666 | dict.replaceKey(key, makeObject(value)); |
| 685 | } | 667 | } |
| 686 | } else { | 668 | } else { |
| 687 | - throw std::logic_error( | ||
| 688 | - "QPDF_json: unknown state " + std::to_string(state)); | 669 | + throw std::logic_error("QPDF_json: unknown state " + std::to_string(state)); |
| 689 | } | 670 | } |
| 690 | return true; | 671 | return true; |
| 691 | } | 672 | } |
| @@ -746,8 +727,7 @@ QPDF::JSONReactor::makeObject(JSON const& value) | @@ -746,8 +727,7 @@ QPDF::JSONReactor::makeObject(JSON const& value) | ||
| 746 | result = QPDFObjectHandle::newBool(bool_v); | 727 | result = QPDFObjectHandle::newBool(bool_v); |
| 747 | } else if (value.getNumber(str_v)) { | 728 | } else if (value.getNumber(str_v)) { |
| 748 | if (QUtil::is_long_long(str_v.c_str())) { | 729 | if (QUtil::is_long_long(str_v.c_str())) { |
| 749 | - result = QPDFObjectHandle::newInteger( | ||
| 750 | - QUtil::string_to_ll(str_v.c_str())); | 730 | + result = QPDFObjectHandle::newInteger(QUtil::string_to_ll(str_v.c_str())); |
| 751 | } else { | 731 | } else { |
| 752 | result = QPDFObjectHandle::newReal(str_v); | 732 | result = QPDFObjectHandle::newReal(str_v); |
| 753 | } | 733 | } |
| @@ -770,8 +750,7 @@ QPDF::JSONReactor::makeObject(JSON const& value) | @@ -770,8 +750,7 @@ QPDF::JSONReactor::makeObject(JSON const& value) | ||
| 770 | } | 750 | } |
| 771 | } | 751 | } |
| 772 | if (!result.isInitialized()) { | 752 | if (!result.isInitialized()) { |
| 773 | - throw std::logic_error( | ||
| 774 | - "JSONReactor::makeObject didn't initialize the object"); | 753 | + throw std::logic_error("JSONReactor::makeObject didn't initialize the object"); |
| 775 | } | 754 | } |
| 776 | 755 | ||
| 777 | if (!result.hasObjectDescription()) { | 756 | if (!result.hasObjectDescription()) { |
| @@ -842,9 +821,7 @@ QPDF::writeJSONStream( | @@ -842,9 +821,7 @@ QPDF::writeJSONStream( | ||
| 842 | } | 821 | } |
| 843 | auto j = JSON::makeDictionary(); | 822 | auto j = JSON::makeDictionary(); |
| 844 | j.addDictionaryMember( | 823 | j.addDictionaryMember( |
| 845 | - "stream", | ||
| 846 | - obj.getStreamJSON( | ||
| 847 | - version, json_stream_data, decode_level, stream_p, filename)); | 824 | + "stream", obj.getStreamJSON(version, json_stream_data, decode_level, stream_p, filename)); |
| 848 | 825 | ||
| 849 | JSON::writeDictionaryItem(p, first, key, j, 3); | 826 | JSON::writeDictionaryItem(p, first, key, j, 3); |
| 850 | if (f) { | 827 | if (f) { |
| @@ -856,11 +833,7 @@ QPDF::writeJSONStream( | @@ -856,11 +833,7 @@ QPDF::writeJSONStream( | ||
| 856 | 833 | ||
| 857 | void | 834 | void |
| 858 | QPDF::writeJSONObject( | 835 | QPDF::writeJSONObject( |
| 859 | - int version, | ||
| 860 | - Pipeline* p, | ||
| 861 | - bool& first, | ||
| 862 | - std::string const& key, | ||
| 863 | - QPDFObjectHandle& obj) | 836 | + int version, Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle& obj) |
| 864 | { | 837 | { |
| 865 | auto j = JSON::makeDictionary(); | 838 | auto j = JSON::makeDictionary(); |
| 866 | j.addDictionaryMember("value", obj.getJSON(version, true)); | 839 | j.addDictionaryMember("value", obj.getJSON(version, true)); |
| @@ -877,15 +850,7 @@ QPDF::writeJSON( | @@ -877,15 +850,7 @@ QPDF::writeJSON( | ||
| 877 | std::set<std::string> wanted_objects) | 850 | std::set<std::string> wanted_objects) |
| 878 | { | 851 | { |
| 879 | bool first = true; | 852 | bool first = true; |
| 880 | - writeJSON( | ||
| 881 | - version, | ||
| 882 | - p, | ||
| 883 | - true, | ||
| 884 | - first, | ||
| 885 | - decode_level, | ||
| 886 | - json_stream_data, | ||
| 887 | - file_prefix, | ||
| 888 | - wanted_objects); | 853 | + writeJSON(version, p, true, first, decode_level, json_stream_data, file_prefix, wanted_objects); |
| 889 | } | 854 | } |
| 890 | 855 | ||
| 891 | void | 856 | void |
| @@ -905,8 +870,7 @@ QPDF::writeJSON( | @@ -905,8 +870,7 @@ QPDF::writeJSON( | ||
| 905 | int const depth_qpdf_inner = 3; | 870 | int const depth_qpdf_inner = 3; |
| 906 | 871 | ||
| 907 | if (version != 2) { | 872 | if (version != 2) { |
| 908 | - throw std::runtime_error( | ||
| 909 | - "QPDF::writeJSON: only version 2 is supported"); | 873 | + throw std::runtime_error("QPDF::writeJSON: only version 2 is supported"); |
| 910 | } | 874 | } |
| 911 | bool first = true; | 875 | bool first = true; |
| 912 | if (complete) { | 876 | if (complete) { |
| @@ -921,17 +885,9 @@ QPDF::writeJSON( | @@ -921,17 +885,9 @@ QPDF::writeJSON( | ||
| 921 | bool first_qpdf_inner = true; | 885 | bool first_qpdf_inner = true; |
| 922 | JSON::writeDictionaryOpen(p, first_qpdf_inner, depth_qpdf); | 886 | JSON::writeDictionaryOpen(p, first_qpdf_inner, depth_qpdf); |
| 923 | JSON::writeDictionaryItem( | 887 | JSON::writeDictionaryItem( |
| 924 | - p, | ||
| 925 | - first_qpdf_inner, | ||
| 926 | - "jsonversion", | ||
| 927 | - JSON::makeInt(version), | ||
| 928 | - depth_qpdf_inner); | 888 | + p, first_qpdf_inner, "jsonversion", JSON::makeInt(version), depth_qpdf_inner); |
| 929 | JSON::writeDictionaryItem( | 889 | JSON::writeDictionaryItem( |
| 930 | - p, | ||
| 931 | - first_qpdf_inner, | ||
| 932 | - "pdfversion", | ||
| 933 | - JSON::makeString(getPDFVersion()), | ||
| 934 | - depth_qpdf_inner); | 890 | + p, first_qpdf_inner, "pdfversion", JSON::makeString(getPDFVersion()), depth_qpdf_inner); |
| 935 | JSON::writeDictionaryItem( | 891 | JSON::writeDictionaryItem( |
| 936 | p, | 892 | p, |
| 937 | first_qpdf_inner, | 893 | first_qpdf_inner, |
libqpdf/QPDF_linearization.cc
| @@ -19,11 +19,7 @@ | @@ -19,11 +19,7 @@ | ||
| 19 | template <class T, class int_type> | 19 | template <class T, class int_type> |
| 20 | static void | 20 | static void |
| 21 | load_vector_int( | 21 | load_vector_int( |
| 22 | - BitStream& bit_stream, | ||
| 23 | - int nitems, | ||
| 24 | - std::vector<T>& vec, | ||
| 25 | - int bits_wanted, | ||
| 26 | - int_type T::*field) | 22 | + BitStream& bit_stream, int nitems, std::vector<T>& vec, int bits_wanted, int_type T::*field) |
| 27 | { | 23 | { |
| 28 | bool append = vec.empty(); | 24 | bool append = vec.empty(); |
| 29 | // nitems times, read bits_wanted from the given bit stream, | 25 | // nitems times, read bits_wanted from the given bit stream, |
| @@ -57,8 +53,7 @@ load_vector_vector( | @@ -57,8 +53,7 @@ load_vector_vector( | ||
| 57 | // into the vec2 vector field of the ith item of vec1. | 53 | // into the vec2 vector field of the ith item of vec1. |
| 58 | for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1) { | 54 | for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1) { |
| 59 | for (int i2 = 0; i2 < vec1.at(i1).*nitems2; ++i2) { | 55 | for (int i2 = 0; i2 < vec1.at(i1).*nitems2; ++i2) { |
| 60 | - (vec1.at(i1).*vec2) | ||
| 61 | - .push_back(bit_stream.getBitsInt(QIntC::to_size(bits_wanted))); | 56 | + (vec1.at(i1).*vec2).push_back(bit_stream.getBitsInt(QIntC::to_size(bits_wanted))); |
| 62 | } | 57 | } |
| 63 | } | 58 | } |
| 64 | bit_stream.skipToNextByte(); | 59 | bit_stream.skipToNextByte(); |
| @@ -80,8 +75,7 @@ QPDF::checkLinearization() | @@ -80,8 +75,7 @@ QPDF::checkLinearization() | ||
| 80 | result = checkLinearizationInternal(); | 75 | result = checkLinearizationInternal(); |
| 81 | } catch (std::runtime_error& e) { | 76 | } catch (std::runtime_error& e) { |
| 82 | linearizationWarning( | 77 | linearizationWarning( |
| 83 | - "error encountered while checking linearization data: " + | ||
| 84 | - std::string(e.what())); | 78 | + "error encountered while checking linearization data: " + std::string(e.what())); |
| 85 | } | 79 | } |
| 86 | return result; | 80 | return result; |
| 87 | } | 81 | } |
| @@ -127,8 +121,7 @@ QPDF::isLinearized() | @@ -127,8 +121,7 @@ QPDF::isLinearized() | ||
| 127 | } | 121 | } |
| 128 | 122 | ||
| 129 | QPDFTokenizer::Token t1 = readToken(m->file); | 123 | QPDFTokenizer::Token t1 = readToken(m->file); |
| 130 | - if (t1.isInteger() && readToken(m->file).isInteger() && | ||
| 131 | - readToken(m->file).isWord("obj") && | 124 | + if (t1.isInteger() && readToken(m->file).isInteger() && readToken(m->file).isWord("obj") && |
| 132 | (readToken(m->file).getType() == QPDFTokenizer::tt_dict_open)) { | 125 | (readToken(m->file).getType() == QPDFTokenizer::tt_dict_open)) { |
| 133 | lindict_obj = toI(QUtil::string_to_ll(t1.getValue().c_str())); | 126 | lindict_obj = toI(QUtil::string_to_ll(t1.getValue().c_str())); |
| 134 | } | 127 | } |
| @@ -184,8 +177,8 @@ QPDF::readLinearizationData() | @@ -184,8 +177,8 @@ QPDF::readLinearizationData() | ||
| 184 | QPDFObjectHandle T = m->lindict.getKey("/T"); | 177 | QPDFObjectHandle T = m->lindict.getKey("/T"); |
| 185 | QPDFObjectHandle P = m->lindict.getKey("/P"); | 178 | QPDFObjectHandle P = m->lindict.getKey("/P"); |
| 186 | 179 | ||
| 187 | - if (!(H.isArray() && O.isInteger() && E.isInteger() && N.isInteger() && | ||
| 188 | - T.isInteger() && (P.isInteger() || P.isNull()))) { | 180 | + if (!(H.isArray() && O.isInteger() && E.isInteger() && N.isInteger() && T.isInteger() && |
| 181 | + (P.isInteger() || P.isNull()))) { | ||
| 189 | throw damagedPDF( | 182 | throw damagedPDF( |
| 190 | "linearization dictionary", | 183 | "linearization dictionary", |
| 191 | "some keys in linearization dictionary are of the wrong type"); | 184 | "some keys in linearization dictionary are of the wrong type"); |
| @@ -194,8 +187,7 @@ QPDF::readLinearizationData() | @@ -194,8 +187,7 @@ QPDF::readLinearizationData() | ||
| 194 | // Hint table array: offset length [ offset length ] | 187 | // Hint table array: offset length [ offset length ] |
| 195 | size_t n_H_items = toS(H.getArrayNItems()); | 188 | size_t n_H_items = toS(H.getArrayNItems()); |
| 196 | if (!((n_H_items == 2) || (n_H_items == 4))) { | 189 | if (!((n_H_items == 2) || (n_H_items == 4))) { |
| 197 | - throw damagedPDF( | ||
| 198 | - "linearization dictionary", "H has the wrong number of items"); | 190 | + throw damagedPDF("linearization dictionary", "H has the wrong number of items"); |
| 199 | } | 191 | } |
| 200 | 192 | ||
| 201 | std::vector<int> H_items; | 193 | std::vector<int> H_items; |
| @@ -204,9 +196,7 @@ QPDF::readLinearizationData() | @@ -204,9 +196,7 @@ QPDF::readLinearizationData() | ||
| 204 | if (oh.isInteger()) { | 196 | if (oh.isInteger()) { |
| 205 | H_items.push_back(oh.getIntValueAsInt()); | 197 | H_items.push_back(oh.getIntValueAsInt()); |
| 206 | } else { | 198 | } else { |
| 207 | - throw damagedPDF( | ||
| 208 | - "linearization dictionary", | ||
| 209 | - "some H items are of the wrong type"); | 199 | + throw damagedPDF("linearization dictionary", "some H items are of the wrong type"); |
| 210 | } | 200 | } |
| 211 | } | 201 | } |
| 212 | 202 | ||
| @@ -238,8 +228,7 @@ QPDF::readLinearizationData() | @@ -238,8 +228,7 @@ QPDF::readLinearizationData() | ||
| 238 | // initialized from N, to pre-allocate memory, so make sure it's | 228 | // initialized from N, to pre-allocate memory, so make sure it's |
| 239 | // accurate and bail right now if it's not. | 229 | // accurate and bail right now if it's not. |
| 240 | if (N.getIntValue() != static_cast<long long>(getAllPages().size())) { | 230 | if (N.getIntValue() != static_cast<long long>(getAllPages().size())) { |
| 241 | - throw damagedPDF( | ||
| 242 | - "linearization hint table", "/N does not match number of pages"); | 231 | + throw damagedPDF("linearization hint table", "/N does not match number of pages"); |
| 243 | } | 232 | } |
| 244 | 233 | ||
| 245 | // file_size initialized by isLinearized() | 234 | // file_size initialized by isLinearized() |
| @@ -282,21 +271,16 @@ QPDF::readLinearizationData() | @@ -282,21 +271,16 @@ QPDF::readLinearizationData() | ||
| 282 | 271 | ||
| 283 | int HSi = HS.getIntValueAsInt(); | 272 | int HSi = HS.getIntValueAsInt(); |
| 284 | if ((HSi < 0) || (toS(HSi) >= h_size)) { | 273 | if ((HSi < 0) || (toS(HSi) >= h_size)) { |
| 285 | - throw damagedPDF( | ||
| 286 | - "linearization hint table", | ||
| 287 | - "/S (shared object) offset is out of bounds"); | 274 | + throw damagedPDF("linearization hint table", "/S (shared object) offset is out of bounds"); |
| 288 | } | 275 | } |
| 289 | readHSharedObject(BitStream(h_buf + HSi, h_size - toS(HSi))); | 276 | readHSharedObject(BitStream(h_buf + HSi, h_size - toS(HSi))); |
| 290 | 277 | ||
| 291 | if (HO.isInteger()) { | 278 | if (HO.isInteger()) { |
| 292 | int HOi = HO.getIntValueAsInt(); | 279 | int HOi = HO.getIntValueAsInt(); |
| 293 | if ((HOi < 0) || (toS(HOi) >= h_size)) { | 280 | if ((HOi < 0) || (toS(HOi) >= h_size)) { |
| 294 | - throw damagedPDF( | ||
| 295 | - "linearization hint table", | ||
| 296 | - "/O (outline) offset is out of bounds"); | 281 | + throw damagedPDF("linearization hint table", "/O (outline) offset is out of bounds"); |
| 297 | } | 282 | } |
| 298 | - readHGeneric( | ||
| 299 | - BitStream(h_buf + HOi, h_size - toS(HOi)), m->outline_hints); | 283 | + readHGeneric(BitStream(h_buf + HOi, h_size - toS(HOi)), m->outline_hints); |
| 300 | } | 284 | } |
| 301 | } | 285 | } |
| 302 | 286 | ||
| @@ -304,19 +288,13 @@ QPDFObjectHandle | @@ -304,19 +288,13 @@ QPDFObjectHandle | ||
| 304 | QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) | 288 | QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) |
| 305 | { | 289 | { |
| 306 | QPDFObjGen og; | 290 | QPDFObjGen og; |
| 307 | - QPDFObjectHandle H = readObjectAtOffset( | ||
| 308 | - false, | ||
| 309 | - offset, | ||
| 310 | - "linearization hint stream", | ||
| 311 | - QPDFObjGen(0, 0), | ||
| 312 | - og, | ||
| 313 | - false); | 291 | + QPDFObjectHandle H = |
| 292 | + readObjectAtOffset(false, offset, "linearization hint stream", QPDFObjGen(0, 0), og, false); | ||
| 314 | ObjCache& oc = m->obj_cache[og]; | 293 | ObjCache& oc = m->obj_cache[og]; |
| 315 | qpdf_offset_t min_end_offset = oc.end_before_space; | 294 | qpdf_offset_t min_end_offset = oc.end_before_space; |
| 316 | qpdf_offset_t max_end_offset = oc.end_after_space; | 295 | qpdf_offset_t max_end_offset = oc.end_after_space; |
| 317 | if (!H.isStream()) { | 296 | if (!H.isStream()) { |
| 318 | - throw damagedPDF( | ||
| 319 | - "linearization dictionary", "hint table is not a stream"); | 297 | + throw damagedPDF("linearization dictionary", "hint table is not a stream"); |
| 320 | } | 298 | } |
| 321 | 299 | ||
| 322 | QPDFObjectHandle Hdict = H.getDict(); | 300 | QPDFObjectHandle Hdict = H.getDict(); |
| @@ -341,10 +319,8 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) | @@ -341,10 +319,8 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) | ||
| 341 | if ((computed_end < min_end_offset) || (computed_end > max_end_offset)) { | 319 | if ((computed_end < min_end_offset) || (computed_end > max_end_offset)) { |
| 342 | linearizationWarning( | 320 | linearizationWarning( |
| 343 | "expected = " + std::to_string(computed_end) + | 321 | "expected = " + std::to_string(computed_end) + |
| 344 | - "; actual = " + std::to_string(min_end_offset) + ".." + | ||
| 345 | - std::to_string(max_end_offset)); | ||
| 346 | - throw damagedPDF( | ||
| 347 | - "linearization dictionary", "hint table length mismatch"); | 322 | + "; actual = " + std::to_string(min_end_offset) + ".." + std::to_string(max_end_offset)); |
| 323 | + throw damagedPDF("linearization dictionary", "hint table length mismatch"); | ||
| 348 | } | 324 | } |
| 349 | H.pipeStreamData(&pl, 0, qpdf_dl_specialized); | 325 | H.pipeStreamData(&pl, 0, qpdf_dl_specialized); |
| 350 | return Hdict; | 326 | return Hdict; |
| @@ -375,24 +351,11 @@ QPDF::readHPageOffset(BitStream h) | @@ -375,24 +351,11 @@ QPDF::readHPageOffset(BitStream h) | ||
| 375 | std::vector<HPageOffsetEntry>& entries = t.entries; | 351 | std::vector<HPageOffsetEntry>& entries = t.entries; |
| 376 | entries.clear(); | 352 | entries.clear(); |
| 377 | int nitems = m->linp.npages; | 353 | int nitems = m->linp.npages; |
| 354 | + load_vector_int(h, nitems, entries, t.nbits_delta_nobjects, &HPageOffsetEntry::delta_nobjects); | ||
| 378 | load_vector_int( | 355 | load_vector_int( |
| 379 | - h, | ||
| 380 | - nitems, | ||
| 381 | - entries, | ||
| 382 | - t.nbits_delta_nobjects, | ||
| 383 | - &HPageOffsetEntry::delta_nobjects); | ||
| 384 | - load_vector_int( | ||
| 385 | - h, | ||
| 386 | - nitems, | ||
| 387 | - entries, | ||
| 388 | - t.nbits_delta_page_length, | ||
| 389 | - &HPageOffsetEntry::delta_page_length); | 356 | + h, nitems, entries, t.nbits_delta_page_length, &HPageOffsetEntry::delta_page_length); |
| 390 | load_vector_int( | 357 | load_vector_int( |
| 391 | - h, | ||
| 392 | - nitems, | ||
| 393 | - entries, | ||
| 394 | - t.nbits_nshared_objects, | ||
| 395 | - &HPageOffsetEntry::nshared_objects); | 358 | + h, nitems, entries, t.nbits_nshared_objects, &HPageOffsetEntry::nshared_objects); |
| 396 | load_vector_vector( | 359 | load_vector_vector( |
| 397 | h, | 360 | h, |
| 398 | nitems, | 361 | nitems, |
| @@ -408,17 +371,9 @@ QPDF::readHPageOffset(BitStream h) | @@ -408,17 +371,9 @@ QPDF::readHPageOffset(BitStream h) | ||
| 408 | t.nbits_shared_numerator, | 371 | t.nbits_shared_numerator, |
| 409 | &HPageOffsetEntry::shared_numerators); | 372 | &HPageOffsetEntry::shared_numerators); |
| 410 | load_vector_int( | 373 | load_vector_int( |
| 411 | - h, | ||
| 412 | - nitems, | ||
| 413 | - entries, | ||
| 414 | - t.nbits_delta_content_offset, | ||
| 415 | - &HPageOffsetEntry::delta_content_offset); | 374 | + h, nitems, entries, t.nbits_delta_content_offset, &HPageOffsetEntry::delta_content_offset); |
| 416 | load_vector_int( | 375 | load_vector_int( |
| 417 | - h, | ||
| 418 | - nitems, | ||
| 419 | - entries, | ||
| 420 | - t.nbits_delta_content_length, | ||
| 421 | - &HPageOffsetEntry::delta_content_length); | 376 | + h, nitems, entries, t.nbits_delta_content_length, &HPageOffsetEntry::delta_content_length); |
| 422 | } | 377 | } |
| 423 | 378 | ||
| 424 | void | 379 | void |
| @@ -443,13 +398,8 @@ QPDF::readHSharedObject(BitStream h) | @@ -443,13 +398,8 @@ QPDF::readHSharedObject(BitStream h) | ||
| 443 | entries.clear(); | 398 | entries.clear(); |
| 444 | int nitems = t.nshared_total; | 399 | int nitems = t.nshared_total; |
| 445 | load_vector_int( | 400 | load_vector_int( |
| 446 | - h, | ||
| 447 | - nitems, | ||
| 448 | - entries, | ||
| 449 | - t.nbits_delta_group_length, | ||
| 450 | - &HSharedObjectEntry::delta_group_length); | ||
| 451 | - load_vector_int( | ||
| 452 | - h, nitems, entries, 1, &HSharedObjectEntry::signature_present); | 401 | + h, nitems, entries, t.nbits_delta_group_length, &HSharedObjectEntry::delta_group_length); |
| 402 | + load_vector_int(h, nitems, entries, 1, &HSharedObjectEntry::signature_present); | ||
| 453 | for (size_t i = 0; i < toS(nitems); ++i) { | 403 | for (size_t i = 0; i < toS(nitems); ++i) { |
| 454 | if (entries.at(i).signature_present) { | 404 | if (entries.at(i).signature_present) { |
| 455 | // Skip 128-bit MD5 hash. These are not supported by | 405 | // Skip 128-bit MD5 hash. These are not supported by |
| @@ -460,12 +410,7 @@ QPDF::readHSharedObject(BitStream h) | @@ -460,12 +410,7 @@ QPDF::readHSharedObject(BitStream h) | ||
| 460 | } | 410 | } |
| 461 | } | 411 | } |
| 462 | } | 412 | } |
| 463 | - load_vector_int( | ||
| 464 | - h, | ||
| 465 | - nitems, | ||
| 466 | - entries, | ||
| 467 | - t.nbits_nobjects, | ||
| 468 | - &HSharedObjectEntry::nobjects_minus_one); | 413 | + load_vector_int(h, nitems, entries, t.nbits_nobjects, &HSharedObjectEntry::nobjects_minus_one); |
| 469 | } | 414 | } |
| 470 | 415 | ||
| 471 | void | 416 | void |
| @@ -508,8 +453,7 @@ QPDF::checkLinearizationInternal() | @@ -508,8 +453,7 @@ QPDF::checkLinearizationInternal() | ||
| 508 | QPDFObjGen og(page.getObjGen()); | 453 | QPDFObjGen og(page.getObjGen()); |
| 509 | if (m->xref_table[og].getType() == 2) { | 454 | if (m->xref_table[og].getType() == 2) { |
| 510 | linearizationWarning( | 455 | linearizationWarning( |
| 511 | - "page dictionary for page " + std::to_string(i) + | ||
| 512 | - " is compressed"); | 456 | + "page dictionary for page " + std::to_string(i) + " is compressed"); |
| 513 | } | 457 | } |
| 514 | } | 458 | } |
| 515 | 459 | ||
| @@ -541,9 +485,8 @@ QPDF::checkLinearizationInternal() | @@ -541,9 +485,8 @@ QPDF::checkLinearizationInternal() | ||
| 541 | // are in use. | 485 | // are in use. |
| 542 | 486 | ||
| 543 | if (m->uncompressed_after_compressed) { | 487 | if (m->uncompressed_after_compressed) { |
| 544 | - linearizationWarning( | ||
| 545 | - "linearized file contains an uncompressed object" | ||
| 546 | - " after a compressed one in a cross-reference stream"); | 488 | + linearizationWarning("linearized file contains an uncompressed object" |
| 489 | + " after a compressed one in a cross-reference stream"); | ||
| 547 | } | 490 | } |
| 548 | 491 | ||
| 549 | // Further checking requires optimization and order calculation. | 492 | // Further checking requires optimization and order calculation. |
| @@ -593,9 +536,8 @@ QPDF::checkLinearizationInternal() | @@ -593,9 +536,8 @@ QPDF::checkLinearizationInternal() | ||
| 593 | if ((p.first_page_end < min_E) || (p.first_page_end > max_E)) { | 536 | if ((p.first_page_end < min_E) || (p.first_page_end > max_E)) { |
| 594 | QTC::TC("qpdf", "QPDF warn /E mismatch"); | 537 | QTC::TC("qpdf", "QPDF warn /E mismatch"); |
| 595 | linearizationWarning( | 538 | linearizationWarning( |
| 596 | - "end of first page section (/E) mismatch: /E = " + | ||
| 597 | - std::to_string(p.first_page_end) + "; computed = " + | ||
| 598 | - std::to_string(min_E) + ".." + std::to_string(max_E)); | 539 | + "end of first page section (/E) mismatch: /E = " + std::to_string(p.first_page_end) + |
| 540 | + "; computed = " + std::to_string(min_E) + ".." + std::to_string(max_E)); | ||
| 599 | } | 541 | } |
| 600 | 542 | ||
| 601 | // Check hint tables | 543 | // Check hint tables |
| @@ -637,21 +579,18 @@ QPDF::getLinearizationOffset(QPDFObjGen const& og) | @@ -637,21 +579,18 @@ QPDF::getLinearizationOffset(QPDFObjGen const& og) | ||
| 637 | case 2: | 579 | case 2: |
| 638 | // For compressed objects, return the offset of the object | 580 | // For compressed objects, return the offset of the object |
| 639 | // stream that contains them. | 581 | // stream that contains them. |
| 640 | - result = | ||
| 641 | - getLinearizationOffset(QPDFObjGen(entry.getObjStreamNumber(), 0)); | 582 | + result = getLinearizationOffset(QPDFObjGen(entry.getObjStreamNumber(), 0)); |
| 642 | break; | 583 | break; |
| 643 | 584 | ||
| 644 | default: | 585 | default: |
| 645 | - stopOnError( | ||
| 646 | - "getLinearizationOffset called for xref entry not of type 1 or 2"); | 586 | + stopOnError("getLinearizationOffset called for xref entry not of type 1 or 2"); |
| 647 | break; | 587 | break; |
| 648 | } | 588 | } |
| 649 | return result; | 589 | return result; |
| 650 | } | 590 | } |
| 651 | 591 | ||
| 652 | QPDFObjectHandle | 592 | QPDFObjectHandle |
| 653 | -QPDF::getUncompressedObject( | ||
| 654 | - QPDFObjectHandle& obj, std::map<int, int> const& object_stream_data) | 593 | +QPDF::getUncompressedObject(QPDFObjectHandle& obj, std::map<int, int> const& object_stream_data) |
| 655 | { | 594 | { |
| 656 | if (obj.isNull() || (object_stream_data.count(obj.getObjectID()) == 0)) { | 595 | if (obj.isNull() || (object_stream_data.count(obj.getObjectID()) == 0)) { |
| 657 | return obj; | 596 | return obj; |
| @@ -669,15 +608,13 @@ QPDF::lengthNextN(int first_object, int n) | @@ -669,15 +608,13 @@ QPDF::lengthNextN(int first_object, int n) | ||
| 669 | QPDFObjGen og(first_object + i, 0); | 608 | QPDFObjGen og(first_object + i, 0); |
| 670 | if (m->xref_table.count(og) == 0) { | 609 | if (m->xref_table.count(og) == 0) { |
| 671 | linearizationWarning( | 610 | linearizationWarning( |
| 672 | - "no xref table entry for " + std::to_string(first_object + i) + | ||
| 673 | - " 0"); | 611 | + "no xref table entry for " + std::to_string(first_object + i) + " 0"); |
| 674 | } else { | 612 | } else { |
| 675 | if (m->obj_cache.count(og) == 0) { | 613 | if (m->obj_cache.count(og) == 0) { |
| 676 | stopOnError("found unknown object while" | 614 | stopOnError("found unknown object while" |
| 677 | " calculating length for linearization data"); | 615 | " calculating length for linearization data"); |
| 678 | } | 616 | } |
| 679 | - length += toI( | ||
| 680 | - m->obj_cache[og].end_after_space - getLinearizationOffset(og)); | 617 | + length += toI(m->obj_cache[og].end_after_space - getLinearizationOffset(og)); |
| 681 | } | 618 | } |
| 682 | } | 619 | } |
| 683 | return length; | 620 | return length; |
| @@ -685,8 +622,7 @@ QPDF::lengthNextN(int first_object, int n) | @@ -685,8 +622,7 @@ QPDF::lengthNextN(int first_object, int n) | ||
| 685 | 622 | ||
| 686 | void | 623 | void |
| 687 | QPDF::checkHPageOffset( | 624 | QPDF::checkHPageOffset( |
| 688 | - std::vector<QPDFObjectHandle> const& pages, | ||
| 689 | - std::map<int, int>& shared_idx_to_obj) | 625 | + std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& shared_idx_to_obj) |
| 690 | { | 626 | { |
| 691 | // Implementation note 126 says Acrobat always sets | 627 | // Implementation note 126 says Acrobat always sets |
| 692 | // delta_content_offset and delta_content_length in the page | 628 | // delta_content_offset and delta_content_length in the page |
| @@ -706,8 +642,7 @@ QPDF::checkHPageOffset( | @@ -706,8 +642,7 @@ QPDF::checkHPageOffset( | ||
| 706 | // even when they are private. | 642 | // even when they are private. |
| 707 | 643 | ||
| 708 | int npages = toI(pages.size()); | 644 | int npages = toI(pages.size()); |
| 709 | - qpdf_offset_t table_offset = | ||
| 710 | - adjusted_offset(m->page_offset_hints.first_page_offset); | 645 | + qpdf_offset_t table_offset = adjusted_offset(m->page_offset_hints.first_page_offset); |
| 711 | QPDFObjGen first_page_og(pages.at(0).getObjGen()); | 646 | QPDFObjGen first_page_og(pages.at(0).getObjGen()); |
| 712 | if (m->xref_table.count(first_page_og) == 0) { | 647 | if (m->xref_table.count(first_page_og) == 0) { |
| 713 | stopOnError("supposed first page object is not known"); | 648 | stopOnError("supposed first page object is not known"); |
| @@ -731,23 +666,20 @@ QPDF::checkHPageOffset( | @@ -731,23 +666,20 @@ QPDF::checkHPageOffset( | ||
| 731 | if (h_nobjects != ce.nobjects) { | 666 | if (h_nobjects != ce.nobjects) { |
| 732 | // This happens with pdlin when there are thumbnails. | 667 | // This happens with pdlin when there are thumbnails. |
| 733 | linearizationWarning( | 668 | linearizationWarning( |
| 734 | - "object count mismatch for page " + std::to_string(pageno) + | ||
| 735 | - ": hint table = " + std::to_string(h_nobjects) + | ||
| 736 | - "; computed = " + std::to_string(ce.nobjects)); | 669 | + "object count mismatch for page " + std::to_string(pageno) + ": hint table = " + |
| 670 | + std::to_string(h_nobjects) + "; computed = " + std::to_string(ce.nobjects)); | ||
| 737 | } | 671 | } |
| 738 | 672 | ||
| 739 | // Use value for number of objects in hint table rather than | 673 | // Use value for number of objects in hint table rather than |
| 740 | // computed value if there is a discrepancy. | 674 | // computed value if there is a discrepancy. |
| 741 | int length = lengthNextN(first_object, h_nobjects); | 675 | int length = lengthNextN(first_object, h_nobjects); |
| 742 | - int h_length = | ||
| 743 | - toI(he.delta_page_length + m->page_offset_hints.min_page_length); | 676 | + int h_length = toI(he.delta_page_length + m->page_offset_hints.min_page_length); |
| 744 | if (length != h_length) { | 677 | if (length != h_length) { |
| 745 | // This condition almost certainly indicates a bad hint | 678 | // This condition almost certainly indicates a bad hint |
| 746 | // table or a bug in this code. | 679 | // table or a bug in this code. |
| 747 | linearizationWarning( | 680 | linearizationWarning( |
| 748 | - "page length mismatch for page " + std::to_string(pageno) + | ||
| 749 | - ": hint table = " + std::to_string(h_length) + | ||
| 750 | - "; computed length = " + std::to_string(length) + | 681 | + "page length mismatch for page " + std::to_string(pageno) + ": hint table = " + |
| 682 | + std::to_string(h_length) + "; computed length = " + std::to_string(length) + | ||
| 751 | " (offset = " + std::to_string(offset) + ")"); | 683 | " (offset = " + std::to_string(offset) + ")"); |
| 752 | } | 684 | } |
| 753 | 685 | ||
| @@ -785,8 +717,7 @@ QPDF::checkHPageOffset( | @@ -785,8 +717,7 @@ QPDF::checkHPageOffset( | ||
| 785 | if (!computed_shared.count(iter)) { | 717 | if (!computed_shared.count(iter)) { |
| 786 | // pdlin puts thumbnails here even though it shouldn't | 718 | // pdlin puts thumbnails here even though it shouldn't |
| 787 | linearizationWarning( | 719 | linearizationWarning( |
| 788 | - "page " + std::to_string(pageno) + ": shared object " + | ||
| 789 | - std::to_string(iter) + | 720 | + "page " + std::to_string(pageno) + ": shared object " + std::to_string(iter) + |
| 790 | ": in hint table but not computed list"); | 721 | ": in hint table but not computed list"); |
| 791 | } | 722 | } |
| 792 | } | 723 | } |
| @@ -797,8 +728,7 @@ QPDF::checkHPageOffset( | @@ -797,8 +728,7 @@ QPDF::checkHPageOffset( | ||
| 797 | // built-in fonts and procsets here, at least in some | 728 | // built-in fonts and procsets here, at least in some |
| 798 | // cases. | 729 | // cases. |
| 799 | linearizationWarning( | 730 | linearizationWarning( |
| 800 | - ("page " + std::to_string(pageno) + ": shared object " + | ||
| 801 | - std::to_string(iter) + | 731 | + ("page " + std::to_string(pageno) + ": shared object " + std::to_string(iter) + |
| 802 | ": in computed list but not hint table")); | 732 | ": in computed list but not hint table")); |
| 803 | } | 733 | } |
| 804 | } | 734 | } |
| @@ -806,8 +736,7 @@ QPDF::checkHPageOffset( | @@ -806,8 +736,7 @@ QPDF::checkHPageOffset( | ||
| 806 | } | 736 | } |
| 807 | 737 | ||
| 808 | void | 738 | void |
| 809 | -QPDF::checkHSharedObject( | ||
| 810 | - std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& idx_to_obj) | 739 | +QPDF::checkHSharedObject(std::vector<QPDFObjectHandle> const& pages, std::map<int, int>& idx_to_obj) |
| 811 | { | 740 | { |
| 812 | // Implementation note 125 says shared object groups always | 741 | // Implementation note 125 says shared object groups always |
| 813 | // contain only one object. Implementation note 128 says that | 742 | // contain only one object. Implementation note 128 says that |
| @@ -859,13 +788,11 @@ QPDF::checkHSharedObject( | @@ -859,13 +788,11 @@ QPDF::checkHSharedObject( | ||
| 859 | stopOnError("unknown object in shared object hint table"); | 788 | stopOnError("unknown object in shared object hint table"); |
| 860 | } | 789 | } |
| 861 | qpdf_offset_t offset = getLinearizationOffset(og); | 790 | qpdf_offset_t offset = getLinearizationOffset(og); |
| 862 | - qpdf_offset_t h_offset = | ||
| 863 | - adjusted_offset(so.first_shared_offset); | 791 | + qpdf_offset_t h_offset = adjusted_offset(so.first_shared_offset); |
| 864 | if (offset != h_offset) { | 792 | if (offset != h_offset) { |
| 865 | linearizationWarning( | 793 | linearizationWarning( |
| 866 | "first shared object offset mismatch: hint table = " + | 794 | "first shared object offset mismatch: hint table = " + |
| 867 | - std::to_string(h_offset) + | ||
| 868 | - "; computed = " + std::to_string(offset)); | 795 | + std::to_string(h_offset) + "; computed = " + std::to_string(offset)); |
| 869 | } | 796 | } |
| 870 | } | 797 | } |
| 871 | 798 | ||
| @@ -876,10 +803,8 @@ QPDF::checkHSharedObject( | @@ -876,10 +803,8 @@ QPDF::checkHSharedObject( | ||
| 876 | int h_length = so.min_group_length + se.delta_group_length; | 803 | int h_length = so.min_group_length + se.delta_group_length; |
| 877 | if (length != h_length) { | 804 | if (length != h_length) { |
| 878 | linearizationWarning( | 805 | linearizationWarning( |
| 879 | - "shared object " + std::to_string(i) + | ||
| 880 | - " length mismatch: hint table = " + | ||
| 881 | - std::to_string(h_length) + | ||
| 882 | - "; computed = " + std::to_string(length)); | 806 | + "shared object " + std::to_string(i) + " length mismatch: hint table = " + |
| 807 | + std::to_string(h_length) + "; computed = " + std::to_string(length)); | ||
| 883 | } | 808 | } |
| 884 | cur_object += nobjects; | 809 | cur_object += nobjects; |
| 885 | } | 810 | } |
| @@ -909,8 +834,7 @@ QPDF::checkHOutlines() | @@ -909,8 +834,7 @@ QPDF::checkHOutlines() | ||
| 909 | // This case is not exercised in test suite since not | 834 | // This case is not exercised in test suite since not |
| 910 | // permitted by the spec, but if this does occur, the | 835 | // permitted by the spec, but if this does occur, the |
| 911 | // code below would fail. | 836 | // code below would fail. |
| 912 | - linearizationWarning( | ||
| 913 | - "/Outlines key of root dictionary is not indirect"); | 837 | + linearizationWarning("/Outlines key of root dictionary is not indirect"); |
| 914 | return; | 838 | return; |
| 915 | } | 839 | } |
| 916 | QPDFObjGen og(outlines.getObjGen()); | 840 | QPDFObjGen og(outlines.getObjGen()); |
| @@ -920,20 +844,17 @@ QPDF::checkHOutlines() | @@ -920,20 +844,17 @@ QPDF::checkHOutlines() | ||
| 920 | qpdf_offset_t offset = getLinearizationOffset(og); | 844 | qpdf_offset_t offset = getLinearizationOffset(og); |
| 921 | ObjUser ou(ObjUser::ou_root_key, "/Outlines"); | 845 | ObjUser ou(ObjUser::ou_root_key, "/Outlines"); |
| 922 | int length = toI(maxEnd(ou) - offset); | 846 | int length = toI(maxEnd(ou) - offset); |
| 923 | - qpdf_offset_t table_offset = | ||
| 924 | - adjusted_offset(m->outline_hints.first_object_offset); | 847 | + qpdf_offset_t table_offset = adjusted_offset(m->outline_hints.first_object_offset); |
| 925 | if (offset != table_offset) { | 848 | if (offset != table_offset) { |
| 926 | linearizationWarning( | 849 | linearizationWarning( |
| 927 | "incorrect offset in outlines table: hint table = " + | 850 | "incorrect offset in outlines table: hint table = " + |
| 928 | - std::to_string(table_offset) + | ||
| 929 | - "; computed = " + std::to_string(offset)); | 851 | + std::to_string(table_offset) + "; computed = " + std::to_string(offset)); |
| 930 | } | 852 | } |
| 931 | int table_length = m->outline_hints.group_length; | 853 | int table_length = m->outline_hints.group_length; |
| 932 | if (length != table_length) { | 854 | if (length != table_length) { |
| 933 | linearizationWarning( | 855 | linearizationWarning( |
| 934 | "incorrect length in outlines table: hint table = " + | 856 | "incorrect length in outlines table: hint table = " + |
| 935 | - std::to_string(table_length) + | ||
| 936 | - "; computed = " + std::to_string(length)); | 857 | + std::to_string(table_length) + "; computed = " + std::to_string(length)); |
| 937 | } | 858 | } |
| 938 | } else { | 859 | } else { |
| 939 | linearizationWarning("incorrect first object number in outline " | 860 | linearizationWarning("incorrect first object number in outline " |
| @@ -962,12 +883,10 @@ QPDF::dumpLinearizationDataInternal() | @@ -962,12 +883,10 @@ QPDF::dumpLinearizationDataInternal() | ||
| 962 | *m->log->getInfo() << m->file->getName() << ": linearization data:\n\n"; | 883 | *m->log->getInfo() << m->file->getName() << ": linearization data:\n\n"; |
| 963 | 884 | ||
| 964 | *m->log->getInfo() << "file_size: " << m->linp.file_size << "\n" | 885 | *m->log->getInfo() << "file_size: " << m->linp.file_size << "\n" |
| 965 | - << "first_page_object: " << m->linp.first_page_object | ||
| 966 | - << "\n" | 886 | + << "first_page_object: " << m->linp.first_page_object << "\n" |
| 967 | << "first_page_end: " << m->linp.first_page_end << "\n" | 887 | << "first_page_end: " << m->linp.first_page_end << "\n" |
| 968 | << "npages: " << m->linp.npages << "\n" | 888 | << "npages: " << m->linp.npages << "\n" |
| 969 | - << "xref_zero_offset: " << m->linp.xref_zero_offset | ||
| 970 | - << "\n" | 889 | + << "xref_zero_offset: " << m->linp.xref_zero_offset << "\n" |
| 971 | << "first_page: " << m->linp.first_page << "\n" | 890 | << "first_page: " << m->linp.first_page << "\n" |
| 972 | << "H_offset: " << m->linp.H_offset << "\n" | 891 | << "H_offset: " << m->linp.H_offset << "\n" |
| 973 | << "H_length: " << m->linp.H_length << "\n" | 892 | << "H_length: " << m->linp.H_length << "\n" |
| @@ -1000,41 +919,37 @@ void | @@ -1000,41 +919,37 @@ void | ||
| 1000 | QPDF::dumpHPageOffset() | 919 | QPDF::dumpHPageOffset() |
| 1001 | { | 920 | { |
| 1002 | HPageOffset& t = m->page_offset_hints; | 921 | HPageOffset& t = m->page_offset_hints; |
| 1003 | - *m->log->getInfo() | ||
| 1004 | - << "min_nobjects: " << t.min_nobjects << "\n" | ||
| 1005 | - << "first_page_offset: " << adjusted_offset(t.first_page_offset) << "\n" | ||
| 1006 | - << "nbits_delta_nobjects: " << t.nbits_delta_nobjects << "\n" | ||
| 1007 | - << "min_page_length: " << t.min_page_length << "\n" | ||
| 1008 | - << "nbits_delta_page_length: " << t.nbits_delta_page_length << "\n" | ||
| 1009 | - << "min_content_offset: " << t.min_content_offset << "\n" | ||
| 1010 | - << "nbits_delta_content_offset: " << t.nbits_delta_content_offset | ||
| 1011 | - << "\n" | ||
| 1012 | - << "min_content_length: " << t.min_content_length << "\n" | ||
| 1013 | - << "nbits_delta_content_length: " << t.nbits_delta_content_length | ||
| 1014 | - << "\n" | ||
| 1015 | - << "nbits_nshared_objects: " << t.nbits_nshared_objects << "\n" | ||
| 1016 | - << "nbits_shared_identifier: " << t.nbits_shared_identifier << "\n" | ||
| 1017 | - << "nbits_shared_numerator: " << t.nbits_shared_numerator << "\n" | ||
| 1018 | - << "shared_denominator: " << t.shared_denominator << "\n"; | 922 | + *m->log->getInfo() << "min_nobjects: " << t.min_nobjects << "\n" |
| 923 | + << "first_page_offset: " << adjusted_offset(t.first_page_offset) << "\n" | ||
| 924 | + << "nbits_delta_nobjects: " << t.nbits_delta_nobjects << "\n" | ||
| 925 | + << "min_page_length: " << t.min_page_length << "\n" | ||
| 926 | + << "nbits_delta_page_length: " << t.nbits_delta_page_length << "\n" | ||
| 927 | + << "min_content_offset: " << t.min_content_offset << "\n" | ||
| 928 | + << "nbits_delta_content_offset: " << t.nbits_delta_content_offset << "\n" | ||
| 929 | + << "min_content_length: " << t.min_content_length << "\n" | ||
| 930 | + << "nbits_delta_content_length: " << t.nbits_delta_content_length << "\n" | ||
| 931 | + << "nbits_nshared_objects: " << t.nbits_nshared_objects << "\n" | ||
| 932 | + << "nbits_shared_identifier: " << t.nbits_shared_identifier << "\n" | ||
| 933 | + << "nbits_shared_numerator: " << t.nbits_shared_numerator << "\n" | ||
| 934 | + << "shared_denominator: " << t.shared_denominator << "\n"; | ||
| 1019 | 935 | ||
| 1020 | for (size_t i1 = 0; i1 < toS(m->linp.npages); ++i1) { | 936 | for (size_t i1 = 0; i1 < toS(m->linp.npages); ++i1) { |
| 1021 | HPageOffsetEntry& pe = t.entries.at(i1); | 937 | HPageOffsetEntry& pe = t.entries.at(i1); |
| 1022 | - *m->log->getInfo() | ||
| 1023 | - << "Page " << i1 << ":\n" | ||
| 1024 | - << " nobjects: " << pe.delta_nobjects + t.min_nobjects << "\n" | ||
| 1025 | - << " length: " << pe.delta_page_length + t.min_page_length | ||
| 1026 | - << "\n" | ||
| 1027 | - // content offset is relative to page, not file | ||
| 1028 | - << " content_offset: " | ||
| 1029 | - << pe.delta_content_offset + t.min_content_offset << "\n" | ||
| 1030 | - << " content_length: " | ||
| 1031 | - << pe.delta_content_length + t.min_content_length << "\n" | ||
| 1032 | - << " nshared_objects: " << pe.nshared_objects << "\n"; | 938 | + *m->log->getInfo() << "Page " << i1 << ":\n" |
| 939 | + << " nobjects: " << pe.delta_nobjects + t.min_nobjects << "\n" | ||
| 940 | + << " length: " << pe.delta_page_length + t.min_page_length | ||
| 941 | + << "\n" | ||
| 942 | + // content offset is relative to page, not file | ||
| 943 | + << " content_offset: " << pe.delta_content_offset + t.min_content_offset | ||
| 944 | + << "\n" | ||
| 945 | + << " content_length: " << pe.delta_content_length + t.min_content_length | ||
| 946 | + << "\n" | ||
| 947 | + << " nshared_objects: " << pe.nshared_objects << "\n"; | ||
| 1033 | for (size_t i2 = 0; i2 < toS(pe.nshared_objects); ++i2) { | 948 | for (size_t i2 = 0; i2 < toS(pe.nshared_objects); ++i2) { |
| 1034 | - *m->log->getInfo() << " identifier " << i2 << ": " | ||
| 1035 | - << pe.shared_identifiers.at(i2) << "\n"; | ||
| 1036 | - *m->log->getInfo() << " numerator " << i2 << ": " | ||
| 1037 | - << pe.shared_numerators.at(i2) << "\n"; | 949 | + *m->log->getInfo() << " identifier " << i2 << ": " << pe.shared_identifiers.at(i2) |
| 950 | + << "\n"; | ||
| 951 | + *m->log->getInfo() << " numerator " << i2 << ": " << pe.shared_numerators.at(i2) | ||
| 952 | + << "\n"; | ||
| 1038 | } | 953 | } |
| 1039 | } | 954 | } |
| 1040 | } | 955 | } |
| @@ -1044,20 +959,17 @@ QPDF::dumpHSharedObject() | @@ -1044,20 +959,17 @@ QPDF::dumpHSharedObject() | ||
| 1044 | { | 959 | { |
| 1045 | HSharedObject& t = m->shared_object_hints; | 960 | HSharedObject& t = m->shared_object_hints; |
| 1046 | *m->log->getInfo() << "first_shared_obj: " << t.first_shared_obj << "\n" | 961 | *m->log->getInfo() << "first_shared_obj: " << t.first_shared_obj << "\n" |
| 1047 | - << "first_shared_offset: " | ||
| 1048 | - << adjusted_offset(t.first_shared_offset) << "\n" | 962 | + << "first_shared_offset: " << adjusted_offset(t.first_shared_offset) << "\n" |
| 1049 | << "nshared_first_page: " << t.nshared_first_page << "\n" | 963 | << "nshared_first_page: " << t.nshared_first_page << "\n" |
| 1050 | << "nshared_total: " << t.nshared_total << "\n" | 964 | << "nshared_total: " << t.nshared_total << "\n" |
| 1051 | << "nbits_nobjects: " << t.nbits_nobjects << "\n" | 965 | << "nbits_nobjects: " << t.nbits_nobjects << "\n" |
| 1052 | << "min_group_length: " << t.min_group_length << "\n" | 966 | << "min_group_length: " << t.min_group_length << "\n" |
| 1053 | - << "nbits_delta_group_length: " | ||
| 1054 | - << t.nbits_delta_group_length << "\n"; | 967 | + << "nbits_delta_group_length: " << t.nbits_delta_group_length << "\n"; |
| 1055 | 968 | ||
| 1056 | for (size_t i = 0; i < toS(t.nshared_total); ++i) { | 969 | for (size_t i = 0; i < toS(t.nshared_total); ++i) { |
| 1057 | HSharedObjectEntry& se = t.entries.at(i); | 970 | HSharedObjectEntry& se = t.entries.at(i); |
| 1058 | *m->log->getInfo() << "Shared Object " << i << ":\n" | 971 | *m->log->getInfo() << "Shared Object " << i << ":\n" |
| 1059 | - << " group length: " | ||
| 1060 | - << se.delta_group_length + t.min_group_length | 972 | + << " group length: " << se.delta_group_length + t.min_group_length |
| 1061 | << "\n"; | 973 | << "\n"; |
| 1062 | // PDF spec says signature present nobjects_minus_one are | 974 | // PDF spec says signature present nobjects_minus_one are |
| 1063 | // always 0, so print them only if they have a non-zero value. | 975 | // always 0, so print them only if they have a non-zero value. |
| @@ -1065,8 +977,7 @@ QPDF::dumpHSharedObject() | @@ -1065,8 +977,7 @@ QPDF::dumpHSharedObject() | ||
| 1065 | *m->log->getInfo() << " signature present\n"; | 977 | *m->log->getInfo() << " signature present\n"; |
| 1066 | } | 978 | } |
| 1067 | if (se.nobjects_minus_one != 0) { | 979 | if (se.nobjects_minus_one != 0) { |
| 1068 | - *m->log->getInfo() | ||
| 1069 | - << " nobjects: " << se.nobjects_minus_one + 1 << "\n"; | 980 | + *m->log->getInfo() << " nobjects: " << se.nobjects_minus_one + 1 << "\n"; |
| 1070 | } | 981 | } |
| 1071 | } | 982 | } |
| 1072 | } | 983 | } |
| @@ -1075,8 +986,7 @@ void | @@ -1075,8 +986,7 @@ void | ||
| 1075 | QPDF::dumpHGeneric(HGeneric& t) | 986 | QPDF::dumpHGeneric(HGeneric& t) |
| 1076 | { | 987 | { |
| 1077 | *m->log->getInfo() << "first_object: " << t.first_object << "\n" | 988 | *m->log->getInfo() << "first_object: " << t.first_object << "\n" |
| 1078 | - << "first_object_offset: " | ||
| 1079 | - << adjusted_offset(t.first_object_offset) << "\n" | 989 | + << "first_object_offset: " << adjusted_offset(t.first_object_offset) << "\n" |
| 1080 | << "nobjects: " << t.nobjects << "\n" | 990 | << "nobjects: " << t.nobjects << "\n" |
| 1081 | << "group_length: " << t.group_length << "\n"; | 991 | << "group_length: " << t.group_length << "\n"; |
| 1082 | } | 992 | } |
| @@ -1094,9 +1004,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1094,9 +1004,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1094 | if (m->object_to_obj_users.empty()) { | 1004 | if (m->object_to_obj_users.empty()) { |
| 1095 | // Note that we can't call optimize here because we don't know | 1005 | // Note that we can't call optimize here because we don't know |
| 1096 | // whether it should be called with or without allow changes. | 1006 | // whether it should be called with or without allow changes. |
| 1097 | - throw std::logic_error( | ||
| 1098 | - "INTERNAL ERROR: QPDF::calculateLinearizationData " | ||
| 1099 | - "called before optimize()"); | 1007 | + throw std::logic_error("INTERNAL ERROR: QPDF::calculateLinearizationData " |
| 1008 | + "called before optimize()"); | ||
| 1100 | } | 1009 | } |
| 1101 | 1010 | ||
| 1102 | // Separate objects into the categories sufficient for us to | 1011 | // Separate objects into the categories sufficient for us to |
| @@ -1159,8 +1068,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1159,8 +1068,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1159 | QPDFObjectHandle root = getRoot(); | 1068 | QPDFObjectHandle root = getRoot(); |
| 1160 | bool outlines_in_first_page = false; | 1069 | bool outlines_in_first_page = false; |
| 1161 | QPDFObjectHandle pagemode = root.getKey("/PageMode"); | 1070 | QPDFObjectHandle pagemode = root.getKey("/PageMode"); |
| 1162 | - QTC::TC( | ||
| 1163 | - "qpdf", "QPDF categorize pagemode present", pagemode.isName() ? 1 : 0); | 1071 | + QTC::TC("qpdf", "QPDF categorize pagemode present", pagemode.isName() ? 1 : 0); |
| 1164 | if (pagemode.isName()) { | 1072 | if (pagemode.isName()) { |
| 1165 | if (pagemode.getName() == "/UseOutlines") { | 1073 | if (pagemode.getName() == "/UseOutlines") { |
| 1166 | if (root.hasKey("/Outlines")) { | 1074 | if (root.hasKey("/Outlines")) { |
| @@ -1169,10 +1077,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1169,10 +1077,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1169 | QTC::TC("qpdf", "QPDF UseOutlines but no Outlines"); | 1077 | QTC::TC("qpdf", "QPDF UseOutlines but no Outlines"); |
| 1170 | } | 1078 | } |
| 1171 | } | 1079 | } |
| 1172 | - QTC::TC( | ||
| 1173 | - "qpdf", | ||
| 1174 | - "QPDF categorize pagemode outlines", | ||
| 1175 | - outlines_in_first_page ? 1 : 0); | 1080 | + QTC::TC("qpdf", "QPDF categorize pagemode outlines", outlines_in_first_page ? 1 : 0); |
| 1176 | } | 1081 | } |
| 1177 | 1082 | ||
| 1178 | std::set<std::string> open_document_keys; | 1083 | std::set<std::string> open_document_keys; |
| @@ -1254,9 +1159,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1254,9 +1159,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1254 | lc_outlines.insert(og); | 1159 | lc_outlines.insert(og); |
| 1255 | } else if (in_open_document) { | 1160 | } else if (in_open_document) { |
| 1256 | lc_open_document.insert(og); | 1161 | lc_open_document.insert(og); |
| 1257 | - } else if ( | ||
| 1258 | - (in_first_page) && (others == 0) && (other_pages == 0) && | ||
| 1259 | - (thumbs == 0)) { | 1162 | + } else if ((in_first_page) && (others == 0) && (other_pages == 0) && (thumbs == 0)) { |
| 1260 | lc_first_page_private.insert(og); | 1163 | lc_first_page_private.insert(og); |
| 1261 | } else if (in_first_page) { | 1164 | } else if (in_first_page) { |
| 1262 | lc_first_page_shared.insert(og); | 1165 | lc_first_page_shared.insert(og); |
| @@ -1335,9 +1238,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1335,9 +1238,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1335 | } | 1238 | } |
| 1336 | QPDFObjGen first_page_og(pages.at(0).getObjGen()); | 1239 | QPDFObjGen first_page_og(pages.at(0).getObjGen()); |
| 1337 | if (!lc_first_page_private.count(first_page_og)) { | 1240 | if (!lc_first_page_private.count(first_page_og)) { |
| 1338 | - stopOnError( | ||
| 1339 | - "INTERNAL ERROR: QPDF::calculateLinearizationData: first page " | ||
| 1340 | - "object not in lc_first_page_private"); | 1241 | + stopOnError("INTERNAL ERROR: QPDF::calculateLinearizationData: first page " |
| 1242 | + "object not in lc_first_page_private"); | ||
| 1341 | } | 1243 | } |
| 1342 | lc_first_page_private.erase(first_page_og); | 1244 | lc_first_page_private.erase(first_page_og); |
| 1343 | m->c_linp.first_page_object = pages.at(0).getObjectID(); | 1245 | m->c_linp.first_page_object = pages.at(0).getObjectID(); |
| @@ -1405,10 +1307,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1405,10 +1307,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1405 | } | 1307 | } |
| 1406 | // That should have covered all part7 objects. | 1308 | // That should have covered all part7 objects. |
| 1407 | if (!lc_other_page_private.empty()) { | 1309 | if (!lc_other_page_private.empty()) { |
| 1408 | - stopOnError( | ||
| 1409 | - "INTERNAL ERROR:" | ||
| 1410 | - " QPDF::calculateLinearizationData: lc_other_page_private is " | ||
| 1411 | - "not empty after generation of part7"); | 1310 | + stopOnError("INTERNAL ERROR:" |
| 1311 | + " QPDF::calculateLinearizationData: lc_other_page_private is " | ||
| 1312 | + "not empty after generation of part7"); | ||
| 1412 | } | 1313 | } |
| 1413 | 1314 | ||
| 1414 | // Part 8: other pages' shared objects | 1315 | // Part 8: other pages' shared objects |
| @@ -1461,8 +1362,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1461,8 +1362,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1461 | // having been in some set other than | 1362 | // having been in some set other than |
| 1462 | // lc_thumbnail_private. | 1363 | // lc_thumbnail_private. |
| 1463 | } | 1364 | } |
| 1464 | - std::set<QPDFObjGen>& ogs = | ||
| 1465 | - m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))]; | 1365 | + std::set<QPDFObjGen>& ogs = m->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))]; |
| 1466 | for (auto const& og: ogs) { | 1366 | for (auto const& og: ogs) { |
| 1467 | if (lc_thumbnail_private.count(og)) { | 1367 | if (lc_thumbnail_private.count(og)) { |
| 1468 | lc_thumbnail_private.erase(og); | 1368 | lc_thumbnail_private.erase(og); |
| @@ -1494,15 +1394,14 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1494,15 +1394,14 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1494 | 1394 | ||
| 1495 | // Make sure we got everything exactly once. | 1395 | // Make sure we got everything exactly once. |
| 1496 | 1396 | ||
| 1497 | - size_t num_placed = m->part4.size() + m->part6.size() + m->part7.size() + | ||
| 1498 | - m->part8.size() + m->part9.size(); | 1397 | + size_t num_placed = |
| 1398 | + m->part4.size() + m->part6.size() + m->part7.size() + m->part8.size() + m->part9.size(); | ||
| 1499 | size_t num_wanted = m->object_to_obj_users.size(); | 1399 | size_t num_wanted = m->object_to_obj_users.size(); |
| 1500 | if (num_placed != num_wanted) { | 1400 | if (num_placed != num_wanted) { |
| 1501 | stopOnError( | 1401 | stopOnError( |
| 1502 | "INTERNAL ERROR: QPDF::calculateLinearizationData: wrong " | 1402 | "INTERNAL ERROR: QPDF::calculateLinearizationData: wrong " |
| 1503 | "number of objects placed (num_placed = " + | 1403 | "number of objects placed (num_placed = " + |
| 1504 | - std::to_string(num_placed) + | ||
| 1505 | - "; number of objects: " + std::to_string(num_wanted)); | 1404 | + std::to_string(num_placed) + "; number of objects: " + std::to_string(num_wanted)); |
| 1506 | } | 1405 | } |
| 1507 | 1406 | ||
| 1508 | // Calculate shared object hint table information including | 1407 | // Calculate shared object hint table information including |
| @@ -1553,8 +1452,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1553,8 +1452,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1553 | " calculating linearization data"); | 1452 | " calculating linearization data"); |
| 1554 | } | 1453 | } |
| 1555 | for (auto const& og: m->obj_user_to_objects[ou]) { | 1454 | for (auto const& og: m->obj_user_to_objects[ou]) { |
| 1556 | - if ((m->object_to_obj_users[og].size() > 1) && | ||
| 1557 | - (obj_to_index.count(og.getObj()) > 0)) { | 1455 | + if ((m->object_to_obj_users[og].size() > 1) && (obj_to_index.count(og.getObj()) > 0)) { |
| 1558 | int idx = obj_to_index[og.getObj()]; | 1456 | int idx = obj_to_index[og.getObj()]; |
| 1559 | ++pe.nshared_objects; | 1457 | ++pe.nshared_objects; |
| 1560 | pe.shared_identifiers.push_back(idx); | 1458 | pe.shared_identifiers.push_back(idx); |
| @@ -1663,8 +1561,8 @@ QPDF::calculateHPageOffset( | @@ -1663,8 +1561,8 @@ QPDF::calculateHPageOffset( | ||
| 1663 | 1561 | ||
| 1664 | int min_nobjects = cphe.at(0).nobjects; | 1562 | int min_nobjects = cphe.at(0).nobjects; |
| 1665 | int max_nobjects = min_nobjects; | 1563 | int max_nobjects = min_nobjects; |
| 1666 | - int min_length = outputLengthNextN( | ||
| 1667 | - pages.at(0).getObjectID(), min_nobjects, lengths, obj_renumber); | 1564 | + int min_length = |
| 1565 | + outputLengthNextN(pages.at(0).getObjectID(), min_nobjects, lengths, obj_renumber); | ||
| 1668 | int max_length = min_length; | 1566 | int max_length = min_length; |
| 1669 | int max_shared = cphe.at(0).nshared_objects; | 1567 | int max_shared = cphe.at(0).nshared_objects; |
| 1670 | 1568 | ||
| @@ -1681,8 +1579,7 @@ QPDF::calculateHPageOffset( | @@ -1681,8 +1579,7 @@ QPDF::calculateHPageOffset( | ||
| 1681 | // without duplicating those assignments. | 1579 | // without duplicating those assignments. |
| 1682 | 1580 | ||
| 1683 | int nobjects = cphe.at(i).nobjects; | 1581 | int nobjects = cphe.at(i).nobjects; |
| 1684 | - int length = outputLengthNextN( | ||
| 1685 | - pages.at(i).getObjectID(), nobjects, lengths, obj_renumber); | 1582 | + int length = outputLengthNextN(pages.at(i).getObjectID(), nobjects, lengths, obj_renumber); |
| 1686 | int nshared = cphe.at(i).nshared_objects; | 1583 | int nshared = cphe.at(i).nshared_objects; |
| 1687 | 1584 | ||
| 1688 | min_nobjects = std::min(min_nobjects, nobjects); | 1585 | min_nobjects = std::min(min_nobjects, nobjects); |
| @@ -1727,8 +1624,7 @@ QPDF::calculateHPageOffset( | @@ -1727,8 +1624,7 @@ QPDF::calculateHPageOffset( | ||
| 1727 | phe.at(i).delta_content_length = phe.at(i).delta_page_length; | 1624 | phe.at(i).delta_content_length = phe.at(i).delta_page_length; |
| 1728 | 1625 | ||
| 1729 | for (size_t j = 0; j < toS(cphe.at(i).nshared_objects); ++j) { | 1626 | for (size_t j = 0; j < toS(cphe.at(i).nshared_objects); ++j) { |
| 1730 | - phe.at(i).shared_identifiers.push_back( | ||
| 1731 | - cphe.at(i).shared_identifiers.at(j)); | 1627 | + phe.at(i).shared_identifiers.push_back(cphe.at(i).shared_identifiers.at(j)); |
| 1732 | phe.at(i).shared_numerators.push_back(0); | 1628 | phe.at(i).shared_numerators.push_back(0); |
| 1733 | } | 1629 | } |
| 1734 | } | 1630 | } |
| @@ -1746,14 +1642,12 @@ QPDF::calculateHSharedObject( | @@ -1746,14 +1642,12 @@ QPDF::calculateHSharedObject( | ||
| 1746 | std::vector<HSharedObjectEntry>& soe = so.entries; | 1642 | std::vector<HSharedObjectEntry>& soe = so.entries; |
| 1747 | soe.clear(); | 1643 | soe.clear(); |
| 1748 | 1644 | ||
| 1749 | - int min_length = | ||
| 1750 | - outputLengthNextN(csoe.at(0).object, 1, lengths, obj_renumber); | 1645 | + int min_length = outputLengthNextN(csoe.at(0).object, 1, lengths, obj_renumber); |
| 1751 | int max_length = min_length; | 1646 | int max_length = min_length; |
| 1752 | 1647 | ||
| 1753 | for (size_t i = 0; i < toS(cso.nshared_total); ++i) { | 1648 | for (size_t i = 0; i < toS(cso.nshared_total); ++i) { |
| 1754 | // Assign absolute numbers to deltas; adjust later | 1649 | // Assign absolute numbers to deltas; adjust later |
| 1755 | - int length = | ||
| 1756 | - outputLengthNextN(csoe.at(i).object, 1, lengths, obj_renumber); | 1650 | + int length = outputLengthNextN(csoe.at(i).object, 1, lengths, obj_renumber); |
| 1757 | min_length = std::min(min_length, length); | 1651 | min_length = std::min(min_length, length); |
| 1758 | max_length = std::max(max_length, length); | 1652 | max_length = std::max(max_length, length); |
| 1759 | soe.push_back(HSharedObjectEntry()); | 1653 | soe.push_back(HSharedObjectEntry()); |
| @@ -1766,10 +1660,8 @@ QPDF::calculateHSharedObject( | @@ -1766,10 +1660,8 @@ QPDF::calculateHSharedObject( | ||
| 1766 | so.nshared_total = cso.nshared_total; | 1660 | so.nshared_total = cso.nshared_total; |
| 1767 | so.nshared_first_page = cso.nshared_first_page; | 1661 | so.nshared_first_page = cso.nshared_first_page; |
| 1768 | if (so.nshared_total > so.nshared_first_page) { | 1662 | if (so.nshared_total > so.nshared_first_page) { |
| 1769 | - so.first_shared_obj = | ||
| 1770 | - (*(obj_renumber.find(cso.first_shared_obj))).second; | ||
| 1771 | - so.first_shared_offset = | ||
| 1772 | - (*(xref.find(so.first_shared_obj))).second.getOffset(); | 1663 | + so.first_shared_obj = (*(obj_renumber.find(cso.first_shared_obj))).second; |
| 1664 | + so.first_shared_offset = (*(xref.find(so.first_shared_obj))).second.getOffset(); | ||
| 1773 | } | 1665 | } |
| 1774 | so.min_group_length = min_length; | 1666 | so.min_group_length = min_length; |
| 1775 | so.nbits_delta_group_length = nbits(max_length - min_length); | 1667 | so.nbits_delta_group_length = nbits(max_length - min_length); |
| @@ -1801,21 +1693,18 @@ QPDF::calculateHOutline( | @@ -1801,21 +1693,18 @@ QPDF::calculateHOutline( | ||
| 1801 | ho.first_object = (*(obj_renumber.find(cho.first_object))).second; | 1693 | ho.first_object = (*(obj_renumber.find(cho.first_object))).second; |
| 1802 | ho.first_object_offset = (*(xref.find(ho.first_object))).second.getOffset(); | 1694 | ho.first_object_offset = (*(xref.find(ho.first_object))).second.getOffset(); |
| 1803 | ho.nobjects = cho.nobjects; | 1695 | ho.nobjects = cho.nobjects; |
| 1804 | - ho.group_length = | ||
| 1805 | - outputLengthNextN(cho.first_object, ho.nobjects, lengths, obj_renumber); | 1696 | + ho.group_length = outputLengthNextN(cho.first_object, ho.nobjects, lengths, obj_renumber); |
| 1806 | } | 1697 | } |
| 1807 | 1698 | ||
| 1808 | template <class T, class int_type> | 1699 | template <class T, class int_type> |
| 1809 | static void | 1700 | static void |
| 1810 | -write_vector_int( | ||
| 1811 | - BitWriter& w, int nitems, std::vector<T>& vec, int bits, int_type T::*field) | 1701 | +write_vector_int(BitWriter& w, int nitems, std::vector<T>& vec, int bits, int_type T::*field) |
| 1812 | { | 1702 | { |
| 1813 | // nitems times, write bits bits from the given field of the ith | 1703 | // nitems times, write bits bits from the given field of the ith |
| 1814 | // vector to the given bit writer. | 1704 | // vector to the given bit writer. |
| 1815 | 1705 | ||
| 1816 | for (size_t i = 0; i < QIntC::to_size(nitems); ++i) { | 1706 | for (size_t i = 0; i < QIntC::to_size(nitems); ++i) { |
| 1817 | - w.writeBits( | ||
| 1818 | - QIntC::to_ulonglong(vec.at(i).*field), QIntC::to_size(bits)); | 1707 | + w.writeBits(QIntC::to_ulonglong(vec.at(i).*field), QIntC::to_size(bits)); |
| 1819 | } | 1708 | } |
| 1820 | // The PDF spec says that each hint table starts at a byte | 1709 | // The PDF spec says that each hint table starts at a byte |
| 1821 | // boundary. Each "row" actually must start on a byte boundary. | 1710 | // boundary. Each "row" actually must start on a byte boundary. |
| @@ -1836,9 +1725,7 @@ write_vector_vector( | @@ -1836,9 +1725,7 @@ write_vector_vector( | ||
| 1836 | // from the vec2 vector field of the ith item of vec1. | 1725 | // from the vec2 vector field of the ith item of vec1. |
| 1837 | for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1) { | 1726 | for (size_t i1 = 0; i1 < QIntC::to_size(nitems1); ++i1) { |
| 1838 | for (size_t i2 = 0; i2 < QIntC::to_size(vec1.at(i1).*nitems2); ++i2) { | 1727 | for (size_t i2 = 0; i2 < QIntC::to_size(vec1.at(i1).*nitems2); ++i2) { |
| 1839 | - w.writeBits( | ||
| 1840 | - QIntC::to_ulonglong((vec1.at(i1).*vec2).at(i2)), | ||
| 1841 | - QIntC::to_size(bits)); | 1728 | + w.writeBits(QIntC::to_ulonglong((vec1.at(i1).*vec2).at(i2)), QIntC::to_size(bits)); |
| 1842 | } | 1729 | } |
| 1843 | } | 1730 | } |
| 1844 | w.flush(); | 1731 | w.flush(); |
| @@ -1866,24 +1753,11 @@ QPDF::writeHPageOffset(BitWriter& w) | @@ -1866,24 +1753,11 @@ QPDF::writeHPageOffset(BitWriter& w) | ||
| 1866 | int nitems = toI(getAllPages().size()); | 1753 | int nitems = toI(getAllPages().size()); |
| 1867 | std::vector<HPageOffsetEntry>& entries = t.entries; | 1754 | std::vector<HPageOffsetEntry>& entries = t.entries; |
| 1868 | 1755 | ||
| 1756 | + write_vector_int(w, nitems, entries, t.nbits_delta_nobjects, &HPageOffsetEntry::delta_nobjects); | ||
| 1869 | write_vector_int( | 1757 | write_vector_int( |
| 1870 | - w, | ||
| 1871 | - nitems, | ||
| 1872 | - entries, | ||
| 1873 | - t.nbits_delta_nobjects, | ||
| 1874 | - &HPageOffsetEntry::delta_nobjects); | ||
| 1875 | - write_vector_int( | ||
| 1876 | - w, | ||
| 1877 | - nitems, | ||
| 1878 | - entries, | ||
| 1879 | - t.nbits_delta_page_length, | ||
| 1880 | - &HPageOffsetEntry::delta_page_length); | 1758 | + w, nitems, entries, t.nbits_delta_page_length, &HPageOffsetEntry::delta_page_length); |
| 1881 | write_vector_int( | 1759 | write_vector_int( |
| 1882 | - w, | ||
| 1883 | - nitems, | ||
| 1884 | - entries, | ||
| 1885 | - t.nbits_nshared_objects, | ||
| 1886 | - &HPageOffsetEntry::nshared_objects); | 1760 | + w, nitems, entries, t.nbits_nshared_objects, &HPageOffsetEntry::nshared_objects); |
| 1887 | write_vector_vector( | 1761 | write_vector_vector( |
| 1888 | w, | 1762 | w, |
| 1889 | nitems, | 1763 | nitems, |
| @@ -1899,17 +1773,9 @@ QPDF::writeHPageOffset(BitWriter& w) | @@ -1899,17 +1773,9 @@ QPDF::writeHPageOffset(BitWriter& w) | ||
| 1899 | t.nbits_shared_numerator, | 1773 | t.nbits_shared_numerator, |
| 1900 | &HPageOffsetEntry::shared_numerators); | 1774 | &HPageOffsetEntry::shared_numerators); |
| 1901 | write_vector_int( | 1775 | write_vector_int( |
| 1902 | - w, | ||
| 1903 | - nitems, | ||
| 1904 | - entries, | ||
| 1905 | - t.nbits_delta_content_offset, | ||
| 1906 | - &HPageOffsetEntry::delta_content_offset); | 1776 | + w, nitems, entries, t.nbits_delta_content_offset, &HPageOffsetEntry::delta_content_offset); |
| 1907 | write_vector_int( | 1777 | write_vector_int( |
| 1908 | - w, | ||
| 1909 | - nitems, | ||
| 1910 | - entries, | ||
| 1911 | - t.nbits_delta_content_length, | ||
| 1912 | - &HPageOffsetEntry::delta_content_length); | 1778 | + w, nitems, entries, t.nbits_delta_content_length, &HPageOffsetEntry::delta_content_length); |
| 1913 | } | 1779 | } |
| 1914 | 1780 | ||
| 1915 | void | 1781 | void |
| @@ -1934,13 +1800,8 @@ QPDF::writeHSharedObject(BitWriter& w) | @@ -1934,13 +1800,8 @@ QPDF::writeHSharedObject(BitWriter& w) | ||
| 1934 | std::vector<HSharedObjectEntry>& entries = t.entries; | 1800 | std::vector<HSharedObjectEntry>& entries = t.entries; |
| 1935 | 1801 | ||
| 1936 | write_vector_int( | 1802 | write_vector_int( |
| 1937 | - w, | ||
| 1938 | - nitems, | ||
| 1939 | - entries, | ||
| 1940 | - t.nbits_delta_group_length, | ||
| 1941 | - &HSharedObjectEntry::delta_group_length); | ||
| 1942 | - write_vector_int( | ||
| 1943 | - w, nitems, entries, 1, &HSharedObjectEntry::signature_present); | 1803 | + w, nitems, entries, t.nbits_delta_group_length, &HSharedObjectEntry::delta_group_length); |
| 1804 | + write_vector_int(w, nitems, entries, 1, &HSharedObjectEntry::signature_present); | ||
| 1944 | for (size_t i = 0; i < toS(nitems); ++i) { | 1805 | for (size_t i = 0; i < toS(nitems); ++i) { |
| 1945 | // If signature were present, we'd have to write a 128-bit hash. | 1806 | // If signature were present, we'd have to write a 128-bit hash. |
| 1946 | if (entries.at(i).signature_present != 0) { | 1807 | if (entries.at(i).signature_present != 0) { |
| @@ -1948,12 +1809,7 @@ QPDF::writeHSharedObject(BitWriter& w) | @@ -1948,12 +1809,7 @@ QPDF::writeHSharedObject(BitWriter& w) | ||
| 1948 | " while writing linearization data"); | 1809 | " while writing linearization data"); |
| 1949 | } | 1810 | } |
| 1950 | } | 1811 | } |
| 1951 | - write_vector_int( | ||
| 1952 | - w, | ||
| 1953 | - nitems, | ||
| 1954 | - entries, | ||
| 1955 | - t.nbits_nobjects, | ||
| 1956 | - &HSharedObjectEntry::nobjects_minus_one); | 1812 | + write_vector_int(w, nitems, entries, t.nbits_nobjects, &HSharedObjectEntry::nobjects_minus_one); |
| 1957 | } | 1813 | } |
| 1958 | 1814 | ||
| 1959 | void | 1815 | void |
libqpdf/QPDF_optimization.cc
| @@ -109,9 +109,7 @@ QPDF::optimize( | @@ -109,9 +109,7 @@ QPDF::optimize( | ||
| 109 | // time to time, so this is almost certain not to cause any | 109 | // time to time, so this is almost certain not to cause any |
| 110 | // problems. | 110 | // problems. |
| 111 | updateObjectMaps( | 111 | updateObjectMaps( |
| 112 | - ObjUser(ObjUser::ou_root_key, key), | ||
| 113 | - root.getKey(key), | ||
| 114 | - skip_stream_parameters); | 112 | + ObjUser(ObjUser::ou_root_key, key), root.getKey(key), skip_stream_parameters); |
| 115 | } | 113 | } |
| 116 | 114 | ||
| 117 | ObjUser root_ou = ObjUser(ObjUser::ou_root); | 115 | ObjUser root_ou = ObjUser(ObjUser::ou_root); |
| @@ -177,8 +175,8 @@ QPDF::pushInheritedAttributesToPageInternal( | @@ -177,8 +175,8 @@ QPDF::pushInheritedAttributesToPageInternal( | ||
| 177 | 175 | ||
| 178 | std::set<std::string> inheritable_keys; | 176 | std::set<std::string> inheritable_keys; |
| 179 | for (auto const& key: cur_pages.getKeys()) { | 177 | for (auto const& key: cur_pages.getKeys()) { |
| 180 | - if ((key == "/MediaBox") || (key == "/CropBox") || | ||
| 181 | - (key == "/Resources") || (key == "/Rotate")) { | 178 | + if ((key == "/MediaBox") || (key == "/CropBox") || (key == "/Resources") || |
| 179 | + (key == "/Rotate")) { | ||
| 182 | if (!allow_changes) { | 180 | if (!allow_changes) { |
| 183 | throw QPDFExc( | 181 | throw QPDFExc( |
| 184 | qpdf_e_internal, | 182 | qpdf_e_internal, |
| @@ -193,10 +191,7 @@ QPDF::pushInheritedAttributesToPageInternal( | @@ -193,10 +191,7 @@ QPDF::pushInheritedAttributesToPageInternal( | ||
| 193 | // This is an inheritable resource | 191 | // This is an inheritable resource |
| 194 | inheritable_keys.insert(key); | 192 | inheritable_keys.insert(key); |
| 195 | QPDFObjectHandle oh = cur_pages.getKey(key); | 193 | QPDFObjectHandle oh = cur_pages.getKey(key); |
| 196 | - QTC::TC( | ||
| 197 | - "qpdf", | ||
| 198 | - "QPDF opt direct pages resource", | ||
| 199 | - oh.isIndirect() ? 0 : 1); | 194 | + QTC::TC("qpdf", "QPDF opt direct pages resource", oh.isIndirect() ? 0 : 1); |
| 200 | if (!oh.isIndirect()) { | 195 | if (!oh.isIndirect()) { |
| 201 | if (!oh.isScalar()) { | 196 | if (!oh.isScalar()) { |
| 202 | // Replace shared direct object non-scalar | 197 | // Replace shared direct object non-scalar |
| @@ -216,8 +211,8 @@ QPDF::pushInheritedAttributesToPageInternal( | @@ -216,8 +211,8 @@ QPDF::pushInheritedAttributesToPageInternal( | ||
| 216 | // Remove this resource from this node. It will be | 211 | // Remove this resource from this node. It will be |
| 217 | // reattached at the page level. | 212 | // reattached at the page level. |
| 218 | cur_pages.removeKey(key); | 213 | cur_pages.removeKey(key); |
| 219 | - } else if (!((key == "/Type") || (key == "/Parent") || | ||
| 220 | - (key == "/Kids") || (key == "/Count"))) { | 214 | + } else if (!((key == "/Type") || (key == "/Parent") || (key == "/Kids") || |
| 215 | + (key == "/Count"))) { | ||
| 221 | // Warn when flattening, but not if the key is at the top | 216 | // Warn when flattening, but not if the key is at the top |
| 222 | // level (i.e. "/Parent" not set), as we don't change these; | 217 | // level (i.e. "/Parent" not set), as we don't change these; |
| 223 | // but flattening removes intermediate /Pages nodes. | 218 | // but flattening removes intermediate /Pages nodes. |
| @@ -349,17 +344,12 @@ QPDF::updateObjectMapsInternal( | @@ -349,17 +344,12 @@ QPDF::updateObjectMapsInternal( | ||
| 349 | // Don't traverse back up the page tree | 344 | // Don't traverse back up the page tree |
| 350 | } else if ( | 345 | } else if ( |
| 351 | ((ssp >= 1) && (key == "/Length")) || | 346 | ((ssp >= 1) && (key == "/Length")) || |
| 352 | - ((ssp >= 2) && | ||
| 353 | - ((key == "/Filter") || (key == "/DecodeParms")))) { | 347 | + ((ssp >= 2) && ((key == "/Filter") || (key == "/DecodeParms")))) { |
| 354 | // Don't traverse into stream parameters that we are | 348 | // Don't traverse into stream parameters that we are |
| 355 | // not going to write. | 349 | // not going to write. |
| 356 | } else { | 350 | } else { |
| 357 | updateObjectMapsInternal( | 351 | updateObjectMapsInternal( |
| 358 | - ou, | ||
| 359 | - dict.getKey(key), | ||
| 360 | - skip_stream_parameters, | ||
| 361 | - visited, | ||
| 362 | - false); | 352 | + ou, dict.getKey(key), skip_stream_parameters, visited, false); |
| 363 | } | 353 | } |
| 364 | } | 354 | } |
| 365 | } | 355 | } |
libqpdf/QPDF_pages.cc
| @@ -69,9 +69,8 @@ QPDF::getAllPages() | @@ -69,9 +69,8 @@ QPDF::getAllPages() | ||
| 69 | // catalog points to the first page. Try to work around | 69 | // catalog points to the first page. Try to work around |
| 70 | // this and similar cases with this heuristic. | 70 | // this and similar cases with this heuristic. |
| 71 | if (!warned) { | 71 | if (!warned) { |
| 72 | - getRoot().warnIfPossible( | ||
| 73 | - "document page tree root (root -> /Pages) doesn't point" | ||
| 74 | - " to the root of the page tree; attempting to correct"); | 72 | + getRoot().warnIfPossible("document page tree root (root -> /Pages) doesn't point" |
| 73 | + " to the root of the page tree; attempting to correct"); | ||
| 75 | warned = true; | 74 | warned = true; |
| 76 | } | 75 | } |
| 77 | changed_pages = true; | 76 | changed_pages = true; |
| @@ -102,8 +101,7 @@ QPDF::getAllPagesInternal( | @@ -102,8 +101,7 @@ QPDF::getAllPagesInternal( | ||
| 102 | "Loop detected in /Pages structure (getAllPages)"); | 101 | "Loop detected in /Pages structure (getAllPages)"); |
| 103 | } | 102 | } |
| 104 | if (!cur_node.isDictionaryOfType("/Pages")) { | 103 | if (!cur_node.isDictionaryOfType("/Pages")) { |
| 105 | - cur_node.warnIfPossible( | ||
| 106 | - "/Type key should be /Pages but is not; overriding"); | 104 | + cur_node.warnIfPossible("/Type key should be /Pages but is not; overriding"); |
| 107 | cur_node.replaceKey("/Type", "/Pages"_qpdf); | 105 | cur_node.replaceKey("/Type", "/Pages"_qpdf); |
| 108 | } | 106 | } |
| 109 | auto kids = cur_node.getKey("/Kids"); | 107 | auto kids = cur_node.getKey("/Kids"); |
| @@ -116,8 +114,7 @@ QPDF::getAllPagesInternal( | @@ -116,8 +114,7 @@ QPDF::getAllPagesInternal( | ||
| 116 | if (!kid.isIndirect()) { | 114 | if (!kid.isIndirect()) { |
| 117 | QTC::TC("qpdf", "QPDF handle direct page object"); | 115 | QTC::TC("qpdf", "QPDF handle direct page object"); |
| 118 | cur_node.warnIfPossible( | 116 | cur_node.warnIfPossible( |
| 119 | - "kid " + std::to_string(i) + | ||
| 120 | - " (from 0) is direct; converting to indirect"); | 117 | + "kid " + std::to_string(i) + " (from 0) is direct; converting to indirect"); |
| 121 | kid = makeIndirectObject(kid); | 118 | kid = makeIndirectObject(kid); |
| 122 | kids.setArrayItem(i, kid); | 119 | kids.setArrayItem(i, kid); |
| 123 | } else if (!seen.add(kid)) { | 120 | } else if (!seen.add(kid)) { |
| @@ -133,8 +130,7 @@ QPDF::getAllPagesInternal( | @@ -133,8 +130,7 @@ QPDF::getAllPagesInternal( | ||
| 133 | kids.setArrayItem(i, kid); | 130 | kids.setArrayItem(i, kid); |
| 134 | } | 131 | } |
| 135 | if (!kid.isDictionaryOfType("/Page")) { | 132 | if (!kid.isDictionaryOfType("/Page")) { |
| 136 | - kid.warnIfPossible( | ||
| 137 | - "/Type key should be /Page but is not; overriding"); | 133 | + kid.warnIfPossible("/Type key should be /Page but is not; overriding"); |
| 138 | kid.replaceKey("/Type", "/Page"_qpdf); | 134 | kid.replaceKey("/Type", "/Page"_qpdf); |
| 139 | } | 135 | } |
| 140 | m->all_pages.push_back(kid); | 136 | m->all_pages.push_back(kid); |
| @@ -190,16 +186,14 @@ QPDF::flattenPagesTree() | @@ -190,16 +186,14 @@ QPDF::flattenPagesTree() | ||
| 190 | } | 186 | } |
| 191 | 187 | ||
| 192 | void | 188 | void |
| 193 | -QPDF::insertPageobjToPage( | ||
| 194 | - QPDFObjectHandle const& obj, int pos, bool check_duplicate) | 189 | +QPDF::insertPageobjToPage(QPDFObjectHandle const& obj, int pos, bool check_duplicate) |
| 195 | { | 190 | { |
| 196 | QPDFObjGen og(obj.getObjGen()); | 191 | QPDFObjGen og(obj.getObjGen()); |
| 197 | if (check_duplicate) { | 192 | if (check_duplicate) { |
| 198 | if (!m->pageobj_to_pages_pos.insert(std::make_pair(og, pos)).second) { | 193 | if (!m->pageobj_to_pages_pos.insert(std::make_pair(og, pos)).second) { |
| 199 | // The library never calls insertPageobjToPage in a way | 194 | // The library never calls insertPageobjToPage in a way |
| 200 | // that causes this to happen. | 195 | // that causes this to happen. |
| 201 | - setLastObjectDescription( | ||
| 202 | - "page " + std::to_string(pos) + " (numbered from zero)", og); | 196 | + setLastObjectDescription("page " + std::to_string(pos) + " (numbered from zero)", og); |
| 203 | throw QPDFExc( | 197 | throw QPDFExc( |
| 204 | qpdf_e_pages, | 198 | qpdf_e_pages, |
| 205 | m->file->getName(), | 199 | m->file->getName(), |
| @@ -233,8 +227,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) | @@ -233,8 +227,7 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) | ||
| 233 | } | 227 | } |
| 234 | 228 | ||
| 235 | if ((pos < 0) || (toS(pos) > m->all_pages.size())) { | 229 | if ((pos < 0) || (toS(pos) > m->all_pages.size())) { |
| 236 | - throw std::runtime_error( | ||
| 237 | - "QPDF::insertPage called with pos out of range"); | 230 | + throw std::runtime_error("QPDF::insertPage called with pos out of range"); |
| 238 | } | 231 | } |
| 239 | 232 | ||
| 240 | QTC::TC( | 233 | QTC::TC( |
| @@ -306,9 +299,7 @@ QPDF::addPage(QPDFObjectHandle newpage, bool first) | @@ -306,9 +299,7 @@ QPDF::addPage(QPDFObjectHandle newpage, bool first) | ||
| 306 | if (first) { | 299 | if (first) { |
| 307 | insertPage(newpage, 0); | 300 | insertPage(newpage, 0); |
| 308 | } else { | 301 | } else { |
| 309 | - insertPage( | ||
| 310 | - newpage, | ||
| 311 | - getRoot().getKey("/Pages").getKey("/Count").getIntValueAsInt()); | 302 | + insertPage(newpage, getRoot().getKey("/Pages").getKey("/Count").getIntValueAsInt()); |
| 312 | } | 303 | } |
| 313 | } | 304 | } |
| 314 | 305 |
libqpdf/QUtil.cc
| @@ -255,56 +255,41 @@ static unsigned short mac_roman_to_unicode[] = { | @@ -255,56 +255,41 @@ static unsigned short mac_roman_to_unicode[] = { | ||
| 255 | }; | 255 | }; |
| 256 | 256 | ||
| 257 | static std::map<unsigned long, unsigned char> unicode_to_win_ansi = { | 257 | static std::map<unsigned long, unsigned char> unicode_to_win_ansi = { |
| 258 | - {0x20ac, 0x80}, {0x201a, 0x82}, {0x192, 0x83}, {0x201e, 0x84}, | ||
| 259 | - {0x2026, 0x85}, {0x2020, 0x86}, {0x2021, 0x87}, {0x2c6, 0x88}, | ||
| 260 | - {0x2030, 0x89}, {0x160, 0x8a}, {0x2039, 0x8b}, {0x152, 0x8c}, | ||
| 261 | - {0x17d, 0x8e}, {0x2018, 0x91}, {0x2019, 0x92}, {0x201c, 0x93}, | ||
| 262 | - {0x201d, 0x94}, {0x2022, 0x95}, {0x2013, 0x96}, {0x2014, 0x97}, | ||
| 263 | - {0x303, 0x98}, {0x2122, 0x99}, {0x161, 0x9a}, {0x203a, 0x9b}, | 258 | + {0x20ac, 0x80}, {0x201a, 0x82}, {0x192, 0x83}, {0x201e, 0x84}, {0x2026, 0x85}, {0x2020, 0x86}, |
| 259 | + {0x2021, 0x87}, {0x2c6, 0x88}, {0x2030, 0x89}, {0x160, 0x8a}, {0x2039, 0x8b}, {0x152, 0x8c}, | ||
| 260 | + {0x17d, 0x8e}, {0x2018, 0x91}, {0x2019, 0x92}, {0x201c, 0x93}, {0x201d, 0x94}, {0x2022, 0x95}, | ||
| 261 | + {0x2013, 0x96}, {0x2014, 0x97}, {0x303, 0x98}, {0x2122, 0x99}, {0x161, 0x9a}, {0x203a, 0x9b}, | ||
| 264 | {0x153, 0x9c}, {0x17e, 0x9e}, {0x178, 0x9f}, {0xa0, 0xa0}, | 262 | {0x153, 0x9c}, {0x17e, 0x9e}, {0x178, 0x9f}, {0xa0, 0xa0}, |
| 265 | }; | 263 | }; |
| 266 | static std::map<unsigned long, unsigned char> unicode_to_mac_roman = { | 264 | static std::map<unsigned long, unsigned char> unicode_to_mac_roman = { |
| 267 | - {0xc4, 0x80}, {0xc5, 0x81}, {0xc7, 0x82}, {0xc9, 0x83}, | ||
| 268 | - {0xd1, 0x84}, {0xd6, 0x85}, {0xdc, 0x86}, {0xe1, 0x87}, | ||
| 269 | - {0xe0, 0x88}, {0xe2, 0x89}, {0xe4, 0x8a}, {0xe3, 0x8b}, | ||
| 270 | - {0xe5, 0x8c}, {0xe7, 0x8d}, {0xe9, 0x8e}, {0xe8, 0x8f}, | ||
| 271 | - {0xea, 0x90}, {0xeb, 0x91}, {0xed, 0x92}, {0xec, 0x93}, | ||
| 272 | - {0xee, 0x94}, {0xef, 0x95}, {0xf1, 0x96}, {0xf3, 0x97}, | ||
| 273 | - {0xf2, 0x98}, {0xf4, 0x99}, {0xf6, 0x9a}, {0xf5, 0x9b}, | ||
| 274 | - {0xfa, 0x9c}, {0xf9, 0x9d}, {0xfb, 0x9e}, {0xfc, 0x9f}, | ||
| 275 | - {0x2020, 0xa0}, {0xb0, 0xa1}, {0xa2, 0xa2}, {0xa3, 0xa3}, | ||
| 276 | - {0xa7, 0xa4}, {0x2022, 0xa5}, {0xb6, 0xa6}, {0xdf, 0xa7}, | ||
| 277 | - {0xae, 0xa8}, {0xa9, 0xa9}, {0x2122, 0xaa}, {0x301, 0xab}, | ||
| 278 | - {0x308, 0xac}, {0xc6, 0xae}, {0xd8, 0xaf}, {0xb1, 0xb1}, | ||
| 279 | - {0xa5, 0xb4}, {0x3bc, 0xb5}, {0x1d43, 0xbb}, {0x1d52, 0xbc}, | ||
| 280 | - {0xe6, 0xbe}, {0xf8, 0xbf}, {0xbf, 0xc0}, {0xa1, 0xc1}, | ||
| 281 | - {0xac, 0xc2}, {0x192, 0xc4}, {0xab, 0xc7}, {0xbb, 0xc8}, | ||
| 282 | - {0x2026, 0xc9}, {0xc0, 0xcb}, {0xc3, 0xcc}, {0xd5, 0xcd}, | ||
| 283 | - {0x152, 0xce}, {0x153, 0xcf}, {0x2013, 0xd0}, {0x2014, 0xd1}, | ||
| 284 | - {0x201c, 0xd2}, {0x201d, 0xd3}, {0x2018, 0xd4}, {0x2019, 0xd5}, | ||
| 285 | - {0xf7, 0xd6}, {0xff, 0xd8}, {0x178, 0xd9}, {0x2044, 0xda}, | ||
| 286 | - {0xa4, 0xdb}, {0x2039, 0xdc}, {0x203a, 0xdd}, {0xfb01, 0xde}, | ||
| 287 | - {0xfb02, 0xdf}, {0x2021, 0xe0}, {0xb7, 0xe1}, {0x201a, 0xe2}, | ||
| 288 | - {0x201e, 0xe3}, {0x2030, 0xe4}, {0xc2, 0xe5}, {0xca, 0xe6}, | ||
| 289 | - {0xc1, 0xe7}, {0xcb, 0xe8}, {0xc8, 0xe9}, {0xcd, 0xea}, | ||
| 290 | - {0xce, 0xeb}, {0xcf, 0xec}, {0xcc, 0xed}, {0xd3, 0xee}, | ||
| 291 | - {0xd4, 0xef}, {0xd2, 0xf1}, {0xda, 0xf2}, {0xdb, 0xf3}, | ||
| 292 | - {0xd9, 0xf4}, {0x131, 0xf5}, {0x2c6, 0xf6}, {0x303, 0xf7}, | ||
| 293 | - {0x304, 0xf8}, {0x306, 0xf9}, {0x307, 0xfa}, {0x30a, 0xfb}, | 265 | + {0xc4, 0x80}, {0xc5, 0x81}, {0xc7, 0x82}, {0xc9, 0x83}, {0xd1, 0x84}, {0xd6, 0x85}, |
| 266 | + {0xdc, 0x86}, {0xe1, 0x87}, {0xe0, 0x88}, {0xe2, 0x89}, {0xe4, 0x8a}, {0xe3, 0x8b}, | ||
| 267 | + {0xe5, 0x8c}, {0xe7, 0x8d}, {0xe9, 0x8e}, {0xe8, 0x8f}, {0xea, 0x90}, {0xeb, 0x91}, | ||
| 268 | + {0xed, 0x92}, {0xec, 0x93}, {0xee, 0x94}, {0xef, 0x95}, {0xf1, 0x96}, {0xf3, 0x97}, | ||
| 269 | + {0xf2, 0x98}, {0xf4, 0x99}, {0xf6, 0x9a}, {0xf5, 0x9b}, {0xfa, 0x9c}, {0xf9, 0x9d}, | ||
| 270 | + {0xfb, 0x9e}, {0xfc, 0x9f}, {0x2020, 0xa0}, {0xb0, 0xa1}, {0xa2, 0xa2}, {0xa3, 0xa3}, | ||
| 271 | + {0xa7, 0xa4}, {0x2022, 0xa5}, {0xb6, 0xa6}, {0xdf, 0xa7}, {0xae, 0xa8}, {0xa9, 0xa9}, | ||
| 272 | + {0x2122, 0xaa}, {0x301, 0xab}, {0x308, 0xac}, {0xc6, 0xae}, {0xd8, 0xaf}, {0xb1, 0xb1}, | ||
| 273 | + {0xa5, 0xb4}, {0x3bc, 0xb5}, {0x1d43, 0xbb}, {0x1d52, 0xbc}, {0xe6, 0xbe}, {0xf8, 0xbf}, | ||
| 274 | + {0xbf, 0xc0}, {0xa1, 0xc1}, {0xac, 0xc2}, {0x192, 0xc4}, {0xab, 0xc7}, {0xbb, 0xc8}, | ||
| 275 | + {0x2026, 0xc9}, {0xc0, 0xcb}, {0xc3, 0xcc}, {0xd5, 0xcd}, {0x152, 0xce}, {0x153, 0xcf}, | ||
| 276 | + {0x2013, 0xd0}, {0x2014, 0xd1}, {0x201c, 0xd2}, {0x201d, 0xd3}, {0x2018, 0xd4}, {0x2019, 0xd5}, | ||
| 277 | + {0xf7, 0xd6}, {0xff, 0xd8}, {0x178, 0xd9}, {0x2044, 0xda}, {0xa4, 0xdb}, {0x2039, 0xdc}, | ||
| 278 | + {0x203a, 0xdd}, {0xfb01, 0xde}, {0xfb02, 0xdf}, {0x2021, 0xe0}, {0xb7, 0xe1}, {0x201a, 0xe2}, | ||
| 279 | + {0x201e, 0xe3}, {0x2030, 0xe4}, {0xc2, 0xe5}, {0xca, 0xe6}, {0xc1, 0xe7}, {0xcb, 0xe8}, | ||
| 280 | + {0xc8, 0xe9}, {0xcd, 0xea}, {0xce, 0xeb}, {0xcf, 0xec}, {0xcc, 0xed}, {0xd3, 0xee}, | ||
| 281 | + {0xd4, 0xef}, {0xd2, 0xf1}, {0xda, 0xf2}, {0xdb, 0xf3}, {0xd9, 0xf4}, {0x131, 0xf5}, | ||
| 282 | + {0x2c6, 0xf6}, {0x303, 0xf7}, {0x304, 0xf8}, {0x306, 0xf9}, {0x307, 0xfa}, {0x30a, 0xfb}, | ||
| 294 | {0x327, 0xfc}, {0x30b, 0xfd}, {0x328, 0xfe}, {0x2c7, 0xff}, | 283 | {0x327, 0xfc}, {0x30b, 0xfd}, {0x328, 0xfe}, {0x2c7, 0xff}, |
| 295 | }; | 284 | }; |
| 296 | static std::map<unsigned long, unsigned char> unicode_to_pdf_doc = { | 285 | static std::map<unsigned long, unsigned char> unicode_to_pdf_doc = { |
| 297 | - {0x02d8, 0x18}, {0x02c7, 0x19}, {0x02c6, 0x1a}, {0x02d9, 0x1b}, | ||
| 298 | - {0x02dd, 0x1c}, {0x02db, 0x1d}, {0x02da, 0x1e}, {0x02dc, 0x1f}, | ||
| 299 | - {0x2022, 0x80}, {0x2020, 0x81}, {0x2021, 0x82}, {0x2026, 0x83}, | ||
| 300 | - {0x2014, 0x84}, {0x2013, 0x85}, {0x0192, 0x86}, {0x2044, 0x87}, | ||
| 301 | - {0x2039, 0x88}, {0x203a, 0x89}, {0x2212, 0x8a}, {0x2030, 0x8b}, | ||
| 302 | - {0x201e, 0x8c}, {0x201c, 0x8d}, {0x201d, 0x8e}, {0x2018, 0x8f}, | ||
| 303 | - {0x2019, 0x90}, {0x201a, 0x91}, {0x2122, 0x92}, {0xfb01, 0x93}, | ||
| 304 | - {0xfb02, 0x94}, {0x0141, 0x95}, {0x0152, 0x96}, {0x0160, 0x97}, | ||
| 305 | - {0x0178, 0x98}, {0x017d, 0x99}, {0x0131, 0x9a}, {0x0142, 0x9b}, | ||
| 306 | - {0x0153, 0x9c}, {0x0161, 0x9d}, {0x017e, 0x9e}, {0xfffd, 0x9f}, | ||
| 307 | - {0x20ac, 0xa0}, | 286 | + {0x02d8, 0x18}, {0x02c7, 0x19}, {0x02c6, 0x1a}, {0x02d9, 0x1b}, {0x02dd, 0x1c}, {0x02db, 0x1d}, |
| 287 | + {0x02da, 0x1e}, {0x02dc, 0x1f}, {0x2022, 0x80}, {0x2020, 0x81}, {0x2021, 0x82}, {0x2026, 0x83}, | ||
| 288 | + {0x2014, 0x84}, {0x2013, 0x85}, {0x0192, 0x86}, {0x2044, 0x87}, {0x2039, 0x88}, {0x203a, 0x89}, | ||
| 289 | + {0x2212, 0x8a}, {0x2030, 0x8b}, {0x201e, 0x8c}, {0x201c, 0x8d}, {0x201d, 0x8e}, {0x2018, 0x8f}, | ||
| 290 | + {0x2019, 0x90}, {0x201a, 0x91}, {0x2122, 0x92}, {0xfb01, 0x93}, {0xfb02, 0x94}, {0x0141, 0x95}, | ||
| 291 | + {0x0152, 0x96}, {0x0160, 0x97}, {0x0178, 0x98}, {0x017d, 0x99}, {0x0131, 0x9a}, {0x0142, 0x9b}, | ||
| 292 | + {0x0153, 0x9c}, {0x0161, 0x9d}, {0x017e, 0x9e}, {0xfffd, 0x9f}, {0x20ac, 0xa0}, | ||
| 308 | }; | 293 | }; |
| 309 | 294 | ||
| 310 | template <typename T> | 295 | template <typename T> |
| @@ -316,8 +301,7 @@ int_to_string_base_internal(T num, int base, int length) | @@ -316,8 +301,7 @@ int_to_string_base_internal(T num, int base, int length) | ||
| 316 | // such that a negative value appends spaces and a positive value | 301 | // such that a negative value appends spaces and a positive value |
| 317 | // prepends zeroes. | 302 | // prepends zeroes. |
| 318 | if (!((base == 8) || (base == 10) || (base == 16))) { | 303 | if (!((base == 8) || (base == 10) || (base == 16))) { |
| 319 | - throw std::logic_error( | ||
| 320 | - "int_to_string_base called with unsupported base"); | 304 | + throw std::logic_error("int_to_string_base called with unsupported base"); |
| 321 | } | 305 | } |
| 322 | std::string cvt; | 306 | std::string cvt; |
| 323 | if (base == 10) { | 307 | if (base == 10) { |
| @@ -366,8 +350,7 @@ QUtil::uint_to_string_base(unsigned long long num, int base, int length) | @@ -366,8 +350,7 @@ QUtil::uint_to_string_base(unsigned long long num, int base, int length) | ||
| 366 | } | 350 | } |
| 367 | 351 | ||
| 368 | std::string | 352 | std::string |
| 369 | -QUtil::double_to_string( | ||
| 370 | - double num, int decimal_places, bool trim_trailing_zeroes) | 353 | +QUtil::double_to_string(double num, int decimal_places, bool trim_trailing_zeroes) |
| 371 | { | 354 | { |
| 372 | // Backward compatibility -- this code used to use sprintf and | 355 | // Backward compatibility -- this code used to use sprintf and |
| 373 | // treated decimal_places <= 0 to mean to use the default, which | 356 | // treated decimal_places <= 0 to mean to use the default, which |
| @@ -402,8 +385,7 @@ QUtil::string_to_ll(char const* str) | @@ -402,8 +385,7 @@ QUtil::string_to_ll(char const* str) | ||
| 402 | #endif | 385 | #endif |
| 403 | if (errno == ERANGE) { | 386 | if (errno == ERANGE) { |
| 404 | throw std::range_error( | 387 | throw std::range_error( |
| 405 | - std::string("overflow/underflow converting ") + str + | ||
| 406 | - " to 64-bit integer"); | 388 | + std::string("overflow/underflow converting ") + str + " to 64-bit integer"); |
| 407 | } | 389 | } |
| 408 | return result; | 390 | return result; |
| 409 | } | 391 | } |
| @@ -424,8 +406,7 @@ QUtil::string_to_ull(char const* str) | @@ -424,8 +406,7 @@ QUtil::string_to_ull(char const* str) | ||
| 424 | } | 406 | } |
| 425 | if (*p == '-') { | 407 | if (*p == '-') { |
| 426 | throw std::runtime_error( | 408 | throw std::runtime_error( |
| 427 | - std::string("underflow converting ") + str + | ||
| 428 | - " to 64-bit unsigned integer"); | 409 | + std::string("underflow converting ") + str + " to 64-bit unsigned integer"); |
| 429 | } | 410 | } |
| 430 | 411 | ||
| 431 | errno = 0; | 412 | errno = 0; |
| @@ -436,8 +417,7 @@ QUtil::string_to_ull(char const* str) | @@ -436,8 +417,7 @@ QUtil::string_to_ull(char const* str) | ||
| 436 | #endif | 417 | #endif |
| 437 | if (errno == ERANGE) { | 418 | if (errno == ERANGE) { |
| 438 | throw std::runtime_error( | 419 | throw std::runtime_error( |
| 439 | - std::string("overflow converting ") + str + | ||
| 440 | - " to 64-bit unsigned integer"); | 420 | + std::string("overflow converting ") + str + " to 64-bit unsigned integer"); |
| 441 | } | 421 | } |
| 442 | return result; | 422 | return result; |
| 443 | } | 423 | } |
| @@ -567,10 +547,7 @@ int | @@ -567,10 +547,7 @@ int | ||
| 567 | QUtil::seek(FILE* stream, qpdf_offset_t offset, int whence) | 547 | QUtil::seek(FILE* stream, qpdf_offset_t offset, int whence) |
| 568 | { | 548 | { |
| 569 | #if HAVE_FSEEKO | 549 | #if HAVE_FSEEKO |
| 570 | - return fseeko( | ||
| 571 | - stream, | ||
| 572 | - QIntC::IntConverter<qpdf_offset_t, off_t>::convert(offset), | ||
| 573 | - whence); | 550 | + return fseeko(stream, QIntC::IntConverter<qpdf_offset_t, off_t>::convert(offset), whence); |
| 574 | #elif HAVE_FSEEKO64 | 551 | #elif HAVE_FSEEKO64 |
| 575 | return fseeko64(stream, offset, whence); | 552 | return fseeko64(stream, offset, whence); |
| 576 | #else | 553 | #else |
| @@ -601,37 +578,22 @@ QUtil::tell(FILE* stream) | @@ -601,37 +578,22 @@ QUtil::tell(FILE* stream) | ||
| 601 | bool | 578 | bool |
| 602 | QUtil::same_file(char const* name1, char const* name2) | 579 | QUtil::same_file(char const* name1, char const* name2) |
| 603 | { | 580 | { |
| 604 | - if ((name1 == nullptr) || (strlen(name1) == 0) || (name2 == nullptr) || | ||
| 605 | - (strlen(name2) == 0)) { | 581 | + if ((name1 == nullptr) || (strlen(name1) == 0) || (name2 == nullptr) || (strlen(name2) == 0)) { |
| 606 | return false; | 582 | return false; |
| 607 | } | 583 | } |
| 608 | #ifdef _WIN32 | 584 | #ifdef _WIN32 |
| 609 | bool same = false; | 585 | bool same = false; |
| 610 | # ifndef AVOID_WINDOWS_HANDLE | 586 | # ifndef AVOID_WINDOWS_HANDLE |
| 611 | HANDLE fh1 = CreateFile( | 587 | HANDLE fh1 = CreateFile( |
| 612 | - name1, | ||
| 613 | - GENERIC_READ, | ||
| 614 | - FILE_SHARE_READ, | ||
| 615 | - NULL, | ||
| 616 | - OPEN_EXISTING, | ||
| 617 | - FILE_ATTRIBUTE_NORMAL, | ||
| 618 | - NULL); | 588 | + name1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 619 | HANDLE fh2 = CreateFile( | 589 | HANDLE fh2 = CreateFile( |
| 620 | - name2, | ||
| 621 | - GENERIC_READ, | ||
| 622 | - FILE_SHARE_READ, | ||
| 623 | - NULL, | ||
| 624 | - OPEN_EXISTING, | ||
| 625 | - FILE_ATTRIBUTE_NORMAL, | ||
| 626 | - NULL); | 590 | + name2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 627 | BY_HANDLE_FILE_INFORMATION fi1; | 591 | BY_HANDLE_FILE_INFORMATION fi1; |
| 628 | BY_HANDLE_FILE_INFORMATION fi2; | 592 | BY_HANDLE_FILE_INFORMATION fi2; |
| 629 | if ((fh1 != INVALID_HANDLE_VALUE) && (fh2 != INVALID_HANDLE_VALUE) && | 593 | if ((fh1 != INVALID_HANDLE_VALUE) && (fh2 != INVALID_HANDLE_VALUE) && |
| 630 | - GetFileInformationByHandle(fh1, &fi1) && | ||
| 631 | - GetFileInformationByHandle(fh2, &fi2) && | 594 | + GetFileInformationByHandle(fh1, &fi1) && GetFileInformationByHandle(fh2, &fi2) && |
| 632 | (fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber) && | 595 | (fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber) && |
| 633 | - (fi1.nFileIndexLow == fi2.nFileIndexLow) && | ||
| 634 | - (fi1.nFileIndexHigh == fi2.nFileIndexHigh)) { | 596 | + (fi1.nFileIndexLow == fi2.nFileIndexLow) && (fi1.nFileIndexHigh == fi2.nFileIndexHigh)) { |
| 635 | same = true; | 597 | same = true; |
| 636 | } | 598 | } |
| 637 | if (fh1 != INVALID_HANDLE_VALUE) { | 599 | if (fh1 != INVALID_HANDLE_VALUE) { |
| @@ -645,8 +607,8 @@ QUtil::same_file(char const* name1, char const* name2) | @@ -645,8 +607,8 @@ QUtil::same_file(char const* name1, char const* name2) | ||
| 645 | #else | 607 | #else |
| 646 | struct stat st1; | 608 | struct stat st1; |
| 647 | struct stat st2; | 609 | struct stat st2; |
| 648 | - if ((stat(name1, &st1) == 0) && (stat(name2, &st2) == 0) && | ||
| 649 | - (st1.st_ino == st2.st_ino) && (st1.st_dev == st2.st_dev)) { | 610 | + if ((stat(name1, &st1) == 0) && (stat(name2, &st2) == 0) && (st1.st_ino == st2.st_ino) && |
| 611 | + (st1.st_dev == st2.st_dev)) { | ||
| 650 | return true; | 612 | return true; |
| 651 | } | 613 | } |
| 652 | #endif | 614 | #endif |
| @@ -675,13 +637,9 @@ QUtil::rename_file(char const* oldname, char const* newname) | @@ -675,13 +637,9 @@ QUtil::rename_file(char const* oldname, char const* newname) | ||
| 675 | } | 637 | } |
| 676 | std::shared_ptr<wchar_t> wold = win_convert_filename(oldname); | 638 | std::shared_ptr<wchar_t> wold = win_convert_filename(oldname); |
| 677 | std::shared_ptr<wchar_t> wnew = win_convert_filename(newname); | 639 | std::shared_ptr<wchar_t> wnew = win_convert_filename(newname); |
| 678 | - os_wrapper( | ||
| 679 | - std::string("rename ") + oldname + " " + newname, | ||
| 680 | - _wrename(wold.get(), wnew.get())); | 640 | + os_wrapper(std::string("rename ") + oldname + " " + newname, _wrename(wold.get(), wnew.get())); |
| 681 | #else | 641 | #else |
| 682 | - os_wrapper( | ||
| 683 | - std::string("rename ") + oldname + " " + newname, | ||
| 684 | - rename(oldname, newname)); | 642 | + os_wrapper(std::string("rename ") + oldname + " " + newname, rename(oldname, newname)); |
| 685 | #endif | 643 | #endif |
| 686 | } | 644 | } |
| 687 | 645 | ||
| @@ -699,8 +657,7 @@ QUtil::pipe_file(char const* filename, Pipeline* p) | @@ -699,8 +657,7 @@ QUtil::pipe_file(char const* filename, Pipeline* p) | ||
| 699 | } | 657 | } |
| 700 | p->finish(); | 658 | p->finish(); |
| 701 | if (ferror(f)) { | 659 | if (ferror(f)) { |
| 702 | - throw std::runtime_error( | ||
| 703 | - std::string("failure reading file ") + filename); | 660 | + throw std::runtime_error(std::string("failure reading file ") + filename); |
| 704 | } | 661 | } |
| 705 | } | 662 | } |
| 706 | 663 | ||
| @@ -843,8 +800,7 @@ QUtil::getWhoami(char* argv0) | @@ -843,8 +800,7 @@ QUtil::getWhoami(char* argv0) | ||
| 843 | ++whoami; | 800 | ++whoami; |
| 844 | } | 801 | } |
| 845 | 802 | ||
| 846 | - if ((strlen(whoami) > 4) && | ||
| 847 | - (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0)) { | 803 | + if ((strlen(whoami) > 4) && (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0)) { |
| 848 | whoami[strlen(whoami) - 4] = '\0'; | 804 | whoami[strlen(whoami) - 4] = '\0'; |
| 849 | } | 805 | } |
| 850 | 806 | ||
| @@ -974,15 +930,12 @@ QUtil::qpdf_time_to_pdf_time(QPDFTime const& qtm) | @@ -974,15 +930,12 @@ QUtil::qpdf_time_to_pdf_time(QPDFTime const& qtm) | ||
| 974 | } else { | 930 | } else { |
| 975 | tz_offset += "-"; | 931 | tz_offset += "-"; |
| 976 | } | 932 | } |
| 977 | - tz_offset += QUtil::int_to_string(t / 60, 2) + "'" + | ||
| 978 | - QUtil::int_to_string(t % 60, 2) + "'"; | 933 | + tz_offset += QUtil::int_to_string(t / 60, 2) + "'" + QUtil::int_to_string(t % 60, 2) + "'"; |
| 979 | } | 934 | } |
| 980 | return ( | 935 | return ( |
| 981 | - "D:" + QUtil::int_to_string(qtm.year, 4) + | ||
| 982 | - QUtil::int_to_string(qtm.month, 2) + QUtil::int_to_string(qtm.day, 2) + | ||
| 983 | - QUtil::int_to_string(qtm.hour, 2) + | ||
| 984 | - QUtil::int_to_string(qtm.minute, 2) + | ||
| 985 | - QUtil::int_to_string(qtm.second, 2) + tz_offset); | 936 | + "D:" + QUtil::int_to_string(qtm.year, 4) + QUtil::int_to_string(qtm.month, 2) + |
| 937 | + QUtil::int_to_string(qtm.day, 2) + QUtil::int_to_string(qtm.hour, 2) + | ||
| 938 | + QUtil::int_to_string(qtm.minute, 2) + QUtil::int_to_string(qtm.second, 2) + tz_offset); | ||
| 986 | } | 939 | } |
| 987 | 940 | ||
| 988 | std::string | 941 | std::string |
| @@ -999,16 +952,13 @@ QUtil::qpdf_time_to_iso8601(QPDFTime const& qtm) | @@ -999,16 +952,13 @@ QUtil::qpdf_time_to_iso8601(QPDFTime const& qtm) | ||
| 999 | } else { | 952 | } else { |
| 1000 | tz_offset += "-"; | 953 | tz_offset += "-"; |
| 1001 | } | 954 | } |
| 1002 | - tz_offset += QUtil::int_to_string(t / 60, 2) + ":" + | ||
| 1003 | - QUtil::int_to_string(t % 60, 2); | 955 | + tz_offset += QUtil::int_to_string(t / 60, 2) + ":" + QUtil::int_to_string(t % 60, 2); |
| 1004 | } | 956 | } |
| 1005 | return ( | 957 | return ( |
| 1006 | - QUtil::int_to_string(qtm.year, 4) + "-" + | ||
| 1007 | - QUtil::int_to_string(qtm.month, 2) + "-" + | ||
| 1008 | - QUtil::int_to_string(qtm.day, 2) + "T" + | ||
| 1009 | - QUtil::int_to_string(qtm.hour, 2) + ":" + | ||
| 1010 | - QUtil::int_to_string(qtm.minute, 2) + ":" + | ||
| 1011 | - QUtil::int_to_string(qtm.second, 2) + tz_offset); | 958 | + QUtil::int_to_string(qtm.year, 4) + "-" + QUtil::int_to_string(qtm.month, 2) + "-" + |
| 959 | + QUtil::int_to_string(qtm.day, 2) + "T" + QUtil::int_to_string(qtm.hour, 2) + ":" + | ||
| 960 | + QUtil::int_to_string(qtm.minute, 2) + ":" + QUtil::int_to_string(qtm.second, 2) + | ||
| 961 | + tz_offset); | ||
| 1012 | } | 962 | } |
| 1013 | 963 | ||
| 1014 | bool | 964 | bool |
| @@ -1022,9 +972,7 @@ QUtil::pdf_time_to_qpdf_time(std::string const& str, QPDFTime* qtm) | @@ -1022,9 +972,7 @@ QUtil::pdf_time_to_qpdf_time(std::string const& str, QPDFTime* qtm) | ||
| 1022 | return false; | 972 | return false; |
| 1023 | } | 973 | } |
| 1024 | int tz_delta = 0; | 974 | int tz_delta = 0; |
| 1025 | - auto to_i = [](std::string const& s) { | ||
| 1026 | - return QUtil::string_to_int(s.c_str()); | ||
| 1027 | - }; | 975 | + auto to_i = [](std::string const& s) { return QUtil::string_to_int(s.c_str()); }; |
| 1028 | 976 | ||
| 1029 | if (m[8] != "") { | 977 | if (m[8] != "") { |
| 1030 | tz_delta = ((to_i(m[9]) * 60) + to_i(m[10])); | 978 | 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) | @@ -1034,13 +982,7 @@ QUtil::pdf_time_to_qpdf_time(std::string const& str, QPDFTime* qtm) | ||
| 1034 | } | 982 | } |
| 1035 | if (qtm) { | 983 | if (qtm) { |
| 1036 | *qtm = QPDFTime( | 984 | *qtm = QPDFTime( |
| 1037 | - to_i(m[1]), | ||
| 1038 | - to_i(m[2]), | ||
| 1039 | - to_i(m[3]), | ||
| 1040 | - to_i(m[4]), | ||
| 1041 | - to_i(m[5]), | ||
| 1042 | - to_i(m[6]), | ||
| 1043 | - tz_delta); | 985 | + 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); |
| 1044 | } | 986 | } |
| 1045 | return true; | 987 | return true; |
| 1046 | } | 988 | } |
| @@ -1098,8 +1040,7 @@ QUtil::toUTF8(unsigned long uval) | @@ -1098,8 +1040,7 @@ QUtil::toUTF8(unsigned long uval) | ||
| 1098 | } | 1040 | } |
| 1099 | // If maxval is k bits long, the high (7 - k) bits of the | 1041 | // If maxval is k bits long, the high (7 - k) bits of the |
| 1100 | // resulting byte must be high. | 1042 | // resulting byte must be high. |
| 1101 | - *cur_byte = static_cast<unsigned char>( | ||
| 1102 | - QIntC::to_ulong(0xff - (1 + (maxval << 1))) + uval); | 1043 | + *cur_byte = static_cast<unsigned char>(QIntC::to_ulong(0xff - (1 + (maxval << 1))) + uval); |
| 1103 | 1044 | ||
| 1104 | result += reinterpret_cast<char*>(cur_byte); | 1045 | result += reinterpret_cast<char*>(cur_byte); |
| 1105 | } | 1046 | } |
| @@ -1121,10 +1062,8 @@ QUtil::toUTF16(unsigned long uval) | @@ -1121,10 +1062,8 @@ QUtil::toUTF16(unsigned long uval) | ||
| 1121 | } else if (uval <= 0x10ffff) { | 1062 | } else if (uval <= 0x10ffff) { |
| 1122 | char out[4]; | 1063 | char out[4]; |
| 1123 | uval -= 0x10000; | 1064 | uval -= 0x10000; |
| 1124 | - unsigned short high = | ||
| 1125 | - static_cast<unsigned short>(((uval & 0xffc00) >> 10) + 0xd800); | ||
| 1126 | - unsigned short low = | ||
| 1127 | - static_cast<unsigned short>((uval & 0x3ff) + 0xdc00); | 1065 | + unsigned short high = static_cast<unsigned short>(((uval & 0xffc00) >> 10) + 0xd800); |
| 1066 | + unsigned short low = static_cast<unsigned short>((uval & 0x3ff) + 0xdc00); | ||
| 1128 | out[0] = static_cast<char>((high & 0xff00) >> 8); | 1067 | out[0] = static_cast<char>((high & 0xff00) >> 8); |
| 1129 | out[1] = static_cast<char>(high & 0xff); | 1068 | out[1] = static_cast<char>(high & 0xff); |
| 1130 | out[2] = static_cast<char>((low & 0xff00) >> 8); | 1069 | out[2] = static_cast<char>((low & 0xff00) >> 8); |
| @@ -1203,14 +1142,12 @@ long | @@ -1203,14 +1142,12 @@ long | ||
| 1203 | QUtil::random() | 1142 | QUtil::random() |
| 1204 | { | 1143 | { |
| 1205 | long result = 0L; | 1144 | long result = 0L; |
| 1206 | - initializeWithRandomBytes( | ||
| 1207 | - reinterpret_cast<unsigned char*>(&result), sizeof(result)); | 1145 | + initializeWithRandomBytes(reinterpret_cast<unsigned char*>(&result), sizeof(result)); |
| 1208 | return result; | 1146 | return result; |
| 1209 | } | 1147 | } |
| 1210 | 1148 | ||
| 1211 | void | 1149 | void |
| 1212 | -QUtil::read_file_into_memory( | ||
| 1213 | - char const* filename, std::shared_ptr<char>& file_buf, size_t& size) | 1150 | +QUtil::read_file_into_memory(char const* filename, std::shared_ptr<char>& file_buf, size_t& size) |
| 1214 | { | 1151 | { |
| 1215 | FILE* f = safe_fopen(filename, "rb"); | 1152 | FILE* f = safe_fopen(filename, "rb"); |
| 1216 | FileCloser fc(f); | 1153 | FileCloser fc(f); |
| @@ -1227,14 +1164,12 @@ QUtil::read_file_into_memory( | @@ -1227,14 +1164,12 @@ QUtil::read_file_into_memory( | ||
| 1227 | if (bytes_read != size) { | 1164 | if (bytes_read != size) { |
| 1228 | if (ferror(f)) { | 1165 | if (ferror(f)) { |
| 1229 | throw std::runtime_error( | 1166 | throw std::runtime_error( |
| 1230 | - std::string("failure reading file ") + filename + | ||
| 1231 | - " into memory: read " + uint_to_string(bytes_read) + | ||
| 1232 | - "; wanted " + uint_to_string(size)); | 1167 | + std::string("failure reading file ") + filename + " into memory: read " + |
| 1168 | + uint_to_string(bytes_read) + "; wanted " + uint_to_string(size)); | ||
| 1233 | } else { | 1169 | } else { |
| 1234 | throw std::runtime_error( | 1170 | throw std::runtime_error( |
| 1235 | - std::string("premature eof reading file ") + filename + | ||
| 1236 | - " into memory: read " + uint_to_string(bytes_read) + | ||
| 1237 | - "; wanted " + uint_to_string(size)); | 1171 | + std::string("premature eof reading file ") + filename + " into memory: read " + |
| 1172 | + uint_to_string(bytes_read) + "; wanted " + uint_to_string(size)); | ||
| 1238 | } | 1173 | } |
| 1239 | } | 1174 | } |
| 1240 | } | 1175 | } |
| @@ -1258,13 +1193,11 @@ QUtil::read_file_into_string(FILE* f, std::string_view filename) | @@ -1258,13 +1193,11 @@ QUtil::read_file_into_string(FILE* f, std::string_view filename) | ||
| 1258 | if (ferror(f)) { | 1193 | if (ferror(f)) { |
| 1259 | throw std::runtime_error( | 1194 | throw std::runtime_error( |
| 1260 | std::string("failure reading file ") + std::string(filename) + | 1195 | std::string("failure reading file ") + std::string(filename) + |
| 1261 | - " into memory: read " + uint_to_string(read) + "; wanted " + | ||
| 1262 | - uint_to_string(size)); | 1196 | + " into memory: read " + uint_to_string(read) + "; wanted " + uint_to_string(size)); |
| 1263 | } else { | 1197 | } else { |
| 1264 | throw std::runtime_error( | 1198 | throw std::runtime_error( |
| 1265 | - std::string("premature eof reading file ") + | ||
| 1266 | - std::string(filename) + " into memory: read " + | ||
| 1267 | - uint_to_string(read) + "; wanted " + uint_to_string(size)); | 1199 | + std::string("premature eof reading file ") + std::string(filename) + |
| 1200 | + " into memory: read " + uint_to_string(read) + "; wanted " + uint_to_string(size)); | ||
| 1268 | } | 1201 | } |
| 1269 | } | 1202 | } |
| 1270 | return result; | 1203 | return result; |
| @@ -1314,9 +1247,7 @@ QUtil::read_lines_from_file(FILE* f, bool preserve_eol) | @@ -1314,9 +1247,7 @@ QUtil::read_lines_from_file(FILE* f, bool preserve_eol) | ||
| 1314 | 1247 | ||
| 1315 | void | 1248 | void |
| 1316 | QUtil::read_lines_from_file( | 1249 | QUtil::read_lines_from_file( |
| 1317 | - std::function<bool(char&)> next_char, | ||
| 1318 | - std::list<std::string>& lines, | ||
| 1319 | - bool preserve_eol) | 1250 | + std::function<bool(char&)> next_char, std::list<std::string>& lines, bool preserve_eol) |
| 1320 | { | 1251 | { |
| 1321 | std::string* buf = nullptr; | 1252 | std::string* buf = nullptr; |
| 1322 | char c; | 1253 | char c; |
| @@ -1463,8 +1394,7 @@ QUtil::parse_numrange(char const* range, int max) | @@ -1463,8 +1394,7 @@ QUtil::parse_numrange(char const* range, int max) | ||
| 1463 | // max == 0 means we don't know the max and are just | 1394 | // max == 0 means we don't know the max and are just |
| 1464 | // testing for valid syntax. | 1395 | // testing for valid syntax. |
| 1465 | if ((max > 0) && ((num < 1) || (num > max))) { | 1396 | if ((max > 0) && ((num < 1) || (num > max))) { |
| 1466 | - throw std::runtime_error( | ||
| 1467 | - "number " + QUtil::int_to_string(num) + " out of range"); | 1397 | + throw std::runtime_error("number " + QUtil::int_to_string(num) + " out of range"); |
| 1468 | } | 1398 | } |
| 1469 | if (i == 0) { | 1399 | if (i == 0) { |
| 1470 | result.push_back(work.at(i)); | 1400 | result.push_back(work.at(i)); |
| @@ -1484,8 +1414,7 @@ QUtil::parse_numrange(char const* range, int max) | @@ -1484,8 +1414,7 @@ QUtil::parse_numrange(char const* range, int max) | ||
| 1484 | } | 1414 | } |
| 1485 | } | 1415 | } |
| 1486 | } else { | 1416 | } else { |
| 1487 | - throw std::logic_error( | ||
| 1488 | - "INTERNAL ERROR parsing numeric range"); | 1417 | + throw std::logic_error("INTERNAL ERROR parsing numeric range"); |
| 1489 | } | 1418 | } |
| 1490 | } | 1419 | } |
| 1491 | } | 1420 | } |
| @@ -1500,11 +1429,9 @@ QUtil::parse_numrange(char const* range, int max) | @@ -1500,11 +1429,9 @@ QUtil::parse_numrange(char const* range, int max) | ||
| 1500 | std::string message; | 1429 | std::string message; |
| 1501 | if (p) { | 1430 | if (p) { |
| 1502 | message = "error at * in numeric range " + | 1431 | message = "error at * in numeric range " + |
| 1503 | - std::string(range, QIntC::to_size(p - range)) + "*" + p + ": " + | ||
| 1504 | - e.what(); | 1432 | + std::string(range, QIntC::to_size(p - range)) + "*" + p + ": " + e.what(); |
| 1505 | } else { | 1433 | } else { |
| 1506 | - message = "error in numeric range " + std::string(range) + ": " + | ||
| 1507 | - e.what(); | 1434 | + message = "error in numeric range " + std::string(range) + ": " + e.what(); |
| 1508 | } | 1435 | } |
| 1509 | throw std::runtime_error(message); | 1436 | throw std::runtime_error(message); |
| 1510 | } | 1437 | } |
| @@ -1544,8 +1471,7 @@ encode_pdfdoc(unsigned long codepoint) | @@ -1544,8 +1471,7 @@ encode_pdfdoc(unsigned long codepoint) | ||
| 1544 | } | 1471 | } |
| 1545 | 1472 | ||
| 1546 | unsigned long | 1473 | unsigned long |
| 1547 | -QUtil::get_next_utf8_codepoint( | ||
| 1548 | - std::string const& utf8_val, size_t& pos, bool& error) | 1474 | +QUtil::get_next_utf8_codepoint(std::string const& utf8_val, size_t& pos, bool& error) |
| 1549 | { | 1475 | { |
| 1550 | size_t len = utf8_val.length(); | 1476 | size_t len = utf8_val.length(); |
| 1551 | unsigned char ch = static_cast<unsigned char>(utf8_val.at(pos++)); | 1477 | unsigned char ch = static_cast<unsigned char>(utf8_val.at(pos++)); |
| @@ -1562,8 +1488,7 @@ QUtil::get_next_utf8_codepoint( | @@ -1562,8 +1488,7 @@ QUtil::get_next_utf8_codepoint( | ||
| 1562 | to_clear = static_cast<unsigned char>(to_clear | bit_check); | 1488 | to_clear = static_cast<unsigned char>(to_clear | bit_check); |
| 1563 | bit_check >>= 1; | 1489 | bit_check >>= 1; |
| 1564 | } | 1490 | } |
| 1565 | - if (((bytes_needed > 5) || (bytes_needed < 1)) || | ||
| 1566 | - ((pos + bytes_needed) > len)) { | 1491 | + if (((bytes_needed > 5) || (bytes_needed < 1)) || ((pos + bytes_needed) > len)) { |
| 1567 | error = true; | 1492 | error = true; |
| 1568 | return 0xfffd; | 1493 | return 0xfffd; |
| 1569 | } | 1494 | } |
| @@ -1584,11 +1509,7 @@ QUtil::get_next_utf8_codepoint( | @@ -1584,11 +1509,7 @@ QUtil::get_next_utf8_codepoint( | ||
| 1584 | } | 1509 | } |
| 1585 | 1510 | ||
| 1586 | static bool | 1511 | static bool |
| 1587 | -transcode_utf8( | ||
| 1588 | - std::string const& utf8_val, | ||
| 1589 | - std::string& result, | ||
| 1590 | - encoding_e encoding, | ||
| 1591 | - char unknown) | 1512 | +transcode_utf8(std::string const& utf8_val, std::string& result, encoding_e encoding, char unknown) |
| 1592 | { | 1513 | { |
| 1593 | bool okay = true; | 1514 | bool okay = true; |
| 1594 | result.clear(); | 1515 | result.clear(); |
| @@ -1613,8 +1534,7 @@ transcode_utf8( | @@ -1613,8 +1534,7 @@ transcode_utf8( | ||
| 1613 | static std::string ef_bb_bf("\xaf\xc2\xbb\xc2\xbf"); | 1534 | static std::string ef_bb_bf("\xaf\xc2\xbb\xc2\xbf"); |
| 1614 | // C++-20 has starts_with, but when this was written, qpdf | 1535 | // C++-20 has starts_with, but when this was written, qpdf |
| 1615 | // had a minimum supported version of C++-17. | 1536 | // had a minimum supported version of C++-17. |
| 1616 | - if ((utf8_val.compare(1, 3, fe_ff) == 0) || | ||
| 1617 | - (utf8_val.compare(1, 3, ff_fe) == 0) || | 1537 | + if ((utf8_val.compare(1, 3, fe_ff) == 0) || (utf8_val.compare(1, 3, ff_fe) == 0) || |
| 1618 | (utf8_val.compare(1, 5, ef_bb_bf) == 0)) { | 1538 | (utf8_val.compare(1, 5, ef_bb_bf) == 0)) { |
| 1619 | result += unknown; | 1539 | result += unknown; |
| 1620 | okay = false; | 1540 | okay = false; |
| @@ -1627,8 +1547,7 @@ transcode_utf8( | @@ -1627,8 +1547,7 @@ transcode_utf8( | ||
| 1627 | size_t pos = 0; | 1547 | size_t pos = 0; |
| 1628 | while (pos < len) { | 1548 | while (pos < len) { |
| 1629 | bool error = false; | 1549 | bool error = false; |
| 1630 | - unsigned long codepoint = | ||
| 1631 | - QUtil::get_next_utf8_codepoint(utf8_val, pos, error); | 1550 | + unsigned long codepoint = QUtil::get_next_utf8_codepoint(utf8_val, pos, error); |
| 1632 | if (error) { | 1551 | if (error) { |
| 1633 | okay = false; | 1552 | okay = false; |
| 1634 | if (encoding == e_utf16) { | 1553 | if (encoding == e_utf16) { |
| @@ -1640,9 +1559,7 @@ transcode_utf8( | @@ -1640,9 +1559,7 @@ transcode_utf8( | ||
| 1640 | char ch = static_cast<char>(codepoint); | 1559 | char ch = static_cast<char>(codepoint); |
| 1641 | if (encoding == e_utf16) { | 1560 | if (encoding == e_utf16) { |
| 1642 | result += QUtil::toUTF16(QIntC::to_ulong(ch)); | 1561 | result += QUtil::toUTF16(QIntC::to_ulong(ch)); |
| 1643 | - } else if ( | ||
| 1644 | - (encoding == e_pdfdoc) && | ||
| 1645 | - (((ch >= 0x18) && (ch <= 0x1f)) || (ch == 127))) { | 1562 | + } else if ((encoding == e_pdfdoc) && (((ch >= 0x18) && (ch <= 0x1f)) || (ch == 127))) { |
| 1646 | // PDFDocEncoding maps some low characters to Unicode, | 1563 | // PDFDocEncoding maps some low characters to Unicode, |
| 1647 | // so if we encounter those invalid UTF-8 code points, | 1564 | // so if we encounter those invalid UTF-8 code points, |
| 1648 | // map them to unknown so reversing the mapping | 1565 | // map them to unknown so reversing the mapping |
| @@ -1720,29 +1637,25 @@ QUtil::utf8_to_pdf_doc(std::string const& utf8, char unknown_char) | @@ -1720,29 +1637,25 @@ QUtil::utf8_to_pdf_doc(std::string const& utf8, char unknown_char) | ||
| 1720 | } | 1637 | } |
| 1721 | 1638 | ||
| 1722 | bool | 1639 | bool |
| 1723 | -QUtil::utf8_to_ascii( | ||
| 1724 | - std::string const& utf8, std::string& ascii, char unknown_char) | 1640 | +QUtil::utf8_to_ascii(std::string const& utf8, std::string& ascii, char unknown_char) |
| 1725 | { | 1641 | { |
| 1726 | return transcode_utf8(utf8, ascii, e_ascii, unknown_char); | 1642 | return transcode_utf8(utf8, ascii, e_ascii, unknown_char); |
| 1727 | } | 1643 | } |
| 1728 | 1644 | ||
| 1729 | bool | 1645 | bool |
| 1730 | -QUtil::utf8_to_win_ansi( | ||
| 1731 | - std::string const& utf8, std::string& win, char unknown_char) | 1646 | +QUtil::utf8_to_win_ansi(std::string const& utf8, std::string& win, char unknown_char) |
| 1732 | { | 1647 | { |
| 1733 | return transcode_utf8(utf8, win, e_winansi, unknown_char); | 1648 | return transcode_utf8(utf8, win, e_winansi, unknown_char); |
| 1734 | } | 1649 | } |
| 1735 | 1650 | ||
| 1736 | bool | 1651 | bool |
| 1737 | -QUtil::utf8_to_mac_roman( | ||
| 1738 | - std::string const& utf8, std::string& mac, char unknown_char) | 1652 | +QUtil::utf8_to_mac_roman(std::string const& utf8, std::string& mac, char unknown_char) |
| 1739 | { | 1653 | { |
| 1740 | return transcode_utf8(utf8, mac, e_macroman, unknown_char); | 1654 | return transcode_utf8(utf8, mac, e_macroman, unknown_char); |
| 1741 | } | 1655 | } |
| 1742 | 1656 | ||
| 1743 | bool | 1657 | bool |
| 1744 | -QUtil::utf8_to_pdf_doc( | ||
| 1745 | - std::string const& utf8, std::string& pdfdoc, char unknown_char) | 1658 | +QUtil::utf8_to_pdf_doc(std::string const& utf8, std::string& pdfdoc, char unknown_char) |
| 1746 | { | 1659 | { |
| 1747 | return transcode_utf8(utf8, pdfdoc, e_pdfdoc, unknown_char); | 1660 | return transcode_utf8(utf8, pdfdoc, e_pdfdoc, unknown_char); |
| 1748 | } | 1661 | } |
| @@ -1869,10 +1782,7 @@ QUtil::pdf_doc_to_utf8(std::string const& val) | @@ -1869,10 +1782,7 @@ QUtil::pdf_doc_to_utf8(std::string const& val) | ||
| 1869 | 1782 | ||
| 1870 | void | 1783 | void |
| 1871 | QUtil::analyze_encoding( | 1784 | QUtil::analyze_encoding( |
| 1872 | - std::string const& val, | ||
| 1873 | - bool& has_8bit_chars, | ||
| 1874 | - bool& is_valid_utf8, | ||
| 1875 | - bool& is_utf16) | 1785 | + std::string const& val, bool& has_8bit_chars, bool& is_valid_utf8, bool& is_utf16) |
| 1876 | { | 1786 | { |
| 1877 | has_8bit_chars = is_utf16 = is_valid_utf8 = false; | 1787 | has_8bit_chars = is_utf16 = is_valid_utf8 = false; |
| 1878 | if (QUtil::is_utf16(val)) { | 1788 | if (QUtil::is_utf16(val)) { |
| @@ -1976,10 +1886,7 @@ QUtil::possible_repaired_encodings(std::string supplied) | @@ -1976,10 +1886,7 @@ QUtil::possible_repaired_encodings(std::string supplied) | ||
| 1976 | #ifndef QPDF_NO_WCHAR_T | 1886 | #ifndef QPDF_NO_WCHAR_T |
| 1977 | static int | 1887 | static int |
| 1978 | call_main_from_wmain( | 1888 | call_main_from_wmain( |
| 1979 | - bool, | ||
| 1980 | - int argc, | ||
| 1981 | - wchar_t const* const argv[], | ||
| 1982 | - std::function<int(int, char*[])> realmain) | 1889 | + bool, int argc, wchar_t const* const argv[], std::function<int(int, char*[])> realmain) |
| 1983 | { | 1890 | { |
| 1984 | // argv contains UTF-16-encoded strings with a 16-bit wchar_t. | 1891 | // argv contains UTF-16-encoded strings with a 16-bit wchar_t. |
| 1985 | // Convert this to UTF-8-encoded strings for compatibility with | 1892 | // Convert this to UTF-8-encoded strings for compatibility with |
| @@ -1992,8 +1899,7 @@ call_main_from_wmain( | @@ -1992,8 +1899,7 @@ call_main_from_wmain( | ||
| 1992 | for (size_t j = 0; j < std::wcslen(argv[i]); ++j) { | 1899 | for (size_t j = 0; j < std::wcslen(argv[i]); ++j) { |
| 1993 | unsigned short codepoint = static_cast<unsigned short>(argv[i][j]); | 1900 | unsigned short codepoint = static_cast<unsigned short>(argv[i][j]); |
| 1994 | utf16.append(1, static_cast<char>(QIntC::to_uchar(codepoint >> 8))); | 1901 | utf16.append(1, static_cast<char>(QIntC::to_uchar(codepoint >> 8))); |
| 1995 | - utf16.append( | ||
| 1996 | - 1, static_cast<char>(QIntC::to_uchar(codepoint & 0xff))); | 1902 | + utf16.append(1, static_cast<char>(QIntC::to_uchar(codepoint & 0xff))); |
| 1997 | } | 1903 | } |
| 1998 | std::string utf8 = QUtil::utf16_to_utf8(utf16); | 1904 | std::string utf8 = QUtil::utf16_to_utf8(utf16); |
| 1999 | utf8_argv.push_back(QUtil::make_unique_cstr(utf8)); | 1905 | utf8_argv.push_back(QUtil::make_unique_cstr(utf8)); |
| @@ -2009,22 +1915,18 @@ call_main_from_wmain( | @@ -2009,22 +1915,18 @@ call_main_from_wmain( | ||
| 2009 | } | 1915 | } |
| 2010 | 1916 | ||
| 2011 | int | 1917 | int |
| 2012 | -QUtil::call_main_from_wmain( | ||
| 2013 | - int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain) | 1918 | +QUtil::call_main_from_wmain(int argc, wchar_t* argv[], std::function<int(int, char*[])> realmain) |
| 2014 | { | 1919 | { |
| 2015 | return ::call_main_from_wmain(true, argc, argv, realmain); | 1920 | return ::call_main_from_wmain(true, argc, argv, realmain); |
| 2016 | } | 1921 | } |
| 2017 | 1922 | ||
| 2018 | int | 1923 | int |
| 2019 | QUtil::call_main_from_wmain( | 1924 | QUtil::call_main_from_wmain( |
| 2020 | - int argc, | ||
| 2021 | - wchar_t const* const argv[], | ||
| 2022 | - std::function<int(int, char const* const[])> realmain) | 1925 | + int argc, wchar_t const* const argv[], std::function<int(int, char const* const[])> realmain) |
| 2023 | { | 1926 | { |
| 2024 | - return ::call_main_from_wmain( | ||
| 2025 | - true, argc, argv, [realmain](int new_argc, char* new_argv[]) { | ||
| 2026 | - return realmain(new_argc, new_argv); | ||
| 2027 | - }); | 1927 | + return ::call_main_from_wmain(true, argc, argv, [realmain](int new_argc, char* new_argv[]) { |
| 1928 | + return realmain(new_argc, new_argv); | ||
| 1929 | + }); | ||
| 2028 | } | 1930 | } |
| 2029 | 1931 | ||
| 2030 | #endif // QPDF_NO_WCHAR_T | 1932 | #endif // QPDF_NO_WCHAR_T |
| @@ -2080,12 +1982,10 @@ QUtil::get_max_memory_usage() | @@ -2080,12 +1982,10 @@ QUtil::get_max_memory_usage() | ||
| 2080 | } | 1982 | } |
| 2081 | if (tag == "total") { | 1983 | if (tag == "total") { |
| 2082 | if (attrs.count("size") > 0) { | 1984 | if (attrs.count("size") > 0) { |
| 2083 | - result += QIntC::to_size( | ||
| 2084 | - QUtil::string_to_ull(attrs["size"].c_str())); | 1985 | + result += QIntC::to_size(QUtil::string_to_ull(attrs["size"].c_str())); |
| 2085 | } | 1986 | } |
| 2086 | } else if (tag == "system" && attrs["type"] == "max") { | 1987 | } else if (tag == "system" && attrs["type"] == "max") { |
| 2087 | - result += QIntC::to_size( | ||
| 2088 | - QUtil::string_to_ull(attrs["size"].c_str())); | 1988 | + result += QIntC::to_size(QUtil::string_to_ull(attrs["size"].c_str())); |
| 2089 | } | 1989 | } |
| 2090 | } | 1990 | } |
| 2091 | } | 1991 | } |
libqpdf/RC4_native.cc
| @@ -17,8 +17,7 @@ swap_byte(unsigned char& a, unsigned char& b) | @@ -17,8 +17,7 @@ swap_byte(unsigned char& a, unsigned char& b) | ||
| 17 | RC4_native::RC4_native(unsigned char const* key_data, int key_len) | 17 | RC4_native::RC4_native(unsigned char const* key_data, int key_len) |
| 18 | { | 18 | { |
| 19 | if (key_len == -1) { | 19 | if (key_len == -1) { |
| 20 | - key_len = | ||
| 21 | - QIntC::to_int(strlen(reinterpret_cast<char const*>(key_data))); | 20 | + key_len = QIntC::to_int(strlen(reinterpret_cast<char const*>(key_data))); |
| 22 | } | 21 | } |
| 23 | 22 | ||
| 24 | for (int i = 0; i < 256; ++i) { | 23 | for (int i = 0; i < 256; ++i) { |
| @@ -37,8 +36,7 @@ RC4_native::RC4_native(unsigned char const* key_data, int key_len) | @@ -37,8 +36,7 @@ RC4_native::RC4_native(unsigned char const* key_data, int key_len) | ||
| 37 | } | 36 | } |
| 38 | 37 | ||
| 39 | void | 38 | void |
| 40 | -RC4_native::process( | ||
| 41 | - unsigned char const* in_data, size_t len, unsigned char* out_data) | 39 | +RC4_native::process(unsigned char const* in_data, size_t len, unsigned char* out_data) |
| 42 | { | 40 | { |
| 43 | for (size_t i = 0; i < len; ++i) { | 41 | for (size_t i = 0; i < len; ++i) { |
| 44 | key.x = static_cast<unsigned char>((key.x + 1) % 256); | 42 | key.x = static_cast<unsigned char>((key.x + 1) % 256); |
libqpdf/SF_FlateLzwDecode.cc
| @@ -39,9 +39,7 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms) | @@ -39,9 +39,7 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms) | ||
| 39 | } else { | 39 | } else { |
| 40 | filterable = false; | 40 | filterable = false; |
| 41 | } | 41 | } |
| 42 | - } else if ( | ||
| 43 | - (key == "/Columns") || (key == "/Colors") || | ||
| 44 | - (key == "/BitsPerComponent")) { | 42 | + } else if ((key == "/Columns") || (key == "/Colors") || (key == "/BitsPerComponent")) { |
| 45 | if (value.isInteger()) { | 43 | if (value.isInteger()) { |
| 46 | int val = value.getIntValueAsInt(); | 44 | int val = value.getIntValueAsInt(); |
| 47 | if (key == "/Columns") { | 45 | if (key == "/Columns") { |
| @@ -103,11 +101,9 @@ SF_FlateLzwDecode::getDecodePipeline(Pipeline* next) | @@ -103,11 +101,9 @@ SF_FlateLzwDecode::getDecodePipeline(Pipeline* next) | ||
| 103 | } | 101 | } |
| 104 | 102 | ||
| 105 | if (lzw) { | 103 | if (lzw) { |
| 106 | - pipeline = std::make_shared<Pl_LZWDecoder>( | ||
| 107 | - "lzw decode", next, early_code_change); | 104 | + pipeline = std::make_shared<Pl_LZWDecoder>("lzw decode", next, early_code_change); |
| 108 | } else { | 105 | } else { |
| 109 | - pipeline = std::make_shared<Pl_Flate>( | ||
| 110 | - "stream inflate", next, Pl_Flate::a_inflate); | 106 | + pipeline = std::make_shared<Pl_Flate>("stream inflate", next, Pl_Flate::a_inflate); |
| 111 | } | 107 | } |
| 112 | this->pipelines.push_back(pipeline); | 108 | this->pipelines.push_back(pipeline); |
| 113 | return pipeline.get(); | 109 | return pipeline.get(); |
libqpdf/SHA2_native.cc
| @@ -73,16 +73,13 @@ SHA2_native::getRawDigest() | @@ -73,16 +73,13 @@ SHA2_native::getRawDigest() | ||
| 73 | std::string result; | 73 | std::string result; |
| 74 | switch (bits) { | 74 | switch (bits) { |
| 75 | case 256: | 75 | case 256: |
| 76 | - result = std::string( | ||
| 77 | - reinterpret_cast<char*>(this->sha256sum), sizeof(this->sha256sum)); | 76 | + result = std::string(reinterpret_cast<char*>(this->sha256sum), sizeof(this->sha256sum)); |
| 78 | break; | 77 | break; |
| 79 | case 384: | 78 | case 384: |
| 80 | - result = std::string( | ||
| 81 | - reinterpret_cast<char*>(this->sha384sum), sizeof(this->sha384sum)); | 79 | + result = std::string(reinterpret_cast<char*>(this->sha384sum), sizeof(this->sha384sum)); |
| 82 | break; | 80 | break; |
| 83 | case 512: | 81 | case 512: |
| 84 | - result = std::string( | ||
| 85 | - reinterpret_cast<char*>(this->sha512sum), sizeof(this->sha512sum)); | 82 | + result = std::string(reinterpret_cast<char*>(this->sha512sum), sizeof(this->sha512sum)); |
| 86 | break; | 83 | break; |
| 87 | default: | 84 | default: |
| 88 | badBits(); | 85 | badBits(); |
libqpdf/SecureRandomDataProvider.cc
| @@ -39,13 +39,8 @@ namespace | @@ -39,13 +39,8 @@ namespace | ||
| 39 | WindowsCryptProvider() | 39 | WindowsCryptProvider() |
| 40 | { | 40 | { |
| 41 | if (!CryptAcquireContextW( | 41 | if (!CryptAcquireContextW( |
| 42 | - &crypt_prov, | ||
| 43 | - NULL, | ||
| 44 | - NULL, | ||
| 45 | - PROV_RSA_FULL, | ||
| 46 | - CRYPT_VERIFYCONTEXT)) { | ||
| 47 | - throw std::runtime_error( | ||
| 48 | - "unable to acquire crypt context: " + getErrorMessage()); | 42 | + &crypt_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { |
| 43 | + throw std::runtime_error("unable to acquire crypt context: " + getErrorMessage()); | ||
| 49 | } | 44 | } |
| 50 | } | 45 | } |
| 51 | ~WindowsCryptProvider() | 46 | ~WindowsCryptProvider() |
| @@ -74,8 +69,7 @@ namespace | @@ -74,8 +69,7 @@ namespace | ||
| 74 | std::string message(messageBuffer, size); | 69 | std::string message(messageBuffer, size); |
| 75 | LocalFree(messageBuffer); | 70 | LocalFree(messageBuffer); |
| 76 | return ( | 71 | return ( |
| 77 | - "error number " + | ||
| 78 | - QUtil::int_to_string_base(errorMessageID, 16) + ": " + message); | 72 | + "error number " + QUtil::int_to_string_base(errorMessageID, 16) + ": " + message); |
| 79 | } | 73 | } |
| 80 | }; | 74 | }; |
| 81 | } // namespace | 75 | } // namespace |
| @@ -89,10 +83,7 @@ SecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len) | @@ -89,10 +83,7 @@ SecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len) | ||
| 89 | // Optimization: make the WindowsCryptProvider static as long as | 83 | // Optimization: make the WindowsCryptProvider static as long as |
| 90 | // it can be done in a thread-safe fashion. | 84 | // it can be done in a thread-safe fashion. |
| 91 | WindowsCryptProvider c; | 85 | WindowsCryptProvider c; |
| 92 | - if (!CryptGenRandom( | ||
| 93 | - c.crypt_prov, | ||
| 94 | - static_cast<DWORD>(len), | ||
| 95 | - reinterpret_cast<BYTE*>(data))) { | 86 | + if (!CryptGenRandom(c.crypt_prov, static_cast<DWORD>(len), reinterpret_cast<BYTE*>(data))) { |
| 96 | throw std::runtime_error("unable to generate secure random data"); | 87 | throw std::runtime_error("unable to generate secure random data"); |
| 97 | } | 88 | } |
| 98 | 89 | ||
| @@ -107,8 +98,7 @@ SecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len) | @@ -107,8 +98,7 @@ SecureRandomDataProvider::provideRandomData(unsigned char* data, size_t len) | ||
| 107 | fclose(f); | 98 | fclose(f); |
| 108 | if (fr != len) { | 99 | if (fr != len) { |
| 109 | throw std::runtime_error( | 100 | throw std::runtime_error( |
| 110 | - "unable to read " + std::to_string(len) + " bytes from " + | ||
| 111 | - std::string(RANDOM_DEVICE)); | 101 | + "unable to read " + std::to_string(len) + " bytes from " + std::string(RANDOM_DEVICE)); |
| 112 | } | 102 | } |
| 113 | 103 | ||
| 114 | # else | 104 | # else |
libqpdf/qpdf-c.cc
| @@ -32,18 +32,14 @@ static void | @@ -32,18 +32,14 @@ static void | ||
| 32 | call_read_memory(qpdf_data qpdf) | 32 | call_read_memory(qpdf_data qpdf) |
| 33 | { | 33 | { |
| 34 | qpdf->qpdf->processMemoryFile( | 34 | qpdf->qpdf->processMemoryFile( |
| 35 | - qpdf->filename, | ||
| 36 | - qpdf->buffer, | ||
| 37 | - QIntC::to_size(qpdf->size), | ||
| 38 | - qpdf->password); | 35 | + qpdf->filename, qpdf->buffer, QIntC::to_size(qpdf->size), qpdf->password); |
| 39 | } | 36 | } |
| 40 | 37 | ||
| 41 | // must set qpdf->filename | 38 | // must set qpdf->filename |
| 42 | static void | 39 | static void |
| 43 | call_init_write(qpdf_data qpdf) | 40 | call_init_write(qpdf_data qpdf) |
| 44 | { | 41 | { |
| 45 | - qpdf->qpdf_writer = | ||
| 46 | - std::make_shared<QPDFWriter>(*(qpdf->qpdf), qpdf->filename); | 42 | + qpdf->qpdf_writer = std::make_shared<QPDFWriter>(*(qpdf->qpdf), qpdf->filename); |
| 47 | } | 43 | } |
| 48 | 44 | ||
| 49 | static void | 45 | static void |
| @@ -79,12 +75,10 @@ trap_errors(qpdf_data qpdf, std::function<void(qpdf_data)> fn) | @@ -79,12 +75,10 @@ trap_errors(qpdf_data qpdf, std::function<void(qpdf_data)> fn) | ||
| 79 | qpdf->error = std::make_shared<QPDFExc>(e); | 75 | qpdf->error = std::make_shared<QPDFExc>(e); |
| 80 | status |= QPDF_ERRORS; | 76 | status |= QPDF_ERRORS; |
| 81 | } catch (std::runtime_error& e) { | 77 | } catch (std::runtime_error& e) { |
| 82 | - qpdf->error = | ||
| 83 | - std::make_shared<QPDFExc>(qpdf_e_system, "", "", 0, e.what()); | 78 | + qpdf->error = std::make_shared<QPDFExc>(qpdf_e_system, "", "", 0, e.what()); |
| 84 | status |= QPDF_ERRORS; | 79 | status |= QPDF_ERRORS; |
| 85 | } catch (std::exception& e) { | 80 | } catch (std::exception& e) { |
| 86 | - qpdf->error = | ||
| 87 | - std::make_shared<QPDFExc>(qpdf_e_internal, "", "", 0, e.what()); | 81 | + qpdf->error = std::make_shared<QPDFExc>(qpdf_e_internal, "", "", 0, e.what()); |
| 88 | status |= QPDF_ERRORS; | 82 | status |= QPDF_ERRORS; |
| 89 | } | 83 | } |
| 90 | 84 | ||
| @@ -119,8 +113,7 @@ qpdf_cleanup(qpdf_data* qpdf) | @@ -119,8 +113,7 @@ qpdf_cleanup(qpdf_data* qpdf) | ||
| 119 | if ((*qpdf)->error.get()) { | 113 | if ((*qpdf)->error.get()) { |
| 120 | QTC::TC("qpdf", "qpdf-c cleanup warned about unhandled error"); | 114 | QTC::TC("qpdf", "qpdf-c cleanup warned about unhandled error"); |
| 121 | *QPDFLogger::defaultLogger()->getWarn() | 115 | *QPDFLogger::defaultLogger()->getWarn() |
| 122 | - << "WARNING: application did not handle error: " | ||
| 123 | - << (*qpdf)->error->what() << "\n"; | 116 | + << "WARNING: application did not handle error: " << (*qpdf)->error->what() << "\n"; |
| 124 | } | 117 | } |
| 125 | delete *qpdf; | 118 | delete *qpdf; |
| 126 | *qpdf = nullptr; | 119 | *qpdf = nullptr; |
| @@ -377,8 +370,7 @@ qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value) | @@ -377,8 +370,7 @@ qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value) | ||
| 377 | if (!trailer.hasKey("/Info")) { | 370 | if (!trailer.hasKey("/Info")) { |
| 378 | QTC::TC("qpdf", "qpdf-c add info to trailer"); | 371 | QTC::TC("qpdf", "qpdf-c add info to trailer"); |
| 379 | trailer.replaceKey( | 372 | trailer.replaceKey( |
| 380 | - "/Info", | ||
| 381 | - qpdf->qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary())); | 373 | + "/Info", qpdf->qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary())); |
| 382 | } else { | 374 | } else { |
| 383 | QTC::TC("qpdf", "qpdf-c set-info-key use existing info"); | 375 | QTC::TC("qpdf", "qpdf-c set-info-key use existing info"); |
| 384 | } | 376 | } |
| @@ -765,8 +757,7 @@ qpdf_set_minimum_pdf_version(qpdf_data qpdf, char const* version) | @@ -765,8 +757,7 @@ qpdf_set_minimum_pdf_version(qpdf_data qpdf, char const* version) | ||
| 765 | } | 757 | } |
| 766 | 758 | ||
| 767 | void | 759 | void |
| 768 | -qpdf_set_minimum_pdf_version_and_extension( | ||
| 769 | - qpdf_data qpdf, char const* version, int extension_level) | 760 | +qpdf_set_minimum_pdf_version_and_extension(qpdf_data qpdf, char const* version, int extension_level) |
| 770 | { | 761 | { |
| 771 | QTC::TC("qpdf", "qpdf-c called qpdf_set_minimum_pdf_version"); | 762 | QTC::TC("qpdf", "qpdf-c called qpdf_set_minimum_pdf_version"); |
| 772 | qpdf->qpdf_writer->setMinimumPDFVersion(version, extension_level); | 763 | qpdf->qpdf_writer->setMinimumPDFVersion(version, extension_level); |
| @@ -779,8 +770,7 @@ qpdf_force_pdf_version(qpdf_data qpdf, char const* version) | @@ -779,8 +770,7 @@ qpdf_force_pdf_version(qpdf_data qpdf, char const* version) | ||
| 779 | } | 770 | } |
| 780 | 771 | ||
| 781 | void | 772 | void |
| 782 | -qpdf_force_pdf_version_and_extension( | ||
| 783 | - qpdf_data qpdf, char const* version, int extension_level) | 773 | +qpdf_force_pdf_version_and_extension(qpdf_data qpdf, char const* version, int extension_level) |
| 784 | { | 774 | { |
| 785 | QTC::TC("qpdf", "qpdf-c called qpdf_force_pdf_version"); | 775 | QTC::TC("qpdf", "qpdf-c called qpdf_force_pdf_version"); |
| 786 | qpdf->qpdf_writer->forcePDFVersion(version, extension_level); | 776 | qpdf->qpdf_writer->forcePDFVersion(version, extension_level); |
| @@ -788,15 +778,12 @@ qpdf_force_pdf_version_and_extension( | @@ -788,15 +778,12 @@ qpdf_force_pdf_version_and_extension( | ||
| 788 | 778 | ||
| 789 | void | 779 | void |
| 790 | qpdf_register_progress_reporter( | 780 | qpdf_register_progress_reporter( |
| 791 | - qpdf_data qpdf, | ||
| 792 | - void (*report_progress)(int percent, void* data), | ||
| 793 | - void* data) | 781 | + qpdf_data qpdf, void (*report_progress)(int percent, void* data), void* data) |
| 794 | { | 782 | { |
| 795 | QTC::TC("qpdf", "qpdf-c registered progress reporter"); | 783 | QTC::TC("qpdf", "qpdf-c registered progress reporter"); |
| 796 | qpdf->qpdf_writer->registerProgressReporter( | 784 | qpdf->qpdf_writer->registerProgressReporter( |
| 797 | - std::shared_ptr<QPDFWriter::ProgressReporter>( | ||
| 798 | - new QPDFWriter::FunctionProgressReporter( | ||
| 799 | - std::bind(report_progress, std::placeholders::_1, data)))); | 785 | + std::shared_ptr<QPDFWriter::ProgressReporter>(new QPDFWriter::FunctionProgressReporter( |
| 786 | + std::bind(report_progress, std::placeholders::_1, data)))); | ||
| 800 | } | 787 | } |
| 801 | 788 | ||
| 802 | QPDF_ERROR_CODE | 789 | QPDF_ERROR_CODE |
| @@ -817,23 +804,16 @@ qpdf_silence_errors(qpdf_data qpdf) | @@ -817,23 +804,16 @@ qpdf_silence_errors(qpdf_data qpdf) | ||
| 817 | 804 | ||
| 818 | template <class RET> | 805 | template <class RET> |
| 819 | static RET | 806 | static RET |
| 820 | -trap_oh_errors( | ||
| 821 | - qpdf_data qpdf, | ||
| 822 | - std::function<RET()> fallback, | ||
| 823 | - std::function<RET(qpdf_data)> fn) | 807 | +trap_oh_errors(qpdf_data qpdf, std::function<RET()> fallback, std::function<RET(qpdf_data)> fn) |
| 824 | { | 808 | { |
| 825 | // Note: fallback is a function so we don't have to evaluate it | 809 | // Note: fallback is a function so we don't have to evaluate it |
| 826 | // unless needed. This is important because sometimes the fallback | 810 | // unless needed. This is important because sometimes the fallback |
| 827 | // creates an object. | 811 | // creates an object. |
| 828 | RET ret; | 812 | RET ret; |
| 829 | - QPDF_ERROR_CODE status = | ||
| 830 | - trap_errors(qpdf, [&ret, fn](qpdf_data q) { ret = fn(q); }); | 813 | + QPDF_ERROR_CODE status = trap_errors(qpdf, [&ret, fn](qpdf_data q) { ret = fn(q); }); |
| 831 | if (status & QPDF_ERRORS) { | 814 | if (status & QPDF_ERRORS) { |
| 832 | if (!qpdf->silence_errors) { | 815 | if (!qpdf->silence_errors) { |
| 833 | - QTC::TC( | ||
| 834 | - "qpdf", | ||
| 835 | - "qpdf-c warn about oh error", | ||
| 836 | - qpdf->oh_error_occurred ? 0 : 1); | 816 | + QTC::TC("qpdf", "qpdf-c warn about oh error", qpdf->oh_error_occurred ? 0 : 1); |
| 837 | if (!qpdf->oh_error_occurred) { | 817 | if (!qpdf->oh_error_occurred) { |
| 838 | qpdf->warnings.push_back(QPDFExc( | 818 | qpdf->warnings.push_back(QPDFExc( |
| 839 | qpdf_e_internal, | 819 | qpdf_e_internal, |
| @@ -845,8 +825,7 @@ trap_oh_errors( | @@ -845,8 +825,7 @@ trap_oh_errors( | ||
| 845 | " to ERROR HANDLING in qpdf-c.h")); | 825 | " to ERROR HANDLING in qpdf-c.h")); |
| 846 | qpdf->oh_error_occurred = true; | 826 | qpdf->oh_error_occurred = true; |
| 847 | } | 827 | } |
| 848 | - *QPDFLogger::defaultLogger()->getError() | ||
| 849 | - << qpdf->error->what() << "\n"; | 828 | + *QPDFLogger::defaultLogger()->getError() << qpdf->error->what() << "\n"; |
| 850 | } | 829 | } |
| 851 | return fallback(); | 830 | return fallback(); |
| 852 | } | 831 | } |
| @@ -911,20 +890,18 @@ qpdf_oh | @@ -911,20 +890,18 @@ qpdf_oh | ||
| 911 | qpdf_get_trailer(qpdf_data qpdf) | 890 | qpdf_get_trailer(qpdf_data qpdf) |
| 912 | { | 891 | { |
| 913 | QTC::TC("qpdf", "qpdf-c called qpdf_get_trailer"); | 892 | QTC::TC("qpdf", "qpdf-c called qpdf_get_trailer"); |
| 914 | - return trap_oh_errors<qpdf_oh>( | ||
| 915 | - qpdf, return_uninitialized(qpdf), [](qpdf_data q) { | ||
| 916 | - return new_object(q, q->qpdf->getTrailer()); | ||
| 917 | - }); | 893 | + return trap_oh_errors<qpdf_oh>(qpdf, return_uninitialized(qpdf), [](qpdf_data q) { |
| 894 | + return new_object(q, q->qpdf->getTrailer()); | ||
| 895 | + }); | ||
| 918 | } | 896 | } |
| 919 | 897 | ||
| 920 | qpdf_oh | 898 | qpdf_oh |
| 921 | qpdf_get_root(qpdf_data qpdf) | 899 | qpdf_get_root(qpdf_data qpdf) |
| 922 | { | 900 | { |
| 923 | QTC::TC("qpdf", "qpdf-c called qpdf_get_root"); | 901 | QTC::TC("qpdf", "qpdf-c called qpdf_get_root"); |
| 924 | - return trap_oh_errors<qpdf_oh>( | ||
| 925 | - qpdf, return_uninitialized(qpdf), [](qpdf_data q) { | ||
| 926 | - return new_object(q, q->qpdf->getRoot()); | ||
| 927 | - }); | 902 | + return trap_oh_errors<qpdf_oh>(qpdf, return_uninitialized(qpdf), [](qpdf_data q) { |
| 903 | + return new_object(q, q->qpdf->getRoot()); | ||
| 904 | + }); | ||
| 928 | } | 905 | } |
| 929 | 906 | ||
| 930 | qpdf_oh | 907 | qpdf_oh |
| @@ -959,14 +936,12 @@ do_with_oh( | @@ -959,14 +936,12 @@ do_with_oh( | ||
| 959 | } | 936 | } |
| 960 | 937 | ||
| 961 | static void | 938 | static void |
| 962 | -do_with_oh_void( | ||
| 963 | - qpdf_data qpdf, qpdf_oh oh, std::function<void(QPDFObjectHandle&)> fn) | 939 | +do_with_oh_void(qpdf_data qpdf, qpdf_oh oh, std::function<void(QPDFObjectHandle&)> fn) |
| 964 | { | 940 | { |
| 965 | - do_with_oh<bool>( | ||
| 966 | - qpdf, oh, return_T<bool>(false), [fn](QPDFObjectHandle& o) { | ||
| 967 | - fn(o); | ||
| 968 | - return true; // unused | ||
| 969 | - }); | 941 | + do_with_oh<bool>(qpdf, oh, return_T<bool>(false), [fn](QPDFObjectHandle& o) { |
| 942 | + fn(o); | ||
| 943 | + return true; // unused | ||
| 944 | + }); | ||
| 970 | } | 945 | } |
| 971 | 946 | ||
| 972 | void | 947 | void |
| @@ -983,9 +958,7 @@ qpdf_oh_is_initialized(qpdf_data qpdf, qpdf_oh oh) | @@ -983,9 +958,7 @@ qpdf_oh_is_initialized(qpdf_data qpdf, qpdf_oh oh) | ||
| 983 | { | 958 | { |
| 984 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_initialized"); | 959 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_initialized"); |
| 985 | return do_with_oh<QPDF_BOOL>( | 960 | return do_with_oh<QPDF_BOOL>( |
| 986 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 987 | - return o.isInitialized(); | ||
| 988 | - }); | 961 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isInitialized(); }); |
| 989 | } | 962 | } |
| 990 | 963 | ||
| 991 | QPDF_BOOL | 964 | QPDF_BOOL |
| @@ -1009,9 +982,7 @@ qpdf_oh_is_integer(qpdf_data qpdf, qpdf_oh oh) | @@ -1009,9 +982,7 @@ qpdf_oh_is_integer(qpdf_data qpdf, qpdf_oh oh) | ||
| 1009 | { | 982 | { |
| 1010 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_integer"); | 983 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_integer"); |
| 1011 | return do_with_oh<QPDF_BOOL>( | 984 | return do_with_oh<QPDF_BOOL>( |
| 1012 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1013 | - return o.isInteger(); | ||
| 1014 | - }); | 985 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isInteger(); }); |
| 1015 | } | 986 | } |
| 1016 | 987 | ||
| 1017 | QPDF_BOOL | 988 | QPDF_BOOL |
| @@ -1035,9 +1006,7 @@ qpdf_oh_is_string(qpdf_data qpdf, qpdf_oh oh) | @@ -1035,9 +1006,7 @@ qpdf_oh_is_string(qpdf_data qpdf, qpdf_oh oh) | ||
| 1035 | { | 1006 | { |
| 1036 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_string"); | 1007 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_string"); |
| 1037 | return do_with_oh<QPDF_BOOL>( | 1008 | return do_with_oh<QPDF_BOOL>( |
| 1038 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1039 | - return o.isString(); | ||
| 1040 | - }); | 1009 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isString(); }); |
| 1041 | } | 1010 | } |
| 1042 | 1011 | ||
| 1043 | QPDF_BOOL | 1012 | QPDF_BOOL |
| @@ -1045,9 +1014,7 @@ qpdf_oh_is_operator(qpdf_data qpdf, qpdf_oh oh) | @@ -1045,9 +1014,7 @@ qpdf_oh_is_operator(qpdf_data qpdf, qpdf_oh oh) | ||
| 1045 | { | 1014 | { |
| 1046 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_operator"); | 1015 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_operator"); |
| 1047 | return do_with_oh<QPDF_BOOL>( | 1016 | return do_with_oh<QPDF_BOOL>( |
| 1048 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1049 | - return o.isOperator(); | ||
| 1050 | - }); | 1017 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isOperator(); }); |
| 1051 | } | 1018 | } |
| 1052 | 1019 | ||
| 1053 | QPDF_BOOL | 1020 | QPDF_BOOL |
| @@ -1055,9 +1022,7 @@ qpdf_oh_is_inline_image(qpdf_data qpdf, qpdf_oh oh) | @@ -1055,9 +1022,7 @@ qpdf_oh_is_inline_image(qpdf_data qpdf, qpdf_oh oh) | ||
| 1055 | { | 1022 | { |
| 1056 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_inline_image"); | 1023 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_inline_image"); |
| 1057 | return do_with_oh<QPDF_BOOL>( | 1024 | return do_with_oh<QPDF_BOOL>( |
| 1058 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1059 | - return o.isInlineImage(); | ||
| 1060 | - }); | 1025 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isInlineImage(); }); |
| 1061 | } | 1026 | } |
| 1062 | 1027 | ||
| 1063 | QPDF_BOOL | 1028 | QPDF_BOOL |
| @@ -1065,9 +1030,7 @@ qpdf_oh_is_array(qpdf_data qpdf, qpdf_oh oh) | @@ -1065,9 +1030,7 @@ qpdf_oh_is_array(qpdf_data qpdf, qpdf_oh oh) | ||
| 1065 | { | 1030 | { |
| 1066 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_array"); | 1031 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_array"); |
| 1067 | return do_with_oh<QPDF_BOOL>( | 1032 | return do_with_oh<QPDF_BOOL>( |
| 1068 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1069 | - return o.isArray(); | ||
| 1070 | - }); | 1033 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isArray(); }); |
| 1071 | } | 1034 | } |
| 1072 | 1035 | ||
| 1073 | QPDF_BOOL | 1036 | QPDF_BOOL |
| @@ -1075,9 +1038,7 @@ qpdf_oh_is_dictionary(qpdf_data qpdf, qpdf_oh oh) | @@ -1075,9 +1038,7 @@ qpdf_oh_is_dictionary(qpdf_data qpdf, qpdf_oh oh) | ||
| 1075 | { | 1038 | { |
| 1076 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_dictionary"); | 1039 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_dictionary"); |
| 1077 | return do_with_oh<QPDF_BOOL>( | 1040 | return do_with_oh<QPDF_BOOL>( |
| 1078 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1079 | - return o.isDictionary(); | ||
| 1080 | - }); | 1041 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isDictionary(); }); |
| 1081 | } | 1042 | } |
| 1082 | 1043 | ||
| 1083 | QPDF_BOOL | 1044 | QPDF_BOOL |
| @@ -1085,9 +1046,7 @@ qpdf_oh_is_stream(qpdf_data qpdf, qpdf_oh oh) | @@ -1085,9 +1046,7 @@ qpdf_oh_is_stream(qpdf_data qpdf, qpdf_oh oh) | ||
| 1085 | { | 1046 | { |
| 1086 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_stream"); | 1047 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_stream"); |
| 1087 | return do_with_oh<QPDF_BOOL>( | 1048 | return do_with_oh<QPDF_BOOL>( |
| 1088 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1089 | - return o.isStream(); | ||
| 1090 | - }); | 1049 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isStream(); }); |
| 1091 | } | 1050 | } |
| 1092 | 1051 | ||
| 1093 | QPDF_BOOL | 1052 | QPDF_BOOL |
| @@ -1095,9 +1054,7 @@ qpdf_oh_is_indirect(qpdf_data qpdf, qpdf_oh oh) | @@ -1095,9 +1054,7 @@ qpdf_oh_is_indirect(qpdf_data qpdf, qpdf_oh oh) | ||
| 1095 | { | 1054 | { |
| 1096 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_indirect"); | 1055 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_indirect"); |
| 1097 | return do_with_oh<QPDF_BOOL>( | 1056 | return do_with_oh<QPDF_BOOL>( |
| 1098 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1099 | - return o.isIndirect(); | ||
| 1100 | - }); | 1057 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isIndirect(); }); |
| 1101 | } | 1058 | } |
| 1102 | 1059 | ||
| 1103 | QPDF_BOOL | 1060 | QPDF_BOOL |
| @@ -1105,51 +1062,42 @@ qpdf_oh_is_scalar(qpdf_data qpdf, qpdf_oh oh) | @@ -1105,51 +1062,42 @@ qpdf_oh_is_scalar(qpdf_data qpdf, qpdf_oh oh) | ||
| 1105 | { | 1062 | { |
| 1106 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_scalar"); | 1063 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_scalar"); |
| 1107 | return do_with_oh<QPDF_BOOL>( | 1064 | return do_with_oh<QPDF_BOOL>( |
| 1108 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1109 | - return o.isScalar(); | ||
| 1110 | - }); | 1065 | + qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isScalar(); }); |
| 1111 | } | 1066 | } |
| 1112 | 1067 | ||
| 1113 | QPDF_BOOL | 1068 | QPDF_BOOL |
| 1114 | qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh) | 1069 | qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh) |
| 1115 | { | 1070 | { |
| 1116 | - return do_with_oh<QPDF_BOOL>( | ||
| 1117 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1118 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_number"); | ||
| 1119 | - return o.isNumber(); | ||
| 1120 | - }); | 1071 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [](QPDFObjectHandle& o) { |
| 1072 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_number"); | ||
| 1073 | + return o.isNumber(); | ||
| 1074 | + }); | ||
| 1121 | } | 1075 | } |
| 1122 | 1076 | ||
| 1123 | QPDF_BOOL | 1077 | QPDF_BOOL |
| 1124 | qpdf_oh_is_name_and_equals(qpdf_data qpdf, qpdf_oh oh, char const* name) | 1078 | qpdf_oh_is_name_and_equals(qpdf_data qpdf, qpdf_oh oh, char const* name) |
| 1125 | { | 1079 | { |
| 1126 | - return do_with_oh<QPDF_BOOL>( | ||
| 1127 | - qpdf, oh, return_false, [name](QPDFObjectHandle& o) { | ||
| 1128 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_name_and_equals"); | ||
| 1129 | - return o.isNameAndEquals(name); | ||
| 1130 | - }); | 1080 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [name](QPDFObjectHandle& o) { |
| 1081 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_name_and_equals"); | ||
| 1082 | + return o.isNameAndEquals(name); | ||
| 1083 | + }); | ||
| 1131 | } | 1084 | } |
| 1132 | 1085 | ||
| 1133 | QPDF_BOOL | 1086 | QPDF_BOOL |
| 1134 | -qpdf_oh_is_dictionary_of_type( | ||
| 1135 | - qpdf_data qpdf, qpdf_oh oh, char const* type, char const* subtype) | 1087 | +qpdf_oh_is_dictionary_of_type(qpdf_data qpdf, qpdf_oh oh, char const* type, char const* subtype) |
| 1136 | { | 1088 | { |
| 1137 | auto stype = (subtype == nullptr) ? "" : subtype; | 1089 | auto stype = (subtype == nullptr) ? "" : subtype; |
| 1138 | - return do_with_oh<QPDF_BOOL>( | ||
| 1139 | - qpdf, oh, return_false, [type, stype](QPDFObjectHandle& o) { | ||
| 1140 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_dictionary_of_type"); | ||
| 1141 | - return o.isDictionaryOfType(type, stype); | ||
| 1142 | - }); | 1090 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [type, stype](QPDFObjectHandle& o) { |
| 1091 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_dictionary_of_type"); | ||
| 1092 | + return o.isDictionaryOfType(type, stype); | ||
| 1093 | + }); | ||
| 1143 | } | 1094 | } |
| 1144 | 1095 | ||
| 1145 | qpdf_object_type_e | 1096 | qpdf_object_type_e |
| 1146 | qpdf_oh_get_type_code(qpdf_data qpdf, qpdf_oh oh) | 1097 | qpdf_oh_get_type_code(qpdf_data qpdf, qpdf_oh oh) |
| 1147 | { | 1098 | { |
| 1148 | return do_with_oh<qpdf_object_type_e>( | 1099 | return do_with_oh<qpdf_object_type_e>( |
| 1149 | - qpdf, | ||
| 1150 | - oh, | ||
| 1151 | - return_T<qpdf_object_type_e>(ot_uninitialized), | ||
| 1152 | - [](QPDFObjectHandle& o) { | 1100 | + qpdf, oh, return_T<qpdf_object_type_e>(ot_uninitialized), [](QPDFObjectHandle& o) { |
| 1153 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_type_code"); | 1101 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_type_code"); |
| 1154 | return o.getTypeCode(); | 1102 | return o.getTypeCode(); |
| 1155 | }); | 1103 | }); |
| @@ -1180,9 +1128,7 @@ qpdf_oh_wrap_in_array(qpdf_data qpdf, qpdf_oh oh) | @@ -1180,9 +1128,7 @@ qpdf_oh_wrap_in_array(qpdf_data qpdf, qpdf_oh oh) | ||
| 1180 | } else { | 1128 | } else { |
| 1181 | QTC::TC("qpdf", "qpdf-c non-array to wrap_in_array"); | 1129 | QTC::TC("qpdf", "qpdf-c non-array to wrap_in_array"); |
| 1182 | return new_object( | 1130 | return new_object( |
| 1183 | - qpdf, | ||
| 1184 | - QPDFObjectHandle::newArray( | ||
| 1185 | - std::vector<QPDFObjectHandle>{qoh})); | 1131 | + qpdf, QPDFObjectHandle::newArray(std::vector<QPDFObjectHandle>{qoh})); |
| 1186 | } | 1132 | } |
| 1187 | }); | 1133 | }); |
| 1188 | } | 1134 | } |
| @@ -1191,55 +1137,50 @@ qpdf_oh | @@ -1191,55 +1137,50 @@ qpdf_oh | ||
| 1191 | qpdf_oh_parse(qpdf_data qpdf, char const* object_str) | 1137 | qpdf_oh_parse(qpdf_data qpdf, char const* object_str) |
| 1192 | { | 1138 | { |
| 1193 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_parse"); | 1139 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_parse"); |
| 1194 | - return trap_oh_errors<qpdf_oh>( | ||
| 1195 | - qpdf, return_uninitialized(qpdf), [object_str](qpdf_data q) { | ||
| 1196 | - return new_object(q, QPDFObjectHandle::parse(object_str)); | ||
| 1197 | - }); | 1140 | + return trap_oh_errors<qpdf_oh>(qpdf, return_uninitialized(qpdf), [object_str](qpdf_data q) { |
| 1141 | + return new_object(q, QPDFObjectHandle::parse(object_str)); | ||
| 1142 | + }); | ||
| 1198 | } | 1143 | } |
| 1199 | 1144 | ||
| 1200 | QPDF_BOOL | 1145 | QPDF_BOOL |
| 1201 | qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh) | 1146 | qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh) |
| 1202 | { | 1147 | { |
| 1203 | - return do_with_oh<QPDF_BOOL>( | ||
| 1204 | - qpdf, oh, return_false, [](QPDFObjectHandle& o) { | ||
| 1205 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_bool_value"); | ||
| 1206 | - return o.getBoolValue(); | ||
| 1207 | - }); | 1148 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [](QPDFObjectHandle& o) { |
| 1149 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_bool_value"); | ||
| 1150 | + return o.getBoolValue(); | ||
| 1151 | + }); | ||
| 1208 | } | 1152 | } |
| 1209 | 1153 | ||
| 1210 | QPDF_BOOL | 1154 | QPDF_BOOL |
| 1211 | qpdf_oh_get_value_as_bool(qpdf_data qpdf, qpdf_oh oh, QPDF_BOOL* value) | 1155 | qpdf_oh_get_value_as_bool(qpdf_data qpdf, qpdf_oh oh, QPDF_BOOL* value) |
| 1212 | { | 1156 | { |
| 1213 | - return do_with_oh<QPDF_BOOL>( | ||
| 1214 | - qpdf, oh, return_false, [value](QPDFObjectHandle& o) { | ||
| 1215 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_bool"); | ||
| 1216 | - bool v = *value; | ||
| 1217 | - QPDF_BOOL result = o.getValueAsBool(v); | ||
| 1218 | - if (result) { | ||
| 1219 | - *value = v; | ||
| 1220 | - } | ||
| 1221 | - return result; | ||
| 1222 | - }); | 1157 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) { |
| 1158 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_bool"); | ||
| 1159 | + bool v = *value; | ||
| 1160 | + QPDF_BOOL result = o.getValueAsBool(v); | ||
| 1161 | + if (result) { | ||
| 1162 | + *value = v; | ||
| 1163 | + } | ||
| 1164 | + return result; | ||
| 1165 | + }); | ||
| 1223 | } | 1166 | } |
| 1224 | 1167 | ||
| 1225 | long long | 1168 | long long |
| 1226 | qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh) | 1169 | qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh) |
| 1227 | { | 1170 | { |
| 1228 | - return do_with_oh<long long>( | ||
| 1229 | - qpdf, oh, return_T<long long>(0LL), [](QPDFObjectHandle& o) { | ||
| 1230 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_int_value"); | ||
| 1231 | - return o.getIntValue(); | ||
| 1232 | - }); | 1171 | + return do_with_oh<long long>(qpdf, oh, return_T<long long>(0LL), [](QPDFObjectHandle& o) { |
| 1172 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_int_value"); | ||
| 1173 | + return o.getIntValue(); | ||
| 1174 | + }); | ||
| 1233 | } | 1175 | } |
| 1234 | 1176 | ||
| 1235 | QPDF_BOOL | 1177 | QPDF_BOOL |
| 1236 | qpdf_oh_get_value_as_longlong(qpdf_data qpdf, qpdf_oh oh, long long* value) | 1178 | qpdf_oh_get_value_as_longlong(qpdf_data qpdf, qpdf_oh oh, long long* value) |
| 1237 | { | 1179 | { |
| 1238 | - return do_with_oh<QPDF_BOOL>( | ||
| 1239 | - qpdf, oh, return_false, [value](QPDFObjectHandle& o) { | ||
| 1240 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_longlong"); | ||
| 1241 | - return o.getValueAsInt(*value); | ||
| 1242 | - }); | 1180 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) { |
| 1181 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_longlong"); | ||
| 1182 | + return o.getValueAsInt(*value); | ||
| 1183 | + }); | ||
| 1243 | } | 1184 | } |
| 1244 | 1185 | ||
| 1245 | int | 1186 | int |
| @@ -1254,11 +1195,10 @@ qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh) | @@ -1254,11 +1195,10 @@ qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh) | ||
| 1254 | QPDF_BOOL | 1195 | QPDF_BOOL |
| 1255 | qpdf_oh_get_value_as_int(qpdf_data qpdf, qpdf_oh oh, int* value) | 1196 | qpdf_oh_get_value_as_int(qpdf_data qpdf, qpdf_oh oh, int* value) |
| 1256 | { | 1197 | { |
| 1257 | - return do_with_oh<QPDF_BOOL>( | ||
| 1258 | - qpdf, oh, return_false, [value](QPDFObjectHandle& o) { | ||
| 1259 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_int"); | ||
| 1260 | - return o.getValueAsInt(*value); | ||
| 1261 | - }); | 1198 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) { |
| 1199 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_int"); | ||
| 1200 | + return o.getValueAsInt(*value); | ||
| 1201 | + }); | ||
| 1262 | } | 1202 | } |
| 1263 | 1203 | ||
| 1264 | unsigned long long | 1204 | unsigned long long |
| @@ -1272,34 +1212,30 @@ qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh) | @@ -1272,34 +1212,30 @@ qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh) | ||
| 1272 | } | 1212 | } |
| 1273 | 1213 | ||
| 1274 | QPDF_BOOL | 1214 | QPDF_BOOL |
| 1275 | -qpdf_oh_get_value_as_ulonglong( | ||
| 1276 | - qpdf_data qpdf, qpdf_oh oh, unsigned long long* value) | 1215 | +qpdf_oh_get_value_as_ulonglong(qpdf_data qpdf, qpdf_oh oh, unsigned long long* value) |
| 1277 | { | 1216 | { |
| 1278 | - return do_with_oh<QPDF_BOOL>( | ||
| 1279 | - qpdf, oh, return_false, [value](QPDFObjectHandle& o) { | ||
| 1280 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_ulonglong"); | ||
| 1281 | - return o.getValueAsUInt(*value); | ||
| 1282 | - }); | 1217 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) { |
| 1218 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_ulonglong"); | ||
| 1219 | + return o.getValueAsUInt(*value); | ||
| 1220 | + }); | ||
| 1283 | } | 1221 | } |
| 1284 | 1222 | ||
| 1285 | unsigned int | 1223 | unsigned int |
| 1286 | qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh) | 1224 | qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh) |
| 1287 | { | 1225 | { |
| 1288 | - return do_with_oh<unsigned int>( | ||
| 1289 | - qpdf, oh, return_T<unsigned int>(0U), [](QPDFObjectHandle& o) { | ||
| 1290 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_uint_value_as_uint"); | ||
| 1291 | - return o.getUIntValueAsUInt(); | ||
| 1292 | - }); | 1226 | + return do_with_oh<unsigned int>(qpdf, oh, return_T<unsigned int>(0U), [](QPDFObjectHandle& o) { |
| 1227 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_uint_value_as_uint"); | ||
| 1228 | + return o.getUIntValueAsUInt(); | ||
| 1229 | + }); | ||
| 1293 | } | 1230 | } |
| 1294 | 1231 | ||
| 1295 | QPDF_BOOL | 1232 | QPDF_BOOL |
| 1296 | qpdf_oh_get_value_as_uint(qpdf_data qpdf, qpdf_oh oh, unsigned int* value) | 1233 | qpdf_oh_get_value_as_uint(qpdf_data qpdf, qpdf_oh oh, unsigned int* value) |
| 1297 | { | 1234 | { |
| 1298 | - return do_with_oh<QPDF_BOOL>( | ||
| 1299 | - qpdf, oh, return_false, [value](QPDFObjectHandle& o) { | ||
| 1300 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_uint"); | ||
| 1301 | - return o.getValueAsUInt(*value); | ||
| 1302 | - }); | 1235 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) { |
| 1236 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_uint"); | ||
| 1237 | + return o.getValueAsUInt(*value); | ||
| 1238 | + }); | ||
| 1303 | } | 1239 | } |
| 1304 | 1240 | ||
| 1305 | char const* | 1241 | char const* |
| @@ -1314,8 +1250,7 @@ qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh) | @@ -1314,8 +1250,7 @@ qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh) | ||
| 1314 | } | 1250 | } |
| 1315 | 1251 | ||
| 1316 | QPDF_BOOL | 1252 | QPDF_BOOL |
| 1317 | -qpdf_oh_get_value_as_real( | ||
| 1318 | - qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length) | 1253 | +qpdf_oh_get_value_as_real(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length) |
| 1319 | { | 1254 | { |
| 1320 | return do_with_oh<QPDF_BOOL>( | 1255 | return do_with_oh<QPDF_BOOL>( |
| 1321 | qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) { | 1256 | qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) { |
| @@ -1332,21 +1267,19 @@ qpdf_oh_get_value_as_real( | @@ -1332,21 +1267,19 @@ qpdf_oh_get_value_as_real( | ||
| 1332 | double | 1267 | double |
| 1333 | qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh) | 1268 | qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh) |
| 1334 | { | 1269 | { |
| 1335 | - return do_with_oh<double>( | ||
| 1336 | - qpdf, oh, return_T<double>(0.0), [](QPDFObjectHandle& o) { | ||
| 1337 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_numeric_value"); | ||
| 1338 | - return o.getNumericValue(); | ||
| 1339 | - }); | 1270 | + return do_with_oh<double>(qpdf, oh, return_T<double>(0.0), [](QPDFObjectHandle& o) { |
| 1271 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_numeric_value"); | ||
| 1272 | + return o.getNumericValue(); | ||
| 1273 | + }); | ||
| 1340 | } | 1274 | } |
| 1341 | 1275 | ||
| 1342 | QPDF_BOOL | 1276 | QPDF_BOOL |
| 1343 | qpdf_oh_get_value_as_number(qpdf_data qpdf, qpdf_oh oh, double* value) | 1277 | qpdf_oh_get_value_as_number(qpdf_data qpdf, qpdf_oh oh, double* value) |
| 1344 | { | 1278 | { |
| 1345 | - return do_with_oh<QPDF_BOOL>( | ||
| 1346 | - qpdf, oh, return_false, [value](QPDFObjectHandle& o) { | ||
| 1347 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_number"); | ||
| 1348 | - return o.getValueAsNumber(*value); | ||
| 1349 | - }); | 1279 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [value](QPDFObjectHandle& o) { |
| 1280 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_number"); | ||
| 1281 | + return o.getValueAsNumber(*value); | ||
| 1282 | + }); | ||
| 1350 | } | 1283 | } |
| 1351 | 1284 | ||
| 1352 | char const* | 1285 | char const* |
| @@ -1361,8 +1294,7 @@ qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh) | @@ -1361,8 +1294,7 @@ qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh) | ||
| 1361 | } | 1294 | } |
| 1362 | 1295 | ||
| 1363 | QPDF_BOOL | 1296 | QPDF_BOOL |
| 1364 | -qpdf_oh_get_value_as_name( | ||
| 1365 | - qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length) | 1297 | +qpdf_oh_get_value_as_name(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length) |
| 1366 | { | 1298 | { |
| 1367 | return do_with_oh<QPDF_BOOL>( | 1299 | return do_with_oh<QPDF_BOOL>( |
| 1368 | qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) { | 1300 | qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) { |
| @@ -1388,8 +1320,7 @@ qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh) | @@ -1388,8 +1320,7 @@ qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh) | ||
| 1388 | } | 1320 | } |
| 1389 | 1321 | ||
| 1390 | QPDF_BOOL | 1322 | QPDF_BOOL |
| 1391 | -qpdf_oh_get_value_as_string( | ||
| 1392 | - qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length) | 1323 | +qpdf_oh_get_value_as_string(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length) |
| 1393 | { | 1324 | { |
| 1394 | return do_with_oh<QPDF_BOOL>( | 1325 | return do_with_oh<QPDF_BOOL>( |
| 1395 | qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) { | 1326 | qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) { |
| @@ -1415,8 +1346,7 @@ qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh) | @@ -1415,8 +1346,7 @@ qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh) | ||
| 1415 | } | 1346 | } |
| 1416 | 1347 | ||
| 1417 | QPDF_BOOL | 1348 | QPDF_BOOL |
| 1418 | -qpdf_oh_get_value_as_utf8( | ||
| 1419 | - qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length) | 1349 | +qpdf_oh_get_value_as_utf8(qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length) |
| 1420 | { | 1350 | { |
| 1421 | return do_with_oh<QPDF_BOOL>( | 1351 | return do_with_oh<QPDF_BOOL>( |
| 1422 | qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) { | 1352 | qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) { |
| @@ -1434,10 +1364,7 @@ char const* | @@ -1434,10 +1364,7 @@ char const* | ||
| 1434 | qpdf_oh_get_binary_string_value(qpdf_data qpdf, qpdf_oh oh, size_t* length) | 1364 | qpdf_oh_get_binary_string_value(qpdf_data qpdf, qpdf_oh oh, size_t* length) |
| 1435 | { | 1365 | { |
| 1436 | return do_with_oh<char const*>( | 1366 | return do_with_oh<char const*>( |
| 1437 | - qpdf, | ||
| 1438 | - oh, | ||
| 1439 | - return_T<char const*>(""), | ||
| 1440 | - [qpdf, length](QPDFObjectHandle& o) { | 1367 | + qpdf, oh, return_T<char const*>(""), [qpdf, length](QPDFObjectHandle& o) { |
| 1441 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_binary_string_value"); | 1368 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_binary_string_value"); |
| 1442 | qpdf->tmp_string = o.getStringValue(); | 1369 | qpdf->tmp_string = o.getStringValue(); |
| 1443 | *length = qpdf->tmp_string.length(); | 1370 | *length = qpdf->tmp_string.length(); |
| @@ -1449,10 +1376,7 @@ char const* | @@ -1449,10 +1376,7 @@ char const* | ||
| 1449 | qpdf_oh_get_binary_utf8_value(qpdf_data qpdf, qpdf_oh oh, size_t* length) | 1376 | qpdf_oh_get_binary_utf8_value(qpdf_data qpdf, qpdf_oh oh, size_t* length) |
| 1450 | { | 1377 | { |
| 1451 | return do_with_oh<char const*>( | 1378 | return do_with_oh<char const*>( |
| 1452 | - qpdf, | ||
| 1453 | - oh, | ||
| 1454 | - return_T<char const*>(""), | ||
| 1455 | - [qpdf, length](QPDFObjectHandle& o) { | 1379 | + qpdf, oh, return_T<char const*>(""), [qpdf, length](QPDFObjectHandle& o) { |
| 1456 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_binary_utf8_value"); | 1380 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_binary_utf8_value"); |
| 1457 | qpdf->tmp_string = o.getUTF8Value(); | 1381 | qpdf->tmp_string = o.getUTF8Value(); |
| 1458 | *length = qpdf->tmp_string.length(); | 1382 | *length = qpdf->tmp_string.length(); |
| @@ -1472,11 +1396,10 @@ qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh) | @@ -1472,11 +1396,10 @@ qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh) | ||
| 1472 | qpdf_oh | 1396 | qpdf_oh |
| 1473 | qpdf_oh_get_array_item(qpdf_data qpdf, qpdf_oh oh, int n) | 1397 | qpdf_oh_get_array_item(qpdf_data qpdf, qpdf_oh oh, int n) |
| 1474 | { | 1398 | { |
| 1475 | - return do_with_oh<qpdf_oh>( | ||
| 1476 | - qpdf, oh, return_null(qpdf), [qpdf, n](QPDFObjectHandle& o) { | ||
| 1477 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_array_item"); | ||
| 1478 | - return new_object(qpdf, o.getArrayItem(n)); | ||
| 1479 | - }); | 1399 | + return do_with_oh<qpdf_oh>(qpdf, oh, return_null(qpdf), [qpdf, n](QPDFObjectHandle& o) { |
| 1400 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_array_item"); | ||
| 1401 | + return new_object(qpdf, o.getArrayItem(n)); | ||
| 1402 | + }); | ||
| 1480 | } | 1403 | } |
| 1481 | 1404 | ||
| 1482 | void | 1405 | void |
| @@ -1516,41 +1439,37 @@ qpdf_oh_dict_next_key(qpdf_data qpdf) | @@ -1516,41 +1439,37 @@ qpdf_oh_dict_next_key(qpdf_data qpdf) | ||
| 1516 | QPDF_BOOL | 1439 | QPDF_BOOL |
| 1517 | qpdf_oh_has_key(qpdf_data qpdf, qpdf_oh oh, char const* key) | 1440 | qpdf_oh_has_key(qpdf_data qpdf, qpdf_oh oh, char const* key) |
| 1518 | { | 1441 | { |
| 1519 | - return do_with_oh<QPDF_BOOL>( | ||
| 1520 | - qpdf, oh, return_false, [key](QPDFObjectHandle& o) { | ||
| 1521 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_has_key"); | ||
| 1522 | - return o.hasKey(key); | ||
| 1523 | - }); | 1442 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [key](QPDFObjectHandle& o) { |
| 1443 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_has_key"); | ||
| 1444 | + return o.hasKey(key); | ||
| 1445 | + }); | ||
| 1524 | } | 1446 | } |
| 1525 | 1447 | ||
| 1526 | qpdf_oh | 1448 | qpdf_oh |
| 1527 | qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key) | 1449 | qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key) |
| 1528 | { | 1450 | { |
| 1529 | - return do_with_oh<qpdf_oh>( | ||
| 1530 | - qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) { | ||
| 1531 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key"); | ||
| 1532 | - return new_object(qpdf, o.getKey(key)); | ||
| 1533 | - }); | 1451 | + return do_with_oh<qpdf_oh>(qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) { |
| 1452 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key"); | ||
| 1453 | + return new_object(qpdf, o.getKey(key)); | ||
| 1454 | + }); | ||
| 1534 | } | 1455 | } |
| 1535 | 1456 | ||
| 1536 | qpdf_oh | 1457 | qpdf_oh |
| 1537 | qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key) | 1458 | qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key) |
| 1538 | { | 1459 | { |
| 1539 | - return do_with_oh<qpdf_oh>( | ||
| 1540 | - qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) { | ||
| 1541 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key_if_dict"); | ||
| 1542 | - return new_object(qpdf, o.getKeyIfDict(key)); | ||
| 1543 | - }); | 1460 | + return do_with_oh<qpdf_oh>(qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) { |
| 1461 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key_if_dict"); | ||
| 1462 | + return new_object(qpdf, o.getKeyIfDict(key)); | ||
| 1463 | + }); | ||
| 1544 | } | 1464 | } |
| 1545 | 1465 | ||
| 1546 | QPDF_BOOL | 1466 | QPDF_BOOL |
| 1547 | qpdf_oh_is_or_has_name(qpdf_data qpdf, qpdf_oh oh, char const* key) | 1467 | qpdf_oh_is_or_has_name(qpdf_data qpdf, qpdf_oh oh, char const* key) |
| 1548 | { | 1468 | { |
| 1549 | - return do_with_oh<QPDF_BOOL>( | ||
| 1550 | - qpdf, oh, return_false, [key](QPDFObjectHandle& o) { | ||
| 1551 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_or_has_name"); | ||
| 1552 | - return o.isOrHasName(key); | ||
| 1553 | - }); | 1469 | + return do_with_oh<QPDF_BOOL>(qpdf, oh, return_false, [key](QPDFObjectHandle& o) { |
| 1470 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_or_has_name"); | ||
| 1471 | + return o.isOrHasName(key); | ||
| 1472 | + }); | ||
| 1554 | } | 1473 | } |
| 1555 | 1474 | ||
| 1556 | qpdf_oh | 1475 | qpdf_oh |
| @@ -1620,18 +1539,14 @@ qpdf_oh | @@ -1620,18 +1539,14 @@ qpdf_oh | ||
| 1620 | qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length) | 1539 | qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length) |
| 1621 | { | 1540 | { |
| 1622 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_binary_string"); | 1541 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_binary_string"); |
| 1623 | - return new_object( | ||
| 1624 | - qpdf, QPDFObjectHandle::newString(std::string(str, length))); | 1542 | + return new_object(qpdf, QPDFObjectHandle::newString(std::string(str, length))); |
| 1625 | } | 1543 | } |
| 1626 | 1544 | ||
| 1627 | qpdf_oh | 1545 | qpdf_oh |
| 1628 | -qpdf_oh_new_binary_unicode_string( | ||
| 1629 | - qpdf_data qpdf, char const* utf8_str, size_t length) | 1546 | +qpdf_oh_new_binary_unicode_string(qpdf_data qpdf, char const* utf8_str, size_t length) |
| 1630 | { | 1547 | { |
| 1631 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_binary_unicode_string"); | 1548 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_binary_unicode_string"); |
| 1632 | - return new_object( | ||
| 1633 | - qpdf, | ||
| 1634 | - QPDFObjectHandle::newUnicodeString(std::string(utf8_str, length))); | 1549 | + return new_object(qpdf, QPDFObjectHandle::newUnicodeString(std::string(utf8_str, length))); |
| 1635 | } | 1550 | } |
| 1636 | 1551 | ||
| 1637 | qpdf_oh | 1552 | qpdf_oh |
| @@ -1667,10 +1582,9 @@ qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh) | @@ -1667,10 +1582,9 @@ qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh) | ||
| 1667 | qpdf_oh | 1582 | qpdf_oh |
| 1668 | qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh) | 1583 | qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh) |
| 1669 | { | 1584 | { |
| 1670 | - return do_with_oh<qpdf_oh>( | ||
| 1671 | - qpdf, oh, return_uninitialized(qpdf), [qpdf](QPDFObjectHandle& o) { | ||
| 1672 | - return new_object(qpdf, qpdf->qpdf->makeIndirectObject(o)); | ||
| 1673 | - }); | 1585 | + return do_with_oh<qpdf_oh>(qpdf, oh, return_uninitialized(qpdf), [qpdf](QPDFObjectHandle& o) { |
| 1586 | + return new_object(qpdf, qpdf->qpdf->makeIndirectObject(o)); | ||
| 1587 | + }); | ||
| 1674 | } | 1588 | } |
| 1675 | 1589 | ||
| 1676 | static QPDFObjectHandle | 1590 | static QPDFObjectHandle |
| @@ -1738,8 +1652,7 @@ qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key) | @@ -1738,8 +1652,7 @@ qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key) | ||
| 1738 | } | 1652 | } |
| 1739 | 1653 | ||
| 1740 | void | 1654 | void |
| 1741 | -qpdf_oh_replace_or_remove_key( | ||
| 1742 | - qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item) | 1655 | +qpdf_oh_replace_or_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item) |
| 1743 | { | 1656 | { |
| 1744 | do_with_oh_void(qpdf, oh, [qpdf, key, item](QPDFObjectHandle& o) { | 1657 | do_with_oh_void(qpdf, oh, [qpdf, key, item](QPDFObjectHandle& o) { |
| 1745 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_or_remove_key"); | 1658 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_or_remove_key"); |
| @@ -1750,11 +1663,10 @@ qpdf_oh_replace_or_remove_key( | @@ -1750,11 +1663,10 @@ qpdf_oh_replace_or_remove_key( | ||
| 1750 | qpdf_oh | 1663 | qpdf_oh |
| 1751 | qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh) | 1664 | qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh) |
| 1752 | { | 1665 | { |
| 1753 | - return do_with_oh<qpdf_oh>( | ||
| 1754 | - qpdf, oh, return_null(qpdf), [qpdf](QPDFObjectHandle& o) { | ||
| 1755 | - QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_dict"); | ||
| 1756 | - return new_object(qpdf, o.getDict()); | ||
| 1757 | - }); | 1666 | + return do_with_oh<qpdf_oh>(qpdf, oh, return_null(qpdf), [qpdf](QPDFObjectHandle& o) { |
| 1667 | + QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_dict"); | ||
| 1668 | + return new_object(qpdf, o.getDict()); | ||
| 1669 | + }); | ||
| 1758 | } | 1670 | } |
| 1759 | 1671 | ||
| 1760 | int | 1672 | int |
| @@ -1809,14 +1721,10 @@ qpdf_oh_unparse_binary(qpdf_data qpdf, qpdf_oh oh) | @@ -1809,14 +1721,10 @@ qpdf_oh_unparse_binary(qpdf_data qpdf, qpdf_oh oh) | ||
| 1809 | } | 1721 | } |
| 1810 | 1722 | ||
| 1811 | qpdf_oh | 1723 | qpdf_oh |
| 1812 | -qpdf_oh_copy_foreign_object( | ||
| 1813 | - qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh) | 1724 | +qpdf_oh_copy_foreign_object(qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh) |
| 1814 | { | 1725 | { |
| 1815 | return do_with_oh<qpdf_oh>( | 1726 | return do_with_oh<qpdf_oh>( |
| 1816 | - other_qpdf, | ||
| 1817 | - foreign_oh, | ||
| 1818 | - return_uninitialized(qpdf), | ||
| 1819 | - [qpdf](QPDFObjectHandle& o) { | 1727 | + other_qpdf, foreign_oh, return_uninitialized(qpdf), [qpdf](QPDFObjectHandle& o) { |
| 1820 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_copy_foreign_object"); | 1728 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_copy_foreign_object"); |
| 1821 | return new_object(qpdf, qpdf->qpdf->copyForeignObject(o)); | 1729 | return new_object(qpdf, qpdf->qpdf->copyForeignObject(o)); |
| 1822 | }); | 1730 | }); |
| @@ -1831,39 +1739,31 @@ qpdf_oh_get_stream_data( | @@ -1831,39 +1739,31 @@ qpdf_oh_get_stream_data( | ||
| 1831 | unsigned char** bufp, | 1739 | unsigned char** bufp, |
| 1832 | size_t* len) | 1740 | size_t* len) |
| 1833 | { | 1741 | { |
| 1834 | - return trap_errors( | ||
| 1835 | - qpdf, [stream_oh, decode_level, filtered, bufp, len](qpdf_data q) { | ||
| 1836 | - auto stream = qpdf_oh_item_internal(q, stream_oh); | ||
| 1837 | - Pipeline* p = nullptr; | ||
| 1838 | - Pl_Buffer buf("stream data"); | ||
| 1839 | - if (bufp) { | ||
| 1840 | - p = &buf; | 1742 | + return trap_errors(qpdf, [stream_oh, decode_level, filtered, bufp, len](qpdf_data q) { |
| 1743 | + auto stream = qpdf_oh_item_internal(q, stream_oh); | ||
| 1744 | + Pipeline* p = nullptr; | ||
| 1745 | + Pl_Buffer buf("stream data"); | ||
| 1746 | + if (bufp) { | ||
| 1747 | + p = &buf; | ||
| 1748 | + } | ||
| 1749 | + bool was_filtered = false; | ||
| 1750 | + if (stream.pipeStreamData(p, &was_filtered, 0, decode_level, false, false)) { | ||
| 1751 | + QTC::TC("qpdf", "qpdf-c stream data buf set", bufp ? 0 : 1); | ||
| 1752 | + if (p && bufp && len) { | ||
| 1753 | + buf.getMallocBuffer(bufp, len); | ||
| 1841 | } | 1754 | } |
| 1842 | - bool was_filtered = false; | ||
| 1843 | - if (stream.pipeStreamData( | ||
| 1844 | - p, &was_filtered, 0, decode_level, false, false)) { | ||
| 1845 | - QTC::TC("qpdf", "qpdf-c stream data buf set", bufp ? 0 : 1); | ||
| 1846 | - if (p && bufp && len) { | ||
| 1847 | - buf.getMallocBuffer(bufp, len); | ||
| 1848 | - } | ||
| 1849 | - QTC::TC( | ||
| 1850 | - "qpdf", | ||
| 1851 | - "qpdf-c stream data filtered set", | ||
| 1852 | - filtered ? 0 : 1); | ||
| 1853 | - if (filtered) { | ||
| 1854 | - *filtered = was_filtered ? QPDF_TRUE : QPDF_FALSE; | ||
| 1855 | - } | ||
| 1856 | - } else { | ||
| 1857 | - throw std::runtime_error( | ||
| 1858 | - "unable to access stream data for stream " + | ||
| 1859 | - stream.unparse()); | 1755 | + QTC::TC("qpdf", "qpdf-c stream data filtered set", filtered ? 0 : 1); |
| 1756 | + if (filtered) { | ||
| 1757 | + *filtered = was_filtered ? QPDF_TRUE : QPDF_FALSE; | ||
| 1860 | } | 1758 | } |
| 1861 | - }); | 1759 | + } else { |
| 1760 | + throw std::runtime_error("unable to access stream data for stream " + stream.unparse()); | ||
| 1761 | + } | ||
| 1762 | + }); | ||
| 1862 | } | 1763 | } |
| 1863 | 1764 | ||
| 1864 | QPDF_ERROR_CODE | 1765 | QPDF_ERROR_CODE |
| 1865 | -qpdf_oh_get_page_content_data( | ||
| 1866 | - qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len) | 1766 | +qpdf_oh_get_page_content_data(qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len) |
| 1867 | { | 1767 | { |
| 1868 | return trap_errors(qpdf, [page_oh, bufp, len](qpdf_data q) { | 1768 | return trap_errors(qpdf, [page_oh, bufp, len](qpdf_data q) { |
| 1869 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_page_content_data"); | 1769 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_page_content_data"); |
| @@ -1884,17 +1784,13 @@ qpdf_oh_replace_stream_data( | @@ -1884,17 +1784,13 @@ qpdf_oh_replace_stream_data( | ||
| 1884 | qpdf_oh decode_parms_oh) | 1784 | qpdf_oh decode_parms_oh) |
| 1885 | { | 1785 | { |
| 1886 | do_with_oh_void( | 1786 | do_with_oh_void( |
| 1887 | - qpdf, | ||
| 1888 | - stream_oh, | ||
| 1889 | - [qpdf, buf, len, filter_oh, decode_parms_oh](QPDFObjectHandle& o) { | 1787 | + qpdf, stream_oh, [qpdf, buf, len, filter_oh, decode_parms_oh](QPDFObjectHandle& o) { |
| 1890 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_stream_data"); | 1788 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_stream_data"); |
| 1891 | auto filter = qpdf_oh_item_internal(qpdf, filter_oh); | 1789 | auto filter = qpdf_oh_item_internal(qpdf, filter_oh); |
| 1892 | auto decode_parms = qpdf_oh_item_internal(qpdf, decode_parms_oh); | 1790 | auto decode_parms = qpdf_oh_item_internal(qpdf, decode_parms_oh); |
| 1893 | // XXX test with binary data with null | 1791 | // XXX test with binary data with null |
| 1894 | o.replaceStreamData( | 1792 | o.replaceStreamData( |
| 1895 | - std::string(reinterpret_cast<char const*>(buf), len), | ||
| 1896 | - filter, | ||
| 1897 | - decode_parms); | 1793 | + std::string(reinterpret_cast<char const*>(buf), len), filter, decode_parms); |
| 1898 | }); | 1794 | }); |
| 1899 | } | 1795 | } |
| 1900 | 1796 | ||
| @@ -1903,9 +1799,8 @@ qpdf_get_num_pages(qpdf_data qpdf) | @@ -1903,9 +1799,8 @@ qpdf_get_num_pages(qpdf_data qpdf) | ||
| 1903 | { | 1799 | { |
| 1904 | QTC::TC("qpdf", "qpdf-c called qpdf_num_pages"); | 1800 | QTC::TC("qpdf", "qpdf-c called qpdf_num_pages"); |
| 1905 | int n = -1; | 1801 | int n = -1; |
| 1906 | - QPDF_ERROR_CODE code = trap_errors(qpdf, [&n](qpdf_data q) { | ||
| 1907 | - n = QIntC::to_int(q->qpdf->getAllPages().size()); | ||
| 1908 | - }); | 1802 | + QPDF_ERROR_CODE code = |
| 1803 | + trap_errors(qpdf, [&n](qpdf_data q) { n = QIntC::to_int(q->qpdf->getAllPages().size()); }); | ||
| 1909 | if (code & QPDF_ERRORS) { | 1804 | if (code & QPDF_ERRORS) { |
| 1910 | return -1; | 1805 | return -1; |
| 1911 | } | 1806 | } |
| @@ -1917,9 +1812,8 @@ qpdf_get_page_n(qpdf_data qpdf, size_t i) | @@ -1917,9 +1812,8 @@ qpdf_get_page_n(qpdf_data qpdf, size_t i) | ||
| 1917 | { | 1812 | { |
| 1918 | QTC::TC("qpdf", "qpdf-c called qpdf_get_page_n"); | 1813 | QTC::TC("qpdf", "qpdf-c called qpdf_get_page_n"); |
| 1919 | qpdf_oh result = 0; | 1814 | qpdf_oh result = 0; |
| 1920 | - QPDF_ERROR_CODE code = trap_errors(qpdf, [&result, i](qpdf_data q) { | ||
| 1921 | - result = new_object(q, q->qpdf->getAllPages().at(i)); | ||
| 1922 | - }); | 1815 | + QPDF_ERROR_CODE code = trap_errors( |
| 1816 | + qpdf, [&result, i](qpdf_data q) { result = new_object(q, q->qpdf->getAllPages().at(i)); }); | ||
| 1923 | if ((code & QPDF_ERRORS) || (result == 0)) { | 1817 | if ((code & QPDF_ERRORS) || (result == 0)) { |
| 1924 | return qpdf_oh_new_uninitialized(qpdf); | 1818 | return qpdf_oh_new_uninitialized(qpdf); |
| 1925 | } | 1819 | } |
| @@ -1930,8 +1824,7 @@ QPDF_ERROR_CODE | @@ -1930,8 +1824,7 @@ QPDF_ERROR_CODE | ||
| 1930 | qpdf_update_all_pages_cache(qpdf_data qpdf) | 1824 | qpdf_update_all_pages_cache(qpdf_data qpdf) |
| 1931 | { | 1825 | { |
| 1932 | QTC::TC("qpdf", "qpdf-c called qpdf_update_all_pages_cache"); | 1826 | QTC::TC("qpdf", "qpdf-c called qpdf_update_all_pages_cache"); |
| 1933 | - return trap_errors( | ||
| 1934 | - qpdf, [](qpdf_data q) { q->qpdf->updateAllPagesCache(); }); | 1827 | + return trap_errors(qpdf, [](qpdf_data q) { q->qpdf->updateAllPagesCache(); }); |
| 1935 | } | 1828 | } |
| 1936 | 1829 | ||
| 1937 | int | 1830 | int |
| @@ -1940,9 +1833,8 @@ qpdf_find_page_by_id(qpdf_data qpdf, int objid, int generation) | @@ -1940,9 +1833,8 @@ qpdf_find_page_by_id(qpdf_data qpdf, int objid, int generation) | ||
| 1940 | QTC::TC("qpdf", "qpdf-c called qpdf_find_page_by_id"); | 1833 | QTC::TC("qpdf", "qpdf-c called qpdf_find_page_by_id"); |
| 1941 | int n = -1; | 1834 | int n = -1; |
| 1942 | QPDFObjGen og(objid, generation); | 1835 | QPDFObjGen og(objid, generation); |
| 1943 | - QPDF_ERROR_CODE code = trap_errors(qpdf, [&n, &og](qpdf_data q) { | ||
| 1944 | - n = QIntC::to_int(q->qpdf->findPage(og)); | ||
| 1945 | - }); | 1836 | + QPDF_ERROR_CODE code = |
| 1837 | + trap_errors(qpdf, [&n, &og](qpdf_data q) { n = QIntC::to_int(q->qpdf->findPage(og)); }); | ||
| 1946 | if (code & QPDF_ERRORS) { | 1838 | if (code & QPDF_ERRORS) { |
| 1947 | return -1; | 1839 | return -1; |
| 1948 | } | 1840 | } |
| @@ -1953,44 +1845,35 @@ int | @@ -1953,44 +1845,35 @@ int | ||
| 1953 | qpdf_find_page_by_oh(qpdf_data qpdf, qpdf_oh oh) | 1845 | qpdf_find_page_by_oh(qpdf_data qpdf, qpdf_oh oh) |
| 1954 | { | 1846 | { |
| 1955 | QTC::TC("qpdf", "qpdf-c called qpdf_find_page_by_oh"); | 1847 | QTC::TC("qpdf", "qpdf-c called qpdf_find_page_by_oh"); |
| 1956 | - return do_with_oh<int>( | ||
| 1957 | - qpdf, oh, return_T<int>(-1), [qpdf](QPDFObjectHandle& o) { | ||
| 1958 | - return qpdf->qpdf->findPage(o); | ||
| 1959 | - }); | 1848 | + return do_with_oh<int>(qpdf, oh, return_T<int>(-1), [qpdf](QPDFObjectHandle& o) { |
| 1849 | + return qpdf->qpdf->findPage(o); | ||
| 1850 | + }); | ||
| 1960 | } | 1851 | } |
| 1961 | 1852 | ||
| 1962 | QPDF_ERROR_CODE | 1853 | QPDF_ERROR_CODE |
| 1963 | qpdf_push_inherited_attributes_to_page(qpdf_data qpdf) | 1854 | qpdf_push_inherited_attributes_to_page(qpdf_data qpdf) |
| 1964 | { | 1855 | { |
| 1965 | QTC::TC("qpdf", "qpdf-c called qpdf_push_inherited_attributes_to_page"); | 1856 | QTC::TC("qpdf", "qpdf-c called qpdf_push_inherited_attributes_to_page"); |
| 1966 | - return trap_errors( | ||
| 1967 | - qpdf, [](qpdf_data q) { q->qpdf->pushInheritedAttributesToPage(); }); | 1857 | + return trap_errors(qpdf, [](qpdf_data q) { q->qpdf->pushInheritedAttributesToPage(); }); |
| 1968 | } | 1858 | } |
| 1969 | 1859 | ||
| 1970 | QPDF_ERROR_CODE | 1860 | QPDF_ERROR_CODE |
| 1971 | -qpdf_add_page( | ||
| 1972 | - qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL first) | 1861 | +qpdf_add_page(qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL first) |
| 1973 | { | 1862 | { |
| 1974 | QTC::TC("qpdf", "qpdf-c called qpdf_add_page"); | 1863 | QTC::TC("qpdf", "qpdf-c called qpdf_add_page"); |
| 1975 | auto page = qpdf_oh_item_internal(newpage_qpdf, newpage); | 1864 | auto page = qpdf_oh_item_internal(newpage_qpdf, newpage); |
| 1976 | - return trap_errors( | ||
| 1977 | - qpdf, [&page, first](qpdf_data q) { q->qpdf->addPage(page, first); }); | 1865 | + return trap_errors(qpdf, [&page, first](qpdf_data q) { q->qpdf->addPage(page, first); }); |
| 1978 | } | 1866 | } |
| 1979 | 1867 | ||
| 1980 | QPDF_ERROR_CODE | 1868 | QPDF_ERROR_CODE |
| 1981 | qpdf_add_page_at( | 1869 | qpdf_add_page_at( |
| 1982 | - qpdf_data qpdf, | ||
| 1983 | - qpdf_data newpage_qpdf, | ||
| 1984 | - qpdf_oh newpage, | ||
| 1985 | - QPDF_BOOL before, | ||
| 1986 | - qpdf_oh refpage) | 1870 | + qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL before, qpdf_oh refpage) |
| 1987 | { | 1871 | { |
| 1988 | QTC::TC("qpdf", "qpdf-c called qpdf_add_page_at"); | 1872 | QTC::TC("qpdf", "qpdf-c called qpdf_add_page_at"); |
| 1989 | auto page = qpdf_oh_item_internal(newpage_qpdf, newpage); | 1873 | auto page = qpdf_oh_item_internal(newpage_qpdf, newpage); |
| 1990 | auto ref = qpdf_oh_item_internal(qpdf, refpage); | 1874 | auto ref = qpdf_oh_item_internal(qpdf, refpage); |
| 1991 | - return trap_errors(qpdf, [&page, before, &ref](qpdf_data q) { | ||
| 1992 | - q->qpdf->addPageAt(page, before, ref); | ||
| 1993 | - }); | 1875 | + return trap_errors( |
| 1876 | + qpdf, [&page, before, &ref](qpdf_data q) { q->qpdf->addPageAt(page, before, ref); }); | ||
| 1994 | } | 1877 | } |
| 1995 | 1878 | ||
| 1996 | QPDF_ERROR_CODE | 1879 | QPDF_ERROR_CODE |
| @@ -2006,24 +1889,20 @@ qpdf_create_from_json_file(qpdf_data qpdf, char const* filename) | @@ -2006,24 +1889,20 @@ qpdf_create_from_json_file(qpdf_data qpdf, char const* filename) | ||
| 2006 | { | 1889 | { |
| 2007 | QPDF_ERROR_CODE status = QPDF_SUCCESS; | 1890 | QPDF_ERROR_CODE status = QPDF_SUCCESS; |
| 2008 | qpdf->filename = filename; | 1891 | qpdf->filename = filename; |
| 2009 | - status = trap_errors( | ||
| 2010 | - qpdf, [](qpdf_data q) { q->qpdf->createFromJSON(q->filename); }); | 1892 | + status = trap_errors(qpdf, [](qpdf_data q) { q->qpdf->createFromJSON(q->filename); }); |
| 2011 | return status; | 1893 | return status; |
| 2012 | } | 1894 | } |
| 2013 | 1895 | ||
| 2014 | QPDF_ERROR_CODE | 1896 | QPDF_ERROR_CODE |
| 2015 | -qpdf_create_from_json_data( | ||
| 2016 | - qpdf_data qpdf, char const* buffer, unsigned long long size) | 1897 | +qpdf_create_from_json_data(qpdf_data qpdf, char const* buffer, unsigned long long size) |
| 2017 | { | 1898 | { |
| 2018 | QPDF_ERROR_CODE status = QPDF_SUCCESS; | 1899 | QPDF_ERROR_CODE status = QPDF_SUCCESS; |
| 2019 | qpdf->filename = "json buffer"; | 1900 | qpdf->filename = "json buffer"; |
| 2020 | qpdf->buffer = buffer; | 1901 | qpdf->buffer = buffer; |
| 2021 | qpdf->size = size; | 1902 | qpdf->size = size; |
| 2022 | - auto b = | ||
| 2023 | - new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size)); | 1903 | + auto b = new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size)); |
| 2024 | auto is = std::make_shared<BufferInputSource>(qpdf->filename, b, true); | 1904 | auto is = std::make_shared<BufferInputSource>(qpdf->filename, b, true); |
| 2025 | - status = | ||
| 2026 | - trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->createFromJSON(is); }); | 1905 | + status = trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->createFromJSON(is); }); |
| 2027 | return status; | 1906 | return status; |
| 2028 | } | 1907 | } |
| 2029 | 1908 | ||
| @@ -2031,21 +1910,17 @@ QPDF_ERROR_CODE | @@ -2031,21 +1910,17 @@ QPDF_ERROR_CODE | ||
| 2031 | qpdf_update_from_json_file(qpdf_data qpdf, char const* filename) | 1910 | qpdf_update_from_json_file(qpdf_data qpdf, char const* filename) |
| 2032 | { | 1911 | { |
| 2033 | QPDF_ERROR_CODE status = QPDF_SUCCESS; | 1912 | QPDF_ERROR_CODE status = QPDF_SUCCESS; |
| 2034 | - status = trap_errors( | ||
| 2035 | - qpdf, [filename](qpdf_data q) { q->qpdf->updateFromJSON(filename); }); | 1913 | + status = trap_errors(qpdf, [filename](qpdf_data q) { q->qpdf->updateFromJSON(filename); }); |
| 2036 | return status; | 1914 | return status; |
| 2037 | } | 1915 | } |
| 2038 | 1916 | ||
| 2039 | QPDF_ERROR_CODE | 1917 | QPDF_ERROR_CODE |
| 2040 | -qpdf_update_from_json_data( | ||
| 2041 | - qpdf_data qpdf, char const* buffer, unsigned long long size) | 1918 | +qpdf_update_from_json_data(qpdf_data qpdf, char const* buffer, unsigned long long size) |
| 2042 | { | 1919 | { |
| 2043 | QPDF_ERROR_CODE status = QPDF_SUCCESS; | 1920 | QPDF_ERROR_CODE status = QPDF_SUCCESS; |
| 2044 | - auto b = | ||
| 2045 | - new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size)); | 1921 | + auto b = new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size)); |
| 2046 | auto is = std::make_shared<BufferInputSource>(qpdf->filename, b, true); | 1922 | auto is = std::make_shared<BufferInputSource>(qpdf->filename, b, true); |
| 2047 | - status = | ||
| 2048 | - trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->updateFromJSON(is); }); | 1923 | + status = trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->updateFromJSON(is); }); |
| 2049 | return status; | 1924 | return status; |
| 2050 | } | 1925 | } |
| 2051 | 1926 | ||
| @@ -2070,19 +1945,10 @@ qpdf_write_json( | @@ -2070,19 +1945,10 @@ qpdf_write_json( | ||
| 2070 | } | 1945 | } |
| 2071 | status = trap_errors( | 1946 | status = trap_errors( |
| 2072 | qpdf, | 1947 | qpdf, |
| 2073 | - [version, | ||
| 2074 | - p, | ||
| 2075 | - decode_level, | ||
| 2076 | - json_stream_data, | ||
| 2077 | - file_prefix, | ||
| 2078 | - &wanted_objects_set](qpdf_data q) { | 1948 | + [version, p, decode_level, json_stream_data, file_prefix, &wanted_objects_set]( |
| 1949 | + qpdf_data q) { | ||
| 2079 | q->qpdf->writeJSON( | 1950 | q->qpdf->writeJSON( |
| 2080 | - version, | ||
| 2081 | - p.get(), | ||
| 2082 | - decode_level, | ||
| 2083 | - json_stream_data, | ||
| 2084 | - file_prefix, | ||
| 2085 | - wanted_objects_set); | 1951 | + version, p.get(), decode_level, json_stream_data, file_prefix, wanted_objects_set); |
| 2086 | }); | 1952 | }); |
| 2087 | return status; | 1953 | return status; |
| 2088 | } | 1954 | } |
libqpdf/qpdf/JSONHandler.hh
| @@ -27,14 +27,10 @@ class JSONHandler | @@ -27,14 +27,10 @@ class JSONHandler | ||
| 27 | // called. There is no "final" handler -- if the top-level is a | 27 | // called. There is no "final" handler -- if the top-level is a |
| 28 | // dictionary or array, just use its end handler. | 28 | // dictionary or array, just use its end handler. |
| 29 | 29 | ||
| 30 | - typedef std::function<void(std::string const& path, JSON value)> | ||
| 31 | - json_handler_t; | 30 | + typedef std::function<void(std::string const& path, JSON value)> json_handler_t; |
| 32 | typedef std::function<void(std::string const& path)> void_handler_t; | 31 | typedef std::function<void(std::string const& path)> void_handler_t; |
| 33 | - typedef std::function<void( | ||
| 34 | - std::string const& path, std::string const& value)> | ||
| 35 | - string_handler_t; | ||
| 36 | - typedef std::function<void(std::string const& path, bool value)> | ||
| 37 | - bool_handler_t; | 32 | + typedef std::function<void(std::string const& path, std::string const& value)> string_handler_t; |
| 33 | + typedef std::function<void(std::string const& path, bool value)> bool_handler_t; | ||
| 38 | 34 | ||
| 39 | // If an any handler is added, it will be called for any value | 35 | // If an any handler is added, it will be called for any value |
| 40 | // including null, and no other handler will be called. | 36 | // including null, and no other handler will be called. |
| @@ -48,14 +44,11 @@ class JSONHandler | @@ -48,14 +44,11 @@ class JSONHandler | ||
| 48 | void addBoolHandler(bool_handler_t fn); | 44 | void addBoolHandler(bool_handler_t fn); |
| 49 | 45 | ||
| 50 | void addDictHandlers(json_handler_t start_fn, void_handler_t end_fn); | 46 | void addDictHandlers(json_handler_t start_fn, void_handler_t end_fn); |
| 51 | - void | ||
| 52 | - addDictKeyHandler(std::string const& key, std::shared_ptr<JSONHandler>); | 47 | + void addDictKeyHandler(std::string const& key, std::shared_ptr<JSONHandler>); |
| 53 | void addFallbackDictHandler(std::shared_ptr<JSONHandler>); | 48 | void addFallbackDictHandler(std::shared_ptr<JSONHandler>); |
| 54 | 49 | ||
| 55 | void addArrayHandlers( | 50 | void addArrayHandlers( |
| 56 | - json_handler_t start_fn, | ||
| 57 | - void_handler_t end_fn, | ||
| 58 | - std::shared_ptr<JSONHandler> item_handlers); | 51 | + json_handler_t start_fn, void_handler_t end_fn, std::shared_ptr<JSONHandler> item_handlers); |
| 59 | 52 | ||
| 60 | // Apply handlers recursively to a JSON object. | 53 | // Apply handlers recursively to a JSON object. |
| 61 | void handle(std::string const& path, JSON j); | 54 | void handle(std::string const& path, JSON j); |
libqpdf/qpdf/MD5.hh
| @@ -38,14 +38,10 @@ class MD5 | @@ -38,14 +38,10 @@ class MD5 | ||
| 38 | 38 | ||
| 39 | // Convenience functions | 39 | // Convenience functions |
| 40 | static std::string getDataChecksum(char const* buf, size_t len); | 40 | static std::string getDataChecksum(char const* buf, size_t len); |
| 41 | - static std::string | ||
| 42 | - getFileChecksum(char const* filename, qpdf_offset_t up_to_offset = -1); | ||
| 43 | - static bool | ||
| 44 | - checkDataChecksum(char const* const checksum, char const* buf, size_t len); | 41 | + static std::string getFileChecksum(char const* filename, qpdf_offset_t up_to_offset = -1); |
| 42 | + static bool checkDataChecksum(char const* const checksum, char const* buf, size_t len); | ||
| 45 | static bool checkFileChecksum( | 43 | static bool checkFileChecksum( |
| 46 | - char const* const checksum, | ||
| 47 | - char const* filename, | ||
| 48 | - qpdf_offset_t up_to_offset = -1); | 44 | + char const* const checksum, char const* filename, qpdf_offset_t up_to_offset = -1); |
| 49 | 45 | ||
| 50 | private: | 46 | private: |
| 51 | void init(); | 47 | void init(); |
libqpdf/qpdf/NNTree.hh
| @@ -76,11 +76,9 @@ class NNTreeIterator | @@ -76,11 +76,9 @@ class NNTreeIterator | ||
| 76 | void addPathElement(QPDFObjectHandle const& node, int kid_number); | 76 | void addPathElement(QPDFObjectHandle const& node, int kid_number); |
| 77 | QPDFObjectHandle getNextKid(PathElement& element, bool backward); | 77 | QPDFObjectHandle getNextKid(PathElement& element, bool backward); |
| 78 | void increment(bool backward); | 78 | void increment(bool backward); |
| 79 | - void | ||
| 80 | - resetLimits(QPDFObjectHandle node, std::list<PathElement>::iterator parent); | 79 | + void resetLimits(QPDFObjectHandle node, std::list<PathElement>::iterator parent); |
| 81 | 80 | ||
| 82 | - void | ||
| 83 | - split(QPDFObjectHandle to_split, std::list<PathElement>::iterator parent); | 81 | + void split(QPDFObjectHandle to_split, std::list<PathElement>::iterator parent); |
| 84 | std::list<PathElement>::iterator lastPathElement(); | 82 | std::list<PathElement>::iterator lastPathElement(); |
| 85 | 83 | ||
| 86 | NNTreeImpl& impl; | 84 | NNTreeImpl& impl; |
| @@ -97,11 +95,7 @@ class NNTreeImpl | @@ -97,11 +95,7 @@ class NNTreeImpl | ||
| 97 | public: | 95 | public: |
| 98 | typedef NNTreeIterator iterator; | 96 | typedef NNTreeIterator iterator; |
| 99 | 97 | ||
| 100 | - NNTreeImpl( | ||
| 101 | - NNTreeDetails const&, | ||
| 102 | - QPDF&, | ||
| 103 | - QPDFObjectHandle&, | ||
| 104 | - bool auto_repair = true); | 98 | + NNTreeImpl(NNTreeDetails const&, QPDF&, QPDFObjectHandle&, bool auto_repair = true); |
| 105 | iterator begin(); | 99 | iterator begin(); |
| 106 | iterator end(); | 100 | iterator end(); |
| 107 | iterator last(); | 101 | iterator last(); |
| @@ -117,16 +111,14 @@ class NNTreeImpl | @@ -117,16 +111,14 @@ class NNTreeImpl | ||
| 117 | 111 | ||
| 118 | private: | 112 | private: |
| 119 | void repair(); | 113 | void repair(); |
| 120 | - iterator | ||
| 121 | - findInternal(QPDFObjectHandle key, bool return_prev_if_not_found = false); | 114 | + iterator findInternal(QPDFObjectHandle key, bool return_prev_if_not_found = false); |
| 122 | int withinLimits(QPDFObjectHandle key, QPDFObjectHandle node); | 115 | int withinLimits(QPDFObjectHandle key, QPDFObjectHandle node); |
| 123 | int binarySearch( | 116 | int binarySearch( |
| 124 | QPDFObjectHandle key, | 117 | QPDFObjectHandle key, |
| 125 | QPDFObjectHandle items, | 118 | QPDFObjectHandle items, |
| 126 | int num_items, | 119 | int num_items, |
| 127 | bool return_prev_if_not_found, | 120 | bool return_prev_if_not_found, |
| 128 | - int (NNTreeImpl::*compare)( | ||
| 129 | - QPDFObjectHandle& key, QPDFObjectHandle& arr, int item)); | 121 | + int (NNTreeImpl::*compare)(QPDFObjectHandle& key, QPDFObjectHandle& arr, int item)); |
| 130 | int compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx); | 122 | int compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx); |
| 131 | int compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx); | 123 | int compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx); |
| 132 | 124 |
libqpdf/qpdf/OffsetInputSource.hh
| @@ -9,8 +9,7 @@ | @@ -9,8 +9,7 @@ | ||
| 9 | class OffsetInputSource: public InputSource | 9 | class OffsetInputSource: public InputSource |
| 10 | { | 10 | { |
| 11 | public: | 11 | public: |
| 12 | - OffsetInputSource( | ||
| 13 | - std::shared_ptr<InputSource>, qpdf_offset_t global_offset); | 12 | + OffsetInputSource(std::shared_ptr<InputSource>, qpdf_offset_t global_offset); |
| 14 | ~OffsetInputSource() override = default; | 13 | ~OffsetInputSource() override = default; |
| 15 | 14 | ||
| 16 | qpdf_offset_t findAndSkipNextEOL() override; | 15 | qpdf_offset_t findAndSkipNextEOL() override; |
libqpdf/qpdf/Pl_LZWDecoder.hh
| @@ -9,8 +9,7 @@ | @@ -9,8 +9,7 @@ | ||
| 9 | class Pl_LZWDecoder: public Pipeline | 9 | class Pl_LZWDecoder: public Pipeline |
| 10 | { | 10 | { |
| 11 | public: | 11 | public: |
| 12 | - Pl_LZWDecoder( | ||
| 13 | - char const* identifier, Pipeline* next, bool early_code_change); | 12 | + Pl_LZWDecoder(char const* identifier, Pipeline* next, bool early_code_change); |
| 14 | virtual ~Pl_LZWDecoder() = default; | 13 | virtual ~Pl_LZWDecoder() = default; |
| 15 | virtual void write(unsigned char const* buf, size_t len); | 14 | virtual void write(unsigned char const* buf, size_t len); |
| 16 | virtual void finish(); | 15 | virtual void finish(); |
libqpdf/qpdf/QPDFArgParser.hh
| @@ -53,23 +53,17 @@ class QPDFArgParser | @@ -53,23 +53,17 @@ class QPDFArgParser | ||
| 53 | void selectOptionTable(std::string const& name); | 53 | void selectOptionTable(std::string const& name); |
| 54 | 54 | ||
| 55 | // Register a new options table. This also selects the option table. | 55 | // Register a new options table. This also selects the option table. |
| 56 | - void registerOptionTable( | ||
| 57 | - std::string const& name, bare_arg_handler_t end_handler); | 56 | + void registerOptionTable(std::string const& name, bare_arg_handler_t end_handler); |
| 58 | 57 | ||
| 59 | // Add handlers for options in the current table | 58 | // Add handlers for options in the current table |
| 60 | 59 | ||
| 61 | void addPositional(param_arg_handler_t); | 60 | void addPositional(param_arg_handler_t); |
| 62 | void addBare(std::string const& arg, bare_arg_handler_t); | 61 | void addBare(std::string const& arg, bare_arg_handler_t); |
| 63 | - void addRequiredParameter( | ||
| 64 | - std::string const& arg, | ||
| 65 | - param_arg_handler_t, | ||
| 66 | - char const* parameter_name); | 62 | + void |
| 63 | + addRequiredParameter(std::string const& arg, param_arg_handler_t, char const* parameter_name); | ||
| 67 | void addOptionalParameter(std::string const& arg, param_arg_handler_t); | 64 | void addOptionalParameter(std::string const& arg, param_arg_handler_t); |
| 68 | - void addChoices( | ||
| 69 | - std::string const& arg, | ||
| 70 | - param_arg_handler_t, | ||
| 71 | - bool required, | ||
| 72 | - char const** choices); | 65 | + void |
| 66 | + addChoices(std::string const& arg, param_arg_handler_t, bool required, char const** choices); | ||
| 73 | 67 | ||
| 74 | // The default behavior when an invalid choice is specified with | 68 | // The default behavior when an invalid choice is specified with |
| 75 | // an option that takes choices is to list all the choices. This | 69 | // an option that takes choices is to list all the choices. This |
| @@ -123,9 +117,7 @@ class QPDFArgParser | @@ -123,9 +117,7 @@ class QPDFArgParser | ||
| 123 | 117 | ||
| 124 | // Add a help topic along with the text for that topic | 118 | // Add a help topic along with the text for that topic |
| 125 | void addHelpTopic( | 119 | void addHelpTopic( |
| 126 | - std::string const& topic, | ||
| 127 | - std::string const& short_text, | ||
| 128 | - std::string const& long_text); | 120 | + std::string const& topic, std::string const& short_text, std::string const& long_text); |
| 129 | 121 | ||
| 130 | // Add help for an option, and associate it with a topic. | 122 | // Add help for an option, and associate it with a topic. |
| 131 | void addOptionHelp( | 123 | void addOptionHelp( |
| @@ -220,16 +212,13 @@ class QPDFArgParser | @@ -220,16 +212,13 @@ class QPDFArgParser | ||
| 220 | void readArgsFromFile(std::string const& filename); | 212 | void readArgsFromFile(std::string const& filename); |
| 221 | void doFinalChecks(); | 213 | void doFinalChecks(); |
| 222 | void addOptionsToCompletions(option_table_t&); | 214 | void addOptionsToCompletions(option_table_t&); |
| 223 | - void addChoicesToCompletions( | ||
| 224 | - option_table_t&, std::string const&, std::string const&); | ||
| 225 | - void | ||
| 226 | - insertCompletions(option_table_t&, std::string const&, std::string const&); | 215 | + void addChoicesToCompletions(option_table_t&, std::string const&, std::string const&); |
| 216 | + void insertCompletions(option_table_t&, std::string const&, std::string const&); | ||
| 227 | void handleCompletion(); | 217 | void handleCompletion(); |
| 228 | 218 | ||
| 229 | void getTopHelp(std::ostringstream&); | 219 | void getTopHelp(std::ostringstream&); |
| 230 | void getAllHelp(std::ostringstream&); | 220 | void getAllHelp(std::ostringstream&); |
| 231 | - void getTopicHelp( | ||
| 232 | - std::string const& name, HelpTopic const&, std::ostringstream&); | 221 | + void getTopicHelp(std::string const& name, HelpTopic const&, std::ostringstream&); |
| 233 | 222 | ||
| 234 | class Members | 223 | class Members |
| 235 | { | 224 | { |
libqpdf/qpdf/QPDFCrypto_gnutls.hh
| @@ -25,8 +25,7 @@ class QPDFCrypto_gnutls: public QPDFCryptoImpl | @@ -25,8 +25,7 @@ class QPDFCrypto_gnutls: public QPDFCryptoImpl | ||
| 25 | virtual void MD5_digest(MD5_Digest); | 25 | virtual void MD5_digest(MD5_Digest); |
| 26 | 26 | ||
| 27 | virtual void RC4_init(unsigned char const* key_data, int key_len = -1); | 27 | virtual void RC4_init(unsigned char const* key_data, int key_len = -1); |
| 28 | - virtual void RC4_process( | ||
| 29 | - unsigned char const* in_data, size_t len, unsigned char* out_data = 0); | 28 | + virtual void RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0); |
| 30 | virtual void RC4_finalize(); | 29 | virtual void RC4_finalize(); |
| 31 | 30 | ||
| 32 | virtual void SHA2_init(int bits); | 31 | virtual void SHA2_init(int bits); |
| @@ -40,8 +39,7 @@ class QPDFCrypto_gnutls: public QPDFCryptoImpl | @@ -40,8 +39,7 @@ class QPDFCrypto_gnutls: public QPDFCryptoImpl | ||
| 40 | size_t key_len, | 39 | size_t key_len, |
| 41 | bool cbc_mode, | 40 | bool cbc_mode, |
| 42 | unsigned char* cbc_block); | 41 | unsigned char* cbc_block); |
| 43 | - virtual void | ||
| 44 | - rijndael_process(unsigned char* in_data, unsigned char* out_data); | 42 | + virtual void rijndael_process(unsigned char* in_data, unsigned char* out_data); |
| 45 | virtual void rijndael_finalize(); | 43 | virtual void rijndael_finalize(); |
| 46 | 44 | ||
| 47 | private: | 45 | private: |
libqpdf/qpdf/QPDFCrypto_native.hh
| @@ -23,8 +23,7 @@ class QPDFCrypto_native: public QPDFCryptoImpl | @@ -23,8 +23,7 @@ class QPDFCrypto_native: public QPDFCryptoImpl | ||
| 23 | virtual void MD5_digest(MD5_Digest); | 23 | virtual void MD5_digest(MD5_Digest); |
| 24 | 24 | ||
| 25 | virtual void RC4_init(unsigned char const* key_data, int key_len = -1); | 25 | virtual void RC4_init(unsigned char const* key_data, int key_len = -1); |
| 26 | - virtual void RC4_process( | ||
| 27 | - unsigned char const* in_data, size_t len, unsigned char* out_data = 0); | 26 | + virtual void RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0); |
| 28 | virtual void RC4_finalize(); | 27 | virtual void RC4_finalize(); |
| 29 | 28 | ||
| 30 | virtual void SHA2_init(int bits); | 29 | virtual void SHA2_init(int bits); |
| @@ -38,8 +37,7 @@ class QPDFCrypto_native: public QPDFCryptoImpl | @@ -38,8 +37,7 @@ class QPDFCrypto_native: public QPDFCryptoImpl | ||
| 38 | size_t key_len, | 37 | size_t key_len, |
| 39 | bool cbc_mode, | 38 | bool cbc_mode, |
| 40 | unsigned char* cbc_block); | 39 | unsigned char* cbc_block); |
| 41 | - virtual void | ||
| 42 | - rijndael_process(unsigned char* in_data, unsigned char* out_data); | 40 | + virtual void rijndael_process(unsigned char* in_data, unsigned char* out_data); |
| 43 | virtual void rijndael_finalize(); | 41 | virtual void rijndael_finalize(); |
| 44 | 42 | ||
| 45 | private: | 43 | private: |
libqpdf/qpdf/QPDFCrypto_openssl.hh
| @@ -37,9 +37,7 @@ class QPDFCrypto_openssl: public QPDFCryptoImpl | @@ -37,9 +37,7 @@ class QPDFCrypto_openssl: public QPDFCryptoImpl | ||
| 37 | 37 | ||
| 38 | void RC4_init(unsigned char const* key_data, int key_len = -1) override; | 38 | void RC4_init(unsigned char const* key_data, int key_len = -1) override; |
| 39 | void RC4_process( | 39 | void RC4_process( |
| 40 | - unsigned char const* in_data, | ||
| 41 | - size_t len, | ||
| 42 | - unsigned char* out_data = nullptr) override; | 40 | + unsigned char const* in_data, size_t len, unsigned char* out_data = nullptr) override; |
| 43 | void RC4_finalize() override; | 41 | void RC4_finalize() override; |
| 44 | 42 | ||
| 45 | void SHA2_init(int bits) override; | 43 | void SHA2_init(int bits) override; |
| @@ -53,8 +51,7 @@ class QPDFCrypto_openssl: public QPDFCryptoImpl | @@ -53,8 +51,7 @@ class QPDFCrypto_openssl: public QPDFCryptoImpl | ||
| 53 | size_t key_len, | 51 | size_t key_len, |
| 54 | bool cbc_mode, | 52 | bool cbc_mode, |
| 55 | unsigned char* cbc_block) override; | 53 | unsigned char* cbc_block) override; |
| 56 | - void | ||
| 57 | - rijndael_process(unsigned char* in_data, unsigned char* out_data) override; | 54 | + void rijndael_process(unsigned char* in_data, unsigned char* out_data) override; |
| 58 | void rijndael_finalize() override; | 55 | void rijndael_finalize() override; |
| 59 | 56 | ||
| 60 | private: | 57 | private: |
libqpdf/qpdf/QPDFObject_private.hh
| @@ -71,9 +71,7 @@ class QPDFObject | @@ -71,9 +71,7 @@ class QPDFObject | ||
| 71 | } | 71 | } |
| 72 | void | 72 | void |
| 73 | setDescription( | 73 | setDescription( |
| 74 | - QPDF* qpdf, | ||
| 75 | - std::shared_ptr<QPDFValue::Description>& description, | ||
| 76 | - qpdf_offset_t offset = -1) | 74 | + QPDF* qpdf, std::shared_ptr<QPDFValue::Description>& description, qpdf_offset_t offset = -1) |
| 77 | { | 75 | { |
| 78 | return value->setDescription(qpdf, description, offset); | 76 | return value->setDescription(qpdf, description, offset); |
| 79 | } | 77 | } |
| @@ -84,8 +82,7 @@ class QPDFObject | @@ -84,8 +82,7 @@ class QPDFObject | ||
| 84 | std::string var_descr) | 82 | std::string var_descr) |
| 85 | { | 83 | { |
| 86 | auto qpdf = parent ? parent->value->qpdf : nullptr; | 84 | auto qpdf = parent ? parent->value->qpdf : nullptr; |
| 87 | - value->setChildDescription( | ||
| 88 | - qpdf, parent->value, static_descr, var_descr); | 85 | + value->setChildDescription(qpdf, parent->value, static_descr, var_descr); |
| 89 | } | 86 | } |
| 90 | void | 87 | void |
| 91 | setChildDescription( | 88 | setChildDescription( |
libqpdf/qpdf/QPDFParser.hh
| @@ -22,8 +22,8 @@ class QPDFParser | @@ -22,8 +22,8 @@ class QPDFParser | ||
| 22 | tokenizer(tokenizer), | 22 | tokenizer(tokenizer), |
| 23 | decrypter(decrypter), | 23 | decrypter(decrypter), |
| 24 | context(context), | 24 | context(context), |
| 25 | - description(std::make_shared<QPDFValue::Description>(std::string( | ||
| 26 | - input->getName() + ", " + object_description + " at offset $PO"))) | 25 | + description(std::make_shared<QPDFValue::Description>( |
| 26 | + std::string(input->getName() + ", " + object_description + " at offset $PO"))) | ||
| 27 | { | 27 | { |
| 28 | } | 28 | } |
| 29 | virtual ~QPDFParser() = default; | 29 | virtual ~QPDFParser() = default; |
| @@ -31,20 +31,12 @@ class QPDFParser | @@ -31,20 +31,12 @@ class QPDFParser | ||
| 31 | QPDFObjectHandle parse(bool& empty, bool content_stream); | 31 | QPDFObjectHandle parse(bool& empty, bool content_stream); |
| 32 | 32 | ||
| 33 | private: | 33 | private: |
| 34 | - enum parser_state_e { | ||
| 35 | - st_top, | ||
| 36 | - st_start, | ||
| 37 | - st_stop, | ||
| 38 | - st_eof, | ||
| 39 | - st_dictionary, | ||
| 40 | - st_array | ||
| 41 | - }; | 34 | + enum parser_state_e { st_top, st_start, st_stop, st_eof, st_dictionary, st_array }; |
| 42 | 35 | ||
| 43 | void warn(qpdf_offset_t offset, std::string const& msg) const; | 36 | void warn(qpdf_offset_t offset, std::string const& msg) const; |
| 44 | void warn(std::string const& msg) const; | 37 | void warn(std::string const& msg) const; |
| 45 | void warn(QPDFExc const&) const; | 38 | void warn(QPDFExc const&) const; |
| 46 | - void setDescription( | ||
| 47 | - std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset); | 39 | + void setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset); |
| 48 | std::shared_ptr<InputSource> input; | 40 | std::shared_ptr<InputSource> input; |
| 49 | std::string const& object_description; | 41 | std::string const& object_description; |
| 50 | QPDFTokenizer& tokenizer; | 42 | QPDFTokenizer& tokenizer; |
libqpdf/qpdf/QPDFValue.hh
| @@ -28,8 +28,7 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> | @@ -28,8 +28,7 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> | ||
| 28 | 28 | ||
| 29 | struct JSON_Descr | 29 | struct JSON_Descr |
| 30 | { | 30 | { |
| 31 | - JSON_Descr( | ||
| 32 | - std::shared_ptr<std::string> input, std::string const& object) : | 31 | + JSON_Descr(std::shared_ptr<std::string> input, std::string const& object) : |
| 33 | input(input), | 32 | input(input), |
| 34 | object(object) | 33 | object(object) |
| 35 | { | 34 | { |
| @@ -59,10 +58,7 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> | @@ -59,10 +58,7 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> | ||
| 59 | using Description = std::variant<std::string, JSON_Descr, ChildDescr>; | 58 | using Description = std::variant<std::string, JSON_Descr, ChildDescr>; |
| 60 | 59 | ||
| 61 | virtual void | 60 | virtual void |
| 62 | - setDescription( | ||
| 63 | - QPDF* qpdf_p, | ||
| 64 | - std::shared_ptr<Description>& description, | ||
| 65 | - qpdf_offset_t offset) | 61 | + setDescription(QPDF* qpdf_p, std::shared_ptr<Description>& description, qpdf_offset_t offset) |
| 66 | { | 62 | { |
| 67 | qpdf = qpdf_p; | 63 | qpdf = qpdf_p; |
| 68 | object_description = description; | 64 | object_description = description; |
| @@ -81,8 +77,8 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> | @@ -81,8 +77,8 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> | ||
| 81 | std::string_view const& static_descr, | 77 | std::string_view const& static_descr, |
| 82 | std::string var_descr) | 78 | std::string var_descr) |
| 83 | { | 79 | { |
| 84 | - object_description = std::make_shared<Description>( | ||
| 85 | - ChildDescr(parent, static_descr, var_descr)); | 80 | + object_description = |
| 81 | + std::make_shared<Description>(ChildDescr(parent, static_descr, var_descr)); | ||
| 86 | qpdf = a_qpdf; | 82 | qpdf = a_qpdf; |
| 87 | } | 83 | } |
| 88 | std::string getDescription(); | 84 | std::string getDescription(); |
| @@ -132,10 +128,7 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> | @@ -132,10 +128,7 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> | ||
| 132 | { | 128 | { |
| 133 | } | 129 | } |
| 134 | QPDFValue( | 130 | QPDFValue( |
| 135 | - qpdf_object_type_e type_code, | ||
| 136 | - char const* type_name, | ||
| 137 | - QPDF* qpdf, | ||
| 138 | - QPDFObjGen const& og) : | 131 | + qpdf_object_type_e type_code, char const* type_name, QPDF* qpdf, QPDFObjGen const& og) : |
| 139 | type_code(type_code), | 132 | type_code(type_code), |
| 140 | type_name(type_name), | 133 | type_name(type_name), |
| 141 | qpdf(qpdf), | 134 | qpdf(qpdf), |
libqpdf/qpdf/QPDF_Array.hh
| @@ -10,8 +10,7 @@ class QPDF_Array: public QPDFValue | @@ -10,8 +10,7 @@ class QPDF_Array: public QPDFValue | ||
| 10 | { | 10 | { |
| 11 | public: | 11 | public: |
| 12 | virtual ~QPDF_Array() = default; | 12 | virtual ~QPDF_Array() = default; |
| 13 | - static std::shared_ptr<QPDFObject> | ||
| 14 | - create(std::vector<QPDFObjectHandle> const& items); | 13 | + static std::shared_ptr<QPDFObject> create(std::vector<QPDFObjectHandle> const& items); |
| 15 | static std::shared_ptr<QPDFObject> | 14 | static std::shared_ptr<QPDFObject> |
| 16 | create(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse); | 15 | create(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse); |
| 17 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); | 16 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
libqpdf/qpdf/QPDF_Dictionary.hh
| @@ -12,10 +12,8 @@ class QPDF_Dictionary: public QPDFValue | @@ -12,10 +12,8 @@ class QPDF_Dictionary: public QPDFValue | ||
| 12 | { | 12 | { |
| 13 | public: | 13 | public: |
| 14 | virtual ~QPDF_Dictionary() = default; | 14 | virtual ~QPDF_Dictionary() = default; |
| 15 | - static std::shared_ptr<QPDFObject> | ||
| 16 | - create(std::map<std::string, QPDFObjectHandle> const& items); | ||
| 17 | - static std::shared_ptr<QPDFObject> | ||
| 18 | - create(std::map<std::string, QPDFObjectHandle>&& items); | 15 | + static std::shared_ptr<QPDFObject> create(std::map<std::string, QPDFObjectHandle> const& items); |
| 16 | + static std::shared_ptr<QPDFObject> create(std::map<std::string, QPDFObjectHandle>&& items); | ||
| 19 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); | 17 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
| 20 | virtual std::string unparse(); | 18 | virtual std::string unparse(); |
| 21 | virtual JSON getJSON(int json_version); | 19 | virtual JSON getJSON(int json_version); |
libqpdf/qpdf/QPDF_Stream.hh
| @@ -27,9 +27,7 @@ class QPDF_Stream: public QPDFValue | @@ -27,9 +27,7 @@ class QPDF_Stream: public QPDFValue | ||
| 27 | virtual std::string unparse(); | 27 | virtual std::string unparse(); |
| 28 | virtual JSON getJSON(int json_version); | 28 | virtual JSON getJSON(int json_version); |
| 29 | virtual void setDescription( | 29 | virtual void setDescription( |
| 30 | - QPDF*, | ||
| 31 | - std::shared_ptr<QPDFValue::Description>& description, | ||
| 32 | - qpdf_offset_t offset); | 30 | + QPDF*, std::shared_ptr<QPDFValue::Description>& description, qpdf_offset_t offset); |
| 33 | virtual void disconnect(); | 31 | virtual void disconnect(); |
| 34 | QPDFObjectHandle getDict() const; | 32 | QPDFObjectHandle getDict() const; |
| 35 | bool isDataModified() const; | 33 | bool isDataModified() const; |
| @@ -39,8 +37,7 @@ class QPDF_Stream: public QPDFValue | @@ -39,8 +37,7 @@ class QPDF_Stream: public QPDFValue | ||
| 39 | // Methods to help QPDF copy foreign streams | 37 | // Methods to help QPDF copy foreign streams |
| 40 | size_t getLength() const; | 38 | size_t getLength() const; |
| 41 | std::shared_ptr<Buffer> getStreamDataBuffer() const; | 39 | std::shared_ptr<Buffer> getStreamDataBuffer() const; |
| 42 | - std::shared_ptr<QPDFObjectHandle::StreamDataProvider> | ||
| 43 | - getStreamDataProvider() const; | 40 | + std::shared_ptr<QPDFObjectHandle::StreamDataProvider> getStreamDataProvider() const; |
| 44 | 41 | ||
| 45 | // See comments in QPDFObjectHandle.hh for these methods. | 42 | // See comments in QPDFObjectHandle.hh for these methods. |
| 46 | bool pipeStreamData( | 43 | bool pipeStreamData( |
| @@ -60,8 +57,7 @@ class QPDF_Stream: public QPDFValue | @@ -60,8 +57,7 @@ class QPDF_Stream: public QPDFValue | ||
| 60 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider, | 57 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider, |
| 61 | QPDFObjectHandle const& filter, | 58 | QPDFObjectHandle const& filter, |
| 62 | QPDFObjectHandle const& decode_parms); | 59 | QPDFObjectHandle const& decode_parms); |
| 63 | - void | ||
| 64 | - addTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter); | 60 | + void addTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter); |
| 65 | JSON getStreamJSON( | 61 | JSON getStreamJSON( |
| 66 | int json_version, | 62 | int json_version, |
| 67 | qpdf_json_stream_data_e json_data, | 63 | qpdf_json_stream_data_e json_data, |
| @@ -72,8 +68,7 @@ class QPDF_Stream: public QPDFValue | @@ -72,8 +68,7 @@ class QPDF_Stream: public QPDFValue | ||
| 72 | void replaceDict(QPDFObjectHandle const& new_dict); | 68 | void replaceDict(QPDFObjectHandle const& new_dict); |
| 73 | 69 | ||
| 74 | static void registerStreamFilter( | 70 | static void registerStreamFilter( |
| 75 | - std::string const& filter_name, | ||
| 76 | - std::function<std::shared_ptr<QPDFStreamFilter>()> factory); | 71 | + std::string const& filter_name, std::function<std::shared_ptr<QPDFStreamFilter>()> factory); |
| 77 | 72 | ||
| 78 | private: | 73 | private: |
| 79 | QPDF_Stream( | 74 | QPDF_Stream( |
| @@ -83,14 +78,11 @@ class QPDF_Stream: public QPDFValue | @@ -83,14 +78,11 @@ class QPDF_Stream: public QPDFValue | ||
| 83 | qpdf_offset_t offset, | 78 | qpdf_offset_t offset, |
| 84 | size_t length); | 79 | size_t length); |
| 85 | static std::map<std::string, std::string> filter_abbreviations; | 80 | static std::map<std::string, std::string> filter_abbreviations; |
| 86 | - static std:: | ||
| 87 | - map<std::string, std::function<std::shared_ptr<QPDFStreamFilter>()>> | ||
| 88 | - filter_factories; | 81 | + static std::map<std::string, std::function<std::shared_ptr<QPDFStreamFilter>()>> |
| 82 | + filter_factories; | ||
| 89 | 83 | ||
| 90 | void replaceFilterData( | 84 | void replaceFilterData( |
| 91 | - QPDFObjectHandle const& filter, | ||
| 92 | - QPDFObjectHandle const& decode_parms, | ||
| 93 | - size_t length); | 85 | + QPDFObjectHandle const& filter, QPDFObjectHandle const& decode_parms, size_t length); |
| 94 | bool filterable( | 86 | bool filterable( |
| 95 | std::vector<std::shared_ptr<QPDFStreamFilter>>& filters, | 87 | std::vector<std::shared_ptr<QPDFStreamFilter>>& filters, |
| 96 | bool& specialized_compression, | 88 | bool& specialized_compression, |
libqpdf/qpdf/QPDF_String.hh
| @@ -12,8 +12,7 @@ class QPDF_String: public QPDFValue | @@ -12,8 +12,7 @@ class QPDF_String: public QPDFValue | ||
| 12 | public: | 12 | public: |
| 13 | virtual ~QPDF_String() = default; | 13 | virtual ~QPDF_String() = default; |
| 14 | static std::shared_ptr<QPDFObject> create(std::string const& val); | 14 | static std::shared_ptr<QPDFObject> create(std::string const& val); |
| 15 | - static std::shared_ptr<QPDFObject> | ||
| 16 | - create_utf16(std::string const& utf8_val); | 15 | + static std::shared_ptr<QPDFObject> create_utf16(std::string const& utf8_val); |
| 17 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); | 16 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
| 18 | virtual std::string unparse(); | 17 | virtual std::string unparse(); |
| 19 | std::string unparse(bool force_binary); | 18 | std::string unparse(bool force_binary); |
libqpdf/qpdf/RC4.hh
| @@ -13,8 +13,7 @@ class RC4 | @@ -13,8 +13,7 @@ class RC4 | ||
| 13 | 13 | ||
| 14 | // It is safe to pass the same pointer to in_data and out_data to | 14 | // It is safe to pass the same pointer to in_data and out_data to |
| 15 | // encrypt/decrypt in place | 15 | // encrypt/decrypt in place |
| 16 | - void | ||
| 17 | - process(unsigned char const* in_data, size_t len, unsigned char* out_data); | 16 | + void process(unsigned char const* in_data, size_t len, unsigned char* out_data); |
| 18 | 17 | ||
| 19 | private: | 18 | private: |
| 20 | std::shared_ptr<QPDFCryptoImpl> crypto; | 19 | std::shared_ptr<QPDFCryptoImpl> crypto; |
libqpdf/qpdf/RC4_native.hh
| @@ -10,8 +10,7 @@ class RC4_native | @@ -10,8 +10,7 @@ class RC4_native | ||
| 10 | RC4_native(unsigned char const* key_data, int key_len = -1); | 10 | RC4_native(unsigned char const* key_data, int key_len = -1); |
| 11 | 11 | ||
| 12 | // out_data = 0 means to encrypt/decrypt in place | 12 | // out_data = 0 means to encrypt/decrypt in place |
| 13 | - void process( | ||
| 14 | - unsigned char const* in_data, size_t len, unsigned char* out_data = 0); | 13 | + void process(unsigned char const* in_data, size_t len, unsigned char* out_data = 0); |
| 15 | 14 | ||
| 16 | private: | 15 | private: |
| 17 | class RC4Key | 16 | class RC4Key |
libqpdf/qpdf/ResourceFinder.hh
| @@ -18,8 +18,7 @@ class ResourceFinder: public QPDFObjectHandle::ParserCallbacks | @@ -18,8 +18,7 @@ class ResourceFinder: public QPDFObjectHandle::ParserCallbacks | ||
| 18 | std::string last_name; | 18 | std::string last_name; |
| 19 | size_t last_name_offset; | 19 | size_t last_name_offset; |
| 20 | std::set<std::string> names; | 20 | std::set<std::string> names; |
| 21 | - std::map<std::string, std::map<std::string, std::set<size_t>>> | ||
| 22 | - names_by_resource_type; | 21 | + std::map<std::string, std::map<std::string, std::set<size_t>>> names_by_resource_type; |
| 23 | }; | 22 | }; |
| 24 | 23 | ||
| 25 | #endif // RESOURCEFINDER_HH | 24 | #endif // RESOURCEFINDER_HH |
libqpdf/qpdf/SF_ASCII85Decode.hh
| @@ -14,8 +14,7 @@ class SF_ASCII85Decode: public QPDFStreamFilter | @@ -14,8 +14,7 @@ class SF_ASCII85Decode: public QPDFStreamFilter | ||
| 14 | Pipeline* | 14 | Pipeline* |
| 15 | getDecodePipeline(Pipeline* next) override | 15 | getDecodePipeline(Pipeline* next) override |
| 16 | { | 16 | { |
| 17 | - this->pipeline = | ||
| 18 | - std::make_shared<Pl_ASCII85Decoder>("ascii85 decode", next); | 17 | + this->pipeline = std::make_shared<Pl_ASCII85Decoder>("ascii85 decode", next); |
| 19 | return this->pipeline.get(); | 18 | return this->pipeline.get(); |
| 20 | } | 19 | } |
| 21 | 20 |
libqpdf/qpdf/SF_ASCIIHexDecode.hh
| @@ -14,8 +14,7 @@ class SF_ASCIIHexDecode: public QPDFStreamFilter | @@ -14,8 +14,7 @@ class SF_ASCIIHexDecode: public QPDFStreamFilter | ||
| 14 | Pipeline* | 14 | Pipeline* |
| 15 | getDecodePipeline(Pipeline* next) override | 15 | getDecodePipeline(Pipeline* next) override |
| 16 | { | 16 | { |
| 17 | - this->pipeline = | ||
| 18 | - std::make_shared<Pl_ASCIIHexDecoder>("asciiHex decode", next); | 17 | + this->pipeline = std::make_shared<Pl_ASCIIHexDecoder>("asciiHex decode", next); |
| 19 | return this->pipeline.get(); | 18 | return this->pipeline.get(); |
| 20 | } | 19 | } |
| 21 | 20 |
libqpdf/qpdf/SF_RunLengthDecode.hh
| @@ -14,8 +14,8 @@ class SF_RunLengthDecode: public QPDFStreamFilter | @@ -14,8 +14,8 @@ class SF_RunLengthDecode: public QPDFStreamFilter | ||
| 14 | Pipeline* | 14 | Pipeline* |
| 15 | getDecodePipeline(Pipeline* next) override | 15 | getDecodePipeline(Pipeline* next) override |
| 16 | { | 16 | { |
| 17 | - this->pipeline = std::make_shared<Pl_RunLength>( | ||
| 18 | - "runlength decode", next, Pl_RunLength::a_decode); | 17 | + this->pipeline = |
| 18 | + std::make_shared<Pl_RunLength>("runlength decode", next, Pl_RunLength::a_decode); | ||
| 19 | return this->pipeline.get(); | 19 | return this->pipeline.get(); |
| 20 | } | 20 | } |
| 21 | 21 |
libqpdf/qpdf/bits_functions.hh
| @@ -17,11 +17,7 @@ | @@ -17,11 +17,7 @@ | ||
| 17 | 17 | ||
| 18 | #ifdef BITS_READ | 18 | #ifdef BITS_READ |
| 19 | static unsigned long long | 19 | static unsigned long long |
| 20 | -read_bits( | ||
| 21 | - unsigned char const*& p, | ||
| 22 | - size_t& bit_offset, | ||
| 23 | - size_t& bits_available, | ||
| 24 | - size_t bits_wanted) | 20 | +read_bits(unsigned char const*& p, size_t& bit_offset, size_t& bits_available, size_t bits_wanted) |
| 25 | { | 21 | { |
| 26 | // View p as a stream of bits: | 22 | // View p as a stream of bits: |
| 27 | 23 | ||
| @@ -32,8 +28,7 @@ read_bits( | @@ -32,8 +28,7 @@ read_bits( | ||
| 32 | 28 | ||
| 33 | if (bits_wanted > bits_available) { | 29 | if (bits_wanted > bits_available) { |
| 34 | throw std::runtime_error( | 30 | throw std::runtime_error( |
| 35 | - "overflow reading bit stream: wanted = " + | ||
| 36 | - std::to_string(bits_wanted) + | 31 | + "overflow reading bit stream: wanted = " + std::to_string(bits_wanted) + |
| 37 | "; available = " + std::to_string(bits_available)); | 32 | "; available = " + std::to_string(bits_available)); |
| 38 | } | 33 | } |
| 39 | if (bits_wanted > 32) { | 34 | if (bits_wanted > 32) { |
| @@ -49,20 +44,14 @@ read_bits( | @@ -49,20 +44,14 @@ read_bits( | ||
| 49 | while (bits_wanted > 0) { | 44 | while (bits_wanted > 0) { |
| 50 | // Grab bits from the first byte clearing anything before | 45 | // Grab bits from the first byte clearing anything before |
| 51 | // bit_offset. | 46 | // bit_offset. |
| 52 | - unsigned char byte = | ||
| 53 | - static_cast<unsigned char>(*p & ((1U << (bit_offset + 1U)) - 1U)); | 47 | + unsigned char byte = static_cast<unsigned char>(*p & ((1U << (bit_offset + 1U)) - 1U)); |
| 54 | 48 | ||
| 55 | // There are bit_offset + 1 bits available in the first byte. | 49 | // There are bit_offset + 1 bits available in the first byte. |
| 56 | size_t to_copy = std::min(bits_wanted, bit_offset + 1); | 50 | size_t to_copy = std::min(bits_wanted, bit_offset + 1); |
| 57 | size_t leftover = (bit_offset + 1) - to_copy; | 51 | size_t leftover = (bit_offset + 1) - to_copy; |
| 58 | 52 | ||
| 59 | # ifdef BITS_TESTING | 53 | # ifdef BITS_TESTING |
| 60 | - QTC::TC( | ||
| 61 | - "libtests", | ||
| 62 | - "bits bit_offset", | ||
| 63 | - ((bit_offset == 0) ? 0 | ||
| 64 | - : (bit_offset == 7) ? 1 | ||
| 65 | - : 2)); | 54 | + QTC::TC("libtests", "bits bit_offset", ((bit_offset == 0) ? 0 : (bit_offset == 7) ? 1 : 2)); |
| 66 | QTC::TC("libtests", "bits leftover", (leftover > 0) ? 1 : 0); | 55 | QTC::TC("libtests", "bits leftover", (leftover > 0) ? 1 : 0); |
| 67 | # endif | 56 | # endif |
| 68 | 57 | ||
| @@ -84,12 +73,7 @@ read_bits( | @@ -84,12 +73,7 @@ read_bits( | ||
| 84 | bits_available -= to_copy; | 73 | bits_available -= to_copy; |
| 85 | 74 | ||
| 86 | # ifdef BITS_TESTING | 75 | # ifdef BITS_TESTING |
| 87 | - QTC::TC( | ||
| 88 | - "libtests", | ||
| 89 | - "bits iterations", | ||
| 90 | - ((bits_wanted > 8) ? 0 | ||
| 91 | - : (bits_wanted > 0) ? 1 | ||
| 92 | - : 2)); | 76 | + QTC::TC("libtests", "bits iterations", ((bits_wanted > 8) ? 0 : (bits_wanted > 0) ? 1 : 2)); |
| 93 | # endif | 77 | # endif |
| 94 | } | 78 | } |
| 95 | 79 | ||
| @@ -100,11 +84,7 @@ read_bits( | @@ -100,11 +84,7 @@ read_bits( | ||
| 100 | #ifdef BITS_WRITE | 84 | #ifdef BITS_WRITE |
| 101 | static void | 85 | static void |
| 102 | write_bits( | 86 | write_bits( |
| 103 | - unsigned char& ch, | ||
| 104 | - size_t& bit_offset, | ||
| 105 | - unsigned long long val, | ||
| 106 | - size_t bits, | ||
| 107 | - Pipeline* pipeline) | 87 | + unsigned char& ch, size_t& bit_offset, unsigned long long val, size_t bits, Pipeline* pipeline) |
| 108 | { | 88 | { |
| 109 | if (bits > 32) { | 89 | if (bits > 32) { |
| 110 | throw std::out_of_range("write_bits: too many bits requested"); | 90 | throw std::out_of_range("write_bits: too many bits requested"); |
| @@ -138,12 +118,7 @@ write_bits( | @@ -138,12 +118,7 @@ write_bits( | ||
| 138 | } | 118 | } |
| 139 | bits -= bits_to_write; | 119 | bits -= bits_to_write; |
| 140 | # ifdef BITS_TESTING | 120 | # ifdef BITS_TESTING |
| 141 | - QTC::TC( | ||
| 142 | - "libtests", | ||
| 143 | - "bits write iterations", | ||
| 144 | - ((bits > 8) ? 0 | ||
| 145 | - : (bits > 0) ? 1 | ||
| 146 | - : 2)); | 121 | + QTC::TC("libtests", "bits write iterations", ((bits > 8) ? 0 : (bits > 0) ? 1 : 2)); |
| 147 | # endif | 122 | # endif |
| 148 | } | 123 | } |
| 149 | } | 124 | } |
libqpdf/qpdf/rijndael.h
| @@ -10,10 +10,8 @@ | @@ -10,10 +10,8 @@ | ||
| 10 | #endif | 10 | #endif |
| 11 | #include <stddef.h> | 11 | #include <stddef.h> |
| 12 | 12 | ||
| 13 | -unsigned int | ||
| 14 | -rijndaelSetupEncrypt(uint32_t* rk, const unsigned char* key, size_t keybits); | ||
| 15 | -unsigned int | ||
| 16 | -rijndaelSetupDecrypt(uint32_t* rk, const unsigned char* key, size_t keybits); | 13 | +unsigned int rijndaelSetupEncrypt(uint32_t* rk, const unsigned char* key, size_t keybits); |
| 14 | +unsigned int rijndaelSetupDecrypt(uint32_t* rk, const unsigned char* key, size_t keybits); | ||
| 17 | void rijndaelEncrypt( | 15 | void rijndaelEncrypt( |
| 18 | const uint32_t* rk, | 16 | const uint32_t* rk, |
| 19 | unsigned int nrounds, | 17 | unsigned int nrounds, |
libqpdf/qpdfjob-c.cc
| @@ -35,8 +35,7 @@ wrap_qpdfjob(qpdfjob_handle j, std::function<int(qpdfjob_handle j)> fn) | @@ -35,8 +35,7 @@ wrap_qpdfjob(qpdfjob_handle j, std::function<int(qpdfjob_handle j)> fn) | ||
| 35 | try { | 35 | try { |
| 36 | return fn(j); | 36 | return fn(j); |
| 37 | } catch (std::exception& e) { | 37 | } catch (std::exception& e) { |
| 38 | - *j->j.getLogger()->getError() | ||
| 39 | - << j->j.getMessagePrefix() << ": " << e.what() << "\n"; | 38 | + *j->j.getLogger()->getError() << j->j.getMessagePrefix() << ": " << e.what() << "\n"; |
| 40 | } | 39 | } |
| 41 | return QPDFJob::EXIT_ERROR; | 40 | return QPDFJob::EXIT_ERROR; |
| 42 | } | 41 | } |
| @@ -70,10 +69,9 @@ qpdfjob_initialize_from_wide_argv(qpdfjob_handle j, wchar_t const* const argv[]) | @@ -70,10 +69,9 @@ qpdfjob_initialize_from_wide_argv(qpdfjob_handle j, wchar_t const* const argv[]) | ||
| 70 | for (auto k = argv; *k; ++k) { | 69 | for (auto k = argv; *k; ++k) { |
| 71 | ++argc; | 70 | ++argc; |
| 72 | } | 71 | } |
| 73 | - return QUtil::call_main_from_wmain( | ||
| 74 | - argc, argv, [j](int, char const* const new_argv[]) { | ||
| 75 | - return qpdfjob_initialize_from_argv(j, new_argv); | ||
| 76 | - }); | 72 | + return QUtil::call_main_from_wmain(argc, argv, [j](int, char const* const new_argv[]) { |
| 73 | + return qpdfjob_initialize_from_argv(j, new_argv); | ||
| 74 | + }); | ||
| 77 | } | 75 | } |
| 78 | #endif // QPDF_NO_WCHAR_T | 76 | #endif // QPDF_NO_WCHAR_T |
| 79 | 77 | ||
| @@ -105,8 +103,7 @@ qpdfjob_create_qpdf(qpdfjob_handle j) | @@ -105,8 +103,7 @@ qpdfjob_create_qpdf(qpdfjob_handle j) | ||
| 105 | auto qpdf = j->j.createQPDF(); | 103 | auto qpdf = j->j.createQPDF(); |
| 106 | return qpdf ? new _qpdf_data(std::move(qpdf)) : nullptr; | 104 | return qpdf ? new _qpdf_data(std::move(qpdf)) : nullptr; |
| 107 | } catch (std::exception& e) { | 105 | } catch (std::exception& e) { |
| 108 | - *j->j.getLogger()->getError() | ||
| 109 | - << j->j.getMessagePrefix() << ": " << e.what() << "\n"; | 106 | + *j->j.getLogger()->getError() << j->j.getMessagePrefix() << ": " << e.what() << "\n"; |
| 110 | } | 107 | } |
| 111 | return nullptr; | 108 | return nullptr; |
| 112 | } | 109 | } |
| @@ -136,35 +133,29 @@ run_with_handle(std::function<int(qpdfjob_handle)> fn) | @@ -136,35 +133,29 @@ run_with_handle(std::function<int(qpdfjob_handle)> fn) | ||
| 136 | int | 133 | int |
| 137 | qpdfjob_run_from_argv(char const* const argv[]) | 134 | qpdfjob_run_from_argv(char const* const argv[]) |
| 138 | { | 135 | { |
| 139 | - return run_with_handle([argv](qpdfjob_handle j) { | ||
| 140 | - return qpdfjob_initialize_from_argv(j, argv); | ||
| 141 | - }); | 136 | + return run_with_handle( |
| 137 | + [argv](qpdfjob_handle j) { return qpdfjob_initialize_from_argv(j, argv); }); | ||
| 142 | } | 138 | } |
| 143 | 139 | ||
| 144 | #ifndef QPDF_NO_WCHAR_T | 140 | #ifndef QPDF_NO_WCHAR_T |
| 145 | int | 141 | int |
| 146 | qpdfjob_run_from_wide_argv(wchar_t const* const argv[]) | 142 | qpdfjob_run_from_wide_argv(wchar_t const* const argv[]) |
| 147 | { | 143 | { |
| 148 | - return run_with_handle([argv](qpdfjob_handle j) { | ||
| 149 | - return qpdfjob_initialize_from_wide_argv(j, argv); | ||
| 150 | - }); | 144 | + return run_with_handle( |
| 145 | + [argv](qpdfjob_handle j) { return qpdfjob_initialize_from_wide_argv(j, argv); }); | ||
| 151 | } | 146 | } |
| 152 | #endif /* QPDF_NO_WCHAR_T */ | 147 | #endif /* QPDF_NO_WCHAR_T */ |
| 153 | 148 | ||
| 154 | int | 149 | int |
| 155 | qpdfjob_run_from_json(char const* json) | 150 | qpdfjob_run_from_json(char const* json) |
| 156 | { | 151 | { |
| 157 | - return run_with_handle([json](qpdfjob_handle j) { | ||
| 158 | - return qpdfjob_initialize_from_json(j, json); | ||
| 159 | - }); | 152 | + return run_with_handle( |
| 153 | + [json](qpdfjob_handle j) { return qpdfjob_initialize_from_json(j, json); }); | ||
| 160 | } | 154 | } |
| 161 | 155 | ||
| 162 | void | 156 | void |
| 163 | qpdfjob_register_progress_reporter( | 157 | qpdfjob_register_progress_reporter( |
| 164 | - qpdfjob_handle j, | ||
| 165 | - void (*report_progress)(int percent, void* data), | ||
| 166 | - void* data) | 158 | + qpdfjob_handle j, void (*report_progress)(int percent, void* data), void* data) |
| 167 | { | 159 | { |
| 168 | - j->j.registerProgressReporter( | ||
| 169 | - std::bind(report_progress, std::placeholders::_1, data)); | 160 | + j->j.registerProgressReporter(std::bind(report_progress, std::placeholders::_1, data)); |
| 170 | } | 161 | } |
libqpdf/qpdflogger-c.cc
| @@ -70,59 +70,40 @@ set_log_dest( | @@ -70,59 +70,40 @@ set_log_dest( | ||
| 70 | void* udata) | 70 | void* udata) |
| 71 | { | 71 | { |
| 72 | set_log_dest( | 72 | set_log_dest( |
| 73 | - l, | ||
| 74 | - std::bind(std::mem_fn(method), l, std::placeholders::_1), | ||
| 75 | - dest, | ||
| 76 | - identifier, | ||
| 77 | - fn, | ||
| 78 | - udata); | 73 | + l, std::bind(std::mem_fn(method), l, std::placeholders::_1), dest, identifier, fn, udata); |
| 79 | } | 74 | } |
| 80 | 75 | ||
| 81 | void | 76 | void |
| 82 | -qpdflogger_set_info( | ||
| 83 | - qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata) | 77 | +qpdflogger_set_info(qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata) |
| 84 | { | 78 | { |
| 85 | - set_log_dest( | ||
| 86 | - l->l.get(), &QPDFLogger::setInfo, dest, "info logger", fn, udata); | 79 | + set_log_dest(l->l.get(), &QPDFLogger::setInfo, dest, "info logger", fn, udata); |
| 87 | } | 80 | } |
| 88 | 81 | ||
| 89 | void | 82 | void |
| 90 | -qpdflogger_set_warn( | ||
| 91 | - qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata) | 83 | +qpdflogger_set_warn(qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata) |
| 92 | { | 84 | { |
| 93 | - set_log_dest( | ||
| 94 | - l->l.get(), &QPDFLogger::setWarn, dest, "warn logger", fn, udata); | 85 | + set_log_dest(l->l.get(), &QPDFLogger::setWarn, dest, "warn logger", fn, udata); |
| 95 | } | 86 | } |
| 96 | 87 | ||
| 97 | void | 88 | void |
| 98 | -qpdflogger_set_error( | ||
| 99 | - qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata) | 89 | +qpdflogger_set_error(qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata) |
| 100 | { | 90 | { |
| 101 | - set_log_dest( | ||
| 102 | - l->l.get(), &QPDFLogger::setError, dest, "error logger", fn, udata); | 91 | + set_log_dest(l->l.get(), &QPDFLogger::setError, dest, "error logger", fn, udata); |
| 103 | } | 92 | } |
| 104 | 93 | ||
| 105 | void | 94 | void |
| 106 | qpdflogger_set_save( | 95 | qpdflogger_set_save( |
| 107 | - qpdflogger_handle l, | ||
| 108 | - qpdf_log_dest_e dest, | ||
| 109 | - qpdf_log_fn_t fn, | ||
| 110 | - void* udata, | ||
| 111 | - int only_if_not_set) | 96 | + qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata, int only_if_not_set) |
| 112 | { | 97 | { |
| 113 | auto method = std::bind( | 98 | auto method = std::bind( |
| 114 | - std::mem_fn(&QPDFLogger::setSave), | ||
| 115 | - l->l.get(), | ||
| 116 | - std::placeholders::_1, | ||
| 117 | - only_if_not_set); | 99 | + std::mem_fn(&QPDFLogger::setSave), l->l.get(), std::placeholders::_1, only_if_not_set); |
| 118 | set_log_dest(l->l.get(), method, dest, "save logger", fn, udata); | 100 | set_log_dest(l->l.get(), method, dest, "save logger", fn, udata); |
| 119 | } | 101 | } |
| 120 | 102 | ||
| 121 | void | 103 | void |
| 122 | qpdflogger_save_to_standard_output(qpdflogger_handle l, int only_if_not_set) | 104 | qpdflogger_save_to_standard_output(qpdflogger_handle l, int only_if_not_set) |
| 123 | { | 105 | { |
| 124 | - qpdflogger_set_save( | ||
| 125 | - l, qpdf_log_dest_stdout, nullptr, nullptr, only_if_not_set); | 106 | + qpdflogger_set_save(l, qpdf_log_dest_stdout, nullptr, nullptr, only_if_not_set); |
| 126 | } | 107 | } |
| 127 | 108 | ||
| 128 | int | 109 | int |
libtests/aes.cc
| @@ -17,8 +17,7 @@ usage() | @@ -17,8 +17,7 @@ usage() | ||
| 17 | << " -encrypt -- encrypt" << std::endl | 17 | << " -encrypt -- encrypt" << std::endl |
| 18 | << " -decrypt -- decrypt CBC mode" << std::endl | 18 | << " -decrypt -- decrypt CBC mode" << std::endl |
| 19 | << " -zero-iv -- use zero initialization vector" << std::endl | 19 | << " -zero-iv -- use zero initialization vector" << std::endl |
| 20 | - << " -static-iv -- use static initialization vector" | ||
| 21 | - << std::endl | 20 | + << " -static-iv -- use static initialization vector" << std::endl |
| 22 | << " -no-padding -- disable padding" << std::endl | 21 | << " -no-padding -- disable padding" << std::endl |
| 23 | << "Options must precede key and file names." << std::endl; | 22 | << "Options must precede key and file names." << std::endl; |
| 24 | exit(2); | 23 | exit(2); |
libtests/arg_parser.cc
| @@ -41,9 +41,7 @@ ArgParser::ArgParser(int argc, char* argv[]) : | @@ -41,9 +41,7 @@ ArgParser::ArgParser(int argc, char* argv[]) : | ||
| 41 | void | 41 | void |
| 42 | ArgParser::initOptions() | 42 | ArgParser::initOptions() |
| 43 | { | 43 | { |
| 44 | - auto b = [this](void (ArgParser::*f)()) { | ||
| 45 | - return QPDFArgParser::bindBare(f, this); | ||
| 46 | - }; | 44 | + auto b = [this](void (ArgParser::*f)()) { return QPDFArgParser::bindBare(f, this); }; |
| 47 | auto p = [this](void (ArgParser::*f)(std::string const&)) { | 45 | auto p = [this](void (ArgParser::*f)(std::string const&)) { |
| 48 | return QPDFArgParser::bindParam(f, this); | 46 | return QPDFArgParser::bindParam(f, this); |
| 49 | }; | 47 | }; |
| @@ -71,9 +69,7 @@ ArgParser::initOptions() | @@ -71,9 +69,7 @@ ArgParser::initOptions() | ||
| 71 | 69 | ||
| 72 | ap.addHelpFooter("For more help, read the manual.\n"); | 70 | ap.addHelpFooter("For more help, read the manual.\n"); |
| 73 | ap.addHelpTopic( | 71 | ap.addHelpTopic( |
| 74 | - "quack", | ||
| 75 | - "Quack Options", | ||
| 76 | - "Just put stuff after quack to get a count at the end.\n"); | 72 | + "quack", "Quack Options", "Just put stuff after quack to get a count at the end.\n"); |
| 77 | ap.addHelpTopic( | 73 | ap.addHelpTopic( |
| 78 | "baaa", | 74 | "baaa", |
| 79 | "Baaa Options", | 75 | "Baaa Options", |
| @@ -139,8 +135,7 @@ ArgParser::getQuack(std::string const& p) | @@ -139,8 +135,7 @@ ArgParser::getQuack(std::string const& p) | ||
| 139 | { | 135 | { |
| 140 | ++this->quacks; | 136 | ++this->quacks; |
| 141 | if (this->ap.isCompleting() && (this->ap.argsLeft() == 0)) { | 137 | if (this->ap.isCompleting() && (this->ap.argsLeft() == 0)) { |
| 142 | - this->ap.insertCompletion( | ||
| 143 | - std::string("thing-") + std::to_string(this->quacks)); | 138 | + this->ap.insertCompletion(std::string("thing-") + std::to_string(this->quacks)); |
| 144 | return; | 139 | return; |
| 145 | } | 140 | } |
| 146 | output(std::string("got quack: ") + p); | 141 | output(std::string("got quack: ") + p); |
| @@ -178,24 +173,17 @@ ArgParser::test_exceptions() | @@ -178,24 +173,17 @@ ArgParser::test_exceptions() | ||
| 178 | ap.selectOptionTable("baaa"); | 173 | ap.selectOptionTable("baaa"); |
| 179 | ap.addBare("ram", []() {}); | 174 | ap.addBare("ram", []() {}); |
| 180 | }); | 175 | }); |
| 181 | - err("duplicate table", | ||
| 182 | - [this]() { ap.registerOptionTable("baaa", nullptr); }); | 176 | + err("duplicate table", [this]() { ap.registerOptionTable("baaa", nullptr); }); |
| 183 | err("unknown table", [this]() { ap.selectOptionTable("aardvark"); }); | 177 | err("unknown table", [this]() { ap.selectOptionTable("aardvark"); }); |
| 184 | - err("add existing help topic", | ||
| 185 | - [this]() { ap.addHelpTopic("baaa", "potato", "salad"); }); | ||
| 186 | - err("add reserved help topic", | ||
| 187 | - [this]() { ap.addHelpTopic("all", "potato", "salad"); }); | ||
| 188 | - err("add to unknown topic", | ||
| 189 | - [this]() { ap.addOptionHelp("--new", "oops", "potato", "salad"); }); | ||
| 190 | - err("bad option for help", | ||
| 191 | - [this]() { ap.addOptionHelp("nodash", "baaa", "potato", "salad"); }); | ||
| 192 | - err("bad topic for help", | ||
| 193 | - [this]() { ap.addHelpTopic("--dashes", "potato", "salad"); }); | 178 | + err("add existing help topic", [this]() { ap.addHelpTopic("baaa", "potato", "salad"); }); |
| 179 | + err("add reserved help topic", [this]() { ap.addHelpTopic("all", "potato", "salad"); }); | ||
| 180 | + err("add to unknown topic", [this]() { ap.addOptionHelp("--new", "oops", "potato", "salad"); }); | ||
| 181 | + err("bad option for help", [this]() { ap.addOptionHelp("nodash", "baaa", "potato", "salad"); }); | ||
| 182 | + err("bad topic for help", [this]() { ap.addHelpTopic("--dashes", "potato", "salad"); }); | ||
| 194 | err("duplicate option help", | 183 | err("duplicate option help", |
| 195 | [this]() { ap.addOptionHelp("--ewe", "baaa", "potato", "salad"); }); | 184 | [this]() { ap.addOptionHelp("--ewe", "baaa", "potato", "salad"); }); |
| 196 | - err("invalid choice handler to unknown", [this]() { | ||
| 197 | - ap.addInvalidChoiceHandler("elephant", [](std::string const&) {}); | ||
| 198 | - }); | 185 | + err("invalid choice handler to unknown", |
| 186 | + [this]() { ap.addInvalidChoiceHandler("elephant", [](std::string const&) {}); }); | ||
| 199 | } | 187 | } |
| 200 | 188 | ||
| 201 | int | 189 | int |
libtests/bits.cc
| @@ -28,25 +28,19 @@ test_read_bits( | @@ -28,25 +28,19 @@ test_read_bits( | ||
| 28 | size_t& bits_available, | 28 | size_t& bits_available, |
| 29 | size_t bits_wanted) | 29 | size_t bits_wanted) |
| 30 | { | 30 | { |
| 31 | - unsigned long result = | ||
| 32 | - QIntC::to_ulong(read_bits(p, bit_offset, bits_available, bits_wanted)); | 31 | + unsigned long result = QIntC::to_ulong(read_bits(p, bit_offset, bits_available, bits_wanted)); |
| 33 | 32 | ||
| 34 | - std::cout << "bits read: " << bits_wanted << ", result = " << result | ||
| 35 | - << std::endl; | 33 | + std::cout << "bits read: " << bits_wanted << ", result = " << result << std::endl; |
| 36 | print_values(p - buf, bit_offset, bits_available); | 34 | print_values(p - buf, bit_offset, bits_available); |
| 37 | } | 35 | } |
| 38 | 36 | ||
| 39 | static void | 37 | static void |
| 40 | test_write_bits( | 38 | test_write_bits( |
| 41 | - unsigned char& ch, | ||
| 42 | - size_t& bit_offset, | ||
| 43 | - unsigned long val, | ||
| 44 | - size_t bits, | ||
| 45 | - Pl_Buffer* bp) | 39 | + unsigned char& ch, size_t& bit_offset, unsigned long val, size_t bits, Pl_Buffer* bp) |
| 46 | { | 40 | { |
| 47 | write_bits(ch, bit_offset, val, bits, bp); | 41 | write_bits(ch, bit_offset, val, bits, bp); |
| 48 | - std::cout << "ch = " << QUtil::uint_to_string_base(ch, 16, 2) | ||
| 49 | - << ", bit_offset = " << bit_offset << std::endl; | 42 | + std::cout << "ch = " << QUtil::uint_to_string_base(ch, 16, 2) << ", bit_offset = " << bit_offset |
| 43 | + << std::endl; | ||
| 50 | } | 44 | } |
| 51 | 45 | ||
| 52 | static void | 46 | static void |
| @@ -57,8 +51,7 @@ print_buffer(Pl_Buffer* bp) | @@ -57,8 +51,7 @@ print_buffer(Pl_Buffer* bp) | ||
| 57 | unsigned char const* p = b->getBuffer(); | 51 | unsigned char const* p = b->getBuffer(); |
| 58 | size_t l = b->getSize(); | 52 | size_t l = b->getSize(); |
| 59 | for (unsigned long i = 0; i < l; ++i) { | 53 | for (unsigned long i = 0; i < l; ++i) { |
| 60 | - std::cout << QUtil::uint_to_string_base(p[i], 16, 2) | ||
| 61 | - << ((i == l - 1) ? "\n" : " "); | 54 | + std::cout << QUtil::uint_to_string_base(p[i], 16, 2) << ((i == l - 1) ? "\n" : " "); |
| 62 | } | 55 | } |
| 63 | std::cout << std::endl; | 56 | std::cout << std::endl; |
| 64 | delete b; | 57 | delete b; |
| @@ -72,8 +65,7 @@ test() | @@ -72,8 +65,7 @@ test() | ||
| 72 | 65 | ||
| 73 | // Read tests | 66 | // Read tests |
| 74 | 67 | ||
| 75 | - static unsigned char const buf[] = { | ||
| 76 | - 0xF5, 0x15, 0x65, 0x79, 0x12, 0x89, 0x75, 0x4B}; | 68 | + static unsigned char const buf[] = {0xF5, 0x15, 0x65, 0x79, 0x12, 0x89, 0x75, 0x4B}; |
| 77 | 69 | ||
| 78 | unsigned char const* p = buf; | 70 | unsigned char const* p = buf; |
| 79 | size_t bit_offset = 7; | 71 | size_t bit_offset = 7; |
libtests/concatenate.cc
| @@ -29,8 +29,7 @@ main(int argc, char* argv[]) | @@ -29,8 +29,7 @@ main(int argc, char* argv[]) | ||
| 29 | inflate.write(b1_buf->getBuffer(), b1_buf->getSize()); | 29 | inflate.write(b1_buf->getBuffer(), b1_buf->getSize()); |
| 30 | inflate.finish(); | 30 | inflate.finish(); |
| 31 | auto b2_buf = b2.getBufferSharedPointer(); | 31 | auto b2_buf = b2.getBufferSharedPointer(); |
| 32 | - std::string result( | ||
| 33 | - reinterpret_cast<char*>(b2_buf->getBuffer()), b2_buf->getSize()); | 32 | + std::string result(reinterpret_cast<char*>(b2_buf->getBuffer()), b2_buf->getSize()); |
| 34 | if (result == "-one--two-") { | 33 | if (result == "-one--two-") { |
| 35 | std::cout << "concatenate test passed" << std::endl; | 34 | std::cout << "concatenate test passed" << std::endl; |
| 36 | } else { | 35 | } else { |
libtests/cxx11.cc
| @@ -33,8 +33,7 @@ do_functional() | @@ -33,8 +33,7 @@ do_functional() | ||
| 33 | x = 7; // change not seen by lambda | 33 | x = 7; // change not seen by lambda |
| 34 | assert(by_value(1) == 6); | 34 | assert(by_value(1) == 6); |
| 35 | // Also >> at end of template | 35 | // Also >> at end of template |
| 36 | - assert((std::is_convertible<decltype(by_value), std::function<int(int)>>:: | ||
| 37 | - value)); | 36 | + assert((std::is_convertible<decltype(by_value), std::function<int(int)>>::value)); |
| 38 | 37 | ||
| 39 | // Capture by reference | 38 | // Capture by reference |
| 40 | auto by_reference = [&x](int a) { return a + x; }; | 39 | auto by_reference = [&x](int a) { return a + x; }; |
libtests/input_source.cc
| @@ -47,8 +47,7 @@ Finder::check() | @@ -47,8 +47,7 @@ Finder::check() | ||
| 47 | void | 47 | void |
| 48 | check(char const* description, bool expected, bool actual) | 48 | check(char const* description, bool expected, bool actual) |
| 49 | { | 49 | { |
| 50 | - std::cout << description << ": " << ((actual == expected) ? "PASS" : "FAIL") | ||
| 51 | - << std::endl; | 50 | + std::cout << description << ": " << ((actual == expected) ? "PASS" : "FAIL") << std::endl; |
| 52 | } | 51 | } |
| 53 | 52 | ||
| 54 | int | 53 | int |
| @@ -61,28 +60,15 @@ main() | @@ -61,28 +60,15 @@ main() | ||
| 61 | // Overlap so that the first check() would advance past the start | 60 | // Overlap so that the first check() would advance past the start |
| 62 | // of the next match | 61 | // of the next match |
| 63 | memcpy(b + 2037, "potato potato salad ", 20); | 62 | memcpy(b + 2037, "potato potato salad ", 20); |
| 64 | - auto is = std::shared_ptr<InputSource>( | ||
| 65 | - new BufferInputSource("test buffer input source", b1.get())); | 63 | + auto is = |
| 64 | + std::shared_ptr<InputSource>(new BufferInputSource("test buffer input source", b1.get())); | ||
| 66 | Finder f1(is, "salad"); | 65 | Finder f1(is, "salad"); |
| 67 | check("find potato salad", true, is->findFirst("potato", 0, 0, f1)); | 66 | check("find potato salad", true, is->findFirst("potato", 0, 0, f1)); |
| 68 | - check( | ||
| 69 | - "barely find potato salad", | ||
| 70 | - true, | ||
| 71 | - is->findFirst("potato", 1100, 945, f1)); | ||
| 72 | - check( | ||
| 73 | - "barely find potato salad", | ||
| 74 | - true, | ||
| 75 | - is->findFirst("potato", 2000, 45, f1)); | ||
| 76 | - check( | ||
| 77 | - "potato salad is too late", | ||
| 78 | - false, | ||
| 79 | - is->findFirst("potato", 1100, 944, f1)); | ||
| 80 | - check( | ||
| 81 | - "potato salad is too late", | ||
| 82 | - false, | ||
| 83 | - is->findFirst("potato", 2000, 44, f1)); | ||
| 84 | - check( | ||
| 85 | - "potato salad not found", false, is->findFirst("potato", 2045, 0, f1)); | 67 | + check("barely find potato salad", true, is->findFirst("potato", 1100, 945, f1)); |
| 68 | + check("barely find potato salad", true, is->findFirst("potato", 2000, 45, f1)); | ||
| 69 | + check("potato salad is too late", false, is->findFirst("potato", 1100, 944, f1)); | ||
| 70 | + check("potato salad is too late", false, is->findFirst("potato", 2000, 44, f1)); | ||
| 71 | + check("potato salad not found", false, is->findFirst("potato", 2045, 0, f1)); | ||
| 86 | check("potato salad not found", false, is->findFirst("potato", 0, 1, f1)); | 72 | check("potato salad not found", false, is->findFirst("potato", 0, 1, f1)); |
| 87 | 73 | ||
| 88 | // Put one more right at EOF | 74 | // Put one more right at EOF |
| @@ -91,18 +77,13 @@ main() | @@ -91,18 +77,13 @@ main() | ||
| 91 | 77 | ||
| 92 | is->findFirst("potato", 0, 0, f1); | 78 | is->findFirst("potato", 0, 0, f1); |
| 93 | check("findFirst found first", true, is->tell() == 2056); | 79 | check("findFirst found first", true, is->tell() == 2056); |
| 94 | - check( | ||
| 95 | - "findLast found potato salad", true, is->findLast("potato", 0, 0, f1)); | 80 | + check("findLast found potato salad", true, is->findLast("potato", 0, 0, f1)); |
| 96 | check("findLast found at EOF", true, is->tell() == 3172); | 81 | check("findLast found at EOF", true, is->tell() == 3172); |
| 97 | 82 | ||
| 98 | // Make check() bump into EOF | 83 | // Make check() bump into EOF |
| 99 | memcpy(b + b1->getSize() - 6, "potato", 6); | 84 | memcpy(b + b1->getSize() - 6, "potato", 6); |
| 100 | - check( | ||
| 101 | - "potato but not salad salad at EOF", | ||
| 102 | - false, | ||
| 103 | - is->findFirst("potato", 3000, 0, f1)); | ||
| 104 | - check( | ||
| 105 | - "findLast found potato salad", true, is->findLast("potato", 0, 0, f1)); | 85 | + check("potato but not salad salad at EOF", false, is->findFirst("potato", 3000, 0, f1)); |
| 86 | + check("findLast found potato salad", true, is->findLast("potato", 0, 0, f1)); | ||
| 106 | check("findLast found first one", true, is->tell() == 2056); | 87 | check("findLast found first one", true, is->tell() == 2056); |
| 107 | 88 | ||
| 108 | return 0; | 89 | return 0; |
libtests/json.cc
| @@ -17,8 +17,7 @@ check(JSON const& j, std::string const& exp) | @@ -17,8 +17,7 @@ check(JSON const& j, std::string const& exp) | ||
| 17 | static void | 17 | static void |
| 18 | test_main() | 18 | test_main() |
| 19 | { | 19 | { |
| 20 | - JSON jstr = JSON::makeString( | ||
| 21 | - "<1>\xcf\x80<2>\xf0\x9f\xa5\x94\\\"<3>\x03\t\b\r\n<4>"); | 20 | + JSON jstr = JSON::makeString("<1>\xcf\x80<2>\xf0\x9f\xa5\x94\\\"<3>\x03\t\b\r\n<4>"); |
| 22 | check( | 21 | check( |
| 23 | jstr, | 22 | jstr, |
| 24 | "\"<1>\xcf\x80<2>\xf0\x9f\xa5\x94\\\\\\\"<3>" | 23 | "\"<1>\xcf\x80<2>\xf0\x9f\xa5\x94\\\\\\\"<3>" |
| @@ -60,8 +59,7 @@ test_main() | @@ -60,8 +59,7 @@ test_main() | ||
| 60 | " 2.1e5\n" | 59 | " 2.1e5\n" |
| 61 | "]"); | 60 | "]"); |
| 62 | std::vector<std::string> avalue; | 61 | std::vector<std::string> avalue; |
| 63 | - assert(jarr.forEachArrayItem( | ||
| 64 | - [&avalue](JSON j) { avalue.push_back(j.unparse()); })); | 62 | + assert(jarr.forEachArrayItem([&avalue](JSON j) { avalue.push_back(j.unparse()); })); |
| 65 | std::vector<std::string> xavalue = { | 63 | std::vector<std::string> xavalue = { |
| 66 | "\"a\\tb\"", | 64 | "\"a\\tb\"", |
| 67 | "null", | 65 | "null", |
| @@ -79,8 +77,7 @@ test_main() | @@ -79,8 +77,7 @@ test_main() | ||
| 79 | jmap.addDictionaryMember("no", JSON::makeBool(true)); | 77 | jmap.addDictionaryMember("no", JSON::makeBool(true)); |
| 80 | jmap.addDictionaryMember("empty_dict", JSON::makeDictionary()); | 78 | jmap.addDictionaryMember("empty_dict", JSON::makeDictionary()); |
| 81 | jmap.addDictionaryMember("empty_list", JSON::makeArray()); | 79 | jmap.addDictionaryMember("empty_list", JSON::makeArray()); |
| 82 | - jmap.addDictionaryMember("single", JSON::makeArray()) | ||
| 83 | - .addArrayElement(JSON::makeInt(12)); | 80 | + jmap.addDictionaryMember("single", JSON::makeArray()).addArrayElement(JSON::makeInt(12)); |
| 84 | check( | 81 | check( |
| 85 | jmap, | 82 | jmap, |
| 86 | "{\n" | 83 | "{\n" |
| @@ -117,9 +114,7 @@ test_main() | @@ -117,9 +114,7 @@ test_main() | ||
| 117 | {"c", "[\n true\n]"}, | 114 | {"c", "[\n true\n]"}, |
| 118 | }; | 115 | }; |
| 119 | assert(dvalue == xdvalue); | 116 | assert(dvalue == xdvalue); |
| 120 | - auto blob_data = [](Pipeline* p) { | ||
| 121 | - *p << "\x01\x02\x03\x04\x05\xff\xfe\xfd\xfc\xfb"; | ||
| 122 | - }; | 117 | + auto blob_data = [](Pipeline* p) { *p << "\x01\x02\x03\x04\x05\xff\xfe\xfd\xfc\xfb"; }; |
| 123 | JSON jblob = JSON::makeDictionary(); | 118 | JSON jblob = JSON::makeDictionary(); |
| 124 | jblob.addDictionaryMember("normal", JSON::parse(R"("string")")); | 119 | jblob.addDictionaryMember("normal", JSON::parse(R"("string")")); |
| 125 | jblob.addDictionaryMember("blob", JSON::makeBlob(blob_data)); | 120 | jblob.addDictionaryMember("blob", JSON::makeBlob(blob_data)); |
| @@ -133,12 +128,7 @@ test_main() | @@ -133,12 +128,7 @@ test_main() | ||
| 133 | } | 128 | } |
| 134 | 129 | ||
| 135 | static void | 130 | static void |
| 136 | -check_schema( | ||
| 137 | - JSON& obj, | ||
| 138 | - JSON& schema, | ||
| 139 | - unsigned long flags, | ||
| 140 | - bool exp, | ||
| 141 | - std::string const& description) | 131 | +check_schema(JSON& obj, JSON& schema, unsigned long flags, bool exp, std::string const& description) |
| 142 | { | 132 | { |
| 143 | std::list<std::string> errors; | 133 | std::list<std::string> errors; |
| 144 | std::cout << "--- " << description << std::endl; | 134 | std::cout << "--- " << description << std::endl; |
libtests/json_handler.cc
| @@ -38,9 +38,7 @@ print_json(std::string const& path, JSON value) | @@ -38,9 +38,7 @@ print_json(std::string const& path, JSON value) | ||
| 38 | static JSONHandler::void_handler_t | 38 | static JSONHandler::void_handler_t |
| 39 | make_print_message(std::string msg) | 39 | make_print_message(std::string msg) |
| 40 | { | 40 | { |
| 41 | - return [msg](std::string const& path) { | ||
| 42 | - std::cout << path << ": json: " << msg << std::endl; | ||
| 43 | - }; | 41 | + return [msg](std::string const& path) { std::cout << path << ": json: " << msg << std::endl; }; |
| 44 | } | 42 | } |
| 45 | 43 | ||
| 46 | static void | 44 | static void |
libtests/json_parse.cc
| @@ -74,8 +74,7 @@ Reactor::arrayItem(JSON const& value) | @@ -74,8 +74,7 @@ Reactor::arrayItem(JSON const& value) | ||
| 74 | void | 74 | void |
| 75 | Reactor::printItem(JSON const& j) | 75 | Reactor::printItem(JSON const& j) |
| 76 | { | 76 | { |
| 77 | - std::cout << "[" << j.getStart() << ", " << j.getEnd() | ||
| 78 | - << "): " << j.unparse() << std::endl; | 77 | + std::cout << "[" << j.getStart() << ", " << j.getEnd() << "): " << j.unparse() << std::endl; |
| 79 | } | 78 | } |
| 80 | 79 | ||
| 81 | static void | 80 | static void |
libtests/logger.cc
| @@ -25,8 +25,7 @@ test1() | @@ -25,8 +25,7 @@ test1() | ||
| 25 | logger->saveToStandardOutput(true); | 25 | logger->saveToStandardOutput(true); |
| 26 | assert(false); | 26 | assert(false); |
| 27 | } catch (std::logic_error& e) { | 27 | } catch (std::logic_error& e) { |
| 28 | - *(logger->getInfo()) | ||
| 29 | - << "saveToStandardOutput exception: " << e.what() << "\n"; | 28 | + *(logger->getInfo()) << "saveToStandardOutput exception: " << e.what() << "\n"; |
| 30 | } | 29 | } |
| 31 | logger->setWarn(logger->discard()); | 30 | logger->setWarn(logger->discard()); |
| 32 | logger->warn("warning not seen\n"); | 31 | logger->warn("warning not seen\n"); |
libtests/logger_c.c
| @@ -54,15 +54,9 @@ main() | @@ -54,15 +54,9 @@ main() | ||
| 54 | qpdflogger_set_error(l, qpdf_log_dest_custom, fn, (void*)error); | 54 | qpdflogger_set_error(l, qpdf_log_dest_custom, fn, (void*)error); |
| 55 | qpdflogger_set_save(l, qpdf_log_dest_custom, fn, (void*)save, 0); | 55 | qpdflogger_set_save(l, qpdf_log_dest_custom, fn, (void*)save, 0); |
| 56 | 56 | ||
| 57 | - do_run( | ||
| 58 | - "{\"inputFile\": \"normal.pdf\", \"showNpages\": \"\"}", | ||
| 59 | - qpdf_exit_success); | ||
| 60 | - do_run( | ||
| 61 | - "{\"inputFile\": \"warning.pdf\", \"showNpages\": \"\"}", | ||
| 62 | - qpdf_exit_warning); | ||
| 63 | - do_run( | ||
| 64 | - "{\"inputFile\": \"missing.pdf\", \"showNpages\": \"\"}", | ||
| 65 | - qpdf_exit_error); | 57 | + do_run("{\"inputFile\": \"normal.pdf\", \"showNpages\": \"\"}", qpdf_exit_success); |
| 58 | + do_run("{\"inputFile\": \"warning.pdf\", \"showNpages\": \"\"}", qpdf_exit_warning); | ||
| 59 | + do_run("{\"inputFile\": \"missing.pdf\", \"showNpages\": \"\"}", qpdf_exit_error); | ||
| 66 | do_run( | 60 | do_run( |
| 67 | "{\"inputFile\": \"normal.pdf\"," | 61 | "{\"inputFile\": \"normal.pdf\"," |
| 68 | " \"staticId\": \"\"," | 62 | " \"staticId\": \"\"," |
| @@ -79,16 +73,11 @@ main() | @@ -79,16 +73,11 @@ main() | ||
| 79 | qpdflogger_set_error(l, qpdf_log_dest_default, NULL, NULL); | 73 | qpdflogger_set_error(l, qpdf_log_dest_default, NULL, NULL); |
| 80 | qpdflogger_set_save(l, qpdf_log_dest_custom, fn, (void*)save2, 0); | 74 | qpdflogger_set_save(l, qpdf_log_dest_custom, fn, (void*)save2, 0); |
| 81 | 75 | ||
| 82 | - do_run( | ||
| 83 | - "{\"inputFile\": \"2pages.pdf\", \"showNpages\": \"\"}", | ||
| 84 | - qpdf_exit_success); | ||
| 85 | - do_run( | ||
| 86 | - "{\"inputFile\": \"warning.pdf\", \"showNpages\": \"\"}", | ||
| 87 | - qpdf_exit_warning); | 76 | + do_run("{\"inputFile\": \"2pages.pdf\", \"showNpages\": \"\"}", qpdf_exit_success); |
| 77 | + do_run("{\"inputFile\": \"warning.pdf\", \"showNpages\": \"\"}", qpdf_exit_warning); | ||
| 88 | do_run( | 78 | do_run( |
| 89 | 79 | ||
| 90 | - "{\"inputFile\": \"missing.pdf\", \"showNpages\": \"\"}", | ||
| 91 | - qpdf_exit_error); | 80 | + "{\"inputFile\": \"missing.pdf\", \"showNpages\": \"\"}", qpdf_exit_error); |
| 92 | do_run( | 81 | do_run( |
| 93 | "{\"inputFile\": \"attach.pdf\"," | 82 | "{\"inputFile\": \"attach.pdf\"," |
| 94 | " \"showAttachment\": \"a\"}", | 83 | " \"showAttachment\": \"a\"}", |
libtests/lzw.cc
| @@ -15,8 +15,7 @@ main(int argc, char* argv[]) | @@ -15,8 +15,7 @@ main(int argc, char* argv[]) | ||
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | if (argc < 3) { | 17 | if (argc < 3) { |
| 18 | - std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]" | ||
| 19 | - << std::endl; | 18 | + std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]" << std::endl; |
| 20 | exit(2); | 19 | exit(2); |
| 21 | } | 20 | } |
| 22 | 21 |
libtests/matrix.cc
| @@ -16,31 +16,21 @@ check(QPDFMatrix const& m, std::string const& exp) | @@ -16,31 +16,21 @@ check(QPDFMatrix const& m, std::string const& exp) | ||
| 16 | static void | 16 | static void |
| 17 | check_xy(double x, double y, std::string const& exp) | 17 | check_xy(double x, double y, std::string const& exp) |
| 18 | { | 18 | { |
| 19 | - std::string u = | ||
| 20 | - (QUtil::double_to_string(x, 2) + " " + QUtil::double_to_string(y, 2)); | 19 | + std::string u = (QUtil::double_to_string(x, 2) + " " + QUtil::double_to_string(y, 2)); |
| 21 | if (u != exp) { | 20 | if (u != exp) { |
| 22 | std::cout << "got " << u << ", wanted " << exp << std::endl; | 21 | std::cout << "got " << u << ", wanted " << exp << std::endl; |
| 23 | } | 22 | } |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | static void | 25 | static void |
| 27 | -check_rect( | ||
| 28 | - QPDFObjectHandle::Rectangle const& r, | ||
| 29 | - double llx, | ||
| 30 | - double lly, | ||
| 31 | - double urx, | ||
| 32 | - double ury) | 26 | +check_rect(QPDFObjectHandle::Rectangle const& r, double llx, double lly, double urx, double ury) |
| 33 | { | 27 | { |
| 34 | std::string actual = | 28 | std::string actual = |
| 35 | - (QUtil::double_to_string(r.llx, 2) + " " + | ||
| 36 | - QUtil::double_to_string(r.lly, 2) + " " + | ||
| 37 | - QUtil::double_to_string(r.urx, 2) + " " + | ||
| 38 | - QUtil::double_to_string(r.ury, 2)); | 29 | + (QUtil::double_to_string(r.llx, 2) + " " + QUtil::double_to_string(r.lly, 2) + " " + |
| 30 | + QUtil::double_to_string(r.urx, 2) + " " + QUtil::double_to_string(r.ury, 2)); | ||
| 39 | std::string wanted = | 31 | std::string wanted = |
| 40 | - (QUtil::double_to_string(llx, 2) + " " + | ||
| 41 | - QUtil::double_to_string(lly, 2) + " " + | ||
| 42 | - QUtil::double_to_string(urx, 2) + " " + | ||
| 43 | - QUtil::double_to_string(ury, 2)); | 32 | + (QUtil::double_to_string(llx, 2) + " " + QUtil::double_to_string(lly, 2) + " " + |
| 33 | + QUtil::double_to_string(urx, 2) + " " + QUtil::double_to_string(ury, 2)); | ||
| 44 | if (actual != wanted) { | 34 | if (actual != wanted) { |
| 45 | std::cout << "got " << actual << ", wanted " << wanted << std::endl; | 35 | std::cout << "got " << actual << ", wanted " << wanted << std::endl; |
| 46 | } | 36 | } |
| @@ -80,19 +70,13 @@ main() | @@ -80,19 +70,13 @@ main() | ||
| 80 | check_xy(xp, yp, "2582.5 4912"); | 70 | check_xy(xp, yp, "2582.5 4912"); |
| 81 | 71 | ||
| 82 | check( | 72 | check( |
| 83 | - QPDFMatrix( | ||
| 84 | - QPDFObjectHandle::parse("[3 1 4 1 5 9.26535]").getArrayAsMatrix()), | 73 | + QPDFMatrix(QPDFObjectHandle::parse("[3 1 4 1 5 9.26535]").getArrayAsMatrix()), |
| 85 | "3 1 4 1 5 9.26535"); | 74 | "3 1 4 1 5 9.26535"); |
| 86 | 75 | ||
| 87 | m = QPDFMatrix(); | 76 | m = QPDFMatrix(); |
| 88 | m.rotatex90(90); | 77 | m.rotatex90(90); |
| 89 | m.translate(200, -100); | 78 | m.translate(200, -100); |
| 90 | - check_rect( | ||
| 91 | - m.transformRectangle(QPDFObjectHandle::Rectangle(10, 20, 30, 50)), | ||
| 92 | - 50, | ||
| 93 | - 210, | ||
| 94 | - 80, | ||
| 95 | - 230); | 79 | + check_rect(m.transformRectangle(QPDFObjectHandle::Rectangle(10, 20, 30, 50)), 50, 210, 80, 230); |
| 96 | 80 | ||
| 97 | std::cout << "matrix tests done" << std::endl; | 81 | std::cout << "matrix tests done" << std::endl; |
| 98 | return 0; | 82 | return 0; |
libtests/md5.cc
| @@ -32,17 +32,11 @@ main(int, char*[]) | @@ -32,17 +32,11 @@ main(int, char*[]) | ||
| 32 | b.encodeFile("md5.in", 100); | 32 | b.encodeFile("md5.in", 100); |
| 33 | std::cout << b.unparse() << std::endl; | 33 | std::cout << b.unparse() << std::endl; |
| 34 | 34 | ||
| 35 | - std::cout | ||
| 36 | - << MD5::checkDataChecksum("900150983cd24fb0d6963f7d28e17f72", "abc", 3) | ||
| 37 | - << std::endl | ||
| 38 | - << MD5::checkFileChecksum("5f4b4321873433daae578f85c72f9e74", "md5.in") | ||
| 39 | - << std::endl | ||
| 40 | - << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "md5.in") | ||
| 41 | - << std::endl | ||
| 42 | - << MD5::checkDataChecksum("000150983cd24fb0d6963f7d28e17f72", "abc", 3) | ||
| 43 | - << std::endl | ||
| 44 | - << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "glerbl") | ||
| 45 | - << std::endl; | 35 | + std::cout << MD5::checkDataChecksum("900150983cd24fb0d6963f7d28e17f72", "abc", 3) << std::endl |
| 36 | + << MD5::checkFileChecksum("5f4b4321873433daae578f85c72f9e74", "md5.in") << std::endl | ||
| 37 | + << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "md5.in") << std::endl | ||
| 38 | + << MD5::checkDataChecksum("000150983cd24fb0d6963f7d28e17f72", "abc", 3) << std::endl | ||
| 39 | + << MD5::checkFileChecksum("6f4b4321873433daae578f85c72f9e74", "glerbl") << std::endl; | ||
| 46 | 40 | ||
| 47 | Pl_Discard d; | 41 | Pl_Discard d; |
| 48 | Pl_MD5 p("MD5", &d); | 42 | Pl_MD5 p("MD5", &d); |
libtests/nntree.cc
| @@ -20,15 +20,12 @@ report(QPDF& q, QPDFObjectHandle oh, long long item, long long exp_item) | @@ -20,15 +20,12 @@ report(QPDF& q, QPDFObjectHandle oh, long long item, long long exp_item) | ||
| 20 | auto show = [&failed, &oh, &item]() { | 20 | auto show = [&failed, &oh, &item]() { |
| 21 | if (!failed) { | 21 | if (!failed) { |
| 22 | failed = true; | 22 | failed = true; |
| 23 | - std::cout << "key = " << item << ", oh = " << oh.unparseResolved() | ||
| 24 | - << std::endl; | 23 | + std::cout << "key = " << item << ", oh = " << oh.unparseResolved() << std::endl; |
| 25 | } | 24 | } |
| 26 | }; | 25 | }; |
| 27 | 26 | ||
| 28 | auto mk_wanted = [](long long i) { | 27 | auto mk_wanted = [](long long i) { |
| 29 | - return ( | ||
| 30 | - (i == -1) ? "end" | ||
| 31 | - : (std::to_string(i) + "/(-" + std::to_string(i) + "-)")); | 28 | + return ((i == -1) ? "end" : (std::to_string(i) + "/(-" + std::to_string(i) + "-)")); |
| 32 | }; | 29 | }; |
| 33 | std::string i1_wanted = mk_wanted(exp_item); | 30 | std::string i1_wanted = mk_wanted(exp_item); |
| 34 | std::string i2_wanted = mk_wanted(item == exp_item ? item : -1); | 31 | std::string i2_wanted = mk_wanted(item == exp_item ? item : -1); |
| @@ -40,13 +37,11 @@ report(QPDF& q, QPDFObjectHandle oh, long long item, long long exp_item) | @@ -40,13 +37,11 @@ report(QPDF& q, QPDFObjectHandle oh, long long item, long long exp_item) | ||
| 40 | 37 | ||
| 41 | if (i1_wanted != i1_actual) { | 38 | if (i1_wanted != i1_actual) { |
| 42 | show(); | 39 | show(); |
| 43 | - std::cout << "i1: wanted " << i1_wanted << ", got " << i1_actual | ||
| 44 | - << std::endl; | 40 | + std::cout << "i1: wanted " << i1_wanted << ", got " << i1_actual << std::endl; |
| 45 | } | 41 | } |
| 46 | if (i2_wanted != i2_actual) { | 42 | if (i2_wanted != i2_actual) { |
| 47 | show(); | 43 | show(); |
| 48 | - std::cout << "i2: wanted " << i2_wanted << ", got " << i2_actual | ||
| 49 | - << std::endl; | 44 | + std::cout << "i2: wanted " << i2_wanted << ", got " << i2_actual << std::endl; |
| 50 | } | 45 | } |
| 51 | 46 | ||
| 52 | return failed; | 47 | return failed; |
| @@ -62,8 +57,7 @@ test_bsearch() | @@ -62,8 +57,7 @@ test_bsearch() | ||
| 62 | auto nums = QPDFObjectHandle::newArray(); | 57 | auto nums = QPDFObjectHandle::newArray(); |
| 63 | for (auto i: v) { | 58 | for (auto i: v) { |
| 64 | nums.appendItem(QPDFObjectHandle::newInteger(i)); | 59 | nums.appendItem(QPDFObjectHandle::newInteger(i)); |
| 65 | - nums.appendItem( | ||
| 66 | - QPDFObjectHandle::newString("-" + std::to_string(i) + "-")); | 60 | + nums.appendItem(QPDFObjectHandle::newString("-" + std::to_string(i) + "-")); |
| 67 | } | 61 | } |
| 68 | auto limits = QPDFObjectHandle::newArray(); | 62 | auto limits = QPDFObjectHandle::newArray(); |
| 69 | limits.appendItem(QPDFObjectHandle::newInteger(v.at(0))); | 63 | limits.appendItem(QPDFObjectHandle::newInteger(v.at(0))); |
| @@ -125,10 +119,7 @@ new_node(QPDF& q, std::string const& key) | @@ -125,10 +119,7 @@ new_node(QPDF& q, std::string const& key) | ||
| 125 | } | 119 | } |
| 126 | 120 | ||
| 127 | static void | 121 | static void |
| 128 | -check_find( | ||
| 129 | - QPDFNameTreeObjectHelper& nh, | ||
| 130 | - std::string const& key, | ||
| 131 | - bool prev_if_not_found) | 122 | +check_find(QPDFNameTreeObjectHelper& nh, std::string const& key, bool prev_if_not_found) |
| 132 | { | 123 | { |
| 133 | auto i = nh.find(key, prev_if_not_found); | 124 | auto i = nh.find(key, prev_if_not_found); |
| 134 | std::cout << "find " << key << " (" << prev_if_not_found << "): "; | 125 | std::cout << "find " << key << " (" << prev_if_not_found << "): "; |
| @@ -165,8 +156,7 @@ test_depth() | @@ -165,8 +156,7 @@ test_depth() | ||
| 165 | std::string first; | 156 | std::string first; |
| 166 | std::string last; | 157 | std::string last; |
| 167 | for (int i4 = 0; i4 < NITEMS; ++i4) { | 158 | for (int i4 = 0; i4 < NITEMS; ++i4) { |
| 168 | - int val = | ||
| 169 | - (((((i1 * NITEMS) + i2) * NITEMS) + i3) * NITEMS) + i4; | 159 | + int val = (((((i1 * NITEMS) + i2) * NITEMS) + i3) * NITEMS) + i4; |
| 170 | std::string str = QUtil::int_to_string(10 * val, 6); | 160 | std::string str = QUtil::int_to_string(10 * val, 6); |
| 171 | items.appendItem(QPDFObjectHandle::newString(str)); | 161 | items.appendItem(QPDFObjectHandle::newString(str)); |
| 172 | items.appendItem(QPDFObjectHandle::newString("val " + str)); | 162 | items.appendItem(QPDFObjectHandle::newString("val " + str)); |
| @@ -183,16 +173,13 @@ test_depth() | @@ -183,16 +173,13 @@ test_depth() | ||
| 183 | } | 173 | } |
| 184 | auto limits = QPDFObjectHandle::newArray(); | 174 | auto limits = QPDFObjectHandle::newArray(); |
| 185 | n2.replaceKey("/Limits", limits); | 175 | n2.replaceKey("/Limits", limits); |
| 186 | - limits.appendItem( | ||
| 187 | - k2.getArrayItem(0).getKey("/Limits").getArrayItem(0)); | ||
| 188 | - limits.appendItem( | ||
| 189 | - k2.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1)); | 176 | + limits.appendItem(k2.getArrayItem(0).getKey("/Limits").getArrayItem(0)); |
| 177 | + limits.appendItem(k2.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1)); | ||
| 190 | } | 178 | } |
| 191 | auto limits = QPDFObjectHandle::newArray(); | 179 | auto limits = QPDFObjectHandle::newArray(); |
| 192 | n1.replaceKey("/Limits", limits); | 180 | n1.replaceKey("/Limits", limits); |
| 193 | limits.appendItem(k1.getArrayItem(0).getKey("/Limits").getArrayItem(0)); | 181 | limits.appendItem(k1.getArrayItem(0).getKey("/Limits").getArrayItem(0)); |
| 194 | - limits.appendItem( | ||
| 195 | - k1.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1)); | 182 | + limits.appendItem(k1.getArrayItem(NITEMS - 1).getKey("/Limits").getArrayItem(1)); |
| 196 | } | 183 | } |
| 197 | 184 | ||
| 198 | QPDFNameTreeObjectHelper nh(n0, q); | 185 | QPDFNameTreeObjectHelper nh(n0, q); |
libtests/pointer_holder.cc
| @@ -185,8 +185,7 @@ ph_sp_compat() | @@ -185,8 +185,7 @@ ph_sp_compat() | ||
| 185 | PointerHolder<Object> arr1_ph; | 185 | PointerHolder<Object> arr1_ph; |
| 186 | { | 186 | { |
| 187 | std::cout << "initialize ph array from shared_ptr" << std::endl; | 187 | std::cout << "initialize ph array from shared_ptr" << std::endl; |
| 188 | - std::shared_ptr<Object> arr1( | ||
| 189 | - new Object[2], std::default_delete<Object[]>()); | 188 | + std::shared_ptr<Object> arr1(new Object[2], std::default_delete<Object[]>()); |
| 190 | arr1_ph = arr1; | 189 | arr1_ph = arr1; |
| 191 | } | 190 | } |
| 192 | std::cout << "delete ph array" << std::endl; | 191 | std::cout << "delete ph array" << std::endl; |
libtests/qintc.cc
| @@ -3,16 +3,11 @@ | @@ -3,16 +3,11 @@ | ||
| 3 | #include <qpdf/QIntC.hh> | 3 | #include <qpdf/QIntC.hh> |
| 4 | #include <cstdint> | 4 | #include <cstdint> |
| 5 | 5 | ||
| 6 | -#define try_convert(exp_pass, fn, i) \ | ||
| 7 | - try_convert_real(#fn "(" #i ")", exp_pass, fn, i) | 6 | +#define try_convert(exp_pass, fn, i) try_convert_real(#fn "(" #i ")", exp_pass, fn, i) |
| 8 | 7 | ||
| 9 | template <typename From, typename To> | 8 | template <typename From, typename To> |
| 10 | static void | 9 | static void |
| 11 | -try_convert_real( | ||
| 12 | - char const* description, | ||
| 13 | - bool exp_pass, | ||
| 14 | - To (*fn)(From const&), | ||
| 15 | - From const& i) | 10 | +try_convert_real(char const* description, bool exp_pass, To (*fn)(From const&), From const& i) |
| 16 | { | 11 | { |
| 17 | bool passed = false; | 12 | bool passed = false; |
| 18 | try { | 13 | try { |
| @@ -26,13 +21,11 @@ try_convert_real( | @@ -26,13 +21,11 @@ try_convert_real( | ||
| 26 | std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << std::endl; | 21 | std::cout << ((passed == exp_pass) ? " PASSED" : " FAILED") << std::endl; |
| 27 | } | 22 | } |
| 28 | 23 | ||
| 29 | -#define try_range_check(exp_pass, a, b) \ | ||
| 30 | - try_range_check_real(#a " + " #b, exp_pass, a, b) | 24 | +#define try_range_check(exp_pass, a, b) try_range_check_real(#a " + " #b, exp_pass, a, b) |
| 31 | 25 | ||
| 32 | template <typename T> | 26 | template <typename T> |
| 33 | static void | 27 | static void |
| 34 | -try_range_check_real( | ||
| 35 | - char const* description, bool exp_pass, T const& a, T const& b) | 28 | +try_range_check_real(char const* description, bool exp_pass, T const& a, T const& b) |
| 36 | { | 29 | { |
| 37 | bool passed = false; | 30 | bool passed = false; |
| 38 | try { | 31 | try { |
| @@ -51,8 +44,7 @@ try_range_check_real( | @@ -51,8 +44,7 @@ try_range_check_real( | ||
| 51 | 44 | ||
| 52 | template <typename T> | 45 | template <typename T> |
| 53 | static void | 46 | static void |
| 54 | -try_range_check_subtract_real( | ||
| 55 | - char const* description, bool exp_pass, T const& a, T const& b) | 47 | +try_range_check_subtract_real(char const* description, bool exp_pass, T const& a, T const& b) |
| 56 | { | 48 | { |
| 57 | bool passed = false; | 49 | bool passed = false; |
| 58 | try { | 50 | try { |
| @@ -75,7 +67,7 @@ main() | @@ -75,7 +67,7 @@ main() | ||
| 75 | uint64_t ul2 = 12345; // Fits into 32-bit | 67 | uint64_t ul2 = 12345; // Fits into 32-bit |
| 76 | int32_t i2 = 81; // Fits in char and uchar | 68 | int32_t i2 = 81; // Fits in char and uchar |
| 77 | auto c1 = static_cast<signed char>('\xf7'); // Signed value when char | 69 | auto c1 = static_cast<signed char>('\xf7'); // Signed value when char |
| 78 | - char c2 = 'W'; // char; may be signed or unsigned | 70 | + char c2 = 'W'; // char; may be signed or unsigned |
| 79 | 71 | ||
| 80 | // Verify i1 and u1 have same bit pattern | 72 | // Verify i1 and u1 have same bit pattern |
| 81 | assert(static_cast<uint32_t>(i1) == u1); | 73 | assert(static_cast<uint32_t>(i1) == u1); |
libtests/qutil.cc
| @@ -17,8 +17,7 @@ | @@ -17,8 +17,7 @@ | ||
| 17 | 17 | ||
| 18 | template <class int_T> | 18 | template <class int_T> |
| 19 | void | 19 | void |
| 20 | -test_to_number( | ||
| 21 | - char const* str, int_T wanted, bool error, int_T (*fn)(char const*)) | 20 | +test_to_number(char const* str, int_T wanted, bool error, int_T (*fn)(char const*)) |
| 22 | { | 21 | { |
| 23 | bool threw = false; | 22 | bool threw = false; |
| 24 | bool worked = false; | 23 | bool worked = false; |
| @@ -33,11 +32,9 @@ test_to_number( | @@ -33,11 +32,9 @@ test_to_number( | ||
| 33 | } | 32 | } |
| 34 | if (threw) { | 33 | if (threw) { |
| 35 | if (error) { | 34 | if (error) { |
| 36 | - std::cout << str << " to int threw (" << msg << "): PASSED" | ||
| 37 | - << std::endl; | 35 | + std::cout << str << " to int threw (" << msg << "): PASSED" << std::endl; |
| 38 | } else { | 36 | } else { |
| 39 | - std::cout << str << " to int threw but wanted " << wanted | ||
| 40 | - << std::endl; | 37 | + std::cout << str << " to int threw but wanted " << wanted << std::endl; |
| 41 | } | 38 | } |
| 42 | } else { | 39 | } else { |
| 43 | if (worked) { | 40 | if (worked) { |
| @@ -203,11 +200,10 @@ void | @@ -203,11 +200,10 @@ void | ||
| 203 | getenv_test() | 200 | getenv_test() |
| 204 | { | 201 | { |
| 205 | std::string val; | 202 | std::string val; |
| 206 | - std::cout << "IN_TESTSUITE: " << QUtil::get_env("IN_TESTSUITE", &val) | ||
| 207 | - << ": " << val << std::endl; | ||
| 208 | - // Hopefully this environment variable is not defined. | ||
| 209 | - std::cout << "HAGOOGAMAGOOGLE: " << QUtil::get_env("HAGOOGAMAGOOGLE") | 203 | + std::cout << "IN_TESTSUITE: " << QUtil::get_env("IN_TESTSUITE", &val) << ": " << val |
| 210 | << std::endl; | 204 | << std::endl; |
| 205 | + // Hopefully this environment variable is not defined. | ||
| 206 | + std::cout << "HAGOOGAMAGOOGLE: " << QUtil::get_env("HAGOOGAMAGOOGLE") << std::endl; | ||
| 211 | } | 207 | } |
| 212 | 208 | ||
| 213 | static void | 209 | static void |
| @@ -224,9 +220,7 @@ print_utf8(unsigned long val) | @@ -224,9 +220,7 @@ print_utf8(unsigned long val) | ||
| 224 | for (auto const& ch: result) { | 220 | for (auto const& ch: result) { |
| 225 | std::cout << " " | 221 | std::cout << " " |
| 226 | << QUtil::int_to_string_base( | 222 | << QUtil::int_to_string_base( |
| 227 | - static_cast<int>(static_cast<unsigned char>(ch)), | ||
| 228 | - 16, | ||
| 229 | - 2); | 223 | + static_cast<int>(static_cast<unsigned char>(ch)), 16, 2); |
| 230 | } | 224 | } |
| 231 | } | 225 | } |
| 232 | std::cout << std::endl; | 226 | std::cout << std::endl; |
| @@ -282,9 +276,7 @@ print_utf16(unsigned long val) | @@ -282,9 +276,7 @@ print_utf16(unsigned long val) | ||
| 282 | for (auto const& ch: result) { | 276 | for (auto const& ch: result) { |
| 283 | std::cout << " " | 277 | std::cout << " " |
| 284 | << QUtil::int_to_string_base( | 278 | << QUtil::int_to_string_base( |
| 285 | - static_cast<int>(static_cast<unsigned char>(ch)), | ||
| 286 | - 16, | ||
| 287 | - 2); | 279 | + static_cast<int>(static_cast<unsigned char>(ch)), 16, 2); |
| 288 | } | 280 | } |
| 289 | std::cout << std::endl; | 281 | std::cout << std::endl; |
| 290 | } | 282 | } |
| @@ -303,8 +295,7 @@ to_utf16_test() | @@ -303,8 +295,7 @@ to_utf16_test() | ||
| 303 | std::string s(QUtil::utf8_to_utf16("\xcf\x80")); | 295 | std::string s(QUtil::utf8_to_utf16("\xcf\x80")); |
| 304 | std::cout << QUtil::utf16_to_utf8(s) << std::endl; | 296 | std::cout << QUtil::utf16_to_utf8(s) << std::endl; |
| 305 | std::cout << QUtil::utf16_to_utf8(s + ".") << std::endl; | 297 | std::cout << QUtil::utf16_to_utf8(s + ".") << std::endl; |
| 306 | - std::cout << "LE: " << QUtil::utf16_to_utf8("\xff\xfe\xc0\x03") | ||
| 307 | - << std::endl; | 298 | + std::cout << "LE: " << QUtil::utf16_to_utf8("\xff\xfe\xc0\x03") << std::endl; |
| 308 | } | 299 | } |
| 309 | 300 | ||
| 310 | void | 301 | void |
| @@ -316,13 +307,10 @@ utf8_to_ascii_test() | @@ -316,13 +307,10 @@ utf8_to_ascii_test() | ||
| 316 | << QUtil::utf8_to_ascii(input, '*') << std::endl; | 307 | << QUtil::utf8_to_ascii(input, '*') << std::endl; |
| 317 | std::string a = QUtil::utf8_to_win_ansi(input, '*'); | 308 | std::string a = QUtil::utf8_to_win_ansi(input, '*'); |
| 318 | std::string b = QUtil::utf8_to_mac_roman(input, '*'); | 309 | std::string b = QUtil::utf8_to_mac_roman(input, '*'); |
| 319 | - std::cout | ||
| 320 | - << "<" | ||
| 321 | - << QUtil::int_to_string_base(static_cast<unsigned char>(a.at(0)), 16, 2) | ||
| 322 | - << ">" << a.substr(1) << std::endl | ||
| 323 | - << "<" | ||
| 324 | - << QUtil::int_to_string_base(static_cast<unsigned char>(b.at(0)), 16, 2) | ||
| 325 | - << ">" << b.substr(1) << std::endl; | 310 | + std::cout << "<" << QUtil::int_to_string_base(static_cast<unsigned char>(a.at(0)), 16, 2) << ">" |
| 311 | + << a.substr(1) << std::endl | ||
| 312 | + << "<" << QUtil::int_to_string_base(static_cast<unsigned char>(b.at(0)), 16, 2) << ">" | ||
| 313 | + << b.substr(1) << std::endl; | ||
| 326 | } | 314 | } |
| 327 | 315 | ||
| 328 | void | 316 | void |
| @@ -342,8 +330,8 @@ transcoding_test( | @@ -342,8 +330,8 @@ transcoding_test( | ||
| 342 | std::string wanted = (out == "\xef\xbf\xbd") ? unknown : in; | 330 | std::string wanted = (out == "\xef\xbf\xbd") ? unknown : in; |
| 343 | back = (*from_utf8)(out, '?'); | 331 | back = (*from_utf8)(out, '?'); |
| 344 | if (back != wanted) { | 332 | if (back != wanted) { |
| 345 | - std::cout << i << ": " << in << " -> " << out << " -> " << back | ||
| 346 | - << " (wanted " << wanted << ")" << std::endl; | 333 | + std::cout << i << ": " << in << " -> " << out << " -> " << back << " (wanted " << wanted |
| 334 | + << ")" << std::endl; | ||
| 347 | } | 335 | } |
| 348 | } | 336 | } |
| 349 | } | 337 | } |
| @@ -355,8 +343,7 @@ check_analyze(std::string const& str, bool has8bit, bool utf8, bool utf16) | @@ -355,8 +343,7 @@ check_analyze(std::string const& str, bool has8bit, bool utf8, bool utf16) | ||
| 355 | bool is_valid_utf8 = false; | 343 | bool is_valid_utf8 = false; |
| 356 | bool is_utf16 = false; | 344 | bool is_utf16 = false; |
| 357 | QUtil::analyze_encoding(str, has_8bit_chars, is_valid_utf8, is_utf16); | 345 | QUtil::analyze_encoding(str, has_8bit_chars, is_valid_utf8, is_utf16); |
| 358 | - if (!((has_8bit_chars == has8bit) && (is_valid_utf8 == utf8) && | ||
| 359 | - (is_utf16 == utf16))) { | 346 | + if (!((has_8bit_chars == has8bit) && (is_valid_utf8 == utf8) && (is_utf16 == utf16))) { |
| 360 | std::cout << "analysis failed: " << str << std::endl; | 347 | std::cout << "analysis failed: " << str << std::endl; |
| 361 | } | 348 | } |
| 362 | } | 349 | } |
| @@ -374,17 +361,13 @@ print_alternatives(std::string const& str) | @@ -374,17 +361,13 @@ print_alternatives(std::string const& str) | ||
| 374 | void | 361 | void |
| 375 | transcoding_test() | 362 | transcoding_test() |
| 376 | { | 363 | { |
| 377 | - transcoding_test( | ||
| 378 | - &QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 127, 160, "\x9f"); | 364 | + transcoding_test(&QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 127, 160, "\x9f"); |
| 379 | std::cout << "bidirectional pdf doc done" << std::endl; | 365 | std::cout << "bidirectional pdf doc done" << std::endl; |
| 380 | - transcoding_test( | ||
| 381 | - &QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 24, 31, "?"); | 366 | + transcoding_test(&QUtil::pdf_doc_to_utf8, &QUtil::utf8_to_pdf_doc, 24, 31, "?"); |
| 382 | std::cout << "bidirectional pdf doc low done" << std::endl; | 367 | std::cout << "bidirectional pdf doc low done" << std::endl; |
| 383 | - transcoding_test( | ||
| 384 | - &QUtil::win_ansi_to_utf8, &QUtil::utf8_to_win_ansi, 128, 160, "?"); | 368 | + transcoding_test(&QUtil::win_ansi_to_utf8, &QUtil::utf8_to_win_ansi, 128, 160, "?"); |
| 385 | std::cout << "bidirectional win ansi done" << std::endl; | 369 | std::cout << "bidirectional win ansi done" << std::endl; |
| 386 | - transcoding_test( | ||
| 387 | - &QUtil::mac_roman_to_utf8, &QUtil::utf8_to_mac_roman, 128, 255, "?"); | 370 | + transcoding_test(&QUtil::mac_roman_to_utf8, &QUtil::utf8_to_mac_roman, 128, 255, "?"); |
| 388 | std::cout << "bidirectional mac roman done" << std::endl; | 371 | std::cout << "bidirectional mac roman done" << std::endl; |
| 389 | check_analyze("pi = \317\200", true, true, false); | 372 | check_analyze("pi = \317\200", true, true, false); |
| 390 | check_analyze("pi != \317", true, false, false); | 373 | check_analyze("pi != \317", true, false, false); |
| @@ -426,8 +409,7 @@ transcoding_test() | @@ -426,8 +409,7 @@ transcoding_test() | ||
| 426 | // cSpell: ignore xadw | 409 | // cSpell: ignore xadw |
| 427 | std::string other_doc = other + "\x9fw\xadw"; | 410 | std::string other_doc = other + "\x9fw\xadw"; |
| 428 | std::cout << QUtil::pdf_doc_to_utf8(other_doc) << std::endl; | 411 | std::cout << QUtil::pdf_doc_to_utf8(other_doc) << std::endl; |
| 429 | - std::string other_utf8 = | ||
| 430 | - other + QUtil::toUTF8(0x9f) + "w" + QUtil::toUTF8(0xad) + "w"; | 412 | + std::string other_utf8 = other + QUtil::toUTF8(0x9f) + "w" + QUtil::toUTF8(0xad) + "w"; |
| 431 | std::string other_to_utf8; | 413 | std::string other_to_utf8; |
| 432 | assert(!QUtil::utf8_to_pdf_doc(other_utf8, other_to_utf8)); | 414 | assert(!QUtil::utf8_to_pdf_doc(other_utf8, other_to_utf8)); |
| 433 | std::cout << other_to_utf8 << std::endl; | 415 | std::cout << other_to_utf8 << std::endl; |
| @@ -533,8 +515,7 @@ read_from_file_test() | @@ -533,8 +515,7 @@ read_from_file_test() | ||
| 533 | } | 515 | } |
| 534 | 516 | ||
| 535 | // Test with EOL preservation | 517 | // Test with EOL preservation |
| 536 | - std::list<std::string> lines2 = | ||
| 537 | - QUtil::read_lines_from_file("other-file", true); | 518 | + std::list<std::string> lines2 = QUtil::read_lines_from_file("other-file", true); |
| 538 | auto line = lines2.begin(); | 519 | auto line = lines2.begin(); |
| 539 | assert(37 == (*line).length()); | 520 | assert(37 == (*line).length()); |
| 540 | assert('.' == (*line).at(35)); | 521 | assert('.' == (*line).at(35)); |
| @@ -693,8 +674,8 @@ timestamp_test() | @@ -693,8 +674,8 @@ timestamp_test() | ||
| 693 | // Round trip on the current time without actually printing it. | 674 | // Round trip on the current time without actually printing it. |
| 694 | // Manual testing was done to ensure that we are actually getting | 675 | // Manual testing was done to ensure that we are actually getting |
| 695 | // back the current time in various time zones. | 676 | // back the current time in various time zones. |
| 696 | - assert(QUtil::pdf_time_to_qpdf_time( | ||
| 697 | - QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time()))); | 677 | + assert( |
| 678 | + QUtil::pdf_time_to_qpdf_time(QUtil::qpdf_time_to_pdf_time(QUtil::get_current_qpdf_time()))); | ||
| 698 | } | 679 | } |
| 699 | 680 | ||
| 700 | void | 681 | void |
libtests/runlength.cc
| @@ -11,8 +11,7 @@ int | @@ -11,8 +11,7 @@ int | ||
| 11 | main(int argc, char* argv[]) | 11 | main(int argc, char* argv[]) |
| 12 | { | 12 | { |
| 13 | if (argc != 4) { | 13 | if (argc != 4) { |
| 14 | - std::cerr << "Usage: runlength {-encode|-decode} infile outfile" | ||
| 15 | - << std::endl; | 14 | + std::cerr << "Usage: runlength {-encode|-decode} infile outfile" << std::endl; |
| 16 | exit(2); | 15 | exit(2); |
| 17 | } | 16 | } |
| 18 | 17 | ||
| @@ -25,10 +24,7 @@ main(int argc, char* argv[]) | @@ -25,10 +24,7 @@ main(int argc, char* argv[]) | ||
| 25 | Pl_StdioFile out("stdout", outfile); | 24 | Pl_StdioFile out("stdout", outfile); |
| 26 | unsigned char buf[100]; | 25 | unsigned char buf[100]; |
| 27 | bool done = false; | 26 | bool done = false; |
| 28 | - Pl_RunLength rl( | ||
| 29 | - "runlength", | ||
| 30 | - &out, | ||
| 31 | - (encode ? Pl_RunLength::a_encode : Pl_RunLength::a_decode)); | 27 | + Pl_RunLength rl("runlength", &out, (encode ? Pl_RunLength::a_encode : Pl_RunLength::a_decode)); |
| 32 | while (!done) { | 28 | while (!done) { |
| 33 | size_t len = fread(buf, 1, sizeof(buf), infile); | 29 | size_t len = fread(buf, 1, sizeof(buf), infile); |
| 34 | if (len <= 0) { | 30 | if (len <= 0) { |
libtests/sha2.cc
| @@ -4,12 +4,7 @@ | @@ -4,12 +4,7 @@ | ||
| 4 | #include <iostream> | 4 | #include <iostream> |
| 5 | 5 | ||
| 6 | static void | 6 | static void |
| 7 | -test( | ||
| 8 | - Pl_SHA2& sha2, | ||
| 9 | - char const* description, | ||
| 10 | - int bits, | ||
| 11 | - char const* input, | ||
| 12 | - std::string const& output) | 7 | +test(Pl_SHA2& sha2, char const* description, int bits, char const* input, std::string const& output) |
| 13 | { | 8 | { |
| 14 | sha2.resetBits(bits); | 9 | sha2.resetBits(bits); |
| 15 | sha2.write(QUtil::unsigned_char_pointer(input), strlen(input)); | 10 | sha2.write(QUtil::unsigned_char_pointer(input), strlen(input)); |
qpdf/fix-qdf.cc
| @@ -103,9 +103,7 @@ QdfFixer::processLines(std::string const& input) | @@ -103,9 +103,7 @@ QdfFixer::processLines(std::string const& input) | ||
| 103 | static const std::regex re_num("^\\d+\n$"); | 103 | static const std::regex re_num("^\\d+\n$"); |
| 104 | static const std::regex re_size_n("^ /Size \\d+\n$"); | 104 | static const std::regex re_size_n("^ /Size \\d+\n$"); |
| 105 | 105 | ||
| 106 | - auto sv_diff = [](size_t i) { | ||
| 107 | - return static_cast<std::string_view::difference_type>(i); | ||
| 108 | - }; | 106 | + auto sv_diff = [](size_t i) { return static_cast<std::string_view::difference_type>(i); }; |
| 109 | 107 | ||
| 110 | lineno = 0; | 108 | lineno = 0; |
| 111 | bool more = true; | 109 | bool more = true; |
| @@ -170,8 +168,7 @@ QdfFixer::processLines(std::string const& input) | @@ -170,8 +168,7 @@ QdfFixer::processLines(std::string const& input) | ||
| 170 | // there are no object streams. | 168 | // there are no object streams. |
| 171 | int max_objects = 1; | 169 | int max_objects = 1; |
| 172 | for (auto const& e: xref) { | 170 | for (auto const& e: xref) { |
| 173 | - if ((e.getType() == 2) && | ||
| 174 | - (e.getObjStreamIndex() > max_objects)) { | 171 | + if ((e.getType() == 2) && (e.getObjStreamIndex() > max_objects)) { |
| 175 | max_objects = e.getObjStreamIndex(); | 172 | max_objects = e.getObjStreamIndex(); |
| 176 | } | 173 | } |
| 177 | } | 174 | } |
| @@ -183,8 +180,7 @@ QdfFixer::processLines(std::string const& input) | @@ -183,8 +180,7 @@ QdfFixer::processLines(std::string const& input) | ||
| 183 | xref_size = 1 + xref.size(); | 180 | xref_size = 1 + xref.size(); |
| 184 | auto length = xref_size * esize; | 181 | auto length = xref_size * esize; |
| 185 | std::cout << " /Length " << length << "\n" | 182 | std::cout << " /Length " << length << "\n" |
| 186 | - << " /W [ 1 " << xref_f1_nbytes << " " | ||
| 187 | - << xref_f2_nbytes << " ]" | 183 | + << " /W [ 1 " << xref_f1_nbytes << " " << xref_f2_nbytes << " ]" |
| 188 | << "\n"; | 184 | << "\n"; |
| 189 | state = st_in_xref_stream_dict; | 185 | state = st_in_xref_stream_dict; |
| 190 | } | 186 | } |
| @@ -224,8 +220,7 @@ QdfFixer::processLines(std::string const& input) | @@ -224,8 +220,7 @@ QdfFixer::processLines(std::string const& input) | ||
| 224 | state = st_in_obj; | 220 | state = st_in_obj; |
| 225 | } | 221 | } |
| 226 | } else if (state == st_in_xref_stream_dict) { | 222 | } else if (state == st_in_xref_stream_dict) { |
| 227 | - if ((line.find("/Length"sv) != line.npos) || | ||
| 228 | - (line.find("/W"sv) != line.npos)) { | 223 | + if ((line.find("/Length"sv) != line.npos) || (line.find("/W"sv) != line.npos)) { |
| 229 | // already printed | 224 | // already printed |
| 230 | } else if (line.find("/Size"sv) != line.npos) { | 225 | } else if (line.find("/Size"sv) != line.npos) { |
| 231 | auto xref_size = 1 + xref.size(); | 226 | auto xref_size = 1 + xref.size(); |
| @@ -274,9 +269,7 @@ QdfFixer::processLines(std::string const& input) | @@ -274,9 +269,7 @@ QdfFixer::processLines(std::string const& input) | ||
| 274 | std::cout << line; | 269 | std::cout << line; |
| 275 | } else if (state == st_in_length) { | 270 | } else if (state == st_in_length) { |
| 276 | if (!matches(re_num)) { | 271 | if (!matches(re_num)) { |
| 277 | - fatal( | ||
| 278 | - filename + ":" + std::to_string(lineno) + | ||
| 279 | - ": expected integer"); | 272 | + fatal(filename + ":" + std::to_string(lineno) + ": expected integer"); |
| 280 | } | 273 | } |
| 281 | std::string new_length = std::to_string(stream_length) + "\n"; | 274 | std::string new_length = std::to_string(stream_length) + "\n"; |
| 282 | offset -= QIntC::to_offset(line.length()); | 275 | offset -= QIntC::to_offset(line.length()); |
| @@ -287,8 +280,7 @@ QdfFixer::processLines(std::string const& input) | @@ -287,8 +280,7 @@ QdfFixer::processLines(std::string const& input) | ||
| 287 | auto n = xref.size(); | 280 | auto n = xref.size(); |
| 288 | std::cout << "0 " << 1 + n << "\n0000000000 65535 f \n"; | 281 | std::cout << "0 " << 1 + n << "\n0000000000 65535 f \n"; |
| 289 | for (auto const& e: xref) { | 282 | for (auto const& e: xref) { |
| 290 | - std::cout << QUtil::int_to_string(e.getOffset(), 10) | ||
| 291 | - << " 00000 n \n"; | 283 | + std::cout << QUtil::int_to_string(e.getOffset(), 10) << " 00000 n \n"; |
| 292 | } | 284 | } |
| 293 | state = st_before_trailer; | 285 | state = st_before_trailer; |
| 294 | } else if (state == st_before_trailer) { | 286 | } else if (state == st_before_trailer) { |
| @@ -376,8 +368,7 @@ void | @@ -376,8 +368,7 @@ void | ||
| 376 | QdfFixer::writeBinary(unsigned long long val, size_t bytes) | 368 | QdfFixer::writeBinary(unsigned long long val, size_t bytes) |
| 377 | { | 369 | { |
| 378 | if (bytes > sizeof(unsigned long long)) { | 370 | if (bytes > sizeof(unsigned long long)) { |
| 379 | - throw std::logic_error( | ||
| 380 | - "fix-qdf::writeBinary called with too many bytes"); | 371 | + throw std::logic_error("fix-qdf::writeBinary called with too many bytes"); |
| 381 | } | 372 | } |
| 382 | std::string data(bytes, '\0'); | 373 | std::string data(bytes, '\0'); |
| 383 | for (auto i = bytes; i > 0; --i) { | 374 | for (auto i = bytes; i > 0; --i) { |
| @@ -396,8 +387,7 @@ realmain(int argc, char* argv[]) | @@ -396,8 +387,7 @@ realmain(int argc, char* argv[]) | ||
| 396 | if (argc > 2) { | 387 | if (argc > 2) { |
| 397 | usage(); | 388 | usage(); |
| 398 | } else if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) { | 389 | } else if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) { |
| 399 | - std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() | ||
| 400 | - << std::endl; | 390 | + std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl; |
| 401 | return 0; | 391 | return 0; |
| 402 | } else if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { | 392 | } else if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { |
| 403 | usage(); | 393 | usage(); |
qpdf/pdf_from_scratch.cc
| @@ -38,17 +38,16 @@ runtest(int n) | @@ -38,17 +38,16 @@ runtest(int n) | ||
| 38 | if (n == 0) { | 38 | if (n == 0) { |
| 39 | // Create a minimal PDF from scratch. | 39 | // Create a minimal PDF from scratch. |
| 40 | 40 | ||
| 41 | - QPDFObjectHandle font = pdf.makeIndirectObject( | ||
| 42 | - QPDFObjectHandle::parse("<<" | ||
| 43 | - " /Type /Font" | ||
| 44 | - " /Subtype /Type1" | ||
| 45 | - " /Name /F1" | ||
| 46 | - " /BaseFont /Helvetica" | ||
| 47 | - " /Encoding /WinAnsiEncoding" | ||
| 48 | - ">>")); | ||
| 49 | - | ||
| 50 | - QPDFObjectHandle procset = | ||
| 51 | - pdf.makeIndirectObject(QPDFObjectHandle::parse("[/PDF /Text]")); | 41 | + QPDFObjectHandle font = |
| 42 | + pdf.makeIndirectObject(QPDFObjectHandle::parse("<<" | ||
| 43 | + " /Type /Font" | ||
| 44 | + " /Subtype /Type1" | ||
| 45 | + " /Name /F1" | ||
| 46 | + " /BaseFont /Helvetica" | ||
| 47 | + " /Encoding /WinAnsiEncoding" | ||
| 48 | + ">>")); | ||
| 49 | + | ||
| 50 | + QPDFObjectHandle procset = pdf.makeIndirectObject(QPDFObjectHandle::parse("[/PDF /Text]")); | ||
| 52 | 51 | ||
| 53 | QPDFObjectHandle contents = createPageContents(pdf, "First Page"); | 52 | QPDFObjectHandle contents = createPageContents(pdf, "First Page"); |
| 54 | 53 | ||
| @@ -61,8 +60,7 @@ runtest(int n) | @@ -61,8 +60,7 @@ runtest(int n) | ||
| 61 | resources.replaceKey("/ProcSet", procset); | 60 | resources.replaceKey("/ProcSet", procset); |
| 62 | resources.replaceKey("/Font", rfont); | 61 | resources.replaceKey("/Font", rfont); |
| 63 | 62 | ||
| 64 | - QPDFObjectHandle page = | ||
| 65 | - pdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); | 63 | + QPDFObjectHandle page = pdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); |
| 66 | page.replaceKey("/Type", newName("/Page")); | 64 | page.replaceKey("/Type", newName("/Page")); |
| 67 | page.replaceKey("/MediaBox", mediabox); | 65 | page.replaceKey("/MediaBox", mediabox); |
| 68 | page.replaceKey("/Contents", contents); | 66 | page.replaceKey("/Contents", contents); |
| @@ -75,8 +73,7 @@ runtest(int n) | @@ -75,8 +73,7 @@ runtest(int n) | ||
| 75 | w.setStreamDataMode(qpdf_s_preserve); | 73 | w.setStreamDataMode(qpdf_s_preserve); |
| 76 | w.write(); | 74 | w.write(); |
| 77 | } else { | 75 | } else { |
| 78 | - throw std::runtime_error( | ||
| 79 | - std::string("invalid test ") + std::to_string(n)); | 76 | + throw std::runtime_error(std::string("invalid test ") + std::to_string(n)); |
| 80 | } | 77 | } |
| 81 | 78 | ||
| 82 | std::cout << "test " << n << " done" << std::endl; | 79 | std::cout << "test " << n << " done" << std::endl; |
qpdf/qpdf-ctest.c
| @@ -25,12 +25,7 @@ safe_fopen(char const* filename, char const* mode) | @@ -25,12 +25,7 @@ safe_fopen(char const* filename, char const* mode) | ||
| 25 | #else | 25 | #else |
| 26 | f = fopen(filename, mode); | 26 | f = fopen(filename, mode); |
| 27 | if (f == NULL) { | 27 | if (f == NULL) { |
| 28 | - fprintf( | ||
| 29 | - stderr, | ||
| 30 | - "%s: unable to open %s: %s\n", | ||
| 31 | - whoami, | ||
| 32 | - filename, | ||
| 33 | - strerror(errno)); | 28 | + fprintf(stderr, "%s: unable to open %s: %s\n", whoami, filename, strerror(errno)); |
| 34 | exit(2); | 29 | exit(2); |
| 35 | } | 30 | } |
| 36 | #endif | 31 | #endif |
| @@ -105,20 +100,11 @@ read_file_into_memory(char const* filename, char** buf, unsigned long* size) | @@ -105,20 +100,11 @@ read_file_into_memory(char const* filename, char** buf, unsigned long* size) | ||
| 105 | } | 100 | } |
| 106 | if (bytes_read != *size) { | 101 | if (bytes_read != *size) { |
| 107 | if (ferror(f)) { | 102 | if (ferror(f)) { |
| 108 | - fprintf( | ||
| 109 | - stderr, | ||
| 110 | - "%s: failure reading file %s into memory:", | ||
| 111 | - whoami, | ||
| 112 | - filename); | 103 | + fprintf(stderr, "%s: failure reading file %s into memory:", whoami, filename); |
| 113 | } else { | 104 | } else { |
| 114 | - fprintf( | ||
| 115 | - stderr, "%s: premature EOF reading file %s:", whoami, filename); | 105 | + fprintf(stderr, "%s: premature EOF reading file %s:", whoami, filename); |
| 116 | } | 106 | } |
| 117 | - fprintf( | ||
| 118 | - stderr, | ||
| 119 | - " read %lu, wanted %lu\n", | ||
| 120 | - (unsigned long)bytes_read, | ||
| 121 | - (unsigned long)*size); | 107 | + fprintf(stderr, " read %lu, wanted %lu\n", (unsigned long)bytes_read, (unsigned long)*size); |
| 122 | exit(2); | 108 | exit(2); |
| 123 | } | 109 | } |
| 124 | fclose(f); | 110 | fclose(f); |
| @@ -147,11 +133,7 @@ custom_log(char const* data, size_t size, void* udata) | @@ -147,11 +133,7 @@ custom_log(char const* data, size_t size, void* udata) | ||
| 147 | } | 133 | } |
| 148 | 134 | ||
| 149 | static void | 135 | static void |
| 150 | -test01( | ||
| 151 | - char const* infile, | ||
| 152 | - char const* password, | ||
| 153 | - char const* outfile, | ||
| 154 | - char const* xarg) | 136 | +test01(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 155 | { | 137 | { |
| 156 | qpdf_read(qpdf, infile, password); | 138 | qpdf_read(qpdf, infile, password); |
| 157 | printf("version: %s\n", qpdf_get_pdf_version(qpdf)); | 139 | printf("version: %s\n", qpdf_get_pdf_version(qpdf)); |
| @@ -162,13 +144,11 @@ test01( | @@ -162,13 +144,11 @@ test01( | ||
| 162 | printf("encrypted: %d\n", qpdf_is_encrypted(qpdf)); | 144 | printf("encrypted: %d\n", qpdf_is_encrypted(qpdf)); |
| 163 | if (qpdf_is_encrypted(qpdf)) { | 145 | if (qpdf_is_encrypted(qpdf)) { |
| 164 | printf("user password: %s\n", qpdf_get_user_password(qpdf)); | 146 | printf("user password: %s\n", qpdf_get_user_password(qpdf)); |
| 165 | - printf( | ||
| 166 | - "extract for accessibility: %d\n", qpdf_allow_accessibility(qpdf)); | 147 | + printf("extract for accessibility: %d\n", qpdf_allow_accessibility(qpdf)); |
| 167 | printf("extract for any purpose: %d\n", qpdf_allow_extract_all(qpdf)); | 148 | printf("extract for any purpose: %d\n", qpdf_allow_extract_all(qpdf)); |
| 168 | printf("print low resolution: %d\n", qpdf_allow_print_low_res(qpdf)); | 149 | printf("print low resolution: %d\n", qpdf_allow_print_low_res(qpdf)); |
| 169 | printf("print high resolution: %d\n", qpdf_allow_print_high_res(qpdf)); | 150 | printf("print high resolution: %d\n", qpdf_allow_print_high_res(qpdf)); |
| 170 | - printf( | ||
| 171 | - "modify document assembly: %d\n", qpdf_allow_modify_assembly(qpdf)); | 151 | + printf("modify document assembly: %d\n", qpdf_allow_modify_assembly(qpdf)); |
| 172 | printf("modify forms: %d\n", qpdf_allow_modify_form(qpdf)); | 152 | printf("modify forms: %d\n", qpdf_allow_modify_form(qpdf)); |
| 173 | printf("modify annotations: %d\n", qpdf_allow_modify_annotation(qpdf)); | 153 | printf("modify annotations: %d\n", qpdf_allow_modify_annotation(qpdf)); |
| 174 | printf("modify other: %d\n", qpdf_allow_modify_other(qpdf)); | 154 | printf("modify other: %d\n", qpdf_allow_modify_other(qpdf)); |
| @@ -178,11 +158,7 @@ test01( | @@ -178,11 +158,7 @@ test01( | ||
| 178 | } | 158 | } |
| 179 | 159 | ||
| 180 | static void | 160 | static void |
| 181 | -test02( | ||
| 182 | - char const* infile, | ||
| 183 | - char const* password, | ||
| 184 | - char const* outfile, | ||
| 185 | - char const* xarg) | 161 | +test02(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 186 | { | 162 | { |
| 187 | qpdf_set_suppress_warnings(qpdf, QPDF_TRUE); | 163 | qpdf_set_suppress_warnings(qpdf, QPDF_TRUE); |
| 188 | if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && | 164 | if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && |
| @@ -194,11 +170,7 @@ test02( | @@ -194,11 +170,7 @@ test02( | ||
| 194 | } | 170 | } |
| 195 | 171 | ||
| 196 | static void | 172 | static void |
| 197 | -test03( | ||
| 198 | - char const* infile, | ||
| 199 | - char const* password, | ||
| 200 | - char const* outfile, | ||
| 201 | - char const* xarg) | 173 | +test03(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 202 | { | 174 | { |
| 203 | qpdf_read(qpdf, infile, password); | 175 | qpdf_read(qpdf, infile, password); |
| 204 | qpdf_init_write(qpdf, outfile); | 176 | qpdf_init_write(qpdf, outfile); |
| @@ -209,11 +181,7 @@ test03( | @@ -209,11 +181,7 @@ test03( | ||
| 209 | } | 181 | } |
| 210 | 182 | ||
| 211 | static void | 183 | static void |
| 212 | -test04( | ||
| 213 | - char const* infile, | ||
| 214 | - char const* password, | ||
| 215 | - char const* outfile, | ||
| 216 | - char const* xarg) | 184 | +test04(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 217 | { | 185 | { |
| 218 | qpdf_set_ignore_xref_streams(qpdf, QPDF_TRUE); | 186 | qpdf_set_ignore_xref_streams(qpdf, QPDF_TRUE); |
| 219 | qpdf_read(qpdf, infile, password); | 187 | qpdf_read(qpdf, infile, password); |
| @@ -224,11 +192,7 @@ test04( | @@ -224,11 +192,7 @@ test04( | ||
| 224 | } | 192 | } |
| 225 | 193 | ||
| 226 | static void | 194 | static void |
| 227 | -test05( | ||
| 228 | - char const* infile, | ||
| 229 | - char const* password, | ||
| 230 | - char const* outfile, | ||
| 231 | - char const* xarg) | 195 | +test05(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 232 | { | 196 | { |
| 233 | int count = 0; | 197 | int count = 0; |
| 234 | qpdf_read(qpdf, infile, password); | 198 | qpdf_read(qpdf, infile, password); |
| @@ -243,11 +207,7 @@ test05( | @@ -243,11 +207,7 @@ test05( | ||
| 243 | } | 207 | } |
| 244 | 208 | ||
| 245 | static void | 209 | static void |
| 246 | -test06( | ||
| 247 | - char const* infile, | ||
| 248 | - char const* password, | ||
| 249 | - char const* outfile, | ||
| 250 | - char const* xarg) | 210 | +test06(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 251 | { | 211 | { |
| 252 | char* buf = NULL; | 212 | char* buf = NULL; |
| 253 | unsigned long size = 0; | 213 | unsigned long size = 0; |
| @@ -262,11 +222,7 @@ test06( | @@ -262,11 +222,7 @@ test06( | ||
| 262 | } | 222 | } |
| 263 | 223 | ||
| 264 | static void | 224 | static void |
| 265 | -test07( | ||
| 266 | - char const* infile, | ||
| 267 | - char const* password, | ||
| 268 | - char const* outfile, | ||
| 269 | - char const* xarg) | 225 | +test07(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 270 | { | 226 | { |
| 271 | qpdf_read(qpdf, infile, password); | 227 | qpdf_read(qpdf, infile, password); |
| 272 | qpdf_init_write(qpdf, outfile); | 228 | qpdf_init_write(qpdf, outfile); |
| @@ -277,11 +233,7 @@ test07( | @@ -277,11 +233,7 @@ test07( | ||
| 277 | } | 233 | } |
| 278 | 234 | ||
| 279 | static void | 235 | static void |
| 280 | -test08( | ||
| 281 | - char const* infile, | ||
| 282 | - char const* password, | ||
| 283 | - char const* outfile, | ||
| 284 | - char const* xarg) | 236 | +test08(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 285 | { | 237 | { |
| 286 | qpdf_read(qpdf, infile, password); | 238 | qpdf_read(qpdf, infile, password); |
| 287 | qpdf_init_write(qpdf, outfile); | 239 | qpdf_init_write(qpdf, outfile); |
| @@ -293,11 +245,7 @@ test08( | @@ -293,11 +245,7 @@ test08( | ||
| 293 | } | 245 | } |
| 294 | 246 | ||
| 295 | static void | 247 | static void |
| 296 | -test09( | ||
| 297 | - char const* infile, | ||
| 298 | - char const* password, | ||
| 299 | - char const* outfile, | ||
| 300 | - char const* xarg) | 248 | +test09(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 301 | { | 249 | { |
| 302 | qpdf_read(qpdf, infile, password); | 250 | qpdf_read(qpdf, infile, password); |
| 303 | qpdf_init_write(qpdf, outfile); | 251 | qpdf_init_write(qpdf, outfile); |
| @@ -308,11 +256,7 @@ test09( | @@ -308,11 +256,7 @@ test09( | ||
| 308 | } | 256 | } |
| 309 | 257 | ||
| 310 | static void | 258 | static void |
| 311 | -test10( | ||
| 312 | - char const* infile, | ||
| 313 | - char const* password, | ||
| 314 | - char const* outfile, | ||
| 315 | - char const* xarg) | 259 | +test10(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 316 | { | 260 | { |
| 317 | qpdf_set_attempt_recovery(qpdf, QPDF_FALSE); | 261 | qpdf_set_attempt_recovery(qpdf, QPDF_FALSE); |
| 318 | qpdf_read(qpdf, infile, password); | 262 | qpdf_read(qpdf, infile, password); |
| @@ -320,11 +264,7 @@ test10( | @@ -320,11 +264,7 @@ test10( | ||
| 320 | } | 264 | } |
| 321 | 265 | ||
| 322 | static void | 266 | static void |
| 323 | -test11( | ||
| 324 | - char const* infile, | ||
| 325 | - char const* password, | ||
| 326 | - char const* outfile, | ||
| 327 | - char const* xarg) | 267 | +test11(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 328 | { | 268 | { |
| 329 | qpdf_read(qpdf, infile, password); | 269 | qpdf_read(qpdf, infile, password); |
| 330 | qpdf_init_write(qpdf, outfile); | 270 | qpdf_init_write(qpdf, outfile); |
| @@ -336,11 +276,7 @@ test11( | @@ -336,11 +276,7 @@ test11( | ||
| 336 | } | 276 | } |
| 337 | 277 | ||
| 338 | static void | 278 | static void |
| 339 | -test12( | ||
| 340 | - char const* infile, | ||
| 341 | - char const* password, | ||
| 342 | - char const* outfile, | ||
| 343 | - char const* xarg) | 279 | +test12(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 344 | { | 280 | { |
| 345 | qpdf_read(qpdf, infile, password); | 281 | qpdf_read(qpdf, infile, password); |
| 346 | qpdf_init_write(qpdf, outfile); | 282 | qpdf_init_write(qpdf, outfile); |
| @@ -361,11 +297,7 @@ test12( | @@ -361,11 +297,7 @@ test12( | ||
| 361 | } | 297 | } |
| 362 | 298 | ||
| 363 | static void | 299 | static void |
| 364 | -test13( | ||
| 365 | - char const* infile, | ||
| 366 | - char const* password, | ||
| 367 | - char const* outfile, | ||
| 368 | - char const* xarg) | 300 | +test13(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 369 | { | 301 | { |
| 370 | qpdf_read(qpdf, infile, password); | 302 | qpdf_read(qpdf, infile, password); |
| 371 | printf("user password: %s\n", qpdf_get_user_password(qpdf)); | 303 | printf("user password: %s\n", qpdf_get_user_password(qpdf)); |
| @@ -377,11 +309,7 @@ test13( | @@ -377,11 +309,7 @@ test13( | ||
| 377 | } | 309 | } |
| 378 | 310 | ||
| 379 | static void | 311 | static void |
| 380 | -test14( | ||
| 381 | - char const* infile, | ||
| 382 | - char const* password, | ||
| 383 | - char const* outfile, | ||
| 384 | - char const* xarg) | 312 | +test14(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 385 | { | 313 | { |
| 386 | qpdf_read(qpdf, infile, password); | 314 | qpdf_read(qpdf, infile, password); |
| 387 | qpdf_init_write(qpdf, outfile); | 315 | qpdf_init_write(qpdf, outfile); |
| @@ -396,11 +324,7 @@ test14( | @@ -396,11 +324,7 @@ test14( | ||
| 396 | } | 324 | } |
| 397 | 325 | ||
| 398 | static void | 326 | static void |
| 399 | -test15( | ||
| 400 | - char const* infile, | ||
| 401 | - char const* password, | ||
| 402 | - char const* outfile, | ||
| 403 | - char const* xarg) | 327 | +test15(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 404 | { | 328 | { |
| 405 | qpdf_read(qpdf, infile, password); | 329 | qpdf_read(qpdf, infile, password); |
| 406 | qpdf_init_write(qpdf, outfile); | 330 | qpdf_init_write(qpdf, outfile); |
| @@ -431,11 +355,7 @@ print_info(char const* key) | @@ -431,11 +355,7 @@ print_info(char const* key) | ||
| 431 | } | 355 | } |
| 432 | 356 | ||
| 433 | static void | 357 | static void |
| 434 | -test16( | ||
| 435 | - char const* infile, | ||
| 436 | - char const* password, | ||
| 437 | - char const* outfile, | ||
| 438 | - char const* xarg) | 358 | +test16(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 439 | { | 359 | { |
| 440 | unsigned long buflen = 0L; | 360 | unsigned long buflen = 0L; |
| 441 | unsigned char const* buf = 0; | 361 | unsigned char const* buf = 0; |
| @@ -465,11 +385,7 @@ test16( | @@ -465,11 +385,7 @@ test16( | ||
| 465 | } | 385 | } |
| 466 | 386 | ||
| 467 | static void | 387 | static void |
| 468 | -test17( | ||
| 469 | - char const* infile, | ||
| 470 | - char const* password, | ||
| 471 | - char const* outfile, | ||
| 472 | - char const* xarg) | 388 | +test17(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 473 | { | 389 | { |
| 474 | qpdf_read(qpdf, infile, password); | 390 | qpdf_read(qpdf, infile, password); |
| 475 | qpdf_init_write(qpdf, outfile); | 391 | qpdf_init_write(qpdf, outfile); |
| @@ -492,11 +408,7 @@ test17( | @@ -492,11 +408,7 @@ test17( | ||
| 492 | } | 408 | } |
| 493 | 409 | ||
| 494 | static void | 410 | static void |
| 495 | -test18( | ||
| 496 | - char const* infile, | ||
| 497 | - char const* password, | ||
| 498 | - char const* outfile, | ||
| 499 | - char const* xarg) | 411 | +test18(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 500 | { | 412 | { |
| 501 | qpdf_read(qpdf, infile, password); | 413 | qpdf_read(qpdf, infile, password); |
| 502 | qpdf_init_write(qpdf, outfile); | 414 | qpdf_init_write(qpdf, outfile); |
| @@ -519,11 +431,7 @@ test18( | @@ -519,11 +431,7 @@ test18( | ||
| 519 | } | 431 | } |
| 520 | 432 | ||
| 521 | static void | 433 | static void |
| 522 | -test19( | ||
| 523 | - char const* infile, | ||
| 524 | - char const* password, | ||
| 525 | - char const* outfile, | ||
| 526 | - char const* xarg) | 434 | +test19(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 527 | { | 435 | { |
| 528 | qpdf_read(qpdf, infile, password); | 436 | qpdf_read(qpdf, infile, password); |
| 529 | qpdf_init_write(qpdf, outfile); | 437 | qpdf_init_write(qpdf, outfile); |
| @@ -533,11 +441,7 @@ test19( | @@ -533,11 +441,7 @@ test19( | ||
| 533 | } | 441 | } |
| 534 | 442 | ||
| 535 | static void | 443 | static void |
| 536 | -test20( | ||
| 537 | - char const* infile, | ||
| 538 | - char const* password, | ||
| 539 | - char const* outfile, | ||
| 540 | - char const* xarg) | 444 | +test20(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 541 | { | 445 | { |
| 542 | qpdf_read(qpdf, infile, password); | 446 | qpdf_read(qpdf, infile, password); |
| 543 | qpdf_init_write(qpdf, outfile); | 447 | qpdf_init_write(qpdf, outfile); |
| @@ -550,11 +454,7 @@ test20( | @@ -550,11 +454,7 @@ test20( | ||
| 550 | } | 454 | } |
| 551 | 455 | ||
| 552 | static void | 456 | static void |
| 553 | -test21( | ||
| 554 | - char const* infile, | ||
| 555 | - char const* password, | ||
| 556 | - char const* outfile, | ||
| 557 | - char const* xarg) | 457 | +test21(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 558 | { | 458 | { |
| 559 | qpdf_read(qpdf, infile, password); | 459 | qpdf_read(qpdf, infile, password); |
| 560 | qpdf_init_write(qpdf, outfile); | 460 | qpdf_init_write(qpdf, outfile); |
| @@ -566,11 +466,7 @@ test21( | @@ -566,11 +466,7 @@ test21( | ||
| 566 | } | 466 | } |
| 567 | 467 | ||
| 568 | static void | 468 | static void |
| 569 | -test22( | ||
| 570 | - char const* infile, | ||
| 571 | - char const* password, | ||
| 572 | - char const* outfile, | ||
| 573 | - char const* xarg) | 469 | +test22(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 574 | { | 470 | { |
| 575 | qpdf_read(qpdf, infile, password); | 471 | qpdf_read(qpdf, infile, password); |
| 576 | qpdf_init_write(qpdf, outfile); | 472 | qpdf_init_write(qpdf, outfile); |
| @@ -583,11 +479,7 @@ test22( | @@ -583,11 +479,7 @@ test22( | ||
| 583 | } | 479 | } |
| 584 | 480 | ||
| 585 | static void | 481 | static void |
| 586 | -test23( | ||
| 587 | - char const* infile, | ||
| 588 | - char const* password, | ||
| 589 | - char const* outfile, | ||
| 590 | - char const* xarg) | 482 | +test23(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 591 | { | 483 | { |
| 592 | /* Test check and also exercise custom logger */ | 484 | /* Test check and also exercise custom logger */ |
| 593 | qpdflogger_handle l1 = qpdf_get_logger(qpdf); | 485 | qpdflogger_handle l1 = qpdf_get_logger(qpdf); |
| @@ -611,11 +503,7 @@ test23( | @@ -611,11 +503,7 @@ test23( | ||
| 611 | } | 503 | } |
| 612 | 504 | ||
| 613 | static void | 505 | static void |
| 614 | -test24( | ||
| 615 | - char const* infile, | ||
| 616 | - char const* password, | ||
| 617 | - char const* outfile, | ||
| 618 | - char const* xarg) | 506 | +test24(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 619 | { | 507 | { |
| 620 | /* This test case is designed for minimal.pdf. Pull objects out of | 508 | /* This test case is designed for minimal.pdf. Pull objects out of |
| 621 | * minimal.pdf to make sure all our accessors work as expected. | 509 | * minimal.pdf to make sure all our accessors work as expected. |
| @@ -630,9 +518,7 @@ test24( | @@ -630,9 +518,7 @@ test24( | ||
| 630 | qpdf_oh root = qpdf_get_root(qpdf); | 518 | qpdf_oh root = qpdf_get_root(qpdf); |
| 631 | assert(qpdf_oh_get_generation(qpdf, root) == 0); | 519 | assert(qpdf_oh_get_generation(qpdf, root) == 0); |
| 632 | qpdf_oh root_from_trailer = qpdf_oh_get_key(qpdf, trailer, "/Root"); | 520 | qpdf_oh root_from_trailer = qpdf_oh_get_key(qpdf, trailer, "/Root"); |
| 633 | - assert( | ||
| 634 | - qpdf_oh_get_object_id(qpdf, root) == | ||
| 635 | - qpdf_oh_get_object_id(qpdf, root_from_trailer)); | 521 | + assert(qpdf_oh_get_object_id(qpdf, root) == qpdf_oh_get_object_id(qpdf, root_from_trailer)); |
| 636 | 522 | ||
| 637 | /* Go to the first page and look at all the keys */ | 523 | /* Go to the first page and look at all the keys */ |
| 638 | qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages"); | 524 | qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages"); |
| @@ -686,8 +572,7 @@ test24( | @@ -686,8 +572,7 @@ test24( | ||
| 686 | qpdf, | 572 | qpdf, |
| 687 | qpdf_oh_get_key( | 573 | qpdf_oh_get_key( |
| 688 | qpdf, | 574 | qpdf, |
| 689 | - qpdf_oh_get_key( | ||
| 690 | - qpdf, qpdf_oh_get_key(qpdf, page1, "/Resources"), "/Font"), | 575 | + qpdf_oh_get_key(qpdf, qpdf_oh_get_key(qpdf, page1, "/Resources"), "/Font"), |
| 691 | "/F1"), | 576 | "/F1"), |
| 692 | "/Encoding"); | 577 | "/Encoding"); |
| 693 | assert(strcmp(qpdf_oh_get_name(qpdf, encoding), "/WinAnsiEncoding") == 0); | 578 | assert(strcmp(qpdf_oh_get_name(qpdf, encoding), "/WinAnsiEncoding") == 0); |
| @@ -698,8 +583,7 @@ test24( | @@ -698,8 +583,7 @@ test24( | ||
| 698 | while (qpdf_more_warnings(qpdf)) { | 583 | while (qpdf_more_warnings(qpdf)) { |
| 699 | qpdf_next_warning(qpdf); | 584 | qpdf_next_warning(qpdf); |
| 700 | } | 585 | } |
| 701 | - res = qpdf_oh_get_key_if_dict( | ||
| 702 | - qpdf, qpdf_oh_get_key_if_dict(qpdf, page1, "/Missing"), "/Font"); | 586 | + res = qpdf_oh_get_key_if_dict(qpdf, qpdf_oh_get_key_if_dict(qpdf, page1, "/Missing"), "/Font"); |
| 703 | assert(!qpdf_more_warnings(qpdf)); | 587 | assert(!qpdf_more_warnings(qpdf)); |
| 704 | 588 | ||
| 705 | /* Look at page contents to exercise stream functions */ | 589 | /* Look at page contents to exercise stream functions */ |
| @@ -713,31 +597,26 @@ test24( | @@ -713,31 +597,26 @@ test24( | ||
| 713 | qpdf_oh contents_length = qpdf_oh_get_key(qpdf, contents_dict, "/Length"); | 597 | qpdf_oh contents_length = qpdf_oh_get_key(qpdf, contents_dict, "/Length"); |
| 714 | assert(qpdf_oh_is_integer(qpdf, contents_length)); | 598 | assert(qpdf_oh_is_integer(qpdf, contents_length)); |
| 715 | assert(qpdf_oh_get_type_code(qpdf, contents_length) == ot_integer); | 599 | assert(qpdf_oh_get_type_code(qpdf, contents_length) == ot_integer); |
| 716 | - assert( | ||
| 717 | - strcmp(qpdf_oh_get_type_name(qpdf, contents_length), "integer") == 0); | 600 | + assert(strcmp(qpdf_oh_get_type_name(qpdf, contents_length), "integer") == 0); |
| 718 | assert(qpdf_oh_is_scalar(qpdf, contents_length)); | 601 | assert(qpdf_oh_is_scalar(qpdf, contents_length)); |
| 719 | assert(qpdf_oh_is_number(qpdf, contents_length)); | 602 | assert(qpdf_oh_is_number(qpdf, contents_length)); |
| 720 | qpdf_oh contents_array = qpdf_oh_wrap_in_array(qpdf, contents); | 603 | qpdf_oh contents_array = qpdf_oh_wrap_in_array(qpdf, contents); |
| 721 | assert(qpdf_oh_get_array_n_items(qpdf, contents_array) == 1); | 604 | assert(qpdf_oh_get_array_n_items(qpdf, contents_array) == 1); |
| 722 | assert( | 605 | assert( |
| 723 | - qpdf_oh_get_object_id( | ||
| 724 | - qpdf, qpdf_oh_get_array_item(qpdf, contents_array, 0)) == | 606 | + qpdf_oh_get_object_id(qpdf, qpdf_oh_get_array_item(qpdf, contents_array, 0)) == |
| 725 | qpdf_oh_get_object_id(qpdf, contents)); | 607 | qpdf_oh_get_object_id(qpdf, contents)); |
| 726 | /* Wrap in array for a non-trivial case */ | 608 | /* Wrap in array for a non-trivial case */ |
| 727 | - qpdf_oh wrapped_contents_array = | ||
| 728 | - qpdf_oh_wrap_in_array(qpdf, contents_array); | 609 | + qpdf_oh wrapped_contents_array = qpdf_oh_wrap_in_array(qpdf, contents_array); |
| 729 | assert(qpdf_oh_get_array_n_items(qpdf, wrapped_contents_array) == 1); | 610 | assert(qpdf_oh_get_array_n_items(qpdf, wrapped_contents_array) == 1); |
| 730 | assert( | 611 | assert( |
| 731 | - qpdf_oh_get_object_id( | ||
| 732 | - qpdf, qpdf_oh_get_array_item(qpdf, wrapped_contents_array, 0)) == | 612 | + qpdf_oh_get_object_id(qpdf, qpdf_oh_get_array_item(qpdf, wrapped_contents_array, 0)) == |
| 733 | qpdf_oh_get_object_id(qpdf, contents)); | 613 | qpdf_oh_get_object_id(qpdf, contents)); |
| 734 | 614 | ||
| 735 | /* Exercise functions that work with indirect objects */ | 615 | /* Exercise functions that work with indirect objects */ |
| 736 | qpdf_oh resources = qpdf_oh_get_key(qpdf, page1, "/Resources"); | 616 | qpdf_oh resources = qpdf_oh_get_key(qpdf, page1, "/Resources"); |
| 737 | qpdf_oh procset = qpdf_oh_get_key(qpdf, resources, "/ProcSet"); | 617 | qpdf_oh procset = qpdf_oh_get_key(qpdf, resources, "/ProcSet"); |
| 738 | assert(strcmp(qpdf_oh_unparse(qpdf, procset), "5 0 R") == 0); | 618 | assert(strcmp(qpdf_oh_unparse(qpdf, procset), "5 0 R") == 0); |
| 739 | - assert( | ||
| 740 | - strcmp(qpdf_oh_unparse_resolved(qpdf, procset), "[ /PDF /Text ]") == 0); | 619 | + assert(strcmp(qpdf_oh_unparse_resolved(qpdf, procset), "[ /PDF /Text ]") == 0); |
| 741 | qpdf_oh_make_direct(qpdf, procset); | 620 | qpdf_oh_make_direct(qpdf, procset); |
| 742 | assert(strcmp(qpdf_oh_unparse(qpdf, procset), "[ /PDF /Text ]") == 0); | 621 | assert(strcmp(qpdf_oh_unparse(qpdf, procset), "[ /PDF /Text ]") == 0); |
| 743 | /* The replaced /ProcSet can be seen to be a direct object in the | 622 | /* The replaced /ProcSet can be seen to be a direct object in the |
| @@ -774,19 +653,15 @@ test24( | @@ -774,19 +653,15 @@ test24( | ||
| 774 | } | 653 | } |
| 775 | 654 | ||
| 776 | static void | 655 | static void |
| 777 | -test25( | ||
| 778 | - char const* infile, | ||
| 779 | - char const* password, | ||
| 780 | - char const* outfile, | ||
| 781 | - char const* xarg) | 656 | +test25(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 782 | { | 657 | { |
| 783 | /* This test case is designed for minimal.pdf. */ | 658 | /* This test case is designed for minimal.pdf. */ |
| 784 | qpdf_read(qpdf, infile, password); | 659 | qpdf_read(qpdf, infile, password); |
| 785 | qpdf_oh root = qpdf_get_root(qpdf); | 660 | qpdf_oh root = qpdf_get_root(qpdf); |
| 786 | 661 | ||
| 787 | /* Parse objects from a string */ | 662 | /* Parse objects from a string */ |
| 788 | - qpdf_oh parsed = qpdf_oh_parse( | ||
| 789 | - qpdf, "[ 1 2.0 (3\xf7) << /Four [/Five] >> null true false /Six]"); | 663 | + qpdf_oh parsed = |
| 664 | + qpdf_oh_parse(qpdf, "[ 1 2.0 (3\xf7) << /Four [/Five] >> null true false /Six]"); | ||
| 790 | qpdf_oh p_int = qpdf_oh_get_array_item(qpdf, parsed, 0); | 665 | qpdf_oh p_int = qpdf_oh_get_array_item(qpdf, parsed, 0); |
| 791 | qpdf_oh p_real = qpdf_oh_get_array_item(qpdf, parsed, 1); | 666 | qpdf_oh p_real = qpdf_oh_get_array_item(qpdf, parsed, 1); |
| 792 | qpdf_oh p_string = qpdf_oh_get_array_item(qpdf, parsed, 2); | 667 | qpdf_oh p_string = qpdf_oh_get_array_item(qpdf, parsed, 2); |
| @@ -795,32 +670,24 @@ test25( | @@ -795,32 +670,24 @@ test25( | ||
| 795 | qpdf_oh p_bool = qpdf_oh_get_array_item(qpdf, parsed, 5); | 670 | qpdf_oh p_bool = qpdf_oh_get_array_item(qpdf, parsed, 5); |
| 796 | qpdf_oh p_bool_f = qpdf_oh_get_array_item(qpdf, parsed, 6); | 671 | qpdf_oh p_bool_f = qpdf_oh_get_array_item(qpdf, parsed, 6); |
| 797 | qpdf_oh p_name = qpdf_oh_get_array_item(qpdf, parsed, 7); | 672 | qpdf_oh p_name = qpdf_oh_get_array_item(qpdf, parsed, 7); |
| 798 | - assert( | ||
| 799 | - qpdf_oh_is_integer(qpdf, p_int) && | ||
| 800 | - qpdf_oh_get_int_value_as_int(qpdf, p_int) == 1); | 673 | + assert(qpdf_oh_is_integer(qpdf, p_int) && qpdf_oh_get_int_value_as_int(qpdf, p_int) == 1); |
| 801 | long long l = 0; | 674 | long long l = 0; |
| 802 | assert(qpdf_oh_get_value_as_longlong(qpdf, p_bool, &l) == QPDF_FALSE); | 675 | assert(qpdf_oh_get_value_as_longlong(qpdf, p_bool, &l) == QPDF_FALSE); |
| 803 | - assert( | ||
| 804 | - (qpdf_oh_get_value_as_longlong(qpdf, p_int, &l) == QPDF_TRUE) && | ||
| 805 | - (l == 1)); | 676 | + assert((qpdf_oh_get_value_as_longlong(qpdf, p_int, &l) == QPDF_TRUE) && (l == 1)); |
| 806 | int i = 0; | 677 | int i = 0; |
| 807 | assert(qpdf_oh_get_value_as_int(qpdf, p_bool, &i) == QPDF_FALSE); | 678 | assert(qpdf_oh_get_value_as_int(qpdf, p_bool, &i) == QPDF_FALSE); |
| 808 | - assert( | ||
| 809 | - (qpdf_oh_get_value_as_int(qpdf, p_int, &i) == QPDF_TRUE) && (i == 1)); | 679 | + assert((qpdf_oh_get_value_as_int(qpdf, p_int, &i) == QPDF_TRUE) && (i == 1)); |
| 810 | unsigned long long ul = 0u; | 680 | unsigned long long ul = 0u; |
| 811 | assert(qpdf_oh_get_value_as_ulonglong(qpdf, p_bool, &ul) == QPDF_FALSE); | 681 | assert(qpdf_oh_get_value_as_ulonglong(qpdf, p_bool, &ul) == QPDF_FALSE); |
| 812 | - assert( | ||
| 813 | - (qpdf_oh_get_value_as_ulonglong(qpdf, p_int, &ul) == QPDF_TRUE) && | ||
| 814 | - (ul == 1u)); | 682 | + assert((qpdf_oh_get_value_as_ulonglong(qpdf, p_int, &ul) == QPDF_TRUE) && (ul == 1u)); |
| 815 | unsigned int u = 0u; | 683 | unsigned int u = 0u; |
| 816 | assert(qpdf_oh_get_value_as_uint(qpdf, p_bool, &u) == QPDF_FALSE); | 684 | assert(qpdf_oh_get_value_as_uint(qpdf, p_bool, &u) == QPDF_FALSE); |
| 817 | - assert( | ||
| 818 | - (qpdf_oh_get_value_as_uint(qpdf, p_int, &u) == QPDF_TRUE) && (u == 1u)); | 685 | + assert((qpdf_oh_get_value_as_uint(qpdf, p_int, &u) == QPDF_TRUE) && (u == 1u)); |
| 819 | double d = 0.0; | 686 | double d = 0.0; |
| 820 | assert(qpdf_oh_get_value_as_number(qpdf, p_bool, &d) == QPDF_FALSE); | 687 | assert(qpdf_oh_get_value_as_number(qpdf, p_bool, &d) == QPDF_FALSE); |
| 821 | assert( | 688 | assert( |
| 822 | - (qpdf_oh_get_value_as_number(qpdf, p_int, &d) == QPDF_TRUE) && | ||
| 823 | - ((d - 1.0) < 1e-6) && ((d - 1.0) > -1e-6)); | 689 | + (qpdf_oh_get_value_as_number(qpdf, p_int, &d) == QPDF_TRUE) && ((d - 1.0) < 1e-6) && |
| 690 | + ((d - 1.0) > -1e-6)); | ||
| 824 | assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer); | 691 | assert(qpdf_oh_get_type_code(qpdf, p_int) == ot_integer); |
| 825 | assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0); | 692 | assert(strcmp(qpdf_oh_get_type_name(qpdf, p_int), "integer") == 0); |
| 826 | assert( | 693 | assert( |
| @@ -845,22 +712,18 @@ test25( | @@ -845,22 +712,18 @@ test25( | ||
| 845 | const char* str = ""; | 712 | const char* str = ""; |
| 846 | length = 0; | 713 | length = 0; |
| 847 | assert( | 714 | assert( |
| 848 | - (qpdf_oh_get_value_as_string(qpdf, p_name, &str, &length) == | ||
| 849 | - QPDF_FALSE) && | 715 | + (qpdf_oh_get_value_as_string(qpdf, p_name, &str, &length) == QPDF_FALSE) && |
| 850 | (strcmp(str, "") == 0) && (length == 0)); | 716 | (strcmp(str, "") == 0) && (length == 0)); |
| 851 | assert( | 717 | assert( |
| 852 | - (qpdf_oh_get_value_as_string(qpdf, p_string, &str, &length) == | ||
| 853 | - QPDF_TRUE) && | 718 | + (qpdf_oh_get_value_as_string(qpdf, p_string, &str, &length) == QPDF_TRUE) && |
| 854 | (strcmp(str, "3\xf7") == 0) && (length == 2)); | 719 | (strcmp(str, "3\xf7") == 0) && (length == 2)); |
| 855 | const char* utf8 = ""; | 720 | const char* utf8 = ""; |
| 856 | length = 0; | 721 | length = 0; |
| 857 | assert( | 722 | assert( |
| 858 | - (qpdf_oh_get_value_as_utf8(qpdf, p_name, &utf8, &length) == | ||
| 859 | - QPDF_FALSE) && | 723 | + (qpdf_oh_get_value_as_utf8(qpdf, p_name, &utf8, &length) == QPDF_FALSE) && |
| 860 | (strcmp(utf8, "") == 0) && (length == 0)); | 724 | (strcmp(utf8, "") == 0) && (length == 0)); |
| 861 | assert( | 725 | assert( |
| 862 | - (qpdf_oh_get_value_as_utf8(qpdf, p_string, &utf8, &length) == | ||
| 863 | - QPDF_TRUE) && | 726 | + (qpdf_oh_get_value_as_utf8(qpdf, p_string, &utf8, &length) == QPDF_TRUE) && |
| 864 | (strcmp(utf8, "3\xc3\xb7") == 0) && (length == 3)); | 727 | (strcmp(utf8, "3\xc3\xb7") == 0) && (length == 3)); |
| 865 | assert(qpdf_oh_get_type_code(qpdf, p_string) == ot_string); | 728 | assert(qpdf_oh_get_type_code(qpdf, p_string) == ot_string); |
| 866 | assert(!qpdf_oh_is_name_and_equals(qpdf, p_string, "3\xf7")); | 729 | assert(!qpdf_oh_is_name_and_equals(qpdf, p_string, "3\xf7")); |
| @@ -869,33 +732,22 @@ test25( | @@ -869,33 +732,22 @@ test25( | ||
| 869 | qpdf_oh p_five = qpdf_oh_get_key(qpdf, p_dict, "/Four"); | 732 | qpdf_oh p_five = qpdf_oh_get_key(qpdf, p_dict, "/Four"); |
| 870 | assert(qpdf_oh_is_or_has_name(qpdf, p_five, "/Five")); | 733 | assert(qpdf_oh_is_or_has_name(qpdf, p_five, "/Five")); |
| 871 | assert(!qpdf_oh_is_name_and_equals(qpdf, p_five, "/Five")); | 734 | assert(!qpdf_oh_is_name_and_equals(qpdf, p_five, "/Five")); |
| 872 | - assert(qpdf_oh_is_or_has_name( | ||
| 873 | - qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five")); | ||
| 874 | - assert(qpdf_oh_is_name_and_equals( | ||
| 875 | - qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five")); | 735 | + assert(qpdf_oh_is_or_has_name(qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five")); |
| 736 | + assert(qpdf_oh_is_name_and_equals(qpdf, qpdf_oh_get_array_item(qpdf, p_five, 0), "/Five")); | ||
| 876 | assert(qpdf_oh_is_null(qpdf, p_null)); | 737 | assert(qpdf_oh_is_null(qpdf, p_null)); |
| 877 | assert(qpdf_oh_get_type_code(qpdf, p_null) == ot_null); | 738 | assert(qpdf_oh_get_type_code(qpdf, p_null) == ot_null); |
| 878 | assert(strcmp(qpdf_oh_get_type_name(qpdf, p_null), "null") == 0); | 739 | assert(strcmp(qpdf_oh_get_type_name(qpdf, p_null), "null") == 0); |
| 879 | - assert( | ||
| 880 | - qpdf_oh_is_bool(qpdf, p_bool) && | ||
| 881 | - (qpdf_oh_get_bool_value(qpdf, p_bool) == QPDF_TRUE)); | 740 | + assert(qpdf_oh_is_bool(qpdf, p_bool) && (qpdf_oh_get_bool_value(qpdf, p_bool) == QPDF_TRUE)); |
| 882 | QPDF_BOOL b = QPDF_FALSE; | 741 | QPDF_BOOL b = QPDF_FALSE; |
| 883 | - assert( | ||
| 884 | - (qpdf_oh_get_value_as_bool(qpdf, p_int, &b) == QPDF_FALSE) && | ||
| 885 | - b == QPDF_FALSE); | ||
| 886 | - assert( | ||
| 887 | - (qpdf_oh_get_value_as_bool(qpdf, p_bool, &b) == QPDF_TRUE) && | ||
| 888 | - b == QPDF_TRUE); | ||
| 889 | - assert( | ||
| 890 | - (qpdf_oh_get_value_as_bool(qpdf, p_bool_f, &b) == QPDF_TRUE) && | ||
| 891 | - b == QPDF_FALSE); | 742 | + assert((qpdf_oh_get_value_as_bool(qpdf, p_int, &b) == QPDF_FALSE) && b == QPDF_FALSE); |
| 743 | + assert((qpdf_oh_get_value_as_bool(qpdf, p_bool, &b) == QPDF_TRUE) && b == QPDF_TRUE); | ||
| 744 | + assert((qpdf_oh_get_value_as_bool(qpdf, p_bool_f, &b) == QPDF_TRUE) && b == QPDF_FALSE); | ||
| 892 | assert(qpdf_oh_get_type_code(qpdf, p_bool) == ot_boolean); | 745 | assert(qpdf_oh_get_type_code(qpdf, p_bool) == ot_boolean); |
| 893 | assert(strcmp(qpdf_oh_get_type_name(qpdf, p_bool), "boolean") == 0); | 746 | assert(strcmp(qpdf_oh_get_type_name(qpdf, p_bool), "boolean") == 0); |
| 894 | const char* n = ""; | 747 | const char* n = ""; |
| 895 | length = 0; | 748 | length = 0; |
| 896 | assert( | 749 | assert( |
| 897 | - (qpdf_oh_get_value_as_name(qpdf, p_string, &n, &length) == | ||
| 898 | - QPDF_FALSE) && | 750 | + (qpdf_oh_get_value_as_name(qpdf, p_string, &n, &length) == QPDF_FALSE) && |
| 899 | (strcmp(n, "") == 0) && (length == 0)); | 751 | (strcmp(n, "") == 0) && (length == 0)); |
| 900 | assert( | 752 | assert( |
| 901 | (qpdf_oh_get_value_as_name(qpdf, p_name, &n, &length) == QPDF_TRUE) && | 753 | (qpdf_oh_get_value_as_name(qpdf, p_name, &n, &length) == QPDF_TRUE) && |
| @@ -905,8 +757,7 @@ test25( | @@ -905,8 +757,7 @@ test25( | ||
| 905 | qpdf, | 757 | qpdf, |
| 906 | parsed, | 758 | parsed, |
| 907 | 2, | 759 | 2, |
| 908 | - qpdf_oh_parse( | ||
| 909 | - qpdf, "<</A 1 /B 2 /C 3 /D 4 /Type /Test /Subtype /Marvin>>")); | 760 | + qpdf_oh_parse(qpdf, "<</A 1 /B 2 /C 3 /D 4 /Type /Test /Subtype /Marvin>>")); |
| 910 | qpdf_oh new_dict = qpdf_oh_get_array_item(qpdf, parsed, 2); | 761 | qpdf_oh new_dict = qpdf_oh_get_array_item(qpdf, parsed, 2); |
| 911 | assert(qpdf_oh_has_key(qpdf, new_dict, "/A")); | 762 | assert(qpdf_oh_has_key(qpdf, new_dict, "/A")); |
| 912 | assert(qpdf_oh_has_key(qpdf, new_dict, "/D")); | 763 | assert(qpdf_oh_has_key(qpdf, new_dict, "/D")); |
| @@ -924,22 +775,14 @@ test25( | @@ -924,22 +775,14 @@ test25( | ||
| 924 | assert(!qpdf_oh_has_key(qpdf, new_dict, "/A")); | 775 | assert(!qpdf_oh_has_key(qpdf, new_dict, "/A")); |
| 925 | assert(!qpdf_oh_has_key(qpdf, new_dict, "/D")); | 776 | assert(!qpdf_oh_has_key(qpdf, new_dict, "/D")); |
| 926 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_string(qpdf, "potato")); | 777 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_string(qpdf, "potato")); |
| 778 | + qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_unicode_string(qpdf, "qww\xc3\xb7\xcf\x80")); | ||
| 927 | qpdf_oh_append_item( | 779 | qpdf_oh_append_item( |
| 928 | - qpdf, | ||
| 929 | - new_array, | ||
| 930 | - qpdf_oh_new_unicode_string(qpdf, "qww\xc3\xb7\xcf\x80")); | ||
| 931 | - qpdf_oh_append_item( | ||
| 932 | - qpdf, | ||
| 933 | - new_array, | ||
| 934 | - qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8)); | 780 | + qpdf, new_array, qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8)); |
| 935 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_null(qpdf)); /* 2 */ | 781 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_null(qpdf)); /* 2 */ |
| 936 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_null(qpdf)); /* 3 */ | 782 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_null(qpdf)); /* 3 */ |
| 937 | - qpdf_oh_set_array_item( | ||
| 938 | - qpdf, new_array, 3, qpdf_oh_new_name(qpdf, "/Quack")); | ||
| 939 | - qpdf_oh_append_item( | ||
| 940 | - qpdf, new_array, qpdf_oh_new_real_from_double(qpdf, 4.123, 2)); | ||
| 941 | - qpdf_oh_append_item( | ||
| 942 | - qpdf, new_array, qpdf_oh_new_real_from_string(qpdf, "5.0")); | 783 | + qpdf_oh_set_array_item(qpdf, new_array, 3, qpdf_oh_new_name(qpdf, "/Quack")); |
| 784 | + qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_real_from_double(qpdf, 4.123, 2)); | ||
| 785 | + qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_real_from_string(qpdf, "5.0")); | ||
| 943 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_integer(qpdf, 6)); | 786 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_integer(qpdf, 6)); |
| 944 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_bool(qpdf, QPDF_TRUE)); | 787 | qpdf_oh_append_item(qpdf, new_array, qpdf_oh_new_bool(qpdf, QPDF_TRUE)); |
| 945 | qpdf_oh_replace_key(qpdf, root, "/QTest", new_dict); | 788 | qpdf_oh_replace_key(qpdf, root, "/QTest", new_dict); |
| @@ -952,11 +795,7 @@ test25( | @@ -952,11 +795,7 @@ test25( | ||
| 952 | report_errors(); | 795 | report_errors(); |
| 953 | } | 796 | } |
| 954 | static void | 797 | static void |
| 955 | -test26( | ||
| 956 | - char const* infile, | ||
| 957 | - char const* password, | ||
| 958 | - char const* outfile, | ||
| 959 | - char const* xarg) | 798 | +test26(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 960 | { | 799 | { |
| 961 | /* Make sure we detect uninitialized objects */ | 800 | /* Make sure we detect uninitialized objects */ |
| 962 | qpdf_data qpdf2 = qpdf_init(); | 801 | qpdf_data qpdf2 = qpdf_init(); |
| @@ -967,11 +806,7 @@ test26( | @@ -967,11 +806,7 @@ test26( | ||
| 967 | } | 806 | } |
| 968 | 807 | ||
| 969 | static void | 808 | static void |
| 970 | -test27( | ||
| 971 | - char const* infile, | ||
| 972 | - char const* password, | ||
| 973 | - char const* outfile, | ||
| 974 | - char const* xarg) | 809 | +test27(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 975 | { | 810 | { |
| 976 | /* Exercise a string with a null. Since the regular methods return | 811 | /* Exercise a string with a null. Since the regular methods return |
| 977 | * char*, we can't see past the null character without looking | 812 | * char*, we can't see past the null character without looking |
| @@ -979,15 +814,10 @@ test27( | @@ -979,15 +814,10 @@ test27( | ||
| 979 | */ | 814 | */ |
| 980 | qpdf_oh p_string_with_null = qpdf_oh_parse(qpdf, "<6f6e650074776f>"); | 815 | qpdf_oh p_string_with_null = qpdf_oh_parse(qpdf, "<6f6e650074776f>"); |
| 981 | assert(qpdf_oh_is_string(qpdf, p_string_with_null)); | 816 | assert(qpdf_oh_is_string(qpdf, p_string_with_null)); |
| 982 | - assert( | ||
| 983 | - strcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), "one") == 0); | 817 | + assert(strcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), "one") == 0); |
| 984 | assert(qpdf_get_last_string_length(qpdf) == 7); | 818 | assert(qpdf_get_last_string_length(qpdf) == 7); |
| 985 | /* memcmp adds a character to verify the trailing null */ | 819 | /* memcmp adds a character to verify the trailing null */ |
| 986 | - assert( | ||
| 987 | - memcmp( | ||
| 988 | - qpdf_oh_get_string_value(qpdf, p_string_with_null), | ||
| 989 | - "one\000two", | ||
| 990 | - 8) == 0); | 820 | + assert(memcmp(qpdf_oh_get_string_value(qpdf, p_string_with_null), "one\000two", 8) == 0); |
| 991 | size_t length = 0; | 821 | size_t length = 0; |
| 992 | p_string_with_null = qpdf_oh_new_binary_string(qpdf, "potato\000salad", 12); | 822 | p_string_with_null = qpdf_oh_new_binary_string(qpdf, "potato\000salad", 12); |
| 993 | /* memcmp adds a character to verify the trailing null */ | 823 | /* memcmp adds a character to verify the trailing null */ |
| @@ -999,27 +829,22 @@ test27( | @@ -999,27 +829,22 @@ test27( | ||
| 999 | assert(qpdf_get_last_string_length(qpdf) == 12); | 829 | assert(qpdf_get_last_string_length(qpdf) == 12); |
| 1000 | assert(length == 12); | 830 | assert(length == 12); |
| 1001 | /* repeat for UTF8 string */ | 831 | /* repeat for UTF8 string */ |
| 1002 | - qpdf_oh p_utf8_string_with_null = | ||
| 1003 | - qpdf_oh_parse(qpdf, "<feff007100770000007700f703c0>"); | 832 | + qpdf_oh p_utf8_string_with_null = qpdf_oh_parse(qpdf, "<feff007100770000007700f703c0>"); |
| 1004 | assert(qpdf_oh_is_string(qpdf, p_utf8_string_with_null)); | 833 | assert(qpdf_oh_is_string(qpdf, p_utf8_string_with_null)); |
| 1005 | assert( | 834 | assert( |
| 1006 | - strcmp( | ||
| 1007 | - qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null), | ||
| 1008 | - "qw\x00w\xc3\xb7\xcf\x80") == 0); | 835 | + strcmp(qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null), "qw\x00w\xc3\xb7\xcf\x80") == |
| 836 | + 0); | ||
| 1009 | assert(qpdf_get_last_string_length(qpdf) == 8); | 837 | assert(qpdf_get_last_string_length(qpdf) == 8); |
| 1010 | /* memcmp adds a character to verify the trailing null */ | 838 | /* memcmp adds a character to verify the trailing null */ |
| 1011 | assert( | 839 | assert( |
| 1012 | memcmp( | 840 | memcmp( |
| 1013 | - qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null), | ||
| 1014 | - "qw\x00w\xc3\xb7\xcf\x80", | ||
| 1015 | - 8) == 0); | ||
| 1016 | - p_utf8_string_with_null = | ||
| 1017 | - qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8); | 841 | + qpdf_oh_get_utf8_value(qpdf, p_utf8_string_with_null), "qw\x00w\xc3\xb7\xcf\x80", 8) == |
| 842 | + 0); | ||
| 843 | + p_utf8_string_with_null = qpdf_oh_new_binary_unicode_string(qpdf, "qw\x00w\xc3\xb7\xcf\x80", 8); | ||
| 1018 | /* memcmp adds a character to verify the trailing null */ | 844 | /* memcmp adds a character to verify the trailing null */ |
| 1019 | assert( | 845 | assert( |
| 1020 | memcmp( | 846 | memcmp( |
| 1021 | - qpdf_oh_get_binary_utf8_value( | ||
| 1022 | - qpdf, p_utf8_string_with_null, &length), | 847 | + qpdf_oh_get_binary_utf8_value(qpdf, p_utf8_string_with_null, &length), |
| 1023 | "qw\x00w\xc3\xb7\xcf\x80", | 848 | "qw\x00w\xc3\xb7\xcf\x80", |
| 1024 | 9) == 0); | 849 | 9) == 0); |
| 1025 | assert(qpdf_get_last_string_length(qpdf) == 8); | 850 | assert(qpdf_get_last_string_length(qpdf) == 8); |
| @@ -1027,11 +852,7 @@ test27( | @@ -1027,11 +852,7 @@ test27( | ||
| 1027 | } | 852 | } |
| 1028 | 853 | ||
| 1029 | static void | 854 | static void |
| 1030 | -test28( | ||
| 1031 | - char const* infile, | ||
| 1032 | - char const* password, | ||
| 1033 | - char const* outfile, | ||
| 1034 | - char const* xarg) | 855 | +test28(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1035 | { | 856 | { |
| 1036 | /* This test case is designed for minimal.pdf. */ | 857 | /* This test case is designed for minimal.pdf. */ |
| 1037 | 858 | ||
| @@ -1062,21 +883,15 @@ test28( | @@ -1062,21 +883,15 @@ test28( | ||
| 1062 | : i == 3 ? 792 | 883 | : i == 3 ? 792 |
| 1063 | : -1)); | 884 | : -1)); |
| 1064 | assert( | 885 | assert( |
| 1065 | - qpdf_oh_get_int_value_as_int(qpdf, item) == | ||
| 1066 | - qpdf_oh_get_int_value_as_int(qpdf, item2)); | 886 | + qpdf_oh_get_int_value_as_int(qpdf, item) == qpdf_oh_get_int_value_as_int(qpdf, item2)); |
| 1067 | assert( | 887 | assert( |
| 1068 | - qpdf_oh_get_int_value_as_int(qpdf, item) == | ||
| 1069 | - qpdf_oh_get_int_value_as_int(qpdf, item3)); | 888 | + qpdf_oh_get_int_value_as_int(qpdf, item) == qpdf_oh_get_int_value_as_int(qpdf, item3)); |
| 1070 | qpdf_oh_release(qpdf, item); | 889 | qpdf_oh_release(qpdf, item); |
| 1071 | } | 890 | } |
| 1072 | } | 891 | } |
| 1073 | 892 | ||
| 1074 | static void | 893 | static void |
| 1075 | -test29( | ||
| 1076 | - char const* infile, | ||
| 1077 | - char const* password, | ||
| 1078 | - char const* outfile, | ||
| 1079 | - char const* xarg) | 894 | +test29(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1080 | { | 895 | { |
| 1081 | /* Trap exceptions thrown by object accessors. Type mismatches are | 896 | /* Trap exceptions thrown by object accessors. Type mismatches are |
| 1082 | * errors rather than warnings when they don't have an owning QPDF | 897 | * errors rather than warnings when they don't have an owning QPDF |
| @@ -1094,8 +909,7 @@ test29( | @@ -1094,8 +909,7 @@ test29( | ||
| 1094 | handle_oh_error(qpdf, "bad parse"); | 909 | handle_oh_error(qpdf, "bad parse"); |
| 1095 | report_errors(); | 910 | report_errors(); |
| 1096 | 911 | ||
| 1097 | - assert( | ||
| 1098 | - qpdf_oh_get_int_value_as_int(qpdf, qpdf_oh_new_string(qpdf, "x")) == 0); | 912 | + assert(qpdf_oh_get_int_value_as_int(qpdf, qpdf_oh_new_string(qpdf, "x")) == 0); |
| 1099 | handle_oh_error(qpdf, "type mismatch (int operation on string)"); | 913 | handle_oh_error(qpdf, "type mismatch (int operation on string)"); |
| 1100 | qpdf_oh int_oh = qpdf_oh_new_integer(qpdf, 12); | 914 | qpdf_oh int_oh = qpdf_oh_new_integer(qpdf, 12); |
| 1101 | assert(strlen(qpdf_oh_get_string_value(qpdf, int_oh)) == 0); | 915 | assert(strlen(qpdf_oh_get_string_value(qpdf, int_oh)) == 0); |
| @@ -1125,22 +939,14 @@ test29( | @@ -1125,22 +939,14 @@ test29( | ||
| 1125 | } | 939 | } |
| 1126 | 940 | ||
| 1127 | static void | 941 | static void |
| 1128 | -test30( | ||
| 1129 | - char const* infile, | ||
| 1130 | - char const* password, | ||
| 1131 | - char const* outfile, | ||
| 1132 | - char const* xarg) | 942 | +test30(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1133 | { | 943 | { |
| 1134 | assert(qpdf_read(qpdf, infile, password) & QPDF_ERRORS); | 944 | assert(qpdf_read(qpdf, infile, password) & QPDF_ERRORS); |
| 1135 | /* Fail to handle error */ | 945 | /* Fail to handle error */ |
| 1136 | } | 946 | } |
| 1137 | 947 | ||
| 1138 | static void | 948 | static void |
| 1139 | -test31( | ||
| 1140 | - char const* infile, | ||
| 1141 | - char const* password, | ||
| 1142 | - char const* outfile, | ||
| 1143 | - char const* xarg) | 949 | +test31(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1144 | { | 950 | { |
| 1145 | /* Make sure type warnings have a specific error code. This test | 951 | /* Make sure type warnings have a specific error code. This test |
| 1146 | * case is designed for minimal.pdf. | 952 | * case is designed for minimal.pdf. |
| @@ -1156,11 +962,7 @@ test31( | @@ -1156,11 +962,7 @@ test31( | ||
| 1156 | } | 962 | } |
| 1157 | 963 | ||
| 1158 | static void | 964 | static void |
| 1159 | -test32( | ||
| 1160 | - char const* infile, | ||
| 1161 | - char const* password, | ||
| 1162 | - char const* outfile, | ||
| 1163 | - char const* xarg) | 965 | +test32(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1164 | { | 966 | { |
| 1165 | /* This test case is designed for minimal.pdf. */ | 967 | /* This test case is designed for minimal.pdf. */ |
| 1166 | assert(qpdf_read(qpdf, infile, password) == 0); | 968 | assert(qpdf_read(qpdf, infile, password) == 0); |
| @@ -1171,11 +973,7 @@ test32( | @@ -1171,11 +973,7 @@ test32( | ||
| 1171 | } | 973 | } |
| 1172 | 974 | ||
| 1173 | static void | 975 | static void |
| 1174 | -test33( | ||
| 1175 | - char const* infile, | ||
| 1176 | - char const* password, | ||
| 1177 | - char const* outfile, | ||
| 1178 | - char const* xarg) | 976 | +test33(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1179 | { | 977 | { |
| 1180 | /* This test case is designed for minimal.pdf. */ | 978 | /* This test case is designed for minimal.pdf. */ |
| 1181 | 979 | ||
| @@ -1210,11 +1008,7 @@ test33( | @@ -1210,11 +1008,7 @@ test33( | ||
| 1210 | } | 1008 | } |
| 1211 | 1009 | ||
| 1212 | static void | 1010 | static void |
| 1213 | -test34( | ||
| 1214 | - char const* infile, | ||
| 1215 | - char const* password, | ||
| 1216 | - char const* outfile, | ||
| 1217 | - char const* xarg) | 1011 | +test34(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1218 | { | 1012 | { |
| 1219 | /* This test expects 11-pages.pdf as file1 and minimal.pdf as xarg. */ | 1013 | /* This test expects 11-pages.pdf as file1 and minimal.pdf as xarg. */ |
| 1220 | 1014 | ||
| @@ -1233,8 +1027,7 @@ test34( | @@ -1233,8 +1027,7 @@ test34( | ||
| 1233 | assert(qpdf_oh_get_object_id(qpdf, qpdf_get_page_n(qpdf, 10)) == 14); | 1027 | assert(qpdf_oh_get_object_id(qpdf, qpdf_get_page_n(qpdf, 10)) == 14); |
| 1234 | qpdf_oh page3 = qpdf_get_page_n(qpdf, 3); | 1028 | qpdf_oh page3 = qpdf_get_page_n(qpdf, 3); |
| 1235 | assert(qpdf_find_page_by_oh(qpdf, page3) == 3); | 1029 | assert(qpdf_find_page_by_oh(qpdf, page3) == 3); |
| 1236 | - assert( | ||
| 1237 | - qpdf_find_page_by_id(qpdf, qpdf_oh_get_object_id(qpdf, page3), 0) == 3); | 1030 | + assert(qpdf_find_page_by_id(qpdf, qpdf_oh_get_object_id(qpdf, page3), 0) == 3); |
| 1238 | 1031 | ||
| 1239 | /* Add other page to the end */ | 1032 | /* Add other page to the end */ |
| 1240 | qpdf_oh opage0 = qpdf_get_page_n(qpdf2, 0); | 1033 | qpdf_oh opage0 = qpdf_get_page_n(qpdf2, 0); |
| @@ -1256,11 +1049,7 @@ test34( | @@ -1256,11 +1049,7 @@ test34( | ||
| 1256 | } | 1049 | } |
| 1257 | 1050 | ||
| 1258 | static void | 1051 | static void |
| 1259 | -test35( | ||
| 1260 | - char const* infile, | ||
| 1261 | - char const* password, | ||
| 1262 | - char const* outfile, | ||
| 1263 | - char const* xarg) | 1052 | +test35(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1264 | { | 1053 | { |
| 1265 | /* This test uses 11-pages.pdf */ | 1054 | /* This test uses 11-pages.pdf */ |
| 1266 | 1055 | ||
| @@ -1306,11 +1095,7 @@ test35( | @@ -1306,11 +1095,7 @@ test35( | ||
| 1306 | } | 1095 | } |
| 1307 | 1096 | ||
| 1308 | static void | 1097 | static void |
| 1309 | -test36( | ||
| 1310 | - char const* infile, | ||
| 1311 | - char const* password, | ||
| 1312 | - char const* outfile, | ||
| 1313 | - char const* xarg) | 1098 | +test36(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1314 | { | 1099 | { |
| 1315 | /* This test uses inherited-rotate.pdf */ | 1100 | /* This test uses inherited-rotate.pdf */ |
| 1316 | 1101 | ||
| @@ -1332,11 +1117,7 @@ test36( | @@ -1332,11 +1117,7 @@ test36( | ||
| 1332 | } | 1117 | } |
| 1333 | 1118 | ||
| 1334 | static void | 1119 | static void |
| 1335 | -test37( | ||
| 1336 | - char const* infile, | ||
| 1337 | - char const* password, | ||
| 1338 | - char const* outfile, | ||
| 1339 | - char const* xarg) | 1120 | +test37(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1340 | { | 1121 | { |
| 1341 | /* This test uses 11-pages.pdf */ | 1122 | /* This test uses 11-pages.pdf */ |
| 1342 | 1123 | ||
| @@ -1353,11 +1134,7 @@ test37( | @@ -1353,11 +1134,7 @@ test37( | ||
| 1353 | } | 1134 | } |
| 1354 | 1135 | ||
| 1355 | static void | 1136 | static void |
| 1356 | -test38( | ||
| 1357 | - char const* infile, | ||
| 1358 | - char const* password, | ||
| 1359 | - char const* outfile, | ||
| 1360 | - char const* xarg) | 1137 | +test38(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1361 | { | 1138 | { |
| 1362 | /* This test expects 11-pages.pdf. */ | 1139 | /* This test expects 11-pages.pdf. */ |
| 1363 | 1140 | ||
| @@ -1366,35 +1143,24 @@ test38( | @@ -1366,35 +1143,24 @@ test38( | ||
| 1366 | assert(qpdf_read(qpdf, infile, password) == 0); | 1143 | assert(qpdf_read(qpdf, infile, password) == 0); |
| 1367 | qpdf_oh stream = qpdf_get_object_by_id(qpdf, 17, 0); | 1144 | qpdf_oh stream = qpdf_get_object_by_id(qpdf, 17, 0); |
| 1368 | qpdf_oh dict = qpdf_oh_get_dict(qpdf, stream); | 1145 | qpdf_oh dict = qpdf_oh_get_dict(qpdf, stream); |
| 1369 | - assert( | ||
| 1370 | - qpdf_oh_get_int_value_as_int( | ||
| 1371 | - qpdf, qpdf_oh_get_key(qpdf, dict, "/Length")) == 53); | 1146 | + assert(qpdf_oh_get_int_value_as_int(qpdf, qpdf_oh_get_key(qpdf, dict, "/Length")) == 53); |
| 1372 | /* Get raw data */ | 1147 | /* Get raw data */ |
| 1373 | unsigned char* buf = 0; | 1148 | unsigned char* buf = 0; |
| 1374 | size_t len = 0; | 1149 | size_t len = 0; |
| 1375 | - assert( | ||
| 1376 | - qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_none, 0, &buf, &len) == | ||
| 1377 | - 0); | 1150 | + assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_none, 0, &buf, &len) == 0); |
| 1378 | assert(len == 53); | 1151 | assert(len == 53); |
| 1379 | assert(((int)buf[0] == 'x') && ((int)buf[1] == 0234)); | 1152 | assert(((int)buf[0] == 'x') && ((int)buf[1] == 0234)); |
| 1380 | free(buf); | 1153 | free(buf); |
| 1381 | 1154 | ||
| 1382 | /* Test whether filterable */ | 1155 | /* Test whether filterable */ |
| 1383 | QPDF_BOOL filtered = QPDF_FALSE; | 1156 | QPDF_BOOL filtered = QPDF_FALSE; |
| 1384 | - assert( | ||
| 1385 | - qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, &filtered, 0, 0) == | ||
| 1386 | - 0); | 1157 | + assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, &filtered, 0, 0) == 0); |
| 1387 | assert(filtered == QPDF_TRUE); | 1158 | assert(filtered == QPDF_TRUE); |
| 1388 | 1159 | ||
| 1389 | /* Get filtered data */ | 1160 | /* Get filtered data */ |
| 1390 | - assert( | ||
| 1391 | - qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, 0, &buf, &len) == 0); | 1161 | + assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_all, 0, &buf, &len) == 0); |
| 1392 | assert(len == 47); | 1162 | assert(len == 47); |
| 1393 | - assert( | ||
| 1394 | - memcmp( | ||
| 1395 | - (char const*)buf, | ||
| 1396 | - "BT /F1 15 Tf 72 720 Td (Original page 2) Tj ET\n", | ||
| 1397 | - len) == 0); | 1163 | + assert(memcmp((char const*)buf, "BT /F1 15 Tf 72 720 Td (Original page 2) Tj ET\n", len) == 0); |
| 1398 | 1164 | ||
| 1399 | /* Get page data */ | 1165 | /* Get page data */ |
| 1400 | qpdf_oh page2 = qpdf_get_page_n(qpdf, 1); /* 0-based index */ | 1166 | qpdf_oh page2 = qpdf_get_page_n(qpdf, 1); /* 0-based index */ |
| @@ -1419,11 +1185,7 @@ test38( | @@ -1419,11 +1185,7 @@ test38( | ||
| 1419 | } | 1185 | } |
| 1420 | 1186 | ||
| 1421 | static void | 1187 | static void |
| 1422 | -test39( | ||
| 1423 | - char const* infile, | ||
| 1424 | - char const* password, | ||
| 1425 | - char const* outfile, | ||
| 1426 | - char const* xarg) | 1188 | +test39(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1427 | { | 1189 | { |
| 1428 | /* This test expects 11-pages.pdf as file1 and minimal.pdf as xarg. */ | 1190 | /* This test expects 11-pages.pdf as file1 and minimal.pdf as xarg. */ |
| 1429 | 1191 | ||
| @@ -1448,11 +1210,7 @@ test39( | @@ -1448,11 +1210,7 @@ test39( | ||
| 1448 | } | 1210 | } |
| 1449 | 1211 | ||
| 1450 | static void | 1212 | static void |
| 1451 | -test40( | ||
| 1452 | - char const* infile, | ||
| 1453 | - char const* password, | ||
| 1454 | - char const* outfile, | ||
| 1455 | - char const* xarg) | 1213 | +test40(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1456 | { | 1214 | { |
| 1457 | /* This test expects minimal.pdf. */ | 1215 | /* This test expects minimal.pdf. */ |
| 1458 | 1216 | ||
| @@ -1479,11 +1237,7 @@ test40( | @@ -1479,11 +1237,7 @@ test40( | ||
| 1479 | } | 1237 | } |
| 1480 | 1238 | ||
| 1481 | static void | 1239 | static void |
| 1482 | -test41( | ||
| 1483 | - char const* infile, | ||
| 1484 | - char const* password, | ||
| 1485 | - char const* outfile, | ||
| 1486 | - char const* xarg) | 1240 | +test41(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1487 | { | 1241 | { |
| 1488 | /* Empty PDF -- infile is ignored */ | 1242 | /* Empty PDF -- infile is ignored */ |
| 1489 | assert(qpdf_empty_pdf(qpdf) == 0); | 1243 | assert(qpdf_empty_pdf(qpdf) == 0); |
| @@ -1494,11 +1248,7 @@ test41( | @@ -1494,11 +1248,7 @@ test41( | ||
| 1494 | } | 1248 | } |
| 1495 | 1249 | ||
| 1496 | static void | 1250 | static void |
| 1497 | -test42( | ||
| 1498 | - char const* infile, | ||
| 1499 | - char const* password, | ||
| 1500 | - char const* outfile, | ||
| 1501 | - char const* xarg) | 1251 | +test42(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1502 | { | 1252 | { |
| 1503 | assert(qpdf_create_from_json_file(qpdf, infile) == QPDF_SUCCESS); | 1253 | assert(qpdf_create_from_json_file(qpdf, infile) == QPDF_SUCCESS); |
| 1504 | qpdf_init_write(qpdf, outfile); | 1254 | qpdf_init_write(qpdf, outfile); |
| @@ -1508,11 +1258,7 @@ test42( | @@ -1508,11 +1258,7 @@ test42( | ||
| 1508 | } | 1258 | } |
| 1509 | 1259 | ||
| 1510 | static void | 1260 | static void |
| 1511 | -test43( | ||
| 1512 | - char const* infile, | ||
| 1513 | - char const* password, | ||
| 1514 | - char const* outfile, | ||
| 1515 | - char const* xarg) | 1261 | +test43(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1516 | { | 1262 | { |
| 1517 | char* buf = NULL; | 1263 | char* buf = NULL; |
| 1518 | unsigned long size = 0; | 1264 | unsigned long size = 0; |
| @@ -1526,11 +1272,7 @@ test43( | @@ -1526,11 +1272,7 @@ test43( | ||
| 1526 | } | 1272 | } |
| 1527 | 1273 | ||
| 1528 | static void | 1274 | static void |
| 1529 | -test44( | ||
| 1530 | - char const* infile, | ||
| 1531 | - char const* password, | ||
| 1532 | - char const* outfile, | ||
| 1533 | - char const* xarg) | 1275 | +test44(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1534 | { | 1276 | { |
| 1535 | assert(qpdf_read(qpdf, infile, password) == 0); | 1277 | assert(qpdf_read(qpdf, infile, password) == 0); |
| 1536 | assert(qpdf_update_from_json_file(qpdf, xarg) == QPDF_SUCCESS); | 1278 | assert(qpdf_update_from_json_file(qpdf, xarg) == QPDF_SUCCESS); |
| @@ -1541,11 +1283,7 @@ test44( | @@ -1541,11 +1283,7 @@ test44( | ||
| 1541 | } | 1283 | } |
| 1542 | 1284 | ||
| 1543 | static void | 1285 | static void |
| 1544 | -test45( | ||
| 1545 | - char const* infile, | ||
| 1546 | - char const* password, | ||
| 1547 | - char const* outfile, | ||
| 1548 | - char const* xarg) | 1286 | +test45(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1549 | { | 1287 | { |
| 1550 | char* buf = NULL; | 1288 | char* buf = NULL; |
| 1551 | unsigned long size = 0; | 1289 | unsigned long size = 0; |
| @@ -1560,39 +1298,23 @@ test45( | @@ -1560,39 +1298,23 @@ test45( | ||
| 1560 | } | 1298 | } |
| 1561 | 1299 | ||
| 1562 | static void | 1300 | static void |
| 1563 | -test46( | ||
| 1564 | - char const* infile, | ||
| 1565 | - char const* password, | ||
| 1566 | - char const* outfile, | ||
| 1567 | - char const* xarg) | 1301 | +test46(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1568 | { | 1302 | { |
| 1569 | FILE* f = safe_fopen(outfile, "wb"); | 1303 | FILE* f = safe_fopen(outfile, "wb"); |
| 1570 | assert(qpdf_read(qpdf, infile, password) == 0); | 1304 | assert(qpdf_read(qpdf, infile, password) == 0); |
| 1571 | - qpdf_write_json( | ||
| 1572 | - qpdf, 2, write_to_file, f, qpdf_dl_none, qpdf_sj_inline, "", NULL); | 1305 | + qpdf_write_json(qpdf, 2, write_to_file, f, qpdf_dl_none, qpdf_sj_inline, "", NULL); |
| 1573 | fclose(f); | 1306 | fclose(f); |
| 1574 | report_errors(); | 1307 | report_errors(); |
| 1575 | } | 1308 | } |
| 1576 | 1309 | ||
| 1577 | static void | 1310 | static void |
| 1578 | -test47( | ||
| 1579 | - char const* infile, | ||
| 1580 | - char const* password, | ||
| 1581 | - char const* outfile, | ||
| 1582 | - char const* xarg) | 1311 | +test47(char const* infile, char const* password, char const* outfile, char const* xarg) |
| 1583 | { | 1312 | { |
| 1584 | FILE* f = safe_fopen(outfile, "wb"); | 1313 | FILE* f = safe_fopen(outfile, "wb"); |
| 1585 | assert(qpdf_read(qpdf, infile, password) == 0); | 1314 | assert(qpdf_read(qpdf, infile, password) == 0); |
| 1586 | char const* wanted_objects[] = {"obj:4 0 R", "trailer", NULL}; | 1315 | char const* wanted_objects[] = {"obj:4 0 R", "trailer", NULL}; |
| 1587 | qpdf_write_json( | 1316 | qpdf_write_json( |
| 1588 | - qpdf, | ||
| 1589 | - 2, | ||
| 1590 | - write_to_file, | ||
| 1591 | - f, | ||
| 1592 | - qpdf_dl_specialized, | ||
| 1593 | - qpdf_sj_file, | ||
| 1594 | - xarg, | ||
| 1595 | - wanted_objects); | 1317 | + qpdf, 2, write_to_file, f, qpdf_dl_specialized, qpdf_sj_file, xarg, wanted_objects); |
| 1596 | fclose(f); | 1318 | fclose(f); |
| 1597 | report_errors(); | 1319 | report_errors(); |
| 1598 | } | 1320 | } |
qpdf/qpdf.cc
| @@ -15,15 +15,10 @@ usageExit(std::string const& msg) | @@ -15,15 +15,10 @@ usageExit(std::string const& msg) | ||
| 15 | << whoami << ": " << msg << std::endl | 15 | << whoami << ": " << msg << std::endl |
| 16 | << std::endl | 16 | << std::endl |
| 17 | << "For help:" << std::endl | 17 | << "For help:" << std::endl |
| 18 | - << " " << whoami << " --help=usage usage information" | ||
| 19 | - << std::endl | ||
| 20 | - << " " << whoami << " --help=topic help on a topic" | ||
| 21 | - << std::endl | ||
| 22 | - << " " << whoami << " --help=--option help on an option" | ||
| 23 | - << std::endl | ||
| 24 | - << " " << whoami | ||
| 25 | - << " --help general help and a topic list" | ||
| 26 | - << std::endl | 18 | + << " " << whoami << " --help=usage usage information" << std::endl |
| 19 | + << " " << whoami << " --help=topic help on a topic" << std::endl | ||
| 20 | + << " " << whoami << " --help=--option help on an option" << std::endl | ||
| 21 | + << " " << whoami << " --help general help and a topic list" << std::endl | ||
| 27 | << std::endl; | 22 | << std::endl; |
| 28 | exit(QPDFJob::EXIT_ERROR); | 23 | exit(QPDFJob::EXIT_ERROR); |
| 29 | } | 24 | } |
qpdf/test_driver.cc
| @@ -112,15 +112,13 @@ ParserCallbacks::contentSize(size_t size) | @@ -112,15 +112,13 @@ ParserCallbacks::contentSize(size_t size) | ||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | void | 114 | void |
| 115 | -ParserCallbacks::handleObject( | ||
| 116 | - QPDFObjectHandle obj, size_t offset, size_t length) | 115 | +ParserCallbacks::handleObject(QPDFObjectHandle obj, size_t offset, size_t length) |
| 117 | { | 116 | { |
| 118 | if (obj.isName() && (obj.getName() == "/Abort")) { | 117 | if (obj.isName() && (obj.getName() == "/Abort")) { |
| 119 | std::cout << "test suite: terminating parsing" << std::endl; | 118 | std::cout << "test suite: terminating parsing" << std::endl; |
| 120 | terminateParsing(); | 119 | terminateParsing(); |
| 121 | } | 120 | } |
| 122 | - std::cout << obj.getTypeName() << ", offset=" << offset | ||
| 123 | - << ", length=" << length << ": "; | 121 | + std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": "; |
| 124 | if (obj.isInlineImage()) { | 122 | if (obj.isInlineImage()) { |
| 125 | // Exercise getTypeCode | 123 | // Exercise getTypeCode |
| 126 | assert(obj.getTypeCode() == ::ot_inlineimage); | 124 | assert(obj.getTypeCode() == ::ot_inlineimage); |
| @@ -163,9 +161,7 @@ static std::string | @@ -163,9 +161,7 @@ static std::string | ||
| 163 | getPageContents(QPDFObjectHandle page) | 161 | getPageContents(QPDFObjectHandle page) |
| 164 | { | 162 | { |
| 165 | std::shared_ptr<Buffer> b1 = page.getKey("/Contents").getStreamData(); | 163 | std::shared_ptr<Buffer> b1 = page.getKey("/Contents").getStreamData(); |
| 166 | - return std::string( | ||
| 167 | - reinterpret_cast<char*>(b1->getBuffer()), b1->getSize()) + | ||
| 168 | - "\0"; | 164 | + return std::string(reinterpret_cast<char*>(b1->getBuffer()), b1->getSize()) + "\0"; |
| 169 | } | 165 | } |
| 170 | 166 | ||
| 171 | static void | 167 | static void |
| @@ -173,8 +169,7 @@ checkPageContents(QPDFObjectHandle page, std::string const& wanted_string) | @@ -173,8 +169,7 @@ checkPageContents(QPDFObjectHandle page, std::string const& wanted_string) | ||
| 173 | { | 169 | { |
| 174 | std::string contents = getPageContents(page); | 170 | std::string contents = getPageContents(page); |
| 175 | if (contents.find(wanted_string) == std::string::npos) { | 171 | if (contents.find(wanted_string) == std::string::npos) { |
| 176 | - std::cout << "didn't find " << wanted_string << " in " << contents | ||
| 177 | - << std::endl; | 172 | + std::cout << "didn't find " << wanted_string << " in " << contents << std::endl; |
| 178 | } | 173 | } |
| 179 | } | 174 | } |
| 180 | 175 | ||
| @@ -188,20 +183,18 @@ createPageContents(QPDF& pdf, std::string const& text) | @@ -188,20 +183,18 @@ createPageContents(QPDF& pdf, std::string const& text) | ||
| 188 | static void | 183 | static void |
| 189 | print_rect(std::ostream& out, QPDFObjectHandle::Rectangle const& r) | 184 | print_rect(std::ostream& out, QPDFObjectHandle::Rectangle const& r) |
| 190 | { | 185 | { |
| 191 | - out << "[" << r.llx << ", " << r.lly << ", " << r.urx << ", " << r.ury | ||
| 192 | - << "]"; | 186 | + out << "[" << r.llx << ", " << r.lly << ", " << r.urx << ", " << r.ury << "]"; |
| 193 | } | 187 | } |
| 194 | 188 | ||
| 195 | -#define assert_compare_numbers(expected, expr) \ | ||
| 196 | - compare_numbers(#expr, expected, expr) | 189 | +#define assert_compare_numbers(expected, expr) compare_numbers(#expr, expected, expr) |
| 197 | 190 | ||
| 198 | template <typename T1, typename T2> | 191 | template <typename T1, typename T2> |
| 199 | static void | 192 | static void |
| 200 | compare_numbers(char const* description, T1 const& expected, T2 const& actual) | 193 | compare_numbers(char const* description, T1 const& expected, T2 const& actual) |
| 201 | { | 194 | { |
| 202 | if (expected != actual) { | 195 | if (expected != actual) { |
| 203 | - std::cerr << description << ": expected = " << expected | ||
| 204 | - << "; actual = " << actual << std::endl; | 196 | + std::cerr << description << ": expected = " << expected << "; actual = " << actual |
| 197 | + << std::endl; | ||
| 205 | } | 198 | } |
| 206 | } | 199 | } |
| 207 | 200 | ||
| @@ -222,43 +215,35 @@ test_0_1(QPDF& pdf, char const* arg2) | @@ -222,43 +215,35 @@ test_0_1(QPDF& pdf, char const* arg2) | ||
| 222 | } | 215 | } |
| 223 | 216 | ||
| 224 | QTC::TC("qpdf", "main QTest indirect", qtest.isIndirect() ? 1 : 0); | 217 | QTC::TC("qpdf", "main QTest indirect", qtest.isIndirect() ? 1 : 0); |
| 225 | - std::cout << "/QTest is " << (qtest.isIndirect() ? "in" : "") | ||
| 226 | - << "direct and has type " << qtest.getTypeName() << " (" | ||
| 227 | - << qtest.getTypeCode() << ")" << std::endl; | 218 | + std::cout << "/QTest is " << (qtest.isIndirect() ? "in" : "") << "direct and has type " |
| 219 | + << qtest.getTypeName() << " (" << qtest.getTypeCode() << ")" << std::endl; | ||
| 228 | 220 | ||
| 229 | if (qtest.isNull()) { | 221 | if (qtest.isNull()) { |
| 230 | QTC::TC("qpdf", "main QTest null"); | 222 | QTC::TC("qpdf", "main QTest null"); |
| 231 | std::cout << "/QTest is null" << std::endl; | 223 | std::cout << "/QTest is null" << std::endl; |
| 232 | } else if (qtest.isBool()) { | 224 | } else if (qtest.isBool()) { |
| 233 | QTC::TC("qpdf", "main QTest bool", qtest.getBoolValue() ? 1 : 0); | 225 | QTC::TC("qpdf", "main QTest bool", qtest.getBoolValue() ? 1 : 0); |
| 234 | - std::cout << "/QTest is Boolean with value " | ||
| 235 | - << (qtest.getBoolValue() ? "true" : "false") << std::endl; | 226 | + std::cout << "/QTest is Boolean with value " << (qtest.getBoolValue() ? "true" : "false") |
| 227 | + << std::endl; | ||
| 236 | } else if (qtest.isInteger()) { | 228 | } else if (qtest.isInteger()) { |
| 237 | QTC::TC("qpdf", "main QTest int"); | 229 | QTC::TC("qpdf", "main QTest int"); |
| 238 | - std::cout << "/QTest is an integer with value " << qtest.getIntValue() | ||
| 239 | - << std::endl; | 230 | + std::cout << "/QTest is an integer with value " << qtest.getIntValue() << std::endl; |
| 240 | } else if (qtest.isReal()) { | 231 | } else if (qtest.isReal()) { |
| 241 | QTC::TC("qpdf", "main QTest real"); | 232 | QTC::TC("qpdf", "main QTest real"); |
| 242 | - std::cout << "/QTest is a real number with value " | ||
| 243 | - << qtest.getRealValue() << std::endl; | 233 | + std::cout << "/QTest is a real number with value " << qtest.getRealValue() << std::endl; |
| 244 | } else if (qtest.isName()) { | 234 | } else if (qtest.isName()) { |
| 245 | QTC::TC("qpdf", "main QTest name"); | 235 | QTC::TC("qpdf", "main QTest name"); |
| 246 | - std::cout << "/QTest is a name with value " << qtest.getName() | ||
| 247 | - << std::endl; | 236 | + std::cout << "/QTest is a name with value " << qtest.getName() << std::endl; |
| 248 | } else if (qtest.isString()) { | 237 | } else if (qtest.isString()) { |
| 249 | QTC::TC("qpdf", "main QTest string"); | 238 | QTC::TC("qpdf", "main QTest string"); |
| 250 | - std::cout << "/QTest is a string with value " << qtest.getStringValue() | ||
| 251 | - << std::endl; | 239 | + std::cout << "/QTest is a string with value " << qtest.getStringValue() << std::endl; |
| 252 | } else if (qtest.isArray()) { | 240 | } else if (qtest.isArray()) { |
| 253 | QTC::TC("qpdf", "main QTest array"); | 241 | QTC::TC("qpdf", "main QTest array"); |
| 254 | - std::cout << "/QTest is an array with " << qtest.getArrayNItems() | ||
| 255 | - << " items" << std::endl; | 242 | + std::cout << "/QTest is an array with " << qtest.getArrayNItems() << " items" << std::endl; |
| 256 | int i = 0; | 243 | int i = 0; |
| 257 | for (auto& iter: qtest.aitems()) { | 244 | for (auto& iter: qtest.aitems()) { |
| 258 | - QTC::TC( | ||
| 259 | - "qpdf", "main QTest array indirect", iter.isIndirect() ? 1 : 0); | ||
| 260 | - std::cout << " item " << i << " is " | ||
| 261 | - << (iter.isIndirect() ? "in" : "") << "direct" | 245 | + QTC::TC("qpdf", "main QTest array indirect", iter.isIndirect() ? 1 : 0); |
| 246 | + std::cout << " item " << i << " is " << (iter.isIndirect() ? "in" : "") << "direct" | ||
| 262 | << std::endl; | 247 | << std::endl; |
| 263 | ++i; | 248 | ++i; |
| 264 | } | 249 | } |
| @@ -266,18 +251,13 @@ test_0_1(QPDF& pdf, char const* arg2) | @@ -266,18 +251,13 @@ test_0_1(QPDF& pdf, char const* arg2) | ||
| 266 | QTC::TC("qpdf", "main QTest dictionary"); | 251 | QTC::TC("qpdf", "main QTest dictionary"); |
| 267 | std::cout << "/QTest is a dictionary" << std::endl; | 252 | std::cout << "/QTest is a dictionary" << std::endl; |
| 268 | for (auto& iter: qtest.ditems()) { | 253 | for (auto& iter: qtest.ditems()) { |
| 269 | - QTC::TC( | ||
| 270 | - "qpdf", | ||
| 271 | - "main QTest dictionary indirect", | ||
| 272 | - iter.second.isIndirect() ? 1 : 0); | ||
| 273 | - std::cout << " " << iter.first << " is " | ||
| 274 | - << (iter.second.isIndirect() ? "in" : "") << "direct" | ||
| 275 | - << std::endl; | 254 | + QTC::TC("qpdf", "main QTest dictionary indirect", iter.second.isIndirect() ? 1 : 0); |
| 255 | + std::cout << " " << iter.first << " is " << (iter.second.isIndirect() ? "in" : "") | ||
| 256 | + << "direct" << std::endl; | ||
| 276 | } | 257 | } |
| 277 | } else if (qtest.isStream()) { | 258 | } else if (qtest.isStream()) { |
| 278 | QTC::TC("qpdf", "main QTest stream"); | 259 | QTC::TC("qpdf", "main QTest stream"); |
| 279 | - std::cout << "/QTest is a stream. Dictionary: " | ||
| 280 | - << qtest.getDict().unparse() << std::endl; | 260 | + std::cout << "/QTest is a stream. Dictionary: " << qtest.getDict().unparse() << std::endl; |
| 281 | 261 | ||
| 282 | std::cout << "Raw stream data:" << std::endl; | 262 | std::cout << "Raw stream data:" << std::endl; |
| 283 | std::cout.flush(); | 263 | std::cout.flush(); |
| @@ -311,11 +291,8 @@ test_2(QPDF& pdf, char const* arg2) | @@ -311,11 +291,8 @@ test_2(QPDF& pdf, char const* arg2) | ||
| 311 | // PDF file. | 291 | // PDF file. |
| 312 | 292 | ||
| 313 | QPDFObjectHandle trailer = pdf.getTrailer(); | 293 | QPDFObjectHandle trailer = pdf.getTrailer(); |
| 314 | - std::cout | ||
| 315 | - << trailer.getKey("/Info").getKey("/CreationDate").getStringValue() | ||
| 316 | - << std::endl; | ||
| 317 | - std::cout << trailer.getKey("/Info").getKey("/Producer").getStringValue() | ||
| 318 | - << std::endl; | 294 | + std::cout << trailer.getKey("/Info").getKey("/CreationDate").getStringValue() << std::endl; |
| 295 | + std::cout << trailer.getKey("/Info").getKey("/Producer").getStringValue() << std::endl; | ||
| 319 | 296 | ||
| 320 | QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); | 297 | QPDFObjectHandle encrypt = trailer.getKey("/Encrypt"); |
| 321 | std::cout << encrypt.getKey("/O").unparse() << std::endl; | 298 | std::cout << encrypt.getKey("/O").unparse() << std::endl; |
| @@ -341,8 +318,7 @@ test_3(QPDF& pdf, char const* arg2) | @@ -341,8 +318,7 @@ test_3(QPDF& pdf, char const* arg2) | ||
| 341 | std::cout.flush(); | 318 | std::cout.flush(); |
| 342 | QUtil::binary_stdout(); | 319 | QUtil::binary_stdout(); |
| 343 | auto out = std::make_shared<Pl_StdioFile>("tokenized stream", stdout); | 320 | auto out = std::make_shared<Pl_StdioFile>("tokenized stream", stdout); |
| 344 | - stream.pipeStreamData( | ||
| 345 | - out.get(), qpdf_ef_normalize, qpdf_dl_generalized); | 321 | + stream.pipeStreamData(out.get(), qpdf_ef_normalize, qpdf_dl_generalized); |
| 346 | } | 322 | } |
| 347 | } | 323 | } |
| 348 | 324 | ||
| @@ -410,8 +386,7 @@ test_5(QPDF& pdf, char const* arg2) | @@ -410,8 +386,7 @@ test_5(QPDF& pdf, char const* arg2) | ||
| 410 | QPDFObjectHandle dict = image.getDict(); | 386 | QPDFObjectHandle dict = image.getDict(); |
| 411 | long long width = dict.getKey("/Width").getIntValue(); | 387 | long long width = dict.getKey("/Width").getIntValue(); |
| 412 | long long height = dict.getKey("/Height").getIntValue(); | 388 | long long height = dict.getKey("/Height").getIntValue(); |
| 413 | - std::cout << " " << name << ": " << width << " x " << height | ||
| 414 | - << std::endl; | 389 | + std::cout << " " << name << ": " << width << " x " << height << std::endl; |
| 415 | } | 390 | } |
| 416 | 391 | ||
| 417 | std::cout << " content:" << std::endl; | 392 | std::cout << " content:" << std::endl; |
| @@ -439,9 +414,7 @@ test_5(QPDF& pdf, char const* arg2) | @@ -439,9 +414,7 @@ test_5(QPDF& pdf, char const* arg2) | ||
| 439 | int nitems = qnumbers.getArrayNItems(); | 414 | int nitems = qnumbers.getArrayNItems(); |
| 440 | for (int i = 0; i < nitems; ++i) { | 415 | for (int i = 0; i < nitems; ++i) { |
| 441 | std::cout << QUtil::double_to_string( | 416 | std::cout << QUtil::double_to_string( |
| 442 | - qnumbers.getArrayItem(i).getNumericValue(), | ||
| 443 | - 3, | ||
| 444 | - false) | 417 | + qnumbers.getArrayItem(i).getNumericValue(), 3, false) |
| 445 | << std::endl; | 418 | << std::endl; |
| 446 | } | 419 | } |
| 447 | } | 420 | } |
| @@ -475,9 +448,7 @@ test_7(QPDF& pdf, char const* arg2) | @@ -475,9 +448,7 @@ test_7(QPDF& pdf, char const* arg2) | ||
| 475 | throw std::logic_error("test 7 run on file with no QStream"); | 448 | throw std::logic_error("test 7 run on file with no QStream"); |
| 476 | } | 449 | } |
| 477 | qstream.replaceStreamData( | 450 | qstream.replaceStreamData( |
| 478 | - "new data for stream\n", | ||
| 479 | - QPDFObjectHandle::newNull(), | ||
| 480 | - QPDFObjectHandle::newNull()); | 451 | + "new data for stream\n", QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 481 | QPDFWriter w(pdf, "a.pdf"); | 452 | QPDFWriter w(pdf, "a.pdf"); |
| 482 | w.setStaticID(true); | 453 | w.setStaticID(true); |
| 483 | w.setStreamDataMode(qpdf_s_preserve); | 454 | w.setStreamDataMode(qpdf_s_preserve); |
| @@ -502,9 +473,7 @@ test_8(QPDF& pdf, char const* arg2) | @@ -502,9 +473,7 @@ test_8(QPDF& pdf, char const* arg2) | ||
| 502 | auto* provider = new Provider(b); | 473 | auto* provider = new Provider(b); |
| 503 | auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(provider); | 474 | auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(provider); |
| 504 | qstream.replaceStreamData( | 475 | qstream.replaceStreamData( |
| 505 | - p, | ||
| 506 | - QPDFObjectHandle::newName("/FlateDecode"), | ||
| 507 | - QPDFObjectHandle::newNull()); | 476 | + p, QPDFObjectHandle::newName("/FlateDecode"), QPDFObjectHandle::newNull()); |
| 508 | provider->badLength(false); | 477 | provider->badLength(false); |
| 509 | QPDFWriter w(pdf, "a.pdf"); | 478 | QPDFWriter w(pdf, "a.pdf"); |
| 510 | w.setStaticID(true); | 479 | w.setStaticID(true); |
| @@ -541,9 +510,7 @@ test_9(QPDF& pdf, char const* arg2) | @@ -541,9 +510,7 @@ test_9(QPDF& pdf, char const* arg2) | ||
| 541 | std::cout << "exception: " << e.what() << std::endl; | 510 | std::cout << "exception: " << e.what() << std::endl; |
| 542 | } | 511 | } |
| 543 | rstream.replaceStreamData( | 512 | rstream.replaceStreamData( |
| 544 | - "data for other stream\n", | ||
| 545 | - QPDFObjectHandle::newNull(), | ||
| 546 | - QPDFObjectHandle::newNull()); | 513 | + "data for other stream\n", QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 547 | root.replaceKey("/QStream", qstream); | 514 | root.replaceKey("/QStream", qstream); |
| 548 | root.replaceKey("/RStream", rstream); | 515 | root.replaceKey("/RStream", rstream); |
| 549 | QPDFWriter w(pdf, "a.pdf"); | 516 | QPDFWriter w(pdf, "a.pdf"); |
| @@ -555,17 +522,12 @@ test_9(QPDF& pdf, char const* arg2) | @@ -555,17 +522,12 @@ test_9(QPDF& pdf, char const* arg2) | ||
| 555 | static void | 522 | static void |
| 556 | test_10(QPDF& pdf, char const* arg2) | 523 | test_10(QPDF& pdf, char const* arg2) |
| 557 | { | 524 | { |
| 558 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 559 | - QPDFPageDocumentHelper(pdf).getAllPages(); | 525 | + std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(pdf).getAllPages(); |
| 560 | QPDFPageObjectHelper& ph(pages.at(0)); | 526 | QPDFPageObjectHelper& ph(pages.at(0)); |
| 561 | ph.addPageContents( | 527 | ph.addPageContents( |
| 562 | - QPDFObjectHandle::newStream( | ||
| 563 | - &pdf, "BT /F1 12 Tf 72 620 Td (Baked) Tj ET\n"), | ||
| 564 | - true); | 528 | + QPDFObjectHandle::newStream(&pdf, "BT /F1 12 Tf 72 620 Td (Baked) Tj ET\n"), true); |
| 565 | ph.addPageContents( | 529 | ph.addPageContents( |
| 566 | - QPDFObjectHandle::newStream( | ||
| 567 | - &pdf, "BT /F1 18 Tf 72 520 Td (Mashed) Tj ET\n"), | ||
| 568 | - false); | 530 | + QPDFObjectHandle::newStream(&pdf, "BT /F1 18 Tf 72 520 Td (Mashed) Tj ET\n"), false); |
| 569 | 531 | ||
| 570 | QPDFWriter w(pdf, "a.pdf"); | 532 | QPDFWriter w(pdf, "a.pdf"); |
| 571 | w.setStaticID(true); | 533 | w.setStaticID(true); |
| @@ -583,8 +545,7 @@ test_11(QPDF& pdf, char const* arg2) | @@ -583,8 +545,7 @@ test_11(QPDF& pdf, char const* arg2) | ||
| 583 | if ((b1->getSize() == 7) && (memcmp(b1->getBuffer(), "potato\n", 7) == 0)) { | 545 | if ((b1->getSize() == 7) && (memcmp(b1->getBuffer(), "potato\n", 7) == 0)) { |
| 584 | std::cout << "filtered stream data okay" << std::endl; | 546 | std::cout << "filtered stream data okay" << std::endl; |
| 585 | } | 547 | } |
| 586 | - if ((b2->getSize() == 15) && | ||
| 587 | - (memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0)) { | 548 | + if ((b2->getSize() == 15) && (memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0)) { |
| 588 | std::cout << "raw stream data okay" << std::endl; | 549 | std::cout << "raw stream data okay" << std::endl; |
| 589 | } | 550 | } |
| 590 | } | 551 | } |
| @@ -661,28 +622,22 @@ test_14(QPDF& pdf, char const* arg2) | @@ -661,28 +622,22 @@ test_14(QPDF& pdf, char const* arg2) | ||
| 661 | } | 622 | } |
| 662 | pdf.replaceObject(qdict.getObjGen(), new_dict); | 623 | pdf.replaceObject(qdict.getObjGen(), new_dict); |
| 663 | // Now qdict points to the new dictionary | 624 | // Now qdict points to the new dictionary |
| 664 | - std::cout << "old dict: " << qdict.getKey("/NewDict").getIntValue() | ||
| 665 | - << std::endl; | 625 | + std::cout << "old dict: " << qdict.getKey("/NewDict").getIntValue() << std::endl; |
| 666 | // Swap dict and array | 626 | // Swap dict and array |
| 667 | pdf.swapObjects(qdict.getObjGen(), qarray.getObjGen()); | 627 | pdf.swapObjects(qdict.getObjGen(), qarray.getObjGen()); |
| 668 | // Now qarray will resolve to new object and qdict resolves to | 628 | // Now qarray will resolve to new object and qdict resolves to |
| 669 | // the array | 629 | // the array |
| 670 | - std::cout << "swapped array: " << qdict.getArrayItem(0).getName() | ||
| 671 | - << std::endl; | ||
| 672 | - std::cout << "new dict: " << qarray.getKey("/NewDict").getIntValue() | ||
| 673 | - << std::endl; | 630 | + std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << std::endl; |
| 631 | + std::cout << "new dict: " << qarray.getKey("/NewDict").getIntValue() << std::endl; | ||
| 674 | // Reread qdict, still pointing to an array | 632 | // Reread qdict, still pointing to an array |
| 675 | qdict = pdf.getObjectByObjGen(qdict.getObjGen()); | 633 | qdict = pdf.getObjectByObjGen(qdict.getObjGen()); |
| 676 | - std::cout << "swapped array: " << qdict.getArrayItem(0).getName() | ||
| 677 | - << std::endl; | 634 | + std::cout << "swapped array: " << qdict.getArrayItem(0).getName() << std::endl; |
| 678 | 635 | ||
| 679 | // Exercise getAsMap and getAsArray | 636 | // Exercise getAsMap and getAsArray |
| 680 | std::vector<QPDFObjectHandle> array_elements = qdict.getArrayAsVector(); | 637 | std::vector<QPDFObjectHandle> array_elements = qdict.getArrayAsVector(); |
| 681 | std::map<std::string, QPDFObjectHandle> dict_items = qarray.getDictAsMap(); | 638 | std::map<std::string, QPDFObjectHandle> dict_items = qarray.getDictAsMap(); |
| 682 | - if ((array_elements.size() == 1) && | ||
| 683 | - (array_elements.at(0).getName() == "/Array") && | ||
| 684 | - (dict_items.size() == 1) && | ||
| 685 | - (dict_items["/NewDict"].getIntValue() == 2)) { | 639 | + if ((array_elements.size() == 1) && (array_elements.at(0).getName() == "/Array") && |
| 640 | + (dict_items.size() == 1) && (dict_items["/NewDict"].getIntValue() == 2)) { | ||
| 686 | std::cout << "array and dictionary contents are correct" << std::endl; | 641 | std::cout << "array and dictionary contents are correct" << std::endl; |
| 687 | } | 642 | } |
| 688 | 643 | ||
| @@ -796,8 +751,7 @@ test_16(QPDF& pdf, char const* arg2) | @@ -796,8 +751,7 @@ test_16(QPDF& pdf, char const* arg2) | ||
| 796 | assert(pdf.everCalledGetAllPages()); | 751 | assert(pdf.everCalledGetAllPages()); |
| 797 | 752 | ||
| 798 | QPDFObjectHandle contents = createPageContents(pdf, "New page 10"); | 753 | QPDFObjectHandle contents = createPageContents(pdf, "New page 10"); |
| 799 | - QPDFObjectHandle page = | ||
| 800 | - pdf.makeIndirectObject(QPDFObjectHandle(all_pages.at(0)).shallowCopy()); | 754 | + QPDFObjectHandle page = pdf.makeIndirectObject(QPDFObjectHandle(all_pages.at(0)).shallowCopy()); |
| 801 | page.replaceKey("/Contents", contents); | 755 | page.replaceKey("/Contents", contents); |
| 802 | 756 | ||
| 803 | // Insert the page manually. | 757 | // Insert the page manually. |
| @@ -806,8 +760,7 @@ test_16(QPDF& pdf, char const* arg2) | @@ -806,8 +760,7 @@ test_16(QPDF& pdf, char const* arg2) | ||
| 806 | QPDFObjectHandle kids = pages.getKey("/Kids"); | 760 | QPDFObjectHandle kids = pages.getKey("/Kids"); |
| 807 | page.replaceKey("/Parent", pages); | 761 | page.replaceKey("/Parent", pages); |
| 808 | pages.replaceKey( | 762 | pages.replaceKey( |
| 809 | - "/Count", | ||
| 810 | - QPDFObjectHandle::newInteger(1 + QIntC::to_longlong(all_pages.size()))); | 763 | + "/Count", QPDFObjectHandle::newInteger(1 + QIntC::to_longlong(all_pages.size()))); |
| 811 | kids.appendItem(page); | 764 | kids.appendItem(page); |
| 812 | assert(all_pages.size() == 10); | 765 | assert(all_pages.size() == 10); |
| 813 | pdf.updateAllPagesCache(); | 766 | pdf.updateAllPagesCache(); |
| @@ -826,9 +779,7 @@ test_17(QPDF& pdf, char const* arg2) | @@ -826,9 +779,7 @@ test_17(QPDF& pdf, char const* arg2) | ||
| 826 | { | 779 | { |
| 827 | // The input file to this test case has a duplicated page. | 780 | // The input file to this test case has a duplicated page. |
| 828 | QPDFObjectHandle page_kids = pdf.getRoot().getKey("/Pages").getKey("/Kids"); | 781 | QPDFObjectHandle page_kids = pdf.getRoot().getKey("/Pages").getKey("/Kids"); |
| 829 | - assert( | ||
| 830 | - page_kids.getArrayItem(0).getObjGen() == | ||
| 831 | - page_kids.getArrayItem(1).getObjGen()); | 782 | + assert(page_kids.getArrayItem(0).getObjGen() == page_kids.getArrayItem(1).getObjGen()); |
| 832 | std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); | 783 | std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); |
| 833 | assert(pages.size() == 3); | 784 | assert(pages.size() == 3); |
| 834 | assert(!(pages.at(0).getObjGen() == pages.at(1).getObjGen())); | 785 | assert(!(pages.at(0).getObjGen() == pages.at(1).getObjGen())); |
| @@ -837,10 +788,8 @@ test_17(QPDF& pdf, char const* arg2) | @@ -837,10 +788,8 @@ test_17(QPDF& pdf, char const* arg2) | ||
| 837 | QPDFObjectHandle(pages.at(1)).getKey("/Contents").getObjGen()); | 788 | QPDFObjectHandle(pages.at(1)).getKey("/Contents").getObjGen()); |
| 838 | pdf.removePage(pages.at(0)); | 789 | pdf.removePage(pages.at(0)); |
| 839 | assert(pages.size() == 2); | 790 | assert(pages.size() == 2); |
| 840 | - std::shared_ptr<Buffer> b = | ||
| 841 | - QPDFObjectHandle(pages.at(0)).getKey("/Contents").getStreamData(); | ||
| 842 | - std::string contents = std::string( | ||
| 843 | - reinterpret_cast<char const*>(b->getBuffer()), b->getSize()); | 791 | + std::shared_ptr<Buffer> b = QPDFObjectHandle(pages.at(0)).getKey("/Contents").getStreamData(); |
| 792 | + std::string contents = std::string(reinterpret_cast<char const*>(b->getBuffer()), b->getSize()); | ||
| 844 | assert(contents.find("page 0") != std::string::npos); | 793 | assert(contents.find("page 0") != std::string::npos); |
| 845 | } | 794 | } |
| 846 | 795 | ||
| @@ -880,9 +829,7 @@ test_19(QPDF& pdf, char const* arg2) | @@ -880,9 +829,7 @@ test_19(QPDF& pdf, char const* arg2) | ||
| 880 | auto last = pages.back(); | 829 | auto last = pages.back(); |
| 881 | assert(pages.size() == count + 1); | 830 | assert(pages.size() == count + 1); |
| 882 | assert(!(last.getObjGen() == newpage.getObjGen())); | 831 | assert(!(last.getObjGen() == newpage.getObjGen())); |
| 883 | - assert( | ||
| 884 | - last.getKey("/Contents").getObjGen() == | ||
| 885 | - newpage.getKey("/Contents").getObjGen()); | 832 | + assert(last.getKey("/Contents").getObjGen() == newpage.getKey("/Contents").getObjGen()); |
| 886 | } | 833 | } |
| 887 | 834 | ||
| 888 | static void | 835 | static void |
| @@ -955,8 +902,7 @@ test_24(QPDF& pdf, char const* arg2) | @@ -955,8 +902,7 @@ test_24(QPDF& pdf, char const* arg2) | ||
| 955 | std::cout << "oops -- res1 is an array" << std::endl; | 902 | std::cout << "oops -- res1 is an array" << std::endl; |
| 956 | } | 903 | } |
| 957 | if (res1.isReserved()) { | 904 | if (res1.isReserved()) { |
| 958 | - std::cout << "res1 is still reserved after checking if array" | ||
| 959 | - << std::endl; | 905 | + std::cout << "res1 is still reserved after checking if array" << std::endl; |
| 960 | } | 906 | } |
| 961 | pdf.replaceReserved(res1, array1); | 907 | pdf.replaceReserved(res1, array1); |
| 962 | if (res1.isReserved()) { | 908 | if (res1.isReserved()) { |
| @@ -1076,8 +1022,7 @@ test_27(QPDF& pdf, char const* arg2) | @@ -1076,8 +1022,7 @@ test_27(QPDF& pdf, char const* arg2) | ||
| 1076 | QPDF empty1; | 1022 | QPDF empty1; |
| 1077 | empty1.emptyPDF(); | 1023 | empty1.emptyPDF(); |
| 1078 | QPDFObjectHandle s1 = QPDFObjectHandle::newStream(&empty1); | 1024 | QPDFObjectHandle s1 = QPDFObjectHandle::newStream(&empty1); |
| 1079 | - s1.replaceStreamData( | ||
| 1080 | - p1, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | 1025 | + s1.replaceStreamData(p1, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 1081 | QPDF empty2; | 1026 | QPDF empty2; |
| 1082 | empty2.emptyPDF(); | 1027 | empty2.emptyPDF(); |
| 1083 | s1 = empty2.copyForeignObject(s1); | 1028 | s1 = empty2.copyForeignObject(s1); |
| @@ -1102,8 +1047,7 @@ test_27(QPDF& pdf, char const* arg2) | @@ -1102,8 +1047,7 @@ test_27(QPDF& pdf, char const* arg2) | ||
| 1102 | empty3.emptyPDF(); | 1047 | empty3.emptyPDF(); |
| 1103 | empty3.setImmediateCopyFrom(true); | 1048 | empty3.setImmediateCopyFrom(true); |
| 1104 | QPDFObjectHandle s3 = QPDFObjectHandle::newStream(&empty3); | 1049 | QPDFObjectHandle s3 = QPDFObjectHandle::newStream(&empty3); |
| 1105 | - s3.replaceStreamData( | ||
| 1106 | - p2, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | 1050 | + s3.replaceStreamData(p2, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 1107 | assert(arg2 != nullptr); | 1051 | assert(arg2 != nullptr); |
| 1108 | QPDF oldpdf; | 1052 | QPDF oldpdf; |
| 1109 | oldpdf.processFile(arg2); | 1053 | oldpdf.processFile(arg2); |
| @@ -1115,8 +1059,7 @@ test_27(QPDF& pdf, char const* arg2) | @@ -1115,8 +1059,7 @@ test_27(QPDF& pdf, char const* arg2) | ||
| 1115 | QPDFObjectHandle s2 = QPDFObjectHandle::newStream(&oldpdf, "potato\n"); | 1059 | QPDFObjectHandle s2 = QPDFObjectHandle::newStream(&oldpdf, "potato\n"); |
| 1116 | auto trailer = pdf.getTrailer(); | 1060 | auto trailer = pdf.getTrailer(); |
| 1117 | trailer.replaceKey("/QTest", pdf.copyForeignObject(qtest)); | 1061 | trailer.replaceKey("/QTest", pdf.copyForeignObject(qtest)); |
| 1118 | - auto qtest2 = trailer.replaceKeyAndGetNew( | ||
| 1119 | - "/QTest2", QPDFObjectHandle::newArray()); | 1062 | + auto qtest2 = trailer.replaceKeyAndGetNew("/QTest2", QPDFObjectHandle::newArray()); |
| 1120 | qtest2.appendItem(pdf.copyForeignObject(s1)); | 1063 | qtest2.appendItem(pdf.copyForeignObject(s1)); |
| 1121 | qtest2.appendItem(pdf.copyForeignObject(s2)); | 1064 | qtest2.appendItem(pdf.copyForeignObject(s2)); |
| 1122 | qtest2.appendItem(pdf.copyForeignObject(s3)); | 1065 | qtest2.appendItem(pdf.copyForeignObject(s3)); |
| @@ -1244,16 +1187,11 @@ test_31(QPDF& pdf, char const* arg2) | @@ -1244,16 +1187,11 @@ test_31(QPDF& pdf, char const* arg2) | ||
| 1244 | } catch (std::runtime_error const& e) { | 1187 | } catch (std::runtime_error const& e) { |
| 1245 | std::cout << "trailing data: " << e.what() << std::endl; | 1188 | std::cout << "trailing data: " << e.what() << std::endl; |
| 1246 | } | 1189 | } |
| 1247 | - assert( | ||
| 1248 | - QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isInteger()); | 1190 | + assert(QPDFObjectHandle::parse(&pdf, "[5 0 R]").getArrayItem(0).isInteger()); |
| 1249 | // Make sure an indirect integer followed by "0 R" is not | 1191 | // Make sure an indirect integer followed by "0 R" is not |
| 1250 | // mistakenly parsed as an indirect object. | 1192 | // mistakenly parsed as an indirect object. |
| 1251 | - assert( | ||
| 1252 | - QPDFObjectHandle::parse(&pdf, "[5 0 R 0 R /X]").unparse() == | ||
| 1253 | - "[ 5 0 R 0 (R) /X ]"); | ||
| 1254 | - assert( | ||
| 1255 | - QPDFObjectHandle::parse(&pdf, "[1 0 R]", "indirect test").unparse() == | ||
| 1256 | - "[ 1 0 R ]"); | 1193 | + assert(QPDFObjectHandle::parse(&pdf, "[5 0 R 0 R /X]").unparse() == "[ 5 0 R 0 (R) /X ]"); |
| 1194 | + assert(QPDFObjectHandle::parse(&pdf, "[1 0 R]", "indirect test").unparse() == "[ 1 0 R ]"); | ||
| 1257 | } | 1195 | } |
| 1258 | 1196 | ||
| 1259 | static void | 1197 | static void |
| @@ -1270,8 +1208,7 @@ test_32(QPDF& pdf, char const* arg2) | @@ -1270,8 +1208,7 @@ test_32(QPDF& pdf, char const* arg2) | ||
| 1270 | << "linearized: " << (linearized ? "yes" : "no") << std::endl | 1208 | << "linearized: " << (linearized ? "yes" : "no") << std::endl |
| 1271 | << "newline: " << (newline ? "yes" : "no") << std::endl; | 1209 | << "newline: " << (newline ? "yes" : "no") << std::endl; |
| 1272 | w.setLinearization(linearized); | 1210 | w.setLinearization(linearized); |
| 1273 | - w.setExtraHeaderText( | ||
| 1274 | - newline ? "%% Comment with newline\n" : "%% Comment\n% No newline"); | 1211 | + w.setExtraHeaderText(newline ? "%% Comment with newline\n" : "%% Comment\n% No newline"); |
| 1275 | w.write(); | 1212 | w.write(); |
| 1276 | } | 1213 | } |
| 1277 | } | 1214 | } |
| @@ -1302,8 +1239,7 @@ test_34(QPDF& pdf, char const* arg2) | @@ -1302,8 +1239,7 @@ test_34(QPDF& pdf, char const* arg2) | ||
| 1302 | std::string v_string; | 1239 | std::string v_string; |
| 1303 | int extension_level; | 1240 | int extension_level; |
| 1304 | v.getVersion(v_string, extension_level); | 1241 | v.getVersion(v_string, extension_level); |
| 1305 | - std::cout << "As PDFVersion: " << v_string << "/" << extension_level | ||
| 1306 | - << std::endl; | 1242 | + std::cout << "As PDFVersion: " << v_string << "/" << extension_level << std::endl; |
| 1307 | } | 1243 | } |
| 1308 | 1244 | ||
| 1309 | static void | 1245 | static void |
| @@ -1319,8 +1255,7 @@ test_35(QPDF& pdf, char const* arg2) | @@ -1319,8 +1255,7 @@ test_35(QPDF& pdf, char const* arg2) | ||
| 1319 | for (int i = 0; i < names.getArrayNItems(); ++i) { | 1255 | for (int i = 0; i < names.getArrayNItems(); ++i) { |
| 1320 | QPDFObjectHandle item = names.getArrayItem(i); | 1256 | QPDFObjectHandle item = names.getArrayItem(i); |
| 1321 | if (item.isDictionary() && item.getKey("/Type").isName() && | 1257 | if (item.isDictionary() && item.getKey("/Type").isName() && |
| 1322 | - (item.getKey("/Type").getName() == "/Filespec") && | ||
| 1323 | - item.getKey("/EF").isDictionary() && | 1258 | + (item.getKey("/Type").getName() == "/Filespec") && item.getKey("/EF").isDictionary() && |
| 1324 | item.getKey("/EF").getKey("/F").isStream()) { | 1259 | item.getKey("/EF").getKey("/F").isStream()) { |
| 1325 | std::string filename = item.getKey("/F").getStringValue(); | 1260 | std::string filename = item.getKey("/F").getStringValue(); |
| 1326 | QPDFObjectHandle stream = item.getKey("/EF").getKey("/F"); | 1261 | QPDFObjectHandle stream = item.getKey("/EF").getKey("/F"); |
| @@ -1330,8 +1265,7 @@ test_35(QPDF& pdf, char const* arg2) | @@ -1330,8 +1265,7 @@ test_35(QPDF& pdf, char const* arg2) | ||
| 1330 | for (auto const& iter: attachments) { | 1265 | for (auto const& iter: attachments) { |
| 1331 | std::string const& filename = iter.first; | 1266 | std::string const& filename = iter.first; |
| 1332 | std::string data = std::string( | 1267 | std::string data = std::string( |
| 1333 | - reinterpret_cast<char const*>(iter.second->getBuffer()), | ||
| 1334 | - iter.second->getSize()); | 1268 | + reinterpret_cast<char const*>(iter.second->getBuffer()), iter.second->getSize()); |
| 1335 | bool is_binary = false; | 1269 | bool is_binary = false; |
| 1336 | for (size_t i = 0; i < data.size(); ++i) { | 1270 | for (size_t i = 0; i < data.size(); ++i) { |
| 1337 | if ((data.at(i) < 0) || (data.at(i) > 126)) { | 1271 | if ((data.at(i) < 0) || (data.at(i) > 126)) { |
| @@ -1341,8 +1275,7 @@ test_35(QPDF& pdf, char const* arg2) | @@ -1341,8 +1275,7 @@ test_35(QPDF& pdf, char const* arg2) | ||
| 1341 | } | 1275 | } |
| 1342 | if (is_binary) { | 1276 | if (is_binary) { |
| 1343 | std::string t; | 1277 | std::string t; |
| 1344 | - for (size_t i = 0; i < std::min(data.size(), QIntC::to_size(20)); | ||
| 1345 | - ++i) { | 1278 | + for (size_t i = 0; i < std::min(data.size(), QIntC::to_size(20)); ++i) { |
| 1346 | if ((data.at(i) >= 32) && (data.at(i) <= 126)) { | 1279 | if ((data.at(i) >= 32) && (data.at(i) <= 126)) { |
| 1347 | t += data.at(i); | 1280 | t += data.at(i); |
| 1348 | } else { | 1281 | } else { |
| @@ -1368,8 +1301,7 @@ test_36(QPDF& pdf, char const* arg2) | @@ -1368,8 +1301,7 @@ test_36(QPDF& pdf, char const* arg2) | ||
| 1368 | for (int i = 0; i < names.getArrayNItems(); ++i) { | 1301 | for (int i = 0; i < names.getArrayNItems(); ++i) { |
| 1369 | QPDFObjectHandle item = names.getArrayItem(i); | 1302 | QPDFObjectHandle item = names.getArrayItem(i); |
| 1370 | if (item.isDictionary() && item.getKey("/Type").isName() && | 1303 | if (item.isDictionary() && item.getKey("/Type").isName() && |
| 1371 | - (item.getKey("/Type").getName() == "/Filespec") && | ||
| 1372 | - item.getKey("/EF").isDictionary() && | 1304 | + (item.getKey("/Type").getName() == "/Filespec") && item.getKey("/EF").isDictionary() && |
| 1373 | item.getKey("/EF").getKey("/F").isStream() && | 1305 | item.getKey("/EF").getKey("/F").isStream() && |
| 1374 | (item.getKey("/F").getStringValue() == "attachment1.txt")) { | 1306 | (item.getKey("/F").getStringValue() == "attachment1.txt")) { |
| 1375 | std::string filename = item.getKey("/F").getStringValue(); | 1307 | std::string filename = item.getKey("/F").getStringValue(); |
| @@ -1378,11 +1310,9 @@ test_36(QPDF& pdf, char const* arg2) | @@ -1378,11 +1310,9 @@ test_36(QPDF& pdf, char const* arg2) | ||
| 1378 | Pl_Flate p2("compress", &p1, Pl_Flate::a_inflate); | 1310 | Pl_Flate p2("compress", &p1, Pl_Flate::a_inflate); |
| 1379 | stream.pipeStreamData(&p2, 0, qpdf_dl_none); | 1311 | stream.pipeStreamData(&p2, 0, qpdf_dl_none); |
| 1380 | auto buf = p1.getBufferSharedPointer(); | 1312 | auto buf = p1.getBufferSharedPointer(); |
| 1381 | - std::string data = std::string( | ||
| 1382 | - reinterpret_cast<char const*>(buf->getBuffer()), | ||
| 1383 | - buf->getSize()); | ||
| 1384 | - std::cout << stream.getDict().unparse() << filename << ":\n" | ||
| 1385 | - << data << "--END--\n"; | 1313 | + std::string data = |
| 1314 | + std::string(reinterpret_cast<char const*>(buf->getBuffer()), buf->getSize()); | ||
| 1315 | + std::cout << stream.getDict().unparse() << filename << ":\n" << data << "--END--\n"; | ||
| 1386 | } | 1316 | } |
| 1387 | } | 1317 | } |
| 1388 | } | 1318 | } |
| @@ -1417,10 +1347,8 @@ test_39(QPDF& pdf, char const* arg2) | @@ -1417,10 +1347,8 @@ test_39(QPDF& pdf, char const* arg2) | ||
| 1417 | std::map<std::string, QPDFObjectHandle> images = page.getImages(); | 1347 | std::map<std::string, QPDFObjectHandle> images = page.getImages(); |
| 1418 | for (auto& i_iter: images) { | 1348 | for (auto& i_iter: images) { |
| 1419 | QPDFObjectHandle image_dict = i_iter.second.getDict(); | 1349 | QPDFObjectHandle image_dict = i_iter.second.getDict(); |
| 1420 | - std::cout << "filter: " | ||
| 1421 | - << image_dict.getKey("/Filter").unparseResolved() | ||
| 1422 | - << ", color space: " | ||
| 1423 | - << image_dict.getKey("/ColorSpace").unparseResolved() | 1350 | + std::cout << "filter: " << image_dict.getKey("/Filter").unparseResolved() |
| 1351 | + << ", color space: " << image_dict.getKey("/ColorSpace").unparseResolved() | ||
| 1424 | << std::endl; | 1352 | << std::endl; |
| 1425 | } | 1353 | } |
| 1426 | } | 1354 | } |
| @@ -1540,27 +1468,23 @@ test_42(QPDF& pdf, char const* arg2) | @@ -1540,27 +1468,23 @@ test_42(QPDF& pdf, char const* arg2) | ||
| 1540 | assert(array.getArrayItem(1).isDictionary()); | 1468 | assert(array.getArrayItem(1).isDictionary()); |
| 1541 | assert(array.getArrayItem(1).getKey("/K").isArray()); | 1469 | assert(array.getArrayItem(1).getKey("/K").isArray()); |
| 1542 | assert(array.getArrayItem(1).getKey("/K").getArrayItem(0).isName()); | 1470 | assert(array.getArrayItem(1).getKey("/K").getArrayItem(0).isName()); |
| 1543 | - assert( | ||
| 1544 | - "/V" == array.getArrayItem(1).getKey("/K").getArrayItem(0).getName()); | 1471 | + assert("/V" == array.getArrayItem(1).getKey("/K").getArrayItem(0).getName()); |
| 1545 | std::cerr << "Two errors\n"; | 1472 | std::cerr << "Two errors\n"; |
| 1546 | assert(array.getArrayItem(16059).getStringValue().empty()); | 1473 | assert(array.getArrayItem(16059).getStringValue().empty()); |
| 1547 | std::cerr << "One error\n"; | 1474 | std::cerr << "One error\n"; |
| 1548 | array.getArrayItem(1).getKey("/K").getArrayItem(0).getStringValue(); | 1475 | array.getArrayItem(1).getKey("/K").getArrayItem(0).getStringValue(); |
| 1549 | // Stream dictionary | 1476 | // Stream dictionary |
| 1550 | QPDFObjectHandle page = pdf.getAllPages().at(0); | 1477 | QPDFObjectHandle page = pdf.getAllPages().at(0); |
| 1551 | - assert( | ||
| 1552 | - "/QPDFFakeName" == | ||
| 1553 | - page.getKey("/Contents").getDict().getKey("/Potato").getName()); | 1478 | + assert("/QPDFFakeName" == page.getKey("/Contents").getDict().getKey("/Potato").getName()); |
| 1554 | // Rectangles | 1479 | // Rectangles |
| 1555 | QPDFObjectHandle::Rectangle r0 = integer.getArrayAsRectangle(); | 1480 | QPDFObjectHandle::Rectangle r0 = integer.getArrayAsRectangle(); |
| 1556 | assert((r0.llx == 0) && (r0.lly == 0) && (r0.urx == 0) && (r0.ury == 0)); | 1481 | assert((r0.llx == 0) && (r0.lly == 0) && (r0.urx == 0) && (r0.ury == 0)); |
| 1557 | - QPDFObjectHandle rect = QPDFObjectHandle::newFromRectangle( | ||
| 1558 | - QPDFObjectHandle::Rectangle(1.2, 3.4, 5.6, 7.8)); | 1482 | + QPDFObjectHandle rect = |
| 1483 | + QPDFObjectHandle::newFromRectangle(QPDFObjectHandle::Rectangle(1.2, 3.4, 5.6, 7.8)); | ||
| 1559 | QPDFObjectHandle::Rectangle r1 = rect.getArrayAsRectangle(); | 1484 | QPDFObjectHandle::Rectangle r1 = rect.getArrayAsRectangle(); |
| 1560 | assert( | 1485 | assert( |
| 1561 | - (r1.llx > 1.19) && (r1.llx < 1.21) && (r1.lly > 3.39) && | ||
| 1562 | - (r1.lly < 3.41) && (r1.urx > 5.59) && (r1.urx < 5.61) && | ||
| 1563 | - (r1.ury > 7.79) && (r1.ury < 7.81)); | 1486 | + (r1.llx > 1.19) && (r1.llx < 1.21) && (r1.lly > 3.39) && (r1.lly < 3.41) && |
| 1487 | + (r1.urx > 5.59) && (r1.urx < 5.61) && (r1.ury > 7.79) && (r1.ury < 7.81)); | ||
| 1564 | QPDFObjectHandle uninitialized; | 1488 | QPDFObjectHandle uninitialized; |
| 1565 | assert(!uninitialized.isInitialized()); | 1489 | assert(!uninitialized.isInitialized()); |
| 1566 | assert(!uninitialized.isInteger()); | 1490 | assert(!uninitialized.isInteger()); |
| @@ -1589,40 +1513,29 @@ test_43(QPDF& pdf, char const* arg2) | @@ -1589,40 +1513,29 @@ test_43(QPDF& pdf, char const* arg2) | ||
| 1589 | << std::endl; | 1513 | << std::endl; |
| 1590 | node = parent; | 1514 | node = parent; |
| 1591 | } | 1515 | } |
| 1592 | - std::cout << " Fully qualified name: " << ffh.getFullyQualifiedName() | ||
| 1593 | - << std::endl; | 1516 | + std::cout << " Fully qualified name: " << ffh.getFullyQualifiedName() << std::endl; |
| 1594 | std::cout << " Partial name: " << ffh.getPartialName() << std::endl; | 1517 | std::cout << " Partial name: " << ffh.getPartialName() << std::endl; |
| 1595 | - std::cout << " Alternative name: " << ffh.getAlternativeName() | ||
| 1596 | - << std::endl; | 1518 | + std::cout << " Alternative name: " << ffh.getAlternativeName() << std::endl; |
| 1597 | std::cout << " Mapping name: " << ffh.getMappingName() << std::endl; | 1519 | std::cout << " Mapping name: " << ffh.getMappingName() << std::endl; |
| 1598 | std::cout << " Field type: " << ffh.getFieldType() << std::endl; | 1520 | std::cout << " Field type: " << ffh.getFieldType() << std::endl; |
| 1599 | std::cout << " Value: " << ffh.getValue().unparse() << std::endl; | 1521 | std::cout << " Value: " << ffh.getValue().unparse() << std::endl; |
| 1600 | - std::cout << " Value as string: " << ffh.getValueAsString() | ||
| 1601 | - << std::endl; | ||
| 1602 | - std::cout << " Default value: " << ffh.getDefaultValue().unparse() | ||
| 1603 | - << std::endl; | ||
| 1604 | - std::cout << " Default value as string: " | ||
| 1605 | - << ffh.getDefaultValueAsString() << std::endl; | ||
| 1606 | - std::cout << " Default appearance: " << ffh.getDefaultAppearance() | ||
| 1607 | - << std::endl; | 1522 | + std::cout << " Value as string: " << ffh.getValueAsString() << std::endl; |
| 1523 | + std::cout << " Default value: " << ffh.getDefaultValue().unparse() << std::endl; | ||
| 1524 | + std::cout << " Default value as string: " << ffh.getDefaultValueAsString() << std::endl; | ||
| 1525 | + std::cout << " Default appearance: " << ffh.getDefaultAppearance() << std::endl; | ||
| 1608 | std::cout << " Quadding: " << ffh.getQuadding() << std::endl; | 1526 | std::cout << " Quadding: " << ffh.getQuadding() << std::endl; |
| 1609 | - std::vector<QPDFAnnotationObjectHelper> annotations = | ||
| 1610 | - afdh.getAnnotationsForField(ffh); | 1527 | + std::vector<QPDFAnnotationObjectHelper> annotations = afdh.getAnnotationsForField(ffh); |
| 1611 | for (auto& aoh: annotations) { | 1528 | for (auto& aoh: annotations) { |
| 1612 | - std::cout << " Annotation: " << aoh.getObjectHandle().unparse() | ||
| 1613 | - << std::endl; | 1529 | + std::cout << " Annotation: " << aoh.getObjectHandle().unparse() << std::endl; |
| 1614 | } | 1530 | } |
| 1615 | } | 1531 | } |
| 1616 | std::cout << "iterating over annotations per page\n"; | 1532 | std::cout << "iterating over annotations per page\n"; |
| 1617 | for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { | 1533 | for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1618 | std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl; | 1534 | std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl; |
| 1619 | for (auto& ah: afdh.getWidgetAnnotationsForPage(page)) { | 1535 | for (auto& ah: afdh.getWidgetAnnotationsForPage(page)) { |
| 1620 | - std::cout << " Annotation: " << ah.getObjectHandle().unparse() | ||
| 1621 | - << std::endl; | ||
| 1622 | - std::cout | ||
| 1623 | - << " Field: " | ||
| 1624 | - << (afdh.getFieldForAnnotation(ah).getObjectHandle().unparse()) | ||
| 1625 | - << std::endl; | 1536 | + std::cout << " Annotation: " << ah.getObjectHandle().unparse() << std::endl; |
| 1537 | + std::cout << " Field: " | ||
| 1538 | + << (afdh.getFieldForAnnotation(ah).getObjectHandle().unparse()) << std::endl; | ||
| 1626 | std::cout << " Subtype: " << ah.getSubtype() << std::endl; | 1539 | std::cout << " Subtype: " << ah.getSubtype() << std::endl; |
| 1627 | std::cout << " Rect: "; | 1540 | std::cout << " Rect: "; |
| 1628 | print_rect(std::cout, ah.getRect()); | 1541 | print_rect(std::cout, ah.getRect()); |
| @@ -1631,11 +1544,10 @@ test_43(QPDF& pdf, char const* arg2) | @@ -1631,11 +1544,10 @@ test_43(QPDF& pdf, char const* arg2) | ||
| 1631 | if (!state.empty()) { | 1544 | if (!state.empty()) { |
| 1632 | std::cout << " Appearance state: " << state << std::endl; | 1545 | std::cout << " Appearance state: " << state << std::endl; |
| 1633 | } | 1546 | } |
| 1634 | - std::cout << " Appearance stream (/N): " | ||
| 1635 | - << ah.getAppearanceStream("/N").unparse() << std::endl; | ||
| 1636 | - std::cout << " Appearance stream (/N, /3): " | ||
| 1637 | - << ah.getAppearanceStream("/N", "/3").unparse() | 1547 | + std::cout << " Appearance stream (/N): " << ah.getAppearanceStream("/N").unparse() |
| 1638 | << std::endl; | 1548 | << std::endl; |
| 1549 | + std::cout << " Appearance stream (/N, /3): " | ||
| 1550 | + << ah.getAppearanceStream("/N", "/3").unparse() << std::endl; | ||
| 1639 | } | 1551 | } |
| 1640 | } | 1552 | } |
| 1641 | } | 1553 | } |
| @@ -1649,8 +1561,8 @@ test_44(QPDF& pdf, char const* arg2) | @@ -1649,8 +1561,8 @@ test_44(QPDF& pdf, char const* arg2) | ||
| 1649 | if (ft.isName() && (ft.getName() == "/Tx")) { | 1561 | if (ft.isName() && (ft.getName() == "/Tx")) { |
| 1650 | // \xc3\xb7 is utf-8 for U+00F7 (divided by) | 1562 | // \xc3\xb7 is utf-8 for U+00F7 (divided by) |
| 1651 | field.setV("3.14 \xc3\xb7 0"); | 1563 | field.setV("3.14 \xc3\xb7 0"); |
| 1652 | - std::cout << "Set field value: " << field.getFullyQualifiedName() | ||
| 1653 | - << " -> " << field.getValueAsString() << std::endl; | 1564 | + std::cout << "Set field value: " << field.getFullyQualifiedName() << " -> " |
| 1565 | + << field.getValueAsString() << std::endl; | ||
| 1654 | } | 1566 | } |
| 1655 | } | 1567 | } |
| 1656 | QPDFWriter w(pdf, "a.pdf"); | 1568 | QPDFWriter w(pdf, "a.pdf"); |
| @@ -1682,13 +1594,11 @@ test_46(QPDF& pdf, char const* arg2) | @@ -1682,13 +1594,11 @@ test_46(QPDF& pdf, char const* arg2) | ||
| 1682 | QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); | 1594 | QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); |
| 1683 | QPDFNumberTreeObjectHelper ntoh(qtest, pdf); | 1595 | QPDFNumberTreeObjectHelper ntoh(qtest, pdf); |
| 1684 | for (auto& iter: ntoh) { | 1596 | for (auto& iter: ntoh) { |
| 1685 | - std::cout << iter.first << " " << iter.second.getStringValue() | ||
| 1686 | - << std::endl; | 1597 | + std::cout << iter.first << " " << iter.second.getStringValue() << std::endl; |
| 1687 | } | 1598 | } |
| 1688 | QPDFNumberTreeObjectHelper::idx_map ntoh_map = ntoh.getAsMap(); | 1599 | QPDFNumberTreeObjectHelper::idx_map ntoh_map = ntoh.getAsMap(); |
| 1689 | for (auto& iter: ntoh_map) { | 1600 | for (auto& iter: ntoh_map) { |
| 1690 | - std::cout << iter.first << " " << iter.second.getStringValue() | ||
| 1691 | - << std::endl; | 1601 | + std::cout << iter.first << " " << iter.second.getStringValue() << std::endl; |
| 1692 | } | 1602 | } |
| 1693 | assert(1 == ntoh.getMin()); | 1603 | assert(1 == ntoh.getMin()); |
| 1694 | assert(29 == ntoh.getMax()); | 1604 | assert(29 == ntoh.getMax()); |
| @@ -1747,14 +1657,12 @@ test_46(QPDF& pdf, char const* arg2) | @@ -1747,14 +1657,12 @@ test_46(QPDF& pdf, char const* arg2) | ||
| 1747 | } | 1657 | } |
| 1748 | 1658 | ||
| 1749 | std::cout << "/Bad1" << std::endl; | 1659 | std::cout << "/Bad1" << std::endl; |
| 1750 | - auto bad1 = | ||
| 1751 | - QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad1"), pdf); | 1660 | + auto bad1 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad1"), pdf); |
| 1752 | assert(bad1.begin() == bad1.end()); | 1661 | assert(bad1.begin() == bad1.end()); |
| 1753 | assert(bad1.last() == bad1.end()); | 1662 | assert(bad1.last() == bad1.end()); |
| 1754 | 1663 | ||
| 1755 | std::cout << "/Bad2" << std::endl; | 1664 | std::cout << "/Bad2" << std::endl; |
| 1756 | - auto bad2 = | ||
| 1757 | - QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad2"), pdf); | 1665 | + auto bad2 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad2"), pdf); |
| 1758 | for (auto& i: bad2) { | 1666 | for (auto& i: bad2) { |
| 1759 | std::cout << i.first << " " << i.second.unparse() << std::endl; | 1667 | std::cout << i.first << " " << i.second.unparse() << std::endl; |
| 1760 | } | 1668 | } |
| @@ -1762,8 +1670,7 @@ test_46(QPDF& pdf, char const* arg2) | @@ -1762,8 +1670,7 @@ test_46(QPDF& pdf, char const* arg2) | ||
| 1762 | std::vector<std::string> empties = {"/Empty1", "/Empty2"}; | 1670 | std::vector<std::string> empties = {"/Empty1", "/Empty2"}; |
| 1763 | for (auto const& k: empties) { | 1671 | for (auto const& k: empties) { |
| 1764 | std::cout << k << std::endl; | 1672 | std::cout << k << std::endl; |
| 1765 | - auto empty = | ||
| 1766 | - QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey(k), pdf); | 1673 | + auto empty = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey(k), pdf); |
| 1767 | assert(empty.begin() == empty.end()); | 1674 | assert(empty.begin() == empty.end()); |
| 1768 | assert(empty.last() == empty.end()); | 1675 | assert(empty.last() == empty.end()); |
| 1769 | auto i = empty.insert(5, QPDFObjectHandle::newString("5")); | 1676 | auto i = empty.insert(5, QPDFObjectHandle::newString("5")); |
| @@ -1784,8 +1691,7 @@ test_46(QPDF& pdf, char const* arg2) | @@ -1784,8 +1691,7 @@ test_46(QPDF& pdf, char const* arg2) | ||
| 1784 | assert(empty.last()->second.getStringValue() == "6"); | 1691 | assert(empty.last()->second.getStringValue() == "6"); |
| 1785 | } | 1692 | } |
| 1786 | std::cout << "Insert into invalid" << std::endl; | 1693 | std::cout << "Insert into invalid" << std::endl; |
| 1787 | - auto invalid1 = | ||
| 1788 | - QPDFNumberTreeObjectHelper(QPDFObjectHandle::newDictionary(), pdf); | 1694 | + auto invalid1 = QPDFNumberTreeObjectHelper(QPDFObjectHandle::newDictionary(), pdf); |
| 1789 | try { | 1695 | try { |
| 1790 | invalid1.insert(1, QPDFObjectHandle::newNull()); | 1696 | invalid1.insert(1, QPDFObjectHandle::newNull()); |
| 1791 | } catch (QPDFExc& e) { | 1697 | } catch (QPDFExc& e) { |
| @@ -1808,16 +1714,14 @@ test_46(QPDF& pdf, char const* arg2) | @@ -1808,16 +1714,14 @@ test_46(QPDF& pdf, char const* arg2) | ||
| 1808 | assert(bad3_oh.getKey("/Kids").getArrayItem(0).isIndirect()); | 1714 | assert(bad3_oh.getKey("/Kids").getArrayItem(0).isIndirect()); |
| 1809 | 1715 | ||
| 1810 | std::cout << "/Bad4 -- missing limits" << std::endl; | 1716 | std::cout << "/Bad4 -- missing limits" << std::endl; |
| 1811 | - auto bad4 = | ||
| 1812 | - QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad4"), pdf); | 1717 | + auto bad4 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad4"), pdf); |
| 1813 | bad4.insert(5, QPDFObjectHandle::newString("5")); | 1718 | bad4.insert(5, QPDFObjectHandle::newString("5")); |
| 1814 | for (auto& i: bad4) { | 1719 | for (auto& i: bad4) { |
| 1815 | std::cout << i.first << " " << i.second.unparse() << std::endl; | 1720 | std::cout << i.first << " " << i.second.unparse() << std::endl; |
| 1816 | } | 1721 | } |
| 1817 | 1722 | ||
| 1818 | std::cout << "/Bad5 -- limit errors" << std::endl; | 1723 | std::cout << "/Bad5 -- limit errors" << std::endl; |
| 1819 | - auto bad5 = | ||
| 1820 | - QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad5"), pdf); | 1724 | + auto bad5 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Bad5"), pdf); |
| 1821 | assert(bad5.find(10) == bad5.end()); | 1725 | assert(bad5.find(10) == bad5.end()); |
| 1822 | } | 1726 | } |
| 1823 | 1727 | ||
| @@ -1826,14 +1730,12 @@ test_47(QPDF& pdf, char const* arg2) | @@ -1826,14 +1730,12 @@ test_47(QPDF& pdf, char const* arg2) | ||
| 1826 | { | 1730 | { |
| 1827 | // Test page labels. | 1731 | // Test page labels. |
| 1828 | QPDFPageLabelDocumentHelper pldh(pdf); | 1732 | QPDFPageLabelDocumentHelper pldh(pdf); |
| 1829 | - long long npages = | ||
| 1830 | - pdf.getRoot().getKey("/Pages").getKey("/Count").getIntValue(); | 1733 | + long long npages = pdf.getRoot().getKey("/Pages").getKey("/Count").getIntValue(); |
| 1831 | std::vector<QPDFObjectHandle> labels; | 1734 | std::vector<QPDFObjectHandle> labels; |
| 1832 | pldh.getLabelsForPageRange(0, npages - 1, 1, labels); | 1735 | pldh.getLabelsForPageRange(0, npages - 1, 1, labels); |
| 1833 | assert(labels.size() % 2 == 0); | 1736 | assert(labels.size() % 2 == 0); |
| 1834 | for (size_t i = 0; i < labels.size(); i += 2) { | 1737 | for (size_t i = 0; i < labels.size(); i += 2) { |
| 1835 | - std::cout << labels.at(i).getIntValue() << " " | ||
| 1836 | - << labels.at(i + 1).unparse() << std::endl; | 1738 | + std::cout << labels.at(i).getIntValue() << " " << labels.at(i + 1).unparse() << std::endl; |
| 1837 | } | 1739 | } |
| 1838 | } | 1740 | } |
| 1839 | 1741 | ||
| @@ -1845,13 +1747,11 @@ test_48(QPDF& pdf, char const* arg2) | @@ -1845,13 +1747,11 @@ test_48(QPDF& pdf, char const* arg2) | ||
| 1845 | QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); | 1747 | QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); |
| 1846 | QPDFNameTreeObjectHelper ntoh(qtest, pdf); | 1748 | QPDFNameTreeObjectHelper ntoh(qtest, pdf); |
| 1847 | for (auto& iter: ntoh) { | 1749 | for (auto& iter: ntoh) { |
| 1848 | - std::cout << iter.first << " -> " << iter.second.getStringValue() | ||
| 1849 | - << std::endl; | 1750 | + std::cout << iter.first << " -> " << iter.second.getStringValue() << std::endl; |
| 1850 | } | 1751 | } |
| 1851 | std::map<std::string, QPDFObjectHandle> ntoh_map = ntoh.getAsMap(); | 1752 | std::map<std::string, QPDFObjectHandle> ntoh_map = ntoh.getAsMap(); |
| 1852 | for (auto& iter: ntoh_map) { | 1753 | for (auto& iter: ntoh_map) { |
| 1853 | - std::cout << iter.first << " -> " << iter.second.getStringValue() | ||
| 1854 | - << std::endl; | 1754 | + std::cout << iter.first << " -> " << iter.second.getStringValue() << std::endl; |
| 1855 | } | 1755 | } |
| 1856 | assert(ntoh.hasName("11 elephant")); | 1756 | assert(ntoh.hasName("11 elephant")); |
| 1857 | assert(ntoh.hasName("07 sev\xe2\x80\xa2n")); | 1757 | assert(ntoh.hasName("07 sev\xe2\x80\xa2n")); |
| @@ -1971,8 +1871,7 @@ test_49(QPDF& pdf, char const* arg2) | @@ -1971,8 +1871,7 @@ test_49(QPDF& pdf, char const* arg2) | ||
| 1971 | QPDFOutlineDocumentHelper odh(pdf); | 1871 | QPDFOutlineDocumentHelper odh(pdf); |
| 1972 | int pageno = 0; | 1872 | int pageno = 0; |
| 1973 | for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { | 1873 | for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1974 | - auto outlines = | ||
| 1975 | - odh.getOutlinesForPage(page.getObjectHandle().getObjGen()); | 1874 | + auto outlines = odh.getOutlinesForPage(page.getObjectHandle().getObjGen()); |
| 1976 | for (auto& ol: outlines) { | 1875 | for (auto& ol: outlines) { |
| 1977 | std::cout << "page " << pageno << ": " << ol.getTitle() << " -> " | 1876 | std::cout << "page " << pageno << ": " << ol.getTitle() << " -> " |
| 1978 | << ol.getDest().unparseResolved() << std::endl; | 1877 | << ol.getDest().unparseResolved() << std::endl; |
| @@ -2069,8 +1968,7 @@ test_53(QPDF& pdf, char const* arg2) | @@ -2069,8 +1968,7 @@ test_53(QPDF& pdf, char const* arg2) | ||
| 2069 | { | 1968 | { |
| 2070 | // Test get all objects and dangling ref handling | 1969 | // Test get all objects and dangling ref handling |
| 2071 | QPDFObjectHandle root = pdf.getRoot(); | 1970 | QPDFObjectHandle root = pdf.getRoot(); |
| 2072 | - auto new_obj = | ||
| 2073 | - pdf.makeIndirectObject(QPDFObjectHandle::newString("potato")); | 1971 | + auto new_obj = pdf.makeIndirectObject(QPDFObjectHandle::newString("potato")); |
| 2074 | root.replaceKey("/Q1", new_obj); | 1972 | root.replaceKey("/Q1", new_obj); |
| 2075 | std::cout << "new object: " << new_obj.unparse() << std::endl; | 1973 | std::cout << "new object: " << new_obj.unparse() << std::endl; |
| 2076 | std::cout << "all objects" << std::endl; | 1974 | std::cout << "all objects" << std::endl; |
| @@ -2101,8 +1999,7 @@ static void | @@ -2101,8 +1999,7 @@ static void | ||
| 2101 | test_55(QPDF& pdf, char const* arg2) | 1999 | test_55(QPDF& pdf, char const* arg2) |
| 2102 | { | 2000 | { |
| 2103 | // Form XObjects | 2001 | // Form XObjects |
| 2104 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 2105 | - QPDFPageDocumentHelper(pdf).getAllPages(); | 2002 | + std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(pdf).getAllPages(); |
| 2106 | QPDFObjectHandle qtest = QPDFObjectHandle::newArray(); | 2003 | QPDFObjectHandle qtest = QPDFObjectHandle::newArray(); |
| 2107 | for (auto& ph: pages) { | 2004 | for (auto& ph: pages) { |
| 2108 | qtest.appendItem(ph.getFormXObjectForPage()); | 2005 | qtest.appendItem(ph.getFormXObjectForPage()); |
| @@ -2117,10 +2014,7 @@ test_55(QPDF& pdf, char const* arg2) | @@ -2117,10 +2014,7 @@ test_55(QPDF& pdf, char const* arg2) | ||
| 2117 | 2014 | ||
| 2118 | static void | 2015 | static void |
| 2119 | test_56_59( | 2016 | test_56_59( |
| 2120 | - QPDF& pdf, | ||
| 2121 | - char const* arg2, | ||
| 2122 | - bool handle_from_transformation, | ||
| 2123 | - bool invert_to_transformation) | 2017 | + QPDF& pdf, char const* arg2, bool handle_from_transformation, bool invert_to_transformation) |
| 2124 | { | 2018 | { |
| 2125 | // red pages are from pdf, blue pages are from pdf2 | 2019 | // red pages are from pdf, blue pages are from pdf2 |
| 2126 | // red pages always have stated rotation absolutely | 2020 | // red pages always have stated rotation absolutely |
| @@ -2134,32 +2028,24 @@ test_56_59( | @@ -2134,32 +2028,24 @@ test_56_59( | ||
| 2134 | QPDF pdf2; | 2028 | QPDF pdf2; |
| 2135 | pdf2.processFile(arg2); | 2029 | pdf2.processFile(arg2); |
| 2136 | 2030 | ||
| 2137 | - std::vector<QPDFPageObjectHelper> pages1 = | ||
| 2138 | - QPDFPageDocumentHelper(pdf).getAllPages(); | ||
| 2139 | - std::vector<QPDFPageObjectHelper> pages2 = | ||
| 2140 | - QPDFPageDocumentHelper(pdf2).getAllPages(); | ||
| 2141 | - size_t npages = | ||
| 2142 | - (pages1.size() < pages2.size() ? pages1.size() : pages2.size()); | 2031 | + std::vector<QPDFPageObjectHelper> pages1 = QPDFPageDocumentHelper(pdf).getAllPages(); |
| 2032 | + std::vector<QPDFPageObjectHelper> pages2 = QPDFPageDocumentHelper(pdf2).getAllPages(); | ||
| 2033 | + size_t npages = (pages1.size() < pages2.size() ? pages1.size() : pages2.size()); | ||
| 2143 | for (size_t i = 0; i < npages; ++i) { | 2034 | for (size_t i = 0; i < npages; ++i) { |
| 2144 | QPDFPageObjectHelper& ph1 = pages1.at(i); | 2035 | QPDFPageObjectHelper& ph1 = pages1.at(i); |
| 2145 | QPDFPageObjectHelper& ph2 = pages2.at(i); | 2036 | QPDFPageObjectHelper& ph2 = pages2.at(i); |
| 2146 | - QPDFObjectHandle fo = pdf.copyForeignObject( | ||
| 2147 | - ph2.getFormXObjectForPage(handle_from_transformation)); | 2037 | + QPDFObjectHandle fo = |
| 2038 | + pdf.copyForeignObject(ph2.getFormXObjectForPage(handle_from_transformation)); | ||
| 2148 | int min_suffix = 1; | 2039 | int min_suffix = 1; |
| 2149 | QPDFObjectHandle resources = ph1.getAttribute("/Resources", true); | 2040 | QPDFObjectHandle resources = ph1.getAttribute("/Resources", true); |
| 2150 | std::string name = resources.getUniqueResourceName("/Fx", min_suffix); | 2041 | std::string name = resources.getUniqueResourceName("/Fx", min_suffix); |
| 2151 | std::string content = ph1.placeFormXObject( | 2042 | std::string content = ph1.placeFormXObject( |
| 2152 | - fo, | ||
| 2153 | - name, | ||
| 2154 | - ph1.getTrimBox().getArrayAsRectangle(), | ||
| 2155 | - invert_to_transformation); | 2043 | + fo, name, ph1.getTrimBox().getArrayAsRectangle(), invert_to_transformation); |
| 2156 | if (!content.empty()) { | 2044 | if (!content.empty()) { |
| 2157 | - resources.mergeResources( | ||
| 2158 | - QPDFObjectHandle::parse("<< /XObject << >> >>")); | 2045 | + resources.mergeResources(QPDFObjectHandle::parse("<< /XObject << >> >>")); |
| 2159 | resources.getKey("/XObject").replaceKey(name, fo); | 2046 | resources.getKey("/XObject").replaceKey(name, fo); |
| 2160 | ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "q\n"), true); | 2047 | ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "q\n"), true); |
| 2161 | - ph1.addPageContents( | ||
| 2162 | - QPDFObjectHandle::newStream(&pdf, "\nQ\n" + content), false); | 2048 | + ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "\nQ\n" + content), false); |
| 2163 | } | 2049 | } |
| 2164 | } | 2050 | } |
| 2165 | QPDFWriter w(pdf, "a.pdf"); | 2051 | QPDFWriter w(pdf, "a.pdf"); |
| @@ -2205,13 +2091,12 @@ test_60(QPDF& pdf, char const* arg2) | @@ -2205,13 +2091,12 @@ test_60(QPDF& pdf, char const* arg2) | ||
| 2205 | r1.mergeResources(QPDFObjectHandle::parse("<< /Z << >> >>")); | 2091 | r1.mergeResources(QPDFObjectHandle::parse("<< /Z << >> >>")); |
| 2206 | r1.getKey("/Z").replaceKey(name, QPDFObjectHandle::newString("moo")); | 2092 | r1.getKey("/Z").replaceKey(name, QPDFObjectHandle::newString("moo")); |
| 2207 | } | 2093 | } |
| 2208 | - auto make_resource = [&](QPDFObjectHandle& dict, | ||
| 2209 | - std::string const& key, | ||
| 2210 | - std::string const& str) { | ||
| 2211 | - auto o1 = QPDFObjectHandle::newArray(); | ||
| 2212 | - o1.appendItem(QPDFObjectHandle::newString(str)); | ||
| 2213 | - dict.replaceKey(key, pdf.makeIndirectObject(o1)); | ||
| 2214 | - }; | 2094 | + auto make_resource = |
| 2095 | + [&](QPDFObjectHandle& dict, std::string const& key, std::string const& str) { | ||
| 2096 | + auto o1 = QPDFObjectHandle::newArray(); | ||
| 2097 | + o1.appendItem(QPDFObjectHandle::newString(str)); | ||
| 2098 | + dict.replaceKey(key, pdf.makeIndirectObject(o1)); | ||
| 2099 | + }; | ||
| 2215 | 2100 | ||
| 2216 | auto z = r1.getKey("/Z"); | 2101 | auto z = r1.getKey("/Z"); |
| 2217 | r1.replaceKey("/Y", QPDFObjectHandle::newDictionary()); | 2102 | r1.replaceKey("/Y", QPDFObjectHandle::newDictionary()); |
| @@ -2235,8 +2120,7 @@ test_60(QPDF& pdf, char const* arg2) | @@ -2235,8 +2120,7 @@ test_60(QPDF& pdf, char const* arg2) | ||
| 2235 | for (auto const& i1: conflicts) { | 2120 | for (auto const& i1: conflicts) { |
| 2236 | std::cout << i1.first << ":" << std::endl; | 2121 | std::cout << i1.first << ":" << std::endl; |
| 2237 | for (auto const& i2: i1.second) { | 2122 | for (auto const& i2: i1.second) { |
| 2238 | - std::cout << " " << i2.first << " -> " << i2.second | ||
| 2239 | - << std::endl; | 2123 | + std::cout << " " << i2.first << " -> " << i2.second << std::endl; |
| 2240 | } | 2124 | } |
| 2241 | } | 2125 | } |
| 2242 | }; | 2126 | }; |
| @@ -2313,8 +2197,7 @@ test_61(QPDF& pdf, char const* arg2) | @@ -2313,8 +2197,7 @@ test_61(QPDF& pdf, char const* arg2) | ||
| 2313 | // For some reason, QPDFNameTreeObjectHelper's vtable seems to | 2197 | // For some reason, QPDFNameTreeObjectHelper's vtable seems to |
| 2314 | // like to not make it into the shared library with mingw. Try to | 2198 | // like to not make it into the shared library with mingw. Try to |
| 2315 | // make sure this is really fixed. | 2199 | // make sure this is really fixed. |
| 2316 | - QPDFNameTreeObjectHelper* n = | ||
| 2317 | - new ExtendNameTree(QPDFObjectHandle::newNull(), pdf); | 2200 | + QPDFNameTreeObjectHelper* n = new ExtendNameTree(QPDFObjectHandle::newNull(), pdf); |
| 2318 | delete n; | 2201 | delete n; |
| 2319 | } | 2202 | } |
| 2320 | 2203 | ||
| @@ -2354,8 +2237,7 @@ test_63(QPDF& pdf, char const* arg2) | @@ -2354,8 +2237,7 @@ test_63(QPDF& pdf, char const* arg2) | ||
| 2354 | // or deterministic ID is used because the filename is not | 2237 | // or deterministic ID is used because the filename is not |
| 2355 | // used as part of the input data for ID generation in those | 2238 | // used as part of the input data for ID generation in those |
| 2356 | // cases. | 2239 | // cases. |
| 2357 | - w.setR6EncryptionParameters( | ||
| 2358 | - "u", "o", true, true, true, true, true, true, qpdf_r3p_full, true); | 2240 | + w.setR6EncryptionParameters("u", "o", true, true, true, true, true, true, qpdf_r3p_full, true); |
| 2359 | w.setOutputFilename("a.pdf"); | 2241 | w.setOutputFilename("a.pdf"); |
| 2360 | w.write(); | 2242 | w.write(); |
| 2361 | } | 2243 | } |
| @@ -2374,34 +2256,23 @@ test_64_67(QPDF& pdf, char const* arg2, bool allow_shrink, bool allow_expand) | @@ -2374,34 +2256,23 @@ test_64_67(QPDF& pdf, char const* arg2, bool allow_shrink, bool allow_expand) | ||
| 2374 | QPDF pdf2; | 2256 | QPDF pdf2; |
| 2375 | pdf2.processFile(arg2); | 2257 | pdf2.processFile(arg2); |
| 2376 | 2258 | ||
| 2377 | - std::vector<QPDFPageObjectHelper> pages1 = | ||
| 2378 | - QPDFPageDocumentHelper(pdf).getAllPages(); | ||
| 2379 | - std::vector<QPDFPageObjectHelper> pages2 = | ||
| 2380 | - QPDFPageDocumentHelper(pdf2).getAllPages(); | ||
| 2381 | - size_t npages = | ||
| 2382 | - (pages1.size() < pages2.size() ? pages1.size() : pages2.size()); | 2259 | + std::vector<QPDFPageObjectHelper> pages1 = QPDFPageDocumentHelper(pdf).getAllPages(); |
| 2260 | + std::vector<QPDFPageObjectHelper> pages2 = QPDFPageDocumentHelper(pdf2).getAllPages(); | ||
| 2261 | + size_t npages = (pages1.size() < pages2.size() ? pages1.size() : pages2.size()); | ||
| 2383 | for (size_t i = 0; i < npages; ++i) { | 2262 | for (size_t i = 0; i < npages; ++i) { |
| 2384 | QPDFPageObjectHelper& ph1 = pages1.at(i); | 2263 | QPDFPageObjectHelper& ph1 = pages1.at(i); |
| 2385 | QPDFPageObjectHelper& ph2 = pages2.at(i); | 2264 | QPDFPageObjectHelper& ph2 = pages2.at(i); |
| 2386 | - QPDFObjectHandle fo = | ||
| 2387 | - pdf.copyForeignObject(ph2.getFormXObjectForPage()); | 2265 | + QPDFObjectHandle fo = pdf.copyForeignObject(ph2.getFormXObjectForPage()); |
| 2388 | int min_suffix = 1; | 2266 | int min_suffix = 1; |
| 2389 | QPDFObjectHandle resources = ph1.getAttribute("/Resources", true); | 2267 | QPDFObjectHandle resources = ph1.getAttribute("/Resources", true); |
| 2390 | std::string name = resources.getUniqueResourceName("/Fx", min_suffix); | 2268 | std::string name = resources.getUniqueResourceName("/Fx", min_suffix); |
| 2391 | std::string content = ph1.placeFormXObject( | 2269 | std::string content = ph1.placeFormXObject( |
| 2392 | - fo, | ||
| 2393 | - name, | ||
| 2394 | - ph1.getTrimBox().getArrayAsRectangle(), | ||
| 2395 | - false, | ||
| 2396 | - allow_shrink, | ||
| 2397 | - allow_expand); | 2270 | + fo, name, ph1.getTrimBox().getArrayAsRectangle(), false, allow_shrink, allow_expand); |
| 2398 | if (!content.empty()) { | 2271 | if (!content.empty()) { |
| 2399 | - resources.mergeResources( | ||
| 2400 | - QPDFObjectHandle::parse("<< /XObject << >> >>")); | 2272 | + resources.mergeResources(QPDFObjectHandle::parse("<< /XObject << >> >>")); |
| 2401 | resources.getKey("/XObject").replaceKey(name, fo); | 2273 | resources.getKey("/XObject").replaceKey(name, fo); |
| 2402 | ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "q\n"), true); | 2274 | ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "q\n"), true); |
| 2403 | - ph1.addPageContents( | ||
| 2404 | - QPDFObjectHandle::newStream(&pdf, "\nQ\n" + content), false); | 2275 | + ph1.addPageContents(QPDFObjectHandle::newStream(&pdf, "\nQ\n" + content), false); |
| 2405 | } | 2276 | } |
| 2406 | } | 2277 | } |
| 2407 | QPDFWriter w(pdf, "a.pdf"); | 2278 | QPDFWriter w(pdf, "a.pdf"); |
| @@ -2446,15 +2317,12 @@ test_68(QPDF& pdf, char const* arg2) | @@ -2446,15 +2317,12 @@ test_68(QPDF& pdf, char const* arg2) | ||
| 2446 | std::cout << "get unfilterable stream: " << e.what() << std::endl; | 2317 | std::cout << "get unfilterable stream: " << e.what() << std::endl; |
| 2447 | } | 2318 | } |
| 2448 | std::shared_ptr<Buffer> b1 = qstream.getStreamData(qpdf_dl_all); | 2319 | std::shared_ptr<Buffer> b1 = qstream.getStreamData(qpdf_dl_all); |
| 2449 | - if ((b1->getSize() > 10) && | ||
| 2450 | - (memcmp(b1->getBuffer(), "wwwwwwwww", 9) == 0)) { | 2320 | + if ((b1->getSize() > 10) && (memcmp(b1->getBuffer(), "wwwwwwwww", 9) == 0)) { |
| 2451 | std::cout << "filtered stream data okay" << std::endl; | 2321 | std::cout << "filtered stream data okay" << std::endl; |
| 2452 | } | 2322 | } |
| 2453 | std::shared_ptr<Buffer> b2 = qstream.getRawStreamData(); | 2323 | std::shared_ptr<Buffer> b2 = qstream.getRawStreamData(); |
| 2454 | if ((b2->getSize() > 10) && | 2324 | if ((b2->getSize() > 10) && |
| 2455 | - (memcmp( | ||
| 2456 | - b2->getBuffer(), "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46", 10) == | ||
| 2457 | - 0)) { | 2325 | + (memcmp(b2->getBuffer(), "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46", 10) == 0)) { |
| 2458 | std::cout << "raw stream data okay" << std::endl; | 2326 | std::cout << "raw stream data okay" << std::endl; |
| 2459 | } | 2327 | } |
| 2460 | } | 2328 | } |
| @@ -2468,8 +2336,7 @@ test_69(QPDF& pdf, char const* arg2) | @@ -2468,8 +2336,7 @@ test_69(QPDF& pdf, char const* arg2) | ||
| 2468 | QPDF out; | 2336 | QPDF out; |
| 2469 | out.emptyPDF(); | 2337 | out.emptyPDF(); |
| 2470 | out.addPage(pages.at(i), false); | 2338 | out.addPage(pages.at(i), false); |
| 2471 | - std::string outname = | ||
| 2472 | - std::string("auto-") + QUtil::uint_to_string(i) + ".pdf"; | 2339 | + std::string outname = std::string("auto-") + QUtil::uint_to_string(i) + ".pdf"; |
| 2473 | QPDFWriter w(out, outname.c_str()); | 2340 | QPDFWriter w(out, outname.c_str()); |
| 2474 | w.setStaticID(true); | 2341 | w.setStaticID(true); |
| 2475 | w.write(); | 2342 | w.write(); |
| @@ -2491,11 +2358,8 @@ test_70(QPDF& pdf, char const* arg2) | @@ -2491,11 +2358,8 @@ test_70(QPDF& pdf, char const* arg2) | ||
| 2491 | static void | 2358 | static void |
| 2492 | test_71(QPDF& pdf, char const* arg2) | 2359 | test_71(QPDF& pdf, char const* arg2) |
| 2493 | { | 2360 | { |
| 2494 | - auto show = [](QPDFObjectHandle& obj, | ||
| 2495 | - QPDFObjectHandle& xobj_dict, | ||
| 2496 | - std::string const& key) { | ||
| 2497 | - std::cout << xobj_dict.unparse() << " -> " << key << " -> " | ||
| 2498 | - << obj.unparse() << std::endl; | 2361 | + auto show = [](QPDFObjectHandle& obj, QPDFObjectHandle& xobj_dict, std::string const& key) { |
| 2362 | + std::cout << xobj_dict.unparse() << " -> " << key << " -> " << obj.unparse() << std::endl; | ||
| 2499 | }; | 2363 | }; |
| 2500 | auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0); | 2364 | auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0); |
| 2501 | std::cout << "--- recursive, all ---" << std::endl; | 2365 | std::cout << "--- recursive, all ---" << std::endl; |
| @@ -2510,10 +2374,8 @@ test_71(QPDF& pdf, char const* arg2) | @@ -2510,10 +2374,8 @@ test_71(QPDF& pdf, char const* arg2) | ||
| 2510 | page.forEachFormXObject(true, show); | 2374 | page.forEachFormXObject(true, show); |
| 2511 | std::cout << "--- non-recursive, form XObjects ---" << std::endl; | 2375 | std::cout << "--- non-recursive, form XObjects ---" << std::endl; |
| 2512 | page.forEachFormXObject(false, show); | 2376 | page.forEachFormXObject(false, show); |
| 2513 | - auto fx1 = QPDFPageObjectHelper(page.getObjectHandle() | ||
| 2514 | - .getKey("/Resources") | ||
| 2515 | - .getKey("/XObject") | ||
| 2516 | - .getKey("/Fx1")); | 2377 | + auto fx1 = QPDFPageObjectHelper( |
| 2378 | + page.getObjectHandle().getKey("/Resources").getKey("/XObject").getKey("/Fx1")); | ||
| 2517 | std::cout << "--- recursive, all, from fx1 ---" << std::endl; | 2379 | std::cout << "--- recursive, all, from fx1 ---" << std::endl; |
| 2518 | fx1.forEachXObject(true, show); | 2380 | fx1.forEachXObject(true, show); |
| 2519 | std::cout << "--- non-recursive, all, from fx1 ---" << std::endl; | 2381 | std::cout << "--- non-recursive, all, from fx1 ---" << std::endl; |
| @@ -2541,10 +2403,8 @@ test_72(QPDF& pdf, char const* arg2) | @@ -2541,10 +2403,8 @@ test_72(QPDF& pdf, char const* arg2) | ||
| 2541 | { | 2403 | { |
| 2542 | // Call some QPDFPageObjectHelper methods on form XObjects. | 2404 | // Call some QPDFPageObjectHelper methods on form XObjects. |
| 2543 | auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0); | 2405 | auto page = QPDFPageDocumentHelper(pdf).getAllPages().at(0); |
| 2544 | - auto fx1 = QPDFPageObjectHelper(page.getObjectHandle() | ||
| 2545 | - .getKey("/Resources") | ||
| 2546 | - .getKey("/XObject") | ||
| 2547 | - .getKey("/Fx1")); | 2406 | + auto fx1 = QPDFPageObjectHelper( |
| 2407 | + page.getObjectHandle().getKey("/Resources").getKey("/XObject").getKey("/Fx1")); | ||
| 2548 | std::cout << "--- parseContents ---" << std::endl; | 2408 | std::cout << "--- parseContents ---" << std::endl; |
| 2549 | ParserCallbacks cb; | 2409 | ParserCallbacks cb; |
| 2550 | fx1.parseContents(&cb); | 2410 | fx1.parseContents(&cb); |
| @@ -2555,17 +2415,14 @@ test_72(QPDF& pdf, char const* arg2) | @@ -2555,17 +2415,14 @@ test_72(QPDF& pdf, char const* arg2) | ||
| 2555 | Pl_Buffer b("buffer"); | 2415 | Pl_Buffer b("buffer"); |
| 2556 | if (i == 0) { | 2416 | if (i == 0) { |
| 2557 | fx1.addContentTokenFilter( | 2417 | fx1.addContentTokenFilter( |
| 2558 | - std::shared_ptr<QPDFObjectHandle::TokenFilter>( | ||
| 2559 | - new TokenFilter())); | 2418 | + std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter())); |
| 2560 | } else { | 2419 | } else { |
| 2561 | fx1.getObjectHandle().addTokenFilter( | 2420 | fx1.getObjectHandle().addTokenFilter( |
| 2562 | - std::shared_ptr<QPDFObjectHandle::TokenFilter>( | ||
| 2563 | - new TokenFilter())); | 2421 | + std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter())); |
| 2564 | } | 2422 | } |
| 2565 | fx1.pipeContents(&b); | 2423 | fx1.pipeContents(&b); |
| 2566 | std::unique_ptr<Buffer> buf(b.getBuffer()); | 2424 | std::unique_ptr<Buffer> buf(b.getBuffer()); |
| 2567 | - std::string s( | ||
| 2568 | - reinterpret_cast<char const*>(buf->getBuffer()), buf->getSize()); | 2425 | + std::string s(reinterpret_cast<char const*>(buf->getBuffer()), buf->getSize()); |
| 2569 | assert(s.find("/bye") != std::string::npos); | 2426 | assert(s.find("/bye") != std::string::npos); |
| 2570 | } | 2427 | } |
| 2571 | } | 2428 | } |
| @@ -2589,12 +2446,10 @@ test_74(QPDF& pdf, char const* arg2) | @@ -2589,12 +2446,10 @@ test_74(QPDF& pdf, char const* arg2) | ||
| 2589 | { | 2446 | { |
| 2590 | // This test is crafted to work with split-nntree.pdf | 2447 | // This test is crafted to work with split-nntree.pdf |
| 2591 | std::cout << "/Split1" << std::endl; | 2448 | std::cout << "/Split1" << std::endl; |
| 2592 | - auto split1 = | ||
| 2593 | - QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Split1"), pdf); | 2449 | + auto split1 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Split1"), pdf); |
| 2594 | split1.setSplitThreshold(4); | 2450 | split1.setSplitThreshold(4); |
| 2595 | auto check_split1 = [&split1](int k) { | 2451 | auto check_split1 = [&split1](int k) { |
| 2596 | - auto i = split1.insert( | ||
| 2597 | - k, QPDFObjectHandle::newString(QUtil::int_to_string(k))); | 2452 | + auto i = split1.insert(k, QPDFObjectHandle::newString(QUtil::int_to_string(k))); |
| 2598 | assert(i->first == k); | 2453 | assert(i->first == k); |
| 2599 | }; | 2454 | }; |
| 2600 | check_split1(15); | 2455 | check_split1(15); |
| @@ -2605,11 +2460,9 @@ test_74(QPDF& pdf, char const* arg2) | @@ -2605,11 +2460,9 @@ test_74(QPDF& pdf, char const* arg2) | ||
| 2605 | } | 2460 | } |
| 2606 | 2461 | ||
| 2607 | std::cout << "/Split2" << std::endl; | 2462 | std::cout << "/Split2" << std::endl; |
| 2608 | - auto split2 = | ||
| 2609 | - QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split2"), pdf); | 2463 | + auto split2 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split2"), pdf); |
| 2610 | split2.setSplitThreshold(4); | 2464 | split2.setSplitThreshold(4); |
| 2611 | - auto check_split2 = [](QPDFNameTreeObjectHelper& noh, | ||
| 2612 | - std::string const& k) { | 2465 | + auto check_split2 = [](QPDFNameTreeObjectHelper& noh, std::string const& k) { |
| 2613 | auto i = noh.insert(k, QPDFObjectHandle::newUnicodeString(k)); | 2466 | auto i = noh.insert(k, QPDFObjectHandle::newUnicodeString(k)); |
| 2614 | assert(i->first == k); | 2467 | assert(i->first == k); |
| 2615 | }; | 2468 | }; |
| @@ -2619,8 +2472,7 @@ test_74(QPDF& pdf, char const* arg2) | @@ -2619,8 +2472,7 @@ test_74(QPDF& pdf, char const* arg2) | ||
| 2619 | } | 2472 | } |
| 2620 | 2473 | ||
| 2621 | std::cout << "/Split3" << std::endl; | 2474 | std::cout << "/Split3" << std::endl; |
| 2622 | - auto split3 = | ||
| 2623 | - QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split3"), pdf); | 2475 | + auto split3 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Split3"), pdf); |
| 2624 | split3.setSplitThreshold(4); | 2476 | split3.setSplitThreshold(4); |
| 2625 | check_split2(split3, "P"); | 2477 | check_split2(split3, "P"); |
| 2626 | check_split2(split3, "\xcf\x80"); | 2478 | check_split2(split3, "\xcf\x80"); |
| @@ -2638,8 +2490,7 @@ static void | @@ -2638,8 +2490,7 @@ static void | ||
| 2638 | test_75(QPDF& pdf, char const* arg2) | 2490 | test_75(QPDF& pdf, char const* arg2) |
| 2639 | { | 2491 | { |
| 2640 | // This test is crafted to work with erase-nntree.pdf | 2492 | // This test is crafted to work with erase-nntree.pdf |
| 2641 | - auto erase1 = | ||
| 2642 | - QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Erase1"), pdf); | 2493 | + auto erase1 = QPDFNameTreeObjectHelper(pdf.getTrailer().getKey("/Erase1"), pdf); |
| 2643 | QPDFObjectHandle value; | 2494 | QPDFObjectHandle value; |
| 2644 | assert(!erase1.remove("1X")); | 2495 | assert(!erase1.remove("1X")); |
| 2645 | assert(erase1.remove("1C", &value)); | 2496 | assert(erase1.remove("1C", &value)); |
| @@ -2675,16 +2526,14 @@ test_75(QPDF& pdf, char const* arg2) | @@ -2675,16 +2526,14 @@ test_75(QPDF& pdf, char const* arg2) | ||
| 2675 | k1 = k1.getKey("/Kids"); | 2526 | k1 = k1.getKey("/Kids"); |
| 2676 | assert(k1.getArrayNItems() == 1); | 2527 | assert(k1.getArrayNItems() == 1); |
| 2677 | 2528 | ||
| 2678 | - auto erase3 = | ||
| 2679 | - QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Erase3"), pdf); | 2529 | + auto erase3 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Erase3"), pdf); |
| 2680 | iter2 = erase3.find(320); | 2530 | iter2 = erase3.find(320); |
| 2681 | iter2.remove(); | 2531 | iter2.remove(); |
| 2682 | assert(iter2 == erase3.end()); | 2532 | assert(iter2 == erase3.end()); |
| 2683 | erase3.remove(310); | 2533 | erase3.remove(310); |
| 2684 | assert(erase3.begin() == erase3.end()); | 2534 | assert(erase3.begin() == erase3.end()); |
| 2685 | 2535 | ||
| 2686 | - auto erase4 = | ||
| 2687 | - QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Erase4"), pdf); | 2536 | + auto erase4 = QPDFNumberTreeObjectHelper(pdf.getTrailer().getKey("/Erase4"), pdf); |
| 2688 | iter2 = erase4.find(420); | 2537 | iter2 = erase4.find(420); |
| 2689 | iter2.remove(); | 2538 | iter2.remove(); |
| 2690 | assert(iter2->first == 430); | 2539 | assert(iter2->first == 430); |
| @@ -2714,12 +2563,10 @@ test_76(QPDF& pdf, char const* arg2) | @@ -2714,12 +2563,10 @@ test_76(QPDF& pdf, char const* arg2) | ||
| 2714 | // exercise Pipeline::operator<<(std::string const&) | 2563 | // exercise Pipeline::operator<<(std::string const&) |
| 2715 | p << std::string("from buffer"); | 2564 | p << std::string("from buffer"); |
| 2716 | p.finish(); | 2565 | p.finish(); |
| 2717 | - auto efs3 = QPDFEFStreamObjectHelper::createEFStream( | ||
| 2718 | - pdf, p.getBufferSharedPointer()); | 2566 | + auto efs3 = QPDFEFStreamObjectHelper::createEFStream(pdf, p.getBufferSharedPointer()); |
| 2719 | efs3.setSubtype("text/plain"); | 2567 | efs3.setSubtype("text/plain"); |
| 2720 | efdh.replaceEmbeddedFile( | 2568 | efdh.replaceEmbeddedFile( |
| 2721 | - "att2", | ||
| 2722 | - QPDFFileSpecObjectHelper::createFileSpec(pdf, "att2.txt", efs2)); | 2569 | + "att2", QPDFFileSpecObjectHelper::createFileSpec(pdf, "att2.txt", efs2)); |
| 2723 | auto fs3 = QPDFFileSpecObjectHelper::createFileSpec(pdf, "att3.txt", efs3); | 2570 | auto fs3 = QPDFFileSpecObjectHelper::createFileSpec(pdf, "att3.txt", efs3); |
| 2724 | efdh.replaceEmbeddedFile("att3", fs3); | 2571 | efdh.replaceEmbeddedFile("att3", fs3); |
| 2725 | fs3.setFilename("\xcf\x80.txt", "att3.txt"); | 2572 | fs3.setFilename("\xcf\x80.txt", "att3.txt"); |
| @@ -2728,13 +2575,10 @@ test_76(QPDF& pdf, char const* arg2) | @@ -2728,13 +2575,10 @@ test_76(QPDF& pdf, char const* arg2) | ||
| 2728 | assert(efs1.getModDate() == "D:20210208001122Z"); | 2575 | assert(efs1.getModDate() == "D:20210208001122Z"); |
| 2729 | assert(efs2.getSize() == 11); | 2576 | assert(efs2.getSize() == 11); |
| 2730 | assert(efs2.getSubtype() == "text/plain"); | 2577 | assert(efs2.getSubtype() == "text/plain"); |
| 2731 | - assert( | ||
| 2732 | - QUtil::hex_encode(efs2.getChecksum()) == | ||
| 2733 | - "2fce9c8228e360ba9b04a1bd1bf63d6b"); | 2578 | + assert(QUtil::hex_encode(efs2.getChecksum()) == "2fce9c8228e360ba9b04a1bd1bf63d6b"); |
| 2734 | 2579 | ||
| 2735 | for (auto iter: efdh.getEmbeddedFiles()) { | 2580 | for (auto iter: efdh.getEmbeddedFiles()) { |
| 2736 | - std::cout << iter.first << " -> " << iter.second->getFilename() | ||
| 2737 | - << std::endl; | 2581 | + std::cout << iter.first << " -> " << iter.second->getFilename() << std::endl; |
| 2738 | } | 2582 | } |
| 2739 | assert(efdh.getEmbeddedFile("att1")->getFilename() == "att1.txt"); | 2583 | assert(efdh.getEmbeddedFile("att1")->getFilename() == "att1.txt"); |
| 2740 | assert(!efdh.getEmbeddedFile("potato")); | 2584 | assert(!efdh.getEmbeddedFile("potato")); |
| @@ -2787,8 +2631,7 @@ test_78(QPDF& pdf, char const* arg2) | @@ -2787,8 +2631,7 @@ test_78(QPDF& pdf, char const* arg2) | ||
| 2787 | s1.replaceStreamData(f1, null, null); | 2631 | s1.replaceStreamData(f1, null, null); |
| 2788 | auto s2 = QPDFObjectHandle::newStream(&pdf); | 2632 | auto s2 = QPDFObjectHandle::newStream(&pdf); |
| 2789 | s2.replaceStreamData(f2, null, null); | 2633 | s2.replaceStreamData(f2, null, null); |
| 2790 | - pdf.getTrailer().replaceKey( | ||
| 2791 | - "/Streams", QPDFObjectHandle::newArray({s1, s2})); | 2634 | + pdf.getTrailer().replaceKey("/Streams", QPDFObjectHandle::newArray({s1, s2})); |
| 2792 | std::cout << "piping with warning suppression" << std::endl; | 2635 | std::cout << "piping with warning suppression" << std::endl; |
| 2793 | Pl_Discard d; | 2636 | Pl_Discard d; |
| 2794 | s2.pipeStreamData(&d, nullptr, 0, qpdf_dl_all, true, false); | 2637 | s2.pipeStreamData(&d, nullptr, 0, qpdf_dl_all, true, false); |
| @@ -2823,11 +2666,8 @@ test_79(QPDF& pdf, char const* arg2) | @@ -2823,11 +2666,8 @@ test_79(QPDF& pdf, char const* arg2) | ||
| 2823 | QPDFObjectHandle::parse( | 2666 | QPDFObjectHandle::parse( |
| 2824 | &pdf, | 2667 | &pdf, |
| 2825 | "<< /Direct 3 /Indirect " + | 2668 | "<< /Direct 3 /Indirect " + |
| 2826 | - pdf.makeIndirectObject(QPDFObjectHandle::newInteger(16059)) | ||
| 2827 | - .unparse() + | ||
| 2828 | - ">>")); | ||
| 2829 | - s2.getDict().replaceKey( | ||
| 2830 | - "/Other", QPDFObjectHandle::newString("other stuff")); | 2669 | + pdf.makeIndirectObject(QPDFObjectHandle::newInteger(16059)).unparse() + ">>")); |
| 2670 | + s2.getDict().replaceKey("/Other", QPDFObjectHandle::newString("other stuff")); | ||
| 2831 | 2671 | ||
| 2832 | // Use a provider | 2672 | // Use a provider |
| 2833 | Pl_Buffer b("buffer"); | 2673 | Pl_Buffer b("buffer"); |
| @@ -2837,8 +2677,7 @@ test_79(QPDF& pdf, char const* arg2) | @@ -2837,8 +2677,7 @@ test_79(QPDF& pdf, char const* arg2) | ||
| 2837 | auto s3 = QPDFObjectHandle::newStream(&pdf, bp); | 2677 | auto s3 = QPDFObjectHandle::newStream(&pdf, bp); |
| 2838 | 2678 | ||
| 2839 | std::vector<QPDFObjectHandle> streams = {s1, s2, s3}; | 2679 | std::vector<QPDFObjectHandle> streams = {s1, s2, s3}; |
| 2840 | - pdf.getTrailer().replaceKey( | ||
| 2841 | - "/Originals", QPDFObjectHandle::newArray(streams)); | 2680 | + pdf.getTrailer().replaceKey("/Originals", QPDFObjectHandle::newArray(streams)); |
| 2842 | 2681 | ||
| 2843 | int i = 0; | 2682 | int i = 0; |
| 2844 | for (auto orig: streams) { | 2683 | for (auto orig: streams) { |
| @@ -2846,16 +2685,11 @@ test_79(QPDF& pdf, char const* arg2) | @@ -2846,16 +2685,11 @@ test_79(QPDF& pdf, char const* arg2) | ||
| 2846 | auto istr = QUtil::int_to_string(i); | 2685 | auto istr = QUtil::int_to_string(i); |
| 2847 | auto orig_data = orig.getStreamData(); | 2686 | auto orig_data = orig.getStreamData(); |
| 2848 | auto copy = orig.copyStream(); | 2687 | auto copy = orig.copyStream(); |
| 2849 | - copy.getDict().replaceKey( | ||
| 2850 | - "/Other", QPDFObjectHandle::newString("other: " + istr)); | 2688 | + copy.getDict().replaceKey("/Other", QPDFObjectHandle::newString("other: " + istr)); |
| 2851 | orig.replaceStreamData("something new " + istr, null, null); | 2689 | orig.replaceStreamData("something new " + istr, null, null); |
| 2852 | auto copy_data = copy.getStreamData(); | 2690 | auto copy_data = copy.getStreamData(); |
| 2853 | assert(orig_data->getSize() == copy_data->getSize()); | 2691 | assert(orig_data->getSize() == copy_data->getSize()); |
| 2854 | - assert( | ||
| 2855 | - memcmp( | ||
| 2856 | - orig_data->getBuffer(), | ||
| 2857 | - copy_data->getBuffer(), | ||
| 2858 | - orig_data->getSize()) == 0); | 2692 | + assert(memcmp(orig_data->getBuffer(), copy_data->getBuffer(), orig_data->getSize()) == 0); |
| 2859 | copies.appendItem(copy); | 2693 | copies.appendItem(copy); |
| 2860 | } | 2694 | } |
| 2861 | 2695 | ||
| @@ -2887,8 +2721,7 @@ test_80(QPDF& pdf, char const* arg2) | @@ -2887,8 +2721,7 @@ test_80(QPDF& pdf, char const* arg2) | ||
| 2887 | std::set<QPDFObjGen> old_fields; | 2721 | std::set<QPDFObjGen> old_fields; |
| 2888 | QPDFAcroFormDocumentHelper afdh(pdf); | 2722 | QPDFAcroFormDocumentHelper afdh(pdf); |
| 2889 | // Use defaults for from_qpdf and from_afdh. | 2723 | // Use defaults for from_qpdf and from_afdh. |
| 2890 | - afdh.transformAnnotations( | ||
| 2891 | - old_annots, new_annots, new_fields, old_fields, m); | 2724 | + afdh.transformAnnotations(old_annots, new_annots, new_fields, old_fields, m); |
| 2892 | for (auto const& annot: new_annots) { | 2725 | for (auto const& annot: new_annots) { |
| 2893 | old_annots.appendItem(annot); | 2726 | old_annots.appendItem(annot); |
| 2894 | } | 2727 | } |
| @@ -2935,8 +2768,7 @@ test_82(QPDF& pdf, char const* arg2) | @@ -2935,8 +2768,7 @@ test_82(QPDF& pdf, char const* arg2) | ||
| 2935 | assert(name.isNameAndEquals("/Marvin")); | 2768 | assert(name.isNameAndEquals("/Marvin")); |
| 2936 | assert(!name.isNameAndEquals("Marvin")); | 2769 | assert(!name.isNameAndEquals("Marvin")); |
| 2937 | assert(!str.isNameAndEquals("/Marvin")); | 2770 | assert(!str.isNameAndEquals("/Marvin")); |
| 2938 | - auto dict = | ||
| 2939 | - QPDFObjectHandle::parse("<</A 1 /Type /Test /Subtype /Marvin>>"); | 2771 | + auto dict = QPDFObjectHandle::parse("<</A 1 /Type /Test /Subtype /Marvin>>"); |
| 2940 | assert(dict.isDictionaryOfType("/Test", "")); | 2772 | assert(dict.isDictionaryOfType("/Test", "")); |
| 2941 | assert(dict.isDictionaryOfType("/Test")); | 2773 | assert(dict.isDictionaryOfType("/Test")); |
| 2942 | assert(dict.isDictionaryOfType("/Test", "/Marvin")); | 2774 | assert(dict.isDictionaryOfType("/Test", "/Marvin")); |
| @@ -3016,9 +2848,8 @@ test_84(QPDF& pdf, char const* arg2) | @@ -3016,9 +2848,8 @@ test_84(QPDF& pdf, char const* arg2) | ||
| 3016 | std::cout << "custom progress reporter" << std::endl; | 2848 | std::cout << "custom progress reporter" << std::endl; |
| 3017 | { | 2849 | { |
| 3018 | QPDFJob j; | 2850 | QPDFJob j; |
| 3019 | - j.registerProgressReporter([](int p) { | ||
| 3020 | - std::cout << "custom write progress: " << p << "%" << std::endl; | ||
| 3021 | - }); | 2851 | + j.registerProgressReporter( |
| 2852 | + [](int p) { std::cout << "custom write progress: " << p << "%" << std::endl; }); | ||
| 3022 | j.config() | 2853 | j.config() |
| 3023 | ->inputFile("minimal.pdf") | 2854 | ->inputFile("minimal.pdf") |
| 3024 | ->outputFile("a.pdf") | 2855 | ->outputFile("a.pdf") |
| @@ -3071,10 +2902,7 @@ test_84(QPDF& pdf, char const* arg2) | @@ -3071,10 +2902,7 @@ test_84(QPDF& pdf, char const* arg2) | ||
| 3071 | #if (defined(__GNUC__) || defined(__clang__)) | 2902 | #if (defined(__GNUC__) || defined(__clang__)) |
| 3072 | # pragma GCC diagnostic pop | 2903 | # pragma GCC diagnostic pop |
| 3073 | #endif | 2904 | #endif |
| 3074 | - j.config() | ||
| 3075 | - ->inputFile("bad2.pdf") | ||
| 3076 | - ->showObject("4,0") | ||
| 3077 | - ->checkConfiguration(); | 2905 | + j.config()->inputFile("bad2.pdf")->showObject("4,0")->checkConfiguration(); |
| 3078 | std::cout << "calling run" << std::endl; | 2906 | std::cout << "calling run" << std::endl; |
| 3079 | j.run(); | 2907 | j.run(); |
| 3080 | std::cout << "captured stdout" << std::endl; | 2908 | std::cout << "captured stdout" << std::endl; |
| @@ -3091,12 +2919,9 @@ test_85(QPDF& pdf, char const* arg2) | @@ -3091,12 +2919,9 @@ test_85(QPDF& pdf, char const* arg2) | ||
| 3091 | 2919 | ||
| 3092 | auto oh_b = QPDFObjectHandle::newBool(false); | 2920 | auto oh_b = QPDFObjectHandle::newBool(false); |
| 3093 | auto oh_i = QPDFObjectHandle::newInteger(1); | 2921 | auto oh_i = QPDFObjectHandle::newInteger(1); |
| 3094 | - auto oh_i_maxplus = | ||
| 3095 | - QPDFObjectHandle::newInteger(QIntC::to_longlong(INT_MAX) + 1LL); | ||
| 3096 | - auto oh_i_umaxplus = | ||
| 3097 | - QPDFObjectHandle::newInteger(QIntC::to_longlong(UINT_MAX) + 1LL); | ||
| 3098 | - auto oh_i_minminus = | ||
| 3099 | - QPDFObjectHandle::newInteger(QIntC::to_longlong(INT_MIN) - 1LL); | 2922 | + auto oh_i_maxplus = QPDFObjectHandle::newInteger(QIntC::to_longlong(INT_MAX) + 1LL); |
| 2923 | + auto oh_i_umaxplus = QPDFObjectHandle::newInteger(QIntC::to_longlong(UINT_MAX) + 1LL); | ||
| 2924 | + auto oh_i_minminus = QPDFObjectHandle::newInteger(QIntC::to_longlong(INT_MIN) - 1LL); | ||
| 3100 | auto oh_i_neg = QPDFObjectHandle::newInteger(-1); | 2925 | auto oh_i_neg = QPDFObjectHandle::newInteger(-1); |
| 3101 | auto oh_r = QPDFObjectHandle::newReal("42.0"); | 2926 | auto oh_r = QPDFObjectHandle::newReal("42.0"); |
| 3102 | auto oh_n = QPDFObjectHandle::newName("/Test"); | 2927 | auto oh_n = QPDFObjectHandle::newName("/Test"); |
| @@ -3226,8 +3051,7 @@ test_88(QPDF& pdf, char const* arg2) | @@ -3226,8 +3051,7 @@ test_88(QPDF& pdf, char const* arg2) | ||
| 3226 | auto dict = QPDFObjectHandle::newDictionary(); | 3051 | auto dict = QPDFObjectHandle::newDictionary(); |
| 3227 | dict.replaceKey("/One", QPDFObjectHandle::newInteger(1)); | 3052 | dict.replaceKey("/One", QPDFObjectHandle::newInteger(1)); |
| 3228 | dict.replaceKey("/Two", QPDFObjectHandle::newInteger(2)); | 3053 | dict.replaceKey("/Two", QPDFObjectHandle::newInteger(2)); |
| 3229 | - auto three = | ||
| 3230 | - dict.replaceKeyAndGetNew("/Three", QPDFObjectHandle::newArray()); | 3054 | + auto three = dict.replaceKeyAndGetNew("/Three", QPDFObjectHandle::newArray()); |
| 3231 | three.appendItem("(a)"_qpdf); | 3055 | three.appendItem("(a)"_qpdf); |
| 3232 | three.appendItem("(b)"_qpdf); | 3056 | three.appendItem("(b)"_qpdf); |
| 3233 | auto newdict = three.appendItemAndGetNew(QPDFObjectHandle::newDictionary()); | 3057 | auto newdict = three.appendItemAndGetNew(QPDFObjectHandle::newDictionary()); |
| @@ -3236,8 +3060,7 @@ test_88(QPDF& pdf, char const* arg2) | @@ -3236,8 +3060,7 @@ test_88(QPDF& pdf, char const* arg2) | ||
| 3236 | dict.replaceKey("/Quack", "[1 2 3]"_qpdf); | 3060 | dict.replaceKey("/Quack", "[1 2 3]"_qpdf); |
| 3237 | auto quack = dict.replaceKeyAndGetOld("/Quack", "/Moo"_qpdf); | 3061 | auto quack = dict.replaceKeyAndGetOld("/Quack", "/Moo"_qpdf); |
| 3238 | assert(quack.unparse() == "[ 1 2 3 ]"); | 3062 | assert(quack.unparse() == "[ 1 2 3 ]"); |
| 3239 | - auto nothing = | ||
| 3240 | - dict.replaceKeyAndGetOld("/NotThere", QPDFObjectHandle::newNull()); | 3063 | + auto nothing = dict.replaceKeyAndGetOld("/NotThere", QPDFObjectHandle::newNull()); |
| 3241 | assert(nothing.isNull()); | 3064 | assert(nothing.isNull()); |
| 3242 | assert(dict.unparse() == R"( | 3065 | assert(dict.unparse() == R"( |
| 3243 | << | 3066 | << |
| @@ -3250,15 +3073,11 @@ test_88(QPDF& pdf, char const* arg2) | @@ -3250,15 +3073,11 @@ test_88(QPDF& pdf, char const* arg2) | ||
| 3250 | auto arr = dict.getKey("/Three"); | 3073 | auto arr = dict.getKey("/Three"); |
| 3251 | arr.insertItem(0, QPDFObjectHandle::newString("0")); | 3074 | arr.insertItem(0, QPDFObjectHandle::newString("0")); |
| 3252 | arr.insertItem(0, QPDFObjectHandle::newString("00")); | 3075 | arr.insertItem(0, QPDFObjectHandle::newString("00")); |
| 3253 | - assert( | ||
| 3254 | - arr.unparse() == | ||
| 3255 | - "[ (00) (0) (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse()); | 3076 | + assert(arr.unparse() == "[ (00) (0) (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse()); |
| 3256 | auto new_dict = arr.insertItemAndGetNew(1, "<< /P /Q /R /S >>"_qpdf); | 3077 | auto new_dict = arr.insertItemAndGetNew(1, "<< /P /Q /R /S >>"_qpdf); |
| 3257 | arr.eraseItem(2); | 3078 | arr.eraseItem(2); |
| 3258 | arr.eraseItem(0); | 3079 | arr.eraseItem(0); |
| 3259 | - assert( | ||
| 3260 | - arr.unparse() == | ||
| 3261 | - "[ << /P /Q /R /S >> (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse()); | 3080 | + assert(arr.unparse() == "[ << /P /Q /R /S >> (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse()); |
| 3262 | 3081 | ||
| 3263 | // new_dict shares internals with the one in the array. It has | 3082 | // new_dict shares internals with the one in the array. It has |
| 3264 | // always been this way, and there is code that relies on this | 3083 | // always been this way, and there is code that relies on this |
| @@ -3266,14 +3085,10 @@ test_88(QPDF& pdf, char const* arg2) | @@ -3266,14 +3085,10 @@ test_88(QPDF& pdf, char const* arg2) | ||
| 3266 | // again... | 3085 | // again... |
| 3267 | new_dict.removeKey("/R"); | 3086 | new_dict.removeKey("/R"); |
| 3268 | new_dict.replaceKey("/T", "/U"_qpdf); | 3087 | new_dict.replaceKey("/T", "/U"_qpdf); |
| 3269 | - assert( | ||
| 3270 | - arr.unparse() == | ||
| 3271 | - "[ << /P /Q /T /U >> (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse()); | 3088 | + assert(arr.unparse() == "[ << /P /Q /T /U >> (a) (b) << /Z /Y /X /W >> ]"_qpdf.unparse()); |
| 3272 | auto s = arr.eraseItemAndGetOld(1); | 3089 | auto s = arr.eraseItemAndGetOld(1); |
| 3273 | assert(s.unparse() == "(a)"); | 3090 | assert(s.unparse() == "(a)"); |
| 3274 | - assert( | ||
| 3275 | - arr.unparse() == | ||
| 3276 | - "[ << /P /Q /T /U >> (b) << /Z /Y /X /W >> ]"_qpdf.unparse()); | 3091 | + assert(arr.unparse() == "[ << /P /Q /T /U >> (b) << /Z /Y /X /W >> ]"_qpdf.unparse()); |
| 3277 | 3092 | ||
| 3278 | assert(new_dict.removeKeyAndGetOld("/M").isNull()); | 3093 | assert(new_dict.removeKeyAndGetOld("/M").isNull()); |
| 3279 | assert(new_dict.removeKeyAndGetOld("/P").unparse() == "/Q"); | 3094 | assert(new_dict.removeKeyAndGetOld("/P").unparse() == "/Q"); |
| @@ -3316,8 +3131,7 @@ test_91(QPDF& pdf, char const* arg2) | @@ -3316,8 +3131,7 @@ test_91(QPDF& pdf, char const* arg2) | ||
| 3316 | { | 3131 | { |
| 3317 | // Exercise the simpler version of writeJSON. | 3132 | // Exercise the simpler version of writeJSON. |
| 3318 | Pl_StdioFile p("stdout", stdout); | 3133 | Pl_StdioFile p("stdout", stdout); |
| 3319 | - pdf.writeJSON( | ||
| 3320 | - 2, &p, qpdf_dl_none, qpdf_sj_inline, "", std::set<std::string>()); | 3134 | + pdf.writeJSON(2, &p, qpdf_dl_none, qpdf_sj_inline, "", std::set<std::string>()); |
| 3321 | } | 3135 | } |
| 3322 | 3136 | ||
| 3323 | static void | 3137 | static void |
| @@ -3587,8 +3401,7 @@ runtest(int n, char const* filename1, char const* arg2) | @@ -3587,8 +3401,7 @@ runtest(int n, char const* filename1, char const* arg2) | ||
| 3587 | for (size_t i = 0; i < size; ++i) { | 3401 | for (size_t i = 0; i < size; ++i) { |
| 3588 | p[i] = static_cast<char>(p[i] ^ 0xcc); | 3402 | p[i] = static_cast<char>(p[i] ^ 0xcc); |
| 3589 | } | 3403 | } |
| 3590 | - pdf.processMemoryFile( | ||
| 3591 | - (std::string(filename1) + ".pdf").c_str(), p, size); | 3404 | + pdf.processMemoryFile((std::string(filename1) + ".pdf").c_str(), p, size); |
| 3592 | } else if (ignore_filename.count(n)) { | 3405 | } else if (ignore_filename.count(n)) { |
| 3593 | // Ignore filename argument entirely | 3406 | // Ignore filename argument entirely |
| 3594 | } else if (n == 89) { | 3407 | } else if (n == 89) { |
| @@ -3610,35 +3423,26 @@ runtest(int n, char const* filename1, char const* arg2) | @@ -3610,35 +3423,26 @@ runtest(int n, char const* filename1, char const* arg2) | ||
| 3610 | } | 3423 | } |
| 3611 | 3424 | ||
| 3612 | std::map<int, void (*)(QPDF&, char const*)> test_functions = { | 3425 | std::map<int, void (*)(QPDF&, char const*)> test_functions = { |
| 3613 | - {0, test_0_1}, {1, test_0_1}, {2, test_2}, {3, test_3}, | ||
| 3614 | - {4, test_4}, {5, test_5}, {6, test_6}, {7, test_7}, | ||
| 3615 | - {8, test_8}, {9, test_9}, {10, test_10}, {11, test_11}, | ||
| 3616 | - {12, test_12}, {13, test_13}, {14, test_14}, {15, test_15}, | ||
| 3617 | - {16, test_16}, {17, test_17}, {18, test_18}, {19, test_19}, | ||
| 3618 | - {20, test_20}, {21, test_21}, {22, test_22}, {23, test_23}, | ||
| 3619 | - {24, test_24}, {25, test_25}, {26, test_26}, {27, test_27}, | ||
| 3620 | - {28, test_28}, {29, test_29}, {30, test_30}, {31, test_31}, | ||
| 3621 | - {32, test_32}, {33, test_33}, {34, test_34}, {35, test_35}, | ||
| 3622 | - {36, test_36}, {37, test_37}, {38, test_38}, {39, test_39}, | ||
| 3623 | - {40, test_40}, {41, test_41}, {42, test_42}, {43, test_43}, | ||
| 3624 | - {44, test_44}, {45, test_45}, {46, test_46}, {47, test_47}, | ||
| 3625 | - {48, test_48}, {49, test_49}, {50, test_50}, {51, test_51}, | ||
| 3626 | - {52, test_52}, {53, test_53}, {54, test_54}, {55, test_55}, | ||
| 3627 | - {56, test_56}, {57, test_57}, {58, test_58}, {59, test_59}, | ||
| 3628 | - {60, test_60}, {61, test_61}, {62, test_62}, {63, test_63}, | ||
| 3629 | - {64, test_64}, {65, test_65}, {66, test_66}, {67, test_67}, | ||
| 3630 | - {68, test_68}, {69, test_69}, {70, test_70}, {71, test_71}, | ||
| 3631 | - {72, test_72}, {73, test_73}, {74, test_74}, {75, test_75}, | ||
| 3632 | - {76, test_76}, {77, test_77}, {78, test_78}, {79, test_79}, | ||
| 3633 | - {80, test_80}, {81, test_81}, {82, test_82}, {83, test_83}, | ||
| 3634 | - {84, test_84}, {85, test_85}, {86, test_86}, {87, test_87}, | ||
| 3635 | - {88, test_88}, {89, test_89}, {90, test_90}, {91, test_91}, | ||
| 3636 | - {92, test_92}, {93, test_93}, {94, test_94}, {95, test_95}}; | 3426 | + {0, test_0_1}, {1, test_0_1}, {2, test_2}, {3, test_3}, {4, test_4}, {5, test_5}, |
| 3427 | + {6, test_6}, {7, test_7}, {8, test_8}, {9, test_9}, {10, test_10}, {11, test_11}, | ||
| 3428 | + {12, test_12}, {13, test_13}, {14, test_14}, {15, test_15}, {16, test_16}, {17, test_17}, | ||
| 3429 | + {18, test_18}, {19, test_19}, {20, test_20}, {21, test_21}, {22, test_22}, {23, test_23}, | ||
| 3430 | + {24, test_24}, {25, test_25}, {26, test_26}, {27, test_27}, {28, test_28}, {29, test_29}, | ||
| 3431 | + {30, test_30}, {31, test_31}, {32, test_32}, {33, test_33}, {34, test_34}, {35, test_35}, | ||
| 3432 | + {36, test_36}, {37, test_37}, {38, test_38}, {39, test_39}, {40, test_40}, {41, test_41}, | ||
| 3433 | + {42, test_42}, {43, test_43}, {44, test_44}, {45, test_45}, {46, test_46}, {47, test_47}, | ||
| 3434 | + {48, test_48}, {49, test_49}, {50, test_50}, {51, test_51}, {52, test_52}, {53, test_53}, | ||
| 3435 | + {54, test_54}, {55, test_55}, {56, test_56}, {57, test_57}, {58, test_58}, {59, test_59}, | ||
| 3436 | + {60, test_60}, {61, test_61}, {62, test_62}, {63, test_63}, {64, test_64}, {65, test_65}, | ||
| 3437 | + {66, test_66}, {67, test_67}, {68, test_68}, {69, test_69}, {70, test_70}, {71, test_71}, | ||
| 3438 | + {72, test_72}, {73, test_73}, {74, test_74}, {75, test_75}, {76, test_76}, {77, test_77}, | ||
| 3439 | + {78, test_78}, {79, test_79}, {80, test_80}, {81, test_81}, {82, test_82}, {83, test_83}, | ||
| 3440 | + {84, test_84}, {85, test_85}, {86, test_86}, {87, test_87}, {88, test_88}, {89, test_89}, | ||
| 3441 | + {90, test_90}, {91, test_91}, {92, test_92}, {93, test_93}, {94, test_94}, {95, test_95}}; | ||
| 3637 | 3442 | ||
| 3638 | auto fn = test_functions.find(n); | 3443 | auto fn = test_functions.find(n); |
| 3639 | if (fn == test_functions.end()) { | 3444 | if (fn == test_functions.end()) { |
| 3640 | - throw std::runtime_error( | ||
| 3641 | - std::string("invalid test ") + QUtil::int_to_string(n)); | 3445 | + throw std::runtime_error(std::string("invalid test ") + QUtil::int_to_string(n)); |
| 3642 | } | 3446 | } |
| 3643 | (fn->second)(pdf, arg2); | 3447 | (fn->second)(pdf, arg2); |
| 3644 | 3448 |
qpdf/test_large_file.cc
| @@ -53,9 +53,8 @@ static inline unsigned char | @@ -53,9 +53,8 @@ static inline unsigned char | ||
| 53 | get_pixel_color(size_t n, size_t row) | 53 | get_pixel_color(size_t n, size_t row) |
| 54 | { | 54 | { |
| 55 | return ( | 55 | return ( |
| 56 | - (n & (1LLU << (nstripes - 1LLU - row))) | ||
| 57 | - ? static_cast<unsigned char>('\xc0') | ||
| 58 | - : static_cast<unsigned char>('\x40')); | 56 | + (n & (1LLU << (nstripes - 1LLU - row))) ? static_cast<unsigned char>('\xc0') |
| 57 | + : static_cast<unsigned char>('\x40')); | ||
| 59 | } | 58 | } |
| 60 | 59 | ||
| 61 | class ImageChecker: public Pipeline | 60 | class ImageChecker: public Pipeline |
| @@ -97,8 +96,7 @@ void | @@ -97,8 +96,7 @@ void | ||
| 97 | ImageChecker::finish() | 96 | ImageChecker::finish() |
| 98 | { | 97 | { |
| 99 | if (!okay) { | 98 | if (!okay) { |
| 100 | - std::cout << "errors found checking image data for page " << n | ||
| 101 | - << std::endl; | 99 | + std::cout << "errors found checking image data for page " << n << std::endl; |
| 102 | } | 100 | } |
| 103 | } | 101 | } |
| 104 | 102 | ||
| @@ -107,8 +105,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider | @@ -107,8 +105,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider | ||
| 107 | public: | 105 | public: |
| 108 | ImageProvider(size_t n); | 106 | ImageProvider(size_t n); |
| 109 | virtual ~ImageProvider() = default; | 107 | virtual ~ImageProvider() = default; |
| 110 | - virtual void | ||
| 111 | - provideStreamData(int objid, int generation, Pipeline* pipeline); | 108 | + virtual void provideStreamData(int objid, int generation, Pipeline* pipeline); |
| 112 | 109 | ||
| 113 | private: | 110 | private: |
| 114 | size_t n; | 111 | size_t n; |
| @@ -137,8 +134,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline) | @@ -137,8 +134,7 @@ ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline) | ||
| 137 | void | 134 | void |
| 138 | usage() | 135 | usage() |
| 139 | { | 136 | { |
| 140 | - std::cerr << "Usage: " << whoami << " {read|write} {large|small} outfile" | ||
| 141 | - << std::endl; | 137 | + std::cerr << "Usage: " << whoami << " {read|write} {large|small} outfile" << std::endl; |
| 142 | exit(2); | 138 | exit(2); |
| 143 | } | 139 | } |
| 144 | 140 | ||
| @@ -153,8 +149,7 @@ set_parameters(bool large) | @@ -153,8 +149,7 @@ set_parameters(bool large) | ||
| 153 | std::string | 149 | std::string |
| 154 | generate_page_contents(size_t pageno) | 150 | generate_page_contents(size_t pageno) |
| 155 | { | 151 | { |
| 156 | - std::string contents = "BT /F1 24 Tf 72 720 Td (page " + | ||
| 157 | - QUtil::uint_to_string(pageno) + | 152 | + std::string contents = "BT /F1 24 Tf 72 720 Td (page " + QUtil::uint_to_string(pageno) + |
| 158 | ") Tj ET\n" | 153 | ") Tj ET\n" |
| 159 | "q 468 0 0 468 72 72 cm /Im1 Do Q\n"; | 154 | "q 468 0 0 468 72 72 cm /Im1 Do Q\n"; |
| 160 | return contents; | 155 | return contents; |
| @@ -185,16 +180,14 @@ create_pdf(char const* filename) | @@ -185,16 +180,14 @@ create_pdf(char const* filename) | ||
| 185 | 180 | ||
| 186 | pdf.emptyPDF(); | 181 | pdf.emptyPDF(); |
| 187 | 182 | ||
| 188 | - QPDFObjectHandle font = | ||
| 189 | - pdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); | 183 | + QPDFObjectHandle font = pdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); |
| 190 | font.replaceKey("/Type", newName("/Font")); | 184 | font.replaceKey("/Type", newName("/Font")); |
| 191 | font.replaceKey("/Subtype", newName("/Type1")); | 185 | font.replaceKey("/Subtype", newName("/Type1")); |
| 192 | font.replaceKey("/Name", newName("/F1")); | 186 | font.replaceKey("/Name", newName("/F1")); |
| 193 | font.replaceKey("/BaseFont", newName("/Helvetica")); | 187 | font.replaceKey("/BaseFont", newName("/Helvetica")); |
| 194 | font.replaceKey("/Encoding", newName("/WinAnsiEncoding")); | 188 | font.replaceKey("/Encoding", newName("/WinAnsiEncoding")); |
| 195 | 189 | ||
| 196 | - QPDFObjectHandle procset = | ||
| 197 | - pdf.makeIndirectObject(QPDFObjectHandle::newArray()); | 190 | + QPDFObjectHandle procset = pdf.makeIndirectObject(QPDFObjectHandle::newArray()); |
| 198 | procset.appendItem(newName("/PDF")); | 191 | procset.appendItem(newName("/PDF")); |
| 199 | procset.appendItem(newName("/Text")); | 192 | procset.appendItem(newName("/Text")); |
| 200 | procset.appendItem(newName("/ImageC")); | 193 | procset.appendItem(newName("/ImageC")); |
| @@ -220,8 +213,7 @@ create_pdf(char const* filename) | @@ -220,8 +213,7 @@ create_pdf(char const* filename) | ||
| 220 | image_dict.replaceKey("/Height", newInteger(height)); | 213 | image_dict.replaceKey("/Height", newInteger(height)); |
| 221 | auto* p = new ImageProvider(pageno); | 214 | auto* p = new ImageProvider(pageno); |
| 222 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p); | 215 | std::shared_ptr<QPDFObjectHandle::StreamDataProvider> provider(p); |
| 223 | - image.replaceStreamData( | ||
| 224 | - provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); | 216 | + image.replaceStreamData(provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| 225 | 217 | ||
| 226 | QPDFObjectHandle xobject = QPDFObjectHandle::newDictionary(); | 218 | QPDFObjectHandle xobject = QPDFObjectHandle::newDictionary(); |
| 227 | xobject.replaceKey("/Im1", image); | 219 | xobject.replaceKey("/Im1", image); |
| @@ -233,8 +225,7 @@ create_pdf(char const* filename) | @@ -233,8 +225,7 @@ create_pdf(char const* filename) | ||
| 233 | 225 | ||
| 234 | QPDFObjectHandle contents = create_page_contents(pdf, pageno); | 226 | QPDFObjectHandle contents = create_page_contents(pdf, pageno); |
| 235 | 227 | ||
| 236 | - QPDFObjectHandle page = | ||
| 237 | - pdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); | 228 | + QPDFObjectHandle page = pdf.makeIndirectObject(QPDFObjectHandle::newDictionary()); |
| 238 | page.replaceKey("/Type", newName("/Page")); | 229 | page.replaceKey("/Type", newName("/Page")); |
| 239 | page.replaceKey("/MediaBox", mediabox); | 230 | page.replaceKey("/MediaBox", mediabox); |
| 240 | page.replaceKey("/Contents", contents); | 231 | page.replaceKey("/Contents", contents); |
| @@ -259,16 +250,14 @@ check_page_contents(size_t pageno, QPDFObjectHandle page) | @@ -259,16 +250,14 @@ check_page_contents(size_t pageno, QPDFObjectHandle page) | ||
| 259 | std::string expected_contents = generate_page_contents(pageno); | 250 | std::string expected_contents = generate_page_contents(pageno); |
| 260 | if (expected_contents != actual_contents) { | 251 | if (expected_contents != actual_contents) { |
| 261 | std::cout << "page contents wrong for page " << pageno << std::endl | 252 | std::cout << "page contents wrong for page " << pageno << std::endl |
| 262 | - << "ACTUAL: " << actual_contents | ||
| 263 | - << "EXPECTED: " << expected_contents << "----\n"; | 253 | + << "ACTUAL: " << actual_contents << "EXPECTED: " << expected_contents << "----\n"; |
| 264 | } | 254 | } |
| 265 | } | 255 | } |
| 266 | 256 | ||
| 267 | static void | 257 | static void |
| 268 | check_image(size_t pageno, QPDFObjectHandle page) | 258 | check_image(size_t pageno, QPDFObjectHandle page) |
| 269 | { | 259 | { |
| 270 | - QPDFObjectHandle image = | ||
| 271 | - page.getKey("/Resources").getKey("/XObject").getKey("/Im1"); | 260 | + QPDFObjectHandle image = page.getKey("/Resources").getKey("/XObject").getKey("/Im1"); |
| 272 | ImageChecker ic(pageno); | 261 | ImageChecker ic(pageno); |
| 273 | image.pipeStreamData(&ic, 0, qpdf_dl_specialized); | 262 | image.pipeStreamData(&ic, 0, qpdf_dl_specialized); |
| 274 | } | 263 | } |
qpdf/test_parsedoffset.cc
| @@ -20,12 +20,10 @@ std::string | @@ -20,12 +20,10 @@ std::string | ||
| 20 | make_objdesc(qpdf_offset_t offset, QPDFObjectHandle obj) | 20 | make_objdesc(qpdf_offset_t offset, QPDFObjectHandle obj) |
| 21 | { | 21 | { |
| 22 | std::stringstream ss; | 22 | std::stringstream ss; |
| 23 | - ss << "offset = " << offset << " (0x" << std::hex << offset << std::dec | ||
| 24 | - << "), "; | 23 | + ss << "offset = " << offset << " (0x" << std::hex << offset << std::dec << "), "; |
| 25 | 24 | ||
| 26 | if (obj.isIndirect()) { | 25 | if (obj.isIndirect()) { |
| 27 | - ss << "indirect " << obj.getObjectID() << "/" << obj.getGeneration() | ||
| 28 | - << ", "; | 26 | + ss << "indirect " << obj.getObjectID() << "/" << obj.getGeneration() << ", "; |
| 29 | } else { | 27 | } else { |
| 30 | ss << "direct, "; | 28 | ss << "direct, "; |
| 31 | } | 29 | } |
| @@ -42,8 +40,7 @@ walk( | @@ -42,8 +40,7 @@ walk( | ||
| 42 | std::vector<std::vector<std::pair<qpdf_offset_t, std::string>>>& result) | 40 | std::vector<std::vector<std::pair<qpdf_offset_t, std::string>>>& result) |
| 43 | { | 41 | { |
| 44 | qpdf_offset_t offset = obj.getParsedOffset(); | 42 | qpdf_offset_t offset = obj.getParsedOffset(); |
| 45 | - std::pair<qpdf_offset_t, std::string> p = | ||
| 46 | - std::make_pair(offset, make_objdesc(offset, obj)); | 43 | + std::pair<qpdf_offset_t, std::string> p = std::make_pair(offset, make_objdesc(offset, obj)); |
| 47 | 44 | ||
| 48 | if (result.size() < stream_number + 1) { | 45 | if (result.size() < stream_number + 1) { |
| 49 | result.resize(stream_number + 1); | 46 | result.resize(stream_number + 1); |
| @@ -73,9 +70,7 @@ walk( | @@ -73,9 +70,7 @@ walk( | ||
| 73 | } | 70 | } |
| 74 | 71 | ||
| 75 | void | 72 | void |
| 76 | -process( | ||
| 77 | - std::string fn, | ||
| 78 | - std::vector<std::vector<std::pair<qpdf_offset_t, std::string>>>& result) | 73 | +process(std::string fn, std::vector<std::vector<std::pair<qpdf_offset_t, std::string>>>& result) |
| 79 | { | 74 | { |
| 80 | QPDF qpdf; | 75 | QPDF qpdf; |
| 81 | qpdf.processFile(fn.c_str()); | 76 | qpdf.processFile(fn.c_str()); |
| @@ -93,8 +88,8 @@ process( | @@ -93,8 +88,8 @@ process( | ||
| 93 | 88 | ||
| 94 | switch (xref.getType()) { | 89 | switch (xref.getType()) { |
| 95 | case 0: | 90 | case 0: |
| 96 | - std::cerr << oh.getObjectID() << "/" << oh.getGeneration() | ||
| 97 | - << " xref entry is free" << std::endl; | 91 | + std::cerr << oh.getObjectID() << "/" << oh.getGeneration() << " xref entry is free" |
| 92 | + << std::endl; | ||
| 98 | std::exit(2); | 93 | std::exit(2); |
| 99 | case 1: | 94 | case 1: |
| 100 | stream_number = 0; | 95 | stream_number = 0; |
| @@ -133,8 +128,7 @@ main(int argc, char* argv[]) | @@ -133,8 +128,7 @@ main(int argc, char* argv[]) | ||
| 133 | if (i == 0) { | 128 | if (i == 0) { |
| 134 | std::cout << "--- objects not in streams ---" << std::endl; | 129 | std::cout << "--- objects not in streams ---" << std::endl; |
| 135 | } else { | 130 | } else { |
| 136 | - std::cout << "--- objects in stream " << i << " ---" | ||
| 137 | - << std::endl; | 131 | + std::cout << "--- objects in stream " << i << " ---" << std::endl; |
| 138 | } | 132 | } |
| 139 | 133 | ||
| 140 | for (auto const& iter: table[i]) { | 134 | for (auto const& iter: table[i]) { |
qpdf/test_pdf_unicode.cc
| @@ -28,8 +28,7 @@ main(int argc, char* argv[]) | @@ -28,8 +28,7 @@ main(int argc, char* argv[]) | ||
| 28 | char const* infilename = argv[1]; | 28 | char const* infilename = argv[1]; |
| 29 | for (auto const& line: QUtil::read_lines_from_file(infilename)) { | 29 | for (auto const& line: QUtil::read_lines_from_file(infilename)) { |
| 30 | QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line); | 30 | QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line); |
| 31 | - std::cout << str.getUTF8Value() << " // " << str.unparseBinary() | ||
| 32 | - << std::endl; | 31 | + std::cout << str.getUTF8Value() << " // " << str.unparseBinary() << std::endl; |
| 33 | } | 32 | } |
| 34 | return 0; | 33 | return 0; |
| 35 | } | 34 | } |
qpdf/test_renumber.cc
| @@ -117,9 +117,7 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b) | @@ -117,9 +117,7 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b) | ||
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | bool | 119 | bool |
| 120 | -compare_xref_table( | ||
| 121 | - std::map<QPDFObjGen, QPDFXRefEntry> a, | ||
| 122 | - std::map<QPDFObjGen, QPDFXRefEntry> b) | 120 | +compare_xref_table(std::map<QPDFObjGen, QPDFXRefEntry> a, std::map<QPDFObjGen, QPDFXRefEntry> b) |
| 123 | { | 121 | { |
| 124 | if (a.size() != b.size()) { | 122 | if (a.size() != b.size()) { |
| 125 | std::cerr << "different size" << std::endl; | 123 | std::cerr << "different size" << std::endl; |
| @@ -127,8 +125,8 @@ compare_xref_table( | @@ -127,8 +125,8 @@ compare_xref_table( | ||
| 127 | } | 125 | } |
| 128 | 126 | ||
| 129 | for (auto const& iter: a) { | 127 | for (auto const& iter: a) { |
| 130 | - std::cout << "xref entry for " << iter.first.getObj() << "/" | ||
| 131 | - << iter.first.getGen() << std::endl; | 128 | + std::cout << "xref entry for " << iter.first.getObj() << "/" << iter.first.getGen() |
| 129 | + << std::endl; | ||
| 132 | 130 | ||
| 133 | if (b.count(iter.first) == 0) { | 131 | if (b.count(iter.first) == 0) { |
| 134 | std::cerr << "not found" << std::endl; | 132 | std::cerr << "not found" << std::endl; |
| @@ -222,20 +220,16 @@ main(int argc, char* argv[]) | @@ -222,20 +220,16 @@ main(int argc, char* argv[]) | ||
| 222 | 220 | ||
| 223 | QPDF qpdf_ren; | 221 | QPDF qpdf_ren; |
| 224 | qpdf_ren.processMemoryFile( | 222 | qpdf_ren.processMemoryFile( |
| 225 | - "renumbered", | ||
| 226 | - reinterpret_cast<char*>(buf->getBuffer()), | ||
| 227 | - buf->getSize()); | 223 | + "renumbered", reinterpret_cast<char*>(buf->getBuffer()), buf->getSize()); |
| 228 | std::map<QPDFObjGen, QPDFXRefEntry> xrefs_ren = qpdf_ren.getXRefTable(); | 224 | std::map<QPDFObjGen, QPDFXRefEntry> xrefs_ren = qpdf_ren.getXRefTable(); |
| 229 | 225 | ||
| 230 | - std::cout << "--- compare between input and renumbered objects ---" | ||
| 231 | - << std::endl; | 226 | + std::cout << "--- compare between input and renumbered objects ---" << std::endl; |
| 232 | for (auto const& iter: objs_in) { | 227 | for (auto const& iter: objs_in) { |
| 233 | QPDFObjGen og_in = iter.getObjGen(); | 228 | QPDFObjGen og_in = iter.getObjGen(); |
| 234 | QPDFObjGen og_ren = w.getRenumberedObjGen(og_in); | 229 | QPDFObjGen og_ren = w.getRenumberedObjGen(og_in); |
| 235 | 230 | ||
| 236 | - std::cout << "input " << og_in.getObj() << "/" << og_in.getGen() | ||
| 237 | - << " -> renumbered " << og_ren.getObj() << "/" | ||
| 238 | - << og_ren.getGen() << std::endl; | 231 | + std::cout << "input " << og_in.getObj() << "/" << og_in.getGen() << " -> renumbered " |
| 232 | + << og_ren.getObj() << "/" << og_ren.getGen() << std::endl; | ||
| 239 | 233 | ||
| 240 | if (og_ren.getObj() == 0) { | 234 | if (og_ren.getObj() == 0) { |
| 241 | std::cout << "deleted" << std::endl; | 235 | std::cout << "deleted" << std::endl; |
| @@ -249,8 +243,7 @@ main(int argc, char* argv[]) | @@ -249,8 +243,7 @@ main(int argc, char* argv[]) | ||
| 249 | } | 243 | } |
| 250 | std::cout << "complete" << std::endl; | 244 | std::cout << "complete" << std::endl; |
| 251 | 245 | ||
| 252 | - std::cout << "--- compare between written and reloaded xref tables ---" | ||
| 253 | - << std::endl; | 246 | + std::cout << "--- compare between written and reloaded xref tables ---" << std::endl; |
| 254 | if (!compare_xref_table(xrefs_w, xrefs_ren)) { | 247 | if (!compare_xref_table(xrefs_w, xrefs_ren)) { |
| 255 | std::cerr << "different" << std::endl; | 248 | std::cerr << "different" << std::endl; |
| 256 | std::exit(2); | 249 | std::exit(2); |
qpdf/test_tokenizer.cc
| @@ -16,8 +16,7 @@ static char const* whoami = nullptr; | @@ -16,8 +16,7 @@ static char const* whoami = nullptr; | ||
| 16 | void | 16 | void |
| 17 | usage() | 17 | usage() |
| 18 | { | 18 | { |
| 19 | - std::cerr << "Usage: " << whoami | ||
| 20 | - << " [-maxlen len | -no-ignorable] filename" << std::endl; | 19 | + std::cerr << "Usage: " << whoami << " [-maxlen len | -no-ignorable] filename" << std::endl; |
| 21 | exit(2); | 20 | exit(2); |
| 22 | } | 21 | } |
| 23 | 22 | ||
| @@ -102,9 +101,7 @@ sanitize(std::string const& value) | @@ -102,9 +101,7 @@ sanitize(std::string const& value) | ||
| 102 | if ((iter >= 32) && (iter <= 126)) { | 101 | if ((iter >= 32) && (iter <= 126)) { |
| 103 | result.append(1, iter); | 102 | result.append(1, iter); |
| 104 | } else { | 103 | } else { |
| 105 | - result += "\\x" + | ||
| 106 | - QUtil::int_to_string_base( | ||
| 107 | - static_cast<unsigned char>(iter), 16, 2); | 104 | + result += "\\x" + QUtil::int_to_string_base(static_cast<unsigned char>(iter), 16, 2); |
| 108 | } | 105 | } |
| 109 | } | 106 | } |
| 110 | return result; | 107 | return result; |
| @@ -145,8 +142,8 @@ dump_tokens( | @@ -145,8 +142,8 @@ dump_tokens( | ||
| 145 | } | 142 | } |
| 146 | qpdf_offset_t inline_image_offset = 0; | 143 | qpdf_offset_t inline_image_offset = 0; |
| 147 | while (!done) { | 144 | while (!done) { |
| 148 | - QPDFTokenizer::Token token = tokenizer.readToken( | ||
| 149 | - is, "test", true, inline_image_offset ? 0 : max_len); | 145 | + QPDFTokenizer::Token token = |
| 146 | + tokenizer.readToken(is, "test", true, inline_image_offset ? 0 : max_len); | ||
| 150 | if (inline_image_offset && (token.getType() == QPDFTokenizer::tt_bad)) { | 147 | if (inline_image_offset && (token.getType() == QPDFTokenizer::tt_bad)) { |
| 151 | std::cout << "EI not found; resuming normal scanning" << std::endl; | 148 | std::cout << "EI not found; resuming normal scanning" << std::endl; |
| 152 | is->seek(inline_image_offset, SEEK_SET); | 149 | is->seek(inline_image_offset, SEEK_SET); |
| @@ -167,12 +164,10 @@ dump_tokens( | @@ -167,12 +164,10 @@ dump_tokens( | ||
| 167 | std::cout << " (" << token.getErrorMessage() << ")"; | 164 | std::cout << " (" << token.getErrorMessage() << ")"; |
| 168 | } | 165 | } |
| 169 | std::cout << std::endl; | 166 | std::cout << std::endl; |
| 170 | - if (skip_streams && | ||
| 171 | - (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream"))) { | 167 | + if (skip_streams && (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream"))) { |
| 172 | try_skipping(tokenizer, is, max_len, "endstream", f1); | 168 | try_skipping(tokenizer, is, max_len, "endstream", f1); |
| 173 | } else if ( | 169 | } else if ( |
| 174 | - skip_inline_images && | ||
| 175 | - (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "ID"))) { | 170 | + skip_inline_images && (token == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "ID"))) { |
| 176 | char ch; | 171 | char ch; |
| 177 | is->read(&ch, 1); | 172 | is->read(&ch, 1); |
| 178 | tokenizer.expectInlineImage(is); | 173 | tokenizer.expectInlineImage(is); |
| @@ -206,12 +201,7 @@ process(char const* filename, bool include_ignorable, size_t max_len) | @@ -206,12 +201,7 @@ process(char const* filename, bool include_ignorable, size_t max_len) | ||
| 206 | auto* bis = new BufferInputSource("content data", content_data.get()); | 201 | auto* bis = new BufferInputSource("content data", content_data.get()); |
| 207 | is = std::shared_ptr<InputSource>(bis); | 202 | is = std::shared_ptr<InputSource>(bis); |
| 208 | dump_tokens( | 203 | dump_tokens( |
| 209 | - is, | ||
| 210 | - "PAGE " + QUtil::int_to_string(pageno), | ||
| 211 | - max_len, | ||
| 212 | - include_ignorable, | ||
| 213 | - false, | ||
| 214 | - true); | 204 | + is, "PAGE " + QUtil::int_to_string(pageno), max_len, include_ignorable, false, true); |
| 215 | } | 205 | } |
| 216 | 206 | ||
| 217 | // Tokenize object streams | 207 | // Tokenize object streams |
qpdf/test_xref.cc
| @@ -17,23 +17,18 @@ main(int argc, char* argv[]) | @@ -17,23 +17,18 @@ main(int argc, char* argv[]) | ||
| 17 | qpdf.processFile(argv[1]); | 17 | qpdf.processFile(argv[1]); |
| 18 | 18 | ||
| 19 | for (auto const& iter: qpdf.getXRefTable()) { | 19 | for (auto const& iter: qpdf.getXRefTable()) { |
| 20 | - std::cout << iter.first.getObj() << "/" << iter.first.getGen() | ||
| 21 | - << ", "; | 20 | + std::cout << iter.first.getObj() << "/" << iter.first.getGen() << ", "; |
| 22 | switch (iter.second.getType()) { | 21 | switch (iter.second.getType()) { |
| 23 | case 0: | 22 | case 0: |
| 24 | std::cout << "free entry" << std::endl; | 23 | std::cout << "free entry" << std::endl; |
| 25 | break; | 24 | break; |
| 26 | case 1: | 25 | case 1: |
| 27 | - std::cout << "uncompressed, offset = " | ||
| 28 | - << iter.second.getOffset() << " (0x" << std::hex | ||
| 29 | - << iter.second.getOffset() << std::dec << ")" | ||
| 30 | - << std::endl; | 26 | + std::cout << "uncompressed, offset = " << iter.second.getOffset() << " (0x" |
| 27 | + << std::hex << iter.second.getOffset() << std::dec << ")" << std::endl; | ||
| 31 | break; | 28 | break; |
| 32 | case 2: | 29 | case 2: |
| 33 | - std::cout << "compressed, stream number = " | ||
| 34 | - << iter.second.getObjStreamNumber() | ||
| 35 | - << ", stream index = " | ||
| 36 | - << iter.second.getObjStreamIndex() << std::endl; | 30 | + std::cout << "compressed, stream number = " << iter.second.getObjStreamNumber() |
| 31 | + << ", stream index = " << iter.second.getObjStreamIndex() << std::endl; | ||
| 37 | break; | 32 | break; |
| 38 | default: | 33 | default: |
| 39 | std::cerr << "unknown" << std::endl; | 34 | std::cerr << "unknown" << std::endl; |
zlib-flate/zlib-flate.cc
| @@ -14,8 +14,7 @@ static char const* whoami = nullptr; | @@ -14,8 +14,7 @@ static char const* whoami = nullptr; | ||
| 14 | void | 14 | void |
| 15 | usage() | 15 | usage() |
| 16 | { | 16 | { |
| 17 | - std::cerr << "Usage: " << whoami << " { -uncompress | -compress[=n] }" | ||
| 18 | - << std::endl | 17 | + std::cerr << "Usage: " << whoami << " { -uncompress | -compress[=n] }" << std::endl |
| 19 | << "If n is specified with -compress, it is a" | 18 | << "If n is specified with -compress, it is a" |
| 20 | << " zlib compression level from" << std::endl | 19 | << " zlib compression level from" << std::endl |
| 21 | << "1 to 9 where lower numbers are faster and" | 20 | << "1 to 9 where lower numbers are faster and" |
| @@ -34,8 +33,7 @@ main(int argc, char* argv[]) | @@ -34,8 +33,7 @@ main(int argc, char* argv[]) | ||
| 34 | } | 33 | } |
| 35 | 34 | ||
| 36 | if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) { | 35 | if ((argc == 2) && (strcmp(argv[1], "--version") == 0)) { |
| 37 | - std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() | ||
| 38 | - << std::endl; | 36 | + std::cout << whoami << " from qpdf version " << QPDF::QPDFVersion() << std::endl; |
| 39 | exit(0); | 37 | exit(0); |
| 40 | } | 38 | } |
| 41 | 39 | ||
| @@ -64,8 +62,7 @@ main(int argc, char* argv[]) | @@ -64,8 +62,7 @@ main(int argc, char* argv[]) | ||
| 64 | bool warn = false; | 62 | bool warn = false; |
| 65 | flate->setWarnCallback([&warn](char const* msg, int code) { | 63 | flate->setWarnCallback([&warn](char const* msg, int code) { |
| 66 | warn = true; | 64 | warn = true; |
| 67 | - std::cerr << whoami << ": WARNING: zlib code " << code | ||
| 68 | - << ", msg = " << msg << std::endl; | 65 | + std::cerr << whoami << ": WARNING: zlib code " << code << ", msg = " << msg << std::endl; |
| 69 | }); | 66 | }); |
| 70 | 67 | ||
| 71 | try { | 68 | try { |