line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::API2::Resource::ColorSpace::DeviceN; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1137
|
use base 'PDF::API2::Resource::ColorSpace'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
223
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '2.043'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use PDF::API2::Basic::PDF::Utils; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
124
|
|
11
|
1
|
|
|
1
|
|
9
|
use PDF::API2::Util; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
171
|
|
12
|
1
|
|
|
1
|
|
8
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
756
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
0
|
|
|
0
|
1
|
|
my ($class, $pdf, $key, $clrs) = @_; |
16
|
0
|
|
|
|
|
|
my $sampled = 2; |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
$class = ref($class) if ref($class); |
19
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new($pdf, $key); |
20
|
0
|
0
|
|
|
|
|
$pdf->new_obj($self) unless $self->is_obj($pdf); |
21
|
0
|
|
|
|
|
|
$self->{' apipdf'} = $pdf; |
22
|
0
|
|
|
|
|
|
weaken $self->{' apipdf'}; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $fct = PDFDict(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# The base colorspace was formerly chosen based on the base colorspace of |
27
|
|
|
|
|
|
|
# the first color component, but since only DeviceCMYK has been implemented |
28
|
|
|
|
|
|
|
# (everything else throws an error), always use DeviceCMYK. |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
# my $csname = $clrs->[0]->type(); |
31
|
0
|
|
|
|
|
|
my $csname = 'DeviceCMYK'; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my @xclr = map { $_->color() } @$clrs; |
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my @xnam = map { $_->tintname() } @$clrs; |
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if ($csname eq 'DeviceCMYK') { |
36
|
0
|
|
|
|
|
|
@xclr = map { [ namecolor_cmyk($_) ] } @xclr; |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$fct->{'FunctionType'} = PDFNum(0); |
39
|
0
|
|
|
|
|
|
$fct->{'Order'} = PDFNum(3); |
40
|
0
|
|
|
|
|
|
$fct->{'Range'} = PDFArray(map { PDFNum($_) } (0, 1, 0, 1, 0, 1, 0, 1)); |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$fct->{'BitsPerSample'} = PDFNum(8); |
42
|
0
|
|
|
|
|
|
$fct->{'Domain'} = PDFArray(); |
43
|
0
|
|
|
|
|
|
$fct->{'Size'} = PDFArray(); |
44
|
0
|
|
|
|
|
|
foreach (@xclr) { |
45
|
0
|
|
|
|
|
|
$fct->{'Size'}->add_elements(PDFNum($sampled)); |
46
|
0
|
|
|
|
|
|
$fct->{'Domain'}->add_elements(PDFNum(0), PDFNum(1)); |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
my @spec; |
49
|
0
|
|
|
|
|
|
foreach my $xc (0 .. (scalar @xclr) - 1) { |
50
|
0
|
|
|
|
|
|
foreach my $n (0 .. ($sampled ** (scalar @xclr)) - 1) { |
51
|
0
|
|
0
|
|
|
|
$spec[$n] ||= [0, 0, 0, 0]; |
52
|
0
|
|
|
|
|
|
my $factor = ($n / ($sampled ** $xc)) % $sampled; |
53
|
0
|
|
|
|
|
|
my @color = map { ($_ * $factor) / ($sampled - 1) } @{$xclr[$xc]}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
foreach my $s (0 .. 3) { |
55
|
0
|
|
|
|
|
|
$spec[$n]->[$s] += $color[$s]; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
0
|
|
|
|
|
@{$spec[$n]} = map { $_ > 1 ? 1 : $_ } @{$spec[$n]}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
my @b; |
61
|
0
|
|
|
|
|
|
foreach my $s (@spec) { |
62
|
0
|
|
|
|
|
|
push @b, map { pack('C', $_ * 255) } @$s; |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
$fct->{' stream'} = join('', @b); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
|
|
|
|
|
die "unsupported colorspace specification (=$csname)."; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
$fct->{'Filter'} = PDFArray(PDFName('ASCIIHexDecode')); |
70
|
0
|
|
|
|
|
|
$self->type($csname); |
71
|
0
|
|
|
|
|
|
$pdf->new_obj($fct); |
72
|
0
|
|
|
|
|
|
my $attr = PDFDict(); |
73
|
0
|
|
|
|
|
|
foreach my $cs (@$clrs) { |
74
|
0
|
|
|
|
|
|
$attr->{$cs->tintname()} = $cs; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
$self->add_elements(PDFName('DeviceN'), |
77
|
0
|
|
|
|
|
|
PDFArray(map { PDFName($_) } @xnam), |
|
0
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
PDFName($csname), $fct); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return $self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub param { |
84
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
85
|
0
|
|
|
|
|
|
return @_; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |