App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/lib/SVGPDF.pm view on Meta::CPAN
$width = $svg->u( $vb[2],
width => $pagesize->[0],
fontsize => $fontsize );
$height = $svg->u( $vb[3],
width => $pagesize->[1],
fontsize => $fontsize );
if ( $minw && $minw > $width ) {
$width = $minw;
$vb[2] = $minw / $vheight * $height;
$self->_dbg("minw: ", $style->{'min-width'}, " ",
"width -> $width, \$vb[2] -> $vb[2]\n");
}
if ( $valign ) {
# Verify valign against the vbox.
my $va = sprintf("%.2f", -$valign/$vheight);
my $vb = sprintf("%.2f", ($vb[3]+$vb[1])/$vb[3]);
warn("Vertical align = $va, but vbox says $vb\n")
unless $va eq $vb;
}
if ( $vwidth && !$vheight ) {
$vheight = $vwidth * $height / $width;
}
if ( $vheight && !$vwidth ) {
$vwidth = $vheight * $width / $height;
}
}
else {
# Use to width/height, falling back to pagesize.
$width = $svg->u( $vwidth ||$pagesize->[0],
width => $pagesize->[0],
fontsize => $fontsize );
$height = $svg->u( $vheight ||$pagesize->[1],
width => $pagesize->[1],
fontsize => $fontsize );
if ( $minw && $minw > $width ) {
$width = $minw if $minw > $width;
$self->_dbg("minw: ", $style->{'min-width'}, " ",
"width -> $width");
}
@vb = ( 0, 0, $width, $height );
if ( $valign ) {
$vb[1] = -( $vb[3] + $valign );
$self->_dbg("valign: ", $style->{'vertical-align'}, " ",
"\$vb[1] -> $vb[1]");
}
$vbox = sprintf("%.2f %.2f %.2f %.2f (inferred)", @vb);
}
$svg->nfi("disproportional vbox/width/height")
if $vheight &&
( (( $width/$height) / ($vwidth/$vheight) > 1.05)
|| (( $width/$height) / ($vwidth/$vheight) < 0.95) );
# Get llx lly urx ury bounding box rectangle.
@bb = $self->vb2bb(@vb);
$self->_dbg( "vb $vbox => bb %.2f %.2f %.2f %.2f", @bb );
warn( sprintf("vb $vbox => bb %.2f %.2f %.2f %.2f\n", @bb ))
if $verbose && !$debug;
$xo->bbox(@bb);
if ( my $c = $style->{"background-color"} ) {
if ( $c ne "none" ) {
$xo->fill_color($c);
$xo->rectangle(@bb);
$xo->fill;
}
}
# Set up result forms.
$xoforms->[-1] =
{ xo => $xo,
# Design (desired) width and height.
vwidth => $vwidth || $vb[2],
vheight => $vheight || $vb[3],
# viewBox (SVG coordinates)
vbox => [ @vb ],
width => $vb[2],
height => $vb[3],
# See e.g. https://oreillymedia.github.io/Using_SVG/extras/ch05-percentages.html
diag => sqrt( $vb[2]**2 + $vb[3]**2 ) / sqrt(2),
# bbox (PDF coordinates)
bbox => [ @bb ],
};
# Not sure if this is ever needed.
$xoforms->[-1]->{valign} = $valign if $valign;
# use DDumper; DDumper( { %{$xoforms->[-1]}, xo => 'XO' } );
# <svg> coordinates are topleft down, so translate.
$self->_dbg( "matrix( 1 0 0 -1 0 0)" );
$xo->matrix( 1, 0, 0, -1, 0, 0 );
if ( $debug ) { # show bb
$xo->save;
$self->_dbg( "vb rect( %.2f %.2f %.2f %.2f)",
$vb[0], $vb[1], $vb[2]+$vb[0], $vb[1]+$vb[3]);
$xo->rectangle( $vb[0], $vb[1], $vb[2]+$vb[0], $vb[1]+$vb[3]);
$xo->fill_color("#ffffc0");
$xo->fill;
$xo->move( $vb[0], 0 );
$xo->hline( $vb[0]+$vb[2]);
$xo->move( 0, $vb[1] );
$xo->vline( $vb[1]+$vb[3] );
$xo->line_width(0.5);
$xo->stroke_color( "red" );
$xo->stroke;
$xo->restore;
}
$self->draw_grid( $xo, \@vb ) if $grid;
# Establish currentColor.
for ( $css->find("fill") ) {
next if $_ eq 'none' or $_ eq 'transparent';
$self->_dbg( "xo fill_color ",
$_ eq 'currentColor' ? 'black' : $_,
" (initial)");
$xo->fill_color( $_ eq 'currentColor' ? 'black' : $_ );
}
for ( $css->find("stroke") ) {
next if $_ eq 'none' or $_ eq 'transparent';
$self->_dbg( "xo stroke_color ",
( run in 2.064 seconds using v1.01-cache-2.11-cpan-f56aa216473 )