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

sakharuk lon-capa-cvs@mail.lon-capa.org
Tue, 23 Jul 2002 14:41:06 -0000


sakharuk		Tue Jul 23 10:41:06 2002 EDT

  Modified files:              
    /loncom/homework	imageresponse.pm 
  Log:
  Added latex output for the <image> tag which cares about:
  1. Dynamical production of the eps counterpart;
  2. Size of image.
  
  
Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.18 loncom/homework/imageresponse.pm:1.19
--- loncom/homework/imageresponse.pm:1.18	Fri May  3 16:44:46 2002
+++ loncom/homework/imageresponse.pm	Tue Jul 23 10:41:06 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # image click response style
 #
-# $Id: imageresponse.pm,v 1.18 2002/05/03 20:44:46 albertel Exp $
+# $Id: imageresponse.pm,v 1.19 2002/07/23 14:41:06 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -244,12 +244,13 @@
 
 sub start_image {
   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
-  if ($target eq 'web') { &Apache::lonxml::startredirection; }
+  if ($target eq 'web' || $target eq 'tex') { &Apache::lonxml::startredirection; }
   return '';
 }
 
 sub end_image {
-  my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+  my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;            
+  my $currentstring = '';
   if ($target eq 'web') {
     my $name = $Apache::imageresponse::curname;
     my $image = &Apache::lonxml::endredirection;
@@ -260,8 +261,80 @@
     } else {
       $Apache::response::foilgroup{"$name.image"} = $image;
     }
-  }
-  return '';
+  } elsif ($target eq 'tex') {
+    my $src = &Apache::lonxml::endredirection;
+    $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
+    my $width_param = '';
+    my $height_param = '';
+    my $scaling = .3;
+    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;
+    my $epssrc = $src;
+    $epssrc =~ s/(\.gif|\.jpg)$/\.eps/i;
+    if (not -e $epssrc) {
+	my $localfile = $epssrc;
+	$localfile =~ s/.*(\/res)/$1/;	
+	my $file;
+	my $path;	
+	if ($localfile =~ m!(.*)/([^/]*)$!) {
+	    $file = $2;
+	    $path = $1.'/'; 
+	}	
+	my $signal_eps = 0;
+	my @content_directory = &Apache::lonnet::dirlist($path);
+	for (my $iy=0;$iy<=$#content_directory;$iy++) {
+	    my @tempo_array = split(/&/,$content_directory[$iy]);
+	    $content_directory[$iy] = $tempo_array[0];
+	    if ($file eq $tempo_array[0]) {
+		$signal_eps = 1;
+		last;
+	    }
+	}
+	if ($signal_eps) {
+	    my $eps_file = &Apache::lonnet::getfile($localfile);
+	} else {
+	    $localfile = $src;
+	    $localfile =~ s/.*(\/res)/$1/;	
+	    my $as = &Apache::lonnet::getfile($src);		      
+	}
+    }
+    my $file;
+    my $path;	
+    if ($src =~ m!(.*)/([^/]*)$!) {
+	$file = $2;
+	$path = $1.'/'; 
+    }
+    my $newsrc = $src;
+    $newsrc =~ s/(\.gif|\.jpg)$/\.eps/i;
+    $file=~s/(\.gif|\.jpg)$/\.eps/i;
+    #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);
+    if ($TeXwidth ne '') { 
+	$width_param = $TeXwidth; 
+    } elsif ($TeXheight ne '') { 
+	$width_param = $TeXheight/$height_param*$width_param;
+    } elsif ($width ne '') {
+	$width_param = $width*$scaling;      
+    }
+    #where can we find the picture?
+    if (-e $newsrc) {
+	if ($path) {
+	    $currentstring .= '\vskip 0 mm \noindent\graphicspath{{'.$path.'}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} ';
+	}
+    } else {
+	my $temp_file;
+	my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
+	$temp_file = Apache::File->new('>>'.$filename); 
+	print $temp_file "$src\n";
+	$currentstring .= '\vskip 0 mm \graphicspath{{/home/httpd/prtspool/}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} ';
+    }
+ } 
+  return $currentstring;
 }
 
 sub start_rectangle {