From 0a58bfe65516d8a14417daa6162dc06902a5ef3b Mon Sep 17 00:00:00 2001 From: Karam Qubsi Date: Thu, 29 Dec 2016 16:55:31 +0000 Subject: [PATCH] Bug 12832-Basketgroup printing and non-latin chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch will use DejaVuSans.ttf font instead of Times and this will support the non-Latin characters I tested it with Greek text and Arabic text and it worked for Arabic texts I added Text::Bidi to support direction of text until now the arabic text characters appears but not connected as it should be . Test plan : Create a basket group with metadata that include non-latin characters close and export the group the titles will not appear . apply the patch re export the pdf file , you should find the text appear for the items I used google translate to get Greek text you might use it as will Title : αυτό είναι ένα τίτλο ενός βιβλίου Author : συγγραφέας Arabic : Title : عنوان بالعربي author : مؤلف --- acqui/pdfformat/layout3pages.pm | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/acqui/pdfformat/layout3pages.pm b/acqui/pdfformat/layout3pages.pm index e91d1e6..0b96de3 100644 --- a/acqui/pdfformat/layout3pages.pm +++ b/acqui/pdfformat/layout3pages.pm @@ -28,6 +28,7 @@ use List::MoreUtils qw/uniq/; use strict; use warnings; use utf8; +use Text::Bidi qw(log2vis); use Koha::Number::Price; use Koha::DateUtils; @@ -54,7 +55,7 @@ use PDF::Table; sub printorders { my ($pdf, $basketgroup, $baskets, $orders) = @_; - + my $cur_format = C4::Context->preference("CurrencyFormat"); $pdf->mediabox($height/mm, $width/mm); @@ -69,7 +70,7 @@ sub printorders { $box->rectxy(($width - 10)/mm, ($height - 5)/mm, 10/mm, ($height - 25)/mm); $box->stroke; # $box->restore(); - + # create a text my $text = $page->text; # add basketgroup number @@ -114,8 +115,9 @@ sub printorders { ( $line->{publishercode} ? ' published by '. $line->{publishercode} : '') . ( $line->{copyrightdate} ? ' '. $line->{copyrightdate} : ''); } + $titleinfo = log2vis($titleinfo); push( @$arrbasket, - $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor : " . $line->{order_vendornote} : '' ), + $titleinfo. ($line->{order_vendornote} ? "\n----------------\nNote for vendor : " . $line->{order_vendornote} : '' ), $line->{quantity}, Koha::Number::Price->new( $line->{rrp_tax_excluded} )->format, Koha::Number::Price->new( $line->{rrp_tax_included} )->format, @@ -138,7 +140,7 @@ sub printorders { padding => 5, padding_right => 5, background_color_odd => "lightgray", - font => $pdf->corefont("Times", -encoding => "utf8"), + font => $pdf->ttfont('/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf', -encoding => "utf8"), font_size => 3/mm, header_props => { font => $pdf->corefont("Times", -encoding => "utf8"), @@ -182,17 +184,17 @@ sub printorders { sub printbaskets { my ($pdf, $basketgroup, $hbaskets, $bookseller, $GSTrate, $orders) = @_; - + # get library name my $libraryname = C4::Context->preference("LibraryName"); - + my $cur_format = C4::Context->preference("CurrencyFormat"); $pdf->mediabox($width/mm, $height/mm); my $page = $pdf->openpage(2); # create a text my $text = $page->text; - + # add basketgroup number $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); $text->translate(($width-40)/mm, ($height-53)/mm); @@ -318,10 +320,10 @@ sub printhead { # open 1st page (with the header) my $page = $pdf->openpage(1); - + # create a text my $text = $page->text; - + # print the libraryname in the header $text->font( $pdf->corefont("Times", -encoding => "utf8"), 6/mm ); $text->translate(30/mm, ($height-28.5)/mm); @@ -331,14 +333,14 @@ sub printhead { $text->font( $pdf->corefont("Times", -encoding => "utf8"), 8/mm ); $text->translate(100/mm, ($height-5-48)/mm); $text->text($basketgroup->{'id'}); - + # print the date my $today = output_pref({ dt => dt_from_string, dateonly => 1 }); $text->translate(130/mm, ($height-5-48)/mm); $text->text($today); - + $text->font( $pdf->corefont("Times", -encoding => "utf8"), 4/mm ); - + # print billing infos $text->translate(100/mm, ($height-86)/mm); $text->text($libraryname); @@ -358,11 +360,11 @@ sub printhead { $text->text(join(' ', $billing_library->branchzip, $billing_library->branchcity, $billing_library->branchcountry)); $text->translate(100/mm, ($height-147.5)/mm); $text->text($billing_library->branchemail); - + # print subject $text->translate(100/mm, ($height-145.5)/mm); $text->text($subject); - + # print bookseller infos $text->translate(100/mm, ($height-180)/mm); $text->text($bookseller->{name}); @@ -376,7 +378,7 @@ sub printhead { $text->text($bookseller->{address3}); $text->translate(100/mm, ($height-205)/mm); $text->text($bookseller->{accountnumber}); - + # print delivery infos $text->font( $pdf->corefont("Times-Bold", -encoding => "utf8"), 4/mm ); $text->translate(50/mm, ($height-237)/mm); -- 2.1.4