Get the default width of a table cell (the length of its longest line).

This is inspired by Table->getCellWidth(), but this also accounts for
multi-line cells.

@param string|TableCell $cell

@return float|int
490534
private function getCellWidth($cell)
    {
        $lineWidths = [0];
        foreach (explode(PHP_EOL, $cell) as $line) {
            $lineWidths[] = Helper::strlenWithoutDecoration($this->outputCopy->getFormatter(), $line);
        }
        $cellWidth = max($lineWidths);
        if ($cell instanceof TableCell && $cell->getColspan() > 1) {
            $cellWidth /= $cell->getColspan();
        }

        return $cellWidth;
    }
827521
protected function getWidth()
    {
        $first_row = reset($this->data);
        $first_row = $this->buildRow($first_row);

        return $this->lengthWithoutTags($first_row);
    }
239487
public function getCellHelper($cell)
    {
        $renderer = lcfirst(str_replace('\\', '', get_class($cell)));
        if (method_exists($this->view, 'plugin')) {
            $helper = $this->view->plugin($renderer);
        }
        return $helper;
    }
1244995
protected function updateMaxRowLength($table_line)
  {
    $length = $table_line->getLength();
    if($length > $this->max_length_rows)
    {
      $this->max_length_rows = $length;
    }

    return $this->max_length_rows;
  }
1004038
private function getColumnWidth(array $commands): int
	{
		$widths = [];

		foreach ($commands as $command)
		{
			if ($command instanceof AbstractCommand)
			{
				$widths[] = StringHelper::strlen($command->getName());

				foreach ($command->getAliases() as $alias)
				{
					$widths[] = StringHelper::strlen($alias);
				}
			}
			else
			{
				$widths[] = StringHelper::strlen($command);
			}
		}

		return $widths ? max($widths) + 2 : 0;
	}
1262217
def GetCellValue (self, column, row = None, default = None):
                
                if row == None:
                        (row, column) = ParseCellSpec(column)
                if row in self:
                        return self[row].GetCellValue(column, default)
                return default
694223
private function getRemainingColumnWidth(TcTable $table, $width) {
        if (!$this->maxWidth) {
            $margins = $table->getPdf()->getMargins();
            $content_width = $table->getPdf()->getPageWidth() - $margins['left'] - $margins['right'];
        } else {
            $content_width = $this->maxWidth;
        }
        $result = $content_width - (is_array($width) ? array_sum($width) : $width);
        return $result > 0 ? $result : 0;
    }
671106
public function getMaxLineWidth()
    {
        $m = $this->getMargins();
        if ($this->getRTL()) {
            return ($this->getRemainingWidth() + $m['right']);
        }

        return ($this->getRemainingWidth() + $m['left']);
    }
468362
public function setWidth(TcTable $table) {
        if (!$this->width) {
            $widths = [];
            foreach ($table->getColumns() as $key => $column) {
                $widths[$key] = $column['width'];
            }
            unset($widths[$this->columnIndex]);
            $this->width = $this->getRemainingColumnWidth($table, $widths);
        }
        $width = $this->width;
        $table->setColumnDefinition($this->columnIndex, 'width', $width);
    }
6048
public static function fromCell($cell)
    {
        switch (Cell::toValue($cell)) {
            case null:
                return null;
            case Cell::SMALL:
                return self::SMALL();
            case Cell::TALL_TOP:
                return self::TALL();
            case Cell::WIDE_LEFT:
                return self::WIDE();
            default:
                return false;
        }
    }
122382
public function getWidth()
    {
        if (null === $this->width && !$this->initialised) {
            $this->refreshDimensions();
        }

        if (null === $this->width) {
            $width = getenv('COLUMNS');
            if (false !== $width) {
                $this->width = (int) trim($width);
            }
        }

        return $this->width ?: static::DEFAULT_WIDTH;
    }
1240173
def get_table_width(self):
        
        if self.column_count == 0:
            return 0
        width = sum(self._column_widths)
        width += ((self._column_count - 1)
                  * termwidth(self.column_separator_char))
        width += termwidth(self.left_border_char)
        width += termwidth(self.right_border_char)
        return width
248085
public function set_tab_width($width) {
        $this->tab_width = intval($width);

        //Check if it fit's the constraints:
        if ($this->tab_width < 1) {
            //Return it to the default
            $this->tab_width = 8;
        }
    }
1083333
protected function _cellWidth($text)
    {
        if (strpos($text, '<') === false && strpos($text, '>') === false) {
            return mb_strwidth($text);
        }
        $styles = array_keys($this->_io->styles());
        $tags = implode('|', $styles);
        $text = preg_replace('#</?(?:' . $tags . ')>#', '', $text);

        return mb_strwidth($text);
    }
