SVGPDF/Image.pm

filter: Statementstmt 86.6% 65 / 75 Branchbran 73.3% 22 / 30 Conditioncond 47.3% 9 / 19 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 73.2% 104 / 142 CC 24 SCAR 33.2
CC
24
Cov
77%
process
33.2
BEGIN
1.0
BEGIN
1.0
CRAP 27.7
« SVGPDF/Contrib/Bogen.pm ↑ Summary SVGPDF/Path.pm »
1 #! perl
2  
3 2 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 class SVGPDF::Image :isa(SVGPDF::Element);
9  
10 18 ▶method process () {
Subroutine process: called CC=24 SCAR=35.0
Pod undocumented
11 18 my $atts = $self->atts;
12 18 my $xo = $self->xo;
13 18 ▶ return if $atts->{omit}; # for testing/debugging.
Branch: 1 branch
BranchTrueFalseTotal
if $atts->{"omit"} 0 18 18
14  
15 18 my ( $x, $y, $w, $h, $link, $tf ) =
16 $self->get_params( $atts, qw( x:H y:V width:H height:V href:! transform:s ) );
17  
18 18 ▶ $x ||= 0; $y ||= 0;
Condition75%3/4
$x ||= 0
l!l
135
$y ||= 0
l!l
018
MC/DC100%1/1
$x ||= 0
$x
MC/DC0%0/1
$y ||= 0
$y
Truth table100%2/2
A
A= $x
Aresult
11
00
Truth table50%1/2
A
A= $y
Aresult
11
00
19 18 ▶ $w ||= 0; $h ||= 0;
Condition50%2/4
$w ||= 0
l!l
180
$h ||= 0
l!l
180
MC/DC0%0/1
$w ||= 0
$w
MC/DC0%0/1
$h ||= 0
$h
Truth table50%1/2
A
A= $w
Aresult
11
00
Truth table50%1/2
A
A= $h
Aresult
11
00
20  
21 18 ▶ unless ( $w && $h ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($w and $h) 0 18 18
Condition33%1/3
$w and $h
!ll&&!rl&&r
0018
MC/DC0%0/2
$w and $h
$w $h
Truth table33%1/3
A and B
A= $wB= $h
ABresult
0X0
100
111
22 0 $self->_dbg( $self->name, " x=$x y=$y w=$w h=$h **skipped**" );
23 0 return;
24 }
25  
26 18 $self->_dbg( $self->name, " x=$x y=$y w=$w h=$h" );
27  
28 18 my $img;
29 18 ▶ if ( $link =~ /^data:/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($link =~ /^data:/u) { } 8 10 18
elsif ($link =~ /^.+\.(png|jpe?g|gif)$/iu and -s $link) { } 5 5 10
elsif ($link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iu and -s $link) { } 5 0 5
30 # In-line image asset.
31 8 my $info = $self->data_inline($link);
32 8 ▶ if ( $info->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"error"}) 0 8 8
33 0 warn( "SVG: ", $info->{error}, "\n" );
34 0 $self->css_pop, return;
35 }
36  
37 8 my $mimetype = $info->{mimetype};
38 8 my $subtype = $info->{subtype};
39  
40 8 ▶ unless ( $mimetype eq "image" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mimetype eq "image") 0 8 8
41 0 warn("SVG: Unhandled mime type \"mimetype/$subtype\" in inline image\n");
42 0 $self->css_pop, return;
43 }
44 8 my $data = $info->{data};
45  
46 # Get info.
47 8 require Image::Info;
48 8 $info = Image::Info::image_info(\$data);
49 8 ▶ if ( $info->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"error"}) 0 8 8
50 0 warn($info->{error});
51 0 $self->css_pop, return;
52 }
53  
54 8 my $format = $info->{file_ext};
55 8 ▶ $format = "jpeg" if $format eq "jpg";
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "jpg" 1 7 8
56 8 ▶ $format = "pnm" if $format =~ /^p[bgp]m$/;
Branch: 1 branch
BranchTrueFalseTotal
if $format =~ /^p[bgp]m$/u 3 5 8
57 8 ▶ $format = "pnm" if $format =~ /^x[bp]m$/; # bonus
Branch: 1 branch
BranchTrueFalseTotal
if $format =~ /^x[bp]m$/u 0 8 8
58 8 ▶ $format = "tiff" if $format eq "tif";
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "tif" 1 7 8
59  
60 # Make the image. Silence missing library warnings.
61 8 my $fh;
62 # Also, do not use the fast IPL module, it cannot read from scalar.
63 8 ▶ if ( $format eq "tiff" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq 'tiff') { } 1 7 8
64 # TIFF can't read from scalar file handle.
65 2 ▶ use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ( my $fd, $fh ) = File::Temp::tempfile( UNLINK => 1 );
67 1 binmode $fd => ':raw';
68 1 print $fd $data;
69 1 close($fd);
70 # Yes, trickery... $fh is now a file name, not a handle.
71 }
72 else {
73 7 open( $fh, '<:raw', \$data );
74 }
75 8 $img = $self->root->pdf->image( $fh, format => $format,
76 silent => 1, nouseIPL => 1 );
77 }
78 ▶ elsif ( $link =~ m!^.+\.(png|jpe?g|gif)$!i && -s $link ) {
Condition66%2/3
$link =~ /^.+\.(png|jpe?g|gif)$/iu and -s $link
!ll&&!rl&&r
505
MC/DC50%1/2
$link =~ /^.+\.(png|jpe?g|gif)$/iu and -s $link
$link =~ /^.+\.(png|jpe?g|gif)$/iu -s $link
Truth table66%2/3
A and B
A= $link =~ /^.+\.(png|jpe?g|gif)$/iuB= -s $link
ABresult
0X0
100
111
79 # Autodetected. Make the image.
80 5 $img = $self->root->pdf->image( $link, silent => 1 );
81 }
82 ▶ elsif ( $link =~ m!^.+\.(tiff?|p[bgp]m|x[bp]m)$!i && -s $link ) {
Condition33%1/3
$link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iu and -s $link
!ll&&!rl&&r
005
MC/DC0%0/2
$link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iu and -s $link
$link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iu -s $link
Truth table33%1/3
A and B
A= $link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iuB= -s $link
ABresult
0X0
100
111
83 # Not autodetected, need format.
84 # Note that xbm and xpm are bonus.
85 5 ▶ my $format = $1 =~ /tif/i ? "tiff" : "pnm";
Branch: 1 branch
BranchTrueFalseTotal
$1 =~ /tif/iu ? : 2 3 5
86 # Make the image.
87 5 $img = $self->root->pdf->image( $link, format => $format, silent => 1 );
88 }
89 else {
90 0 ▶ warn("SVG: Unhandled or missing image link: ",
Condition0%0/2
qq["$link"] // "<undef>"
l!l
00
MC/DC0%0/1
qq["$link"] // "<undef>"
qq["$link"]
Truth table0%0/2
A
A= qq["$link"]
Aresult
11
00
91 "\"$link\""//"<undef>", "\n");
92 0 return;
93 }
94  
95 18 $self->_dbg( "xo save" );
96 18 $xo->save;
97  
98 # Place the image.
99 18 ▶ $self->set_transform($tf) if $tf;
Branch: 1 branch
BranchTrueFalseTotal
if $tf 0 18 18
100 18 $xo->transform( translate => [ $x, $y+$h ] );
101 18 $xo->image( $img, 0, 0, $w, -$h );
102  
103 18 $self->_dbg( "xo restore" );
104 18 $xo->restore;
105 18 $self->css_pop;
106 2 }
107  
108  
109 2 1;
« SVGPDF/Contrib/Bogen.pm ↑ Summary SVGPDF/Path.pm »