From 35cd4452887eb2a3219816bd900e6dc5918430a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 25 Feb 2016 11:41:47 +0100 Subject: [PATCH] =?utf8?q?Unterst=C3=BCtzung=20f=C3=BCr=20zellen=C3=BCberg?= =?utf8?q?reifende=20=C3=9Cberschriften=20im=20PDF-Export=20des=20ReportGe?= =?utf8?q?nerators=20verbessert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reimplementation von d3897394 --- modules/override/PDF/Table.pm | 43 +++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/modules/override/PDF/Table.pm b/modules/override/PDF/Table.pm index 1b44bb568..95b2db88f 100644 --- a/modules/override/PDF/Table.pm +++ b/modules/override/PDF/Table.pm @@ -4,6 +4,7 @@ use 5.006; use strict; use warnings; use Carp; +use List::Util qw(sum); our $VERSION = '0.9.10'; print __PACKAGE__.' is version: '.$VERSION.$/ if($ENV{'PDF_TABLE_DEBUG'}); @@ -536,6 +537,7 @@ sub table # Calc real column widths and expand table width if needed. my $calc_column_widths; ($calc_column_widths, $width) = CalcColumnWidths( $col_props, $width ); + my $num_cols = scalar @{ $calc_column_widths }; # Lets draw what we have! my $row_index = 0; @@ -587,7 +589,7 @@ sub table # Check for safety reasons if( $bot_marg < 0 ) { # This warning should remain i think - carp "!!! Warning: !!! Incorrect Table Geometry! Setting bottom margin to end of sheet!\n"; +# carp "!!! Warning: !!! Incorrect Table Geometry! Setting bottom margin to end of sheet!\n"; $bot_marg = 0; } @@ -664,6 +666,7 @@ sub table my $cur_x = $xbase; my $leftovers = undef; # Reference to text that is returned from textblock() my $do_leftovers = 0; + my ($colspan, @vertical_lines); # Process every cell(column) from current row for( my $column_idx = 0; $column_idx < scalar( @$record); $column_idx++ ) @@ -704,20 +707,32 @@ sub table # Init cell font object $txt->font( $cell_font, $cell_font_size ); $txt->fillcolor($cell_font_color); + + my $this_width; + if (!$first_row && $cell_props->[$row_index][$column_idx]->{colspan}) { + $colspan = -1 == $cell_props->[$row_index][$column_idx]->{colspan} + ? $num_cols - $column_idx + : $cell_props->[$row_index][$column_idx]->{colspan}; + my $last_idx = $column_idx + $colspan - 1; + $this_width = sum @{ $calc_column_widths }[$column_idx..$last_idx]; + + } else { + $this_width = $calc_column_widths->[$column_idx]; + } # If the content is wider than the specified width, we need to add the text as a text block if( $record->[$column_idx] !~ m/(.\n.)/ and $record_widths->[$column_idx] and - $record_widths->[$column_idx] <= $calc_column_widths->[$column_idx] + $record_widths->[$column_idx] <= $this_width ){ my $space = $pad_left; if ($justify eq 'right') { - $space = $calc_column_widths->[$column_idx] -($txt->advancewidth($record->[$column_idx]) + $pad_right); + $space = $this_width -($txt->advancewidth($record->[$column_idx]) + $pad_right); } elsif ($justify eq 'center') { - $space = ($calc_column_widths->[$column_idx] - $txt->advancewidth($record->[$column_idx])) / 2; + $space = ($this_width - $txt->advancewidth($record->[$column_idx])) / 2; } $txt->translate( $cur_x + $space, $text_start ); $txt->text( $record->[$column_idx] ); @@ -730,7 +745,7 @@ sub table $record->[$column_idx], x => $cur_x + $pad_left, y => $text_start, - w => $calc_column_widths->[$column_idx] - $pad_left - $pad_right, + w => $this_width - $pad_left - $pad_right, h => $cur_y - $bot_marg - $pad_top - $pad_bot, align => $justify, lead => $lead @@ -749,6 +764,9 @@ sub table } } $cur_x += $calc_column_widths->[$column_idx]; + + push @vertical_lines, (!$colspan || (1 >= $colspan)) ? 1 : 0; + $colspan-- if $colspan; } if( $do_leftovers ) { @@ -782,6 +800,12 @@ sub table $gfx_bg->fill(); } $cur_x += $calc_column_widths->[$column_idx]; + + if ($line_w && $vertical_lines[$column_idx] && ($column_idx != (scalar(@{ $record }) - 1))) { + $gfx->move($cur_x, $cur_y); + $gfx->vline($cur_y - $row_h); + $gfx->fillcolor($border_color); + } }#End of for(my $column_idx.... $cur_y -= $current_row_height; @@ -802,13 +826,8 @@ sub table { $gfx->move( $xbase, $table_top_y); $gfx->vline( $cur_y ); - my $cur_x = $xbase; - for( my $j = 0; $j < $columns_number; $j++ ) - { - $cur_x += $calc_column_widths->[$j]; - $gfx->move( $cur_x, $table_top_y ); - $gfx->vline( $cur_y ); - } + $gfx->move($xbase + sum(@{ $calc_column_widths }[0..$num_cols - 1]), $table_top_y); + $gfx->vline( $cur_y ); } # ACTUALLY draw all the lines -- 2.20.1