Commit c2148fb19595af662b4af387858ffd2a058a790c
1 parent
8007a849
Refactor `QPDFWriter`: remove `static` qualifiers from helper functions, replace…
… `QPDF` parameter with `pdf` member, and simplify method calls.
Showing
1 changed file
with
25 additions
and
28 deletions
libqpdf/QPDFWriter.cc
| ... | ... | @@ -268,18 +268,16 @@ class QPDF::Writer |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | protected: |
| 271 | - static void | |
| 271 | + void | |
| 272 | 272 | optimize( |
| 273 | - QPDF& qpdf, | |
| 274 | 273 | QPDFWriter::ObjTable const& obj, |
| 275 | 274 | std::function<int(QPDFObjectHandle&)> skip_stream_parameters) |
| 276 | 275 | { |
| 277 | - qpdf.optimize(obj, skip_stream_parameters); | |
| 276 | + pdf.optimize(obj, skip_stream_parameters); | |
| 278 | 277 | } |
| 279 | 278 | |
| 280 | - static void | |
| 279 | + void | |
| 281 | 280 | getLinearizedParts( |
| 282 | - QPDF& qpdf, | |
| 283 | 281 | QPDFWriter::ObjTable const& obj, |
| 284 | 282 | std::vector<QPDFObjectHandle>& part4, |
| 285 | 283 | std::vector<QPDFObjectHandle>& part6, |
| ... | ... | @@ -287,12 +285,11 @@ class QPDF::Writer |
| 287 | 285 | std::vector<QPDFObjectHandle>& part8, |
| 288 | 286 | std::vector<QPDFObjectHandle>& part9) |
| 289 | 287 | { |
| 290 | - qpdf.getLinearizedParts(obj, part4, part6, part7, part8, part9); | |
| 288 | + pdf.getLinearizedParts(obj, part4, part6, part7, part8, part9); | |
| 291 | 289 | } |
| 292 | 290 | |
| 293 | - static void | |
| 291 | + void | |
| 294 | 292 | generateHintStream( |
| 295 | - QPDF& qpdf, | |
| 296 | 293 | QPDFWriter::NewObjTable const& new_obj, |
| 297 | 294 | QPDFWriter::ObjTable const& obj, |
| 298 | 295 | std::string& hint_stream, |
| ... | ... | @@ -300,31 +297,31 @@ class QPDF::Writer |
| 300 | 297 | int& O, |
| 301 | 298 | bool compressed) |
| 302 | 299 | { |
| 303 | - qpdf.generateHintStream(new_obj, obj, hint_stream, S, O, compressed); | |
| 300 | + pdf.generateHintStream(new_obj, obj, hint_stream, S, O, compressed); | |
| 304 | 301 | } |
| 305 | 302 | |
| 306 | - static std::vector<QPDFObjGen> | |
| 307 | - getCompressibleObjGens(QPDF& qpdf) | |
| 303 | + std::vector<QPDFObjGen> | |
| 304 | + getCompressibleObjGens() | |
| 308 | 305 | { |
| 309 | - return qpdf.getCompressibleObjVector(); | |
| 306 | + return pdf.getCompressibleObjVector(); | |
| 310 | 307 | } |
| 311 | 308 | |
| 312 | - static std::vector<bool> | |
| 313 | - getCompressibleObjSet(QPDF& qpdf) | |
| 309 | + std::vector<bool> | |
| 310 | + getCompressibleObjSet() | |
| 314 | 311 | { |
| 315 | - return qpdf.getCompressibleObjSet(); | |
| 312 | + return pdf.getCompressibleObjSet(); | |
| 316 | 313 | } |
| 317 | 314 | |
| 318 | - static std::map<QPDFObjGen, QPDFXRefEntry> const& | |
| 319 | - getXRefTable(QPDF& qpdf) | |
| 315 | + std::map<QPDFObjGen, QPDFXRefEntry> const& | |
| 316 | + getXRefTable() | |
| 320 | 317 | { |
| 321 | - return qpdf.getXRefTableInternal(); | |
| 318 | + return pdf.getXRefTableInternal(); | |
| 322 | 319 | } |
| 323 | 320 | |
| 324 | - static size_t | |
| 325 | - tableSize(QPDF& qpdf) | |
| 321 | + size_t | |
| 322 | + tableSize() | |
| 326 | 323 | { |
| 327 | - return qpdf.tableSize(); | |
| 324 | + return pdf.tableSize(); | |
| 328 | 325 | } |
| 329 | 326 | |
| 330 | 327 | QPDF& pdf; |
| ... | ... | @@ -2160,7 +2157,7 @@ QPDFWriter::Members::initializeSpecialStreams() |
| 2160 | 2157 | void |
| 2161 | 2158 | QPDFWriter::Members::preserveObjectStreams() |
| 2162 | 2159 | { |
| 2163 | - auto const& xref = QPDF::Writer::getXRefTable(pdf); | |
| 2160 | + auto const& xref = getXRefTable(); | |
| 2164 | 2161 | // Our object_to_object_stream map has to map ObjGen -> ObjGen since we may be generating object |
| 2165 | 2162 | // streams out of old objects that have generation numbers greater than zero. However in an |
| 2166 | 2163 | // existing PDF, all object stream objects and all objects in them must have generation 0 |
| ... | ... | @@ -2185,7 +2182,7 @@ QPDFWriter::Members::preserveObjectStreams() |
| 2185 | 2182 | if (iter->second.getType() == 2) { |
| 2186 | 2183 | // Pdf contains object streams. |
| 2187 | 2184 | obj.streams_empty = false; |
| 2188 | - auto eligible = QPDF::Writer::getCompressibleObjSet(pdf); | |
| 2185 | + auto eligible = getCompressibleObjSet(); | |
| 2189 | 2186 | // The object pointed to by iter may be a previous generation, in which case it is |
| 2190 | 2187 | // removed by getCompressibleObjSet. We need to restart the loop (while the object |
| 2191 | 2188 | // table may contain multiple generations of an object). |
| ... | ... | @@ -2216,7 +2213,7 @@ QPDFWriter::Members::generateObjectStreams() |
| 2216 | 2213 | |
| 2217 | 2214 | // This code doesn't do anything with /Extends. |
| 2218 | 2215 | |
| 2219 | - std::vector<QPDFObjGen> eligible = QPDF::Writer::getCompressibleObjGens(pdf); | |
| 2216 | + std::vector<QPDFObjGen> eligible = getCompressibleObjGens(); | |
| 2220 | 2217 | size_t n_object_streams = (eligible.size() + 99U) / 100U; |
| 2221 | 2218 | |
| 2222 | 2219 | initializeTables(2U * n_object_streams); |
| ... | ... | @@ -2297,7 +2294,7 @@ QPDFWriter::Members::prepareFileForWrite() |
| 2297 | 2294 | void |
| 2298 | 2295 | QPDFWriter::Members::initializeTables(size_t extra) |
| 2299 | 2296 | { |
| 2300 | - auto size = QIntC::to_size(QPDF::Writer::tableSize(pdf) + 100) + extra; | |
| 2297 | + auto size = QIntC::to_size(tableSize() + 100) + extra; | |
| 2301 | 2298 | obj.resize(size); |
| 2302 | 2299 | new_obj.resize(size); |
| 2303 | 2300 | } |
| ... | ... | @@ -2577,7 +2574,7 @@ QPDFWriter::Members::writeHintStream(int hint_id) |
| 2577 | 2574 | int S = 0; |
| 2578 | 2575 | int O = 0; |
| 2579 | 2576 | bool compressed = compress_streams && !qdf_mode; |
| 2580 | - QPDF::Writer::generateHintStream(pdf, new_obj, obj, hint_buffer, S, O, compressed); | |
| 2577 | + generateHintStream(new_obj, obj, hint_buffer, S, O, compressed); | |
| 2581 | 2578 | |
| 2582 | 2579 | openObject(hint_id); |
| 2583 | 2580 | setDataKey(hint_id); |
| ... | ... | @@ -2786,14 +2783,14 @@ QPDFWriter::Members::writeLinearized() |
| 2786 | 2783 | return result; |
| 2787 | 2784 | }; |
| 2788 | 2785 | |
| 2789 | - QPDF::Writer::optimize(pdf, obj, skip_stream_parameters); | |
| 2786 | + optimize(obj, skip_stream_parameters); | |
| 2790 | 2787 | |
| 2791 | 2788 | std::vector<QPDFObjectHandle> part4; |
| 2792 | 2789 | std::vector<QPDFObjectHandle> part6; |
| 2793 | 2790 | std::vector<QPDFObjectHandle> part7; |
| 2794 | 2791 | std::vector<QPDFObjectHandle> part8; |
| 2795 | 2792 | std::vector<QPDFObjectHandle> part9; |
| 2796 | - QPDF::Writer::getLinearizedParts(pdf, obj, part4, part6, part7, part8, part9); | |
| 2793 | + getLinearizedParts(obj, part4, part6, part7, part8, part9); | |
| 2797 | 2794 | |
| 2798 | 2795 | // Object number sequence: |
| 2799 | 2796 | // | ... | ... |