API2/Util.pm

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