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