lib/ChordPro/Output/PDF/StringDiagram.pm

filter: Statementstmt 84.8% 235 / 277 Branchbran 54.4% 49 / 90 Conditioncond 45.2% 19 / 42 MC/DCmcdc 7.6% 2 / 26 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 9 totaltotal 69.4% 318 / 458 CC 75 SCAR 50.3
CC
75
Cov
74%
diagram_xo
216.9
hsp
6.0
draw
4.0
CRAP 153.7
« lib/ChordPro/Config.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Rect.pm »
1 #! perl
2  
3 10 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 my $dcache; # cache core grids
8 10 my $pdf = ""; # for cache flush
9  
10 class ChordPro::Output::PDF::StringDiagram;
11  
12 10 field $pr :param;
13  
14 10 field $config;
15 10 field $ps;
16  
17 10 field $gw; # width of a cell, pt
18 10 field $gh; # height of a cell, pt
19 10 field $lw; # fraction of cell width
20 10 field $nutwidth; # width (in linewidth) of the top nut
21 10 field $nw; # extra width for the top nut, pt
22 10 field $vc; # cells, vertical
23 10 field $strings; # number of strings
24 10 field $hc; # cells, horizontal (= strings)
25 10 field $dot; # dot size, fraction of cell width
26 10 field $bsz; # barre size, fraction of dot
27 10 field $bstyle; # barre style ("line", "arc")
28 10 field $fsh; # show fingers (0, 1, "below")
29 10 field $fg; # foreground color
30 10 field $bg; # background color
31 10 field $fbp; # fret base position ("left", "right")
32 10 field $fbt; # fret base text ("%s" is default)
33  
34 ADJUST {
35 $config = $::config;
36 $ps = $pr->{ps};
37 $strings = $config->diagram_strings;
38 my $ctl = $ps->{diagrams};
39 $gw = $ctl->{width} || 6;
40 $gh = $ctl->{height} || 6;
41 $lw = ($ctl->{linewidth} || 0.10) * $gw;
42 $nutwidth = $ctl->{nutwidth} || 1;
43 $nw = ($nutwidth-1) * $lw;
44 $vc = $ctl->{vcells} || 4;
45 $hc = $strings;
46 $dot = $ctl->{dotsize} * ( $gh < $gw ? $gh : $gw );
47 $bsz = $ctl->{barwidth} * $dot;
48 $bstyle = $ctl->{barstyle} || "line";
49 $fsh = $ctl->{fingers} || 0;
50 $fbp = $ctl->{fretbaseposition} || "left";
51 $fbt = $ctl->{fretbasetext} || "%s";
52 $dcache = {} if $pr->{pdf} ne $pdf;
53 $pdf = $pr->{pdf};
54 }
55  
56 10 ▶use constant DIAG_DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 # The vertical space the diagram requires.
59 27 ▶method vsp0( $elt, $dummy = 0 ) {
Subroutine vsp0: called CC=3 SCAR=11.0
Pod undocumented
60 $ps->{fonts}->{diagram}->{size} * $ps->{spacing}->{diagramchords}
61 + $nutwidth * $lw + 0.40 * $gw
62 + $vc * $gh
63 27 ▶ + ( $fsh eq "below" ? $ps->{fonts}->{diagram}->{size} : 0 )
Branch: 1 branch
BranchTrueFalseTotal
$fsh eq 'below' ? : 0 27 27
64 ;
65 10 }
66  
67 # The advance height.
68 54 ▶method vsp1( $elt, $dummy = 0 ) {
Subroutine vsp1: called CC=2 SCAR=6.9
Pod undocumented
69 54 $ps->{diagrams}->{vspace} * $gh;
70 10 }
71  
72 # The vertical space the diagram requires, including advance height.
73 27 ▶method vsp( $elt, $dummy = 0 ) {
Subroutine vsp: called CC=2 SCAR=6.9
Pod undocumented
74 27 $self->vsp0($elt) + $self->vsp1($elt);
75 10 }
76  
77 # The horizontal space the diagram requires.
78 27 ▶method hsp0( $elt, $dummy = 0 ) {
Subroutine hsp0: called CC=2 SCAR=6.9
Pod undocumented
79 27 ($strings - 1) * $gw;
80 10 }
81  
82 # The advance width.
83 27 ▶method hsp1( $elt, $dummy = 0 ) {
Subroutine hsp1: called CC=2 SCAR=6.9
Pod undocumented
84 27 $ps->{diagrams}->{hspace} * $gw;
85 10 }
86  
87 # The horizontal space the diagram requires, including advance width.
88 0 ▶method hsp( $elt, $dummy = 0 ) {
Subroutine hsp: not called CC=2 SCAR=17.9
Pod undocumented
89 0 $self->hsp0($elt) + $self->hsp1($elt);
90 10 }
91  
92 # The actual draw method.
93 54 ▶method draw( $info, $x, $y, $dummy=0 ) {
Subroutine draw: called CC=4 SCAR=13.9
Pod undocumented
94 54 ▶ return unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 54 54
95  
96 54 my $font = $ps->{fonts}->{diagram};
97  
98 54 my $xo = $self->diagram_xo($info);
99 54 my @bb = $xo->bbox;
100 54 warn("BB [ @bb ] $x $y\n") if DIAG_DEBUG;
101 $pr->{pdfgfx}->object( $xo, $x,
102  
103 54 $y - ($font->{size} * $ps->{spacing}->{diagramchords} + $dot + $lw) );
104  
105 # Draw name.
106 54 my $w = $gw * ($strings - 1);
107 54 $pr->setfont($font);
108 54 my $name = $info->chord_display;
109 $name = "<span color='$fg'>$name</span>"
110 54 ▶ if $info->{diagram};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"diagram"} 0 54 54
111 54 $pr->text( $name, $x + ($w - $pr->strwidth($name))/2,
112 $y-$pr->font_bl($font));#+$font->{fd}->{ascender}/1000 );
113 10 }
114  
115 # Returns the complete diagram as an xo. This includes the core grid,
116 # finger/fret positions, open and muted string indicators.
117 # The bounding box includes space form the open and muted string indicators
118 # and dots on the first and last strings, even when absent.
119 # The bbox includes basefret and fingers (below) if present.
120 # Origin is top left of the grid.
121 # Note that the chord name is not part of the diagram.
122  
123 54 ▶method diagram_xo( $info ) {
Subroutine diagram_xo: called CC=62 SCAR=53.8
Pod undocumented
124 54 ▶ return unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 54 54
125 54 ▶ $fg = $info->{diagram} // $config->{pdf}->{theme}->{foreground};
Condition33%1/3
$info->{"diagram"} // $config->{"pdf"}{"theme"}{"foreground"}
l!l&&r!l&&!r
0540
MC/DC0%0/2
$info->{"diagram"} // $config->{"pdf"}{"theme"}{"foreground"}
$info->{"diagram"} $config->{"pdf"}{"theme"}{"foreground"}
Truth table33%1/3
A // B
A= $info->{"diagram"}B= $config->{"pdf"}{"theme"}{"foreground"}
ABresult
1X1
011
000
126 54 $bg = $config->{pdf}->{theme}->{background};
127  
128 # Set default options for safety if they have not already been set
129 54 ▶ $fg = "black" if $fg eq "none";
Branch: 1 branch
BranchTrueFalseTotal
if $fg eq "none" 0 54 54
130 54 ▶ $bg = "white" if $bg eq "none";
Branch: 1 branch
BranchTrueFalseTotal
if $bg eq "none" 54 0 54
131  
132 54 my $x = 0;
133 54 my $w = $gw * ($strings - 1);
134 54 ▶ my $baselabeloffset = $info->{baselabeloffset} || 0;
Condition50%1/2
$info->{'baselabeloffset'} || 0
l!l
054
MC/DC0%0/1
$info->{'baselabeloffset'} || 0
$info->{'baselabeloffset'}
Truth table50%1/2
A
A= $info->{'baselabeloffset'}
Aresult
11
00
135 54 my $basefretno = $info->{base} + $baselabeloffset;
136 54 my $basefrettext=""; # for base label
137 54 my $basefont; # for base label
138 my $basesize; # for base label
139  
140 # Get the core grid.
141 54 my $xg = $self->grid_xo;
142 54 my @xgbb = $xg->bbox;
143  
144 54 my $xo = $pdf->xo_form;
145 54 my @bb = ( 0,
146 0.77 * $dot + 2*$lw,
147 $w + $dot/2,
148 $xgbb[3] );
149  
150 54 ▶ if ( $basefretno > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($basefretno > 1) { } 0 54 54
151 0 $basefont = $ps->{fonts}->{diagram_base}->{fd}->{font};
152 0 $basesize = $gh/0.85;
153 0 my $basefretformat = $fbt;
154 0 ▶ $basefretformat = '%s' unless $basefretformat =~ /^[^%]*\%s[^%]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $basefretformat =~ /^[^%]*\%s[^%]*$/u 0 0 0
155 0 $basefrettext = sprintf($basefretformat, $basefretno);
156  
157 0 ▶ if ( $fbp eq "left" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fbp eq 'left') { } 0 0 0
158 0 $bb[0] -= $basefont->width("xx$basefrettext") * $basesize;
159 }
160 else {
161 #fret base position on "right" side
162 0 $bb[0] -= $dot/2;
163 0 $bb[2] += $basefont->width("xx$basefrettext") * $basesize;
164 }
165 }
166 else {
167 54 $bb[0] -= $dot/2;
168 }
169 54 ▶ if ( $fsh eq "below" && $info->{fingers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fsh eq "below" and $info->{"fingers"}) 0 54 54
Condition33%1/3
$fsh eq "below" and $info->{"fingers"}
!ll&&!rl&&r
5400
MC/DC0%0/2
$fsh eq "below" and $info->{"fingers"}
$fsh eq "below" $info->{"fingers"}
Truth table33%1/3
A and B
A= $fsh eq "below"B= $info->{"fingers"}
ABresult
0X0
100
111
170 0 $bb[3] -= $gh + $lw;
171 }
172 54 $xo->bbox(@bb);
173 54 $xo->line_width($lw);
174 54 $xo->stroke_color($fg);
175 54 $xo->fill_color($fg);
176  
177 54 if ( DIAG_DEBUG ) {
178 # Draw the grid.
179 $xo->save;
180 $xo->fill_color('yellow');
181 $xo->rectangle($xo->bbox)->fill;
182 $xo->object( $xg, 0, 0, 1 );
183 $xo->fill_color('red');
184 my $lw = $lw/2;
185 $xo->rectangle( -$lw, -$lw, $lw, $lw )->fill;
186 $xo->restore;
187 }
188 else {
189 54 $xo->object( $xg, 0, 0, 1 );
190 }
191  
192 # Draw extended nut if base = 1.
193 54 ▶ if ( $info->{base} <= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"base"} <= 1) 54 0 54
194 54 ▶ if ( $nutwidth > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nutwidth > 1) 54 0 54
195 54 for ( 0 .. $nutwidth-2 ) {
196 216 $xo->move( -$lw/2, -$_*$lw );
197 216 $xo->hline( $w + $lw/2 );
198 }
199 54 $xo->stroke;
200 }
201 }
202  
203 # Draw first fret number, if > 1.
204 54 ▶ if ( $basefretno > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($basefretno > 1) 0 54 54
205 0 $xo->textstart;
206 0 $xo->font( $basefont, $basesize );
207  
208 0 ▶ if ( $fbp eq "left" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fbp eq 'left') { } 0 0 0
209 0 $xo->translate( -$basefont->width("x") * 0.85 * $basesize,
210 -$nw - ($baselabeloffset+0.85)*$gh );
211 0 $xo->text( $basefrettext, align => "right" );
212 }
213 else {
214 #fret base position on "right" side
215 0 $xo->translate( ($strings-1)*$gw + $basefont->width("x") * 0.85 * $basesize,
216 -$nw - ($baselabeloffset+0.85)*$gh );
217 0 $xo->text( $basefrettext, align => "left" );
218 }
219  
220 0 $xo->textend;
221 }
222  
223 54 my $fingers;
224 54 ▶ $fingers = $info->{fingers} if $fsh;
Branch: 1 branch
BranchTrueFalseTotal
if $fsh 54 0 54
225  
226 # Bar detection.
227 54 my $bar = {};
228 54 ▶ if ( $fingers ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fingers) 54 0 54
229 54 my %h;
230 54 my $str = 0;
231 54 my $got = 0;
232  
233 54 foreach ( @{ $fingers } ) {
234 324 ▶ $str++, next unless $info->{frets}->[$str] > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{"frets"}[$str] > 0 108 216 324
235 216 ▶ if ( $bar->{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bar->{$_}) { } 27 189 216
236 # Same finger on multiple strings -> bar.
237 27 $got++;
238 27 $bar->{$_}->[-1] = $str;
239 }
240 else {
241 # Register.
242 189 $bar->{$_} = [ $_, $info->{frets}->[$str], $str, $str ];
243 }
244 216 $str++;
245 }
246  
247 54 ▶ if ( $got ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got) 27 27 54
248 27 $xo->save;
249
250 27 ▶ if ( $bstyle eq "line" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bstyle eq 'line') { } 27 0 27
251 27 $xo->line_width($bsz)->line_cap(0);
252 }
253 else {
254 # bar in "arc" style.
255 0 $xo->line_width($lw+0.2);
256 }
257  
258 27 foreach ( sort keys %$bar ) {
259 108 my @bi = @{ $bar->{$_} };
260 # $bi array description = [finger, fret, first_string, last_string].
261  
262 108 ▶ if ( $bi[-2] == $bi[-1] ) { # not a bar
Branch: 1 branch
BranchTrueFalseTotal
if ($bi[-2] == $bi[-1]) 81 27 108
263 81 delete $bar->{$_};
264 81 next;
265 }
266  
267 27 ▶ if ( $bstyle eq "line" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bstyle eq 'line') { } 27 0 27
268 # Print the bar line.
269 27 $x = $bi[2]*$gw;
270 27 $xo->move( $x, -$nw -$bi[1]*$gh+$gh/2 );
271 27 $xo->hline( $x+($bi[3]-$bi[2])*$gw);
272 }
273 else {
274 # Print arcs for barre
275 0 my $arcw = (($bi[3]-$bi[2])*$gw + 0.7*$gw)/2;
276 0 my $arch = 0.4*$gw;
277 0 my $arcy = -$nw -$bi[1]*$gh +$gh+0.25*$gh;
278 0 my $arcx = $bi[2]*$gw - (0.7*$gw)/2;
279  
280 0 ▶ if ( $bi[1] == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bi[1] == 1) 0 0 0
281 # Bar is on the first fret so bar arcs
282 # must be drawn above the nut.
283 0 $arcy += $nw;
284 }
285  
286 # Draw first arc.
287 0 $xo->move( $arcx, $arcy );
288 0 $xo->arc( $arcx+$arcw, $arcy, $arcw, $arch, 180, 0 );
289  
290 # Draw second arc a little higher, this is
291 # a fast way to have narrower corners look at the arc edge.
292 0 $xo->move( $arcx, $arcy-0.8 );
293 0 $xo->arc( $arcx+$arcw, $arcy-0.8, $arcw, $arch, 180, 0 );
294 }
295  
296 27 $xo->stroke;
297 27 $xo->fill;
298 }
299 27 $xo->stroke->restore;
300 }
301 }
302  
303 54 my $oflo; # to detect out of range frets
304  
305 # Color of the dots and numbers.
306 54 my $fbg = ""; # numbers
307 54 my $ffg = $fg; # dots
308 # The numbercolor property of the chordfingers is used for the
309 # color of the dot numbers.
310 54 my $fcf = $ps->{fonts}->{chordfingers};
311 54 $fbg = $pr->_bgcolor($fcf->{numbercolor});
312 54 $ffg = $pr->_bgcolor($fcf->{color});
313  
314 54 ▶ if ( $fsh ne "below" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fsh ne 'below') { } 54 0 54
315 # However, if none we should really use "background" color.
316 54 ▶ $fbg = $bg if $fbg eq "none";
Branch: 1 branch
BranchTrueFalseTotal
if $fbg eq "none" 54 0 54
317 }
318 else {
319 # However, for "below" case if none or numbercolor equals background color we should really use "foreground".
320 0 ▶ $fbg = $fg if ( $fbg eq "none") || ( $fbg eq $bg );
Branch: 1 branch
BranchTrueFalseTotal
if $fbg eq "none" or $fbg eq $bg 0 0 0
Condition0%0/3
$fbg eq "none" or $fbg eq $bg
l!l&&r!l&&!r
000
MC/DC0%0/2
$fbg eq "none" or $fbg eq $bg
$fbg eq "none" $fbg eq $bg
Truth table0%0/3
A or B
A= $fbg eq "none"B= $fbg eq $bg
ABresult
1X1
011
000
321 }
322  
323 54 $x = -$gw;
324 54 for my $sx ( 0 .. $strings-1 ) {
325 324 $x += $gw;
326 324 my $fret = $info->{frets}->[$sx];
327 324 my $fing = -1;
328 324 ▶ $fing = $fingers->[$sx] // -1 if $fingers;
Branch: 1 branch
BranchTrueFalseTotal
if $fingers 324 0 324
Condition50%1/2
$fingers->[$sx] // -1
l!l
3240
MC/DC0%0/1
$fingers->[$sx] // -1
$fingers->[$sx]
Truth table50%1/2
A
A= $fingers->[$sx]
Aresult
11
00
329  
330 # For bars in "line" style, only the first and last finger.
331 324 ▶ if ( $fing && $bar->{$fing} && $bstyle eq "line" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fing and $bar->{$fing} and $bstyle eq "line") 135 189 324
Condition66%4/6
$fing and $bar->{$fing} and $bstyle eq "line"
!ll&&!rl&&r
1890135
$fing and $bar->{$fing}
!ll&&!rl&&r
0189135
MC/DC33%1/3
$fing and $bar->{$fing} and $bstyle eq "line"
$fing $bar->{$fing} $bstyle eq "line"
Truth table50%2/4
A and B and C
A= $fingB= $bar->{$fing}C= $bstyle eq "line"
ABCresult
0XX0
10X0
1100
1111
332 135 ▶ next unless $sx == $bar->{$fing}->[2] || $sx == $bar->{$fing}->[3];
Branch: 1 branch
BranchTrueFalseTotal
unless $sx == $bar->{$fing}[2] or $sx == $bar->{$fing}[3] 0 135 135
Condition66%2/3
$sx == $bar->{$fing}[2] or $sx == $bar->{$fing}[3]
l!l&&r!l&&!r
108270
MC/DC0%0/2
$sx == $bar->{$fing}[2] or $sx == $bar->{$fing}[3]
$sx == $bar->{$fing}[2] $sx == $bar->{$fing}[3]
Truth table66%2/3
A or B
A= $sx == $bar->{$fing}[2]B= $sx == $bar->{$fing}[3]
ABresult
1X1
011
000
333 }
334  
335 324 ▶ if ( $fret > 0 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($fret > 0) { } 216 108 324
elsif ($fret < 0) { } 54 54 108
elsif ($info->{'base'} > 0) { } 54 0 54
336 216 ▶ if ( $fret > $vc && !$oflo++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fret > $vc and not $oflo++) 0 216 216
Condition33%1/3
$fret > $vc and not $oflo++
!ll&&!rl&&r
21600
MC/DC0%0/2
$fret > $vc and not $oflo++
$fret > $vc not $oflo++
Truth table33%1/3
A and not(B)
A= $fret > $vcB= not $oflo++
ABresult
0X0
100
111
337 0 warn("Diagram $info->{name}: ",
338 "Fret position $fret exceeds diagram size $vc\n");
339 0 next;
340 }
341 216 $xo->fill_color($ffg);
342 216 $xo->circle( $x, -$nw - ($fret-0.5)*$gh, $dot/2 )->fill;
343  
344 }
345 elsif ( $fret < 0 ) {
346 54 $xo->move( $x - $dot/3, 0.77 * $dot + $lw );
347 54 $xo->line( $x + $dot/3, 0.1 * $gh + $lw );
348 54 $xo->move( $x + $dot/3, 0.77 * $dot + $lw );
349 54 $xo->line( $x - $dot/3, 0.1 * $gh + $lw );
350 54 $xo->stroke;
351 }
352 elsif ( $info->{base} > 0 ) {
353 54 $xo->circle( $x, 3.5*$gh/10 + $lw, $dot/3 )->stroke;
354 }
355 }
356  
357 # Show the fingers, if any.
358 54 ▶ if ( $fingers && @$fingers ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fingers and @$fingers) 54 0 54
Condition33%1/3
$fingers and @$fingers
!ll&&!rl&&r
0054
MC/DC0%0/2
$fingers and @$fingers
$fingers @$fingers
Truth table33%1/3
A and B
A= $fingersB= @$fingers
ABresult
0X0
100
111
359 54 my ( $font, $size );
360 54 $font = "chordfingers";
361 54 $size = $dot;
362 54 ▶ if ( $fsh eq "below" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fsh eq "below") 0 54 54
363 0 ▶ $size = $ps->{fonts}->{$font}->{size} // "00";
Condition0%0/2
$ps->{"fonts"}{$font}{"size"} // "00"
l!l
00
MC/DC0%0/1
$ps->{"fonts"}{$font}{"size"} // "00"
$ps->{"fonts"}{$font}{"size"}
Truth table0%0/2
A
A= $ps->{"fonts"}{$font}{"size"}
Aresult
11
00
364 0 ▶ $size = $dot if $size <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size <= 0 0 0 0
365 }
366 54 $font = $ps->{fonts}->{$font}->{fd}->{font};
367 54 warn("XXX ", $font->{' data'}->{fontname}, " $size\n") if DIAG_DEBUG;
368  
369 54 $x = -$gw;
370 54 my $did = 0;
371 54 for my $sx ( 0 .. $strings-1 ) {
372 #when "below", chord fingers should be always drawn and not take into account the dot color
373 324 ▶ last if ( $fsh ne "below" ) && ( $fbg eq $ffg );
Branch: 1 branch
BranchTrueFalseTotal
if $fsh ne "below" and $fbg eq $ffg 0 324 324
Condition33%1/3
$fsh ne "below" and $fbg eq $ffg
!ll&&!rl&&r
03240
MC/DC0%0/2
$fsh ne "below" and $fbg eq $ffg
$fsh ne "below" $fbg eq $ffg
Truth table33%1/3
A and B
A= $fsh ne "below"B= $fbg eq $ffg
ABresult
0X0
100
111
374 324 $x += $gw;
375 324 my $fret = $info->{frets}->[$sx];
376 324 ▶ next unless $fret > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $fret > 0 108 216 324
377 216 my $fing = uc $fingers->[$sx];
378 216 ▶ next unless $fing =~ /^[1-9A-Z]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $fing =~ /^[1-9A-Z]$/u 0 216 216
379  
380 # For barre, only the first and last finger.
381 216 ▶ if ( $bar->{$fing} && $fsh ne "below" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bar->{$fing} and $fsh ne "below") 135 81 216
Condition66%2/3
$bar->{$fing} and $fsh ne "below"
!ll&&!rl&&r
810135
MC/DC50%1/2
$bar->{$fing} and $fsh ne "below"
$bar->{$fing} $fsh ne "below"
Truth table66%2/3
A and B
A= $bar->{$fing}B= $fsh ne "below"
ABresult
0X0
100
111
382 next unless ( $sx == $bar->{$fing}->[2]
383 135 ▶ || $sx == $bar->{$fing}->[3] );
Branch: 1 branch
BranchTrueFalseTotal
unless $sx == $bar->{$fing}[2] or $sx == $bar->{$fing}[3] 0 135 135
Condition66%2/3
$sx == $bar->{$fing}[2] or $sx == $bar->{$fing}[3]
l!l&&r!l&&!r
108270
MC/DC0%0/2
$sx == $bar->{$fing}[2] or $sx == $bar->{$fing}[3]
$sx == $bar->{$fing}[2] $sx == $bar->{$fing}[3]
Truth table66%2/3
A or B
A= $sx == $bar->{$fing}[2]B= $sx == $bar->{$fing}[3]
ABresult
1X1
011
000
384 }
385  
386 216 ▶ unless ( $did++ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($did++) 54 162 216
387 54 ▶ if ( $fsh eq "below" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fsh eq "below") 0 54 54
388 0 $size *= 1.4;
389 }
390 54 $xo->fill_color($fbg);
391 54 $xo->textstart;
392 54 $xo->font( $font, $size );
393 }
394 216 ▶ if ( $fsh eq "below" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fsh eq 'below') { } 0 216 216
395 0 $xo->translate( $x, -$nw - $lw - ($vc+1)*$gh );
396 }
397 else {
398 216 $xo->translate( $x, -$nw - ($fret-0.5)*$gh - $dot/3 );
399 }
400 216 $xo->text( $fing, align => "center" );
401 }
402 54 ▶ $xo->textend if $did;
Branch: 1 branch
BranchTrueFalseTotal
if $did 54 0 54
403 }
404  
405 54 return $xo;
406 10 }
407  
408 # The core grid. Just the horizontal and vertical lines, with a fitting
409 # bounding box. Origin is (half linewidth from) top left.
410 # Grid objects are cached globally.
411  
412 10 ▶use constant DIAG_GRID_XO => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
413  
414 54 ▶method grid_xo {
Subroutine grid_xo: called CC=4 SCAR=13.9
Pod undocumented
415  
416 54 ▶ return $dcache->{$gw,$gh,$lw,$nw,$fg,$vc,$hc} //= do {
Condition66%2/3
$$dcache{join $;, $gw, $gh, $lw, $nw, $fg, $vc, $hc} //= do { my $w = $gw * ($hc - 1); my $h = $gh * $vc; my $xo = $pdf->xo_form; my $xp = 0; my(@bb) = (-$lw / 2 - $xp, $lw / 2 + $xp, $w + $lw / 2 + $xp, -($vc * $gh + $nw) - $lw / 2 - $xp); $xo->bbox(@bb); $xo->line_width($lw); '???'; $xo->stroke_color($fg); foreach $_ (0 .. $vc) { $xo->move(-$lw / 2, -$_ * $gh - $nw); $xo->hline($w + $lw / 2); } ; foreach $_ (0 .. $hc - 1) { $xo->move($_ * $gw, $lw / 2); $xo->vline(-($gh * $vc + $nw + $lw / 2)); } ; $xo->stroke; '???'; $xo }
l!l&&r!l&&!r
4590
MC/DC0%0/2
$$dcache{join $;, $gw, $gh, $lw, $nw, $fg, $vc, $hc} //= do { my $w = $gw * ($hc - 1); my $h = $gh * $vc; my $xo = $pdf->xo_form; my $xp = 0; my(@bb) = (-$lw / 2 - $xp, $lw / 2 + $xp, $w + $lw / 2 + $xp, -($vc * $gh + $nw) - $lw / 2 - $xp); $xo->bbox(@bb); $xo->line_width($lw); '???'; $xo->stroke_color($fg); foreach $_ (0 .. $vc) { $xo->move(-$lw / 2, -$_ * $gh - $nw); $xo->hline($w + $lw / 2); } ; foreach $_ (0 .. $hc - 1) { $xo->move($_ * $gw, $lw / 2); $xo->vline(-($gh * $vc + $nw + $lw / 2)); } ; $xo->stroke; '???'; $xo }
$$dcache{join $;, $gw, $gh, $lw, $nw, $fg, $vc, $hc} do { my $w = $gw * ($hc - 1); my $h = $gh * $vc; my $xo = $pdf->xo_form; my $xp = 0; my(@bb) = (-$lw / 2 - $xp, $lw / 2 + $xp, $w + $lw / 2 + $xp, -($vc * $gh + $nw) - $lw / 2 - $xp); $xo->bbox(@bb); $xo->line_width($lw); '???'; $xo->stroke_color($fg); foreach $_ (0 .. $vc) { $xo->move(-$lw / 2, -$_ * $gh - $nw); $xo->hline($w + $lw / 2); } ; foreach $_ (0 .. $hc - 1) { $xo->move($_ * $gw, $lw / 2); $xo->vline(-($gh * $vc + $nw + $lw / 2)); } ; $xo->stroke; '???'; $xo }
Truth table66%2/3
A //= B
A= $$dcache{join $;, $gw, $gh, $lw, $nw, $fg, $vc, $hc}B= do { my $w = $gw * ($hc - 1); my $h = $gh * $vc; my $xo = $pdf->xo_form; my $xp = 0; my(@bb) = (-$lw / 2 - $xp, $lw / 2 + $xp, $w + $lw / 2 + $xp, -($vc * $gh + $nw) - $lw / 2 - $xp); $xo->bbox(@bb); $xo->line_width($lw); '???'; $xo->stroke_color($fg); foreach $_ (0 .. $vc) { $xo->move(-$lw / 2, -$_ * $gh - $nw); $xo->hline($w + $lw / 2); } ; foreach $_ (0 .. $hc - 1) { $xo->move($_ * $gw, $lw / 2); $xo->vline(-($gh * $vc + $nw + $lw / 2)); } ; $xo->stroke; '???'; $xo }
ABresult
1X1
011
000
417  
418 9 my $w = $gw * ($hc - 1);
419 9 my $h = $gh * $vc;
420  
421 9 my $xo = $pdf->xo_form;
422  
423 # Bounding box must take linewidth into account.
424 # Origin is top left, so y runs negative.
425 9 my $xp = DIAG_GRID_XO ? 2 : 0;
426 9 my @bb = ( -$lw/2 - $xp, $lw/2 + $xp,
427 $w + $lw/2 + $xp, -($vc * $gh + $nw) - $lw/2 - $xp );
428 9 $xo->bbox(@bb);
429 9 $xo->line_width($lw);
430  
431 9 if ( DIAG_GRID_XO ) {
432 # Draw the grid.
433 $xo->fill_color('yellow');
434 $xo->rectangle(@bb)->fill;
435  
436 # Draw additional nuts.
437 if ( 0&& $nutwidth > 1 ) {
438 for ( 0 .. $nutwidth-2 ) {
439 $xo->stroke_color( $_ % 2 ? "#c0c0c0" : "#e0e0e0" );
440 $xo->move( -$lw/2, -$_*$lw );
441 $xo->hline( $w + $lw/2 )->stroke;
442 }
443 }
444 }
445  
446 9 $xo->stroke_color($fg);
447 9 for ( 0 .. $vc ) {
448 45 $xo->move( -$lw/2, -$_*$gh - $nw);
449 45 $xo->hline( $w + $lw/2 );
450 }
451 9 for ( 0 .. $hc-1 ) {
452 54 $xo->move( $_*$gw, $lw/2 );
453 54 $xo->vline( -($gh*$vc + $nw + $lw/2 ) );
454 }
455 9 $xo->stroke;
456  
457 9 if ( DIAG_GRID_XO ) {
458 # Show origin.
459 $xo->fill_color('red');
460 my $lw = $lw/2;
461 $xo->rectangle( -$lw, -$lw, $lw, $lw )->fill;
462 }
463  
464 9 $xo;
465 };
466 10 }
467  
468 10 1;
« lib/ChordPro/Config.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Rect.pm »