App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Output/PDF/Writer.pm view on Meta::CPAN
}
foreach my $b ( @$book ) {
my $song = $b->[-1];
my $title = demarkup( fmt_subst( $song, $ctl->{line} ) );
next if $title eq $prev_title;
# Leaf outline.
my $ol = $outline->outline;
# Display info.
$ol->title($title);
my $p = $song->{meta}->{tocpage};
$p = $pdf->openpage( $p + $start ) unless ref($p);
my $c = $ol->can("destination") // $ol->can("dest");
$ol->$c($p);
$prev_title = $title;
}
}
}
=for xxx
# Add bookmarks.
my $outline = $ol_root->outline;
$outline->title("Bookmarks");
$outline->closed;
my @tops =
map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_ => s/^song_([0-9]+)$/sprintf("song_%06d",$1)/er ] }
grep { ! /^(?:cover|front|toc|back)$/ }
keys %{ $self->{_nd} };
for ( "cover", "front", "toc", @tops, "back" ) {
next unless my $p = $self->{_nd}->{$_};
my $ol = $outline->outline;
$ol->title($_);
if ( my $c = $ol->can("destination") ) {
$c->( $ol, $p );
}
else {
$ol->dest($p);
}
}
=cut
}
sub finish {
my ( $self, $file ) = @_;
::dump($self->{pdf}->{pagestack})
if $::config->{debug}->{pages} & 0x04;
if ( $file && $file ne "-" ) {
my $fd = fs_open( $file, '>:raw' );
print $fd $self->{pdf}->stringify;
close($fd);
}
else {
binmode(STDOUT);
print STDOUT ( $self->{pdf}->stringify );
close(STDOUT);
}
}
sub init_fonts {
my ( $self ) = @_;
my $ps = $self->{ps};
my $fail;
my $fc = Text::Layout::FontConfig->new( debug => $config->{debug}->{fonts} > 1 );
# Add font dirs.
my @dirs;
my @d = ( @{$ps->{fontdir}}, @{ CP->findresdirs("fonts") }, $ENV{FONTDIR} );
# Avoid rsc result if dummy.
splice( @d, -2, 1 ) if $d[-2] eq "fonts/";
for my $fontdir ( @d ) {
next unless $fontdir;
$fontdir = expand_tilde($fontdir);
if ( fs_test( d => $fontdir ) ) {
$self->{pdfapi}->can("addFontDirs")->($fontdir);
$fc->add_fontdirs($fontdir);
push( @dirs, $fontdir );
}
else {
warn("PDF: Ignoring fontdir $fontdir [$!]\n");
undef $fontdir;
}
}
# Make sure we have this one.
$fc->register_font( "ChordProSymbols.ttf", "chordprosymbols", "", {} );
# Remap corefonts if possible.
my $remap = $ENV{CHORDPRO_COREFONTS_REMAP} // $ps->{corefonts}->{remap};
# Packager adds the fonts.
$remap //= "free" if CP->packager;
unless ( defined $remap ) {
# Not defined -- find the GNU Free Fonts.
for my $dir ( @dirs ) {
my $have = 1;
for my $font ( qw( FreeSerif.ttf
FreeSerifBoldItalic.ttf
FreeSerifBold.ttf
FreeSerifItalic.ttf
FreeSans.ttf
FreeSansBoldOblique.ttf
FreeSansBold.ttf
FreeSansOblique.ttf
FreeMono.ttf
FreeMonoBoldOblique.ttf
FreeMonoBold.ttf
FreeMonoOblique.ttf
) ) {
$have = 0, last unless fs_test( fs => "$dir/$font" );
}
$remap = "free", last if $have;
( run in 1.391 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )