Commit 2bd0657ded9d71b1c4485a52717cd9bea8e89423
1 parent
1edbed57
Refactor `QPDF::getAllPages` usage: replace with `Pages::all` across `QPDFJob`.
Showing
1 changed file
with
32 additions
and
22 deletions
libqpdf/QPDFJob.cc
| ... | ... | @@ -30,8 +30,11 @@ |
| 30 | 30 | |
| 31 | 31 | using namespace qpdf; |
| 32 | 32 | |
| 33 | +using Doc = QPDF::Doc; | |
| 34 | +using Pages = Doc::Pages; | |
| 35 | + | |
| 33 | 36 | // JobSetter class is restricted to QPDFJob. |
| 34 | -class QPDF::Doc::JobSetter | |
| 37 | +class Doc::JobSetter | |
| 35 | 38 | { |
| 36 | 39 | public: |
| 37 | 40 | // Enable enhanced warnings for pdf file checking. |
| ... | ... | @@ -746,7 +749,7 @@ QPDFJob::doCheck(QPDF& pdf) |
| 746 | 749 | bool okay = true; |
| 747 | 750 | auto& cout = *m->log->getInfo(); |
| 748 | 751 | cout << "checking " << m->infile_name() << "\n"; |
| 749 | - QPDF::Doc::JobSetter::setCheckMode(pdf, true); | |
| 752 | + Doc::JobSetter::setCheckMode(pdf, true); | |
| 750 | 753 | try { |
| 751 | 754 | int extension_level = pdf.getExtensionLevel(); |
| 752 | 755 | cout << "PDF Version: " << pdf.getPDFVersion(); |
| ... | ... | @@ -852,7 +855,7 @@ QPDFJob::doShowPages(QPDF& pdf) |
| 852 | 855 | { |
| 853 | 856 | int pageno = 0; |
| 854 | 857 | auto& cout = *m->log->getInfo(); |
| 855 | - for (auto& page: pdf.getAllPages()) { | |
| 858 | + for (auto& page: pdf.doc().pages().all()) { | |
| 856 | 859 | QPDFPageObjectHelper ph(page); |
| 857 | 860 | ++pageno; |
| 858 | 861 | |
| ... | ... | @@ -1040,13 +1043,14 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf) |
| 1040 | 1043 | void |
| 1041 | 1044 | QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) |
| 1042 | 1045 | { |
| 1046 | + auto& doc = pdf.doc(); | |
| 1043 | 1047 | JSON::writeDictionaryKey(p, first, "pages", 1); |
| 1044 | 1048 | bool first_page = true; |
| 1045 | 1049 | JSON::writeArrayOpen(p, first_page, 2); |
| 1046 | - auto& pldh = pdf.doc().page_labels(); | |
| 1047 | - auto& odh = pdf.doc().outlines(); | |
| 1050 | + auto& pldh = doc.page_labels(); | |
| 1051 | + auto& odh = doc.outlines(); | |
| 1048 | 1052 | int pageno = -1; |
| 1049 | - for (auto& page: pdf.getAllPages()) { | |
| 1053 | + for (auto& page: doc.pages().all()) { | |
| 1050 | 1054 | ++pageno; |
| 1051 | 1055 | JSON j_page = JSON::makeDictionary(); |
| 1052 | 1056 | QPDFPageObjectHelper ph(page); |
| ... | ... | @@ -1105,9 +1109,10 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) |
| 1105 | 1109 | void |
| 1106 | 1110 | QPDFJob::doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf) |
| 1107 | 1111 | { |
| 1112 | + auto& doc = pdf.doc(); | |
| 1108 | 1113 | JSON j_labels = JSON::makeArray(); |
| 1109 | - auto& pldh = pdf.doc().page_labels(); | |
| 1110 | - long long npages = QIntC::to_longlong(pdf.getAllPages().size()); | |
| 1114 | + auto& pldh = doc.page_labels(); | |
| 1115 | + long long npages = QIntC::to_longlong(doc.pages().all().size()); | |
| 1111 | 1116 | if (pldh.hasPageLabels()) { |
| 1112 | 1117 | std::vector<QPDFObjectHandle> labels; |
| 1113 | 1118 | pldh.getLabelsForPageRange(0, npages - 1, 0, labels); |
| ... | ... | @@ -1153,27 +1158,29 @@ QPDFJob::addOutlinesToJson( |
| 1153 | 1158 | void |
| 1154 | 1159 | QPDFJob::doJSONOutlines(Pipeline* p, bool& first, QPDF& pdf) |
| 1155 | 1160 | { |
| 1161 | + auto& doc = pdf.doc(); | |
| 1156 | 1162 | std::map<QPDFObjGen, int> page_numbers; |
| 1157 | 1163 | int n = 0; |
| 1158 | - for (auto const& oh: pdf.getAllPages()) { | |
| 1164 | + for (auto const& oh: doc.pages().all()) { | |
| 1159 | 1165 | page_numbers[oh] = ++n; |
| 1160 | 1166 | } |
| 1161 | 1167 | |
| 1162 | 1168 | JSON j_outlines = JSON::makeArray(); |
| 1163 | - addOutlinesToJson(pdf.doc().outlines().getTopLevelOutlines(), j_outlines, page_numbers); | |
| 1169 | + addOutlinesToJson(doc.outlines().getTopLevelOutlines(), j_outlines, page_numbers); | |
| 1164 | 1170 | JSON::writeDictionaryItem(p, first, "outlines", j_outlines, 1); |
| 1165 | 1171 | } |
| 1166 | 1172 | |
| 1167 | 1173 | void |
| 1168 | 1174 | QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) |
| 1169 | 1175 | { |
| 1176 | + auto& doc = pdf.doc(); | |
| 1170 | 1177 | JSON j_acroform = JSON::makeDictionary(); |
| 1171 | - auto& afdh = pdf.doc().acroform(); | |
| 1178 | + auto& afdh = doc.acroform(); | |
| 1172 | 1179 | j_acroform.addDictionaryMember("hasacroform", JSON::makeBool(afdh.hasAcroForm())); |
| 1173 | 1180 | j_acroform.addDictionaryMember("needappearances", JSON::makeBool(afdh.getNeedAppearances())); |
| 1174 | 1181 | JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray()); |
| 1175 | 1182 | int pagepos1 = 0; |
| 1176 | - for (auto const& page: pdf.getAllPages()) { | |
| 1183 | + for (auto const& page: doc.pages().all()) { | |
| 1177 | 1184 | ++pagepos1; |
| 1178 | 1185 | for (auto& aoh: afdh.getWidgetAnnotationsForPage({page})) { |
| 1179 | 1186 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh); |
| ... | ... | @@ -1851,8 +1858,8 @@ QPDFJob::validateUnderOverlay(QPDF& pdf, UnderOverlay* uo) |
| 1851 | 1858 | { |
| 1852 | 1859 | processFile(uo->pdf, uo->filename.data(), uo->password.data(), true, false); |
| 1853 | 1860 | try { |
| 1854 | - uo->to_pagenos = | |
| 1855 | - QUtil::parse_numrange(uo->to_nr.data(), static_cast<int>(pdf.getAllPages().size())); | |
| 1861 | + uo->to_pagenos = QUtil::parse_numrange( | |
| 1862 | + uo->to_nr.data(), static_cast<int>(pdf.doc().pages().all().size())); | |
| 1856 | 1863 | } catch (std::runtime_error& e) { |
| 1857 | 1864 | throw std::runtime_error( |
| 1858 | 1865 | "parsing numeric range for " + uo->which + " \"to\" pages: " + e.what()); |
| ... | ... | @@ -1861,7 +1868,7 @@ QPDFJob::validateUnderOverlay(QPDF& pdf, UnderOverlay* uo) |
| 1861 | 1868 | if (uo->from_nr.empty()) { |
| 1862 | 1869 | uo->from_nr = uo->repeat_nr; |
| 1863 | 1870 | } |
| 1864 | - int uo_npages = static_cast<int>(uo->pdf->getAllPages().size()); | |
| 1871 | + int uo_npages = static_cast<int>(uo->pdf->doc().pages().size()); | |
| 1865 | 1872 | uo->from_pagenos = QUtil::parse_numrange(uo->from_nr.data(), uo_npages); |
| 1866 | 1873 | if (!uo->repeat_nr.empty()) { |
| 1867 | 1874 | uo->repeat_pagenos = QUtil::parse_numrange(uo->repeat_nr.data(), uo_npages); |
| ... | ... | @@ -1887,7 +1894,7 @@ QPDFJob::doUnderOverlayForPage( |
| 1887 | 1894 | } |
| 1888 | 1895 | auto& dest_afdh = dest_page.qpdf()->doc().acroform(); |
| 1889 | 1896 | |
| 1890 | - auto const& pages = uo.pdf->getAllPages(); | |
| 1897 | + auto const& pages = uo.pdf->doc().pages().all(); | |
| 1891 | 1898 | std::string content; |
| 1892 | 1899 | int min_suffix = 1; |
| 1893 | 1900 | QPDFObjectHandle resources = dest_page.getAttribute("/Resources", true); |
| ... | ... | @@ -1957,7 +1964,7 @@ QPDFJob::handleUnderOverlay(QPDF& pdf) |
| 1957 | 1964 | validateUnderOverlay(pdf, &uo); |
| 1958 | 1965 | } |
| 1959 | 1966 | |
| 1960 | - auto const& dest_pages = pdf.getAllPages(); | |
| 1967 | + auto const& dest_pages = pdf.doc().pages().all(); | |
| 1961 | 1968 | |
| 1962 | 1969 | // First vector key is 0-based page number. Second is index into the overlay/underlay vector. |
| 1963 | 1970 | // Watch out to not reverse the keys or be off by one. |
| ... | ... | @@ -2348,15 +2355,16 @@ void |
| 2348 | 2355 | QPDFJob::Input::initialize(Inputs& in, QPDF* a_qpdf) |
| 2349 | 2356 | { |
| 2350 | 2357 | qpdf = a_qpdf ? a_qpdf : qpdf_p.get(); |
| 2358 | + auto& doc = qpdf->doc(); | |
| 2351 | 2359 | if (qpdf) { |
| 2352 | - orig_pages = qpdf->getAllPages(); | |
| 2360 | + orig_pages = doc.pages().all(); | |
| 2353 | 2361 | n_pages = static_cast<int>(orig_pages.size()); |
| 2354 | 2362 | copied_pages = std::vector<bool>(orig_pages.size(), false); |
| 2355 | 2363 | |
| 2356 | 2364 | if (in.job.m->remove_unreferenced_page_resources != QPDFJob::re_no) { |
| 2357 | 2365 | remove_unreferenced = in.job.shouldRemoveUnreferencedResources(*qpdf); |
| 2358 | 2366 | } |
| 2359 | - if (qpdf->doc().page_labels().hasPageLabels()) { | |
| 2367 | + if (doc.page_labels().hasPageLabels()) { | |
| 2360 | 2368 | in.any_page_labels = true; |
| 2361 | 2369 | } |
| 2362 | 2370 | } |
| ... | ... | @@ -3001,6 +3009,8 @@ QPDFJob::setWriterOptions(QPDFWriter& w) |
| 3001 | 3009 | void |
| 3002 | 3010 | QPDFJob::doSplitPages(QPDF& pdf) |
| 3003 | 3011 | { |
| 3012 | + auto& doc = pdf.doc(); | |
| 3013 | + | |
| 3004 | 3014 | // Generate output file pattern |
| 3005 | 3015 | std::string before; |
| 3006 | 3016 | std::string after; |
| ... | ... | @@ -3024,9 +3034,9 @@ QPDFJob::doSplitPages(QPDF& pdf) |
| 3024 | 3034 | QPDFPageDocumentHelper dh(pdf); |
| 3025 | 3035 | dh.removeUnreferencedResources(); |
| 3026 | 3036 | } |
| 3027 | - auto& pldh = pdf.doc().page_labels(); | |
| 3028 | - auto& afdh = pdf.doc().acroform(); | |
| 3029 | - std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); | |
| 3037 | + auto& pldh = doc.page_labels(); | |
| 3038 | + auto& afdh = doc.acroform(); | |
| 3039 | + std::vector<QPDFObjectHandle> const& pages = doc.pages().all(); | |
| 3030 | 3040 | size_t pageno_len = std::to_string(pages.size()).length(); |
| 3031 | 3041 | size_t num_pages = pages.size(); |
| 3032 | 3042 | for (size_t i = 0; i < num_pages; i += QIntC::to_size(m->split_pages)) { | ... | ... |