Commit 41c839e20ee3431c881e87917930175b0fbf27ae

Authored by m-holger
1 parent 7db44e26

Refactor `QPDFWriter`: update `qdf` handling logic to include `preserve_encrypti…

…on` checks, consolidate parameter updates, and remove redundant code for improved clarity.
libqpdf/QPDFWriter.cc
@@ -648,7 +648,26 @@ Config::qdf(bool val) @@ -648,7 +648,26 @@ Config::qdf(bool val)
648 if (pclm_ || linearize_) { 648 if (pclm_ || linearize_) {
649 usage("qdf cannot be set when linearize or pclm are set"); 649 usage("qdf cannot be set when linearize or pclm are set");
650 } 650 }
  651 + if (preserve_encryption_) {
  652 + usage("preserve_encryption cannot be set when qdf is set");
  653 + }
651 qdf_ = val; 654 qdf_ = val;
  655 + if (val) {
  656 + if (!normalize_content_set_) {
  657 + normalize_content(true);
  658 + }
  659 + if (!compress_streams_set_) {
  660 + compress_streams(false);
  661 + }
  662 + if (!stream_decode_level_set_) {
  663 + stream_decode_level(qpdf_dl_generalized);
  664 + }
  665 + preserve_encryption_ = false;
  666 + // Generate indirect stream lengths for qdf mode since fix-qdf uses them for storing
  667 + // recomputed stream length data. Certain streams such as object streams, xref streams, and
  668 + // hint streams always get direct stream lengths.
  669 + direct_stream_lengths_ = false;
  670 + }
652 return *this; 671 return *this;
653 } 672 }
654 673
@@ -2307,22 +2326,10 @@ impl::Writer::doWriteSetup() @@ -2307,22 +2326,10 @@ impl::Writer::doWriteSetup()
2307 encryption = nullptr; 2326 encryption = nullptr;
2308 } 2327 }
2309 2328
2310 - if (cfg.qdf()) {  
2311 - if (!cfg.normalize_content_set_) {  
2312 - cfg.normalize_content(true);  
2313 - }  
2314 - if (!cfg.compress_streams_set_) {  
2315 - cfg.compress_streams(false);  
2316 - }  
2317 - if (!cfg.stream_decode_level_set_) {  
2318 - cfg.stream_decode_level(qpdf_dl_generalized);  
2319 - }  
2320 - }  
2321 -  
2322 if (encryption) { 2329 if (encryption) {
2323 // Encryption has been explicitly set 2330 // Encryption has been explicitly set
2324 cfg.preserve_encryption(false); 2331 cfg.preserve_encryption(false);
2325 - } else if (cfg.normalize_content() || cfg.pclm() || cfg.qdf()) { 2332 + } else if (cfg.normalize_content() || cfg.pclm()) {
2326 // Encryption makes looking at contents pretty useless. If the user explicitly encrypted 2333 // Encryption makes looking at contents pretty useless. If the user explicitly encrypted
2327 // though, we still obey that. 2334 // though, we still obey that.
2328 cfg.preserve_encryption(false); 2335 cfg.preserve_encryption(false);
@@ -2346,13 +2353,6 @@ impl::Writer::doWriteSetup() @@ -2346,13 +2353,6 @@ impl::Writer::doWriteSetup()
2346 initializeSpecialStreams(); 2353 initializeSpecialStreams();
2347 } 2354 }
2348 2355
2349 - if (cfg.qdf()) {  
2350 - // Generate indirect stream lengths for qdf mode since fix-qdf uses them for storing  
2351 - // recomputed stream length data. Certain streams such as object streams, xref streams, and  
2352 - // hint streams always get direct stream lengths.  
2353 - cfg.direct_stream_lengths_ = false;  
2354 - }  
2355 -  
2356 switch (cfg.object_streams()) { 2356 switch (cfg.object_streams()) {
2357 case qpdf_o_disable: 2357 case qpdf_o_disable:
2358 initializeTables(); 2358 initializeTables();
libqpdf/qpdf/QPDFWriter_private.hh
@@ -22,8 +22,6 @@ namespace qpdf @@ -22,8 +22,6 @@ namespace qpdf
22 public: 22 public:
23 class Config 23 class Config
24 { 24 {
25 - friend class impl::Writer;  
26 -  
27 public: 25 public:
28 bool 26 bool
29 linearize() const 27 linearize() const