Skip to content

Commit e458249

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

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/PhpWord/Shared/Html.php

+8
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,14 @@ 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#', $value)) {
778+
$tValue = true;
779+
}
780+
$styles['smallCaps'] = $tValue;
781+
774782
break;
775783
case 'margin':
776784
$value = Converter::cssToTwip($value);

tests/PhpWordTests/Shared/HtmlTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ public function testParseTextDecoration(): void
176176
self::assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val'));
177177
}
178178

179+
/**
180+
* Test font-variant style.
181+
*/
182+
public function testParseFontVariant(): void
183+
{
184+
$html = '<span style="font-variant: small-caps;">test</span>';
185+
$phpWord = new PhpWord();
186+
$section = $phpWord->addSection();
187+
Html::addHtml($section, $html);
188+
189+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
190+
self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:smallCaps'));
191+
self::assertEquals('1', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:smallCaps', 'w:val'));
192+
}
193+
179194
/**
180195
* Test font.
181196
*/

0 commit comments

Comments
 (0)