| 1 | #! perl | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package main; | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | our $config; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | our $options; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | package ChordPro::Assets; | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | our @EXPORT; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | use ChordPro::Files; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use ChordPro::Utils; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use ChordPro::Output::SVG::Images; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use IO::String; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 83 | ▶ | sub prepare_assets( $s, $pr = undef ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_assets: called CC=10 SCAR=27.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 83 | ▶ | my %sa = %{$s->{assets}//{}} ; # song assets | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$s->{"assets"} // {}
MC/DC0%0/1
$s->{"assets"} // {}
$s->{"assets"}
Truth table50%1/2
A
A= $s->{"assets"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | warn("Assets: Preparing ", plural(scalar(keys %sa), " image"), "\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 83 | ▶ | if $config->{debug}->{images} || $config->{debug}->{assets}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$main::config->{"debug"}{"images"} or $main::config->{"debug"}{"assets"}
MC/DC0%0/2
$main::config->{"debug"}{"images"} or $main::config->{"debug"}{"assets"}
$main::config->{"debug"}{"images"}
$main::config->{"debug"}{"assets"}
Truth table33%1/3
A or B
A= $main::config->{"debug"}{"images"}B= $main::config->{"debug"}{"assets"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 83 | for my $id ( sort keys %sa ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | prepare_asset( $id, $s, $pr ); | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | warn("Assets: Preparing ", plural(scalar(keys %sa), " image"), ", done\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 83 | ▶ | if $config->{debug}->{images} || $config->{debug}->{assets}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$main::config->{"debug"}{"images"} or $main::config->{"debug"}{"assets"}
MC/DC0%0/2
$main::config->{"debug"}{"images"} or $main::config->{"debug"}{"assets"}
$main::config->{"debug"}{"images"}
$main::config->{"debug"}{"assets"}
Truth table33%1/3
A or B
A= $main::config->{"debug"}{"images"}B= $main::config->{"debug"}{"assets"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 83 | ▶ | my $assets = $s->{assets} || {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$s->{'assets'} || {}
MC/DC0%0/1
$s->{'assets'} || {}
$s->{'assets'}
Truth table50%1/2
A
A= $s->{'assets'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ::dump( $assets, as => "Assets, Pass 2" ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 83 | ▶ | if $config->{debug}->{assets} & 0x02; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 83 | return $assets; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 13 | push( @EXPORT, 'prepare_assets' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub prepare_asset( $id, $s, $pr ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_asset: not called CC=71 SCAR=85.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $ps; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $ps = $s->{_ps} = $pr->{ps} if $pr; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # All elements generate zero or one display items, except for SVG images | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # than can result in a series of display items. | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # So we first scan the list for SVG and delegate items and turn these | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # into simple display items. | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # warn("_MR = ", $ps->{_marginright}, ", _RM = ", $ps->{_rightmargin}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # ", __RM = ", $ps->{__rightmargin}, "\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # my $pw = $ps->{__rightmargin} - $ps->{_marginleft}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $pw = $ps ? $ps->{_marginright} - $ps->{_marginleft} : 700; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | my $cw = $ps ? ( $pw - ( $ps->{columns} - 1 ) * $ps->{columnspace} ) /$ps->{columns} | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | - $ps->{_indent} : 700; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | for my $elt ( $s->{assets}->{$id} ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | # Already prepared, e.g. multi-pass songbook. | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | next if UNIVERSAL::can($elt->{data}, "width"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $elt->{subtype} //= "image" if $elt->{uri}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$elt->{"subtype"} //= "image"
MC/DC0%0/1
$elt->{"subtype"} //= "image"
$elt->{"subtype"}
Truth table0%0/2
A
A= $elt->{"subtype"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( $elt->{type} eq "image" && $elt->{subtype} eq "delegate" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$elt->{"type"} eq "image" and $elt->{"subtype"} eq "delegate"
MC/DC0%0/2
$elt->{"type"} eq "image" and $elt->{"subtype"} eq "delegate"
$elt->{"type"} eq "image"
$elt->{"subtype"} eq "delegate"
Truth table0%0/3
A and B
A= $elt->{"type"} eq "image"B= $elt->{"subtype"} eq "delegate"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $delegate = $elt->{delegate}; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | warn("Assets: Preparing delegate $delegate, handler ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | $elt->{handler}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | ( map { " $_=" . $elt->{opts}->{$_} } keys(%{$elt->{opts}//{}})), | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$elt->{"opts"} // {}
MC/DC0%0/1
$elt->{"opts"} // {}
$elt->{"opts"}
Truth table0%0/2
A
A= $elt->{"opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | "\n") if $config->{debug}->{images}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $pkg = 'ChordPro::Delegate::' . $delegate; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | eval "require $pkg" || die($@); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $hd = $pkg->can($elt->{handler}) // | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$pkg->can($elt->{"handler"}) // die(qq[Assets: Missing delegate handler ${pkg}::$elt->{"handler"}\n])
MC/DC0%0/2
$pkg->can($elt->{"handler"}) // die(qq[Assets: Missing delegate handler ${pkg}::$elt->{"handler"}\n])
$pkg->can($elt->{"handler"})
die(qq[Assets: Missing delegate handler ${pkg}::$elt->{"handler"}\n])
Truth table0%0/3
A // B
A= $pkg->can($elt->{"handler"})B= die(qq[Assets: Missing delegate handler ${pkg}::$elt->{"handler"}\n])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | die("Assets: Missing delegate handler ${pkg}::$elt->{handler}\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | unless ( $elt->{data} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $elt->{data} = fs_load( $elt->{uri}, { fail => 'hard' } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # Determine actual width. | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my $w = defined($elt->{opts}->{spread}) ? $pw : $cw; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | $w = $elt->{opts}->{width} | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if $elt->{opts}->{width} && $elt->{opts}->{width} < $w; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$elt->{"opts"}{"width"} and $elt->{"opts"}{"width"} < $w
MC/DC0%0/2
$elt->{"opts"}{"width"} and $elt->{"opts"}{"width"} < $w
$elt->{"opts"}{"width"}
$elt->{"opts"}{"width"} < $w
Truth table0%0/3
A and B
A= $elt->{"opts"}{"width"}B= $elt->{"opts"}{"width"} < $w
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $res = $hd->( $s, elt => $elt, pagewidth => $w ); | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( $res ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $res->{opts} = { %{ $res->{opts} // {} }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$res->{"opts"} // {}
MC/DC0%0/1
$res->{"opts"} // {}
$res->{"opts"}
Truth table0%0/2
A
A= $res->{"opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | %{ $elt->{opts} // {} } }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$elt->{"opts"} // {}
MC/DC0%0/1
$elt->{"opts"} // {}
$elt->{"opts"}
Truth table0%0/2
A
A= $elt->{"opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | warn( "Assets: Preparing delegate $delegate, handler ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | $elt->{handler}, " => ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | $res->{type}, "/", $res->{subtype}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | ( map { " $_=" . $res->{opts}->{$_} } keys(%{$res->{opts}//{}})), | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$res->{"opts"} // {}
MC/DC0%0/1
$res->{"opts"} // {}
$res->{"opts"}
Truth table0%0/2
A
A= $res->{"opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | " w=$w", | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | "\n" ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if $config->{debug}->{images}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $s->{assets}->{$id} = $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Substitute alert image. | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | $s->{assets}->{$id} = $res = | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | { type => "image", | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | line => $elt->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | subtype => "svg", | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | data => [ SVG->alert(60) ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | opts => { %{$elt->{opts}//{}} } }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$elt->{"opts"} // {}
MC/DC0%0/1
$elt->{"opts"} // {}
$elt->{"opts"}
Truth table0%0/2
A
A= $elt->{"opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # If the delegate produced an image, continue processing. | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( $res && $res->{type} eq "image" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res and $res->{"type"} eq "image"
MC/DC0%0/2
$res and $res->{"type"} eq "image"
$res
$res->{"type"} eq "image"
Truth table0%0/3
A and B
A= $resB= $res->{"type"} eq "image"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $elt = $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Proceed to next asset. | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | next unless $ps; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ( $elt->{type} eq "image" && $elt->{subtype} eq "svg" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$elt->{"type"} eq "image" and $elt->{"subtype"} eq "svg"
MC/DC0%0/2
$elt->{"type"} eq "image" and $elt->{"subtype"} eq "svg"
$elt->{"type"} eq "image"
$elt->{"subtype"} eq "svg"
Truth table0%0/3
A and B
A= $elt->{"type"} eq "image"B= $elt->{"subtype"} eq "svg"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | warn("Assets: Preparing SVG image\n") if $config->{debug}->{images}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | require SVGPDF; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | SVGPDF->VERSION(0.080); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # One or more? | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | my $combine = ( !($elt->{opts}->{split}//1) | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | || $elt->{opts}->{id} | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | || defined($elt->{opts}->{spread}) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
not $elt->{"opts"}{"split"} // 1 or $elt->{"opts"}{"id"} or defined $elt->{"opts"}{"spread"}
not $elt->{"opts"}{"split"} // 1 or $elt->{"opts"}{"id"}
$elt->{"opts"}{"split"} // 1
MC/DC0%0/3
not $elt->{"opts"}{"split"} // 1 or $elt->{"opts"}{"id"} or defined $elt->{"opts"}{"spread"}
$elt->{"opts"}{"split"}
$elt->{"opts"}{"id"}
defined $elt->{"opts"}{"spread"}
Truth table0%0/4
not(A) or B or C
A= $elt->{"opts"}{"split"}B= $elt->{"opts"}{"id"}C= defined $elt->{"opts"}{"spread"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ? "stacked" : "none"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | my $sep = $elt->{opts}->{staffsep} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$elt->{'opts'}{'staffsep'} || 0
MC/DC0%0/1
$elt->{'opts'}{'staffsep'} || 0
$elt->{'opts'}{'staffsep'}
Truth table0%0/2
A
A= $elt->{'opts'}{'staffsep'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # Note we need special font and text handlers. | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | my $p = SVGPDF->new | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ( pdf => $ps->{pr}->{pdf}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | fc => sub { svg_fonthandler( $ps, @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | tc => sub { svg_texthandler( $ps, @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | atts => { debug => $config->{debug}->{svg} > 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | verbose => $config->{debug}->{svg} // 0, | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$main::config->{"debug"}{"svg"} // 0
MC/DC0%0/1
$main::config->{"debug"}{"svg"} // 0
$main::config->{"debug"}{"svg"}
Truth table0%0/2
A
A= $main::config->{"debug"}{"svg"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $data = $elt->{data}; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | my $o = $p->process( $data ? \join( "\n", @$data ) : $elt->{uri}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | combine => $combine, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | sep => $sep, | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | warn( "Assets: Preparing SVG image => ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | plural(0+@$o, " element"), ", combine=$combine\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if $config->{debug}->{images}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ( ! @$o ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | warn("Error in SVG embedding (no SVG objects found)\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | my $res = | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | $s->{assets}->{$id} = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | type => "image", | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | subtype => "xform", | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | width => $o->[0]->{width}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | height => $o->[0]->{height}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | vwidth => $o->[0]->{vwidth}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | vheight => $o->[0]->{vheight}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | data => $o->[0]->{xo}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | opts => { %{ $o->[0]->{opts} // {} }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$o->[0]{"opts"} // {}
MC/DC0%0/1
$o->[0]{"opts"} // {}
$o->[0]{"opts"}
Truth table0%0/2
A
A= $o->[0]{"opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | %{ $s->{assets}->{$id}->{opts} // {} }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$s->{"assets"}{$id}{"opts"} // {}
MC/DC0%0/1
$s->{"assets"}{$id}{"opts"} // {}
$s->{"assets"}{$id}{"opts"}
Truth table0%0/2
A
A= $s->{"assets"}{$id}{"opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | sep => $sep, | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ( @$o > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $res->{multi} = $o; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | warn("Created asset $id (xform, ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | $o->[0]->{vwidth}, "x", $o->[0]->{vheight}, ")", | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | " scale=", $res->{opts}->{scale} || 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | " align=", $res->{opts}->{align}//"default", | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | " sep=", $sep, | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | " base=", $res->{opts}->{base}//"", | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | "\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if $config->{debug}->{images}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$res->{'opts'}{'scale'} || 1
$res->{"opts"}{"align"} // "default"
$res->{"opts"}{"base"} // ""
MC/DC0%0/1
$res->{'opts'}{'scale'} || 1
$res->{'opts'}{'scale'}
MC/DC0%0/1
$res->{"opts"}{"align"} // "default"
$res->{"opts"}{"align"}
MC/DC0%0/1
$res->{"opts"}{"base"} // ""
$res->{"opts"}{"base"}
Truth table0%0/2
A
A= $res->{'opts'}{'scale'}
Truth table0%0/2
A
A= $res->{"opts"}{"align"}
Truth table0%0/2
A
A= $res->{"opts"}{"base"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ( $elt->{type} eq "image" && $elt->{subtype} eq "xform" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$elt->{"type"} eq "image" and $elt->{"subtype"} eq "xform"
MC/DC0%0/2
$elt->{"type"} eq "image" and $elt->{"subtype"} eq "xform"
$elt->{"type"} eq "image"
$elt->{"subtype"} eq "xform"
Truth table0%0/3
A and B
A= $elt->{"type"} eq "image"B= $elt->{"subtype"} eq "xform"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # Ready to go. | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ( $elt->{type} eq "image" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | warn("Assets: Preparing $elt->{subtype} image\n") if $config->{debug}->{images}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if ( ($elt->{uri}//"") =~ /^chord:(.+)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$elt->{"uri"} // ""
MC/DC0%0/1
$elt->{"uri"} // ""
$elt->{"uri"}
Truth table0%0/2
A
A= $elt->{"uri"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $chord = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | # Look it up. | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | my $info = $s->{chordsinfo}->{$chord} | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$s->{"chordsinfo"}{$chord} // ChordPro::Chords::known_chord($chord)
MC/DC0%0/2
$s->{"chordsinfo"}{$chord} // ChordPro::Chords::known_chord($chord)
$s->{"chordsinfo"}{$chord}
ChordPro::Chords::known_chord($chord)
Truth table0%0/3
A // B
A= $s->{"chordsinfo"}{$chord}B= ChordPro::Chords::known_chord($chord)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | // ChordPro::Chords::known_chord($chord); | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # If it is defined locally, merge. | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | for my $def ( @{ $s->{define} // [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$s->{"define"} // []
MC/DC0%0/1
$s->{"define"} // []
$s->{"define"}
Truth table0%0/2
A
A= $s->{"define"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | next unless $def->{name} eq $chord; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $info->{$_} = $def->{$_} for keys(%$def); | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $xo; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | unless ( $info ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | warn("Unknown chord in asset: $1\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $xo = TextLayoutImageElement::alert(20); | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my $type = $elt->{opts}->{type} || $config->{instrument}->{type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$elt->{'opts'}{'type'} || $main::config->{'instrument'}{'type'}
MC/DC0%0/2
$elt->{'opts'}{'type'} || $main::config->{'instrument'}{'type'}
$elt->{'opts'}{'type'}
$main::config->{'instrument'}{'type'}
Truth table0%0/3
A || B
A= $elt->{'opts'}{'type'}B= $main::config->{'instrument'}{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $p = ChordPro::Output::PDF::diagrammer($type); | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $xo = $p->diagram_xo($info); | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | my $res = | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | $s->{assets}->{$id} = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | type => "image", | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | subtype => "xform", | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | width => $xo->width, | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | height => $xo->height, | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | data => $xo, | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | maybe opts => $s->{assets}->{$id}->{opts}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | warn("Created asset $id ($elt->{subtype}, ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | $res->{width}, "x", $res->{height}, ")", | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | map { " $_=" . $res->{opts}->{$_} } keys( %{$res->{opts}//{}} ), | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$res->{"opts"} // {}
MC/DC0%0/1
$res->{"opts"} // {}
$res->{"opts"}
Truth table0%0/2
A
A= $res->{"opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | "\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if $config->{debug}->{images}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | if ( $elt->{uri} && !$elt->{data} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$elt->{"uri"} and not $elt->{"data"}
MC/DC0%0/2
$elt->{"uri"} and not $elt->{"data"}
$elt->{"uri"}
not $elt->{"data"}
Truth table0%0/3
A and not(B)
A= $elt->{"uri"}B= not $elt->{"data"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $elt->{data} = fs_blob( $elt->{uri}, { fail => 'hard' } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | my $data = $elt->{data} ? IO::String->new($elt->{data}) : $elt->{uri}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $img = $pr->{pdf}->image($data); | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $subtype = lc(ref($img) =~ s/^.*://r); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $subtype = "jpg" if $subtype eq "jpeg"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | my $res = | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | $s->{assets}->{$id} = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | type => "image", | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | subtype => $subtype, | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | width => $img->width, | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | height => $img->height, | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | data => $img, | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | maybe opts => $s->{assets}->{$id}->{opts}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | warn("Created asset $id ($elt->{subtype}, ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | $res->{width}, "x", $res->{height}, ")", | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ( map { " $_=" . $res->{opts}->{$_} } | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | keys( %{$res->{opts}//{}} ) ), | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$res->{"opts"} // {}
MC/DC0%0/1
$res->{"opts"} // {}
$res->{"opts"}
Truth table0%0/2
A
A= $res->{"opts"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | "\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if $config->{debug}->{images}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ( $elt->{type} eq "image" && $elt->{opts}->{spread} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$elt->{"type"} eq "image" and $elt->{"opts"}{"spread"}
MC/DC0%0/2
$elt->{"type"} eq "image" and $elt->{"opts"}{"spread"}
$elt->{"type"} eq "image"
$elt->{"opts"}{"spread"}
Truth table0%0/3
A and B
A= $elt->{"type"} eq "image"B= $elt->{"opts"}{"spread"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ( $s->{spreadimage} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | warn("Ignoring superfluous spread image\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $s->{spreadimage} = $elt; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | warn("Assets: Preparing images, got spread image\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if $config->{debug}->{images}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | next; # do not copy back | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 13 | push( @EXPORT, 'prepare_asset' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Font handler for SVG embedding. | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub svg_fonthandler { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svg_fonthandler: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my ( $ps, $svg, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my ( $pdf, $style ) = @args{qw(pdf style)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $family = lc( $style->{'font-family'} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | my $stl = lc( $style->{'font-style'} // "normal" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$style->{"font-style"} // "normal"
MC/DC0%0/1
$style->{"font-style"} // "normal"
$style->{"font-style"}
Truth table0%0/2
A
A= $style->{"font-style"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | my $weight = lc( $style->{'font-weight'} // "normal" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$style->{"font-weight"} // "normal"
MC/DC0%0/1
$style->{"font-weight"} // "normal"
$style->{"font-weight"}
Truth table0%0/2
A
A= $style->{"font-weight"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | my $size = $style->{'font-size'} || 12; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$style->{'font-size'} || 12
MC/DC0%0/1
$style->{'font-size'} || 12
$style->{'font-size'}
Truth table0%0/2
A
A= $style->{'font-size'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # Font cache. | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | state $fc = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $key = join( "|", $family, $stl, $weight ); | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Clear cache when the PDF changes. | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | state $cf = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if ( $cf ne $ps->{pr}->{pdf} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $cf = $ps->{pr}->{pdf}; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $fc = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # As a special case we handle fonts with 'names' like | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # pdf.font.foo and map these to the corresponding font | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # in the pdf.fonts structure. | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ( $family =~ /^pdf\.fonts\.(.*)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $try = $ps->{fonts}->{$1}; | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if ( $try ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | warn("SVG: Font $family found in config: ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | $try->{_ff}, "\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if $config->{debug}->{svg}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # The font may change during the run, so we do not | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # cache it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | return $try->{fd}->{font}; | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | local *Text::Layout::FontConfig::_fallback = sub { 0 }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | my $font = $fc->{$key} //= do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$fc->{$key} //= do {
my $t;
my $try = eval {
do {
$t = "Text::Layout::FontConfig"->find_font($family, $stl, $weight);
$t->get_font($ps->{"pr"}{"layout"}->copy)
}
};
if ($try) {
warn("SVG: Font $key found in font config: ", $t->{"loader_data"}, "\n") if $main::config->{"debug"}{"svg"};
$try;
}
else {
return;
}
}
MC/DC0%0/2
$fc->{$key} //= do {
my $t;
my $try = eval {
do {
$t = "Text::Layout::FontConfig"->find_font($family, $stl, $weight);
$t->get_font($ps->{"pr"}{"layout"}->copy)
}
};
if ($try) {
warn("SVG: Font $key found in font config: ", $t->{"loader_data"}, "\n") if $main::config->{"debug"}{"svg"};
$try;
}
else {
return;
}
}
$fc->{$key}
do {
my $t;
my $try = eval {
do {
$t = "Text::Layout::FontConfig"->find_font($family, $stl, $weight);
$t->get_font($ps->{"pr"}{"layout"}->copy)
}
};
if ($try) {
warn("SVG: Font $key found in font config: ", $t->{"loader_data"}, "\n") if $main::config->{"debug"}{"svg"};
$try;
}
else {
return;
}
}
Truth table0%0/3
A //= B
A= $fc->{$key}B= do {
my $t;
my $try = eval {
do {
$t = "Text::Layout::FontConfig"->find_font($family, $stl, $weight);
$t->get_font($ps->{"pr"}{"layout"}->copy)
}
};
if ($try) {
warn("SVG: Font $key found in font config: ", $t->{"loader_data"}, "\n") if $main::config->{"debug"}{"svg"};
$try;
}
else {
return;
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $t; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | my $try = | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $t = Text::Layout::FontConfig->find_font( $family, $stl, $weight ); | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $t->get_font($ps->{pr}->{layout}->copy); | |||||||||||||||||||||||||||||||||||||||||||||
| 316 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if ( $try ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | warn("SVG: Font $key found in font config: ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | $t->{loader_data}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | "\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if $config->{debug}->{svg}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $try; | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | return $font; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # Text handler for SVG embedding. | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | sub svg_texthandler { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svg_texthandler: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my ( $ps, $svg, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my $xo = delete($args{xo}); | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $pdf = delete($args{pdf}); | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my $style = delete($args{style}); | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my $text = delete($args{text}); | |||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my %opts = %args; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my @t = split( /([♯♭])/, $text ); | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ( @t == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # Nothing special. | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $svg->set_font( $xo, $style ); | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | return $xo->text( $text, %opts ); | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my ( $font, $sz ) = $svg->root->fontmanager->find_font($style); | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $has_sharp = $font->glyphByUni(ord("♯")) ne ".notdef"; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $has_flat = $font->glyphByUni(ord("♭")) ne ".notdef"; | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | # For convenience we assume that either both are available, or missing. | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ( $has_sharp && $has_flat ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$has_sharp and $has_flat
MC/DC0%0/2
$has_sharp and $has_flat
$has_sharp
$has_flat
Truth table0%0/3
A and B
A= $has_sharpB= $has_flat
| |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # Nothing special. | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $xo->font( $font, $sz ); | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | return $xo->text( $text, %opts ); | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # Replace the sharp and flat glyphs by glyps from the chordfingers font. | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $d = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $this = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | while ( @t ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $text = shift(@t); | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my $fs = shift(@t); | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | $xo->font( $font, $sz ) unless $this eq $font; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $d += $xo->text($text); | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $this = $font; | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | next unless $fs; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $xo->font( $ps->{fonts}->{chordprosymbols}->{fd}->{font}, $sz ); | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $this = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | $d += $xo->text( $fs eq '♭' ? '!' : '#' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | return $d; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||||||