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)
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
- preg_match ('/Heading(\d)/ ' , $ name , $ headingMatches );
71
+ preg_match ('/Heading\s* (\d)/i ' , $ name , $ headingMatches );
72
72
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
73
73
switch ($ type ) {
74
74
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
@@ -145,4 +146,29 @@ public function testReadIndent()
145
146
$ this ->assertSame (TblWidth::TWIP , $ tableStyle ->getIndent ()->getType ());
146
147
$ this ->assertSame (2160 , $ tableStyle ->getIndent ()->getValue ());
147
148
}
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
+ }
148
174
}
You can’t perform that action at this time.
0 commit comments