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

sakharuk lon-capa-cvs@mail.lon-capa.org
Thu, 25 Sep 2003 14:05:44 -0000


sakharuk		Thu Sep 25 10:05:44 2003 EDT

  Modified files:              
    /loncom/homework	randomlabel.pm 
  Log:
  Bug 2221 (click on image problems don't properly scale image) is fixed. Additional cleanup is done too.
  
  
Index: loncom/homework/randomlabel.pm
diff -u loncom/homework/randomlabel.pm:1.49 loncom/homework/randomlabel.pm:1.50
--- loncom/homework/randomlabel.pm:1.49	Tue Sep 23 17:20:42 2003
+++ loncom/homework/randomlabel.pm	Thu Sep 25 10:05:44 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # random labelling tool
 #
-# $Id: randomlabel.pm,v 1.49 2003/09/23 21:20:42 albertel Exp $
+# $Id: randomlabel.pm,v 1.50 2003/09/25 14:05:44 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -92,7 +92,7 @@
     }
     my $w= &check_int(&Apache::lonxml::get_param('width',$parstack,$safeeval));
     my $h= &check_int(&Apache::lonxml::get_param('height',$parstack,$safeeval));
-    my $texwidth= &Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1);
+    my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1));
     if (!$texwidth) { $texwidth=90; }
     $Apache::randomlabel::tlabel_cnt=0;
     $Apache::randomlabel::ilabel_cnt=0;
@@ -127,13 +127,9 @@
 	}
 	$bgimg=~s/\/$//;
 	my $dirtywidth=$texwidth+5;
-	if ($texwidth==90) {
-	    $result.='\vspace*{2mm}\noindent \parbox{'.$dirtywidth.' mm}{  \noindent \epsfxsize='.$texwidth.' mm \epsffile{'.
-		$bgimg.'}\setlength{\unitlength}{1mm}  \begin{picture}('.$texwidth.','.$texwidth*$h/$w.')(0,-'.$texwidth*$h/$w.')';
-	} else {
-	    $result.='\vspace*{2mm}\noindent \parbox{'.$dirtywidth.' mm}{  \noindent \epsfxsize='.$texwidth.' mm \epsffile{'.
-		$bgimg.'}\setlength{\unitlength}{1mm}  \begin{picture}('.$texwidth.','.$texwidth*$h/$w.')(0,-'.$texwidth*$h/$w.')';
-	}
+	$result.='\vspace*{2mm}\noindent \parbox{'.$dirtywidth.' mm}{  \noindent \epsfxsize='.
+	    $texwidth.' mm \epsffile{'.$bgimg.'}\setlength{\unitlength}{1mm}  \begin{picture}('.
+	    $texwidth.','.$texwidth*$h/$w.')(0,-'.$texwidth*$h/$w.')';
     } elsif ($target eq 'edit') {
 	$result.=&Apache::edit::tag_start($target,$token);
 	$Apache::edit::bgimgsrc=
@@ -179,7 +175,7 @@
 	$result='\end{picture}\\\\';
 	my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
 	my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
-	my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1);
+	my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1));
         if (!$texwidth) { $texwidth=90; }
 	my $howtoskipback = $texwidth*$height/$width;
 	$result.= ' \vskip -'.$howtoskipback.' mm }  \\\\ ';
@@ -189,6 +185,14 @@
     return $result;
 }
 
+sub adjust_textwidth {
+    my $texwidth=shift; 
+    my $pagewidth=$ENV{'form.textwidth'};
+    $pagewidth=~s/\s*mm\s*$//;
+    if ($texwidth>$pagewidth) {$texwidth=$pagewidth;}
+    return $texwidth;
+}
+
 sub start_labelgroup {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result='';
@@ -287,7 +291,7 @@
 	my $WY1=0; #  Web y-coord. of (ULC)
 	my $wwidth=&Apache::lonxml::get_param('width',$parstack,$safeeval,-2);
 	my $wheight=&Apache::lonxml::get_param('height',$parstack,$safeeval,-2);
-	my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,-2,1);
+	my $texwidth=&adjust_textwidth(&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,-2,1));
 	if (!$texwidth) { $texwidth=90; }
 	my $TX1=0;
 	my $TY1=$texwidth*($wheight/$wwidth);