File:
[LON-CAPA] /
loncom /
homework /
drawimage.pm
Revision
1.6:
download - view:
text,
annotated -
select for diffs
Tue Mar 23 20:38:09 2004 UTC (20 years, 4 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_1_2_X,
version_1_2_1,
version_1_2_0,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
version_1_1_99_0,
HEAD
- use redirection in <text> so contents get parsed.
1: # The LearningOnline Network with CAPA
2: # programatic image drawing
3: #
4: # $Id: drawimage.pm,v 1.6 2004/03/23 20:38:09 albertel Exp $
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',('text','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_text {
76: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
77: my $result;
78: if ($target eq 'web' || $target eq 'tex') {
79: &Apache::lonxml::startredirection();
80: }
81: return $result;
82: }
83:
84: sub end_text {
85: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
86: my $result;
87: if ($target eq 'web' || $target eq 'tex') {
88: my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
89: my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
90: my $font = &Apache::lonxml::get_param('font',$parstack,$safeeval);
91: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
92: my $direction = &Apache::lonxml::get_param('direction',$parstack,$safeeval);
93: my $text = &Apache::lonxml::endredirection();
94: $text = &Apache::lonnet::escape($text);
95: $args{"cgi.$cgi_id.OBJTYPE"}.='LABEL:';
96: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
97: $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$text,$font,$color,$direction));
98: }
99: return $result;
100: }
101:
102: sub start_line {
103: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
104: my $result;
105: if ($target eq 'web' || $target eq 'tex') {
106: my $x1 = &Apache::lonxml::get_param('x1',$parstack,$safeeval);
107: my $y1 = &Apache::lonxml::get_param('y1',$parstack,$safeeval);
108: my $x2 = &Apache::lonxml::get_param('x2',$parstack,$safeeval);
109: my $y2 = &Apache::lonxml::get_param('y2',$parstack,$safeeval);
110: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
111: my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);
112: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
113: $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x1,$y1,$x2,$y2,$color,$thickness));
114: $args{"cgi.$cgi_id.OBJTYPE"}.='LINE:';
115: }
116: return $result;
117: }
118:
119: sub end_line {
120: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
121: my $result;
122: return $result;
123: }
124:
125: sub start_rectangle {
126: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
127: my $result;
128: if ($target eq 'web' || $target eq 'tex') {
129: my $x1 = &Apache::lonxml::get_param('x1',$parstack,$safeeval);
130: my $y1 = &Apache::lonxml::get_param('y1',$parstack,$safeeval);
131: my $x2 = &Apache::lonxml::get_param('x2',$parstack,$safeeval);
132: my $y2 = &Apache::lonxml::get_param('y2',$parstack,$safeeval);
133: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
134: my $thickness = &Apache::lonxml::get_param('thickness',$parstack,
135: $safeeval);
136: my $filled = &Apache::lonxml::get_param('filled',$parstack,
137: $safeeval);
138: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
139: $args{"cgi.$cgi_id.OBJ$i"}=
140: join(':',($x1,$y1,$x2,$y2,$color,$thickness,$filled));
141: $args{"cgi.$cgi_id.OBJTYPE"}.='RECTANGLE:';
142: }
143: return $result;
144: }
145:
146: sub end_rectangle {
147: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
148: my $result;
149: return $result;
150: }
151:
152: sub start_arc {
153: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
154: my $result;
155: if ($target eq 'web' || $target eq 'tex') {
156: my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
157: my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
158: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
159: my $height = &Apache::lonxml::get_param('height',$parstack,$safeeval);
160: my $start = &Apache::lonxml::get_param('start',$parstack,$safeeval);
161: my $end = &Apache::lonxml::get_param('end',$parstack,$safeeval);
162: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
163: my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);
164: my $filled = &Apache::lonxml::get_param('filled',$parstack,$safeeval);
165: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
166: $args{"cgi.$cgi_id.OBJ$i"}=
167: join(':',($x,$y,$width,$height,$start,$end,$color,$thickness,
168: $filled));
169: $args{"cgi.$cgi_id.OBJTYPE"}.='ARC:';
170: }
171: return $result;
172: }
173:
174: sub end_arc {
175: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
176: my $result;
177: return $result;
178: }
179:
180: sub start_fill {
181: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
182: my $result;
183: if ($target eq 'web' || $target eq 'tex') {
184: my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
185: my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
186: my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
187: my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
188: $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$color));
189: $args{"cgi.$cgi_id.OBJTYPE"}.='FILL:';
190: }
191: return $result;
192: }
193:
194: sub end_fill {
195: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
196: my $result;
197: return $result;
198: }
199:
200:
201: 1;
202: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>