@@ -138,60 +138,59 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, &$parent,
138
138
/**
139
139
* Read w:pPr
140
140
*
141
- * @return string| array|null
141
+ * @return array|null
142
142
*/
143
143
protected function readParagraphStyle (XMLReader $ xmlReader , \DOMElement $ domNode )
144
144
{
145
- $ style = null ;
146
- if ($ xmlReader ->elementExists ('w:pPr ' , $ domNode )) {
147
- if ($ xmlReader ->elementExists ('w:pPr/w:pStyle ' , $ domNode )) {
148
- $ style = $ xmlReader ->getAttribute ('w:val ' , $ domNode , 'w:pPr/w:pStyle ' );
149
- } else {
150
- $ style = array ();
151
- $ mapping = array (
152
- 'w:ind ' => 'indent ' , 'w:spacing ' => 'spacing ' ,
153
- 'w:jc ' => 'align ' , 'w:basedOn ' => 'basedOn ' , 'w:next ' => 'next ' ,
154
- 'w:widowControl ' => 'widowControl ' , 'w:keepNext ' => 'keepNext ' ,
155
- 'w:keepLines ' => 'keepLines ' , 'w:pageBreakBefore ' => 'pageBreakBefore ' ,
156
- );
157
-
158
- $ nodes = $ xmlReader ->getElements ('w:pPr/* ' , $ domNode );
159
- foreach ($ nodes as $ node ) {
160
- if (!array_key_exists ($ node ->nodeName , $ mapping )) {
161
- continue ;
162
- }
163
- $ property = $ mapping [$ node ->nodeName ];
164
- switch ($ node ->nodeName ) {
165
-
166
- case 'w:ind ' :
167
- $ style ['indent ' ] = $ xmlReader ->getAttribute ('w:left ' , $ node );
168
- $ style ['hanging ' ] = $ xmlReader ->getAttribute ('w:hanging ' , $ node );
169
- break ;
170
-
171
- case 'w:spacing ' :
172
- $ style ['spaceAfter ' ] = $ xmlReader ->getAttribute ('w:after ' , $ node );
173
- $ style ['spaceBefore ' ] = $ xmlReader ->getAttribute ('w:before ' , $ node );
174
- // Commented. Need to adjust the number when return value is null
175
- // $style['spacing'] = $xmlReader->getAttribute('w:line', $node);
176
- break ;
177
-
178
- case 'w:keepNext ' :
179
- case 'w:keepLines ' :
180
- case 'w:pageBreakBefore ' :
181
- $ style [$ property ] = true ;
182
- break ;
183
-
184
- case 'w:widowControl ' :
185
- $ style [$ property ] = false ;
186
- break ;
145
+ if (!$ xmlReader ->elementExists ('w:pPr ' , $ domNode )) {
146
+ return ;
147
+ }
187
148
188
- case 'w:jc ' :
189
- case 'w:basedOn ' :
190
- case 'w:next ' :
191
- $ style [$ property ] = $ xmlReader ->getAttribute ('w:val ' , $ node );
192
- break ;
193
- }
194
- }
149
+ $ style = array ();
150
+ $ mapping = array (
151
+ 'w:pStyle ' => 'styleName ' ,
152
+ 'w:ind ' => 'indent ' , 'w:spacing ' => 'spacing ' ,
153
+ 'w:jc ' => 'align ' , 'w:basedOn ' => 'basedOn ' , 'w:next ' => 'next ' ,
154
+ 'w:widowControl ' => 'widowControl ' , 'w:keepNext ' => 'keepNext ' ,
155
+ 'w:keepLines ' => 'keepLines ' , 'w:pageBreakBefore ' => 'pageBreakBefore ' ,
156
+ );
157
+
158
+ $ nodes = $ xmlReader ->getElements ('w:pPr/* ' , $ domNode );
159
+ foreach ($ nodes as $ node ) {
160
+ if (!array_key_exists ($ node ->nodeName , $ mapping )) {
161
+ continue ;
162
+ }
163
+ $ property = $ mapping [$ node ->nodeName ];
164
+ switch ($ node ->nodeName ) {
165
+
166
+ case 'w:ind ' :
167
+ $ style ['indent ' ] = $ xmlReader ->getAttribute ('w:left ' , $ node );
168
+ $ style ['hanging ' ] = $ xmlReader ->getAttribute ('w:hanging ' , $ node );
169
+ break ;
170
+
171
+ case 'w:spacing ' :
172
+ $ style ['spaceAfter ' ] = $ xmlReader ->getAttribute ('w:after ' , $ node );
173
+ $ style ['spaceBefore ' ] = $ xmlReader ->getAttribute ('w:before ' , $ node );
174
+ // Commented. Need to adjust the number when return value is null
175
+ // $style['spacing'] = $xmlReader->getAttribute('w:line', $node);
176
+ break ;
177
+
178
+ case 'w:keepNext ' :
179
+ case 'w:keepLines ' :
180
+ case 'w:pageBreakBefore ' :
181
+ $ style [$ property ] = true ;
182
+ break ;
183
+
184
+ case 'w:widowControl ' :
185
+ $ style [$ property ] = false ;
186
+ break ;
187
+
188
+ case 'w:pStyle ' :
189
+ case 'w:jc ' :
190
+ case 'w:basedOn ' :
191
+ case 'w:next ' :
192
+ $ style [$ property ] = $ xmlReader ->getAttribute ('w:val ' , $ node );
193
+ break ;
195
194
}
196
195
}
197
196
@@ -201,70 +200,69 @@ protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode
201
200
/**
202
201
* Read w:rPr
203
202
*
204
- * @return string| array|null
203
+ * @return array|null
205
204
*/
206
205
protected function readFontStyle (XMLReader $ xmlReader , \DOMElement $ domNode )
207
206
{
208
- $ style = null ;
207
+ if (is_null ($ domNode )) {
208
+ return ;
209
+ }
209
210
// Hyperlink has an extra w:r child
210
211
if ($ domNode ->nodeName == 'w:hyperlink ' ) {
211
212
$ domNode = $ xmlReader ->getElement ('w:r ' , $ domNode );
212
213
}
213
- if (is_null ( $ domNode )) {
214
- return $ style ;
214
+ if (! $ xmlReader -> elementExists ( ' w:rPr ' , $ domNode )) {
215
+ return ;
215
216
}
216
- if ($ xmlReader ->elementExists ('w:rPr ' , $ domNode )) {
217
- if ($ xmlReader ->elementExists ('w:rPr/w:rStyle ' , $ domNode )) {
218
- $ style = $ xmlReader ->getAttribute ('w:val ' , $ domNode , 'w:rPr/w:rStyle ' );
219
- } else {
220
- $ style = array ();
221
- $ mapping = array (
222
- 'w:b ' => 'bold ' , 'w:i ' => 'italic ' , 'w:color ' => 'color ' ,
223
- 'w:strike ' => 'strikethrough ' , 'w:u ' => 'underline ' ,
224
- 'w:highlight ' => 'fgColor ' , 'w:sz ' => 'size ' ,
225
- 'w:rFonts ' => 'name ' , 'w:vertAlign ' => 'superScript ' ,
226
- );
227
217
228
- $ nodes = $ xmlReader ->getElements ('w:rPr/* ' , $ domNode );
229
- foreach ($ nodes as $ node ) {
230
- if (!array_key_exists ($ node ->nodeName , $ mapping )) {
231
- continue ;
232
- }
233
- $ property = $ mapping [$ node ->nodeName ];
234
- switch ($ node ->nodeName ) {
235
-
236
- case 'w:rFonts ' :
237
- $ style ['name ' ] = $ xmlReader ->getAttribute ('w:ascii ' , $ node );
238
- $ style ['hint ' ] = $ xmlReader ->getAttribute ('w:hint ' , $ node );
239
- break ;
240
-
241
- case 'w:b ' :
242
- case 'w:i ' :
243
- case 'w:strike ' :
244
- $ style [$ property ] = true ;
245
- break ;
246
-
247
- case 'w:u ' :
248
- case 'w:highlight ' :
249
- case 'w:color ' :
250
- $ style [$ property ] = $ xmlReader ->getAttribute ('w:val ' , $ node );
251
- break ;
252
-
253
- case 'w:sz ' :
254
- $ style [$ property ] = $ xmlReader ->getAttribute ('w:val ' , $ node ) / 2 ;
255
- break ;
256
-
257
- case 'w:vertAlign ' :
258
- $ style [$ property ] = $ xmlReader ->getAttribute ('w:val ' , $ node );
259
- if ($ style [$ property ] == 'superscript ' ) {
260
- $ style ['superScript ' ] = true ;
261
- } else {
262
- $ style ['superScript ' ] = false ;
263
- $ style ['subScript ' ] = true ;
264
- }
265
- break ;
218
+ $ style = array ();
219
+ $ mapping = array (
220
+ 'w:rStyle ' => 'styleName ' ,
221
+ 'w:b ' => 'bold ' , 'w:i ' => 'italic ' , 'w:color ' => 'color ' ,
222
+ 'w:strike ' => 'strikethrough ' , 'w:u ' => 'underline ' ,
223
+ 'w:highlight ' => 'fgColor ' , 'w:sz ' => 'size ' ,
224
+ 'w:rFonts ' => 'name ' , 'w:vertAlign ' => 'superScript ' ,
225
+ );
226
+
227
+ $ nodes = $ xmlReader ->getElements ('w:rPr/* ' , $ domNode );
228
+ foreach ($ nodes as $ node ) {
229
+ if (!array_key_exists ($ node ->nodeName , $ mapping )) {
230
+ continue ;
231
+ }
232
+ $ property = $ mapping [$ node ->nodeName ];
233
+ switch ($ node ->nodeName ) {
234
+
235
+ case 'w:rFonts ' :
236
+ $ style ['name ' ] = $ xmlReader ->getAttribute ('w:ascii ' , $ node );
237
+ $ style ['hint ' ] = $ xmlReader ->getAttribute ('w:hint ' , $ node );
238
+ break ;
239
+
240
+ case 'w:b ' :
241
+ case 'w:i ' :
242
+ case 'w:strike ' :
243
+ $ style [$ property ] = true ;
244
+ break ;
245
+
246
+ case 'w:rStyle ' :
247
+ case 'w:u ' :
248
+ case 'w:highlight ' :
249
+ case 'w:color ' :
250
+ $ style [$ property ] = $ xmlReader ->getAttribute ('w:val ' , $ node );
251
+ break ;
252
+
253
+ case 'w:sz ' :
254
+ $ style [$ property ] = $ xmlReader ->getAttribute ('w:val ' , $ node ) / 2 ;
255
+ break ;
256
+
257
+ case 'w:vertAlign ' :
258
+ $ style [$ property ] = $ xmlReader ->getAttribute ('w:val ' , $ node );
259
+ if ($ style [$ property ] == 'superscript ' ) {
260
+ $ style ['superScript ' ] = true ;
261
+ } else {
262
+ $ style ['superScript ' ] = false ;
263
+ $ style ['subScript ' ] = true ;
266
264
}
267
- }
265
+ break ;
268
266
}
269
267
}
270
268
0 commit comments