File Coverage

blib/lib/PDF/API3/Compat/API2/Resource/ColorSpace/Separation.pm
Criterion Covered Total %
statement 23 101 22.7
branch 0 18 0.0
condition 0 6 0.0
subroutine 8 13 61.5
pod 5 5 100.0
total 36 143 25.1


line stmt bran cond sub pod time code
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 .
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             BEGIN {
37            
38 1     1   7 use strict;
  1         2  
  1         49  
39 1     1   7 use vars qw(@ISA $VERSION);
  1         3  
  1         63  
40 1     1   7 use PDF::API3::Compat::API2::Resource::ColorSpace;
  1         2  
  1         23  
41 1     1   7 use PDF::API3::Compat::API2::Basic::PDF::Utils;
  1         2  
  1         166  
42 1     1   7 use PDF::API3::Compat::API2::Util;
  1         2  
  1         218  
43 1     1   8 use Math::Trig;
  1         2  
  1         341  
44            
45 1     1   29 @ISA = qw( PDF::API3::Compat::API2::Resource::ColorSpace );
46 1         34 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:18:14 $
47            
48             }
49 1     1   6 no warnings qw[ deprecated recursion uninitialized ];
  1         2  
  1         1445  
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             sub new {
58 0     0 1   my ($class,$pdf,$key,@opts)=@_;
59 0           my ($name,@clr)=@opts;
60            
61 0 0         $class = ref $class if ref $class;
62 0           $self=$class->SUPER::new($pdf,$key,@opts);
63 0 0         $pdf->new_obj($self) unless($self->is_obj($pdf));
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 0         if($clr[0]=~/^[a-z\#\!]+/) {
    0          
    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));
  0            
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));
  0            
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; }
  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));
  0            
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));
  0            
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));
  0            
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             sub new_api {
147 0     0 1   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             sub color {
162 0     0 1   my $self=shift @_;
163 0 0 0       if(scalar @_ >0 && defined($_[0])) {
164 0           $self->{' color'}=[@_];
165             }
166 0           return(@{$self->{' color'}});
  0            
167             }
168            
169             =item $tintname = $res->tintname $tintname
170            
171             Returns the tint-name of the Separation-Colorspace.
172            
173             =cut
174            
175             sub tintname {
176 0     0 1   my $self=shift @_;
177 0 0 0       if(scalar @_ >0 && defined($_[0])) {
178 0           $self->{' tintname'}=[@_];
179             }
180 0           return(@{$self->{' tintname'}});
  0            
181             }
182            
183            
184             sub param {
185 0     0 1   my $self=shift @_;
186 0           return($_[0]);
187             }
188            
189            
190             1;
191            
192             __END__