[LON-CAPA-cvs] cvs: loncom /homework randomlabel.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 14 Jul 2005 04:08:57 -0000


albertel		Thu Jul 14 00:08:57 2005 EDT

  Modified files:              
    /loncom/homework	randomlabel.pm 
  Log:
  - image style random label images weren't being drawn in th correct location (the ararently are drawn up from the point they are placed at)
  
  
Index: loncom/homework/randomlabel.pm
diff -u loncom/homework/randomlabel.pm:1.78 loncom/homework/randomlabel.pm:1.79
--- loncom/homework/randomlabel.pm:1.78	Tue Jun 28 10:58:23 2005
+++ loncom/homework/randomlabel.pm	Thu Jul 14 00:08:55 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # random labelling tool
 #
-# $Id: randomlabel.pm,v 1.78 2005/06/28 14:58:23 albertel Exp $
+# $Id: randomlabel.pm,v 1.79 2005/07/14 04:08:55 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -369,6 +369,21 @@
     
 	
 }
+
+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; }
@@ -446,6 +461,11 @@
 	    #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);
@@ -456,7 +476,7 @@
 	    } 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";