App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Output/PDF/Grid.pm view on Meta::CPAN
for my $t ( @$tok ) {
$x += $cellwidth, next if $t eq '';
my $text = $t eq '/' ? $t : $t->chord_display;
$pr->text( $text, $x, $y,
$t->info->is_gridstrum ? $schord : $fchord );
$x += $cellwidth;
}
}
elsif ( exists $token->{chord} ) {
# I'm not sure why not testing for class = chord...
warn("Chord token without class\n")
unless $token->{class} eq "chord";
my $t = $token->{chord};
$t = $t->chord_display;
$pr->text( $t, $x, $y, $fchord )
unless $token eq ".";
$x += $cellwidth;
}
elsif ( $token->{class} eq "slash" ) {
$pr->text( "/", $x, $y, $fchord );
$x += $cellwidth;
}
elsif ( $token->{class} eq "space" ) {
$x += $cellwidth;
}
elsif ( $token->{class} eq "repeat1" ) {
$t = $token->{symbol};
my $k = $prevbar + 1;
while ( $k <= $#tokens
&& !is_bar($tokens[$k]) ) {
$k++;
}
pr_repeat( $x + ($k - $prevbar - 1)*$cellwidth/2, $y,
0, $fchord->{size}, $col, $pr );
$x += $cellwidth;
}
if ( $x > $ps->{papersize}->[0] ) {
# This should be signalled by the parser.
# warn("PDF: Too few cells for content\n");
last;
}
}
if ( $margin->[1] && $elt->{comment} ) {
my $t = $elt->{comment};
if ( $t->{chords} ) {
$t->{text} = "";
for ( 0..$#{ $t->{chords} } ) {
$t->{text} .= $t->{chords}->[$_]->chord_display . $t->{phrases}->[$_];
}
}
$pr->text( " " . $t->{text}, $x, $y, $fonts->{grid_margin} );
}
}
sub is_bar( $elt ) {
exists( $elt->{class} ) && $elt->{class} eq "bar";
}
# Location and size of vertical bars
sub yh( $y, $h, $pr ) {
my $d = $pr->{ps}->{grids}->{stretch} || 0.825;
return ( $y + 0.9 * $h,
$h * $d * $pr->{ps}->{spacing}->{grid} );
}
sub pr_cellline( $x, $y, $lcr, $sz, $w, $col, $pr ) {
$x -= $w / 2;
$pr->vline( $x, yh($y,$sz,$pr), $w, $col );
}
sub pr_barline( $x, $y, $lcr, $sz, $col, $pr ) {
my $w = $sz / 10; # glyph width = $w
$x -= $w / 2;
$x += $w if $lcr < 0;
$pr->vline( $x, yh($y,$sz,$pr), $w, $col );
}
sub pr_dbarline( $x, $y, $lcr, $sz, $col, $pr ) {
my $w = $sz / 10; # glyph width = 3 * $w
$x -= 0.5 + $w * ($lcr + 1);
# $x -= $w * (( 0.5, 1.5, 2.5 )[1+$lcr]);
$pr->vline( $x, yh($y,$sz,$pr), $w, $col );
$x += 2 * $w;
$pr->vline( $x, yh($y,$sz,$pr), $w, $col );
}
sub pr_rptstart( $x, $y, $lcr, $sz, $col, $pr ) {
my $w = $sz / 10; # glyph width = 3 * $w
$x -= 0.5;
$x += $w if $lcr < 0;
$pr->vline( $x, yh($y,$sz,$pr), $w, $col );
$x += 2 * $w;
$y += 0.55 * $sz;
$pr->line( $x, $y, $x, $y+$w, $w, $col );
$y -= 0.4 * $sz;
$pr->line( $x, $y, $x, $y+$w, $w, $col );
}
sub pr_rptvolta( $x, $y, $lcr, $sz, $symcol, $pr, $token ) {
my $w = $sz / 10; # glyph width = 3 * $w
my $col = $pr->{ps}->{grids}->{volta}->{color};
$x += $w if $lcr < 0;
if ( $token->{symbol} eq ":|" ) {
pr_rptend( $x, $y, $lcr, $sz, $col, $pr );
}
else {
pr_barline( $x, $y, 0, $sz, $col, $pr );
}
my $ret = $x -= $w / 2;
my $font = $pr->{ps}->{fonts}->{grid};
$pr->setfont($font);
$pr->text( "<span color='$col'><sup>" . $token->{volta} . "</sup></span>",
$x+$w, $y, $font );
$ret;
}
sub pr_voltafinish( $x, $y, $width, $sz, $symcol, $pr ) {
my $w = $sz / 10; # glyph width = 3 * $w
my ( $col, $span ) = @{$pr->{ps}->{grids}->{volta}}{qw(color span)};
$pr->hline( $x, $y+0.9*$sz+$w/4, $width*$span, $w/2, $col );
( run in 2.395 seconds using v1.01-cache-2.11-cpan-302cb4679cc )