|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xls; |
|
4
|
|
|
|
|
5
|
|
|
class Font |
|
6
|
|
|
{ |
|
7
|
|
|
const FONT_NORMAL = 400; |
|
8
|
|
|
const FONT_BOLD = 700; |
|
9
|
|
|
|
|
10
|
|
|
const UNDERLINE_NONE = 0; |
|
11
|
|
|
const UNDERLINE_ONCE = 1; |
|
12
|
|
|
const UNDERLINE_TWICE = 2; |
|
13
|
|
|
|
|
14
|
|
|
const SCRIPT_NONE = 0; |
|
15
|
|
|
const SCRIPT_SUPER = 1; |
|
16
|
|
|
const SCRIPT_SUB = 2; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Index to the FONT record. |
|
20
|
|
|
* @var integer |
|
21
|
|
|
*/ |
|
22
|
|
|
public $index = 0; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The font name (ASCII). |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $name = 'Arial'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Height of font (1/20 of a point) |
|
32
|
|
|
* @var integer |
|
33
|
|
|
*/ |
|
34
|
|
|
public $size = 10; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Bold style |
|
38
|
|
|
* @var integer |
|
39
|
|
|
*/ |
|
40
|
|
|
public $bold = self::FONT_NORMAL; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Bit specifiying if the font is italic. |
|
44
|
|
|
* @var integer |
|
45
|
|
|
*/ |
|
46
|
|
|
public $italic = 0; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Index to the cell's color |
|
50
|
|
|
* @var integer |
|
51
|
|
|
*/ |
|
52
|
|
|
public $color = 0x7FFF; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* The text underline property |
|
56
|
|
|
* @var integer |
|
57
|
|
|
*/ |
|
58
|
|
|
public $underline = self::UNDERLINE_NONE; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Bit specifiying if the font has strikeout. |
|
62
|
|
|
* @var integer |
|
63
|
|
|
*/ |
|
64
|
|
|
public $strikeout = 0; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Bit specifiying if the font has outline. |
|
68
|
|
|
* @var integer |
|
69
|
|
|
*/ |
|
70
|
|
|
public $outline = 0; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Bit specifiying if the font has shadow. |
|
74
|
|
|
* @var integer |
|
75
|
|
|
*/ |
|
76
|
|
|
public $shadow = 0; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* 2 bytes specifiying the script type for the font. |
|
80
|
|
|
* @var integer |
|
81
|
|
|
*/ |
|
82
|
|
|
public $script = self::SCRIPT_NONE; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Sets the boldness of the text. |
|
86
|
|
|
* @param bool $bold |
|
87
|
|
|
* |
|
88
|
|
|
* @return Font |
|
89
|
|
|
*/ |
|
90
|
|
|
public function setBold($bold = true) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->bold = ($bold) ? self::FONT_BOLD : self::FONT_NORMAL; |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Sets the cell's font color |
|
99
|
|
|
* |
|
100
|
|
|
* @param string|integer $color either a string (like 'blue'), or an integer (range is [8...63]). |
|
101
|
|
|
* |
|
102
|
|
|
* @return Font |
|
103
|
|
|
*/ |
|
104
|
|
|
public function setColor($color) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->color = Palette::getColor($color); |
|
107
|
|
|
|
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Sets the underline of the text |
|
113
|
|
|
* |
|
114
|
|
|
* @param integer $underline The value for underline. Possible values are: |
|
115
|
|
|
* UNDERLINE_ONCE => underline, UNDERLINE_TWICE => double underline. |
|
116
|
|
|
* |
|
117
|
|
|
* @return Font |
|
118
|
|
|
*/ |
|
119
|
|
|
public function setUnderline($underline) |
|
120
|
|
|
{ |
|
121
|
|
|
$this->underline = $underline; |
|
122
|
|
|
|
|
123
|
|
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Sets the font style as italic |
|
128
|
|
|
* @param bool $italic |
|
129
|
|
|
* |
|
130
|
|
|
* @return Font |
|
131
|
|
|
*/ |
|
132
|
|
|
public function setItalic($italic = true) |
|
133
|
|
|
{ |
|
134
|
|
|
$this->italic = ($italic) ? 1 : 0; |
|
135
|
|
|
|
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Sets the font size |
|
141
|
|
|
* |
|
142
|
|
|
* @param integer $size The font size (in pixels I think). |
|
143
|
|
|
* |
|
144
|
|
|
* @return Font |
|
145
|
|
|
*/ |
|
146
|
|
|
public function setSize($size) |
|
147
|
|
|
{ |
|
148
|
|
|
$this->size = $size; |
|
149
|
|
|
|
|
150
|
|
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Sets font as strikeout |
|
155
|
|
|
* @param bool $strikeout |
|
156
|
|
|
* |
|
157
|
|
|
* @return Font |
|
158
|
|
|
*/ |
|
159
|
|
|
public function setStrikeOut($strikeout = true) |
|
160
|
|
|
{ |
|
161
|
|
|
$this->strikeout = ($strikeout) ? 1 : 0; |
|
162
|
|
|
|
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Sets outlining for a font. |
|
168
|
|
|
* @param bool $outline |
|
169
|
|
|
* |
|
170
|
|
|
* @return Font |
|
171
|
|
|
*/ |
|
172
|
|
|
public function setOutLine($outline = true) |
|
173
|
|
|
{ |
|
174
|
|
|
$this->outline = ($outline) ? 1 : 0; |
|
175
|
|
|
|
|
176
|
|
|
return $this; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Sets font as shadow. |
|
181
|
|
|
* @param bool $shadow |
|
182
|
|
|
* |
|
183
|
|
|
* @return Font |
|
184
|
|
|
*/ |
|
185
|
|
|
public function setShadow($shadow = true) |
|
186
|
|
|
{ |
|
187
|
|
|
$this->shadow = ($shadow) ? 1 : 0; |
|
188
|
|
|
|
|
189
|
|
|
return $this; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @param bool $enable |
|
194
|
|
|
* |
|
195
|
|
|
* @return Font |
|
196
|
|
|
*/ |
|
197
|
|
|
public function setSuperScript($enable = true) |
|
198
|
|
|
{ |
|
199
|
|
|
$this->script = ($enable) ? self::SCRIPT_SUPER : self::SCRIPT_NONE; |
|
200
|
|
|
|
|
201
|
|
|
return $this; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @param bool $enable |
|
206
|
|
|
* |
|
207
|
|
|
* @return Font |
|
208
|
|
|
*/ |
|
209
|
|
|
public function setSubScript($enable = true) |
|
210
|
|
|
{ |
|
211
|
|
|
$this->script = ($enable) ? self::SCRIPT_SUB : self::SCRIPT_NONE; |
|
212
|
|
|
|
|
213
|
|
|
return $this; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Sets the font name. |
|
218
|
|
|
* |
|
219
|
|
|
* @param string $name The font name. Possible values are: |
|
220
|
|
|
* 'Times New Roman', 'Arial', 'Courier'. |
|
221
|
|
|
* |
|
222
|
|
|
* @return Font |
|
223
|
|
|
*/ |
|
224
|
|
|
public function setName($name) |
|
225
|
|
|
{ |
|
226
|
|
|
$this->name = $name; |
|
227
|
|
|
|
|
228
|
|
|
return $this; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Returns a unique hash key for a font. |
|
233
|
|
|
* The elements that form the key are arranged to increase the probability of |
|
234
|
|
|
* generating a unique key. Elements that hold a large range of numbers |
|
235
|
|
|
* (eg. color) are placed between two binary elements such as italic |
|
236
|
|
|
* |
|
237
|
|
|
* @return string A key for this font |
|
238
|
|
|
*/ |
|
239
|
|
|
public function getKey() |
|
240
|
|
|
{ |
|
241
|
|
|
$key = "$this->name$this->size"; |
|
242
|
|
|
$key .= "$this->script$this->underline"; |
|
243
|
|
|
$key .= "$this->strikeout$this->bold$this->outline"; |
|
244
|
|
|
$key .= "$this->shadow$this->color$this->italic"; |
|
245
|
|
|
$key = str_replace(' ', '_', $key); |
|
246
|
|
|
|
|
247
|
|
|
return $key; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @return int |
|
252
|
|
|
*/ |
|
253
|
|
|
public function getIndex() |
|
254
|
|
|
{ |
|
255
|
|
|
return $this->index; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @return string |
|
260
|
|
|
*/ |
|
261
|
|
|
public function getName() |
|
262
|
|
|
{ |
|
263
|
|
|
return $this->name; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @return int |
|
268
|
|
|
*/ |
|
269
|
|
|
public function getSize() |
|
270
|
|
|
{ |
|
271
|
|
|
return $this->size; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* @return int |
|
276
|
|
|
*/ |
|
277
|
|
|
public function getBold() |
|
278
|
|
|
{ |
|
279
|
|
|
return $this->bold; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* @return int |
|
284
|
|
|
*/ |
|
285
|
|
|
public function getItalic() |
|
286
|
|
|
{ |
|
287
|
|
|
return $this->italic; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* @return int |
|
292
|
|
|
*/ |
|
293
|
|
|
public function getColor() |
|
294
|
|
|
{ |
|
295
|
|
|
return $this->color; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @return int |
|
300
|
|
|
*/ |
|
301
|
|
|
public function getUnderline() |
|
302
|
|
|
{ |
|
303
|
|
|
return $this->underline; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* @return int |
|
308
|
|
|
*/ |
|
309
|
|
|
public function getStrikeout() |
|
310
|
|
|
{ |
|
311
|
|
|
return $this->strikeout; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* @return int |
|
316
|
|
|
*/ |
|
317
|
|
|
public function getOutline() |
|
318
|
|
|
{ |
|
319
|
|
|
return $this->outline; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* @return int |
|
324
|
|
|
*/ |
|
325
|
|
|
public function getShadow() |
|
326
|
|
|
{ |
|
327
|
|
|
return $this->shadow; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* @return int |
|
332
|
|
|
*/ |
|
333
|
|
|
public function getScript() |
|
334
|
|
|
{ |
|
335
|
|
|
return $this->script; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* @param int $index |
|
340
|
|
|
*/ |
|
341
|
|
|
public function setIndex($index) |
|
342
|
|
|
{ |
|
343
|
|
|
$this->index = $index; |
|
344
|
|
|
} |
|
345
|
|
|
} |
|
346
|
|
|
|