line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::API2::Util; |
2
|
|
|
|
|
|
|
|
3
|
39
|
|
|
39
|
|
280
|
use strict; |
|
39
|
|
|
|
|
80
|
|
|
39
|
|
|
|
|
1327
|
|
4
|
39
|
|
|
39
|
|
196
|
no warnings qw[ recursion uninitialized ]; |
|
39
|
|
|
|
|
70
|
|
|
39
|
|
|
|
|
1919
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.045'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
39
|
|
|
39
|
|
211
|
use Encode qw(:all); |
|
39
|
|
|
|
|
76
|
|
|
39
|
|
|
|
|
10199
|
|
10
|
39
|
|
|
39
|
|
21212
|
use Math::Trig; |
|
39
|
|
|
|
|
521132
|
|
|
39
|
|
|
|
|
5509
|
|
11
|
39
|
|
|
39
|
|
341
|
use List::Util qw(min max); |
|
39
|
|
|
|
|
80
|
|
|
39
|
|
|
|
|
3956
|
|
12
|
39
|
|
|
39
|
|
283
|
use PDF::API2::Basic::PDF::Utils; |
|
39
|
|
|
|
|
83
|
|
|
39
|
|
|
|
|
2688
|
|
13
|
39
|
|
|
39
|
|
267
|
use PDF::API2::Basic::PDF::Filter; |
|
39
|
|
|
|
|
90
|
|
|
39
|
|
|
|
|
1073
|
|
14
|
39
|
|
|
39
|
|
22508
|
use PDF::API2::Resource::Colors; |
|
39
|
|
|
|
|
124
|
|
|
39
|
|
|
|
|
1317
|
|
15
|
39
|
|
|
39
|
|
53080
|
use PDF::API2::Resource::Glyphs; |
|
39
|
|
|
|
|
574
|
|
|
39
|
|
|
|
|
14949
|
|
16
|
39
|
|
|
39
|
|
19880
|
use PDF::API2::Resource::PaperSizes; |
|
39
|
|
|
|
|
111
|
|
|
39
|
|
|
|
|
1381
|
|
17
|
39
|
|
|
39
|
|
243
|
use POSIX qw( HUGE_VAL floor ); |
|
39
|
|
|
|
|
87
|
|
|
39
|
|
|
|
|
317
|
|
18
|
|
|
|
|
|
|
|
19
|
39
|
|
|
|
|
3495
|
use vars qw( |
20
|
|
|
|
|
|
|
@ISA |
21
|
|
|
|
|
|
|
@EXPORT |
22
|
|
|
|
|
|
|
@EXPORT_OK |
23
|
|
|
|
|
|
|
%colors |
24
|
|
|
|
|
|
|
$key_var |
25
|
|
|
|
|
|
|
%u2n |
26
|
|
|
|
|
|
|
%n2u |
27
|
|
|
|
|
|
|
$pua |
28
|
|
|
|
|
|
|
%PaperSizes |
29
|
39
|
|
|
39
|
|
4048
|
); |
|
39
|
|
|
|
|
77
|
|
30
|
|
|
|
|
|
|
|
31
|
39
|
|
|
39
|
|
217
|
use Exporter; |
|
39
|
|
|
|
|
76
|
|
|
39
|
|
|
|
|
5061
|
|
32
|
39
|
|
|
39
|
|
813
|
@ISA = qw(Exporter); |
33
|
39
|
|
|
|
|
251
|
@EXPORT = qw( |
34
|
|
|
|
|
|
|
pdfkey |
35
|
|
|
|
|
|
|
float floats floats5 intg intgs |
36
|
|
|
|
|
|
|
mMin mMax |
37
|
|
|
|
|
|
|
HSVtoRGB RGBtoHSV HSLtoRGB RGBtoHSL RGBtoLUM |
38
|
|
|
|
|
|
|
namecolor namecolor_cmyk namecolor_lab optInvColor defineColor |
39
|
|
|
|
|
|
|
dofilter unfilter |
40
|
|
|
|
|
|
|
nameByUni uniByName initNameTable defineName |
41
|
|
|
|
|
|
|
page_size |
42
|
|
|
|
|
|
|
getPaperSizes |
43
|
|
|
|
|
|
|
); |
44
|
39
|
|
|
|
|
172
|
@EXPORT_OK = qw( |
45
|
|
|
|
|
|
|
pdfkey |
46
|
|
|
|
|
|
|
digest digestx digest16 digest32 |
47
|
|
|
|
|
|
|
float floats floats5 intg intgs |
48
|
|
|
|
|
|
|
mMin mMax |
49
|
|
|
|
|
|
|
cRGB cRGB8 RGBasCMYK |
50
|
|
|
|
|
|
|
HSVtoRGB RGBtoHSV HSLtoRGB RGBtoHSL RGBtoLUM |
51
|
|
|
|
|
|
|
namecolor namecolor_cmyk namecolor_lab optInvColor defineColor |
52
|
|
|
|
|
|
|
dofilter unfilter |
53
|
|
|
|
|
|
|
nameByUni uniByName initNameTable defineName |
54
|
|
|
|
|
|
|
page_size |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
39
|
|
|
|
|
363
|
%colors = PDF::API2::Resource::Colors->get_colors(); |
58
|
39
|
|
|
|
|
1068
|
%PaperSizes = PDF::API2::Resource::PaperSizes->get_paper_sizes(); |
59
|
|
|
|
|
|
|
|
60
|
39
|
|
|
39
|
|
276
|
no warnings qw[ recursion uninitialized ]; |
|
39
|
|
|
|
|
77
|
|
|
39
|
|
|
|
|
2906
|
|
61
|
|
|
|
|
|
|
|
62
|
39
|
|
|
|
|
168
|
$key_var = 'CBA'; |
63
|
|
|
|
|
|
|
|
64
|
39
|
|
|
|
|
67
|
$pua = 0xE000; |
65
|
|
|
|
|
|
|
|
66
|
39
|
|
|
|
|
75
|
%u2n = %{$PDF::API2::Resource::Glyphs::u2n}; |
|
39
|
|
|
|
|
75112
|
|
67
|
39
|
|
|
|
|
5371
|
%n2u = %{$PDF::API2::Resource::Glyphs::n2u}; |
|
39
|
|
|
|
|
242986
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub pdfkey { |
71
|
86
|
|
|
86
|
0
|
969
|
return $PDF::API2::Util::key_var++; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub digestx { |
75
|
0
|
|
|
0
|
0
|
0
|
my $len = shift(); |
76
|
0
|
|
|
|
|
0
|
my $mask = $len - 1; |
77
|
0
|
|
|
|
|
0
|
my $ddata = join('', @_); |
78
|
0
|
|
|
|
|
0
|
my $mdkey = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789gT'; |
79
|
0
|
|
|
|
|
0
|
my $xdata = '0' x $len; |
80
|
0
|
|
|
|
|
0
|
my $off = 0; |
81
|
0
|
|
|
|
|
0
|
foreach my $set (0 .. (length($ddata) << 1)) { |
82
|
0
|
|
|
|
|
0
|
$off += vec($ddata, $set, 4); |
83
|
0
|
|
|
|
|
0
|
$off += vec($xdata, ($set & $mask), 8); |
84
|
0
|
|
|
|
|
0
|
vec($xdata, ($set & ($mask << 1 | 1)), 4) = vec($mdkey, ($off & 0x7f), 4); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# foreach $set (0 .. $mask) { |
88
|
|
|
|
|
|
|
# vec($xdata, $set, 8) = (vec($xdata, $set, 8) & 0x7f) | 0x40; |
89
|
|
|
|
|
|
|
# } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# $off = 0; |
92
|
|
|
|
|
|
|
# foreach $set (0 .. $mask) { |
93
|
|
|
|
|
|
|
# $off += vec($xdata, $set, 8); |
94
|
|
|
|
|
|
|
# vec($xdata, $set, 8) = vec($mdkey, ($off & 0x3f), 8); |
95
|
|
|
|
|
|
|
# } |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
0
|
return $xdata; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub digest { |
101
|
0
|
|
|
0
|
0
|
0
|
return digestx(32, @_); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub digest16 { |
105
|
0
|
|
|
0
|
0
|
0
|
return digestx(16, @_); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub digest32 { |
109
|
0
|
|
|
0
|
0
|
0
|
return digestx(32, @_); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub xlog10 { |
113
|
1506
|
|
|
1506
|
0
|
1893
|
my $n = shift(); |
114
|
1506
|
100
|
|
|
|
2267
|
if ($n) { |
115
|
1110
|
|
|
|
|
3738
|
return log(abs($n)) / log(10); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
396
|
|
|
|
|
1103
|
return 0; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub float { |
123
|
1506
|
|
|
1506
|
0
|
2008
|
my $f = shift(); |
124
|
1506
|
|
100
|
|
|
3640
|
my $mxd = shift() || 4; |
125
|
1506
|
100
|
|
|
|
2896
|
$f = 0 if abs($f) < 0.0000000000000001; |
126
|
1506
|
|
|
|
|
2234
|
my $ad = floor(xlog10($f) - $mxd); |
127
|
1506
|
100
|
|
|
|
4303
|
if (abs($f - int($f)) < (10 ** (-$mxd))) { |
|
|
50
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# just in case we have an integer |
129
|
918
|
|
|
|
|
3862
|
return sprintf('%i', $f); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
elsif ($ad > 0) { |
132
|
0
|
|
|
|
|
0
|
my $value = sprintf('%f', $f); |
133
|
|
|
|
|
|
|
# Remove trailing zeros |
134
|
0
|
|
|
|
|
0
|
$value =~ s/(\.\d*?)0+$/$1/; |
135
|
0
|
|
|
|
|
0
|
$value =~ s/\.$//; |
136
|
0
|
|
|
|
|
0
|
return $value; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { |
139
|
588
|
|
|
|
|
2561
|
my $value = sprintf('%.*f', abs($ad), $f); |
140
|
|
|
|
|
|
|
# Remove trailing zeros |
141
|
588
|
|
|
|
|
1815
|
$value =~ s/(\.\d*?)0+$/$1/; |
142
|
588
|
|
|
|
|
867
|
$value =~ s/\.$//; |
143
|
588
|
|
|
|
|
1461
|
return $value; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
321
|
|
|
321
|
0
|
537
|
sub floats { return map { float($_) } @_; } |
|
1072
|
|
|
|
|
1720
|
|
147
|
49
|
|
|
49
|
0
|
95
|
sub floats5 { return map { float($_, 5) } @_; } |
|
149
|
|
|
|
|
285
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub intg { |
150
|
1
|
|
|
1
|
0
|
2
|
my $f = shift(); |
151
|
1
|
|
|
|
|
10
|
return sprintf('%i', $f); |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
0
|
0
|
0
|
sub intgs { return map { intg($_) } @_; } |
|
0
|
|
|
|
|
0
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub mMin { |
156
|
0
|
|
|
0
|
0
|
0
|
my $n = HUGE_VAL(); |
157
|
0
|
0
|
|
|
|
0
|
map { $n = ($n > $_) ? $_ : $n } @_; |
|
0
|
|
|
|
|
0
|
|
158
|
0
|
|
|
|
|
0
|
return $n; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub mMax { |
162
|
0
|
|
|
0
|
0
|
0
|
my $n = -HUGE_VAL(); |
163
|
0
|
0
|
|
|
|
0
|
map { $n = ($n < $_) ? $_ : $n } @_; |
|
0
|
|
|
|
|
0
|
|
164
|
0
|
|
|
|
|
0
|
return $n; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub cRGB { |
168
|
0
|
|
|
0
|
0
|
0
|
my @cmy = (map { 1 - $_ } @_); |
|
0
|
|
|
|
|
0
|
|
169
|
0
|
|
|
|
|
0
|
my $k = mMin(@cmy); |
170
|
0
|
|
|
|
|
0
|
return (map { $_ - $k } @cmy), $k; |
|
0
|
|
|
|
|
0
|
|
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub cRGB8 { |
174
|
0
|
|
|
0
|
0
|
0
|
return cRGB(map { $_ / 255 } @_); |
|
0
|
|
|
|
|
0
|
|
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub RGBtoLUM { |
178
|
0
|
|
|
0
|
0
|
0
|
my ($r, $g, $b) = @_; |
179
|
0
|
|
|
|
|
0
|
return $r * 0.299 + $g * 0.587 + $b * 0.114; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub RGBasCMYK { |
183
|
0
|
|
|
0
|
0
|
0
|
my @rgb = @_; |
184
|
0
|
|
|
|
|
0
|
my @cmy = map { 1 - $_ } @rgb; |
|
0
|
|
|
|
|
0
|
|
185
|
0
|
|
|
|
|
0
|
my $k = mMin(@cmy) * 0.44; |
186
|
0
|
|
|
|
|
0
|
return (map { $_ - $k } @cmy), $k; |
|
0
|
|
|
|
|
0
|
|
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub HSVtoRGB { |
190
|
24
|
|
|
24
|
0
|
45
|
my ($h, $s, $v) = @_; |
191
|
24
|
|
|
|
|
31
|
my ($r, $g, $b, $i, $f, $p, $q, $t); |
192
|
|
|
|
|
|
|
|
193
|
24
|
50
|
|
|
|
49
|
if ($s == 0) { |
194
|
|
|
|
|
|
|
# achromatic (grey) |
195
|
0
|
|
|
|
|
0
|
return ($v, $v, $v); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
24
|
|
|
|
|
31
|
$h %= 360; |
199
|
24
|
|
|
|
|
33
|
$h /= 60; ## sector 0 to 5 |
200
|
24
|
|
|
|
|
56
|
$i = POSIX::floor($h); |
201
|
24
|
|
|
|
|
35
|
$f = $h - $i; ## factorial part of h |
202
|
24
|
|
|
|
|
34
|
$p = $v * (1 - $s); |
203
|
24
|
|
|
|
|
37
|
$q = $v * (1 - $s * $f); |
204
|
24
|
|
|
|
|
32
|
$t = $v * (1 - $s * (1 - $f)); |
205
|
|
|
|
|
|
|
|
206
|
24
|
100
|
|
|
|
64
|
if ($i < 1) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
207
|
5
|
|
|
|
|
6
|
$r = $v; |
208
|
5
|
|
|
|
|
6
|
$g = $t; |
209
|
5
|
|
|
|
|
6
|
$b = $p; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
elsif ($i < 2) { |
212
|
4
|
|
|
|
|
7
|
$r = $q; |
213
|
4
|
|
|
|
|
5
|
$g = $v; |
214
|
4
|
|
|
|
|
5
|
$b = $p; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
elsif ($i < 3) { |
217
|
3
|
|
|
|
|
6
|
$r = $p; |
218
|
3
|
|
|
|
|
5
|
$g = $v; |
219
|
3
|
|
|
|
|
3
|
$b = $t; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
elsif ($i < 4) { |
222
|
5
|
|
|
|
|
7
|
$r = $p; |
223
|
5
|
|
|
|
|
7
|
$g = $q; |
224
|
5
|
|
|
|
|
8
|
$b = $v; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
elsif ($i < 5) { |
227
|
3
|
|
|
|
|
4
|
$r = $t; |
228
|
3
|
|
|
|
|
5
|
$g = $p; |
229
|
3
|
|
|
|
|
5
|
$b = $v; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
else { |
232
|
4
|
|
|
|
|
5
|
$r = $v; |
233
|
4
|
|
|
|
|
5
|
$g = $p; |
234
|
4
|
|
|
|
|
6
|
$b = $q; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
24
|
|
|
|
|
51
|
return ($r, $g, $b); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub RGBquant { |
241
|
0
|
|
|
0
|
0
|
0
|
my ($q1, $q2, $h) = @_; |
242
|
0
|
|
|
|
|
0
|
while ($h < 0){ |
243
|
0
|
|
|
|
|
0
|
$h += 360; |
244
|
|
|
|
|
|
|
} |
245
|
0
|
|
|
|
|
0
|
$h %= 360; |
246
|
0
|
0
|
|
|
|
0
|
if ($h < 60) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
247
|
0
|
|
|
|
|
0
|
return $q1 + (($q2 - $q1) * $h / 60); |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
elsif ($h < 180) { |
250
|
0
|
|
|
|
|
0
|
return $q2; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
elsif ($h < 240) { |
253
|
0
|
|
|
|
|
0
|
return $q1 + (($q2 - $q1) * (240 - $h) / 60); |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
else { |
256
|
0
|
|
|
|
|
0
|
return $q1; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub RGBtoHSV { |
261
|
0
|
|
|
0
|
0
|
0
|
my ($r, $g, $b) = @_; |
262
|
0
|
|
|
|
|
0
|
my ($h, $s, $v, $min, $max, $delta); |
263
|
|
|
|
|
|
|
|
264
|
0
|
|
|
|
|
0
|
$min = mMin($r, $g, $b); |
265
|
0
|
|
|
|
|
0
|
$max = mMax($r, $g, $b); |
266
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
0
|
$v = $max; |
268
|
|
|
|
|
|
|
|
269
|
0
|
|
|
|
|
0
|
$delta = $max - $min; |
270
|
|
|
|
|
|
|
|
271
|
0
|
0
|
|
|
|
0
|
if ($delta > 0.000000001) { |
272
|
0
|
|
|
|
|
0
|
$s = $delta / $max; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
else { |
275
|
0
|
|
|
|
|
0
|
$s = 0; |
276
|
0
|
|
|
|
|
0
|
$h = 0; |
277
|
0
|
|
|
|
|
0
|
return ($h, $s, $v); |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
|
280
|
0
|
0
|
|
|
|
0
|
if ($r == $max) { |
|
|
0
|
|
|
|
|
|
281
|
0
|
|
|
|
|
0
|
$h = ($g - $b) / $delta; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
elsif ($g == $max) { |
284
|
0
|
|
|
|
|
0
|
$h = 2 + ($b - $r) / $delta; |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
else { |
287
|
0
|
|
|
|
|
0
|
$h = 4 + ($r - $g) / $delta; |
288
|
|
|
|
|
|
|
} |
289
|
0
|
|
|
|
|
0
|
$h *= 60; |
290
|
0
|
0
|
|
|
|
0
|
if ($h < 0) { |
291
|
0
|
|
|
|
|
0
|
$h += 360; |
292
|
|
|
|
|
|
|
} |
293
|
0
|
|
|
|
|
0
|
return ($h, $s, $v); |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
sub RGBtoHSL { |
297
|
0
|
|
|
0
|
0
|
0
|
my ($r, $g, $b) = @_; |
298
|
0
|
|
|
|
|
0
|
my ($h, $s, $v, $l, $min, $max, $delta); |
299
|
|
|
|
|
|
|
|
300
|
0
|
|
|
|
|
0
|
$min = mMin($r, $g, $b); |
301
|
0
|
|
|
|
|
0
|
$max = mMax($r, $g, $b); |
302
|
0
|
|
|
|
|
0
|
($h, $s, $v) = RGBtoHSV($r, $g, $b); |
303
|
0
|
|
|
|
|
0
|
$l = ($max + $min) / 2.0; |
304
|
0
|
|
|
|
|
0
|
$delta = $max - $min; |
305
|
0
|
0
|
|
|
|
0
|
if ($delta < 0.00000000001) { |
306
|
0
|
|
|
|
|
0
|
return (0, 0, $l); |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
else { |
309
|
0
|
0
|
|
|
|
0
|
if ($l <= 0.5) { |
310
|
0
|
|
|
|
|
0
|
$s = $delta / ($max + $min); |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
else { |
313
|
0
|
|
|
|
|
0
|
$s = $delta / (2 - $max - $min); |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
} |
316
|
0
|
|
|
|
|
0
|
return ($h, $s, $l); |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
sub HSLtoRGB { |
320
|
0
|
|
|
0
|
0
|
0
|
my ($h, $s, $l, $r, $g, $b, $p1, $p2) = @_; |
321
|
0
|
0
|
|
|
|
0
|
if ($l <= 0.5) { |
322
|
0
|
|
|
|
|
0
|
$p2 = $l * (1 + $s); |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
else { |
325
|
0
|
|
|
|
|
0
|
$p2 = $l + $s - ($l * $s); |
326
|
|
|
|
|
|
|
} |
327
|
0
|
|
|
|
|
0
|
$p1 = 2 * $l - $p2; |
328
|
0
|
0
|
|
|
|
0
|
if ($s < 0.0000000000001) { |
329
|
0
|
|
|
|
|
0
|
$r = $g = $b = $l; |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
else { |
332
|
0
|
|
|
|
|
0
|
$r = RGBquant($p1, $p2, $h + 120); |
333
|
0
|
|
|
|
|
0
|
$g = RGBquant($p1, $p2, $h); |
334
|
0
|
|
|
|
|
0
|
$b = RGBquant($p1, $p2, $h - 120); |
335
|
|
|
|
|
|
|
} |
336
|
0
|
|
|
|
|
0
|
return ($r, $g, $b); |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
sub optInvColor { |
340
|
0
|
|
|
0
|
0
|
0
|
my ($r, $g, $b) = @_; |
341
|
|
|
|
|
|
|
|
342
|
0
|
|
|
|
|
0
|
my $ab = (0.2 * $r) + (0.7 * $g) + (0.1 * $b); |
343
|
|
|
|
|
|
|
|
344
|
0
|
0
|
|
|
|
0
|
if ($ab > 0.45) { |
345
|
0
|
|
|
|
|
0
|
return (0, 0, 0); |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
else { |
348
|
0
|
|
|
|
|
0
|
return (1, 1, 1); |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
sub defineColor { |
353
|
0
|
|
|
0
|
0
|
0
|
my ($name, $mx, $r, $g, $b) = @_; |
354
|
0
|
|
0
|
|
|
0
|
$colors{$name} ||= [ map {$_ / $mx} ($r, $g, $b) ]; |
|
0
|
|
|
|
|
0
|
|
355
|
0
|
|
|
|
|
0
|
return $colors{$name}; |
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
sub rgbHexValues { |
359
|
23
|
|
|
23
|
0
|
47
|
my $name = lc(shift()); |
360
|
23
|
|
|
|
|
39
|
my ($r, $g, $b); |
361
|
23
|
50
|
|
|
|
100
|
if (length($name) < 5) { # zb. #fa4, #cf0 |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
362
|
0
|
|
|
|
|
0
|
$r = hex(substr($name, 1, 1)) / 0xf; |
363
|
0
|
|
|
|
|
0
|
$g = hex(substr($name, 2, 1)) / 0xf; |
364
|
0
|
|
|
|
|
0
|
$b = hex(substr($name, 3, 1)) / 0xf; |
365
|
|
|
|
|
|
|
} |
366
|
|
|
|
|
|
|
elsif (length($name) < 8) { # zb. #ffaa44, #ccff00 |
367
|
23
|
|
|
|
|
82
|
$r = hex(substr($name, 1, 2)) / 0xff; |
368
|
23
|
|
|
|
|
59
|
$g = hex(substr($name, 3, 2)) / 0xff; |
369
|
23
|
|
|
|
|
45
|
$b = hex(substr($name, 5, 2)) / 0xff; |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
elsif(length($name) < 11) { # zb. #fffaaa444, #cccfff000 |
372
|
0
|
|
|
|
|
0
|
$r = hex(substr($name, 1, 3)) / 0xfff; |
373
|
0
|
|
|
|
|
0
|
$g = hex(substr($name, 4, 3)) / 0xfff; |
374
|
0
|
|
|
|
|
0
|
$b = hex(substr($name, 7, 3)) / 0xfff; |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
else { # zb. #ffffaaaa4444, #ccccffff0000 |
377
|
0
|
|
|
|
|
0
|
$r = hex(substr($name, 1, 4)) / 0xffff; |
378
|
0
|
|
|
|
|
0
|
$g = hex(substr($name, 5, 4)) / 0xffff; |
379
|
0
|
|
|
|
|
0
|
$b = hex(substr($name, 9, 4)) / 0xffff; |
380
|
|
|
|
|
|
|
} |
381
|
23
|
|
|
|
|
74
|
return ($r, $g, $b); |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
sub cmykHexValues { |
385
|
2
|
|
|
2
|
0
|
6
|
my $name = lc(shift()); |
386
|
2
|
|
|
|
|
4
|
my ($c, $m, $y, $k); |
387
|
2
|
50
|
|
|
|
19
|
if (length($name) < 6) { # zb. %cmyk |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
388
|
0
|
|
|
|
|
0
|
$c = hex(substr($name, 1, 1)) / 0xf; |
389
|
0
|
|
|
|
|
0
|
$m = hex(substr($name, 2, 1)) / 0xf; |
390
|
0
|
|
|
|
|
0
|
$y = hex(substr($name, 3, 1)) / 0xf; |
391
|
0
|
|
|
|
|
0
|
$k = hex(substr($name, 4, 1)) / 0xf; |
392
|
|
|
|
|
|
|
} |
393
|
|
|
|
|
|
|
elsif (length($name) < 10) { # zb. %ccmmyykk |
394
|
2
|
|
|
|
|
10
|
$c = hex(substr($name, 1, 2)) / 0xff; |
395
|
2
|
|
|
|
|
5
|
$m = hex(substr($name, 3, 2)) / 0xff; |
396
|
2
|
|
|
|
|
5
|
$y = hex(substr($name, 5, 2)) / 0xff; |
397
|
2
|
|
|
|
|
4
|
$k = hex(substr($name, 7, 2)) / 0xff; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
elsif (length($name) < 14) { # zb. %cccmmmyyykkk |
400
|
0
|
|
|
|
|
0
|
$c = hex(substr($name, 1, 3)) / 0xfff; |
401
|
0
|
|
|
|
|
0
|
$m = hex(substr($name, 4, 3)) / 0xfff; |
402
|
0
|
|
|
|
|
0
|
$y = hex(substr($name, 7, 3)) / 0xfff; |
403
|
0
|
|
|
|
|
0
|
$k = hex(substr($name, 10, 3)) / 0xfff; |
404
|
|
|
|
|
|
|
} |
405
|
|
|
|
|
|
|
else { # zb. %ccccmmmmyyyykkkk |
406
|
0
|
|
|
|
|
0
|
$c = hex(substr($name, 1, 4)) / 0xffff; |
407
|
0
|
|
|
|
|
0
|
$m = hex(substr($name, 5, 4)) / 0xffff; |
408
|
0
|
|
|
|
|
0
|
$y = hex(substr($name, 9, 4)) / 0xffff; |
409
|
0
|
|
|
|
|
0
|
$k = hex(substr($name, 13, 4)) / 0xffff; |
410
|
|
|
|
|
|
|
} |
411
|
2
|
|
|
|
|
8
|
return ($c, $m, $y, $k); |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
sub hsvHexValues { |
415
|
24
|
|
|
24
|
0
|
37
|
my $name = lc(shift()); |
416
|
24
|
|
|
|
|
34
|
my ($h, $s, $v); |
417
|
24
|
50
|
|
|
|
62
|
if (length($name) < 5) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
418
|
0
|
|
|
|
|
0
|
$h = 360 * hex(substr($name, 1, 1)) / 0x10; |
419
|
0
|
|
|
|
|
0
|
$s = hex(substr($name, 2, 1)) / 0xf; |
420
|
0
|
|
|
|
|
0
|
$v = hex(substr($name, 3, 1)) / 0xf; |
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
elsif (length($name) < 8) { |
423
|
24
|
|
|
|
|
57
|
$h = 360 * hex(substr($name, 1, 2)) / 0x100; |
424
|
24
|
|
|
|
|
35
|
$s = hex(substr($name, 3, 2)) / 0xff; |
425
|
24
|
|
|
|
|
33
|
$v = hex(substr($name, 5, 2)) / 0xff; |
426
|
|
|
|
|
|
|
} |
427
|
|
|
|
|
|
|
elsif (length($name) < 11) { |
428
|
0
|
|
|
|
|
0
|
$h = 360 * hex(substr($name, 1, 3)) / 0x1000; |
429
|
0
|
|
|
|
|
0
|
$s = hex(substr($name, 4, 3)) / 0xfff; |
430
|
0
|
|
|
|
|
0
|
$v = hex(substr($name, 7, 3)) / 0xfff; |
431
|
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
else { |
433
|
0
|
|
|
|
|
0
|
$h = 360 * hex(substr($name, 1, 4)) / 0x10000; |
434
|
0
|
|
|
|
|
0
|
$s = hex(substr($name, 5, 4)) / 0xffff; |
435
|
0
|
|
|
|
|
0
|
$v = hex(substr($name, 9, 4)) / 0xffff; |
436
|
|
|
|
|
|
|
} |
437
|
24
|
|
|
|
|
59
|
return ($h, $s, $v); |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
sub labHexValues { |
441
|
0
|
|
|
0
|
0
|
0
|
my $name = lc(shift()); |
442
|
0
|
|
|
|
|
0
|
my ($l, $a, $b); |
443
|
0
|
0
|
|
|
|
0
|
if (length($name) < 5) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
444
|
0
|
|
|
|
|
0
|
$l = 100 * hex(substr($name, 1, 1)) / 0xf; |
445
|
0
|
|
|
|
|
0
|
$a = (200 * hex(substr($name, 2, 1)) / 0xf) - 100; |
446
|
0
|
|
|
|
|
0
|
$b = (200 * hex(substr($name, 3, 1)) / 0xf) - 100; |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
elsif (length($name) < 8) { |
449
|
0
|
|
|
|
|
0
|
$l = 100 * hex(substr($name, 1, 2)) / 0xff; |
450
|
0
|
|
|
|
|
0
|
$a = (200 * hex(substr($name, 3, 2)) / 0xff) - 100; |
451
|
0
|
|
|
|
|
0
|
$b = (200 * hex(substr($name, 5, 2)) / 0xff) - 100; |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
elsif (length($name) < 11) { |
454
|
0
|
|
|
|
|
0
|
$l = 100 * hex(substr($name, 1, 3)) / 0xfff; |
455
|
0
|
|
|
|
|
0
|
$a = (200 * hex(substr($name, 4, 3)) / 0xfff) - 100; |
456
|
0
|
|
|
|
|
0
|
$b = (200 * hex(substr($name, 7, 3)) / 0xfff) - 100; |
457
|
|
|
|
|
|
|
} |
458
|
|
|
|
|
|
|
else { |
459
|
0
|
|
|
|
|
0
|
$l = 100 * hex(substr($name, 1, 4)) / 0xffff; |
460
|
0
|
|
|
|
|
0
|
$a = (200 * hex(substr($name, 5, 4)) / 0xffff) - 100; |
461
|
0
|
|
|
|
|
0
|
$b = (200 * hex(substr($name, 9, 4)) / 0xffff) - 100; |
462
|
|
|
|
|
|
|
} |
463
|
|
|
|
|
|
|
|
464
|
0
|
|
|
|
|
0
|
return ($l, $a, $b); |
465
|
|
|
|
|
|
|
} |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
sub namecolor { |
468
|
68
|
|
|
68
|
0
|
113
|
my $name = shift(); |
469
|
68
|
50
|
|
|
|
141
|
unless (ref($name)) { |
470
|
68
|
|
|
|
|
138
|
$name = lc($name); |
471
|
68
|
|
|
|
|
147
|
$name =~ s/[^\#!%\&\$a-z0-9]//g; |
472
|
|
|
|
|
|
|
} |
473
|
68
|
100
|
|
|
|
266
|
if ($name =~ /^[a-z]/) { # name spec. |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
474
|
21
|
|
|
|
|
88
|
return namecolor($colors{$name}); |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
elsif ($name =~ /^#/) { # rgb spec. |
477
|
23
|
|
|
|
|
77
|
return floats5(rgbHexValues($name)); |
478
|
|
|
|
|
|
|
} |
479
|
|
|
|
|
|
|
elsif ($name =~ /^%/) { # cmyk spec. |
480
|
0
|
|
|
|
|
0
|
return floats5(cmykHexValues($name)); |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
elsif ($name =~ /^!/) { # hsv spec. |
483
|
24
|
|
|
|
|
45
|
return floats5(HSVtoRGB(hsvHexValues($name))); |
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
elsif ($name =~ /^&/) { # hsl spec. |
486
|
0
|
|
|
|
|
0
|
return floats5(HSLtoRGB(hsvHexValues($name))); |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
else { # or it is a ref ? |
489
|
0
|
0
|
|
|
|
0
|
return floats5(@{$name || [0.5, 0.5, 0.5]}); |
|
0
|
|
|
|
|
0
|
|
490
|
|
|
|
|
|
|
} |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
sub namecolor_cmyk { |
494
|
2
|
|
|
2
|
0
|
5
|
my $name = shift(); |
495
|
2
|
50
|
|
|
|
5
|
unless (ref($name)) { |
496
|
2
|
|
|
|
|
7
|
$name = lc($name); |
497
|
2
|
|
|
|
|
7
|
$name =~ s/[^\#!%\&\$a-z0-9]//g; |
498
|
|
|
|
|
|
|
} |
499
|
2
|
50
|
|
|
|
16
|
if ($name =~ /^[a-z]/) { # name spec. |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
500
|
0
|
|
|
|
|
0
|
return namecolor_cmyk($colors{$name}); |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
elsif ($name =~ /^#/) { # rgb spec. |
503
|
0
|
|
|
|
|
0
|
return floats5(RGBasCMYK(rgbHexValues($name))); |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
elsif ($name =~ /^%/) { # cmyk spec. |
506
|
2
|
|
|
|
|
8
|
return floats5(cmykHexValues($name)); |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
elsif ($name =~ /^!/) { # hsv spec. |
509
|
0
|
|
|
|
|
0
|
return floats5(RGBasCMYK(HSVtoRGB(hsvHexValues($name)))); |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
elsif ($name =~ /^&/) { # hsl spec. |
512
|
0
|
|
|
|
|
0
|
return floats5(RGBasCMYK(HSLtoRGB(hsvHexValues($name)))); |
513
|
|
|
|
|
|
|
} |
514
|
|
|
|
|
|
|
else { # or it is a ref ? |
515
|
0
|
0
|
|
|
|
0
|
return floats5(RGBasCMYK(@{$name || [0.5, 0.5, 0.5]})); |
|
0
|
|
|
|
|
0
|
|
516
|
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
} |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
sub namecolor_lab { |
520
|
0
|
|
|
0
|
0
|
0
|
my $name = shift(); |
521
|
0
|
0
|
|
|
|
0
|
unless (ref($name)) { |
522
|
0
|
|
|
|
|
0
|
$name = lc($name); |
523
|
0
|
|
|
|
|
0
|
$name =~ s/[^\#!%\&\$a-z0-9]//g; |
524
|
|
|
|
|
|
|
} |
525
|
0
|
0
|
|
|
|
0
|
if ($name =~ /^[a-z]/) { # name spec. |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
526
|
0
|
|
|
|
|
0
|
return namecolor_lab($colors{$name}); |
527
|
|
|
|
|
|
|
} |
528
|
|
|
|
|
|
|
elsif ($name =~ /^\$/) { # lab spec. |
529
|
0
|
|
|
|
|
0
|
return floats5(labHexValues($name)); |
530
|
|
|
|
|
|
|
} |
531
|
|
|
|
|
|
|
elsif ($name =~ /^#/) { # rgb spec. |
532
|
0
|
|
|
|
|
0
|
my ($h, $s, $v) = RGBtoHSV(rgbHexValues($name)); |
533
|
0
|
|
|
|
|
0
|
my $a = cos(deg2rad($h)) * $s * 100; |
534
|
0
|
|
|
|
|
0
|
my $b = sin(deg2rad($h)) * $s * 100; |
535
|
0
|
|
|
|
|
0
|
my $l = 100 * $v; |
536
|
0
|
|
|
|
|
0
|
return floats5($l,$a,$b); |
537
|
|
|
|
|
|
|
} |
538
|
|
|
|
|
|
|
elsif ($name =~ /^!/) { # hsv spec. |
539
|
|
|
|
|
|
|
# fake conversion |
540
|
0
|
|
|
|
|
0
|
my ($h, $s, $v) = hsvHexValues($name); |
541
|
0
|
|
|
|
|
0
|
my $a = cos(deg2rad($h)) * $s * 100; |
542
|
0
|
|
|
|
|
0
|
my $b = sin(deg2rad($h)) * $s * 100; |
543
|
0
|
|
|
|
|
0
|
my $l = 100 * $v; |
544
|
0
|
|
|
|
|
0
|
return floats5($l,$a,$b); |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
elsif ($name =~ /^&/) { # hsl spec. |
547
|
0
|
|
|
|
|
0
|
my ($h, $s, $v) = hsvHexValues($name); |
548
|
0
|
|
|
|
|
0
|
my $a = cos(deg2rad($h)) * $s * 100; |
549
|
0
|
|
|
|
|
0
|
my $b = sin(deg2rad($h)) * $s * 100; |
550
|
0
|
|
|
|
|
0
|
($h, $s, $v) = RGBtoHSV(HSLtoRGB($h, $s, $v)); |
551
|
0
|
|
|
|
|
0
|
my $l = 100 * $v; |
552
|
0
|
|
|
|
|
0
|
return floats5($l,$a,$b); |
553
|
|
|
|
|
|
|
} |
554
|
|
|
|
|
|
|
else { # or it is a ref ? |
555
|
0
|
0
|
|
|
|
0
|
my ($h, $s, $v) = RGBtoHSV(@{$name || [0.5, 0.5, 0.5]}); |
|
0
|
|
|
|
|
0
|
|
556
|
0
|
|
|
|
|
0
|
my $a = cos(deg2rad($h)) * $s * 100; |
557
|
0
|
|
|
|
|
0
|
my $b = sin(deg2rad($h)) * $s * 100; |
558
|
0
|
|
|
|
|
0
|
my $l = 100 * $v; |
559
|
0
|
|
|
|
|
0
|
return floats5($l,$a,$b); |
560
|
|
|
|
|
|
|
} |
561
|
|
|
|
|
|
|
} |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
sub unfilter { |
564
|
6
|
|
|
6
|
0
|
14
|
my ($filter, $stream) = @_; |
565
|
|
|
|
|
|
|
|
566
|
6
|
50
|
|
|
|
15
|
if (defined $filter) { |
567
|
|
|
|
|
|
|
# we need to fix filter because it MAY be |
568
|
|
|
|
|
|
|
# an array BUT IT COULD BE only a name |
569
|
6
|
50
|
|
|
|
26
|
if (ref($filter) !~ /Array$/) { |
570
|
0
|
|
|
|
|
0
|
$filter = PDFArray($filter); |
571
|
|
|
|
|
|
|
} |
572
|
6
|
|
|
|
|
12
|
my @filts; |
573
|
6
|
|
|
|
|
11
|
my ($hasflate) = -1; |
574
|
6
|
|
|
|
|
21
|
my ($temp, $i, $temp1); |
575
|
|
|
|
|
|
|
|
576
|
6
|
|
|
|
|
20
|
@filts = map { ("PDF::API2::Basic::PDF::Filter::" . $_->val())->new() } $filter->elements(); |
|
6
|
|
|
|
|
23
|
|
577
|
|
|
|
|
|
|
|
578
|
6
|
|
|
|
|
17
|
foreach my $f (@filts) { |
579
|
6
|
|
|
|
|
22
|
$stream = $f->infilt($stream, 1); |
580
|
|
|
|
|
|
|
} |
581
|
|
|
|
|
|
|
} |
582
|
|
|
|
|
|
|
|
583
|
6
|
|
|
|
|
46
|
return $stream; |
584
|
|
|
|
|
|
|
} |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
sub dofilter { |
587
|
3
|
|
|
3
|
0
|
38
|
my ($filter, $stream) = @_; |
588
|
|
|
|
|
|
|
|
589
|
3
|
50
|
|
|
|
10
|
if (defined $filter) { |
590
|
|
|
|
|
|
|
# we need to fix filter because it MAY be |
591
|
|
|
|
|
|
|
# an array BUT IT COULD BE only a name |
592
|
3
|
50
|
|
|
|
22
|
if (ref($filter) !~ /Array$/) { |
593
|
0
|
|
|
|
|
0
|
$filter = PDFArray($filter); |
594
|
|
|
|
|
|
|
} |
595
|
3
|
|
|
|
|
15
|
my @filts; |
596
|
3
|
|
|
|
|
6
|
my $hasflate = -1; |
597
|
3
|
|
|
|
|
7
|
my ($temp, $i, $temp1); |
598
|
|
|
|
|
|
|
|
599
|
3
|
|
|
|
|
21
|
@filts = map { ("PDF::API2::Basic::PDF::Filter::" . $_->val())->new() } $filter->elements(); |
|
3
|
|
|
|
|
11
|
|
600
|
|
|
|
|
|
|
|
601
|
3
|
|
|
|
|
11
|
foreach my $f (@filts) { |
602
|
3
|
|
|
|
|
25
|
$stream = $f->outfilt($stream, 1); |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
} |
605
|
|
|
|
|
|
|
|
606
|
3
|
|
|
|
|
18
|
return $stream; |
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
sub nameByUni { |
610
|
512
|
|
|
512
|
0
|
504
|
my $e = shift(); |
611
|
512
|
|
66
|
|
|
1494
|
return $u2n{$e} || sprintf('uni%04X', $e); |
612
|
|
|
|
|
|
|
} |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
sub uniByName { |
615
|
13365
|
|
|
13365
|
0
|
17407
|
my $e = shift(); |
616
|
13365
|
50
|
|
|
|
22028
|
if ($e =~ /^uni([0-9A-F]{4})$/) { |
617
|
0
|
|
|
|
|
0
|
return hex($1); |
618
|
|
|
|
|
|
|
} |
619
|
13365
|
|
100
|
|
|
45582
|
return $n2u{$e} || undef; |
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
sub initNameTable { |
623
|
0
|
|
|
0
|
0
|
0
|
%u2n = %{$PDF::API2::Resource::Glyphs::u2n}; |
|
0
|
|
|
|
|
0
|
|
624
|
0
|
|
|
|
|
0
|
%n2u = %{$PDF::API2::Resource::Glyphs::n2u}; |
|
0
|
|
|
|
|
0
|
|
625
|
0
|
|
|
|
|
0
|
$pua = 0xE000; |
626
|
0
|
|
|
|
|
0
|
return; |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
sub defineName { |
630
|
0
|
|
|
0
|
0
|
0
|
my $name = shift(); |
631
|
0
|
0
|
|
|
|
0
|
return $n2u{$name} if defined $n2u{$name}; |
632
|
|
|
|
|
|
|
|
633
|
0
|
|
|
|
|
0
|
$pua++ while defined $u2n{$pua}; |
634
|
|
|
|
|
|
|
|
635
|
0
|
|
|
|
|
0
|
$u2n{$pua} = $name; |
636
|
0
|
|
|
|
|
0
|
$n2u{$name} = $pua; |
637
|
|
|
|
|
|
|
|
638
|
0
|
|
|
|
|
0
|
return $pua; |
639
|
|
|
|
|
|
|
} |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
sub page_size { |
642
|
95
|
|
|
95
|
0
|
163
|
my ($x1, $y1, $x2, $y2) = @_; |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
# full bbox |
645
|
95
|
100
|
|
|
|
279
|
if (defined $x2) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
646
|
48
|
|
|
|
|
117
|
return ($x1, $y1, $x2, $y2); |
647
|
|
|
|
|
|
|
} |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
# half bbox |
650
|
|
|
|
|
|
|
elsif (defined $y1) { |
651
|
13
|
|
|
|
|
48
|
return (0, 0, $x1, $y1); |
652
|
|
|
|
|
|
|
} |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
# textual spec. |
655
|
|
|
|
|
|
|
elsif (defined $PaperSizes{lc $x1}) { |
656
|
33
|
|
|
|
|
57
|
return (0, 0, @{$PaperSizes{lc $x1}}); |
|
33
|
|
|
|
|
136
|
|
657
|
|
|
|
|
|
|
} |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
# single quadratic |
660
|
|
|
|
|
|
|
elsif ($x1 =~ /^[\d\.]+$/) { |
661
|
0
|
|
|
|
|
0
|
return(0, 0, $x1, $x1); |
662
|
|
|
|
|
|
|
} |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
# pdf default. |
665
|
|
|
|
|
|
|
else { |
666
|
1
|
|
|
|
|
4
|
return (0, 0, 612, 792); |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
} |
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
sub getPaperSizes { |
671
|
0
|
|
|
0
|
0
|
|
my %sizes = (); |
672
|
0
|
|
|
|
|
|
foreach my $type (keys %PaperSizes) { |
673
|
0
|
|
|
|
|
|
$sizes{$type} = [@{$PaperSizes{$type}}]; |
|
0
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
} |
675
|
0
|
|
|
|
|
|
return %sizes; |
676
|
|
|
|
|
|
|
} |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
1; |