--- loncom/xml/londefdef.pm 2002/05/22 21:07:45 1.62 +++ loncom/xml/londefdef.pm 2002/07/12 16:37:38 1.73 @@ -1,8 +1,7 @@ - # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.62 2002/05/22 21:07:45 sakharuk Exp $ +# $Id: londefdef.pm,v 1.73 2002/07/12 16:37:38 albertel Exp $ # # # Copyright Michigan State University Board of Trustees @@ -49,10 +48,11 @@ use Apache::lonnet; use strict; use Apache::lonxml; use Apache::File(); +use Image::Magick; BEGIN { - &Apache::lonxml::register('Apache::londefdef',('m','html','head','map','select','option','input','textarea','form','meta','title','body','center','b','strong','dt','h1','h2','h3','h4','h5','h6','cite','i','address','dd','dl','dir','ol','ul','menu','dfn','kbd','tt','code','em','q','p','br','big','small','basefont','font','s','sub','strike','sup','hr','a','li','u','output','param','applet','img','embed','allow','frameset','pre','insert','externallink','table','tr','th','td')); + &Apache::lonxml::register('Apache::londefdef',('m','html','head','map','select','option','input','textarea','form','meta','title','body','center','b','strong','dt','h1','h2','h3','h4','h5','h6','cite','i','address','dd','dl','dir','ol','ul','menu','dfn','kbd','tt','code','em','q','p','br','big','small','basefont','font','s','sub','strike','sup','hr','a','li','u','output','param','applet','img','embed','allow','frameset','pre','insert','externallink','table','tr','th','td','blankspace','bubble','bubbles','bubbleline')); } @@ -74,7 +74,7 @@ sub start_m { my $currentstring = ''; if ($target eq 'web') { $Apache::lonxml::prevent_entity_encode++; - my $inside = &Apache::lonxml::get_all_text("/m",$$parser[-1]); + 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); @@ -90,7 +90,9 @@ sub start_m { } #&Apache::lonxml::debug("M is ends with:$currentstring:"); } elsif ($target eq 'tex') { - $currentstring = ""; + $currentstring = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); + } else { + my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); } return $currentstring; } @@ -122,7 +124,7 @@ sub end_m { $currentstring .= '\documentclass[letterpaper]{article} \newcommand{\keephidden}[1]{} \usepackage[dvips]{graphicx} - \usepackage{epsfig}'; + \usepackage{epsfig}\usepackage{calc}'; } return $currentstring; } @@ -840,7 +842,7 @@ EDITBUTTON if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '\\\\'; + $currentstring .= '\vskip 0 mm'; } elsif ($target eq 'latexsource') { $currentstring .= '\\'; } @@ -1286,7 +1288,7 @@ EDITBUTTON $Apache::londefdef::table[-1]{'vvinc'} = '|'; } else { $Apache::londefdef::table[-1]{'hinc'} = ''; - $Apache::londefdef::table[-1]{'vinc'} = ''; + $Apache::londefdef::table[-1]{'vinc'} = '&'; $Apache::londefdef::table[-1]{'vvinc'} = ''; } } @@ -1311,7 +1313,17 @@ EDITBUTTON chop $output; $output .= ' \\\\ '; } - $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$output.$Apache::londefdef::table[-1]{'hinc'}.'\end{tabular}'; + my @length = split(/,/,$Apache::londefdef::table[-1]{'length'}); + my $how_many_columns = $#length+1; + my $parboxlength = '(\textwidth'; + for (my $io=0; $io<=$#length;$io++) { + if ($length[$io] ne '') { + $parboxlength .= ' - '.$length[$io].' '; + } + } + $parboxlength .= ')/'.$how_many_columns.' - 7 mm'; + $output =~ s/\\parbox{}/\\parbox{$parboxlength}/g; + $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$output.$Apache::londefdef::table[-1]{'hinc'}.'\end{tabular}\vskip 0 mm '; if ($#Apache::londefdef::table > 0) { $inmemory = $Apache::londefdef::table[-1]{'output'}; pop @Apache::londefdef::table; @@ -1336,10 +1348,11 @@ EDITBUTTON if ($alignchar ne '') { push @ {$Apache::londefdef::table[-1]{'rows'} }, $alignchar; } else { - push @ {$Apache::londefdef::table[-1]{'rows'} }, 'c'; + push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l'; } push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'}); $Apache::londefdef::table[-1]{'counter_columns'} = -1; + $Apache::londefdef::table[-1]{'length'} = ''; #just added } return $currentstring; @@ -1380,7 +1393,10 @@ EDITBUTTON } elsif ($target eq 'tex') { my $current_row = $Apache::londefdef::table[-1]{'row_number'}; my $data=&Apache::lonxml::endredirection(); - @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= $data.' '.$Apache::londefdef::table[-1]{'vinc'}; + if ($data=~m/width\s*=\s*(\d+\.*\d*\s*(mm|cm))/) { #just added + $Apache::londefdef::table[-1]{'length'} .= $1.','; #just added + } #just added + @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{'.$1.'}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; } return $currentstring; } @@ -1410,7 +1426,10 @@ EDITBUTTON } elsif ($target eq 'tex') { my $current_row = $Apache::londefdef::table[-1]{'row_number'}; my $data=&Apache::lonxml::endredirection(); - @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\bf{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; + if ($data=~m/width\s*=\s*(\d+\.*\d*\s*(mm|cm))/) { #just added + $Apache::londefdef::table[-1]{'length'} .= $1.','; #just added + } #just added + @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{'.$1.'}{\textbf{'.$data.'}} '.$Apache::londefdef::table[-1]{'vinc'}; } return $currentstring; } @@ -1421,31 +1440,21 @@ EDITBUTTON $token->[2]->{'src'}; my $currentstring = ''; my $width_param = ''; + my $height_param = ''; + my $scaling = .3; if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); - my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); - my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval); - if ($TeXwidth ne '') { - $width_param = $TeXwidth; - } elsif ($TeXheight ne '') { - $width_param = $TeXheight; - } else { - if ($width ne '') { - $width_param = $width*.3; - if ($width_param <= 900) { - $width_param = '[width='.$width_param.'mm]'; - } else { - $width_param = '[width= 9.0 cm]'; - } - } - } my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval); $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); + my $image = Image::Magick->new; + my $current_figure = $image->Read($src); + $width_param = $image->Get('width') * $scaling;; + $height_param = $image->Get('height') * $scaling;; + undef $image; my $epssrc = $src; - $epssrc =~ s/(\.gif|\.jpg|\.GIF|\.JPG)$/\.eps/; + $epssrc =~ s/(\.gif|\.jpg)$/\.eps/i; if (not -e $epssrc) { my $localfile = $epssrc; $localfile =~ s/.*(\/res)/$1/; @@ -1470,8 +1479,7 @@ EDITBUTTON } else { $localfile = $src; $localfile =~ s/.*(\/res)/$1/; - my $as = &Apache::lonnet::getfile($src); - + my $as = &Apache::lonnet::getfile($src); } } my $file; @@ -1481,18 +1489,30 @@ EDITBUTTON $path = $1.'/'; } my $newsrc = $src; - $newsrc =~ s/(\.gif|\.jpg|\.GIF|\.JPG)$/\.eps/; - $file=~s/(\.gif|\.jpg|\.GIF|\.JPG)$/\.eps/; + $newsrc =~ s/(\.gif|\.jpg)$/\.eps/i; + $file=~s/(\.gif|\.jpg)$/\.eps/i; + #do we have any specified size of the picture? + my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); + my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); + my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval); + if ($TeXwidth ne '') { + $width_param = $TeXwidth; + } elsif ($TeXheight ne '') { + $width_param = $TeXheight/$height_param*$width_param; + } elsif ($width ne '') { + $width_param = $width*$scaling; + } + #where can we find the picture? if (-e $newsrc) { if ($path) { - $currentstring .= '\graphicspath{{'.$path.'}}\fbox{\includegraphics'.$width_param.'{'.$file.'}}'; + $currentstring .= '\noindent\graphicspath{{'.$path.'}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} '; } } else { my $temp_file; - my $filename = "/home/httpd/prtspool/$ENV{'user.name'}$ENV{'user.domain'}temp$ENV{'user.login.time'}.dat"; + my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"; $temp_file = Apache::File->new('>>'.$filename); print $temp_file "$src\n"; - $currentstring .= '\graphicspath{{/home/httpd/prtspool/}}\fbox{\includegraphics'.$width_param.'{'.$file.'}}'; + $currentstring .= '\graphicspath{{/home/httpd/prtspool/}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} '; } } return $currentstring; @@ -1679,5 +1699,24 @@ sub start_embed { } return $currentstring; } +#-- + sub start_blankspace { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my $currentstring = ''; + if ($target eq 'tex') { + my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval); + $currentstring .= '\vskip '.$howmuch.' '; + } + return $currentstring; + } + sub end_blankspace { + my ($target,$token) = @_; + my $currentstring = ''; + if ($target eq 'tex') { + $currentstring .= ''; + } + return $currentstring; + } + 1; __END__