Merge branch 'master' of ssh://lx-office/~/lx-office-erp
[kivitendo-erp.git] / modules / override / PDF / Table.pm
index 2dbcb98..7040b29 100644 (file)
@@ -135,8 +135,8 @@ sub text_block {
       $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));
@@ -334,6 +334,7 @@ sub table {
           $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;