Skip to content

Commit 11c711b

Browse files
committed
Merge branch 'fix_font_style_based_on' into develop
2 parents 6e49e89 + 09e669f commit 11c711b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/PhpWord/Writer/Word2007/Part/Styles.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ private function writeFontStyle(XMLWriter $xmlWriter, $styleName, FontStyle $sty
182182

183183
// Parent style
184184
if (!is_null($paragraphStyle)) {
185-
$xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getStyleName());
185+
if ($paragraphStyle->getStyleName() != null) {
186+
$xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getStyleName());
187+
} elseif ($paragraphStyle->getBasedOn() != null) {
188+
$xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getBasedOn());
189+
}
186190
}
187191

188192
// w:pPr

tests/PhpWord/Writer/Word2007/Part/StylesTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,32 @@ public function testFontStyleBasedOn()
114114
$element = $doc->getElement($path, $file);
115115
$this->assertNull($element);
116116
}
117+
118+
function testFontStyleBasedOnOtherFontStyle() {
119+
$phpWord = new PhpWord();
120+
121+
$styleGenerationP = new Paragraph();
122+
$styleGenerationP->setAlignment(Jc::BOTH);
123+
124+
$styleGeneration = new Font();
125+
$styleGeneration->setParagraph($styleGenerationP);
126+
$styleGeneration->setSize(9.5);
127+
$phpWord->addFontStyle('Generation', $styleGeneration);
128+
129+
$styleGenerationEteinteP = new Paragraph();
130+
$styleGenerationEteinteP->setBasedOn('Generation');
131+
132+
$styleGenerationEteinte = new Font();
133+
$styleGenerationEteinte->setParagraph($styleGenerationEteinteP);
134+
$styleGenerationEteinte->setSize(8.5);
135+
$phpWord->addFontStyle('GeneratEteinte', $styleGenerationEteinte);
136+
137+
$doc = TestHelperDOCX::getDocument($phpWord);
138+
139+
$file = 'word/styles.xml';
140+
141+
$path = '/w:styles/w:style[@w:styleId="GeneratEteinte"]/w:basedOn';
142+
$element = $doc->getElement($path, $file);
143+
$this->assertEquals('Generation', $element->getAttribute('w:val'));
144+
}
117145
}

0 commit comments

Comments
 (0)