--- loncom/homework/randomlabel.pm 2005/06/07 22:31:30 1.77 +++ loncom/homework/randomlabel.pm 2005/07/14 04:08:55 1.79 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # random labelling tool # -# $Id: randomlabel.pm,v 1.77 2005/06/07 22:31:30 foxr Exp $ +# $Id: randomlabel.pm,v 1.79 2005/07/14 04:08:55 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -206,15 +206,18 @@ sub end_bgimg { # If the tag produced has sizes, they override ours. # (for now anyway). # - &Apache::lonxml::debug("Base sizes: $width_param x $height_param"); my ($plot_x, $plot_y) = &extract_tag_sizes($bgimg, $width_param, - $height_param ); + $height_param); &Apache::lonxml::debug("Extracted sizes: $plot_x x $plot_y"); - $label_xscale = $plot_x / $width_param; - $label_yscale = $plot_y / $height_param; + if ($width_param) { + $label_xscale = $plot_x / $width_param; + } + if ($height_param) { + $label_yscale = $plot_y / $height_param; + } &Apache::lonxml::debug("Scale factors: $label_xscale $label_yscale"); &Apache::lonxml::debug("Image: $bgimg"); @@ -272,8 +275,6 @@ sub end_bgimg { $Apache::lonxml::debug = 0; } else { - - $result.=&make_eps_image($bgimg,$parstack,$safeeval,-2); } } @@ -368,6 +369,21 @@ sub get_label_width { } + +sub get_label_height { + my $label = shift; + &Apache::lonxml::debug("image label = $label"); + if (-e $label) { + &Apache::lonxml::debug("$label exists"); + } else { + &Apache::lonxml::debug("$label does not exist"); + } + my $magick = Image::Magick->new; + $magick->Read($label); + my $pixel_height = $magick->Get('height'); + return $pixel_height * $scale_factor; +} + sub add_vars { my ($name,$order,$label,$labelorder,$value,$image,$safeeval) = @_; if (!defined($name) || $name eq '') { return; } @@ -445,6 +461,11 @@ sub end_labelgroup { #y latex coordinate # my $ratio=($wwidth > 0 ? $wheight/$wwidth : 1 ); my $tcY=$height_param-$y*($height_param/$wheight); + if ( $type eq 'image') { + my $label_height = &get_label_height($label); + $tcY=$tcY-$label_height; + } + &Apache::lonxml::debug("hparam = $height_param wheight = $wheight texy = $tcY"); $tcX=sprintf('%.2f',$tcX); $tcY=sprintf('%.2f',$tcY); @@ -455,7 +476,7 @@ sub end_labelgroup { } elsif ( $type eq 'image') { my ($path,$file) = &Apache::londefdef::get_eps_image($label); my $image_name = $path.$file; - my $label_width = get_label_width($label); + my $label_width = &get_label_width($label); $result .= '\includegraphics[width='.$label_width.'mm]{' .$image_name."}}\n";