[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 3 require_once dirname(__FILE__) . '/../Image.php'; 4 require_once 'XML/SVG.php'; 5 6 /** 7 * This class implements the Horde_Image:: API for SVG. 8 * 9 * $Horde: framework/Image/Image/svg.php,v 1.31.10.6 2006/01/01 21:28:22 jan Exp $ 10 * 11 * Copyright 2002-2006 Chuck Hagenbuch <chuck@horde.org> 12 * 13 * See the enclosed file COPYING for license information (LGPL). If you 14 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 15 * 16 * @author Chuck Hagenbuch <chuck@horde.org> 17 * @since Horde 3.0 18 * @package Horde_Image 19 */ 20 class Horde_Image_svg extends Horde_Image { 21 22 var $_svg; 23 24 /** 25 * Capabilites of this driver. 26 * 27 * @var array 28 */ 29 var $_capabilities = array('canvas'); 30 31 function Horde_Image_svg($params) 32 { 33 parent::Horde_Image($params); 34 $this->_svg = &new XML_SVG_Document(array('width' => $this->_width, 35 'height' => $this->_height)); 36 } 37 38 function getContentType() 39 { 40 return 'image/svg+xml'; 41 } 42 43 function getLink($url, $title = '') 44 { 45 } 46 47 function display() 48 { 49 $this->_svg->printElement(); 50 } 51 52 /** 53 * Return the raw data for this image. 54 * 55 * @return string The raw image data. 56 */ 57 function raw() 58 { 59 return $this->_svg->bufferObject(); 60 } 61 62 function getFont($font) 63 { 64 return $font; 65 } 66 67 function _createSymbol($s, $id) 68 { 69 $s->setParam('id', $id); 70 $defs = &new XML_SVG_Defs(); 71 $defs->addChild($s); 72 $this->_svg->addChild($defs); 73 } 74 75 function _createDropShadow($id = 'dropShadow') 76 { 77 $defs = &new XML_SVG_Defs(); 78 $filter = &new XML_SVG_Filter(array('id' => $id)); 79 $filter->addPrimitive('GaussianBlur', array('in' => 'SourceAlpha', 80 'stdDeviation' => 2, 81 'result' => 'blur')); 82 $filter->addPrimitive('Offset', array('in' => 'blur', 83 'dx' => 4, 84 'dy' => 4, 85 'result' => 'offsetBlur')); 86 $merge = &new XML_SVG_FilterPrimitive('Merge'); 87 $merge->addMergeNode('offsetBlur'); 88 $merge->addMergeNode('SourceGraphic'); 89 90 $filter->addChild($merge); 91 $defs->addChild($filter); 92 $this->_svg->addChild($defs); 93 } 94 95 /** 96 * Draws a text string on the image in a specified location, with 97 * the specified style information. 98 * 99 * @param string $text The text to draw. 100 * @param integer $x The left x coordinate of the start of the text string. 101 * @param integer $y The top y coordinate of the start of the text string. 102 * @param string $font The font identifier you want to use for the text. 103 * @param string $color The color that you want the text displayed in. 104 * @param integer $direction An integer that specifies the orientation of the text. 105 */ 106 function text($string, $x, $y, $font = 'monospace', $color = 'black', $direction = 0) 107 { 108 $height = 12; 109 $style = 'font-family:' . $font . ';font-height:' . $height . 'px;fill:' . $this->getHexColor($color) . ';text-anchor:start;'; 110 $transform = 'rotate(' . $direction . ',' . $x . ',' . $y . ')'; 111 $this->_svg->addChild(new XML_SVG_Text(array('text' => $string, 112 'x' => (int)$x, 113 'y' => (int)$y + $height, 114 'transform' => $transform, 115 'style' => $style))); 116 } 117 118 /** 119 * Draw a circle. 120 * 121 * @param integer $x The x coordinate of the centre. 122 * @param integer $y The y coordinate of the centre. 123 * @param integer $r The radius of the circle. 124 * @param string $color The line color of the circle. 125 * @param string $fill The color to fill the circle. 126 */ 127 function circle($x, $y, $r, $color, $fill = null) 128 { 129 if (!empty($fill)) { 130 $style = 'fill:' . $this->getHexColor($fill) . '; '; 131 } else { 132 $style = 'fill:none;'; 133 } 134 $style .= 'stroke:' . $this->getHexColor($color) . '; stroke-width:1'; 135 136 $this->_svg->addChild(new XML_SVG_Circle(array('cx' => $x, 137 'cy' => $y, 138 'r' => $r, 139 'style' => $style))); 140 } 141 142 /** 143 * Draw a polygon based on a set of vertices. 144 * 145 * @param array $vertices An array of x and y labeled arrays 146 * (eg. $vertices[0]['x'], $vertices[0]['y'], ...). 147 * @param string $color The color you want to draw the polygon with. 148 * @param string $fill The color to fill the polygon. 149 */ 150 function polygon($verts, $color, $fill = null) 151 { 152 if (!empty($fill)) { 153 $style = 'fill:' . $this->getHexColor($fill) . '; '; 154 } else { 155 $style = 'fill:none;'; 156 } 157 $style .= 'stroke:' . $this->getHexColor($color) . '; stroke-width:1'; 158 159 $points = ''; 160 foreach ($verts as $v) { 161 $points .= $v['x'] . ',' . $v['y'] . ' '; 162 } 163 $points = trim($points); 164 165 $this->_svg->addChild(new XML_SVG_Polygon(array('points' => $points, 166 'style' => $style))); 167 } 168 169 /** 170 * Draw a rectangle. 171 * 172 * @param integer $x The left x-coordinate of the rectangle. 173 * @param integer $y The top y-coordinate of the rectangle. 174 * @param integer $width The width of the rectangle. 175 * @param integer $height The height of the rectangle. 176 * @param string $color The line color of the rectangle. 177 * @param string $fill The color to fill the rectangle. 178 */ 179 function rectangle($x, $y, $width, $height, $color, $fill = null) 180 { 181 if (!empty($fill)) { 182 $style = 'fill:' . $this->getHexColor($fill) . '; '; 183 } else { 184 $style = 'fill:none;'; 185 } 186 $style .= 'stroke:' . $this->getHexColor($color) . '; stroke-width:1'; 187 188 $this->_svg->addChild(new XML_SVG_Rect(array('x' => $x, 189 'y' => $y, 190 'width' => $width, 191 'height' => $height, 192 'style' => $style))); 193 } 194 195 /** 196 * Draw a rectangle. 197 * 198 * @param integer $x The left x-coordinate of the rectangle. 199 * @param integer $y The top y-coordinate of the rectangle. 200 * @param integer $width The width of the rectangle. 201 * @param integer $height The height of the rectangle. 202 * @param integer $round The width of the corner rounding. 203 * @param string $color The line color of the rectangle. 204 * @param string $fill The color to fill the rectangle. 205 */ 206 function roundedRectangle($x, $y, $width, $height, $round, $color, $fill) 207 { 208 if (!empty($fill)) { 209 $style = 'fill:' . $this->getHexColor($fill) . '; '; 210 } else { 211 $style = 'fill:none;'; 212 } 213 $style .= 'stroke:' . $this->getHexColor($color) . '; stroke-width:1'; 214 215 $this->_svg->addChild(new XML_SVG_Rect(array('x' => $x, 216 'y' => $y, 217 'rx' => $round, 218 'ry' => $round, 219 'width' => $width, 220 'height' => $height, 221 'style' => $style))); 222 } 223 224 /** 225 * Draw a line. 226 * 227 * @param integer $x0 The x coordinate of the start. 228 * @param integer $y0 The y coordinate of the start. 229 * @param integer $x1 The x coordinate of the end. 230 * @param integer $y1 The y coordinate of the end. 231 * @param string $color The line color. 232 * @param string $width The width of the line. 233 */ 234 function line($x1, $y1, $x2, $y2, $color = 'black', $width = 1) 235 { 236 $style = 'stroke:' . $this->getHexColor($color) . '; stroke-width:' . (int)$width; 237 $this->_svg->addChild(new XML_SVG_Line(array('x1' => $x1, 238 'y1' => $y1, 239 'x2' => $x2, 240 'y2' => $y2, 241 'style' => $style))); 242 } 243 244 /** 245 * Draw a dashed line. 246 * 247 * @param integer $x0 The x coordinate of the start. 248 * @param integer $y0 The y coordinate of the start. 249 * @param integer $x1 The x coordinate of the end. 250 * @param integer $y1 The y coordinate of the end. 251 * @param string $color The line color. 252 * @param string $width The width of the line. 253 * @param integer $dash_length The length of a dash on the dashed line 254 * @param integer $dash_space The length of a space in the dashed line 255 */ 256 function dashedLine($x1, $y1, $x2, $y2, $color = 'black', $width = 1, $dash_length = 2, $dash_space = 2) 257 { 258 $style = 'stroke:' . $this->getHexColor($color) . '; stroke-width:' . (int)$width . '; stroke-dasharray:' . $dash_length . ',' . $dash_space . ';'; 259 $this->_svg->addChild(new XML_SVG_Line(array('x1' => $x1, 260 'y1' => $y1, 261 'x2' => $x2, 262 'y2' => $y2, 263 'style' => $style))); 264 } 265 266 /** 267 * Draw a polyline (a non-closed, non-filled polygon) based on a 268 * set of vertices. 269 * 270 * @param array $vertices An array of x and y labeled arrays 271 * (eg. $vertices[0]['x'], $vertices[0]['y'], ...). 272 * @param string $color The color you want to draw the line with. 273 * @param string $width The width of the line. 274 */ 275 function polyline($verts, $color, $width = 1) 276 { 277 $style = 'stroke:' . $this->getHexColor($color) . '; stroke-width:' . $width . ';fill:none;'; 278 279 // Calculate the path entry. 280 $path = ''; 281 282 $first = true; 283 foreach ($verts as $vert) { 284 if ($first) { 285 $first = false; 286 $path .= 'M ' . $vert['x'] . ',' . $vert['y']; 287 } else { 288 $path .= ' L ' . $vert['x'] . ',' . $vert['y']; 289 } 290 } 291 292 $this->_svg->addChild(new XML_SVG_Path(array('d' => $path, 293 'style' => $style))); 294 } 295 296 /** 297 * Draw an arc. 298 * 299 * @param integer $x The x coordinate of the centre. 300 * @param integer $y The y coordinate of the centre. 301 * @param integer $r The radius of the arc. 302 * @param integer $start The start angle of the arc. 303 * @param integer $end The end angle of the arc. 304 * @param string $color The line color of the arc. 305 * @param string $fill The fill color of the arc (defaults to none). 306 */ 307 function arc($x, $y, $r, $start, $end, $color = 'black', $fill = null) 308 { 309 if (!empty($fill)) { 310 $style = 'fill:' . $this->getHexColor($fill) . '; '; 311 } else { 312 $style = 'fill:none;'; 313 } 314 $style .= 'stroke:' . $this->getHexColor($color) . '; stroke-width:1'; 315 316 $mid = round(($start + $end) / 2); 317 318 // Calculate the path entry. 319 $path = ''; 320 321 // If filled, draw the outline. 322 if (!empty($fill)) { 323 // Start at the center of the ellipse the arc is on. 324 $path .= "M $x,$y "; 325 326 // Draw out to ellipse edge. 327 list($arcX, $arcY) = $this->_circlePoint($start, $r * 2); 328 $path .= 'L ' . round($x + $arcX) . ',' . 329 round($y + $arcY) . ' '; 330 } 331 332 // Draw arcs. 333 list($arcX, $arcY) = $this->_circlePoint($mid, $r * 2); 334 $path .= "A $r,$r 0 0 1 " . 335 round($x + $arcX) . ',' . 336 round($y + $arcY) . ' '; 337 338 list($arcX, $arcY) = $this->_circlePoint($end, $r * 2); 339 $path .= "A $r,$r 0 0 1 " . 340 round($x + $arcX) . ',' . 341 round($y + $arcY) . ' '; 342 343 // If filled, close the outline. 344 if (!empty($fill)) { 345 $path .= 'Z'; 346 } 347 348 $path = trim($path); 349 350 $this->_svg->addChild(new XML_SVG_Path(array('d' => $path, 351 'style' => $style))); 352 } 353 354 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |