[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 06 Apr 2005 06:09:43 -0000


albertel		Wed Apr  6 02:09:43 2005 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  - &image_size really prefers to get a png/gif etc so it can get a pixel count of the image
  - protect against dividing by zero
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.265 loncom/xml/londefdef.pm:1.266
--- loncom/xml/londefdef.pm:1.265	Thu Mar 31 10:54:33 2005
+++ loncom/xml/londefdef.pm	Wed Apr  6 02:09:42 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.265 2005/03/31 15:54:33 albertel Exp $
+# $Id: londefdef.pm,v 1.266 2005/04/06 06:09:42 albertel Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -2497,19 +2497,25 @@
 	&Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
 
 	#if original gif/jpg/png file exist do following:
+	my $origsrc=$src;
 	my ($path,$file) = &get_eps_image($src);
 	$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
 	&Apache::lonxml::debug("path = $path file = $file src = $src");
 	if (-e $src) {
 	    &Apache::lonxml::debug("$src exists");
 	    my ($height_param,$width_param)=
-		&image_size($src,0.3,$parstack,$safeeval);
+		&image_size($origsrc,0.3,$parstack,$safeeval);
 	    my $destpath = $path;
 	    $destpath    =~ s/ /\_/g; # Spaces in path cause LaTex to vomit.
 	    my $destfile = $file;
 	    $destfile    =~ s/ /\_/g;
+	    my $size;
+	    if ($width_param)  { $size.='width='.$width_param.' mm,'; }
+	    if ($height_param) { $size.='height='.$height_param.' mm]'; }
+	    $size='['.$size;
+	    $size=~s/,$/]/; 
 	    $currentstring .= '\graphicspath{{'.$destpath.'}}'
-		.'\includegraphics[width='.$width_param.' mm,height='.$height_param.'mm]{'.$destfile.'} ';
+		.'\includegraphics'.$size.'{'.$destfile.'} ';
 
 	    #    If there's an alignment specification we need to honor it here.
 	    #    For the horizontal alignments, we will also honor the
@@ -3795,19 +3801,29 @@
 	} else { 
 	    $width_param = $TeXwidth;
 	}
-	$height_param=$TeXwidth/$old_width_param*$height_param;
+	if ($TeXheight) {
+	    $height_param = $TeXheight;
+	} elsif ($old_width_param) {
+	    $height_param=$TeXwidth/$old_width_param*$height_param;
+	}
     } elsif ($TeXheight) {
 	$height_param = $TeXheight;
-	$width_param  = $TeXheight/$height_param*$width_param;
+	if ($height_param) {
+	    $width_param  = $TeXheight/$height_param*$width_param;
+	}
     } elsif ($width) {
 	my $old_width_param=$width_param;
 	$width_param = $width*$scaling;
-        $height_param=$width_param/$old_width_param*$height_param;
+	if ($old_width_param) {
+	    $height_param=$width_param/$old_width_param*$height_param;
+	}
     }
     if ($width_param > $ENV{'form.textwidth'}) {
         my $old_width_param=$width_param;
 	$width_param =0.95*$ENV{'form.textwidth'};
-        $height_param=$width_param/$old_width_param*$height_param;
+	if ($old_width_param) {
+	    $height_param=$width_param/$old_width_param*$height_param;
+	}
     }
     return ($height_param, $width_param);
 }