[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm

foxr lon-capa-cvs@mail.lon-capa.org
Thu, 01 Feb 2007 10:49:28 -0000


foxr		Thu Feb  1 05:49:28 2007 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Allow image alignment with return of env closure.  I was originally
  thinking about using this for e.g. bz 4952...but it's maybe useful
  anyway.
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.353 loncom/xml/londefdef.pm:1.354
--- loncom/xml/londefdef.pm:1.353	Mon Jan 22 06:28:08 2007
+++ loncom/xml/londefdef.pm	Thu Feb  1 05:49:27 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.353 2007/01/22 11:28:08 foxr Exp $
+# $Id: londefdef.pm,v 1.354 2007/02/01 10:49:27 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -2879,9 +2879,13 @@
 	    $size=~s/,$/]/; 
 	    $currentstring .= '\graphicspath{{'.$path.'}}'
 		.'\includegraphics'.$size.'{'.$file.'} ';
-	    $currentstring = &align_latex_image($align, $latex_rendering, 
-						$currentstring, 
-						$width_param, $height_param);
+	    my $closure;
+	    ($currentstring, $closure) = &align_latex_image($align, 
+							    $latex_rendering, 
+							    $currentstring, 
+							    $width_param, 
+							    $height_param);
+	    $currentstring .= $closure;
 						
 	} else {
 	    &Apache::lonxml::debug("$src does not exist");
@@ -4360,11 +4364,15 @@
 #     latex_rendering - rendering hint for latex.
 #     image   - The LaTeX needed to insert the image itsef.
 #     width,height - dimensions of the image.
+# Returns:
+#    The 1/2 wrapped image and the stuff required to close the
+#    wrappage.  This allows e.g. randomlabel to insert more stuff
+#    into the closure.
 #
 sub align_latex_image {
     my ($align, $latex_rendering, $image, $width, $height) = @_;
-    my $currentstring;        # The result.
-    
+    my $currentstring;        # The 1/2 wrapped image.
+    my $closure;              # The closure of the wrappage.
     #    If there's an alignment specification we need to honor it here.
     #    For the horizontal alignments, we will also honor the
     #    value of the latex specfication.  The default is parbox,
@@ -4373,40 +4381,52 @@
     #    Even though we set a default alignment value, the user
     #    could have given us an illegal value.  In that case we
     #    just use the default alignment of bottom..
+    $currentstring = "\n% figurewrapping \n";
     if      ($align eq "top")    {
-	$currentstring = '\raisebox{-'.$height.'mm}{'.$image.'}';
+	$currentstring .= '\raisebox{-'.$height.'mm}{'.$image;
+	$closure = '}';
     } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
 	my $offset = $height/2;
-	$currentstring = '\raisebox{-'.$offset.'mm}{'.$image.'}';
+	$currentstring .= '\raisebox{-'.$offset.'mm}{'.$image;
+	$closure       = '}';
     } elsif ($align eq "left")   { 
 	if ($latex_rendering eq "parpic") { 
-	    $currentstring = '\parpic[l]{'.$image.'}';
+	    $currentstring .= '\parpic[l]{'.$image;
+	    $closure       = '}';
 	} elsif ($latex_rendering eq "parbox") {
-	    $currentstring = '\begin{minipage}[l]{'.$width.'mm}'
-		.$image.'\end{minipage}';
+	    $currentstring .= '\begin{minipage}[l]{'.$width.'mm}'
+		.$image;
+	    $closure = '\end{minipage}';
 	} elsif ($latex_rendering eq "wrapfigure"
 		 || $latex_rendering ne 'none') {  # wrapfig render
-	    $currentstring = 
+	    $currentstring .= 
 		'\begin{wrapfigure}{l}{'.$width.'mm}'
-		.'\scalebox{1.0}{'.$image.'}\end{wrapfigure}';
+		.'\scalebox{1.0}{'.$image;
+	    $closure = '}\end{wrapfigure}';
 	}
     } elsif ($align eq "right")  {   
 	if ($latex_rendering eq "parpic") {
-	    $currentstring = '\parpic[r]{'.$image.'}';
+	    $currentstring .= '\parpic[r]{'.$image;
+	    $closure = '}';
 	} elsif ($latex_rendering eq "parbox") {
-	    $currentstring =  '\begin{minipage}[r]{'.$width.'mm}'
-		.$image.'\end{minipage}';
+	    $currentstring .=  '\begin{minipage}[r]{'.$width.'mm}'
+		.$image;
+	    $closure = '\end{minipage}';
 	} elsif ($latex_rendering eq "wrapfigure"
 		 || $latex_rendering ne 'none') {  # wrapfig render
-	    $currentstring = 
+	    $currentstring .= 
 		'\begin{wrapfigure}{r}{'.$width.'mm}'
-		.'\scalebox{1.0}{'.$image.'}\end{wrapfigure}';
+		.'\scalebox{1.0}{'.$image;
+	    $closure = '}\end{wrapfigure}';
 	}
     } else {		# Bottom is also default.
 	# $currentstring = '\raisebox{'.$height.'mm}{'.$image.'}';
-	$currentstring = $image;
+	$currentstring .= "{$image";
+	$closure       = '}';
     }
-    return $currentstring;
+    $currentstring .= "\n% end wrappage\n";
+    $closure        = "\n% Begin closure\n".$closure."\n% End closure\n";
+    return ($currentstring, $closure);
 }
 
 # is_inside_of $tagstack $tag