Merge branch 'parsing_heading2' develop

Conflicts:
	src/PhpWord/Reader/Word2007/Styles.php
	tests/PhpWord/Reader/Word2007/StyleTest.php
This commit is contained in:
troosan 2018-12-28 22:33:48 +01:00
commit b2c627d57c
2 changed files with 29 additions and 3 deletions

View File

@ -64,12 +64,12 @@ class Styles extends AbstractPart
if ($nodes->length > 0) {
foreach ($nodes as $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)) {
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
$name = $xmlReader->getAttribute('w:styleId', $node);
}
$headingMatches = array();
preg_match('/Heading(\d)/', $name, $headingMatches);
preg_match('/Heading\s*(\d)/i', $name, $headingMatches);
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
switch ($type) {
case 'paragraph':

View File

@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\PhpWord\AbstractTestReader;
use PhpOffice\PhpWord\SimpleType\TblWidth;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Table;
use PhpOffice\PhpWord\Style\TablePosition;
@ -169,4 +170,29 @@ class StyleTest extends AbstractTestReader
$fontStyle = $textRun->getElement(0)->getFontStyle();
$this->assertTrue($fontStyle->isHidden());
}
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));
}
}