Commit 48bacbf2e66b08c9f738416044d5797554ffa203

Authored by Jay Berkenbilt
1 parent e65bb2c5

Refactor overlay/underlay in preparation for change

include/qpdf/QPDFJob.hh
@@ -526,15 +526,14 @@ class QPDFJob @@ -526,15 +526,14 @@ class QPDFJob
526 void 526 void
527 getUOPagenos(UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos); 527 getUOPagenos(UnderOverlay& uo, std::map<int, std::vector<int>>& pagenos);
528 void handleUnderOverlay(QPDF& pdf); 528 void handleUnderOverlay(QPDF& pdf);
529 - void doUnderOverlayForPage( 529 + std::string doUnderOverlayForPage(
530 QPDF& pdf, 530 QPDF& pdf,
531 UnderOverlay& uo, 531 UnderOverlay& uo,
532 std::map<int, std::vector<int>>& pagenos, 532 std::map<int, std::vector<int>>& pagenos,
533 size_t page_idx, 533 size_t page_idx,
534 std::map<int, QPDFObjectHandle>& fo, 534 std::map<int, QPDFObjectHandle>& fo,
535 std::vector<QPDFPageObjectHelper>& pages, 535 std::vector<QPDFPageObjectHelper>& pages,
536 - QPDFPageObjectHelper& dest_page,  
537 - bool before); 536 + QPDFPageObjectHelper& dest_page);
538 void validateUnderOverlay(QPDF& pdf, UnderOverlay* uo); 537 void validateUnderOverlay(QPDF& pdf, UnderOverlay* uo);
539 void handleTransformations(QPDF& pdf); 538 void handleTransformations(QPDF& pdf);
540 void addAttachments(QPDF& pdf); 539 void addAttachments(QPDF& pdf);
libqpdf/QPDFJob.cc
@@ -2056,7 +2056,7 @@ get_afdh_for_qpdf( @@ -2056,7 +2056,7 @@ get_afdh_for_qpdf(
2056 return afdh_map[uid].get(); 2056 return afdh_map[uid].get();
2057 } 2057 }
2058 2058
2059 -void 2059 +std::string
2060 QPDFJob::doUnderOverlayForPage( 2060 QPDFJob::doUnderOverlayForPage(
2061 QPDF& pdf, 2061 QPDF& pdf,
2062 UnderOverlay& uo, 2062 UnderOverlay& uo,
@@ -2064,12 +2064,11 @@ QPDFJob::doUnderOverlayForPage( @@ -2064,12 +2064,11 @@ QPDFJob::doUnderOverlayForPage(
2064 size_t page_idx, 2064 size_t page_idx,
2065 std::map<int, QPDFObjectHandle>& fo, 2065 std::map<int, QPDFObjectHandle>& fo,
2066 std::vector<QPDFPageObjectHelper>& pages, 2066 std::vector<QPDFPageObjectHelper>& pages,
2067 - QPDFPageObjectHelper& dest_page,  
2068 - bool before) 2067 + QPDFPageObjectHelper& dest_page)
2069 { 2068 {
2070 int pageno = 1 + QIntC::to_int(page_idx); 2069 int pageno = 1 + QIntC::to_int(page_idx);
2071 if (!pagenos.count(pageno)) { 2070 if (!pagenos.count(pageno)) {
2072 - return; 2071 + return "";
2073 } 2072 }
2074 2073
2075 std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>> 2074 std::map<unsigned long long, std::shared_ptr<QPDFAcroFormDocumentHelper>>
@@ -2121,14 +2120,7 @@ QPDFJob::doUnderOverlayForPage( @@ -2121,14 +2120,7 @@ QPDFJob::doUnderOverlayForPage(
2121 content += new_content; 2120 content += new_content;
2122 } 2121 }
2123 } 2122 }
2124 - if (!content.empty()) {  
2125 - if (before) {  
2126 - dest_page.addPageContents(pdf.newStream(content), true);  
2127 - } else {  
2128 - dest_page.addPageContents(pdf.newStream("q\n"), true);  
2129 - dest_page.addPageContents(pdf.newStream("\nQ\n" + content), false);  
2130 - }  
2131 - } 2123 + return content;
2132 } 2124 }
2133 2125
2134 void 2126 void
@@ -2182,24 +2174,29 @@ QPDFJob::handleUnderOverlay(QPDF&amp; pdf) @@ -2182,24 +2174,29 @@ QPDFJob::handleUnderOverlay(QPDF&amp; pdf)
2182 doIfVerbose([&](Pipeline& v, std::string const& prefix) { 2174 doIfVerbose([&](Pipeline& v, std::string const& prefix) {
2183 v << " page " << 1 + i << "\n"; 2175 v << " page " << 1 + i << "\n";
2184 }); 2176 });
2185 - doUnderOverlayForPage( 2177 + auto pageno = QIntC::to_int(i) + 1;
  2178 + if (!(underlay_pagenos.count(pageno) ||
  2179 + overlay_pagenos.count(pageno))) {
  2180 + continue;
  2181 + }
  2182 + auto& dest_page = main_pages.at(i);
  2183 + auto content = doUnderOverlayForPage(
2186 pdf, 2184 pdf,
2187 m->underlay, 2185 m->underlay,
2188 underlay_pagenos, 2186 underlay_pagenos,
2189 i, 2187 i,
2190 underlay_fo, 2188 underlay_fo,
2191 upages, 2189 upages,
2192 - main_pages.at(i),  
2193 - true);  
2194 - doUnderOverlayForPage(  
2195 - pdf,  
2196 - m->overlay,  
2197 - overlay_pagenos,  
2198 - i,  
2199 - overlay_fo,  
2200 - opages,  
2201 - main_pages.at(i),  
2202 - false); 2190 + dest_page);
  2191 + if (!content.empty()) {
  2192 + dest_page.addPageContents(pdf.newStream(content), true);
  2193 + }
  2194 + content = doUnderOverlayForPage(
  2195 + pdf, m->overlay, overlay_pagenos, i, overlay_fo, opages, dest_page);
  2196 + if (!content.empty()) {
  2197 + dest_page.addPageContents(pdf.newStream("q\n"), true);
  2198 + dest_page.addPageContents(pdf.newStream("\nQ\n" + content), false);
  2199 + }
2203 } 2200 }
2204 } 2201 }
2205 2202