--- loncom/xml/londefdef.pm 2003/10/21 19:40:32 1.185 +++ loncom/xml/londefdef.pm 2004/01/28 17:16:27 1.194 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.185 2003/10/21 19:40:32 albertel Exp $ +# $Id: londefdef.pm,v 1.194 2004/01/28 17:16:27 albertel Exp $ # # # Copyright Michigan State University Board of Trustees @@ -50,8 +50,8 @@ use Apache::File(); use Image::Magick; use Apache::lonmenu(); use Apache::lonmeta(); +use Apache::Constants qw(:common); -$Apache::londefdef::TD_redirection=0; BEGIN { @@ -59,6 +59,15 @@ BEGIN { } +sub initialize_londefdef { + $Apache::londefdef::TD_redirection=0; + @Apache::londefdef::table = (); + $Apache::londefdef::select=0; + @Apache::londefdef::description=(); + $Apache::londefdef::DD_redirection=0; + $Apache::londefdef::DT_redirection=0; +} + #======================= TAG SUBROUTINES ===================== #-- sub start_output { @@ -73,11 +82,11 @@ sub end_output { } #-- tag sub start_m { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $currentstring = ''; - if ($target eq 'web') { + my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); + if ($target eq 'web' || $target eq 'analyze') { $Apache::lonxml::prevent_entity_encode++; - my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); $inside ='\\documentstyle{article}'.$inside; &Apache::lonxml::debug("M is starting with:$inside:"); my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); @@ -94,15 +103,13 @@ sub start_m { #&Apache::lonxml::debug("M is ends with:$currentstring:"); $Apache::lonxml::post_evaluate=0; } elsif ($target eq 'tex') { - $currentstring = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); + $currentstring = $inside; my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); if ($eval eq 'on') { $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]); } if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';} $Apache::lonxml::post_evaluate=0; - } else { - my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); } return $currentstring; } @@ -144,22 +151,9 @@ sub end_tthoption { sub start_html { my ($target,$token) = @_; my $currentstring = ''; - if ($ENV{'browser.mathml'}) { - &tth::ttminit(); - if ($ENV{'browser.unicode'}) { - &tth::ttmoptions('-L -u1'); - } else { - &tth::ttmoptions('-L -u0'); - } - } else { - &tth::tthinit(); - if ($ENV{'browser.unicode'}) { - &tth::tthoptions('-L -u1'); - } else { - &tth::tthoptions('-L -u0'); - } - } - if ($target eq 'web') { + my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'}; + &init_tth(); + if ($target eq 'web' || $target eq 'edit') { $currentstring = &Apache::lonxml::xmlbegin(). &Apache::lonxml::fontsettings(); } elsif ($target eq 'tex') { @@ -2084,6 +2078,11 @@ sub start_img { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval, undef,1); + if (not $src and ($target eq 'web' or $target eq 'tex')) { + my $inside = &Apache::lonxml::get_all_text("/img",$parser); + &Apache::lonnet::logthis("inside was $inside"); + return ''; + } $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src; my $currentstring = ''; my $width_param = ''; @@ -2105,7 +2104,7 @@ sub start_img { $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); &image_replication($src); #if original gif/jpg/png file exist do following: - if (-e $src) { + if (-e $src) { #defines the default size of image my $image = Image::Magick->new; my $current_figure = $image->Read($src); @@ -2160,6 +2159,8 @@ sub start_img { $temp_file = Apache::File->new('>>'.$filename); print $temp_file "$src\n"; $newsrc=~s/\/home\/httpd\/html\/res//; + $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//; + $newsrc=~s/\/\.\//\//; $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//; $currentstring .= '\vskip 1 mm \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; } @@ -2178,6 +2179,45 @@ sub start_img { # tag will care about replication } } + } elsif ($target eq 'edit') { + $currentstring .=&Apache::edit::tag_start($target,$token); + $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70). + &Apache::edit::browse('src',undef,'alt').' '. + &Apache::edit::search('src',undef,'alt').'
'; + $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'
'; + $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5); + $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'
'; + $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5); + $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5); + $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); + my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval); + my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval); + my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval); + my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval); + $currentstring .= ''.$alt.'[2]{'src'}; + if (!$token->[2]{'width'} && !$token->[2]{'height'}) { + $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); + &image_replication($src); + if (-e $src) { + my $image = Image::Magick->new; + my ($width, $height, $size, $format) = $image->Ping($src); + if ($width && $height) { + $token->[2]{'width'} =$width; + $token->[2]{'height'}=$height; + $constructtag=1; + } + } + } + if ($constructtag) {$currentstring=&Apache::edit::rebuild_tag($token);} } return $currentstring; } @@ -3294,18 +3334,14 @@ sub end_hideweboutput { sub image_replication { my $src = shift; - if (not -e $src) { - #replicates image itself - &Apache::lonnet::repcopy($src); - #replicates eps or ps - my $newsrc = $src; - $newsrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i; - if (not -e $newsrc) { - if (&Apache::lonnet::repcopy($newsrc) ne 'OK') { - $newsrc =~ s/\.eps$/\.ps/; - &Apache::lonnet::repcopy($newsrc); - } - } + if (not -e $src) { &Apache::lonnet::repcopy($src); } + #replicates eps or ps + my $epssrc = my $pssrc = $src; + $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i; + $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i; + if (not -e $epssrc && not -e $pssrc) { + my $result=&Apache::lonnet::repcopy($epssrc); + if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); } } return ''; }