--- loncom/xml/lontable.pm 2008/12/02 11:57:25 1.4 +++ loncom/xml/lontable.pm 2008/12/09 11:50:08 1.5 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Generating TeX tables. # -# $Id: lontable.pm,v 1.4 2008/12/02 11:57:25 foxr Exp $ +# $Id: lontable.pm,v 1.5 2008/12/09 11:50:08 foxr Exp $ # # # Copyright Michigan State University Board of Trustees @@ -39,7 +39,7 @@ # This module is a support packkage that helps londefdef generate # LaTeX tables using the LaTeX::Table package. A prerequisite is that -# the print generator must have added the following to the LaTeX header: +# the print generator must have added the following to the LaTeX # # \usepackage{xtab} # \usepackage{booktabs} @@ -278,9 +278,9 @@ sub alignment { my ($self, $new_value) = @_; if (defined($new_value)) { - $self->{alignment} = $new_value; + $self->{'alignment'} = $new_value; } - return $self->{alignment}; + return $self->{'alignment'}; } =pod @@ -303,9 +303,9 @@ sub table_border { my ($self, $new_value) = @_; if (defined($new_value)) { - $self->{outer_border} = $new_value; + $self->{'outer_border'} = $new_value; } - return $self->{outer_border}; + return $self->{'outer_border'}; } @@ -329,9 +329,9 @@ sub cell_border { my ($self, $new_value) = @_; if (defined($new_value)) { - $self->{inner_border} = $new_value; + $self->{'inner_border'} = $new_value; } - return $self->{inner_border}; + return $self->{'inner_border'}; } =pod @@ -353,10 +353,10 @@ sub caption { my ($self, $new_value) = @_; if (defined($new_value)) { - $self->{caption} = $new_value; + $self->{'caption'} = $new_value; } - return $self->{caption}; + return $self->{'caption'}; } =pod @@ -378,9 +378,9 @@ sub theme { my ($self, $new_value) = @_; if (defined($new_value)) { - $self->{theme} = $new_value; + $self->{'theme'} = $new_value; } - return $self->{theme}; + return $self->{'theme'}; } =pod @@ -412,9 +412,9 @@ The default vertical alignment of the ro =cut sub start_row { - my ($self, %config) = @_; + my ($self, $config) = @_; - if ($self->{row_open}) { + if ($self->{'row_open'}) { $self->end_row(); } my $row_hash = { @@ -425,16 +425,17 @@ sub start_row { # Override the defaults if the config hash is present: - if (defined(%config)) { - foreach my $key (keys %config) { - $row_hash->{$key} = $config{$key}; + if (defined($config)) { + foreach my $key (keys %$config) { + $row_hash->{$key} = $config->{$key}; } } + - my $rows = $self->{rows}; + my $rows = $self->{'rows'}; push(@$rows, $row_hash); - $self->{row_open} = 1; # Row is now open and ready for business. + $self->{"row_open"} = 1; # Row is now open and ready for business. } =pod @@ -453,13 +454,13 @@ Closes off a row. Once closed, cells ca sub end_row { my ($self) = @_; - if ($self->{row_open}) { + if ($self->{'row_open'}) { # Mostly we need to determine if this row has the maximum # cell count of any row in existence in the table: - my $row = $self->{rows}[-1]; - my $cells = $row->{cells}; + my $row = $self->{'rows'}[-1]; + my $cells = $row->{'cells'}; my $raw_cell_count = scalar(@$cells); # Need to iterate through the columns as @@ -467,13 +468,13 @@ sub end_row { # my $cell_count = 0; for (my $i =0; $i < $raw_cell_count; $i++) { - $cell_count = $cell_count + $cells->[$i]->{colspan}; + $cell_count = $cell_count + $cells->[$i]->{'colspan'}; } - if ($cell_count > $self->{column_count}) { - $self->{column_count} = $cell_count; + if ($cell_count > $self->{'column_count'}) { + $self->{'column_count'} = $cell_count; } - $self->{row_open} = 0;; + $self->{'row_open'} = 0;; } } @@ -509,11 +510,11 @@ The default vertical alignment for text sub configure_row { my ($self, $config) = @_; - if (!$self->{row_open}) { + if (!$self->{'row_open'}) { $self->start_row(); } - my $row = $self->{rows}[-1]; + my $row = $self->{'rows'}[-1]; foreach my $config_item (keys %$config) { $row->{$config_item} = $config->{$config_item}; } @@ -568,12 +569,12 @@ sub add_cell { # If a row is not open, we must open it: - if (!$self->{row_open}) { + if (!$self->{'row_open'}) { $self->start_row(); } - my $current_row = $self->{rows}->[-1]; - my $current_cells = $current_row->{cells}; + my $current_row = $self->{'rows'}->[-1]; + my $current_cells = $current_row->{'cells'}; # The way we handle row spans is to insert additional # blank cells as needed to reach this column. Each @@ -582,18 +583,25 @@ sub add_cell { # and handled when the table's LaTeX is generated. # There must be at least two rows in the row table to need to do this: - my $row_count = scalar(@$self->{rows}); + my $rows = $self->{'rows'}; + my $row_count = scalar(@$rows); if ($row_count > 1) { - my $prior_row = $self->{rows}->[-2]; - my $curr_colcount = scaler(@$current_row->{cells}); - my $prior_colcount = scaler(@$prior_row->{cells}); + my $prior_row = $rows->[-2]; + my $cells = $current_row->{'cells'}; + my $prior_cells = $prior_row->{'cells'}; + my $curr_colcount = scalar(@$cells); + + my $prior_colcount = scalar(@$prior_cells); while (($curr_colcount < $prior_colcount) && - $prior_row->{cells}->[$curr_colcount]->{rowspan} > 1) { - my %cell = $prior_row->{cells}->[$curr_colcount]; - %cell->{rowspan}--; - %cell->{contents} = ""; + $prior_cells->[$curr_colcount]->{'rowspan'} > 1) { + my %cell; + my $prior_cell = $prior_cells->[$curr_colcount]; + %cell = %$prior_cell; + $cell{'rowspan'}--; + $cell{'contents'} = ""; push(@$current_cells, \%cell); + $curr_colcount += $prior_cells->[$curr_colcount]->{'colspan'}; # could be a colspan too. } } # @@ -613,7 +621,7 @@ sub add_cell { push(@$current_cells, $cell); } -# The following method allows for testability. +# The following methods allow for testability. sub get_object_attribute { @@ -621,7 +629,11 @@ sub get_object_attribute { return $self->{$attribute}; } - +sub get_row { + my ($self, $row) = @_; + my $rows = $self->{'rows'}; # ref to an array.... + return $rows->[$row]; # ref to the row hash for the selected row. +} # Mandatory initialization. BEGIN{ }