trim color codes and add tests
This commit is contained in:
parent
5206c7f690
commit
3219950d59
@ -516,7 +516,7 @@ class Html
|
|||||||
$styles['alignment'] = self::mapAlign($cValue);
|
$styles['alignment'] = self::mapAlign($cValue);
|
||||||
break;
|
break;
|
||||||
case 'display':
|
case 'display':
|
||||||
$styles['hidden'] = $cValue === 'none';
|
$styles['hidden'] = $cValue === 'none' || $cValue === 'hidden';
|
||||||
break;
|
break;
|
||||||
case 'direction':
|
case 'direction':
|
||||||
$styles['rtl'] = $cValue === 'rtl';
|
$styles['rtl'] = $cValue === 'rtl';
|
||||||
@ -747,7 +747,7 @@ class Html
|
|||||||
$colors = explode(' ', $cssBorderColor);
|
$colors = explode(' ', $cssBorderColor);
|
||||||
$borders = array('borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor');
|
$borders = array('borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor');
|
||||||
for ($i = 0; $i < min(4, $numColors, count($colors)); $i++) {
|
for ($i = 0; $i < min(4, $numColors, count($colors)); $i++) {
|
||||||
$styles[$borders[$i]] = $colors[$i];
|
$styles[$borders[$i]] = trim($colors[$i], '#');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -297,7 +297,7 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
|
|||||||
<thead>
|
<thead>
|
||||||
<tr style="background-color: #FF0000; text-align: center; color: #FFFFFF; font-weight: bold; ">
|
<tr style="background-color: #FF0000; text-align: center; color: #FFFFFF; font-weight: bold; ">
|
||||||
<th style="width: 50pt">header a</th>
|
<th style="width: 50pt">header a</th>
|
||||||
<th style="width: 50">header b</th>
|
<th style="width: 50; border-color: #00EE00">header b</th>
|
||||||
<th style="border-color: #00AA00 #00BB00 #00CC00 #00DD00; border-width: 3px">header c</th>
|
<th style="border-color: #00AA00 #00BB00 #00CC00 #00DD00; border-width: 3px">header c</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -313,11 +313,17 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
|
|||||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tr/w:tc'));
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tr/w:tc'));
|
||||||
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tblPr/w:jc'));
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tblPr/w:jc'));
|
||||||
$this->assertEquals(Jc::START, $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tblPr/w:jc', 'w:val'));
|
$this->assertEquals(Jc::START, $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tblPr/w:jc', 'w:val'));
|
||||||
|
|
||||||
//check border colors
|
//check border colors
|
||||||
$this->assertEquals('#00AA00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:top', 'w:color'));
|
$this->assertEquals('00EE00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:tcPr/w:tcBorders/w:top', 'w:color'));
|
||||||
$this->assertEquals('#00BB00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:right', 'w:color'));
|
$this->assertEquals('00EE00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:tcPr/w:tcBorders/w:right', 'w:color'));
|
||||||
$this->assertEquals('#00CC00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:bottom', 'w:color'));
|
$this->assertEquals('00EE00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:tcPr/w:tcBorders/w:bottom', 'w:color'));
|
||||||
$this->assertEquals('#00DD00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:left', 'w:color'));
|
$this->assertEquals('00EE00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:tcPr/w:tcBorders/w:left', 'w:color'));
|
||||||
|
|
||||||
|
$this->assertEquals('00AA00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:top', 'w:color'));
|
||||||
|
$this->assertEquals('00BB00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:right', 'w:color'));
|
||||||
|
$this->assertEquals('00CC00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:bottom', 'w:color'));
|
||||||
|
$this->assertEquals('00DD00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:left', 'w:color'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -595,4 +601,35 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
|
|||||||
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
$this->assertFalse($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:jc'));
|
$this->assertFalse($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:jc'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests parsing hidden text
|
||||||
|
*/
|
||||||
|
public function testParseHiddenText()
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$html = '<p style="display: hidden">This is some hidden text.</p>';
|
||||||
|
Html::addHtml($section, $html);
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
|
|
||||||
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:vanish'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests parsing letter spacing
|
||||||
|
*/
|
||||||
|
public function testParseLetterSpacing()
|
||||||
|
{
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$html = '<p style="letter-spacing: 150px">This is some text with letter spacing.</p>';
|
||||||
|
Html::addHtml($section, $html);
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
|
|
||||||
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:spacing'));
|
||||||
|
$this->assertEquals(150 * 15, $doc->getElement('/w:document/w:body/w:p/w:r/w:rPr/w:spacing')->getAttribute('w:val'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user