Improving Style Parsing - handling Heading style
This commit is contained in:
parent
4c9e75088a
commit
f5e3807654
|
|
@ -64,11 +64,11 @@ class Styles extends AbstractPart
|
||||||
if ($nodes->length > 0) {
|
if ($nodes->length > 0) {
|
||||||
foreach ($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
$type = $xmlReader->getAttribute('w:type', $node);
|
$type = $xmlReader->getAttribute('w:type', $node);
|
||||||
$name = $xmlReader->getAttribute('w:styleId', $node);
|
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
|
||||||
if (is_null($name)) {
|
if (is_null($name)) {
|
||||||
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
|
$name = $xmlReader->getAttribute('w:styleId', $node);
|
||||||
}
|
}
|
||||||
preg_match('/Heading(\d)/', $name, $headingMatches);
|
preg_match('/Heading\s*(\d)/i', $name, $headingMatches);
|
||||||
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
|
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'paragraph':
|
case 'paragraph':
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\AbstractTestReader;
|
use PhpOffice\PhpWord\AbstractTestReader;
|
||||||
use PhpOffice\PhpWord\SimpleType\TblWidth;
|
use PhpOffice\PhpWord\SimpleType\TblWidth;
|
||||||
|
use PhpOffice\PhpWord\Style;
|
||||||
use PhpOffice\PhpWord\Style\Table;
|
use PhpOffice\PhpWord\Style\Table;
|
||||||
use PhpOffice\PhpWord\Style\TablePosition;
|
use PhpOffice\PhpWord\Style\TablePosition;
|
||||||
|
|
||||||
|
|
@ -145,4 +146,29 @@ class StyleTest extends AbstractTestReader
|
||||||
$this->assertSame(TblWidth::TWIP, $tableStyle->getIndent()->getType());
|
$this->assertSame(TblWidth::TWIP, $tableStyle->getIndent()->getType());
|
||||||
$this->assertSame(2160, $tableStyle->getIndent()->getValue());
|
$this->assertSame(2160, $tableStyle->getIndent()->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testReadHeading()
|
||||||
|
{
|
||||||
|
Style::resetStyles();
|
||||||
|
|
||||||
|
$documentXml = '<w:style w:type="paragraph" w:styleId="Ttulo1">
|
||||||
|
<w:name w:val="heading 1"/>
|
||||||
|
<w:basedOn w:val="Normal"/>
|
||||||
|
<w:uiPriority w:val="1"/>
|
||||||
|
<w:qFormat/>
|
||||||
|
<w:pPr>
|
||||||
|
<w:outlineLvl w:val="0"/>
|
||||||
|
</w:pPr>
|
||||||
|
<w:rPr>
|
||||||
|
<w:rFonts w:ascii="Times New Roman" w:eastAsia="Times New Roman" w:hAnsi="Times New Roman"/>
|
||||||
|
<w:b/>
|
||||||
|
<w:bCs/>
|
||||||
|
</w:rPr>
|
||||||
|
</w:style>';
|
||||||
|
|
||||||
|
$name = 'Heading_1';
|
||||||
|
|
||||||
|
$this->getDocumentFromString(array('styles' => $documentXml));
|
||||||
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', Style::getStyle($name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue