Revision cc042e07
Von Sven Schöling vor mehr als 14 Jahren hinzugefügt
SL/ReportGenerator.pm | ||
---|---|---|
1 | 1 |
package SL::ReportGenerator; |
2 | 2 |
|
3 | 3 |
use Data::Dumper; |
4 |
use Encode; |
|
5 | 4 |
use IO::Wrap; |
6 | 5 |
use List::Util qw(max); |
7 | 6 |
use Text::CSV_XS; |
8 |
use Text::Iconv; |
|
9 | 7 |
#use PDF::API2; # these two eat up to .75s on startup. only load them if we actually need them |
10 | 8 |
#use PDF::Table; |
11 | 9 |
|
... | ... | |
235 | 233 |
my $filename = $self->get_attachment_basename(); |
236 | 234 |
print qq|content-type: text/csv\n|; |
237 | 235 |
print qq|content-disposition: attachment; filename=${filename}.csv\n\n|; |
238 |
$self->generate_csv_content(); |
|
236 |
$::locale->with_raw_io(\*STDOUT, sub { |
|
237 |
$self->generate_csv_content(); |
|
238 |
}); |
|
239 | 239 |
|
240 | 240 |
} elsif ($format eq 'pdf') { |
241 | 241 |
$self->generate_pdf_content(); |
... | ... | |
410 | 410 |
return $_[0] * 72 / 2.54; |
411 | 411 |
} |
412 | 412 |
|
413 |
sub _decode_text { |
|
414 |
my $self = shift; |
|
415 |
my $text = shift; |
|
416 |
|
|
417 |
$text = decode('UTF-8', $text) if ($self->{text_is_utf8}); |
|
418 |
|
|
419 |
return $text; |
|
420 |
} |
|
421 |
|
|
422 | 413 |
sub generate_pdf_content { |
423 | 414 |
eval { |
424 | 415 |
require PDF::API2; |
... | ... | |
440 | 431 |
my $num_columns = scalar @visible_columns; |
441 | 432 |
my $num_header_rows = 1; |
442 | 433 |
|
443 |
my $font_encoding = $main::dbcharset || 'ISO-8859-15'; |
|
444 |
$self->{text_is_utf8} = $font_encoding =~ m/^utf-?8$/i; |
|
434 |
my $font_encoding = $main::dbcharset || 'ISO-8859-15'; |
|
445 | 435 |
|
446 | 436 |
foreach my $name (@visible_columns) { |
447 | 437 |
push @column_props, { 'justify' => $self->{columns}->{$name}->{align} eq 'right' ? 'right' : 'left' }; |
... | ... | |
456 | 446 |
foreach my $name (@visible_columns) { |
457 | 447 |
my $column = $self->{columns}->{$name}; |
458 | 448 |
|
459 |
push @{ $data_row }, $self->_decode_text($column->{text});
|
|
449 |
push @{ $data_row }, $column->{text};
|
|
460 | 450 |
push @{ $cell_props_row }, {}; |
461 | 451 |
} |
462 | 452 |
|
... | ... | |
470 | 460 |
push @cell_props, $cell_props_row; |
471 | 461 |
|
472 | 462 |
foreach my $custom_header_col (@{ $custom_header_row }) { |
473 |
push @{ $data_row }, $self->_decode_text($custom_header_col->{text});
|
|
463 |
push @{ $data_row }, $custom_header_col->{text};
|
|
474 | 464 |
|
475 | 465 |
my $num_output = ($custom_header_col->{colspan} * 1 > 1) ? $custom_header_col->{colspan} : 1; |
476 | 466 |
if ($num_output > 1) { |
... | ... | |
488 | 478 |
foreach my $row_set (@{ $self->{data} }) { |
489 | 479 |
if ('HASH' eq ref $row_set) { |
490 | 480 |
if ($row_set->{type} eq 'colspan_data') { |
491 |
push @data, [ $self->_decode_text($row_set->{data}) ];
|
|
481 |
push @data, [ $row_set->{data} ];
|
|
492 | 482 |
|
493 | 483 |
$cell_props_row = []; |
494 | 484 |
push @cell_props, $cell_props_row; |
... | ... | |
512 | 502 |
my $col_idx = 0; |
513 | 503 |
foreach my $col_name (@visible_columns) { |
514 | 504 |
my $col = $row->{$col_name}; |
515 |
push @{ $data_row }, $self->_decode_text(join("\n", @{ $col->{data} || [] }));
|
|
505 |
push @{ $data_row }, join("\n", @{ $col->{data} || [] });
|
|
516 | 506 |
|
517 | 507 |
$column_props[$col_idx]->{justify} = 'right' if ($col->{align} eq 'right'); |
518 | 508 |
|
... | ... | |
583 | 573 |
my $top_text_height = 0; |
584 | 574 |
|
585 | 575 |
if ($self->{options}->{top_info_text}) { |
586 |
my $top_text = $self->_decode_text($self->{options}->{top_info_text});
|
|
576 |
my $top_text = $self->{options}->{top_info_text};
|
|
587 | 577 |
$top_text =~ s/\r//g; |
588 | 578 |
$top_text =~ s/\n+$//; |
589 | 579 |
|
... | ... | |
631 | 621 |
my $curpage = $pdf->openpage($page_num); |
632 | 622 |
|
633 | 623 |
if ($pdfopts->{number}) { |
634 |
my $label = $self->_decode_text($main::locale->text("Page #1/#2", $page_num, $pdf->pages()));
|
|
624 |
my $label = $main::locale->text("Page #1/#2", $page_num, $pdf->pages());
|
|
635 | 625 |
my $text_obj = $curpage->text(); |
636 | 626 |
|
637 | 627 |
$text_obj->font($font, $font_size); |
... | ... | |
640 | 630 |
} |
641 | 631 |
|
642 | 632 |
if ($opts->{title}) { |
643 |
my $title = $self->_decode_text($opts->{title});
|
|
633 |
my $title = $opts->{title};
|
|
644 | 634 |
my $text_obj = $curpage->text(); |
645 | 635 |
|
646 | 636 |
$text_obj->font($font, $title_font_size); |
... | ... | |
671 | 661 |
print qq|content-type: application/pdf\n|; |
672 | 662 |
print qq|content-disposition: attachment; filename=${filename}.pdf\n\n|; |
673 | 663 |
|
674 |
print $content; |
|
664 |
$::locale->with_raw_io(\*STDOUT, sub { |
|
665 |
print $content; |
|
666 |
}); |
|
675 | 667 |
} |
676 | 668 |
} |
677 | 669 |
|
... | ... | |
700 | 692 |
sub unescape_string { |
701 | 693 |
my $self = shift; |
702 | 694 |
my $text = shift; |
703 |
my $iconv = $main::locale->{iconv}; |
|
704 | 695 |
|
705 | 696 |
$text = $main::locale->unquote_special_chars('HTML', $text); |
706 |
$text = $main::locale->{iconv}->convert($text) if ($main::locale->{iconv});
|
|
697 |
$text = $::locale->{iconv}->convert($text);
|
|
707 | 698 |
|
708 | 699 |
return $text; |
709 | 700 |
} |
Auch abrufbar als: Unified diff
UTF8-Flags setzen/beachten
Conflicts: