App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Output/PDF/Grid.pm view on Meta::CPAN
#! perl
package ChordPro::Output::PDF::Grid;
use strict;
use warnings;
use Carp;
use feature 'state';
use feature 'signatures';
no warnings 'experimental::signatures';
use ChordPro::Utils qw( is_ttrue );
sub gridline( $elt, $x, $y, $cellwidth, $barwidth, $margin, $ps, %opts ) {
# Grid context.
my $pr = $ps->{pr};
my $fonts = $ps->{fonts};
# Use the chords font for the chords, and for the symbols size.
my $fchord = { %{ $fonts->{grid} || $fonts->{chord} } };
my $schord = $fonts->{gridstrum};
delete($fchord->{background});
$y -= $pr->font_bl($fchord);
pr_label_maybe( $ps, $x, $y );
$x += $barwidth;
$cellwidth += $barwidth;
$elt->{tokens} //= [ {} ];
my $firstbar;
my $lastbar;
foreach my $i ( 0 .. $#{ $elt->{tokens} } ) {
next unless is_bar( $elt->{tokens}->[$i] );
$lastbar = $i;
$firstbar //= $i;
}
my $prevbar = -1;
my @tokens = @{ $elt->{tokens} };
my $t;
if ( $margin->[0] ) {
$x -= $barwidth;
my $t = $elt->{margin};
if ( $t && $t->{chords} ) {
if ( 0 && $::config->{settings}->{'chords-as-chords'} ) {
my $x = $x;
for ( 0..$#{ $t->{chords} } ) {
$x = $pr->text( $t->{chords}->[$_]->chord_display,
$x, $y, $fonts->{chord} )
unless $t->{chords}->[$_] eq "";
$x = $pr->text( $t->{phrases}->[$_],
$x, $y, $fonts->{grid_margin} )
}
}
else {
$t->{text} = "";
for ( 0..$#{ $t->{chords} } ) {
$t->{text} .= $t->{chords}->[$_]->chord_display
unless $t->{chords}->[$_] eq "";
$t->{text} .= $t->{phrases}->[$_];
}
$pr->text( $t->{text}, $x, $y, $fonts->{grid_margin} );
}
}
elsif ( $t ) {
$pr->text( $t->{text}, $x, $y, $fonts->{grid_margin} );
}
$x += $margin->[0] * $cellwidth + $barwidth;
}
my $ctl = $pr->{ps}->{grids}->{cellbar};
my $col = $pr->{ps}->{grids}->{symbols}->{color};
$opts{subtype} //= $opts{type} eq "gridline" ? "cellbars" : "";
my $needcell = ( $opts{type} eq "gridline"
|| $opts{subtype} eq "cellbars" ) && $ctl->{width};
state $prevvoltastart;
my $align;
if ( $prevvoltastart && @tokens
( run in 0.663 second using v1.01-cache-2.11-cpan-f56aa216473 )