lib/ChordPro/Output/PDF/Configurator.pm

filter: Statementstmt 79.7% 67 / 84 Branchbran 42.8% 18 / 42 Conditioncond 72.7% 8 / 11 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 66.0% 99 / 150 CC 35 SCAR 32.2
CC
35
Cov
68%
configurator
34.5
config_pdfapi
17.3
__ANON__
6.0
CRAP 25.1
« blib/lib/ChordPro/Wx/Main_wxg.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Polyline.pm »
1 #! perl
2  
3 package main;
4  
5 10 our $config;
6 10 our $options;
7  
8 package ChordPro::Output::PDF;
9  
10 10 our $pdfapi;
11  
12 10 ▶use ChordPro::Utils qw(is_corefont);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 13 ▶sub configurator {
Subroutine configurator: called CC=22 SCAR=35.4
Pod undocumented
15 13 my ( $cfg ) = @_;
16  
17 # From here, we're mainly dealing with the PDF settings.
18 13 my $pdf = $cfg->{pdf};
19  
20 # Get PDF library.
21 13 ▶ $pdfapi //= config_pdfapi( $pdf->{library} );
Condition66%2/3
$pdfapi //= config_pdfapi($pdf->{"library"})
l!l&&r!l&&!r
3100
MC/DC0%0/2
$pdfapi //= config_pdfapi($pdf->{"library"})
$pdfapi config_pdfapi($pdf->{"library"})
Truth table66%2/3
A //= B
A= $pdfapiB= config_pdfapi($pdf->{"library"})
ABresult
1X1
011
000
22  
23 13 my $fonts = $pdf->{fonts};
24  
25 # Apply Chordii command line compatibility.
26  
27 # Command line only takes text and chord fonts.
28 13 for my $type ( qw( text chord ) ) {
29 26 for ( $options->{"$type-font"} ) {
30 26 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 26 0 26
31 0 ▶ if ( m;/; ) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[/]) { } 0 0 0
32 0 $fonts->{$type}->{file} = $_;
33 }
34 else {
35 0 ▶ if ( is_corefont($_) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_corefont($_)) { } 0 0 0
elsif (defined $pdf->{'fontconfig'}{s/\s+\d+$//r}) { } 0 0 0
36 0 $fonts->{$type}->{name} = is_corefont($_);
37 }
38 elsif ( defined $pdf->{fontconfig}->{s/\s+\d+$//r} ) {
39 0 $fonts->{$type}->{description} = $_;
40 }
41 else {
42 0 die("Config error: \"$_\" is not a built-in font\n")
43 }
44 }
45 }
46 26 for ( $options->{"$type-size"} ) {
47 26 ▶ $fonts->{$type}->{size} = $_ if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 0 26 26
48 }
49 }
50  
51 13 for ( $options->{"page-size"} ) {
52 13 ▶ $pdf->{papersize} = $_ if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 0 13 13
53 }
54 13 for ( $options->{"vertical-space"} ) {
55 13 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 13 0 13
56 $pdf->{spacing}->{lyrics} +=
57 0 $_ / $fonts->{text}->{size};
58 }
59 13 for ( $options->{"lyrics-only"} ) {
60 13 ▶ next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 13 0 13
61 # If set on the command line, it cannot be overridden
62 # by configs and {controls}.
63 0 $pdf->{"lyrics-only"} = 2 * $_;
64 }
65 13 for ( $options->{"single-space"} ) {
66 13 ▶ next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 13 0 13
67 0 $pdf->{"suppress-empty-chords"} = $_;
68 }
69  
70 # Chord grid width.
71 13 ▶ if ( $options->{'chord-grid-size'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"chord-grid-size"}) 0 13 13
72 # Note that this is legacy, so for the chord diagrams only,
73 $pdf->{diagrams}->{width} =
74 $pdf->{diagrams}->{height} =
75 $options->{'chord-grid-size'} /
76 0 @{ $config->{notes}->{sharps} };
77 }
78  
79 # Map papersize name to [ width, height ].
80 13 ▶ unless ( eval { $pdf->{papersize}->[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $pdf->{"papersize"}[0] } }) 13 0 13
81 13 eval "require ${pdfapi}::Resource::PaperSizes";
82 13 my %ps = "${pdfapi}::Resource::PaperSizes"->get_paper_sizes;
83 die("Unhandled paper size: ", $pdf->{papersize}, "\n")
84 13 ▶ unless exists $ps{lc $pdf->{papersize}};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ps{lc $pdf->{"papersize"}} 0 13 13
85 $pdf->{papersize} = $ps{lc $pdf->{papersize}}
86 13 }
87  
88 # Merge properties for derived fonts.
89 195 ▶ my $fm = sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
90 195 my ( $font, $def ) = @_;
91 195 for ( keys %{ $fonts->{$def} } ) {
92 754 ▶ next if /^(?:background|frame)$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(?:background|frame)$/ 169 585 754
93 585 ▶ next if $font eq "chordfingers" && $_ eq "size";
Branch: 1 branch
BranchTrueFalseTotal
if $font eq "chordfingers" and $_ eq "size" 13 572 585
Condition100%3/3
$font eq "chordfingers" and $_ eq "size"
!ll&&!rl&&r
5462613
MC/DC100%2/2
$font eq "chordfingers" and $_ eq "size"
$font eq "chordfingers" $_ eq "size"
Truth table100%3/3
A and B
A= $font eq "chordfingers"B= $_ eq "size"
ABresult
0X0
100
111
94 572 ▶ $fonts->{$font}->{$_} //= $fonts->{$def}->{$_};
Condition66%2/3
$fonts->{$font}{$_} //= $fonts->{$def}{$_}
l!l&&r!l&&!r
2213510
MC/DC0%0/2
$fonts->{$font}{$_} //= $fonts->{$def}{$_}
$fonts->{$font}{$_} $fonts->{$def}{$_}
Truth table66%2/3
A //= B
A= $fonts->{$font}{$_}B= $fonts->{$def}{$_}
ABresult
1X1
011
000
95 }
96 13 };
97 13 $fm->( qw( subtitle text ) );
98 13 $fm->( qw( chorus text ) );
99 13 $fm->( qw( comment_italic text ) );
100 13 $fm->( qw( comment_box text ) );
101 13 $fm->( qw( comment text ) );
102 13 $fm->( qw( annotation chord ) );
103 13 $fm->( qw( label text ) );
104 13 $fm->( qw( toc text ) );
105 13 $fm->( qw( empty text ) );
106 13 $fm->( qw( grid chord ) );
107 13 $fm->( qw( grid_margin comment ) );
108 13 $fm->( qw( diagram comment ) );
109 13 $fm->( qw( diagram_base comment ) );
110 13 $fm->( qw( chordfingers diagram ) );
111  
112 # Default footer is small subtitle.
113 13 ▶ $fonts->{footer}->{size} //= 0.6 * $fonts->{subtitle}->{size};
Condition50%1/2
$fonts->{"footer"}{"size"} //= "0.6" * $fonts->{"subtitle"}{"size"}
l!l
013
MC/DC0%0/1
$fonts->{"footer"}{"size"} //= "0.6" * $fonts->{"subtitle"}{"size"}
$fonts->{"footer"}{"size"}
Truth table50%1/2
A
A= $fonts->{"footer"}{"size"}
Aresult
11
00
114 13 $fm->( qw( footer subtitle ) );
115  
116 # This one is fixed.
117 13 $fonts->{chordprosymbols}->{file} = "ChordProSymbols.ttf";
118  
119 }
120  
121 14 ▶sub config_pdfapi {
Subroutine config_pdfapi: called CC=9 SCAR=28.5
Pod undocumented
122 14 my ( $lib, $verbose ) = @_;
123 14 my $pdfapi;
124  
125 14 my $t = "config";
126 # Get PDF library.
127 14 ▶ if ( $ENV{CHORDPRO_PDF_API} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"CHORDPRO_PDF_API"}) 0 14 14
128 0 $t = "CHORDPRO_PDF_API";
129 0 $lib = $ENV{CHORDPRO_PDF_API};
130 }
131 14 ▶ if ( $lib ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lib) { } 0 14 14
132 0 ▶ unless ( eval( "require $lib" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval "require $lib") 0 0 0
133 0 die("Missing PDF library $lib ($t)\n");
134 }
135 0 $pdfapi = $lib;
136 0 ▶ warn("Using PDF library $lib ($t)\n") if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
137 }
138 else {
139 14 for ( qw( PDF::API2 PDF::Builder ) ) {
140 14 ▶ eval "require $_" or next;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $_" or next 14 0 14
141 14 $pdfapi = $_;
142 14 ▶ warn("Using PDF library $_ (detected)\n") if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 14 14
143 14 last;
144 }
145 }
146 14 ▶ die("Missing PDF library\n") unless $pdfapi;
Branch: 1 branch
BranchTrueFalseTotal
unless $pdfapi 0 14 14
147 14 return $pdfapi;
148 }
149  
150 10 1;
« blib/lib/ChordPro/Wx/Main_wxg.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Polyline.pm »