[LON-CAPA-cvs] cvs: loncom /interface printout.pl

foxr lon-capa-cvs@mail.lon-capa.org
Mon, 30 Oct 2006 11:40:50 -0000


foxr		Mon Oct 30 06:40:50 2006 EDT

  Modified files:              
    /loncom/interface	printout.pl 
  Log:
  Part of bz 4265 - if the image conversion queue file has ps or eps images
  in it, just convert any spaces in their names to _'s and copy to the
  spool directory for the latex inclusion..
  
  
Index: loncom/interface/printout.pl
diff -u loncom/interface/printout.pl:1.110 loncom/interface/printout.pl:1.111
--- loncom/interface/printout.pl:1.110	Thu Sep 14 13:04:42 2006
+++ loncom/interface/printout.pl	Mon Oct 30 06:40:49 2006
@@ -29,6 +29,7 @@
 use LONCAPA::loncgi;
 use File::Path;
 use File::Basename;
+use File::Copy;
 use IO::File;
 use Image::Magick;
 use Apache::lonhtmlcommon();
@@ -210,7 +211,6 @@
 	      $not_eps=~s|\/\.\/|\/|g;
 	      my $eps_f = $not_eps;
 	      # $eps_f =~ s/\.[^.]*$/\.eps/i;
-	      $eps_f .= '.eps';	# Just append the eps ext.
 	      if ($eps_f=~/\/home\/([^\/]+)\/public_html\//) {
                   $eps_f=~s/\/home\/([^\/]+)\/public_html/$1/;
 		  $eps_f = '/home/httpd/prtspool/'.$eps_f;
@@ -222,51 +222,68 @@
 		  $eps_f = '/home/httpd/prtspool/'.$1.'/'.$2;
 	      }
 	      $eps_f  =~ s/ /\_/g; # Spaces are problematic for system commands and LaTeX.
-	      my $path=$eps_f;
-	      $path =~ s/\/([^\/]+)\.eps$//;
-	      # print "Final file path: $path "; # Debugging
-	      File::Path::mkpath($path,0,0777);
-	      $not_eps =~ s/^\s+//;
-	      $not_eps =~ s/\s+$//;
-	      $not_eps =~ s/ /\\ /g;
-	      if ( exists($done_conversion{$not_eps})) { next; }
-	      if ($advanced_role) {
-		  my $prettyname=$not_eps;
-		  $prettyname=~s|/home/([^/]+)/public_html|/priv/$1|;
-		  $prettyname=~s|$Apache::lonnet::perlvar{'lonDocRoot'}/|/|;
-		  &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,
-							'Converting to EPS '.$prettyname);
-	      }
-	      $done_conversion{$not_eps}=1;
-	      # print "Converting $not_eps -> $eps_f"; # Debugging
-	      system("convert $not_eps $eps_f");
-              # check is eps exist in prtspool
-              if (not -e $eps_f) {
-		  # converting an animated gif creates either:
-                  # anim.gif.eps.0
-                  # or
-                  # anim.gif-0.eps
-		  for (my $i=0;$i<10000;$i++) {
-		      if (-e $eps_f.'.'.$i) {
-			  rename($eps_f.'.'.$i, $eps_f);
-			  last;
-		      }
-		      my $anim_eps = $eps_f;
-		      $anim_eps =~ s/(\.[^.]*)\.eps$/$1-$i\.eps/i;
-		      if (-e $anim_eps) {
-			  rename($anim_eps, $eps_f);
-			  last;
+	      # 
+	      # If the file is already an .eps or .ps file,
+	      # We really just need to copy it from where it was to prtspool
+	      # but with the spaces substituted to _'s.
+	      #
+	      my ($path, $nsname, $sext) = fileparse($eps_f, qr/\.(ps|eps)/i);
+	      if ($sext =~/ps$/i) {
+		  File::Path::mkpath($path,0,0777);
+		  $not_eps =~ s/^\s+//;
+		  $not_eps =~ s/\s+$//;
+		  $not_eps =~ s/ /\__/g;
+		  File::Copy("$not_eps", "$eps_f"); 
+	      } else {
+	      
+		  $eps_f .= '.eps';	# Just append the eps ext.
+		  my $path=$eps_f;
+		  $path =~ s/\/([^\/]+)\.eps$//;
+		  # print "Final file path: $path "; # Debugging
+		  File::Path::mkpath($path,0,0777);
+		  $not_eps =~ s/^\s+//;
+		  $not_eps =~ s/\s+$//;
+		  $not_eps =~ s/ /\\ /g;
+		  if ( exists($done_conversion{$not_eps})) { next; }
+		  if ($advanced_role) {
+		      my $prettyname=$not_eps;
+		      $prettyname=~s|/home/([^/]+)/public_html|/priv/$1|;
+		      $prettyname=~s|$Apache::lonnet::perlvar{'lonDocRoot'}/|/|;
+		      &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,
+							    'Converting to EPS '.$prettyname);
+		  }
+		  $done_conversion{$not_eps}=1;
+		  # print "Converting $not_eps -> $eps_f"; # Debugging
+		  system("convert $not_eps $eps_f");
+		  # check is eps exist in prtspool
+		  if (not -e $eps_f) {
+		      # converting an animated gif creates either:
+		      # anim.gif.eps.0
+		      # or
+		      # anim.gif-0.eps
+		      for (my $i=0;$i<10000;$i++) {
+			  if (-e $eps_f.'.'.$i) {
+			      rename($eps_f.'.'.$i, $eps_f);
+			      last;
+			  }
+			  my $anim_eps = $eps_f;
+			  $anim_eps =~ s/(\.[^.]*)\.eps$/$1-$i\.eps/i;
+			  if (-e $anim_eps) {
+			      rename($anim_eps, $eps_f);
+			      last;
+			  }
 		      }
 		  }
-	      }
-	      # imagemagick 6.2.0-6.2.7 fails to properly handle
-              # convert anim.gif anim.gif.eps
-              # it creates anim.eps instead. 
-              if (not -e $eps_f) {
-		  my $eps_f2 = $eps_f;
-		  $eps_f2 =~ s/\.[^.]*\.eps$/\.eps/i;
-		  if(-e $eps_f2) {
-		      rename($eps_f2,$eps_f);
+		  
+		  # imagemagick 6.2.0-6.2.7 fails to properly handle
+		  # convert anim.gif anim.gif.eps
+		  # it creates anim.eps instead. 
+		  if (not -e $eps_f) {
+		      my $eps_f2 = $eps_f;
+		      $eps_f2 =~ s/\.[^.]*\.eps$/\.eps/i;
+		      if(-e $eps_f2) {
+			  rename($eps_f2,$eps_f);
+		      }
 		  }
 	      }