tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.22k stars 1.52k forks source link

Why is getCellBorder() saving previous styles but not using them? #554

Open s-ohnishi opened 2 years ago

s-ohnishi commented 2 years ago

Looking at the source, it looks like this.

    if (is_array($style) AND !empty($style)) {
        // apply border style
        $prev_style = $this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor.' ';
        $s .= $this->setLineStyle($style, true)."\n";
    }

...

    if (is_array($style) AND !empty($style)) {
        // reset border style to previous value
        $s .= "\n".$this->linestyleWidth.' '.$this->linestyleCap.' '.$this->linestyleJoin.' '.$this->linestyleDash.' '.$this->DrawColor."\n";
    }

The style before change is written to $prev_style and changed using setLineStyle(). And after generating the cell data, there is a "reset border style" comment, writing out the linestyleWidth property, etc. However, the linestyleWidth property etc. have already been rewritten with setLineStyle(), so even if you use those properties, they cannot be restored. If you want to restore it, I think you need to use $prev_style which saved the value before change. $prev_style is set, but I think it's strange that it's not used.

s-ohnishi commented 6 months ago

In other parts, the value before the change is saved and restored after processing, but here it is only saved and not restored.

Although the comment says to "reset border style to previous value", it only writes out the "value that may have changed," not the "previous value."

Furthermore, there is a possibility that the setLineStyle() used may have changed values that have not been saved, but do we need to take these into account?