version 1.259, 2005/03/01 03:21:58
|
version 1.266, 2005/04/06 06:09:42
|
Line 156 sub start_html {
|
Line 156 sub start_html {
|
if ($target eq 'web' || $target eq 'edit') { |
if ($target eq 'web' || $target eq 'edit') { |
$currentstring = &Apache::lonxml::xmlbegin(); |
$currentstring = &Apache::lonxml::xmlbegin(); |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
@Apache::londefdef::table = (); |
|
$currentstring .= '\documentclass[letterpaper]{article}'; |
$currentstring .= '\documentclass[letterpaper]{article}'; |
if (($ENV{'form.latex_type'}=~'batchmode') || |
if (($ENV{'form.latex_type'}=~'batchmode') || |
(!$ENV{'request.role.adv'})) {$currentstring .='\batchmode';} |
(!$ENV{'request.role.adv'})) {$currentstring .='\batchmode';} |
Line 2495 sub start_img {
|
Line 2494 sub start_img {
|
if(!$latex_rendering) { |
if(!$latex_rendering) { |
$latex_rendering = "parbox"; |
$latex_rendering = "parbox"; |
} |
} |
&Apache::lonxml::debug("LaTeX rendering = $latex_rendering"); |
&Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src"); |
|
|
#if original gif/jpg/png file exist do following: |
#if original gif/jpg/png file exist do following: |
|
my $origsrc=$src; |
my ($path,$file) = &get_eps_image($src); |
my ($path,$file) = &get_eps_image($src); |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
|
&Apache::lonxml::debug("path = $path file = $file src = $src"); |
if (-e $src) { |
if (-e $src) { |
|
&Apache::lonxml::debug("$src exists"); |
my ($height_param,$width_param)= |
my ($height_param,$width_param)= |
&image_size($src,0.3,$parstack,$safeeval); |
&image_size($origsrc,0.3,$parstack,$safeeval); |
$currentstring .= '\graphicspath{{'.$path.'}}' |
my $destpath = $path; |
.'\includegraphics[width='.$width_param.' mm,height='.$height_param.'mm]{'.$file.'} '; |
$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'.$size.'{'.$destfile.'} '; |
|
|
# If there's an alignment specification we need to honor it here. |
# If there's an alignment specification we need to honor it here. |
# For the horizontal alignments, we will also honor the |
# For the horizontal alignments, we will also honor the |
Line 2537 sub start_img {
|
Line 2548 sub start_img {
|
# $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}'; |
# $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}'; |
} |
} |
} else { |
} else { |
|
&Apache::lonxml::debug("$src does not exist"); |
#original image file doesn't exist so check the alt attribute |
#original image file doesn't exist so check the alt attribute |
my $alt = |
my $alt = |
&Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1); |
&Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1); |
Line 2615 sub start_img {
|
Line 2627 sub start_img {
|
} |
} |
if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);} |
if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);} |
} |
} |
|
|
return $currentstring; |
return $currentstring; |
} |
} |
|
|
Line 3749 sub image_replication {
|
Line 3762 sub image_replication {
|
$pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i; |
$pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i; |
if (not -e $epssrc && not -e $pssrc) { |
if (not -e $epssrc && not -e $pssrc) { |
my $result=&Apache::lonnet::repcopy($epssrc); |
my $result=&Apache::lonnet::repcopy($epssrc); |
if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); } |
if ($result ne 'ok') { &Apache::lonnet::repcopy($pssrc); } |
} |
} |
return ''; |
return ''; |
} |
} |
|
|
sub image_size { |
sub image_size { |
my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_; |
my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_; |
|
|
#size of image from gif/jpg/jpeg/png |
#size of image from gif/jpg/jpeg/png |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
|
if (-e $ressrc) { |
|
$src = $ressrc; |
|
} |
my $image = Image::Magick->new; |
my $image = Image::Magick->new; |
my $current_figure = $image->Read($src); |
my $current_figure = $image->Read($src); |
my $width_param = $image->Get('width') * $scaling;; |
my $width_param = $image->Get('width') * $scaling;; |
my $height_param = $image->Get('height') * $scaling;; |
my $height_param = $image->Get('height') * $scaling; |
|
&Apache::lonxml::debug("Image magick says: $src : Height = $height_param width = $width_param"); |
undef($image); |
undef($image); |
#do we have any specified LaTeX size of the picture? |
#do we have any specified LaTeX size of the picture? |
my $toget='TeXwidth'; if ($cis) { $toget=lc($toget); } |
my $toget='TeXwidth'; |
|
if ($cis) { |
|
$toget=lc($toget); |
|
} |
my $TeXwidth = &Apache::lonxml::get_param($toget,$parstack, |
my $TeXwidth = &Apache::lonxml::get_param($toget,$parstack, |
$safeeval,$depth,$cis); |
$safeeval,$depth,$cis); |
$toget='TeXheight'; if ($cis) { $toget=lc($toget); } |
$toget='TeXheight'; if ($cis) { $toget=lc($toget); } |
Line 3780 sub image_size {
|
Line 3801 sub image_size {
|
} else { |
} else { |
$width_param = $TeXwidth; |
$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) { |
} elsif ($TeXheight) { |
$height_param = $TeXheight; |
$height_param = $TeXheight; |
$width_param = $TeXheight/$height_param*$width_param; |
if ($height_param) { |
|
$width_param = $TeXheight/$height_param*$width_param; |
|
} |
} elsif ($width) { |
} elsif ($width) { |
my $old_width_param=$width_param; |
my $old_width_param=$width_param; |
$width_param = $width*$scaling; |
$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'}) { |
if ($width_param > $ENV{'form.textwidth'}) { |
my $old_width_param=$width_param; |
my $old_width_param=$width_param; |
$width_param =0.95*$ENV{'form.textwidth'}; |
$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); |
return ($height_param, $width_param); |
} |
} |
Line 3811 sub image_height {
|
Line 3842 sub image_height {
|
|
|
sub get_eps_image { |
sub get_eps_image { |
my ($src)=@_; |
my ($src)=@_; |
my $orig_src=$src; |
my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src); |
|
&Apache::lonxml::debug("get_eps_image: Original image: $orig_src<BR />"); |
$src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i; |
$src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i; |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); |
|
&Apache::lonxml::debug("Filelocation gives; $src <BR />"); |
if (! -e $src) { |
if (! -e $src) { |
if (&Apache::lonnet::repcopy($src) ne OK ) { |
&Apache::lonxml::debug("$src does not exist"); |
|
if (&Apache::lonnet::repcopy($src) ne 'ok' ) { |
|
&Apache::lonxml::debug("Repcopy of $src failed (1)"); |
#if replication failed try to find ps file |
#if replication failed try to find ps file |
$src=~s/\.eps$/\.ps/; |
$src=~s/\.eps$/\.ps/; |
|
&Apache::lonxml::debug("Now looking for $src"); |
#if no ps file try to replicate it |
#if no ps file try to replicate it |
if (not -e $src && |
if (not -e $src && |
&Apache::lonnet::repcopy($src) ne OK) { |
&Apache::lonnet::repcopy($src) ne 'ok') { |
|
&Apache::lonxml::debug("Failed to find or replicate $src"); |
|
|
#if replication failed try to produce eps file dynamically |
#if replication failed try to produce eps file dynamically |
$src=~s/\.ps$/\.eps/; |
$src=~s/\.ps$/\.eps/; |
my $temp_file; |
my $temp_file; |
open(FILE,">>/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"); |
open(FILE,">>/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"); |
my $newsrc=$orig_src; |
my $newsrc=$orig_src; |
$newsrc =~ s|(.*)/res/|/home/httpd/html/res/|; |
$newsrc =~ s|(.*)/res/|/home/httpd/html/res/|; |
|
&Apache::lonxml::debug("queueing $newsrc for dynamic eps production. <BR/>"); |
print FILE "$newsrc\n"; |
print FILE "$newsrc\n"; |
|
close FILE; |
$src=~s|/home/httpd/html/res|/home/httpd/prtspool|; |
$src=~s|/home/httpd/html/res|/home/httpd/prtspool|; |
$src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|; |
$src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|; |
} |
} |
} |
} |
} |
} |
my ($path,$file)=($src=~m|(.*)/([^/]*)$|); |
my ($path,$file)=($src=~m|(.*)/([^/]*)$|); |
|
&Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />"); |
return ($path.'/',$file); |
return ($path.'/',$file); |
} |
} |
|
|