lib/ChordPro/Output/PDF/Writer.pm

filter: Statementstmt 54.1% 374 / 691 Branchbran 30.5% 94 / 308 Conditioncond 23.6% 56 / 237 MC/DCmcdc 8.0% 11 / 136 Subroutinesub 67.6% 46 / 68 Podpod 0.0% 0 / 42 totaltotal 39.2% 581 / 1482 CC 259 SCAR 48.3
CC
259
Cov
42%
add_object
992.0
get_image
132.0
rectxy
110.0
CRAP 125.2
« lib/ChordPro/lib/SVGPDF/Rect.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Colour.pm »
1 #! perl
2  
3 package main;
4  
5 12 our $config;
6  
7 package ChordPro::Output::PDF::Writer;
8  
9 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use Text::Layout;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use IO::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 13 ▶use ChordPro::Files;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 13 ▶use ChordPro::Paths;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶use ChordPro::Utils qw( expand_tilde demarkup min is_corefont maybe is_true is_odd );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 ▶use ChordPro::Output::Common qw( fmt_subst prep_outlines );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶use Ref::Util qw( is_arrayref is_hashref );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 12 ▶use Unicode::Collate;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 12 ▶use Unicode::Normalize;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # For regression testing, run perl with PERL_HASH_SEED set to zero.
26 # This eliminates the arbitrary order of font definitions and triggers
27 # us to pinpoint some other data that would otherwise be varying.
28 12 ▶my $regtest = defined($ENV{PERL_HASH_SEED}) && $ENV{PERL_HASH_SEED} == 0;
Condition33%1/3
defined $ENV{'PERL_HASH_SEED'} && $ENV{'PERL_HASH_SEED'} == 0
!ll&&!rl&&r
1200
MC/DC0%0/2
defined $ENV{'PERL_HASH_SEED'} && $ENV{'PERL_HASH_SEED'} == 0
defined $ENV{'PERL_HASH_SEED'} $ENV{'PERL_HASH_SEED'} == 0
Truth table33%1/3
A && B
A= defined $ENV{'PERL_HASH_SEED'}B= $ENV{'PERL_HASH_SEED'} == 0
ABresult
0X0
100
111
29 12 my $faketime = 1465041600;
30  
31 12 my %fontcache; # speeds up 2 seconds per song
32  
33 14 ▶sub new {
Subroutine new: called CC=9 SCAR=23.3
Pod undocumented
34 14 my ( $pkg, $ps, $pdfapi ) = @_;
35 14 my $self = bless { ps => $ps }, $pkg;
36 14 $self->{pdfapi} = $pdfapi;
37 14 $self->{pdf} = $pdfapi->new;
38 14 ▶ $self->{pdf}->{forcecompress} = 0 if $regtest;
Branch: 1 branch
BranchTrueFalseTotal
if $regtest 0 14 14
39 $self->{pdf}->mediabox( $ps->{papersize}->[0],
40 14 $ps->{papersize}->[1] );
41 $self->{pdf}->page_layout( $ps->{page_layout} )
42 14 ▶ if $ps->{page_layout};
Branch: 1 branch
BranchTrueFalseTotal
if $ps->{"page_layout"} 0 14 14
43 14 $self->{layout} = Text::Layout->new( $self->{pdf} );
44 14 $self->{tmplayout} = undef;
45  
46 12 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
47 # Patches and enhancements to PDF library.
48 14 *{$pdfapi . '::Resource::XObject::Form::width' } = \&_xo_width;
49 14 *{$pdfapi . '::Resource::XObject::Form::height'} = \&_xo_height;
50  
51 14 ▶ if ( $pdfapi eq 'PDF::API2' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pdfapi eq 'PDF::API2') { } 14 0 14
elsif ($pdfapi eq 'PDF::Builder') { } 0 0 0
52 14 my $apiversion = ${$pdfapi . '::VERSION'};
53 12 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 # Fix date validation.
56 0 ▶ *{$pdfapi . '::_is_date'} = sub { 1 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 14 ▶ if $apiversion < 2.045;
Branch: 1 branch
BranchTrueFalseTotal
if $apiversion < "2.045" 0 14 14
58  
59 # Enhanced version that allows named destinations.
60 14 ▶ eval "use $pdfapi" . "::Annotation";
Subroutine BEGIN: called CC=1 SCAR=0.0
61 14 ▶ *{$pdfapi . '::Annotation::pdf' } = \&pdfapi_annotation_pdf
Branch: 1 branch
BranchTrueFalseTotal
if $apiversion < 999 14 0 14
62 if $apiversion < 999; # no milestone yet
63  
64 # Enhanced version that doesn't blow up.
65 14 ▶ eval "use $pdfapi" . "::Basic::PDF::Array";
Subroutine BEGIN: called CC=1 SCAR=0.0
66 14 ▶ *{$pdfapi . '::Basic::PDF::Array::outobjdeep' } = \&pdfapi_outobjdeep
Branch: 1 branch
BranchTrueFalseTotal
if $apiversion < 999 14 0 14
67 if $apiversion < 999; # no milestone yet
68 }
69 elsif ( $pdfapi eq 'PDF::Builder' ) {
70 0 my $apiversion = ${$pdfapi . '::VERSION'};
71 12 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 # Enhanced version that allows named destinations.
74 0 eval "use $pdfapi" . "::Annotation";
75 0 ▶ *{$pdfapi . '::Annotation::pdf' } = \&pdfapi_annotation_pdf
Branch: 1 branch
BranchTrueFalseTotal
if $apiversion < 999 0 0 0
76 if $apiversion < 999; # no milestone yet
77 }
78  
79 # Text::Layout hooks.
80 14 *{$pdfapi . '::named_dest_register' } = \&pdfapi_named_dest_register;
81 14 *{$pdfapi . '::named_dest_fiddle' } = \&pdfapi_named_dest_fiddle;
82  
83 14 %fontcache = ();
84  
85 14 $self->{pdf}->{_pr} = $self;
86 }
87  
88 13 ▶sub info {
Subroutine info: called CC=5 SCAR=17.8
Pod undocumented
89 13 my ( $self, %info ) = @_;
90  
91 13 ▶ $info{CreationDate} //= pdf_date();
Condition33%1/3
$info{"CreationDate"} //= pdf_date()
l!l&&r!l&&!r
0130
MC/DC0%0/2
$info{"CreationDate"} //= pdf_date()
$info{"CreationDate"} pdf_date()
Truth table33%1/3
A //= B
A= $info{"CreationDate"}B= pdf_date()
ABresult
1X1
011
000
92  
93 13 ▶ if ( $self->{pdf}->can("info_metadata") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'pdf'}->can('info_metadata')) { } 13 0 13
94 13 for ( keys(%info) ) {
95 52 $self->{pdf}->info_metadata( $_, demarkup($info{$_}) );
96 }
97 13 ▶ if ( $config->{debug}->{runtimeinfo} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"runtimeinfo"}) 13 0 13
98 13 $self->{pdf}->info_metadata( "RuntimeInfo",
99 "Runtime Info:\n" . ::runtimeinfo() );
100 }
101 }
102 else {
103 0 $self->{pdf}->info(%info);
104 }
105 }
106  
107 # Return a PDF compliant date/time string.
108 13 ▶sub pdf_date {
Subroutine pdf_date: called CC=3 SCAR=12.0
Pod undocumented
109 13 my ( $t ) = @_;
110 13 ▶ $t ||= $regtest ? $faketime : time;
Branch: 1 branch
BranchTrueFalseTotal
$regtest ? : 0 13 13
Condition33%1/3
$t ||= $regtest ? $faketime : time
l!l&&r!l&&!r
0130
MC/DC0%0/2
$t ||= $regtest ? $faketime : time
$t $regtest ? $faketime : time
Truth table33%1/3
A ||= B
A= $tB= $regtest ? $faketime : time
ABresult
1X1
011
000
111  
112 13 my @tm = gmtime($t);
113  
114 13 return sprintf(
115 "%04d%02d%02d%02d%02d%02d+00'00'",
116 1900 + $tm[5],
117 $tm[4] + 1,
118 $tm[3],
119 $tm[2],
120 $tm[1],
121 $tm[0],
122 );
123 }
124  
125 276 ▶sub wrap {
Subroutine wrap: called CC=4 SCAR=22.1
Pod undocumented
126 276 my ( $self, $text, $m ) = @_;
127  
128 276 my $ex = "";
129 276 my $sp = "";
130 #warn("TEXT: |$text| ($m)\n");
131 276 ▶ while ( $self->strwidth($text) > $m ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->strwidth($text) > $m) 0 276 276
132 0 my ( $l, $s, $r ) = $text =~ /^(.+)([-_,.:;\s])(.+)$/;
133 0 ▶ return ( $text, $ex ) unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 0 0
134 #warn("WRAP: |$text| -> |$l|$s|$r$sp$ex|\n");
135 0 ▶ if ( $s =~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\S/) 0 0 0
136 0 $l .= $s;
137 0 $s = "";
138 }
139 0 $text = $l;
140 0 $ex = $r . $sp . $ex;
141 0 $sp = $s;
142 }
143  
144 276 return ( $text, $ex );
145 }
146  
147 731 ▶sub _fgcolor {
Subroutine _fgcolor: called CC=6 SCAR=25.9
148 731 my ( $self, $col ) = @_;
149 731 ▶ if ( !defined($col) || $col =~ /^foreground(?:-medium|-light)?$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $col or $col =~ /^foreground(?:-medium|-light)?$/) { } 731 0 731
elsif ($col eq 'background') { } 0 0 0
elsif (not $col) { } 0 0 0
Condition33%1/3
not defined $col or $col =~ /^foreground(?:-medium|-light)?$/
l!l&&r!l&&!r
07310
MC/DC0%0/2
not defined $col or $col =~ /^foreground(?:-medium|-light)?$/
not defined $col $col =~ /^foreground(?:-medium|-light)?$/
Truth table33%1/3
not(A) or B
A= not defined $colB= $col =~ /^foreground(?:-medium|-light)?$/
ABresult
1X1
011
000
150 731 ▶ $col = $self->{ps}->{theme}->{$col//"foreground"};
Condition50%1/2
$col // "foreground"
l!l
7310
MC/DC0%0/1
$col // "foreground"
$col
Truth table50%1/2
A
A= $col
Aresult
11
00
151 }
152 elsif ( $col eq "background" ) {
153 0 $col = $self->{ps}->{theme}->{background};
154 }
155 elsif ( !$col ) {
156 0 Carp::confess("Undefined fgcolor: $col");
157 }
158 731 $col;
159 }
160  
161 839 ▶sub _bgcolor {
Subroutine _bgcolor: called CC=5 SCAR=17.0
162 839 my ( $self, $col ) = @_;
163 839 ▶ if ( !defined($col) || $col eq "background" ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $col or $col eq 'background') { } 785 54 839
elsif ($col =~ /^foreground(?:-medium|-light)?$/) { } 54 0 54
elsif (not $col) { } 0 0 0
Condition100%3/3
not defined $col or $col eq "background"
l!l&&r!l&&!r
15463154
MC/DC100%2/2
not defined $col or $col eq "background"
not defined $col $col eq "background"
Truth table100%3/3
not(A) or B
A= not defined $colB= $col eq "background"
ABresult
1X1
011
000
164 785 $col = $self->{ps}->{theme}->{background};
165 }
166 elsif ( $col =~ /^foreground(?:-medium|-light)?$/ ) {
167 54 $col = $self->{ps}->{theme}->{$col};
168 }
169 elsif ( !$col ) {
170 0 Carp::confess("Undefined bgcolor: $col");
171 }
172 839 $col;
173 }
174  
175 1754 ▶sub fix_musicsyms {
Subroutine fix_musicsyms: called CC=11 SCAR=39.6
Pod undocumented
176 1754 my ( $text, $font ) = @_;
177  
178 1754 for ( $text ) {
179 1754 ▶ if ( /♯/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\x{266f}/) 0 1754 1754
180 0 ▶ unless ( $font->{has_sharp} //=
Branch: 1 branch
BranchTrueFalseTotal
unless ($font->{"has_sharp"} //= $font->{"fd"}{"font"}->glyphByUni(9839) ne ".notdef") 0 0 0
Condition0%0/2
$font->{"has_sharp"} //= $font->{"fd"}{"font"}->glyphByUni(9839) ne ".notdef"
l!l
00
MC/DC0%0/1
$font->{"has_sharp"} //= $font->{"fd"}{"font"}->glyphByUni(9839) ne ".notdef"
$font->{"has_sharp"}
Truth table0%0/2
A
A= $font->{"has_sharp"}
Aresult
11
00
181 $font->{fd}->{font}->glyphByUni(ord("♯")) ne ".notdef" ) {
182 0 s;♯;<sym sharp/>;g;
183 }
184 }
185 1754 ▶ if ( /â™­/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\x{266d}/) 0 1754 1754
186 0 ▶ unless ( $font->{has_flat} //=
Branch: 1 branch
BranchTrueFalseTotal
unless ($font->{"has_flat"} //= $font->{"fd"}{"font"}->glyphByUni(9837) ne ".notdef") 0 0 0
Condition0%0/2
$font->{"has_flat"} //= $font->{"fd"}{"font"}->glyphByUni(9837) ne ".notdef"
l!l
00
MC/DC0%0/1
$font->{"has_flat"} //= $font->{"fd"}{"font"}->glyphByUni(9837) ne ".notdef"
$font->{"has_flat"}
Truth table0%0/2
A
A= $font->{"has_flat"}
Aresult
11
00
187 $font->{fd}->{font}->glyphByUni(ord("â™­")) ne ".notdef" ) {
188 0 s;â™­;<sym flat/>;g;
189 }
190 }
191 1754 ▶ if ( /Δ/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\x{394}/) 0 1754 1754
192 0 ▶ unless ( $font->{has_delta} //=
Branch: 1 branch
BranchTrueFalseTotal
unless ($font->{"has_delta"} //= $font->{"fd"}{"font"}->glyphByUni(916) ne ".notdef") 0 0 0
Condition0%0/2
$font->{"has_delta"} //= $font->{"fd"}{"font"}->glyphByUni(916) ne ".notdef"
l!l
00
MC/DC0%0/1
$font->{"has_delta"} //= $font->{"fd"}{"font"}->glyphByUni(916) ne ".notdef"
$font->{"has_delta"}
Truth table0%0/2
A
A= $font->{"has_delta"}
Aresult
11
00
193 $font->{fd}->{font}->glyphByUni(ord("Δ")) ne ".notdef" ) {
194 0 s;Δ;<sym delta/>;g;
195 }
196 }
197 }
198 1754 return $text;
199 }
200  
201 731 ▶sub text {
Subroutine text: called CC=19 SCAR=41.0
Pod undocumented
202 731 my ( $self, $text, $x, $y, $font, $size, $nomarkup ) = @_;
203 # print STDERR ("T: @_\n");
204 731 ▶ $font ||= $self->{font};
Condition66%2/3
$font ||= $self->{"font"}
l!l&&r!l&&!r
3843470
MC/DC0%0/2
$font ||= $self->{"font"}
$font $self->{"font"}
Truth table66%2/3
A ||= B
A= $fontB= $self->{"font"}
ABresult
1X1
011
000
205 731 $text = fix_musicsyms( $text, $font );
206 731 ▶ $size ||= $font->{size};
Condition33%1/3
$size ||= $font->{"size"}
l!l&&r!l&&!r
07310
MC/DC0%0/2
$size ||= $font->{"size"}
$size $font->{"size"}
Truth table33%1/3
A ||= B
A= $sizeB= $font->{"size"}
ABresult
1X1
011
000
207  
208 731 $self->{layout}->set_font_description($font->{fd});
209 731 $self->{layout}->set_font_size($size);
210 # We don't have set_color in the API.
211 731 $self->{layout}->{_currentcolor} = $self->_fgcolor($font->{color});
212 # Watch out for regression... May have to do this in the nomarkup case only.
213 731 ▶ if ( $nomarkup ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nomarkup) { } 0 731 731
214 0 $text =~ s/'/\x{2019}/g; # friendly quote
215 0 $self->{layout}->set_text($text);
216 }
217 else {
218 731 $self->{layout}->set_markup($text);
219 731 for ( @{ $self->{layout}->{_content} } ) {
220 731 ▶ next unless $_->{type} eq "text";
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"type"} eq "text" 0 731 731
221 731 $_->{text} =~ s/\'/\x{2019}/g; # friendly quote
222 }
223 }
224 731 $y -= $self->{layout}->get_baseline;
225 731 $self->{layout}->show( $x, $y, $self->{pdftext} );
226  
227 731 my $e = $self->{layout}->get_pixel_extents;
228 731 $e->{y} += $e->{height};
229  
230 # Handle decorations (background, box).
231 731 my $bgcol = $self->_bgcolor($font->{background});
232 731 ▶ undef $bgcol if $bgcol && $bgcol =~ /^no(?:ne)?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $bgcol and $bgcol =~ /^no(?:ne)?$/i 731 0 731
Condition33%1/3
$bgcol and $bgcol =~ /^no(?:ne)?$/i
!ll&&!rl&&r
00731
MC/DC0%0/2
$bgcol and $bgcol =~ /^no(?:ne)?$/i
$bgcol $bgcol =~ /^no(?:ne)?$/i
Truth table33%1/3
A and B
A= $bgcolB= $bgcol =~ /^no(?:ne)?$/i
ABresult
0X0
100
111
233 731 ▶ my $debug = $ENV{CHORDPRO_DEBUG_TEXT} ? "magenta" : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'CHORDPRO_DEBUG_TEXT'} ? : 0 731 731
234 731 ▶ my $frame = $font->{frame} || $debug;
Condition33%1/3
$font->{'frame'} || $debug
l!l&&r!l&&!r
00731
MC/DC0%0/2
$font->{'frame'} || $debug
$font->{'frame'} $debug
Truth table33%1/3
A || B
A= $font->{'frame'}B= $debug
ABresult
1X1
011
000
235 731 ▶ undef $frame if $frame && $frame =~ /^no(?:ne)?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $frame and $frame =~ /^no(?:ne)?$/i 0 731 731
Condition33%1/3
$frame and $frame =~ /^no(?:ne)?$/i
!ll&&!rl&&r
73100
MC/DC0%0/2
$frame and $frame =~ /^no(?:ne)?$/i
$frame $frame =~ /^no(?:ne)?$/i
Truth table33%1/3
A and B
A= $frameB= $frame =~ /^no(?:ne)?$/i
ABresult
0X0
100
111
236 731 ▶ if ( $bgcol || $frame ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bgcol or $frame) 0 731 731
Condition33%1/3
$bgcol or $frame
l!l&&r!l&&!r
00731
MC/DC0%0/2
$bgcol or $frame
$bgcol $frame
Truth table33%1/3
A or B
A= $bgcolB= $frame
ABresult
1X1
011
000
237 0 ▶ printf("BB: %.2f %.2f %.2f %.2f\n", @{$e}{qw( x y width height ) } )
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
238 if $debug;
239 # Draw background and.or frame.
240 0 ▶ my $d = $debug ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$debug ? : 0 0 0
241 0 ▶ $frame = $debug || $font->{color} || $self->{ps}->{theme}->{foreground} if $frame;
Branch: 1 branch
BranchTrueFalseTotal
if $frame 0 0 0
Condition0%0/6
$debug || $font->{'color'} || $self->{'ps'}{'theme'}{'foreground'}
l!l&&r!l&&!r
000
$debug or $font->{"color"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$debug || $font->{'color'} || $self->{'ps'}{'theme'}{'foreground'}
$debug $font->{"color"} $self->{'ps'}{'theme'}{'foreground'}
Truth table0%0/4
A or B || C
A= $debugB= $font->{"color"}C= $self->{'ps'}{'theme'}{'foreground'}
ABCresult
1XX1
01X1
0011
0000
242 $self->rectxy( $x + $e->{x} - $d,
243 $y + $e->{y} + $d,
244 $x + $e->{x} + $e->{width} + $d,
245 0 $y + $e->{y} - $e->{height} - $d,
246 0.5, $bgcol, $frame);
247 }
248  
249 731 $x += $e->{width};
250 # print STDERR ("TX: $x\n");
251 731 return $x;
252 }
253  
254 717 ▶sub setfont {
Subroutine setfont: called CC=5 SCAR=20.9
Pod undocumented
255 717 my ( $self, $font, $size ) = @_;
256 717 $self->{font} = $font;
257 warn("PDF: Font ", $font->{_ff}, " should have a size!\n")
258 717 ▶ unless $size ||= $font->{size};
Branch: 1 branch
BranchTrueFalseTotal
unless $size ||= $font->{"size"} 0 717 717
Condition33%1/3
$size ||= $font->{"size"}
l!l&&r!l&&!r
07170
MC/DC0%0/2
$size ||= $font->{"size"}
$size $font->{"size"}
Truth table33%1/3
A ||= B
A= $sizeB= $font->{"size"}
ABresult
1X1
011
000
259 717 ▶ $self->{fontsize} = $size ||= $font->{size} || $font->{fd}->{size};
Condition16%1/6
$size ||= $font->{"size"} || $font->{"fd"}{"size"}
l!l&&r!l&&!r
71700
$font->{'size'} || $font->{'fd'}{'size'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$size ||= $font->{"size"} || $font->{"fd"}{"size"}
$size $font->{'size'} $font->{'fd'}{'size'}
Truth table0%0/4
A ||= B || C
A= $sizeB= $font->{'size'}C= $font->{'fd'}{'size'}
ABCresult
1XX1
01X1
0011
0000
260 717 $self->{pdftext}->font( $font->{fd}->{font}, $size );
261 }
262  
263 495 ▶sub font_bl {
Subroutine font_bl: called CC=1 SCAR=0.0
Pod undocumented
264 495 my ( $self, $font ) = @_;
265 # $font->{size} / ( 1 - $font->{fd}->{font}->descender / $font->{fd}->{font}->ascender );
266 495 $font->{size} * $font->{fd}->{font}->ascender / 1000;
267 }
268  
269 0 ▶sub font_ul {
Subroutine font_ul: not called CC=1 SCAR=6.9
Pod undocumented
270 0 my ( $self, $font ) = @_;
271 0 $font->{fd}->{font}->underlineposition / 1024 * $font->{size};
272 }
273  
274 1023 ▶sub strwidth {
Subroutine strwidth: called CC=6 SCAR=18.9
Pod undocumented
275 1023 my ( $self, $text, $font, $size ) = @_;
276 1023 ▶ $font ||= $self->{font};
Condition66%2/3
$font ||= $self->{"font"}
l!l&&r!l&&!r
1418820
MC/DC0%0/2
$font ||= $self->{"font"}
$font $self->{"font"}
Truth table66%2/3
A ||= B
A= $fontB= $self->{"font"}
ABresult
1X1
011
000
277 1023 $text = fix_musicsyms( $text, $font );
278 1023 ▶ $size ||= $self->{fontsize} || $font->{size};
Condition50%3/6
$size ||= $self->{"fontsize"} || $font->{"size"}
l!l&&r!l&&!r
010230
$self->{'fontsize'} || $font->{'size'}
l!l&&r!l&&!r
101850
MC/DC0%0/3
$size ||= $self->{"fontsize"} || $font->{"size"}
$size $self->{'fontsize'} $font->{'size'}
Truth table0%0/4
A ||= B || C
A= $sizeB= $self->{'fontsize'}C= $font->{'size'}
ABCresult
1XX1
01X1
0011
0000
279 1023 ▶ $self->{tmplayout} //= $self->{layout}->copy;
Condition66%2/3
$self->{"tmplayout"} //= $self->{"layout"}->copy
l!l&&r!l&&!r
1009140
MC/DC0%0/2
$self->{"tmplayout"} //= $self->{"layout"}->copy
$self->{"tmplayout"} $self->{"layout"}->copy
Truth table66%2/3
A //= B
A= $self->{"tmplayout"}B= $self->{"layout"}->copy
ABresult
1X1
011
000
280 1023 $self->{tmplayout}->set_font_description($font->{fd});
281 1023 $self->{tmplayout}->set_font_size($size);
282 1023 $self->{tmplayout}->set_markup($text);
283 wantarray ? $self->{tmplayout}->get_pixel_size
284 1023 ▶ : $self->{tmplayout}->get_pixel_size->{width};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1023 1023
285 }
286  
287 0 ▶sub strheight {
Subroutine strheight: not called CC=6 SCAR=37.4
Pod undocumented
288 0 my ( $self, $text, $font, $size ) = @_;
289 0 ▶ $font ||= $self->{font};
Condition0%0/3
$font ||= $self->{"font"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$font ||= $self->{"font"}
$font $self->{"font"}
Truth table0%0/3
A ||= B
A= $fontB= $self->{"font"}
ABresult
1X1
011
000
290 0 $text = fix_musicsyms( $text, $font );
291 0 ▶ $size ||= $self->{fontsize} || $font->{size};
Condition0%0/6
$size ||= $self->{"fontsize"} || $font->{"size"}
l!l&&r!l&&!r
000
$self->{'fontsize'} || $font->{'size'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$size ||= $self->{"fontsize"} || $font->{"size"}
$size $self->{'fontsize'} $font->{'size'}
Truth table0%0/4
A ||= B || C
A= $sizeB= $self->{'fontsize'}C= $font->{'size'}
ABCresult
1XX1
01X1
0011
0000
292 0 ▶ $self->{tmplayout} //= $self->{layout}->copy;
Condition0%0/3
$self->{"tmplayout"} //= $self->{"layout"}->copy
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"tmplayout"} //= $self->{"layout"}->copy
$self->{"tmplayout"} $self->{"layout"}->copy
Truth table0%0/3
A //= B
A= $self->{"tmplayout"}B= $self->{"layout"}->copy
ABresult
1X1
011
000
293 0 $self->{tmplayout}->set_font_description($font->{fd});
294 0 $self->{tmplayout}->set_font_size($size);
295 0 $self->{tmplayout}->set_markup($text);
296 wantarray ? $self->{tmplayout}->get_pixel_size
297 0 ▶ : $self->{tmplayout}->get_pixel_size->{height};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
298 }
299  
300 0 ▶sub line {
Subroutine line: not called CC=2 SCAR=17.9
Pod undocumented
301 0 my ( $self, $x0, $y0, $x1, $y1, $lw, $color ) = @_;
302 0 my $gfx = $self->{pdfgfx};
303 0 $gfx->save;
304 0 $gfx->strokecolor( $self->_fgcolor($color) );
305 0 $gfx->linecap(1);
306 0 ▶ $gfx->linewidth($lw||1);
Condition0%0/2
$lw || 1
l!l
00
MC/DC0%0/1
$lw || 1
$lw
Truth table0%0/2
A
A= $lw
Aresult
11
00
307 0 $gfx->move( $x0, $y0 );
308 0 $gfx->line( $x1, $y1 );
309 0 $gfx->stroke;
310 0 $gfx->restore;
311 }
312  
313 0 ▶sub hline {
Subroutine hline: not called CC=3 SCAR=24.8
Pod undocumented
314 0 my ( $self, $x, $y, $w, $lw, $color, $cap ) = @_;
315 0 ▶ $cap //= 2;
Condition0%0/2
$cap //= 2
l!l
00
MC/DC0%0/1
$cap //= 2
$cap
Truth table0%0/2
A
A= $cap
Aresult
11
00
316 0 my $gfx = $self->{pdfgfx};
317 0 $gfx->save;
318 0 $gfx->strokecolor( $self->_fgcolor($color) );
319 0 $gfx->linecap($cap);
320 0 ▶ $gfx->linewidth($lw||1);
Condition0%0/2
$lw || 1
l!l
00
MC/DC0%0/1
$lw || 1
$lw
Truth table0%0/2
A
A= $lw
Aresult
11
00
321 0 $gfx->move( $x, $y );
322 0 $gfx->hline( $x + $w );
323 0 $gfx->stroke;
324 0 $gfx->restore;
325 }
326  
327 0 ▶sub vline {
Subroutine vline: not called CC=3 SCAR=24.8
Pod undocumented
328 0 my ( $self, $x, $y, $h, $lw, $color, $cap ) = @_;
329 0 ▶ $cap //= 2;
Condition0%0/2
$cap //= 2
l!l
00
MC/DC0%0/1
$cap //= 2
$cap
Truth table0%0/2
A
A= $cap
Aresult
11
00
330 0 my $gfx = $self->{pdfgfx};
331 0 $gfx->save;
332 0 $gfx->strokecolor( $self->_fgcolor($color) );
333 0 $gfx->linecap($cap);
334 0 ▶ $gfx->linewidth($lw||1);
Condition0%0/2
$lw || 1
l!l
00
MC/DC0%0/1
$lw || 1
$lw
Truth table0%0/2
A
A= $lw
Aresult
11
00
335 0 $gfx->move( $x, $y );
336 0 $gfx->vline( $y - $h );
337 0 $gfx->stroke;
338 0 $gfx->restore;
339 }
340  
341 0 ▶sub rectxy {
Subroutine rectxy: not called CC=10 SCAR=47.0
Pod undocumented
342 0 my ( $self, $x, $y, $x1, $y1, $lw, $fillcolor, $strokecolor ) = @_;
343 0 my $gfx = $self->{pdfgfx};
344 0 $gfx->save;
345 0 ▶ $gfx->strokecolor($self->_fgcolor($strokecolor)) if $strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $strokecolor 0 0 0
346 0 ▶ $gfx->fillcolor($self->_fgcolor($fillcolor)) if $fillcolor;
Branch: 1 branch
BranchTrueFalseTotal
if $fillcolor 0 0 0
347 0 $gfx->linecap(2);
348 0 ▶ $gfx->linewidth($lw||1);
Condition0%0/2
$lw || 1
l!l
00
MC/DC0%0/1
$lw || 1
$lw
Truth table0%0/2
A
A= $lw
Aresult
11
00
349 0 $gfx->rectxy( $x, $y, $x1, $y1 );
350 0 ▶ $gfx->fill if $fillcolor && !$strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $fillcolor and not $strokecolor 0 0 0
Condition0%0/3
$fillcolor and not $strokecolor
!ll&&!rl&&r
000
MC/DC0%0/2
$fillcolor and not $strokecolor
$fillcolor not $strokecolor
Truth table0%0/3
A and not(B)
A= $fillcolorB= not $strokecolor
ABresult
0X0
100
111
351 0 ▶ $gfx->fillstroke if $fillcolor && $strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $fillcolor and $strokecolor 0 0 0
Condition0%0/3
$fillcolor and $strokecolor
!ll&&!rl&&r
000
MC/DC0%0/2
$fillcolor and $strokecolor
$fillcolor $strokecolor
Truth table0%0/3
A and B
A= $fillcolorB= $strokecolor
ABresult
0X0
100
111
352 0 ▶ $gfx->stroke if $strokecolor && !$fillcolor;
Branch: 1 branch
BranchTrueFalseTotal
if $strokecolor and not $fillcolor 0 0 0
Condition0%0/3
$strokecolor and not $fillcolor
!ll&&!rl&&r
000
MC/DC0%0/2
$strokecolor and not $fillcolor
$strokecolor not $fillcolor
Truth table0%0/3
A and not(B)
A= $strokecolorB= not $fillcolor
ABresult
0X0
100
111
353 0 $gfx->restore;
354 }
355  
356 0 ▶sub poly {
Subroutine poly: not called CC=10 SCAR=47.0
Pod undocumented
357 0 my ( $self, $points, $lw, $fillcolor, $strokecolor ) = @_;
358 0 ▶ undef $strokecolor unless $lw;
Branch: 1 branch
BranchTrueFalseTotal
unless $lw 0 0 0
359 0 my $gfx = $self->{pdfgfx};
360 0 $gfx->save;
361 0 ▶ $gfx->strokecolor($self->_fgcolor($strokecolor)) if $strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $strokecolor 0 0 0
362 0 ▶ $gfx->fillcolor($self->_fgcolor($fillcolor)) if $fillcolor;
Branch: 1 branch
BranchTrueFalseTotal
if $fillcolor 0 0 0
363 0 $gfx->linecap(2);
364 0 $gfx->linewidth($lw);
365 0 $gfx->poly( @$points );
366 0 $gfx->close;
367 0 ▶ $gfx->fill if $fillcolor && !$strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $fillcolor and not $strokecolor 0 0 0
Condition0%0/3
$fillcolor and not $strokecolor
!ll&&!rl&&r
000
MC/DC0%0/2
$fillcolor and not $strokecolor
$fillcolor not $strokecolor
Truth table0%0/3
A and not(B)
A= $fillcolorB= not $strokecolor
ABresult
0X0
100
111
368 0 ▶ $gfx->fillstroke if $fillcolor && $strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $fillcolor and $strokecolor 0 0 0
Condition0%0/3
$fillcolor and $strokecolor
!ll&&!rl&&r
000
MC/DC0%0/2
$fillcolor and $strokecolor
$fillcolor $strokecolor
Truth table0%0/3
A and B
A= $fillcolorB= $strokecolor
ABresult
0X0
100
111
369 0 ▶ $gfx->stroke if $strokecolor && !$fillcolor;
Branch: 1 branch
BranchTrueFalseTotal
if $strokecolor and not $fillcolor 0 0 0
Condition0%0/3
$strokecolor and not $fillcolor
!ll&&!rl&&r
000
MC/DC0%0/2
$strokecolor and not $fillcolor
$strokecolor not $fillcolor
Truth table0%0/3
A and not(B)
A= $strokecolorB= not $fillcolor
ABresult
0X0
100
111
370 0 $gfx->restore;
371 }
372  
373 0 ▶sub circle {
Subroutine circle: not called CC=10 SCAR=47.0
Pod undocumented
374 0 my ( $self, $x, $y, $r, $lw, $fillcolor, $strokecolor ) = @_;
375 0 my $gfx = $self->{pdfgfx};
376 0 $gfx->save;
377 0 ▶ $gfx->strokecolor($self->_fgcolor($strokecolor)) if $strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $strokecolor 0 0 0
378 0 ▶ $gfx->fillcolor($self->_fgcolor($fillcolor)) if $fillcolor;
Branch: 1 branch
BranchTrueFalseTotal
if $fillcolor 0 0 0
379 0 ▶ $gfx->linewidth($lw||1);
Condition0%0/2
$lw || 1
l!l
00
MC/DC0%0/1
$lw || 1
$lw
Truth table0%0/2
A
A= $lw
Aresult
11
00
380 0 $gfx->circle( $x, $y, $r );
381 0 ▶ $gfx->fill if $fillcolor && !$strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $fillcolor and not $strokecolor 0 0 0
Condition0%0/3
$fillcolor and not $strokecolor
!ll&&!rl&&r
000
MC/DC0%0/2
$fillcolor and not $strokecolor
$fillcolor not $strokecolor
Truth table0%0/3
A and not(B)
A= $fillcolorB= not $strokecolor
ABresult
0X0
100
111
382 0 ▶ $gfx->fillstroke if $fillcolor && $strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $fillcolor and $strokecolor 0 0 0
Condition0%0/3
$fillcolor and $strokecolor
!ll&&!rl&&r
000
MC/DC0%0/2
$fillcolor and $strokecolor
$fillcolor $strokecolor
Truth table0%0/3
A and B
A= $fillcolorB= $strokecolor
ABresult
0X0
100
111
383 0 ▶ $gfx->stroke if $strokecolor && !$fillcolor;
Branch: 1 branch
BranchTrueFalseTotal
if $strokecolor and not $fillcolor 0 0 0
Condition0%0/3
$strokecolor and not $fillcolor
!ll&&!rl&&r
000
MC/DC0%0/2
$strokecolor and not $fillcolor
$strokecolor not $fillcolor
Truth table0%0/3
A and not(B)
A= $strokecolorB= not $fillcolor
ABresult
0X0
100
111
384 0 $gfx->restore;
385 }
386  
387 0 ▶sub cross {
Subroutine cross: not called CC=5 SCAR=34.0
Pod undocumented
388 0 my ( $self, $x, $y, $r, $lw, $strokecolor ) = @_;
389 0 my $gfx = $self->{pdfgfx};
390 0 $gfx->save;
391 0 ▶ $gfx->strokecolor($self->_fgcolor($strokecolor)) if $strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $strokecolor 0 0 0
392 0 ▶ $gfx->linewidth($lw||1);
Condition0%0/2
$lw || 1
l!l
00
MC/DC0%0/1
$lw || 1
$lw
Truth table0%0/2
A
A= $lw
Aresult
11
00
393 0 $r = 0.9 * $r;
394 0 $gfx->move( $x-$r, $y-$r );
395 0 $gfx->line( $x+$r, $y+$r );
396 0 ▶ $gfx->stroke if $strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $strokecolor 0 0 0
397 0 $gfx->move( $x-$r, $y+$r );
398 0 $gfx->line( $x+$r, $y-$r );
399 0 ▶ $gfx->stroke if $strokecolor;
Branch: 1 branch
BranchTrueFalseTotal
if $strokecolor 0 0 0
400 0 $gfx->restore;
401 }
402  
403 # Fetch an image or xform object.
404 # Source is $elt->{uri} (for files), $elt->{chord} (for chords).
405 # Result is delivered, and stored in $elt->{data};
406 0 ▶sub get_image {
Subroutine get_image: not called CC=11 SCAR=48.8
Pod undocumented
407 0 my ( $self, $elt ) = @_;
408  
409 0 my $img;
410 0 my $subtype = $elt->{subtype};
411 0 my $data;
412  
413 0 ▶ if ( $subtype eq "delegate" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtype eq "delegate") 0 0 0
414 0 croak("delegated image in get_image()");
415 }
416  
417 0 ▶ if ( $elt->{data} ) { # have data
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"data"}) 0 0 0
418 0 $data = $elt->{data};
419 warn("get_image($elt->{subtype}): data ", length($data), " bytes\n")
420 0 ▶ if $config->{debug}->{images};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"images"} 0 0 0
421 0 return $data;
422 }
423  
424 0 my $uri = $elt->{uri};
425 0 ▶ if ( !$subtype && $uri =~ /\.(\w+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $subtype and $uri =~ /\.(\w+)$/) 0 0 0
Condition0%0/3
not $subtype and $uri =~ /\.(\w+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
not $subtype and $uri =~ /\.(\w+)$/
not $subtype $uri =~ /\.(\w+)$/
Truth table0%0/3
not(A) and B
A= not $subtypeB= $uri =~ /\.(\w+)$/
ABresult
0X0
100
111
426 0 ▶ $subtype //= $1;
Condition0%0/3
$subtype //= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$subtype //= $1
$subtype $1
Truth table0%0/3
A //= B
A= $subtypeB= $1
ABresult
1X1
011
000
427 }
428  
429 0 ▶ if ( $subtype =~ /^(jpg|png|gif)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subtype =~ /^(jpg|png|gif)$/) { } 0 0 0
elsif ($subtype =~ /^(xform)$/) { } 0 0 0
430 0 $img = $self->{pdf}->image($uri);
431 warn("get_image($subtype, $uri): img ", length($img), " bytes\n")
432 0 ▶ if $config->{debug}->{images};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"images"} 0 0 0
433 }
434 elsif ( $subtype =~ /^(xform)$/ ) {
435 0 $img = $data;
436 warn("get_image($subtype): xobject (",
437 # join(" ", $img->bbox),
438 0 join(" ", @{$data->{bbox}}),
439 ")\n")
440 0 ▶ if $config->{debug}->{images};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"images"} 0 0 0
441 }
442 else {
443 0 croak("Unhandled image type: $subtype\n");
444 }
445 0 return $img;
446 }
447  
448 0 ▶sub _xo_width {
Subroutine _xo_width: not called CC=1 SCAR=6.9
449 0 my ( $self ) = @_;
450 0 my @bb = $self->bbox;
451 0 return abs($bb[2]-$bb[0]);
452 }
453 0 ▶sub _xo_height {
Subroutine _xo_height: not called CC=1 SCAR=6.9
454 0 my ( $self ) = @_;
455 0 my @bb = $self->bbox;
456 0 return abs($bb[3]-$bb[1]);
457 }
458  
459 0 ▶sub add_object {
Subroutine add_object: not called CC=31 SCAR=69.0
Pod undocumented
460 0 my ( $self, $o, $x, $y, %options ) = @_;
461  
462 0 ▶ my $scale_x = $options{"xscale"} || $options{"scale"} || 1;
Condition0%0/5
$options{'xscale'} || $options{'scale'} || 1
l!l
00
$options{"xscale"} or $options{"scale"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{'xscale'} || $options{'scale'} || 1
$options{"xscale"} $options{"scale"}
Truth table0%0/3
A or B
A= $options{"xscale"}B= $options{"scale"}
ABresult
1X1
011
000
463 0 ▶ my $scale_y = $options{"yscale"} || $options{"scale"} || $scale_x;
Condition0%0/6
$options{'yscale'} || $options{'scale'} || $scale_x
l!l&&r!l&&!r
000
$options{"yscale"} or $options{"scale"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$options{'yscale'} || $options{'scale'} || $scale_x
$options{"yscale"} $options{"scale"} $scale_x
Truth table0%0/4
A or B || C
A= $options{"yscale"}B= $options{"scale"}C= $scale_x
ABCresult
1XX1
01X1
0011
0000
464  
465 0 ▶ my $va = $options{valign} // "bottom";
Condition0%0/2
$options{"valign"} // "bottom"
l!l
00
MC/DC0%0/1
$options{"valign"} // "bottom"
$options{"valign"}
Truth table0%0/2
A
A= $options{"valign"}
Aresult
11
00
466 0 ▶ my $ha = $options{align} // "left";
Condition0%0/2
$options{"align"} // "left"
l!l
00
MC/DC0%0/1
$options{"align"} // "left"
$options{"align"}
Truth table0%0/2
A
A= $options{"align"}
Aresult
11
00
467  
468 0 my $gfx = $self->{pdfgfx};
469 0 my $w = $o->width * $scale_x;
470 0 my $h = $o->height * $scale_y;
471  
472 0 ▶ if ( $config->{debug}->{images} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"images"}) 0 0 0
473 0 my $s;
474 0 ▶ if ( abs( $scale_x - $scale_y ) < 0.01 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $scale_x - $scale_y < 0.01) { } 0 0 0
475 0 $s = sprintf( "%.2f", $scale_x );
476 }
477 else {
478 0 $s = sprintf( "%.2f,%.2f", $scale_x, $scale_y );
479 }
480 0 warn( sprintf( "add_object x=%.1f y=%.1f w=%.1f h=%.1f scale=%s %s\n",
481 $x, $y, $w, $h, $s, $ha, ) );
482 }
483  
484 0 ▶ $self->crosshairs( $x, $y, color => "lime" ) if $config->{debug}->{images};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"images"} 0 0 0
485 0 ▶ if ( $va eq "top" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($va eq 'top') { } 0 0 0
elsif ($va eq 'middle') { } 0 0 0
486 0 $y -= $h;
487 }
488 elsif ( $va eq "middle" ) {
489 0 $y -= $h/2;
490 }
491 0 ▶ if ( $ha eq "right" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ha eq 'right') { } 0 0 0
elsif ($ha eq 'center') { } 0 0 0
492 0 $x -= $w;
493 }
494 elsif ( $ha eq "center" ) {
495 0 $x -= $w/2;
496 }
497  
498 0 ▶ $self->crosshairs( $x, $y, color => "red" ) if $config->{debug}->{images};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"images"} 0 0 0
499 0 $gfx->save;
500 0 ▶ if ( ref($o) =~ /::Resource::XObject::Image::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($o) =~ /::Resource::XObject::Image::/) { } 0 0 0
501 # Image wants width and height.
502 0 $gfx->object( $o, $x, $y, $w, $h );
503 }
504 else {
505 # XO_Form wants xscale and yscale.
506 0 my @bb = $o->bbox;
507 0 $gfx->object( $o, $x-min($bb[0],$bb[2])*$scale_x,
508 $y-min($bb[1],$bb[3])*$scale_y, $scale_x, $scale_y );
509 }
510  
511 0 ▶ if ( $options{border} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"border"}) 0 0 0
512 0 ▶ my $bc = $self->_fgcolor($options{"bordercolor"} || $options{"color"});
Condition0%0/3
$options{'bordercolor'} || $options{'color'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{'bordercolor'} || $options{'color'}
$options{'bordercolor'} $options{'color'}
Truth table0%0/3
A || B
A= $options{'bordercolor'}B= $options{'color'}
ABresult
1X1
011
000
513 0 my $lw = $options{border};
514  
515 # Selective parts, Top Right Bottom Left.
516 0 ▶ my $trbl = lc( $options{bordertrbl} // "trbl" );
Condition0%0/2
$options{"bordertrbl"} // "trbl"
l!l
00
MC/DC0%0/1
$options{"bordertrbl"} // "trbl"
$options{"bordertrbl"}
Truth table0%0/2
A
A= $options{"bordertrbl"}
Aresult
11
00
517 0 ▶ unless ( $trbl =~ /^[trbl]*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($trbl =~ /^[trbl]*$/) 0 0 0
518 0 warn("Image with invalid bordertrbl ($trbl)\n");
519 0 $trbl = "trbl";
520 }
521 0 ▶ $gfx->stroke_color($bc) if $bc;
Branch: 1 branch
BranchTrueFalseTotal
if $bc 0 0 0
522 0 ▶ if ( $trbl =~ /t/ && $trbl =~ /r/
Branch: 2 branches
BranchTrueFalseTotal
if ($trbl =~ /t/ and $trbl =~ /r/ and $trbl =~ /b/ and $trbl =~ /l/) { } 0 0 0
elsif ($trbl) { } 0 0 0
Condition0%0/9
$trbl =~ /t/ and $trbl =~ /r/ and $trbl =~ /b/ and $trbl =~ /l/
!ll&&!rl&&r
000
$trbl =~ /t/ and $trbl =~ /r/ and $trbl =~ /b/
!ll&&!rl&&r
000
$trbl =~ /t/ and $trbl =~ /r/
!ll&&!rl&&r
000
MC/DC0%0/4
$trbl =~ /t/ and $trbl =~ /r/ and $trbl =~ /b/ and $trbl =~ /l/
$trbl =~ /t/ $trbl =~ /r/ $trbl =~ /b/ $trbl =~ /l/
Truth table0%0/5
A and B and C and D
A= $trbl =~ /t/B= $trbl =~ /r/C= $trbl =~ /b/D= $trbl =~ /l/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
523 && $trbl =~ /b/ && $trbl =~ /l/ ) { # full rect
524 0 $gfx->rectangle( $x, $y, $x+$w, $y+$h )
525 ->line_width($lw)
526 ->stroke;
527 }
528 elsif ( $trbl ) {
529 # Projecting square cap.
530 0 $gfx->line_width($lw)->line_cap(2);
531 0 ▶ $gfx->move( $x, $y )->vline( $y+$h ) if $trbl =~ /l/;
Branch: 1 branch
BranchTrueFalseTotal
if $trbl =~ /l/ 0 0 0
532 0 ▶ $gfx->move( $x, $y )->hline( $x+$w ) if $trbl =~ /b/;
Branch: 1 branch
BranchTrueFalseTotal
if $trbl =~ /b/ 0 0 0
533 0 ▶ $gfx->move( $x+$w, $y )->vline( $y+$h ) if $trbl =~ /r/;
Branch: 1 branch
BranchTrueFalseTotal
if $trbl =~ /r/ 0 0 0
534 0 ▶ $gfx->move( $x, $y+$h )->hline( $x+$w ) if $trbl =~ /t/;
Branch: 1 branch
BranchTrueFalseTotal
if $trbl =~ /t/ 0 0 0
535 0 $gfx->stroke;
536 }
537 }
538  
539 0 ▶ if ( $options{href} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"href"}) 0 0 0
540 0 my $a = $gfx->{' apipage'}->annotation;
541 0 $a->url( $options{href}, -rect => [ $x, $y, $x+$w, $y+$h ] );
542 }
543  
544 0 $gfx->restore;
545 }
546  
547 # For convenience.
548 0 ▶sub crosshairs {
Subroutine crosshairs: not called CC=8 SCAR=42.8
Pod undocumented
549 0 my ( $self, $x, $y, %options ) = @_;
550 0 my $gfx = $self->{pdfgfx};
551 0 ▶ my $col = $options{colour} || $options{color} || "black";
Condition0%0/5
$options{'colour'} || $options{'color'} || 'black'
l!l
00
$options{"colour"} or $options{"color"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{'colour'} || $options{'color'} || 'black'
$options{"colour"} $options{"color"}
Truth table0%0/3
A or B
A= $options{"colour"}B= $options{"color"}
ABresult
1X1
011
000
552 0 ▶ my $lw = $options{linewidth} || 0.1;
Condition0%0/2
$options{'linewidth'} || 0.1
l!l
00
MC/DC0%0/1
$options{'linewidth'} || 0.1
$options{'linewidth'}
Truth table0%0/2
A
A= $options{'linewidth'}
Aresult
11
00
553 0 ▶ my $w = ( $options{width} || 40 ) / 2;
Condition0%0/2
$options{'width'} || 40
l!l
00
MC/DC0%0/1
$options{'width'} || 40
$options{'width'}
Truth table0%0/2
A
A= $options{'width'}
Aresult
11
00
554 0 ▶ my $h = ( $options{width} || $options{height} || 40 ) / 2;
Condition0%0/5
$options{'width'} || $options{'height'} || 40
l!l
00
$options{"width"} or $options{"height"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{'width'} || $options{'height'} || 40
$options{"width"} $options{"height"}
Truth table0%0/3
A or B
A= $options{"width"}B= $options{"height"}
ABresult
1X1
011
000
555 0 for ( $gfx ) {
556 0 $_->save;
557 0 $_->line_width($lw);
558 0 $_->stroke_color($col);
559 0 $_->move($x-$w,$y);
560 0 $_->hline($x+$w);
561 0 $_->move($x,$y+$h);
562 0 $_->vline($y-$h);
563 0 $_->stroke;
564 0 $_->restore;
565 }
566 }
567  
568 0 ▶sub add_image {
Subroutine add_image: not called CC=1 SCAR=6.9
Pod undocumented
569 0 my ( $self, $img, $x, $y, $w, $h,
570 $border, $trbl ) = @_;
571 0 $self->add_object( $img, $x, $y,
572 xscale => $w/$img->width,
573 yscale => $h/$img->height,
574 valign => "bottom",
575 maybe border => $border,
576 maybe bordertrbl => $trbl );
577 }
578  
579 142 ▶sub newpage {
Subroutine newpage: called CC=5 SCAR=18.2
Pod undocumented
580 142 my ( $self, $page ) = @_;
581 142 my $ps = $self->{ps};
582 #$self->{pdftext}->textend if $self->{pdftext};
583 142 ▶ $page ||= 0;
Condition100%2/2
$page ||= 0
l!l
5587
MC/DC100%1/1
$page ||= 0
$page
Truth table100%2/2
A
A= $page
Aresult
11
00
584  
585 # PDF::API2 says $page must refer to an existing page.
586 # Set to 0 to append.
587 142 ▶ $page = 0 if $page == $self->{pdf}->pages + 1;
Branch: 1 branch
BranchTrueFalseTotal
if $page == $self->{"pdf"}->pages + 1 18 124 142
588  
589 142 $self->{pdfpage} = $self->{pdf}->page($page);
590 $self->{pdfpage}->mediabox( $ps->{papersize}->[0],
591 142 $ps->{papersize}->[1] );
592  
593 142 $self->{pdfgfx} = $self->{pdfpage}->gfx;
594 142 $self->{pdftext} = $self->{pdfpage}->text;
595 142 ▶ unless ($ps->{theme}->{background} =~ /^white|none|#ffffff$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ps->{"theme"}{"background"} =~ /^white|none|#ffffff$/i) 0 142 142
596 0 for ( $self->{pdfgfx} ) {
597 0 $_->save;
598 0 $_->fillcolor( $ps->{theme}->{background} );
599 0 $_->linewidth(0);
600 $_->rectxy( 0, 0, $ps->{papersize}->[0],
601 0 $ps->{papersize}->[1] );
602 0 $_->fill;
603 0 $_->restore;
604 }
605 }
606 }
607  
608 # Align.
609 # Ordinal page numbers start with 1.
610 # Assuming the next page to be written is $page, do we need
611 # to insert alignment pages?
612 # If so, insert them, and return the number of pages inserted (zero or one).
613 # Alignment is to an odd page, except for the back matter, whose
614 # final page must be even.
615  
616 92 ▶sub page_align {
Subroutine page_align: called CC=4 SCAR=17.1
Pod undocumented
617 92 my ( $self, $pagectrl, $part, $page, $even ) = @_;
618 92 my $ret = $self->_page_align( $pagectrl, $part, $page, $even );
619 warn( "ALIGN( $part, page $page, ",
620 defined($even) ? "even $even, " : "",
621 ChordPro::Output::PDF::pagectrl_msg($pagectrl),
622 " ) -> $ret\n")
623 if exists($::config->{debug}->{pagealign})
624 92 ▶ && $::config->{debug}->{pagealign};
Branch: 2 branches
BranchTrueFalseTotal
if exists $main::config->{"debug"}{"pagealign"} and $main::config->{"debug"}{"pagealign"} 0 92 92
defined $even ? : 0 0 0
Condition33%1/3
exists $main::config->{"debug"}{"pagealign"} and $main::config->{"debug"}{"pagealign"}
!ll&&!rl&&r
9200
MC/DC0%0/2
exists $main::config->{"debug"}{"pagealign"} and $main::config->{"debug"}{"pagealign"}
exists $main::config->{"debug"}{"pagealign"} $main::config->{"debug"}{"pagealign"}
Truth table33%1/3
A and B
A= exists $main::config->{"debug"}{"pagealign"}B= $main::config->{"debug"}{"pagealign"}
ABresult
0X0
100
111
625 92 return $ret;
626 }
627  
628 92 ▶sub _page_align {
Subroutine _page_align: called CC=11 SCAR=28.8
629 92 my ( $self, $pagectrl, $part, $page, $even ) = @_;
630 92 ▶ $even ||= 0;
Condition100%2/2
$even ||= 0
l!l
686
MC/DC100%1/1
$even ||= 0
$even
Truth table100%2/2
A
A= $even
Aresult
11
00
631  
632 # Only align to odd pages.
633 92 ▶ return 0 if $even xor is_odd($page); # already odd/even
Branch: 1 branch
BranchTrueFalseTotal
if $even xor is_odd($page) 50 42 92
Condition100%4/4
$even xor is_odd($page)
l&&rl&&!r!l&&r!l&&!r
154541
MC/DC100%2/2
$even xor is_odd($page)
$even is_odd($page)
Truth table100%4/4
A xor B
A= $evenB= is_odd($page)
ABresult
110
101
011
000
634 42 ▶ return 0 unless $pagectrl->{dual_pages}; # no alignment
Branch: 1 branch
BranchTrueFalseTotal
unless $pagectrl->{"dual_pages"} 4 38 42
635 38 ▶ return 0 unless $pagectrl->{align_songs}; # no alignment
Branch: 1 branch
BranchTrueFalseTotal
unless $pagectrl->{"align_songs"} 1 37 38
636  
637 12 ▶ use List::Util 'shuffle';
Subroutine BEGIN: called CC=1 SCAR=0.0
638 37 my $ps = $self->{ps};
639 37 my $bg;
640 my $ffile;
641 37 my $filler;
642 37 ▶ if ( ($bg = $ps->{formats}->{filler}->{background})
Branch: 1 branch
BranchTrueFalseTotal
if ($bg = $ps->{'formats'}{'filler'}{'background'} and $ffile = expand_tilde($bg) and $filler = $self->{'pdfapi'}->open($ffile)) { } 0 37 37
Condition33%2/6
$bg = $ps->{"formats"}{"filler"}{"background"} and $ffile = expand_tilde($bg) and $filler = $self->{"pdfapi"}->open($ffile)
!ll&&!rl&&r
3700
$bg = $ps->{"formats"}{"filler"}{"background"} and $ffile = expand_tilde($bg)
!ll&&!rl&&r
3700
MC/DC0%0/3
$bg = $ps->{"formats"}{"filler"}{"background"} and $ffile = expand_tilde($bg) and $filler = $self->{"pdfapi"}->open($ffile)
$bg = $ps->{"formats"}{"filler"}{"background"} $ffile = expand_tilde($bg) $filler = $self->{"pdfapi"}->open($ffile)
Truth table25%1/4
A and B and C
A= $bg = $ps->{"formats"}{"filler"}{"background"}B= $ffile = expand_tilde($bg)C= $filler = $self->{"pdfapi"}->open($ffile)
ABCresult
0XX0
10X0
1100
1111
643 &&
644 ( $ffile = expand_tilde($bg) )
645 &&
646 ( $filler = $self->{pdfapi}->open($ffile) )
647 ) {
648 0 state $file = "";
649 0 state @pages;
650 0 ▶ if ( $file ne $ffile || !@pages ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file ne $ffile or not @pages) 0 0 0
Condition0%0/3
$file ne $ffile or not @pages
l!l&&r!l&&!r
000
MC/DC0%0/2
$file ne $ffile or not @pages
$file ne $ffile not @pages
Truth table0%0/3
A or not(B)
A= $file ne $ffileB= not @pages
ABresult
1X1
011
000
651 0 $file = $ffile;
652 # Try to make it reproducible.
653 0 local $ENV{PERL_HASH_SEED} = 0x12a02ab;
654 0 srand();
655 0 @pages = shuffle( 1..$filler->pages );
656 }
657 # Pick a random page.
658 0 $self->{pdf}->import_page( $filler, shift(@pages), $page );
659 }
660 else {
661 37 $self->newpage($page);
662 }
663 37 return 1; # number of pages added
664 }
665  
666 105 ▶sub openpage {
Subroutine openpage: called CC=2 SCAR=7.0
Pod undocumented
667 105 my ( $self, $page ) = @_;
668 105 $self->{pdfpage} = $self->{pdf}->openpage($page);
669 105 ▶ confess("Fatal: Page $page not found.") unless $self->{pdfpage};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"pdfpage"} 0 105 105
670 105 $self->{pdfgfx} = $self->{pdfpage}->gfx;
671 105 $self->{pdftext} = $self->{pdfpage}->text;
672 }
673  
674 0 ▶sub importpage {
Subroutine importpage: not called CC=3 SCAR=24.8
Pod undocumented
675 0 my ( $self, $fn, $pg ) = @_;
676 0 my $bg = $self->{pdfapi}->open($fn);
677 0 ▶ return unless $bg; # should have been checked
Branch: 1 branch
BranchTrueFalseTotal
unless $bg 0 0 0
678 0 ▶ $pg = $bg->pages if $pg > $bg->pages;
Branch: 1 branch
BranchTrueFalseTotal
if $pg > $bg->pages 0 0 0
679 0 $self->{pdf}->import_page( $bg, $pg, $self->{pdfpage} );
680 # Make sure the contents get on top of it.
681 0 $self->{pdfgfx} = $self->{pdfpage}->gfx;
682 0 $self->{pdftext} = $self->{pdfpage}->text;
683 }
684  
685 0 ▶sub importfile {
Subroutine importfile: not called CC=3 SCAR=24.8
Pod undocumented
686 0 my ( $self, $filename ) = @_;
687 0 my $pdf = $self->{pdfapi}->open($filename);
688 0 ▶ return unless $pdf; # should have been checked
Branch: 1 branch
BranchTrueFalseTotal
unless $pdf 0 0 0
689 0 ▶ for ( my $page = 1; $page <= $pdf->pages; $page++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page <= $pdf->pages) 0 0 0
690 0 $self->{pdf}->import_page( $pdf, $page );
691 }
692 0 return { pages => $pdf->pages, $pdf->info_metadata };
693 }
694  
695 43 ▶sub pagelabel {
Subroutine pagelabel: called CC=10 SCAR=26.2
Pod undocumented
696 43 my ( $self, $page, $style, $prefix, $start ) = @_;
697 43 ▶ $style //= 'arabic';
Condition50%1/2
$style //= "arabic"
l!l
430
MC/DC0%0/1
$style //= "arabic"
$style
Truth table50%1/2
A
A= $style
Aresult
11
00
698 43 ▶ $start //= 1;
Condition100%2/2
$start //= 1
l!l
1330
MC/DC100%1/1
$start //= 1
$start
Truth table100%2/2
A
A= $start
Aresult
11
00
699  
700 # PDF::API2 2.042 has some incompatible changes...
701 43 my $c = $self->{pdf}->can("page_labels");
702 43 ▶ if ( $c ) { # 2.042+
Branch: 1 branch
BranchTrueFalseTotal
if ($c) { } 43 0 43
703 43 ▶ my $opts = { style => $style eq 'Roman' ? 'R' :
Branch: 5 branches
BranchTrueFalseTotal
$style eq 'Roman' ? : 0 43 43
$style eq 'roman' ? : 9 34 43
$style eq 'Alpha' ? : 0 34 34
$style eq 'alpha' ? : 0 34 34
defined $prefix ? : 34 9 43
704 $style eq 'roman' ? 'r' :
705 $style eq 'Alpha' ? 'A' :
706 $style eq 'alpha' ? 'a' : 'D',
707 defined $prefix ? ( prefix => $prefix ) : (),
708 start => $start };
709 43 $c->( $self->{pdf}, $page+1, %$opts );
710 }
711 else {
712 0 ▶ my $opts = { -style => $style,
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 0 0
713 defined $prefix ? ( -prefix => $prefix ) : (),
714 -start => $start };
715 0 $self->{pdf}->pageLabel( $page, $opts );
716 }
717 }
718  
719 13 ▶sub make_outlines {
Subroutine make_outlines: called CC=31 SCAR=38.9
Pod undocumented
720 13 my ( $self, $bk, $start ) = @_;
721 13 ▶ return unless $bk && @$bk; # unlikely
Branch: 1 branch
BranchTrueFalseTotal
unless $bk and @$bk 0 13 13
Condition33%1/3
$bk and @$bk
!ll&&!rl&&r
0013
MC/DC0%0/2
$bk and @$bk
$bk @$bk
Truth table33%1/3
A and B
A= $bkB= @$bk
ABresult
0X0
100
111
722  
723 13 my $pdf = $self->{pdf};
724 13 $start--; # 1-relative
725 13 my $ol_root;
726  
727 # Process outline defs from config.
728 13 foreach my $ctl ( @{ $self->{ps}->{outlines} } ) {
729 39 ▶ next if is_true( $ctl->{omit} // 0 );
Branch: 1 branch
BranchTrueFalseTotal
if is_true($ctl->{"omit"} // 0) 13 26 39
Condition100%2/2
$ctl->{"omit"} // 0
l!l
1326
MC/DC100%1/1
$ctl->{"omit"} // 0
$ctl->{"omit"}
Truth table100%2/2
A
A= $ctl->{"omit"}
Aresult
11
00
730 26 my $book;
731  
732 26 ▶ if ( @{$ctl->{fields}} == 1 && $ctl->{fields}->[0] eq "bookmark" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$ctl->{'fields'};} == 1 and $ctl->{'fields'}[0] eq 'bookmark') { } 0 26 26
Condition33%1/3
@{$ctl->{"fields"};} == 1 and $ctl->{"fields"}[0] eq "bookmark"
!ll&&!rl&&r
2600
MC/DC0%0/2
@{$ctl->{"fields"};} == 1 and $ctl->{"fields"}[0] eq "bookmark"
@{$ctl->{"fields"};} == 1 $ctl->{"fields"}[0] eq "bookmark"
Truth table33%1/3
A and B
A= @{$ctl->{"fields"};} == 1B= $ctl->{"fields"}[0] eq "bookmark"
ABresult
0X0
100
111
733 0 my @book;
734 0 ▶ while ( my ($k,$v) = each %{$self->{ps}->{pr}->{_nd}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"ps"}{"pr"}{"_nd"};}) 0 0 0
735 0 push( @book,
736 0 [ $k =~ s/^song_([0-9]+)$/sprintf("song_%06d",$1)/er,
737 { meta => { tocpage => $v,
738 bookmark => $k } } ] );
739 }
740 0 my $cmp = Unicode::Collate->new;
741 0 $book = [ sort { $cmp->cmp($a->[0], $b->[0]) } @book ];
742 }
743 else {
744 26 $book = prep_outlines( $bk, $ctl );
745 }
746 26 ▶ next unless @$book;
Branch: 1 branch
BranchTrueFalseTotal
unless @$book 0 26 26
747  
748 # Seems not to matter whether we re-use the root or create new.
749 26 ▶ $ol_root //= $pdf->outlines;
Condition66%2/3
$ol_root //= $pdf->outlines
l!l&&r!l&&!r
13130
MC/DC0%0/2
$ol_root //= $pdf->outlines
$ol_root $pdf->outlines
Truth table66%2/3
A //= B
A= $ol_rootB= $pdf->outlines
ABresult
1X1
011
000
750  
751 26 my $outline;
752  
753 # Skip level for a single outline.
754 26 ▶ if ( @{ $self->{ps}->{outlines} } == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'ps'}{'outlines'};} == 1) { } 0 26 26
755 0 $outline = $ol_root;
756 0 ▶ $outline->closed if $ctl->{collapse}; # TODO?
Branch: 1 branch
BranchTrueFalseTotal
if $ctl->{"collapse"} 0 0 0
757 }
758 else {
759 26 $outline = $ol_root->outline;
760 26 $outline->title( $ctl->{label} );
761 26 ▶ $outline->closed if $ctl->{collapse};
Branch: 1 branch
BranchTrueFalseTotal
if $ctl->{"collapse"} 0 26 26
762 }
763  
764 26 my %lh; # letter hierarchy
765 26 my $needlh = 0;
766 26 ▶ if ( $ctl->{letter} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctl->{"letter"} > 0) 26 0 26
767 26 for ( @$book ) {
768 # Group on first letter.
769 # That's why we left the sort fields in...
770 110 my $cur = uc(substr(NFKD($_->[0]),0,1) );
771 110 ▶ $lh{$cur} //= [];
Condition100%2/2
$lh{$cur} //= []
l!l
6446
MC/DC100%1/1
$lh{$cur} //= []
$lh{$cur}
Truth table100%2/2
A
A= $lh{$cur}
Aresult
11
00
772 # Last item is the song.
773 110 push( @{$lh{$cur}}, $_->[-1] );
774 }
775 # Need letter hierarchy?
776 26 $needlh = keys(%lh) >= $ctl->{letter};
777 }
778  
779 26 ▶ if ( $needlh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($needlh) { } 4 22 26
780 4 my $cur_ol;
781 4 my $cur_let = "";
782 4 my $cmp = Unicode::Collate->new;
783 4 foreach my $let ( $cmp->sort( keys %lh )) {
784 24 my $prev_title = "";
785 24 foreach my $song ( @{$lh{$let}} ) {
786 28 ▶ unless ( defined $cur_ol && ( $let eq $cur_let ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cur_ol and $let eq $cur_let) 24 4 28
Condition100%3/3
defined $cur_ol and $let eq $cur_let
!ll&&!rl&&r
4204
MC/DC100%2/2
defined $cur_ol and $let eq $cur_let
defined $cur_ol $let eq $cur_let
Truth table100%3/3
A and B
A= defined $cur_olB= $let eq $cur_let
ABresult
0X0
100
111
787 # Intermediate level autoline.
788 24 $cur_ol = $outline->outline;
789 24 $cur_ol->title($let);
790 24 $cur_let = $let;
791 24 $prev_title = "";
792 }
793 28 my $title = demarkup( fmt_subst( $song, $ctl->{line} ) );
794 28 ▶ next if $title eq $prev_title;
Branch: 1 branch
BranchTrueFalseTotal
if $title eq $prev_title 4 24 28
795 # Leaf outline.
796 24 my $ol = $cur_ol->outline;
797 # Display info.
798 24 $ol->title($title);
799 24 my $p = $song->{meta}->{tocpage};
800 24 ▶ $p = $pdf->openpage( $p + $start ) unless ref($p);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p 24 0 24
801 24 ▶ my $c = $ol->can("destination") // $ol->can("dest");
Condition33%1/3
$ol->can("destination") // $ol->can("dest")
l!l&&r!l&&!r
2400
MC/DC0%0/2
$ol->can("destination") // $ol->can("dest")
$ol->can("destination") $ol->can("dest")
Truth table33%1/3
A // B
A= $ol->can("destination")B= $ol->can("dest")
ABresult
1X1
011
000
802 24 $ol->$c($p);
803 24 $prev_title = $title;
804 }
805 }
806 }
807 else {
808 22 my $prev_title = "";
809 ####TODO: Why?
810 22 ▶ if ( @$book == 1 && ref($book->[0]) eq 'ChordPro::Song' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$book == 1 and ref $book->[0] eq "ChordPro::Song") 0 22 22
Condition33%1/3
@$book == 1 and ref $book->[0] eq "ChordPro::Song"
!ll&&!rl&&r
2200
MC/DC0%0/2
@$book == 1 and ref $book->[0] eq "ChordPro::Song"
@$book == 1 ref $book->[0] eq "ChordPro::Song"
Truth table33%1/3
A and B
A= @$book == 1B= ref $book->[0] eq "ChordPro::Song"
ABresult
0X0
100
111
811 0 $book = [[ $book->[0] ]];
812 }
813 22 foreach my $b ( @$book ) {
814 82 my $song = $b->[-1];
815 82 my $title = demarkup( fmt_subst( $song, $ctl->{line} ) );
816 82 ▶ next if $title eq $prev_title;
Branch: 1 branch
BranchTrueFalseTotal
if $title eq $prev_title 4 78 82
817 # Leaf outline.
818 78 my $ol = $outline->outline;
819 # Display info.
820 78 $ol->title($title);
821 78 my $p = $song->{meta}->{tocpage};
822 78 ▶ $p = $pdf->openpage( $p + $start ) unless ref($p);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p 78 0 78
823 78 ▶ my $c = $ol->can("destination") // $ol->can("dest");
Condition33%1/3
$ol->can("destination") // $ol->can("dest")
l!l&&r!l&&!r
7800
MC/DC0%0/2
$ol->can("destination") // $ol->can("dest")
$ol->can("destination") $ol->can("dest")
Truth table33%1/3
A // B
A= $ol->can("destination")B= $ol->can("dest")
ABresult
1X1
011
000
824 78 $ol->$c($p);
825 78 $prev_title = $title;
826 }
827 }
828 }
829  
830 =for xxx
831  
832 # Add bookmarks.
833 my $outline = $ol_root->outline;
834 $outline->title("Bookmarks");
835 $outline->closed;
836  
837 my @tops =
838 map { $_->[0] }
839 sort { $a->[1] cmp $b->[1] }
840 map { [ $_ => s/^song_([0-9]+)$/sprintf("song_%06d",$1)/er ] }
841 grep { ! /^(?:cover|front|toc|back)$/ }
842 keys %{ $self->{_nd} };
843  
844 for ( "cover", "front", "toc", @tops, "back" ) {
845 next unless my $p = $self->{_nd}->{$_};
846 my $ol = $outline->outline;
847 $ol->title($_);
848 if ( my $c = $ol->can("destination") ) {
849 $c->( $ol, $p );
850 }
851 else {
852 $ol->dest($p);
853 }
854 }
855  
856 =cut
857  
858 }
859  
860 13 ▶sub finish {
Subroutine finish: called CC=4 SCAR=16.8
Pod undocumented
861 13 my ( $self, $file ) = @_;
862  
863 ::dump($self->{pdf}->{pagestack})
864 13 ▶ if $::config->{debug}->{pages} & 0x04;
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"pages"} & 4 0 13 13
865  
866 13 ▶ if ( $file && $file ne "-" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and $file ne '-') { } 13 0 13
Condition33%1/3
$file and $file ne "-"
!ll&&!rl&&r
0013
MC/DC0%0/2
$file and $file ne "-"
$file $file ne "-"
Truth table33%1/3
A and B
A= $fileB= $file ne "-"
ABresult
0X0
100
111
867 13 my $fd = fs_open( $file, '>:raw' );
868 13 print $fd $self->{pdf}->stringify;
869 13 close($fd);
870 }
871 else {
872 0 binmode(STDOUT);
873 0 print STDOUT ( $self->{pdf}->stringify );
874 0 close(STDOUT);
875 }
876 }
877  
878 80 ▶sub init_fonts {
Subroutine init_fonts: called CC=21 SCAR=33.7
Pod undocumented
879 80 my ( $self ) = @_;
880 80 my $ps = $self->{ps};
881 80 my $fail;
882  
883 80 my $fc = Text::Layout::FontConfig->new( debug => $config->{debug}->{fonts} > 1 );
884  
885 # Add font dirs.
886 80 my @dirs;
887 80 my @d = ( @{$ps->{fontdir}}, @{ CP->findresdirs("fonts") }, $ENV{FONTDIR} );
888 # Avoid rsc result if dummy.
889 80 ▶ splice( @d, -2, 1 ) if $d[-2] eq "fonts/";
Branch: 1 branch
BranchTrueFalseTotal
if $d[-2] eq "fonts/" 0 80 80
890 80 for my $fontdir ( @d ) {
891 160 ▶ next unless $fontdir;
Branch: 1 branch
BranchTrueFalseTotal
unless $fontdir 80 80 160
892 80 $fontdir = expand_tilde($fontdir);
893 80 ▶ if ( fs_test( d => $fontdir ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_test('d', $fontdir)) { } 80 0 80
894 80 $self->{pdfapi}->can("addFontDirs")->($fontdir);
895 80 $fc->add_fontdirs($fontdir);
896 80 push( @dirs, $fontdir );
897 }
898 else {
899 0 warn("PDF: Ignoring fontdir $fontdir [$!]\n");
900 0 undef $fontdir;
901 }
902 }
903  
904 # Make sure we have this one.
905 80 $fc->register_font( "ChordProSymbols.ttf", "chordprosymbols", "", {} );
906  
907 # Remap corefonts if possible.
908 80 ▶ my $remap = $ENV{CHORDPRO_COREFONTS_REMAP} // $ps->{corefonts}->{remap};
Condition33%1/3
$ENV{"CHORDPRO_COREFONTS_REMAP"} // $ps->{"corefonts"}{"remap"}
l!l&&r!l&&!r
0080
MC/DC0%0/2
$ENV{"CHORDPRO_COREFONTS_REMAP"} // $ps->{"corefonts"}{"remap"}
$ENV{"CHORDPRO_COREFONTS_REMAP"} $ps->{"corefonts"}{"remap"}
Truth table33%1/3
A // B
A= $ENV{"CHORDPRO_COREFONTS_REMAP"}B= $ps->{"corefonts"}{"remap"}
ABresult
1X1
011
000
909 # Packager adds the fonts.
910 80 ▶ $remap //= "free" if CP->packager;
Branch: 1 branch
BranchTrueFalseTotal
if CP()->packager 0 80 80
Condition0%0/2
$remap //= "free"
l!l
00
MC/DC0%0/1
$remap //= "free"
$remap
Truth table0%0/2
A
A= $remap
Aresult
11
00
911  
912 80 ▶ unless ( defined $remap ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $remap) 80 0 80
913  
914 # Not defined -- find the GNU Free Fonts.
915 80 for my $dir ( @dirs ) {
916 80 my $have = 1;
917 80 for my $font ( qw( FreeSerif.ttf
918 FreeSerifBoldItalic.ttf
919 FreeSerifBold.ttf
920 FreeSerifItalic.ttf
921 FreeSans.ttf
922 FreeSansBoldOblique.ttf
923 FreeSansBold.ttf
924 FreeSansOblique.ttf
925 FreeMono.ttf
926 FreeMonoBoldOblique.ttf
927 FreeMonoBold.ttf
928 FreeMonoOblique.ttf
929 ) ) {
930 960 ▶ $have = 0, last unless fs_test( fs => "$dir/$font" );
Branch: 1 branch
BranchTrueFalseTotal
unless fs_test("fs", "$dir/$font") 0 960 960
931 }
932 80 ▶ $remap = "free", last if $have;
Branch: 1 branch
BranchTrueFalseTotal
if $have 80 0 80
933 }
934 }
935 80 ▶ $fc->register_corefonts( remap => $remap ) if $remap;
Branch: 1 branch
BranchTrueFalseTotal
if $remap 80 0 80
936  
937 # Process the fontconfig.
938 80 foreach my $ff ( keys( %{ $ps->{fontconfig} } ) ) {
939 880 my @fam = split( /\s*,\s*/, $ff );
940 880 foreach my $s ( keys( %{ $ps->{fontconfig}->{$ff} } ) ) {
941 3280 my $v = $ps->{fontconfig}->{$ff}->{$s};
942 3280 ▶ if ( is_hashref($v) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_hashref($v)) { } 0 3280 3280
943 0 my $file = delete( $v->{file} );
944 0 $fc->register_font( $file, $fam[0], $s, $v );
945 }
946 else {
947 3280 $fc->register_font( $v, $fam[0], $s );
948 }
949 }
950 880 ▶ $fc->register_aliases(@fam) if @fam > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @fam > 1 0 880 880
951 }
952  
953 80 foreach my $ff ( keys( %{ $ps->{fonts} } ) ) {
954 1760 ▶ $self->init_font($ff) or $fail++;
Branch: 1 branch
BranchTrueFalseTotal
$self->init_font($ff) or ++$fail 1760 0 1760
955 }
956  
957 80 ▶ die("Unhandled fonts detected -- aborted\n") if $fail;
Branch: 1 branch
BranchTrueFalseTotal
if $fail 0 80 80
958 }
959  
960 1760 ▶sub init_font {
Subroutine init_font: called CC=5 SCAR=16.2
Pod undocumented
961 1760 my ( $self, $ff ) = @_;
962 1760 my $ps = $self->{ps};
963 1760 my $fd;
964 1760 ▶ if ( $ps->{fonts}->{$ff}->{file} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ps->{'fonts'}{$ff}{'file'}) { } 80 1680 1760
elsif ($ps->{'fonts'}{$ff}{'description'}) { } 160 1520 1680
elsif ($ps->{'fonts'}{$ff}{'name'}) { } 1520 0 1520
965 80 $fd = $self->init_filefont($ff);
966 }
967 elsif ( $ps->{fonts}->{$ff}->{description} ) {
968 160 $fd = $self->init_pangofont($ff);
969 }
970 elsif ( $ps->{fonts}->{$ff}->{name} ) {
971 1520 $fd = $self->init_corefont($ff);
972 }
973 1760 ▶ warn("No font found for \"$ff\"\n") unless $fd;
Branch: 1 branch
BranchTrueFalseTotal
unless $fd 0 1760 1760
974 1760 $fd;
975 }
976  
977 160 ▶sub init_pangofont {
Subroutine init_pangofont: called CC=6 SCAR=18.4
Pod undocumented
978 160 my ( $self, $ff ) = @_;
979  
980 160 my $ps = $self->{ps};
981 160 my $font = $ps->{fonts}->{$ff};
982  
983 160 my $fc = Text::Layout::FontConfig->new( debug => $config->{debug}->{fonts} > 1 );
984 160 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $font->{"fd"} = $fc->from_string($font->{"description"}); $font->{"fd"}->get_font($self->{"layout"}); $font->{"fd"}{"font"}{"Name"}{"val"} =~ s/~.*/~$faketime/ if $regtest; $font->{"_ff"} = $ff; $font->{"fd"}->set_shaping(($font->{"fd"}->get_shaping || $font->{"shaping"}) // 0); $font->{"size"} = $font->{"fd"}->get_size if $font->{"fd"}->get_size; 1 } } or return 160 0 160
985 160 $font->{fd} = $fc->from_string($font->{description});
986 160 $font->{fd}->get_font($self->{layout}); # force load
987 160 ▶ $font->{fd}->{font}->{Name}->{val} =~ s/~.*/~$faketime/ if $regtest;
Branch: 1 branch
BranchTrueFalseTotal
if $regtest 0 160 160
988 160 $font->{_ff} = $ff;
989 160 ▶ $font->{fd}->set_shaping( $font->{fd}->get_shaping || $font->{shaping}//0);
Condition40%2/5
($font->{"fd"}->get_shaping || $font->{"shaping"}) // 0
l!l
0160
$font->{"fd"}->get_shaping or $font->{"shaping"}
l!l&&r!l&&!r
00160
MC/DC0%0/2
($font->{"fd"}->get_shaping || $font->{"shaping"}) // 0
$font->{"fd"}->get_shaping $font->{"shaping"}
Truth table33%1/3
A or B
A= $font->{"fd"}->get_shapingB= $font->{"shaping"}
ABresult
1X1
011
000
990 160 ▶ $font->{size} = $font->{fd}->get_size if $font->{fd}->get_size;
Branch: 1 branch
BranchTrueFalseTotal
if $font->{"fd"}->get_size 80 80 160
991 160 1;
992 } or return;
993 160 $font->{fd};
994 }
995  
996 80 ▶sub init_filefont {
Subroutine init_filefont: called CC=2 SCAR=6.9
Pod undocumented
997 80 my ( $self, $ff ) = @_;
998  
999 80 my $ps = $self->{ps};
1000 80 my $font = $ps->{fonts}->{$ff};
1001  
1002 80 my $fc = Text::Layout::FontConfig->new( debug => $config->{debug}->{fonts} > 1 );
1003 80 eval {
1004 80 my $t = $fc->from_filename(expand_tilde($font->{file}));
1005 80 $t->get_font($self->{layout}); # force load
1006 80 ▶ $t->{font}->{Name}->{val} =~ s/~.*/~$faketime/ if $regtest;
Branch: 1 branch
BranchTrueFalseTotal
if $regtest 0 80 80
1007 80 $t->{_ff} = $ff;
1008 80 $font->{fd} = $t;
1009 };
1010 80 $font->{fd};
1011 }
1012  
1013 1520 ▶sub init_corefont {
Subroutine init_corefont: called CC=2 SCAR=6.9
Pod undocumented
1014 1520 my ( $self, $ff ) = @_;
1015  
1016 1520 my $ps = $self->{ps};
1017 1520 my $font = $ps->{fonts}->{$ff};
1018 1520 my $cf = is_corefont($font->{name});
1019 1520 ▶ die("Config error: \"$font->{name}\" is not a built-in font\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $cf 0 1520 1520
1020 unless $cf;
1021 1520 my $fc = Text::Layout::FontConfig->new( debug => $config->{debug}->{fonts} > 1 );
1022 1520 eval {
1023 1520 $font->{fd} = $fc->from_filename($cf);
1024 1520 $font->{fd}->get_font($self->{layout}); # force load
1025 1520 $font->{_ff} = $ff;
1026 };
1027 1520 $font->{fd};
1028 }
1029  
1030 0 ▶sub show_vpos {
Subroutine show_vpos: not called CC=1 SCAR=6.9
Pod undocumented
1031 0 my ( $self, $y, $w ) = @_;
1032 0 $self->{pdfgfx}->move(100*$w,$y)->linewidth(0.25)->hline(100*(1+$w))->stroke;
1033 }
1034  
1035 0 ▶sub embed {
Subroutine embed: not called CC=2 SCAR=17.9
Pod undocumented
1036 0 my ( $self, $file ) = @_;
1037 0 ▶ return unless fs_test( 'f', $file );
Branch: 1 branch
BranchTrueFalseTotal
unless fs_test("f", $file) 0 0 0
1038  
1039 # Borrow some routines from PDF Api.
1040 0 *PDFNum = \&{$self->{pdfapi} . '::Basic::PDF::Utils::PDFNum'};
1041 0 *PDFStr = \&{$self->{pdfapi} . '::Basic::PDF::Utils::PDFStr'};
1042  
1043 # The song.
1044 # Apparently the 'hidden' flag does not hide it completely,
1045 # so give it a rect outside the page.
1046 0 my $a = $self->{pdfpage}->annotation();
1047 0 $a->text( fs_load( $file, { fail => "soft", split => 0 } ),
1048 -open => 0, -rect => [0,0,-1,-1] );
1049 0 $a->{T} = PDFStr("ChordProSong");
1050 0 $a->{F} = PDFNum(2); # hidden
1051  
1052 # The config.
1053 0 $a = $self->{pdfpage}->annotation();
1054 0 $a->text( ChordPro::Config::config_final(),
1055 -open => 0, -rect => [0,0,-1,-1]);
1056 0 $a->{T} = PDFStr("ChordProConfig");
1057 0 $a->{F} = PDFNum(2); # hidden
1058  
1059 # Runtime info.
1060 0 $a = $self->{pdfpage}->annotation();
1061 0 $a->text( ::runtimeinfo(),
1062 -open => 0, -rect => [0,0,-1,-1] );
1063 0 $a->{T} = PDFStr("ChordProRunTime");
1064 0 $a->{F} = PDFNum(2); # hidden
1065  
1066 # Call.
1067 0 $a = $self->{pdfpage}->annotation();
1068 0 $a->text( join(" ", @{$::options->{_argv}}) . "\n",
1069 -open => 0, -rect => [0,0,-1,-1] );
1070 0 $a->{T} = PDFStr("ChordProCall");
1071 0 $a->{F} = PDFNum(2); # hidden
1072 }
1073  
1074 # Add a Named Destination.
1075  
1076 91 ▶sub named_dest {
Subroutine named_dest: called CC=2 SCAR=7.0
Pod undocumented
1077 91 my ( $self, $name, $page ) = @_;
1078 91 ▶ $name = $name->[-1] if is_arrayref($name);
Branch: 1 branch
BranchTrueFalseTotal
if is_arrayref($name) 0 91 91
1079 91 my $pdf = $self->{pdf};
1080 91 my $nd = ref($pdf) . '::NamedDestination';
1081 91 my $dest = $nd->new($pdf);
1082 91 $dest->goto( $page, xyz => (undef,undef,undef) );
1083 91 $pdf->named_destination( 'Dests', $name, $dest );
1084 91 $pdf->named_dest_register( $name, $page );
1085 }
1086  
1087 91 ▶sub pdfapi_named_dest_register {
Subroutine pdfapi_named_dest_register: called CC=2 SCAR=7.1
Pod undocumented
1088 91 my ( $self, $name, $page ) = @_;
1089 91 ▶ Carp::cluck("Undef \$name in pdfapi_named_dest_register")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 91 91
1090 unless defined $name;
1091 91 $self->{_pr}->{_nd}->{$name} = $page;
1092 }
1093  
1094 0 ▶sub pdfapi_named_dest_fiddle {
Subroutine pdfapi_named_dest_fiddle: not called CC=2 SCAR=17.9
Pod undocumented
1095 0 my ( $self, $name ) = @_;
1096 0 ▶ $name eq 'top' ? $self->{_pr}->{bookmark} : $name;
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'top' ? : 0 0 0
1097 }
1098  
1099 # Enhanced version that allows named destinations.
1100 0 ▶sub pdfapi_annotation_pdf {
Subroutine pdfapi_annotation_pdf: not called CC=7 SCAR=40.3
Pod undocumented
1101 package PDF::API2;
1102 0 my $self = shift();
1103 0 my $file = shift();
1104 0 my $dest = shift();
1105 0 my $location;
1106 my @args;
1107  
1108 # Deprecated options
1109 0 my %options;
1110 0 ▶ if ($_[0] and $_[0] =~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and $_[0] =~ /^-/) { } 0 0 0
Condition0%0/3
$_[0] and $_[0] =~ /^-/
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and $_[0] =~ /^-/
$_[0] $_[0] =~ /^-/
Truth table0%0/3
A and B
A= $_[0]B= $_[0] =~ /^-/
ABresult
0X0
100
111
1111 0 %options = @_;
1112 }
1113 else {
1114 0 $location = shift();
1115 0 @args = @_;
1116 }
1117  
1118 0 $self->{'Subtype'} = PDFName('Link');
1119 0 $self->{'A'} = PDFDict();
1120 0 $self->{'A'}->{'S'} = PDFName('GoToR');
1121 0 $self->{'A'}->{'F'} = PDFStr($file);
1122  
1123 0 ▶ unless (%options) {
Branch: 1 branch
BranchTrueFalseTotal
if (%options) { } 0 0 0
1124 0 ▶ if ( $dest =~ /^\/(.+)/ ) { # named dest
Branch: 1 branch
BranchTrueFalseTotal
if ($dest =~ m[^/(.+)]) { } 0 0 0
1125 0 $self->{'A'}->{'D'} = PDFName($1);
1126 }
1127 else {
1128 0 my $destination = PDFNum($dest);
1129 0 $self->{'A'}->{'D'} = _destination($destination, $location, @args);
1130 }
1131 }
1132 else {
1133 # Deprecated
1134 0 $self->dest(PDFNum($dest), %options);
1135 0 ▶ $self->rect(@{$options{'-rect'}}) if defined $options{'-rect'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"-rect"} 0 0 0
1136 0 ▶ $self->border(@{$options{'-border'}}) if defined $options{'-border'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"-border"} 0 0 0
1137 }
1138  
1139 0 return $self;
1140 }
1141  
1142 # Prevent from blowing up.
1143 2406 ▶sub pdfapi_outobjdeep {
Subroutine pdfapi_outobjdeep: called CC=3 SCAR=11.2
Pod undocumented
1144 2406 my ( $self, $fh, $pdf ) = @_;
1145  
1146 2406 $fh->print('[ ');
1147 2406 foreach my $obj (@{$self->{' val'}}) {
1148 # if no graphics object (page->gfx), creates an invalid Contents object
1149 # (unblessed HASH containing no keys) for this page's graphics, and
1150 # this function blows up
1151 0 ▶ if ($obj !~ /^PDF::API2/) { next; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj =~ /^PDF::API2/) 0 7128 7128
1152  
1153 7128 $obj->outobj($fh, $pdf);
1154 7128 $fh->print(' ');
1155 }
1156 2406 $fh->print(']');
1157 }
1158  
1159 12 1;
« lib/ChordPro/lib/SVGPDF/Rect.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Colour.pm »