Diff for /loncom/homework/drawimage.pm between versions 1.1 and 1.9

version 1.1, 2003/11/15 06:33:39 version 1.9, 2006/05/30 12:45:36
Line 29 Line 29
 package Apache::drawimage;  package Apache::drawimage;
 use strict;  use strict;
 use Apache::loncommon;  use Apache::loncommon;
   use lib '/home/httpd/lib/perl/';
   use LONCAPA;
    
   
 my %args;  my %args;
 my $cgi_id;  my $cgi_id;
   my @cgi_ids;
 BEGIN {  BEGIN {
     &Apache::lonxml::register('Apache::drawimage',('drawimage'));      &Apache::lonxml::register('Apache::drawimage',('drawimage'));
 }  }
   
 sub start_drawimage {  sub start_drawimage {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     &Apache::lonxml::register('Apache::drawimage',('line','rectangle','arc','fill'));      &Apache::lonxml::register('Apache::drawimage',('text','line','rectangle','arc','fill','polygon','image'));
     if ($target eq 'web' || $target eq 'tex') {      if ($target eq 'web' || $target eq 'tex') {
  $cgi_id=&Apache::loncommon::get_cgi_id();   my $new_id=&Apache::loncommon::get_cgi_id();
  %args=();   if ($cgi_id) { push(@cgi_ids,$cgi_id); } else { undef(%args); }
    $cgi_id=$new_id;
     }      }
       return '';
 }  }
   
 sub end_drawimage {  sub end_drawimage {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;      my $result;
     if ($target eq 'web' || $target eq 'tex') {      if ($target eq 'web' || $target eq 'tex') {
  if ($target eq 'web') {   my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
     my $width =    my $height =&Apache::lonxml::get_param('height',$parstack,$safeeval);
  &Apache::lonxml::get_param('width',$parstack,$safeeval);   my $bgcolor =&Apache::lonxml::get_param('bgcolor',$parstack,$safeeval);
     my $height =   if (!$width) { $width=300; }
  &Apache::lonxml::get_param('height',$parstack,$safeeval);   if (!$height) { $height=300; }
     my $bgcolor =   $result.="<img width='$width' height='$height'
  &Apache::lonxml::get_param('bgcolor',$parstack,$safeeval);  
     if (!$width) { $width=300; }  
     if (!$height) { $height=300; }  
     $result.="<img width='$width' height='$height'  
                            src='/adm/randomlabel.png?token=$cgi_id' />\n";                             src='/adm/randomlabel.png?token=$cgi_id' />\n";
     $args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height));   $args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height));
     $args{"cgi.$cgi_id.BGCOLOR"}=join(':',($bgcolor));   $args{"cgi.$cgi_id.BGCOLOR"}=join(':',($bgcolor));
     &Apache::lonnet::appenv(%args);   &Apache::lonnet::appenv(%args);
  } elsif ($target eq 'tex') {   if (@cgi_ids) {
     #FIXME generate image some how      $cgi_id=pop(@cgi_ids);
     #probably Simple::PostScript   } else {
       undef($cgi_id);
  }   }
       } elsif ($target eq 'edit') {
       } elsif ($target eq 'modified') {
       }
       
       &Apache::lonxml::register('Apache::drawimage',
         ('text','line','rectangle','arc','fill',
          'polygon'));
       return $result;
   }
   
   sub start_text {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       my $result;
       if ($target eq 'web' || $target eq 'tex') {
    &Apache::lonxml::startredirection();
       }
       return $result;
   }
   
   sub end_text {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       my $result;
       if ($target eq 'web' || $target eq 'tex') {
           my $x     = &Apache::lonxml::get_param('x',$parstack,$safeeval);
           my $y     = &Apache::lonxml::get_param('y',$parstack,$safeeval);
           my $font  = &Apache::lonxml::get_param('font',$parstack,$safeeval);
           my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
           my $direction = &Apache::lonxml::get_param('direction',$parstack,$safeeval);
    my $text  = &Apache::lonxml::endredirection();
           $text = &escape($text);
           $args{"cgi.$cgi_id.OBJTYPE"}.='LABEL:';
    my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
    $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$text,$font,$color,$direction));
     }      }
     &Apache::lonxml::deregister('Apache::drawimage',('line','rectangle'));  
     return $result;      return $result;
 }  }
   
Line 82  sub start_line { Line 117  sub start_line {
  my $y2 = &Apache::lonxml::get_param('y2',$parstack,$safeeval);   my $y2 = &Apache::lonxml::get_param('y2',$parstack,$safeeval);
  my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);   my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
  my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);   my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);
  my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;   my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
  $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x1,$y1,$x2,$y2,$color,$thickness));   $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x1,$y1,$x2,$y2,$color,$thickness));
  $args{"cgi.$cgi_id.OBJTYPE"}.='LINE:';   $args{"cgi.$cgi_id.OBJTYPE"}.='LINE:';
     }      }
