File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
src/PhpWord/Reader/Word2007
tests/PhpWord/Reader/Word2007 Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -64,11 +64,11 @@ 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 }
71- preg_match ('/Heading(\d)/ ' , $ name , $ headingMatches );
71+ preg_match ('/Heading\s* (\d)/i ' , $ name , $ headingMatches );
7272 // $default = ($xmlReader->getAttribute('w:default', $node) == 1);
7373 switch ($ type ) {
7474 case 'paragraph ' :
Original file line number Diff line number Diff line change 1919
2020use PhpOffice \PhpWord \AbstractTestReader ;
2121use PhpOffice \PhpWord \SimpleType \TblWidth ;
22+ use PhpOffice \PhpWord \Style ;
2223use PhpOffice \PhpWord \Style \Table ;
2324use PhpOffice \PhpWord \Style \TablePosition ;
2425
@@ -145,4 +146,29 @@ public function testReadIndent()
145146 $ this ->assertSame (TblWidth::TWIP , $ tableStyle ->getIndent ()->getType ());
146147 $ this ->assertSame (2160 , $ tableStyle ->getIndent ()->getValue ());
147148 }
149+
150+ public function testReadHeading ()
151+ {
152+ Style::resetStyles ();
153+
154+ $ documentXml = '<w:style w:type="paragraph" w:styleId="Ttulo1">
155+ <w:name w:val="heading 1"/>
156+ <w:basedOn w:val="Normal"/>
157+ <w:uiPriority w:val="1"/>
158+ <w:qFormat/>
159+ <w:pPr>
160+ <w:outlineLvl w:val="0"/>
161+ </w:pPr>
162+ <w:rPr>
163+ <w:rFonts w:ascii="Times New Roman" w:eastAsia="Times New Roman" w:hAnsi="Times New Roman"/>
164+ <w:b/>
165+ <w:bCs/>
166+ </w:rPr>
167+ </w:style> ' ;
168+
169+ $ name = 'Heading_1 ' ;
170+
171+ $ this ->getDocumentFromString (array ('styles ' => $ documentXml ));
172+ $ this ->assertInstanceOf ('PhpOffice \\PhpWord \\Style \\Font ' , Style::getStyle ($ name ));
173+ }
148174}
You can’t perform that action at this time.
0 commit comments