From: Tara L Andrews Date: Wed, 5 Sep 2012 11:03:01 +0000 (+0200) Subject: scale viewbox along with width/height X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=14e6a110fadde1dfdee385fd1b5f93158efd0587;p=scpubgit%2Fstemmatology.git scale viewbox along with width/height --- diff --git a/lib/Text/Tradition/Stemma.pm b/lib/Text/Tradition/Stemma.pm index 5ceffaa..f530af0 100644 --- a/lib/Text/Tradition/Stemma.pm +++ b/lib/Text/Tradition/Stemma.pm @@ -445,18 +445,24 @@ sub as_svg { my $height = $svgdoc->documentElement->getAttribute('height'); $width =~ s/\D+//g; $height =~ s/\D+//g; - my( $remove, $keep, $val ); + my( $remove, $keep, $val, $viewbox ); if( $width > $height ) { $remove = 'height'; $keep = 'width'; $val = $ew . 'px'; + my $vbheight = $width / $ew * $height; + $viewbox = "0.00 0.00 $width.00" . sprintf( "%.2f", $vbheight ); } else { $remove = 'width'; $keep = 'height'; $val = $eh . 'px'; + my $vbwidth = $height / $eh * $width; + $viewbox = "0.00 0.00 " . sprintf( "%.2f", $vbwidth ) . " $height.00"; } $svgdoc->documentElement->removeAttribute( $remove ); $svgdoc->documentElement->setAttribute( $keep, $val ); + $svgdoc->documentElement->removeAttribute( 'viewBox' ); + $svgdoc->documentElement->setAttribute( 'viewBox', $viewbox ); $svg = $svgdoc->toString(); } # Return the result