Source for file SvgStyle.php

Documentation is available at SvgStyle.php

  1. <?php
  2. /**
  3.  * $Source: /cvsroot/svggrapher/svggrapher/mains/SvgStyle.php,v $
  4.  *
  5.  * 
  6.  *
  7.  * @version $Id: SvgStyle.php,v 1.4 2007/10/20 22:22:53 geelweb Exp $
  8.  * @author Guillaume L. <guillaume@geelweb.org>
  9.  * @copyright Copyright © 2006, Guillaume Luchet.
  10.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  11.  * @package SvgGrapher
  12.  * @subpackage Elements
  13.  */
  14.  
  15. // doc {{{
  16.  
  17. /**
  18.  * SvgStyle.
  19.  *
  20.  * @author Guillaume L. <guillaume@geelweb.org>
  21.  * @link http://www.geelweb.org
  22.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  23.  * @copyright Copyright © 2006, Guillaume Luchet.
  24.  * @version CVS: $Id: SvgStyle.php,v 1.4 2007/10/20 22:22:53 geelweb Exp $
  25.  * @package SvgGrapher
  26.  * @subpackage Elements
  27.  */ // }}}
  28. class SvgStyle 
  29. {
  30.     // properties {{{
  31.  
  32.     /**
  33.      * _styles
  34.      * 
  35.      * @var array 
  36.      * @access private
  37.      */
  38.     private $_styles = array();
  39.     
  40.     // }}}
  41.     // SvgStyle::__construct() {{{
  42.  
  43.     /**
  44.      * __construct
  45.      * 
  46.      * @param mixed $style 
  47.      * @access public
  48.      * @return void 
  49.      */
  50.     public function __construct($style=NULL
  51.     {
  52.           if(!is_null($style)) {
  53.               $this->FromString($style);
  54.           }
  55.     }
  56.  
  57.     // }}}
  58.     // SvgStyle::set() {{{
  59.     
  60.     /**
  61.      * Set a style attribute.
  62.      *
  63.      * @param string $styleName attribute name
  64.      * @param string $styleValue attribute value
  65.      * @return void 
  66.      */
  67.     public function setAttribute($styleName$styleValue=NULL
  68.     {
  69.         if(is_null($styleValue)) {
  70.             unset($this->_styles[$styleName]);
  71.             return;
  72.         }
  73.         $this->_styles[$styleName$styleValue;
  74.     }
  75.  
  76.     // }}}
  77.     // SvgStyle::get() {{{
  78.  
  79.     /**
  80.      * get a style attribute
  81.      *
  82.      * @param string $styleName attribute name.
  83.      * @return string 
  84.      * @todo rename the method getAttribute
  85.      */
  86.     public function getAttribute($styleName
  87.     {
  88.         return isset($this->_styles[$styleName]
  89.             $this->_styles[$styleNamefalse;
  90.     }
  91.  
  92.     // }}}
  93.     // SvgStyle::fromString() {{{
  94.  
  95.     /**
  96.      * 
  97.      * @param string $str Attribut de style SVG.
  98.      * @return void 
  99.      */
  100.     public function fromString($str
  101.     {
  102.         $stylePairs explode(';'$str);
  103.         foreach($stylePairs as $pair{
  104.             $pair trim($pair);
  105.             if(empty($pair)) 
  106.                 continue
  107.             }
  108.             list($styleName$styleValueexplode(':'$pair);
  109.             $this->_styles[trim($styleName)trim($styleValue);
  110.         }
  111.     }
  112.  
  113.     // }}}
  114.     // SvgStyle::toString() {{{
  115.  
  116.     /**
  117.      * toString
  118.      * 
  119.      * @access public
  120.      * @return void 
  121.      */
  122.     public function toString()
  123.     {
  124.         $retStr '';
  125.         foreach($this->_styles as $styleName=>$styleValue{
  126.             $retStr .= $styleName ':' $styleValue ';';
  127.         }
  128.         return $retStr;
  129.     }
  130.  
  131.     // }}}
  132.  
  133.     /**
  134.      * Allow direct acces to set style attributes
  135.      * 
  136.      * <code>
  137.      * $font = new SvgStyle();
  138.      * $font->color = '#000';
  139.      * $font->{'font-size'} = 14;
  140.      * </code>
  141.      *
  142.      * @param mixed $styleName attribute name
  143.      * @param mixed $styleValue attribute value
  144.      * @access public
  145.      * @return void 
  146.      */
  147.     public function __set($styleName$styleValue=NULL)
  148.     {
  149.         $this->setAttribute($styleName$styleValue);
  150.     }
  151.  
  152.     /**
  153.      * Allow direct access to get a style attribute
  154.      *
  155.      * <code>
  156.      * $color = $font->color;
  157.      * $fontSize = $font->{'font-size'};
  158.      * </code>
  159.      * 
  160.      * @param mixed $styleName attribute name
  161.      * @access public
  162.      * @return void 
  163.      */
  164.     public function __get($styleName)
  165.     {
  166.         $this->getAttribute($styleName);
  167.     }
  168. }
  169.  
  170.  
  171. ?>

Documentation generated on Tue, 23 Oct 2007 11:32:18 +0200 by phpDocumentor 1.4.0