File Coverage

blib/lib/PDF/API3/Compat/API2/Resource/ColorSpace/DeviceN.pm
Criterion Covered Total %
statement 23 88 26.1
branch 0 8 0.0
condition 0 2 0.0
subroutine 8 11 72.7
pod 3 3 100.0
total 34 112 30.3


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: DeviceN.pm,v 2.0 2005/11/16 02:18:14 areibens Exp $
31             #
32             #=======================================================================
33            
34             package PDF::API3::Compat::API2::Resource::ColorSpace::DeviceN;
35            
36             BEGIN {
37            
38 1     1   7 use strict;
  1         3  
  1         54  
39 1     1   7 use vars qw(@ISA $VERSION);
  1         2  
  1         70  
40 1     1   10 use PDF::API3::Compat::API2::Resource::ColorSpace;
  1         3  
  1         28  
41 1     1   8 use PDF::API3::Compat::API2::Basic::PDF::Utils;
  1         3  
  1         179  
42 1     1   7 use PDF::API3::Compat::API2::Util;
  1         4  
  1         224  
43 1     1   7 use Math::Trig;
  1         2  
  1         346  
44            
45 1     1   24 @ISA = qw( PDF::API3::Compat::API2::Resource::ColorSpace );
46 1         52 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:18:14 $
47            
48             }
49 1     1   9 no warnings qw[ deprecated recursion uninitialized ];
  1         2  
  1         954  
50            
51             =item $cs = PDF::API3::Compat::API2::Resource::ColorSpace::DeviceN->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 ($clrs,$sampled)=@opts;
60            
61 0           $sampled=2;
62            
63 0 0         $class = ref $class if ref $class;
64 0           $self=$class->SUPER::new($pdf,$key);
65 0 0         $pdf->new_obj($self) unless($self->is_obj($pdf));
66 0           $self->{' apipdf'}=$pdf;
67            
68 0           my $fct=PDFDict();
69            
70 0           my $csname=$clrs->[0]->type;
71 0           my @xclr=map { $_->color } @{$clrs};
  0            
  0            
72 0           my @xnam=map { $_->tintname } @{$clrs};
  0            
  0            
73             # $self->{' comments'}="DeviceN ColorSpace\n";
74 0 0         if($csname eq 'DeviceCMYK') {
75 0           @xclr=map { [ namecolor_cmyk($_) ] } @xclr;
  0            
76            
77 0           $fct->{FunctionType}=PDFNum(0);
78 0           $fct->{Order}=PDFNum(3);
79 0           $fct->{Range}=PDFArray(map {PDFNum($_)} (0,1,0,1,0,1,0,1));
  0            
80 0           $fct->{BitsPerSample}=PDFNum(8);
81 0           $fct->{Domain}=PDFArray();
82 0           $fct->{Size}=PDFArray();
83 0           foreach (@xclr) {
84 0           $fct->{Size}->add_elements(PDFNum($sampled));
85 0           $fct->{Domain}->add_elements(PDFNum(0),PDFNum(1));
86             }
87 0           my @spec=();
88 0           foreach my $xc (0..(scalar @xclr)-1) {
89 0           foreach my $n (0..($sampled**(scalar @xclr))-1) {
90 0   0       $spec[$n]||=[0,0,0,0];
91 0           my $factor=($n/($sampled**$xc)) % $sampled;
92             # $self->{' comments'}.="C($n): xc=$xc i=$factor ";
93 0           my @thiscolor=map { ($_*$factor)/($sampled-1) } @{$xclr[$xc]};
  0            
  0            
94             # $self->{' comments'}.="(@{$xclr[$xc]}) --> (@thiscolor) ";
95 0           foreach my $s (0..3) {
96 0           $spec[$n]->[$s]+=$thiscolor[$s];
97             }
98 0 0         @{$spec[$n]}=map { $_>1?1:$_ } @{$spec[$n]};
  0            
  0            
  0            
99             # $self->{' comments'}.="--> (@{$spec[$n]})\n";
100             # $self->{' comments'}.="\n";
101             }
102             }
103 0           my @b=();
104 0           foreach my $s (@spec) {
105 0           push @b,(map { pack('C',($_*255)) } @{$s});
  0            
  0            
106             }
107 0           $fct->{' stream'}=join('',@b);
108             } else {
109 0           die "unsupported colorspace specification (=$csname).";
110             }
111 0           $fct->{Filter}=PDFArray(PDFName('ASCIIHexDecode'));
112 0           $self->type($csname);
113 0           $pdf->new_obj($fct);
114 0           my $attr=PDFDict();
115 0           foreach my $cs (@{$clrs}) {
  0            
116 0           $attr->{$cs->tintname}=$cs;
117             }
118 0           $self->add_elements(PDFName('DeviceN'), PDFArray(map { PDFName($_) } @xnam), PDFName($csname), $fct);
  0            
119            
120 0           return($self);
121             }
122            
123             =item $cs = PDF::API3::Compat::API2::Resource::ColorSpace::DeviceN->new_api $api
124            
125             Returns a DeviceN color-space object. This method is different from 'new' that
126             it needs an PDF::API3::Compat::API2-object rather than a Text::PDF::File-object.
127            
128             =cut
129            
130             sub new_api {
131 0     0 1   my ($class,$api,@opts)=@_;
132            
133 0           my $obj=$class->new($api->{pdf},pdfkey(),@opts);
134 0           $self->{' api'}=$api;
135            
136 0           return($obj);
137             }
138            
139             sub param {
140 0     0 1   my $self=shift @_;
141 0           return(@_);
142             }
143            
144            
145             1;
146            
147             __END__