'normal' line-height means default line height

Add unit test
This commit is contained in:
DE TROOSTEMBERGH Antoine 2021-04-15 21:04:45 +02:00
parent 8efd9ff9da
commit a4055fb7a0
2 changed files with 7 additions and 9 deletions

View File

@ -661,16 +661,9 @@ class Html
break;
case 'line-height':
$matches = array();
if (preg_match('/([a-z]+)/', $cValue, $matches)) {
//$cvalue text and not number
if ($cValue == 'normal') {
$cValue = 1.12;
} else {
$cValue = 1.13;
}
if ($cValue === 'normal') {
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
//we are subtracting 1 line height because the Spacing writer is adding one line
$spacing = ($cValue * Paragraph::LINE_HEIGHT) - Paragraph::LINE_HEIGHT;
$spacing = 0;
} elseif (preg_match('/([0-9]+\.?[0-9]*[a-z]+)/', $cValue, $matches)) {
//matches number with a unit, e.g. 12px, 15pt, 20mm, ...
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT;

View File

@ -158,6 +158,7 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
Html::addHtml($section, '<p style="line-height: 15pt;">test</p>');
Html::addHtml($section, '<p style="line-height: 120%;">test</p>');
Html::addHtml($section, '<p style="line-height: 0.17in;">test</p>');
Html::addHtml($section, '<p style="line-height: normal;">test</p>');
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:spacing'));
@ -175,6 +176,10 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[4]/w:pPr/w:spacing'));
$this->assertEquals(244.8, $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:spacing', 'w:line'));
$this->assertEquals(LineSpacingRule::EXACT, $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:spacing', 'w:lineRule'));
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[5]/w:pPr/w:spacing'));
$this->assertEquals(Paragraph::LINE_HEIGHT, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:line'));
$this->assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:lineRule'));
}
/**