Commit 0a9ef286674541699b84af84f8d757c07687fbc2

Authored by m-holger
Committed by GitHub
2 parents e0add341 249427ea

Merge pull request #1411 from m-holger/i1410

Enhance --rotate usage message (fixes #1410)
libqpdf/QPDFJob.cc
@@ -398,24 +398,19 @@ QPDFJob::parseRotationParameter(std::string const& parameter) @@ -398,24 +398,19 @@ QPDFJob::parseRotationParameter(std::string const& parameter)
398 if (range.empty()) { 398 if (range.empty()) {
399 range = "1-z"; 399 range = "1-z";
400 } 400 }
401 - bool range_valid = false;  
402 try { 401 try {
403 QUtil::parse_numrange(range.c_str(), 0); 402 QUtil::parse_numrange(range.c_str(), 0);
404 - range_valid = true;  
405 } catch (std::runtime_error const&) { 403 } catch (std::runtime_error const&) {
406 - // ignore  
407 - }  
408 - if (range_valid &&  
409 - ((angle_str == "0") || (angle_str == "90") || (angle_str == "180") ||  
410 - (angle_str == "270"))) {  
411 - int angle = QUtil::string_to_int(angle_str.c_str());  
412 - if (relative == -1) {  
413 - angle = -angle;  
414 - }  
415 - m->rotations[range] = RotationSpec(angle, (relative != 0));  
416 - } else {  
417 usage("invalid parameter to rotate: " + parameter); 404 usage("invalid parameter to rotate: " + parameter);
418 } 405 }
  406 + int angle = QUtil::string_to_int(angle_str.c_str()) % 360;
  407 + if (angle % 90 != 0) {
  408 + usage("invalid parameter to rotate (angle must be a multiple of 90): " + parameter);
  409 + }
  410 + if (relative == -1) {
  411 + angle = -angle;
  412 + }
  413 + m->rotations[range] = RotationSpec(angle, (relative != 0));
419 } 414 }
420 415
421 std::vector<int> 416 std::vector<int>
qpdf/qtest/qpdf/invalid-rotated.out 0 → 100644
  1 +
  2 +qpdf: invalid parameter to rotate (angle must be a multiple of 90): 45:1,4,11,16
  3 +
  4 +For help:
  5 + qpdf --help=usage usage information
  6 + qpdf --help=topic help on a topic
  7 + qpdf --help=--option help on an option
  8 + qpdf --help general help and a topic list
  9 +
qpdf/qtest/rotate-pages.test
@@ -14,7 +14,7 @@ cleanup(); @@ -14,7 +14,7 @@ cleanup();
14 14
15 my $td = new TestDriver('rotate-pages'); 15 my $td = new TestDriver('rotate-pages');
16 16
17 -my $n_tests = 18; 17 +my $n_tests = 21;
18 18
19 # Do absolute, positive, and negative on ranges that include 19 # Do absolute, positive, and negative on ranges that include
20 # inherited and non-inherited. 20 # inherited and non-inherited.
@@ -32,6 +32,22 @@ $td-&gt;runtest(&quot;check output&quot;, @@ -32,6 +32,22 @@ $td-&gt;runtest(&quot;check output&quot;,
32 {$td->COMMAND => "qpdf-test-compare a.pdf rotated.pdf"}, 32 {$td->COMMAND => "qpdf-test-compare a.pdf rotated.pdf"},
33 {$td->FILE => "rotated.pdf", $td->EXIT_STATUS => 0}); 33 {$td->FILE => "rotated.pdf", $td->EXIT_STATUS => 0});
34 34
  35 +$td->runtest("page rotation (>270)",
  36 + {$td->COMMAND => "qpdf --static-id to-rotate.pdf a.pdf" .
  37 + " --rotate=+450:1,4,11,16" .
  38 + " --rotate=900:2,5,12-13" .
  39 + " --rotate=-1890:3,15,17,18"},
  40 + {$td->STRING => "", $td->EXIT_STATUS => 0});
  41 +$td->runtest("check output",
  42 + {$td->COMMAND => "qpdf-test-compare a.pdf rotated.pdf"},
  43 + {$td->FILE => "rotated.pdf", $td->EXIT_STATUS => 0});
  44 +
  45 +$td->runtest("invald page rotation",
  46 + {$td->COMMAND => "qpdf --static-id to-rotate.pdf a.pdf" .
  47 + " --rotate=45:1,4,11,16"},
  48 + {$td->FILE => "invalid-rotated.out", $td->EXIT_STATUS => 2},
  49 + $td->NORMALIZE_NEWLINES);
  50 +
35 $td->runtest("remove rotation", 51 $td->runtest("remove rotation",
36 {$td->COMMAND => "qpdf --static-id rotated.pdf a.pdf" . 52 {$td->COMMAND => "qpdf --static-id rotated.pdf a.pdf" .
37 " --qdf --no-original-object-ids --rotate=0"}, 53 " --qdf --no-original-object-ids --rotate=0"},