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
|
<?php
/**
* File containing the ezcGraphFontOption class
*
* @package Graph
* @version //autogentag//
* @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Class containing the basic options for charts
*
* @property string $name
* Name of font.
* @property string $path
* Path to font file.
* @property string $type
* Type of used font. May be one of the following:
* - TTF_FONT Native TTF fonts
* - PS_FONT PostScript Type1 fonts
* - FT2_FONT FreeType 2 fonts
* @property float $minFontSize
* Minimum font size for displayed texts.
* @property float $maxFontSize
* Maximum font size for displayed texts.
* @property float $minimalUsedFont
* The minimal used font size for this element.
* @property ezcGraphColor $color
* Font color.
* @property ezcGraphColor $background
* Background color
* @property ezcGraphColor $border
* Border color
* @property int $borderWidth
* Border width
* @property int $padding
* Padding between text and border
* @property bool $minimizeBorder
* Fit the border exactly around the text, or use the complete
* possible space.
* @property bool $textShadow
* Draw shadow for texts
* @property int $textShadowOffset
* Offset for text shadow
* @property ezcGraphColor $textShadowColor
* Color of text shadow. If false the inverse color of the text
* color will be used.
*
* @package Graph
*/
class ezcGraphFontOptions extends ezcBaseOptions
{
protected $pathChecked = false;
/**
* Constructor
*
* @param array $options Default option array
* @return void
* @ignore
*/
public function __construct( array $options = array() )
{
$this->properties['name'] = 'sans-serif';
// $this->properties['path'] = 'Graph/tests/data/font.ttf';
$this->properties['path'] = '';
$this->properties['type'] = ezcGraph::TTF_FONT;
$this->properties['minFontSize'] = 6;
$this->properties['maxFontSize'] = 96;
$this->properties['minimalUsedFont'] = 96;
$this->properties['color'] = ezcGraphColor::fromHex( '#000000' );
$this->properties['background'] = false;
$this->properties['border'] = false;
$this->properties['borderWidth'] = 1;
$this->properties['padding'] = 0;
$this->properties['minimizeBorder'] = true;
$this->properties['textShadow'] = false;
$this->properties['textShadowOffset'] = 1;
$this->properties['textShadowColor'] = false;
parent::__construct( $options );
}
/**
* Set an option value
*
* @param string $propertyName
* @param mixed $propertyValue
* @throws ezcBasePropertyNotFoundException
* If a property is not defined in this class
* @return void
*/
public function __set( $propertyName, $propertyValue )
{
switch ( $propertyName )
{
case 'minFontSize':
case 'maxFontSize':
if ( !is_numeric( $propertyValue ) ||
( $propertyValue < 1 ) )
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 1' );
}
$this->properties[$propertyName] = (float) $propertyValue;
break;
case 'minimalUsedFont':
$propertyValue = (float) $propertyValue;
if ( $propertyValue < $this->minimalUsedFont )
{
$this->properties['minimalUsedFont'] = $propertyValue;
}
break;
case 'color':
case 'background':
case 'border':
case 'textShadowColor':
$this->properties[$propertyName] = ezcGraphColor::create( $propertyValue );
break;
case 'borderWidth':
case 'padding':
case 'textShadowOffset':
if ( !is_numeric( $propertyValue ) ||
( $propertyValue < 0 ) )
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
}
$this->properties[$propertyName] = (int) $propertyValue;
break;
case 'minimizeBorder':
case 'textShadow':
if ( !is_bool( $propertyValue ) )
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'bool' );
}
$this->properties[$propertyName] = (bool) $propertyValue;
break;
case 'name':
if ( is_string( $propertyValue ) )
{
$this->properties['name'] = $propertyValue;
}
else
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'string' );
}
break;
case 'path':
if ( is_file( $propertyValue ) && is_readable( $propertyValue ) )
{
$this->properties['path'] = realpath( $propertyValue );
$parts = pathinfo( $this->properties['path'] );
switch ( strtolower( $parts['extension'] ) )
{
case 'fdb':
$this->properties['type'] = ezcGraph::PALM_FONT;
break;
case 'pfb':
$this->properties['type'] = ezcGraph::PS_FONT;
break;
case 'ttf':
$this->properties['type'] = ezcGraph::TTF_FONT;
break;
default:
throw new ezcGraphUnknownFontTypeException( $propertyValue, $parts['extension'] );
}
$this->pathChecked = true;
}
else
{
throw new ezcBaseFileNotFoundException( $propertyValue, 'font' );
}
break;
case 'type':
if ( is_int( $propertyValue ) )
{
$this->properties['type'] = $propertyValue;
}
else
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int' );
}
break;
default:
throw new ezcBasePropertyNotFoundException( $propertyName );
break;
}
}
/**
* __get
*
* @param mixed $propertyName
* @throws ezcBasePropertyNotFoundException
* If a the value for the property options is not an instance of
* @return mixed
* @ignore
*/
public function __get( $propertyName )
{
switch ( $propertyName )
{
case 'textShadowColor':
// Use inverted font color if false
if ( $this->properties['textShadowColor'] === false )
{
$this->properties['textShadowColor'] = $this->properties['color']->invert();
}
return $this->properties['textShadowColor'];
case 'path':
if ( $this->pathChecked === false )
{
// Enforce call of path check
$this->__set( 'path', $this->properties['path'] );
}
// No break to use parent return
default:
return parent::__get( $propertyName );
}
}
}
?>
|