API3/Compat/API2/Resource/ColorSpace/Separation.pm

filter: Statementstmt 23.5% 24 / 102 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 61.5% 8 / 13 Podpod 100% 5 / 5 totaltotal 24.6% 37 / 150 CC 13 SCAR 35.8
CC
13
Cov
19%
new
90.0
color
12.0
tintname
12.0
CRAP 35.8
« API3/Compat/API2/Resource/XObject/Form.pm ↑ Summary API3/Compat/API2/Basic/TTF/Head.pm »
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 <areibens@cpan.org>.
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: Separation.pm,v 2.0 2005/11/16 02:18:14 areibens Exp $
31 #
32 #=======================================================================
33
34 package PDF::API3::Compat::API2::Resource::ColorSpace::Separation;
35
36 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
37
38 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶ use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶ use PDF::API3::Compat::API2::Resource::ColorSpace;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶ use Math::Trig;
Subroutine BEGIN: called CC=1 SCAR=0.0
44
45 1 @ISA = qw( PDF::API3::Compat::API2::Resource::ColorSpace );
46 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:18:14 $
47
48 }
49 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
50
51 =item $cs = PDF::API3::Compat::API2::Resource::ColorSpace::Separation->new $pdf, $key, %parameters
52
53 Returns a new colorspace object.
54
55 =cut
56
57 0 ▶sub new {
Subroutine new: not called CC=9 SCAR=45.0
Pod documented
58 0 my ($class,$pdf,$key,@opts)=@_;
59 0 my ($name,@clr)=@opts;
60
61 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
62 0 $self=$class->SUPER::new($pdf,$key,@opts);
63 0 ▶ $pdf->new_obj($self) unless($self->is_obj($pdf));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 0 0
64 0 $self->{' apipdf'}=$pdf;
65
66 0 my $fct=PDFDict();
67
68 0 my $csname='DeviceRGB';
69 0 $clr[0]=lc($clr[0]);
70 0 $self->color(@clr);
71 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
72 # colorname or #! specifier
73 # with rgb target colorspace
74 # namecolor returns always a RGB
75 0 my ($r,$g,$b)=namecolor($clr[0]);
76
77 0 $fct->{FunctionType}=PDFNum(0);
78 0 $fct->{Size}=PDFArray(PDFNum(2));
79 0 $fct->{Range}=PDFArray(map {PDFNum($_)} ($r,1,$g,1,$b,1));
80 0 $fct->{Domain}=PDFArray(PDFNum(0),PDFNum(1));
81 0 $fct->{BitsPerSample}=PDFNum(8);
82 0 $fct->{' stream'}="\xff\xff\xff\x00\x00\x00";
83 } elsif($clr[0]=~/^[\%]+/) {
84 # % specifier
85 # with cmyk target colorspace
86 0 my ($c,$m,$y,$k)=namecolor_cmyk($clr[0]);
87 0 $csname='DeviceCMYK';
88
89 0 $fct->{FunctionType}=PDFNum(0);
90 0 $fct->{Size}=PDFArray(PDFNum(2));
91 0 $fct->{Range}=PDFArray(map {PDFNum($_)} (0,$c,0,$m,0,$y,0,$k));
92 0 $fct->{Domain}=PDFArray(PDFNum(0),PDFNum(1));
93 0 $fct->{BitsPerSample}=PDFNum(8);
94 0 $fct->{' stream'}="\x00\x00\x00\x00\xff\xff\xff\xff";
95 } elsif(scalar @clr == 1) {
96 # grey color spec.
97 0 ▶ while($clr[0]>1) { $clr[0]/=255; }
Branch: 1 branch
BranchTrueFalseTotal
if ($clr[0] > 1) 0 0 0
98 # adjusted for 8/16/32bit spec.
99 0 my $g=$clr[0];
100 0 $csname='DeviceGray';
101
102 0 $fct->{FunctionType}=PDFNum(0);
103 0 $fct->{Size}=PDFArray(PDFNum(2));
104 0 $fct->{Range}=PDFArray(map {PDFNum($_)} (0,$g));
105 0 $fct->{Domain}=PDFArray(PDFNum(0),PDFNum(1));
106 0 $fct->{BitsPerSample}=PDFNum(8);
107 0 $fct->{' stream'}="\xff\x00";
108 } elsif(scalar @clr == 3) {
109 # legacy rgb color-spec (0 <= x <= 1)
110 0 my ($r,$g,$b)=@clr;
111
112 0 $fct->{FunctionType}=PDFNum(0);
113 0 $fct->{Size}=PDFArray(PDFNum(2));
114 0 $fct->{Range}=PDFArray(map {PDFNum($_)} ($r,1,$g,1,$b,1));
115 0 $fct->{Domain}=PDFArray(PDFNum(0),PDFNum(1));
116 0 $fct->{BitsPerSample}=PDFNum(8);
117 0 $fct->{' stream'}="\xff\xff\xff\x00\x00\x00";
118 } elsif(scalar @clr == 4) {
119 # legacy cmyk color-spec (0 <= x <= 1)
120 0 my ($c,$m,$y,$k)=@clr;
121 0 $csname='DeviceCMYK';
122
123 0 $fct->{FunctionType}=PDFNum(0);
124 0 $fct->{Size}=PDFArray(PDFNum(2));
125 0 $fct->{Range}=PDFArray(map {PDFNum($_)} (0,$c,0,$m,0,$y,0,$k));
126 0 $fct->{Domain}=PDFArray(PDFNum(0),PDFNum(1));
127 0 $fct->{BitsPerSample}=PDFNum(8);
128 0 $fct->{' stream'}="\x00\x00\x00\x00\xff\xff\xff\xff";
129 } else {
130 0 die 'invalid color specification.';
131 }
132 0 $self->type($csname);
133 0 $pdf->new_obj($fct);
134 0 $self->add_elements(PDFName('Separation'), PDFName($name), PDFName($csname), $fct);
135 0 $self->tintname($name);
136 0 return($self);
137 }
138
139 =item $cs = PDF::API3::Compat::API2::Resource::ColorSpace::Separation->new_api $api, $name
140
141 Returns a separation color-space object. This method is different from 'new' that
142 it needs an PDF::API3::Compat::API2-object rather than a Text::PDF::File-object.
143
144 =cut
145
146 0 ▶sub new_api {
Subroutine new_api: not called CC=1 SCAR=6.9
Pod documented
147 0 my ($class,$api,@opts)=@_;
148
149 0 my $obj=$class->new($api->{pdf},pdfkey(),@opts);
150 0 $self->{' api'}=$api;
151
152 0 return($obj);
153 }
154
155 =item @color = $res->color
156
157 Returns the base-color of the Separation-Colorspace.
158
159 =cut
160
161 0 ▶sub color {
Subroutine color: not called CC=3 SCAR=24.8
Pod documented
162 0 my $self=shift @_;
163 0 ▶ if(scalar @_ >0 && defined($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0 and defined $_[0]) 0 0 0
Condition0%0/3
scalar @_ > 0 and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 0 and defined $_[0]
scalar @_ > 0 defined $_[0]
Truth table0%0/3
A and B
A= scalar @_ > 0B= defined $_[0]
ABresult
0X0
100
111
164 0 $self->{' color'}=[@_];
165 }
166 0 return(@{$self->{' color'}});
167 }
168
169 =item $tintname = $res->tintname $tintname
170
171 Returns the tint-name of the Separation-Colorspace.
172
173 =cut
174
175 0 ▶sub tintname {
Subroutine tintname: not called CC=3 SCAR=24.8
Pod documented
176 0 my $self=shift @_;
177 0 ▶ if(scalar @_ >0 && defined($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 0 and defined $_[0]) 0 0 0
Condition0%0/3
scalar @_ > 0 and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 0 and defined $_[0]
scalar @_ > 0 defined $_[0]
Truth table0%0/3
A and B
A= scalar @_ > 0B= defined $_[0]
ABresult
0X0
100
111
178 0 $self->{' tintname'}=[@_];
179 }
180 0 return(@{$self->{' tintname'}});
181 }
182
183
184 0 ▶sub param {
Subroutine param: not called CC=1 SCAR=6.9
Pod documented
185 0 my $self=shift @_;
186 0 return($_[0]);
187 }
188
189
190 1 1;
191
192 __END__
« API3/Compat/API2/Resource/XObject/Form.pm ↑ Summary API3/Compat/API2/Basic/TTF/Head.pm »