Changeset 336 for cleversvg/trunk/elements/csGroup.class.php
- Timestamp:
- 03/07/08 08:33:04 (4 years ago)
- Files:
-
- 1 modified
-
cleversvg/trunk/elements/csGroup.class.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cleversvg/trunk/elements/csGroup.class.php
r322 r336 2 2 /** 3 3 * SVG Group class 4 * 4 * 5 5 * @author Nicolas Perriault <nperriault@gmail.com> 6 6 * @package cleversvg 7 7 * @subpackage elements 8 8 */ 9 class csGroup extends cs BaseElement9 class csGroup extends csElementsContainer 10 10 { 11 11 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'; 16 23 17 24 /** 18 25 * Class constructor 19 * 26 * 20 27 * @param mixed $id The DOM id of the element 21 28 * @param array $attrs More attributes to affect 22 29 */ 23 public function __construct($id =null, $attrs=array())30 public function __construct($id = null, $attrs = array()) 24 31 { 25 32 $this->setId($id); 26 33 $this->attributes = array_merge($attrs, $this->attributes); 34 $this->container = new csElementsContainer(); 27 35 } 28 36 29 37 /** 30 38 * Computes DOMXML Node 31 * 39 * 32 40 * @param boolean $embedded Is SVG element embedded ? 33 41 * @return DOMElement 34 42 */ 35 public function compile($embedded =false)43 public function compile($embedded = false) 36 44 { 37 45 $group_node = parent::compile($embedded); 38 46 $dom = $this->getDomDocument(); 39 47 40 48 # Prefix 41 49 $prefix = $embedded === true ? 'svg:' : ''; 42 50 43 51 // Add elements to current group node 44 52 foreach ($this->getElements() as $element) … … 47 55 $group_node->appendChild($node_element); 48 56 } 49 57 50 58 // Add used definitions 51 59 foreach ($this->used_definitions as $used_definition) … … 65 73 $group_node->appendChild($use_node); 66 74 } 67 75 68 76 return $group_node; 69 77 } 70 78 71 79 /** 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 75 84 */ 76 85 public function addElement($element) 77 86 { 78 $this->elements[] = $element;87 return $this->container->addElement($element); 79 88 } 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 81 102 /** 82 103 * Returns an array containing current group elements 83 * 84 * @return array 104 * 105 * @return array 85 106 */ 86 p rotectedfunction getElements()107 public function getElements() 87 108 { 88 return $this-> elements;109 return $this->container->getElements(); 89 110 } 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 91 123 /** 92 124 * Uses a definition in current group 93 * 125 * 94 126 * @param mixed $element 95 127 * @param array $attrs More atributes to add to <use/> tag 96 128 */ 97 public function useDefinition($definition, $attrs =array())129 public function useDefinition($definition, $attrs = array()) 98 130 { 99 $this->used_definitions[] = array($definition, $attrs);131 return $this->container->useDefinition($definition, $attrs); 100 132 } 101 133 102 134 }
