Annotation of loncom/homework/drawimage.pm, revision 1.2
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # programatic image drawing
3: #
1.2 ! albertel 4: # $Id: drawimage.pm,v 1.1 2003/11/15 06:33:39 albertel Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::drawimage;
30: use strict;
31: use Apache::loncommon;
32:
33: my %args;
34: my $cgi_id;
35: BEGIN {
36: &Apache::lonxml::register('Apache::drawimage',('drawimage'));
37: }
38:
39: sub start_drawimage {
40: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
41: &Apache::lonxml::register('Apache::drawimage',('line','rectangle','arc','fill'));
42: if ($target eq 'web' || $target eq 'tex') {
43: $cgi_id=&Apache::loncommon::get_cgi_id();
44: %args=();
45: }
46: }
47:
48: sub end_drawimage {
49: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
50: my $result;
51: if ($target eq 'web' || $target eq 'tex') {
52: if ($target eq 'web') {
53: my $width =
54: &Apache::lonxml::get_param('width',$parstack,$safeeval);
55: my $height =
56: &Apache::lonxml::get_param('height',$parstack,$safeeval);
57: my $bgcolor =
58: &Apache::lonxml::get_param('bgcolor',$parstack,$safeeval);
59: if (!$width) { $width=300; }
60: if (!$height) { $height=300; }
61: $result.="<img width='$width' height='$height'
62: src='/adm/randomlabel.png?token=$cgi_id' />\n";
63: $args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height));
64: $args{"cgi.$cgi_id.BGCOLOR"}=join(':',($bgcolor));
65: &Apache::lonnet::appenv(%args);
66: } elsif ($target eq 'tex') {
67: #FIXME generate image some how
68: #probably Simple::PostScript
69: }
70: }
71: &Apache::lonxml::deregister('Apache::drawimage',('line','rectangle'));
72: return $result;
73: }
74:
75: sub start_line {
76: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
77: my $result;
78: if ($target eq 'web' || $target eq 'tex') {
79: my $x1 = &Apache::lonxml::get_param('x1',$parstack,$safeeval);
80: my $y1 = &Apache::lonxml::get_param('y1',$parstack,$safeeval);
81: my $x2 = &Apache::lonxml::get_param('x2',$parstack,$safeeval);
82: my $y2 = &Apache::lonxml::get_param('y2',$parstack,$safeeval);
83: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
84: my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);
85: my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;
86: $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x1,$y1,$x2,$y2,$color,$thickness));
87: $args{"cgi.$cgi_id.OBJTYPE"}.='LINE:';
88: }
89: return $result;
90: }
91:
92: sub end_line {
93: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
94: my $result;
95: return $result;
96: }
97:
98: sub start_rectangle {
99: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
100: my $result;
101: if ($target eq 'web' || $target eq 'tex') {
102: my $x1 = &Apache::lonxml::get_param('x1',$parstack,$safeeval);
103: my $y1 = &Apache::lonxml::get_param('y1',$parstack,$safeeval);
104: my $x2 = &Apache::lonxml::get_param('x2',$parstack,$safeeval);
105: my $y2 = &Apache::lonxml::get_param('y2',$parstack,$safeeval);
106: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
107: my $thickness = &Apache::lonxml::get_param('thickness',$parstack,
108: $safeeval);
109: my $filled = &Apache::lonxml::get_param('filled',$parstack,
110: $safeeval);
111: my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;
112: $args{"cgi.$cgi_id.OBJ$i"}=
113: join(':',($x1,$y1,$x2,$y2,$color,$thickness,$filled));
114: $args{"cgi.$cgi_id.OBJTYPE"}.='RECTANGLE:';
115: }
116: return $result;
117: }
118:
119: sub end_rectangle {
120: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
121: my $result;
122: return $result;
123: }
124:
125: sub start_arc {
126: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
127: my $result;
128: if ($target eq 'web' || $target eq 'tex') {
129: my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
130: my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
131: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
132: my $height = &Apache::lonxml::get_param('height',$parstack,$safeeval);
133: my $start = &Apache::lonxml::get_param('start',$parstack,$safeeval);
134: my $end = &Apache::lonxml::get_param('end',$parstack,$safeeval);
135: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
136: my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);
137: my $filled = &Apache::lonxml::get_param('filled',$parstack,$safeeval);
138: my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;
139: $args{"cgi.$cgi_id.OBJ$i"}=
140: join(':',($x,$y,$width,$height,$start,$end,$color,$thickness,
141: $filled));
142: $args{"cgi.$cgi_id.OBJTYPE"}.='ARC:';
143: }
144: return $result;
145: }
146:
147: sub end_arc {
148: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
149: my $result;
150: return $result;
151: }
152:
1.2 ! albertel 153: sub start_fill {
1.1 albertel 154: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
155: my $result;
156: if ($target eq 'web' || $target eq 'tex') {
157: my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
158: my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
159: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
160: my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;
161: $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$color));
162: $args{"cgi.$cgi_id.OBJTYPE"}.='FILL:';
163: }
164: return $result;
165: }
166:
1.2 ! albertel 167: sub end_fill {
1.1 albertel 168: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
169: my $result;
170: return $result;
171: }
172:
173:
174: 1;
175: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>