Diff for /loncom/xml/lontable.pm between versions 1.17 and 1.21

version 1.17, 2011/04/13 10:08:06 version 1.21, 2011/11/30 18:01:33
Line 57  package Apache::lontable; Line 57  package Apache::lontable;
 use strict;  use strict;
 use Apache::lonlatextable;  use Apache::lonlatextable;
 use Apache::lonnet; # for trace logging.  use Apache::lonnet; # for trace logging.
 use Data::Dumper;  
   
 my $tracing = 1; # Set to 1 to enable log tracing. 2 for local sub tracing.  my $tracing = 0; # Set to 1 to enable log tracing. 2 for local sub tracing.
   
 =pod  =pod
   
Line 272  sub new { Line 271  sub new {
     'foot'     => []      'foot'     => []
  },   },
  col_widths      => {},   col_widths      => {},
  part           => 'body'     # one of 'body', 'head', 'foot'.   part           => 'body',     # one of 'body', 'head', 'foot'.
    colgroups      => []      # Stores information about column groups.
   
     };      };
   
Line 533  sub end_row { Line 533  sub end_row {
  # Mostly we need to determine if this row has the maximum   # Mostly we need to determine if this row has the maximum
  # cell count of any row in existence in the table:   # cell count of any row in existence in the table:
   
  &Apache::lonnet::logthis($self->{'part'});  
  &Apache::lonnet::logthis(Dumper($self->{'rows'}));  
  my $row        = $self->{'rows'}->{$self->{'part'}}->[-1];   my $row        = $self->{'rows'}->{$self->{'part'}}->[-1];
  my $cells      = $row->{'cells'};   my $cells      = $row->{'cells'};
   
Line 932  define the column group. Line 931  define the column group.
 sub define_colgroup {  sub define_colgroup {
     my ($this, $attributes)  = @_;      my ($this, $attributes)  = @_;
     if ($tracing) { &Apache::lonnet::logthis("col_group"); }      if ($tracing) { &Apache::lonnet::logthis("col_group"); }
           my $colgroups = $this->{'colgroups'};
       push(@$colgroups, $attributes); # Colgroups always add at end.
   
   
 }  }
   
Line 968  sub generate { Line 969  sub generate {
     my $cell_lr_border = (($inner_border == 1) || ($inner_border == 3)) ? 1 : 0;      my $cell_lr_border = (($inner_border == 1) || ($inner_border == 3)) ? 1 : 0;
     my $part_border   = ($inner_border == 4);      my $part_border   = ($inner_border == 4);
     
     # Add the caption if supplied.   
         # Add the caption if supplied.
   
     if ($this->{'caption'} ne "") {      if ($this->{'caption'} ne "") {
  $table->set_caption($this->caption);   $table->set_caption($this->caption);
Line 1030  sub generate { Line 1032  sub generate {
           
         }          }
     }      }
       # If rule is groups. we need to have a 
     if ($tracing) { &Apache::lonnet::logthis("rendering head"); }      # list of the column numbers at which a column ends...
     $this->render_part('head', $table, $useP, $default_width);      # and the coldef needs to start with a |
     if ($tracing) { &Apache::lonnet::logthis("rendering body"); }      #
     $this->render_part('body', $table, $useP, $default_width);      my @colgroup_ends;
     if ($tracing) { &Apache::lonnet::logthis("rendering footer"); }      my $colgroup_col = 0;
     $this->render_part('foot', $table, $useP, $default_width);      my $group = 0;
       my $coldef = "";
       if ($outer_border || $cell_lr_border) {
    $coldef .= '|';
       }
       if ($part_border) {
    $coldef .= '|';
    my $colgroup_col = 0;
    my $colgroups = $this->{'colgroups'};
    foreach my $group (@$colgroups) {
       if (defined $group->{'span'}) {
    $colgroup_col += $group->{'span'};
       } else {
    $colgroup_col++;
       }
       push(@colgroup_ends, $colgroup_col);
    }
     
       }
       $this->render_part('head', $table, $useP, $default_width, 
          \@colgroup_ends);
       $this->render_part('body', $table, $useP, $default_width,
    \@colgroup_ends);
       $this->render_part('foot', $table, $useP, $default_width,
    \@colgroup_ends);
   
   
   
   
           
     my $coldef = "";  
     if ($outer_border || $cell_lr_border) {  
  $coldef .= '|';  
     }  
     for (my $i =0; $i < $column_count; $i++) {      for (my $i =0; $i < $column_count; $i++) {
  if ($useP) {   if ($useP) {
     $coldef .= "p{$default_width $colunits}";      $coldef .= "p{$default_width $colunits}";
Line 1056  sub generate { Line 1078  sub generate {
     ($outer_border && ($i == $column_count-1))) {      ($outer_border && ($i == $column_count-1))) {
     $coldef .= '|';      $coldef .= '|';
  }   }
    if ($part_border && ($i == ($colgroup_ends[$group]-1)))  {
       $coldef .= '|';
       $group++;
    }
     }      }
     $table->{'coldef'} = $coldef;      $table->{'coldef'} = $coldef;
   
Line 1100  sub size_to_cm { Line 1126  sub size_to_cm {
 #  respectively.  #  respectively.
 #  #
 sub render_part {  sub render_part {
     my ($this, $part, $table, $useP, $default_width) = @_;      my ($this, $part, $table, $useP,
    $default_width, $colgroup_ends) = @_;
   
     if ($tracing) { &Apache::lonnet::logthis("render_part: $part") };      if ($tracing) { &Apache::lonnet::logthis("render_part: $part") };
   
     # Do nothing if that part of the table is empty:      # Do nothing if that part of the table is empty:
   
     &Apache::lonnet::logthis(Dumper($this->{'rows'}));  
     if ($this->{'rows'}->{$part} == undef) {      if ($this->{'rows'}->{$part} == undef) {
  if ($tracing) {&Apache::lonnet::logthis("$part is empty"); }   if ($tracing) {&Apache::lonnet::logthis("$part is empty"); }
  return;   return;
     }      }
   
       my @cgends = @$colgroup_ends;
     # Build up the data:      # Build up the data:
   
     my @data;      my @data;
     my $colwidths        = $this->{'col_widths'};      my $colwidths        = $this->{'col_widths'};
     my $rows      = $this->{'rows'}->{$part}; # TODO: Render header, body footer as groups.      my $rows      = $this->{'rows'}->{$part}; 
     my $row_count = scalar(@$rows);      my $row_count = scalar(@$rows);
     my $inner_border = $this->{'inner_border'};      my $inner_border = $this->{'inner_border'};
     my $outer_border = $this->{'outer_border'};      my $outer_border = $this->{'outer_border'};
Line 1145  sub render_part { Line 1171  sub render_part {
  my $startcol   = 1;   my $startcol   = 1;
  my @underlines; # Array of \cline cells if cellborder on.   my @underlines; # Array of \cline cells if cellborder on.
   
    my $colgroup_count = @cgends; # Number of column groups.
    my $cgroup         = 0;     # Group we are on.
    my $cgstart        = 0;     # Where the next cgroup starts.
   
  for (my $cell  = 0; $cell < $cell_count; $cell++) {   for (my $cell  = 0; $cell < $cell_count; $cell++) {
     my $contents = $cells->[$cell]->{'contents'};      my $contents = $cells->[$cell]->{'contents'};
       
     #      #
     #  Cell alignment is the default alignment unless      #  Cell alignment is the default alignment unless
     #  explicitly specified in the cell.      #  explicitly specified in the cell.
Line 1198  sub render_part { Line 1226  sub render_part {
     if ($cell_lr_border || ($outer_border && ($cell == ($cell_count -1)))) {      if ($cell_lr_border || ($outer_border && ($cell == ($cell_count -1)))) {
  $col_align = $col_align.'|';   $col_align = $col_align.'|';
     }      }
       if ($part_border)  {
    if ($cell == $cgstart) {
       $col_align = '|' . $col_align;
       if ($cgroup < $colgroup_count) {
    $cgstart = $cgends[$cgroup];
    $cgroup++;
       } else {
    $cgstart = 1000000; # TODO: Get this logic right
       }
       if ($cell == ($cell_count - 1) &&
    ($cell == ($cgstart-1))) {
    $col_align = $col_align . '|'; # last col ends colgrp.
       }
    }
       }
   
     #factor in spans:      #factor in spans:
   
     my $cspan    = $cells->[$cell]->{'colspan'};      my $cspan    = $cells->[$cell]->{'colspan'};
     my $nextcol  = $startcol + $cspan;      my $nextcol  = $startcol + $cspan;
       
       # At this point this col is the start of the span.
       # nextcol is the end of the span.
   
     # If we can avoid the \multicolumn directive that's best as      # If we can avoid the \multicolumn directive that's best as
     # that makes some things like \parpic invalid in LaTeX which      # that makes some things like \parpic invalid in LaTeX which
Line 1224  sub render_part { Line 1270  sub render_part {
  push(@underlines, "\\cline{$startcol-$lastcol}");   push(@underlines, "\\cline{$startcol-$lastcol}");
     }      }
     $startcol = $nextcol;      $startcol = $nextcol;
   
     # Rowspans should take care of themselves.      # Rowspans should take care of themselves.
           
     push(@row, $contents);      push(@row, $contents);

Removed from v.1.17  
changed lines
  Added in v.1.21


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>