public function testAddStyle() { $styler = new Styler(); $initialXml = $styler->getStyleSheetXml(); $styler->addStyle(new Style()); $this->assertEquals($initialXml, $styler->getStyleSheetXml()); $style = new Style(); $styler->addStyle($style->setFontBold()); $oneNewStyleXml = $styler->getStyleSheetXml(); $this->assertNotEquals($initialXml, $oneNewStyleXml); $styler->addStyle($style->setFontBold()); $this->assertEquals($oneNewStyleXml, $styler->getStyleSheetXml()); }
public function testLock() { $styler = new Styler(); $style = new Style(); $unlockedFont = $style->getFont(); $unlockedFill = $style->getFill(); $unlockedBorder = $style->getBorder(); $styler->addStyle($style); $lockedFont = $style->getFont()->setColor('abcdef'); $this->assertEquals($unlockedFont, $style->getFont()); $this->assertNotEquals($unlockedFont, $lockedFont); $lockedFill = $style->setFillColor('abcdef'); $this->assertEquals($unlockedFill, $style->getFill()); $this->assertNotEquals($unlockedFill, $lockedFill); $lockedBorder = $style->setSurroundingBorder(); $this->assertEquals($unlockedBorder, $style->getBorder()); $this->assertNotEquals($unlockedBorder, $lockedBorder); }
/** * Add a new style, if it doesnt exists yet. * * @param Style $style */ public function addStyle(Style $style) { if (null === $style->getId()) { $this->register($style->getFont(), $this->fonts); $this->register($style->getFill(), $this->fills); $this->register($style->getBorder(), $this->borders); $this->register($style, $this->styles); $style->lock(); } }
/** * 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; } } }