From 4f4f23e4fd4d1354651b816a09e428eb30b85a32 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 19 Jul 2012 23:57:28 +0200 Subject: [PATCH] Bug 8375 - use truetype fonts in PDF::Reuse 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 which are included in koha-conf.xml under new section. Without this directive in kona-conf.xml code will still use latin-1 built-in pdf fonts. --- C4/Creators/PDF.pm | 15 +++++++++++++-- etc/koha-conf.xml | 16 ++++++++++++++++ labels/label-create-pdf.pl | 7 +++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/C4/Creators/PDF.pm b/C4/Creators/PDF.pm index 871e32b..14bc9c4 100644 --- a/C4/Creators/PDF.pm +++ b/C4/Creators/PDF.pm @@ -22,6 +22,7 @@ use warnings; use PDF::Reuse; use PDF::Reuse::Barcode; use File::Temp; +use List::Util qw/first/; BEGIN { use version; our $VERSION = qv('3.07.00.049'); @@ -55,8 +56,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,6 +112,17 @@ sub Field { sub Font { my $self = shift; my $fontName = shift; + + my $ttf = C4::Context->config('ttf'); + + if ( $ttf ) { + my $ttf_path = first { $_->{type} eq $fontName } @{ $ttf->{font} }; + if ( -e $ttf_path->{content} ) { + return prTTFont($ttf_path->{content}); + } else { + warn "ERROR in koha-conf.xml -- missing /path/to/font.ttf"; + } + } return prFont($fontName); } diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml index ad7bce7..40bae9c 100644 --- a/etc/koha-conf.xml +++ b/etc/koha-conf.xml @@ -294,5 +294,21 @@ __PAZPAR2_TOGGLE_XML_POST__ __BIB_INDEX_MODE__ __AUTH_INDEX_MODE__ __KOHA_CONF_DIR__/searchengine/queryparser.yaml + + + + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-Bold.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-Italic.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-BoldItalic.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Bold.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Oblique.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-BoldOblique.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-BoldOblique.ttf + + 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