Merge pull request #1316 from troosan/html_css_parse

add parsing of line-height and text-indent
This commit is contained in:
troosan 2018-03-19 07:58:52 +01:00 committed by GitHub
commit fe3f383621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View File

@ -18,6 +18,7 @@ v0.15.0 (?? ??? 2018)
- Add support for Hyphenation @Trainmaster #1282 (Document: `autoHyphenation`, `consecutiveHyphenLimit`, `hyphenationZone`, `doNotHyphenateCaps`, Paragraph: `suppressAutoHyphens`) - Add support for Hyphenation @Trainmaster #1282 (Document: `autoHyphenation`, `consecutiveHyphenLimit`, `hyphenationZone`, `doNotHyphenateCaps`, Paragraph: `suppressAutoHyphens`)
- Added support for Floating Table Positioning (tblpPr) @anrikun #639 - Added support for Floating Table Positioning (tblpPr) @anrikun #639
- Added support for Image text wrapping distance @troosan #1310 - Added support for Image text wrapping distance @troosan #1310
- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
### Fixed ### Fixed
- Fix reading of docx default style - @troosan #1238 - Fix reading of docx default style - @troosan #1238

View File

@ -520,6 +520,12 @@ class Html
case 'background-color': case 'background-color':
$styles['bgColor'] = trim($cValue, '#'); $styles['bgColor'] = trim($cValue, '#');
break; break;
case 'line-height':
$styles['lineHeight'] = $cValue;
break;
case 'text-indent':
$styles['indentation']['firstLine'] = Converter::cssToTwip($cValue);
break;
case 'font-weight': case 'font-weight':
$tValue = false; $tValue = false;
if (preg_match('#bold#', $cValue)) { if (preg_match('#bold#', $cValue)) {

View File

@ -114,6 +114,34 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val')); $this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val'));
} }
/**
* Test line-height style
*/
public function testParseLineHeight()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '<p style="line-height: 1.5;">test</p>');
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:spacing'));
$this->assertEquals(240 * 1.5, $doc->getElementAttribute('/w:document/w:body/w:p/w:pPr/w:spacing', 'w:line'));
}
/**
* Test text-indent style
*/
public function testParseTextIndent()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
Html::addHtml($section, '<p style="text-indent: 50px;">test</p>');
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:ind'));
$this->assertEquals(750, $doc->getElementAttribute('/w:document/w:body/w:p/w:pPr/w:ind', 'w:firstLine'));
}
/** /**
* Test text-align style * Test text-align style
*/ */