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

foxr lon-capa-cvs@mail.lon-capa.org
Mon, 23 May 2005 09:41:40 -0000


foxr		Mon May 23 05:41:40 2005 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Separate image sizing from eps fetching so that if I have a dynamically '
  created eps (e.g. via gnuplot), I can still use the sizing logic.
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.273 loncom/xml/londefdef.pm:1.274
--- loncom/xml/londefdef.pm:1.273	Fri May 20 17:52:27 2005
+++ loncom/xml/londefdef.pm	Mon May 23 05:41:38 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.273 2005/05/20 21:52:27 albertel Exp $
+# $Id: londefdef.pm,v 1.274 2005/05/23 09:41:38 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -660,7 +660,7 @@
 	}
 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
 	if (not defined $TeXsize) {$TeXsize="large";}
-	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
+	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
     } elsif ($target eq 'meta') {
 	$currentstring='<subject>';
 	&start_output($target);
@@ -709,7 +709,7 @@
 	}
 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
 	if (not defined $TeXsize) {$TeXsize="large";}
-	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
+	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
     } 
     return $currentstring;
 }
@@ -752,7 +752,7 @@
 	}
 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
 	if (not defined $TeXsize) {$TeXsize="large";}
-	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
+	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
     } 
     return $currentstring;
 }
@@ -795,7 +795,7 @@
 	}
 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
 	if (not defined $TeXsize) {$TeXsize="large";}
-	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
+	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
     } 
     return $currentstring;
 }
@@ -838,7 +838,7 @@
 	}
 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
 	if (not defined $TeXsize) {$TeXsize="large";}
-	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
+	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
     } 
     return $currentstring;
 }
@@ -881,7 +881,7 @@
 	}
 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
 	if (not defined $TeXsize) {$TeXsize="large";}
-	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
+	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
     } 
     return $currentstring;
 }
@@ -3766,36 +3766,21 @@
     }
     return '';
 }
-#
-#   Get correct sizing parameter for an image given
-#   it's initial ht. and wid.  This allows sizing of
-#   images that are generated on-the-fly (e.g. gnuplot)
-#   as well as serving as a utility for image_size.
-# 
-#  Parameter:
-#        height_param
-#        width_param    - Initial picture dimensions.
-#        scaling        - A scale factor.
-#        parstack,      - the current stack of tag attributes 
-#                         from the xml parser
-#        safeeval,      - pointer to the safespace
-#        depth,         - from what level in the stack to look for attributes
-#                         (assumes -1 if unspecified)
-#        cis            - look for attrubutes case insensitively
-#                         (assumes false)
-#
-# Returns:
-#   height, width   - new dimensions.
-#
-sub resize_image {
-    my ($height_param, $width_param, $scaling,
-	$parstack, $safeeval, $depth, $cis) = @_;
-
-    # First apply the scaling...
 
-    $height_param = $height_param * $scaling;
-    $width_param  = $width_param  * $scaling;
+sub image_size {
+    my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
 
+    #size of image from gif/jpg/jpeg/png 
+    my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
+    if (-e $ressrc) {
+	$src = $ressrc;
+    }
+    my $image = Image::Magick->new;
+    my $current_figure = $image->Read($src);
+    my $width_param = $image->Get('width') * $scaling;;
+    my $height_param = $image->Get('height') * $scaling;
+    &Apache::lonxml::debug("Image magick says: $src :  Height = $height_param width = $width_param");
+    undef($image);
     #do we have any specified LaTeX size of the picture?
     my $toget='TeXwidth'; 
     if ($cis) { 
@@ -3840,29 +3825,6 @@
 	    $height_param=$width_param/$old_width_param*$height_param;
 	}
     }
-
-    return ($height_param, $width_param);
-}
-
-sub image_size {
-    my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
-
-    #size of image from gif/jpg/jpeg/png 
-    my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
-    if (-e $ressrc) {
-	$src = $ressrc;
-    }
-    my $image = Image::Magick->new;
-    my $current_figure = $image->Read($src);
-    my $width_param = $image->Get('width');
-    my $height_param = $image->Get('height');
-    &Apache::lonxml::debug("Image magick says: $src :  Height = $height_param width = $width_param");
-    undef($image);
-
-    ($height_param, $width_param) = &resize_image($height_param, $width_param,
-						  $scaling, $parstack, $safeeval, 
-						  $depth, $cis);
-
     return ($height_param, $width_param);
 }
 
@@ -3881,10 +3843,10 @@
 sub get_eps_image {
     my ($src)=@_;
     my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src);
-    &Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
+    &Apache::lonxml::debug("get_eps_image: Original image: $orig_src<BR />");
     $src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i;
     $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
-    &Apache::lonxml::debug("Filelocation gives: $src");
+    &Apache::lonxml::debug("Filelocation gives; $src <BR />");
     if (! -e $src) {
 	&Apache::lonxml::debug("$src does not exist");
 	if (&Apache::lonnet::repcopy($src) ne 'ok' ) {
@@ -3905,7 +3867,7 @@
 		open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
 		my $newsrc=$orig_src;
 		$newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
-		&Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
+		&Apache::lonxml::debug("queueing $newsrc for dynamic eps production. <BR/>");
 		print FILE "$newsrc\n";
 		close FILE;
 		$src=~s|/home/httpd/html/res|/home/httpd/prtspool|;