Skip to content

Commit b9e601b

Browse files
committed
HTML Reader : Support for font-variant: small-caps
Co-authored-by: cambraca<[email protected]>
1 parent 0d22fa3 commit b9e601b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/PhpWord/Shared/Html.php

+7
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,13 @@ protected static function parseStyleDeclarations(array $selectors, array $styles
771771
}
772772
$styles['italic'] = $tValue;
773773

774+
break;
775+
case 'font-variant':
776+
$tValue = false;
777+
if (preg_match('#small-caps#', $cValue)) {
778+
$tValue = true;
779+
}
780+
$styles['smallCaps'] = $tValue;
774781
break;
775782
case 'margin':
776783
$value = Converter::cssToTwip($value);

tests/PhpWordTests/Shared/HtmlTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ public function testParseTextDecoration(): void
175175
self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:u'));
176176
self::assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val'));
177177
}
178+
/**
179+
* Test font-variant style
180+
*/
181+
public function testParseFontVariant(): void
182+
{
183+
$html = '<span style="font-variant: small-caps;">test</span>';
184+
$phpWord = new PhpWord();
185+
$section = $phpWord->addSection();
186+
Html::addHtml($section, $html);
187+
188+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
189+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:smallCaps'));
190+
$this->assertEquals('1', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:smallCaps', 'w:val'));
191+
}
178192

179193
/**
180194
* Test font.

0 commit comments

Comments
 (0)