Merge pull request #1413 from jgpATs2w/develop

allows decimal numbers in line-height style
This commit is contained in:
troosan 2018-07-14 17:53:14 +02:00 committed by GitHub
commit 27946cad30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -531,7 +531,7 @@ class Html
$styles['bgColor'] = trim($cValue, '#');
break;
case 'line-height':
if (preg_match('/([0-9]+[a-z]+)/', $cValue, $matches)) {
if (preg_match('/([0-9]+\.?[0-9]*[a-z]+)/', $cValue, $matches)) {
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT;
$spacing = Converter::cssToTwip($matches[1]) / \PhpOffice\PhpWord\Style\Paragraph::LINE_HEIGHT;
} elseif (preg_match('/([0-9]+)%/', $cValue, $matches)) {

View File

@ -126,6 +126,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(10, Converter::cssToPoint('10pt'));
$this->assertEquals(7.5, Converter::cssToPoint('10px'));
$this->assertEquals(720, Converter::cssToPoint('10in'));
$this->assertEquals(7.2, Converter::cssToPoint('0.1in'));
$this->assertEquals(120, Converter::cssToPoint('10pc'));
$this->assertEquals(28.346457, Converter::cssToPoint('10mm'), '', 0.000001);
$this->assertEquals(283.464567, Converter::cssToPoint('10cm'), '', 0.000001);

View File

@ -141,6 +141,7 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
Html::addHtml($section, '<p style="line-height: 1.5;">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: 0.17in;">test</p>');
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:spacing'));
@ -154,6 +155,10 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[3]/w:pPr/w:spacing'));
$this->assertEquals(Paragraph::LINE_HEIGHT * 1.2, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:line'));
$this->assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:lineRule'));
$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'));
}
/**