Fixed shared border definitions across different styles #267

This commit is contained in:
madflow 2016-08-17 13:59:43 +02:00
parent bc40ec1830
commit 65a33577fd
2 changed files with 7 additions and 12 deletions

View File

@ -92,18 +92,17 @@ class StyleHelper extends AbstractStyleHelper
$styleId = $style->getId();
if ($style->shouldApplyBorder()) {
$border = $style->getBorder();
$serializedBorder = serialize($border);
if (!isset($this->registeredBorders[$serializedBorder])) {
if (isset($this->registeredBorders[$serializedBorder])) {
$this->styleIdToBorderMappingTable[$styleId] = $this->registeredBorders[$serializedBorder];
} else {
$this->registeredBorders[$serializedBorder] = $styleId;
$this->styleIdToBorderMappingTable[$styleId] = count($this->registeredBorders);
}
} else {
} else { // If no border should be applied - the mapping is the default border: 0
$this->styleIdToBorderMappingTable[$styleId] = 0;
}
}
@ -189,7 +188,6 @@ EOD;
// The other fills are actually registered by setting a background color
foreach ($this->registeredFills as $styleId) {
/** @var Style $style */
$style = $this->styleIdToStyleMappingTable[$styleId];
@ -222,7 +220,6 @@ EOD;
$content .= '<border><left/><right/><top/><bottom/></border>';
foreach ($this->registeredBorders as $styleId) {
/** @var \Box\Spout\Writer\Style\Style $style */
$style = $this->styleIdToStyleMappingTable[$styleId];
$border = $style->getBorder();
@ -232,7 +229,6 @@ EOD;
$sortOrder = ['left', 'right', 'top', 'bottom'];
foreach ($sortOrder as $partName) {
if ($border->hasPart($partName)) {
/** @var $part \Box\Spout\Writer\Style\BorderPart */
$part = $border->getPart($partName);
@ -275,7 +271,6 @@ EOD;
$content = '<cellXfs count="' . count($registeredStyles) . '">';
foreach ($registeredStyles as $style) {
$styleId = $style->getId();
$fillId = $this->styleIdToFillMappingTable[$styleId];
$borderId = $this->styleIdToBorderMappingTable[$styleId];

View File

@ -420,8 +420,8 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
// Where a border is applied - the borderId attribute has to be greater than 0
$bordersApplied = 0;
/** @var \DOMElement $node */
foreach($styleXfsElements->childNodes as $node) {
if($node->getAttribute('applyBorder') == 1) {
foreach ($styleXfsElements->childNodes as $node) {
if ($node->getAttribute('applyBorder') == 1) {
$bordersApplied++;
$this->assertTrue((int)$node->getAttribute('borderId') > 0, 'BorderId is greater than 0');
} else {
@ -429,7 +429,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
}
}
$this->assertEquals(2, $bordersApplied, 'Two borders have been applied');
$this->assertEquals(3, $bordersApplied, 'Three borders have been applied');
}
/**