summaryrefslogtreecommitdiff
path: root/dviware/dvi2bitmap/test/t8.pl.in
blob: 85519e351900da59097f8386e15a7c82ccfe3b92 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#! /usr/bin/perl -w
#
# Testing dvi2bitmap specials
#
# Create a TeX file with strut and mark specials in it, use
# --query=bitmaps, and check that the correct stuff is reported.

sub compare_bitmaps($$\@);

$texbin='@TEX@';
if ($texbin eq 'NO_TEX') {
    print STDERR "No TeX binary available.  Can't run t8, so assume success\n";
    exit 0;
}

$prefix = 'temp-t8';
$texfile = "$prefix.tex";
$m = 2;				# magnification factor

open (TEX, ">$texfile") || die "Can't open $texfile for output";
$newpage = "\n\n\\vfill\\eject\n\n";

$nerrors = 0;

@expected = ();

print TEX <<'EOD';
%\hoffset=0pt
%\voffset=0pt
%\leftskip=0pt % default
%\topskip=0pt
%\parindent=0pt
%\parskip=0pt
\nopagenumbers


EOD

print TEX "\\special{dvi2bitmap default unit bp}\n\n";

print TEX '\vrule width 20bp height 10bp';
print TEX $newpage;
push(@expected, [20*$m, 10*$m]);


print TEX '\vrule width 20bp height 10bp \special{dvi2bitmap strut 10 4 5 6}';
print TEX $newpage;
push(@expected, [24*$m, 16*$m]);

print TEX '\vrule width 10bp height 10bp \special{dvi2bitmap strut 12 0 15 0}';
print TEX $newpage;
push(@expected, [12*$m, 15*$m]);

print TEX '\vrule width 20bp height 10bp \special{dvi2bitmap mark}';
print TEX $newpage;
push(@expected, [20*$m, 10*$m, 20*$m, 10*$m]);

print TEX "\\bye\n";

close(TEX);

system("$texbin $prefix") == 0
    || die "Command 'tex $prefix' failed";

########## test 1
#
# Basic use

$cmd = sprintf("../dvi2bitmap --output=%s-%%d --query=bitmaps --resolution=%d --verbose=quiet %s.dvi",
	       $prefix, 72*$m, $prefix);
$nerrors += compare_bitmaps("Test 1", $cmd, @expected);


########## test 2
#
# Same, but with a --magnification of 2, so that the expected values
# must be doubled 

@texpected = ();
foreach my $ev (@expected) {
    my @t = ();
    foreach my $tt (@$ev) {
        push (@t, $tt*2);
    }
    push (@texpected, \@t);
}

$cmd = sprintf("../dvi2bitmap --output=%s-%%d --query=bitmaps --resolution=%d --verbose=quiet --magnification=2 %s.dvi",
	       $prefix, 72*$m, $prefix);
$nerrors += compare_bitmaps("Test 2", $cmd, @texpected);

########## test 3
#
# Same, but with a --magnification of 5, so that the expected values
# must be multiplied by 5.  This should show up more straightforward
# rounding errors

@texpected = ();
foreach my $ev (@expected) {
    my @t = ();
    foreach my $tt (@$ev) {
        push (@t, $tt*5);
    }
    push (@texpected, \@t);
}

$cmd = sprintf("../dvi2bitmap --output=%s-%%d --query=bitmaps --resolution=%d --verbose=quiet --magnification=5 %s.dvi",
	       $prefix, 72*$m, $prefix);
$nerrors += compare_bitmaps("Test 3", $cmd, @texpected);

########## test 4
#
# Same, but with a --magnification of 3 and --scaledown of 2.  This
# seems to stress roundings.  In DviFilePosition::DviFilePosition, the
# initialised positions are offset by one to avoid a failure here (and
# are otherwise unmotivated). [there's a reference to this text there,
# so change both together]

@texpected = ();
foreach my $ev (@expected) {
    my @t = ();
    foreach my $tt (@$ev) {
        push (@t, $tt*1.5);
    }
    push (@texpected, \@t);
}

$cmd = sprintf("../dvi2bitmap --output=%s-%%d --query=bitmaps --resolution=%d --verbose=quiet --magnification=3 --scaledown=2 %s.dvi",
	       $prefix, 72*$m, $prefix);
$nerrors += compare_bitmaps("Test 4", $cmd, @texpected);

########## That's all....


exit($nerrors);


sub compare_bitmaps ($$\@) {
    my $testlabel = shift;
    my $cmd = shift;
    my $exref = shift;
    my $nerr = 0;

    my @exp = @$exref;

    open (DB, "$cmd |") || die "Can't open $cmd in a pipe";

    my $ntests = 0;
    while (<DB>) {
        chomp;
        s/^Qbitmaps \S*\s*//;
        my @a = split;

        if ($#expected < 0) {
            print STDERR "More actual than expected\n";
            $nerr++;
            last;
        }
        my @e = @{$exp[$ntests]};
        $ntests++;

        my $isok = 1;
        my $i = 0;
        while (1) {
            if (! (defined($e[$i]) && defined($a[$i]))) { # one list has ended
                $isok = !(defined($e[$i]) || defined($a[$i]));
                # false unless both undef
                last;
            }
            if ($e[$i] != $a[$i]) {
                $isok = 0;
                last;
            }
            $i++;
        }
        if (!$isok) {
            print STDERR "$testlabel, page $ntests: expected [";
            foreach $i (0..$#e) {
                printf STDERR " %.1f", $e[$i];
            }
            print STDERR " ], got [";
            foreach $i (0..$#a) {
                printf STDERR " %.1f", $a[$i];
            }
            print " ]\n";
            $nerr++;
        }
    }

    close(DB);

    return $nerr;
}