From 8e71489c33115254a8a95be7a4b1a82b605918c9 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. Signed-off-by: Kyle M Hall Signed-off-by: Chris Nighswonger Signed-off-by: Galen Charlton --- 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 871e32bd87..14bc9c4033 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 26f53b729d..87b538a818 100644 --- a/etc/koha-conf.xml +++ b/etc/koha-conf.xml @@ -113,5 +113,21 @@ __PAZPAR2_TOGGLE_XML_POST__ __AUTH_INDEX_MODE__ __ZEBRA_LOCK_DIR__ __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 3d7ff1fc9c..e23b068462 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'} ); } } -- 2.39.5