lib/ChordPro/lib/SVGPDF/Element.pm

filter: Statementstmt 12.0% 42 / 350 Branchbran 0.0% 0 / 156 Conditioncond 0.0% 0 / 100 MC/DCmcdc 0.0% 0 / 57 Subroutinesub 11.4% 4 / 35 Podpod 0.0% 0 / 22 totaltotal 6.3% 46 / 720 CC 119 SCAR 55.9
CC
119
Cov
7%
set_transform
600.0
set_graphics
552.0
get_params
342.0
CRAP 267.3
« blib/lib/ChordPro/Delegate/Lilypond.pm ↑ Summary lib/ChordPro/Output/Text.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 class SVGPDF::Element;
7  
8 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶field $xo :mutator;
Subroutine xo: not called CC=1 SCAR=2.6
Pod undocumented
11 0 ▶field $style :accessor;
Subroutine style: not called CC=2 SCAR=14.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ and $style = shift() 0 0 0
12 0 ▶field $name :param :accessor;
Subroutine name: not called CC=2 SCAR=14.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ and $name = shift() 0 0 0
13 0 ▶field $atts :param :accessor;
Subroutine atts: not called CC=2 SCAR=14.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ and $atts = shift() 0 0 0
14 0 ▶field $css :accessor;
Subroutine css: not called CC=2 SCAR=14.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ and $css = shift() 0 0 0
15 0 ▶field $content :param :accessor; # array of children
Subroutine content: not called CC=2 SCAR=14.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ and $content = shift() 0 0 0
16 0 ▶field $root :param :accessor; # top module
Subroutine root: not called CC=2 SCAR=14.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ and $root = shift() 0 0 0
17  
18 BUILD {
19 $css = $root->css;
20 $xo = $root->xoforms->[-1]->{xo};
21 12 };
22  
23 0 ▶method _dbg (@args) {
Subroutine _dbg: not called CC=1 SCAR=6.9
24 0 $root->_dbg(@args);
25 12 }
26  
27 0 ▶method css_push ( $updated_atts = undef ) {
Subroutine css_push: not called CC=3 SCAR=24.8
Pod undocumented
28 0 ▶ $style = $css->push( element => $name, %{$updated_atts // $atts} );
Condition0%0/3
$updated_atts // $atts
l!l&&r!l&&!r
000
MC/DC0%0/2
$updated_atts // $atts
$updated_atts $atts
Truth table0%0/3
A // B
A= $updated_attsB= $atts
ABresult
1X1
011
000
29 12 }
30  
31 0 ▶method css_pop () {
Subroutine css_pop: not called CC=1 SCAR=6.9
Pod undocumented
32 0 $css->pop;
33 12 }
34  
35 0 ▶method set_transform ( $tf ) {
Subroutine set_transform: not called CC=24 SCAR=64.0
Pod undocumented
36 0 ▶ return unless $tf;
Branch: 1 branch
BranchTrueFalseTotal
unless $tf 0 0 0
37  
38 0 my $nooptimize = 1;
39 0 $tf =~ s/\s+/ /g;
40  
41 # The parts of the transform need to be executed in order.
42 0 ▶ while ( $tf =~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tf =~ /\S/u) 0 0 0
43 0 ▶ if ( $tf =~ /^\s*translate\s*\((.*?)\)(.*)/ ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($tf =~ /^\s*translate\s*\((.*?)\)(.*)/u) { } 0 0 0
elsif ($tf =~ /^\s*rotate\s*\((.*?)\)(.*)/u) { } 0 0 0
elsif ($tf =~ /^\s*scale\s*\((.*?)\)(.*)/u) { } 0 0 0
elsif ($tf =~ /^\s*matrix\s*\((.*?)\)(.*)/u) { } 0 0 0
elsif ($tf =~ /^\s*skew([XY])\s*\((.*?)\)(.*)/iu) { } 0 0 0
44 0 $tf = $2;
45 0 my ( $x, $y ) = $self->getargs($1);
46 0 ▶ $y ||= 0;
Condition0%0/2
$y ||= 0
l!l
00
MC/DC0%0/1
$y ||= 0
$y
Truth table0%0/2
A
A= $y
Aresult
11
00
47 0 ▶ if ( $nooptimize || $x || $y ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nooptimize or $x or $y) 0 0 0
Condition0%0/6
$nooptimize or $x or $y
l!l&&r!l&&!r
000
$nooptimize or $x
l!l&&r!l&&!r
000
MC/DC0%0/3
$nooptimize or $x or $y
$nooptimize $x $y
Truth table0%0/4
A or B or C
A= $nooptimizeB= $xC= $y
ABCresult
1XX1
01X1
0011
0000
48 0 $xo->transform( translate => [ $x, $y ] );
49 0 $self->_dbg( "transform translate(%.2f,%.2f)", $x, $y );
50 }
51 }
52 elsif ( $tf =~ /^\s*rotate\s*\((.*?)\)(.*)/ ) {
53 0 $tf = $2;
54 0 my ( $r, $x, $y ) = $self->getargs($1);
55 0 ▶ if ( $nooptimize || $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nooptimize or $r) 0 0 0
Condition0%0/3
$nooptimize or $r
l!l&&r!l&&!r
000
MC/DC0%0/2
$nooptimize or $r
$nooptimize $r
Truth table0%0/3
A or B
A= $nooptimizeB= $r
ABresult
1X1
011
000
56 0 ▶ if ( $x || $y ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x or $y) 0 0 0
Condition0%0/3
$x or $y
l!l&&r!l&&!r
000
MC/DC0%0/2
$x or $y
$x $y
Truth table0%0/3
A or B
A= $xB= $y
ABresult
1X1
011
000
57 0 $xo->transform( translate => [ $x, $y ] );
58 0 $self->_dbg( "transform translate(%.2f,%.2f)", $x, $y );
59 }
60 0 $self->_dbg( "transform rotate(%.2f)", $r );
61 0 $xo->transform( rotate => $r );
62 0 ▶ if ( $x || $y ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x or $y) 0 0 0
Condition0%0/3
$x or $y
l!l&&r!l&&!r
000
MC/DC0%0/2
$x or $y
$x $y
Truth table0%0/3
A or B
A= $xB= $y
ABresult
1X1
011
000
63 0 $xo->transform( translate => [ -$x, -$y ] );
64 0 $self->_dbg( "transform translate(%.2f,%.2f)", -$x, -$y );
65 }
66 }
67 }
68 elsif ( $tf =~ /^\s*scale\s*\((.*?)\)(.*)/ ) {
69 0 $tf = $2;
70 0 my ( $x, $y ) = $self->getargs($1);
71 0 ▶ $y ||= $x;
Condition0%0/3
$y ||= $x
l!l&&r!l&&!r
000
MC/DC0%0/2
$y ||= $x
$y $x
Truth table0%0/3
A ||= B
A= $yB= $x
ABresult
1X1
011
000
72 0 ▶ if ( $nooptimize || $x != 1 && $y != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nooptimize or $x != 1 and $y != 1) 0 0 0
Condition0%0/6
$nooptimize or $x != 1 and $y != 1
l!l&&r!l&&!r
000
$x != 1 and $y != 1
!ll&&!rl&&r
000
MC/DC0%0/3
$nooptimize or $x != 1 and $y != 1
$nooptimize $x != 1 $y != 1
Truth table0%0/4
A or B and C
A= $nooptimizeB= $x != 1C= $y != 1
ABCresult
1XX1
0111
00X0
0100
73 0 $self->_dbg( "transform scale(%.2f,%.2f)", $x, $y );
74 0 $xo->transform( scale => [ $x, $y ] );
75 }
76 }
77 elsif ( $tf =~ /^\s*matrix\s*\((.*?)\)(.*)/ ) {
78 0 $tf = $2;
79 0 my ( @m ) = $self->getargs($1);
80  
81 # 1 0 0 1 dx dy translate
82 # sx 0 0 sy 0 0 scale
83 # c s -s c 0 0 rotate (s = sin, c = cos)
84 # 1 a b 1 0 0 skew (a = tan a, b = tan b)
85  
86 0 $self->_dbg( "transform matrix(%.2f,%.2f %.2f,%.2f %.2f,%.2f)", @m);
87 0 $xo->matrix(@m);
88 }
89 elsif ( $tf =~ /^\s*skew([XY])\s*\((.*?)\)(.*)/i ) {
90 0 $tf = $3;
91 0 my ( $x ) = $self->getargs($2);
92 0 my $y = 0;
93 0 ▶ if ( $1 eq "X" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "X") 0 0 0
94 0 $y = $x;
95 0 $x = 0;
96 }
97 0 $self->_dbg( "transform skew(%.2f %.2f)", $x, $y );
98 0 $xo->transform( skew => [ $x, $y ] );
99 }
100 else {
101 0 ▶ warn("Ignoring transform: $tf")
Branch: 1 branch
BranchTrueFalseTotal
if $self->root->verbose 0 0 0
102 if $self->root->verbose;
103 0 $self->_dbg("Ignoring transform: \"$tf\"");
104 0 $tf = "";
105 }
106 # %rel = ( relative => 1 );
107 }
108 12 }
109  
110 # <g matrix = m1>
111 # <g matrix = m2>
112 # <g matrix = m3>
113 # result = multiply_matrices( $m1, $m2, $m3 );
114  
115 0 ▶method multiply_matrices :common (@m) {
Subroutine multiply_matrices: not called CC=4 SCAR=30.0
Pod undocumented
116 0 my $i = @m;
117 0 my $m2 = pop(@m);
118 0 ▶ die("Matrix$i must have 6 elements\n") unless @$m2 == 6;
Branch: 1 branch
BranchTrueFalseTotal
unless @$m2 == 6 0 0 0
119  
120 0 ▶ while ( --$i > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$i > 0) 0 0 0
121 0 my $m1 = pop(@m);
122 0 ▶ die("Matrix$i must have 6 elements\n") unless @$m1 == 6;
Branch: 1 branch
BranchTrueFalseTotal
unless @$m1 == 6 0 0 0
123 0 $m2 = [ $m1->[0] * $m2->[0] + $m1->[2] * $m2->[1],
124 $m1->[1] * $m2->[0] + $m1->[3] * $m2->[1],
125 $m1->[0] * $m2->[2] + $m1->[2] * $m2->[3],
126 $m1->[1] * $m2->[2] + $m1->[3] * $m2->[3],
127 $m1->[0] * $m2->[4] + $m1->[2] * $m2->[5] + $m1->[4],
128 $m1->[1] * $m2->[4] + $m1->[3] * $m2->[5] + $m1->[5] ];
129 }
130 0 $m2;
131 12 }
132  
133 0 ▶method set_graphics () {
Subroutine set_graphics: not called CC=23 SCAR=63.1
Pod undocumented
134  
135 0 my $msg = $name;
136  
137 0 ▶ if ( defined( my $lw = $style->{'stroke-width'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $lw = $style->{"stroke-width"})) 0 0 0
138 my $w = $self->u( $lw,
139 fontsize => $style->{'font-size'},
140 0 width => $self->root->xoforms->[-1]->{diag});
141 0 $msg .= sprintf(" stroke-width=%.2f", $w);
142 0 ▶ if ( $lw =~ /e[mx]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lw =~ /e[mx]/u) 0 0 0
143 $msg .= sprintf("(%s\@%.2f)", $lw,
144 $self->u( $style->{'font-size'}|| $self->root->fontsize,
145 fontsize => $style->{'font-size'},
146 0 ▶ width => $self->root->xoforms->[-1]->{diag}));
Condition0%0/3
$style->{'font-size'} || $self->root->fontsize
l!l&&r!l&&!r
000
MC/DC0%0/2
$style->{'font-size'} || $self->root->fontsize
$style->{'font-size'} $self->root->fontsize
Truth table0%0/3
A || B
A= $style->{'font-size'}B= $self->root->fontsize
ABresult
1X1
011
000
147 }
148 0 ▶ if ( $lw =~ /\%/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lw =~ /\%/u) 0 0 0
149 $msg .= sprintf("(%s\@%.2f)", $lw,
150 $self->u( $self->root->xoforms->[-1]->{diag},
151 fontsize => $style->{'font-size'},
152 0 width => $self->root->xoforms->[-1]->{diag}));
153 }
154 0 $xo->line_width($w);
155 }
156  
157 0 ▶ if ( defined( my $linecap = $style->{'stroke-linecap'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $linecap = $style->{"stroke-linecap"})) 0 0 0
158 0 $linecap = lc($linecap);
159 0 ▶ if ( $linecap eq "round" ) { $linecap = 1 }
Branch: 4 branches
BranchTrueFalseTotal
if ($linecap eq 'round') { } 0 0 0
elsif ($linecap eq 'r') { } 0 0 0
elsif ($linecap eq 'square') { } 0 0 0
elsif ($linecap eq 's') { } 0 0 0
160 0 elsif ( $linecap eq "r" ) { $linecap = 1 }
161 0 elsif ( $linecap eq "square" ) { $linecap = 2 }
162 0 elsif ( $linecap eq "s" ) { $linecap = 2 }
163 0 else { $linecap = 0 } # b butt
164 0 $msg .= " linecap=$linecap";
165 0 $xo->line_cap($linecap);
166 }
167  
168 0 ▶ if ( defined( my $linejoin = $style->{'stroke-linejoin'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $linejoin = $style->{"stroke-linejoin"})) 0 0 0
169 0 $linejoin = lc($linejoin);
170 0 ▶ if ( $linejoin eq "round" ) { $linejoin = 1 }
Branch: 4 branches
BranchTrueFalseTotal
if ($linejoin eq 'round') { } 0 0 0
elsif ($linejoin eq 'r') { } 0 0 0
elsif ($linejoin eq 'bevel') { } 0 0 0
elsif ($linejoin eq 'b') { } 0 0 0
171 0 elsif ( $linejoin eq "r" ) { $linejoin = 1 }
172 0 elsif ( $linejoin eq "bevel" ) { $linejoin = 2 }
173 0 elsif ( $linejoin eq "b" ) { $linejoin = 2 }
174 0 else { $linejoin = 0 } # m miter
175 0 $msg .= " linejoin=$linejoin";
176 0 $xo->line_join($linejoin);
177 }
178  
179 0 my $color = $style->{color};
180 0 my $stroke = $style->{stroke};
181 0 ▶ if ( lc($stroke) eq "currentcolor" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $stroke eq "currentcolor") 0 0 0
182 # Nothing. Use current.
183 0 $msg .= " stroke=(current)";
184 0 $stroke = $color;
185 }
186 0 ▶ if ( $stroke ne "none" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stroke ne 'none') { } 0 0 0
187 0 $stroke = SVGPDF::Colour->new( colour => $stroke )->rgb;
188 0 $xo->stroke_color($stroke);
189 0 $msg .= " stroke=$stroke";
190 }
191 else {
192 0 $msg .= " stroke=none";
193 }
194  
195 0 my $fill = $style->{fill};
196 0 ▶ if ( lc($fill) eq "currentcolor" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $fill eq "currentcolor") 0 0 0
197 # Nothing. Use current.
198 0 $msg .= " fill=(current)";
199 0 $fill = $color;
200 }
201 0 ▶ if ( lc($fill) ne "none" && $fill ne "transparent" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $fill ne 'none' and $fill ne 'transparent') { } 0 0 0
Condition0%0/3
lc $fill ne "none" and $fill ne "transparent"
!ll&&!rl&&r
000
MC/DC0%0/2
lc $fill ne "none" and $fill ne "transparent"
lc $fill ne "none" $fill ne "transparent"
Truth table0%0/3
A and B
A= lc $fill ne "none"B= $fill ne "transparent"
ABresult
0X0
100
111
202 0 $fill = SVGPDF::Colour->new( colour => $fill )->rgb;
203 0 $xo->fill_color($fill);
204 0 $msg .= " fill=$fill";
205 }
206 else {
207 0 $msg .= " fill=none";
208 }
209  
210 0 ▶ if ( my $sda = $style->{'stroke-dasharray'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sda = $style->{"stroke-dasharray"}) 0 0 0
211 0 my @sda;
212 0 ▶ if ( $sda && $sda ne "none" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sda and $sda ne "none") 0 0 0
Condition0%0/3
$sda and $sda ne "none"
!ll&&!rl&&r
000
MC/DC0%0/2
$sda and $sda ne "none"
$sda $sda ne "none"
Truth table0%0/3
A and B
A= $sdaB= $sda ne "none"
ABresult
0X0
100
111
213 0 $sda =~ s/,/ /g;
214 0 @sda = split( ' ', $sda );
215 }
216 0 $msg .= " sda=@sda";
217 0 $xo->line_dash_pattern(@sda);
218 }
219  
220 0 $self->_dbg( "%s", $msg );
221 0 return $style;
222 12 }
223  
224 # Return a stroke/fill/paint sub depending on the fill stroke styles.
225 0 ▶method _paintsub () {
Subroutine _paintsub: not called CC=12 SCAR=50.5
226 0 ▶ if ( $style->{stroke}
Branch: 2 branches
BranchTrueFalseTotal
if ($style->{'stroke'} && $style->{'stroke'} ne 'none' && $style->{'stroke'} ne 'transparent' && $style->{'stroke-width'} // !0) { } 0 0 0
elsif ($style->{'fill'} and $style->{'fill'} ne 'none' and $style->{'fill'} ne 'transparent') { } 0 0 0
Condition0%0/11
$style->{"stroke"} && $style->{"stroke"} ne "none" && $style->{"stroke"} ne "transparent" && $style->{"stroke-width"} //
l!l
00
$style->{"stroke"} and $style->{"stroke"} ne "none" and $style->{"stroke"} ne "transparent" and $style->{"stroke-width"}
!ll&&!rl&&r
000
$style->{"stroke"} and $style->{"stroke"} ne "none" and $style->{"stroke"} ne "transparent"
!ll&&!rl&&r
000
$style->{"stroke"} and $style->{"stroke"} ne "none"
!ll&&!rl&&r
000
MC/DC0%0/4
$style->{"stroke"} && $style->{"stroke"} ne "none" && $style->{"stroke"} ne "transparent" && $style->{"stroke-width"} //
$style->{"stroke"} $style->{"stroke"} ne "none" $style->{"stroke"} ne "transparent" $style->{"stroke-width"}
Truth table0%0/5
A and B and C and D
A= $style->{"stroke"}B= $style->{"stroke"} ne "none"C= $style->{"stroke"} ne "transparent"D= $style->{"stroke-width"}
ABCDresult
11111
0XXX0
10XX0
110X0
11100
227 && $style->{stroke} ne 'none'
228 && $style->{stroke} ne 'transparent'
229 # Hmm. Saw a note somewhere that it defaults to 0 but other notes
230 # say that it should be 1px...
231 && $style->{'stroke-width'}//1 != 0
232 ) {
233 0 ▶ if ( $style->{fill}
Branch: 1 branch
BranchTrueFalseTotal
if ($style->{'fill'} and $style->{'fill'} ne 'none' and $style->{'fill'} ne 'transparent') { } 0 0 0
Condition0%0/6
$style->{"fill"} and $style->{"fill"} ne "none" and $style->{"fill"} ne "transparent"
!ll&&!rl&&r
000
$style->{"fill"} and $style->{"fill"} ne "none"
!ll&&!rl&&r
000
MC/DC0%0/3
$style->{"fill"} and $style->{"fill"} ne "none" and $style->{"fill"} ne "transparent"
$style->{"fill"} $style->{"fill"} ne "none" $style->{"fill"} ne "transparent"
Truth table0%0/4
A and B and C
A= $style->{"fill"}B= $style->{"fill"} ne "none"C= $style->{"fill"} ne "transparent"
ABCresult
0XX0
10X0
1100
1111
234 && $style->{fill} ne 'none'
235 && $style->{fill} ne 'transparent'
236 ) {
237 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
238 $self->_dbg("xo paint (",
239 0 join(" ", $style->{stroke}, $style->{fill} ), ")");
240 0 $xo->paint;
241 0 };
242 }
243 else {
244 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
245 0 $self->_dbg("xo stroke (", $style->{stroke}, ")");
246 0 $xo->stroke;
247 0 };
248 }
249 }
250 ▶ elsif ( $style->{fill}
Condition0%0/6
$style->{"fill"} and $style->{"fill"} ne "none" and $style->{"fill"} ne "transparent"
!ll&&!rl&&r
000
$style->{"fill"} and $style->{"fill"} ne "none"
!ll&&!rl&&r
000
MC/DC0%0/3
$style->{"fill"} and $style->{"fill"} ne "none" and $style->{"fill"} ne "transparent"
$style->{"fill"} $style->{"fill"} ne "none" $style->{"fill"} ne "transparent"
Truth table0%0/4
A and B and C
A= $style->{"fill"}B= $style->{"fill"} ne "none"C= $style->{"fill"} ne "transparent"
ABCresult
0XX0
10X0
1100
1111
251 && $style->{fill} ne 'none'
252 && $style->{fill} ne 'transparent'
253 ) {
254 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
255 0 $self->_dbg("xo fill (", $style->{stroke}, ")");
256 0 $xo->fill;
257 0 };
258 }
259 else {
260 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
261 0 $self->_dbg("xo end");
262 0 $xo->end;
263 }
264 0 }
265 12 }
266  
267 0 ▶method process () {
Subroutine process: not called CC=3 SCAR=24.8
Pod undocumented
268 # Unless overridden in a subclass there's not much we can do.
269 0 state $warned = { desc => 1, title => 1, metadata => 1 };
270 warn("SVG: Skipping element \"$name\" (not implemented)\n")
271 0 ▶ unless $warned->{$name}++ || !$self->root->verbose;
Branch: 1 branch
BranchTrueFalseTotal
unless $warned->{$name}++ or not $self->root->verbose 0 0 0
Condition0%0/3
$warned->{$name}++ or not $self->root->verbose
l!l&&r!l&&!r
000
MC/DC0%0/2
$warned->{$name}++ or not $self->root->verbose
$warned->{$name}++ not $self->root->verbose
Truth table0%0/3
A or not(B)
A= $warned->{$name}++B= not $self->root->verbose
ABresult
1X1
011
000
272 0 $self->_dbg("skipping $name (not implemented)");
273 # $self->traverse;
274 12 }
275  
276 0 ▶method get_children () {
Subroutine get_children: not called CC=5 SCAR=34.0
Pod undocumented
277  
278 # Note: This is the only place where these objects are created.
279  
280 0 my @res;
281 0 for my $e ( @{$self->content} ) {
282 0 ▶ if ( $e->{type} eq 'e' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($e->{'type'} eq 'e') { } 0 0 0
elsif ($e->{'type'} eq 't') { } 0 0 0
283 0 my $pkg = "SVGPDF::" . ucfirst(lc $e->{name});
284 0 ▶ $pkg = "SVGPDF::Element" unless $pkg->can("process");
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg->can("process") 0 0 0
285 push( @res, $pkg->new
286 ( name => $e->{name},
287 0 atts => { map { lc($_) => $e->{attrib}->{$_} } keys %{$e->{attrib}} },
288 content => $e->{content},
289 0 root => $self->root,
290 ) );
291 }
292 elsif ( $e->{type} eq 't' ) {
293 push( @res, SVGPDF::TextElement->new
294 ( content => $e->{content},
295 0 ) );
296 }
297 else {
298 # Basically a 'cannot happen',
299 0 croak("Unhandled node type ", $e->{type});
300 }
301 }
302 0 return @res;
303 12 }
304  
305 0 ▶method traverse () {
Subroutine traverse: not called CC=3 SCAR=24.8
Pod undocumented
306 0 for my $c ( $self->get_children ) {
307 0 ▶ next if ref($c) eq "SVGPDF::TextElement";
Branch: 1 branch
BranchTrueFalseTotal
if ref $c eq "SVGPDF::TextElement" 0 0 0
308 0 $self->_dbg("+ start handling ", $c->name, " (", ref($c), ")");
309 0 $c->process;
310 0 $self->_dbg("- end handling ", $c->name);
311 }
312 12 }
313  
314 0 ▶method u ( $a, %args ) {
Subroutine u: not called CC=17 SCAR=57.2
Pod undocumented
315 0 ▶ confess("Undef in units") unless defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 0 0
316  
317 # Pixels per point. Usually 96/72.
318 0 my $pxpt = $self->root->pxpi / $self->root->ptpi;
319  
320 0 ▶ return undef unless $a =~ /^([-+]?[\d.]+)(.*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $a =~ /^([-+]?[\d.]+)(.*)$/u 0 0 0
321 0 ▶ return $1*$pxpt if $2 eq "pt";
Branch: 1 branch
BranchTrueFalseTotal
if $2 eq "pt" 0 0 0
322  
323 # default is px
324 0 ▶ return $1 if $2 eq "" || $2 eq "px";
Branch: 1 branch
BranchTrueFalseTotal
if $2 eq "" or $2 eq "px" 0 0 0
Condition0%0/3
$2 eq "" or $2 eq "px"
l!l&&r!l&&!r
000
MC/DC0%0/2
$2 eq "" or $2 eq "px"
$2 eq "" $2 eq "px"
Truth table0%0/3
A or B
A= $2 eq ""B= $2 eq "px"
ABresult
1X1
011
000
325  
326 # 1 inch = pxpi px.
327 0 ▶ return $1/2.54 * $self->root->pxpi if $2 eq "cm";
Branch: 1 branch
BranchTrueFalseTotal
if $2 eq "cm" 0 0 0
328 0 ▶ return $1/25.4 * $self->root->pxpi if $2 eq "mm";
Branch: 1 branch
BranchTrueFalseTotal
if $2 eq "mm" 0 0 0
329 0 ▶ return $1 * $self->root->pxpi if $2 eq "in";
Branch: 1 branch
BranchTrueFalseTotal
if $2 eq "in" 0 0 0
330  
331 0 ▶ if ( $2 eq '%' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq "%") 0 0 0
332 0 ▶ my $w = $args{width} || $self->root->xoforms->[-1]->{diag};
Condition0%0/3
$args{'width'} || $self->root->xoforms->[-1]{'diag'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'width'} || $self->root->xoforms->[-1]{'diag'}
$args{'width'} $self->root->xoforms->[-1]{'diag'}
Truth table0%0/3
A || B
A= $args{'width'}B= $self->root->xoforms->[-1]{'diag'}
ABresult
1X1
011
000
333 0 return $1/100 * $w * $pxpt;
334 }
335 # Font dependent.
336 # CSS defines em to be the font size.
337 0 ▶ if ( $2 eq "em" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq "em") 0 0 0
338 return $1 * ( $args{fontsize}
339 0 ▶ || $style->{'font-size'}
Condition0%0/6
$args{'fontsize'} || $style->{'font-size'} || $self->root->fontsize
l!l&&r!l&&!r
000
$args{"fontsize"} or $style->{"font-size"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'fontsize'} || $style->{'font-size'} || $self->root->fontsize
$args{"fontsize"} $style->{"font-size"} $self->root->fontsize
Truth table0%0/4
A or B || C
A= $args{"fontsize"}B= $style->{"font-size"}C= $self->root->fontsize
ABCresult
1XX1
01X1
0011
0000
340 || $self->root->fontsize );
341 }
342 # CSS defines ex to be half the font size.
343 0 ▶ if ( $2 eq "ex" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq "ex") 0 0 0
344 return $1 * 0.5 * ( $args{fontsize}
345 0 ▶ || $style->{'font-size'}
Condition0%0/6
$args{'fontsize'} || $style->{'font-size'} || $self->root->fontsize
l!l&&r!l&&!r
000
$args{"fontsize"} or $style->{"font-size"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'fontsize'} || $style->{'font-size'} || $self->root->fontsize
$args{"fontsize"} $style->{"font-size"} $self->root->fontsize
Truth table0%0/4
A or B || C
A= $args{"fontsize"}B= $style->{"font-size"}C= $self->root->fontsize
ABCresult
1XX1
01X1
0011
0000
346 || $self->root->fontsize );
347 }
348  
349 0 confess("Unhandled units in \"$a\"");
350 0 return $a; # will hopefully crash somewhere...
351 12 }
352  
353 0 ▶method getargs ( $a ) {
Subroutine getargs: not called CC=2 SCAR=17.9
Pod undocumented
354 0 ▶ confess("Null attr?") unless defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 0 0
355 0 $a =~ s/^\s+//;
356 0 $a =~ s/\s+$//;
357 0 map { $self->u($_) } split( /\s*[,\s]\s*/, $a );
358 12 }
359  
360 # Initial fiddling with entity attributes.
361 0 ▶method get_params ( @desc ) {
Subroutine get_params: not called CC=18 SCAR=58.3
Pod undocumented
362 0 ▶ my $atts = shift(@desc) if ref($desc[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $desc[0] eq "HASH" 0 0 0
363 0 my @res;
364 0 ▶ my %atts = %{ $atts // $self->atts }; # copy
Condition0%0/3
$atts // $self->atts
l!l&&r!l&&!r
000
MC/DC0%0/2
$atts // $self->atts
$atts $self->atts
Truth table0%0/3
A // B
A= $attsB= $self->atts
ABresult
1X1
011
000
365  
366 # xlink:href is obsoleted in favour of href.
367 0 ▶ $atts{href} //= delete $atts{"xlink:href"} if exists $atts{"xlink:href"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $atts{"xlink:href"} 0 0 0
Condition0%0/3
$atts{"href"} //= delete $atts{"xlink:href"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$atts{"href"} //= delete $atts{"xlink:href"}
$atts{"href"} delete $atts{"xlink:href"}
Truth table0%0/3
A //= B
A= $atts{"href"}B= delete $atts{"xlink:href"}
ABresult
1X1
011
000
368  
369 0 my @todo;
370 0 for my $param ( @desc ) {
371  
372 # Attribute may be followed by ':' and flags.
373 # 0 undef -> 0
374 # h process units, % is viewBox height
375 # s undef -> ""
376 # u process units
377 # v process units, % is viewBox width
378 # U undef -> 0, process units
379 # ! barf if undef
380 0 my $flags = "";
381 0 ▶ ( $param, $flags ) = ( $1, $2 )
Branch: 1 branch
BranchTrueFalseTotal
if $param =~ /^(.*):(.*)$/u 0 0 0
382 if $param =~ /^(.*):(.*)$/;
383 0 $param = lc($param);
384  
385 # Get and remove the attribute.
386 0 my $p = delete( $atts{$param} );
387  
388 # Queue.
389 0 push( @todo, [ $param, $flags, $p ] );
390 }
391  
392 # CSS push with updated attributes.
393 0 $self->css_push( \%atts );
394  
395 # Now we can process the values.
396 0 for ( @todo ) {
397 0 my ( $param, $flags, $p ) = @$_;
398  
399 0 ▶ unless ( defined $p ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $p) 0 0 0
400 0 ▶ if ( $flags =~ /s/ ) { $p = ""; }
Branch: 2 branches
BranchTrueFalseTotal
if ($flags =~ /s/u) { } 0 0 0
elsif ($flags =~ /[0HUV]/u) { } 0 0 0
401 0 elsif ( $flags =~ /[0HUV]/ ) { $p = 0; }
402 else {
403 0 ▶ croak("Undefined mandatory attribute: $param")
Branch: 1 branch
BranchTrueFalseTotal
if $flags =~ /\!/u 0 0 0
404 if $flags =~ /\!/;
405 0 push( @res, $p );
406 0 next;
407 }
408 }
409  
410 0 $flags = lc($flags);
411 # Convert units if 'u' flag.
412 0 ▶ if ( $flags =~ /([huv])/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags =~ /([huv])/u) 0 0 0
413 0 my $flag = $1;
414 0 ▶ if ( $p =~ /^([\d.]+)\%$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ /^([\d.]+)\%$/u) { } 0 0 0
415 0 $p = $1/100;
416 0 ▶ if ( $flags eq "w" || $param =~ /^(?:w(?:idth)|x)?$/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($flags eq 'w' or $param =~ /^(?:w(?:idth)|x)?$/iu) { } 0 0 0
elsif ($flag eq 'h' or $param =~ /^(?:h(?:eight)?|y)$/iu) { } 0 0 0
Condition0%0/3
$flags eq "w" or $param =~ /^(?:w(?:idth)|x)?$/iu
l!l&&r!l&&!r
000
MC/DC0%0/2
$flags eq "w" or $param =~ /^(?:w(?:idth)|x)?$/iu
$flags eq "w" $param =~ /^(?:w(?:idth)|x)?$/iu
Truth table0%0/3
A or B
A= $flags eq "w"B= $param =~ /^(?:w(?:idth)|x)?$/iu
ABresult
1X1
011
000
417 # Percentage of viewBox width.
418 0 $p *= $root->xoforms->[-1]->{width};
419 }
420 ▶ elsif ( $flag eq "h" || $param =~ /^(?:h(?:eight)?|y)$/i ) {
Condition0%0/3
$flag eq "h" or $param =~ /^(?:h(?:eight)?|y)$/iu
l!l&&r!l&&!r
000
MC/DC0%0/2
$flag eq "h" or $param =~ /^(?:h(?:eight)?|y)$/iu
$flag eq "h" $param =~ /^(?:h(?:eight)?|y)$/iu
Truth table0%0/3
A or B
A= $flag eq "h"B= $param =~ /^(?:h(?:eight)?|y)$/iu
ABresult
1X1
011
000
421 # Percentage of viewBox height.
422 0 $p *= $root->xoforms->[-1]->{height};
423 }
424 else {
425 # Percentage of viewBox diagonal.
426 0 $p *= $root->xoforms->[-1]->{diag};
427 }
428 }
429 else {
430 0 $p = $self->u($p);
431 }
432 }
433  
434 0 push( @res, $p );
435 }
436  
437 # Return param values.
438 0 return @res;
439 12 }
440  
441 0 ▶method get_cdata () {
Subroutine get_cdata: not called CC=3 SCAR=24.8
Pod undocumented
442 0 my $res = "";
443 0 for ( $self->get_children ) {
444 0 ▶ $res .= "\n" . $_->content if ref($_) eq "SVGPDF::TextElement";
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ eq "SVGPDF::TextElement" 0 0 0
445 }
446 0 $res;
447 12 }
448  
449 0 ▶method nfi ( $tag ) {
Subroutine nfi: not called CC=3 SCAR=24.8
Pod undocumented
450 0 state $aw = {};
451 warn("SVG: $tag - not fully implemented, expect strange results.\n")
452 0 ▶ unless !$self->root->verbose || $aw->{$tag}++;
Branch: 1 branch
BranchTrueFalseTotal
unless not $self->root->verbose or $aw->{$tag}++ 0 0 0
Condition0%0/3
not $self->root->verbose or $aw->{$tag}++
l!l&&r!l&&!r
000
MC/DC0%0/2
not $self->root->verbose or $aw->{$tag}++
not $self->root->verbose $aw->{$tag}++
Truth table0%0/3
not(A) or B
A= not $self->root->verboseB= $aw->{$tag}++
ABresult
1X1
011
000
453 12 }
454  
455 0 ▶method set_font ( $xo, $style ) {
Subroutine set_font: not called CC=3 SCAR=24.8
Pod undocumented
456 0 my $msg ="";
457 0 my $ret;
458 {
459 0 ▶ local $SIG{__WARN__} = sub { $msg .= "@_" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
460 0 $ret = $self->root->fontmanager->set_font( $xo, $style );
461 }
462 0 ▶ if ( $msg && $self->root->verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg and $self->root->verbose) 0 0 0
Condition0%0/3
$msg and $self->root->verbose
!ll&&!rl&&r
000
MC/DC0%0/2
$msg and $self->root->verbose
$msg $self->root->verbose
Truth table0%0/3
A and B
A= $msgB= $self->root->verbose
ABresult
0X0
100
111
463 0 warn($msg);
464 }
465 0 $ret;
466 12 }
467  
468 ################ Bounding Box ################
469  
470 # method bb ( $x, $y, $t = 0 ) {
471 # my $bb = $self->root->xoforms->[-1]->{bb};
472 #
473 # $t = $self->u($t) unless $t =~ /^[-+]?\d*(?:\.\d*)$/;
474 # $t /= 2;
475 # $bb->[0] = $x-$t if $bb->[0] > $x-$t;
476 # $bb->[1] = $y-$t if $bb->[1] > $y-$t;
477 # $bb->[2] = $x+$t if $bb->[2] < $x+$t;
478 # $bb->[3] = $y+$t if $bb->[3] < $y+$t;
479 #
480 # return $bb;
481 # }
482 #
483  
484 ################ Utility ################
485  
486 0 ▶method data_inline($src) {
Subroutine data_inline: not called CC=3 SCAR=24.8
Pod undocumented
487  
488 0 my %info;
489  
490 0 ▶ unless ( $src =~ m! ^ data:
Branch: 1 branch
BranchTrueFalseTotal
unless ($src =~ m[ ^ data: (?<mimetype> [^/]+ ) / (?<subtype> [^;]+ ) ; (?<encoding> [^,]+ ) , (?<data> . + ) $ ]sux) 0 0 0
491 (?<mimetype> [^/]+ ) /
492 (?<subtype> [^;]+ ) ;
493 (?<encoding> [^,]+ ) ,
494 (?<data> . + ) $
495 !sx ) {
496 0 return { error => "Malformed inline data" };
497 }
498  
499 0 ▶ if ( $+{encoding} eq "base64" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($+{'encoding'} eq 'base64') { } 0 0 0
500 0 require MIME::Base64;
501 0 $info{data} = MIME::Base64::decode($+{data});
502 }
503 else {
504 0 return { error => "Unhandled encoding \"$+{encoding}\" in inline data" };
505 }
506  
507 0 $info{mimetype} = $+{mimetype};
508 0 $info{subtype} = $+{subtype};
509  
510 0 return \%info;
511 12 }
512  
513 ################ TextElement ################
514  
515 class SVGPDF::TextElement;
516  
517 0 ▶field $content :param :accessor;
Subroutine content: not called CC=2 SCAR=11.6
Branch: 1 branch
BranchTrueFalseTotal
@_ and $content = shift() 0 0 0
518  
519 # Actually, we should take style->{white-space} into account...
520 BUILD {
521 # Reduce whitespace.
522 $content =~ s/\s+/ /g;
523 }
524  
525 0 ▶method process () {
Subroutine process: not called CC=1 SCAR=2.6
526 # Nothing to process.
527 12 }
528  
529 12 1;
« blib/lib/ChordPro/Delegate/Lilypond.pm ↑ Summary lib/ChordPro/Output/Text.pm »