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

foxr foxr@source.lon-capa.org
Wed, 11 Aug 2010 10:57:36 -0000


foxr		Wed Aug 11 10:57:36 2010 EDT

  Modified files:              
    /loncom/xml	londefdef.pm lontable.pm 
  Log:
  BZ 6317 : Honor the table border. 
            Furthermore.. add limited support for rules attribute. This
            allows table borders without cell borders e.g.
  
  
  
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.419 loncom/xml/londefdef.pm:1.420
--- loncom/xml/londefdef.pm:1.419	Wed Aug  4 14:20:26 2010
+++ loncom/xml/londefdef.pm	Wed Aug 11 10:57:36 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.419 2010/08/04 14:20:26 raeburn Exp $
+# $Id: londefdef.pm,v 1.420 2010/08/11 10:57:36 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -2048,29 +2048,39 @@
 	my $width  = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval, undef, 0);
 	my $theme  = &Apache::lonxml::get_param('TeXtheme', $parstack, $safeeval, undef, 0);
 	my $align  = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 0);
+	my $cell_border = &Apache::lonxml::get_param('rules', $parstack, $safeeval, undef, 0);
 
 	# The only thing that needs any figuring out is the width.. and then only if it is
 	# a percent. If not it's assumed to be some valid TeX measurement unit e.g. 3.0cm
 	#
 
 	my $table = new Apache::lontable();
-	if ($border ne '' && $border != 0) {
+	if ((defined $border) && ($border > 0)) {
+	    &Apache::lonnet::logthis("Turning on table borderes: $border");
 	    $table->table_border(1);
+	    if ($cell_border ne 'none') {
+		$table->cell_border(1); # html specs that border turns on both...unless rules='none'.
+	    }
+	}
+	# Only all or nothing for cell borders for now:
+
+	if ((defined $cell_border) && ($cell_border ne 'none')) {
+	    &Apache::lonnet::logthis("Turning on cell borders: $cell_border");
 	    $table->cell_border(1);
 	}
-	if ($theme ne '') {
+	if (defined $theme) {
 	    $table->theme($theme);
 	}
-	if ($align ne '') {
+	if (defined $align) {
 	    $table->alignment($align);
 	}
 
 	# Missing width is most of page width
 
-	if ($width eq "") {
+	if (!(defined $width)) {
 	    $width = '70%';
 	}
-	
+
 	# If a percentage, need to calculate what this means in terms of
 	# page width:
 	
Index: loncom/xml/lontable.pm
diff -u loncom/xml/lontable.pm:1.10 loncom/xml/lontable.pm:1.11
--- loncom/xml/lontable.pm:1.10	Fri Apr 17 20:17:48 2009
+++ loncom/xml/lontable.pm	Wed Aug 11 10:57:36 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 #  Generating TeX tables.
 #
-# $Id: lontable.pm,v 1.10 2009/04/17 20:17:48 raeburn Exp $
+# $Id: lontable.pm,v 1.11 2010/08/11 10:57:36 foxr Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -265,7 +265,7 @@
 	outer_border   => 0,
 	inner_border  => 0,
 	caption        => "",
-	theme          => "Zurich",
+	theme          => "plain",
 	column_count   => 0,
 	row_open       => 0,
 	rows           => [],
@@ -733,6 +733,7 @@
     my $table = LaTeX::Table->new();
     $table->set_center(0);	# loncapa tables don't float.
     $table->set_environment(0);
+    $table->set_theme($this->{'theme'});
 
 
     # Add the caption if supplied.
@@ -761,6 +762,13 @@
     my $outer_border = $this->{'outer_border'};
     my $column_count = $this->{'column_count'};
 
+    # Add a top line if the outer or inner border is enabled:
+
+    if ($outer_border || $inner_border) {
+	push(@data, ["\\cline{1-$column_count}"]);	     
+
+    }
+
     for (my $row = 0; $row < $row_count; $row++) {
 	my @row;
 	my $cells      = $rows->[$row]->{'cells'};
@@ -770,6 +778,7 @@
 	my @underlines;		# Array of \cline cells if cellborder on.
 
 
+
 	for (my $cell  = 0; $cell < $cell_count; $cell++) {
 	    my $contents = $cells->[$cell]->{'contents'};
 
@@ -838,6 +847,7 @@
 		}
 	    }
 	    if ($inner_border && ($cells->[$cell]->{'rowspan'} == 1)) {
+		&Apache::lonnet::logthis("Pushing underlines $inner_border");
 		my $lastcol = $nextcol -1;
 		push(@underlines, "\\cline{$startcol-$lastcol}");
 	    }
@@ -849,16 +859,26 @@
 	}
 	push(@data, \@row);
 	if ($inner_border) {
+	    &Apache::lonnet::logthis("Pushing underlines with inner_border");
 	    for (my $i =0; $i < scalar(@underlines); $i++) {
 		push(@data, [$underlines[$i]]);
 	    }
 	}
 
     }
+    #
+    # Add bottom border if necessary: if the inner border was on, the loops above
+    # will have done a bottom line under the last cell.
+    #
+    if ($outer_border && !$inner_border) {
+	push(@data, ["\\cline{1-$column_count}"]);	     
+
+    }
     $table->set_data(\@data);
     
     my $coldef = "";
     if ($outer_border || $inner_border) {
+	&Apache::lonnet::logthis("adding | $outer_border : $inner_border");
 	$coldef .= '|';
     }
     for (my $i =0; $i < $column_count; $i++) {