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 <hola@cambraca.com>
  • Loading branch information
Progi1984 and cambraca committed Aug 30, 2023
1 parent 0d22fa3 commit e458249
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions tests/PhpWordTests/Shared/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<span style="font-variant: small-caps;">test</span>';
$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.
*/
Expand Down

0 comments on commit e458249

Please sign in to comment.