PDF-Table
view release on metacpan or search on metacpan
lib/PDF/Table.pm view on Meta::CPAN
if ($ink) {
if (defined $bg_color &&
$bg_color ne 'transparent' && $bg_color ne 'trans' &&
!$colspanned{$row_idx.'_'.$col_idx}) {
$gfx_bg->rect( $cur_x, $cur_y-$actual_row_height,
$actual_column_widths[$row_idx][$col_idx], $actual_row_height);
$gfx_bg->fillcolor($bg_color);
$gfx_bg->fill();
}
# draw left vertical border of this cell unless leftmost
if ($gfx && $cell_v_rule_w && $col_idx &&
!$colspanned{$row_idx.'_'.$col_idx}) {
$gfx->linewidth($cell_v_rule_w);
$gfx->strokecolor($cell_v_rule_c);
$gfx->move($cur_x, $cur_y-$actual_row_height);
$gfx->vline( $cur_y - ($row_idx? 0: $h_border_w/2));
$gfx->stroke(); # don't confuse different widths and colors
}
# draw bottom horizontal rule of this cell unless bottom
# of page (no more data or not room for at least one line).
# TBD fix up when implement rowspan
if ($gfx && $cell_h_rule_w && scalar(@{$data}) &&
$cur_y-$actual_row_height-$current_min_rh > $bot_margin ) {
$gfx->linewidth($cell_h_rule_w);
$gfx->strokecolor($cell_h_rule_c);
$gfx->move($cur_x, $cur_y-$actual_row_height);
$gfx->hline( $cur_x + $actual_column_widths[$row_idx][$col_idx] );
$gfx->stroke(); # don't confuse different widths and colors
}
}
$cur_x += $calc_column_widths->[$col_idx];
} # End of for (my $col_idx....
$cur_y -= $actual_row_height;
if (!$ink) {
if ($first_row && $do_headers) {
# this was a header row
$vsizes[1] = $actual_row_height;
} else {
# this was a non-header row
push @vsizes, $actual_row_height;
}
# if implement footer, it will go in [2]
}
if ($do_leftovers) {
# a row has been split across pages. undo bg toggle
$row_is_odd = !$row_is_odd;
$next_top_border = 2; # dashed line
} else {
$row_idx++;
$next_top_border = 1; # solid line
}
$first_row = 0;
} # End of Row_Loop for this page, and possibly whole table
# draw bottom border on this page. first, is this very last row?
# The line overlays and hides any odd business with vertical rules
# in the last row
if (!scalar(@{$data})) { $next_top_border = 0; }
if ($ink) {
if ($gfx && $h_border_w) {
if ($next_top_border == 0) {
# last bottom border, use specified border
$gfx->linewidth($h_border_w);
} elsif ($next_top_border == 1) {
# solid thin line at start of a row
$gfx->linewidth($border_w_default);
} else { # == 2
# dashed thin line at continuation in middle of row
$gfx->linewidth($border_w_default);
$gfx->linedash($dashed_rule_default);
}
# leave next_top_border for next page top of continued table
$gfx->strokecolor($border_c);
$gfx->move( $xbase-$v_border_w/2 , $cur_y );
$gfx->hline($xbase + $width + $v_border_w/2);
$gfx->stroke();
$gfx->linedash();
}
if ($gfx) {
if ($v_border_w) {
# Draw left and right table borders
# These overlay and hide any odd business with horizontal
# rules at the left or right edge
$gfx->linewidth($v_border_w);
$gfx->move( $xbase, $table_top_y);
$gfx->vline( $cur_y );
$gfx->move( $xbase + $width, $table_top_y);
$gfx->vline( $cur_y );
}
# draw all the unrendered lines
$gfx->stroke();
}
}
$pg_cnt++; # on a spillover page
} # End of while (scalar(@{$data})) next row, adding new page if necessary
if ($ink) {
return ($page, --$pg_cnt, $cur_y);
} else {
# calculate overall table height as sum of 1..$#vsizes
for (my $i = 1; $i < @vsizes; $i++) {
$vsizes[0] += $vsizes[$i];
}
# might need to account for really thick horizontal border rules
return @vsizes;
}
} # end of table()
############################################################
# find a value that might be set in a default or in a global
# or column/row/cell specific parameter. fixed order of search
# is cell/header properties, column properties, row properties,
# fallback sequences (e.g., padding_left inherits from padding),
# global default
############################################################
sub find_value {
my ($cell_val, $name, $fallback, $default, $GLOBALS) = @_;
# $fallback can be '' (will be skipped)
my ($cell_props, $col_props, $row_props, $row_idx, $col_idx, $argref) =
@$GLOBALS;
# $row_idx should be 0 for a header entry
my %arg = %$argref;
# $default should never be undefined, except for specific cases!
if (!defined $default &&
($name ne 'underline' &&
$name ne 'bg_color' && $name ne 'fg_color' &&
$name ne 'bg_color_even' && $name ne 'bg_color_odd' &&
$name ne 'fg_color_even' && $name ne 'fg_color_odd' &&
$name ne 'min_w' && $name ne 'max_w') ) {
carp "Error! find_value() default value undefined for '$name'\n";
}
# upon entry, $cell_val is usually either undefined (data row) or
# header property setting (in which case, already set and we're done here)
$cell_val = $cell_props->[$row_idx][$col_idx]->{$name} if
!defined $cell_val;
$cell_val = $cell_props->[$row_idx][$col_idx]->{$fallback} if
!defined $cell_val && $fallback ne '';
$cell_val = $col_props->[$col_idx]->{$name} if
( run in 0.534 second using v1.01-cache-2.11-cpan-39bf76dae61 )