* @package cleversvg * @subpackage gradients */ class csBaseGradient extends csBaseElement { protected $stops = array(), $xml_node_name = 'unknown'; /** * Adds a <stop/> elementto specify gradient marker points * * @param mixed $offset Stop offset (can be percentage) * @param string $stop_color (optional, default=black) * @param string $stop_opacity (optional, default=1) */ public function addStop($offset, $stop_color='black', $stop_opacity=1) { $this->stops[] = array('offset' => $offset, 'stop-color' => $stop_color, 'stop-opacity' => $stop_opacity); } /** * Computes DOMXML Node * * @param boolean $embedded Is SVG element embedded ? * @return DOMElement */ public function compile($embedded=false) { $dom = $this->getDomDocument(); $element_node = parent::compile($embedded); // Add stops if (count($this->stops) > 0) { foreach ($this->stops as $stop) { $stop_node = $dom->createElement($this->getStopNodeName($embedded)); foreach ($stop as $attr_name => $attr_value) { $stop_node->setAttribute($attr_name, $attr_value); } $element_node->appendChild($stop_node); } } return $element_node; } /** * Gets the node name of current SVG element * * @param boolean $embedded * @return string */ protected function getStopNodeName($embedded) { return $embedded === true ? 'svg:stop' : 'stop'; } }