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