1 | <?php |
||
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 | protected $id = null; |
||
20 | |||
21 | /** @var bool Whether the font should be bold */ |
||
22 | protected $fontBold = false; |
||
23 | /** @var bool Whether the bold property was set */ |
||
24 | protected $hasSetFontBold = false; |
||
25 | |||
26 | /** @var bool Whether the font should be italic */ |
||
27 | protected $fontItalic = false; |
||
28 | /** @var bool Whether the italic property was set */ |
||
29 | protected $hasSetFontItalic = false; |
||
30 | |||
31 | /** @var bool Whether the font should be underlined */ |
||
32 | protected $fontUnderline = false; |
||
33 | /** @var bool Whether the underline property was set */ |
||
34 | protected $hasSetFontUnderline = false; |
||
35 | |||
36 | /** @var bool Whether the font should be struck through */ |
||
37 | protected $fontStrikethrough = false; |
||
38 | /** @var bool Whether the strikethrough property was set */ |
||
39 | protected $hasSetFontStrikethrough = false; |
||
40 | |||
41 | /** @var int Font size */ |
||
42 | protected $fontSize = self::DEFAULT_FONT_SIZE; |
||
43 | /** @var bool Whether the font size property was set */ |
||
44 | protected $hasSetFontSize = false; |
||
45 | |||
46 | /** @var string Font color */ |
||
47 | protected $fontColor = self::DEFAULT_FONT_COLOR; |
||
48 | /** @var bool Whether the font color property was set */ |
||
49 | protected $hasSetFontColor = false; |
||
50 | |||
51 | /** @var string Font name */ |
||
52 | protected $fontName = self::DEFAULT_FONT_NAME; |
||
53 | /** @var bool Whether the font name property was set */ |
||
54 | protected $hasSetFontName = false; |
||
55 | |||
56 | /** @var bool Whether specific font properties should be applied */ |
||
57 | protected $shouldApplyFont = false; |
||
58 | |||
59 | /** @var bool Whether the text should wrap in the cell (useful for long or multi-lines text) */ |
||
60 | protected $shouldWrapText = false; |
||
61 | /** @var bool Whether the wrap text property was set */ |
||
62 | protected $hasSetWrapText = false; |
||
63 | |||
64 | /** |
||
65 | * @return int|null |
||
66 | */ |
||
67 | public function getId() |
||
71 | |||
72 | /** |
||
73 | * @param int $id |
||
74 | * @return Style |
||
75 | */ |
||
76 | public function setId($id) |
||
81 | |||
82 | /** |
||
83 | * @return boolean |
||
84 | */ |
||
85 | public function isFontBold() |
||
89 | |||
90 | /** |
||
91 | * @return Style |
||
92 | */ |
||
93 | public function setFontBold() |
||
100 | |||
101 | /** |
||
102 | * @return boolean |
||
103 | */ |
||
104 | public function isFontItalic() |
||
108 | |||
109 | /** |
||
110 | * @return Style |
||
111 | */ |
||
112 | public function setFontItalic() |
||
119 | |||
120 | /** |
||
121 | * @return boolean |
||
122 | */ |
||
123 | public function isFontUnderline() |
||
127 | |||
128 | /** |
||
129 | * @return Style |
||
130 | */ |
||
131 | public function setFontUnderline() |
||
138 | |||
139 | /** |
||
140 | * @return boolean |
||
141 | */ |
||
142 | public function isFontStrikethrough() |
||
146 | |||
147 | /** |
||
148 | * @return Style |
||
149 | */ |
||
150 | public function setFontStrikethrough() |
||
157 | |||
158 | /** |
||
159 | * @return int |
||
160 | */ |
||
161 | public function getFontSize() |
||
165 | |||
166 | /** |
||
167 | * @param int $fontSize Font size, in pixels |
||
168 | * @return Style |
||
169 | */ |
||
170 | public function setFontSize($fontSize) |
||
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | */ |
||
181 | public function getFontColor() |
||
185 | |||
186 | /** |
||
187 | * Sets the font color. |
||
188 | * |
||
189 | * @param string $fontColor ARGB color (@see Color) |
||
190 | * @return Style |
||
191 | */ |
||
192 | public function setFontColor($fontColor) |
||
199 | |||
200 | /** |
||
201 | * @return string |
||
202 | */ |
||
203 | public function getFontName() |
||
207 | |||
208 | /** |
||
209 | * @param string $fontName Name of the font to use |
||
210 | * @return Style |
||
211 | */ |
||
212 | public function setFontName($fontName) |
||
219 | |||
220 | /** |
||
221 | * @return boolean |
||
222 | */ |
||
223 | public function shouldWrapText() |
||
227 | |||
228 | /** |
||
229 | * @return Style |
||
230 | */ |
||
231 | public function setShouldWrapText() |
||
237 | |||
238 | /** |
||
239 | * @return bool Whether specific font properties should be applied |
||
240 | */ |
||
241 | public function shouldApplyFont() |
||
245 | |||
246 | /** |
||
247 | * Serializes the style for future comparison with other styles. |
||
248 | * The ID is excluded from the comparison, as we only care about |
||
249 | * actual style properties. |
||
250 | * |
||
251 | * @return string The serialized style |
||
252 | */ |
||
253 | public function serialize() |
||
265 | |||
266 | /** |
||
267 | * Merges the current style with the given style, using the given style as a base. This means that: |
||
268 | * - if current style and base style both have property A set, use current style property's value |
||
269 | * - if current style has property A set but base style does not, use current style property's value |
||
270 | * - if base style has property A set but current style does not, use base style property's value |
||
271 | * |
||
272 | * @NOTE: This function returns a new style. |
||
273 | * |
||
274 | * @param Style $baseStyle |
||
275 | * @return Style New style corresponding to the merge of the 2 styles |
||
276 | */ |
||
277 | public function mergeWith($baseStyle) |
||
308 | } |
||
309 |