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
| @@ -460,7 +460,6 @@ class QPDFJob | @@ -460,7 +460,6 @@ class QPDFJob | ||
| 460 | bool main_input); | 460 | bool main_input); |
| 461 | 461 | ||
| 462 | // Transformations | 462 | // Transformations |
| 463 | - void setQPDFOptions(QPDF& pdf); | ||
| 464 | void handlePageSpecs(QPDF& pdf); | 463 | void handlePageSpecs(QPDF& pdf); |
| 465 | bool shouldRemoveUnreferencedResources(QPDF& pdf); | 464 | bool shouldRemoveUnreferencedResources(QPDF& pdf); |
| 466 | void handleRotations(QPDF& pdf); | 465 | void handleRotations(QPDF& pdf); |
libqpdf/QPDFJob.cc
| @@ -477,7 +477,7 @@ QPDFJob::writeQPDF(QPDF& pdf) | @@ -477,7 +477,7 @@ QPDFJob::writeQPDF(QPDF& pdf) | ||
| 477 | if (!pdf.getWarnings().empty()) { | 477 | if (!pdf.getWarnings().empty()) { |
| 478 | m->warnings = true; | 478 | m->warnings = true; |
| 479 | } | 479 | } |
| 480 | - if (m->warnings && (!m->suppress_warnings)) { | 480 | + if (m->warnings && !m->qcf.suppress_warnings()) { |
| 481 | if (createsOutput()) { | 481 | if (createsOutput()) { |
| 482 | *m->log->getWarn() | 482 | *m->log->getWarn() |
| 483 | << m->message_prefix | 483 | << m->message_prefix |
| @@ -635,24 +635,6 @@ QPDFJob::getEncryptionStatus() | @@ -635,24 +635,6 @@ QPDFJob::getEncryptionStatus() | ||
| 635 | return m->encryption_status; | 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 | static std::string | 638 | static std::string |
| 657 | show_bool(bool v) | 639 | show_bool(bool v) |
| 658 | { | 640 | { |
| @@ -737,7 +719,6 @@ QPDFJob::doCheck(QPDF& pdf) | @@ -737,7 +719,6 @@ QPDFJob::doCheck(QPDF& pdf) | ||
| 737 | bool okay = true; | 719 | bool okay = true; |
| 738 | auto& cout = *m->log->getInfo(); | 720 | auto& cout = *m->log->getInfo(); |
| 739 | cout << "checking " << m->infile_name() << "\n"; | 721 | cout << "checking " << m->infile_name() << "\n"; |
| 740 | - pdf.doc().config().check_mode(true); | ||
| 741 | try { | 722 | try { |
| 742 | int extension_level = pdf.getExtensionLevel(); | 723 | int extension_level = pdf.getExtensionLevel(); |
| 743 | cout << "PDF Version: " << pdf.getPDFVersion(); | 724 | cout << "PDF Version: " << pdf.getPDFVersion(); |
| @@ -1728,7 +1709,7 @@ QPDFJob::doProcessOnce( | @@ -1728,7 +1709,7 @@ QPDFJob::doProcessOnce( | ||
| 1728 | bool main_input) | 1709 | bool main_input) |
| 1729 | { | 1710 | { |
| 1730 | pdf = std::make_unique<QPDF>(); | 1711 | pdf = std::make_unique<QPDF>(); |
| 1731 | - setQPDFOptions(*pdf); | 1712 | + pdf->doc().config(m->qcf.log(m->log)); |
| 1732 | if (empty) { | 1713 | if (empty) { |
| 1733 | pdf->emptyPDF(); | 1714 | pdf->emptyPDF(); |
| 1734 | } else if (main_input && m->json_input) { | 1715 | } else if (main_input && m->json_input) { |
| @@ -1758,16 +1739,16 @@ QPDFJob::doProcess( | @@ -1758,16 +1739,16 @@ QPDFJob::doProcess( | ||
| 1758 | // was incorrectly encoded, there's a good chance we'd succeed here. | 1739 | // was incorrectly encoded, there's a good chance we'd succeed here. |
| 1759 | 1740 | ||
| 1760 | std::string ptemp; | 1741 | std::string ptemp; |
| 1761 | - if (password && (!m->password_is_hex_key)) { | 1742 | + if (password && !m->qcf.provided_password_is_hex_key()) { |
| 1762 | if (m->password_mode == QPDFJob::pm_hex_bytes) { | 1743 | if (m->password_mode == QPDFJob::pm_hex_bytes) { |
| 1763 | // Special case: handle --password-mode=hex-bytes for input password as well as output | 1744 | // Special case: handle --password-mode=hex-bytes for input password as well as output |
| 1764 | // password | 1745 | // password |
| 1765 | - QTC::TC("qpdf", "QPDFJob input password hex-bytes"); | ||
| 1766 | ptemp = QUtil::hex_decode(password); | 1746 | ptemp = QUtil::hex_decode(password); |
| 1767 | password = ptemp.c_str(); | 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 | // There is no password, or we're not doing recovery, so just do the normal processing with | 1752 | // There is no password, or we're not doing recovery, so just do the normal processing with |
| 1772 | // the supplied password. | 1753 | // the supplied password. |
| 1773 | doProcessOnce(pdf, fn, password, empty, used_for_input, main_input); | 1754 | doProcessOnce(pdf, fn, password, empty, used_for_input, main_input); |
| @@ -3034,12 +3015,10 @@ QPDFJob::doSplitPages(QPDF& pdf) | @@ -3034,12 +3015,10 @@ QPDFJob::doSplitPages(QPDF& pdf) | ||
| 3034 | last = num_pages; | 3015 | last = num_pages; |
| 3035 | } | 3016 | } |
| 3036 | QPDF outpdf; | 3017 | QPDF outpdf; |
| 3018 | + outpdf.doc().config(m->qcf); | ||
| 3037 | outpdf.emptyPDF(); | 3019 | outpdf.emptyPDF(); |
| 3038 | QPDFAcroFormDocumentHelper* out_afdh = | 3020 | QPDFAcroFormDocumentHelper* out_afdh = |
| 3039 | afdh.hasAcroForm() ? &outpdf.doc().acroform() : nullptr; | 3021 | afdh.hasAcroForm() ? &outpdf.doc().acroform() : nullptr; |
| 3040 | - if (m->suppress_warnings) { | ||
| 3041 | - outpdf.setSuppressWarnings(true); | ||
| 3042 | - } | ||
| 3043 | for (size_t pageno = first; pageno <= last; ++pageno) { | 3022 | for (size_t pageno = first; pageno <= last; ++pageno) { |
| 3044 | QPDFObjectHandle page = pages.at(pageno - 1); | 3023 | QPDFObjectHandle page = pages.at(pageno - 1); |
| 3045 | outpdf.addPage(page, false); | 3024 | outpdf.addPage(page, false); |
libqpdf/QPDFJob_config.cc
| @@ -68,6 +68,7 @@ QPDFJob::Config* | @@ -68,6 +68,7 @@ QPDFJob::Config* | ||
| 68 | QPDFJob::Config::check() | 68 | QPDFJob::Config::check() |
| 69 | { | 69 | { |
| 70 | o.m->check = true; | 70 | o.m->check = true; |
| 71 | + o.m->qcf.check_mode(true); | ||
| 71 | o.m->require_outfile = false; | 72 | o.m->require_outfile = false; |
| 72 | return this; | 73 | return this; |
| 73 | } | 74 | } |
| @@ -233,7 +234,7 @@ QPDFJob::Config::generateAppearances() | @@ -233,7 +234,7 @@ QPDFJob::Config::generateAppearances() | ||
| 233 | QPDFJob::Config* | 234 | QPDFJob::Config* |
| 234 | QPDFJob::Config::ignoreXrefStreams() | 235 | QPDFJob::Config::ignoreXrefStreams() |
| 235 | { | 236 | { |
| 236 | - o.m->ignore_xref_streams = true; | 237 | + o.m->qcf.ignore_xref_streams(true); |
| 237 | return this; | 238 | return this; |
| 238 | } | 239 | } |
| 239 | 240 | ||
| @@ -415,7 +416,7 @@ QPDFJob::Config::noOriginalObjectIds() | @@ -415,7 +416,7 @@ QPDFJob::Config::noOriginalObjectIds() | ||
| 415 | QPDFJob::Config* | 416 | QPDFJob::Config* |
| 416 | QPDFJob::Config::noWarn() | 417 | QPDFJob::Config::noWarn() |
| 417 | { | 418 | { |
| 418 | - o.m->suppress_warnings = true; | 419 | + o.m->qcf.suppress_warnings(true); |
| 419 | return this; | 420 | return this; |
| 420 | } | 421 | } |
| 421 | 422 | ||
| @@ -465,7 +466,7 @@ QPDFJob::Config::password(std::string const& parameter) | @@ -465,7 +466,7 @@ QPDFJob::Config::password(std::string const& parameter) | ||
| 465 | QPDFJob::Config* | 466 | QPDFJob::Config* |
| 466 | QPDFJob::Config::passwordIsHexKey() | 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 | return this; | 470 | return this; |
| 470 | } | 471 | } |
| 471 | 472 | ||
| @@ -662,7 +663,7 @@ QPDFJob::Config::suppressPasswordRecovery() | @@ -662,7 +663,7 @@ QPDFJob::Config::suppressPasswordRecovery() | ||
| 662 | QPDFJob::Config* | 663 | QPDFJob::Config* |
| 663 | QPDFJob::Config::suppressRecovery() | 664 | QPDFJob::Config::suppressRecovery() |
| 664 | { | 665 | { |
| 665 | - o.m->suppress_recovery = true; | 666 | + o.m->qcf.attempt_recovery(false); |
| 666 | return this; | 667 | return this; |
| 667 | } | 668 | } |
| 668 | 669 |
libqpdf/qpdf/QPDFJob_private.hh
| @@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
| 5 | 5 | ||
| 6 | #include <qpdf/ClosedFileInputSource.hh> | 6 | #include <qpdf/ClosedFileInputSource.hh> |
| 7 | #include <qpdf/QPDFLogger.hh> | 7 | #include <qpdf/QPDFLogger.hh> |
| 8 | +#include <qpdf/QPDF_private.hh> | ||
| 8 | 9 | ||
| 9 | // A selection of pages from a single input PDF to be included in the output. This corresponds to a | 10 | // A selection of pages from a single input PDF to be included in the output. This corresponds to a |
| 10 | // single clause in the --pages option. | 11 | // single clause in the --pages option. |
| @@ -149,7 +150,7 @@ class QPDFJob::Members | @@ -149,7 +150,7 @@ class QPDFJob::Members | ||
| 149 | 150 | ||
| 150 | public: | 151 | public: |
| 151 | Members(QPDFJob& job) : | 152 | Members(QPDFJob& job) : |
| 152 | - log(QPDFLogger::defaultLogger()), | 153 | + log(qcf.log()), |
| 153 | inputs(job) | 154 | inputs(job) |
| 154 | { | 155 | { |
| 155 | } | 156 | } |
| @@ -167,6 +168,7 @@ class QPDFJob::Members | @@ -167,6 +168,7 @@ class QPDFJob::Members | ||
| 167 | static int constexpr DEFAULT_OI_MIN_AREA = 16384; | 168 | static int constexpr DEFAULT_OI_MIN_AREA = 16384; |
| 168 | static int constexpr DEFAULT_II_MIN_BYTES = 1024; | 169 | static int constexpr DEFAULT_II_MIN_BYTES = 1024; |
| 169 | 170 | ||
| 171 | + qpdf::Doc::Config qcf; | ||
| 170 | std::shared_ptr<QPDFLogger> log; | 172 | std::shared_ptr<QPDFLogger> log; |
| 171 | std::string message_prefix{"qpdf"}; | 173 | std::string message_prefix{"qpdf"}; |
| 172 | bool warnings{false}; | 174 | bool warnings{false}; |
| @@ -179,11 +181,9 @@ class QPDFJob::Members | @@ -179,11 +181,9 @@ class QPDFJob::Members | ||
| 179 | int split_pages{0}; | 181 | int split_pages{0}; |
| 180 | bool progress{false}; | 182 | bool progress{false}; |
| 181 | std::function<void(int)> progress_handler{nullptr}; | 183 | std::function<void(int)> progress_handler{nullptr}; |
| 182 | - bool suppress_warnings{false}; | ||
| 183 | bool warnings_exit_zero{false}; | 184 | bool warnings_exit_zero{false}; |
| 184 | bool copy_encryption{false}; | 185 | bool copy_encryption{false}; |
| 185 | bool encrypt{false}; | 186 | bool encrypt{false}; |
| 186 | - bool password_is_hex_key{false}; | ||
| 187 | bool suppress_password_recovery{false}; | 187 | bool suppress_password_recovery{false}; |
| 188 | password_mode_e password_mode{pm_auto}; | 188 | password_mode_e password_mode{pm_auto}; |
| 189 | bool allow_insecure{false}; | 189 | bool allow_insecure{false}; |
| @@ -218,10 +218,8 @@ class QPDFJob::Members | @@ -218,10 +218,8 @@ class QPDFJob::Members | ||
| 218 | bool decode_level_set{false}; | 218 | bool decode_level_set{false}; |
| 219 | bool normalize_set{false}; | 219 | bool normalize_set{false}; |
| 220 | bool normalize{false}; | 220 | bool normalize{false}; |
| 221 | - bool suppress_recovery{false}; | ||
| 222 | bool object_stream_set{false}; | 221 | bool object_stream_set{false}; |
| 223 | qpdf_object_stream_e object_stream_mode{qpdf_o_preserve}; | 222 | qpdf_object_stream_e object_stream_mode{qpdf_o_preserve}; |
| 224 | - bool ignore_xref_streams{false}; | ||
| 225 | bool qdf_mode{false}; | 223 | bool qdf_mode{false}; |
| 226 | bool preserve_unreferenced_objects{false}; | 224 | bool preserve_unreferenced_objects{false}; |
| 227 | remove_unref_e remove_unreferenced_page_resources{re_auto}; | 225 | remove_unref_e remove_unreferenced_page_resources{re_auto}; |
libqpdf/qpdf/QPDF_private.hh
| @@ -504,6 +504,12 @@ class QPDF::Doc | @@ -504,6 +504,12 @@ class QPDF::Doc | ||
| 504 | return cf; | 504 | return cf; |
| 505 | } | 505 | } |
| 506 | 506 | ||
| 507 | + void | ||
| 508 | + config(qpdf::Doc::Config val) | ||
| 509 | + { | ||
| 510 | + cf = val; | ||
| 511 | + } | ||
| 512 | + | ||
| 507 | inline Linearization& linearization(); | 513 | inline Linearization& linearization(); |
| 508 | 514 | ||
| 509 | inline Objects& objects(); | 515 | inline Objects& objects(); |
qpdf/qpdf.testcov
| @@ -248,7 +248,6 @@ QPDFJob password not encodable 0 | @@ -248,7 +248,6 @@ QPDFJob password not encodable 0 | ||
| 248 | QPDFJob auto-encode password 0 | 248 | QPDFJob auto-encode password 0 |
| 249 | QPDFJob bytes fallback warning 0 | 249 | QPDFJob bytes fallback warning 0 |
| 250 | QPDFJob invalid utf-8 in auto 0 | 250 | QPDFJob invalid utf-8 in auto 0 |
| 251 | -QPDFJob input password hex-bytes 0 | ||
| 252 | QPDFFormFieldObjectHelper replaced BMC at EOF 0 | 251 | QPDFFormFieldObjectHelper replaced BMC at EOF 0 |
| 253 | QPDFFormFieldObjectHelper fallback Tf 0 | 252 | QPDFFormFieldObjectHelper fallback Tf 0 |
| 254 | QPDFPageObjectHelper copy shared attribute 1 | 253 | QPDFPageObjectHelper copy shared attribute 1 |
qpdf/qtest/qpdf/catalgg.out
| 1 | -checking catalgg.pdf | ||
| 2 | WARNING: catalgg.pdf: catalog /Type entry missing or invalid | 1 | WARNING: catalgg.pdf: catalog /Type entry missing or invalid |
| 2 | +checking catalgg.pdf | ||
| 3 | PDF Version: 1.3 | 3 | PDF Version: 1.3 |
| 4 | File is not encrypted | 4 | File is not encrypted |
| 5 | File is not linearized | 5 | File is not linearized |