Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 35cd4452

Von Sven Schöling vor fast 9 Jahren hinzugefügt

  • ID 35cd4452887eb2a3219816bd900e6dc5918430a6
  • Vorgänger ca2ec834
  • Nachfolger b6a82d77

Unterstützung für zellenübergreifende Überschriften im PDF-Export des ReportGenerators verbessert.

Reimplementation von d3897394

Unterschiede anzeigen:

modules/override/PDF/Table.pm
4 4
use strict;
5 5
use warnings;
6 6
use Carp;
7
use List::Util qw(sum);
7 8
our $VERSION = '0.9.10';
8 9

  
9 10
print __PACKAGE__.' is version: '.$VERSION.$/ if($ENV{'PDF_TABLE_DEBUG'});
......
536 537
    # Calc real column widths and expand table width if needed.
537 538
    my $calc_column_widths; 
538 539
    ($calc_column_widths, $width) = CalcColumnWidths( $col_props, $width );
540
    my $num_cols = scalar @{ $calc_column_widths };
539 541

  
540 542
    # Lets draw what we have!
541 543
    my $row_index    = 0;
......
587 589
        # Check for safety reasons
588 590
        if( $bot_marg < 0 )
589 591
        {   # This warning should remain i think
590
            carp "!!! Warning: !!! Incorrect Table Geometry! Setting bottom margin to end of sheet!\n";
592
#            carp "!!! Warning: !!! Incorrect Table Geometry! Setting bottom margin to end of sheet!\n";
591 593
            $bot_marg = 0;
592 594
        }
593 595

  
......
664 666
            my $cur_x        = $xbase;
665 667
            my $leftovers    = undef;   # Reference to text that is returned from textblock()
666 668
            my $do_leftovers = 0;
669
            my ($colspan, @vertical_lines);
667 670

  
668 671
            # Process every cell(column) from current row
669 672
            for( my $column_idx = 0; $column_idx < scalar( @$record); $column_idx++ ) 
......
704 707
                # Init cell font object
705 708
                $txt->font( $cell_font, $cell_font_size );
706 709
                $txt->fillcolor($cell_font_color);
710

  
711
                my $this_width;
712
                if (!$first_row && $cell_props->[$row_index][$column_idx]->{colspan}) {
713
                    $colspan     = -1 == $cell_props->[$row_index][$column_idx]->{colspan} 
714
                                 ? $num_cols - $column_idx
715
                                 : $cell_props->[$row_index][$column_idx]->{colspan};
716
                    my $last_idx = $column_idx + $colspan - 1;
717
                    $this_width  = sum @{ $calc_column_widths }[$column_idx..$last_idx];
718

  
719
                } else {
720
                    $this_width = $calc_column_widths->[$column_idx];
721
                }
707 722
 
708 723
                # If the content is wider than the specified width, we need to add the text as a text block
709 724
                if( $record->[$column_idx] !~ m/(.\n.)/ and
710 725
                    $record_widths->[$column_idx] and 
711
                    $record_widths->[$column_idx] <= $calc_column_widths->[$column_idx]
726
                    $record_widths->[$column_idx] <= $this_width
712 727
                ){
713 728
                    my $space = $pad_left;
714 729
                    if ($justify eq 'right')
715 730
                    {
716
                        $space = $calc_column_widths->[$column_idx] -($txt->advancewidth($record->[$column_idx]) + $pad_right);
731
                        $space = $this_width -($txt->advancewidth($record->[$column_idx]) + $pad_right);
717 732
                    }
718 733
                    elsif ($justify eq 'center')
719 734
                    {
720
                        $space = ($calc_column_widths->[$column_idx] - $txt->advancewidth($record->[$column_idx])) / 2;
735
                        $space = ($this_width - $txt->advancewidth($record->[$column_idx])) / 2;
721 736
                    }
722 737
                    $txt->translate( $cur_x + $space, $text_start );
723 738
                    $txt->text( $record->[$column_idx] );
......
730 745
                        $record->[$column_idx],
731 746
                        x        => $cur_x + $pad_left,
732 747
                        y        => $text_start,
733
                        w        => $calc_column_widths->[$column_idx] - $pad_left - $pad_right,
748
                        w        => $this_width - $pad_left - $pad_right,
734 749
                        h        => $cur_y - $bot_marg - $pad_top - $pad_bot,
735 750
                        align    => $justify,
736 751
                        lead     => $lead
......
749 764
                    }
750 765
                }
751 766
                $cur_x += $calc_column_widths->[$column_idx];
767

  
768
                push @vertical_lines, (!$colspan || (1 >= $colspan)) ? 1 : 0;
769
                $colspan-- if $colspan;
752 770
            }
753 771
            if( $do_leftovers )
754 772
            {
......
782 800
                    $gfx_bg->fill();
783 801
                }
784 802
                $cur_x += $calc_column_widths->[$column_idx];
803

  
804
                if ($line_w && $vertical_lines[$column_idx] && ($column_idx != (scalar(@{ $record }) - 1))) {
805
                    $gfx->move($cur_x, $cur_y);
806
                    $gfx->vline($cur_y - $row_h);
807
                    $gfx->fillcolor($border_color);
808
                }
785 809
            }#End of for(my $column_idx....
786 810

  
787 811
            $cur_y -= $current_row_height;
......
802 826
            {
803 827
                $gfx->move(  $xbase, $table_top_y);
804 828
                $gfx->vline( $cur_y );
805
                my $cur_x = $xbase;
806
                for( my $j = 0; $j < $columns_number; $j++ )
807
                {
808
                    $cur_x += $calc_column_widths->[$j];
809
                    $gfx->move(  $cur_x, $table_top_y );
810
                    $gfx->vline( $cur_y );
811
                }
829
                $gfx->move($xbase + sum(@{ $calc_column_widths }[0..$num_cols - 1]), $table_top_y);
830
                $gfx->vline( $cur_y );
812 831
            }
813 832

  
814 833
            # ACTUALLY draw all the lines

Auch abrufbar als: Unified diff