Annotation of loncom/homework/drawimage.pm, revision 1.4
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # programatic image drawing
3: #
1.4 ! matthew 4: # $Id: drawimage.pm,v 1.3 2004/02/24 00:16:35 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)=@_;
1.4 ! matthew 41: &Apache::lonxml::register('Apache::drawimage',('textlabel','line','rectangle','arc','fill'));
1.1 albertel 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'));
1.4 ! matthew 72: return $result;
! 73: }
! 74:
! 75: sub start_textlabel {
! 76: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 77: my $result;
! 78: if ($target eq 'web' || $target eq 'tex') {
! 79: my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
! 80: my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
! 81: my $font = &Apache::lonxml::get_param('font',$parstack,$safeeval);
! 82: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
! 83: my $text = &Apache::lonxml::get_all_text("/textlabel",$parser);
! 84: $text = &Apache::lonnet::escape($text);
! 85: $args{"cgi.$cgi_id.OBJTYPE"}.='LABEL:';
! 86: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
! 87: $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$text,$font,$color));
! 88: }
! 89: return $result;
! 90: }
! 91:
! 92: sub end_textlabel {
! 93: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
! 94: my $result;
1.1 albertel 95: return $result;
96: }
97:
98: sub start_line {
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,$safeeval);
1.3 albertel 108: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
1.1 albertel 109: $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x1,$y1,$x2,$y2,$color,$thickness));
110: $args{"cgi.$cgi_id.OBJTYPE"}.='LINE:';
111: }
112: return $result;
113: }
114:
115: sub end_line {
116: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
117: my $result;
118: return $result;
119: }
120:
121: sub start_rectangle {
122: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
123: my $result;
124: if ($target eq 'web' || $target eq 'tex') {
125: my $x1 = &Apache::lonxml::get_param('x1',$parstack,$safeeval);
126: my $y1 = &Apache::lonxml::get_param('y1',$parstack,$safeeval);
127: my $x2 = &Apache::lonxml::get_param('x2',$parstack,$safeeval);
128: my $y2 = &Apache::lonxml::get_param('y2',$parstack,$safeeval);
129: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
130: my $thickness = &Apache::lonxml::get_param('thickness',$parstack,
131: $safeeval);
132: my $filled = &Apache::lonxml::get_param('filled',$parstack,
133: $safeeval);
1.3 albertel 134: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
1.1 albertel 135: $args{"cgi.$cgi_id.OBJ$i"}=
136: join(':',($x1,$y1,$x2,$y2,$color,$thickness,$filled));
137: $args{"cgi.$cgi_id.OBJTYPE"}.='RECTANGLE:';
138: }
139: return $result;
140: }
141:
142: sub end_rectangle {
143: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
144: my $result;
145: return $result;
146: }
147:
148: sub start_arc {
149: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
150: my $result;
151: if ($target eq 'web' || $target eq 'tex') {
152: my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
153: my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
154: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
155: my $height = &Apache::lonxml::get_param('height',$parstack,$safeeval);
156: my $start = &Apache::lonxml::get_param('start',$parstack,$safeeval);
157: my $end = &Apache::lonxml::get_param('end',$parstack,$safeeval);
158: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
159: my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);
160: my $filled = &Apache::lonxml::get_param('filled',$parstack,$safeeval);
1.3 albertel 161: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
1.1 albertel 162: $args{"cgi.$cgi_id.OBJ$i"}=
163: join(':',($x,$y,$width,$height,$start,$end,$color,$thickness,
164: $filled));
165: $args{"cgi.$cgi_id.OBJTYPE"}.='ARC:';
166: }
167: return $result;
168: }
169:
170: sub end_arc {
171: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
172: my $result;
173: return $result;
174: }
175:
1.2 albertel 176: sub start_fill {
1.1 albertel 177: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
178: my $result;
179: if ($target eq 'web' || $target eq 'tex') {
180: my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
181: my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
182: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
1.3 albertel 183: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
1.1 albertel 184: $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$color));
185: $args{"cgi.$cgi_id.OBJTYPE"}.='FILL:';
186: }
187: return $result;
188: }
189:
1.2 albertel 190: sub end_fill {
1.1 albertel 191: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
192: my $result;
193: return $result;
194: }
195:
196:
197: 1;
198: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>