aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/rotate-pages.test
blob: c5e293e85bdf62c5297346bfb8d5ea3cc8ca93ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;

unshift(@INC, '.');
require qpdf_test_helpers;

chdir("qpdf") or die "chdir testdir failed: $!\n";

require TestDriver;

cleanup();

my $td = new TestDriver('rotate-pages');

my $n_tests = 18;

# Do absolute, positive, and negative on ranges that include
# inherited and non-inherited.
# Pages 11-15 inherit /Rotate 90
# Pages 1 and 2 have explicit /Rotate 270
# Pages 16 and 17 have explicit /Rotate 180

$td->runtest("page rotation",
             {$td->COMMAND => "qpdf --static-id to-rotate.pdf a.pdf" .
                  " --rotate=+90:1,4,11,16" .
                  " --rotate=180:2,5,12-13" .
                  " --rotate=-90:3,15,17,18"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "rotated.pdf"});

$td->runtest("remove rotation",
             {$td->COMMAND => "qpdf --static-id rotated.pdf a.pdf" .
                  " --qdf --no-original-object-ids --rotate=0"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "unrotated.pdf"});

$td->runtest("rotate all pages",
             {$td->COMMAND =>
                  "qpdf --static-id --rotate=180 minimal.pdf a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "minimal-rotated.pdf"});

$td->runtest("flatten with inherited rotate",
             {$td->COMMAND =>
                  "qpdf --static-id --flatten-rotation" .
                  " inherited-rotate.pdf a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "inherited-flattened.pdf"});

foreach my $angle (qw(90 180 270))
{
    $td->runtest("rotate annotations",
                 {$td->COMMAND =>
                      "qpdf --static-id --qdf --rotate=$angle" .
                      " --flatten-rotation --no-original-object-ids" .
                      " form-fields-and-annotations.pdf a.pdf"},
                 {$td->STRING => "", $td->EXIT_STATUS => 0});
    $td->runtest("check output (flatten $angle)",
                 {$td->FILE => "a.pdf"},
                 {$td->FILE => "annotations-rotated-$angle.pdf"});
}

# The file form-fields-and-annotations-shared.pdf contains some
# annotations that appear in multiple pages /Annots, some non-shared
# things that share appearance streams, some form fields appear on
# multiple pages, and an indirect /Annotations array. It is out of
# spec in several ways but still works in most viewers. These test
# make sure we don't make anything worse and also end up exercising
# some cases of things being copied more than once, though we also
# exercise that with legitimate test cases using overlay.

$td->runtest("shared annotations 1 page",
             {$td->COMMAND =>
                  "qpdf --qdf --no-original-object-ids --static-id" .
                  " --rotate=90:1 form-fields-and-annotations-shared.pdf" .
                  " a.pdf --flatten-rotation"},
             {$td->STRING => "", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "rotated-shared-annotations-1.pdf"});
$td->runtest("shared annotations 2 pages",
             {$td->COMMAND =>
                  "qpdf --qdf --no-original-object-ids --static-id" .
                  " --rotate=90:1,2 form-fields-and-annotations-shared.pdf" .
                  " a.pdf --flatten-rotation"},
             {$td->STRING => "", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "rotated-shared-annotations-2.pdf"});

cleanup();
$td->report($n_tests);