Skip to content

Commit b2c627d

Browse files
committed
Merge branch 'parsing_heading2' develop
Conflicts: src/PhpWord/Reader/Word2007/Styles.php tests/PhpWord/Reader/Word2007/StyleTest.php
2 parents 9e5da1e + f5e3807 commit b2c627d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/PhpWord/Reader/Word2007/Styles.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public function read(PhpWord $phpWord)
6464
if ($nodes->length > 0) {
6565
foreach ($nodes as $node) {
6666
$type = $xmlReader->getAttribute('w:type', $node);
67-
$name = $xmlReader->getAttribute('w:styleId', $node);
67+
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
6868
if (is_null($name)) {
69-
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
69+
$name = $xmlReader->getAttribute('w:styleId', $node);
7070
}
7171
$headingMatches = array();
72-
preg_match('/Heading(\d)/', $name, $headingMatches);
72+
preg_match('/Heading\s*(\d)/i', $name, $headingMatches);
7373
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
7474
switch ($type) {
7575
case 'paragraph':

tests/PhpWord/Reader/Word2007/StyleTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use PhpOffice\PhpWord\AbstractTestReader;
2121
use PhpOffice\PhpWord\SimpleType\TblWidth;
22+
use PhpOffice\PhpWord\Style;
2223
use PhpOffice\PhpWord\Style\Table;
2324
use PhpOffice\PhpWord\Style\TablePosition;
2425

@@ -169,4 +170,29 @@ public function testReadHidden()
169170
$fontStyle = $textRun->getElement(0)->getFontStyle();
170171
$this->assertTrue($fontStyle->isHidden());
171172
}
173+
174+
public function testReadHeading()
175+
{
176+
Style::resetStyles();
177+
178+
$documentXml = '<w:style w:type="paragraph" w:styleId="Ttulo1">
179+
<w:name w:val="heading 1"/>
180+
<w:basedOn w:val="Normal"/>
181+
<w:uiPriority w:val="1"/>
182+
<w:qFormat/>
183+
<w:pPr>
184+
<w:outlineLvl w:val="0"/>
185+
</w:pPr>
186+
<w:rPr>
187+
<w:rFonts w:ascii="Times New Roman" w:eastAsia="Times New Roman" w:hAnsi="Times New Roman"/>
188+
<w:b/>
189+
<w:bCs/>
190+
</w:rPr>
191+
</w:style>';
192+
193+
$name = 'Heading_1';
194+
195+
$this->getDocumentFromString(array('styles' => $documentXml));
196+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', Style::getStyle($name));
197+
}
172198
}

0 commit comments

Comments
 (0)