File Coverage

blib/lib/PDF/API2/Resource/ColorSpace/Separation.pm
Criterion Covered Total %
statement 18 92 19.5
branch 0 18 0.0
condition 0 6 0.0
subroutine 6 10 60.0
pod 4 4 100.0
total 28 130 21.5


line stmt bran cond sub pod time code
1             package PDF::API2::Resource::ColorSpace::Separation;
2              
3 1     1   1130 use base 'PDF::API2::Resource::ColorSpace';
  1         3  
  1         105  
4              
5 1     1   7 use strict;
  1         2  
  1         22  
6 1     1   6 use warnings;
  1         3  
  1         41  
7              
8             our $VERSION = '2.045'; # VERSION
9              
10 1     1   5 use PDF::API2::Basic::PDF::Utils;
  1         3  
  1         84  
11 1     1   7 use PDF::API2::Util;
  1         2  
  1         148  
12 1     1   8 use Scalar::Util qw(weaken);
  1         4  
  1         1054  
13              
14             =head1 NAME
15              
16             PDF::API2::Resource::ColorSpace::Separation - Support for color space separations
17              
18             =head1 METHODS
19              
20             =over
21              
22             =item $cs = PDF::API2::Resource::ColorSpace::Separation->new $pdf, $key, %parameters
23              
24             Returns a new colorspace object.
25              
26             =cut
27              
28             sub new {
29 0     0 1   my ($class, $pdf, $key, $name, @clr) = @_;
30              
31 0 0         $class = ref($class) if ref($class);
32 0           my $self = $class->SUPER::new($pdf, $key);
33 0 0         $pdf->new_obj($self) unless $self->is_obj($pdf);
34 0           $self->{' apipdf'} = $pdf;
35 0           weaken $self->{' apipdf'};
36              
37 0           my $fct = PDFDict();
38              
39 0           my $csname;
40 0           $clr[0] = lc($clr[0]);
41 0           $self->color(@clr);
42 0 0         if ($clr[0] =~ /^[a-z\#\!]+/) {
    0          
    0          
    0          
    0          
43             # colorname or #! specifier
44             # with rgb target colorspace
45             # namecolor returns always a RGB
46 0           my ($r, $g, $b) = namecolor($clr[0]);
47 0           $csname = 'DeviceRGB';
48              
49 0           $fct->{'FunctionType'} = PDFNum(0);
50 0           $fct->{'Size'} = PDFArray(PDFNum(2));
51 0           $fct->{'Range'} = PDFArray(map { PDFNum($_) } ($r, 1, $g, 1, $b, 1));
  0            
52 0           $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1));
53 0           $fct->{'BitsPerSample'} = PDFNum(8);
54 0           $fct->{' stream'} = "\xff\xff\xff\x00\x00\x00";
55             }
56             elsif ($clr[0] =~ /^[\%]+/) {
57             # % specifier
58             # with cmyk target colorspace
59 0           my ($c, $m, $y, $k) = namecolor_cmyk($clr[0]);
60 0           $csname = 'DeviceCMYK';
61              
62 0           $fct->{'FunctionType'} = PDFNum(0);
63 0           $fct->{'Size'} = PDFArray(PDFNum(2));
64 0           $fct->{'Range'} = PDFArray(map { PDFNum($_) } (0, $c, 0, $m, 0, $y, 0, $k));
  0            
65 0           $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1));
66 0           $fct->{'BitsPerSample'} = PDFNum(8);
67 0           $fct->{' stream'} = "\x00\x00\x00\x00\xff\xff\xff\xff";
68             }
69             elsif (@clr == 1) {
70             # grey color spec.
71 0           $clr[0] /= 255 while $clr[0] > 1;
72              
73             # adjusted for 8/16/32bit spec.
74 0           my $g = $clr[0];
75 0           $csname = 'DeviceGray';
76              
77 0           $fct->{'FunctionType'} = PDFNum(0);
78 0           $fct->{'Size'} = PDFArray(PDFNum(2));
79 0           $fct->{'Range'} = PDFArray(PDFNum(0), PDFNum($g));
80 0           $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1));
81 0           $fct->{'BitsPerSample'} = PDFNum(8);
82 0           $fct->{' stream'} = "\xff\x00";
83             }
84             elsif (@clr == 3) {
85             # legacy rgb color-spec (0 <= x <= 1)
86 0           my ($r, $g, $b) = @clr;
87 0           $csname = 'DeviceRGB';
88              
89 0           $fct->{'FunctionType'} = PDFNum(0);
90 0           $fct->{'Size'} = PDFArray(PDFNum(2));
91 0           $fct->{'Range'} = PDFArray(map { PDFNum($_) } ($r, 1, $g, 1, $b, 1));
  0            
92 0           $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1));
93 0           $fct->{'BitsPerSample'} = PDFNum(8);
94 0           $fct->{' stream'} = "\xff\xff\xff\x00\x00\x00";
95             }
96             elsif (@clr == 4) {
97             # legacy cmyk color-spec (0 <= x <= 1)
98 0           my ($c, $m, $y, $k) = @clr;
99 0           $csname='DeviceCMYK';
100              
101 0           $fct->{'FunctionType'} = PDFNum(0);
102 0           $fct->{'Size'} = PDFArray(PDFNum(2));
103 0           $fct->{'Range'} = PDFArray(map { PDFNum($_) } (0, $c, 0, $m, 0, $y, 0, $k));
  0            
104 0           $fct->{'Domain'} = PDFArray(PDFNum(0), PDFNum(1));
105 0           $fct->{'BitsPerSample'} = PDFNum(8);
106 0           $fct->{' stream'} = "\x00\x00\x00\x00\xff\xff\xff\xff";
107             }
108             else {
109 0           die 'invalid color specification.';
110             }
111 0           $self->type($csname);
112 0           $pdf->new_obj($fct);
113 0           $self->add_elements(PDFName('Separation'),
114             PDFName($name),
115             PDFName($csname),
116             $fct);
117 0           $self->tintname($name);
118              
119 0           return $self;
120             }
121              
122             =item @color = $res->color
123              
124             Returns the base-color of the Separation-Colorspace.
125              
126             =cut
127              
128             sub color {
129 0     0 1   my $self = shift();
130 0 0 0       if (@_ and defined $_[0]) {
131 0           $self->{' color'} = [@_];
132             }
133 0           return @{$self->{' color'}};
  0            
134             }
135              
136             =item $tintname = $res->tintname $tintname
137              
138             Returns the tint-name of the Separation-Colorspace.
139              
140             =cut
141              
142             sub tintname {
143 0     0 1   my $self = shift();
144 0 0 0       if (@_ and defined $_[0]) {
145 0           $self->{' tintname'} = [@_];
146             }
147 0           return @{$self->{' tintname'}};
  0            
148             }
149              
150              
151             sub param {
152 0     0 1   my $self = shift();
153 0           return $_[0];
154             }
155              
156             =back
157              
158             =cut
159              
160             1;