package SL::ReportGenerator;
+use Encode;
use IO::Wrap;
use List::Util qw(max);
use Text::CSV_XS;
return $_[0] * 72 / 2.54;
}
+sub _decode_text {
+ my $self = shift;
+ my $text = shift;
+
+ $text = decode('UTF-8', $text) if ($self->{text_is_utf8});
+
+ return $text;
+}
+
sub generate_pdf_content {
eval {
require PDF::API2;
my $num_columns = scalar @visible_columns;
my $num_header_rows = 1;
+ my $font_encoding = $main::dbcharset || 'ISO-8859-15';
+ $self->{text_is_utf8} = $font_encoding =~ m/^utf-?8$/i;
+
foreach $name (@visible_columns) {
push @column_props, { 'justify' => $self->{columns}->{$name}->{align} eq 'right' ? 'right' : 'left' };
}
foreach $name (@visible_columns) {
$column = $self->{columns}->{$name};
- push @{ $data_row }, $column->{text};
+ push @{ $data_row }, $self->_decode_text($column->{text});
push @{ $cell_props_row }, {};
}
push @cell_props, $cell_props_row;
foreach my $custom_header_col (@{ $custom_header_row }) {
- push @{ $data_row }, $custom_header_col->{text};
+ push @{ $data_row }, $self->_decode_text($custom_header_col->{text});
my $num_output = ($custom_header_col->{colspan} * 1 > 1) ? $custom_header_col->{colspan} : 1;
if ($num_output > 1) {
foreach my $row_set (@{ $self->{data} }) {
if ('HASH' eq ref $row_set) {
if ($row_set->{type} eq 'colspan_data') {
- push @data, [ $row_set->{data} ];
+ push @data, [ $self->_decode_text($row_set->{data}) ];
$cell_props_row = [];
push @cell_props, $cell_props_row;
my $col_idx = 0;
foreach my $col_name (@visible_columns) {
my $col = $row->{$col_name};
- push @{ $data_row }, join("\n", @{ $col->{data} });
+ push @{ $data_row }, $self->_decode_text(join("\n", @{ $col->{data} }));
$column_props[$col_idx]->{justify} = 'right' if ($col->{align} eq 'right');
$pdf->mediabox($paper_width, $paper_height);
my $font = $pdf->corefont(defined $pdfopts->{font_name} && $supported_fonts{lc $pdfopts->{font_name}} ? ucfirst $pdfopts->{font_name} : 'Verdana',
- '-encoding' => $main::dbcharset || 'ISO-8859-15');
+ '-encoding' => $font_encoding);
my $font_size = $pdfopts->{font_size} || 7;
my $title_font_size = $font_size + 1;
my $padding = 1;
my $top_text_height = 0;
if ($self->{options}->{top_info_text}) {
- my $top_text = $self->{options}->{top_info_text};
+ my $top_text = $self->_decode_text($self->{options}->{top_info_text});
$top_text =~ s/\r//g;
$top_text =~ s/\n+$//;
my $curpage = $pdf->openpage($page_num);
if ($pdfopts->{number}) {
- my $label = $main::locale->text("Page #1/#2", $page_num, $pdf->pages());
+ my $label = $self->_decode_text($main::locale->text("Page #1/#2", $page_num, $pdf->pages()));
my $text_obj = $curpage->text();
$text_obj->font($font, $font_size);
}
if ($opts->{title}) {
+ my $title = $self->_decode_text($opts->{title});
my $text_obj = $curpage->text();
$text_obj->font($font, $title_font_size);
- $text_obj->translate(($paper_width - $margin_left - $margin_right) / 2 + $margin_left - $text_obj->advancewidth($opts->{title}) / 2,
+ $text_obj->translate(($paper_width - $margin_left - $margin_right) / 2 + $margin_left - $text_obj->advancewidth($title) / 2,
$paper_height - $margin_top);
- $text_obj->text($opts->{title}, '-underline' => 1);
+ $text_obj->text($title, '-underline' => 1);
}
}