line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormatPS; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Format HTML as PostScript |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
20749
|
use 5.006_001; |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
116
|
|
10
|
1
|
|
|
1
|
|
793
|
use IO::File; |
|
1
|
|
|
|
|
10235
|
|
|
1
|
|
|
|
|
139
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use base 'HTML::Formatter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
692
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '2.06'; # VERSION |
15
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# We now use Smart::Comments in place of the old DEBUG framework. |
18
|
|
|
|
|
|
|
# this should be commented out in release versions.... |
19
|
|
|
|
|
|
|
##use Smart::Comments; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
22
|
|
|
|
|
|
|
# A few routines that convert lengths into points |
23
|
14
|
|
|
14
|
0
|
57
|
sub mm { $_[0] * 72 / 25.4; } |
24
|
14
|
|
|
14
|
0
|
45
|
sub in { $_[0] * 72; } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
27
|
|
|
|
|
|
|
my %PaperSizes = ( |
28
|
|
|
|
|
|
|
A3 => [ mm(297), mm(420) ], |
29
|
|
|
|
|
|
|
A4 => [ mm(210), mm(297) ], |
30
|
|
|
|
|
|
|
A5 => [ mm(148), mm(210) ], |
31
|
|
|
|
|
|
|
B4 => [ 729, 1032 ], |
32
|
|
|
|
|
|
|
B5 => [ 516, 729 ], |
33
|
|
|
|
|
|
|
Letter => [ in(8.5), in(11) ], |
34
|
|
|
|
|
|
|
Legal => [ in(8.5), in(14) ], |
35
|
|
|
|
|
|
|
Executive => [ in(7.5), in(10) ], |
36
|
|
|
|
|
|
|
Tabloid => [ in(11), in(17) ], |
37
|
|
|
|
|
|
|
Statement => [ in(5.5), in(8.5) ], |
38
|
|
|
|
|
|
|
Folio => [ in(8.5), in(13) ], |
39
|
|
|
|
|
|
|
"10x14" => [ in(10), in(14) ], |
40
|
|
|
|
|
|
|
Quarto => [ 610, 780 ], |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
44
|
|
|
|
|
|
|
my %FontFamilies = ( |
45
|
|
|
|
|
|
|
Courier => [ |
46
|
|
|
|
|
|
|
qw(Courier |
47
|
|
|
|
|
|
|
Courier-Bold |
48
|
|
|
|
|
|
|
Courier-Oblique |
49
|
|
|
|
|
|
|
Courier-BoldOblique) |
50
|
|
|
|
|
|
|
], |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Helvetica => [ |
53
|
|
|
|
|
|
|
qw(Helvetica |
54
|
|
|
|
|
|
|
Helvetica-Bold |
55
|
|
|
|
|
|
|
Helvetica-Oblique |
56
|
|
|
|
|
|
|
Helvetica-BoldOblique) |
57
|
|
|
|
|
|
|
], |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Times => [ |
60
|
|
|
|
|
|
|
qw(Times-Roman |
61
|
|
|
|
|
|
|
Times-Bold |
62
|
|
|
|
|
|
|
Times-Italic |
63
|
|
|
|
|
|
|
Times-BoldItalic) |
64
|
|
|
|
|
|
|
], |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
68
|
|
|
|
|
|
|
# size 0 1 2 3 4 5 6 7 8 |
69
|
|
|
|
|
|
|
my @FontSizes = ( 5, 6, 8, 10, 12, 14, 18, 24, 32 ); |
70
|
|
|
|
|
|
|
|
71
|
8
|
|
|
8
|
0
|
13
|
sub BOLD { 0x01; } |
72
|
0
|
|
|
0
|
0
|
0
|
sub ITALIC { 0x02; } |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my %param = ( |
75
|
|
|
|
|
|
|
papersize => 'papersize', |
76
|
|
|
|
|
|
|
paperwidth => 'paperwidth', |
77
|
|
|
|
|
|
|
paperheight => 'paperheigth', |
78
|
|
|
|
|
|
|
leftmargin => 'lmW', |
79
|
|
|
|
|
|
|
rightmargin => 'rmW', |
80
|
|
|
|
|
|
|
horizontalmargin => 'mW', |
81
|
|
|
|
|
|
|
topmargin => 'tmH', |
82
|
|
|
|
|
|
|
bottommargin => 'bmH', |
83
|
|
|
|
|
|
|
verticalmargin => 'mH', |
84
|
|
|
|
|
|
|
no_prolog => 'no_prolog', |
85
|
|
|
|
|
|
|
no_trailer => 'no_trailer', |
86
|
|
|
|
|
|
|
pageno => 'printpageno', |
87
|
|
|
|
|
|
|
startpage => 'startpage', |
88
|
|
|
|
|
|
|
fontfamily => 'family', |
89
|
|
|
|
|
|
|
fontscale => 'fontscale', |
90
|
|
|
|
|
|
|
leading => 'leading', |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub new { |
97
|
2
|
|
|
2
|
1
|
61
|
my $class = shift; |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
15
|
my $self = $class->SUPER::new(@_); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Obtained from the element |
102
|
2
|
|
|
|
|
9
|
$self->{title} = ""; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# The font ID last sent to the PostScript output (this may be |
105
|
|
|
|
|
|
|
# temporarily different from the "current font" as read from |
106
|
|
|
|
|
|
|
# the HTML input). Initially none. |
107
|
2
|
|
|
|
|
28
|
$self->{psfontid} = ""; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Pending horizontal space. A list [ " ", $fontid, $width ], |
110
|
|
|
|
|
|
|
# or undef if no space is pending. |
111
|
2
|
|
|
|
|
4
|
$self->{hspace} = undef; |
112
|
|
|
|
|
|
|
|
113
|
2
|
|
|
|
|
5
|
$self; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
117
|
|
|
|
|
|
|
sub default_values { |
118
|
2
|
|
|
2
|
0
|
10
|
( shift->SUPER::default_values(), |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
family => "Times", |
121
|
|
|
|
|
|
|
mH => mm(40), |
122
|
|
|
|
|
|
|
mW => mm(20), |
123
|
|
|
|
|
|
|
printpageno => 1, |
124
|
|
|
|
|
|
|
startpage => 1, # yes, you can start numbering at 10, or whatever. |
125
|
|
|
|
|
|
|
fontscale => 1, |
126
|
|
|
|
|
|
|
leading => 0.1, |
127
|
|
|
|
|
|
|
papersize => 'A4', |
128
|
|
|
|
|
|
|
paperwidth => mm(210), |
129
|
|
|
|
|
|
|
paperheight => mm(297), |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
134
|
|
|
|
|
|
|
sub configure { |
135
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $hash ) = @_; |
136
|
|
|
|
|
|
|
|
137
|
1
|
|
|
|
|
1
|
my ( $key, $val ); |
138
|
1
|
|
|
|
|
7
|
while ( ( $key, $val ) = each %$hash ) { |
139
|
2
|
|
|
|
|
6
|
$key = lc $key; |
140
|
2
|
50
|
|
|
|
8
|
croak "Illegal parameter ($key => $val)" unless exists $param{$key}; |
141
|
2
|
|
|
|
|
4
|
$key = $param{$key}; |
142
|
|
|
|
|
|
|
{ |
143
|
2
|
50
|
|
|
|
2
|
$key eq "family" && do { |
|
2
|
|
|
|
|
6
|
|
144
|
0
|
|
|
|
|
0
|
$val = "\u\L$val"; |
145
|
|
|
|
|
|
|
croak "Unknown font family ($val)" |
146
|
0
|
0
|
|
|
|
0
|
unless exists $FontFamilies{$val}; |
147
|
0
|
|
|
|
|
0
|
$self->{family} = $val; |
148
|
0
|
|
|
|
|
0
|
last; |
149
|
|
|
|
|
|
|
}; |
150
|
2
|
50
|
|
|
|
4
|
$key eq "papersize" && do { |
151
|
0
|
0
|
|
|
|
0
|
$self->papersize($val) |
152
|
|
|
|
|
|
|
|| croak sprintf "Unknown papersize '%s'.\nThe knowns are: %s.\nAborting", |
153
|
|
|
|
|
|
|
$val, |
154
|
|
|
|
|
|
|
join( ', ', sort keys %PaperSizes ); |
155
|
0
|
|
|
|
|
0
|
last; |
156
|
|
|
|
|
|
|
}; |
157
|
2
|
|
|
|
|
11
|
$self->{$key} = lc $val; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
163
|
|
|
|
|
|
|
sub papersize { |
164
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $val ) = @_; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
0
|
$val = "\u\L$val"; |
167
|
0
|
0
|
|
|
|
0
|
my ( $width, $height ) = @{ $PaperSizes{$val} || return 0 }; |
|
0
|
|
|
|
|
0
|
|
168
|
0
|
0
|
|
|
|
0
|
return 0 unless defined $width; |
169
|
0
|
|
|
|
|
0
|
$self->{papersize} = $val; |
170
|
0
|
|
|
|
|
0
|
$self->{paperwidth} = $width; |
171
|
0
|
|
|
|
|
0
|
$self->{paperheight} = $height; |
172
|
0
|
|
|
|
|
0
|
1; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
176
|
|
|
|
|
|
|
sub fontsize { |
177
|
638
|
|
|
638
|
0
|
792
|
my $self = shift; |
178
|
|
|
|
|
|
|
|
179
|
638
|
|
|
|
|
954
|
my $size = $self->{font_size}[-1]; |
180
|
638
|
50
|
|
|
|
1197
|
$size = 8 if $size > 8; |
181
|
638
|
50
|
|
|
|
1194
|
$size = 3 if $size < 0; |
182
|
638
|
|
|
|
|
1290
|
$FontSizes[$size] * $self->{fontscale}; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# Determine the current font and set font-related members. |
186
|
|
|
|
|
|
|
# If $plain_with_size is given (a number), use a plain font |
187
|
|
|
|
|
|
|
# of that size. Otherwise, use the font specified by the |
188
|
|
|
|
|
|
|
# HTML context. Returns the "font ID" of the current font. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
191
|
|
|
|
|
|
|
sub setfont { |
192
|
638
|
|
|
638
|
0
|
851
|
my ( $self, $plain_with_size ) = @_; |
193
|
|
|
|
|
|
|
|
194
|
638
|
|
|
|
|
723
|
my $index = 0; |
195
|
638
|
|
50
|
|
|
1386
|
my $family = $self->{family} || 'Times'; |
196
|
638
|
|
|
|
|
785
|
my $size = $plain_with_size; |
197
|
638
|
100
|
|
|
|
1161
|
unless ($plain_with_size) { |
198
|
637
|
100
|
|
|
|
1317
|
$index |= BOLD if $self->{bold}; |
199
|
637
|
50
|
33
|
|
|
2023
|
$index |= ITALIC if $self->{italic} || $self->{underline}; |
200
|
637
|
100
|
|
|
|
1162
|
$family = 'Courier' if $self->{teletype}; |
201
|
637
|
|
|
|
|
1173
|
$size = $self->fontsize; |
202
|
|
|
|
|
|
|
} |
203
|
638
|
|
|
|
|
1098
|
my $font = $FontFamilies{$family}[$index]; |
204
|
638
|
|
|
|
|
1054
|
my $font_with_size = "$font-$size"; |
205
|
638
|
100
|
|
|
|
1530
|
if ( $self->{currentfont} eq $font_with_size ) { |
206
|
631
|
|
|
|
|
1616
|
return $self->{currentfontid}; |
207
|
|
|
|
|
|
|
} |
208
|
7
|
|
|
|
|
12
|
$self->{currentfont} = $font_with_size; |
209
|
7
|
|
|
|
|
9
|
$self->{pointsize} = $size; |
210
|
7
|
|
|
|
|
13
|
my $fontmod = "Font::Metrics::$font"; |
211
|
7
|
|
|
|
|
24
|
$fontmod =~ s/-//g; |
212
|
7
|
|
|
|
|
13
|
my $fontfile = $fontmod . ".pm"; |
213
|
7
|
|
|
|
|
23
|
$fontfile =~ s,::,/,g; |
214
|
7
|
|
|
|
|
2948
|
require $fontfile; |
215
|
|
|
|
|
|
|
{ |
216
|
|
|
|
|
|
|
## no critic |
217
|
1
|
|
|
1
|
|
10
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3187
|
|
|
7
|
|
|
|
|
133
|
|
218
|
7
|
|
|
|
|
10
|
$self->{wx} = \@{"${fontmod}::wx"}; |
|
7
|
|
|
|
|
25
|
|
219
|
|
|
|
|
|
|
## use critic |
220
|
|
|
|
|
|
|
} |
221
|
7
|
|
66
|
|
|
26
|
$font = $self->{fonts}{$font_with_size} || do { |
222
|
|
|
|
|
|
|
my $fontID = "F" . ++$self->{fno}; |
223
|
|
|
|
|
|
|
$self->{fonts}{$font_with_size} = $fontID; |
224
|
|
|
|
|
|
|
$fontID; |
225
|
|
|
|
|
|
|
}; |
226
|
7
|
|
|
|
|
13
|
$self->{currentfontid} = $font; |
227
|
7
|
|
|
|
|
22
|
return $font; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
231
|
|
|
|
|
|
|
# Construct PostScript code for setting the current font according |
232
|
|
|
|
|
|
|
# to $fontid, or an empty string if no font change is needed. |
233
|
|
|
|
|
|
|
# Assumes the return string will always be output as PostScript if |
234
|
|
|
|
|
|
|
# nonempty, so that our notion of the current PostScript font |
235
|
|
|
|
|
|
|
# stays in sync with that of the PostScript interpreter. |
236
|
|
|
|
|
|
|
# |
237
|
|
|
|
|
|
|
sub switchfont { |
238
|
614
|
|
|
614
|
0
|
785
|
my ( $self, $fontid ) = @_; |
239
|
|
|
|
|
|
|
|
240
|
614
|
100
|
|
|
|
1252
|
if ( $self->{psfontid} eq $fontid ) { |
241
|
607
|
|
|
|
|
1104
|
return ""; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
else { |
244
|
7
|
|
|
|
|
11
|
$self->{psfontid} = $fontid; |
245
|
7
|
|
|
|
|
16
|
return "$fontid SF"; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
250
|
|
|
|
|
|
|
# Like setfont + switchfont. |
251
|
|
|
|
|
|
|
sub findfont { |
252
|
2
|
|
|
2
|
0
|
4
|
my ( $self, $plain_with_size ) = @_; |
253
|
|
|
|
|
|
|
|
254
|
2
|
|
|
|
|
10
|
return $self->switchfont( $self->setfont($plain_with_size) ); |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
258
|
|
|
|
|
|
|
sub width { |
259
|
636
|
|
|
636
|
0
|
753
|
my $self = shift; |
260
|
|
|
|
|
|
|
|
261
|
636
|
|
|
|
|
770
|
my $w = 0; |
262
|
636
|
|
|
|
|
872
|
my $wx = $self->{wx}; |
263
|
636
|
|
|
|
|
871
|
my $sz = $self->{pointsize}; |
264
|
636
|
|
|
|
|
1391
|
for ( unpack( "C*", $_[0] ) ) { |
265
|
1865
|
|
|
|
|
2865
|
$w += $wx->[$_] * $sz # unless $_ eq 0xAD; # optional hyphen |
266
|
|
|
|
|
|
|
} |
267
|
636
|
|
|
|
|
1166
|
$w; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
271
|
|
|
|
|
|
|
sub begin { |
272
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
273
|
|
|
|
|
|
|
|
274
|
1
|
|
|
|
|
7
|
$self->SUPER::begin; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# Margins are in points |
277
|
1
|
|
33
|
|
|
5
|
$self->{lm} = $self->{lmW} || $self->{mW}; |
278
|
1
|
|
33
|
|
|
8
|
$self->{rm} = $self->{paperwidth} - ( $self->{rmW} || $self->{mW} ); |
279
|
1
|
|
33
|
|
|
6
|
$self->{tm} = $self->{paperheight} - ( $self->{tmH} || $self->{mH} ); |
280
|
1
|
|
33
|
|
|
5
|
$self->{bm} = $self->{bmH} || $self->{mH}; |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
$self->{'orig_margins'} = # used only by the debug-mode print-area marker |
283
|
1
|
|
|
|
|
2
|
[ map { sprintf "%.1f", $_ } @{$self}{qw(lm bm rm tm)} ]; |
|
4
|
|
|
|
|
27
|
|
|
1
|
|
|
|
|
3
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
# Font setup |
286
|
1
|
|
|
|
|
3
|
$self->{fno} = 0; |
287
|
1
|
|
|
|
|
2
|
$self->{fonts} = {}; |
288
|
1
|
|
|
|
|
9
|
$self->{en} = 0.55 * $self->fontsize(3); |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# Initial position |
291
|
1
|
|
|
|
|
3
|
$self->{xpos} = $self->{lm}; # top of the current line |
292
|
1
|
|
|
|
|
3
|
$self->{ypos} = $self->{tm}; |
293
|
|
|
|
|
|
|
|
294
|
1
|
|
|
|
|
2
|
$self->{pageno} = 1; |
295
|
1
|
|
|
|
|
2
|
$self->{visible_page_number} = $self->{startpage}; |
296
|
|
|
|
|
|
|
|
297
|
1
|
|
|
|
|
2
|
$self->{line} = ""; |
298
|
1
|
|
|
|
|
2
|
$self->{showstring} = ""; |
299
|
1
|
|
|
|
|
2
|
$self->{currentfont} = ""; |
300
|
1
|
|
|
|
|
2
|
$self->{prev_currentfont} = ""; |
301
|
1
|
|
|
|
|
2
|
$self->{largest_pointsize} = 0; |
302
|
|
|
|
|
|
|
|
303
|
1
|
|
|
|
|
4
|
$self->newpage; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
307
|
|
|
|
|
|
|
sub end { |
308
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
309
|
|
|
|
|
|
|
|
310
|
1
|
|
|
|
|
13
|
$self->showline; |
311
|
1
|
50
|
|
|
|
7
|
$self->endpage if $self->{'out'}; |
312
|
1
|
|
|
|
|
2
|
my $pages = $self->{pageno} - 1; |
313
|
|
|
|
|
|
|
|
314
|
1
|
|
|
|
|
2
|
my @prolog = (); |
315
|
1
|
|
|
|
|
3
|
push( @prolog, "%!PS-Adobe-3.0\n" ); |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
#push(@prolog,"%%Title: No title\n"); # should look for the element |
318
|
1
|
|
|
|
|
7
|
push( @prolog, "%%Creator: " . $self->version_tag . "\n" ); |
319
|
1
|
|
|
|
|
130
|
push( @prolog, "%%CreationDate: " . localtime() . "\n" ); |
320
|
1
|
|
|
|
|
4
|
push( @prolog, "%%Pages: $pages\n" ); |
321
|
1
|
|
|
|
|
3
|
push( @prolog, "%%PageOrder: Ascend\n" ); |
322
|
1
|
|
|
|
|
2
|
push( @prolog, "%%Orientation: Portrait\n" ); |
323
|
1
|
|
|
|
|
2
|
my ( $pw, $ph ) = map { int($_); } @{$self}{qw(paperwidth paperheight)}; |
|
2
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
4
|
|
324
|
|
|
|
|
|
|
|
325
|
1
|
|
|
|
|
5
|
push( @prolog, "%%DocumentMedia: Plain $pw $ph 0 white ()\n" ); |
326
|
1
|
|
|
|
|
3
|
push( @prolog, "%%DocumentNeededResources: \n" ); |
327
|
1
|
|
|
|
|
2
|
my %seenfont; |
328
|
1
|
|
|
|
|
3
|
for my $full ( sort keys %{ $self->{fonts} } ) { |
|
1
|
|
|
|
|
9
|
|
329
|
5
|
|
|
|
|
20
|
$full =~ s/-\d+$//; |
330
|
5
|
100
|
|
|
|
20
|
next if $seenfont{$full}++; |
331
|
3
|
|
|
|
|
8
|
push( @prolog, "%%+ font $full\n" ); |
332
|
|
|
|
|
|
|
} |
333
|
1
|
|
|
|
|
2
|
push( @prolog, "%%DocumentSuppliedResources: procset newencode 1.0 0\n" ); |
334
|
1
|
|
|
|
|
3
|
push( @prolog, "%%+ encoding ISOLatin1Encoding\n" ); |
335
|
1
|
|
|
|
|
2
|
push( @prolog, "%%EndComments\n" ); |
336
|
1
|
|
|
|
|
2
|
push( @prolog, <<'EOT'); |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
%%BeginProlog |
339
|
|
|
|
|
|
|
/S/show load def |
340
|
|
|
|
|
|
|
/M/moveto load def |
341
|
|
|
|
|
|
|
/SF/setfont load def |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
%%BeginResource: encoding ISOLatin1Encoding |
344
|
|
|
|
|
|
|
systemdict /ISOLatin1Encoding known not { |
345
|
|
|
|
|
|
|
/ISOLatin1Encoding [ |
346
|
|
|
|
|
|
|
/space /space /space /space /space /space /space /space |
347
|
|
|
|
|
|
|
/space /space /space /space /space /space /space /space |
348
|
|
|
|
|
|
|
/space /space /space /space /space /space /space /space |
349
|
|
|
|
|
|
|
/space /space /space /space /space /space /space /space |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
/space /exclam /quotedbl /numbersign /dollar /percent /ampersand |
352
|
|
|
|
|
|
|
/quoteright |
353
|
|
|
|
|
|
|
/parenleft /parenright /asterisk /plus /comma /minus /period /slash |
354
|
|
|
|
|
|
|
/zero /one /two /three /four /five /six /seven |
355
|
|
|
|
|
|
|
/eight /nine /colon /semicolon /less /equal /greater /question |
356
|
|
|
|
|
|
|
/at /A /B /C /D /E /F /G |
357
|
|
|
|
|
|
|
/H /I /J /K /L /M /N /O |
358
|
|
|
|
|
|
|
/P /Q /R /S /T /U /V /W |
359
|
|
|
|
|
|
|
/X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore |
360
|
|
|
|
|
|
|
/quoteleft /a /b /c /d /e /f /g |
361
|
|
|
|
|
|
|
/h /i /j /k /l /m /n /o |
362
|
|
|
|
|
|
|
/p /q /r /s /t /u /v /w |
363
|
|
|
|
|
|
|
/x /y /z /braceleft /bar /braceright /asciitilde /space |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
/space /space /space /space /space /space /space /space |
366
|
|
|
|
|
|
|
/space /space /space /space /space /space /space /space |
367
|
|
|
|
|
|
|
/dotlessi /grave /acute /circumflex /tilde /macron /breve /dotaccent |
368
|
|
|
|
|
|
|
/dieresis /space /ring /cedilla /space /hungarumlaut /ogonek /caron |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
/space /exclamdown /cent /sterling /currency /yen /brokenbar /section |
371
|
|
|
|
|
|
|
/dieresis /copyright /ordfeminine /guillemotleft /logicalnot /hyphen |
372
|
|
|
|
|
|
|
/registered /macron |
373
|
|
|
|
|
|
|
/degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph |
374
|
|
|
|
|
|
|
/periodcentered |
375
|
|
|
|
|
|
|
/cedillar /onesuperior /ordmasculine /guillemotright /onequarter |
376
|
|
|
|
|
|
|
/onehalf /threequarters /questiondown |
377
|
|
|
|
|
|
|
/Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla |
378
|
|
|
|
|
|
|
/Egrave /Eacute /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex |
379
|
|
|
|
|
|
|
/Idieresis |
380
|
|
|
|
|
|
|
/Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply |
381
|
|
|
|
|
|
|
/Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn |
382
|
|
|
|
|
|
|
/germandbls |
383
|
|
|
|
|
|
|
/agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla |
384
|
|
|
|
|
|
|
/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex |
385
|
|
|
|
|
|
|
/idieresis |
386
|
|
|
|
|
|
|
/eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis /divide |
387
|
|
|
|
|
|
|
/oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn |
388
|
|
|
|
|
|
|
/ydieresis |
389
|
|
|
|
|
|
|
] def |
390
|
|
|
|
|
|
|
} if |
391
|
|
|
|
|
|
|
%%EndResource |
392
|
|
|
|
|
|
|
%%BeginResource: procset newencode 1.0 0 |
393
|
|
|
|
|
|
|
/NE { %def |
394
|
|
|
|
|
|
|
findfont begin |
395
|
|
|
|
|
|
|
currentdict dup length dict begin |
396
|
|
|
|
|
|
|
{ %forall |
397
|
|
|
|
|
|
|
1 index/FID ne {def} {pop pop} ifelse |
398
|
|
|
|
|
|
|
} forall |
399
|
|
|
|
|
|
|
/FontName exch def |
400
|
|
|
|
|
|
|
/Encoding exch def |
401
|
|
|
|
|
|
|
currentdict dup |
402
|
|
|
|
|
|
|
end |
403
|
|
|
|
|
|
|
end |
404
|
|
|
|
|
|
|
/FontName get exch definefont pop |
405
|
|
|
|
|
|
|
} bind def |
406
|
|
|
|
|
|
|
%%EndResource |
407
|
|
|
|
|
|
|
%%EndProlog |
408
|
|
|
|
|
|
|
EOT |
409
|
|
|
|
|
|
|
|
410
|
1
|
|
|
|
|
2
|
push( @prolog, "\n%%BeginSetup\n" ); |
411
|
1
|
|
|
|
|
2
|
for my $full ( sort keys %{ $self->{fonts} } ) { |
|
1
|
|
|
|
|
5
|
|
412
|
5
|
|
|
|
|
10
|
my $short = $self->{fonts}{$full}; |
413
|
5
|
|
|
|
|
17
|
$full =~ s/-(\d+)$//; |
414
|
5
|
|
|
|
|
9
|
my $size = $1; |
415
|
5
|
|
|
|
|
14
|
push( @prolog, "ISOLatin1Encoding/$full-ISO/$full NE\n" ); |
416
|
5
|
|
|
|
|
15
|
push( @prolog, "/$short/$full-ISO findfont $size scalefont def\n" ); |
417
|
|
|
|
|
|
|
} |
418
|
1
|
|
|
|
|
3
|
push( @prolog, "%%EndSetup\n" ); |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
$self->collect("\n%%Trailer\n%%EOF\n") |
421
|
1
|
50
|
|
|
|
7
|
unless $self->{'no_trailer'}; |
422
|
|
|
|
|
|
|
|
423
|
1
|
|
|
|
|
16
|
unshift( @{ $self->{output} }, @prolog ) |
424
|
1
|
50
|
|
|
|
9
|
unless $self->{'no_prolog'}; |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
428
|
|
|
|
|
|
|
sub header_start { |
429
|
2
|
|
|
2
|
0
|
4
|
my ( $self, $level ) = @_; |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
# If we are close enough to be bottom of the page, start a new page |
432
|
|
|
|
|
|
|
# instead of this: |
433
|
|
|
|
|
|
|
### Heading of level: $level |
434
|
2
|
|
|
|
|
13
|
$self->vspace( 1 + ( 6 - $level ) * 0.4 ); |
435
|
2
|
|
|
|
|
3
|
$self->{bold}++; |
436
|
2
|
|
|
|
|
4
|
push( @{ $self->{font_size} }, 8 - $level ); |
|
2
|
|
|
|
|
5
|
|
437
|
2
|
|
|
|
|
7
|
1; |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
441
|
|
|
|
|
|
|
sub header_end { |
442
|
2
|
|
|
2
|
0
|
4
|
my ($self) = @_; |
443
|
|
|
|
|
|
|
|
444
|
2
|
|
|
|
|
6
|
$self->vspace(1); |
445
|
2
|
|
|
|
|
3
|
$self->{bold}--; |
446
|
2
|
|
|
|
|
3
|
pop( @{ $self->{font_size} } ); |
|
2
|
|
|
|
|
5
|
|
447
|
2
|
|
|
|
|
6
|
1; |
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
451
|
|
|
|
|
|
|
sub hr_start { |
452
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
### Making an HR... |
455
|
0
|
|
|
|
|
0
|
$self->showline; |
456
|
0
|
|
|
|
|
0
|
$self->vspace(0.5); |
457
|
0
|
|
|
|
|
0
|
$self->skip_vspace; |
458
|
0
|
|
|
|
|
0
|
my $lm = $self->{lm}; |
459
|
0
|
|
|
|
|
0
|
my $rm = $self->{rm}; |
460
|
0
|
|
|
|
|
0
|
my $y = $self->{ypos}; |
461
|
0
|
|
|
|
|
0
|
$self->collect( sprintf "newpath %.1f %.1f M %.1f %.1f lineto stroke\n", $lm, $y, $rm, $y ); |
462
|
0
|
|
|
|
|
0
|
$self->vspace(0.5); |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
466
|
|
|
|
|
|
|
sub skip_vspace { |
467
|
317
|
|
|
317
|
0
|
373
|
my $self = shift; |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
### Skipping some amount of vspace... |
470
|
317
|
100
|
|
|
|
661
|
if ( defined $self->{vspace} ) { |
471
|
11
|
|
|
|
|
23
|
$self->showline; |
472
|
11
|
100
|
|
|
|
22
|
if ( $self->{'out'} ) { |
473
|
10
|
|
|
|
|
20
|
$self->{ypos} -= $self->{vspace} * 10 * $self->{fontscale}; |
474
|
|
|
|
|
|
|
|
475
|
10
|
50
|
|
|
|
24
|
if ( $self->{ypos} < $self->{bm} ) { |
476
|
|
|
|
|
|
|
### vspace skip forced new page... |
477
|
0
|
|
|
|
|
0
|
$self->newpage; |
478
|
|
|
|
|
|
|
} |
479
|
|
|
|
|
|
|
else { |
480
|
|
|
|
|
|
|
### Skipped vspace making y: $self->{'ypos'}, |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
} |
483
|
|
|
|
|
|
|
else { |
484
|
|
|
|
|
|
|
### Not skipping vspace as out is false: $self->{ypos} |
485
|
|
|
|
|
|
|
} |
486
|
11
|
|
|
|
|
16
|
$self->{xpos} = $self->{lm}; |
487
|
11
|
|
|
|
|
15
|
$self->{vspace} = undef; |
488
|
11
|
|
|
|
|
19
|
$self->{hspace} = undef; |
489
|
|
|
|
|
|
|
} |
490
|
|
|
|
|
|
|
else { |
491
|
|
|
|
|
|
|
### No vspace to skip... |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
317
|
|
|
|
|
408
|
return; |
495
|
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
498
|
|
|
|
|
|
|
sub show { |
499
|
37
|
|
|
37
|
0
|
44
|
my $self = shift; |
500
|
|
|
|
|
|
|
|
501
|
37
|
|
|
|
|
53
|
my $str = $self->{showstring}; |
502
|
37
|
|
|
|
|
54
|
$str =~ tr/\x01//d; |
503
|
37
|
100
|
|
|
|
83
|
return unless length $str; |
504
|
|
|
|
|
|
|
|
505
|
24
|
|
|
|
|
71
|
$str =~ s/[^\x00-\xff]/\xA4/g; |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
# replace any Unicode characters with the otherwise useless |
508
|
|
|
|
|
|
|
# International Communist Conspiracy money logo! |
509
|
|
|
|
|
|
|
|
510
|
24
|
|
|
|
|
87
|
$str =~ s/([\(\)\\])/\\$1/g; # must escape parentheses and backslash |
511
|
24
|
|
|
|
|
65
|
$self->{line} .= "($str)S\n"; |
512
|
24
|
|
|
|
|
43
|
$self->{showstring} = ""; |
513
|
|
|
|
|
|
|
} |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
516
|
|
|
|
|
|
|
sub showline { |
517
|
31
|
|
|
31
|
0
|
35
|
my $self = shift; |
518
|
|
|
|
|
|
|
|
519
|
31
|
|
|
|
|
60
|
$self->show; |
520
|
31
|
|
|
|
|
42
|
my $line = $self->{line}; |
521
|
31
|
100
|
|
|
|
60
|
unless ( length $line ) { |
522
|
|
|
|
|
|
|
### Showline is a no-op because line buffer is empty... |
523
|
7
|
|
|
|
|
10
|
return; |
524
|
|
|
|
|
|
|
} |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
### Showline emitting: $line |
527
|
|
|
|
|
|
|
|
528
|
24
|
|
66
|
|
|
62
|
$self->{ypos} -= $self->{largest_pointsize} || $self->{pointsize}; |
529
|
24
|
50
|
|
|
|
53
|
if ( $self->{ypos} < $self->{bm} ) { |
530
|
|
|
|
|
|
|
### Showline forcing new page... |
531
|
0
|
|
|
|
|
0
|
$self->newpage; |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
# newpage might alter currentfont! |
534
|
|
|
|
|
|
|
### Showline sets vspace: $self->{vspace} || 0 |
535
|
|
|
|
|
|
|
|
536
|
0
|
|
|
|
|
0
|
$self->{ypos} -= $self->{pointsize}; |
537
|
|
|
|
|
|
|
#### Showline/Newpage x: $self->{xpos} |
538
|
|
|
|
|
|
|
#### Showline/Newpage y: $self->{ypos} |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
# must set current font again |
541
|
0
|
|
|
|
|
0
|
my $font = $self->{prev_currentfont}; |
542
|
0
|
0
|
|
|
|
0
|
if ($font) { |
543
|
0
|
|
|
|
|
0
|
$self->collect("$self->{fonts}{$font} SF\n\n"); |
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
### End of doing newpage... |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
|
549
|
24
|
|
|
|
|
32
|
my $lm = $self->{lm}; |
550
|
24
|
|
|
|
|
26
|
my $x = $lm; |
551
|
24
|
50
|
|
|
|
49
|
if ( $self->{center} ) { |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
# Unfortunately, the center attribute is gone when we get here, |
554
|
|
|
|
|
|
|
# so this code is never activated |
555
|
0
|
|
|
|
|
0
|
my $linewidth = $self->{xpos} - $lm; |
556
|
0
|
|
|
|
|
0
|
$x += ( $self->{rm} - $lm - $linewidth ) / 2; |
557
|
|
|
|
|
|
|
} |
558
|
|
|
|
|
|
|
|
559
|
24
|
|
|
|
|
208
|
$self->collect( sprintf "%.1f %.1f M\n", $x, $self->{ypos} ); # moveto |
560
|
24
|
|
|
|
|
48
|
$line =~ s/\s\)S$/)S/; # many lines will end uselessly with space |
561
|
24
|
|
|
|
|
64
|
$self->collect($line); |
562
|
24
|
|
|
|
|
36
|
$self->{'out'}++; |
563
|
|
|
|
|
|
|
|
564
|
24
|
100
|
|
|
|
54
|
if ( $self->{bullet} ) { |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
# Putting this behind the first line of the list item |
567
|
|
|
|
|
|
|
# makes it more likely that we get the right font. We should |
568
|
|
|
|
|
|
|
# really set the font that we want to use. |
569
|
2
|
|
|
|
|
5
|
my $bullet = $self->{bullet}; |
570
|
2
|
50
|
|
|
|
6
|
if ( $bullet eq '*' ) { |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
# There is no character that is really suitable. Let's make |
573
|
|
|
|
|
|
|
# a medium-sized filled cirle ourself. |
574
|
2
|
|
|
|
|
6
|
my $radius = $self->{pointsize} / 8; |
575
|
|
|
|
|
|
|
### Adding code for a '*' bullet for that line... |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
$self->collect( |
578
|
|
|
|
|
|
|
sprintf "newpath %.1f %.1f %.1f 0 360 arc fill\n", |
579
|
|
|
|
|
|
|
$self->{bullet_pos} + $radius, |
580
|
2
|
|
|
|
|
22
|
$self->{ypos} + $radius * 2, $radius, |
581
|
|
|
|
|
|
|
); |
582
|
|
|
|
|
|
|
} |
583
|
|
|
|
|
|
|
else { |
584
|
|
|
|
|
|
|
### Adding code for other bullet for that line... |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
$self->collect( |
587
|
|
|
|
|
|
|
sprintf "%.1f (%s) stringwidth pop sub %.1f add %.1f M\n", # moveto |
588
|
|
|
|
|
|
|
$self->{bullet_pos}, |
589
|
|
|
|
|
|
|
$bullet, |
590
|
|
|
|
|
|
|
$self->{pointsize} * 0.62, |
591
|
|
|
|
|
|
|
$self->{ypos}, |
592
|
0
|
|
|
|
|
0
|
); |
593
|
0
|
|
|
|
|
0
|
$self->collect("($bullet)S\n"); |
594
|
|
|
|
|
|
|
} |
595
|
2
|
|
|
|
|
6
|
$self->{bullet} = ''; |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
} |
598
|
|
|
|
|
|
|
|
599
|
24
|
|
|
|
|
39
|
$self->{prev_currentfont} = $self->{currentfont}; |
600
|
24
|
|
|
|
|
34
|
$self->{largest_pointsize} = 0; |
601
|
24
|
|
|
|
|
35
|
$self->{line} = ""; |
602
|
24
|
|
|
|
|
28
|
$self->{xpos} = $lm; |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
# Additional linespacing |
605
|
|
|
|
|
|
|
|
606
|
24
|
|
|
|
|
61
|
$self->{ypos} -= $self->{leading} * $self->{pointsize}; |
607
|
|
|
|
|
|
|
#### Showline/end x: $self->{xpos} |
608
|
|
|
|
|
|
|
#### Showline/end y: $self->{ypos} |
609
|
|
|
|
|
|
|
|
610
|
24
|
|
|
|
|
51
|
return; |
611
|
|
|
|
|
|
|
} |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
614
|
|
|
|
|
|
|
sub endpage { |
615
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
### End page: $self->{pageno} |
618
|
|
|
|
|
|
|
# End previous page |
619
|
1
|
|
|
|
|
4
|
$self->collect("showpage\n"); |
620
|
1
|
|
|
|
|
2
|
$self->{visible_page_number}++; |
621
|
1
|
|
|
|
|
3
|
$self->{pageno}++; |
622
|
|
|
|
|
|
|
} |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
625
|
|
|
|
|
|
|
sub newpage { |
626
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
627
|
|
|
|
|
|
|
|
628
|
1
|
|
|
|
|
3
|
local $self->{'pointsize'} = $self->{'pointsize'}; |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
# That's needed for protecting against one bit of the |
631
|
|
|
|
|
|
|
# potential side-effects from from page-numbering code |
632
|
|
|
|
|
|
|
|
633
|
1
|
50
|
|
|
|
11
|
if ( $self->{'out'} ) { # whether we've sent anything to the current page so far. |
634
|
|
|
|
|
|
|
### Newpage calls endpage... |
635
|
0
|
|
|
|
|
0
|
$self->endpage; |
636
|
0
|
|
|
|
|
0
|
$self->collect( sprintf "%% %s has sent %s write-events to the above page.\n", ref($self), $self->{'out'}, ); |
637
|
|
|
|
|
|
|
} |
638
|
|
|
|
|
|
|
|
639
|
1
|
|
|
|
|
2
|
$self->{'out'} = 0; |
640
|
1
|
|
|
|
|
2
|
my $pageno = $self->{pageno}; |
641
|
1
|
|
|
|
|
2
|
my $visible_page_number = $self->{visible_page_number}; |
642
|
|
|
|
|
|
|
|
643
|
1
|
|
|
|
|
10
|
$self->collect("\n%%Page: $pageno $pageno\n"); |
644
|
|
|
|
|
|
|
### Starting page: $pageno |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
# Print page number |
647
|
1
|
50
|
|
|
|
4
|
if ( $self->{printpageno} ) { |
648
|
|
|
|
|
|
|
### Printing page number: $visible_page_number |
649
|
1
|
|
|
|
|
4
|
$self->collect("%% Title and pageno\n"); |
650
|
1
|
|
|
|
|
4
|
my $f = $self->findfont(8); |
651
|
1
|
50
|
|
|
|
6
|
$self->collect("$f\n") if $f; |
652
|
1
|
|
|
|
|
3
|
my $x = $self->{paperwidth}; |
653
|
1
|
50
|
|
|
|
3
|
if ($x) { $x -= 30; } |
|
1
|
|
|
|
|
2
|
|
654
|
0
|
|
|
|
|
0
|
else { $x = 30; } |
655
|
1
|
|
|
|
|
11
|
$self->collect( sprintf "%.1f 30.0 M($visible_page_number)S\n", $x ); |
656
|
1
|
|
|
|
|
3
|
$x = $self->{lm}; |
657
|
1
|
|
|
|
|
2
|
$self->{title} =~ tr/\x01//d; |
658
|
1
|
|
|
|
|
8
|
$self->collect( sprintf "%.1f 30.0 M($self->{title})S\n", $x ); |
659
|
|
|
|
|
|
|
} |
660
|
|
|
|
|
|
|
else { |
661
|
|
|
|
|
|
|
### Pointedly not printing page number... |
662
|
|
|
|
|
|
|
} |
663
|
1
|
|
|
|
|
4
|
$self->collect("\n"); |
664
|
|
|
|
|
|
|
|
665
|
1
|
|
|
|
|
3
|
$self->{xpos} = $self->{lm}; |
666
|
1
|
|
|
|
|
29
|
$self->{ypos} = $self->{tm}; |
667
|
|
|
|
|
|
|
#### Newpage/end x: $self->{xpos} |
668
|
|
|
|
|
|
|
#### Newpage/end y: $self->{ypos} |
669
|
|
|
|
|
|
|
} |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
672
|
|
|
|
|
|
|
sub out { # Output a word |
673
|
643
|
|
|
643
|
0
|
947
|
my ( $self, $text ) = @_; |
674
|
|
|
|
|
|
|
|
675
|
643
|
|
|
|
|
828
|
$text =~ tr/\xA0\xAD/ /d; |
676
|
|
|
|
|
|
|
### Trapping new word: $text |
677
|
|
|
|
|
|
|
|
678
|
643
|
100
|
|
|
|
1402
|
if ( $self->{collectingTheTitle} ) { |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
# Both collect and print the title |
681
|
7
|
|
|
|
|
12
|
$text =~ s/([\(\)\\])/\\$1/g; # Escape parens and the backslash |
682
|
7
|
|
|
|
|
10
|
$self->{title} .= $text; |
683
|
7
|
|
|
|
|
17
|
return; |
684
|
|
|
|
|
|
|
} |
685
|
|
|
|
|
|
|
|
686
|
636
|
|
|
|
|
1230
|
my $fontid = $self->setfont(); |
687
|
636
|
|
|
|
|
1319
|
my $w = $self->width($text); |
688
|
|
|
|
|
|
|
|
689
|
636
|
100
|
|
|
|
1980
|
if ( $text =~ /^\s*$/ ) { |
690
|
320
|
|
|
|
|
762
|
$self->{hspace} = [ " ", $fontid, $w ]; |
691
|
320
|
|
|
|
|
842
|
return; |
692
|
|
|
|
|
|
|
} |
693
|
|
|
|
|
|
|
|
694
|
316
|
|
|
|
|
605
|
$self->skip_vspace; |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
# determine spacing / line breaks needed before text |
697
|
316
|
100
|
|
|
|
703
|
if ( $self->{hspace} ) { |
698
|
306
|
|
|
|
|
340
|
my ( $stext, $sfont, $swidth ) = @{ $self->{hspace} }; |
|
306
|
|
|
|
|
638
|
|
699
|
306
|
100
|
|
|
|
746
|
if ( $self->{xpos} + $swidth + $w > $self->{rm} ) { |
700
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
# line break |
702
|
10
|
|
|
|
|
57
|
$self->showline; |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
else { |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
# no line break; output a space |
707
|
296
|
|
|
|
|
551
|
$self->show_with_font( $stext, $sfont, $swidth ); |
708
|
|
|
|
|
|
|
} |
709
|
306
|
|
|
|
|
491
|
$self->{hspace} = undef; |
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
# output the text |
713
|
316
|
|
|
|
|
747
|
$self->show_with_font( $text, $fontid, $w ); |
714
|
|
|
|
|
|
|
} |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
717
|
|
|
|
|
|
|
sub show_with_font { |
718
|
612
|
|
|
612
|
0
|
904
|
my ( $self, $text, $fontid, $w ) = @_; |
719
|
|
|
|
|
|
|
|
720
|
612
|
|
|
|
|
1116
|
my $fontps = $self->switchfont($fontid); |
721
|
612
|
100
|
|
|
|
1309
|
if ( length $fontps ) { |
722
|
5
|
|
|
|
|
10
|
$self->show; |
723
|
5
|
|
|
|
|
10
|
$self->{line} .= "$fontps\n"; |
724
|
|
|
|
|
|
|
} |
725
|
|
|
|
|
|
|
|
726
|
612
|
|
|
|
|
822
|
$self->{xpos} += $w; |
727
|
612
|
|
|
|
|
858
|
$self->{showstring} .= $text; |
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
#### Append to string buffer: $text |
730
|
|
|
|
|
|
|
#### with font: $fontid |
731
|
|
|
|
|
|
|
#### with xpos: $self->{xpos} |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
$self->{largest_pointsize} = $self->{pointsize} |
734
|
612
|
100
|
|
|
|
1263
|
if $self->{largest_pointsize} < $self->{pointsize}; |
735
|
612
|
|
|
|
|
1428
|
$self->{'out'}++; |
736
|
|
|
|
|
|
|
} |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
739
|
|
|
|
|
|
|
sub pre_out { |
740
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $text ) = @_; |
741
|
|
|
|
|
|
|
|
742
|
1
|
|
|
|
|
3
|
$self->skip_vspace; |
743
|
1
|
|
|
|
|
7
|
$self->tt_start; |
744
|
1
|
|
|
|
|
5
|
my $font = $self->findfont(); |
745
|
1
|
50
|
|
|
|
5
|
if ( length $font ) { |
746
|
1
|
|
|
|
|
4
|
$self->show; |
747
|
1
|
|
|
|
|
4
|
$self->{line} .= "$font\n"; |
748
|
|
|
|
|
|
|
} |
749
|
1
|
|
|
|
|
7
|
while ( $text =~ s/(.*)\n// ) { |
750
|
3
|
|
|
|
|
5
|
$self->{'out'}++; |
751
|
3
|
|
|
|
|
7
|
$self->{showstring} .= $1; |
752
|
3
|
|
|
|
|
8
|
$self->showline; |
753
|
|
|
|
|
|
|
} |
754
|
1
|
|
|
|
|
2
|
$self->{showstring} .= $text; |
755
|
1
|
|
|
|
|
10
|
$self->tt_end; |
756
|
1
|
|
|
|
|
3
|
1; |
757
|
|
|
|
|
|
|
} |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
760
|
|
|
|
|
|
|
sub bullet { |
761
|
2
|
|
|
2
|
0
|
30
|
my ( $self, $bullet ) = @_; |
762
|
|
|
|
|
|
|
|
763
|
2
|
|
|
|
|
4
|
$self->{bullet} = $bullet; |
764
|
2
|
|
|
|
|
7
|
$self->{bullet_pos} = $self->{lm}; |
765
|
|
|
|
|
|
|
} |
766
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
768
|
|
|
|
|
|
|
sub adjust_lm { |
769
|
6
|
|
|
6
|
0
|
11
|
my $self = shift; |
770
|
|
|
|
|
|
|
|
771
|
6
|
|
|
|
|
11
|
$self->showline; |
772
|
|
|
|
|
|
|
|
773
|
6
|
|
|
|
|
11
|
$self->{lm} += $_[0] * $self->{en}; |
774
|
6
|
|
|
|
|
13
|
1; |
775
|
|
|
|
|
|
|
} |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
778
|
|
|
|
|
|
|
sub adjust_rm { |
779
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
780
|
|
|
|
|
|
|
|
781
|
0
|
|
|
|
|
0
|
$self->showline; |
782
|
|
|
|
|
|
|
|
783
|
0
|
|
|
|
|
0
|
$self->{rm} += $_[0] * $self->{en}; |
784
|
|
|
|
|
|
|
} |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
787
|
1
|
|
|
1
|
0
|
3
|
sub head_start { 1; } |
788
|
1
|
|
|
1
|
0
|
3
|
sub head_end { 1; } |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
sub title_start { |
791
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
792
|
|
|
|
|
|
|
|
793
|
1
|
|
|
|
|
3
|
$self->{collectingTheTitle} = 1; |
794
|
1
|
|
|
|
|
3
|
1; |
795
|
|
|
|
|
|
|
} |
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
sub title_end { |
798
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
799
|
|
|
|
|
|
|
|
800
|
1
|
|
|
|
|
2
|
$self->{collectingTheTitle} = 0; |
801
|
1
|
|
|
|
|
3
|
1; |
802
|
|
|
|
|
|
|
} |
803
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
805
|
|
|
|
|
|
|
my ( $counter, $last_state_filename ); |
806
|
|
|
|
|
|
|
|
807
|
|
|
|
|
|
|
# For use in circumstances of total desperation: |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
sub dump_state { |
810
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
811
|
0
|
|
|
|
|
|
require Data::Dumper; |
812
|
|
|
|
|
|
|
|
813
|
0
|
|
|
|
|
|
++$counter; |
814
|
0
|
|
|
|
|
|
my $filename = sprintf( "state%04d.txt", $counter ); |
815
|
0
|
0
|
|
|
|
|
my $state = IO::File->new( $filename, 'w' ) or die "Can't write-open $filename: $!"; |
816
|
0
|
|
|
|
|
|
$state->printf( "%s line %s\n", ( caller(1) )[ 3, 2 ] ); |
817
|
|
|
|
|
|
|
{ |
818
|
0
|
|
|
|
|
|
local ( $self->{'wx'} ) = ''; |
|
0
|
|
|
|
|
|
|
819
|
0
|
|
|
|
|
|
local ( $self->{'output'} ) = ''; |
820
|
0
|
|
|
|
|
|
$state->print( Data::Dumper::Dumper($self) ); |
821
|
|
|
|
|
|
|
} |
822
|
0
|
|
|
|
|
|
$state->close; |
823
|
0
|
|
|
|
|
|
sleep 0; |
824
|
|
|
|
|
|
|
|
825
|
0
|
0
|
|
|
|
|
if ($last_state_filename) { |
826
|
0
|
|
|
|
|
|
system("perl -S diff.bat $last_state_filename $filename > $filename.diff"); |
827
|
|
|
|
|
|
|
} |
828
|
|
|
|
|
|
|
|
829
|
0
|
|
|
|
|
|
$last_state_filename = $filename; |
830
|
0
|
|
|
|
|
|
return 1; |
831
|
|
|
|
|
|
|
} |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
1; |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
__END__ |