add parsing of line-height and text-indent

This commit is contained in:
troosan 2018-03-18 22:26:45 +01:00
parent 4c846426ce
commit 997e21433c
2 changed files with 34 additions and 0 deletions

View File

@ -520,6 +520,12 @@ class Html
case 'background-color':
$styles['bgColor'] = trim($cValue, '#');
break;
case 'line-height':
$styles['lineHeight'] = $cValue;
break;
case 'text-indent':
$styles['indentation']['firstLine'] = Converter::cssToTwip($cValue);
break;
case 'font-weight':
$tValue = false;
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'));
}
/**
* 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
*/