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,12 +64,12 @@ public function read(PhpWord $phpWord)
64
64
if ($ nodes ->length > 0 ) {
65
65
foreach ($ nodes as $ node ) {
66
66
$ type = $ xmlReader ->getAttribute ('w:type ' , $ node );
67
- $ name = $ xmlReader ->getAttribute ('w:styleId ' , $ node );
67
+ $ name = $ xmlReader ->getAttribute ('w:val ' , $ node, ' w:name ' );
68
68
if (is_null ($ name )) {
69
- $ name = $ xmlReader ->getAttribute ('w:val ' , $ node, ' w:name ' );
69
+ $ name = $ xmlReader ->getAttribute ('w:styleId ' , $ node );
70
70
}
71
71
$ headingMatches = array ();
72
- preg_match ('/Heading(\d)/ ' , $ name , $ headingMatches );
72
+ preg_match ('/Heading\s* (\d)/i ' , $ name , $ headingMatches );
73
73
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
74
74
switch ($ type ) {
75
75
case 'paragraph ' :
Original file line number Diff line number Diff line change 19
19
20
20
use PhpOffice \PhpWord \AbstractTestReader ;
21
21
use PhpOffice \PhpWord \SimpleType \TblWidth ;
22
+ use PhpOffice \PhpWord \Style ;
22
23
use PhpOffice \PhpWord \Style \Table ;
23
24
use PhpOffice \PhpWord \Style \TablePosition ;
24
25
@@ -169,4 +170,29 @@ public function testReadHidden()
169
170
$ fontStyle = $ textRun ->getElement (0 )->getFontStyle ();
170
171
$ this ->assertTrue ($ fontStyle ->isHidden ());
171
172
}
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
+ }
172
198
}
You can’t perform that action at this time.
0 commit comments