From e993fbf2056ee58c8160410de6560dc0c1143d97 Mon Sep 17 00:00:00 2001 From: Dietrich Streifert Date: Tue, 22 Sep 2020 14:23:50 +0200 Subject: [PATCH 1/2] Allow to configure the font encoding via parameter font_encoding --- lib/PDF/ReportWriter.pm | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/PDF/ReportWriter.pm b/lib/PDF/ReportWriter.pm index 363dcea..70005eb 100644 --- a/lib/PDF/ReportWriter.pm +++ b/lib/PDF/ReportWriter.pm @@ -294,25 +294,28 @@ sub parse_options # Add requested fonts $opt->{font_list} ||= $opt->{font} || [ 'Helvetica' ]; + # Requested encoding or default latin1 + $opt->{font_encoding} ||= 'latin1'; + for my $font ( @{$opt->{font_list}} ) { # Roman fonts are easy - $self->{fonts}->{$font}->{Roman} = $self->{pdf}->corefont( $font, -encoding => 'latin1'); + $self->{fonts}->{$font}->{Roman} = $self->{pdf}->corefont( $font, -encoding => $opt->{font_encoding}); # The rest are f'n ridiculous. Adobe either didn't think about this, or are just stoopid if ($font eq 'Courier') { - $self->{fonts}->{$font}->{Bold} = $self->{pdf}->corefont( "Courier-Bold", -encoding => 'latin1'); - $self->{fonts}->{$font}->{Italic} = $self->{pdf}->corefont( "Courier-Oblique", -encoding => 'latin1'); - $self->{fonts}->{$font}->{BoldItalic} = $self->{pdf}->corefont( "Courier-BoldOblique", -encoding => 'latin1'); + $self->{fonts}->{$font}->{Bold} = $self->{pdf}->corefont( "Courier-Bold", -encoding => $opt->{font_encoding}); + $self->{fonts}->{$font}->{Italic} = $self->{pdf}->corefont( "Courier-Oblique", -encoding => $opt->{font_encoding}); + $self->{fonts}->{$font}->{BoldItalic} = $self->{pdf}->corefont( "Courier-BoldOblique", -encoding => $opt->{font_encoding}); } if ($font eq 'Helvetica') { - $self->{fonts}->{$font}->{Bold} = $self->{pdf}->corefont( "Helvetica-Bold", -encoding => 'latin1'); - $self->{fonts}->{$font}->{Italic} = $self->{pdf}->corefont( "Helvetica-Oblique", -encoding => 'latin1'); - $self->{fonts}->{$font}->{BoldItalic} = $self->{pdf}->corefont( "Helvetica-BoldOblique",-encoding => 'latin1'); + $self->{fonts}->{$font}->{Bold} = $self->{pdf}->corefont( "Helvetica-Bold", -encoding => $opt->{font_encoding}); + $self->{fonts}->{$font}->{Italic} = $self->{pdf}->corefont( "Helvetica-Oblique", -encoding => $opt->{font_encoding}); + $self->{fonts}->{$font}->{BoldItalic} = $self->{pdf}->corefont( "Helvetica-BoldOblique",-encoding => $opt->{font_encoding}); } if ($font eq 'Times') { - $self->{fonts}->{$font}->{Bold} = $self->{pdf}->corefont( "Times-Bold", -encoding => 'latin1'); - $self->{fonts}->{$font}->{Italic} = $self->{pdf}->corefont( "Times-Italic", -encoding => 'latin1'); - $self->{fonts}->{$font}->{BoldItalic} = $self->{pdf}->corefont( "Times-BoldItalic", -encoding => 'latin1'); + $self->{fonts}->{$font}->{Bold} = $self->{pdf}->corefont( "Times-Bold", -encoding => $opt->{font_encoding}); + $self->{fonts}->{$font}->{Italic} = $self->{pdf}->corefont( "Times-Italic", -encoding => $opt->{font_encoding}); + $self->{fonts}->{$font}->{BoldItalic} = $self->{pdf}->corefont( "Times-BoldItalic", -encoding => $opt->{font_encoding}); } } From 5078877e033e61413bd451fe57f77bd64a658ad9 Mon Sep 17 00:00:00 2001 From: Dietrich Streifert Date: Tue, 22 Sep 2020 14:30:16 +0200 Subject: [PATCH 2/2] Add documentation for new option font_encoding --- lib/PDF/ReportWriter.pm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/PDF/ReportWriter.pm b/lib/PDF/ReportWriter.pm index 70005eb..c7a5375 100644 --- a/lib/PDF/ReportWriter.pm +++ b/lib/PDF/ReportWriter.pm @@ -4057,6 +4057,14 @@ When you include a font 'family', a range of fonts ( roman, italic, bold, etc ) =back +=head2 font_encoding + +=over 4 + +The font encoding used which defaults to 'latin1' but can be changed ot e.g. to 'utf8'. + +=back + =head2 default_font =over 4