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