- $auto_widths = $widths;
-
- // First we determine the distribution of row lengths in each column.
- // This is an array of descending character length keys (i.e. starting at
- // the rightmost character column), with the value indicating the number
- // of rows where that character column is present.
- $col_dist = [];
- // We will also calculate the longest word in each column
- $max_word_lens = [];
- foreach ($rows as $rowkey => $row) {
- foreach ($row as $col_id => $cell) {
- $longest_word_len = static::longestWordLength($cell);
- if ((!isset($max_word_lens[$col_id]) || ($max_word_lens[$col_id] < $longest_word_len))) {
- $max_word_lens[$col_id] = $longest_word_len;
- }
- if (empty($widths[$col_id])) {
- $length = strlen($cell);
- if ($length == 0) {
- $col_dist[$col_id][0] = 0;
- }
- while ($length > 0) {
- if (!isset($col_dist[$col_id][$length])) {
- $col_dist[$col_id][$length] = 0;
- }
- $col_dist[$col_id][$length]++;
- $length--;
- }
- }
- }
+ // Widths must be provided in some form or another, or we won't wrap.
+ if (empty($widths) && !$this->width) {
+ return new ColumnWidths();