Commit bd4bc9445dd3869f7d5886328fab19f490e0c708

Authored by m-holger
1 parent 26edf767

Refactor `Linearization` methods: move logic from `QPDF` to `Lin`, add `lineariz…

…ed`, `check`, and `show_data` methods, update usage across the codebase, and streamline related logic.
libqpdf/QPDF_linearization.cc
@@ -366,12 +366,18 @@ Lin::linearizationWarning(std::string_view msg) @@ -366,12 +366,18 @@ Lin::linearizationWarning(std::string_view msg)
366 bool 366 bool
367 QPDF::checkLinearization() 367 QPDF::checkLinearization()
368 { 368 {
  369 + return m->lin.check();
  370 +}
  371 +
  372 +bool
  373 +Lin::check()
  374 +{
369 try { 375 try {
370 - m->lin.readLinearizationData();  
371 - m->lin.checkLinearizationInternal(); 376 + readLinearizationData();
  377 + checkLinearizationInternal();
372 return !m->linearization_warnings; 378 return !m->linearization_warnings;
373 } catch (std::runtime_error& e) { 379 } catch (std::runtime_error& e) {
374 - m->lin.linearizationWarning( 380 + linearizationWarning(
375 "error encountered while checking linearization data: " + std::string(e.what())); 381 "error encountered while checking linearization data: " + std::string(e.what()));
376 return false; 382 return false;
377 } 383 }
@@ -380,6 +386,12 @@ QPDF::checkLinearization() @@ -380,6 +386,12 @@ QPDF::checkLinearization()
380 bool 386 bool
381 QPDF::isLinearized() 387 QPDF::isLinearized()
382 { 388 {
  389 + return m->lin.linearized();
  390 +}
  391 +
  392 +bool
  393 +Lin::linearized()
  394 +{
383 // If the first object in the file is a dictionary with a suitable /Linearized key and has an /L 395 // If the first object in the file is a dictionary with a suitable /Linearized key and has an /L
384 // key that accurately indicates the file size, initialize m->lindict and return true. 396 // key that accurately indicates the file size, initialize m->lindict and return true.
385 397
@@ -411,7 +423,7 @@ QPDF::isLinearized() @@ -411,7 +423,7 @@ QPDF::isLinearized()
411 continue; 423 continue;
412 } 424 }
413 425
414 - Dictionary candidate = getObject(toI(QUtil::string_to_ll(t1.getValue().data())), 0); 426 + Dictionary candidate = qpdf.getObject(toI(QUtil::string_to_ll(t1.getValue().data())), 0);
415 auto linkey = candidate["/Linearized"]; 427 auto linkey = candidate["/Linearized"];
416 if (!(linkey.isNumber() && toI(floor(linkey.getNumericValue())) == 1)) { 428 if (!(linkey.isNumber() && toI(floor(linkey.getNumericValue())) == 1)) {
417 return false; 429 return false;
@@ -432,7 +444,7 @@ void @@ -432,7 +444,7 @@ void
432 Lin::readLinearizationData() 444 Lin::readLinearizationData()
433 { 445 {
434 util::assertion( 446 util::assertion(
435 - qpdf.isLinearized(), "called readLinearizationData for file that is not linearized" // 447 + linearized(), "called readLinearizationData for file that is not linearized" //
436 ); 448 );
437 449
438 // This function throws an exception (which is trapped by checkLinearization()) for any errors 450 // This function throws an exception (which is trapped by checkLinearization()) for any errors
@@ -1083,12 +1095,18 @@ Lin::checkHOutlines() @@ -1083,12 +1095,18 @@ Lin::checkHOutlines()
1083 void 1095 void
1084 QPDF::showLinearizationData() 1096 QPDF::showLinearizationData()
1085 { 1097 {
  1098 + m->lin.show_data();
  1099 +}
  1100 +
  1101 +void
  1102 +Lin::show_data()
  1103 +{
1086 try { 1104 try {
1087 - m->lin.readLinearizationData();  
1088 - m->lin.checkLinearizationInternal();  
1089 - m->lin.dumpLinearizationDataInternal(); 1105 + readLinearizationData();
  1106 + checkLinearizationInternal();
  1107 + dumpLinearizationDataInternal();
1090 } catch (QPDFExc& e) { 1108 } catch (QPDFExc& e) {
1091 - m->lin.linearizationWarning(e.what()); 1109 + linearizationWarning(e.what());
1092 } 1110 }
1093 } 1111 }
1094 1112
libqpdf/qpdf/QPDF_private.hh
@@ -709,6 +709,10 @@ class QPDF::Doc::Linearization: Common @@ -709,6 +709,10 @@ class QPDF::Doc::Linearization: Common
709 { 709 {
710 } 710 }
711 711
  712 + bool linearized();
  713 + bool check();
  714 + void show_data();
  715 +
712 // For QPDFWriter: 716 // For QPDFWriter:
713 717
714 template <typename T> 718 template <typename T>
@@ -738,6 +742,7 @@ class QPDF::Doc::Linearization: Common @@ -738,6 +742,7 @@ class QPDF::Doc::Linearization: Common
738 int& O, 742 int& O,
739 bool compressed); 743 bool compressed);
740 744
  745 + private:
741 // methods to support linearization checking -- implemented in QPDF_linearization.cc 746 // methods to support linearization checking -- implemented in QPDF_linearization.cc
742 747
743 void readLinearizationData(); 748 void readLinearizationData();