PlayTab/Output/PDF.pm

filter: Statementstmt 17.2% 99 / 573 Branchbran 0.0% 0 / 160 Conditioncond 0.0% 0 / 59 MC/DCmcdc 0.0% 0 / 37 Subroutinesub 33.7% 26 / 77 Podpod 0.0% 0 / 28 totaltotal 13.3% 125 / 934 CC 118 SCAR 49.1
CC
118
Cov
12%
render
506.0
width
506.0
pagesettings
110.0
CRAP 135.5
↑ Summary PlayTab.pm »
1 #! perl
2  
3 # Author : Johan Vromans
4 # Created On : Tue Apr 15 11:02:34 2014
5 # Last Modified By: Johan Vromans
6 # Last Modified On: Fri Apr 7 17:28:35 2017
7 # Update Count : 698
8 # Status : Unknown, Use with caution!
9  
10 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 package App::Music::PlayTab::Output::PDF;
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use App::Packager;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 our $VERSION = "0.002";
19  
20 # Globals.
21  
22 1 my $ps =
23 { papersize => [ 595, 840 ], # A4, portrait
24 marginleft => 50,
25 margintop => 40,
26 marginbottom => 50,
27 marginright => 45, # only used for page number!
28 lineheight => 15,
29 fonts => {
30 title => { name => 'Helvetica',
31 file => 'ArialMT.ttf',
32 size => 16 },
33 subtitle => { name => 'Helvetica',
34 file => 'ArialMT.ttf',
35 size => 12 },
36 chord_n => { name => 'Helvetica',
37 file => 'ArialMT.ttf',
38 size => 17 },
39 chord_cn => { name => 'Myriad-CnSemibold',
40 file => 'Myriad-CnSemibold.ttf',
41 size => 20 },
42 barno => { file => 'Helvetica',
43 file => 'ArialMT.ttf',
44 size => 8 },
45 msyms => { file => 'MSyms.ttf',
46 size => 15 },
47 },
48 };
49  
50 1 my $f_chord;
51 my $f_msyms;
52  
53 # Actual media box.
54 1 my @mediabox;
55  
56 # Low level PDF api.
57 1 my $pr;
58  
59 # Initial delta values for width, height and margin.
60 1 my @delta_values;
61  
62 # Position control.
63 1 my $xd = 0; # step (in bar lines)
64 1 my $yd = 0; # vertical space between lines
65 1 my $md = 0; # additional left margin
66 1 my $x; # actual x pos
67 my $y; # actual y pos
68  
69 1 my $barno;
70 1 my $std_gridscale = 8;
71 1 my $condensed = 0;
72  
73 ################ API Functions ################
74  
75 # Object creation.
76 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
77 0 my ( $pkg, $args ) = @_;
78 0 my $self = bless { }, $pkg;
79 0 $self;
80 }
81  
82 # Init the backend.
83 0 ▶sub setup {
Subroutine setup: not called CC=6 SCAR=37.4
Pod undocumented
84 0 my ( $self, $args, $title ) = @_;
85  
86 0 @delta_values = ( 0, 0, 0 );
87 0 $ps->{fonts}->{chord} = $ps->{fonts}->{chord_n};
88 0 @mediabox = ( 0, 0, @{ $ps->{papersize} } );
89  
90 0 ▶ if ( $args->{opus}->{globalsettings} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"opus"}{"globalsettings"}) 0 0 0
91 0 $self->globalsettings( $args->{opus}->{globalsettings} );
92 }
93  
94 0 my $options = { pagedefs_default => { pdf => $ps } };
95 0 $self->pagesettings($options);
96 0 $ps = $self->{ps};
97  
98 # Add font dirs.
99 0 for my $fontdir ( $self->{fontdir}, ::findlib("fonts"), $ENV{FONTDIR} ) {
100 0 ▶ next unless $fontdir;
Branch: 1 branch
BranchTrueFalseTotal
unless $fontdir 0 0 0
101 0 ▶ if ( -d $fontdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $fontdir) { } 0 0 0
102 0 warn("PDF: Adding fontdir $fontdir\n");
103 0 PDF::API2::addFontDirs($fontdir);
104 }
105 else {
106 0 warn("PDF: Ignoring fontdir $fontdir [$!]\n");
107 0 undef $fontdir;
108 }
109 }
110  
111 0 $self->initfonts($options);
112  
113 0 ▶ unless ( $pr ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pr) 0 0 0
114 0 $pr = PDFWriter->new;
115  
116 0 my @tm = gmtime(time);
117 $pr->info( Title => $args->{opus}->{title},
118 0 Creator => "PlayTab $App::Music::PlayTab::VERSION",
119 CreationDate =>
120 sprintf( "D:%04d%02d%02d%02d%02d%02d+00'00'",
121 1900+$tm[5], 1+$tm[4], @tm[3,2,1,0] ),
122 );
123  
124 }
125  
126 # newline() is called before setup_line(). Supply standard value.
127 0 $yd = -15;
128  
129 0 $f_chord = $ps->{fonts}->{chord};
130 0 $f_msyms = $ps->{fonts}->{msyms};
131 }
132  
133 0 ▶sub globalsettings {
Subroutine globalsettings: not called CC=8 SCAR=42.8
Pod undocumented
134 0 my ( $self, $args ) = @_;
135  
136 0 my @args = @$args;
137  
138 0 ▶ while ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
139 0 my $arg = shift(@args);
140  
141 0 ▶ if ( $arg =~ /^media=(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^media=(.*)$/) 0 0 0
142 0 my $media = $1;
143 0 ▶ if ( $media eq "800x1280" ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($media eq '800x1280') { } 0 0 0
elsif ($media =~ /^(ipad|960x1280)$/) { } 0 0 0
elsif ($media eq '768x1024') { } 0 0 0
144 # 800x1280 Samsung Galaxy Note 10.1 tablet.
145 0 @delta_values = ( -4, 2, 4 );
146 0 $condensed = 1;
147 0 $ps->{fonts}->{chord} = $ps->{fonts}->{chord_cn};
148 0 @mediabox = map { $_ * (72/150) } 80, 435, 800, 1280;
149 0 $mediabox[2] += $mediabox[0];
150 0 $mediabox[3] += $mediabox[1];
151 }
152 elsif ( $media =~ /^(ipad|960x1280)$/ ) {
153 # 768x1024 iPad2.
154 0 @delta_values = ( -7, 2, -10 );
155 0 $condensed = 0;
156 0 $ps->{fonts}->{chord} = $ps->{fonts}->{chord_cn};
157 0 @mediabox = map { $_ * (72/150) } 70, 440, 960, 1280;
158 0 $mediabox[2] += $mediabox[0];
159 0 $mediabox[3] += $mediabox[1];
160 }
161 elsif ( $media eq "768x1024" ) {
162 # 768x1024 iPad2.
163 0 @delta_values = ( -12, 3, -10 );
164 0 $ps->{fonts}->{chord} = $ps->{fonts}->{chord_cn};
165 0 @mediabox = map { $_ * (72/150) } 90, 685, 768, 1024;
166 0 $mediabox[2] += $mediabox[0];
167 0 $mediabox[3] += $mediabox[1];
168 }
169 else {
170 0 warn("PDF backend: Unrecognized media type: $media\n");
171 }
172 0 next;
173 }
174 0 ▶ if ( $arg eq "narrow" ) { #### IN PROGRESS
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "narrow") 0 0 0
175 0 @delta_values = ( -4, 1, 4 );
176 0 $condensed = 1;
177 0 $ps->{fonts}->{chord} = $ps->{fonts}->{chord_cn};
178 0 @mediabox = map { $_ * (72/150) } 70, 440, 800, 1280;
179 0 $mediabox[2] += $mediabox[0];
180 0 $mediabox[3] += $mediabox[1];
181 0 next;
182 }
183 0 ▶ if ( $arg eq "condensed" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "condensed") 0 0 0
184 0 $ps->{fonts}->{chord} = $ps->{fonts}->{chord_cn};
185 0 next;
186 }
187 }
188 }
189  
190  
191 # New page.
192 0 ▶sub setuppage {
Subroutine setuppage: not called CC=1 SCAR=6.9
Pod undocumented
193 0 my ( $self, $title, $stitles ) = @_;
194 0 $self->pdf_page( 1, $title, $stitles );
195 0 undef $barno;
196 }
197  
198 0 ▶sub finish {
Subroutine finish: not called CC=2 SCAR=17.9
Pod undocumented
199 0 my $self = shift;
200 0 ▶ return unless $pr;
Branch: 1 branch
BranchTrueFalseTotal
unless $pr 0 0 0
201 0 $self->{fh}->binmode;
202 0 $self->{fh}->print( $pr->finish );
203 0 undef $pr;
204 }
205  
206 # New print line.
207 0 ▶sub setupline {
Subroutine setupline: not called CC=6 SCAR=37.4
Pod undocumented
208 0 my ( $self, $line ) = @_;
209 0 ▶ $xd = $delta_values[0] + ( $line->{width} || 0 );
Condition0%0/2
$line->{'width'} || 0
l!l
00
MC/DC0%0/1
$line->{'width'} || 0
$line->{'width'}
Truth table0%0/2
A
A= $line->{'width'}
Aresult
11
00
210 0 ▶ $yd = $delta_values[1] + ( $line->{height} || 0 );
Condition0%0/2
$line->{'height'} || 0
l!l
00
MC/DC0%0/1
$line->{'height'} || 0
$line->{'height'}
Truth table0%0/2
A
A= $line->{'height'}
Aresult
11
00
211 0 ▶ $md = $delta_values[2] + ( $line->{margin} || 0 );
Condition0%0/2
$line->{'margin'} || 0
l!l
00
MC/DC0%0/1
$line->{'margin'} || 0
$line->{'margin'}
Truth table0%0/2
A
A= $line->{'margin'}
Aresult
11
00
212 0 $barno = $line->{barno};
213 0 ▶ if ( $condensed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($condensed) 0 0 0
214 0 $_ *= 0.7 for $xd, $md;
215 }
216 }
217  
218 0 ▶sub bar {
Subroutine bar: not called CC=3 SCAR=24.8
Pod undocumented
219 0 my ( $self, $first ) = @_;
220 0 $self->checkvspace;
221 0 $pr->vline( $x + $md, $y + 13, 16 );
222 $pr->rtext( $x + $md - 2, $y + 9, $barno, $ps->{fonts}->{barno} )
223 0 ▶ if $first && defined($barno);
Branch: 1 branch
BranchTrueFalseTotal
if $first and defined $barno 0 0 0
Condition0%0/3
$first and defined $barno
!ll&&!rl&&r
000
MC/DC0%0/2
$first and defined $barno
$first defined $barno
Truth table0%0/3
A and B
A= $firstB= defined $barno
ABresult
0X0
100
111
224 0 $x += 4;
225 }
226  
227 0 ▶sub chord {
Subroutine chord: not called CC=4 SCAR=30.0
Pod undocumented
228 0 my ( $self, $chord, $dup ) = ( @_, 0 );
229 0 ▶ if ( ref($chord) =~ /::/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref($chord) =~ /::/) { } 0 0 0
elsif (ref $chord eq 'ARRAY') { } 0 0 0
230 0 my $save_x = $x;
231 0 my $save_y = $y;
232 0 $chord->render;
233 0 $x = $save_x + $xd;
234 0 $y = $save_y;
235 0 $self->{_prev_chord} = $chord;
236 }
237 elsif ( ref($chord) eq 'ARRAY' ) {
238 0 my $fun = "render__" . shift(@$chord);
239 0 $self->$fun( @$chord );
240 }
241 else {
242 0 my $fun = "render__$chord";
243 0 $self->$fun;
244 }
245 0 ▶ while ( $dup-- > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dup-- > 1) 0 0 0
246 0 $self->render__space;
247 }
248 }
249  
250 0 ▶sub newline {
Subroutine newline: not called CC=2 SCAR=17.9
Pod undocumented
251 0 my ( $self, $xtra ) = @_;
252 0 $x = $ps->{marginleft};
253 0 $y += $yd;
254 0 ▶ $y += ($xtra-1)*$yd if defined $xtra;
Branch: 1 branch
BranchTrueFalseTotal
if defined $xtra 0 0 0
255 }
256  
257 0 ▶sub text {
Subroutine text: not called CC=3 SCAR=24.8
Pod undocumented
258 0 my ( $self, $text, $xxmd, $font ) = @_;
259 0 ▶ $font ||= $ps->{fonts}->{subtitle};
Condition0%0/3
$font ||= $ps->{"fonts"}{"subtitle"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$font ||= $ps->{"fonts"}{"subtitle"}
$font $ps->{"fonts"}{"subtitle"}
Truth table0%0/3
A ||= B
A= $fontB= $ps->{"fonts"}{"subtitle"}
ABresult
1X1
011
000
260 0 ▶ $xxmd ||= 0;
Condition0%0/2
$xxmd ||= 0
l!l
00
MC/DC0%0/1
$xxmd ||= 0
$xxmd
Truth table0%0/2
A
A= $xxmd
Aresult
11
00
261 0 $self->checkvspace;
262 0 $pr->text( $x + $xxmd, $y, $text, $font );
263 }
264  
265 0 ▶sub postfix {
Subroutine postfix: not called CC=1 SCAR=6.9
Pod undocumented
266 0 my ( $self, $text ) = @_;
267 0 $x += 4;
268 0 $self->text( $text, $md );
269 }
270  
271 1 ▶use constant GRIDSTEP => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
272 1 ▶use constant GRIDSPACE => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
273  
274 0 ▶sub grids {
Subroutine grids: not called CC=3 SCAR=24.8
Pod undocumented
275 0 my ( $self, $grids ) = @_;
276  
277 0 my $n = int( ( 570 - $md - 45 ) / ( GRIDSPACE * GRIDSTEP ) );
278  
279 0 my $i = 0;
280 0 foreach my $ch ( @$grids ) {
281 0 $self->render_grid($ch);
282 0 ▶ if ( ++$i >= $n ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i >= $n) { } 0 0 0
283 0 $self->newline(4);
284 0 $i = 0;
285 }
286 else {
287 0 $x += GRIDSPACE * GRIDSTEP;
288 }
289 }
290 0 $self->newline(3);
291 }
292  
293 ################ Other Render Functions ################
294  
295 1 ▶use constant MS_REST => "\x{002b}";
Subroutine BEGIN: called CC=1 SCAR=0.0
296 1 ▶use constant MS_REPT => "\x{0024}";
Subroutine BEGIN: called CC=1 SCAR=0.0
297  
298 0 ▶sub render__again {
Subroutine render__again: not called CC=1 SCAR=6.9
Pod undocumented
299 0 my ( $self ) = @_;
300 0 $self->chord( $self->{_prev_chord} );
301 }
302  
303 0 ▶sub render__space {
Subroutine render__space: not called CC=1 SCAR=6.9
Pod undocumented
304 0 my ( $self ) = @_;
305 0 $x += $xd;
306 }
307  
308 0 ▶sub render__rest {
Subroutine render__rest: not called CC=1 SCAR=6.9
Pod undocumented
309 0 my $self = shift;
310 0 $pr->msym( $x + $md, $y, MS_REST, 20 );
311 0 $x += $xd;
312 }
313  
314 0 ▶sub render__same {
Subroutine render__same: not called CC=1 SCAR=6.9
Pod undocumented
315 # Whole bar(s) repeat.
316 0 my ( $self, $wh, $xs ) = @_;
317 # Currently, $wh will always be 1 (single bar repeat).
318 0 $pr->ctext( $x + $md + ($xs * $xd) / 2, $y + 3, MS_REPT, $f_msyms, 25 );
319 0 $x += $xs * $xd;
320 }
321  
322 0 ▶sub render__hmore {
Subroutine render__hmore: not called CC=1 SCAR=6.9
Pod undocumented
323 0 $x += 4;
324 }
325  
326 0 ▶sub render__hless {
Subroutine render__hless: not called CC=1 SCAR=6.9
Pod undocumented
327 0 $x -= 4;
328 }
329  
330 0 ▶sub render_grid {
Subroutine render_grid: not called CC=2 SCAR=17.9
Pod undocumented
331 0 my ( $self, $grid ) = @_;
332  
333 0 my @c = @$grid;
334 0 my $chord = shift(@c);
335 0 my $save_x = $x;
336 0 my $save_y = $y;
337 0 $y += 0;
338 0 $x += 28;
339 0 ▶ if ( $chord =~ /::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chord =~ /::/) { } 0 0 0
340 0 $x -= $chord->width($self) / 2;
341 0 $chord->render;
342 }
343 else {
344 0 $pr->ctext( $x, $y, $chord, $f_chord );
345 }
346 0 $x = $save_x;
347 0 $y = $save_y;
348  
349 # Fretboard.
350 0 my $c = shift(@c);
351 0 $pr->fretboard( $x + $md + 8, $y - 5,
352 5 * GRIDSTEP, 4 * GRIDSTEP,
353 $c, \@c );
354 }
355  
356 ################ Page managemant ################
357  
358 1 my $pdf_pages = 0; # physcial page number
359 1 my $pdf_page = 1; # logical page number
360  
361 0 ▶sub pdf_page {
Subroutine pdf_page: not called CC=5 SCAR=34.0
Pod undocumented
362 0 my ( $self, $first, $title, $stitles ) = @_;
363  
364 # Physical newpage, if needed.
365 0 ▶ $pr->newpage if $pdf_pages++;
Branch: 1 branch
BranchTrueFalseTotal
if $pdf_pages++ 0 0 0
366  
367 # (Re)set coordinates and page number.
368 0 $x = $ps->{marginleft};
369 0 $y = $ps->{papersize}->[1] - $ps->{margintop};
370 0 ▶ $pdf_page = $first ? 1 : $pdf_page+1;
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 0 0 0
371  
372 # Print title header.
373 0 $pr->text( $x, $y, $self->{title} = $title, $ps->{fonts}->{title} );
374  
375 # Add page number, if not first (or only) page.
376 0 ▶ if ( $pdf_page > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pdf_page > 1) 0 0 0
377 $pr->rtext( $ps->{papersize}->[0] - $ps->{marginright}, $y,
378 "Page $pdf_page",
379 0 $ps->{fonts}->{subtitle} );
380 }
381 0 $self->newline;
382  
383 # Add subtitles, if any,
384 0 foreach ( @$stitles ) {
385 0 $pr->text( $x, $y, $_, $ps->{fonts}->{subtitle} );
386 0 $self->newline;
387 }
388  
389 # And finally some vertical space.
390 0 $self->newline(2);
391 }
392  
393 0 ▶sub checkvspace {
Subroutine checkvspace: not called CC=2 SCAR=17.9
Pod undocumented
394 0 my ( $self ) = @_;
395  
396 # Check if this still fits.
397 0 ▶ return if $y >= $ps->{marginbottom};
Branch: 1 branch
BranchTrueFalseTotal
if $y >= $ps->{"marginbottom"} 0 0 0
398  
399 # Otherwise, new page.
400 0 $self->pdf_page( 0, $self->{title}, [] );
401 }
402  
403 ################ Page settings ################
404 #
405 # Copied from GImager.
406  
407 1 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
408  
409 # Setup fonts.
410 0 ▶sub initfonts {
Subroutine initfonts: not called CC=1 SCAR=6.9
Pod undocumented
411 0 my ( $self ) = @_;
412 }
413  
414 # API: pagesettings (inheritable)
415 0 ▶sub pagesettings {
Subroutine pagesettings: not called CC=10 SCAR=47.0
Pod undocumented
416 0 my ( $self, $options ) = @_;
417  
418 0 ▶ my $ret = delete( $options->{pagedefs_default} ) || {};
Condition0%0/2
delete $options->{'pagedefs_default'} || {}
l!l
00
MC/DC0%0/1
delete $options->{'pagedefs_default'} || {}
delete $options->{'pagedefs_default'}
Truth table0%0/2
A
A= delete $options->{'pagedefs_default'}
Aresult
11
00
419 0 ▶ if ( open( my $fd, "<:utf8", $options->{pagedefs} || "pagedefs.json" ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (open my $fd, '<:utf8', $options->{'pagedefs'} || 'pagedefs.json') { } 0 0 0
elsif ($options->{'pagedefs'}) { } 0 0 0
Condition0%0/2
$options->{'pagedefs'} || 'pagedefs.json'
l!l
00
MC/DC0%0/1
$options->{'pagedefs'} || 'pagedefs.json'
$options->{'pagedefs'}
Truth table0%0/2
A
A= $options->{'pagedefs'}
Aresult
11
00
420 0 local $/;
421 0 $ret = JSON::PP->new->utf8->relaxed->decode( scalar( <$fd> ) );
422 0 $fd->close;
423 }
424 elsif ( $options->{pagedefs} ) {
425 0 die("Cannot open ", $options->{pagedefs}, " [$!]\n");
426 }
427  
428 0 my $def =
429 { papersize => 'a4',
430 marginleft => 130,
431 margintop => 66,
432 marginbottom => 40,
433 marginright => 40,
434 offsets => [ 50, 300 ],
435 };
436  
437 # Use fallback values, if necessary.
438 0 ▶ $ret->{pdf}->{$_} ||= $def->{$_} foreach keys(%$def);
Condition0%0/3
$ret->{"pdf"}{$_} ||= $def->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ret->{"pdf"}{$_} ||= $def->{$_}
$ret->{"pdf"}{$_} $def->{$_}
Truth table0%0/3
A ||= B
A= $ret->{"pdf"}{$_}B= $def->{$_}
ABresult
1X1
011
000
439  
440 0 my $stdfonts =
441 { text => {
442 name => 'Times-Roman',
443 size => 12,
444 fallback => "/home/jv/.fonts/TimesNewRomanPSMT.ttf",
445 },
446 };
447  
448 # Use fallback fonts, if necessary.
449 0 ▶ $ret->{pdf}->{fonts}->{$_} ||= $stdfonts->{$_} foreach keys(%$stdfonts);
Condition0%0/3
$ret->{"pdf"}{"fonts"}{$_} ||= $stdfonts->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ret->{"pdf"}{"fonts"}{$_} ||= $stdfonts->{$_}
$ret->{"pdf"}{"fonts"}{$_} $stdfonts->{$_}
Truth table0%0/3
A ||= B
A= $ret->{"pdf"}{"fonts"}{$_}B= $stdfonts->{$_}
ABresult
1X1
011
000
450  
451 0 ▶ unless ( eval { $ret->{pdf}->{papersize}->[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $ret->{"pdf"}{"papersize"}[0] } }) 0 0 0
452 0 require PDF::API2::Resource::PaperSizes;
453 0 my %ps = PDF::API2::Resource::PaperSizes->get_paper_sizes;
454 $ret->{pdf}->{papersize} = $ps{lc $ret->{pdf}->{papersize}}
455 0 }
456  
457 0 if ( 0 ) {
458 open( my $fd, '>:utf8', 'pagedefs.new' );
459 $fd->print(JSON::PP->new->utf8->canonical->indent(4)->pretty->encode($ret));
460 $fd->close;
461 }
462  
463 0 $self->{ps} = $ret->{pdf};
464 }
465  
466 ################ App::Music::PlayTab::Note ################
467  
468 package App::Music::PlayTab::Note;
469  
470 # Glyph mappings of the MSyms font.
471 1 ▶use constant MS_SHARP => "\x{0021}";
Subroutine BEGIN: called CC=1 SCAR=0.0
472 1 ▶use constant MS_FLAT => "\x{0022}";
Subroutine BEGIN: called CC=1 SCAR=0.0
473 1 ▶use constant MS_NATURAL => "\x{0023}";
Subroutine BEGIN: called CC=1 SCAR=0.0
474  
475 0 ▶sub render {
Subroutine render: not called CC=3 SCAR=24.8
Pod undocumented
476 0 my ($self) = @_;
477 0 my $name = $self->name;
478  
479 0 ▶ if ( $name =~ /(.)b/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /(.)b/) { } 0 0 0
elsif ($name =~ /(.)#/) { } 0 0 0
480 0 my $width = $pr->strwidth( $1, $f_chord );
481 0 $pr->text( $x + $md, $y, $1, $f_chord );
482 0 $pr->msym( $x + $md + $width + 1, $y + 3, MS_FLAT, 25 );
483 }
484 elsif ( $name =~ /(.)#/ ) {
485 0 my $width = $pr->strwidth( $1, $f_chord );
486 0 $pr->text( $x + $md, $y, $1, $f_chord );
487 0 $pr->msym( $x + $md + $width + 1, $y + 3, MS_SHARP, 25 );
488 }
489 else {
490 0 $pr->text( $x + $md, $y, $name, $f_chord );
491 }
492 }
493  
494 1 my $chord_small;
495 my $msym_small;
496  
497 0 ▶sub render_small {
Subroutine render_small: not called CC=5 SCAR=34.0
Pod undocumented
498 0 my ($self) = @_;
499 0 my $name = $self->name;
500  
501 0 ▶ $chord_small ||= 0.7 * $ps->{fonts}->{chord}->{size};
Condition0%0/3
$chord_small ||= "0.7" * $ps->{"fonts"}{"chord"}{"size"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$chord_small ||= "0.7" * $ps->{"fonts"}{"chord"}{"size"}
$chord_small "0.7" * $ps->{"fonts"}{"chord"}{"size"}
Truth table0%0/3
A ||= B
A= $chord_smallB= "0.7" * $ps->{"fonts"}{"chord"}{"size"}
ABresult
1X1
011
000
502 0 ▶ $msym_small ||= 0.7 * 25;
Condition0%0/2
$msym_small ||= "17.5"
l!l
00
MC/DC0%0/1
$msym_small ||= "17.5"
$msym_small
Truth table0%0/2
A
A= $msym_small
Aresult
11
00
503 0 my $width;
504  
505 0 ▶ if ( $name =~ /(.)b/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /(.)b/) { } 0 0 0
elsif ($name =~ /(.)#/) { } 0 0 0
506 0 $width = $pr->strwidth( $1, $f_chord, $chord_small );
507 0 $pr->text( $x + $md, $y, $1, $f_chord, $chord_small );
508 0 $pr->msym( $x + $md + $width + 1, $y + 3, MS_FLAT, $msym_small );
509 0 $width += 1 + $pr->msymwidth( MS_FLAT, $msym_small );
510 }
511 elsif ( $name =~ /(.)#/ ) {
512 0 $width = $pr->strwidth( $1, $f_chord, $chord_small );
513 0 $pr->text( $x + $md, $y, $1, $f_chord, $chord_small );
514 0 $pr->msym( $x + $md + $width + 1, $y + 3, MS_SHARP, $msym_small );
515 0 $width += 1 + $pr->msymwidth( MS_FLAT, $msym_small );
516 }
517 else {
518 0 $width = $pr->strwidth( $name, $f_chord, $chord_small );
519 0 $pr->text( $x + $md, $y, $name, $f_chord, $chord_small );
520 }
521  
522 0 $width;
523 }
524  
525 0 ▶sub width {
Subroutine width: not called CC=3 SCAR=24.8
Pod undocumented
526 0 my ($self) = @_;
527 0 my $name = $self->name;
528  
529 0 ▶ if ( $name =~ /(.)b/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /(.)b/) 0 0 0
530 0 return $pr->strwidth( $1, $f_chord )
531 + 1 + $pr->msymwidth( MS_FLAT );
532 }
533 0 ▶ if ( $name =~ /(.)#/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /(.)#/) 0 0 0
534 0 return $pr->strwidth( $1, $f_chord )
535 + 1 + $pr->msymwidth( MS_SHARP ) + 7;
536 }
537  
538 0 return $pr->strwidth( $name, $f_chord );
539 }
540  
541 ################ App::Music::PlayTab::Chord ################
542  
543 package App::Music::PlayTab::Chord;
544  
545 # Glyph mappings of the MSyms font.
546 1 ▶use constant MS_SHARP => "\x{0021}";
Subroutine BEGIN: called CC=1 SCAR=0.0
547 1 ▶use constant MS_FLAT => "\x{0022}";
Subroutine BEGIN: called CC=1 SCAR=0.0
548 1 ▶use constant MS_DIM => "\x{0027}";
Subroutine BEGIN: called CC=1 SCAR=0.0
549 1 ▶use constant MS_HDIM => "\x{0028}";
Subroutine BEGIN: called CC=1 SCAR=0.0
550 1 ▶use constant MS_AUG => "\x{0029}";
Subroutine BEGIN: called CC=1 SCAR=0.0
551 1 ▶use constant MS_MAJOR7 => "\x{002a}";
Subroutine BEGIN: called CC=1 SCAR=0.0
552 1 ▶use constant MS_MINOR => "\x{002b}";
Subroutine BEGIN: called CC=1 SCAR=0.0
553  
554 0 ▶sub render {
Subroutine render: not called CC=22 SCAR=62.3
Pod undocumented
555 0 my ($self) = @_;
556  
557 0 my $width = $self->{key}->width;
558 0 $self->{key}->render;
559  
560 0 my $res = "";
561 0 my @v = @{$self->{vec}};
562 0 my $v = "@v ";
563 0 shift (@v);
564  
565 0 ▶ if ( $v =~ s/^0 (2 )?4 (6|7|8) / / ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($v =~ s/^0 (2 )?4 (6|7|8) / /) { } 0 0 0
elsif ($v =~ s/^0 3 6 9 / /) { } 0 0 0
elsif ($v =~ s/^0 (2 )?3 (6|7|8) / /) { } 0 0 0
566 0 ▶ if ( $2 == 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 == 8) 0 0 0
567 0 $pr->msym( $x + $md + $width + 1, $y + 8, MS_AUG );
568 }
569 0 ▶ $v = ' 6' . $v if $2 == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $2 == 6 0 0 0
570 0 ▶ $v = ' 2' . $v if defined $1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 0 0 0
571 }
572 elsif ( $v =~ s/^0 3 6 9 / / ) {
573 0 $pr->msym( $x + $md + $width + 1, $y + 8, MS_DIM );
574 }
575 elsif ( $v =~ s/^0 (2 )?3 (6|7|8) / / ) {
576 0 ▶ if ( $2 == 6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 == 6) { } 0 0 0
577 0 ▶ if ( $v =~ s/^ 10 // ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/^ 10 //) { } 0 0 0
578 0 $pr->msym( $x + $md + $width + 1, $y + 8, MS_HDIM );
579 }
580 else {
581 0 $pr->msym( $x + $md + $width + 1, $y + 8, MS_DIM );
582 }
583 }
584 else {
585 0 $pr->msym( $x + $md + $width + 1, $y + 8, MS_MINOR );
586 }
587 0 ▶ $v = ' 8' . $v if $2 == 8;
Branch: 1 branch
BranchTrueFalseTotal
if $2 == 8 0 0 0
588 0 ▶ $v = ' 2' . $v if defined $1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 0 0 0
589 }
590  
591 0 $v =~ s/^0 5 7 / 5 7 /;
592 0 $v =~ s/ 10 14 18 (21) / $1 /; # 13
593 0 $v =~ s/ 10 14 18 (20|22) / 10 $1 /; # 7#13 7b13
594 0 $v =~ s/ 10 14 (17) / $1 /; # 11
595 0 $v =~ s/ 10 14 (18) / 10 $1 /; # 7#11
596 0 $v =~ s/ 10 (14) / $1 /; # 9
597 0 $v =~ s/ 10 (15) / 10 $1 /; # 7#9
598 0 $v =~ s/ 11 14 18 (21|22) / $1 11 /; # 13#5
599 0 $v =~ s/ 11 14 (17|18) / $1 11 /; # 11#5
600 0 $v =~ s/ 11 (14|15) / $1 11 /; # 9#5
601 0 ▶ if ( $v =~ s/ 10 / / ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v =~ s/ 10 / /) { } 0 0 0
elsif ($v =~ s/^( \d| 10|) 11 / $1/) { } 0 0 0
602 0 $pr->text( $x + $md + $width + 0.5, $y - 3, "7", $f_chord, 12);
603 0 $width += 0.5 + $pr->strwidth( "7", $f_chord, 12 );
604 }
605 elsif ( $v =~ s/^( \d| 10|) 11 / $1/ ) {
606 #### TODO: Correct -2 if flat?
607 0 $pr->msym( $x + $md + $width + 0.5, $y - 3, MS_MAJOR7 );
608 0 $width += 0.5 + $pr->msymwidth( MS_MAJOR7 );
609 }
610 0 ▶ if ( $v =~ s/ 5 7 / / ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($v =~ s/ 5 7 / /) { } 0 0 0
elsif ($v =~ s/^0 7 / /) { } 0 0 0
elsif ($v =~ s/^0 4 / /) { } 0 0 0
611 0 $pr->text( $x + $md + $width + 1, $y - 3, "sus", $f_chord, 12 );
612 0 $width += 1 + $pr->strwidth( "sus", $f_chord, 12 );
613 }
614 elsif ( $v =~ s/^0 7 / / ) {
615 0 $pr->text( $x + $md + $width + 1, $y - 3, "sus2", $f_chord, 12 );
616 0 $width += 1 + $pr->strwidth( "sus2", $f_chord, 12 );
617 }
618 elsif ( $v =~ s/^0 4 / / ) {
619 0 $pr->text( $x + $md + $width + 1, $y - 3, "no5", $f_chord, 12 );
620 0 $width += 1 + $pr->strwidth( "no5", $f_chord, 12 );
621 }
622  
623 0 ▶ my $addn = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
624 0 my ( $text ) = @_;
625 0 $pr->text( $x + $md + $width + 0.5, $y - 3, $text, $f_chord, 12);
626 0 $width += 0.5 + $pr->strwidth( $text, $f_chord, 12 );
627 0 };
628 0 ▶ my $addf = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
629 0 my ( $text ) = @_;
630 0 $pr->msym( $x + $md + $width + 0.5, $y - 3, MS_FLAT, 18);
631 0 $width += 0.5 + $pr->msymwidth( MS_FLAT, 18 );
632 0 $pr->text( $x + $md + $width + 0.5, $y - 3, $text, $f_chord, 12);
633 0 $width += 0.5 + $pr->strwidth( $text, $f_chord, 12 )
634 0 };
635 0 ▶ my $adds = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
636 0 my ( $text ) = @_;
637 0 $pr->msym( $x + $md + $width + 0.5, $y - 3, MS_SHARP, 18);
638 0 $width += 0.5 + $pr->msymwidth( MS_SHARP, 18 );
639 0 $pr->text( $x + $md + $width + 0.5, $y - 3, $text, $f_chord, 12);
640 0 $width += 0.5 + $pr->strwidth( $text, $f_chord, 12 );
641 0 };
642  
643 0 chop ($v);
644 0 $v =~ s/^ //;
645 0 @v = split(' ', $v);
646 0 foreach ( @v ) {
647 0 my $op =
648 ( [ $addn, 1 ], [ $addf, 2 ], [ $addn, 2 ], [ $addf, 3 ],
649 [ $addn, 3 ], [ $addn, 4 ], [ $addf, 5 ], [ $addn, 5 ],
650 [ $adds, 5 ], [ $addn, 6 ], [ $addn, 7 ], [ $adds, 7 ],
651 [ $addn, 8 ], [ $addf, 9 ], [ $addn, 9 ], [ $adds, 9 ],
652 [ $addf, 11 ], [ $addn, 11 ], [ $adds, 11 ], [ $addn, 12 ],
653 [ $addf, 13 ], [ $addn, 13 ],
654 )[$_];
655  
656 0 ▶ $op->[0]->( $op->[1] ) if $op;
Branch: 1 branch
BranchTrueFalseTotal
if $op 0 0 0
657 }
658  
659 0 ▶ if ( $self->{high} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"high"}) 0 0 0
660 #### TODO
661 0 $y += 5;
662 0 $x += $width;
663 0 foreach ( @{$self->{high}} ) {
664 0 $pr->text( $x + $md + 2, $y, "\\", $f_chord );
665 0 $x += 7;
666 0 $x += $_->{key}->render_small;
667 0 $y += 4;
668 }
669 }
670  
671 0 ▶ if ( $self->{bass} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bass"}) 0 0 0
672 0 $y -= 5;
673 0 $x += $width;
674 0 foreach ( @{$self->{bass}} ) {
675 0 $pr->text( $x + $md + 2, $y, "/", $f_chord );
676 0 $x += 7;
677 0 $x += $_->{key}->render_small;
678 0 $y -= 4;
679 }
680 }
681  
682 }
683  
684 0 ▶sub width {
Subroutine width: not called CC=22 SCAR=62.3
Pod undocumented
685 0 my ($self) = @_;
686  
687 0 my $width = $self->{key}->width;
688  
689 0 my $res;
690 0 my @v = @{$self->{vec}};
691 0 my $v = "@v ";
692 0 shift (@v);
693  
694 0 ▶ if ( $v =~ s/^0 (2 )?4 (6|7|8) / / ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($v =~ s/^0 (2 )?4 (6|7|8) / /) { } 0 0 0
elsif ($v =~ s/^0 3 6 9 / /) { } 0 0 0
elsif ($v =~ s/^0 (2 )?3 (6|7|8) / /) { } 0 0 0
695 0 ▶ if ( $2 == 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 == 8) 0 0 0
696 0 $width += $pr->msymwidth( MS_AUG );
697 }
698 0 ▶ $v = ' 6' . $v if $2 == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $2 == 6 0 0 0
699 0 ▶ $v = ' 2' . $v if defined $1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 0 0 0
700 }
701 elsif ( $v =~ s/^0 3 6 9 / / ) {
702 0 $width += $pr->msymwidth( MS_DIM );
703 }
704 elsif ( $v =~ s/^0 (2 )?3 (6|7|8) / / ) {
705 0 ▶ if ( $2 == 6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 == 6) { } 0 0 0
706 0 ▶ if ( $v =~ s/^ 10 // ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/^ 10 //) { } 0 0 0
707 0 $width += $pr->msymwidth( MS_HDIM );
708 }
709 else {
710 0 $width += $pr->msymwidth( MS_DIM );
711 }
712 }
713 else {
714 0 $width += $pr->msymwidth( MS_MINOR );
715 }
716 0 ▶ $v = ' 8' . $v if $2 == 8;
Branch: 1 branch
BranchTrueFalseTotal
if $2 == 8 0 0 0
717 0 ▶ $v = ' 2' . $v if defined $1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 0 0 0
718 }
719  
720 0 $v =~ s/^0 5 7 / 5 7 /;
721 0 $v =~ s/ 10 14 18 (21) / $1 /; # 13
722 0 $v =~ s/ 10 14 18 (20|22) / 10 $1 /; # 7#13 7b13
723 0 $v =~ s/ 10 14 (17) / $1 /; # 11
724 0 $v =~ s/ 10 14 (18) / 10 $1 /; # 7#11
725 0 $v =~ s/ 10 (14) / $1 /; # 9
726 0 $v =~ s/ 10 (15) / 10 $1 /; # 7#9
727 0 $v =~ s/ 11 14 18 (21|22) / $1 11 /; # 13#5
728 0 $v =~ s/ 11 14 (17|18) / $1 11 /; # 11#5
729 0 $v =~ s/ 11 (14|15) / $1 11 /; # 9#5
730 0 ▶ if ( $v =~ s/ 10 / / ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v =~ s/ 10 / /) { } 0 0 0
elsif ($v =~ s/^( \d| 10|) 11 / $1/) { } 0 0 0
731 0 $width += $pr->strwidth( "7", $f_chord, 12);
732 }
733 elsif ( $v =~ s/^( \d| 10|) 11 / $1/ ) {
734 0 $width += $pr->msymwidth( MS_MAJOR7 );
735 }
736 0 ▶ if ( $v =~ s/ 5 7 / / ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($v =~ s/ 5 7 / /) { } 0 0 0
elsif ($v =~ s/^0 7 / /) { } 0 0 0
elsif ($v =~ s/^0 4 / /) { } 0 0 0
737 0 $width += 1 + $pr->strwidth( "sus", $f_chord, 12 );
738 }
739 elsif ( $v =~ s/^0 7 / / ) {
740 0 $width += 1 + $pr->strwidth( "sus2", $f_chord, 12 );
741 }
742 elsif ( $v =~ s/^0 4 / / ) {
743 0 $width += 1 + $pr->strwidth( "no5", $f_chord, 12 );
744 }
745  
746 0 ▶ my $addn = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
747 0 my ( $text ) = @_;
748 0 $width += 0.5 + $pr->strwidth( $text, $f_chord, 12 );
749 0 };
750 0 ▶ my $addf = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
751 0 my ( $text ) = @_;
752 0 $width += 0.5 + $pr->msymwidth( MS_FLAT, 18 );
753 0 $width += 0.5 + $pr->strwidth( $text, $f_chord, 12 )
754 0 };
755 0 ▶ my $adds = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
756 0 my ( $text ) = @_;
757 0 $width += 0.5 + $pr->msymwidth( MS_SHARP, 18 );
758 0 $width += 0.5 + $pr->strwidth( $text, $f_chord, 12 );
759 0 };
760  
761 0 chop ($v);
762 0 $v =~ s/^ //;
763 0 @v = split(' ', $v);
764 0 foreach ( @v ) {
765 0 my $op =
766 ( [ $addn, 1 ], [ $addf, 2 ], [ $addn, 2 ], [ $addf, 3 ],
767 [ $addn, 3 ], [ $addn, 4 ], [ $addf, 5 ], [ $addn, 5 ],
768 [ $adds, 5 ], [ $addn, 6 ], [ $addn, 7 ], [ $adds, 7 ],
769 [ $addn, 8 ], [ $addf, 9 ], [ $addn, 9 ], [ $adds, 9 ],
770 [ $addf, 11 ], [ $addn, 11 ], [ $adds, 11 ], [ $addn, 12 ],
771 [ $addf, 13 ], [ $addn, 13 ],
772 )[$_];
773  
774 0 ▶ $op->[0]->( $op->[1] ) if $op;
Branch: 1 branch
BranchTrueFalseTotal
if $op 0 0 0
775 }
776  
777 0 ▶ if ( $self->{high} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"high"}) 0 0 0
778 0 foreach ( @{$self->{high}} ) {
779 0 $pr->strwidth( "\\", $f_chord );
780 0 $width += 7;
781 0 $width += $_->{key}->width * 0.7;
782 }
783 }
784  
785 0 ▶ if ( $self->{bass} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bass"}) 0 0 0
786 0 foreach ( @{$self->{bass}} ) {
787 0 $pr->strwidth( "/", $f_chord );
788 0 $width += 7;
789 0 $width += $_->{key}->width * 0.7;
790 }
791 }
792  
793 0 return $width;
794 }
795  
796 ################ PDF Writer (low level PDF API) ################
797  
798 package PDFWriter;
799  
800 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
801 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
802 1 ▶use PDF::API2;
Subroutine BEGIN: called CC=1 SCAR=0.0
803 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
804  
805 1 my %fonts;
806  
807 # Glyph mappings of the MSyms font.
808 1 ▶use constant MS_FBFILLED => "\x{002e}";
Subroutine BEGIN: called CC=1 SCAR=0.0
809 1 ▶use constant MS_FBX => "\x{002f}";
Subroutine BEGIN: called CC=1 SCAR=0.0
810 1 ▶use constant MS_FBOPEN => "\x{0030}";
Subroutine BEGIN: called CC=1 SCAR=0.0
811  
812 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
813 0 my ( $pkg ) = @_;
814 0 my $self = bless { }, $pkg;
815 0 $self->{pdf} = PDF::API2->new;
816 # $self->{pdf}->{forcecompress} = 0; # development
817 0 $self->newpage;
818 0 $self;
819 }
820  
821 0 ▶sub info {
Subroutine info: not called CC=1 SCAR=6.9
822 0 my ( $self, %info ) = @_;
823 0 $self->{pdf}->info( %info );
824 }
825  
826 0 ▶sub text {
Subroutine text: not called CC=1 SCAR=6.9
827 0 splice( @_, 1, 0, -1 );
828 0 goto &_text;
829 }
830 0 ▶sub rtext {
Subroutine rtext: not called CC=1 SCAR=6.9
831 0 splice( @_, 1, 0, 1 );
832 0 goto &_text;
833 }
834 0 ▶sub ctext {
Subroutine ctext: not called CC=1 SCAR=6.9
835 0 splice( @_, 1, 0, 0 );
836 0 goto &_text;
837 }
838  
839 0 ▶sub msym {
Subroutine msym: not called CC=2 SCAR=17.9
840 0 my ( $self, $x, $y, $sym, $size ) = @_;
841 0 my $font = $f_msyms;
842 0 ▶ $size ||= $font->{size};
Condition0%0/3
$size ||= $font->{"size"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$size ||= $font->{"size"}
$size $font->{"size"}
Truth table0%0/3
A ||= B
A= $sizeB= $font->{"size"}
ABresult
1X1
011
000
843 0 $self->setfont($font, $size);
844 0 $self->{pdftext}->translate( $x, $y );
845 0 $self->{pdftext}->text($sym);
846 }
847  
848 1 my %msymwidth;
849  
850 0 ▶sub msymwidth {
Subroutine msymwidth: not called CC=4 SCAR=30.0
851 0 my ( $self, $sym, $size ) = @_;
852 0 my $key = $sym;
853 0 ▶ $key .= "\0$size" if defined $size;
Branch: 1 branch
BranchTrueFalseTotal
if defined $size 0 0 0
854 0 ▶ $msymwidth{$key} ||= do {
Condition0%0/3
$msymwidth{$key} ||= do { my $font = $f_msyms; $size ||= $font->{"size"}; $self->setfont($font, $size); $self->{"pdftext"}->advancewidth($sym) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$msymwidth{$key} ||= do { my $font = $f_msyms; $size ||= $font->{"size"}; $self->setfont($font, $size); $self->{"pdftext"}->advancewidth($sym) }
$msymwidth{$key} do { my $font = $f_msyms; $size ||= $font->{"size"}; $self->setfont($font, $size); $self->{"pdftext"}->advancewidth($sym) }
Truth table0%0/3
A ||= B
A= $msymwidth{$key}B= do { my $font = $f_msyms; $size ||= $font->{"size"}; $self->setfont($font, $size); $self->{"pdftext"}->advancewidth($sym) }
ABresult
1X1
011
000
855 0 my $font = $f_msyms;
856 0 ▶ $size ||= $font->{size};
Condition0%0/3
$size ||= $font->{"size"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$size ||= $font->{"size"}
$size $font->{"size"}
Truth table0%0/3
A ||= B
A= $sizeB= $font->{"size"}
ABresult
1X1
011
000
857 0 $self->setfont($font, $size);
858 0 $self->{pdftext}->advancewidth($sym);
859 };
860 }
861  
862 0 ▶sub _text {
Subroutine _text: not called CC=5 SCAR=34.0
863 0 my ( $self, $align, $x, $y, $text, $font, $size ) = @_;
864  
865 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
866 0 ▶ $size ||= $font->{size};
Condition0%0/3
$size ||= $font->{"size"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$size ||= $font->{"size"}
$size $font->{"size"}
Truth table0%0/3
A ||= B
A= $sizeB= $font->{"size"}
ABresult
1X1
011
000
867 0 $self->setfont($font, $size);
868  
869 # $text = encode( "cp1250", $text ) unless $font->{file}; # #### TODO ???
870 0 $text =~ s/'/’/g; # '/;
871  
872 0 $text =~ s/\x{2007}/ /g; # Figure space.
873  
874 0 if ( 0 ) {
875 warn( "TEXT: ",
876 '"', $text, '" [ ',
877 defined $x ? "x=$x " : "",
878 defined $y ? "y=$y " : "",
879 $font->{name} ? "font=".($font->{name})." " : "",
880 $size ? "size=$size " : "",
881 "]\n" );
882 }
883  
884 0 $self->{pdftext}->translate( $x, $y );
885 0 ▶ if ( $align > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($align > 0) { } 0 0 0
elsif ($align < 0) { } 0 0 0
886 0 $self->{pdftext}->text_right($text);
887 }
888 elsif ( $align < 0 ) {
889 0 $self->{pdftext}->text($text);
890 }
891 else {
892 0 $self->{pdftext}->text_center($text);
893 }
894 }
895  
896 0 ▶sub setfont {
Subroutine setfont: not called CC=2 SCAR=17.9
897 0 my ( $self, $font, $size ) = @_;
898 0 $self->{font} = $font;
899 0 ▶ $self->{fontsize} = $size ||= $font->{size};
Condition0%0/3
$size ||= $font->{"size"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$size ||= $font->{"size"}
$size $font->{"size"}
Truth table0%0/3
A ||= B
A= $sizeB= $font->{"size"}
ABresult
1X1
011
000
900 0 $self->{pdftext}->font( $self->_getfont($font), $size );
901 }
902  
903 0 ▶sub _getfont {
Subroutine _getfont: not called CC=6 SCAR=37.4
904 0 my ( $self, $font ) = @_;
905 0 $self->{font} = $font;
906  
907 0 ▶ if ( $font->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($font->{'file'}) { } 0 0 0
908 0 ▶ return $fonts{$font->{file}} if $fonts{$font->{file}};
Branch: 1 branch
BranchTrueFalseTotal
if $fonts{$font->{"file"}} 0 0 0
909  
910 0 my $fn = $font->{file};
911 0 warn("PDF: Adding font $fn\n");
912 0 $fn =~ s;^.*/([^/]+)$;$1;;
913 0 ▶ if ( $font->{file} =~ /\.ttf$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($font->{"file"} =~ /\.ttf$/) 0 0 0
914 return $fonts{$font->{file}} =
915 0 $self->{pdf}->ttfont( $fn,
916 -dokern => 1 );
917 }
918  
919 0 ▶ if ( $font->{file} =~ /(^.*)\.pf[ab]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($font->{"file"} =~ /(^.*)\.pf[ab]$/) 0 0 0
920 0 my $metrics = "$1.afm";
921 return $fonts{$font->{file}} =
922 $self->{pdf}->psfont( $fn,
923 -afmfile => "$metrics",
924 0 -dokern => $font->{file} !~ /msyms/i );
925 }
926 }
927 else {
928 return $fonts{$font->{name}} ||=
929 0 ▶ $self->{pdf}->corefont( $font->{name} );
Condition0%0/3
$fonts{$font->{"name"}} ||= $self->{"pdf"}->corefont($font->{"name"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$fonts{$font->{"name"}} ||= $self->{"pdf"}->corefont($font->{"name"})
$fonts{$font->{"name"}} $self->{"pdf"}->corefont($font->{"name"})
Truth table0%0/3
A ||= B
A= $fonts{$font->{"name"}}B= $self->{"pdf"}->corefont($font->{"name"})
ABresult
1X1
011
000
930 }
931 }
932  
933 1 my %strwidth;
934  
935 0 ▶sub strwidth {
Subroutine strwidth: not called CC=4 SCAR=30.0
936 0 my ( $self, $text, $font, $size ) = @_;
937 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
938 0 ▶ $size ||= $font->{size};
Condition0%0/3
$size ||= $font->{"size"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$size ||= $font->{"size"}
$size $font->{"size"}
Truth table0%0/3
A ||= B
A= $sizeB= $font->{"size"}
ABresult
1X1
011
000
939 0 my $key = "$text\0$font\0$size";
940 0 ▶ $strwidth{$key} ||= do {
Condition0%0/3
$strwidth{$key} ||= do { $self->setfont($font, $size); $self->{"pdftext"}->advancewidth($text) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$strwidth{$key} ||= do { $self->setfont($font, $size); $self->{"pdftext"}->advancewidth($text) }
$strwidth{$key} do { $self->setfont($font, $size); $self->{"pdftext"}->advancewidth($text) }
Truth table0%0/3
A ||= B
A= $strwidth{$key}B= do { $self->setfont($font, $size); $self->{"pdftext"}->advancewidth($text) }
ABresult
1X1
011
000
941 0 $self->setfont( $font, $size );
942 0 $self->{pdftext}->advancewidth($text);
943 };
944 }
945  
946 0 ▶sub newpage {
Subroutine newpage: not called CC=1 SCAR=6.9
947 0 my ( $self ) = @_;
948 #$self->{pdftext}->textend if $self->{pdftext};
949 0 $self->{pdfpage} = $self->{pdf}->page;
950  
951 0 $self->{pdfpage}->mediabox( @mediabox );
952 0 $self->{pdftext} = $self->{pdfpage}->text;
953 0 $self->{pdfgfx} = $self->{pdfpage}->gfx;
954 0 $self->{pdfgfx}->linewidth(1);
955 0 $self->{pdfgfx}->strokecolor("#000000");
956 }
957  
958 0 ▶sub vline {
Subroutine vline: not called CC=1 SCAR=6.9
959 0 my ( $self, $x, $y, $height ) = @_;
960 0 $self->{pdfgfx}->move( $x, $y );
961 0 $self->{pdfgfx}->vline( $y - $height );
962 0 $self->{pdfgfx}->stroke;
963 }
964  
965 0 ▶sub hline {
Subroutine hline: not called CC=1 SCAR=6.9
966 0 my ( $self, $x, $y, $width ) = @_;
967 0 $self->{pdfgfx}->move( $x, $y );
968 0 $self->{pdfgfx}->hline( $x + $width );
969 0 $self->{pdfgfx}->stroke;
970 }
971  
972 1 my @Rom = qw(I II III IV V VI VII VIII IX X XI XII
973 XIII XIV XV XVI XVII XVIII XIX XX XXI XXII XXIII XXIV );
974  
975 0 ▶sub fretboard {
Subroutine fretboard: not called CC=8 SCAR=42.8
976 0 my ( $self, $x, $y, $width, $height, $start, $dots ) = @_;
977 0 my $cw = $width / 5;
978 0 my $ch = $height / 4;
979  
980 0 $self->{pdfgfx}->rectxy( $x, $y, $x + $width, $y - $height );
981 0 $self->{pdfgfx}->stroke;
982  
983 0 for my $i ( 1 .. 4 ) {
984 0 $self->vline( $x + $i*$cw, $y, 4*$ch );
985 0 for my $j ( 1 .. 3 ) {
986 0 $self->hline( $x, $y - $j*$ch, 5*$cw );
987 }
988 }
989  
990 0 ▶ if ( $start ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start) { } 0 0 0
991 0 my $r = $Rom[$start-1];
992 # Map to MSyms glyphs.
993 0 $r =~ tr/IVXLMDC/1234567/;
994 0 $self->rtext( $x - 3, $y - 4, $r, $f_msyms );
995 }
996 else {
997 0 $self->hline( $x, $y - 0.7, 5*$cw );
998 }
999  
1000 0 ▶ return unless $dots;
Branch: 1 branch
BranchTrueFalseTotal
unless $dots 0 0 0
1001  
1002 0 $x -= $cw / 2;
1003 0 $y += $ch / 2;
1004 0 foreach my $dot ( @$dots ) {
1005 0 ▶ if ( $dot < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dot < 0) { } 0 0 0
elsif ($dot > 0) { } 0 0 0
1006 0 $self->msym( $x + 1.8, $y - $ch - 2.5, MS_FBX, 30 );
1007 }
1008 elsif ( $dot > 0 ) {
1009 0 $self->msym( $x + 1, $y - $ch*$dot - 2.7, MS_FBFILLED, 40 );
1010 }
1011 0 $x += $ch;
1012 }
1013  
1014 }
1015  
1016 0 ▶sub add {
Subroutine add: not called CC=1 SCAR=6.9
1017 0 my ( $self, @text ) = @_;
1018 # prAdd( "@text" );
1019 }
1020  
1021 0 ▶sub finish {
Subroutine finish: not called CC=1 SCAR=6.9
1022 0 my $self = shift;
1023 0 $self->{pdf}->stringify;
1024 }
1025  
1026 1 1;
1027  
1028 __END__
↑ Summary PlayTab.pm »