--- loncom/xml/londefdef.pm 2004/04/06 18:05:29 1.208 +++ loncom/xml/londefdef.pm 2004/05/12 18:29:57 1.214 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.208 2004/04/06 18:05:29 sakharuk Exp $ +# $Id: londefdef.pm,v 1.214 2004/05/12 18:29:57 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -633,7 +633,7 @@ sub start_h1 { } elsif ($target eq 'tex') { my $pre; my $align=lc(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1)); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $pre='\begin{center}'; } elsif ($align eq 'left') { $pre='\rlap{'; @@ -656,9 +656,9 @@ sub end_h1 { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - my $post; + my $post='\vskip 0 mm '; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $post='\end{center}'; } elsif ($align eq 'left') { $post='} \hfill'.'\vskip 0 mm '; @@ -682,7 +682,7 @@ sub start_h2 { } elsif ($target eq 'tex') { my $pre; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $pre='\begin{center}'; } elsif ($align eq 'left') { $pre='\rlap{'; @@ -702,9 +702,9 @@ sub end_h2 { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - my $post; + my $post='\vskip 0 mm '; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $post='\end{center}'; } elsif ($align eq 'left') { $post='} \hfill'.'\vskip 0 mm '; @@ -725,7 +725,7 @@ sub start_h3 { } elsif ($target eq 'tex') { my $pre; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $pre='\begin{center}'; } elsif ($align eq 'left') { $pre='\rlap{'; @@ -745,9 +745,9 @@ sub end_h3 { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - my $post; + my $post='\vskip 0 mm '; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $post='\end{center}'; } elsif ($align eq 'left') { $post='} \hfill'.'\vskip 0 mm '; @@ -768,7 +768,7 @@ sub start_h4 { } elsif ($target eq 'tex') { my $pre; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $pre='\begin{center}'; } elsif ($align eq 'left') { $pre='\rlap{'; @@ -788,9 +788,9 @@ sub end_h4 { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - my $post; + my $post='\vskip 0 mm '; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $post='\end{center}'; } elsif ($align eq 'left') { $post='} \hfill'.'\vskip 0 mm '; @@ -811,7 +811,7 @@ sub start_h5 { } elsif ($target eq 'tex') { my $pre; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $pre='\begin{center}'; } elsif ($align eq 'left') { $pre='\rlap{'; @@ -831,9 +831,9 @@ sub end_h5 { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - my $post; + my $post='\vskip 0 mm '; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $post='\end{center}'; } elsif ($align eq 'left') { $post='} \hfill'.'\vskip 0 mm '; @@ -854,7 +854,7 @@ sub start_h6 { } elsif ($target eq 'tex') { my $pre; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $pre='\begin{center}'; } elsif ($align eq 'left') { $pre='\rlap{'; @@ -874,9 +874,9 @@ sub end_h6 { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - my $post; + my $post='\vskip 0 mm '; my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (($align eq 'center') || (not defined $align)) { + if ($align eq 'center') { $post='\end{center}'; } elsif ($align eq 'left') { $post='} \hfill'.'\vskip 0 mm '; @@ -1904,7 +1904,6 @@ sub end_table { $space_neeeded=$space_neeeded+$max_len[$jn]; } if ($space_neeeded<=$available_space) { -## &Apache::lonnet::logthis("I am in position 1: $space_neeeded <= $available_space"); for (my $jn=0;$jn<=$#max_len;$jn++) { if ($fwidth[$jn]==0) { $fwidth[$jn]=$max_len[$jn]; @@ -1917,7 +1916,6 @@ sub end_table { $space_neeeded+=$min_len[$jn]; } if ($space_neeeded>$available_space) { -## &Apache::lonnet::logthis("I am in position 2"); $WARNING=' \textbf{NOT ENOUGH SPACE FOR TABLE} '; for (my $jn=0;$jn<=$#max_len;$jn++) { if ($fwidth[$jn]==0) { @@ -1926,7 +1924,6 @@ sub end_table { } } else { #step 3. adjustment over minimal + corrections -## &Apache::lonnet::logthis("I am in position 3"); my $enlarge_coef=$available_space/$space_neeeded; my $acsessive=0; for (my $jn=0;$jn<=$#min_len;$jn++) { @@ -2271,6 +2268,10 @@ sub start_img { } } elsif ($target eq 'tex') { $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); + #if uploaded restore the path + if ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/simplepage\/([^\/]+)$/) { + $src=&Apache::loncommon::propath($1,$2).'/userfiles/simplepage/'.$3; + } #if original gif/jpg/png file exist do following: if (-e $src) { #what is the image size? @@ -2333,25 +2334,45 @@ sub start_img { if ($height) { $currentstring.=' height="'.$height.'" '; } $currentstring .= ' />'; } elsif ($target eq 'modified') { - my $constructtag=&Apache::edit::get_new_args($token,$parstack, - $safeeval,'src','alt', - 'TeXwidth','TeXheight', - 'width','height'); - $src=$token->[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; + my ($osrc,$owidth,$oheight)= + ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'}); + my $ctag=&Apache::edit::get_new_args($token,$parstack, + $safeeval,'src','alt', + 'TeXwidth','TeXheight', + 'width','height'); + my ($nsrc,$nwidth,$nheight)= + ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'}); + my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc); + &image_replication($loc); + my ($iwidth,$iheight); + if (-e $loc) { + my $image = Image::Magick->new; + $image->Read($loc); + ($iwidth, $iheight) = ($image->Get('width'), + $image->Get('height')); + } + if ($osrc ne $nsrc || (!$nwidth && !$nheight)) { + # changed image or no size specified, + # if they didn't explicitly change the + # width or height use the ones from the image + if ($iwidth && $iheight) { + if ($owidth == $nwidth || (!$nwidth && !$nheight)) { + $token->[2]{'width'} = $iwidth;$ctag=1; + } + if ($oheight == $nheight || (!$nwidth && !$nheight)) { + $token->[2]{'height'}=$iheight;$ctag=1; } } } - if ($constructtag) {$currentstring=&Apache::edit::rebuild_tag($token);} + my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'}); + # if we don't have a width or height + if ($iwidth && $cwidth && !$cheight) { + $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1; + } + if ($iheight && $cheight && !$cwidth) { + $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1; + } + if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);} } return $currentstring; } @@ -3520,6 +3541,10 @@ sub eps_generation { $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//; $newsrc=~s/\/\.\//\//; $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//; + if ($newsrc=~/\/home\/httpd\/lonUsers\//) { + $newsrc=~s/\/home\/httpd\/lonUsers//; + $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//; + } return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; }