|
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 font 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 the text should wrap in the cell (useful for long or multi-lines text) */ |
|
58
|
|
|
private $shouldWrapText = false; |
|
59
|
|
|
/** @var bool Whether the wrap text property was set */ |
|
60
|
|
|
private $hasSetWrapText = false; |
|
61
|
|
|
|
|
62
|
|
|
/** @var Border */ |
|
63
|
|
|
private $border; |
|
64
|
|
|
|
|
65
|
|
|
/** @var bool Whether border properties should be applied */ |
|
66
|
|
|
private $shouldApplyBorder = false; |
|
67
|
|
|
|
|
68
|
|
|
/** @var string Background color */ |
|
69
|
|
|
private $backgroundColor; |
|
70
|
|
|
|
|
71
|
|
|
/** @var bool */ |
|
72
|
|
|
private $hasSetBackgroundColor = false; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return int|null |
|
76
|
|
|
*/ |
|
77
|
85 |
|
public function getId() |
|
78
|
|
|
{ |
|
79
|
85 |
|
return $this->id; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param int $id |
|
84
|
|
|
* @return Style |
|
85
|
|
|
*/ |
|
86
|
85 |
|
public function setId($id) |
|
87
|
|
|
{ |
|
88
|
85 |
|
$this->id = $id; |
|
89
|
|
|
|
|
90
|
85 |
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return Border |
|
95
|
|
|
*/ |
|
96
|
73 |
|
public function getBorder() |
|
97
|
|
|
{ |
|
98
|
73 |
|
return $this->border; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param Border $border |
|
103
|
|
|
* @return Style |
|
104
|
|
|
*/ |
|
105
|
8 |
|
public function setBorder(Border $border) |
|
106
|
|
|
{ |
|
107
|
8 |
|
$this->shouldApplyBorder = true; |
|
108
|
8 |
|
$this->border = $border; |
|
109
|
|
|
|
|
110
|
8 |
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return bool |
|
115
|
|
|
*/ |
|
116
|
84 |
|
public function shouldApplyBorder() |
|
117
|
|
|
{ |
|
118
|
84 |
|
return $this->shouldApplyBorder; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return bool |
|
123
|
|
|
*/ |
|
124
|
75 |
|
public function isFontBold() |
|
125
|
|
|
{ |
|
126
|
75 |
|
return $this->fontBold; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return Style |
|
131
|
|
|
*/ |
|
132
|
18 |
|
public function setFontBold() |
|
133
|
|
|
{ |
|
134
|
18 |
|
$this->fontBold = true; |
|
135
|
18 |
|
$this->hasSetFontBold = true; |
|
136
|
18 |
|
$this->shouldApplyFont = true; |
|
137
|
|
|
|
|
138
|
18 |
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return bool |
|
143
|
|
|
*/ |
|
144
|
72 |
|
public function hasSetFontBold() |
|
145
|
|
|
{ |
|
146
|
72 |
|
return $this->hasSetFontBold; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return bool |
|
151
|
|
|
*/ |
|
152
|
75 |
|
public function isFontItalic() |
|
153
|
|
|
{ |
|
154
|
75 |
|
return $this->fontItalic; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return Style |
|
159
|
|
|
*/ |
|
160
|
6 |
|
public function setFontItalic() |
|
161
|
|
|
{ |
|
162
|
6 |
|
$this->fontItalic = true; |
|
163
|
6 |
|
$this->hasSetFontItalic = true; |
|
164
|
6 |
|
$this->shouldApplyFont = true; |
|
165
|
|
|
|
|
166
|
6 |
|
return $this; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @return bool |
|
171
|
|
|
*/ |
|
172
|
72 |
|
public function hasSetFontItalic() |
|
173
|
|
|
{ |
|
174
|
72 |
|
return $this->hasSetFontItalic; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @return bool |
|
179
|
|
|
*/ |
|
180
|
75 |
|
public function isFontUnderline() |
|
181
|
|
|
{ |
|
182
|
75 |
|
return $this->fontUnderline; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @return Style |
|
187
|
|
|
*/ |
|
188
|
7 |
|
public function setFontUnderline() |
|
189
|
|
|
{ |
|
190
|
7 |
|
$this->fontUnderline = true; |
|
191
|
7 |
|
$this->hasSetFontUnderline = true; |
|
192
|
7 |
|
$this->shouldApplyFont = true; |
|
193
|
|
|
|
|
194
|
7 |
|
return $this; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @return bool |
|
199
|
|
|
*/ |
|
200
|
72 |
|
public function hasSetFontUnderline() |
|
201
|
|
|
{ |
|
202
|
72 |
|
return $this->hasSetFontUnderline; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @return bool |
|
207
|
|
|
*/ |
|
208
|
75 |
|
public function isFontStrikethrough() |
|
209
|
|
|
{ |
|
210
|
75 |
|
return $this->fontStrikethrough; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @return Style |
|
215
|
|
|
*/ |
|
216
|
4 |
|
public function setFontStrikethrough() |
|
217
|
|
|
{ |
|
218
|
4 |
|
$this->fontStrikethrough = true; |
|
219
|
4 |
|
$this->hasSetFontStrikethrough = true; |
|
220
|
4 |
|
$this->shouldApplyFont = true; |
|
221
|
|
|
|
|
222
|
4 |
|
return $this; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* @return bool |
|
227
|
|
|
*/ |
|
228
|
72 |
|
public function hasSetFontStrikethrough() |
|
229
|
|
|
{ |
|
230
|
72 |
|
return $this->hasSetFontStrikethrough; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @return int |
|
235
|
|
|
*/ |
|
236
|
77 |
|
public function getFontSize() |
|
237
|
|
|
{ |
|
238
|
77 |
|
return $this->fontSize; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* @param int $fontSize Font size, in pixels |
|
243
|
|
|
* @return Style |
|
244
|
|
|
*/ |
|
245
|
51 |
|
public function setFontSize($fontSize) |
|
246
|
|
|
{ |
|
247
|
51 |
|
$this->fontSize = $fontSize; |
|
248
|
51 |
|
$this->hasSetFontSize = true; |
|
249
|
51 |
|
$this->shouldApplyFont = true; |
|
250
|
|
|
|
|
251
|
51 |
|
return $this; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* @return bool |
|
256
|
|
|
*/ |
|
257
|
72 |
|
public function hasSetFontSize() |
|
258
|
|
|
{ |
|
259
|
72 |
|
return $this->hasSetFontSize; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* @return string |
|
264
|
|
|
*/ |
|
265
|
77 |
|
public function getFontColor() |
|
266
|
|
|
{ |
|
267
|
77 |
|
return $this->fontColor; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* Sets the font color. |
|
272
|
|
|
* |
|
273
|
|
|
* @param string $fontColor ARGB color (@see Color) |
|
274
|
|
|
* @return Style |
|
275
|
|
|
*/ |
|
276
|
3 |
|
public function setFontColor($fontColor) |
|
277
|
|
|
{ |
|
278
|
3 |
|
$this->fontColor = $fontColor; |
|
279
|
3 |
|
$this->hasSetFontColor = true; |
|
280
|
3 |
|
$this->shouldApplyFont = true; |
|
281
|
|
|
|
|
282
|
3 |
|
return $this; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* @return bool |
|
287
|
|
|
*/ |
|
288
|
72 |
|
public function hasSetFontColor() |
|
289
|
|
|
{ |
|
290
|
72 |
|
return $this->hasSetFontColor; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* @return string |
|
295
|
|
|
*/ |
|
296
|
81 |
|
public function getFontName() |
|
297
|
|
|
{ |
|
298
|
81 |
|
return $this->fontName; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* @param string $fontName Name of the font to use |
|
303
|
|
|
* @return Style |
|
304
|
|
|
*/ |
|
305
|
49 |
|
public function setFontName($fontName) |
|
306
|
|
|
{ |
|
307
|
49 |
|
$this->fontName = $fontName; |
|
308
|
49 |
|
$this->hasSetFontName = true; |
|
309
|
49 |
|
$this->shouldApplyFont = true; |
|
310
|
|
|
|
|
311
|
49 |
|
return $this; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* @return bool |
|
316
|
|
|
*/ |
|
317
|
72 |
|
public function hasSetFontName() |
|
318
|
|
|
{ |
|
319
|
72 |
|
return $this->hasSetFontName; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* @return bool |
|
324
|
|
|
*/ |
|
325
|
79 |
|
public function shouldWrapText() |
|
326
|
|
|
{ |
|
327
|
79 |
|
return $this->shouldWrapText; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* @param bool $shouldWrap Should the text be wrapped |
|
332
|
|
|
* @return Style |
|
333
|
|
|
*/ |
|
334
|
8 |
|
public function setShouldWrapText($shouldWrap = true) |
|
335
|
|
|
{ |
|
336
|
8 |
|
$this->shouldWrapText = $shouldWrap; |
|
337
|
8 |
|
$this->hasSetWrapText = true; |
|
338
|
|
|
|
|
339
|
8 |
|
return $this; |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* @return bool |
|
344
|
|
|
*/ |
|
345
|
74 |
|
public function hasSetWrapText() |
|
346
|
|
|
{ |
|
347
|
74 |
|
return $this->hasSetWrapText; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* @return bool Whether specific font properties should be applied |
|
352
|
|
|
*/ |
|
353
|
68 |
|
public function shouldApplyFont() |
|
354
|
|
|
{ |
|
355
|
68 |
|
return $this->shouldApplyFont; |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
/** |
|
359
|
|
|
* Sets the background color |
|
360
|
|
|
* @param string $color ARGB color (@see Color) |
|
361
|
|
|
* @return Style |
|
362
|
|
|
*/ |
|
363
|
7 |
|
public function setBackgroundColor($color) |
|
364
|
|
|
{ |
|
365
|
7 |
|
$this->hasSetBackgroundColor = true; |
|
366
|
7 |
|
$this->backgroundColor = $color; |
|
367
|
|
|
|
|
368
|
7 |
|
return $this; |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
/** |
|
372
|
|
|
* @return string |
|
373
|
|
|
*/ |
|
374
|
44 |
|
public function getBackgroundColor() |
|
375
|
|
|
{ |
|
376
|
44 |
|
return $this->backgroundColor; |
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* @return bool Whether the background color should be applied |
|
381
|
|
|
*/ |
|
382
|
74 |
|
public function shouldApplyBackgroundColor() |
|
383
|
|
|
{ |
|
384
|
74 |
|
return $this->hasSetBackgroundColor; |
|
385
|
|
|
} |
|
386
|
|
|
} |
|
387
|
|
|
|