From e458249d7f9c67901c2cfe4e53bc69c1c116fd06 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Wed, 30 Aug 2023 12:05:32 +0200 Subject: [PATCH] HTML Reader : Support for `font-variant: small-caps` Co-authored-by: cambraca --- src/PhpWord/Shared/Html.php | 8 ++++++++ tests/PhpWordTests/Shared/HtmlTest.php | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 4a9057e60c..15c5246a0c 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -771,6 +771,14 @@ protected static function parseStyleDeclarations(array $selectors, array $styles } $styles['italic'] = $tValue; + break; + case 'font-variant': + $tValue = false; + if (preg_match('#small-caps#', $value)) { + $tValue = true; + } + $styles['smallCaps'] = $tValue; + break; case 'margin': $value = Converter::cssToTwip($value); diff --git a/tests/PhpWordTests/Shared/HtmlTest.php b/tests/PhpWordTests/Shared/HtmlTest.php index 7340b219ab..6887c61829 100644 --- a/tests/PhpWordTests/Shared/HtmlTest.php +++ b/tests/PhpWordTests/Shared/HtmlTest.php @@ -176,6 +176,21 @@ public function testParseTextDecoration(): void self::assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val')); } + /** + * Test font-variant style. + */ + public function testParseFontVariant(): void + { + $html = 'test'; + $phpWord = new PhpWord(); + $section = $phpWord->addSection(); + Html::addHtml($section, $html); + + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); + self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:smallCaps')); + self::assertEquals('1', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:smallCaps', 'w:val')); + } + /** * Test font. */