public function testGetCellWidthMultiByte() { $font = new Font(); $font->setName('Segoe UI'); $calculator = new SizeCalculator(new SizeCollection()); $string = 'ä ö32 4eä18 åæçè €äÜuköß ÄöÜÖö üfzp!'; $expectedValues = array(8 => 29, 11 => 39, 12 => 42.5, 13 => 46); foreach ($expectedValues as $fontSize => $minWidth) { $calculator->setFont($font->setSize($fontSize)); $this->assertGreaterThanOrEqual($minWidth, $calculator->getCellWidth($string, $font)); $this->assertLessThanOrEqual($minWidth + 2, $calculator->getCellWidth($string, $font)); } }
/** * Track cell width for column width sizing if its enabled. * * @param mixed $value * @param int $cellIndex * @param Style $style */ private function updateColumnWidths($value, $cellIndex, Style $style) { if ($this->useCellAutosizing) { $cellWidth = $this->sizeCalculator->getCellWidth($value, $style->getFont()); if (!isset($this->columnWidths[$cellIndex]) || $this->columnWidths[$cellIndex] < $cellWidth) { $this->columnWidths[$cellIndex] = $cellWidth; } } }