From f7ef93e758850e991091e7268b8d1b1453082df4 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 6 May 2014 18:52:12 +0000 Subject: [PATCH] Bug 8375: (follow-up) adjust StrWidth to account for TTF fonts This patch fixes an issue caught by the test case where StrWidth() based its calculations on the internal Adobe font rather than a TrueType font in use. Signed-off-by: Galen Charlton --- C4/Creators/PDF.pm | 12 ++++++++++++ t/Creators.t | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/C4/Creators/PDF.pm b/C4/Creators/PDF.pm index 14bc9c4033..738c34ffc6 100644 --- a/C4/Creators/PDF.pm +++ b/C4/Creators/PDF.pm @@ -308,6 +308,18 @@ sub SinglePage { sub StrWidth { my $self = shift; my ($string, $font, $fontSize) = @_; + + # replace font code with path to TTF font file if need be + my $ttf = C4::Context->config('ttf'); + if ( $ttf ) { + my $ttf_path = first { $_->{type} eq $font } @{ $ttf->{font} }; + if ( -e $ttf_path->{content} ) { + $font = $ttf_path->{content}; + } else { + warn "ERROR in koha-conf.xml -- missing /path/to/font.ttf"; + } + } + return prStrWidth($string, $font, $fontSize); } diff --git a/t/Creators.t b/t/Creators.t index 85701c2c90..899ff33070 100755 --- a/t/Creators.t +++ b/t/Creators.t @@ -34,11 +34,11 @@ $pdf_creator->FontSize(); # Reset font size before testing text width etc below ok($pdf_creator->Page(), "testing Page() works"); -is($pdf_creator->StrWidth("test", "H", 12), '19.344', "testing StrWidth() returns correct point width"); +is($pdf_creator->StrWidth("test", "H", 12), '23.044921875', "testing StrWidth() returns correct point width"); @result = $pdf_creator->Text(10, 10, "test"); is($result[0], '10', "testing Text() writes from a given x-value"); -is($result[1], '29.344', "testing Text() writes to the correct x-value"); +is($result[1], '33.044921875', "testing Text() writes to the correct x-value"); open(my $fh, '>', 'test.pdf'); select $fh; -- 2.39.5