From bd8bde72013e4a13524330c79a81abfcb073341f Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 19 Jul 2012 23:57:28 +0200 Subject: [PATCH] use truetype fonts in PDF::Reuse Content-Type: text/plain; charset="utf-8" Since built-in PDF fonts suport just latin-1 encoding, we have to switch to truetype fonts to correctly encode all utf-8 characters (which we should be getting from database anyway). This approach also nicely sidesteps our encoding cludges, but requires paths to truetype fonts, so this example has single path hard-coded. I don't know if it's better to put font path into koha-conf.xml or can we somehow get it from system. I did try to figure out if fc-list can display paths, but failed. http://bugs.koha-community.org/show_bug.cgi?id=8375 Signed-off-by: Mirko Tietgen --- C4/Creators/PDF.pm | 11 ++++++++--- labels/label-create-pdf.pl | 7 +++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/C4/Creators/PDF.pm b/C4/Creators/PDF.pm index 871e32b..f90fb91 100644 --- a/C4/Creators/PDF.pm +++ b/C4/Creators/PDF.pm @@ -55,8 +55,7 @@ sub new { sub End { my $self = shift; - # if the pdf stream is utf8, explicitly set it to utf8; this avoids at lease some wide character errors -chris_n - utf8::encode($PDF::Reuse::stream) if utf8::is_utf8($PDF::Reuse::stream); + prEnd(); # slurp temporary filename and print it out for plack to pick up @@ -112,7 +111,13 @@ sub Field { sub Font { my $self = shift; my $fontName = shift; - return prFont($fontName); + my $ttf_path = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf'; + if ( -e $ttf_path ) { + warn "# using ttf_path $ttf_path"; + return prTTFont($ttf_path); + } else { + return prFont($fontName); + } } sub FontSize { diff --git a/labels/label-create-pdf.pl b/labels/label-create-pdf.pl index 3d7ff1f..e23b068 100755 --- a/labels/label-create-pdf.pl +++ b/labels/label-create-pdf.pl @@ -88,10 +88,9 @@ sub _calc_next_label_pos { sub _print_text { my $label_text = shift; foreach my $text_line (@$label_text) { - my $pdf_font = $pdf->Font($text_line->{'font'}); - my $line = "BT /$pdf_font $text_line->{'font_size'} Tf $text_line->{'text_llx'} $text_line->{'text_lly'} Td ($text_line->{'line'}) Tj ET"; - utf8::decode($line); - $pdf->Add($line); + $pdf->Font($text_line->{'font'}); + $pdf->FontSize( $text_line->{'font_size'} ); + $pdf->Text( $text_line->{'text_llx'}, $text_line->{'text_lly'}, $text_line->{'line'} ); } } -- 1.7.2.5