| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * File containing the ezcGraphFontOption class 4 * 5 * @package Graph 6 * @version 1.5 7 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved. 8 * @license http://ez.no/licenses/new_bsd New BSD License 9 */ 10 /** 11 * Class containing the options for font configuration. 12 * 13 * We try to fulfill two goals regarding font configuration. First, there 14 * should be a single point to configure the fonts used for the text areas 15 * in the chart. On the other hand, it should be possible to configure 16 * the fonts independently for each chart element. 17 * 18 * The solution is that you can modify the global font configuration by 19 * accessing $graph->options->font. This takes effect on all chart 20 * elements unless you intentionally access the font configuration of an 21 * individual chart element. The following example shows, how this works. 22 * 23 * <code> 24 * $graph = new ezcGraphPieChart(); 25 * $graph->title = 'Access statistics'; 26 * 27 * // Set the maximum font size to 8 for all chart elements 28 * $graph->options->font->maxFontSize = 8; 29 * 30 * // Set the font size for the title independently to 14 31 * $graph->title->font->maxFontSize = 14; 32 * 33 * // The following only affects all elements except the // title element, 34 * // which now has its own font configuration. 35 * // 36 * // Keep in mind that the specified font is driver specific. A pure name 37 * // works for the SVG driver, used here. The GD driver for example 38 * // requires a path to a TTF file. 39 * $graph->options->font->name = 'serif'; 40 * 41 * $graph->data['Access statistics'] = new ezcGraphArrayDataSet( array( 42 * 'Mozilla' => 19113, 43 * 'Explorer' => 10917, 44 * 'Opera' => 1464, 45 * 'Safari' => 652, 46 * 'Konqueror' => 474, 47 * ) ); 48 * </code> 49 * 50 * @property string $name 51 * Name of font. 52 * @property string $path 53 * Path to font file. 54 * @property int $type 55 * Type of used font. May be one of the following: 56 * - TTF_FONT Native TTF fonts 57 * - PS_FONT PostScript Type1 fonts 58 * - FT2_FONT FreeType 2 fonts 59 * The type is normally automatically detected when you set the path 60 * to the font file. 61 * @property float $minFontSize 62 * Minimum font size for displayed texts. 63 * @property float $maxFontSize 64 * Maximum font size for displayed texts. 65 * @property float $minimalUsedFont 66 * The minimal used font size for the current element group. This 67 * property is set by the driver to maintain this information and 68 * should not be used to configure the apperance of the chart. See 69 * $minFontSize instead. 70 * @property ezcGraphColor $color 71 * Font color. 72 * @property ezcGraphColor $background 73 * Background color. The actual area filled with the background color 74 * is influenced by the settings $padding and $minimizeBorder. 75 * @property ezcGraphColor $border 76 * Border color for the text. The distance between the text and 77 * border is defined by the properties $padding and $minimizeBorder. 78 * @property int $borderWidth 79 * With of the border. To enable the border you need to set the 80 * $border property to some color. 81 * @property int $padding 82 * Padding between text and border. 83 * @property bool $minimizeBorder 84 * Fit the border exactly around the text, or use the complete 85 * possible space. This setting is only relevant, when a border 86 * color has been set for the font. 87 * @property bool $textShadow 88 * Draw shadow for texts. The color of the shadow is defined in 89 * the property $textShadowColor. 90 * @property int $textShadowOffset 91 * Offset for text shadow. This defines the distance the shadow 92 * is moved to the bottom left relative from the text position. 93 * @property ezcGraphColor $textShadowColor 94 * Color of text shadow. If left at the default value "false"" 95 * the inverse color of the text color will be used. 96 * 97 * @version 1.5 98 * @package Graph 99 */ 100 class ezcGraphFontOptions extends ezcBaseOptions 101 { 102 /** 103 * Indicates if path already has been checked for correct font 104 * 105 * @var bool 106 */ 107 protected $pathChecked = false; 108 109 /** 110 * Constructor 111 * 112 * @param array $options Default option array 113 * @return void 114 * @ignore 115 */ 116 public function __construct( array $options = array() ) 117 { 118 $this->properties['name'] = 'sans-serif'; 119 // $this->properties['path'] = 'Graph/tests/data/font.ttf'; 120 $this->properties['path'] = ''; 121 $this->properties['type'] = ezcGraph::TTF_FONT; 122 123 $this->properties['minFontSize'] = 6; 124 $this->properties['maxFontSize'] = 96; 125 $this->properties['minimalUsedFont'] = 96; 126 $this->properties['color'] = ezcGraphColor::fromHex( '#000000' ); 127 128 $this->properties['background'] = false; 129 $this->properties['border'] = false; 130 $this->properties['borderWidth'] = 1; 131 $this->properties['padding'] = 0; 132 $this->properties['minimizeBorder'] = true; 133 134 $this->properties['textShadow'] = false; 135 $this->properties['textShadowOffset'] = 1; 136 $this->properties['textShadowColor'] = false; 137 138 parent::__construct( $options ); 139 } 140 141 /** 142 * Set an option value 143 * 144 * @param string $propertyName 145 * @param mixed $propertyValue 146 * @throws ezcBasePropertyNotFoundException 147 * If a property is not defined in this class 148 * @return void 149 */ 150 public function __set( $propertyName, $propertyValue ) 151 { 152 switch ( $propertyName ) 153 { 154 case 'minFontSize': 155 if ( !is_numeric( $propertyValue ) || 156 ( $propertyValue < 1 ) ) 157 { 158 throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 1' ); 159 } 160 161 // Ensure min font size is smaller or equal max font size. 162 if ( $propertyValue > $this->properties['maxFontSize'] ) 163 { 164 throw new ezcBaseValueException( $propertyName, $propertyValue, 'float <= ' . $this->properties['maxFontSize'] ); 165 } 166 167 $this->properties[$propertyName] = (float) $propertyValue; 168 break; 169 170 case 'maxFontSize': 171 if ( !is_numeric( $propertyValue ) || 172 ( $propertyValue < 1 ) ) 173 { 174 throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 1' ); 175 } 176 177 // Ensure max font size is greater or equal min font size. 178 if ( $propertyValue < $this->properties['minFontSize'] ) 179 { 180 throw new ezcBaseValueException( $propertyName, $propertyValue, 'float >= ' . $this->properties['minFontSize'] ); 181 } 182 183 $this->properties[$propertyName] = (float) $propertyValue; 184 break; 185 186 case 'minimalUsedFont': 187 $propertyValue = (float) $propertyValue; 188 if ( $propertyValue < $this->minimalUsedFont ) 189 { 190 $this->properties['minimalUsedFont'] = $propertyValue; 191 } 192 break; 193 194 case 'color': 195 case 'background': 196 case 'border': 197 case 'textShadowColor': 198 $this->properties[$propertyName] = ezcGraphColor::create( $propertyValue ); 199 break; 200 201 case 'borderWidth': 202 case 'padding': 203 case 'textShadowOffset': 204 if ( !is_numeric( $propertyValue ) || 205 ( $propertyValue < 0 ) ) 206 { 207 throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' ); 208 } 209 210 $this->properties[$propertyName] = (int) $propertyValue; 211 break; 212 213 case 'minimizeBorder': 214 case 'textShadow': 215 if ( !is_bool( $propertyValue ) ) 216 { 217 throw new ezcBaseValueException( $propertyName, $propertyValue, 'bool' ); 218 } 219 $this->properties[$propertyName] = (bool) $propertyValue; 220 break; 221 222 case 'name': 223 if ( is_string( $propertyValue ) ) 224 { 225 $this->properties['name'] = $propertyValue; 226 } 227 else 228 { 229 throw new ezcBaseValueException( $propertyName, $propertyValue, 'string' ); 230 } 231 break; 232 case 'path': 233 if ( is_file( $propertyValue ) && is_readable( $propertyValue ) ) 234 { 235 $this->properties['path'] = $propertyValue; 236 $parts = pathinfo( $this->properties['path'] ); 237 switch ( strtolower( $parts['extension'] ) ) 238 { 239 case 'fdb': 240 $this->properties['type'] = ezcGraph::PALM_FONT; 241 break; 242 case 'pfb': 243 $this->properties['type'] = ezcGraph::PS_FONT; 244 break; 245 case 'ttf': 246 $this->properties['type'] = ezcGraph::TTF_FONT; 247 break; 248 case 'svg': 249 $this->properties['type'] = ezcGraph::SVG_FONT; 250 $this->properties['name'] = ezcGraphSvgFont::getFontName( $propertyValue ); 251 break; 252 default: 253 throw new ezcGraphUnknownFontTypeException( $propertyValue, $parts['extension'] ); 254 } 255 $this->pathChecked = true; 256 } 257 else 258 { 259 throw new ezcBaseFileNotFoundException( $propertyValue, 'font' ); 260 } 261 break; 262 case 'type': 263 if ( is_int( $propertyValue ) ) 264 { 265 $this->properties['type'] = $propertyValue; 266 } 267 else 268 { 269 throw new ezcBaseValueException( $propertyName, $propertyValue, 'int' ); 270 } 271 break; 272 default: 273 throw new ezcBasePropertyNotFoundException( $propertyName ); 274 break; 275 } 276 } 277 278 /** 279 * __get 280 * 281 * @param mixed $propertyName 282 * @throws ezcBasePropertyNotFoundException 283 * If a the value for the property options is not an instance of 284 * @return mixed 285 * @ignore 286 */ 287 public function __get( $propertyName ) 288 { 289 switch ( $propertyName ) 290 { 291 case 'textShadowColor': 292 // Use inverted font color if false 293 if ( $this->properties['textShadowColor'] === false ) 294 { 295 $this->properties['textShadowColor'] = $this->properties['color']->invert(); 296 } 297 298 return $this->properties['textShadowColor']; 299 case 'path': 300 if ( $this->pathChecked === false ) 301 { 302 // Enforce call of path check 303 $this->__set( 'path', $this->properties['path'] ); 304 } 305 // No break to use parent return 306 default: 307 return parent::__get( $propertyName ); 308 } 309 } 310 } 311 312 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |