composer package updates
[openemr.git] / vendor / phenx / php-svg-lib / src / Svg / Tag / LinearGradient.php
blob605ec23d97c7c61734c83f2f444360c21564042a
1 <?php
2 /**
3 * @package php-svg-lib
4 * @link http://github.com/PhenX/php-svg-lib
5 * @author Fabien Ménager <fabien.menager@gmail.com>
6 * @license GNU LGPLv3+ http://www.gnu.org/copyleft/lesser.html
7 */
9 namespace Svg\Tag;
12 use Svg\Gradient;
13 use Svg\Style;
15 class LinearGradient extends AbstractTag
17 protected $x1;
18 protected $y1;
19 protected $x2;
20 protected $y2;
22 /** @var Gradient\Stop[] */
23 protected $stops = array();
25 public function start($attributes)
27 parent::start($attributes);
29 if (isset($attributes['x1'])) {
30 $this->x1 = $attributes['x1'];
32 if (isset($attributes['y1'])) {
33 $this->y1 = $attributes['y1'];
35 if (isset($attributes['x2'])) {
36 $this->x2 = $attributes['x2'];
38 if (isset($attributes['y2'])) {
39 $this->y2 = $attributes['y2'];
43 public function getStops() {
44 if (empty($this->stops)) {
45 foreach ($this->children as $_child) {
46 if ($_child->tagName != "stop") {
47 continue;
50 $_stop = new Gradient\Stop();
51 $_attributes = $_child->attributes;
53 // Style
54 if (isset($_attributes["style"])) {
55 $_style = Style::parseCssStyle($_attributes["style"]);
57 if (isset($_style["stop-color"])) {
58 $_stop->color = Style::parseColor($_style["stop-color"]);
61 if (isset($_style["stop-opacity"])) {
62 $_stop->opacity = max(0, min(1.0, $_style["stop-opacity"]));
66 // Attributes
67 if (isset($_attributes["offset"])) {
68 $_stop->offset = $_attributes["offset"];
70 if (isset($_attributes["stop-color"])) {
71 $_stop->color = Style::parseColor($_attributes["stop-color"]);
73 if (isset($_attributes["stop-opacity"])) {
74 $_stop->opacity = max(0, min(1.0, $_attributes["stop-opacity"]));
77 $this->stops[] = $_stop;
81 return $this->stops;