From b5b8a7daeb54a4793f5725aa15927781f52fe106 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Wed, 21 Aug 2019 17:20:16 -0400 Subject: [PATCH] Bug 23488: Line wrapping doesn't always respect word order in Patron card creator When wrapping long lines of text, the line is divided by removing each word from the end of the line and putting it in a new one until the line is the right width. When the word to be removed appears multiple time in the line, it is not the last occurrence that is removed. This patch changes the regular expression used to remove the part of the text that is wrapped to a new line, making sure it removes it at the end of the text. Test plan: 1. Go to Tools > Patron card creator 2. Have a card template and a card batch -> If needs be, you can create them by using New > Card template or New > Card batch 3. Create a layout and use one text field containing a long text with at least one word which is repeated a minimum of 2 times (preferably towrdds the end of the text, since it has to be picked as one of the words to appear in the new line). You can use this: one two three one two three one two three one two three one two three one two three one two three one two three ... 4. Go to Manage > Card batches and export a batch 5. Choose the layout set up in 3. 6. Click the Export button and open the resulting pdf file 7. Notice all the repeated word have been grouped -> For this example : all of the ones appear first, followed by all the twos and only then the threes. 8. Apply patch 9. Repeat step 4 through 7 => this time the order of the words has not changed! Signed-off-by: Gabriel DeCarufel Signed-off-by: William Frazilien Signed-off-by: Bernardo Gonzalez Kriegel Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- C4/Patroncards/Patroncard.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C4/Patroncards/Patroncard.pm b/C4/Patroncards/Patroncard.pm index 661a9e8ac5..963aac8acf 100644 --- a/C4/Patroncards/Patroncard.pm +++ b/C4/Patroncards/Patroncard.pm @@ -261,7 +261,7 @@ sub draw_text { warn sprintf('Line wrap failed. DEBUG INFO: Data: \'%s\'\n Method: C4::Patroncards->draw_text Additional Information: Line wrap regexp failed. (Please file in this information in a bug report at http://bugs.koha-community.org', $line) and last WRAP_LINES if !$1; $trim = $1 . $trim; #Sanitize the input into this regular expression so regex metacharacters are escaped as literal values (https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22429) - $line =~ s/\Q$1\E//; + $line =~ s/\Q$1\E$//; $string_width = C4::Creators::PDF->StrWidth($line, $text_attribs->{'font'}, $text_attribs->{'font_size'}); # $font_units_width = $m->string_width($line); # $string_width = ($font_units_width * $text_attribs->{'font_size'}) / $units_per_em; -- 2.39.5