Merge pull request #2041 from joelgo/patch-1
Update Html parser to accept line-height:normal
This commit is contained in:
commit
fa52c92561
|
|
@ -661,7 +661,10 @@ class Html
|
||||||
break;
|
break;
|
||||||
case 'line-height':
|
case 'line-height':
|
||||||
$matches = array();
|
$matches = array();
|
||||||
if (preg_match('/([0-9]+\.?[0-9]*[a-z]+)/', $cValue, $matches)) {
|
if ($cValue === 'normal') {
|
||||||
|
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
|
||||||
|
$spacing = 0;
|
||||||
|
} elseif (preg_match('/([0-9]+\.?[0-9]*[a-z]+)/', $cValue, $matches)) {
|
||||||
//matches number with a unit, e.g. 12px, 15pt, 20mm, ...
|
//matches number with a unit, e.g. 12px, 15pt, 20mm, ...
|
||||||
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT;
|
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT;
|
||||||
$spacing = Converter::cssToTwip($matches[1]);
|
$spacing = Converter::cssToTwip($matches[1]);
|
||||||
|
|
|
||||||
|
|
@ -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: 15pt;">test</p>');
|
||||||
Html::addHtml($section, '<p style="line-height: 120%;">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: 0.17in;">test</p>');
|
||||||
|
Html::addHtml($section, '<p style="line-height: normal;">test</p>');
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:spacing'));
|
$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->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(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->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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue