[LON-CAPA-cvs] cvs: loncom /homework drawimage.pm

albertel lon-capa-cvs@mail.lon-capa.org
Sat, 15 Nov 2003 06:33:39 -0000


albertel		Sat Nov 15 01:33:39 2003 EDT

  Added files:                 
    /loncom/homework	drawimage.pm 
  Log:
  - first pass at a <drawimage> tag probalby not great and it needs a new version of randomlylabel.pm to work
  
  

Index: loncom/homework/drawimage.pm
+++ loncom/homework/drawimage.pm
# The LearningOnline Network with CAPA
# programatic image drawing
#
# $Id: drawimage.pm,v 1.1 2003/11/15 06:33:39 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#

package Apache::drawimage;
use strict;
use Apache::loncommon;

my %args;
my $cgi_id;
BEGIN {
    &Apache::lonxml::register('Apache::drawimage',('drawimage'));
}

sub start_drawimage {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    &Apache::lonxml::register('Apache::drawimage',('line','rectangle','arc','fill'));
    if ($target eq 'web' || $target eq 'tex') {
	$cgi_id=&Apache::loncommon::get_cgi_id();
	%args=();
    }
}

sub end_drawimage {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    my $result;
    if ($target eq 'web' || $target eq 'tex') {
	if ($target eq 'web') {
	    my $width = 
		&Apache::lonxml::get_param('width',$parstack,$safeeval);
	    my $height =
		&Apache::lonxml::get_param('height',$parstack,$safeeval);
	    my $bgcolor =
		&Apache::lonxml::get_param('bgcolor',$parstack,$safeeval);
	    if (!$width) { $width=300; }
	    if (!$height) { $height=300; }
	    $result.="<img width='$width' height='$height'
                           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);
	} elsif ($target eq 'tex') {
	    #FIXME generate image some how
	    #probably Simple::PostScript
	}
    }
    &Apache::lonxml::deregister('Apache::drawimage',('line','rectangle'));
    return $result;
}

sub start_line {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    my $result;
    if ($target eq 'web' || $target eq 'tex') {
	my $x1 = &Apache::lonxml::get_param('x1',$parstack,$safeeval);
	my $y1 = &Apache::lonxml::get_param('y1',$parstack,$safeeval);
	my $x2 = &Apache::lonxml::get_param('x2',$parstack,$safeeval);
	my $y2 = &Apache::lonxml::get_param('y2',$parstack,$safeeval);
	my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
	my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);
	my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;
	$args{"cgi.$cgi_id.OBJ$i"}=join(':',($x1,$y1,$x2,$y2,$color,$thickness));
	$args{"cgi.$cgi_id.OBJTYPE"}.='LINE:';
    }
    return $result;
}

sub end_line {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    my $result;
    return $result;
}

sub start_rectangle {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    my $result;
    if ($target eq 'web' || $target eq 'tex') {
	my $x1 = &Apache::lonxml::get_param('x1',$parstack,$safeeval);
	my $y1 = &Apache::lonxml::get_param('y1',$parstack,$safeeval);
	my $x2 = &Apache::lonxml::get_param('x2',$parstack,$safeeval);
	my $y2 = &Apache::lonxml::get_param('y2',$parstack,$safeeval);
	my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
	my $thickness = &Apache::lonxml::get_param('thickness',$parstack,
						   $safeeval);
	my $filled = &Apache::lonxml::get_param('filled',$parstack,
						$safeeval);
	my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;
	$args{"cgi.$cgi_id.OBJ$i"}=
	    join(':',($x1,$y1,$x2,$y2,$color,$thickness,$filled));
	$args{"cgi.$cgi_id.OBJTYPE"}.='RECTANGLE:';
    }
    return $result;
}

sub end_rectangle {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    my $result;
    return $result;
}

sub start_arc {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    my $result;
    if ($target eq 'web' || $target eq 'tex') {
	my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
	my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
	my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
	my $height = &Apache::lonxml::get_param('height',$parstack,$safeeval);
	my $start = &Apache::lonxml::get_param('start',$parstack,$safeeval);
	my $end = &Apache::lonxml::get_param('end',$parstack,$safeeval);
	my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
	my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);
	my $filled = &Apache::lonxml::get_param('filled',$parstack,$safeeval);
	my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;
	$args{"cgi.$cgi_id.OBJ$i"}=
	    join(':',($x,$y,$width,$height,$start,$end,$color,$thickness,
		      $filled));
	$args{"cgi.$cgi_id.OBJTYPE"}.='ARC:';
    }
    return $result;
}

sub end_arc {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    my $result;
    return $result;
}

sub start_arc {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    my $result;
    if ($target eq 'web' || $target eq 'tex') {
	my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
	my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
	my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
	my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;
	$args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$color));
	$args{"cgi.$cgi_id.OBJTYPE"}.='FILL:';
    }
    return $result;
}

sub end_arc {
    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    my $result;
    return $result;
}


1;
__END__