Update LPDF to handle tables without a header row

Update LPDF to add a "..." to a table field if all of the text didnt fit in the table field
This commit is contained in:
james 2005-12-08 18:01:30 +00:00
parent b956f4c2d3
commit 668d410207
2 changed files with 31 additions and 15 deletions

View File

@ -359,14 +359,22 @@ class lpdf
function addTable($table,$align="center") function addTable($table,$align="center")
{ {
if(is_array($table['header']))
{
$table_cols=count($table['header']);
$height['tableheader']=0.2; $height['tableheader']=0.2;
}
else
{
$table_cols=count($table['data']);
$height['tableheader']=0;
}
$height['tabledata']=0.18; $height['tabledata']=0.18;
$this->yloc-=$height['tableheader']; $this->yloc-=$height['tableheader'];
$top_of_table=$this->yloc; $top_of_table=$this->yloc;
$table_width=array_sum($table['widths']); $table_width=array_sum($table['widths']);
$table_cols=count($table['header']);
$table_padding=0.03; $table_padding=0.03;
switch($align) switch($align)
@ -381,17 +389,16 @@ class lpdf
pdf_lineto($this->pdf,$this->loc($xpos_of_table+$table_width),$this->loc($this->yloc+$height['tableheader'])); pdf_lineto($this->pdf,$this->loc($xpos_of_table+$table_width),$this->loc($this->yloc+$height['tableheader']));
pdf_stroke($this->pdf); pdf_stroke($this->pdf);
//do the header first
if(is_array($table['header']))
{
//draw the top line of the table (below the table header) //draw the top line of the table (below the table header)
pdf_moveto($this->pdf,$this->loc($xpos_of_table),$this->loc($this->yloc)); pdf_moveto($this->pdf,$this->loc($xpos_of_table),$this->loc($this->yloc));
pdf_lineto($this->pdf,$this->loc($xpos_of_table+$table_width),$this->loc($this->yloc)); pdf_lineto($this->pdf,$this->loc($xpos_of_table+$table_width),$this->loc($this->yloc));
pdf_stroke($this->pdf); pdf_stroke($this->pdf);
//do the header first
if($table['header'])
{
pdf_setfont($this->pdf,$this->headerfont,12);
$xpos=$xpos_of_table; $xpos=$xpos_of_table;
pdf_setfont($this->pdf,$this->headerfont,12);
for($c=0;$c<$table_cols;$c++) for($c=0;$c<$table_cols;$c++)
{ {
@ -416,7 +423,16 @@ class lpdf
{ {
$width=$table['widths'][$c]; $width=$table['widths'][$c];
pdf_show_boxed($this->pdf,$dataline[$c],$this->loc($xpos+$table_padding),$this->loc($this->yloc),$this->loc($width-2*$table_padding),$this->loc($height['tabledata']),$table['dataalign'][$c],null); $notfit=pdf_show_boxed($this->pdf,$dataline[$c],$this->loc($xpos+$table_padding),$this->loc($this->yloc),$this->loc($width-2*$table_padding),$this->loc($height['tabledata']),$table['dataalign'][$c],null);
//put a little "..." at the end of the field
if($notfit)
{
pdf_setfont($this->pdf,$this->normalfont,8);
pdf_show_boxed($this->pdf,"...",$this->loc($xpos+$width-0.10),$this->loc($this->yloc-0.05),$this->loc(0.10),$this->loc($height['tabledata']),$table['dataalign'][$c],null);
pdf_setfont($this->pdf,$this->normalfont,10);
}
$xpos+=$width; $xpos+=$width;
} }