home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Image / GIS / Renderer / SVG.php < prev   
Encoding:
PHP Script  |  2008-07-02  |  3.6 KB  |  137 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: Image :: GIS :: SVG Renderer                                   |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and             |
  7. // |                         Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  8. // +------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,        |
  10. // | that is available at http://www.php.net/license/3_0.txt.               |
  11. // | If you did not receive a copy of the PHP license and are unable to     |
  12. // | obtain it through the world-wide-web, please send a note to            |
  13. // | license@php.net so we can mail you a copy immediately.                 |
  14. // +------------------------------------------------------------------------+
  15. //
  16. // $Id: SVG.php,v 1.8 2004/04/17 10:21:26 sebastian Exp $
  17. //
  18.  
  19. require_once 'Image/GIS/Renderer.php';
  20. require_once 'XML/SVG.php';
  21.  
  22. /**
  23.  * SVG Renderer.
  24.  *
  25.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  26.  * @copyright   Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de>
  27.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  28.  * @category    Image
  29.  * @package     Image_GIS
  30.  */
  31. class Image_GIS_Renderer_SVG extends Image_GIS_Renderer {
  32.     /**
  33.     * SVG Document.
  34.     *
  35.     * @var XML_SVG $svg
  36.     */
  37.     var $svg;
  38.  
  39.     /**
  40.     * SVG Groups.
  41.     *
  42.     * @var XML_SVG_Group[]
  43.     */
  44.     var $svgGroups = array();
  45.  
  46.     /**
  47.     * Constructor.
  48.     *
  49.     * @param  mixed   $width
  50.     * @param  integer $sizyY
  51.     * @param  boolean $debug
  52.     * @access public
  53.     */
  54.     function Image_GIS_Renderer_SVG($width, $height, $debug) {
  55.         $this->Image_GIS_Renderer($width, $height, $debug);
  56.  
  57.         $this->svg = new XML_SVG_Document(
  58.           array(
  59.             'width'  => $width,
  60.             'height' => $height
  61.           )
  62.         );
  63.     }
  64.  
  65.     /**
  66.     * Draws a line from ($x1, $y1) to ($x2, $y2)
  67.     * using the color rgb($r, $g, $b).
  68.     *
  69.     * @param  float   $x1
  70.     * @param  float   $y1
  71.     * @param  float   $x2
  72.     * @param  float   $y2
  73.     * @param  float   $r
  74.     * @param  float   $g
  75.     * @param  float   $b
  76.     * @access public
  77.     */
  78.     function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) {
  79.         $group = md5($r . $g . $b);
  80.  
  81.         if (!isset($this->svgGroups[$group])) {
  82.             $this->svgGroups[$group] = new XML_SVG_Group(
  83.               array(
  84.                 'style' => sprintf(
  85.                   'stroke:rgb(%s, %s, %s)',
  86.  
  87.                   $r,
  88.                   $g,
  89.                   $b
  90.                 )
  91.               )
  92.             );
  93.  
  94.             $this->svgGroups[$group]->addParent($this->svg);
  95.         }
  96.  
  97.         $line = new XML_SVG_Line(
  98.           array(
  99.             'x1'    => $x1,
  100.             'y1'    => $y1,
  101.             'x2'    => $x2,
  102.             'y2'    => $y2,
  103.           )
  104.         );
  105.  
  106.         $this->svgGroups[$group]->addChild($line);
  107.     }
  108.  
  109.     /**
  110.     * Saves the rendered image to a given file.
  111.     *
  112.     * @param  string  $filename
  113.     * @return boolean
  114.     * @access public
  115.     */
  116.     function saveImage($filename) {
  117.         if ($fp = @fopen($filename, 'w')) {
  118.             @fputs($fp, $this->svg->bufferObject());
  119.             @fclose($fp);
  120.  
  121.             return true;
  122.         }
  123.  
  124.         return false;
  125.     }
  126.  
  127.     /**
  128.     * Shows the rendered image.
  129.     *
  130.     * @access public
  131.     */
  132.     function showImage() {
  133.         $this->svg->printElement();
  134.     }
  135. }
  136. ?>
  137.