lib/ChordPro/lib/SVGPDF/Image.pm

filter: Statementstmt 22.6% 17 / 75 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 15.4% 22 / 142 CC 24 SCAR 61.0
CC
24
Cov
14%
process
539.9
BEGIN
1.0
BEGIN
1.0
CRAP 447.0
« lib/ChordPro/Output/MMA.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Tspan.pm »
1 #! perl
2  
3 12 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 class SVGPDF::Image :isa(SVGPDF::Element);
9  
10 0 ▶method process () {
Subroutine process: not called CC=24 SCAR=62.9
Pod undocumented
11 0 my $atts = $self->atts;
12 0 my $xo = $self->xo;
13 0 ▶ return if $atts->{omit}; # for testing/debugging.
Branch: 1 branch
BranchTrueFalseTotal
if $atts->{"omit"} 0 0 0
14  
15 0 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 0 ▶ $x ||= 0; $y ||= 0;
Condition0%0/4
$x ||= 0
l!l
00
$y ||= 0
l!l
00
MC/DC0%0/1
$x ||= 0
$x
MC/DC0%0/1
$y ||= 0
$y
Truth table0%0/2
A
A= $x
Aresult
11
00
Truth table0%0/2
A
A= $y
Aresult
11
00
19 0 ▶ $w ||= 0; $h ||= 0;
Condition0%0/4
$w ||= 0
l!l
00
$h ||= 0
l!l
00
MC/DC0%0/1
$w ||= 0
$w
MC/DC0%0/1
$h ||= 0
$h
Truth table0%0/2
A
A= $w
Aresult
11
00
Truth table0%0/2
A
A= $h
Aresult
11
00
20  
21 0 ▶ unless ( $w && $h ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($w and $h) 0 0 0
Condition0%0/3
$w and $h
!ll&&!rl&&r
000
MC/DC0%0/2
$w and $h
$w $h
Truth table0%0/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 0 $self->_dbg( $self->name, " x=$x y=$y w=$w h=$h" );
27  
28 0 my $img;
29 0 ▶ if ( $link =~ /^data:/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($link =~ /^data:/u) { } 0 0 0
elsif ($link =~ /^.+\.(png|jpe?g|gif)$/iu and -s $link) { } 0 0 0
elsif ($link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iu and -s $link) { } 0 0 0
30 # In-line image asset.
31 0 my $info = $self->data_inline($link);
32 0 ▶ if ( $info->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"error"}) 0 0 0
33 0 warn( "SVG: ", $info->{error}, "\n" );
34 0 $self->css_pop, return;
35 }
36  
37 0 my $mimetype = $info->{mimetype};
38 0 my $subtype = $info->{subtype};
39  
40 0 ▶ unless ( $mimetype eq "image" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mimetype eq "image") 0 0 0
41 0 warn("SVG: Unhandled mime type \"mimetype/$subtype\" in inline image\n");
42 0 $self->css_pop, return;
43 }
44 0 my $data = $info->{data};
45  
46 # Get info.
47 0 require Image::Info;
48 0 $info = Image::Info::image_info(\$data);
49 0 ▶ if ( $info->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"error"}) 0 0 0
50 0 warn($info->{error});
51 0 $self->css_pop, return;
52 }
53  
54 0 my $format = $info->{file_ext};
55 0 ▶ $format = "jpeg" if $format eq "jpg";
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "jpg" 0 0 0
56 0 ▶ $format = "pnm" if $format =~ /^p[bgp]m$/;
Branch: 1 branch
BranchTrueFalseTotal
if $format =~ /^p[bgp]m$/u 0 0 0
57 0 ▶ $format = "pnm" if $format =~ /^x[bp]m$/; # bonus
Branch: 1 branch
BranchTrueFalseTotal
if $format =~ /^x[bp]m$/u 0 0 0
58 0 ▶ $format = "tiff" if $format eq "tif";
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "tif" 0 0 0
59  
60 # Make the image. Silence missing library warnings.
61 0 my $fh;
62 # Also, do not use the fast IPL module, it cannot read from scalar.
63 0 ▶ if ( $format eq "tiff" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq 'tiff') { } 0 0 0
64 # TIFF can't read from scalar file handle.
65 12 ▶ use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 0 ( my $fd, $fh ) = File::Temp::tempfile( UNLINK => 1 );
67 0 binmode $fd => ':raw';
68 0 print $fd $data;
69 0 close($fd);
70 # Yes, trickery... $fh is now a file name, not a handle.
71 }
72 else {
73 0 open( $fh, '<:raw', \$data );
74 }
75 0 $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 ) {
Condition0%0/3
$link =~ /^.+\.(png|jpe?g|gif)$/iu and -s $link
!ll&&!rl&&r
000
MC/DC0%0/2
$link =~ /^.+\.(png|jpe?g|gif)$/iu and -s $link
$link =~ /^.+\.(png|jpe?g|gif)$/iu -s $link
Truth table0%0/3
A and B
A= $link =~ /^.+\.(png|jpe?g|gif)$/iuB= -s $link
ABresult
0X0
100
111
79 # Autodetected. Make the image.
80 0 $img = $self->root->pdf->image( $link, silent => 1 );
81 }
82 ▶ elsif ( $link =~ m!^.+\.(tiff?|p[bgp]m|x[bp]m)$!i && -s $link ) {
Condition0%0/3
$link =~ /^.+\.(tiff?|p[bgp]m|x[bp]m)$/iu and -s $link
!ll&&!rl&&r
000
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 table0%0/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 0 ▶ my $format = $1 =~ /tif/i ? "tiff" : "pnm";
Branch: 1 branch
BranchTrueFalseTotal
$1 =~ /tif/iu ? : 0 0 0
86 # Make the image.
87 0 $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 0 $self->_dbg( "xo save" );
96 0 $xo->save;
97  
98 # Place the image.
99 0 ▶ $self->set_transform($tf) if $tf;
Branch: 1 branch
BranchTrueFalseTotal
if $tf 0 0 0
100 0 $xo->transform( translate => [ $x, $y+$h ] );
101 0 $xo->image( $img, 0, 0, $w, -$h );
102  
103 0 $self->_dbg( "xo restore" );
104 0 $xo->restore;
105 0 $self->css_pop;
106 12 }
107  
108  
109 12 1;
« lib/ChordPro/Output/MMA.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Tspan.pm »