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

sakharuk lon-capa-cvs@mail.lon-capa.org
Fri, 30 Jan 2004 17:31:06 -0000


sakharuk		Fri Jan 30 12:31:06 2004 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Another step in cleanup of <img>.
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.196 loncom/xml/londefdef.pm:1.197
--- loncom/xml/londefdef.pm:1.196	Wed Jan 28 15:41:15 2004
+++ loncom/xml/londefdef.pm	Fri Jan 30 12:31:06 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.196 2004/01/28 20:41:15 albertel Exp $
+# $Id: londefdef.pm,v 1.197 2004/01/30 17:31:06 sakharuk Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -2085,8 +2085,6 @@
     }
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
     my $currentstring = '';
-    my $width_param = '';
-    my $height_param = '';
     my $scaling = .3;
     if ($target eq 'web') {
 	if ($ENV{'browser.imagesuppress'} ne 'on') {
@@ -2100,42 +2098,13 @@
 	    }
 	    $currentstring.='[IMAGE: '.$alttag.']';
 	}
-	$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
-	&image_replication($src);
     } elsif ($target eq 'tex') {
 	$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
-	&image_replication($src);
 	#if original gif/jpg/png file exist do following:
 	if (-e $src) {
-	    #defines the default size of image
-	    my $image = Image::Magick->new;
-	    my $current_figure = $image->Read($src);
-	    $width_param = $image->Get('width') * $scaling;;
-	    $height_param = $image->Get('height') * $scaling;;
-	    undef $image;
-	    #do we have any specified size of the picture?
-	    my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
-	    my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
-	    my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
-						   undef,1);
-	    if ($TeXwidth ne '') {  
-		if ($TeXwidth=~/(\d+)\s*\%/) {
-		    $width_param = $1*$ENV{'form.textwidth'}/100;
-		} else { 
-		    $width_param = $TeXwidth;
-		}
-	    } elsif ($TeXheight ne '') {
-		$width_param = $TeXheight/$height_param*$width_param;
-	    } elsif ($width ne '') {
-		$width_param = $width*$scaling;      
-	    }
-	    if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}}
-	    my $file;
-	    my $path;	
-	    if ($src =~ m!(.*)/([^/]*)$!) {
-		$file = $2; 
-		$path = $1.'/'; 
-	    } 
+	    #what is the image size?
+	    my $width_param=&image_size($src,$scaling,$parstack,$safeeval);
+            my ($file,$path)=&file_path($src); 
 	    my $newsrc = $src;
 	    $newsrc =~ s/\.(gif|jpg|png)$/.eps/i;
 	    $file=~s/\.(gif|jpg|png)$/.eps/i;
@@ -3340,6 +3309,35 @@
     return '';
 }
 
+sub image_size {
+    my ($src,$scaling,$parstack,$safeeval)=@_;
+    #size of image from gif/jpg/jpeg/png 
+    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;;
+    undef $image;
+    #do we have any specified LaTeX size of the picture?
+    my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
+    my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
+    #do we have any specified web size of the picture?
+    my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
+					   undef,1);
+    if ($TeXwidth ne '') {  
+	if ($TeXwidth=~/(\d+)\s*\%/) {
+	    $width_param = $1*$ENV{'form.textwidth'}/100;
+	} else { 
+	    $width_param = $TeXwidth;
+	}
+    } elsif ($TeXheight ne '') {
+	$width_param = $TeXheight/$height_param*$width_param;
+    } elsif ($width ne '') {
+	$width_param = $width*$scaling;      
+    }
+    if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}}
+    return $width_param;
+}
+
 sub eps_generation {
     my ($src,$file,$width_param) = @_;	     
     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
@@ -3352,6 +3350,16 @@
     $newsrc=~s/\/\.\//\//;
     $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
     return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
+}
+
+sub file_path {     
+    my $src=shift;
+    my ($file,$path); 
+    if ($src =~ m!(.*)/([^/]*)$!) {
+	$file = $2; 
+	$path = $1.'/'; 
+    } 
+    return $file,$path;
 }
 
 sub recalc {