--- loncom/homework/imageresponse.pm 2005/04/07 06:56:21 1.65 +++ loncom/homework/imageresponse.pm 2005/06/22 12:03:23 1.72 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # image click response style # -# $Id: imageresponse.pm,v 1.65 2005/04/07 06:56:21 albertel Exp $ +# $Id: imageresponse.pm,v 1.72 2005/06/22 12:03:23 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -228,6 +228,7 @@ sub clean_up_image { } } else { $image=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$image); + &Apache::lonxml::debug("repcopying: $image"); if (&Apache::lonnet::repcopy($image) ne 'ok') { $image='/home/httpd/html/adm/lonKaputt/lonlogo_broken.gif'; } @@ -342,11 +343,12 @@ sub insert_foil { $Apache::imageresponse::curname=''; sub start_foil { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $result; if ($target eq 'web' || $target eq 'grade' || $target eq 'tex' || $target eq 'analyze') { my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); - if (!$name) { - &Apache::lonxml::error("Foils without names exist. This can cause problems to malfunction."); + if ($name eq "") { + &Apache::lonxml::warning("Foils without names exist. This can cause problems to malfunction."); $name=$Apache::lonxml::curdepth; } if (defined($Apache::response::foilnames{$name})) { @@ -361,8 +363,17 @@ sub start_foil { push(@{ $Apache::response::foilgroup{'names'} }, $name); } $Apache::imageresponse::curname=$name; - } - return ''; + } elsif ($target eq 'edit') { + $result = &Apache::edit::tag_start($target,$token); + $result .= &Apache::edit::text_arg('Name:','name',$token); + $result .= &Apache::edit::end_row(). + &Apache::edit::start_spanning_row(); + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack, + $safeeval,'name'); + if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } + } + return $result;; } sub end_foil { @@ -456,10 +467,30 @@ sub end_image { $result=&Apache::edit::end_table(); } elsif ($target eq 'tex') { my $src = &Apache::lonxml::endredirection(); - my ($path,$file) = &Apache::londefdef::get_eps_image($src); - my ($height_param,$width_param)= - &Apache::londefdef::image_size($src,0.3,$parstack,$safeeval); - $Apache::response::foilgroup{"$name.image"} ='\vskip 0 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; + + # There may be all sorts of whitespace on fore and aft: + + $src =~ s/\s+$//s; + $src =~ s/^\s+//s; + + # + # Gnuplot e.g. just generates the latex to put inplace. + # + my $graphinclude; + if ($src =~ /^%DYNAMICIMAGE/) { + # This is needed because the newline is not always passed -> tex. + # At present we don't care about the sizing info. + + my ($commentline, $restofstuff) = split(/\n/, $src); + $graphinclude = $src; + $graphinclude =~ s/^$commentline//; + } else { + my ($path,$file) = &Apache::londefdef::get_eps_image($src); + my ($height_param,$width_param)= + &Apache::londefdef::image_size($src,0.3,$parstack,$safeeval); + $graphinclude = '\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'}'; + } + $Apache::response::foilgroup{"$name.image"} ='\vskip 0 mm \noindent '.$graphinclude; } return $result; }