[LON-CAPA-cvs] cvs: loncom /homework drawimage.pm randomlylabel.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 16 Mar 2004 23:08:23 -0000


albertel		Tue Mar 16 18:08:23 2004 EDT

  Modified files:              
    /loncom/homework	drawimage.pm randomlylabel.pm 
  Log:
  - added font support (I can't get ttf to work)
  - added direction support
  
  
Index: loncom/homework/drawimage.pm
diff -u loncom/homework/drawimage.pm:1.4 loncom/homework/drawimage.pm:1.5
--- loncom/homework/drawimage.pm:1.4	Tue Mar 16 17:27:37 2004
+++ loncom/homework/drawimage.pm	Tue Mar 16 18:08:23 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # programatic image drawing
 #
-# $Id: drawimage.pm,v 1.4 2004/03/16 22:27:37 matthew Exp $
+# $Id: drawimage.pm,v 1.5 2004/03/16 23:08:23 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,7 +38,7 @@
 
 sub start_drawimage {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
-    &Apache::lonxml::register('Apache::drawimage',('textlabel','line','rectangle','arc','fill'));
+    &Apache::lonxml::register('Apache::drawimage',('text','line','rectangle','arc','fill'));
     if ($target eq 'web' || $target eq 'tex') {
 	$cgi_id=&Apache::loncommon::get_cgi_id();
 	%args=();
@@ -72,7 +72,7 @@
     return $result;
 }
 
-sub start_textlabel {
+sub start_text {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;
     if ($target eq 'web' || $target eq 'tex') {
@@ -80,16 +80,17 @@
         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 $text  = &Apache::lonxml::get_all_text("/textlabel",$parser);
+        my $direction = &Apache::lonxml::get_param('direction',$parstack,$safeeval);
+	my $text  = &Apache::lonxml::get_all_text("/text",$parser);
         $text = &Apache::lonnet::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));
+	$args{"cgi.$cgi_id.OBJ$i"}=join(':',($x,$y,$text,$font,$color,$direction));
     }
     return $result;
 }
 
-sub end_textlabel {
+sub end_text {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;
     return $result;
Index: loncom/homework/randomlylabel.pm
diff -u loncom/homework/randomlylabel.pm:1.18 loncom/homework/randomlylabel.pm:1.19
--- loncom/homework/randomlylabel.pm:1.18	Mon Feb 23 18:54:14 2004
+++ loncom/homework/randomlylabel.pm	Tue Mar 16 18:08:23 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # randomlabel.png: composite together text and images into 1 image
 #
-# $Id: randomlylabel.pm,v 1.18 2004/02/23 23:54:14 albertel Exp $
+# $Id: randomlylabel.pm,v 1.19 2004/03/16 23:08:23 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -201,11 +201,38 @@
 	    }
 	    $image->copy($subimage,$x,$y,0,0,$subimage->getBounds());
 	} elsif ($type eq 'LABEL') {
-	    my ($x,$y,$text,$font,$color)=split(':',$ENV{"cgi.$id.OBJ$i"});
+	    my ($x,$y,$text,$font,$color,$direction)=
+		split(':',$ENV{"cgi.$id.OBJ$i"});
 	    $text=&Apache::lonnet::unescape($text);
 	    my $imcolor=&get_color_from_hexstring($image,$color);
-	    my $height=GD::Font->Giant->height;
-	    $image->string(GD::gdGiantFont,$x,$y-$height,$text,$imcolor);
+	    my $type='normal';
+	    my ($height,$fontref);
+	    if ($font eq 'tiny') {
+		$height=GD::Font->Tiny->height;
+		$fontref=GD::gdTinyFont;
+	    } elsif ($font eq 'small') {
+		$height=GD::Font->Small->height;
+		$fontref=GD::gdSmallFont;
+	    } elsif ($font eq 'medium') {
+		$height=GD::Font->MediumBold->height;
+		$fontref=GD::gdMediumBoldFont;
+	    } elsif ($font eq 'large') {
+		$height=GD::Font->Large->height;
+		$fontref=GD::gdLargeFont;
+	    } elsif ($font eq 'giant' || !defined($font)) {
+		$height=GD::Font->Giant->height;
+		$fontref=GD::gdGiantFont;
+	    } else {
+		$type='ttf';
+	    }
+	    if ($type eq 'normal' && $direction eq 'vertical') {
+		$image->stringUp($fontref,$x,$y-$height,$text,$imcolor);
+	    } elsif ($type eq 'normal') {
+		$image->string($fontref,$x,$y-$height,$text,$imcolor);
+	    } elsif ($type eq 'ttf') {
+		my ($fontname,$ptsize)=split(/\s+/,$font);
+		$image->stringFT($imcolor,$fontname,$ptsize,90,$x,$y,$text);
+	    }
 	} else {
 	    &Apache::lonnet::logthis("randomlylabel unable to handle object of type $type");
 	}