Commit 089b817b5b8d2b6f452b1f64f8df51e7df69268f
1 parent
b520c150
Refactor `QPDFJob` configuration: replace direct member access with `Doc::Config…
…` methods, update usage across codebase, and streamline related logic.
Showing
7 changed files
with
21 additions
and
39 deletions
include/qpdf/QPDFJob.hh
libqpdf/QPDFJob.cc
| ... | ... | @@ -477,7 +477,7 @@ QPDFJob::writeQPDF(QPDF& pdf) |
| 477 | 477 | if (!pdf.getWarnings().empty()) { |
| 478 | 478 | m->warnings = true; |
| 479 | 479 | } |
| 480 | - if (m->warnings && (!m->suppress_warnings)) { | |
| 480 | + if (m->warnings && !m->qcf.suppress_warnings()) { | |
| 481 | 481 | if (createsOutput()) { |
| 482 | 482 | *m->log->getWarn() |
| 483 | 483 | << m->message_prefix |
| ... | ... | @@ -635,24 +635,6 @@ QPDFJob::getEncryptionStatus() |
| 635 | 635 | return m->encryption_status; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | -void | |
| 639 | -QPDFJob::setQPDFOptions(QPDF& pdf) | |
| 640 | -{ | |
| 641 | - pdf.setLogger(m->log); | |
| 642 | - if (m->ignore_xref_streams) { | |
| 643 | - pdf.setIgnoreXRefStreams(true); | |
| 644 | - } | |
| 645 | - if (m->suppress_recovery) { | |
| 646 | - pdf.setAttemptRecovery(false); | |
| 647 | - } | |
| 648 | - if (m->password_is_hex_key) { | |
| 649 | - pdf.setPasswordIsHexKey(true); | |
| 650 | - } | |
| 651 | - if (m->suppress_warnings) { | |
| 652 | - pdf.setSuppressWarnings(true); | |
| 653 | - } | |
| 654 | -} | |
| 655 | - | |
| 656 | 638 | static std::string |
| 657 | 639 | show_bool(bool v) |
| 658 | 640 | { |
| ... | ... | @@ -737,7 +719,6 @@ QPDFJob::doCheck(QPDF& pdf) |
| 737 | 719 | bool okay = true; |
| 738 | 720 | auto& cout = *m->log->getInfo(); |
| 739 | 721 | cout << "checking " << m->infile_name() << "\n"; |
| 740 | - pdf.doc().config().check_mode(true); | |
| 741 | 722 | try { |
| 742 | 723 | int extension_level = pdf.getExtensionLevel(); |
| 743 | 724 | cout << "PDF Version: " << pdf.getPDFVersion(); |
| ... | ... | @@ -1728,7 +1709,7 @@ QPDFJob::doProcessOnce( |
| 1728 | 1709 | bool main_input) |
| 1729 | 1710 | { |
| 1730 | 1711 | pdf = std::make_unique<QPDF>(); |
| 1731 | - setQPDFOptions(*pdf); | |
| 1712 | + pdf->doc().config(m->qcf.log(m->log)); | |
| 1732 | 1713 | if (empty) { |
| 1733 | 1714 | pdf->emptyPDF(); |
| 1734 | 1715 | } else if (main_input && m->json_input) { |
| ... | ... | @@ -1758,16 +1739,16 @@ QPDFJob::doProcess( |
| 1758 | 1739 | // was incorrectly encoded, there's a good chance we'd succeed here. |
| 1759 | 1740 | |
| 1760 | 1741 | std::string ptemp; |
| 1761 | - if (password && (!m->password_is_hex_key)) { | |
| 1742 | + if (password && !m->qcf.provided_password_is_hex_key()) { | |
| 1762 | 1743 | if (m->password_mode == QPDFJob::pm_hex_bytes) { |
| 1763 | 1744 | // Special case: handle --password-mode=hex-bytes for input password as well as output |
| 1764 | 1745 | // password |
| 1765 | - QTC::TC("qpdf", "QPDFJob input password hex-bytes"); | |
| 1766 | 1746 | ptemp = QUtil::hex_decode(password); |
| 1767 | 1747 | password = ptemp.c_str(); |
| 1768 | 1748 | } |
| 1769 | 1749 | } |
| 1770 | - if ((password == nullptr) || empty || m->password_is_hex_key || m->suppress_password_recovery) { | |
| 1750 | + if (!password || empty || m->qcf.provided_password_is_hex_key() || | |
| 1751 | + m->suppress_password_recovery) { | |
| 1771 | 1752 | // There is no password, or we're not doing recovery, so just do the normal processing with |
| 1772 | 1753 | // the supplied password. |
| 1773 | 1754 | doProcessOnce(pdf, fn, password, empty, used_for_input, main_input); |
| ... | ... | @@ -3034,12 +3015,10 @@ QPDFJob::doSplitPages(QPDF& pdf) |
| 3034 | 3015 | last = num_pages; |
| 3035 | 3016 | } |
| 3036 | 3017 | QPDF outpdf; |
| 3018 | + outpdf.doc().config(m->qcf); | |
| 3037 | 3019 | outpdf.emptyPDF(); |
| 3038 | 3020 | QPDFAcroFormDocumentHelper* out_afdh = |
| 3039 | 3021 | afdh.hasAcroForm() ? &outpdf.doc().acroform() : nullptr; |
| 3040 | - if (m->suppress_warnings) { | |
| 3041 | - outpdf.setSuppressWarnings(true); | |
| 3042 | - } | |
| 3043 | 3022 | for (size_t pageno = first; pageno <= last; ++pageno) { |
| 3044 | 3023 | QPDFObjectHandle page = pages.at(pageno - 1); |
| 3045 | 3024 | outpdf.addPage(page, false); | ... | ... |
libqpdf/QPDFJob_config.cc
| ... | ... | @@ -68,6 +68,7 @@ QPDFJob::Config* |
| 68 | 68 | QPDFJob::Config::check() |
| 69 | 69 | { |
| 70 | 70 | o.m->check = true; |
| 71 | + o.m->qcf.check_mode(true); | |
| 71 | 72 | o.m->require_outfile = false; |
| 72 | 73 | return this; |
| 73 | 74 | } |
| ... | ... | @@ -233,7 +234,7 @@ QPDFJob::Config::generateAppearances() |
| 233 | 234 | QPDFJob::Config* |
| 234 | 235 | QPDFJob::Config::ignoreXrefStreams() |
| 235 | 236 | { |
| 236 | - o.m->ignore_xref_streams = true; | |
| 237 | + o.m->qcf.ignore_xref_streams(true); | |
| 237 | 238 | return this; |
| 238 | 239 | } |
| 239 | 240 | |
| ... | ... | @@ -415,7 +416,7 @@ QPDFJob::Config::noOriginalObjectIds() |
| 415 | 416 | QPDFJob::Config* |
| 416 | 417 | QPDFJob::Config::noWarn() |
| 417 | 418 | { |
| 418 | - o.m->suppress_warnings = true; | |
| 419 | + o.m->qcf.suppress_warnings(true); | |
| 419 | 420 | return this; |
| 420 | 421 | } |
| 421 | 422 | |
| ... | ... | @@ -465,7 +466,7 @@ QPDFJob::Config::password(std::string const& parameter) |
| 465 | 466 | QPDFJob::Config* |
| 466 | 467 | QPDFJob::Config::passwordIsHexKey() |
| 467 | 468 | { |
| 468 | - o.m->password_is_hex_key = true; | |
| 469 | + o.m->qcf.provided_password_is_hex_key(true); | |
| 469 | 470 | return this; |
| 470 | 471 | } |
| 471 | 472 | |
| ... | ... | @@ -662,7 +663,7 @@ QPDFJob::Config::suppressPasswordRecovery() |
| 662 | 663 | QPDFJob::Config* |
| 663 | 664 | QPDFJob::Config::suppressRecovery() |
| 664 | 665 | { |
| 665 | - o.m->suppress_recovery = true; | |
| 666 | + o.m->qcf.attempt_recovery(false); | |
| 666 | 667 | return this; |
| 667 | 668 | } |
| 668 | 669 | ... | ... |
libqpdf/qpdf/QPDFJob_private.hh
| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | |
| 6 | 6 | #include <qpdf/ClosedFileInputSource.hh> |
| 7 | 7 | #include <qpdf/QPDFLogger.hh> |
| 8 | +#include <qpdf/QPDF_private.hh> | |
| 8 | 9 | |
| 9 | 10 | // A selection of pages from a single input PDF to be included in the output. This corresponds to a |
| 10 | 11 | // single clause in the --pages option. |
| ... | ... | @@ -149,7 +150,7 @@ class QPDFJob::Members |
| 149 | 150 | |
| 150 | 151 | public: |
| 151 | 152 | Members(QPDFJob& job) : |
| 152 | - log(QPDFLogger::defaultLogger()), | |
| 153 | + log(qcf.log()), | |
| 153 | 154 | inputs(job) |
| 154 | 155 | { |
| 155 | 156 | } |
| ... | ... | @@ -167,6 +168,7 @@ class QPDFJob::Members |
| 167 | 168 | static int constexpr DEFAULT_OI_MIN_AREA = 16384; |
| 168 | 169 | static int constexpr DEFAULT_II_MIN_BYTES = 1024; |
| 169 | 170 | |
| 171 | + qpdf::Doc::Config qcf; | |
| 170 | 172 | std::shared_ptr<QPDFLogger> log; |
| 171 | 173 | std::string message_prefix{"qpdf"}; |
| 172 | 174 | bool warnings{false}; |
| ... | ... | @@ -179,11 +181,9 @@ class QPDFJob::Members |
| 179 | 181 | int split_pages{0}; |
| 180 | 182 | bool progress{false}; |
| 181 | 183 | std::function<void(int)> progress_handler{nullptr}; |
| 182 | - bool suppress_warnings{false}; | |
| 183 | 184 | bool warnings_exit_zero{false}; |
| 184 | 185 | bool copy_encryption{false}; |
| 185 | 186 | bool encrypt{false}; |
| 186 | - bool password_is_hex_key{false}; | |
| 187 | 187 | bool suppress_password_recovery{false}; |
| 188 | 188 | password_mode_e password_mode{pm_auto}; |
| 189 | 189 | bool allow_insecure{false}; |
| ... | ... | @@ -218,10 +218,8 @@ class QPDFJob::Members |
| 218 | 218 | bool decode_level_set{false}; |
| 219 | 219 | bool normalize_set{false}; |
| 220 | 220 | bool normalize{false}; |
| 221 | - bool suppress_recovery{false}; | |
| 222 | 221 | bool object_stream_set{false}; |
| 223 | 222 | qpdf_object_stream_e object_stream_mode{qpdf_o_preserve}; |
| 224 | - bool ignore_xref_streams{false}; | |
| 225 | 223 | bool qdf_mode{false}; |
| 226 | 224 | bool preserve_unreferenced_objects{false}; |
| 227 | 225 | remove_unref_e remove_unreferenced_page_resources{re_auto}; | ... | ... |
libqpdf/qpdf/QPDF_private.hh
qpdf/qpdf.testcov
| ... | ... | @@ -248,7 +248,6 @@ QPDFJob password not encodable 0 |
| 248 | 248 | QPDFJob auto-encode password 0 |
| 249 | 249 | QPDFJob bytes fallback warning 0 |
| 250 | 250 | QPDFJob invalid utf-8 in auto 0 |
| 251 | -QPDFJob input password hex-bytes 0 | |
| 252 | 251 | QPDFFormFieldObjectHelper replaced BMC at EOF 0 |
| 253 | 252 | QPDFFormFieldObjectHelper fallback Tf 0 |
| 254 | 253 | QPDFPageObjectHelper copy shared attribute 1 | ... | ... |