--- loncom/xml/londefdef.pm 2005/08/07 16:53:07 1.284
+++ loncom/xml/londefdef.pm 2005/11/03 21:58:11 1.292
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Tags Default Definition Module
#
-# $Id: londefdef.pm,v 1.284 2005/08/07 16:53:07 albertel Exp $
+# $Id: londefdef.pm,v 1.292 2005/11/03 21:58:11 albertel Exp $
#
#
# Copyright Michigan State University Board of Trustees
@@ -55,6 +55,7 @@ BEGIN {
}
+
sub initialize_londefdef {
$Apache::londefdef::TD_redirection=0;
@Apache::londefdef::table = ();
@@ -166,6 +167,7 @@ sub start_html {
'\usepackage{textcomp}'.
'\usepackage{makeidx}'.
'\usepackage[dvips]{graphicx}'.
+ '\usepackage{wrapfig}'.
'\usepackage{picins}'.
'\usepackage{epsfig}'.
'\usepackage{calc}'.
@@ -1205,6 +1207,9 @@ sub start_br {
} elsif ($target eq 'tex') {
my @tempo=@$tagstack;
my $signal=0;
+ # Not going to factor this to is_inside_of since that would require
+ # multiple stack traversals.
+ #
for (my $i=$#tempo;$i>=0;$i--) {
if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') ||
@@ -2526,7 +2531,7 @@ sub start_img {
my $inside = &Apache::lonxml::get_all_text("/img",$parser);
return '';
}
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
+ &Apache::lonxml::extlink($src);
my $currentstring = '';
my $scaling = .3;
@@ -2559,7 +2564,11 @@ sub start_img {
$safeeval,
undef,1));
if(!$align) {
- $align = "bottom"; # This is html's default so it's ours too.
+ if (&is_inside_of($tagstack, "table")) {
+ $align = "right"; # Force wraptext use.
+ } else {
+ $align = "bottom"; # This is html's default so it's ours too.
+ }
}
#
&Apache::lonxml::debug("Alignemnt = $align");
@@ -2576,7 +2585,7 @@ sub start_img {
undef,0);
&Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
if(!$latex_rendering) {
- $latex_rendering = "parbox";
+ $latex_rendering = "texwrap";
}
&Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
@@ -2617,16 +2626,17 @@ sub start_img {
} elsif ($align eq "left") {
if ($latex_rendering eq "parpic") {
$currentstring = '\parpic[l]{'.$currentstring.'}';
- } else { # parbox rendering
- $currentstring = "\\strut\\newline\n".
- '\parbox{'.$width_param.'mm}{'.$currentstring.'}';
+ } else { # wrapfig render
+ $currentstring = '\begin{wrapfigure}{l}{'.$width_param.'mm}'
+ .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
}
} elsif ($align eq "right") {
if ($latex_rendering eq "parpic") {
$currentstring = '\parpic[r]{'.$currentstring.'}';
- } else { # parbox rendering.
- $currentstring = '\parbox{'.$width_param.'mm}{\begin{flushright}'
- .$currentstring.'\end{flushright}} \newline'."\n";
+ } else { # wrapfig rendering
+ $currentstring = '\begin{wrapfigure}{r}{'.$width_param.'mm}'
+ .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
+
}
} else { # Bottom is also default.
# $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}';
@@ -2731,12 +2741,10 @@ sub start_applet {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code;
-
+ &Apache::lonxml::extlink($code);
my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
undef,1);
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive;
-
+ &Apache::lonxml::extlink($archive);
my $currentstring = '';
if ($target eq 'web') {
if ($env{'browser.appletsuppress'} ne 'on') {
@@ -2782,7 +2790,7 @@ sub end_applet {
sub start_embed {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
+ &Apache::lonxml::extlink($src);
my $currentstring = '';
if ($target eq 'web') {
if ($env{'browser.embedsuppress'} ne 'on') {
@@ -2813,13 +2821,15 @@ sub end_embed {
#-- tag (end tag forbidden)
sub start_param {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- if (&Apache::lonxml::get_param
- ('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) {
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
- &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1);
- }
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
- &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
+ if (&Apache::lonxml::get_param('name',$parstack,
+ $safeeval,undef,1)=~/^cabbase$/i) {
+ my $value=&Apache::lonxml::get_param('value',$parstack,
+ $safeeval,undef,1);
+ &Apache::lonxml::extlink($value);
+ }
+
+ my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
+ &Apache::lonxml::extlink($src);
my $currentstring = '';
if ($target eq 'web') {
my %toconvert;
@@ -2851,9 +2861,8 @@ sub end_param {
sub start_allow {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
- $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
- &Apache::lonnet::clutter($src);
+ &Apache::lonxml::extlink($src);
+
if ($target eq 'tex') { &image_replication($src); }
my $result;
if ($target eq 'edit') {
@@ -3447,9 +3456,12 @@ sub end_legend {
#-- tag (end tag forbidden)
sub start_link {
- my ($target,$token) = @_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web') {
+ my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
+ undef,1);
+ &Apache::lonxml::extlink($href);
$currentstring = $token->[4];
}
return $currentstring;
@@ -3965,6 +3977,13 @@ sub image_height {
sub get_eps_image {
my ($src)=@_;
my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src);
+
+ # In order to prevent the substitution of the alt text, we need to
+ # be sure the orig_src file is on system now so:
+
+ if (! -e $orig_src) {
+ &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
+ }
&Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
my ($spath, $sname, $sext) = fileparse($src, qr/\.(gif|png|jpg|jpeg)/i);
$src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i;
@@ -4082,6 +4101,26 @@ sub LATEX_length {
}
+# is_inside_of $tagstack $tag
+# This sub returns true if the current state of Xml processing
+# is inside of the tag.
+# Parameters:
+# tagstack - The tagstack from the parser.
+# tag - The tag (without the <>'s.).
+# Sample usage:
+# if (is_inside_of($tagstack "table")) {
+# # I'm in a table....
+# }
+sub is_inside_of {
+ my ($tagstack, $tag) = @_;
+ my @stack = @$tagstack;
+ for (my $i = ($#stack - 1); $i >= 0; $i--) {
+ if ($stack[$i] eq $tag) {
+ return 1;
+ }
+ }
+ return 0;
+}
1;