Image_GIS
[ class tree: Image_GIS ] [ index: Image_GIS ] [ all elements ]

Source for file SVG.php

Documentation is available at SVG.php

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: Image :: GIS :: SVG Renderer                                   |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2005 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 299207 2010-05-10 10:21:58Z clockwerx $
  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 &copy; 2002-2005 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.     /**
  32.     * SVG Document.
  33.     *
  34.     * @var XML_SVG $svg 
  35.     */
  36.     var $svg;
  37.  
  38.     /**
  39.     * SVG Groups.
  40.     *
  41.     * @var XML_SVG_Group[] 
  42.     */
  43.     var $svgGroups = array();
  44.  
  45.     /**
  46.     * Constructor.
  47.     *
  48.     * @param  mixed   $width 
  49.     * @param  integer $sizyY 
  50.     * @param  boolean $debug 
  51.     * @access public
  52.     */
  53.     function Image_GIS_Renderer_SVG($width$height$debug{
  54.         $this->Image_GIS_Renderer($width$height$debug);
  55.  
  56.         $this->svg = new XML_SVG_Document(
  57.           array(
  58.             'width'  => $width,
  59.             'height' => $height
  60.           )
  61.         );
  62.     }
  63.  
  64.     /**
  65.     * Draws a line from ($x1, $y1) to ($x2, $y2)
  66.     * using the color rgb($r, $g, $b).
  67.     *
  68.     * @param  float   $x1 
  69.     * @param  float   $y1 
  70.     * @param  float   $x2 
  71.     * @param  float   $y2 
  72.     * @param  float   $r 
  73.     * @param  float   $g 
  74.     * @param  float   $b 
  75.     * @access public
  76.     */
  77.     function drawLine($x1$y1$x2$y2$r$g$b{
  78.         $group md5($r $g $b);
  79.  
  80.         if (!isset($this->svgGroups[$group])) {
  81.             $this->svgGroups[$group= new XML_SVG_Group(
  82.               array(
  83.                 'style' => sprintf(
  84.                   'stroke:rgb(%s, %s, %s)',
  85.  
  86.                   $r,
  87.                   $g,
  88.                   $b
  89.                 )
  90.               )
  91.             );
  92.  
  93.             $this->svgGroups[$group]->addParent($this->svg);
  94.         }
  95.  
  96.         $line = new XML_SVG_Line(
  97.           array(
  98.             'x1'    => $x1,
  99.             'y1'    => $y1,
  100.             'x2'    => $x2,
  101.             'y2'    => $y2,
  102.           )
  103.         );
  104.  
  105.         $this->svgGroups[$group]->addChild($line);
  106.     }
  107.  
  108.     /**
  109.     * Saves the rendered image to a given file.
  110.     *
  111.     * @param  string  $filename 
  112.     * @return boolean 
  113.     * @access public
  114.     */
  115.     function saveImage($filename{
  116.         if ($fp @fopen($filename'w')) {
  117.             @fputs($fp$this->svg->bufferObject());
  118.             @fclose($fp);
  119.  
  120.             return true;
  121.         }
  122.  
  123.         return false;
  124.     }
  125.  
  126.     /**
  127.     * Shows the rendered image.
  128.     *
  129.     * @access public
  130.     */
  131.     function showImage({
  132.         $this->svg->printElement();
  133.     }
  134. }
  135. ?>

Documentation generated on Mon, 11 Mar 2019 15:39:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.