Subject: | Bug in text wrapping function |
Date: | Mon, 12 Jan 2009 13:37:14 +0100 |
To: | <bug-PDF-ReportWriter [...] rt.cpan.org> |
From: | "Bartschies, Thomas" <Thomas.Bartschies [...] cvk.de> |
Hello,
we've found a bug in the wrap_text sub function. It occurs if there's no last space to be found
in the rest of a paragraph and the remaining size of the paragraph is more than the allowed
width of the column. This is tested with by the advancewidth function.
In this case the last_space variable remains 0 and position remains < length (paragraph).
We fixed it for ourselves by applying the following changes:
@@ -2125,6 +2126,7 @@
my $position = 0;
my $last_space = 0;
+ my $space_found = 0;
while (
( $self->{txt}->advancewidth( substr( $paragraph, 0, $position ) ) < $text_width )
@@ -2142,6 +2144,10 @@
# This bit doesn't need wrapping. Take it all
$length = $position;
+
+ } elsif ( $last_space == 0 ) {
+
+ $length = $position - 1;
} else {
@@ -2149,16 +2155,18 @@
# Go back to the last space
$length = $last_space;
+ $space_found = 1;
}
if ( $self->{debug} ) {
- print "PDF::ReportWriter::wrap_text returning line: " . substr( $paragraph, 0, $length ) . "\n\n";
+ print STDERR "PDF::ReportWriter::wrap_text returning line: " . substr( $paragraph, 0, $length ) . "\n\n";
}
push @wrapped_text, substr( $paragraph, 0, $length );
- $paragraph = substr( $paragraph, $length + 1, length( $paragraph ) - $length );
+ $paragraph = substr( $paragraph, $length + $space_found,
+ length( $paragraph ) - $length );
}
Regards,
--
i. A. Thomas Bartschies
IT Systeme
Cornelsen Verlagskontor GmbH
Kammerratsheide 66, 33609 Bielefeld
Telefon 0521.9719-310
Telefax 0521.9719-93310
http://www.cvk.de
AG Bielefeld HRB 39324 - Geschäftsführer: Horst Keplinger
Geschäftsführende Komplementärin: AG Bielefeld HRB 7107 - Cornelsen Verlagskontor Verwaltungs-GmbH
Weitere Komplementärin: AG Charlottenburg HRA 20764 - Cornelsen Verlagsholding GmbH & Co., Berlin