Skip to content

Commit fe3f383

Browse files
authored
Merge pull request #1316 from troosan/html_css_parse
add parsing of line-height and text-indent
2 parents 4c84642 + de2e05b commit fe3f383

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ v0.15.0 (?? ??? 2018)
1818
- Add support for Hyphenation @Trainmaster #1282 (Document: `autoHyphenation`, `consecutiveHyphenLimit`, `hyphenationZone`, `doNotHyphenateCaps`, Paragraph: `suppressAutoHyphens`)
1919
- Added support for Floating Table Positioning (tblpPr) @anrikun #639
2020
- Added support for Image text wrapping distance @troosan #1310
21+
- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
2122

2223
### Fixed
2324
- Fix reading of docx default style - @troosan #1238

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)