+ # $row_h is the calculated global user requested row height.
+ # It will be honored, only if it has bigger value than the calculated one.
+ # TODO: It's questionable if padding should be inclided in this calculation or not
+ if($current_row_height < $row_h){
+ $current_row_height = $row_h;
+ }
+
+ # Define the font y base position for this line.
+ $text_start = $cur_y - ($current_row_height - $pad_bot);
+
+ my $cur_x = $xbase;
+ my $leftovers = undef; # Reference to text that is returned from textblock()
+ my $do_leftovers = 0;
+ my ($colspan, @vertical_lines);
+
+ # Process every cell(column) from current row
+ for( my $column_idx = 0; $column_idx < scalar( @$record); $column_idx++ )
+ {
+ next unless $col_props->[$column_idx]->{'max_w'};
+ next unless $col_props->[$column_idx]->{'min_w'};
+ $leftovers->[$column_idx] = undef;
+
+ # look for font information for this cell
+ my ($cell_font, $cell_font_size, $cell_font_color, $cell_font_underline, $justify);
+
+ if( $remaining_header_rows and ref $header_props)
+ {
+ $cell_font = $header_props->{'font'};
+ $cell_font_size = $header_props->{'font_size'};
+ $cell_font_color = $header_props->{'font_color'};
+ $cell_font_underline = $header_props->{'font_underline'};
+ $justify = $header_props->{'justify'};
+ }
+
+ # Get the most specific value if none was already set from header_props
+ $cell_font ||= $cell_props->[$row_index][$column_idx]->{'font'}
+ || $col_props->[$column_idx]->{'font'}
+ || $fnt_name;
+
+ $cell_font_size ||= $cell_props->[$row_index][$column_idx]->{'font_size'}
+ || $col_props->[$column_idx]->{'font_size'}
+ || $fnt_size;
+
+ $cell_font_color ||= $cell_props->[$row_index][$column_idx]->{'font_color'}
+ || $col_props->[$column_idx]->{'font_color'}
+ || $font_color;
+
+ $cell_font_underline ||= $cell_props->[$row_index][$column_idx]->{'font_underline'}
+ || $col_props->[$column_idx]->{'font_underline'}
+ || $fnt_underline;
+
+
+ $justify ||= $cell_props->[$row_index][$column_idx]->{'justify'}
+ || $col_props->[$column_idx]->{'justify'}
+ || $arg{'justify'}
+ || 'left';
+
+ # Init cell font object
+ $txt->font( $cell_font, $cell_font_size );
+ $txt->fillcolor($cell_font_color);
+
+ # Added to resolve infite loop bug with returned undef values
+ $record->[$column_idx] //= $cell_props->[$row_index][$column_idx]->{'default_text'}
+ // $col_props->[$column_idx]->{'default_text'}
+ // $default_text;
+
+ my $this_width;
+ if (!$remaining_header_rows && $cell_props->[$row_index + $header_props->{num_header_rows}][$column_idx]->{colspan}) {
+ $colspan = $cell_props->[$row_index + $header_props->{num_header_rows}][$column_idx]->{colspan};
+ } elsif ($remaining_header_rows && ($header_row_cell_props[$header_props->{num_header_rows} - $remaining_header_rows][$column_idx]->{colspan})) {
+ $colspan = $header_row_cell_props[$header_props->{num_header_rows} - $remaining_header_rows][$column_idx]->{colspan};
+ }
+
+ if ($colspan) {
+ $colspan = $num_cols - $column_idx if (-1 == $colspan);
+ my $last_idx = $column_idx + $colspan - 1;
+ $this_width = sum @{ $calc_column_widths }[$column_idx..$last_idx];
+ } else {
+ $this_width = $calc_column_widths->[$column_idx];
+ }
+
+ # If the content is wider than the specified width, we need to add the text as a text block
+ if( $record->[$column_idx] !~ m/(.\n.)/ and
+ $record_widths->[$column_idx] and
+ $record_widths->[$column_idx] <= $this_width
+ ){
+ my $space = $pad_left;
+ if ($justify eq 'right')
+ {
+ $space = $this_width -($txt->advancewidth($record->[$column_idx]) + $pad_right);
+ }
+ elsif ($justify eq 'center')
+ {
+ $space = ($this_width - $txt->advancewidth($record->[$column_idx])) / 2;
+ }
+ $txt->translate( $cur_x + $space, $text_start );
+ my %text_options;
+ $text_options{'-underline'} = $cell_font_underline if $cell_font_underline;
+ $txt->text( $record->[$column_idx], %text_options );
+ }
+ # Otherwise just use the $page->text() method
+ else
+ {
+ my ($width_of_last_line, $ypos_of_last_line, $left_over_text) = $self->text_block(
+ $txt,
+ $record->[$column_idx],
+ x => $cur_x + $pad_left,
+ y => $text_start,
+ w => $this_width - $pad_left - $pad_right,
+ h => $cur_y - $bot_marg - $pad_top - $pad_bot,
+ align => $justify,
+ lead => $lead
+ );
+ # Desi - Removed $lead because of fixed incorrect ypos bug in text_block
+ my $current_cell_height = $cur_y - $ypos_of_last_line + $pad_bot;
+ if( $current_cell_height > $current_row_height )
+ {
+ $current_row_height = $current_cell_height;
+ }
+
+ if( $left_over_text )
+ {
+ $leftovers->[$column_idx] = $left_over_text;
+ $do_leftovers = 1;
+ }
+ }
+
+ # Hook to pass coordinates back - http://www.perlmonks.org/?node_id=754777
+ if (ref $arg{cell_render_hook} eq 'CODE') {
+ $arg{cell_render_hook}->(
+ $page,
+ $first_row,
+ $row_index,
+ $column_idx,
+ $cur_x,
+ $cur_y-$row_h,
+ $calc_column_widths->[$column_idx],
+ $row_h
+ );
+ }
+
+ $cur_x += $calc_column_widths->[$column_idx];
+
+ push @vertical_lines, (!$colspan || (1 >= $colspan)) ? 1 : 0;
+ $colspan-- if $colspan;
+ }
+ if( $do_leftovers )
+ {
+ unshift @$data, $leftovers;
+ unshift @$row_col_widths, $record_widths;
+ unshift @$rows_height, $pre_calculated_row_height;
+ }
+
+ # Draw cell bgcolor
+ # This has to be separately from the text loop
+ # because we do not know the final height of the cell until all text has been drawn
+ $cur_x = $xbase;
+ for(my $column_idx = 0 ; $column_idx < scalar(@$record) ; $column_idx++)
+ {
+ my $cell_bg_color;
+
+ if( $remaining_header_rows and ref $header_props)
+ { #Compatibility Consistency with other props
+ $cell_bg_color = $header_props->{'bg_color'} || $header_props->{'background_color'};
+ }
+
+ # Get the most specific value if none was already set from header_props
+ $cell_bg_color ||= $cell_props->[$row_index + $header_props->{num_header_rows}][$column_idx]->{'background_color'}
+ || $col_props->[$column_idx]->{'background_color'}
+ || $background_color;
+
+ if ($cell_bg_color)
+ {
+ $gfx_bg->rect( $cur_x, $cur_y-$current_row_height, $calc_column_widths->[$column_idx], $current_row_height);
+ $gfx_bg->fillcolor($cell_bg_color);
+ $gfx_bg->fill();
+ }
+ $cur_x += $calc_column_widths->[$column_idx];
+
+ if ($line_w && $vertical_lines[$column_idx] && ($column_idx != (scalar(@{ $record }) - 1))) {
+ $gfx->move($cur_x, $cur_y);
+ $gfx->vline($cur_y - $current_row_height);
+ $gfx->fillcolor($border_color);
+ }
+ }#End of for(my $column_idx....
+
+ $cur_y -= $current_row_height;
+ if ($gfx && $horiz_borders)
+ {
+ $gfx->move( $xbase , $cur_y );
+ $gfx->hline( $xbase + $width );
+ }