line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=======================================================================
|
2
|
|
|
|
|
|
|
# ____ ____ _____ _ ____ ___ ____
|
3
|
|
|
|
|
|
|
# | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
|
4
|
|
|
|
|
|
|
# | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
|
5
|
|
|
|
|
|
|
# | __/| |_| | _| _ _ / ___ \| __/| | / __/
|
6
|
|
|
|
|
|
|
# |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
|
7
|
|
|
|
|
|
|
#
|
8
|
|
|
|
|
|
|
# A Perl Module Chain to faciliate the Creation and Modification
|
9
|
|
|
|
|
|
|
# of High-Quality "Portable Document Format (PDF)" Files.
|
10
|
|
|
|
|
|
|
#
|
11
|
|
|
|
|
|
|
# Copyright 1999-2005 Alfred Reibenschuh .
|
12
|
|
|
|
|
|
|
#
|
13
|
|
|
|
|
|
|
#=======================================================================
|
14
|
|
|
|
|
|
|
#
|
15
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or
|
16
|
|
|
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
17
|
|
|
|
|
|
|
# License as published by the Free Software Foundation; either
|
18
|
|
|
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
19
|
|
|
|
|
|
|
#
|
20
|
|
|
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
21
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
23
|
|
|
|
|
|
|
# Lesser General Public License for more details.
|
24
|
|
|
|
|
|
|
#
|
25
|
|
|
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
26
|
|
|
|
|
|
|
# License along with this library; if not, write to the
|
27
|
|
|
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
28
|
|
|
|
|
|
|
# Boston, MA 02111-1307, USA.
|
29
|
|
|
|
|
|
|
#
|
30
|
|
|
|
|
|
|
# $Id: Util.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
|
31
|
|
|
|
|
|
|
#
|
32
|
|
|
|
|
|
|
#=======================================================================
|
33
|
|
|
|
|
|
|
package PDF::API3::Compat::API2::Util;
|
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
5
|
no warnings qw[ recursion uninitialized ];
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
BEGIN {
|
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
6
|
use utf8;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
40
|
1
|
|
|
1
|
|
1039
|
use Encode qw(:all);
|
|
1
|
|
|
|
|
20431
|
|
|
1
|
|
|
|
|
449
|
|
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
169
|
use vars qw(
|
43
|
|
|
|
|
|
|
$VERSION
|
44
|
|
|
|
|
|
|
@ISA
|
45
|
|
|
|
|
|
|
@EXPORT
|
46
|
|
|
|
|
|
|
@EXPORT_OK
|
47
|
|
|
|
|
|
|
%colors
|
48
|
|
|
|
|
|
|
$key_var
|
49
|
|
|
|
|
|
|
$key_var2
|
50
|
|
|
|
|
|
|
%u2n
|
51
|
|
|
|
|
|
|
%n2u
|
52
|
|
|
|
|
|
|
%u2n_o
|
53
|
|
|
|
|
|
|
%n2u_o
|
54
|
|
|
|
|
|
|
$pua
|
55
|
|
|
|
|
|
|
$uuu
|
56
|
|
|
|
|
|
|
%PaperSizes
|
57
|
1
|
|
|
1
|
|
12
|
);
|
|
1
|
|
|
|
|
2
|
|
58
|
1
|
|
|
1
|
|
11953
|
use Math::Trig;
|
|
1
|
|
|
|
|
33042
|
|
|
1
|
|
|
|
|
287
|
|
59
|
1
|
|
|
1
|
|
14
|
use List::Util qw(min max);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
127
|
|
60
|
1
|
|
|
1
|
|
7
|
use PDF::API3::Compat::API2::Basic::PDF::Utils;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
132
|
|
61
|
1
|
|
|
1
|
|
7
|
use PDF::API3::Compat::API2::Basic::PDF::Filter;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
1
|
|
1319
|
use POSIX qw( HUGE_VAL floor );
|
|
1
|
|
|
|
|
8417
|
|
|
1
|
|
|
|
|
8
|
|
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
1
|
|
1288
|
use Exporter;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1531
|
|
66
|
1
|
|
|
1
|
|
31
|
@ISA = qw(Exporter);
|
67
|
1
|
|
|
|
|
9
|
@EXPORT = qw(
|
68
|
|
|
|
|
|
|
pdfkey
|
69
|
|
|
|
|
|
|
pdfkey2
|
70
|
|
|
|
|
|
|
float floats floats5 intg intgs
|
71
|
|
|
|
|
|
|
mMin mMax
|
72
|
|
|
|
|
|
|
HSVtoRGB RGBtoHSV HSLtoRGB RGBtoHSL RGBtoLUM
|
73
|
|
|
|
|
|
|
namecolor namecolor_cmyk namecolor_lab optInvColor defineColor
|
74
|
|
|
|
|
|
|
dofilter unfilter
|
75
|
|
|
|
|
|
|
nameByUni uniByName initNameTable defineName
|
76
|
|
|
|
|
|
|
page_size
|
77
|
|
|
|
|
|
|
getPaperSizes
|
78
|
|
|
|
|
|
|
);
|
79
|
1
|
|
|
|
|
8
|
@EXPORT_OK = qw(
|
80
|
|
|
|
|
|
|
pdfkey
|
81
|
|
|
|
|
|
|
pdfkey2
|
82
|
|
|
|
|
|
|
digest digestx digest16 digest32
|
83
|
|
|
|
|
|
|
float floats floats5 intg intgs
|
84
|
|
|
|
|
|
|
mMin mMax
|
85
|
|
|
|
|
|
|
cRGB cRGB8 RGBasCMYK
|
86
|
|
|
|
|
|
|
HSVtoRGB RGBtoHSV HSLtoRGB RGBtoHSL RGBtoLUM
|
87
|
|
|
|
|
|
|
namecolor namecolor_cmyk namecolor_lab optInvColor defineColor
|
88
|
|
|
|
|
|
|
dofilter unfilter
|
89
|
|
|
|
|
|
|
nameByUni uniByName initNameTable defineName
|
90
|
|
|
|
|
|
|
page_size
|
91
|
|
|
|
|
|
|
);
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
4
|
%PaperSizes=();
|
95
|
1
|
|
|
|
|
3
|
foreach my $dir (@INC) {
|
96
|
2
|
100
|
|
|
|
217
|
if(-f "$dir/PDF/API3/Compat/API2/Resource/unipaper.txt")
|
97
|
|
|
|
|
|
|
{
|
98
|
1
|
|
|
|
|
4
|
my ($fh,$line);
|
99
|
1
|
|
|
|
|
69
|
open($fh,"$dir/PDF/API3/Compat/API2/Resource/unipaper.txt");
|
100
|
1
|
|
|
|
|
30
|
while($line=<$fh>)
|
101
|
|
|
|
|
|
|
{
|
102
|
26
|
100
|
|
|
|
64
|
next if($line=~m|^#|);
|
103
|
25
|
|
|
|
|
27
|
chomp($line);
|
104
|
25
|
|
|
|
|
140
|
my ($name,$x,$y)=split(/\s+;\s+/,$line);
|
105
|
25
|
|
|
|
|
143
|
$PaperSizes{lc $name}=[$x,$y];
|
106
|
|
|
|
|
|
|
}
|
107
|
1
|
|
|
|
|
15
|
close($fh);
|
108
|
1
|
|
|
|
|
6
|
last;
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
}
|
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
1
|
|
6
|
no warnings qw[ recursion uninitialized ];
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
856
|
|
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
19
|
( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:16:00 $
|
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
2
|
$key_var='CBA';
|
117
|
1
|
|
|
|
|
1
|
$key_var2=0;
|
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
3
|
$pua=0xE000;
|
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
4
|
%u2n_o=();
|
122
|
1
|
|
|
|
|
2
|
%n2u_o=();
|
123
|
|
|
|
|
|
|
|
124
|
1
|
|
|
|
|
4
|
$uuu={g=>{},u=>{}};
|
125
|
1
|
|
|
|
|
3
|
foreach my $dir (@INC) {
|
126
|
2
|
100
|
|
|
|
49
|
if(-f "$dir/PDF/API3/Compat/API2/Resource/uniglyph.txt")
|
127
|
|
|
|
|
|
|
{
|
128
|
1
|
|
|
|
|
3
|
my ($fh,$line);
|
129
|
1
|
|
|
|
|
44
|
open($fh,"$dir/PDF/API3/Compat/API2/Resource/uniglyph.txt");
|
130
|
1
|
|
|
|
|
34
|
while($line=<$fh>)
|
131
|
|
|
|
|
|
|
{
|
132
|
5509
|
100
|
|
|
|
11994
|
next if($line=~m|^#|);
|
133
|
5508
|
|
|
|
|
6224
|
chomp($line);
|
134
|
5508
|
|
|
|
|
34051
|
$line=~s|\s+\#.+$||go;
|
135
|
5508
|
|
|
|
|
23990
|
my ($uni,$name,$prio)=split(/\s+;\s+/,$line);
|
136
|
5508
|
|
|
|
|
7342
|
$uni=hex($uni);
|
137
|
5508
|
|
100
|
|
|
26236
|
$uuu->{u}->{$uni}||=[];
|
138
|
5508
|
|
100
|
|
|
42917
|
$uuu->{g}->{$name}||=[];
|
139
|
5508
|
|
|
|
|
6119
|
push @{$uuu->{u}->{$uni}},{uni=>$uni,name=>$name,prio=>$prio};
|
|
5508
|
|
|
|
|
24241
|
|
140
|
5508
|
|
|
|
|
6174
|
push @{$uuu->{g}->{$name}},{uni=>$uni,name=>$name,prio=>$prio};
|
|
5508
|
|
|
|
|
42487
|
|
141
|
|
|
|
|
|
|
}
|
142
|
1
|
|
|
|
|
41
|
close($fh);
|
143
|
1
|
|
|
|
|
10
|
last;
|
144
|
|
|
|
|
|
|
}
|
145
|
|
|
|
|
|
|
}
|
146
|
1
|
|
|
|
|
3
|
foreach my $k (sort {$a<=>$b} keys %{$uuu->{u}})
|
|
46462
|
|
|
|
|
48895
|
|
|
1
|
|
|
|
|
1932
|
|
147
|
|
|
|
|
|
|
{
|
148
|
4291
|
|
|
|
|
14158
|
$u2n_o{$k}=$uuu->{u}->{$k}->[0]->{name};
|
149
|
|
|
|
|
|
|
}
|
150
|
1
|
|
|
|
|
378
|
foreach my $k (keys %{$uuu->{g}})
|
|
1
|
|
|
|
|
2462
|
|
151
|
|
|
|
|
|
|
{
|
152
|
5422
|
|
|
|
|
5817
|
my($r)=sort {$a->{prio}<=>$b->{prio}} @{$uuu->{g}->{$k}};
|
|
95
|
|
|
|
|
339
|
|
|
5422
|
|
|
|
|
24755
|
|
153
|
5422
|
|
|
|
|
15800
|
$n2u_o{$k}=$r->{uni};
|
154
|
|
|
|
|
|
|
}
|
155
|
1
|
|
|
|
|
1121
|
$uuu=undef;
|
156
|
|
|
|
|
|
|
|
157
|
1
|
|
|
|
|
25531
|
%u2n=%u2n_o;
|
158
|
1
|
|
|
|
|
5665
|
%n2u=%n2u_o;
|
159
|
|
|
|
|
|
|
|
160
|
1
|
|
|
|
|
525
|
%colors=();
|
161
|
1
|
|
|
|
|
6
|
foreach my $dir (@INC) {
|
162
|
2
|
100
|
|
|
|
105
|
if(-f "$dir/PDF/API3/Compat/API2/Resource/unicolor.txt")
|
163
|
|
|
|
|
|
|
{
|
164
|
1
|
|
|
|
|
3
|
my ($fh,$line);
|
165
|
1
|
|
|
|
|
72
|
open($fh,"$dir/PDF/API3/Compat/API2/Resource/unicolor.txt");
|
166
|
1
|
|
|
|
|
26
|
while($line=<$fh>)
|
167
|
|
|
|
|
|
|
{
|
168
|
683
|
100
|
|
|
|
1319
|
next if($line=~m|^#|);
|
169
|
682
|
|
|
|
|
718
|
chomp($line);
|
170
|
682
|
|
|
|
|
2298
|
my ($name,$val)=split(/\s+;\s+/,$line);
|
171
|
682
|
|
|
|
|
2653
|
$colors{lc $name}=$val;
|
172
|
|
|
|
|
|
|
}
|
173
|
1
|
|
|
|
|
47
|
close($fh);
|
174
|
1
|
|
|
|
|
5773
|
last;
|
175
|
|
|
|
|
|
|
}
|
176
|
|
|
|
|
|
|
}
|
177
|
|
|
|
|
|
|
}
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub pdfkey {
|
180
|
0
|
|
|
0
|
0
|
|
return($PDF::API3::Compat::API2::Util::key_var++);
|
181
|
|
|
|
|
|
|
}
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub pdfkey2 {
|
184
|
0
|
|
|
0
|
0
|
|
return($PDF::API3::Compat::API2::Util::key_var.($PDF::API3::Compat::API2::Util::key_var2++));
|
185
|
|
|
|
|
|
|
}
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub digestx {
|
188
|
0
|
|
|
0
|
0
|
|
my $len=shift @_;
|
189
|
0
|
|
|
|
|
|
my $mask=$len-1;
|
190
|
0
|
|
|
|
|
|
my $ddata=join('',@_);
|
191
|
0
|
|
|
|
|
|
my $mdkey='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789gT';
|
192
|
0
|
|
|
|
|
|
my $xdata="0" x $len;
|
193
|
0
|
|
|
|
|
|
my $off=0;
|
194
|
0
|
|
|
|
|
|
my $set;
|
195
|
0
|
|
|
|
|
|
foreach $set (0..(length($ddata)<<1)) {
|
196
|
0
|
|
|
|
|
|
$off+=vec($ddata,$set,4);
|
197
|
0
|
|
|
|
|
|
$off+=vec($xdata,($set & $mask),8);
|
198
|
0
|
|
|
|
|
|
vec($xdata,($set & ($mask<<1 |1)),4)=vec($mdkey,($off & 0x7f),4);
|
199
|
|
|
|
|
|
|
}
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# foreach $set (0..$mask) {
|
202
|
|
|
|
|
|
|
# vec($xdata,$set,8)=(vec($xdata,$set,8) & 0x7f) | 0x40;
|
203
|
|
|
|
|
|
|
# }
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# $off=0;
|
206
|
|
|
|
|
|
|
# foreach $set (0..$mask) {
|
207
|
|
|
|
|
|
|
# $off+=vec($xdata,$set,8);
|
208
|
|
|
|
|
|
|
# vec($xdata,$set,8)=vec($mdkey,($off & 0x3f),8);
|
209
|
|
|
|
|
|
|
# }
|
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
return($xdata);
|
212
|
|
|
|
|
|
|
}
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub digest {
|
215
|
0
|
|
|
0
|
0
|
|
return(digestx(32,@_));
|
216
|
|
|
|
|
|
|
}
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub digest16 {
|
219
|
0
|
|
|
0
|
0
|
|
return(digestx(16,@_));
|
220
|
|
|
|
|
|
|
}
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub digest32 {
|
223
|
0
|
|
|
0
|
0
|
|
return(digestx(32,@_));
|
224
|
|
|
|
|
|
|
}
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub xlog10 {
|
227
|
0
|
|
|
0
|
0
|
|
my $n = shift;
|
228
|
0
|
0
|
|
|
|
|
if($n) {
|
229
|
0
|
|
|
|
|
|
return log(abs($n))/log(10);
|
230
|
0
|
|
|
|
|
|
} else { return 0; }
|
231
|
|
|
|
|
|
|
}
|
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub float {
|
234
|
0
|
|
|
0
|
0
|
|
my $f=shift @_;
|
235
|
0
|
|
0
|
|
|
|
my $mxd=shift @_||4;
|
236
|
0
|
0
|
|
|
|
|
$f=0 if(abs($f)<0.0000000000000001);
|
237
|
0
|
|
|
|
|
|
my $ad=floor(xlog10($f)-$mxd);
|
238
|
0
|
0
|
|
|
|
|
if(abs($f-int($f)) < (10**(-$mxd))) {
|
|
|
0
|
|
|
|
|
|
239
|
|
|
|
|
|
|
# just in case we have an integer
|
240
|
0
|
|
|
|
|
|
return sprintf('%i',$f);
|
241
|
|
|
|
|
|
|
} elsif($ad>0){
|
242
|
0
|
|
|
|
|
|
return sprintf('%f',$f);
|
243
|
|
|
|
|
|
|
} else {
|
244
|
0
|
|
|
|
|
|
return sprintf('%.'.abs($ad).'f',$f);
|
245
|
|
|
|
|
|
|
}
|
246
|
|
|
|
|
|
|
}
|
247
|
0
|
|
|
0
|
0
|
|
sub floats { return map { float($_); } @_; }
|
|
0
|
|
|
|
|
|
|
248
|
0
|
|
|
0
|
0
|
|
sub floats5 { return map { float($_,5); } @_; }
|
|
0
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub intg {
|
252
|
0
|
|
|
0
|
0
|
|
my $f=shift @_;
|
253
|
0
|
|
|
|
|
|
return sprintf('%i',$f);
|
254
|
|
|
|
|
|
|
}
|
255
|
0
|
|
|
0
|
0
|
|
sub intgs { return map { intg($_); } @_; }
|
|
0
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub mMin {
|
258
|
0
|
|
|
0
|
0
|
|
my $n=HUGE_VAL;
|
259
|
0
|
0
|
|
|
|
|
map { $n=($n>$_) ? $_ : $n } @_;
|
|
0
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
|
return($n);
|
261
|
|
|
|
|
|
|
}
|
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub mMax {
|
264
|
0
|
|
|
0
|
0
|
|
my $n=-(HUGE_VAL);
|
265
|
0
|
0
|
|
|
|
|
map { $n=($n<$_) ? $_ : $n } @_;
|
|
0
|
|
|
|
|
|
|
266
|
0
|
|
|
|
|
|
return($n);
|
267
|
|
|
|
|
|
|
}
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub cRGB {
|
270
|
0
|
|
|
0
|
0
|
|
my @cmy=(map { 1-$_ } @_);
|
|
0
|
|
|
|
|
|
|
271
|
0
|
|
|
|
|
|
my $k=mMin(@cmy);
|
272
|
0
|
|
|
|
|
|
return((map { $_-$k } @cmy),$k);
|
|
0
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
}
|
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
sub cRGB8 {
|
276
|
0
|
|
|
0
|
0
|
|
return cRGB(map { $_/255 } @_);
|
|
0
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
}
|
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
sub RGBtoLUM {
|
280
|
0
|
|
|
0
|
0
|
|
my ($r,$g,$b)=@_;
|
281
|
0
|
|
|
|
|
|
return($r*0.299+$g*0.587+$b*0.114);
|
282
|
|
|
|
|
|
|
}
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub RGBasCMYK {
|
285
|
0
|
|
|
0
|
0
|
|
my @rgb=@_;
|
286
|
0
|
|
|
|
|
|
my @cmy=(map { 1-$_ } @rgb);
|
|
0
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
|
my $k=mMin(@cmy)*0.44;
|
288
|
0
|
|
|
|
|
|
return((map { $_-$k } @cmy),$k);
|
|
0
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
}
|
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
sub HSVtoRGB {
|
292
|
0
|
|
|
0
|
0
|
|
my ($h,$s,$v)=@_;
|
293
|
0
|
|
|
|
|
|
my ($r,$g,$b,$i,$f,$p,$q,$t);
|
294
|
|
|
|
|
|
|
|
295
|
0
|
0
|
|
|
|
|
if( $s == 0 ) {
|
296
|
|
|
|
|
|
|
## achromatic (grey)
|
297
|
0
|
|
|
|
|
|
return ($v,$v,$v);
|
298
|
|
|
|
|
|
|
}
|
299
|
|
|
|
|
|
|
|
300
|
0
|
|
|
|
|
|
$h %= 360;
|
301
|
0
|
|
|
|
|
|
$h /= 60; ## sector 0 to 5
|
302
|
0
|
|
|
|
|
|
$i = POSIX::floor( $h );
|
303
|
0
|
|
|
|
|
|
$f = $h - $i; ## factorial part of h
|
304
|
0
|
|
|
|
|
|
$p = $v * ( 1 - $s );
|
305
|
0
|
|
|
|
|
|
$q = $v * ( 1 - $s * $f );
|
306
|
0
|
|
|
|
|
|
$t = $v * ( 1 - $s * ( 1 - $f ) );
|
307
|
|
|
|
|
|
|
|
308
|
0
|
0
|
|
|
|
|
if($i<1) {
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
309
|
0
|
|
|
|
|
|
$r = $v;
|
310
|
0
|
|
|
|
|
|
$g = $t;
|
311
|
0
|
|
|
|
|
|
$b = $p;
|
312
|
|
|
|
|
|
|
} elsif($i<2){
|
313
|
0
|
|
|
|
|
|
$r = $q;
|
314
|
0
|
|
|
|
|
|
$g = $v;
|
315
|
0
|
|
|
|
|
|
$b = $p;
|
316
|
|
|
|
|
|
|
} elsif($i<3){
|
317
|
0
|
|
|
|
|
|
$r = $p;
|
318
|
0
|
|
|
|
|
|
$g = $v;
|
319
|
0
|
|
|
|
|
|
$b = $t;
|
320
|
|
|
|
|
|
|
} elsif($i<4){
|
321
|
0
|
|
|
|
|
|
$r = $p;
|
322
|
0
|
|
|
|
|
|
$g = $q;
|
323
|
0
|
|
|
|
|
|
$b = $v;
|
324
|
|
|
|
|
|
|
} elsif($i<5){
|
325
|
0
|
|
|
|
|
|
$r = $t;
|
326
|
0
|
|
|
|
|
|
$g = $p;
|
327
|
0
|
|
|
|
|
|
$b = $v;
|
328
|
|
|
|
|
|
|
} else {
|
329
|
0
|
|
|
|
|
|
$r = $v;
|
330
|
0
|
|
|
|
|
|
$g = $p;
|
331
|
0
|
|
|
|
|
|
$b = $q;
|
332
|
|
|
|
|
|
|
}
|
333
|
0
|
|
|
|
|
|
return ($r,$g,$b);
|
334
|
|
|
|
|
|
|
}
|
335
|
|
|
|
|
|
|
sub _HSVtoRGB { # test
|
336
|
0
|
|
|
0
|
|
|
my ($h,$s,$v)=@_;
|
337
|
0
|
|
|
|
|
|
my ($r,$g,$b,$i,$f,$p,$q,$t);
|
338
|
|
|
|
|
|
|
|
339
|
0
|
0
|
|
|
|
|
if( $s == 0 ) {
|
340
|
|
|
|
|
|
|
## achromatic (grey)
|
341
|
0
|
|
|
|
|
|
return ($v,$v,$v);
|
342
|
|
|
|
|
|
|
}
|
343
|
|
|
|
|
|
|
|
344
|
0
|
|
|
|
|
|
$h %= 360;
|
345
|
|
|
|
|
|
|
|
346
|
0
|
|
|
|
|
|
$r = 2*cos(deg2rad($h));
|
347
|
0
|
|
|
|
|
|
$g = 2*cos(deg2rad($h+120));
|
348
|
0
|
|
|
|
|
|
$b = 2*cos(deg2rad($h+240));
|
349
|
|
|
|
|
|
|
|
350
|
0
|
|
|
|
|
|
$p = max($r,$g,$b);
|
351
|
0
|
|
|
|
|
|
$q = min($r,$g,$b);
|
352
|
0
|
0
|
|
|
|
|
($p,$q) = map { ($_<0 ? 0 : ($_>1 ? 1 : $_)) } ($p,$q);
|
|
0
|
0
|
|
|
|
|
|
353
|
0
|
|
|
|
|
|
$f = $p - $q;
|
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
#if($p>=$v) {
|
356
|
|
|
|
|
|
|
# ($r,$g,$b) = map { $_*$v/$p } ($r,$g,$b);
|
357
|
|
|
|
|
|
|
#} else {
|
358
|
|
|
|
|
|
|
# ($r,$g,$b) = map { $_*$p/$v } ($r,$g,$b);
|
359
|
|
|
|
|
|
|
#}
|
360
|
|
|
|
|
|
|
#
|
361
|
|
|
|
|
|
|
#if($f>=$s) {
|
362
|
|
|
|
|
|
|
# ($r,$g,$b) = map { (($_-$q/2)*$f/$s)+$q/2 } ($r,$g,$b);
|
363
|
|
|
|
|
|
|
#} else {
|
364
|
|
|
|
|
|
|
# ($r,$g,$b) = map { (($_-$q/2)*$s/$f)+$q/2 } ($r,$g,$b);
|
365
|
|
|
|
|
|
|
#}
|
366
|
|
|
|
|
|
|
|
367
|
0
|
0
|
|
|
|
|
($r,$g,$b) = map { ($_<0 ? 0 : ($_>1 ? 1 : $_)) } ($r,$g,$b);
|
|
0
|
0
|
|
|
|
|
|
368
|
|
|
|
|
|
|
|
369
|
0
|
|
|
|
|
|
return ($r,$g,$b);
|
370
|
|
|
|
|
|
|
}
|
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
sub RGBquant ($$$) {
|
373
|
0
|
|
|
0
|
0
|
|
my($q1,$q2,$h)=@_;
|
374
|
0
|
|
|
|
|
|
while($h<0){$h+=360;}
|
|
0
|
|
|
|
|
|
|
375
|
0
|
|
|
|
|
|
$h%=360;
|
376
|
0
|
0
|
|
|
|
|
if ($h<60) {
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
377
|
0
|
|
|
|
|
|
return($q1+(($q2-$q1)*$h/60));
|
378
|
|
|
|
|
|
|
} elsif ($h<180) {
|
379
|
0
|
|
|
|
|
|
return($q2);
|
380
|
|
|
|
|
|
|
} elsif ($h<240) {
|
381
|
0
|
|
|
|
|
|
return($q1+(($q2-$q1)*(240-$h)/60));
|
382
|
|
|
|
|
|
|
} else {
|
383
|
0
|
|
|
|
|
|
return($q1);
|
384
|
|
|
|
|
|
|
}
|
385
|
|
|
|
|
|
|
}
|
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
sub RGBtoHSV {
|
388
|
0
|
|
|
0
|
0
|
|
my ($r,$g,$b)=@_;
|
389
|
0
|
|
|
|
|
|
my ($h,$s,$v,$min,$max,$delta);
|
390
|
|
|
|
|
|
|
|
391
|
0
|
|
|
|
|
|
$min= mMin($r,$g,$b);
|
392
|
0
|
|
|
|
|
|
$max= mMax($r,$g,$b);
|
393
|
|
|
|
|
|
|
|
394
|
0
|
|
|
|
|
|
$v = $max;
|
395
|
|
|
|
|
|
|
|
396
|
0
|
|
|
|
|
|
$delta = $max - $min;
|
397
|
|
|
|
|
|
|
|
398
|
0
|
0
|
|
|
|
|
if( $delta > 0.000000001 ) {
|
399
|
0
|
|
|
|
|
|
$s = $delta / $max;
|
400
|
|
|
|
|
|
|
} else {
|
401
|
0
|
|
|
|
|
|
$s = 0;
|
402
|
0
|
|
|
|
|
|
$h = 0;
|
403
|
0
|
|
|
|
|
|
return($h,$s,$v);
|
404
|
|
|
|
|
|
|
}
|
405
|
|
|
|
|
|
|
|
406
|
0
|
0
|
|
|
|
|
if( $r == $max ) {
|
|
|
0
|
|
|
|
|
|
407
|
0
|
|
|
|
|
|
$h = ( $g - $b ) / $delta;
|
408
|
|
|
|
|
|
|
} elsif( $g == $max ) {
|
409
|
0
|
|
|
|
|
|
$h = 2 + ( $b - $r ) / $delta;
|
410
|
|
|
|
|
|
|
} else {
|
411
|
0
|
|
|
|
|
|
$h = 4 + ( $r - $g ) / $delta;
|
412
|
|
|
|
|
|
|
}
|
413
|
0
|
|
|
|
|
|
$h *= 60;
|
414
|
0
|
0
|
|
|
|
|
if( $h < 0 ) {$h += 360;}
|
|
0
|
|
|
|
|
|
|
415
|
0
|
|
|
|
|
|
return($h,$s,$v);
|
416
|
|
|
|
|
|
|
}
|
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
sub RGBtoHSL {
|
419
|
0
|
|
|
0
|
0
|
|
my ($r,$g,$b)=@_;
|
420
|
0
|
|
|
|
|
|
my ($h,$s,$v,$l,$min,$max,$delta);
|
421
|
|
|
|
|
|
|
|
422
|
0
|
|
|
|
|
|
$min= mMin($r,$g,$b);
|
423
|
0
|
|
|
|
|
|
$max= mMax($r,$g,$b);
|
424
|
0
|
|
|
|
|
|
($h,$s,$v)=RGBtoHSV($r,$g,$b);
|
425
|
0
|
|
|
|
|
|
$l=($max+$min)/2.0;
|
426
|
0
|
|
|
|
|
|
$delta = $max - $min;
|
427
|
0
|
0
|
|
|
|
|
if($delta<0.00000000001){
|
428
|
0
|
|
|
|
|
|
return(0,0,$l);
|
429
|
|
|
|
|
|
|
} else {
|
430
|
0
|
0
|
|
|
|
|
if($l<=0.5){
|
431
|
0
|
|
|
|
|
|
$s=$delta/($max+$min);
|
432
|
|
|
|
|
|
|
} else {
|
433
|
0
|
|
|
|
|
|
$s=$delta/(2-$max-$min);
|
434
|
|
|
|
|
|
|
}
|
435
|
|
|
|
|
|
|
}
|
436
|
0
|
|
|
|
|
|
return($h,$s,$l);
|
437
|
|
|
|
|
|
|
}
|
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
sub HSLtoRGB {
|
440
|
0
|
|
|
0
|
0
|
|
my($h,$s,$l,$r,$g,$b,$p1,$p2)=@_;
|
441
|
0
|
0
|
|
|
|
|
if($l<=0.5){
|
442
|
0
|
|
|
|
|
|
$p2=$l*(1+$s);
|
443
|
|
|
|
|
|
|
} else {
|
444
|
0
|
|
|
|
|
|
$p2=$l+$s-($l*$s);
|
445
|
|
|
|
|
|
|
}
|
446
|
0
|
|
|
|
|
|
$p1=2*$l-$p2;
|
447
|
0
|
0
|
|
|
|
|
if($s<0.0000000000001){
|
448
|
0
|
|
|
|
|
|
$r=$l; $g=$l; $b=$l;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
} else {
|
450
|
0
|
|
|
|
|
|
$r=RGBquant($p1,$p2,$h+120);
|
451
|
0
|
|
|
|
|
|
$g=RGBquant($p1,$p2,$h);
|
452
|
0
|
|
|
|
|
|
$b=RGBquant($p1,$p2,$h-120);
|
453
|
|
|
|
|
|
|
}
|
454
|
0
|
|
|
|
|
|
return($r,$g,$b);
|
455
|
|
|
|
|
|
|
}
|
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
sub optInvColor {
|
458
|
0
|
|
|
0
|
0
|
|
my ($r,$g,$b) = @_;
|
459
|
|
|
|
|
|
|
|
460
|
0
|
|
|
|
|
|
my $ab = (0.2*$r) + (0.7*$g) + (0.1*$b);
|
461
|
|
|
|
|
|
|
|
462
|
0
|
0
|
|
|
|
|
if($ab > 0.45) {
|
463
|
0
|
|
|
|
|
|
return(0,0,0);
|
464
|
|
|
|
|
|
|
} else {
|
465
|
0
|
|
|
|
|
|
return(1,1,1);
|
466
|
|
|
|
|
|
|
}
|
467
|
|
|
|
|
|
|
}
|
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
sub defineColor {
|
470
|
0
|
|
|
0
|
0
|
|
my ($name,$mx,$r,$g,$b)=@_;
|
471
|
0
|
|
0
|
|
|
|
$colors{$name}||=[ map {$_/$mx} ($r,$g,$b) ];
|
|
0
|
|
|
|
|
|
|
472
|
0
|
|
|
|
|
|
return($colors{$name});
|
473
|
|
|
|
|
|
|
}
|
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
sub rgbHexValues {
|
476
|
0
|
|
|
0
|
0
|
|
my $name=lc(shift @_);
|
477
|
0
|
|
|
|
|
|
my ($r,$g,$b);
|
478
|
0
|
0
|
|
|
|
|
if(length($name)<5) { # zb. #fa4, #cf0
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
479
|
0
|
|
|
|
|
|
$r=hex(substr($name,1,1))/0xf;
|
480
|
0
|
|
|
|
|
|
$g=hex(substr($name,2,1))/0xf;
|
481
|
0
|
|
|
|
|
|
$b=hex(substr($name,3,1))/0xf;
|
482
|
|
|
|
|
|
|
} elsif(length($name)<8) { # zb. #ffaa44, #ccff00
|
483
|
0
|
|
|
|
|
|
$r=hex(substr($name,1,2))/0xff;
|
484
|
0
|
|
|
|
|
|
$g=hex(substr($name,3,2))/0xff;
|
485
|
0
|
|
|
|
|
|
$b=hex(substr($name,5,2))/0xff;
|
486
|
|
|
|
|
|
|
} elsif(length($name)<11) { # zb. #fffaaa444, #cccfff000
|
487
|
0
|
|
|
|
|
|
$r=hex(substr($name,1,3))/0xfff;
|
488
|
0
|
|
|
|
|
|
$g=hex(substr($name,4,3))/0xfff;
|
489
|
0
|
|
|
|
|
|
$b=hex(substr($name,7,3))/0xfff;
|
490
|
|
|
|
|
|
|
} else { # zb. #ffffaaaa4444, #ccccffff0000
|
491
|
0
|
|
|
|
|
|
$r=hex(substr($name,1,4))/0xffff;
|
492
|
0
|
|
|
|
|
|
$g=hex(substr($name,5,4))/0xffff;
|
493
|
0
|
|
|
|
|
|
$b=hex(substr($name,9,4))/0xffff;
|
494
|
|
|
|
|
|
|
}
|
495
|
0
|
|
|
|
|
|
return($r,$g,$b);
|
496
|
|
|
|
|
|
|
}
|
497
|
|
|
|
|
|
|
sub cmykHexValues {
|
498
|
0
|
|
|
0
|
0
|
|
my $name=lc(shift @_);
|
499
|
0
|
|
|
|
|
|
my ($c,$m,$y,$k);
|
500
|
0
|
0
|
|
|
|
|
if(length($name)<6) { # zb. %cmyk
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
501
|
0
|
|
|
|
|
|
$c=hex(substr($name,1,1))/0xf;
|
502
|
0
|
|
|
|
|
|
$m=hex(substr($name,2,1))/0xf;
|
503
|
0
|
|
|
|
|
|
$y=hex(substr($name,3,1))/0xf;
|
504
|
0
|
|
|
|
|
|
$k=hex(substr($name,4,1))/0xf;
|
505
|
|
|
|
|
|
|
} elsif(length($name)<10) { # zb. %ccmmyykk
|
506
|
0
|
|
|
|
|
|
$c=hex(substr($name,1,2))/0xff;
|
507
|
0
|
|
|
|
|
|
$m=hex(substr($name,3,2))/0xff;
|
508
|
0
|
|
|
|
|
|
$y=hex(substr($name,5,2))/0xff;
|
509
|
0
|
|
|
|
|
|
$k=hex(substr($name,7,2))/0xff;
|
510
|
|
|
|
|
|
|
} elsif(length($name)<14) { # zb. %cccmmmyyykkk
|
511
|
0
|
|
|
|
|
|
$c=hex(substr($name,1,3))/0xfff;
|
512
|
0
|
|
|
|
|
|
$m=hex(substr($name,4,3))/0xfff;
|
513
|
0
|
|
|
|
|
|
$y=hex(substr($name,7,3))/0xfff;
|
514
|
0
|
|
|
|
|
|
$k=hex(substr($name,10,3))/0xfff;
|
515
|
|
|
|
|
|
|
} else { # zb. %ccccmmmmyyyykkkk
|
516
|
0
|
|
|
|
|
|
$c=hex(substr($name,1,4))/0xffff;
|
517
|
0
|
|
|
|
|
|
$m=hex(substr($name,5,4))/0xffff;
|
518
|
0
|
|
|
|
|
|
$y=hex(substr($name,9,4))/0xffff;
|
519
|
0
|
|
|
|
|
|
$k=hex(substr($name,13,4))/0xffff;
|
520
|
|
|
|
|
|
|
}
|
521
|
0
|
|
|
|
|
|
return($c,$m,$y,$k);
|
522
|
|
|
|
|
|
|
}
|
523
|
|
|
|
|
|
|
sub hsvHexValues {
|
524
|
0
|
|
|
0
|
0
|
|
my $name=lc(shift @_);
|
525
|
0
|
|
|
|
|
|
my ($h,$s,$v);
|
526
|
0
|
0
|
|
|
|
|
if(length($name)<5) {
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
527
|
0
|
|
|
|
|
|
$h=360*hex(substr($name,1,1))/0x10;
|
528
|
0
|
|
|
|
|
|
$s=hex(substr($name,2,1))/0xf;
|
529
|
0
|
|
|
|
|
|
$v=hex(substr($name,3,1))/0xf;
|
530
|
|
|
|
|
|
|
} elsif(length($name)<8) {
|
531
|
0
|
|
|
|
|
|
$h=360*hex(substr($name,1,2))/0x100;
|
532
|
0
|
|
|
|
|
|
$s=hex(substr($name,3,2))/0xff;
|
533
|
0
|
|
|
|
|
|
$v=hex(substr($name,5,2))/0xff;
|
534
|
|
|
|
|
|
|
} elsif(length($name)<11) {
|
535
|
0
|
|
|
|
|
|
$h=360*hex(substr($name,1,3))/0x1000;
|
536
|
0
|
|
|
|
|
|
$s=hex(substr($name,4,3))/0xfff;
|
537
|
0
|
|
|
|
|
|
$v=hex(substr($name,7,3))/0xfff;
|
538
|
|
|
|
|
|
|
} else {
|
539
|
0
|
|
|
|
|
|
$h=360*hex(substr($name,1,4))/0x10000;
|
540
|
0
|
|
|
|
|
|
$s=hex(substr($name,5,4))/0xffff;
|
541
|
0
|
|
|
|
|
|
$v=hex(substr($name,9,4))/0xffff;
|
542
|
|
|
|
|
|
|
}
|
543
|
0
|
|
|
|
|
|
return($h,$s,$v);
|
544
|
|
|
|
|
|
|
}
|
545
|
|
|
|
|
|
|
sub labHexValues {
|
546
|
0
|
|
|
0
|
0
|
|
my $name=lc(shift @_);
|
547
|
0
|
|
|
|
|
|
my ($l,$a,$b);
|
548
|
0
|
0
|
|
|
|
|
if(length($name)<5) {
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
549
|
0
|
|
|
|
|
|
$l=100*hex(substr($name,1,1))/0xf;
|
550
|
0
|
|
|
|
|
|
$a=(200*hex(substr($name,2,1))/0xf)-100;
|
551
|
0
|
|
|
|
|
|
$b=(200*hex(substr($name,3,1))/0xf)-100;
|
552
|
|
|
|
|
|
|
} elsif(length($name)<8) {
|
553
|
0
|
|
|
|
|
|
$l=100*hex(substr($name,1,2))/0xff;
|
554
|
0
|
|
|
|
|
|
$a=(200*hex(substr($name,3,2))/0xff)-100;
|
555
|
0
|
|
|
|
|
|
$b=(200*hex(substr($name,5,2))/0xff)-100;
|
556
|
|
|
|
|
|
|
} elsif(length($name)<11) {
|
557
|
0
|
|
|
|
|
|
$l=100*hex(substr($name,1,3))/0xfff;
|
558
|
0
|
|
|
|
|
|
$a=(200*hex(substr($name,4,3))/0xfff)-100;
|
559
|
0
|
|
|
|
|
|
$b=(200*hex(substr($name,7,3))/0xfff)-100;
|
560
|
|
|
|
|
|
|
} else {
|
561
|
0
|
|
|
|
|
|
$l=100*hex(substr($name,1,4))/0xffff;
|
562
|
0
|
|
|
|
|
|
$a=(200*hex(substr($name,5,4))/0xffff)-100;
|
563
|
0
|
|
|
|
|
|
$b=(200*hex(substr($name,9,4))/0xffff)-100;
|
564
|
|
|
|
|
|
|
}
|
565
|
0
|
|
|
|
|
|
return($l,$a,$b);
|
566
|
|
|
|
|
|
|
}
|
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
sub namecolor {
|
569
|
0
|
|
|
0
|
0
|
|
my $name=shift @_;
|
570
|
0
|
0
|
|
|
|
|
unless(ref $name) {
|
571
|
0
|
|
|
|
|
|
$name=lc($name);
|
572
|
0
|
|
|
|
|
|
$name=~s/[^\#!%\&\$a-z0-9]//go;
|
573
|
|
|
|
|
|
|
}
|
574
|
0
|
0
|
|
|
|
|
if($name=~/^[a-z]/) { # name spec.
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
575
|
0
|
|
|
|
|
|
return(namecolor($colors{$name}));
|
576
|
|
|
|
|
|
|
} elsif($name=~/^#/) { # rgb spec.
|
577
|
0
|
|
|
|
|
|
return(floats5(rgbHexValues($name)));
|
578
|
|
|
|
|
|
|
} elsif($name=~/^%/) { # cmyk spec.
|
579
|
0
|
|
|
|
|
|
return(floats5(cmykHexValues($name)));
|
580
|
|
|
|
|
|
|
} elsif($name=~/^!/) { # hsv spec.
|
581
|
0
|
|
|
|
|
|
return(floats5(HSVtoRGB(hsvHexValues($name))));
|
582
|
|
|
|
|
|
|
} elsif($name=~/^&/) { # hsl spec.
|
583
|
0
|
|
|
|
|
|
return(floats5(HSLtoRGB(hsvHexValues($name))));
|
584
|
|
|
|
|
|
|
} else { # or it is a ref ?
|
585
|
0
|
0
|
|
|
|
|
return(floats5(@{$name || [0.5,0.5,0.5]}));
|
|
0
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
}
|
587
|
|
|
|
|
|
|
}
|
588
|
|
|
|
|
|
|
sub namecolor_cmyk {
|
589
|
0
|
|
|
0
|
0
|
|
my $name=shift @_;
|
590
|
0
|
0
|
|
|
|
|
unless(ref $name) {
|
591
|
0
|
|
|
|
|
|
$name=lc($name);
|
592
|
0
|
|
|
|
|
|
$name=~s/[^\#!%\&\$a-z0-9]//go;
|
593
|
|
|
|
|
|
|
}
|
594
|
0
|
0
|
|
|
|
|
if($name=~/^[a-z]/) { # name spec.
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
595
|
0
|
|
|
|
|
|
return(namecolor_cmyk($colors{$name}));
|
596
|
|
|
|
|
|
|
} elsif($name=~/^#/) { # rgb spec.
|
597
|
0
|
|
|
|
|
|
return(floats5(RGBasCMYK(rgbHexValues($name))));
|
598
|
|
|
|
|
|
|
} elsif($name=~/^%/) { # cmyk spec.
|
599
|
0
|
|
|
|
|
|
return(floats5(cmykHexValues($name)));
|
600
|
|
|
|
|
|
|
} elsif($name=~/^!/) { # hsv spec.
|
601
|
0
|
|
|
|
|
|
return(floats5(RGBasCMYK(HSVtoRGB(hsvHexValues($name)))));
|
602
|
|
|
|
|
|
|
} elsif($name=~/^&/) { # hsl spec.
|
603
|
0
|
|
|
|
|
|
return(floats5(RGBasCMYK(HSLtoRGB(hsvHexValues($name)))));
|
604
|
|
|
|
|
|
|
} else { # or it is a ref ?
|
605
|
0
|
0
|
|
|
|
|
return(floats5(RGBasCMYK(@{$name || [0.5,0.5,0.5]})));
|
|
0
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
}
|
607
|
|
|
|
|
|
|
}
|
608
|
|
|
|
|
|
|
sub namecolor_lab {
|
609
|
0
|
|
|
0
|
0
|
|
my $name=shift @_;
|
610
|
0
|
0
|
|
|
|
|
unless(ref $name) {
|
611
|
0
|
|
|
|
|
|
$name=lc($name);
|
612
|
0
|
|
|
|
|
|
$name=~s/[^\#!%\&\$a-z0-9]//go;
|
613
|
|
|
|
|
|
|
}
|
614
|
0
|
0
|
|
|
|
|
if($name=~/^[a-z]/) { # name spec.
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
615
|
0
|
|
|
|
|
|
return(namecolor_lab($colors{$name}));
|
616
|
|
|
|
|
|
|
} elsif($name=~/^\$/) { # lab spec.
|
617
|
0
|
|
|
|
|
|
return(floats5(labHexValues($name)));
|
618
|
|
|
|
|
|
|
} elsif($name=~/^#/) { # rgb spec.
|
619
|
0
|
|
|
|
|
|
my ($h,$s,$v)=RGBtoHSV(rgbHexValues($name));
|
620
|
0
|
|
|
|
|
|
my $a=cos(deg2rad $h)*$s*100;
|
621
|
0
|
|
|
|
|
|
my $b=sin(deg2rad $h)*$s*100;
|
622
|
0
|
|
|
|
|
|
my $l=100*$v;
|
623
|
0
|
|
|
|
|
|
return(floats5($l,$a,$b));
|
624
|
|
|
|
|
|
|
} elsif($name=~/^!/) { # hsv spec.
|
625
|
|
|
|
|
|
|
# fake conversion
|
626
|
0
|
|
|
|
|
|
my ($h,$s,$v)=hsvHexValues($name);
|
627
|
0
|
|
|
|
|
|
my $a=cos(deg2rad $h)*$s*100;
|
628
|
0
|
|
|
|
|
|
my $b=sin(deg2rad $h)*$s*100;
|
629
|
0
|
|
|
|
|
|
my $l=100*$v;
|
630
|
0
|
|
|
|
|
|
return(floats5($l,$a,$b));
|
631
|
|
|
|
|
|
|
} elsif($name=~/^&/) { # hsl spec.
|
632
|
0
|
|
|
|
|
|
my ($h,$s,$v)=hsvHexValues($name);
|
633
|
0
|
|
|
|
|
|
my $a=cos(deg2rad $h)*$s*100;
|
634
|
0
|
|
|
|
|
|
my $b=sin(deg2rad $h)*$s*100;
|
635
|
0
|
|
|
|
|
|
($h,$s,$v)=RGBtoHSV(HSLtoRGB($h,$s,$v));
|
636
|
0
|
|
|
|
|
|
my $l=100*$v;
|
637
|
0
|
|
|
|
|
|
return(floats5($l,$a,$b));
|
638
|
|
|
|
|
|
|
} else { # or it is a ref ?
|
639
|
0
|
0
|
|
|
|
|
my ($h,$s,$v)=RGBtoHSV(@{$name || [0.5,0.5,0.5]});
|
|
0
|
|
|
|
|
|
|
640
|
0
|
|
|
|
|
|
my $a=cos(deg2rad $h)*$s*100;
|
641
|
0
|
|
|
|
|
|
my $b=sin(deg2rad $h)*$s*100;
|
642
|
0
|
|
|
|
|
|
my $l=100*$v;
|
643
|
0
|
|
|
|
|
|
return(floats5($l,$a,$b));
|
644
|
|
|
|
|
|
|
}
|
645
|
|
|
|
|
|
|
}
|
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
sub unfilter
|
648
|
|
|
|
|
|
|
{
|
649
|
0
|
|
|
0
|
0
|
|
my ($filter,$stream)=@_;
|
650
|
|
|
|
|
|
|
|
651
|
0
|
0
|
|
|
|
|
if(defined $filter)
|
652
|
|
|
|
|
|
|
{
|
653
|
|
|
|
|
|
|
# we need to fix filter because it MAY be
|
654
|
|
|
|
|
|
|
# an array BUT IT COULD BE only a name
|
655
|
0
|
0
|
|
|
|
|
if(ref($filter)!~/Array$/)
|
656
|
|
|
|
|
|
|
{
|
657
|
0
|
|
|
|
|
|
$filter = PDFArray($filter);
|
658
|
|
|
|
|
|
|
}
|
659
|
0
|
|
|
|
|
|
my @filts;
|
660
|
0
|
|
|
|
|
|
my ($hasflate) = -1;
|
661
|
0
|
|
|
|
|
|
my ($temp, $i, $temp1);
|
662
|
|
|
|
|
|
|
|
663
|
0
|
|
|
|
|
|
@filts=(map { ("PDF::API3::Compat::API2::Basic::PDF::".($_->val))->new } $filter->elementsof);
|
|
0
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
|
665
|
0
|
|
|
|
|
|
foreach my $f (@filts)
|
666
|
|
|
|
|
|
|
{
|
667
|
0
|
|
|
|
|
|
$stream = $f->infilt($stream, 1);
|
668
|
|
|
|
|
|
|
}
|
669
|
|
|
|
|
|
|
}
|
670
|
0
|
|
|
|
|
|
return($stream);
|
671
|
|
|
|
|
|
|
}
|
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
sub dofilter {
|
674
|
0
|
|
|
0
|
0
|
|
my ($filter,$stream)=@_;
|
675
|
|
|
|
|
|
|
|
676
|
0
|
0
|
|
|
|
|
if((defined $filter) ) {
|
677
|
|
|
|
|
|
|
# we need to fix filter because it MAY be
|
678
|
|
|
|
|
|
|
# an array BUT IT COULD BE only a name
|
679
|
0
|
0
|
|
|
|
|
if(ref($filter)!~/Array$/) {
|
680
|
0
|
|
|
|
|
|
$filter = PDFArray($filter);
|
681
|
|
|
|
|
|
|
}
|
682
|
0
|
|
|
|
|
|
my @filts;
|
683
|
0
|
|
|
|
|
|
my ($hasflate) = -1;
|
684
|
0
|
|
|
|
|
|
my ($temp, $i, $temp1);
|
685
|
|
|
|
|
|
|
|
686
|
0
|
|
|
|
|
|
@filts=(map { ("PDF::API3::Compat::API2::Basic::PDF::".($_->val))->new } $filter->elementsof);
|
|
0
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
|
688
|
0
|
|
|
|
|
|
foreach my $f (@filts) {
|
689
|
0
|
|
|
|
|
|
$stream = $f->outfilt($stream, 1);
|
690
|
|
|
|
|
|
|
}
|
691
|
|
|
|
|
|
|
}
|
692
|
0
|
|
|
|
|
|
return($stream);
|
693
|
|
|
|
|
|
|
}
|
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
sub nameByUni {
|
696
|
0
|
|
|
0
|
0
|
|
my ($e)=@_;
|
697
|
0
|
|
0
|
|
|
|
return($u2n{$e} || sprintf('uni%04X',$e));
|
698
|
|
|
|
|
|
|
}
|
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
sub uniByName {
|
701
|
0
|
|
|
0
|
0
|
|
my ($e)=@_;
|
702
|
0
|
0
|
|
|
|
|
if($e=~/^uni([0-9A-F]{4})$/) {
|
703
|
0
|
|
|
|
|
|
return(hex($1));
|
704
|
|
|
|
|
|
|
}
|
705
|
0
|
|
0
|
|
|
|
return($n2u{$e} || undef);
|
706
|
|
|
|
|
|
|
}
|
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
sub initNameTable {
|
709
|
0
|
|
|
0
|
0
|
|
%u2n=(); %u2n=%u2n_o;
|
|
0
|
|
|
|
|
|
|
710
|
0
|
|
|
|
|
|
%n2u=(); %n2u=%n2u_o;
|
|
0
|
|
|
|
|
|
|
711
|
0
|
|
|
|
|
|
$pua=0xE000;
|
712
|
0
|
|
|
|
|
|
1;
|
713
|
|
|
|
|
|
|
}
|
714
|
|
|
|
|
|
|
sub defineName {
|
715
|
0
|
|
|
0
|
0
|
|
my $name=shift @_;
|
716
|
0
|
0
|
|
|
|
|
return($n2u{$name}) if(defined $n2u{$name});
|
717
|
|
|
|
|
|
|
|
718
|
0
|
|
|
|
|
|
while(defined $u2n{$pua}) { $pua++; }
|
|
0
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
|
720
|
0
|
|
|
|
|
|
$u2n{$pua}=$name;
|
721
|
0
|
|
|
|
|
|
$n2u{$name}=$pua;
|
722
|
|
|
|
|
|
|
|
723
|
0
|
|
|
|
|
|
return($pua);
|
724
|
|
|
|
|
|
|
}
|
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
sub page_size {
|
727
|
0
|
|
|
0
|
0
|
|
my ($x1,$y1,$x2,$y2) = @_;
|
728
|
0
|
0
|
|
|
|
|
if(defined $x2) {
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
729
|
|
|
|
|
|
|
# full bbox
|
730
|
0
|
|
|
|
|
|
return($x1,$y1,$x2,$y2);
|
731
|
|
|
|
|
|
|
} elsif(defined $y1) {
|
732
|
|
|
|
|
|
|
# half bbox
|
733
|
0
|
|
|
|
|
|
return(0,0,$x1,$y1);
|
734
|
|
|
|
|
|
|
} elsif(defined $PaperSizes{lc($x1)}) {
|
735
|
|
|
|
|
|
|
# textual spec.
|
736
|
0
|
|
|
|
|
|
return(0,0,@{$PaperSizes{lc($x1)}});
|
|
0
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
} elsif($x1=~/^[\d\.]+$/) {
|
738
|
|
|
|
|
|
|
# single quadratic
|
739
|
0
|
|
|
|
|
|
return(0,0,$x1,$x1);
|
740
|
|
|
|
|
|
|
} else {
|
741
|
|
|
|
|
|
|
# pdf default.
|
742
|
0
|
|
|
|
|
|
return(0,0,612,792);
|
743
|
|
|
|
|
|
|
}
|
744
|
|
|
|
|
|
|
}
|
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
sub getPaperSizes
|
747
|
|
|
|
|
|
|
{
|
748
|
0
|
|
|
0
|
1
|
|
my %h=();
|
749
|
0
|
|
|
|
|
|
foreach my $k (keys %PaperSizes)
|
750
|
|
|
|
|
|
|
{
|
751
|
0
|
|
|
|
|
|
$h{$k}=[@{$PaperSizes{$k}}];
|
|
0
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
}
|
753
|
0
|
|
|
|
|
|
return(%h);
|
754
|
|
|
|
|
|
|
}
|
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
sub xmlMarkupDecl
|
757
|
|
|
|
|
|
|
{
|
758
|
0
|
|
|
0
|
0
|
|
my $xml=<
|
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
EOT
|
762
|
0
|
|
|
|
|
|
foreach my $n (sort {lc($a) cmp lc($b)} keys %n2u)
|
|
0
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
{
|
764
|
0
|
0
|
|
|
|
|
next if($n eq 'apos');
|
765
|
0
|
0
|
|
|
|
|
next if($n eq 'amp');
|
766
|
0
|
0
|
|
|
|
|
next if($n eq 'quot');
|
767
|
0
|
0
|
|
|
|
|
next if($n eq 'gt');
|
768
|
0
|
0
|
|
|
|
|
next if($n eq 'lt');
|
769
|
0
|
0
|
|
|
|
|
next if($n eq '.notdef');
|
770
|
0
|
0
|
|
|
|
|
next if($n2u{$n}<32);
|
771
|
0
|
|
|
|
|
|
$xml.=sprintf('',$n,$n2u{$n})."\n";
|
772
|
|
|
|
|
|
|
}
|
773
|
0
|
|
|
|
|
|
$xml.="\n]>\n";
|
774
|
0
|
|
|
|
|
|
return($xml);
|
775
|
|
|
|
|
|
|
}
|
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
1;
|
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
__END__
|