Builder/Resource/ColorSpace/Separation.pm

filter: Statementstmt 21.8% 21 / 96 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 6 / 10 Podpod 100% 4 / 4 totaltotal 22.1% 31 / 140 CC 13 SCAR 37.0
CC
13
Cov
17%
new
90.0
color
12.0
tintname
12.0
CRAP 40.5
« Builder/Resource/XObject/Image/TIFF.pm ↑ Summary Builder/Resource/XObject/Form/BarCode.pm »
1 package PDF::Builder::Resource::ColorSpace::Separation;
2  
3 1 ▶use base 'PDF::Builder::Resource::ColorSpace';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '3.028'; # VERSION
9 1 our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
10  
11 1 ▶use PDF::Builder::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use PDF::Builder::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 PDF::Builder::Resource::ColorSpace::Separation - Support for color space separations
18  
19 Inherits from L<PDF::Builder::Resource::ColorSpace>
20  
21 =head1 METHODS
22  
23 =head2 new
24  
25 $cs = PDF::Builder::Resource::ColorSpace::Separation->new($pdf, $key, @colors)
26  
27 =over
28  
29 Returns a new colorspace object.
30  
31 =back
32  
33 =cut
34  
35 0 ▶sub new {
Subroutine new: not called CC=9 SCAR=45.0
Pod documented
36 0 my ($class, $pdf, $key, $name, @clr) = @_;
37  
38 0 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
39 0 my $self = $class->SUPER::new($pdf, $key);
40 0 ▶ $pdf->new_obj($self) unless $self->is_obj($pdf);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 0 0
41 0 $self->{' apipdf'} = $pdf;
42 0 weaken $self->{' apipdf'};
43  
44 0 my $fct = PDFDict();
45  
46 0 my $csname;
47 0 $clr[0] = lc($clr[0]);
48 0 $self->color(@clr);
49 0 ▶ if ($clr[0] =~ /^[a-z\#\!]+/) {
Branch: 5 branches
BranchTrueFalseTotal
if ($clr[0] =~ /^[a-z\#\!]+/) { } 0 0 0
elsif ($clr[0] =~ /^[\%]+/) { } 0 0 0
elsif (scalar @clr == 1) { } 0 0 0
elsif (scalar @clr == 3) { } 0 0 0
elsif (scalar @clr == 4) { } 0 0 0
50 # colorname or #! specifier
51 # with rgb target colorspace
52 # namecolor returns always a RGB
53 0 my ($r,$g,$b) = namecolor($clr[0]);
54 0 $csname = 'DeviceRGB';
55  
56 0 $fct->{'FunctionType'} = PDFNum(0);
57 0 $fct->{'Size'} = PDFArray(PDFNum(2));
58 0 $fct->{'Range'} = PDFArray(map {PDFNum($_)} ($r,1, $g,1, $b,1));
59 0 $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1));
60 0 $fct->{'BitsPerSample'} = PDFNum(8);
61 0 $fct->{' stream'} = "\xff\xff\xff\x00\x00\x00";
62 } elsif ($clr[0] =~ /^[\%]+/) {
63 # % specifier
64 # with cmyk target colorspace
65 0 my ($c,$m,$y,$k) = namecolor_cmyk($clr[0]);
66 0 $csname = 'DeviceCMYK';
67  
68 0 $fct->{'FunctionType'} = PDFNum(0);
69 0 $fct->{'Size'} = PDFArray(PDFNum(2));
70 0 $fct->{'Range'} = PDFArray(map {PDFNum($_)} (0,$c, 0,$m, 0,$y, 0,$k));
71 0 $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1));
72 0 $fct->{'BitsPerSample'} = PDFNum(8);
73 0 $fct->{' stream'}="\x00\x00\x00\x00\xff\xff\xff\xff";
74 } elsif (scalar @clr == 1) {
75 # grey color spec.
76 0 ▶ $clr[0] /= 255 while $clr[0] > 1;
Branch: 1 branch
BranchTrueFalseTotal
$clr[0] > 1 and do { $clr[0] /= 255 } 0 0 0
77  
78 # adjusted for 8/16/32bit spec.
79 0 my $g = $clr[0];
80 0 $csname = 'DeviceGray';
81  
82 0 $fct->{'FunctionType'} = PDFNum(0);
83 0 $fct->{'Size'} = PDFArray(PDFNum(2));
84 0 $fct->{'Range'} = PDFArray(map {PDFNum($_)} (0,$g));
85 0 $fct->{'Domain'} = PDFArray(PDFNum(0),PDFNum(1));
86 0 $fct->{'BitsPerSample'} = PDFNum(8);
87 0 $fct->{' stream'} = "\xff\x00";
88 } elsif (scalar @clr == 3) {
89 # legacy rgb color-spec (0 <= x <= 1)
90 0 my ($r,$g,$b) = @clr;
91 0 $csname = 'DeviceRGB';
92  
93 0 $fct->{'FunctionType'} = PDFNum(0);
94 0 $fct->{'Size'} = PDFArray(PDFNum(2));
95 0 $fct->{'Range'} = PDFArray(map {PDFNum($_)} ($r,1, $g,1, $b,1));
96 0 $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1));
97 0 $fct->{'BitsPerSample'} = PDFNum(8);
98 0 $fct->{' stream'}="\xff\xff\xff\x00\x00\x00";
99 } elsif (scalar @clr == 4) {
100 # legacy cmyk color-spec (0 <= x <= 1)
101 0 my ($c,$m,$y,$k) = @clr;
102 0 $csname = 'DeviceCMYK';
103  
104 0 $fct->{'FunctionType'} = PDFNum(0);
105 0 $fct->{'Size'} = PDFArray(PDFNum(2));
106 0 $fct->{'Range'} = PDFArray(map {PDFNum($_)} (0,$c, 0,$m, 0,$y, 0,$k));
107 0 $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1));
108 0 $fct->{'BitsPerSample'} = PDFNum(8);
109 0 $fct->{' stream'}="\x00\x00\x00\x00\xff\xff\xff\xff";
110 } else {
111 0 die 'invalid color specification.';
112 }
113 0 $self->type($csname);
114 0 $pdf->new_obj($fct);
115 0 $self->add_elements(PDFName('Separation'),
116 PDFName($name),
117 PDFName($csname),
118 $fct);
119 0 $self->tintname($name);
120 0 return $self;
121 }
122  
123 =head2 color
124  
125 @color = $res->color()
126  
127 =over
128  
129 Returns the base-color of the Separation-Colorspace.
130  
131 =back
132  
133 =cut
134  
135 0 ▶sub color {
Subroutine color: not called CC=3 SCAR=24.8
Pod documented
136 0 my $self = shift;
137  
138 0 ▶ if (@_ && defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and defined $_[0]) 0 0 0
Condition0%0/3
@_ and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table0%0/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
139 0 $self->{' color'} = [@_];
140 }
141 0 return @{$self->{' color'}};
142 }
143  
144 =head2 tintname
145  
146 $tintname = $res->tintname($tintname)
147  
148 =over
149  
150 Returns the tint-name of the Separation-Colorspace.
151  
152 =back
153  
154 =cut
155  
156 0 ▶sub tintname {
Subroutine tintname: not called CC=3 SCAR=24.8
Pod documented
157 0 my $self = shift;
158  
159 0 ▶ if (@_ && defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and defined $_[0]) 0 0 0
Condition0%0/3
@_ and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table0%0/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
160 0 $self->{' tintname'} = [@_];
161 }
162 0 return @{$self->{' tintname'}};
163 }
164  
165 0 ▶sub param {
Subroutine param: not called CC=1 SCAR=6.9
Pod documented
166 0 my $self = shift;
167  
168 0 return $_[0];
169 }
170  
171 1 1;
« Builder/Resource/XObject/Image/TIFF.pm ↑ Summary Builder/Resource/XObject/Form/BarCode.pm »