Skip to content

Commit

Permalink
HTML Reader : Support for font-variant: small-caps
Browse files Browse the repository at this point in the history
Co-authored-by: cambraca <[email protected]>
  • Loading branch information
Progi1984 and cambraca committed Aug 30, 2023
1 parent 0d22fa3 commit 2d9f999
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,13 @@ 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);
Expand Down
14 changes: 14 additions & 0 deletions tests/PhpWordTests/Shared/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ public function testParseTextDecoration(): void
self::assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:u'));
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 = '<span style="font-variant: small-caps;">test</span>';
$phpWord = new PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, $html);

$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:smallCaps'));
$this->assertEquals('1', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:smallCaps', 'w:val'));
}

/**
* Test font.
Expand Down

0 comments on commit 2d9f999

Please sign in to comment.