Border.php
7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
/*
PHPRtfLite
Copyright 2007-2008 Denis Slaveckij <sinedas@gmail.com>
Copyright 2010-2012 Steffen Zeidler <sigma_z@sigma-scripts.de>
This file is part of PHPRtfLite.
PHPRtfLite is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PHPRtfLite is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PHPRtfLite. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Class for creating borders within rtf documents.
* @version 1.2
* @author Denis Slaveckij <sinedas@gmail.com>
* @author Steffen Zeidler <sigma_z@sigma-scripts.de>
* @copyright 2007-2008 Denis Slaveckij, 2010-2012 Steffen Zeidler
* @package PHPRtfLite
* @subpackage PHPRtfLite_Border
*/
class PHPRtfLite_Border
{
/**
* @var PHPRtfLite
*/
protected $_rtf;
/**
* @var PHPRtfLite_Border_Format
*/
protected $_borderLeft;
/**
* @var PHPRtfLite_Border_Format
*/
protected $_borderRight;
/**
* @var PHPRtfLite_Border_Format
*/
protected $_borderTop;
/**
* @var PHPRtfLite_Border_Format
*/
protected $_borderBottom;
/**
* constructor
*
* @param PHPRtfLite $rtf
* @param PHPRtfLite_Border_Format $left
* @param PHPRtfLite_Border_Format $top
* @param PHPRtfLite_Border_Format $right
* @param PHPRtfLite_Border_Format $bottom
*/
public function __construct(PHPRtfLite $rtf,
PHPRtfLite_Border_Format $left = null,
PHPRtfLite_Border_Format $top = null,
PHPRtfLite_Border_Format $right = null,
PHPRtfLite_Border_Format $bottom = null)
{
$this->_rtf = $rtf;
if ($left) {
$left->setColorTable($rtf->getColorTable());
}
$this->_borderLeft = $left;
if ($top) {
$top->setColorTable($rtf->getColorTable());
}
$this->_borderTop = $top;
if ($right) {
$right->setColorTable($rtf->getColorTable());
}
$this->_borderRight = $right;
if ($bottom) {
$bottom->setColorTable($rtf->getColorTable());
}
$this->_borderBottom = $bottom;
}
/**
* creates border by defining border format
*
* @param PHPRtfLite $rtf
* @param integer $size size of border
* @param string $color color of border (example '#ff0000' or '#f00')
* @param string $type represented by class constants PHPRtfLite_Border_Format::TYPE_*<br>
* Possible values:<br>
* PHPRtfLite_Border_Format::TYPE_SINGLE 'single'<br>
* PHPRtfLite_Border_Format::TYPE_DOT 'dot'<br>
* PHPRtfLite_Border_Format::TYPE_DASH 'dash'<br>
* PHPRtfLite_Border_Format::TYPE_DOTDASH 'dotdash'
* @param float $space space between borders and the paragraph
* @param boolean $left left border
* @param boolean $top top border
* @param boolean $right right border
* @param boolean $bottom bottom border
* @return PHPRtfLite_Border
*/
public static function create(PHPRtfLite $rtf, $size = 0, $color = null, $type = null, $space = 0.0,
$left = true, $top = true, $right = true, $bottom = true)
{
$border = new self($rtf);
$border->setBorders(new PHPRtfLite_Border_Format($size, $color, $type, $space), $left, $top, $right, $bottom);
return $border;
}
/**
* sets border format of element
*
* @param PHPRtfLite_Border_Format $borderFormat
* @param boolean $left
* @param boolean $top
* @param boolean $right
* @param boolean $bottom
*/
public function setBorders(PHPRtfLite_Border_Format $borderFormat,
$left = true, $top = true, $right = true, $bottom = true)
{
$borderFormat->setColorTable($this->_rtf->getColorTable());
if ($left) {
$this->_borderLeft = $borderFormat;
}
if ($top) {
$this->_borderTop = $borderFormat;
}
if ($right) {
$this->_borderRight = $borderFormat;
}
if ($bottom) {
$this->_borderBottom = $borderFormat;
}
}
/**
* sets border format for left border
*
* @param PHPRtfLite_Border_Format $borderFormat
*/
public function setBorderLeft(PHPRtfLite_Border_Format $borderFormat)
{
$borderFormat->setColorTable($this->_rtf->getColorTable());
$this->_borderLeft = $borderFormat;
}
/**
* gets border format of left border
*
* @return PHPRtfLite_Border_Format
*/
public function getBorderLeft()
{
return $this->_borderLeft;
}
/**
* sets border format for right border
*
* @param PHPRtfLite_Border_Format $borderFormat
*/
public function setBorderRight(PHPRtfLite_Border_Format $borderFormat)
{
$borderFormat->setColorTable($this->_rtf->getColorTable());
$this->_borderRight = $borderFormat;
}
/**
* gets border format of right border
*
* @return PHPRtfLite_Border_Format
*/
public function getBorderRight()
{
return $this->_borderRight;
}
/**
* sets border format for top border
*
* @param PHPRtfLite_Border_Format $borderFormat
*/
public function setBorderTop(PHPRtfLite_Border_Format $borderFormat)
{
$borderFormat->setColorTable($this->_rtf->getColorTable());
$this->_borderTop = $borderFormat;
}
/**
* gets border format of top border
*
* @return PHPRtfLite_Border_Format
*/
public function getBorderTop()
{
return $this->_borderTop;
}
/**
* sets border format for bottom border
*
* @param PHPRtfLite_Border_Format $borderFormat
*/
public function setBorderBottom(PHPRtfLite_Border_Format $borderFormat)
{
$borderFormat->setColorTable($this->_rtf->getColorTable());
$this->_borderBottom = $borderFormat;
}
/**
* gets border format of bottom border
*
* @return PHPRtfLite_Border_Format
*/
public function getBorderBottom()
{
return $this->_borderBottom;
}
/**
* gets rtf code of object
*
* @param string $type rtf code part
* @return string rtf code
*/
public function getContent($type = '\\')
{
$content = '';
if ($this->_borderLeft) {
$content .= $type . 'brdrl' . $this->_borderLeft->getContent();
}
if ($this->_borderRight) {
$content .= $type . 'brdrr' . $this->_borderRight->getContent();
}
if ($this->_borderTop) {
$content .= $type . 'brdrt' . $this->_borderTop->getContent();
}
if ($this->_borderBottom) {
$content .= $type . 'brdrb' . $this->_borderBottom->getContent();
}
return $content;
}
}