App-Music-ChordPro

 view release on metacpan or  search on metacpan

lib/ChordPro/Output/PDF.pm  view on Meta::CPAN

#! perl

package main;

use utf8;
our $config;
our $options;

our $ps;
our $pr;
our $dw;

package ChordPro::Output::PDF;

use strict;
use warnings;
use File::Temp ();
use Ref::Util qw(is_hashref is_arrayref is_coderef);
use Carp;
use ChordPro::Output::Common qw( prep_outlines fmt_subst );
use feature 'signatures';

use ChordPro::Output::PDF::Song;
use ChordPro::Output::PDF::Writer;
use ChordPro::Files;
use ChordPro::Paths;
use ChordPro::Utils;

# Set by Configurator.
our $pdfapi;

use Text::Layout;
use List::Util qw(any);
use Unicode::Collate;

my $verbose = 0;

# For regression testing, run perl with PERL_HASH_SEED set to zero.
# This eliminates the arbitrary order of font definitions and triggers
# us to pinpoint some other data that would otherwise be varying.
my $regtest = defined($ENV{PERL_HASH_SEED}) && $ENV{PERL_HASH_SEED} == 0;

# Convenience.
*generate_song = \&ChordPro::Output::PDF::Song::generate_song;

sub generate_songbook {
    my ( $self, $sb ) = @_;

    return [] unless $sb->{songs}->[0]->{body}
                  || $sb->{songs}->[0]->{source}->{embedding};
    $verbose ||= $options->{verbose};


    $config->unlock;
    $ps = $config->{pdf};
    # use DDP; p $ps->{songbook}, as => "in PDF";
    my $pagectrl = $self->pagectrl;
    $config->lock;

    my $extra_matter = 0;
    if ( $options->{toc} // (@{$sb->{songs}} > 1) ) {
	for ( @{ $::config->{contents} } ) {
	    # Treat ToCs as one.
	    $extra_matter++, last unless $_->{omit};
	}
	$extra_matter++ if $options->{title};
    }
    $extra_matter++ if $pagectrl->{cover} && !$options->{title};
    $extra_matter++ if $pagectrl->{front_matter};
    $extra_matter++ if $pagectrl->{back_matter};
    $extra_matter++ if $options->{csv};

    # $prefill indicates that in 2page mode, a filler page is needed to
    # get the songs properly aligned.
    my $prefill = 0;
    if ( $pagectrl->{align_songs_spread} ) {
	$prefill = 1;
    }



( run in 0.594 second using v1.01-cache-2.11-cpan-ceb78f64989 )