Skip to content

Commit 27946ca

Browse files
authored
Merge pull request #1413 from jgpATs2w/develop
allows decimal numbers in line-height style
2 parents 9ee99d2 + 54155bf commit 27946ca

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ private static function parseStyle($attribute, $styles)
531531
$styles['bgColor'] = trim($cValue, '#');
532532
break;
533533
case 'line-height':
534-
if (preg_match('/([0-9]+[a-z]+)/', $cValue, $matches)) {
534+
if (preg_match('/([0-9]+\.?[0-9]*[a-z]+)/', $cValue, $matches)) {
535535
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT;
536536
$spacing = Converter::cssToTwip($matches[1]) / \PhpOffice\PhpWord\Style\Paragraph::LINE_HEIGHT;
537537
} elseif (preg_match('/([0-9]+)%/', $cValue, $matches)) {

tests/PhpWord/Shared/ConverterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public function testCssSizeParser()
126126
$this->assertEquals(10, Converter::cssToPoint('10pt'));
127127
$this->assertEquals(7.5, Converter::cssToPoint('10px'));
128128
$this->assertEquals(720, Converter::cssToPoint('10in'));
129+
$this->assertEquals(7.2, Converter::cssToPoint('0.1in'));
129130
$this->assertEquals(120, Converter::cssToPoint('10pc'));
130131
$this->assertEquals(28.346457, Converter::cssToPoint('10mm'), '', 0.000001);
131132
$this->assertEquals(283.464567, Converter::cssToPoint('10cm'), '', 0.000001);

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public function testParseLineHeight()
141141
Html::addHtml($section, '<p style="line-height: 1.5;">test</p>');
142142
Html::addHtml($section, '<p style="line-height: 15pt;">test</p>');
143143
Html::addHtml($section, '<p style="line-height: 120%;">test</p>');
144+
Html::addHtml($section, '<p style="line-height: 0.17in;">test</p>');
144145

145146
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
146147
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:spacing'));
@@ -154,6 +155,10 @@ public function testParseLineHeight()
154155
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[3]/w:pPr/w:spacing'));
155156
$this->assertEquals(Paragraph::LINE_HEIGHT * 1.2, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:line'));
156157
$this->assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:lineRule'));
158+
159+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[4]/w:pPr/w:spacing'));
160+
$this->assertEquals(244.8, $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:spacing', 'w:line'));
161+
$this->assertEquals(LineSpacingRule::EXACT, $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:spacing', 'w:lineRule'));
157162
}
158163

159164
/**

0 commit comments

Comments
 (0)