line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormatPS; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Format HTML as PostScript |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
19129
|
use 5.008; |
|
2
|
|
|
|
|
6
|
|
7
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
45
|
|
8
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
9
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
170
|
|
10
|
2
|
|
|
2
|
|
1234
|
use Encode; |
|
2
|
|
|
|
|
18185
|
|
|
2
|
|
|
|
|
161
|
|
11
|
2
|
|
|
2
|
|
2147
|
use IO::File; |
|
2
|
|
|
|
|
16843
|
|
|
2
|
|
|
|
|
312
|
|
12
|
2
|
|
|
2
|
|
1299
|
use utf8; # for the is_utf8 function |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
127
|
use base 'HTML::Formatter'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1186
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '2.16'; # 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
|
44
|
|
|
44
|
0
|
160
|
sub mm { $_[0] * 72 / 25.4; } |
26
|
28
|
|
|
28
|
0
|
91
|
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
|
15
|
sub BOLD { 0x01; } |
74
|
5
|
|
|
5
|
0
|
5
|
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
|
8
|
|
|
8
|
1
|
5459
|
my $class = shift; |
100
|
|
|
|
|
|
|
|
101
|
8
|
|
|
|
|
45
|
my $self = $class->SUPER::new(@_); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Obtained from the element |
104
|
8
|
|
|
|
|
22
|
$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
|
8
|
|
|
|
|
11
|
$self->{psfontid} = ""; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Pending horizontal space. A list [ " ", $fontid, $width ], |
112
|
|
|
|
|
|
|
# or undef if no space is pending. |
113
|
8
|
|
|
|
|
13
|
$self->{hspace} = undef; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# add an encoder object for perl native to Latin1 output |
116
|
8
|
|
|
|
|
30
|
$self->{encoder} = find_encoding('iso-8859-1'); |
117
|
|
|
|
|
|
|
|
118
|
8
|
|
|
|
|
107
|
$self; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
122
|
|
|
|
|
|
|
sub default_values { |
123
|
8
|
|
|
8
|
0
|
29
|
( 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
|
2
|
my ( $self, $hash ) = @_; |
141
|
|
|
|
|
|
|
|
142
|
1
|
|
|
|
|
3
|
my ( $key, $val ); |
143
|
1
|
|
|
|
|
7
|
while ( ( $key, $val ) = each %$hash ) { |
144
|
2
|
|
|
|
|
5
|
$key = lc $key; |
145
|
2
|
50
|
|
|
|
5
|
croak "Illegal parameter ($key => $val)" unless exists $param{$key}; |
146
|
2
|
|
|
|
|
3
|
$key = $param{$key}; |
147
|
|
|
|
|
|
|
{ |
148
|
2
|
50
|
|
|
|
1
|
$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
|
|
|
|
|
9
|
$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
|
666
|
my $self = shift; |
183
|
|
|
|
|
|
|
|
184
|
823
|
|
|
|
|
791
|
my $size = $self->{font_size}[-1]; |
185
|
823
|
50
|
|
|
|
1206
|
$size = 8 if $size > 8; |
186
|
823
|
50
|
|
|
|
1114
|
$size = 3 if $size < 0; |
187
|
823
|
|
|
|
|
1181
|
$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
|
727
|
my ( $self, $plain_with_size ) = @_; |
198
|
|
|
|
|
|
|
|
199
|
823
|
|
|
|
|
665
|
my $index = 0; |
200
|
823
|
|
50
|
|
|
1280
|
my $family = $self->{family} || 'Times'; |
201
|
823
|
|
|
|
|
605
|
my $size = $plain_with_size; |
202
|
823
|
100
|
|
|
|
1135
|
unless ($plain_with_size) { |
203
|
817
|
100
|
|
|
|
1228
|
$index |= BOLD if $self->{bold}; |
204
|
817
|
100
|
66
|
|
|
1930
|
$index |= ITALIC if $self->{italic} || $self->{underline}; |
205
|
817
|
100
|
|
|
|
1040
|
$family = 'Courier' if $self->{teletype}; |
206
|
817
|
|
|
|
|
1030
|
$size = $self->fontsize; |
207
|
|
|
|
|
|
|
} |
208
|
823
|
|
|
|
|
935
|
my $font = $FontFamilies{$family}[$index]; |
209
|
823
|
|
|
|
|
1005
|
my $font_with_size = "$font-$size"; |
210
|
823
|
100
|
|
|
|
1370
|
if ( $self->{currentfont} eq $font_with_size ) { |
211
|
800
|
|
|
|
|
1345
|
return $self->{currentfontid}; |
212
|
|
|
|
|
|
|
} |
213
|
23
|
|
|
|
|
27
|
$self->{currentfont} = $font_with_size; |
214
|
23
|
|
|
|
|
48
|
$self->{pointsize} = $size; |
215
|
23
|
|
|
|
|
30
|
my $fontmod = "Font::Metrics::$font"; |
216
|
23
|
|
|
|
|
75
|
$fontmod =~ s/-//g; |
217
|
23
|
|
|
|
|
41
|
my $fontfile = $fontmod . ".pm"; |
218
|
23
|
|
|
|
|
54
|
$fontfile =~ s,::,/,g; |
219
|
23
|
|
|
|
|
3343
|
require $fontfile; |
220
|
|
|
|
|
|
|
{ |
221
|
|
|
|
|
|
|
## no critic |
222
|
2
|
|
|
2
|
|
22
|
no strict 'refs'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
4206
|
|
|
23
|
|
|
|
|
197
|
|
223
|
23
|
|
|
|
|
21
|
$self->{wx} = \@{"${fontmod}::wx"}; |
|
23
|
|
|
|
|
102
|
|
224
|
|
|
|
|
|
|
## use critic |
225
|
|
|
|
|
|
|
} |
226
|
23
|
|
66
|
|
|
69
|
$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
|
|
|
|
|
29
|
$self->{currentfontid} = $font; |
232
|
23
|
|
|
|
|
47
|
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
|
660
|
my ( $self, $fontid ) = @_; |
244
|
|
|
|
|
|
|
|
245
|
787
|
100
|
|
|
|
1055
|
if ( $self->{psfontid} eq $fontid ) { |
246
|
767
|
|
|
|
|
910
|
return ""; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
else { |
249
|
20
|
|
|
|
|
22
|
$self->{psfontid} = $fontid; |
250
|
20
|
|
|
|
|
64
|
return "$fontid SF"; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
255
|
|
|
|
|
|
|
# Like setfont + switchfont. |
256
|
|
|
|
|
|
|
sub findfont { |
257
|
7
|
|
|
7
|
0
|
11
|
my ( $self, $plain_with_size ) = @_; |
258
|
|
|
|
|
|
|
|
259
|
7
|
|
|
|
|
17
|
return $self->switchfont( $self->setfont($plain_with_size) ); |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
263
|
|
|
|
|
|
|
sub width { |
264
|
816
|
|
|
816
|
0
|
642
|
my $self = shift; |
265
|
816
|
|
|
|
|
624
|
my $str = shift; |
266
|
|
|
|
|
|
|
|
267
|
816
|
|
|
|
|
632
|
my $w = 0; |
268
|
816
|
|
|
|
|
704
|
my $wx = $self->{wx}; |
269
|
816
|
|
|
|
|
704
|
my $sz = $self->{pointsize}; |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# need to encode to same encoding as font before getting width |
272
|
816
|
|
|
|
|
1054
|
for ( unpack( "C*", $self->encode_string($str) ) ) { |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# if the character is outside the table, assume its m sized |
275
|
2345
|
50
|
|
|
|
1658
|
$w += ( ( $_ > $#{$wx} ) ? $wx->[ ord('m') ] : $wx->[$_] ) * $sz # unless $_ eq 0xAD; # optional hyphen |
|
2345
|
|
|
|
|
4205
|
|
276
|
|
|
|
|
|
|
} |
277
|
816
|
|
|
|
|
1116
|
$w; |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
281
|
|
|
|
|
|
|
sub begin { |
282
|
6
|
|
|
6
|
0
|
8
|
my $self = shift; |
283
|
|
|
|
|
|
|
|
284
|
6
|
|
|
|
|
26
|
$self->SUPER::begin; |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
# Margins are in points |
287
|
6
|
|
66
|
|
|
26
|
$self->{lm} = $self->{lmW} || $self->{mW}; |
288
|
6
|
|
66
|
|
|
27
|
$self->{rm} = $self->{paperwidth} - ( $self->{rmW} || $self->{mW} ); |
289
|
6
|
|
33
|
|
|
29
|
$self->{tm} = $self->{paperheight} - ( $self->{tmH} || $self->{mH} ); |
290
|
6
|
|
33
|
|
|
22
|
$self->{bm} = $self->{bmH} || $self->{mH}; |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
$self->{'orig_margins'} = # used only by the debug-mode print-area marker |
293
|
6
|
|
|
|
|
10
|
[ map { sprintf "%.1f", $_ } @{$self}{qw(lm bm rm tm)} ]; |
|
24
|
|
|
|
|
154
|
|
|
6
|
|
|
|
|
12
|
|
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
# Font setup |
296
|
6
|
|
|
|
|
19
|
$self->{fno} = 0; |
297
|
6
|
|
|
|
|
12
|
$self->{fonts} = {}; |
298
|
6
|
|
|
|
|
16
|
$self->{en} = 0.55 * $self->fontsize(3); |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
# Initial position |
301
|
6
|
|
|
|
|
9
|
$self->{xpos} = $self->{lm}; # top of the current line |
302
|
6
|
|
|
|
|
9
|
$self->{ypos} = $self->{tm}; |
303
|
|
|
|
|
|
|
|
304
|
6
|
|
|
|
|
9
|
$self->{pageno} = 1; |
305
|
6
|
|
|
|
|
7
|
$self->{visible_page_number} = $self->{startpage}; |
306
|
|
|
|
|
|
|
|
307
|
6
|
|
|
|
|
12
|
$self->{line} = ""; |
308
|
6
|
|
|
|
|
6
|
$self->{showstring} = ""; |
309
|
6
|
|
|
|
|
13
|
$self->{currentfont} = ""; |
310
|
6
|
|
|
|
|
7
|
$self->{prev_currentfont} = ""; |
311
|
6
|
|
|
|
|
5
|
$self->{largest_pointsize} = 0; |
312
|
|
|
|
|
|
|
|
313
|
6
|
|
|
|
|
28
|
$self->newpage; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
317
|
|
|
|
|
|
|
sub end { |
318
|
6
|
|
|
6
|
0
|
6
|
my $self = shift; |
319
|
|
|
|
|
|
|
|
320
|
6
|
|
|
|
|
28
|
$self->showline; |
321
|
6
|
50
|
|
|
|
37
|
$self->endpage if $self->{'out'}; |
322
|
6
|
|
|
|
|
8
|
my $pages = $self->{pageno} - 1; |
323
|
|
|
|
|
|
|
|
324
|
6
|
|
|
|
|
12
|
my @prolog = (); |
325
|
6
|
|
|
|
|
9
|
push( @prolog, "%!PS-Adobe-3.0\n" ); |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
#push(@prolog,"%%Title: No title\n"); # should look for the element |
328
|
6
|
|
|
|
|
23
|
push( @prolog, "%%Creator: " . $self->version_tag . "\n" ); |
329
|
6
|
|
|
|
|
507
|
push( @prolog, "%%CreationDate: " . localtime() . "\n" ); |
330
|
6
|
|
|
|
|
16
|
push( @prolog, "%%Pages: $pages\n" ); |
331
|
6
|
|
|
|
|
9
|
push( @prolog, "%%PageOrder: Ascend\n" ); |
332
|
6
|
|
|
|
|
8
|
push( @prolog, "%%Orientation: Portrait\n" ); |
333
|
6
|
|
|
|
|
9
|
my ( $pw, $ph ) = map { int($_); } @{$self}{qw(paperwidth paperheight)}; |
|
12
|
|
|
|
|
26
|
|
|
6
|
|
|
|
|
17
|
|
334
|
|
|
|
|
|
|
|
335
|
6
|
|
|
|
|
20
|
push( @prolog, "%%DocumentMedia: Plain $pw $ph 0 white ()\n" ); |
336
|
6
|
|
|
|
|
7
|
push( @prolog, "%%DocumentNeededResources: \n" ); |
337
|
6
|
|
|
|
|
18
|
my %seenfont; |
338
|
6
|
|
|
|
|
8
|
for my $full ( sort keys %{ $self->{fonts} } ) { |
|
6
|
|
|
|
|
45
|
|
339
|
17
|
|
|
|
|
64
|
$full =~ s/-\d+$//; |
340
|
17
|
100
|
|
|
|
91
|
next if $seenfont{$full}++; |
341
|
9
|
|
|
|
|
43
|
push( @prolog, "%%+ font $full\n" ); |
342
|
|
|
|
|
|
|
} |
343
|
6
|
|
|
|
|
11
|
push( @prolog, "%%DocumentSuppliedResources: procset newencode 1.0 0\n" ); |
344
|
6
|
|
|
|
|
9
|
push( @prolog, "%%+ encoding ISOLatin1Encoding\n" ); |
345
|
6
|
|
|
|
|
8
|
push( @prolog, "%%EndComments\n" ); |
346
|
6
|
|
|
|
|
9
|
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
|
|
|
|
|
8
|
push( @prolog, "\n%%BeginSetup\n" ); |
421
|
6
|
|
|
|
|
6
|
for my $full ( sort keys %{ $self->{fonts} } ) { |
|
6
|
|
|
|
|
25
|
|
422
|
17
|
|
|
|
|
22
|
my $short = $self->{fonts}{$full}; |
423
|
17
|
|
|
|
|
62
|
$full =~ s/-(\d+)$//; |
424
|
17
|
|
|
|
|
28
|
my $size = $1; |
425
|
17
|
|
|
|
|
38
|
push( @prolog, "ISOLatin1Encoding/$full-ISO/$full NE\n" ); |
426
|
17
|
|
|
|
|
46
|
push( @prolog, "/$short/$full-ISO findfont $size scalefont def\n" ); |
427
|
|
|
|
|
|
|
} |
428
|
6
|
|
|
|
|
12
|
push( @prolog, "%%EndSetup\n" ); |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
$self->collect("\n%%Trailer\n%%EOF\n") |
431
|
6
|
50
|
|
|
|
28
|
unless $self->{'no_trailer'}; |
432
|
|
|
|
|
|
|
|
433
|
6
|
|
|
|
|
86
|
unshift( @{ $self->{output} }, @prolog ) |
434
|
6
|
50
|
|
|
|
14
|
unless $self->{'no_prolog'}; |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
438
|
|
|
|
|
|
|
sub header_start { |
439
|
2
|
|
|
2
|
0
|
5
|
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
|
|
|
|
|
13
|
$self->vspace( 1 + ( 6 - $level ) * 0.4 ); |
445
|
2
|
|
|
|
|
3
|
$self->{bold}++; |
446
|
2
|
|
|
|
|
3
|
push( @{ $self->{font_size} }, 8 - $level ); |
|
2
|
|
|
|
|
28
|
|
447
|
2
|
|
|
|
|
8
|
1; |
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
451
|
|
|
|
|
|
|
sub header_end { |
452
|
2
|
|
|
2
|
0
|
4
|
my ($self) = @_; |
453
|
|
|
|
|
|
|
|
454
|
2
|
|
|
|
|
16
|
$self->vspace(1); |
455
|
2
|
|
|
|
|
3
|
$self->{bold}--; |
456
|
2
|
|
|
|
|
2
|
pop( @{ $self->{font_size} } ); |
|
2
|
|
|
|
|
4
|
|
457
|
2
|
|
|
|
|
6
|
1; |
458
|
|
|
|
|
|
|
} |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
461
|
|
|
|
|
|
|
sub hr_start { |
462
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
### Making an HR... |
465
|
1
|
|
|
|
|
3
|
$self->showline; |
466
|
1
|
|
|
|
|
4
|
$self->vspace(0.5); |
467
|
1
|
|
|
|
|
3
|
$self->skip_vspace; |
468
|
1
|
|
|
|
|
2
|
my $lm = $self->{lm}; |
469
|
1
|
|
|
|
|
2
|
my $rm = $self->{rm}; |
470
|
1
|
|
|
|
|
2
|
my $y = $self->{ypos}; |
471
|
1
|
|
|
|
|
10
|
$self->collect( sprintf "newpath %.1f %.1f M %.1f %.1f lineto stroke\n", $lm, $y, $rm, $y ); |
472
|
1
|
|
|
|
|
3
|
$self->vspace(0.5); |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
476
|
|
|
|
|
|
|
sub skip_vspace { |
477
|
409
|
|
|
409
|
0
|
349
|
my $self = shift; |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
### Skipping some amount of vspace... |
480
|
409
|
100
|
|
|
|
638
|
if ( defined $self->{vspace} ) { |
481
|
20
|
|
|
|
|
38
|
$self->showline; |
482
|
20
|
100
|
|
|
|
27
|
if ( $self->{'out'} ) { |
483
|
19
|
|
|
|
|
56
|
$self->{ypos} -= $self->{vspace} * 10 * $self->{fontscale}; |
484
|
|
|
|
|
|
|
|
485
|
19
|
50
|
|
|
|
34
|
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
|
|
|
|
|
23
|
$self->{xpos} = $self->{lm}; |
497
|
20
|
|
|
|
|
17
|
$self->{vspace} = undef; |
498
|
20
|
|
|
|
|
25
|
$self->{hspace} = undef; |
499
|
|
|
|
|
|
|
} |
500
|
|
|
|
|
|
|
else { |
501
|
|
|
|
|
|
|
### No vspace to skip... |
502
|
|
|
|
|
|
|
} |
503
|
|
|
|
|
|
|
|
504
|
409
|
|
|
|
|
389
|
return; |
505
|
|
|
|
|
|
|
} |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
508
|
|
|
|
|
|
|
sub show { |
509
|
71
|
|
|
71
|
0
|
71
|
my $self = shift; |
510
|
|
|
|
|
|
|
|
511
|
71
|
|
|
|
|
90
|
my $str = $self->{showstring}; |
512
|
71
|
|
|
|
|
92
|
$str =~ tr/\x01//d; |
513
|
71
|
100
|
|
|
|
139
|
return unless length $str; |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
# must escape parentheses and backslash |
516
|
38
|
|
|
|
|
141
|
$str =~ s/([\(\)\\])/\\$1/g; |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
# encode output to latin1 when pushing it out |
519
|
38
|
|
|
|
|
75
|
$self->{line} .= "(" . $self->encode_string($str) . ")S\n"; |
520
|
38
|
|
|
|
|
65
|
$self->{showstring} = ""; |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
524
|
|
|
|
|
|
|
sub showline { |
525
|
57
|
|
|
57
|
0
|
53
|
my $self = shift; |
526
|
|
|
|
|
|
|
|
527
|
57
|
|
|
|
|
84
|
$self->show; |
528
|
57
|
|
|
|
|
53
|
my $line = $self->{line}; |
529
|
57
|
100
|
|
|
|
95
|
unless ( length $line ) { |
530
|
|
|
|
|
|
|
### Showline is a no-op because line buffer is empty... |
531
|
19
|
|
|
|
|
22
|
return; |
532
|
|
|
|
|
|
|
} |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
### Showline emitting: $line |
535
|
|
|
|
|
|
|
|
536
|
38
|
|
66
|
|
|
93
|
$self->{ypos} -= $self->{largest_pointsize} || $self->{pointsize}; |
537
|
38
|
50
|
|
|
|
72
|
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
|
|
|
|
|
50
|
my $lm = $self->{lm}; |
558
|
38
|
|
|
|
|
33
|
my $x = $lm; |
559
|
38
|
50
|
|
|
|
100
|
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
|
|
|
|
|
432
|
$self->collect( sprintf "%.1f %.1f M\n", $x, $self->{ypos} ); # moveto |
568
|
38
|
|
|
|
|
80
|
$line =~ s/\s\)S$/)S/; # many lines will end uselessly with space |
569
|
38
|
|
|
|
|
67
|
$self->collect($line); |
570
|
38
|
|
|
|
|
52
|
$self->{'out'}++; |
571
|
|
|
|
|
|
|
|
572
|
38
|
100
|
|
|
|
79
|
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
|
|
|
|
|
5
|
my $bullet = $self->{bullet}; |
578
|
4
|
100
|
|
|
|
10
|
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
|
|
|
|
|
6
|
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
|
|
|
|
|
18
|
$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
|
|
|
|
|
50
|
); |
601
|
2
|
|
|
|
|
7
|
$self->collect("($bullet)S\n"); |
602
|
|
|
|
|
|
|
} |
603
|
4
|
|
|
|
|
6
|
$self->{bullet} = ''; |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
} |
606
|
|
|
|
|
|
|
|
607
|
38
|
|
|
|
|
49
|
$self->{prev_currentfont} = $self->{currentfont}; |
608
|
38
|
|
|
|
|
43
|
$self->{largest_pointsize} = 0; |
609
|
38
|
|
|
|
|
35
|
$self->{line} = ""; |
610
|
38
|
|
|
|
|
35
|
$self->{xpos} = $lm; |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
# Additional linespacing |
613
|
|
|
|
|
|
|
|
614
|
38
|
|
|
|
|
60
|
$self->{ypos} -= $self->{leading} * $self->{pointsize}; |
615
|
|
|
|
|
|
|
#### Showline/end x: $self->{xpos} |
616
|
|
|
|
|
|
|
#### Showline/end y: $self->{ypos} |
617
|
|
|
|
|
|
|
|
618
|
38
|
|
|
|
|
61
|
return; |
619
|
|
|
|
|
|
|
} |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
622
|
|
|
|
|
|
|
sub endpage { |
623
|
6
|
|
|
6
|
0
|
5
|
my $self = shift; |
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
### End page: $self->{pageno} |
626
|
|
|
|
|
|
|
# End previous page |
627
|
6
|
|
|
|
|
16
|
$self->collect("showpage\n"); |
628
|
6
|
|
|
|
|
8
|
$self->{visible_page_number}++; |
629
|
6
|
|
|
|
|
20
|
$self->{pageno}++; |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
633
|
|
|
|
|
|
|
sub newpage { |
634
|
6
|
|
|
6
|
0
|
8
|
my $self = shift; |
635
|
|
|
|
|
|
|
|
636
|
6
|
|
|
|
|
13
|
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
|
|
|
|
15
|
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
|
|
|
|
|
9
|
$self->{'out'} = 0; |
648
|
6
|
|
|
|
|
9
|
my $pageno = $self->{pageno}; |
649
|
6
|
|
|
|
|
8
|
my $visible_page_number = $self->{visible_page_number}; |
650
|
|
|
|
|
|
|
|
651
|
6
|
|
|
|
|
32
|
$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
|
|
|
|
|
13
|
$self->collect("%% Title and pageno\n"); |
658
|
6
|
|
|
|
|
15
|
my $f = $self->findfont(8); |
659
|
6
|
50
|
|
|
|
36
|
$self->collect("$f\n") if $f; |
660
|
6
|
|
|
|
|
10
|
my $x = $self->{paperwidth}; |
661
|
6
|
50
|
|
|
|
11
|
if ($x) { $x -= 30; } |
|
6
|
|
|
|
|
13
|
|
662
|
0
|
|
|
|
|
0
|
else { $x = 30; } |
663
|
6
|
|
|
|
|
51
|
$self->collect( sprintf "%.1f 30.0 M($visible_page_number)S\n", $x ); |
664
|
6
|
|
|
|
|
7
|
$x = $self->{lm}; |
665
|
6
|
|
|
|
|
12
|
$self->{title} =~ tr/\x01//d; |
666
|
6
|
|
|
|
|
57
|
$self->collect( sprintf "%.1f 30.0 M($self->{title})S\n", $x ); |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
else { |
669
|
|
|
|
|
|
|
### Pointedly not printing page number... |
670
|
|
|
|
|
|
|
} |
671
|
6
|
|
|
|
|
17
|
$self->collect("\n"); |
672
|
|
|
|
|
|
|
|
673
|
6
|
|
|
|
|
9
|
$self->{xpos} = $self->{lm}; |
674
|
6
|
|
|
|
|
20
|
$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
|
815
|
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
|
|
|
|
1583
|
if ( utf8::is_utf8($str) ) { |
689
|
2
|
|
|
2
|
|
13
|
$str =~ tr/\x{2018}\x{2019}\x{201A}\x{201C}\x{201D}\x{201F}\x{2033}\x{2036}/`',"""""/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
32
|
|
|
64
|
|
|
|
|
110
|
|
690
|
|
|
|
|
|
|
} |
691
|
|
|
|
|
|
|
|
692
|
854
|
|
|
|
|
2760
|
return $self->{encoder}->encode($str); |
693
|
|
|
|
|
|
|
} |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
696
|
|
|
|
|
|
|
sub out { # Output a word |
697
|
823
|
|
|
823
|
0
|
821
|
my ( $self, $text ) = @_; |
698
|
|
|
|
|
|
|
|
699
|
823
|
|
|
|
|
901
|
$text =~ tr/\xA0\xAD/ /d; |
700
|
|
|
|
|
|
|
### Trapping new word: $text |
701
|
|
|
|
|
|
|
|
702
|
823
|
100
|
|
|
|
1345
|
if ( $self->{collectingTheTitle} ) { |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
# Both collect and print the title |
705
|
7
|
|
|
|
|
8
|
$text =~ s/([\(\)\\])/\\$1/g; # Escape parens and the backslash |
706
|
7
|
|
|
|
|
7
|
$self->{title} .= $text; |
707
|
7
|
|
|
|
|
11
|
return; |
708
|
|
|
|
|
|
|
} |
709
|
|
|
|
|
|
|
|
710
|
816
|
|
|
|
|
1011
|
my $fontid = $self->setfont(); |
711
|
816
|
|
|
|
|
1123
|
my $w = $self->width($text); |
712
|
|
|
|
|
|
|
|
713
|
816
|
100
|
|
|
|
2224
|
if ( $text =~ /^\s*$/ ) { |
714
|
409
|
|
|
|
|
718
|
$self->{hspace} = [ " ", $fontid, $w ]; |
715
|
409
|
|
|
|
|
789
|
return; |
716
|
|
|
|
|
|
|
} |
717
|
|
|
|
|
|
|
|
718
|
407
|
|
|
|
|
644
|
$self->skip_vspace; |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
# determine spacing / line breaks needed before text |
721
|
407
|
100
|
|
|
|
656
|
if ( $self->{hspace} ) { |
722
|
384
|
|
|
|
|
293
|
my ( $stext, $sfont, $swidth ) = @{ $self->{hspace} }; |
|
384
|
|
|
|
|
584
|
|
723
|
384
|
100
|
|
|
|
667
|
if ( $self->{xpos} + $swidth + $w > $self->{rm} ) { |
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
# line break |
726
|
11
|
|
|
|
|
25
|
$self->showline; |
727
|
|
|
|
|
|
|
} |
728
|
|
|
|
|
|
|
else { |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
# no line break; output a space |
731
|
373
|
|
|
|
|
511
|
$self->show_with_font( $stext, $sfont, $swidth ); |
732
|
|
|
|
|
|
|
} |
733
|
384
|
|
|
|
|
424
|
$self->{hspace} = undef; |
734
|
|
|
|
|
|
|
} |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
# output the text |
737
|
407
|
|
|
|
|
671
|
$self->show_with_font( $text, $fontid, $w ); |
738
|
|
|
|
|
|
|
} |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
741
|
|
|
|
|
|
|
sub show_with_font { |
742
|
780
|
|
|
780
|
0
|
864
|
my ( $self, $text, $fontid, $w ) = @_; |
743
|
|
|
|
|
|
|
|
744
|
780
|
|
|
|
|
937
|
my $fontps = $self->switchfont($fontid); |
745
|
780
|
100
|
|
|
|
1187
|
if ( length $fontps ) { |
746
|
13
|
|
|
|
|
21
|
$self->show; |
747
|
13
|
|
|
|
|
34
|
$self->{line} .= "$fontps\n"; |
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
|
750
|
780
|
|
|
|
|
691
|
$self->{xpos} += $w; |
751
|
780
|
|
|
|
|
702
|
$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
|
|
|
|
1186
|
if $self->{largest_pointsize} < $self->{pointsize}; |
759
|
780
|
|
|
|
|
1302
|
$self->{'out'}++; |
760
|
|
|
|
|
|
|
} |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
763
|
|
|
|
|
|
|
sub pre_out { |
764
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $text ) = @_; |
765
|
|
|
|
|
|
|
|
766
|
1
|
|
|
|
|
4
|
$self->skip_vspace; |
767
|
1
|
|
|
|
|
6
|
$self->tt_start; |
768
|
1
|
|
|
|
|
2
|
my $font = $self->findfont(); |
769
|
1
|
50
|
|
|
|
6
|
if ( length $font ) { |
770
|
1
|
|
|
|
|
4
|
$self->show; |
771
|
1
|
|
|
|
|
3
|
$self->{line} .= "$font\n"; |
772
|
|
|
|
|
|
|
} |
773
|
1
|
|
|
|
|
9
|
while ( $text =~ s/(.*)\n// ) { |
774
|
3
|
|
|
|
|
4
|
$self->{'out'}++; |
775
|
3
|
|
|
|
|
7
|
$self->{showstring} .= $1; |
776
|
3
|
|
|
|
|
7
|
$self->showline; |
777
|
|
|
|
|
|
|
} |
778
|
1
|
|
|
|
|
2
|
$self->{showstring} .= $text; |
779
|
1
|
|
|
|
|
4
|
$self->tt_end; |
780
|
1
|
|
|
|
|
2
|
1; |
781
|
|
|
|
|
|
|
} |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
784
|
|
|
|
|
|
|
sub bullet { |
785
|
4
|
|
|
4
|
0
|
49
|
my ( $self, $bullet ) = @_; |
786
|
|
|
|
|
|
|
|
787
|
4
|
|
|
|
|
6
|
$self->{bullet} = $bullet; |
788
|
4
|
|
|
|
|
8
|
$self->{bullet_pos} = $self->{lm}; |
789
|
|
|
|
|
|
|
} |
790
|
|
|
|
|
|
|
|
791
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
792
|
|
|
|
|
|
|
sub adjust_lm { |
793
|
14
|
|
|
14
|
0
|
17
|
my $self = shift; |
794
|
|
|
|
|
|
|
|
795
|
14
|
|
|
|
|
21
|
$self->showline; |
796
|
|
|
|
|
|
|
|
797
|
14
|
|
|
|
|
20
|
$self->{lm} += $_[0] * $self->{en}; |
798
|
14
|
|
|
|
|
24
|
1; |
799
|
|
|
|
|
|
|
} |
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
802
|
|
|
|
|
|
|
sub adjust_rm { |
803
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
804
|
|
|
|
|
|
|
|
805
|
2
|
|
|
|
|
3
|
$self->showline; |
806
|
|
|
|
|
|
|
|
807
|
2
|
|
|
|
|
17
|
$self->{rm} += $_[0] * $self->{en}; |
808
|
|
|
|
|
|
|
} |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
811
|
6
|
|
|
6
|
0
|
11
|
sub head_start { 1; } |
812
|
6
|
|
|
6
|
0
|
12
|
sub head_end { 1; } |
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
sub title_start { |
815
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
816
|
|
|
|
|
|
|
|
817
|
1
|
|
|
|
|
1
|
$self->{collectingTheTitle} = 1; |
818
|
1
|
|
|
|
|
3
|
1; |
819
|
|
|
|
|
|
|
} |
820
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
sub title_end { |
822
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
823
|
|
|
|
|
|
|
|
824
|
1
|
|
|
|
|
1
|
$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__ |