Show
Ignore:
Timestamp:
03/07/08 08:33:04 (4 years ago)
Author:
nperriault
Message:

Clever Svg:

  • refs #40: more elements tests
  • Removed depth management, as svg handle it natively

Warning: breaks BC from 0.5.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cleversvg/trunk/elements/csGroup.class.php

    r322 r336  
    22/** 
    33 * SVG Group class 
    4  *  
     4 * 
    55 * @author     Nicolas Perriault <nperriault@gmail.com> 
    66 * @package    cleversvg 
    77 * @subpackage elements 
    88 */ 
    9 class csGroup extends csBaseElement 
     9class csGroup extends csElementsContainer 
    1010{ 
    1111 
    12   protected  
    13     $elements         = array(), 
    14     $used_definitions = array(), 
    15     $xml_node_name    = 'g'; 
     12  /** 
     13   * Definitions and elements container 
     14   * @var csElementsContainer 
     15   */ 
     16  protected $container = null; 
     17 
     18  /** 
     19   * SVG XML node name 
     20   * @var string 
     21   */ 
     22  protected $xml_node_name = 'g'; 
    1623 
    1724  /** 
    1825   * Class constructor 
    19    *  
     26   * 
    2027   * @param  mixed  $id     The DOM id of the element 
    2128   * @param  array  $attrs  More attributes to affect 
    2229   */ 
    23   public function __construct($id=null, $attrs=array()) 
     30  public function __construct($id = null, $attrs = array()) 
    2431  { 
    2532    $this->setId($id); 
    2633    $this->attributes = array_merge($attrs, $this->attributes); 
     34    $this->container = new csElementsContainer(); 
    2735  } 
    28    
     36 
    2937  /** 
    3038   * Computes DOMXML Node 
    31    *  
     39   * 
    3240   * @param  boolean  $embedded  Is SVG element embedded ? 
    3341   * @return DOMElement 
    3442   */ 
    35   public function compile($embedded=false) 
     43  public function compile($embedded = false) 
    3644  { 
    3745    $group_node = parent::compile($embedded); 
    3846    $dom = $this->getDomDocument(); 
    39      
     47 
    4048    # Prefix 
    4149    $prefix = $embedded === true ? 'svg:' : ''; 
    42      
     50 
    4351    // Add elements to current group node 
    4452    foreach ($this->getElements() as $element) 
     
    4755      $group_node->appendChild($node_element); 
    4856    } 
    49      
     57 
    5058    // Add used definitions 
    5159    foreach ($this->used_definitions as $used_definition) 
     
    6573      $group_node->appendChild($use_node); 
    6674    } 
    67      
     75 
    6876    return $group_node; 
    6977  } 
    70    
     78 
    7179  /** 
    72    * Adds a SVG element to current group 
    73    *  
    74    * @param  mixed  $element  SVG element to add 
     80   * Adds a SVG shape or group to current SVG Document at a certain depth 
     81   * 
     82   * @param  mixed    $element  SVG element to add 
     83   * @throws csException 
    7584   */ 
    7685  public function addElement($element) 
    7786  { 
    78     $this->elements[] = $element; 
     87    return $this->container->addElement($element); 
    7988  } 
    80    
     89 
     90  /** 
     91   * Retrieve an contained element instance by its DOM id 
     92   * 
     93   * @param  string  $id 
     94   * @return csBaseElement 
     95   * @throw  csException 
     96   */ 
     97  public function getElementById($id) 
     98  { 
     99    return $this->container->getElementById($id); 
     100  } 
     101 
    81102  /** 
    82103   * Returns an array containing current group elements 
    83    *  
    84    * @return array  
     104   * 
     105   * @return array 
    85106   */ 
    86   protected function getElements() 
     107  public function getElements() 
    87108  { 
    88     return $this->elements; 
     109    return $this->container->getElements(); 
    89110  } 
    90    
     111 
     112  /** 
     113   * Checks if a DOM id already exists in current SVG Document 
     114   * 
     115   * @param  string  $id 
     116   * @return boolean 
     117   */ 
     118  public function hasId($id) 
     119  { 
     120    return $this->container->hasId($id); 
     121  } 
     122 
    91123  /** 
    92124   * Uses a definition in current group 
    93    *  
     125   * 
    94126   * @param  mixed  $element 
    95127   * @param  array  $attrs    More atributes to add to &lt;use/&gt; tag 
    96128   */ 
    97   public function useDefinition($definition, $attrs=array()) 
     129  public function useDefinition($definition, $attrs = array()) 
    98130  { 
    99     $this->used_definitions[] = array($definition, $attrs); 
     131    return $this->container->useDefinition($definition, $attrs); 
    100132  } 
    101    
     133 
    102134}