708448
public function drawCell($w, $h = 0, $txt = '', $implied_styles = "PBF", $ln = 0, $align = '', $valign = "T", $link = '')
    {
        // If a cell contains a line break like a "<BR>" then convert it to new line
        $txt = preg_replace("/<BR>/i", "\n", $txt);
        // Calculate cell height as string width divided by width
        $str_width = $this->document->GetStringWidth($txt);
        $numlines = ceil($this->document->GetStringWidth($txt) / ($w - 1));
        $numlines = $this->document->NbLines($w, $txt);
        $cellheight = ceil($numlines * $h);

        if ($this->draw_mode == "CALCULATE") {
            if ($cellheight > $this->calculated_line_height) {
                $this->calculated_line_height = $cellheight;
            }

        }

        // Add padding
        $toppad = 0;
        $bottompad = 0;
        if (strstr($implied_styles, "P")) {
            $padding = end($this->stylestack["padding"]);
            $toppad = $padding[0];
            $bottompad = $padding[2];
        }

        $fill = false;
        if (strstr($implied_styles, "F")) {
            // Add border and bg color
            $fill = end($this->stylestack["isfilling"]);
        }

        $borderwidth = false;
        if (strstr($implied_styles, "B")) {
            $borderwidth = end($this->stylestack["border-width"]);
            $border = end($this->stylestack["border-style"]);
            if ($border != "none") {
                $border = 1;
            } else {
                $borderwidth = "false";
            }

        }

        // Store current position so we can jump back after cell draw
        $y = $this->document->GetY();

        // To cater for multiline values, jump to bottom of line + padding -
        // cell height
        if ($valign == "T") {
            $jumpy = $toppad;
        } else if ($valign == "B") {
            $jumpy = $toppad + $this->calculated_line_height - $cellheight;
        } else if ($valign == "C") {
            $jumpy = (($toppad + $this->calculated_line_height + $bottompad) - $cellheight) / 2;
        }

        if ($this->draw_mode == "CALCULATE") {
            $fill_line_height = $toppad + $this->calculated_line_height + $bottompad;
            if ($this->max_line_height < $fill_line_height) {
                $this->max_line_height = $fill_line_height;
            }

            return;
        }

        if ($toppad) {
            $tmpborder = "";
            if (preg_match("/T/", $borderwidth)) {
                $tmpborder = preg_replace("/B/", "", $borderwidth);
                $borderwidth = preg_replace("/T/", "", $borderwidth);
            }

            $prevx = $this->document->GetX();
            $this->document->MultiCell($w, $toppad, "", $tmpborder, $align, $fill, $link);
            $this->setPosition($prevx, false);
        }

        if ($bottompad) {
            $tmpborder = "";
            if (preg_match("/B/", $borderwidth)) {
                $tmpborder = preg_replace("/T/", "", $borderwidth);
                $borderwidth = preg_replace("/B/", "", $borderwidth);
            }

            $prevx = $this->document->GetX();
            $this->document->MultiCell($w, $h + $bottompad, "", $tmpborder, $align, $fill, $link);
            $this->setPosition($prevx, false);
        }

        $this->setPosition(false, $y + $jumpy);

        // Link in a PDF must include a full URL contain http:// element
        // drilldown link of web url can be relative .. so prepend required elements
        if ($link) {
            if (!preg_match("/^http:\/\//", $link) && !preg_match("/^\//", $link)) {
                $link = "http://" . $_SERVER["HTTP_HOST"] . dirname($this->query->url_path_to_reportico_runner) . "/" . $link;
            }

            if (preg_match("/^\//", $link)) {
                $link = ReporticoApp::getConfig("http_urlhost"). "/" . $link;
            }

        }
        $this->document->MultiCell($w, $h, $txt, $borderwidth, $align, $fill, $link);
        $cell_height = $this->document->GetY() - $y;

        if ($cell_height > $this->current_line_height) {
            $this->current_line_height = $cell_height;
        }

        // Jump back
        $this->setPosition(false, $y);
    }
1043081
protected function calculateRowHeight($row)
    {
        $rowsPerCell = array_map(function ($size, $columnWidth) {
            if (is_array($columnWidth)) {
                $rows = 0;
                foreach ($columnWidth as $width) {
                    $rows += ceil($width / ($size - 2));
                }

                return $rows;
            }

            return ceil($columnWidth / ($size - 2));
        }, $this->_columnWidths, array_map(function ($val) {
            if (is_array($val)) {
                $encodings = array_fill(0, count($val), $this->app->encoding);
                return array_map('mb_strwidth', $val, $encodings);
            }

            return mb_strwidth($val, $this->app->encoding);
        }, $row)
        );

        return max($rowsPerCell);
    }
