aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/flatten-annotations.test
blob: 91124c6c39d9d3be5ab56c0b8f83ed6a8d36900b (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
#!/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('flatten-annotations');

my $n_tests = 0;

# manual-appearances was created by hand-coding appearance streams
# with graphics that make it easy to test matrix calculations. The
# result of flattening the annotations was compared visually with
# okular. Some PDF viewers don't actually display the original version
# correctly. The pages are as follows:
# - page 1: normal
# - page 2: rotate 90 with /F 20 (NoRotate)
# - page 3: non-trivial matrix
# - page 4: non-trivial matrix, rotate
# - page 5: rotate 180 with /F 20
# - page 6: rotate 90, /F 20, non-trivial matrix
# - page 7: flags: top is print, middle is screen, bottom is hidden
# - page 8: rotate 270 with /F 20
# - page 9: normal -- available for additional testing
#
# form-filled-by-acrobat was filled in using the Acrobat Reader
# android app. One of its appearance streams is actually an image.
#
# need-appearances.pdf is based on field-types.pdf with manual edits
# to turn on NeedAppearances, change /V for several fields, and add
# the comment annotation from comment-annotation.pdf. The test output
# includes a flattened version of the comment annotation but not of
# the form fields. Changes:
# - field-types.pdf has /NeedAppearances true
# - text1: blank -> abc
# - r1: 1 -> 2
# - list1: blank -> five
# - combolist1: blank -> pi
# - drop1: blank -> elephant
# - combodrop1: blank -> delta

my @annotation_files = (
    'manual-appearances',
    'form-filled-by-acrobat',
    'comment-annotation',
    'comment-annotation-direct',
    'sample-form',
    'need-appearances',
    'need-appearances-more',
    'annotation-no-resources',
    );
$n_tests += 2 * scalar(@annotation_files);

foreach my $f (@annotation_files)
{
    my $exp_out = {$td->STRING => "", $td->EXIT_STATUS => 0};
    if (-f "$f-warn.out")
    {
        $exp_out = {$td->FILE => "$f-warn.out", $td->EXIT_STATUS => 3};
    }
    $td->runtest("flatten $f",
                 {$td->COMMAND =>
                      "qpdf --qdf --static-id --no-original-object-ids" .
                      " --flatten-annotations=all $f.pdf a.pdf"},
                 $exp_out,
                 $td->NORMALIZE_NEWLINES);
    $td->runtest("check output",
                 {$td->FILE => "a.pdf"},
                 {$td->FILE => "$f-out.pdf"});
}

$n_tests += 4;
foreach my $f (qw(screen print))
{
    $td->runtest("flatten for $f",
                 {$td->COMMAND =>
                      "qpdf --qdf --static-id --no-original-object-ids" .
                      " --flatten-annotations=$f manual-appearances.pdf a.pdf"},
                 {$td->STRING => "", $td->EXIT_STATUS => 0},
                 $td->NORMALIZE_NEWLINES);
    $td->runtest("check output",
                 {$td->FILE => "a.pdf"},
                 {$td->FILE => "manual-appearances-$f-out.pdf"});
}

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