23
23
use PhpOffice \PhpWord \Style ;
24
24
use PhpOffice \PhpWord \Style \Font ;
25
25
use PhpOffice \PhpWord \Style \Table ;
26
+ use PhpOffice \PhpWord \Style \Numbering ;
26
27
27
28
/**
28
29
* RTF header part writer.
@@ -53,6 +54,13 @@ class Header extends AbstractPart
53
54
*/
54
55
private $ colorTable = [];
55
56
57
+ /**
58
+ * List table.
59
+ *
60
+ * @var array
61
+ */
62
+ private $ listTable = [];
63
+
56
64
/**
57
65
* Get font table.
58
66
*
@@ -73,21 +81,32 @@ public function getColorTable()
73
81
return $ this ->colorTable ;
74
82
}
75
83
84
+ /**
85
+ * Get list table.
86
+ *
87
+ * @return array
88
+ */
89
+ public function getListTable ()
90
+ {
91
+ return $ this ->listTable ;
92
+ }
93
+
76
94
/**
77
95
* Write part.
78
96
*
79
97
* @return string
80
98
*/
81
99
public function write ()
82
100
{
83
- $ this ->registerFont ();
101
+ $ this ->registerHeader ();
84
102
85
103
$ content = '' ;
86
104
87
105
$ content .= $ this ->writeCharset ();
88
106
$ content .= $ this ->writeDefaults ();
89
107
$ content .= $ this ->writeFontTable ();
90
108
$ content .= $ this ->writeColorTable ();
109
+ $ content .= $ this ->writeListTable ();
91
110
$ content .= $ this ->writeGenerator ();
92
111
$ content .= PHP_EOL ;
93
112
@@ -166,6 +185,18 @@ private function writeColorTable()
166
185
return $ content ;
167
186
}
168
187
188
+ /**
189
+ * Write list table.
190
+ *
191
+ * @return string
192
+ */
193
+ private function writeListTable ()
194
+ {
195
+ $ content = '' ;
196
+
197
+ return $ content ;
198
+ }
199
+
169
200
/**
170
201
* Write.
171
202
*
@@ -182,17 +213,17 @@ private function writeGenerator()
182
213
}
183
214
184
215
/**
185
- * Register all fonts and colors in both named and inline styles to appropriate header table.
216
+ * Register all fonts, colors, and lists in both named and inline styles to appropriate header table.
186
217
*/
187
- private function registerFont (): void
218
+ private function registerHeader (): void
188
219
{
189
220
$ phpWord = $ this ->getParentWriter ()->getPhpWord ();
190
221
$ this ->fontTable [] = Settings::getDefaultFontName ();
191
222
192
223
// Search named styles
193
224
$ styles = Style::getStyles ();
194
225
foreach ($ styles as $ style ) {
195
- $ this ->registerFontItems ($ style );
226
+ $ this ->registerHeaderItems ($ style );
196
227
}
197
228
198
229
// Search inline styles
@@ -203,7 +234,7 @@ private function registerFont(): void
203
234
foreach ($ elements as $ element ) {
204
235
if (method_exists ($ element , 'getFontStyle ' )) {
205
236
$ style = $ element ->getFontStyle ();
206
- $ this ->registerFontItems ($ style );
237
+ $ this ->registerHeaderItems ($ style );
207
238
}
208
239
}
209
240
}
@@ -225,11 +256,11 @@ private function registerBorderColor($style): void
225
256
}
226
257
227
258
/**
228
- * Register fonts and colors .
259
+ * Register fonts, colors, and lists .
229
260
*
230
261
* @param Style\AbstractStyle $style
231
262
*/
232
- private function registerFontItems ($ style ): void
263
+ private function registerHeaderItems ($ style ): void
233
264
{
234
265
$ defaultFont = Settings::getDefaultFontName ();
235
266
$ defaultColor = Settings::DEFAULT_FONT_COLOR ;
@@ -247,6 +278,9 @@ private function registerFontItems($style): void
247
278
$ this ->registerTableItem ($ this ->colorTable , $ style ->getBorderLeftColor (), $ defaultColor );
248
279
$ this ->registerTableItem ($ this ->colorTable , $ style ->getBorderBottomColor (), $ defaultColor );
249
280
}
281
+ if ($ style instanceof Numbering) {
282
+ $ this ->registerList ($ this ->listTable , $ style );
283
+ }
250
284
}
251
285
252
286
/**
@@ -262,4 +296,15 @@ private function registerTableItem(&$table, $value, $default = null): void
262
296
$ table [] = $ value ;
263
297
}
264
298
}
299
+
300
+ /**
301
+ * Register lists and fonts within lists.
302
+ *
303
+ * @param array &$table
304
+ * @param Style\Numbering $style
305
+ */
306
+ private function registerList (&$ table , $ style ): void
307
+ {
308
+ $ table [] = [];
309
+ }
265
310
}
0 commit comments