767256
public static function getDefaultRowHeightByFont(PHPExcel_Style_Font $font)
    {
        switch ($font->getName()) {
            case 'Arial':
                switch ($font->getSize()) {
                    case 10:
                        // inspection of Arial 10 workbook says 12.75pt ~17px
                        $rowHeight = 12.75;
                        break;
                    case 9:
                        // inspection of Arial 9 workbook says 12.00pt ~16px
                        $rowHeight = 12;
                        break;
                    case 8:
                        // inspection of Arial 8 workbook says 11.25pt ~15px
                        $rowHeight = 11.25;
                        break;
                    case 7:
                        // inspection of Arial 7 workbook says 9.00pt ~12px
                        $rowHeight = 9;
                        break;
                    case 6:
                    case 5:
                        // inspection of Arial 5,6 workbook says 8.25pt ~11px
                        $rowHeight = 8.25;
                        break;
                    case 4:
                        // inspection of Arial 4 workbook says 6.75pt ~9px
                        $rowHeight = 6.75;
                        break;
                    case 3:
                        // inspection of Arial 3 workbook says 6.00pt ~8px
                        $rowHeight = 6;
                        break;
                    case 2:
                    case 1:
                        // inspection of Arial 1,2 workbook says 5.25pt ~7px
                        $rowHeight = 5.25;
                        break;
                    default:
                        // use Arial 10 workbook as an approximation, extrapolation
                        $rowHeight = 12.75 * $font->getSize() / 10;
                        break;
                }
                break;

            case 'Calibri':
                switch ($font->getSize()) {
                    case 11:
                        // inspection of Calibri 11 workbook says 15.00pt ~20px
                        $rowHeight = 15;
                        break;
                    case 10:
                        // inspection of Calibri 10 workbook says 12.75pt ~17px
                        $rowHeight = 12.75;
                        break;
                    case 9:
                        // inspection of Calibri 9 workbook says 12.00pt ~16px
                        $rowHeight = 12;
                        break;
                    case 8:
                        // inspection of Calibri 8 workbook says 11.25pt ~15px
                        $rowHeight = 11.25;
                        break;
                    case 7:
                        // inspection of Calibri 7 workbook says 9.00pt ~12px
                        $rowHeight = 9;
                        break;
                    case 6:
                    case 5:
                        // inspection of Calibri 5,6 workbook says 8.25pt ~11px
                        $rowHeight = 8.25;
                        break;
                    case 4:
                        // inspection of Calibri 4 workbook says 6.75pt ~9px
                        $rowHeight = 6.75;
                        break;
                    case 3:
                        // inspection of Calibri 3 workbook says 6.00pt ~8px
                        $rowHeight = 6.00;
                        break;
                    case 2:
                    case 1:
                        // inspection of Calibri 1,2 workbook says 5.25pt ~7px
                        $rowHeight = 5.25;
                        break;
                    default:
                        // use Calibri 11 workbook as an approximation, extrapolation
                        $rowHeight = 15 * $font->getSize() / 11;
                        break;
                }
                break;

            case 'Verdana':
                switch ($font->getSize()) {
                    case 10:
                        // inspection of Verdana 10 workbook says 12.75pt ~17px
                        $rowHeight = 12.75;
                        break;
                    case 9:
                        // inspection of Verdana 9 workbook says 11.25pt ~15px
                        $rowHeight = 11.25;
                        break;
                    case 8:
                        // inspection of Verdana 8 workbook says 10.50pt ~14px
                        $rowHeight = 10.50;
                        break;
                    case 7:
                        // inspection of Verdana 7 workbook says 9.00pt ~12px
                        $rowHeight = 9.00;
                        break;
                    case 6:
                    case 5:
                        // inspection of Verdana 5,6 workbook says 8.25pt ~11px
                        $rowHeight = 8.25;
                        break;
                    case 4:
                        // inspection of Verdana 4 workbook says 6.75pt ~9px
                        $rowHeight = 6.75;
                        break;
                    case 3:
                        // inspection of Verdana 3 workbook says 6.00pt ~8px
                        $rowHeight = 6;
                        break;
                    case 2:
                    case 1:
                        // inspection of Verdana 1,2 workbook says 5.25pt ~7px
                        $rowHeight = 5.25;
                        break;
                    default:
                        // use Verdana 10 workbook as an approximation, extrapolation
                        $rowHeight = 12.75 * $font->getSize() / 10;
                        break;
                }
                break;
            default:
                // just use Calibri as an approximation
                $rowHeight = 15 * $font->getSize() / 11;
                break;
        }

        return $rowHeight;
    }