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

filter: Statementstmt 26.9% 24 / 89 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 72.7% 8 / 11 Podpod 100% 3 / 3 totaltotal 30.7% 35 / 114 CC 12 SCAR 44.5
CC
12
Cov
24%
new
156.0
new_api
2.0
param
2.0
CRAP 85.6
« API3/Compat/API2/Resource/Font/CoreFont.pm ↑ Summary API3/Compat/API2/Basic/TTF/Post.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: 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 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::DeviceN->new $pdf, $key, %parameters
52
53 Returns a new colorspace object.
54
55 =cut
56
57 0 ▶sub new {
Subroutine new: not called CC=12 SCAR=50.5
Pod documented
58 0 my ($class,$pdf,$key,@opts)=@_;
59 0 my ($clrs,$sampled)=@opts;
60
61 0 $sampled=2;
62
63 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
64 0 $self=$class->SUPER::new($pdf,$key);
65 0 ▶ $pdf->new_obj($self) unless($self->is_obj($pdf));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 0 0
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};
72 0 my @xnam=map { $_->tintname } @{$clrs};
73 # $self->{' comments'}="DeviceN ColorSpace\n";
74 0 ▶ if($csname eq 'DeviceCMYK') {
Branch: 1 branch
BranchTrueFalseTotal
if ($csname eq 'DeviceCMYK') { } 0 0 0
75 0 @xclr=map { [ namecolor_cmyk($_) ] } @xclr;
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));
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 ▶ $spec[$n]||=[0,0,0,0];
Condition0%0/2
$spec[$n] ||= [0, 0, 0, 0]
l!l
00
MC/DC0%0/1
$spec[$n] ||= [0, 0, 0, 0]
$spec[$n]
Truth table0%0/2
A
A= $spec[$n]
Aresult
11
00
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]};
94 # $self->{' comments'}.="(@{$xclr[$xc]}) --> (@thiscolor) ";
95 0 foreach my $s (0..3) {
96 0 $spec[$n]->[$s]+=$thiscolor[$s];
97 }
98 0 ▶ @{$spec[$n]}=map { $_>1?1:$_ } @{$spec[$n]};
Branch: 1 branch
BranchTrueFalseTotal
$_ > 1 ? : 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});
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}) {
116 0 $attr->{$cs->tintname}=$cs;
117 }
118 0 $self->add_elements(PDFName('DeviceN'), PDFArray(map { PDFName($_) } @xnam), PDFName($csname), $fct);
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 0 ▶sub new_api {
Subroutine new_api: not called CC=1 SCAR=6.9
Pod documented
131 0 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 0 ▶sub param {
Subroutine param: not called CC=1 SCAR=6.9
Pod documented
140 0 my $self=shift @_;
141 0 return(@_);
142 }
143
144
145 1 1;
146
147 __END__
« API3/Compat/API2/Resource/Font/CoreFont.pm ↑ Summary API3/Compat/API2/Basic/TTF/Post.pm »