[LON-CAPA-cvs] cvs: modules /damieng/graphical_editor/loncapa_daxe/web/config loncapa.xsd loncom/homework drawimage.pm randomlylabel.pm
raeburn
raeburn at source.lon-capa.org
Fri Apr 5 00:05:09 EDT 2024
raeburn Fri Apr 5 04:05:09 2024 EDT
Modified files:
/loncom/homework drawimage.pm randomlylabel.pm
/modules/damieng/graphical_editor/loncapa_daxe/web/config
loncapa.xsd
Log:
- drawimage tag supported for tex target, and texwidth attribute (units: mm)
added (default value: 90).
Index: loncom/homework/drawimage.pm
diff -u loncom/homework/drawimage.pm:1.11 loncom/homework/drawimage.pm:1.12
--- loncom/homework/drawimage.pm:1.11 Fri Apr 5 02:31:23 2024
+++ loncom/homework/drawimage.pm Fri Apr 5 04:05:08 2024
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# programatic image drawing
#
-# $Id: drawimage.pm,v 1.11 2024/04/05 02:31:23 raeburn Exp $
+# $Id: drawimage.pm,v 1.12 2024/04/05 04:05:08 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -29,7 +29,10 @@
package Apache::drawimage;
use strict;
use Apache::loncommon;
+use Apache::lonnet;
+use Apache::lonxml;
use lib '/home/httpd/lib/perl/';
+use Time::HiRes qw(gettimeofday);
use LONCAPA;
@@ -54,16 +57,42 @@
sub end_drawimage {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
+ # need to call rand everytime start_script would evaluate, as the
+ # safe space rand number generator and the global rand generator
+ # are not separate
+ my $randnumber;
+ if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
+ $target eq 'answer') {
+ $randnumber=int(rand(1000));
+ }
if ($target eq 'web' || $target eq 'tex') {
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'
+ $args{"cgi.$cgi_id.BGCOLOR"}=join(':',($bgcolor));
+ if ($target eq 'tex') {
+ my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1);
+ if (!$texwidth) { $texwidth='90'; }
+ $args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height,$texwidth));
+ my $tmpdir = LONCAPA::tempdir(); # Where temporary files live:
+ ## Determine filename
+ my ($seconds, $microseconds) = gettimeofday;
+ my $filename = $env{'user.name'}.'_'.$env{'user.domain'}.
+ '_'.$seconds.'_'.$microseconds.'_'.$$.$randnumber.'_drawimage.eps';
+ $args{"cgi.$cgi_id.EPSFILE"} = $env{'user.name'}.'_'.$env{'user.domain'}.
+ '_'.$seconds.'_'.$microseconds.'_'.$$.$randnumber.
+ '_drawimage.eps';
+ $result = "%DYNAMICIMAGE:$width:$height:$texwidth\n";
+ $result .= '\graphicspath{{'.$tmpdir.'}}'."\n";
+ $result .= '\includegraphics[width='.$texwidth.' mm]{'.$filename.'}';
+ &Apache::lonxml::register_ssi('/adm/randomlabel.png?token='.$cgi_id);
+ } else {
+ $args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height));
+ $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);
if (@cgi_ids) {
$cgi_id=pop(@cgi_ids);
Index: loncom/homework/randomlylabel.pm
diff -u loncom/homework/randomlylabel.pm:1.35 loncom/homework/randomlylabel.pm:1.36
--- loncom/homework/randomlylabel.pm:1.35 Fri Apr 5 02:43:25 2024
+++ loncom/homework/randomlylabel.pm Fri Apr 5 04:05:08 2024
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# randomlabel.png: composite together text and images into 1 image
#
-# $Id: randomlylabel.pm,v 1.35 2024/04/05 02:43:25 raeburn Exp $
+# $Id: randomlylabel.pm,v 1.36 2024/04/05 04:05:08 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -302,8 +302,6 @@
sub handler {
my $r = shift;
- $r->content_type('image/png');
- $r->send_http_header;
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
@@ -313,6 +311,22 @@
} else {
$prefix="cgi.$env{'form.token'}.";
}
+ my $epsfile;
+ if (defined($env{$prefix."EPSFILE"})) {
+ my $user = $env{'user.name'}.'_'.$env{'user.domain'};
+ if ($env{$prefix."EPSFILE"} =~ /^\Q$user\E_\d+_\d+_\d+_drawimage\.eps$/) {
+ $epsfile = $Apache::lonnet::perlvar{'lonPrtDir'}.'/'.$env{$prefix."EPSFILE"};
+ } else {
+ &Apache::lonnet::logthis('Unable to create eps file for image object for -'.
+ $env{'form.token'}.'- for '.$user.' as EPSFILE has '.
+ 'unexpected value');
+ return OK;
+ }
+ }
+ unless ($epsfile) {
+ $r->content_type('image/png');
+ $r->send_http_header;
+ }
my $image;
if (defined($env{$prefix."BGIMG"})) {
@@ -472,7 +486,16 @@
}
if (exists($env{'form.clickdata'})) { &add_click($image); }
$image->setThickness(1);
- $r->print($image->png);
+ if ($epsfile) {
+ if (open(my $pipe, "| convert png:- $epsfile")) {
+ print $pipe $image->png;
+ close($pipe);
+ } else {
+ &Apache::lonnet::logthis("randomlylabel unable to open pipe to convert png to eps");
+ }
+ } else {
+ $r->print($image->png);
+ }
return OK;
}
Index: modules/damieng/graphical_editor/loncapa_daxe/web/config/loncapa.xsd
diff -u modules/damieng/graphical_editor/loncapa_daxe/web/config/loncapa.xsd:1.28 modules/damieng/graphical_editor/loncapa_daxe/web/config/loncapa.xsd:1.29
--- modules/damieng/graphical_editor/loncapa_daxe/web/config/loncapa.xsd:1.28 Fri Apr 5 02:31:23 2024
+++ modules/damieng/graphical_editor/loncapa_daxe/web/config/loncapa.xsd Fri Apr 5 04:05:09 2024
@@ -5354,6 +5354,7 @@
</xs:choice>
<xs:attribute name="width" type="int-or-perl" default="300"/>
<xs:attribute name="height" type="int-or-perl" default="300"/>
+ <xs:attribute name="texwidth" type="decimal-or-perl" default="90"/>
<xs:attribute name="bgcolor" type="xs:string"/>
</xs:complexType>
</xs:element>
More information about the LON-CAPA-cvs
mailing list