Style.php
6.55 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Style.php 23775 2011-03-01 17:25:24Z ralph $
*/
/**
* Style object.
* Style object doesn't directly correspond to any PDF file object.
* It's utility class, used as a container for style information.
* It's used by Zend_Pdf_Page class in draw operations.
*
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Pdf_Style
{
/**
* Fill color.
* Used to fill geometric shapes or text.
*
* @var Zend_Pdf_Color|null
*/
private $_fillColor = null;
/**
* Line color.
* Current color, used for lines and font outlines.
*
* @var Zend_Pdf_Color|null
*/
private $_color;
/**
* Line width.
*
* @var Zend_Pdf_Element_Numeric
*/
private $_lineWidth;
/**
* Array which describes line dashing pattern.
* It's array of numeric:
* array($on_length, $off_length, $on_length, $off_length, ...)
*
* @var array
*/
private $_lineDashingPattern;
/**
* Line dashing phase
*
* @var float
*/
private $_lineDashingPhase;
/**
* Current font
*
* @var Zend_Pdf_Resource_Font
*/
private $_font;
/**
* Font size
*
* @var float
*/
private $_fontSize;
/**
* Create style.
*
* @param Zend_Pdf_Style $anotherStyle
*/
public function __construct($anotherStyle = null)
{
if ($anotherStyle !== null) {
$this->_fillColor = $anotherStyle->_fillColor;
$this->_color = $anotherStyle->_color;
$this->_lineWidth = $anotherStyle->_lineWidth;
$this->_lineDashingPattern = $anotherStyle->_lineDashingPattern;
$this->_lineDashingPhase = $anotherStyle->_lineDashingPhase;
$this->_font = $anotherStyle->_font;
$this->_fontSize = $anotherStyle->_fontSize;
}
}
/**
* Set fill color.
*
* @param Zend_Pdf_Color $color
*/
public function setFillColor(Zend_Pdf_Color $color)
{
$this->_fillColor = $color;
}
/**
* Set line color.
*
* @param Zend_Pdf_Color $color
*/
public function setLineColor(Zend_Pdf_Color $color)
{
$this->_color = $color;
}
/**
* Set line width.
*
* @param float $width
*/
public function setLineWidth($width)
{
require_once 'Zend/Pdf/Element/Numeric.php';
$this->_lineWidth = new Zend_Pdf_Element_Numeric($width);
}
/**
* Set line dashing pattern
*
* @param array $pattern
* @param float $phase
*/
public function setLineDashingPattern($pattern, $phase = 0)
{
require_once 'Zend/Pdf/Page.php';
if ($pattern === Zend_Pdf_Page::LINE_DASHING_SOLID) {
$pattern = array();
$phase = 0;
}
require_once 'Zend/Pdf/Element/Numeric.php';
$this->_lineDashingPattern = $pattern;
$this->_lineDashingPhase = new Zend_Pdf_Element_Numeric($phase);
}
/**
* Set current font.
*
* @param Zend_Pdf_Resource_Font $font
* @param float $fontSize
*/
public function setFont(Zend_Pdf_Resource_Font $font, $fontSize)
{
$this->_font = $font;
$this->_fontSize = $fontSize;
}
/**
* Modify current font size
*
* @param float $fontSize
*/
public function setFontSize($fontSize)
{
$this->_fontSize = $fontSize;
}
/**
* Get fill color.
*
* @return Zend_Pdf_Color|null
*/
public function getFillColor()
{
return $this->_fillColor;
}
/**
* Get line color.
*
* @return Zend_Pdf_Color|null
*/
public function getLineColor()
{
return $this->_color;
}
/**
* Get line width.
*
* @return float
*/
public function getLineWidth()
{
return $this->_lineWidth->value;
}
/**
* Get line dashing pattern
*
* @return array
*/
public function getLineDashingPattern()
{
return $this->_lineDashingPattern;
}
/**
* Get current font.
*
* @return Zend_Pdf_Resource_Font $font
*/
public function getFont()
{
return $this->_font;
}
/**
* Get current font size
*
* @return float $fontSize
*/
public function getFontSize()
{
return $this->_fontSize;
}
/**
* Get line dashing phase
*
* @return float
*/
public function getLineDashingPhase()
{
return $this->_lineDashingPhase->value;
}
/**
* Dump style to a string, which can be directly inserted into content stream
*
* @return string
*/
public function instructions()
{
$instructions = '';
if ($this->_fillColor !== null) {
$instructions .= $this->_fillColor->instructions(false);
}
if ($this->_color !== null) {
$instructions .= $this->_color->instructions(true);
}
if ($this->_lineWidth !== null) {
$instructions .= $this->_lineWidth->toString() . " w\n";
}
if ($this->_lineDashingPattern !== null) {
require_once 'Zend/Pdf/Element/Array.php';
$dashPattern = new Zend_Pdf_Element_Array();
require_once 'Zend/Pdf/Element/Numeric.php';
foreach ($this->_lineDashingPattern as $dashItem) {
$dashElement = new Zend_Pdf_Element_Numeric($dashItem);
$dashPattern->items[] = $dashElement;
}
$instructions .= $dashPattern->toString() . ' '
. $this->_lineDashingPhase->toString() . " d\n";
}
return $instructions;
}
}