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

foxr lon-capa-cvs@mail.lon-capa.org
Mon, 22 Jan 2007 11:28:09 -0000


foxr		Mon Jan 22 06:28:09 2007 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Factor out image alignment wrapping so that enhancement request
  4952 can be done without duplicating code between londefdef.pm
  and randomlabel.pm.
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.352 loncom/xml/londefdef.pm:1.353
--- loncom/xml/londefdef.pm:1.352	Thu Jan 18 15:48:02 2007
+++ loncom/xml/londefdef.pm	Mon Jan 22 06:28:08 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.352 2007/01/18 20:48:02 albertel Exp $
+# $Id: londefdef.pm,v 1.353 2007/01/22 11:28:08 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -2879,47 +2879,10 @@
 	    $size=~s/,$/]/; 
 	    $currentstring .= '\graphicspath{{'.$path.'}}'
 		.'\includegraphics'.$size.'{'.$file.'} ';
-
-	    #    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,
-	    #    and that's used for illegal values too.  
-	    #    
-	    #    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..
-	    if      ($align eq "top")    {
-		$currentstring = '\raisebox{-'.$height_param.'mm}{'.$currentstring.'}';
-	    } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
-		my $offset = $height_param/2;
-		$currentstring = '\raisebox{-'.$offset.'mm}{'.$currentstring.'}';
-	    } elsif ($align eq "left")   { 
-		if ($latex_rendering eq "parpic") { 
-		    $currentstring = '\parpic[l]{'.$currentstring.'}';
-		} elsif ($latex_rendering eq "parbox") {
-		    $currentstring = '\begin{minipage}[l]{'.$width_param.'mm}'
-			.$currentstring.'\end{minipage}';
-		} elsif ($latex_rendering eq "wrapfigure"
-			 || $latex_rendering ne 'none') {  # wrapfig render
-		    $currentstring = 
-			'\begin{wrapfigure}{l}{'.$width_param.'mm}'
-			.'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
-		}
-	    } elsif ($align eq "right")  {   
-		if ($latex_rendering eq "parpic") {
-		    $currentstring = '\parpic[r]{'.$currentstring.'}';
-		} elsif ($latex_rendering eq "parbox") {
-		    $currentstring =  '\begin{minipage}[r]{'.$width_param.'mm}'
-			.$currentstring.'\end{minipage}';
-		} elsif ($latex_rendering eq "wrapfigure"
-			 || $latex_rendering ne 'none') {  # wrapfig render
-		    $currentstring = 
-			'\begin{wrapfigure}{r}{'.$width_param.'mm}'
-			.'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
-		}
-	    } else {		# Bottom is also default.
-		# $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}';
-	    }
+	    $currentstring = &align_latex_image($align, $latex_rendering, 
+						$currentstring, 
+						$width_param, $height_param);
+						
 	} else {
 	    &Apache::lonxml::debug("$src does not exist");
 	    #original image file doesn't exist so check the alt attribute
@@ -4389,6 +4352,62 @@
     return $value;
 }
 
+#   Wrap image 'stuff' inside of the LaTeX required to implement 
+#   alignment:
+#     align_tex_image(align, latex_rendering, image)
+#   Where:
+#     align   - The HTML alignment specification.
+#     latex_rendering - rendering hint for latex.
+#     image   - The LaTeX needed to insert the image itsef.
+#     width,height - dimensions of the image.
+#
+sub align_latex_image {
+    my ($align, $latex_rendering, $image, $width, $height) = @_;
+    my $currentstring;        # The result.
+    
+    #    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,
+    #    and that's used for illegal values too.  
+    #    
+    #    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..
+    if      ($align eq "top")    {
+	$currentstring = '\raisebox{-'.$height.'mm}{'.$image.'}';
+    } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
+	my $offset = $height/2;
+	$currentstring = '\raisebox{-'.$offset.'mm}{'.$image.'}';
+    } elsif ($align eq "left")   { 
+	if ($latex_rendering eq "parpic") { 
+	    $currentstring = '\parpic[l]{'.$image.'}';
+	} elsif ($latex_rendering eq "parbox") {
+	    $currentstring = '\begin{minipage}[l]{'.$width.'mm}'
+		.$image.'\end{minipage}';
+	} elsif ($latex_rendering eq "wrapfigure"
+		 || $latex_rendering ne 'none') {  # wrapfig render
+	    $currentstring = 
+		'\begin{wrapfigure}{l}{'.$width.'mm}'
+		.'\scalebox{1.0}{'.$image.'}\end{wrapfigure}';
+	}
+    } elsif ($align eq "right")  {   
+	if ($latex_rendering eq "parpic") {
+	    $currentstring = '\parpic[r]{'.$image.'}';
+	} elsif ($latex_rendering eq "parbox") {
+	    $currentstring =  '\begin{minipage}[r]{'.$width.'mm}'
+		.$image.'\end{minipage}';
+	} elsif ($latex_rendering eq "wrapfigure"
+		 || $latex_rendering ne 'none') {  # wrapfig render
+	    $currentstring = 
+		'\begin{wrapfigure}{r}{'.$width.'mm}'
+		.'\scalebox{1.0}{'.$image.'}\end{wrapfigure}';
+	}
+    } else {		# Bottom is also default.
+	# $currentstring = '\raisebox{'.$height.'mm}{'.$image.'}';
+	$currentstring = $image;
+    }
+    return $currentstring;
+}
 
 # is_inside_of $tagstack $tag
 #    This sub returns true if the current state of Xml processing