Skip to content

Commit 997e214

Browse files
committed
add parsing of line-height and text-indent
1 parent 4c84642 commit 997e214

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ private static function parseStyle($attribute, $styles)
520520
case 'background-color':
521521
$styles['bgColor'] = trim($cValue, '#');
522522
break;
523+
case 'line-height':
524+
$styles['lineHeight'] = $cValue;
525+
break;
526+
case 'text-indent':
527+
$styles['indentation']['firstLine'] = Converter::cssToTwip($cValue);
528+
break;
523529
case 'font-weight':
524530
$tValue = false;
525531
if (preg_match('#bold#', $cValue)) {

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,34 @@ public function testParseTextDecoration()
114114
$this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val'));
115115
}
116116

117+
/**
118+
* Test line-height style
119+
*/
120+
public function testParseLineHeight()
121+
{
122+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
123+
$section = $phpWord->addSection();
124+
Html::addHtml($section, '<p style="line-height: 1.5;">test</p>');
125+
126+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
127+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:spacing'));
128+
$this->assertEquals(240 * 1.5, $doc->getElementAttribute('/w:document/w:body/w:p/w:pPr/w:spacing', 'w:line'));
129+
}
130+
131+
/**
132+
* Test text-indent style
133+
*/
134+
public function testParseTextIndent()
135+
{
136+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
137+
$section = $phpWord->addSection();
138+
Html::addHtml($section, '<p style="text-indent: 50px;">test</p>');
139+
140+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
141+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:ind'));
142+
$this->assertEquals(750, $doc->getElementAttribute('/w:document/w:body/w:p/w:pPr/w:ind', 'w:firstLine'));
143+
}
144+
117145
/**
118146
* Test text-align style
119147
*/

0 commit comments

Comments
 (0)