Skip to content

Incorrect column width calculation in ezTable #179

@savioret

Description

@savioret

In some situations the calculation of the automatic column width assignment based on the widest column is not correct.
This can also, in some cases, lead into an infinite loop when the incorrect calculated width of the columns are too small.

image

This code shows the problem:

$pdf = new CezPDF('a4');
$pdf->selectFont('Helvetica');

$myoptions = array(
    'width' => $pdf->ez['pageWidth'] - $pdf->ez['rightMargin'] - $pdf->ez['leftMargin'],
    'showHeadings' => 0,
);

$text = str_repeat("lorem ipsum ", 7);
$data = [[$text, $text, $text]];
$pdf->ezTable($data, null, "", $myoptions);

$pdf->ezText("\n");

$text = str_repeat("lorem ipsum ", 8);
$data = [[$text, $text, $text]];
$pdf->ezTable($data, null, "", $myoptions);

$pdf->ezStream();

In this other example we get into an infinite loop:

$pdf = new CezPDF('a4');
$pdf->selectFont('Helvetica');

$myoptions = array(
    'width' => $pdf->ez['pageWidth'] - $pdf->ez['rightMargin'] - $pdf->ez['leftMargin'],
    'showHeadings' => 0,
);
$enum = "One as dasd asd asdas dsa asd saas asdasdasda One as dasd asd asdas dsa asd saas asdasdasda Three"; 

$data = [[$enum, $enum, $enum, $enum]];

$pdf->ezTable($data, null, "", $myoptions);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions