Skip to content

Commit fe647f6

Browse files
author
Javier Garcia
committed
fix when style line-height size comes in decimal number
1 parent 65a594d commit fe647f6

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

samples/resources/Sample_30_ReadHTML.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ <h1>Adding element via HTML</h1>
1717
<h2>Includes images</h2>
1818
<img src="https://phpword.readthedocs.io/en/latest/_images/phpword.png" alt=""/>
1919

20-
<img src="https://localhost/gev/desarrollo/actividades/pruebas_14/5b064503587f7.jpeg" name="Imagen 12" align="bottom" width="208" height="183" border="0"/>
21-
<img src="http://localhost/gev/desarrollo/actividades/pruebas_14/5b064503589db.png" name="Imagen 13" align="bottom" width="143" height="202" border="0"/>
22-
<img src="http://localhost/gev/desarrollo/actividades/pruebas_14/5b0645035aac8.jpeg" name="Imagen 14" align="bottom" width="194" height="188" border="0"/>
20+
<h2>Nested p and i</h2>
21+
<p class="western" align="right" style="font-weight: normal; line-height: 0.17in; orphans: 0; widows: 0">
22+
Contenido
23+
<font size="2" style="font-size: 9pt"><i>B.O. de la Provincia de Barcelona</i></font>
24+
<font size="2" style="font-size: 9pt">, 6-9-1939, citado en Díaz Plaja, F.: "España 1939-1979",</font>
25+
</p>
2326

2427
</body>
2528
</html>

src/PhpWord/Shared/Html.php

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