1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Creator\Style; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Common\Entity\Style\Border; |
6
|
|
|
use Box\Spout\Common\Entity\Style\Style; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class StyleBuilder |
10
|
|
|
* Builder to create new styles |
11
|
|
|
*/ |
12
|
|
|
class StyleBuilder |
13
|
|
|
{ |
14
|
|
|
/** @var Style Style to be created */ |
15
|
|
|
protected $style; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
108 |
|
public function __construct() |
21
|
|
|
{ |
22
|
108 |
|
$this->style = new Style(); |
23
|
108 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Makes the font bold. |
27
|
|
|
* |
28
|
|
|
* @return StyleBuilder |
29
|
|
|
*/ |
30
|
21 |
|
public function setFontBold() |
31
|
|
|
{ |
32
|
21 |
|
$this->style->setFontBold(); |
33
|
|
|
|
34
|
21 |
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Makes the font italic. |
39
|
|
|
* |
40
|
|
|
* @return StyleBuilder |
41
|
|
|
*/ |
42
|
7 |
|
public function setFontItalic() |
43
|
|
|
{ |
44
|
7 |
|
$this->style->setFontItalic(); |
45
|
|
|
|
46
|
7 |
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Makes the font underlined. |
51
|
|
|
* |
52
|
|
|
* @return StyleBuilder |
53
|
|
|
*/ |
54
|
7 |
|
public function setFontUnderline() |
55
|
|
|
{ |
56
|
7 |
|
$this->style->setFontUnderline(); |
57
|
|
|
|
58
|
7 |
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Makes the font struck through. |
63
|
|
|
* |
64
|
|
|
* @return StyleBuilder |
65
|
|
|
*/ |
66
|
4 |
|
public function setFontStrikethrough() |
67
|
|
|
{ |
68
|
4 |
|
$this->style->setFontStrikethrough(); |
69
|
|
|
|
70
|
4 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Sets the font size. |
75
|
|
|
* |
76
|
|
|
* @param int $fontSize Font size, in pixels |
77
|
|
|
* @return StyleBuilder |
78
|
|
|
*/ |
79
|
52 |
|
public function setFontSize($fontSize) |
80
|
|
|
{ |
81
|
52 |
|
$this->style->setFontSize($fontSize); |
82
|
|
|
|
83
|
52 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Sets the font color. |
88
|
|
|
* |
89
|
|
|
* @param string $fontColor ARGB color (@see Color) |
90
|
|
|
* @return StyleBuilder |
91
|
|
|
*/ |
92
|
3 |
|
public function setFontColor($fontColor) |
93
|
|
|
{ |
94
|
3 |
|
$this->style->setFontColor($fontColor); |
95
|
|
|
|
96
|
3 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Sets the font name. |
101
|
|
|
* |
102
|
|
|
* @param string $fontName Name of the font to use |
103
|
|
|
* @return StyleBuilder |
104
|
|
|
*/ |
105
|
50 |
|
public function setFontName($fontName) |
106
|
|
|
{ |
107
|
50 |
|
$this->style->setFontName($fontName); |
108
|
|
|
|
109
|
50 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Makes the text wrap in the cell if requested |
114
|
|
|
* |
115
|
|
|
* @param bool $shouldWrap Should the text be wrapped |
116
|
|
|
* @return StyleBuilder |
117
|
|
|
*/ |
118
|
4 |
|
public function setShouldWrapText($shouldWrap = true) |
119
|
|
|
{ |
120
|
4 |
|
$this->style->setShouldWrapText($shouldWrap); |
121
|
|
|
|
122
|
4 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set a border |
127
|
|
|
* |
128
|
|
|
* @param Border $border |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
8 |
|
public function setBorder(Border $border) |
132
|
|
|
{ |
133
|
8 |
|
$this->style->setBorder($border); |
134
|
|
|
|
135
|
8 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Sets a background color |
140
|
|
|
* |
141
|
|
|
* @param string $color ARGB color (@see Color) |
142
|
|
|
* @return StyleBuilder |
143
|
|
|
*/ |
144
|
7 |
|
public function setBackgroundColor($color) |
145
|
|
|
{ |
146
|
7 |
|
$this->style->setBackgroundColor($color); |
147
|
|
|
|
148
|
7 |
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Sets a format |
153
|
|
|
* |
154
|
|
|
* @param string $format Format |
155
|
|
|
* @return StyleBuilder |
156
|
|
|
* @api |
157
|
|
|
*/ |
158
|
3 |
|
public function setFormat($format) |
159
|
|
|
{ |
160
|
3 |
|
$this->style->setFormat($format); |
161
|
|
|
|
162
|
3 |
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Returns the configured style. The style is cached and can be reused. |
167
|
|
|
* |
168
|
|
|
* @return Style |
169
|
|
|
*/ |
170
|
108 |
|
public function build() |
171
|
|
|
{ |
172
|
108 |
|
return $this->style; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|