1
0
Fork 0
aclindsay.com/svgparser/parser/objects/LinearGradient.php

91 lines
2.2 KiB
PHP

<?php
/*
SVG to dojox.gfx Parser
Copyright (C) 2009 Aaron Lindsay <aclindsay@aclindsay.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
require_once("objects/Gradient.php");
class LinearGradient extends Gradient {
private $x1;
private $y1;
private $x2;
private $y2;
private $transformsApplied = false;
public function __construct() {
parent::__construct();
}
public function setX1($x) {
$this->x1 = $x;
}
public function setY1($x) {
$this->y1 = $x;
}
public function setX2($x) {
$this->x2 = $x;
}
public function setY2($x) {
$this->y2 = $x;
}
public function getX1() {
return $this->x1;
}
public function getY1() {
return $this->y1;
}
public function getX2() {
return $this->x2;
}
public function getY2() {
return $this->y2;
}
public function isValid() {
if (!parent::isValid())
return false;
if (!isset($this->x1) || !isset($this->y1) || !isset($this->x2) || !isset($this->y2))
return false;
return true;
}
public function transformsApplied() {
return $this->transformsApplied;
}
//apply all the transforms to the points in this gradient
public function applyTransforms() {
$transforms = $this->getTransforms();
foreach($transforms as $transform) {
$oldX1 = $this->x1;
$oldY1 = $this->y1;
$oldX2 = $this->x2;
$oldY2 = $this->y2;
$this->x1 = $transform->applyToX($oldX1, $oldY1);
$this->y1 = $transform->applyToY($oldX1, $oldY1);
$this->x2 = $transform->applyToX($oldX2, $oldY2);
$this->y2 = $transform->applyToY($oldX2, $oldY2);
}
$this->transformsApplied = true;
}
}
?>