version 1.3, 2008/12/01 12:25:06
|
version 1.5, 2008/12/09 11:50:08
|
Line 39
|
Line 39
|
|
|
# This module is a support packkage that helps londefdef generate |
# This module is a support packkage that helps londefdef generate |
# LaTeX tables using the LaTeX::Table package. A prerequisite is that |
# 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{xtab} |
# \usepackage{booktabs} |
# \usepackage{booktabs} |
Line 278 sub alignment {
|
Line 278 sub alignment {
|
my ($self, $new_value) = @_; |
my ($self, $new_value) = @_; |
|
|
if (defined($new_value)) { |
if (defined($new_value)) { |
$self->{alignment} = $new_value; |
$self->{'alignment'} = $new_value; |
} |
} |
return $self->{alignment}; |
return $self->{'alignment'}; |
} |
} |
|
|
=pod |
=pod |
Line 303 sub table_border {
|
Line 303 sub table_border {
|
my ($self, $new_value) = @_; |
my ($self, $new_value) = @_; |
|
|
if (defined($new_value)) { |
if (defined($new_value)) { |
$self->{outer_border} = $new_value; |
$self->{'outer_border'} = $new_value; |
} |
} |
return $self->{outer_border}; |
return $self->{'outer_border'}; |
} |
} |
|
|
|
|
Line 320 value of that configuration parameter is
|
Line 320 value of that configuration parameter is
|
|
|
=head3 Examples: |
=head3 Examples: |
|
|
my $cell_borders = $table->cell_border(); # ask if cell borders are requested. |
my $cell_border = $table->cell_border(); # ask if cell borders are requested. |
$table->cell_border(1); # Request cell borders. |
$table->cell_border(1); # Request cell borders. |
|
|
=cut |
=cut |
|
|
sub cell_borders { |
sub cell_border { |
my ($self, $new_value) = @_; |
my ($self, $new_value) = @_; |
|
|
if (defined($new_value)) { |
if (defined($new_value)) { |
$self->{inner_border} = $new_value; |
$self->{'inner_border'} = $new_value; |
} |
} |
reurn $self->{inner_border}; |
return $self->{'inner_border'}; |
} |
} |
|
|
=pod |
=pod |
Line 353 sub caption {
|
Line 353 sub caption {
|
my ($self, $new_value) = @_; |
my ($self, $new_value) = @_; |
|
|
if (defined($new_value)) { |
if (defined($new_value)) { |
$self->catpion = $new_value; |
$self->{'caption'} = $new_value; |
} |
} |
|
|
return $self->caption; |
return $self->{'caption'}; |
} |
} |
|
|
=pod |
=pod |
Line 378 sub theme {
|
Line 378 sub theme {
|
my ($self, $new_value) = @_; |
my ($self, $new_value) = @_; |
|
|
if (defined($new_value)) { |
if (defined($new_value)) { |
$self->theme = $new_value; |
$self->{'theme'} = $new_value; |
} |
} |
return $self->theme; |
return $self->{'theme'}; |
} |
} |
|
|
=pod |
=pod |
Line 412 The default vertical alignment of the ro
|
Line 412 The default vertical alignment of the ro
|
=cut |
=cut |
|
|
sub start_row { |
sub start_row { |
my ($self, %config) = @_; |
my ($self, $config) = @_; |
|
|
if ($self->row_open) { |
if ($self->{'row_open'}) { |
$self->end_row; |
$self->end_row(); |
} |
} |
my $row_hash = { |
my $row_hash = { |
default_halign => "left", |
default_halign => "left", |
Line 425 sub start_row {
|
Line 425 sub start_row {
|
|
|
# Override the defaults if the config hash is present: |
# Override the defaults if the config hash is present: |
|
|
if (defined(%config)) { |
if (defined($config)) { |
foreach my $key (keys %config) { |
foreach my $key (keys %$config) { |
$row_hash->{$key} = $config{$key}; |
$row_hash->{$key} = $config->{$key}; |
} |
} |
} |
} |
|
|
|
|
my $rows = $self->{rows}; |
my $rows = $self->{'rows'}; |
push(@$rows, $row_hash); |
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 |
=pod |
Line 445 Closes off a row. Once closed, cells ca
|
Line 446 Closes off a row. Once closed, cells ca
|
|
|
=head3 Examples: |
=head3 Examples: |
|
|
$table->close_row(); |
$table->end_row(); |
|
|
|
|
=cut |
=cut |
|
|
sub close_row { |
sub end_row { |
my ($self) = @_; |
my ($self) = @_; |
|
|
if ($self->row_open) { |
if ($self->{'row_open'}) { |
|
|
# 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: |
|
|
my $row = $self->{rows}[-1]; |
my $row = $self->{'rows'}[-1]; |
my $cells = $row->{cells}; |
my $cells = $row->{'cells'}; |
my $raw_cell_count = scalar(@$cells); |
my $raw_cell_count = scalar(@$cells); |
|
|
# Need to iterate through the columns as |
# Need to iterate through the columns as |
Line 467 sub close_row {
|
Line 468 sub close_row {
|
# |
# |
my $cell_count = 0; |
my $cell_count = 0; |
for (my $i =0; $i < $raw_cell_count; $i++) { |
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}) { |
if ($cell_count > $self->{'column_count'}) { |
$self->{column_count} = $cell_count; |
$self->{'column_count'} = $cell_count; |
} |
} |
|
|
$self->row_closed; |
$self->{'row_open'} = 0;; |
} |
} |
} |
} |
|
|
Line 509 The default vertical alignment for text
|
Line 510 The default vertical alignment for text
|
sub configure_row { |
sub configure_row { |
my ($self, $config) = @_; |
my ($self, $config) = @_; |
|
|
if (!$self->row_open) { |
if (!$self->{'row_open'}) { |
$self->start_row(); |
$self->start_row(); |
} |
} |
|
|
my $row = $self->{rows}[-1]; |
my $row = $self->{'rows'}[-1]; |
foreach my $config_item (keys %$config) { |
foreach my $config_item (keys %$config) { |
$row->{$config_item} = $config->{$config_item}; |
$row->{$config_item} = $config->{$config_item}; |
} |
} |
Line 568 sub add_cell {
|
Line 569 sub add_cell {
|
|
|
# If a row is not open, we must open it: |
# If a row is not open, we must open it: |
|
|
if (!$self->row_open) { |
if (!$self->{'row_open'}) { |
$self->start_row(); |
$self->start_row(); |
} |
} |
|
|
my $current_row = $self->{rows}->[-1]; |
my $current_row = $self->{'rows'}->[-1]; |
my $current_cells = $current_row->{cells}; |
my $current_cells = $current_row->{'cells'}; |
|
|
# The way we handle row spans is to insert additional |
# The way we handle row spans is to insert additional |
# blank cells as needed to reach this column. Each |
# blank cells as needed to reach this column. Each |
Line 582 sub add_cell {
|
Line 583 sub add_cell {
|
# and handled when the table's LaTeX is generated. |
# 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: |
# 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) { |
if ($row_count > 1) { |
my $prior_row = $self->{rows}->[-2]; |
my $prior_row = $rows->[-2]; |
my $curr_colcount = scaler(@$current_row->{cells}); |
my $cells = $current_row->{'cells'}; |
my $prior_colcount = scaler(@$prior_row->{cells}); |
my $prior_cells = $prior_row->{'cells'}; |
|
my $curr_colcount = scalar(@$cells); |
|
|
|
my $prior_colcount = scalar(@$prior_cells); |
|
|
while (($curr_colcount < $prior_colcount) && |
while (($curr_colcount < $prior_colcount) && |
$prior_row->{cells}->[$curr_colcount]->{rowspan} > 1) { |
$prior_cells->[$curr_colcount]->{'rowspan'} > 1) { |
my %cell = $prior_row->{cells}->[$curr_colcount]; |
my %cell; |
%cell->{rowspan}--; |
my $prior_cell = $prior_cells->[$curr_colcount]; |
%cell->{contents} = ""; |
%cell = %$prior_cell; |
|
$cell{'rowspan'}--; |
|
$cell{'contents'} = ""; |
push(@$current_cells, \%cell); |
push(@$current_cells, \%cell); |
|
$curr_colcount += $prior_cells->[$curr_colcount]->{'colspan'}; # could be a colspan too. |
} |
} |
} |
} |
# |
# |
Line 613 sub add_cell {
|
Line 621 sub add_cell {
|
push(@$current_cells, $cell); |
push(@$current_cells, $cell); |
} |
} |
|
|
|
# The following methods allow for testability. |
|
|
|
|
|
sub get_object_attribute { |
|
my ($self, $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. |
# Mandatory initialization. |
|
BEGIN{ |
|
} |
|
|
1; |
1; |
__END__ |
__END__ |