76 $cell = $row ? $row[$index] :
'-';
77 $width = $this->colWidths[$index];
81 $output .= str_repeat(
' ', $this->indent);
83 $output .= ($this->v_lines[$index] == 1) ? $this->
getVLine() :
' ';
86 if (\is_string($cell)) {
87 $cell = \rtrim(\preg_replace(
'/\s+/',
' ', $cell));
88 if (! $this->preserveSpaceBefore) {
89 $cell = \ltrim($cell);
94 $content = \preg_replace(
'#\x1b[[][^A-Za-z]*[A-Za-z]#',
'', $cell);
96 $delta = - \mb_strlen($cell,
'UTF-8') + \mb_strlen($content,
'UTF-8') +
$this->padding;
97 $output .= $this->
mb_str_pad($cell, $width - $delta, $row ?
' ' :
'-');
99 if ($row && $index == \count($row) - 1) {
100 $output .= ($this->v_lines[\count($row)] == 1) ? $this->
getVLine() :
' ';
125 private function mb_str_pad($str, $pad_len, $pad_str =
' ', $dir = STR_PAD_RIGHT, $encoding = NULL) {
126 $content = \preg_replace(
'#\x1b[[][^A-Za-z]*[A-Za-z]#',
'', $str);
127 $str_len = \mb_strlen($content);
128 $pad_str_len = \mb_strlen($pad_str);
129 if (! $str_len && ($dir == STR_PAD_RIGHT || $dir == STR_PAD_LEFT)) {
132 if (! $pad_len || ! $pad_str_len || $pad_len <= $str_len) {
137 $repeat = \ceil($str_len - $pad_str_len + $pad_len);
138 if ($dir == STR_PAD_RIGHT) {
139 $result = $str . \str_repeat($pad_str, $repeat);
140 $result = \mb_substr($result, 0, $pad_len);
141 }
else if ($dir == STR_PAD_LEFT) {
142 $result = str_repeat($pad_str, $repeat) . $str;
143 $result = \mb_substr($result, - $pad_len);
144 }
else if ($dir == STR_PAD_BOTH) {
145 $length = ($pad_len - $str_len) / 2;
146 $repeat = \ceil($length / $pad_str_len);
147 $result = \mb_substr(str_repeat($pad_str, $repeat), 0, \floor($length)) . $str . \mb_substr(\str_repeat($pad_str, $repeat), 0, ceil($length));
256 if ($row == $this->rowCount) {
259 if ($col == $this->colCount) {
262 if ($this->h_lines[$row] == 1) {
263 if (! isset($res[0])) {
266 if (! isset($res[2])) {
270 if ($this->v_lines[$col] == 1) {
271 if (! isset($res[1])) {
274 if (! isset($res[3])) {
278 foreach ($res as &$r) {
283 $res = implode(
'', $res);
284 return self::BINARY_VALUES[$res];
295 foreach ($this->datas as $row) {
296 if (\is_array($row)) {
301 $this->rowHeight[$y] = 1;
302 foreach ($row as $col) {
303 if ($col instanceof \DateTime) {
304 $col = \Ubiquity\utils\base\UDateTime::elapsed($col);
306 if (\is_scalar($col) || (\is_object($col) && \method_exists($col,
'__toString'))) {
307 $lines = \explode(
"\n", $col);
308 $size = \count($lines);
309 if ($size > $this->rowHeight[$y]) {
310 $this->rowHeight[$y] = $size;
312 foreach ($lines as $line) {
313 $content = \preg_replace(
'#\x1b[[][^A-Za-z]*[A-Za-z]#',
'', $line);
314 $len = \mb_strlen($content,
'UTF-8');
315 if (! isset($this->colWidths[$index])) {
318 if ($len + 2 * $this->padding > $this->colWidths[$index]) {
330 $this->rowCount = \count($this->datas);