Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 389007ac

Von Moritz Bunkus vor mehr als 16 Jahren hinzugefügt

  • ID 389007ac0512ed52a2a9bf1bf46f680b5fbb7f57
  • Vorgänger b7bb9320
  • Nachfolger 5b0ec556

Wenn UTF-8 als Datenbankcharset verwendet wird, so muss der ReportGenerator die an PDF::API2 übergebenen Strings als UTF-8 markieren (mit Perls Encode-Modul).

Unterschiede anzeigen:

SL/ReportGenerator.pm
1 1
package SL::ReportGenerator;
2 2

  
3
use Encode;
3 4
use IO::Wrap;
4 5
use List::Util qw(max);
5 6
use Text::CSV_XS;
......
406 407
  return $_[0] * 72 / 2.54;
407 408
}
408 409

  
410
sub _decode_text {
411
  my $self = shift;
412
  my $text = shift;
413

  
414
  $text    = decode('UTF-8', $text) if ($self->{text_is_utf8});
415

  
416
  return $text;
417
}
418

  
409 419
sub generate_pdf_content {
410 420
  eval {
411 421
    require PDF::API2;
......
427 437
  my $num_columns     = scalar @visible_columns;
428 438
  my $num_header_rows = 1;
429 439

  
440
  my $font_encoding     = $main::dbcharset || 'ISO-8859-15';
441
  $self->{text_is_utf8} = $font_encoding =~ m/^utf-?8$/i;
442

  
430 443
  foreach $name (@visible_columns) {
431 444
    push @column_props, { 'justify' => $self->{columns}->{$name}->{align} eq 'right' ? 'right' : 'left' };
432 445
  }
......
440 453
    foreach $name (@visible_columns) {
441 454
      $column = $self->{columns}->{$name};
442 455

  
443
      push @{ $data_row },       $column->{text};
456
      push @{ $data_row },       $self->_decode_text($column->{text});
444 457
      push @{ $cell_props_row }, {};
445 458
    }
446 459

  
......
454 467
      push @cell_props, $cell_props_row;
455 468

  
456 469
      foreach my $custom_header_col (@{ $custom_header_row }) {
457
        push @{ $data_row }, $custom_header_col->{text};
470
        push @{ $data_row }, $self->_decode_text($custom_header_col->{text});
458 471

  
459 472
        my $num_output  = ($custom_header_col->{colspan} * 1 > 1) ? $custom_header_col->{colspan} : 1;
460 473
        if ($num_output > 1) {
......
472 485
  foreach my $row_set (@{ $self->{data} }) {
473 486
    if ('HASH' eq ref $row_set) {
474 487
      if ($row_set->{type} eq 'colspan_data') {
475
        push @data, [ $row_set->{data} ];
488
        push @data, [ $self->_decode_text($row_set->{data}) ];
476 489

  
477 490
        $cell_props_row = [];
478 491
        push @cell_props, $cell_props_row;
......
496 509
      my $col_idx = 0;
497 510
      foreach my $col_name (@visible_columns) {
498 511
        my $col = $row->{$col_name};
499
        push @{ $data_row }, join("\n", @{ $col->{data} });
512
        push @{ $data_row }, $self->_decode_text(join("\n", @{ $col->{data} }));
500 513

  
501 514
        $column_props[$col_idx]->{justify} = 'right' if ($col->{align} eq 'right');
502 515

  
......
554 567
  $pdf->mediabox($paper_width, $paper_height);
555 568

  
556 569
  my $font              = $pdf->corefont(defined $pdfopts->{font_name} && $supported_fonts{lc $pdfopts->{font_name}} ? ucfirst $pdfopts->{font_name} : 'Verdana',
557
                                         '-encoding' => $main::dbcharset || 'ISO-8859-15');
570
                                         '-encoding' => $font_encoding);
558 571
  my $font_size         = $pdfopts->{font_size} || 7;
559 572
  my $title_font_size   = $font_size + 1;
560 573
  my $padding           = 1;
......
567 580
  my $top_text_height   = 0;
568 581

  
569 582
  if ($self->{options}->{top_info_text}) {
570
    my $top_text     =  $self->{options}->{top_info_text};
583
    my $top_text     =  $self->_decode_text($self->{options}->{top_info_text});
571 584
    $top_text        =~ s/\r//g;
572 585
    $top_text        =~ s/\n+$//;
573 586

  
......
614 627
    my $curpage  = $pdf->openpage($page_num);
615 628

  
616 629
    if ($pdfopts->{number}) {
617
      my $label    = $main::locale->text("Page #1/#2", $page_num, $pdf->pages());
630
      my $label    = $self->_decode_text($main::locale->text("Page #1/#2", $page_num, $pdf->pages()));
618 631
      my $text_obj = $curpage->text();
619 632

  
620 633
      $text_obj->font($font, $font_size);
......
623 636
    }
624 637

  
625 638
    if ($opts->{title}) {
639
      my $title    = $self->_decode_text($opts->{title});
626 640
      my $text_obj = $curpage->text();
627 641

  
628 642
      $text_obj->font($font, $title_font_size);
629
      $text_obj->translate(($paper_width - $margin_left - $margin_right) / 2 + $margin_left - $text_obj->advancewidth($opts->{title}) / 2,
643
      $text_obj->translate(($paper_width - $margin_left - $margin_right) / 2 + $margin_left - $text_obj->advancewidth($title) / 2,
630 644
                           $paper_height - $margin_top);
631
      $text_obj->text($opts->{title}, '-underline' => 1);
645
      $text_obj->text($title, '-underline' => 1);
632 646
    }
633 647
  }
634 648

  

Auch abrufbar als: Unified diff