line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#! perl |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
65
|
use strict; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
707
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package main; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $config; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package ChordPro::Output::PDF::StringDiagrams; |
10
|
|
|
|
|
|
|
|
11
|
8
|
|
|
8
|
|
69
|
use ChordPro::Chords; |
|
8
|
|
|
|
|
25
|
|
|
8
|
|
|
|
|
17542
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
40
|
|
|
40
|
0
|
142
|
my ( $pkg, $ps ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
40
|
|
|
|
|
152
|
my $ctl = $ps->{kbdiagrams}; |
17
|
|
|
|
|
|
|
|
18
|
40
|
|
|
|
|
128
|
my $show = $ctl->{show}; |
19
|
40
|
50
|
|
|
|
299
|
unless ( $show =~ /^(?:top|bottom|right|below)$/i ) { |
20
|
0
|
|
|
|
|
0
|
die("pdf.diagrams.show is \"$show\", must be one of ". |
21
|
|
|
|
|
|
|
"\"top\", \"bottom\", \"right\", or \"below\"\n"); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
40
|
|
|
|
|
228
|
bless { ps => $ps } => $pkg; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# The vertical space the diagram requires. |
28
|
|
|
|
|
|
|
sub vsp0 { |
29
|
24
|
|
|
24
|
0
|
69
|
my ( $self, $elt, $ps ) = @_; |
30
|
|
|
|
|
|
|
$ps->{fonts}->{diagram}->{size} * $ps->{spacing}->{diagramchords} |
31
|
|
|
|
|
|
|
+ 0.40 * $ps->{diagrams}->{width} |
32
|
24
|
|
|
|
|
176
|
+ $ps->{diagrams}->{vcells} * $ps->{diagrams}->{height}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# The advance height. |
36
|
|
|
|
|
|
|
sub vsp1 { |
37
|
48
|
|
|
48
|
0
|
103
|
my ( $self, $elt, $ps ) = @_; |
38
|
48
|
|
|
|
|
150
|
$ps->{diagrams}->{vspace} * $ps->{diagrams}->{height}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# The vertical space the diagram requires, including advance height. |
42
|
|
|
|
|
|
|
sub vsp { |
43
|
24
|
|
|
24
|
0
|
71
|
my ( $self, $elt, $ps ) = @_; |
44
|
24
|
|
|
|
|
81
|
$self->vsp0( $elt, $ps ) + $self->vsp1( $elt, $ps ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# The horizontal space the diagram requires. |
48
|
|
|
|
|
|
|
sub hsp0 { |
49
|
48
|
|
|
48
|
0
|
113
|
my ( $self, $elt, $ps ) = @_; |
50
|
48
|
|
|
|
|
209
|
($config->diagram_strings - 1) * $ps->{diagrams}->{width}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# The advance width. |
54
|
|
|
|
|
|
|
sub hsp1 { |
55
|
72
|
|
|
72
|
0
|
171
|
my ( $self, $elt, $ps ) = @_; |
56
|
72
|
|
|
|
|
471
|
$ps->{diagrams}->{hspace} * $ps->{diagrams}->{width}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# The horizontal space the diagram requires, including advance width. |
60
|
|
|
|
|
|
|
sub hsp { |
61
|
48
|
|
|
48
|
0
|
115
|
my ( $self, $elt, $ps ) = @_; |
62
|
48
|
|
|
|
|
132
|
$self->hsp0( $elt, $ps ) + $self->hsp1( $elt, $ps ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# my @Roman = qw( I II III IV V VI VI VII VIII IX X XI XII ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub font_bl { |
68
|
48
|
|
|
48
|
0
|
11069
|
goto &ChordPro::Output::PDF::font_bl; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# The actual draw method. |
72
|
|
|
|
|
|
|
sub draw { |
73
|
48
|
|
|
48
|
0
|
149
|
my ( $self, $info, $x, $y, $ps ) = @_; |
74
|
48
|
50
|
|
|
|
125
|
return unless $info; |
75
|
|
|
|
|
|
|
|
76
|
48
|
|
|
|
|
94
|
my $x0 = $x; |
77
|
|
|
|
|
|
|
|
78
|
48
|
|
|
|
|
118
|
my $gw = $ps->{diagrams}->{width}; |
79
|
48
|
|
|
|
|
120
|
my $gh = $ps->{diagrams}->{height}; |
80
|
48
|
|
|
|
|
117
|
my $dot = 0.80 * $gw; |
81
|
48
|
|
50
|
|
|
172
|
my $lw = ($ps->{diagrams}->{linewidth} || 0.10) * $gw; |
82
|
48
|
|
|
|
|
115
|
my $pr = $ps->{pr}; |
83
|
|
|
|
|
|
|
|
84
|
48
|
|
33
|
|
|
319
|
my $fg = $info->{diagram} // $config->{pdf}->{theme}->{foreground}; |
85
|
48
|
|
|
|
|
188
|
my $strings = $config->diagram_strings; |
86
|
48
|
|
|
|
|
138
|
my $w = $gw * ($strings - 1); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Draw font name. |
89
|
48
|
|
|
|
|
116
|
my $font = $ps->{fonts}->{diagram}; |
90
|
48
|
|
|
|
|
268
|
$pr->setfont($font); |
91
|
48
|
|
|
|
|
10802
|
my $name = $info->chord_display; |
92
|
|
|
|
|
|
|
# $name .= "*" |
93
|
|
|
|
|
|
|
# unless $info->{origin} ne "user" |
94
|
|
|
|
|
|
|
# || $::config->{diagrams}->{show} eq "user"; |
95
|
|
|
|
|
|
|
$name = "$name" |
96
|
48
|
50
|
|
|
|
803
|
if $info->{diagram}; |
97
|
48
|
|
|
|
|
238
|
$pr->text( $name, $x + ($w - $pr->strwidth($name))/2, $y - font_bl($font) ); |
98
|
48
|
|
|
|
|
323
|
$y -= $font->{size} * $ps->{spacing}->{diagramchords} + $dot/2 + $lw; |
99
|
48
|
50
|
|
|
|
202
|
if ( $info->{base} + $info->{baselabeloffset} > 1 ) { |
100
|
|
|
|
|
|
|
# my $i = @Roman[$info->{base}] . " "; |
101
|
0
|
|
|
|
|
0
|
my $i = sprintf("%d ", $info->{base} + $info->{baselabeloffset}); |
102
|
0
|
|
|
|
|
0
|
$pr->setfont( $ps->{fonts}->{diagram_base}, $gh ); |
103
|
|
|
|
|
|
|
$pr->text( $i, $x-$pr->strwidth($i), |
104
|
|
|
|
|
|
|
$y-($info->{baselabeloffset}*$gh)-0.85*$gh, |
105
|
0
|
|
|
|
|
0
|
$ps->{fonts}->{diagram_base}, $ps->{spacing}->{diagramchords}*$gh ); |
106
|
0
|
|
|
|
|
0
|
$pr->setfont($font); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
48
|
|
|
|
|
111
|
my $v = $ps->{diagrams}->{vcells}; |
110
|
48
|
|
|
|
|
115
|
my $h = $strings; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Draw the grid. |
113
|
48
|
|
|
|
|
194
|
my $xo = $self->grid_xo( $ps, $fg ); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $crosshairs = sub { |
116
|
0
|
|
|
0
|
|
0
|
my ( $x, $y, $col ) = @_; |
117
|
0
|
|
|
|
|
0
|
for ( $pr->{pdfgfx} ) { |
118
|
0
|
|
|
|
|
0
|
$_->save; |
119
|
0
|
|
|
|
|
0
|
$_->linewidth(0.1); |
120
|
0
|
|
0
|
|
|
0
|
$_->strokecolor($col//"black"); |
121
|
0
|
|
|
|
|
0
|
$_->move($x-10,$y); |
122
|
0
|
|
|
|
|
0
|
$_->hline($x+20); |
123
|
0
|
|
|
|
|
0
|
$_->stroke; |
124
|
0
|
|
|
|
|
0
|
$_->move($x,$y+10); |
125
|
0
|
|
|
|
|
0
|
$_->vline($y-20); |
126
|
0
|
|
|
|
|
0
|
$_->stroke; |
127
|
0
|
|
|
|
|
0
|
$_->restore; |
128
|
|
|
|
|
|
|
} |
129
|
48
|
|
|
|
|
365
|
}; |
130
|
|
|
|
|
|
|
|
131
|
48
|
|
|
|
|
361
|
$pr->{pdfgfx}->formimage( $xo, $x, $y-$v*$gh, 1 ); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# The numbercolor property of the chordfingers is used for the |
134
|
|
|
|
|
|
|
# background of the underlying dot (the numbers are transparent). |
135
|
48
|
|
|
|
|
20958
|
my $fcf = $ps->{fonts}->{chordfingers}; |
136
|
48
|
|
|
|
|
223
|
my $fbg = $pr->_bgcolor($fcf->{numbercolor}); |
137
|
|
|
|
|
|
|
# However, if none we should really use white. |
138
|
48
|
50
|
|
|
|
235
|
$fbg = "white" if $fbg eq "none"; |
139
|
|
|
|
|
|
|
|
140
|
48
|
|
|
|
|
102
|
my $fingers; |
141
|
48
|
50
|
|
|
|
254
|
$fingers = $info->{fingers} if $ps->{diagrams}->{fingers}; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Bar detection. |
144
|
48
|
|
|
|
|
560
|
my $bar; |
145
|
48
|
50
|
33
|
|
|
382
|
if ( $fingers && $fbg ne $fg ) { |
146
|
48
|
|
|
|
|
100
|
my %h; |
147
|
48
|
|
|
|
|
96
|
my $str = 0; |
148
|
48
|
|
|
|
|
89
|
my $got = 0; |
149
|
48
|
|
|
|
|
97
|
foreach ( @{ $fingers } ) { |
|
48
|
|
|
|
|
174
|
|
150
|
0
|
0
|
|
|
|
0
|
$str++, next unless $info->{frets}->[$str] > 0; |
151
|
0
|
0
|
|
|
|
0
|
if ( $bar->{$_} ) { |
152
|
|
|
|
|
|
|
# Same finger on multiple strings -> bar. |
153
|
0
|
|
|
|
|
0
|
$got++; |
154
|
0
|
|
|
|
|
0
|
$bar->{$_}->[-1] = $str; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
else { |
157
|
|
|
|
|
|
|
# Register. |
158
|
0
|
|
|
|
|
0
|
$bar->{$_} = [ $_, $info->{frets}->[$str], $str, $str ]; |
159
|
|
|
|
|
|
|
} |
160
|
0
|
|
|
|
|
0
|
$str++; |
161
|
|
|
|
|
|
|
} |
162
|
48
|
50
|
|
|
|
178
|
if ( $got ) { |
163
|
0
|
|
|
|
|
0
|
foreach (sort keys %$bar ) { |
164
|
0
|
|
|
|
|
0
|
my @bi = @{ $bar->{$_} }; |
|
0
|
|
|
|
|
0
|
|
165
|
0
|
0
|
|
|
|
0
|
if ( $bi[-2] == $bi[-1] ) { # not a bar |
166
|
0
|
|
|
|
|
0
|
delete $bar->{$_}; |
167
|
0
|
|
|
|
|
0
|
next; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
# Print the bar line. Need linecap 0. |
170
|
0
|
|
|
|
|
0
|
$pr->hline( $x+$bi[2]*$gw, $y-$bi[1]*$gh+$gh/2, |
171
|
|
|
|
|
|
|
($bi[3]-$bi[2])*$gw, |
172
|
|
|
|
|
|
|
$dot, $fg, 0 ); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# Process the strings and fingers. |
178
|
48
|
|
|
|
|
150
|
$x -= $gw/2; |
179
|
48
|
|
|
|
|
73
|
my $oflo; # to detect out of range frets |
180
|
|
|
|
|
|
|
|
181
|
48
|
|
|
|
|
91
|
my $g_none = "/"; # unnumbered |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# All symbols from the chordfingers font are equal size: a circle |
184
|
|
|
|
|
|
|
# of 824 (1000-2*88) centered horizontally in the box, with a |
185
|
|
|
|
|
|
|
# decender of 55. |
186
|
|
|
|
|
|
|
# To get it vertically centered we must lower it by 455 (1000/2-55). |
187
|
48
|
|
|
|
|
208
|
$pr->setfont($fcf,$dot); |
188
|
48
|
|
|
|
|
9467
|
my $g_width = $pr->strwidth("1"); |
189
|
48
|
|
|
|
|
14857
|
my $g_lower = -0.455*$g_width; |
190
|
|
|
|
|
|
|
# warn("GW dot=$dot, width=$g_width, lower=$g_lower\n"); |
191
|
|
|
|
|
|
|
# my $e = $fcf->{fd}->{font}->extents("1",10); |
192
|
|
|
|
|
|
|
# use DDumper; DDumper($e); |
193
|
|
|
|
|
|
|
|
194
|
48
|
|
50
|
|
|
166
|
for my $sx ( 0 .. @{ $info->{frets} // [] }-1 ) { |
|
48
|
|
|
|
|
281
|
|
195
|
288
|
|
|
|
|
701
|
my $fret = $info->{frets}->[$sx]; |
196
|
288
|
|
|
|
|
560
|
my $fing = -1; |
197
|
288
|
50
|
50
|
|
|
1284
|
$fing = $fingers->[$sx] // -1 if $fingers; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# For bars, only the first and last finger. |
200
|
288
|
0
|
33
|
|
|
1095
|
if ( $fing && $bar && $bar->{$fing} ) { |
|
|
|
33
|
|
|
|
|
201
|
|
|
|
|
|
|
next unless $sx == $bar->{$fing}->[2] |
202
|
0
|
0
|
0
|
|
|
0
|
|| $sx == $bar->{$fing}->[3]; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
288
|
100
|
|
|
|
862
|
if ( $fret > 0 ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
206
|
192
|
50
|
33
|
|
|
588
|
if ( $fret > $v && !$oflo++ ) { |
207
|
0
|
|
|
|
|
0
|
warn("Diagram $info->{name}: ", |
208
|
|
|
|
|
|
|
"Fret position $fret exceeds diagram size $v\n"); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
192
|
|
|
|
|
310
|
my $glyph; |
212
|
192
|
50
|
|
|
|
1302
|
if ( $fbg eq $fg ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
213
|
0
|
|
|
|
|
0
|
$glyph = $g_none; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
elsif ( $fing =~ /^[A-Z0-9]$/ ) { |
216
|
|
|
|
|
|
|
# Leave it to the user to interpret sensibly. |
217
|
0
|
|
|
|
|
0
|
$glyph = $fing; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
elsif ( $fing =~ /-\d+$/ ) { |
220
|
192
|
|
|
|
|
410
|
$glyph = $g_none; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
else { |
223
|
0
|
|
|
|
|
0
|
warn("Diagram $info->{name}: ", |
224
|
|
|
|
|
|
|
"Invalid finger position $fing, ignored\n"); |
225
|
0
|
|
|
|
|
0
|
$glyph = $g_none; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# The glyphs are open, so we need am explicit |
229
|
|
|
|
|
|
|
# background circle to prevent the grid peeping through. |
230
|
|
|
|
|
|
|
# OTOH, for the unnumbered dot, we need a foreground circle. |
231
|
192
|
50
|
|
|
|
1242
|
$pr->circle( $x+$gw/2, $y-$fret*$gh+$gh/2, $dot/2.2, 1, |
232
|
|
|
|
|
|
|
$glyph eq $g_none ? $fg : $fbg, |
233
|
|
|
|
|
|
|
"none"); |
234
|
|
|
|
|
|
|
|
235
|
192
|
|
|
|
|
9380
|
$pr->setfont( $fcf, $dot ); |
236
|
|
|
|
|
|
|
$glyph = "$glyph" |
237
|
192
|
50
|
|
|
|
37699
|
if $info->{diagram}; |
238
|
192
|
|
|
|
|
973
|
$pr->text( $glyph, |
239
|
|
|
|
|
|
|
$x, |
240
|
|
|
|
|
|
|
$y - $fret*$gh + $gh/2 + $g_lower, |
241
|
|
|
|
|
|
|
$fcf, $dot/0.8 ); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
elsif ( $fret < 0 ) { |
244
|
48
|
|
|
|
|
391
|
$pr->cross( $x+$gw/2, $y+$lw+$gh/3, $dot/3, $lw, |
245
|
|
|
|
|
|
|
$fg ); |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
elsif ( $info->{base} > 0 ) { |
248
|
48
|
|
|
|
|
342
|
$pr->circle( $x+$gw/2, $y+$lw+$gh/3, $dot/3, $lw, |
249
|
|
|
|
|
|
|
undef, $fg ); |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
continue { |
253
|
288
|
|
|
|
|
5264
|
$x += $gw; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
48
|
|
|
|
|
827
|
return $gw * ( $ps->{diagrams}->{hspace} + $strings ); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub grid_xo { |
260
|
48
|
|
|
48
|
0
|
157
|
my ( $self, $ps, $fg ) = @_; |
261
|
|
|
|
|
|
|
|
262
|
48
|
|
|
|
|
107
|
my $gw = $ps->{diagrams}->{width}; |
263
|
48
|
|
|
|
|
97
|
my $gh = $ps->{diagrams}->{height}; |
264
|
48
|
|
50
|
|
|
169
|
my $lw = ($ps->{diagrams}->{linewidth} || 0.10) * $gw; |
265
|
48
|
|
|
|
|
98
|
my $v = $ps->{diagrams}->{vcells}; |
266
|
48
|
|
|
|
|
215
|
my $strings = $config->diagram_strings; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
return $self->{grids}->{$gw,$gh,$lw,$v,$strings,$fg} //= do |
269
|
48
|
|
66
|
|
|
744
|
{ |
270
|
24
|
|
|
|
|
73
|
my $w = $gw * ($strings - 1); |
271
|
24
|
|
|
|
|
72
|
my $h = $strings; |
272
|
|
|
|
|
|
|
|
273
|
24
|
|
|
|
|
201
|
my $form = $ps->{pr}->{pdf}->xo_form; |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
# Bounding box must take linewidth into account. |
276
|
24
|
|
|
|
|
10908
|
my @bb = ( -$lw/2, -$lw/2, ($h-1)*$gw+$lw/2, $v*$gh+$lw/2 ); |
277
|
24
|
|
|
|
|
185
|
$form->bbox(@bb); |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
# Pseudo-object to access low level drawing routines. |
280
|
24
|
|
|
|
|
2303
|
my $dc = bless { pdfgfx => $form } => |
281
|
|
|
|
|
|
|
ChordPro::Output::PDF::Writer::; |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# Draw the grid. |
284
|
24
|
|
|
|
|
53
|
$dc->rectxy( @bb, 0, 'red' ) if 0; |
285
|
24
|
|
|
|
|
65
|
my $color = $fg; |
286
|
24
|
|
|
|
|
212
|
$dc->hline( 0, ($v-$_)*$gh, $w, $lw, $color ) for 0..$v; |
287
|
24
|
|
|
|
|
1445
|
$dc->vline( $_*$gw, $v*$gh, $gh*$v, $lw, $color) for 0..$h-1; |
288
|
|
|
|
|
|
|
|
289
|
24
|
|
|
|
|
1275
|
$form; |
290
|
|
|
|
|
|
|
}; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
1; |