Line 108  sub start_rectangle { Line 143  sub start_rectangle {
    $safeeval);     $safeeval);
  my $filled = &Apache::lonxml::get_param('filled',$parstack,   my $filled = &Apache::lonxml::get_param('filled',$parstack,
  $safeeval);   $safeeval);
  my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;   my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
  $args{"cgi.$cgi_id.OBJ$i"}=   $args{"cgi.$cgi_id.OBJ$i"}=
     join(':',($x1,$y1,$x2,$y2,$color,$thickness,$filled));      join(':',($x1,$y1,$x2,$y2,$color,$thickness,$filled));
  $args{"cgi.$cgi_id.OBJTYPE"}.='RECTANGLE:';   $args{"cgi.$cgi_id.OBJTYPE"}.='RECTANGLE:';
Line 135  sub start_arc { Line 170  sub start_arc {
  my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);   my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
  my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);   my $thickness = &Apache::lonxml::get_param('thickness',$parstack,$safeeval);
  my $filled = &Apache::lonxml::get_param('filled',$parstack,$safeeval);   my $filled = &Apache::lonxml::get_param('filled',$parstack,$safeeval);
  my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;   my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
  $args{"cgi.$cgi_id.OBJ$i"}=   $args{"cgi.$cgi_id.OBJ$i"}=
     join(':',($x,$y,$width,$height,$start,$end,$color,$thickness,      join(':',($x,$y,$width,$height,$start,$end,$color,$thickness,
       $filled));        $filled));
Line 150  sub end_arc { Line 185  sub end_arc {
     return $result;      return $result;
 }  }
   
 sub start_arc {  sub start_fill {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;      my $result;
     if ($target eq 'web' || $target eq 'tex') {      if ($target eq 'web' || $target eq 'tex') {
  my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);   my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
  my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);   my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
  my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);   my $color = &Apache::lonxml::get_param('color',$parstack,$safeeval);
  my $i=(++$args{"cgi.$cgi_id.OBJCOUNT"})-1;   my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
  $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$color));   $args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$color));
  $args{"cgi.$cgi_id.OBJTYPE"}.='FILL:';   $args{"cgi.$cgi_id.OBJTYPE"}.='FILL:';
     }      }
     return $result;      return $result;
 }  }
   
 sub end_arc {  sub end_fill {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;      my $result;
     return $result;      return $result;
 }  }
   
   my @polygon;
   sub start_polygon {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       my $result;
       &Apache::lonxml::register('Apache::drawimage',('point'));
       if ($target eq 'web') {
    undef(@polygon);
       }
       return $result;
   }
   
   sub end_polygon {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       my $result;    
       if ($target eq 'web') {
    my $color=&Apache::lonxml::get_param('color',$parstack,$safeeval);
    my $filled=&Apache::lonxml::get_param('filled',$parstack,$safeeval);
    my $open=&Apache::lonxml::get_param('open',$parstack,$safeeval);
    my $thickness = &Apache::lonxml::get_param('thickness',$parstack,
      $safeeval);
    my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
    $args{"cgi.$cgi_id.OBJTYPE"}.='POLYGON:';
    $args{"cgi.$cgi_id.OBJ$i"}=join(':',($color,$thickness,$open,$filled));
    $args{"cgi.$cgi_id.OBJEXTRA$i"}=join('-',@polygon);
       }
       &Apache::lonxml::deregister('Apache::drawimage',('point'));
       return $result;
   }
   
   sub start_point {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       my $result;
       if ($target eq 'web') {
    my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
           my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
    push (@polygon,"($x,$y)");
       }
       return $result;
   }
   
   sub end_point {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       my $result;
       return $result;
   }
   
   sub start_image {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       my $result;
       if ($target eq 'web' || $target eq 'tex') {
    &Apache::lonxml::startredirection();
       }
       return $result;
   }
   
   sub end_image {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       my $result;
       if ($target eq 'web' || $target eq 'tex') {
    my $bgimg=&Apache::lonxml::endredirection();
    my $x = &Apache::lonxml::get_param('x',$parstack,$safeeval);
           my $y = &Apache::lonxml::get_param('y',$parstack,$safeeval);
    my $clipx = &Apache::lonxml::get_param('clipx',$parstack,$safeeval);
           my $clipy = &Apache::lonxml::get_param('clipy',$parstack,$safeeval);
    my $clipwidth = 
       &Apache::lonxml::get_param('clipwidth',$parstack,$safeeval);
           my $clipheight = 
       &Apache::lonxml::get_param('clipheight',$parstack,$safeeval);
    my $scaledwidth = 
       &Apache::lonxml::get_param('scaledwidth',$parstack,$safeeval);
           my $scaledheight = 
       &Apache::lonxml::get_param('scaledheight',$parstack,$safeeval);
    my $transparent = 
       &Apache::lonxml::get_param('transparent',$parstack,$safeeval);
    $bgimg=&Apache::imageresponse::clean_up_image($bgimg);
    my $i=$args{"cgi.$cgi_id.OBJCOUNT"}++;
    $args{"cgi.$cgi_id.OBJTYPE"}.='IMAGE:';
    $args{"cgi.$cgi_id.OBJ$i"} = 
       join(':',($x,$y,&escape($bgimg),$transparent,
         $clipx,$clipy,$scaledwidth,$scaledheight,$clipwidth,$clipheight));
       }
       return $result;
   }
 1;  1;
 __END__  __END__

Removed from v.1.1  
changed lines
  Added in v.1.9


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>