|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OneSheet\Style; |
|
4
|
|
|
|
|
5
|
|
|
use OneSheet\Xml\StyleXml; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Style |
|
9
|
|
|
* |
|
10
|
|
|
* @package OneSheet |
|
11
|
|
|
*/ |
|
12
|
|
|
class Style implements Component |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var int |
|
16
|
|
|
*/ |
|
17
|
|
|
private $id; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var Font |
|
21
|
|
|
*/ |
|
22
|
|
|
private $font; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var Fill |
|
26
|
|
|
*/ |
|
27
|
|
|
private $fill; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Border |
|
31
|
|
|
*/ |
|
32
|
|
|
private $border; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var bool |
|
36
|
|
|
*/ |
|
37
|
|
|
private $isLocked = false; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Style constructor. |
|
41
|
|
|
*/ |
|
42
|
9 |
|
public function __construct() |
|
43
|
|
|
{ |
|
44
|
9 |
|
$this->font = new Font(); |
|
45
|
9 |
|
$this->fill = new Fill(); |
|
46
|
9 |
|
$this->border = new Border(); |
|
47
|
9 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return int|null |
|
51
|
|
|
*/ |
|
52
|
7 |
|
public function getId() |
|
53
|
|
|
{ |
|
54
|
7 |
|
return $this->id; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param int $id |
|
59
|
|
|
* @return Style |
|
60
|
|
|
*/ |
|
61
|
4 |
|
public function setId($id) |
|
62
|
|
|
{ |
|
63
|
4 |
|
$this->id = $id; |
|
64
|
4 |
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return Font |
|
69
|
|
|
*/ |
|
70
|
8 |
|
public function getFont() |
|
71
|
|
|
{ |
|
72
|
8 |
|
if ($this->isLocked) { |
|
73
|
3 |
|
return clone $this->font; |
|
74
|
|
|
} |
|
75
|
8 |
|
return $this->font; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return Fill |
|
80
|
|
|
*/ |
|
81
|
5 |
|
public function getFill() |
|
82
|
|
|
{ |
|
83
|
5 |
|
if ($this->isLocked) { |
|
84
|
1 |
|
return clone $this->fill; |
|
85
|
|
|
} |
|
86
|
5 |
|
return $this->fill; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return Border |
|
91
|
|
|
*/ |
|
92
|
4 |
|
public function getBorder() |
|
93
|
|
|
{ |
|
94
|
4 |
|
if ($this->isLocked) { |
|
95
|
|
|
return clone $this->border; |
|
96
|
|
|
} |
|
97
|
4 |
|
return $this->border; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param string $name |
|
102
|
|
|
* @return Style |
|
103
|
|
|
*/ |
|
104
|
2 |
|
public function setFontName($name) |
|
105
|
|
|
{ |
|
106
|
2 |
|
$this->getFont()->setName($name); |
|
107
|
2 |
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param string $size |
|
112
|
|
|
* @return Style |
|
113
|
|
|
*/ |
|
114
|
2 |
|
public function setFontSize($size) |
|
115
|
|
|
{ |
|
116
|
2 |
|
$this->getFont()->setSize($size); |
|
117
|
2 |
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param string $color |
|
122
|
|
|
* @return Style |
|
123
|
|
|
*/ |
|
124
|
1 |
|
public function setFontColor($color) |
|
125
|
|
|
{ |
|
126
|
1 |
|
$this->getFont()->setColor($color); |
|
127
|
1 |
|
return $this; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return Style |
|
132
|
|
|
*/ |
|
133
|
2 |
|
public function setFontBold() |
|
134
|
|
|
{ |
|
135
|
2 |
|
$this->getFont()->setBold(); |
|
136
|
2 |
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return Style |
|
141
|
|
|
*/ |
|
142
|
1 |
|
public function setFontItalic() |
|
143
|
|
|
{ |
|
144
|
1 |
|
$this->getFont()->setItalic(); |
|
145
|
1 |
|
return $this; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return Style |
|
150
|
|
|
*/ |
|
151
|
1 |
|
public function setFontUnderline() |
|
152
|
|
|
{ |
|
153
|
1 |
|
$this->getFont()->setUnderline(); |
|
154
|
1 |
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return Style |
|
159
|
|
|
*/ |
|
160
|
1 |
|
public function setFontStrikethrough() |
|
161
|
|
|
{ |
|
162
|
1 |
|
$this->getFont()->setStrikethrough(); |
|
163
|
1 |
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @param string $color |
|
168
|
|
|
* @return Style |
|
169
|
|
|
*/ |
|
170
|
2 |
|
public function setFillColor($color) |
|
171
|
|
|
{ |
|
172
|
2 |
|
$this->getFill()->setColor($color); |
|
173
|
2 |
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param string $pattern |
|
178
|
|
|
* @return Style |
|
179
|
|
|
*/ |
|
180
|
5 |
|
public function setFillPattern($pattern) |
|
181
|
|
|
{ |
|
182
|
5 |
|
$this->getFill()->setPattern($pattern); |
|
183
|
5 |
|
return $this; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @param string $style |
|
188
|
|
|
* @param string $color |
|
189
|
|
|
* @return Style |
|
190
|
|
|
*/ |
|
191
|
|
|
public function setBorderLeft($style, $color) |
|
192
|
|
|
{ |
|
193
|
|
|
$this->getBorder()->set(BorderType::LEFT, $style, $color); |
|
194
|
|
|
return $this; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @param string $style |
|
199
|
|
|
* @param string $color |
|
200
|
|
|
* @return Style |
|
201
|
|
|
*/ |
|
202
|
|
|
public function setBorderRight($style, $color) |
|
203
|
|
|
{ |
|
204
|
|
|
$this->getBorder()->set(BorderType::RIGHT, $style, $color); |
|
205
|
|
|
return $this; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @param string $style |
|
210
|
|
|
* @param string $color |
|
211
|
|
|
* @return Style |
|
212
|
|
|
*/ |
|
213
|
|
|
public function setBorderRightTop($style, $color) |
|
214
|
|
|
{ |
|
215
|
|
|
$this->getBorder()->set(BorderType::TOP, $style, $color); |
|
216
|
|
|
return $this; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @param string $style |
|
221
|
|
|
* @param string $color |
|
222
|
|
|
* @return Style |
|
223
|
|
|
*/ |
|
224
|
|
|
public function setBorderBottom($style, $color) |
|
225
|
|
|
{ |
|
226
|
|
|
$this->getBorder()->set(BorderType::BOTTOM, $style, $color); |
|
227
|
|
|
return $this; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @param string $style |
|
232
|
|
|
* @param string $color |
|
233
|
|
|
* @return Style |
|
234
|
|
|
*/ |
|
235
|
|
|
public function setBorderDiagonal($style, $color) |
|
236
|
|
|
{ |
|
237
|
|
|
$this->getBorder()->set(BorderType::DIAGONAL, $style, $color); |
|
238
|
|
|
return $this; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Lock current style to prevent overwriting of existing styles. |
|
243
|
|
|
*/ |
|
244
|
4 |
|
public function lock() |
|
245
|
|
|
{ |
|
246
|
4 |
|
$this->isLocked = true; |
|
247
|
4 |
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Return single <xf> string for current style. |
|
251
|
|
|
* |
|
252
|
|
|
* @return string |
|
253
|
|
|
*/ |
|
254
|
4 |
|
public function asXml() |
|
255
|
|
|
{ |
|
256
|
4 |
|
return sprintf( |
|
257
|
4 |
|
StyleXml::DEFAULT_XF_XML, |
|
258
|
4 |
|
$this->font->getId(), |
|
259
|
4 |
|
$this->fill->getId(), |
|
260
|
4 |
|
$this->border->getId() |
|
261
|
4 |
|
); |
|
262
|
|
|
} |
|
263
|
|
|
} |
|
264
|
|
|
|