$line_width += $arg{'indent'};
}
- # Lets take from paragraph as many words as we can put into $width - $indent;
- while ( @paragraph and $text_object->advancewidth( join("\x20", @line)."\x20" . $paragraph[0]) + $line_width < $width ) {
+ # Lets take from paragraph as many words as we can put into $width - $indent;. Always take at least one word; otherwise we'd end up in an infinite loop.
+ while (!scalar(@line) || (@paragraph && ($text_object->advancewidth( join("\x20", @line)."\x20" . $paragraph[0]) + $line_width < $width))) {
push(@line, shift(@paragraph));
}
$line_width += $text_object->advancewidth(join('', @line));
# Disable header row into the table
my $header_props;
my $num_header_rows = 0;
- my @header_rows;
+ my (@header_rows, @header_row_cell_props);
# Check if the user enabled it ?
if (defined $arg{'header_props'} and ref( $arg{'header_props'}) eq 'HASH') {
# Transfer the reference to local variable
if (ref $data eq 'ARRAY') {
# Copy the header row if header is enabled
if (defined $header_props) {
- map { push @header_rows, $$data[$_] } (0..$num_header_rows - 1);
+ map { push @header_rows, $$data[$_] } (0..$num_header_rows - 1);
+ map { push @header_row_cell_props, $$cell_props[$_] } (0..$num_header_rows - 1);
}
# Determine column widths based on content
# the actual widths of the column/row intersection
my $row_props = [];
# An array ref with the widths of the header row
- my @header_row_props;
+ my @header_row_widths;
# Scalars that hold sum of the maximum and minimum widths of all columns
my ( $max_col_w, $min_col_w ) = ( 0,0 );
my $rows_counter = 0;
foreach $row ( @{$data} ) {
- push(@header_row_props, []) if ($rows_counter < $num_header_rows);
+ push(@header_row_widths, []) if ($rows_counter < $num_header_rows);
my $column_widths = []; #holds the width of each column
for( my $j = 0; $j < scalar(@$row) ; $j++ ) {
$row->[$j] =~ s#(\b\S{$max_word_len}?)(\S.*?\b)# $1 $2#;
$myone = 1 if ( defined $2 );
} while( $myone );
+ $row->[$j] =~ s/^\s+//;
$space_w = $txt->advancewidth( "\x20" );
$column_widths->[$j] = 0;
$row_props->[$rows_counter] = $column_widths;
# Copy the calculated row properties of header row.
if (($rows_counter < $num_header_rows) && $header_props) {
- push(@header_row_props, [ @{ $column_widths } ]);
+ push(@header_row_widths, [ @{ $column_widths } ]);
}
$rows_counter++;
}
- $main::lxdebug->dump(0, "hrp", \@header_row_props);
# Calc real column widths and expand table width if needed.
my $calc_column_widths;
($calc_column_widths, $width) = $self->CalcColumnWidths( $col_props, $width );
if ( ref $header_props and $header_props->{'repeat'}) {
foreach my $idx (0 .. $num_header_rows - 1) {
unshift @$data, [ @{ $header_rows[$idx] } ];
- unshift @$row_props, [ @{ $header_row_props[$idx] } ];
+ unshift @$row_props, [ @{ $header_row_widths[$idx] } ];
}
$remaining_header_rows = $num_header_rows;
}
my $this_width;
if (!$remaining_header_rows && $cell_props->[$row_cnt]->[$j]->{colspan}) {
- $colspan = -1 == $cell_props->[$row_cnt]->[$j]->{colspan} ? $num_cols - $j : $cell_props->[$row_cnt]->[$j]->{colspan};
+ $colspan = $cell_props->[$row_cnt]->[$j]->{colspan};
+
+ } elsif ($remaining_header_rows && $header_row_cell_props[$num_header_rows - $remaining_header_rows]->[$j]->{colspan}) {
+ $colspan = $header_row_cell_props[$num_header_rows - $remaining_header_rows]->[$j]->{colspan};
+
+ }
+
+ if ($colspan) {
+ $colspan = $num_cols - $j if (-1 == $colspan);
my $last_idx = $j + $colspan - 1;
$this_width = sum @{ $calc_column_widths }[$j..$last_idx];
if ($remaining_header_rows) {
$remaining_header_rows--;
} else {
- $row_cnt++;
+ $row_cnt++ unless $do_leftovers;
}
}# End of while(scalar(@{$data}) and $cur_y-$row_h > $bot_marg)
The text_block() method is a slightly modified copy of the one from
Rick Measham's PDF::API2 tutorial at
http://pdfapi2.sourceforge.net/cgi-bin/view/Main/YourFirstDocument
+update: The tutorial is no longer available. Please visit http://pdfapi2.sourceforge.net .
by Desislav Kamenov