NFePHP\Extras\PdfNFePHP::CellFit PHP Method

CellFit() public method

CellFit Celula com escala horizontal caso o texto seja muito largo
Author: Patrick Benny
public CellFit ( number $w, number $h, string $txt = '', number $border, number $ln, string $align = '', boolean $fill = false, string $link = '', boolean $scale = false, boolean $force = true )
$w number
$h number
$txt string
$border number
$ln number
$align string
$fill boolean
$link string
$scale boolean
$force boolean
    public function CellFit($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '', $scale = false, $force = true)
    {
        $str_width = $this->GetStringWidth($txt);
        if ($w == 0) {
            $w = $this->w - $this->rMargin - $this->x;
        }
        $ratio = ($w - $this->cMargin * 2) / $str_width;
        $fit = $ratio < 1 || $ratio > 1 && $force;
        if ($fit) {
            if ($scale) {
                //Calcula a escala horizontal
                $horiz_scale = $ratio * 100.0;
                //Ajusta a escala horizontal
                $this->_out(sprintf('BT %.2F Tz ET', $horiz_scale));
            } else {
                //Calcula o espaçamento de caracteres em pontos
                $char_space = ($w - $this->cMargin * 2 - $str_width) / max($this->_MBGetStringLength($txt) - 1, 1) * $this->k;
                //Ajusta o espaçamento de caracteres
                $this->_out(sprintf('BT %.2F Tc ET', $char_space));
            }
            //Sobrescreve o alinhamento informado (desde que o texto caiba na celula)
            $align = '';
        }
        //Passa para o método cell
        $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
        //Reseta o espaçamento de caracteres e a escala horizontal
        if ($fit) {
            $this->_out('BT ' . ($scale ? '100 Tz' : '0 Tc') . ' ET');
        }
    }