|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Box\Spout\Common\Entity\Style; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Style |
|
7
|
|
|
* Represents a style to be applied to a cell |
|
8
|
|
|
*/ |
|
9
|
|
|
class Style |
|
10
|
|
|
{ |
|
11
|
|
|
/** Default values */ |
|
12
|
|
|
const DEFAULT_FONT_SIZE = 11; |
|
13
|
|
|
const DEFAULT_FONT_COLOR = Color::BLACK; |
|
14
|
|
|
const DEFAULT_FONT_NAME = 'Arial'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var int|null Style ID */ |
|
17
|
|
|
private $id; |
|
18
|
|
|
|
|
19
|
|
|
/** @var bool Whether the font should be bold */ |
|
20
|
|
|
private $fontBold = false; |
|
21
|
|
|
/** @var bool Whether the bold property was set */ |
|
22
|
|
|
private $hasSetFontBold = false; |
|
23
|
|
|
|
|
24
|
|
|
/** @var bool Whether the font should be italic */ |
|
25
|
|
|
private $fontItalic = false; |
|
26
|
|
|
/** @var bool Whether the italic property was set */ |
|
27
|
|
|
private $hasSetFontItalic = false; |
|
28
|
|
|
|
|
29
|
|
|
/** @var bool Whether the font should be underlined */ |
|
30
|
|
|
private $fontUnderline = false; |
|
31
|
|
|
/** @var bool Whether the underline property was set */ |
|
32
|
|
|
private $hasSetFontUnderline = false; |
|
33
|
|
|
|
|
34
|
|
|
/** @var bool Whether the font should be struck through */ |
|
35
|
|
|
private $fontStrikethrough = false; |
|
36
|
|
|
/** @var bool Whether the strikethrough property was set */ |
|
37
|
|
|
private $hasSetFontStrikethrough = false; |
|
38
|
|
|
|
|
39
|
|
|
/** @var int Font size */ |
|
40
|
|
|
private $fontSize = self::DEFAULT_FONT_SIZE; |
|
41
|
|
|
/** @var bool Whether the font size property was set */ |
|
42
|
|
|
private $hasSetFontSize = false; |
|
43
|
|
|
|
|
44
|
|
|
/** @var string Font color */ |
|
45
|
|
|
private $fontColor = self::DEFAULT_FONT_COLOR; |
|
46
|
|
|
/** @var bool Whether the font color property was set */ |
|
47
|
|
|
private $hasSetFontColor = false; |
|
48
|
|
|
|
|
49
|
|
|
/** @var string Font name */ |
|
50
|
|
|
private $fontName = self::DEFAULT_FONT_NAME; |
|
51
|
|
|
/** @var bool Whether the font name property was set */ |
|
52
|
|
|
private $hasSetFontName = false; |
|
53
|
|
|
|
|
54
|
|
|
/** @var bool Whether specific font properties should be applied */ |
|
55
|
|
|
private $shouldApplyFont = false; |
|
56
|
|
|
|
|
57
|
|
|
/** @var bool Whether specific cell alignment should be applied */ |
|
58
|
|
|
private $shouldApplyCellAlignment = false; |
|
59
|
|
|
/** @var string Cell alignment */ |
|
60
|
|
|
private $cellAlignment; |
|
61
|
|
|
/** @var bool Whether the cell alignment property was set */ |
|
62
|
|
|
private $hasSetCellAlignment = false; |
|
63
|
|
|
|
|
64
|
|
|
/** @var bool Whether the text should wrap in the cell (useful for long or multi-lines text) */ |
|
65
|
|
|
private $shouldWrapText = false; |
|
66
|
|
|
/** @var bool Whether the wrap text property was set */ |
|
67
|
|
|
private $hasSetWrapText = false; |
|
68
|
|
|
|
|
69
|
|
|
/** @var Border */ |
|
70
|
|
|
private $border; |
|
71
|
|
|
|
|
72
|
|
|
/** @var bool Whether border properties should be applied */ |
|
73
|
|
|
private $shouldApplyBorder = false; |
|
74
|
|
|
|
|
75
|
|
|
/** @var string Background color */ |
|
76
|
|
|
private $backgroundColor; |
|
77
|
|
|
|
|
78
|
|
|
/** @var bool */ |
|
79
|
|
|
private $hasSetBackgroundColor = false; |
|
80
|
|
|
|
|
81
|
|
|
/** @var string Format */ |
|
82
|
|
|
private $format; |
|
83
|
|
|
|
|
84
|
|
|
/** @var bool */ |
|
85
|
|
|
private $hasSetFormat = false; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return int|null |
|
89
|
|
|
*/ |
|
90
|
89 |
|
public function getId() |
|
91
|
|
|
{ |
|
92
|
89 |
|
return $this->id; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param int $id |
|
97
|
|
|
* @return Style |
|
98
|
|
|
*/ |
|
99
|
89 |
|
public function setId($id) |
|
100
|
|
|
{ |
|
101
|
89 |
|
$this->id = $id; |
|
102
|
|
|
|
|
103
|
89 |
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return Border |
|
108
|
|
|
*/ |
|
109
|
76 |
|
public function getBorder() |
|
110
|
|
|
{ |
|
111
|
76 |
|
return $this->border; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param Border $border |
|
116
|
|
|
* @return Style |
|
117
|
|
|
*/ |
|
118
|
8 |
|
public function setBorder(Border $border) |
|
119
|
|
|
{ |
|
120
|
8 |
|
$this->shouldApplyBorder = true; |
|
121
|
8 |
|
$this->border = $border; |
|
122
|
|
|
|
|
123
|
8 |
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return bool |
|
128
|
|
|
*/ |
|
129
|
88 |
|
public function shouldApplyBorder() |
|
130
|
|
|
{ |
|
131
|
88 |
|
return $this->shouldApplyBorder; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return bool |
|
136
|
|
|
*/ |
|
137
|
78 |
|
public function isFontBold() |
|
138
|
|
|
{ |
|
139
|
78 |
|
return $this->fontBold; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return Style |
|
144
|
|
|
*/ |
|
145
|
20 |
|
public function setFontBold() |
|
146
|
|
|
{ |
|
147
|
20 |
|
$this->fontBold = true; |
|
148
|
20 |
|
$this->hasSetFontBold = true; |
|
149
|
20 |
|
$this->shouldApplyFont = true; |
|
150
|
|
|
|
|
151
|
20 |
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return bool |
|
156
|
|
|
*/ |
|
157
|
75 |
|
public function hasSetFontBold() |
|
158
|
|
|
{ |
|
159
|
75 |
|
return $this->hasSetFontBold; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return bool |
|
164
|
|
|
*/ |
|
165
|
78 |
|
public function isFontItalic() |
|
166
|
|
|
{ |
|
167
|
78 |
|
return $this->fontItalic; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return Style |
|
172
|
|
|
*/ |
|
173
|
7 |
|
public function setFontItalic() |
|
174
|
|
|
{ |
|
175
|
7 |
|
$this->fontItalic = true; |
|
176
|
7 |
|
$this->hasSetFontItalic = true; |
|
177
|
7 |
|
$this->shouldApplyFont = true; |
|
178
|
|
|
|
|
179
|
7 |
|
return $this; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @return bool |
|
184
|
|
|
*/ |
|
185
|
75 |
|
public function hasSetFontItalic() |
|
186
|
|
|
{ |
|
187
|
75 |
|
return $this->hasSetFontItalic; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @return bool |
|
192
|
|
|
*/ |
|
193
|
78 |
|
public function isFontUnderline() |
|
194
|
|
|
{ |
|
195
|
78 |
|
return $this->fontUnderline; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @return Style |
|
200
|
|
|
*/ |
|
201
|
7 |
|
public function setFontUnderline() |
|
202
|
|
|
{ |
|
203
|
7 |
|
$this->fontUnderline = true; |
|
204
|
7 |
|
$this->hasSetFontUnderline = true; |
|
205
|
7 |
|
$this->shouldApplyFont = true; |
|
206
|
|
|
|
|
207
|
7 |
|
return $this; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @return bool |
|
212
|
|
|
*/ |
|
213
|
75 |
|
public function hasSetFontUnderline() |
|
214
|
|
|
{ |
|
215
|
75 |
|
return $this->hasSetFontUnderline; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @return bool |
|
220
|
|
|
*/ |
|
221
|
78 |
|
public function isFontStrikethrough() |
|
222
|
|
|
{ |
|
223
|
78 |
|
return $this->fontStrikethrough; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @return Style |
|
228
|
|
|
*/ |
|
229
|
4 |
|
public function setFontStrikethrough() |
|
230
|
|
|
{ |
|
231
|
4 |
|
$this->fontStrikethrough = true; |
|
232
|
4 |
|
$this->hasSetFontStrikethrough = true; |
|
233
|
4 |
|
$this->shouldApplyFont = true; |
|
234
|
|
|
|
|
235
|
4 |
|
return $this; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @return bool |
|
240
|
|
|
*/ |
|
241
|
75 |
|
public function hasSetFontStrikethrough() |
|
242
|
|
|
{ |
|
243
|
75 |
|
return $this->hasSetFontStrikethrough; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* @return int |
|
248
|
|
|
*/ |
|
249
|
80 |
|
public function getFontSize() |
|
250
|
|
|
{ |
|
251
|
80 |
|
return $this->fontSize; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* @param int $fontSize Font size, in pixels |
|
256
|
|
|
* @return Style |
|
257
|
|
|
*/ |
|
258
|
53 |
|
public function setFontSize($fontSize) |
|
259
|
|
|
{ |
|
260
|
53 |
|
$this->fontSize = $fontSize; |
|
261
|
53 |
|
$this->hasSetFontSize = true; |
|
262
|
53 |
|
$this->shouldApplyFont = true; |
|
263
|
|
|
|
|
264
|
53 |
|
return $this; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* @return bool |
|
269
|
|
|
*/ |
|
270
|
75 |
|
public function hasSetFontSize() |
|
271
|
|
|
{ |
|
272
|
75 |
|
return $this->hasSetFontSize; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* @return string |
|
277
|
|
|
*/ |
|
278
|
80 |
|
public function getFontColor() |
|
279
|
|
|
{ |
|
280
|
80 |
|
return $this->fontColor; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* Sets the font color. |
|
285
|
|
|
* |
|
286
|
|
|
* @param string $fontColor ARGB color (@see Color) |
|
287
|
|
|
* @return Style |
|
288
|
|
|
*/ |
|
289
|
3 |
|
public function setFontColor($fontColor) |
|
290
|
|
|
{ |
|
291
|
3 |
|
$this->fontColor = $fontColor; |
|
292
|
3 |
|
$this->hasSetFontColor = true; |
|
293
|
3 |
|
$this->shouldApplyFont = true; |
|
294
|
|
|
|
|
295
|
3 |
|
return $this; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @return bool |
|
300
|
|
|
*/ |
|
301
|
75 |
|
public function hasSetFontColor() |
|
302
|
|
|
{ |
|
303
|
75 |
|
return $this->hasSetFontColor; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* @return string |
|
308
|
|
|
*/ |
|
309
|
84 |
|
public function getFontName() |
|
310
|
|
|
{ |
|
311
|
84 |
|
return $this->fontName; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* @param string $fontName Name of the font to use |
|
316
|
|
|
* @return Style |
|
317
|
|
|
*/ |
|
318
|
51 |
|
public function setFontName($fontName) |
|
319
|
|
|
{ |
|
320
|
51 |
|
$this->fontName = $fontName; |
|
321
|
51 |
|
$this->hasSetFontName = true; |
|
322
|
51 |
|
$this->shouldApplyFont = true; |
|
323
|
|
|
|
|
324
|
51 |
|
return $this; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* @return bool |
|
329
|
|
|
*/ |
|
330
|
75 |
|
public function hasSetFontName() |
|
331
|
|
|
{ |
|
332
|
75 |
|
return $this->hasSetFontName; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* @return string |
|
337
|
|
|
*/ |
|
338
|
2 |
|
public function getCellAlignment() |
|
339
|
|
|
{ |
|
340
|
2 |
|
return $this->cellAlignment; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* @param string $cellAlignment The cell alignment |
|
345
|
|
|
* |
|
346
|
|
|
* @return Style |
|
347
|
|
|
*/ |
|
348
|
3 |
|
public function setCellAlignment($cellAlignment) |
|
349
|
|
|
{ |
|
350
|
3 |
|
$this->cellAlignment = $cellAlignment; |
|
351
|
3 |
|
$this->hasSetCellAlignment = true; |
|
352
|
3 |
|
$this->shouldApplyCellAlignment = true; |
|
353
|
|
|
|
|
354
|
3 |
|
return $this; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* @return bool |
|
359
|
|
|
*/ |
|
360
|
75 |
|
public function hasSetCellAlignment() |
|
361
|
|
|
{ |
|
362
|
75 |
|
return $this->hasSetCellAlignment; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* @return bool Whether specific cell alignment should be applied |
|
367
|
|
|
*/ |
|
368
|
81 |
|
public function shouldApplyCellAlignment() |
|
369
|
|
|
{ |
|
370
|
81 |
|
return $this->shouldApplyCellAlignment; |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
/** |
|
374
|
|
|
* @return bool |
|
375
|
|
|
*/ |
|
376
|
82 |
|
public function shouldWrapText() |
|
377
|
|
|
{ |
|
378
|
82 |
|
return $this->shouldWrapText; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* @param bool $shouldWrap Should the text be wrapped |
|
383
|
|
|
* @return Style |
|
384
|
|
|
*/ |
|
385
|
8 |
|
public function setShouldWrapText($shouldWrap = true) |
|
386
|
|
|
{ |
|
387
|
8 |
|
$this->shouldWrapText = $shouldWrap; |
|
388
|
8 |
|
$this->hasSetWrapText = true; |
|
389
|
|
|
|
|
390
|
8 |
|
return $this; |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
/** |
|
394
|
|
|
* @return bool |
|
395
|
|
|
*/ |
|
396
|
77 |
|
public function hasSetWrapText() |
|
397
|
|
|
{ |
|
398
|
77 |
|
return $this->hasSetWrapText; |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* @return bool Whether specific font properties should be applied |
|
403
|
|
|
*/ |
|
404
|
71 |
|
public function shouldApplyFont() |
|
405
|
|
|
{ |
|
406
|
71 |
|
return $this->shouldApplyFont; |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
/** |
|
410
|
|
|
* Sets the background color |
|
411
|
|
|
* @param string $color ARGB color (@see Color) |
|
412
|
|
|
* @return Style |
|
413
|
|
|
*/ |
|
414
|
7 |
|
public function setBackgroundColor($color) |
|
415
|
|
|
{ |
|
416
|
7 |
|
$this->hasSetBackgroundColor = true; |
|
417
|
7 |
|
$this->backgroundColor = $color; |
|
418
|
|
|
|
|
419
|
7 |
|
return $this; |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
/** |
|
423
|
|
|
* @return string |
|
424
|
|
|
*/ |
|
425
|
47 |
|
public function getBackgroundColor() |
|
426
|
|
|
{ |
|
427
|
47 |
|
return $this->backgroundColor; |
|
428
|
|
|
} |
|
429
|
|
|
|
|
430
|
|
|
/** |
|
431
|
|
|
* @return bool Whether the background color should be applied |
|
432
|
|
|
*/ |
|
433
|
77 |
|
public function shouldApplyBackgroundColor() |
|
434
|
|
|
{ |
|
435
|
77 |
|
return $this->hasSetBackgroundColor; |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* Sets format |
|
440
|
|
|
* @param string $format |
|
441
|
|
|
* @return Style |
|
442
|
|
|
*/ |
|
443
|
3 |
|
public function setFormat($format) |
|
444
|
|
|
{ |
|
445
|
3 |
|
$this->hasSetFormat = true; |
|
446
|
3 |
|
$this->format = $format; |
|
447
|
|
|
|
|
448
|
3 |
|
return $this; |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
|
|
* @return string |
|
453
|
|
|
*/ |
|
454
|
85 |
|
public function getFormat() |
|
455
|
|
|
{ |
|
456
|
85 |
|
return $this->format; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
/** |
|
460
|
|
|
* @return bool Whether format should be applied |
|
461
|
|
|
*/ |
|
462
|
75 |
|
public function shouldApplyFormat() |
|
463
|
|
|
{ |
|
464
|
75 |
|
return $this->hasSetFormat; |
|
465
|
|
|
} |
|
466
|
|
|
} |
|
467
|
|
|
|