version 1.7, 2004/09/09 07:24:56
|
version 1.13, 2024/04/05 22:44:19
|
Line 29
|
Line 29
|
package Apache::drawimage; |
package Apache::drawimage; |
use strict; |
use strict; |
use Apache::loncommon; |
use Apache::loncommon; |
|
use Apache::lonnet; |
|
use Apache::lonxml; |
|
use lib '/home/httpd/lib/perl/'; |
|
use Time::HiRes qw(gettimeofday); |
|
use LONCAPA; |
|
|
|
|
my %args; |
my %args; |
my $cgi_id; |
my $cgi_id; |
Line 51 sub start_drawimage {
|
Line 57 sub start_drawimage {
|
sub end_drawimage { |
sub end_drawimage { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result; |
my $result; |
|
# need to call rand everytime start_script would evaluate, as the |
|
# safe space rand number generator and the global rand generator |
|
# are not separate |
|
my $randnumber; |
|
if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' || |
|
$target eq 'answer') { |
|
$randnumber=int(rand(1000)); |
|
} |
if ($target eq 'web' || $target eq 'tex') { |
if ($target eq 'web' || $target eq 'tex') { |
my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval); |
my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval); |
my $height =&Apache::lonxml::get_param('height',$parstack,$safeeval); |
my $height =&Apache::lonxml::get_param('height',$parstack,$safeeval); |
my $bgcolor =&Apache::lonxml::get_param('bgcolor',$parstack,$safeeval); |
my $bgcolor =&Apache::lonxml::get_param('bgcolor',$parstack,$safeeval); |
if (!$width) { $width=300; } |
if (!$width) { $width=300; } |
if (!$height) { $height=300; } |
if (!$height) { $height=300; } |
$result.="<img width='$width' height='$height' |
$args{"cgi.$cgi_id.BGCOLOR"}=join(':',($bgcolor)); |
|
if ($target eq 'tex') { |
|
my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1); |
|
if (!$texwidth) { $texwidth='90'; } |
|
$args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height,$texwidth)); |
|
my $tmpdir = LONCAPA::tempdir(); # Where temporary files live: |
|
## Determine filename |
|
my ($seconds, $microseconds) = gettimeofday; |
|
my $filename = $env{'user.name'}.'_'.$env{'user.domain'}. |
|
'_'.$seconds.'_'.$microseconds.'_'.$$.$randnumber.'_drawimage.eps'; |
|
$args{"cgi.$cgi_id.EPSFILE"} = $env{'user.name'}.'_'.$env{'user.domain'}. |
|
'_'.$seconds.'_'.$microseconds.'_'.$$.$randnumber. |
|
'_drawimage.eps'; |
|
$result = "%DYNAMICIMAGE:$width:$height:$texwidth\n"; |
|
$result .= '\graphicspath{{'.$tmpdir.'}}'."\n"; |
|
$result .= '\includegraphics[width='.$texwidth.' mm]{'.$filename.'}'; |
|
&Apache::lonxml::register_ssi('/adm/randomlabel.png?token='.$cgi_id); |
|
} else { |
|
$args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height)); |
|
$result.="<img width='$width' height='$height' |
src='/adm/randomlabel.png?token=$cgi_id' />\n"; |
src='/adm/randomlabel.png?token=$cgi_id' />\n"; |
$args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height)); |
} |
$args{"cgi.$cgi_id.BGCOLOR"}=join(':',($bgcolor)); |
&Apache::lonnet::appenv(\%args); |
&Apache::lonnet::appenv(%args); |
|
if (@cgi_ids) { |
if (@cgi_ids) { |
$cgi_id=pop(@cgi_ids); |
$cgi_id=pop(@cgi_ids); |
} else { |
} else { |
Line 95 sub end_text {
|
Line 127 sub end_text {
|
my $font = &Apache::lonxml::get_param('font',$parstack,$safeeval); |
my $font = &Apache::lonxml::get_param('font',$parstack,$safeeval); |
my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval); |
my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval); |
my $direction = &Apache::lonxml::get_param('direction',$parstack,$safeeval); |
my $direction = &Apache::lonxml::get_param('direction',$parstack,$safeeval); |
|
my $rotation = &Apache::lonxml::get_param('rotation',$parstack,$safeeval); |
my $text = &Apache::lonxml::endredirection(); |
my $text = &Apache::lonxml::endredirection(); |
$text = &Apache::lonnet::escape($text); |
$text = &escape($text); |
$args{"cgi.$cgi_id.OBJTYPE"}.='LABEL:'; |
$args{"cgi.$cgi_id.OBJTYPE"}.='LABEL:'; |
my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++; |
my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++; |
$args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$text,$font,$color,$direction)); |
$args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$text,$font,$color,$direction,$rotation)); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 207 sub start_polygon {
|
Line 240 sub start_polygon {
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result; |
my $result; |
&Apache::lonxml::register('Apache::drawimage',('point')); |
&Apache::lonxml::register('Apache::drawimage',('point')); |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
undef(@polygon); |
undef(@polygon); |
} |
} |
return $result; |
return $result; |
Line 216 sub start_polygon {
|
Line 249 sub start_polygon {
|
sub end_polygon { |
sub end_polygon { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result; |
my $result; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
my $color=&Apache::lonxml::get_param('color',$parstack,$safeeval); |
my $color=&Apache::lonxml::get_param('color',$parstack,$safeeval); |
my $filled=&Apache::lonxml::get_param('filled',$parstack,$safeeval); |
my $filled=&Apache::lonxml::get_param('filled',$parstack,$safeeval); |
my $open=&Apache::lonxml::get_param('open',$parstack,$safeeval); |
my $open=&Apache::lonxml::get_param('open',$parstack,$safeeval); |
Line 234 sub end_polygon {
|
Line 267 sub end_polygon {
|
sub start_point { |
sub start_point { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result; |
my $result; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval); |
my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval); |
my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval); |
my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval); |
push (@polygon,"($x,$y)"); |
push (@polygon,"($x,$y)"); |
Line 262 sub end_image {
|
Line 295 sub end_image {
|
my $result; |
my $result; |
if ($target eq 'web' || $target eq 'tex') { |
if ($target eq 'web' || $target eq 'tex') { |
my $bgimg=&Apache::lonxml::endredirection(); |
my $bgimg=&Apache::lonxml::endredirection(); |
&Apache::lonnet::logthis("image $bgimg"); |
|
my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval); |
my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval); |
my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval); |
my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval); |
my $clipx = &Apache::lonxml::get_param('clipx',$parstack,$safeeval); |
my $clipx = &Apache::lonxml::get_param('clipx',$parstack,$safeeval); |
Line 278 sub end_image {
|
Line 310 sub end_image {
|
my $transparent = |
my $transparent = |
&Apache::lonxml::get_param('transparent',$parstack,$safeeval); |
&Apache::lonxml::get_param('transparent',$parstack,$safeeval); |
$bgimg=&Apache::imageresponse::clean_up_image($bgimg); |
$bgimg=&Apache::imageresponse::clean_up_image($bgimg); |
&Apache::lonnet::logthis("image af clean $bgimg"); |
|
my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++; |
my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++; |
$args{"cgi.$cgi_id.OBJTYPE"}.='IMAGE:'; |
$args{"cgi.$cgi_id.OBJTYPE"}.='IMAGE:'; |
$args{"cgi.$cgi_id.OBJ$i"} = |
$args{"cgi.$cgi_id.OBJ$i"} = |
join(':',($x,$y,&Apache::lonnet::escape($bgimg),$transparent, |
join(':',($x,$y,&escape($bgimg),$transparent, |
$clipx,$clipy,$scaledwidth,$scaledheight,$clipwidth,$clipheight)); |
$clipx,$clipy,$scaledwidth,$scaledheight,$clipwidth,$clipheight)); |
} |
} |
return $result; |
return $result; |