| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
TeX::DVI -- write out TeX's DVI (DeVice Independent) file |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package TeX::DVI; |
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
24002
|
use FileHandle; |
|
|
2
|
|
|
|
|
37397
|
|
|
|
2
|
|
|
|
|
15
|
|
|
11
|
2
|
|
|
2
|
|
2051
|
use Font::TFM; |
|
|
2
|
|
|
|
|
4588
|
|
|
|
2
|
|
|
|
|
2612
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '1.01'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
|
16
|
|
|
|
|
|
|
{ |
|
17
|
2
|
|
|
2
|
0
|
1864
|
my ($class, $filename) = @_; |
|
18
|
2
|
|
|
|
|
27
|
my $fh = new FileHandle "> $filename"; |
|
19
|
2
|
50
|
|
|
|
321
|
if (not defined $fh) |
|
20
|
0
|
|
|
|
|
0
|
{ return undef; } |
|
21
|
2
|
|
|
|
|
7
|
binmode $fh; |
|
22
|
2
|
|
|
|
|
5
|
my $self = {}; |
|
23
|
2
|
|
|
|
|
4
|
bless $self; |
|
24
|
2
|
|
|
|
|
12
|
$self->{fh} = $fh; |
|
25
|
2
|
|
|
|
|
5
|
$self->{totallength} = 0; |
|
26
|
2
|
|
|
|
|
7
|
$self->{pagenum} = 0; |
|
27
|
2
|
|
|
|
|
5
|
$self->{previouspage} = -1; |
|
28
|
2
|
|
|
|
|
6
|
$self->{currdvipush} = $self->{maxdvipush} = 0; |
|
29
|
2
|
|
|
|
|
6
|
$self; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
sub close |
|
32
|
2
|
|
|
2
|
0
|
19
|
{ shift->{fh}->close; } |
|
33
|
|
|
|
|
|
|
sub output |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
36
|
|
|
36
|
0
|
104
|
my $self = shift; |
|
36
|
36
|
|
|
|
|
88
|
my $outstring = pack(shift(@_), @_); |
|
37
|
36
|
|
|
|
|
63
|
$self->{totallength} += length $outstring; |
|
38
|
36
|
|
|
|
|
35
|
print { $self->{fh} } $outstring; |
|
|
36
|
|
|
|
|
123
|
|
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
sub preamble |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
2
|
|
|
2
|
0
|
443
|
my $self = shift; |
|
43
|
2
|
|
|
|
|
4
|
my (@currenttime, $currentasciitime, $comment, $commentlength); |
|
44
|
2
|
|
|
|
|
48
|
@currenttime = gmtime time; |
|
45
|
2
|
|
|
|
|
25
|
$currentasciitime = sprintf "%02d/%02d/%02d %02d:%02d:%02d GMT", $currenttime[3], |
|
46
|
|
|
|
|
|
|
$currenttime[4] + 1, $currenttime[5] % 100, @currenttime[2, 1, 0]; |
|
47
|
2
|
|
|
|
|
6
|
$comment = "TeX::DVI.pm output ".$currentasciitime; |
|
48
|
2
|
|
|
|
|
4
|
$commentlength = length $comment; |
|
49
|
2
|
|
|
|
|
7
|
my @preamble = (247, 2, 25400000, 473628672, 1000, |
|
50
|
|
|
|
|
|
|
$commentlength, $comment); |
|
51
|
2
|
|
|
|
|
13
|
$self->output("CCNNNCA$commentlength", @preamble); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
sub begin_page |
|
54
|
|
|
|
|
|
|
{ |
|
55
|
2
|
|
|
2
|
0
|
13
|
my $self = shift; |
|
56
|
2
|
|
|
|
|
5
|
$self->{pagenum}++; |
|
57
|
2
|
|
|
|
|
5
|
my $previous = $self->{previouspage}; |
|
58
|
2
|
|
|
|
|
4
|
$self->{previouspage} = $self->{totallength}; |
|
59
|
2
|
|
|
|
|
10
|
$self->output("CN10N", 139, $self->{pagenum}, (0) x 9, $previous); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
sub end_page |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
2
|
|
|
2
|
0
|
12
|
my $self = shift; |
|
64
|
2
|
|
|
|
|
13
|
$self->output("C", 140); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub postamble |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
2
|
|
|
2
|
0
|
11
|
my $self = shift; |
|
70
|
2
|
|
|
|
|
5
|
my $postamblestart = $self->{totallength}; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# postamble |
|
73
|
2
|
|
|
|
|
9
|
$self->output("CNNNNNNnn", 248, $self->{previouspage}, |
|
74
|
|
|
|
|
|
|
25400000, 473628672, 1000, 1000000, 1000000, |
|
75
|
|
|
|
|
|
|
$self->{maxdvipush}, $self->{pagenum}); |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
3
|
for (0 .. $#{$self->{fonts}}) |
|
|
2
|
|
|
|
|
9
|
|
|
78
|
|
|
|
|
|
|
{ |
|
79
|
1
|
|
|
|
|
3
|
$self->print_font_def($_); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
# postpostamble |
|
82
|
2
|
|
|
|
|
9
|
$self->output("CNCC4", 249, $postamblestart, 2, (223) x 4); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub font_def |
|
86
|
|
|
|
|
|
|
{ |
|
87
|
1
|
|
|
1
|
0
|
6
|
my ($self, $font) = @_; |
|
88
|
1
|
|
|
|
|
1
|
my $fontnumber = $#{$self->{fonts}} + 1; |
|
|
1
|
|
|
|
|
3
|
|
|
89
|
1
|
|
|
|
|
3
|
$self->{fonts}[$fontnumber] = $font; |
|
90
|
1
|
|
|
|
|
3
|
$self->print_font_def($fontnumber); |
|
91
|
1
|
|
|
|
|
3
|
$fontnumber; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
sub print_font_def |
|
94
|
|
|
|
|
|
|
{ |
|
95
|
2
|
|
|
2
|
0
|
4
|
my ($self, $fontnumber) = @_; |
|
96
|
2
|
|
|
|
|
3
|
my $font = $self->{fonts}[$fontnumber]; |
|
97
|
2
|
|
|
|
|
7
|
my $name = $font->{name}; |
|
98
|
2
|
|
|
|
|
2
|
my $fontnamelength = length $name; |
|
99
|
2
|
|
|
|
|
17
|
$self->output("CCNNNCCA$fontnamelength", 243, $fontnumber, |
|
100
|
|
|
|
|
|
|
$font->checksum(), $font->{fontsize} * 65536, |
|
101
|
|
|
|
|
|
|
$font->{designsize} * 65536, 0, $fontnamelength, $name); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
sub font |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
1
|
|
|
1
|
0
|
4
|
my ($self, $fontnumber) = @_; |
|
106
|
1
|
|
|
|
|
3
|
$self->output("C", 171 + $fontnumber); |
|
107
|
1
|
|
|
|
|
3
|
$self->{actualfontnumber} = $fontnumber; |
|
108
|
1
|
|
|
|
|
3
|
$self->{actualfont} = $self->{fonts}[$fontnumber]; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
sub pop |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
2
|
|
|
2
|
0
|
11
|
$self = shift; |
|
113
|
2
|
|
|
|
|
5
|
$self->{currdvipush}--; |
|
114
|
2
|
|
|
|
|
5
|
$self->output("C", 142); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
sub push |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
2
|
|
|
2
|
0
|
12
|
$self = shift; |
|
119
|
2
|
|
|
|
|
6
|
$self->{currdvipush}++; |
|
120
|
2
|
50
|
|
|
|
10
|
$self->{maxdvipush} = $self->{currdvipush} |
|
121
|
|
|
|
|
|
|
if ($self->{currdvipush} > $self->{maxdvipush}); |
|
122
|
2
|
|
|
|
|
7
|
$self->output("C", 141); |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
sub hskip |
|
125
|
|
|
|
|
|
|
{ |
|
126
|
5
|
|
|
5
|
0
|
30
|
my ($self, $skip) = @_; |
|
127
|
5
|
|
|
|
|
16
|
$self->output("CN", 146, int($skip)); |
|
128
|
5
|
|
|
|
|
12
|
return $skip; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
sub vskip |
|
131
|
|
|
|
|
|
|
{ |
|
132
|
6
|
|
|
6
|
0
|
11
|
my ($self, $skip) = @_; |
|
133
|
6
|
|
|
|
|
14
|
$self->output("CN", 160, int($skip)); |
|
134
|
6
|
|
|
|
|
11
|
return $skip; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
sub black_box |
|
137
|
|
|
|
|
|
|
{ |
|
138
|
3
|
|
|
3
|
0
|
50
|
my ($self, $width, $height, $depth) = @_; |
|
139
|
3
|
50
|
|
|
|
12
|
$width = 0 unless (defined $width); |
|
140
|
3
|
50
|
|
|
|
16
|
$height = 0 unless (defined $height); |
|
141
|
3
|
50
|
|
|
|
10
|
$depth = 0 unless (defined $depth); |
|
142
|
3
|
|
|
|
|
10
|
$self->vskip($depth); |
|
143
|
3
|
|
|
|
|
9
|
$self->output("CNN", 137, int($height + $depth), int($width)); |
|
144
|
3
|
|
|
|
|
9
|
$self->vskip(-$depth); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
sub special |
|
147
|
|
|
|
|
|
|
{ |
|
148
|
0
|
|
|
0
|
0
|
0
|
my ($self, $text) = @_; |
|
149
|
0
|
|
|
|
|
0
|
my $length = length $text; |
|
150
|
0
|
|
|
|
|
0
|
$self->output("CNA$length", 242, $length, $text); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub word |
|
154
|
|
|
|
|
|
|
{ |
|
155
|
2
|
|
|
2
|
0
|
15
|
my ($self, $text) = @_; |
|
156
|
2
|
|
|
|
|
25
|
my @expanded = $self->{actualfont}->expand($text); |
|
157
|
2
|
|
|
|
|
265
|
while (@expanded) |
|
158
|
|
|
|
|
|
|
{ |
|
159
|
5
|
|
|
|
|
8
|
my $word = shift @expanded; |
|
160
|
5
|
|
|
|
|
10
|
$word =~ s/([\200-\377])/\200${1}/gs; |
|
161
|
5
|
|
|
|
|
10
|
$self->output('A*', $word); |
|
162
|
5
|
100
|
|
|
|
14
|
last if (not @expanded); |
|
163
|
3
|
|
|
|
|
5
|
my $kern = shift @expanded; |
|
164
|
3
|
|
|
|
|
8
|
$self->hskip($kern); |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
1; |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
use TeX::DVI; |
|
172
|
|
|
|
|
|
|
use Font::TFM; |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $dvi = new TeX::DVI "texput.dvi"; |
|
175
|
|
|
|
|
|
|
my $font = new_at Font::TFM "cmr10", 12 |
|
176
|
|
|
|
|
|
|
or die "Error loading cmr10 at 12 pt: $Font::TFM::errstr\n"; |
|
177
|
|
|
|
|
|
|
$dvi->preamble(); |
|
178
|
|
|
|
|
|
|
$dvi->begin_page(); |
|
179
|
|
|
|
|
|
|
$dvi->push(); |
|
180
|
|
|
|
|
|
|
my $fn = $dvi->font_def($font); |
|
181
|
|
|
|
|
|
|
$dvi->font($fn); |
|
182
|
|
|
|
|
|
|
$dvi->word("difficulty"); |
|
183
|
|
|
|
|
|
|
$dvi->hskip($font->space()); |
|
184
|
|
|
|
|
|
|
$dvi->word("AVA"); |
|
185
|
|
|
|
|
|
|
$dvi->black_box($font->em_width(), $font->x_height()); |
|
186
|
|
|
|
|
|
|
$dvi->pop(); |
|
187
|
|
|
|
|
|
|
$dvi->end_page(); |
|
188
|
|
|
|
|
|
|
$dvi->postamble(); |
|
189
|
|
|
|
|
|
|
$dvi->close(); |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Method B creates a new DVI object in memory and opens |
|
194
|
|
|
|
|
|
|
the output DVI file. After that, elements can be written into the |
|
195
|
|
|
|
|
|
|
file using appropriate methods. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
These are the methods available on the B object: |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=over |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item preamble, postamble, begin_page, end_page, push, pop |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Writes out appropriate command of the C<.dvi> file. |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item font_def |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
The parameter is a reference to a B object. Info out of this |
|
208
|
|
|
|
|
|
|
object will be printed out. The method returns the internal number |
|
209
|
|
|
|
|
|
|
of the font in this C<.dvi> file. |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item font |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Writes out the font_sel command, the parametr is the number returned |
|
214
|
|
|
|
|
|
|
by B. |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item hskip, vskip |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Skips. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item black_box |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Creates a black box, can be used for hrules and vrules. |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item special |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Writes out the special command, one parameter is written as the |
|
227
|
|
|
|
|
|
|
command. |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item word |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Writes out a word given as the first parameter. The currently selected |
|
232
|
|
|
|
|
|
|
font is used to gather information about ligatures and kernings, |
|
233
|
|
|
|
|
|
|
that's why it's possible to say |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
$dvi->word("difficulty"); |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
and the C will be ligatured all right. |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item close |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Close the file. |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=back |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 BUGS |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
The error handling is rather weak -- the modul currently assumes you |
|
248
|
|
|
|
|
|
|
know why you call the method you call. |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 VERSION |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
1.01 |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 AVAILABLE FROM |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
http://www.adelton.com/perl/TeX-DVI/ |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 AUTHOR |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
(c) 1996--2011 Jan Pazdziora. |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
All rights reserved. This package is free software; you can |
|
263
|
|
|
|
|
|
|
redistribute it and/or modify it under the same terms as Perl itself. |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Contact the author at jpx dash perl at adelton dot com. |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Font::TFM(3), TeX::DVI::Parse(3), perl(1). |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=cut |
|
272
|
|
|
|
|
|
|
|