Builder/Resource/XObject/Image.pm

filter: Statementstmt 76.7% 33 / 43 Branchbran 60.0% 6 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 81.8% 9 / 11 Podpod 100% 7 / 7 totaltotal 76.3% 58 / 76 CC 7 SCAR 9.7
CC
7
Cov
73%
mask
6.0
colorspace
4.2
height
2.0
CRAP 2.6
« Builder/Resource/XObject/Form/BarCode/int2of5.pm ↑ Summary Builder/Resource.pm »
1 package PDF::Builder::Resource::XObject::Image;
2  
3 6 ▶use base 'PDF::Builder::Resource::XObject';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 our $VERSION = '3.028'; # VERSION
9 6 our $LAST_UPDATE = '3.028'; # manually update whenever code is changed
10  
11 6 ▶use PDF::Builder::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 PDF::Builder::Resource::XObject::Image - Base class for external raster image objects
16  
17 Inherits from L<PDF::Builder::Resource::XObject>
18  
19 =head1 METHODS
20  
21 =head2 new
22  
23 $image = PDF::Builder::Resource::XObject::Image->new($pdf, $name)
24  
25 =over
26  
27 Returns an image resource object.
28  
29 =back
30  
31 =cut
32  
33 17 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
34 17 my ($class, $pdf, $name) = @_;
35  
36 17 my $self = $class->SUPER::new($pdf, $name);
37  
38 17 $self->subtype('Image');
39  
40 17 return $self;
41 }
42  
43 =head2 width
44  
45 $width = $image->width()
46  
47 =over
48  
49 Get the width (in points) of the image object.
50  
51 B<Note> that this function also has the ability to I<set> the width,
52 by giving the new width (in points), but it appears that it never
53 worked correctly. The I<set> capability has been B<deprecated>, and
54 may be removed soon, unless it is found to be needed for an E<lt>img>
55 tag in C<column()>. If you are
56 using the C<width()> method in some manner to I<set> the image width,
57 please let us know, so we can plan to keep it enabled!
58  
59 =back
60  
61 =cut
62  
63 22 ▶sub width {
Subroutine width: called CC=2 SCAR=6.9
Pod documented
64 22 my $self = shift;
65  
66 22 ▶ $self->{'Width'} = PDFNum(shift()) if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 13 9 22
67 22 return $self->{'Width'}->val();
68 }
69  
70 =head2 height
71  
72 $height = $image->height()
73  
74 =over
75  
76 Get the height (in points) of the image object.
77  
78 B<Note> that this function also has the ability to I<set> the height,
79 by giving the new height (in points), but it appears that it never
80 worked correctly. The I<set> capability has been B<deprecated>, and
81 may be removed soon, unless it is found to be needed for an E<lt>img>
82 tag in C<column()>. If you are
83 using the C<height()> method in some manner to I<set> the image height,
84 please let us know, so we can plan to keep it enabled!
85  
86 =back
87  
88 =cut
89  
90 13 ▶sub height {
Subroutine height: called CC=2 SCAR=7.1
Pod documented
91 13 my $self = shift;
92  
93 13 ▶ $self->{'Height'} = PDFNum(shift()) if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 13 0 13
94 13 return $self->{'Height'}->val();
95 }
96  
97 ## probably not useful, so do not add, for now
98 #=head2 bbox
99 #
100 # ($x1,$x2, $w,$h) = $image->bbox()
101 #
102 #=over
103 #
104 #Get the image dimensions similarly to a form's I<bounding box>.
105 #Note that the C<$x1> and C<$x2> values will always be 0.
106 #
107 #This method is offered as an alternative to the C<width> and C<height> methods.
108 #
109 #=back
110 #
111 #=cut
112 #
113 #sub bbox {
114 # my $self = shift();
115 # my @bb = (0,0, $self->width(),$self->height());
116 # return @bb;
117 #}
118  
119 =head2 smask
120  
121 $image->smask($xobject)
122  
123 =over
124  
125 Set the soft-mask image object.
126  
127 =back
128  
129 =cut
130  
131 0 ▶sub smask {
Subroutine smask: not called CC=1 SCAR=6.9
Pod documented
132 0 my $self = shift;
133 0 $self->{'SMask'} = shift;
134  
135 0 return $self;
136 }
137  
138 =head2 mask
139  
140 $image->mask(@color_range)
141  
142 $image->mask($xobject)
143  
144 =over
145  
146 Set the mask to an image mask XObject or an array containing a range
147 of colors to be applied as a color key mask.
148  
149 =back
150  
151 =cut
152  
153 0 ▶sub mask {
Subroutine mask: not called CC=2 SCAR=17.9
Pod documented
154 0 my $self = shift();
155  
156 0 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
157 0 $self->{'Mask'} = shift();
158 } else {
159 0 $self->{'Mask'} = PDFArray(map { PDFNum($_) } @_);
160 }
161  
162 0 return $self;
163 }
164  
165 # imask() functionality rolled into mask()
166  
167 =head2 colorspace
168  
169 $image->colorspace($name)
170  
171 $image->colorspace($array)
172  
173 =over
174  
175 Set the color space used by the image. Depending on the color space,
176 this will either be just the name of the color space, or it will be an
177 array containing the color space and any required parameters.
178  
179 If passing an array, parameters must already be encoded as PDF
180 objects. The array itself may also be a PDF object. If not, one will
181 be created.
182  
183 =back
184  
185 =cut
186  
187 13 ▶sub colorspace {
Subroutine colorspace: called CC=4 SCAR=14.3
Pod documented
188 13 my ($self, @values) = @_;
189  
190 13 ▶ if (scalar @values == 1 and ref($values[0])) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @values == 1 and ref $values[0]) { } 4 9 13
elsif (scalar @values == 1) { } 9 0 9
Condition66%2/3
scalar @values == 1 and ref $values[0]
!ll&&!rl&&r
094
MC/DC50%1/2
scalar @values == 1 and ref $values[0]
scalar @values == 1 ref $values[0]
Truth table66%2/3
A and B
A= scalar @values == 1B= ref $values[0]
ABresult
0X0
100
111
191 4 $self->{'ColorSpace'} = $values[0];
192 } elsif (scalar @values == 1) {
193 9 $self->{'ColorSpace'} = PDFName($values[0]);
194 } else {
195 0 $self->{'ColorSpace'} = PDFArray(@values);
196 }
197  
198 13 return $self;
199 }
200  
201 =head2 bits_per_component
202  
203 $image->bits_per_component($integer)
204  
205 =over
206  
207 Set the number of bits used to represent each color component.
208  
209 =back
210  
211 =cut
212  
213 13 ▶sub bits_per_component {
Subroutine bits_per_component: called CC=1 SCAR=0.0
Pod documented
214 13 my $self = shift;
215  
216 13 $self->{'BitsPerComponent'} = PDFNum(shift());
217  
218 13 return $self;
219 }
220  
221 # bpc() renamed to bits_per_component()
222  
223 6 1;
« Builder/Resource/XObject/Form/BarCode/int2of5.pm ↑ Summary Builder/Resource.pm »