X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FText%2FTradition%2FStemma.pm;h=d6f964620de7048e772ee97ad3abee8ee6a1259c;hb=c84a47788777f257a330f9d011c03077e622310e;hp=c7114303e0ca1a7551194a367f19035f002e67aa;hpb=06e7cbc7f347e9a50ef98bfb0ab92de31b398961;p=scpubgit%2Fstemmatology.git diff --git a/lib/Text/Tradition/Stemma.pm b/lib/Text/Tradition/Stemma.pm index c711430..d6f9646 100644 --- a/lib/Text/Tradition/Stemma.pm +++ b/lib/Text/Tradition/Stemma.pm @@ -107,7 +107,7 @@ has graph => ( isa => 'Graph', predicate => 'has_graph', ); - + sub BUILD { my( $self, $args ) = @_; # If we have been handed a dotfile, initialize it into a graph. @@ -296,7 +296,7 @@ sub extend_graph { # Iterate through, adding a.c. witnesses my $actag = $self->collation->ac_label; - my $graph = $self->graph->copy; + my $graph = $self->graph->deep_copy; foreach my $lw ( @$layerwits ) { # Add the layered witness and set it with the same attributes as # its 'main' analogue @@ -349,8 +349,27 @@ sub as_svg { # Get rid of width and height attributes to allow scaling. my $parser = XML::LibXML->new(); my $svgdoc = $parser->parse_string( decode_utf8( $svg ) ); - $svgdoc->documentElement->removeAttribute('width'); - $svgdoc->documentElement->removeAttribute('height'); + if( $opts->{'size'} ) { + my( $ew, $eh ) = @{$opts->{'size'}}; + # If the graph is wider than it is tall, set width to ew and remove height. + # Otherwise set height to eh and remove width. + my $width = $svgdoc->documentElement->getAttribute('width'); + my $height = $svgdoc->documentElement->getAttribute('height'); + $width =~ s/\D+//g; + $height =~ s/\D+//g; + my( $remove, $keep, $val ); + if( $width > $height ) { + $remove = 'height'; + $keep = 'width'; + $val = $ew . 'px'; + } else { + $remove = 'width'; + $keep = 'height'; + $val = $eh . 'px'; + } + $svgdoc->documentElement->removeAttribute( $remove ); + $svgdoc->documentElement->setAttribute( $keep, $val ); + } # Return the result return decode_utf8( $svgdoc->toString ); }