blob: 9f3b74484d1dfe9faa15ea570c20e3bfbb1105f0 (
plain)
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
|
<?php
/**
* File containing the ezcGraphFontOption class
*
* @package Graph
* @version //autogentag//
* @copyright Copyright (C) 2005, 2006 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
* - GD_FONT Native GD bitmap 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 float $lineSpacing
* Percent of font size used for line spacing
*
* @package Graph
*/
class ezcGraphFontOptions extends ezcBaseOptions
{
/**
* 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['type'] = ezcGraph::TTF_FONT;
$this->properties['minFontSize'] = 6;
$this->properties['maxFontSize'] = 96;
$this->properties['minimalUsedFont'] = 96;
$this->properties['lineSpacing'] = .1;
$this->properties['color'] = ezcGraphColor::fromHex( '#000000' );
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':
$this->properties['minFontSize'] = max(1, (float) $propertyValue);
break;
case 'maxFontSize':
$this->properties['maxFontSize'] = max(1, (float) $propertyValue);
break;
case 'minimalUsedFont':
$propertyValue = (float) $propertyValue;
if ( $propertyValue < $this->minimalUsedFont )
{
$this->properties['minimalUsedFont'] = $propertyValue;
}
break;
case 'color':
if ( $propertyValue instanceof ezcGraphColor )
{
$this->properties['color'] = $propertyValue;
}
else
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphColor' );
}
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'] = $propertyValue;
// @TODO: Autodetect font type
}
else
{
throw new ezcBaseFileNotFoundException( $propertyValue, 'font' );
}
break;
case 'type':
if ( is_int( $propertyValue ) )
{
$this->properties['type'] = $propertyValue;
}
else
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'int' );
}
default:
throw new ezcBasePropertyNotFoundException( $propertyName );
break;
}
}
}
?>
|