Merge branch 'fix_font_style_based_on' into develop

This commit is contained in:
antoine 2017-05-16 02:41:52 +02:00
commit 11c711b275
2 changed files with 33 additions and 1 deletions

View File

@ -182,7 +182,11 @@ class Styles extends AbstractPart
// Parent style
if (!is_null($paragraphStyle)) {
$xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getStyleName());
if ($paragraphStyle->getStyleName() != null) {
$xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getStyleName());
} elseif ($paragraphStyle->getBasedOn() != null) {
$xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getBasedOn());
}
}
// w:pPr

View File

@ -114,4 +114,32 @@ class StylesTest extends \PHPUnit_Framework_TestCase
$element = $doc->getElement($path, $file);
$this->assertNull($element);
}
function testFontStyleBasedOnOtherFontStyle() {
$phpWord = new PhpWord();
$styleGenerationP = new Paragraph();
$styleGenerationP->setAlignment(Jc::BOTH);
$styleGeneration = new Font();
$styleGeneration->setParagraph($styleGenerationP);
$styleGeneration->setSize(9.5);
$phpWord->addFontStyle('Generation', $styleGeneration);
$styleGenerationEteinteP = new Paragraph();
$styleGenerationEteinteP->setBasedOn('Generation');
$styleGenerationEteinte = new Font();
$styleGenerationEteinte->setParagraph($styleGenerationEteinteP);
$styleGenerationEteinte->setSize(8.5);
$phpWord->addFontStyle('GeneratEteinte', $styleGenerationEteinte);
$doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/styles.xml';
$path = '/w:styles/w:style[@w:styleId="GeneratEteinte"]/w:basedOn';
$element = $doc->getElement($path, $file);
$this->assertEquals('Generation', $element->getAttribute('w:val'));
}
}