/** * Obtains the node's very own opacity value, as specified in its styles, * taking care of 'inherit' and defaulting to 1. * * @param SVGNode $node The node to get the opacity value of. * * @return float The node's own opacity value. */ private static function getNodeOpacity(SVGNode $node) { $opacity = $node->getStyle('opacity'); if (is_numeric($opacity)) { return floatval($opacity); } elseif ($opacity === 'inherit') { $parent = $node->getParent(); if (isset($parent)) { return self::getNodeOpacity($parent); } } return 1; }
/** * @param string|null $cx The center's x coordinate. * @param string|null $cy The center's y coordinate. * @param string|null $r The radius. */ public function __construct($cx = null, $cy = null, $r = null) { parent::__construct(); $this->setAttributeOptional('cx', $cx); $this->setAttributeOptional('cy', $cy); $this->setAttributeOptional('r', $r); }
/** * @param string|null $x1 The first point's x coordinate. * @param string|null $y1 The first point's y coordinate. * @param string|null $x2 The second point's x coordinate. * @param string|null $y2 The second point's y coordinate. */ public function __construct($x1 = null, $y1 = null, $x2 = null, $y2 = null) { parent::__construct(); $this->setAttributeOptional('x1', $x1); $this->setAttributeOptional('y1', $y1); $this->setAttributeOptional('x2', $x2); $this->setAttributeOptional('y2', $y2); }
/** * @param string|null $x The x coordinate of the upper left corner. * @param string|null $y The y coordinate of the upper left corner. * @param string|null $width The width. * @param string|null $height The height. */ public function __construct($x = null, $y = null, $width = null, $height = null) { parent::__construct(); $this->setAttributeOptional('x', $x); $this->setAttributeOptional('y', $y); $this->setAttributeOptional('width', $width); $this->setAttributeOptional('height', $height); }
/** * Converts the given node into its XML representation and appends that to * this writer's output string. * * The generated string contains the attributes defined via * SVGNode::getSerializableAttributes() and the styles defined via * SVGNode::getSerializableStyles(). * Container nodes (<g></g>) and self-closing tags (<rect />) are * distinguished correctly. * * @param SVGNode $node The node to write. * * @return void */ public function writeNode(SVGNode $node) { $this->outString .= '<' . $node->getName(); $this->appendAttributes($node->getSerializableAttributes()); $this->appendStyles($node->getSerializableStyles()); if (!$node instanceof SVGNodeContainer) { $this->outString .= ' />'; return; } $this->outString .= '>'; for ($i = 0, $n = $node->countChildren(); $i < $n; ++$i) { $this->writeNode($node->getChild($i)); } $this->outString .= '</' . $node->getName() . '>'; }
public function __construct() { parent::__construct(); $this->children = array(); }
public function getSerializableAttributes() { $attrs = parent::getSerializableAttributes(); $points = ''; for ($i = 0, $n = count($this->points); $i < $n; ++$i) { $point = $this->points[$i]; if ($i > 0) { $points .= ' '; } $points .= $point[0] . ',' . $point[1]; } $attrs['points'] = $points; return $attrs; }
/** * Parses the 'style' attribute (if it exists) and applies all styles to the * given node. * * This method does NOT handle styles expressed as attributes (stroke=""). * @see SVGReader::applyAttributes() For styles expressed as attributes. * * @param SVGNode $node The node to apply the styles to. * @param \SimpleXMLElement $xml The attribute source. * * @return void */ private function applyStyles(SVGNode $node, \SimpleXMLElement $xml) { if (!isset($xml['style'])) { return; } $styles = $this->parseStyles($xml['style']); foreach ($styles as $key => $value) { $node->setStyle($key, $value); } }
/** * @param string|null $d The path description. */ public function __construct($d = null) { parent::__construct(); $this->setAttributeOptional('d', $d); }