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