- Fix the overlapping text in table layout when trying to fit it in multiple lines

- Fix an infinite loop if the text will never fit in the width provided.
This commit is contained in:
dave 2007-12-20 00:56:57 +00:00
parent 5c594a9d85
commit aa2f8883e3

View File

@ -616,20 +616,57 @@ class lpdf
for($c=0;$c<$table_cols;$c++)
{
$width=$table['widths'][$c];
$textstr=$dataline[$c];
$textstr=trim($dataline[$c]);
$h=1;
do
{
//get rid of any leading \n's they cause havok
if($textstr[0]=="\n") $textstr=substr($textstr,1);
$notfit=pdf_show_boxed($this->pdf,$textstr,$this->loc($xpos+$table_padding),$this->loc($this->yloc-($h-1)*$height['tabledata']),$this->loc($width-2*$table_padding),$this->loc($height['tabledata']),$table['dataalign'][$c],null);
$try=0;
$last_notfit = 0;
//echo "allow=$allow_multiline\n";
while(1) {
// echo "h=$h, width=$width, text=[$textstr]\n";
$notfit=pdf_show_boxed($this->pdf,$textstr,
$this->loc($xpos+$table_padding),$this->loc($this->yloc-($h-1)*$height['tabledata']),
$this->loc($width-2*$table_padding),$this->loc($height['tabledata']*$h),
$table['dataalign'][$c],'blind');
// echo " nofit=$notfit\n";
/* It fits, break and do it for real */
if($notfit == 0) break;
/* If we're not allowed to use multiple lines, we're done. */
if($allow_multiline == false) break;
if($last_notfit == $notfit) {
/* Height was increased, but it didn't help the fit at all
* Try again up to 5 times. */
if($try == 5) {
/* Text in is the same as text out for 5 line increments,
* we're probably in an infinite loop. So, instead
* of trying to just add vspace, fudge the hspace and
* restart */
$h = 1;
$width += 0.1;
$try=0;
continue;
}
$try++;
} else {
/* We found a line height that helped the fit */
$try=0;
}
$last_notfit = $notfit;
/* Increase the height and try again */
$h++;
$textstr=substr($textstr,-$notfit);
}
if($allow_multiline == false) break; // default behaviour, don't try multi lines
}while($notfit);
/* Do it for real */
pdf_show_boxed($this->pdf,$textstr,
$this->loc($xpos+$table_padding),$this->loc($this->yloc-($h-1)*$height['tabledata']),
$this->loc($width-2*$table_padding),$this->loc($height['tabledata']*$h),
$table['dataalign'][$c],null);
if($h-2>$extralinestomove) $extralinestomove=$h-2;
if($h-1>$extralinestomove) $extralinestomove=$h-1;
//put a little "..." at the end of the field
if($notfit)