| 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 | ▶ | use FileHandle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Font::TFM; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | $VERSION = '1.01'; | |||||||||
| 14 | |||||||||||
| 15 | sub new | ||||||||||
| 16 | 2 | ▶ | { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 17 | 2 | my ($class, $filename) = @_; | |||||||||
| 18 | 2 | my $fh = new FileHandle "> $filename"; | |||||||||
| 19 | 2 | ▶ | if (not defined $fh) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | { return undef; } | |||||||||
| 21 | 2 | binmode $fh; | |||||||||
| 22 | 2 | my $self = {}; | |||||||||
| 23 | 2 | bless $self; | |||||||||
| 24 | 2 | $self->{fh} = $fh; | |||||||||
| 25 | 2 | $self->{totallength} = 0; | |||||||||
| 26 | 2 | $self->{pagenum} = 0; | |||||||||
| 27 | 2 | $self->{previouspage} = -1; | |||||||||
| 28 | 2 | $self->{currdvipush} = $self->{maxdvipush} = 0; | |||||||||
| 29 | 2 | $self; | |||||||||
| 30 | } | ||||||||||
| 31 | sub close | ||||||||||
| 32 | 2 | ▶ | { shift->{fh}->close; } | ||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 33 | sub output | ||||||||||
| 34 | 36 | ▶ | { | ||||||||
|
Subroutine
output: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 35 | 36 | my $self = shift; | |||||||||
| 36 | 36 | my $outstring = pack(shift(@_), @_); | |||||||||
| 37 | 36 | $self->{totallength} += length $outstring; | |||||||||
| 38 | 36 | print { $self->{fh} } $outstring; | |||||||||
| 39 | } | ||||||||||
| 40 | sub preamble | ||||||||||
| 41 | 2 | ▶ | { | ||||||||
|
Subroutine
preamble: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 42 | 2 | my $self = shift; | |||||||||
| 43 | 2 | my (@currenttime, $currentasciitime, $comment, $commentlength); | |||||||||
| 44 | 2 | @currenttime = gmtime time; | |||||||||
| 45 | 2 | $currentasciitime = sprintf "%02d/%02d/%02d %02d:%02d:%02d GMT", $currenttime[3], | |||||||||
| 46 | $currenttime[4] + 1, $currenttime[5] % 100, @currenttime[2, 1, 0]; | ||||||||||
| 47 | 2 | $comment = "TeX::DVI.pm output ".$currentasciitime; | |||||||||
| 48 | 2 | $commentlength = length $comment; | |||||||||
| 49 | 2 | my @preamble = (247, 2, 25400000, 473628672, 1000, | |||||||||
| 50 | $commentlength, $comment); | ||||||||||
| 51 | 2 | $self->output("CCNNNCA$commentlength", @preamble); | |||||||||
| 52 | } | ||||||||||
| 53 | sub begin_page | ||||||||||
| 54 | 2 | ▶ | { | ||||||||
|
Subroutine
begin_page: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 55 | 2 | my $self = shift; | |||||||||
| 56 | 2 | $self->{pagenum}++; | |||||||||
| 57 | 2 | my $previous = $self->{previouspage}; | |||||||||
| 58 | 2 | $self->{previouspage} = $self->{totallength}; | |||||||||
| 59 | 2 | $self->output("CN10N", 139, $self->{pagenum}, (0) x 9, $previous); | |||||||||
| 60 | } | ||||||||||
| 61 | sub end_page | ||||||||||
| 62 | 2 | ▶ | { | ||||||||
|
Subroutine
end_page: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 63 | 2 | my $self = shift; | |||||||||
| 64 | 2 | $self->output("C", 140); | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | sub postamble | ||||||||||
| 68 | 2 | ▶ | { | ||||||||
|
Subroutine
postamble: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 69 | 2 | my $self = shift; | |||||||||
| 70 | 2 | my $postamblestart = $self->{totallength}; | |||||||||
| 71 | |||||||||||
| 72 | # postamble | ||||||||||
| 73 | $self->output("CNNNNNNnn", 248, $self->{previouspage}, | ||||||||||
| 74 | 25400000, 473628672, 1000, 1000000, 1000000, | ||||||||||
| 75 | 2 | $self->{maxdvipush}, $self->{pagenum}); | |||||||||
| 76 | |||||||||||
| 77 | 2 | for (0 .. $#{$self->{fonts}}) | |||||||||
| 78 | { | ||||||||||
| 79 | 1 | $self->print_font_def($_); | |||||||||
| 80 | } | ||||||||||
| 81 | # postpostamble | ||||||||||
| 82 | 2 | $self->output("CNCC4", 249, $postamblestart, 2, (223) x 4); | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | sub font_def | ||||||||||
| 86 | 1 | ▶ | { | ||||||||
|
Subroutine
font_def: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 87 | 1 | my ($self, $font) = @_; | |||||||||
| 88 | 1 | my $fontnumber = $#{$self->{fonts}} + 1; | |||||||||
| 89 | 1 | $self->{fonts}[$fontnumber] = $font; | |||||||||
| 90 | 1 | $self->print_font_def($fontnumber); | |||||||||
| 91 | 1 | $fontnumber; | |||||||||
| 92 | } | ||||||||||
| 93 | sub print_font_def | ||||||||||
| 94 | 2 | ▶ | { | ||||||||
|
Subroutine
print_font_def: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 95 | 2 | my ($self, $fontnumber) = @_; | |||||||||
| 96 | 2 | my $font = $self->{fonts}[$fontnumber]; | |||||||||
| 97 | 2 | my $name = $font->{name}; | |||||||||
| 98 | 2 | my $fontnamelength = length $name; | |||||||||
| 99 | $self->output("CCNNNCCA$fontnamelength", 243, $fontnumber, | ||||||||||
| 100 | $font->checksum(), $font->{fontsize} * 65536, | ||||||||||
| 101 | 2 | $font->{designsize} * 65536, 0, $fontnamelength, $name); | |||||||||
| 102 | } | ||||||||||
| 103 | sub font | ||||||||||
| 104 | 1 | ▶ | { | ||||||||
|
Subroutine
font: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 105 | 1 | my ($self, $fontnumber) = @_; | |||||||||
| 106 | 1 | $self->output("C", 171 + $fontnumber); | |||||||||
| 107 | 1 | $self->{actualfontnumber} = $fontnumber; | |||||||||
| 108 | 1 | $self->{actualfont} = $self->{fonts}[$fontnumber]; | |||||||||
| 109 | } | ||||||||||
| 110 | sub pop | ||||||||||
| 111 | 2 | ▶ | { | ||||||||
|
Subroutine
pop: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 112 | 2 | $self = shift; | |||||||||
| 113 | 2 | $self->{currdvipush}--; | |||||||||
| 114 | 2 | $self->output("C", 142); | |||||||||
| 115 | } | ||||||||||
| 116 | sub push | ||||||||||
| 117 | 2 | ▶ | { | ||||||||
|
Subroutine
push: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 118 | 2 | $self = shift; | |||||||||
| 119 | 2 | $self->{currdvipush}++; | |||||||||
| 120 | $self->{maxdvipush} = $self->{currdvipush} | ||||||||||
| 121 | 2 | ▶ | if ($self->{currdvipush} > $self->{maxdvipush}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 2 | $self->output("C", 141); | |||||||||
| 123 | } | ||||||||||
| 124 | sub hskip | ||||||||||
| 125 | 5 | ▶ | { | ||||||||
|
Subroutine
hskip: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 126 | 5 | my ($self, $skip) = @_; | |||||||||
| 127 | 5 | $self->output("CN", 146, int($skip)); | |||||||||
| 128 | 5 | return $skip; | |||||||||
| 129 | } | ||||||||||
| 130 | sub vskip | ||||||||||
| 131 | 6 | ▶ | { | ||||||||
|
Subroutine
vskip: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 132 | 6 | my ($self, $skip) = @_; | |||||||||
| 133 | 6 | $self->output("CN", 160, int($skip)); | |||||||||
| 134 | 6 | return $skip; | |||||||||
| 135 | } | ||||||||||
| 136 | sub black_box | ||||||||||
| 137 | 3 | ▶ | { | ||||||||
|
Subroutine
black_box: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||
| 138 | 3 | my ($self, $width, $height, $depth) = @_; | |||||||||
| 139 | 3 | ▶ | $width = 0 unless (defined $width); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 140 | 3 | ▶ | $height = 0 unless (defined $height); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | 3 | ▶ | $depth = 0 unless (defined $depth); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | 3 | $self->vskip($depth); | |||||||||
| 143 | 3 | $self->output("CNN", 137, int($height + $depth), int($width)); | |||||||||
| 144 | 3 | $self->vskip(-$depth); | |||||||||
| 145 | } | ||||||||||
| 146 | sub special | ||||||||||
| 147 | 0 | ▶ | { | ||||||||
|
Subroutine
special: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 148 | 0 | my ($self, $text) = @_; | |||||||||
| 149 | 0 | my $length = length $text; | |||||||||
| 150 | 0 | $self->output("CNA$length", 242, $length, $text); | |||||||||
| 151 | } | ||||||||||
| 152 | |||||||||||
| 153 | sub word | ||||||||||
| 154 | 2 | ▶ | { | ||||||||
|
Subroutine
word: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 155 | 2 | my ($self, $text) = @_; | |||||||||
| 156 | 2 | my @expanded = $self->{actualfont}->expand($text); | |||||||||
| 157 | 2 | ▶ | while (@expanded) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | { | ||||||||||
| 159 | 5 | my $word = shift @expanded; | |||||||||
| 160 | 5 | $word =~ s/([\200-\377])/\200${1}/gs; | |||||||||
| 161 | 5 | $self->output('A*', $word); | |||||||||
| 162 | 5 | ▶ | last if (not @expanded); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 163 | 3 | my $kern = shift @expanded; | |||||||||
| 164 | 3 | $self->hskip($kern); | |||||||||
| 165 | } | ||||||||||
| 166 | } | ||||||||||
| 167 | 2 | 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<TeX::DVI::new> 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<Font::TFM> 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<Font::TFM> 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<font_def>. | ||||||||||
| 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<ffi> 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 | |||||||||||