Initial Commit
This commit is contained in:
41
svgparser/parser/objects/Circle.php
Normal file
41
svgparser/parser/objects/Circle.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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/Element.php");
|
||||
|
||||
class Circle extends Element {
|
||||
private $cx;
|
||||
private $cy;
|
||||
private $r;
|
||||
|
||||
public function __construct() {
|
||||
$this->cx = 0;
|
||||
$this->cy = 0;
|
||||
$this->r = 0;
|
||||
}
|
||||
|
||||
public function getCx() { return $this->cx; }
|
||||
public function getCy() { return $this->cy; }
|
||||
public function getR() { return $this->r; }
|
||||
public function setCx($x) { $this->cx = $x; }
|
||||
public function setCy($x) { $this->cy = $x; }
|
||||
public function setR($x) { $this->r = $x; }
|
||||
}
|
||||
?>
|
183
svgparser/parser/objects/Element.php
Normal file
183
svgparser/parser/objects/Element.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
class Element {
|
||||
private $id;
|
||||
private $styles;
|
||||
private $transforms;
|
||||
private $transform;
|
||||
|
||||
public function __construct() {
|
||||
$this->id = "";
|
||||
$this->styles = array();
|
||||
$this->transforms = array();
|
||||
$this->transform = new Transform();
|
||||
}
|
||||
|
||||
public function setId($newId) {
|
||||
$this->id = $newId;
|
||||
}
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setStyles($newStyles) {
|
||||
$this->styles = array();
|
||||
$smallerStyles = split(";", $newStyles);
|
||||
foreach($smallerStyles as $small) {
|
||||
$parts = split(":", $small);
|
||||
$this->styles[$parts[0]] = $parts[1];
|
||||
}
|
||||
}
|
||||
public function setStyle($key, $style) {
|
||||
$this->styles[$key] = $style;
|
||||
}
|
||||
public function getStyles() {
|
||||
return $this->styles;
|
||||
}
|
||||
public function getStyle($key) {
|
||||
if ($this->styles && array_key_exists($key, $this->styles))
|
||||
return $this->styles[$key];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
public function setStroke($stroke) {
|
||||
$this->styles["stroke"] = $stroke;
|
||||
}
|
||||
public function setStrokeWidth($width) {
|
||||
$this->styles["stroke-width"] = $width;
|
||||
}
|
||||
public function setStrokeLinecap($linecap) {
|
||||
$this->styles["stroke-linecap"] = $linecap;
|
||||
}
|
||||
|
||||
public function setFill($fill) {
|
||||
$this->styles["fill"] = $fill;
|
||||
}
|
||||
|
||||
//$transform is a string of transformations
|
||||
public function setTransforms($transform) {
|
||||
$this->transforms = array();
|
||||
$this->addTransforms($transform);
|
||||
$this->combineTransforms();
|
||||
}
|
||||
|
||||
//$transform is a string of transformations
|
||||
public function addTransforms($transform) {
|
||||
$parts = split("\\)", $transform);
|
||||
foreach ($parts as $part) {
|
||||
//because ')' is the last character, we'll get an empty string here if we don't watch out
|
||||
if ($part == "")
|
||||
break;
|
||||
|
||||
$transform = split("\\(", trim($part));
|
||||
switch (trim($transform[0])) {
|
||||
case "matrix":
|
||||
//get all the matrix elements, create a new transform and set them
|
||||
$elements = split("[[:blank:],]+", trim($transform[1]));
|
||||
$transformObject = new Transform();
|
||||
$transformObject->setFullMatrix($elements[0], $elements[1], $elements[2], $elements[3], $elements[4], $elements[5]);
|
||||
$this->transforms[] = $transformObject;
|
||||
break;
|
||||
case "translate":
|
||||
//get all the matrix elements, create a new translate transform and set them
|
||||
$elements = split("[[:blank:],]+", trim($transform[1]));
|
||||
$transformObject = new Transform();
|
||||
$transformObject->setTranslate($elements[0], $elements[1]);
|
||||
$this->transforms[] = $transformObject;
|
||||
break;
|
||||
case "scale":
|
||||
//get all the matrix elements, create a new scale transform and set them
|
||||
$elements = split("[[:blank:],]+", trim($transform[1]));
|
||||
$transformObject = new Transform();
|
||||
if (count($elements) > 1)
|
||||
$transformObject->setScale($elements[0], $elements[1]);
|
||||
else
|
||||
$transformObject->setScale($elements[0]);
|
||||
$this->transforms[] = $transformObject;
|
||||
break;
|
||||
case "rotate":
|
||||
//get all the matrix elements, create a new rotate transform and set them
|
||||
$elements = split("[[:blank:],]+", trim($transform[1]));
|
||||
//if there are 3 arguments, they are angle, and (x,y) coordinates of the point to rotate about
|
||||
//to handle this, we translate, rotate, and translate back
|
||||
if (count($elements) >= 3) {
|
||||
$transformObject1 = new Transform();
|
||||
$transformObject1->setTranslate(-$elements[1], -$elements[2]);
|
||||
$this->transforms[] = $transformObject1;
|
||||
|
||||
$transformObject2 = new Transform();
|
||||
$transformObject2->setRotate($elements[0]);
|
||||
$this->transforms[] = $transformObject2;
|
||||
|
||||
$transformObject3 = new Transform();
|
||||
$transformObject3->setTranslate($elements[1], $elements[2]);
|
||||
$this->transforms[] = $transformObject3;
|
||||
} else {
|
||||
$transformObject = new Transform();
|
||||
$transformObject->setRotate($elements[0]);
|
||||
$this->transforms[] = $transformObject;
|
||||
}
|
||||
break;
|
||||
case "skewX":
|
||||
//get all the matrix elements, create a new skew transform and set them
|
||||
$elements = split("[[:blank:],]+", trim($transform[1]));
|
||||
$transformObject = new Transform();
|
||||
$transformObject->setSkewX($elements[0]);
|
||||
$this->transforms[] = $transformObject;
|
||||
break;
|
||||
case "skewY":
|
||||
//get all the matrix elements, create a new skew transform and set them
|
||||
$elements = split("[[:blank:],]+", trim($transform[1]));
|
||||
$transformObject = new Transform();
|
||||
$transformObject->setSkewY($elements[0]);
|
||||
$this->transforms[] = $transformObject;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//combine all these into one transform
|
||||
$this->combineTransforms();
|
||||
}
|
||||
|
||||
|
||||
//combine all transforms into one transform and store in $this->transform
|
||||
private function combineTransforms() {
|
||||
$one = new Transform();
|
||||
foreach ($this->transforms as $transform)
|
||||
$one->multiplyBy($transform);
|
||||
$this->transform = $one;
|
||||
}
|
||||
|
||||
public function setTransform($transform) {
|
||||
$this->transform = $transform;
|
||||
$this->transforms = array();
|
||||
$this->transforms[] = $transform;
|
||||
}
|
||||
|
||||
public function getTransform() {
|
||||
return $this->transform;
|
||||
}
|
||||
|
||||
//an ARRAY of Transform objects is returned
|
||||
public function getTransforms() {
|
||||
return $this->transforms;
|
||||
}
|
||||
}
|
||||
?>
|
45
svgparser/parser/objects/Ellipse.php
Normal file
45
svgparser/parser/objects/Ellipse.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?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/Element.php");
|
||||
|
||||
class Ellipse extends Element {
|
||||
private $cx;
|
||||
private $cy;
|
||||
private $rx;
|
||||
private $ry;
|
||||
|
||||
public function __construct() {
|
||||
$this->cx = 0;
|
||||
$this->cy = 0;
|
||||
$this->rx = 0;
|
||||
$this->ry = 0;
|
||||
}
|
||||
|
||||
public function getCx() { return $this->cx; }
|
||||
public function getCy() { return $this->cy; }
|
||||
public function getRx() { return $this->rx; }
|
||||
public function getRy() { return $this->ry; }
|
||||
public function setCx($x) { $this->cx = $x; }
|
||||
public function setCy($x) { $this->cy = $x; }
|
||||
public function setRx($x) { $this->rx = $x; }
|
||||
public function setRy($x) { $this->ry = $x; }
|
||||
}
|
||||
?>
|
55
svgparser/parser/objects/Gradient.php
Normal file
55
svgparser/parser/objects/Gradient.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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/Element.php");
|
||||
|
||||
require_once("objects/Transform.php");
|
||||
|
||||
class Gradient extends Element{
|
||||
private $link;
|
||||
private $stops;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->stops = array();
|
||||
}
|
||||
|
||||
public function setLink($link) {
|
||||
$this->link = trim($link, " \t\n\r#");
|
||||
}
|
||||
public function getLink() {
|
||||
return isset($this->link)?$this->link:null;
|
||||
}
|
||||
|
||||
public function addStop($stop) {
|
||||
$this->stops[] = $stop;
|
||||
}
|
||||
public function setStops($stops) {
|
||||
$this->stops = $stops;
|
||||
}
|
||||
public function getStops() {
|
||||
return $this->stops;
|
||||
}
|
||||
|
||||
public function isValid() {
|
||||
return count($this->stops) > 0;
|
||||
}
|
||||
}
|
||||
?>
|
58
svgparser/parser/objects/GradientStop.php
Normal file
58
svgparser/parser/objects/GradientStop.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
class GradientStop extends Element{
|
||||
private $offset;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->offset = 0;
|
||||
}
|
||||
|
||||
public function setColor($color) {
|
||||
$this->setStyle("stop-color", $color);
|
||||
}
|
||||
public function getColor() {
|
||||
$color = $this->getStyle("stop-color");
|
||||
if ($color == null)
|
||||
return "#000000";
|
||||
else
|
||||
return $color;
|
||||
}
|
||||
|
||||
public function setOpacity($opacity) {
|
||||
$this->setStyle("stop-opacity", $opacity);
|
||||
}
|
||||
public function getOpacity() {
|
||||
$opacity = $this->getStyle("stop-opacity");
|
||||
if ($opacity == null)
|
||||
return 1;
|
||||
else
|
||||
return $opacity;
|
||||
}
|
||||
|
||||
public function setOffset($offset) {
|
||||
$this->offset = $offset;
|
||||
}
|
||||
public function getOffset() {
|
||||
return isset($this->offset)?$this->offset:0;
|
||||
}
|
||||
}
|
||||
?>
|
43
svgparser/parser/objects/Line.php
Normal file
43
svgparser/parser/objects/Line.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
class Line extends Element {
|
||||
private $x1;
|
||||
private $y1;
|
||||
private $x2;
|
||||
private $y2;
|
||||
|
||||
public function __construct() {
|
||||
$this->x1 = 0;
|
||||
$this->y1 = 0;
|
||||
$this->x2 = 0;
|
||||
$this->y2 = 0;
|
||||
}
|
||||
|
||||
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 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; }
|
||||
}
|
||||
?>
|
90
svgparser/parser/objects/LinearGradient.php
Normal file
90
svgparser/parser/objects/LinearGradient.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
?>
|
38
svgparser/parser/objects/Path.php
Normal file
38
svgparser/parser/objects/Path.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?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/Element.php");
|
||||
|
||||
class Path extends Element {
|
||||
private $path;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->path = "";
|
||||
}
|
||||
|
||||
public function setPath($newPath) {
|
||||
$this->path = $newPath;
|
||||
}
|
||||
public function getPath() {
|
||||
return $this->path;
|
||||
}
|
||||
}
|
||||
?>
|
37
svgparser/parser/objects/Polyline.php
Normal file
37
svgparser/parser/objects/Polyline.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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/Element.php");
|
||||
|
||||
class Polyline extends Element {
|
||||
private $points;
|
||||
|
||||
public function __construct() {
|
||||
$this->points="";
|
||||
}
|
||||
|
||||
public function getPoints() {
|
||||
return $this->points;
|
||||
}
|
||||
public function setPoints($x) {
|
||||
$this->points = $x;
|
||||
}
|
||||
}
|
||||
?>
|
97
svgparser/parser/objects/RadialGradient.php
Normal file
97
svgparser/parser/objects/RadialGradient.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?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 RadialGradient extends Gradient {
|
||||
private $cx;
|
||||
private $cy;
|
||||
private $r;
|
||||
private $fx;
|
||||
private $fy;
|
||||
|
||||
private $transformsApplied = false;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function setCx($x) {
|
||||
$this->cx = $x;
|
||||
}
|
||||
public function setCy($x) {
|
||||
$this->cy = $x;
|
||||
}
|
||||
public function setR($x) {
|
||||
$this->r = $x;
|
||||
}
|
||||
public function setFx($x) {
|
||||
$this->fx = $x;
|
||||
}
|
||||
public function setFy($x) {
|
||||
$this->fy = $x;
|
||||
}
|
||||
|
||||
public function getCx() {
|
||||
return $this->cx;
|
||||
}
|
||||
public function getCy() {
|
||||
return $this->cy;
|
||||
}
|
||||
public function getR() {
|
||||
return $this->r;
|
||||
}
|
||||
public function getFx() {
|
||||
return $this->fx;
|
||||
}
|
||||
public function getFy() {
|
||||
return $this->fy;
|
||||
}
|
||||
|
||||
public function isValid() {
|
||||
if (!parent::isValid())
|
||||
return false;
|
||||
if (!isset($this->cx) || !isset($this->cy) || !isset($this->r) || !isset($this->fx) || !isset($this->fy))
|
||||
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) {
|
||||
$oldCx = $this->cx;
|
||||
$oldCy = $this->cy;
|
||||
$oldFx = $this->fx;
|
||||
$oldFy = $this->fy;
|
||||
$this->cx = $transform->applyToX($oldCx, $oldCy);
|
||||
$this->cy = $transform->applyToY($oldCx, $oldCy);
|
||||
$this->fx = $transform->applyToX($oldFx, $oldFy);
|
||||
$this->fy = $transform->applyToY($oldFx, $oldFy);
|
||||
}
|
||||
$this->transformsApplied = true;
|
||||
}
|
||||
}
|
||||
?>
|
66
svgparser/parser/objects/Rectangle.php
Normal file
66
svgparser/parser/objects/Rectangle.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?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/Element.php");
|
||||
|
||||
class Rectangle extends Element {
|
||||
private $x;
|
||||
private $y;
|
||||
private $height;
|
||||
private $width;
|
||||
private $rx;
|
||||
private $ry;
|
||||
|
||||
public function __construct() {
|
||||
$this->x = 0;
|
||||
$this->y = 0;
|
||||
$this->height = 0;
|
||||
$this->width = 0;
|
||||
$this->rx = null;
|
||||
$this->ry = null;
|
||||
}
|
||||
|
||||
public function getX() { return $this->x; }
|
||||
public function getY() { return $this->y; }
|
||||
public function getHeight() { return $this->height; }
|
||||
public function getWidth() { return $this->width; }
|
||||
public function getRx() { return ($this->rx != null)?$this->rx:0; }
|
||||
public function getRy() { return ($this->ry != null)?$this->ry:0; }
|
||||
public function getR() {
|
||||
if ($this->rx != null && $this->ry != null)
|
||||
return ($this->rx + $this->ry) / 2;
|
||||
else if ($this->rx != null)
|
||||
return $this->rx;
|
||||
else if ($this->ry != null)
|
||||
return $this->ry;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function setX($x) { $this->x = $x; }
|
||||
public function setY($x) { $this->y = $x; }
|
||||
public function setHeight($x) { $this->height = $x; }
|
||||
public function setWidth($x) { $this->width = $x; }
|
||||
public function setRx($x) { $this->rx = $x; }
|
||||
public function setRy($x) { $this->ry = $x; }
|
||||
public function setR($r) { $this->setRx($r); $this->setRy($r); }
|
||||
|
||||
}
|
||||
?>
|
153
svgparser/parser/objects/SVG.php
Normal file
153
svgparser/parser/objects/SVG.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
class SVG {
|
||||
private $paths;
|
||||
private $rects;
|
||||
private $circles;
|
||||
private $ellipses;
|
||||
private $lines;
|
||||
private $polylines;
|
||||
private $texts;
|
||||
private $linearGradients;
|
||||
private $radialGradients;
|
||||
|
||||
public function __construct() {
|
||||
$this->paths = array();
|
||||
$this->rects = array();
|
||||
$this->circles = array();
|
||||
$this->ellipses = array();
|
||||
$this->lines = array();
|
||||
$this->polylines = array();
|
||||
$this->texts = array();
|
||||
|
||||
$this->linearGradients = array();
|
||||
$this->radialGradients = array();
|
||||
}
|
||||
|
||||
public function addPath($path) {
|
||||
$this->paths[] = $path;
|
||||
}
|
||||
public function getPaths() {
|
||||
return $this->paths;
|
||||
}
|
||||
|
||||
public function addRectangle($rect) {
|
||||
$this->rects[] = $rect;
|
||||
}
|
||||
public function getRectangles() {
|
||||
return $this->rects;
|
||||
}
|
||||
|
||||
public function addCircle($circle) {
|
||||
$this->circles[] = $circle;
|
||||
}
|
||||
public function getCircles() {
|
||||
return $this->circles;
|
||||
}
|
||||
|
||||
public function addEllipse($ellipse) {
|
||||
$this->ellipses[] = $ellipse;
|
||||
}
|
||||
public function getEllipses() {
|
||||
return $this->ellipses;
|
||||
}
|
||||
|
||||
public function addLine($line) {
|
||||
$this->lines[] = $line;
|
||||
}
|
||||
public function getLines() {
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
public function addPolyline($polyline) {
|
||||
$this->polylines[] = $polyline;
|
||||
}
|
||||
public function getPolylines() {
|
||||
return $this->polylines;
|
||||
}
|
||||
|
||||
public function addText($text) {
|
||||
$this->texts[] = $text;
|
||||
}
|
||||
public function getTexts() {
|
||||
return $this->texts;
|
||||
}
|
||||
|
||||
public function addLinearGradient($gradient) {
|
||||
$this->linearGradients[] = $gradient;
|
||||
}
|
||||
public function getLinearGradients() {
|
||||
return $this->linearGradients;
|
||||
}
|
||||
|
||||
public function addRadialGradient($gradient) {
|
||||
$this->radialGradients[] = $gradient;
|
||||
}
|
||||
public function getRadialGradients() {
|
||||
return $this->radialGradients;
|
||||
}
|
||||
|
||||
public function getCompleteLinearGradients() {
|
||||
$validGradients = array();
|
||||
foreach($this->linearGradients as $gradient) {
|
||||
if ($gradient->isValid()) {
|
||||
$validGradients[] = $gradient;
|
||||
} else if ($gradient->getLink() != null) {
|
||||
$newGradient = $this->linkGradient($gradient);
|
||||
if ($newGradient->isValid()) {
|
||||
$validGradients[] = $newGradient;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $validGradients;
|
||||
}
|
||||
|
||||
public function getCompleteRadialGradients() {
|
||||
$validGradients = array();
|
||||
foreach($this->radialGradients as $gradient) {
|
||||
if ($gradient->isValid()) {
|
||||
$validGradients[] = $gradient;
|
||||
} else if ($gradient->getLink() != null) {
|
||||
$newGradient = $this->linkGradient($gradient);
|
||||
if ($newGradient->isValid())
|
||||
$validGradients[] = $gradient;
|
||||
}
|
||||
}
|
||||
return $validGradients;
|
||||
}
|
||||
|
||||
private function linkGradient($gradient) {
|
||||
//search through all gradients for one with an id matching the link field
|
||||
$link = $gradient->getLink();
|
||||
$toLink = null;
|
||||
foreach($this->linearGradients as $match) {
|
||||
if ($match->getId() == $link) {
|
||||
$toLink = $match;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($toLink != null) {
|
||||
$gradient->setStops($toLink->getStops());
|
||||
}
|
||||
return $gradient;
|
||||
}
|
||||
}
|
||||
?>
|
61
svgparser/parser/objects/Text.php
Normal file
61
svgparser/parser/objects/Text.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
class Text extends Element {
|
||||
private $x;
|
||||
private $y;
|
||||
private $text;
|
||||
|
||||
public function __construct() {
|
||||
$this->x = 0;
|
||||
$this->y = 0;
|
||||
$this->text = "";
|
||||
}
|
||||
|
||||
public function getX() { return $this->x; }
|
||||
public function getY() { return $this->y; }
|
||||
public function getText() { return $this->text; }
|
||||
public function setX($x) { $this->x = $x; }
|
||||
public function setY($x) { $this->y = $x; }
|
||||
public function setText($x) { $this->text = $x; }
|
||||
|
||||
public function setTextAnchor($anchor) {
|
||||
$this->setStyle("text-anchor", $anchor);
|
||||
}
|
||||
public function getTextAnchor() {
|
||||
$anchor = $this->getStyle("text-anchor");
|
||||
if ($anchor == null)
|
||||
return "start";
|
||||
else
|
||||
return $anchor;
|
||||
}
|
||||
|
||||
public function setTextDecoration($decoration) {
|
||||
$this->setStyle("text-decoration", $decoration);
|
||||
}
|
||||
public function getTextDecoration() {
|
||||
$decoration = $this->getStyle("text-decoration");
|
||||
if ($decoration == null)
|
||||
return "none";
|
||||
else
|
||||
return $decoration;
|
||||
}
|
||||
}
|
||||
?>
|
106
svgparser/parser/objects/Transform.php
Normal file
106
svgparser/parser/objects/Transform.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
class Transform {
|
||||
private $xx;
|
||||
private $xy;
|
||||
private $yx;
|
||||
private $yy;
|
||||
private $dx;
|
||||
private $dy;
|
||||
|
||||
public function __construct() {
|
||||
$this->xx = 1;
|
||||
$this->xy = 0;
|
||||
$this->yx = 0;
|
||||
$this->yy = 1;
|
||||
$this->dx = 0;
|
||||
$this->dy = 0;
|
||||
}
|
||||
|
||||
public function setFullMatrix($newXx, $newXy, $newYx, $newYy, $newDx, $newDy) {
|
||||
$this->xx = $newXx;
|
||||
$this->xy = $newXy;
|
||||
$this->yx = $newYx;
|
||||
$this->yy = $newYy;
|
||||
$this->dx = $newDx;
|
||||
$this->dy = $newDy;
|
||||
}
|
||||
|
||||
public function getXx() { return $this->xx; }
|
||||
public function getXy() { return $this->xy; }
|
||||
public function getYx() { return $this->yx; }
|
||||
public function getYy() { return $this->yy; }
|
||||
public function getDx() { return $this->dx; }
|
||||
public function getDy() { return $this->dy; }
|
||||
public function setXx($x) { $this->xx = $x; }
|
||||
public function setXy($x) { $this->xy = $x; }
|
||||
public function setYx($x) { $this->yx = $x; }
|
||||
public function setYy($x) { $this->yy = $x; }
|
||||
public function setDx($x) { $this->dx = $x; }
|
||||
public function setDy($x) { $this->dy = $x; }
|
||||
|
||||
public function setTranslate($newDx, $newDy = 0) {
|
||||
$this->setFullMatrix(1,0,0,1,$newDx, $newDy);
|
||||
}
|
||||
|
||||
public function setScale($scaleX, $scaleY = -1) {
|
||||
if ($scaleY == -1)
|
||||
$scaleY = $scaleX;
|
||||
$this->setFullMatrix($scaleX, 0, 0, $scaleY, 0, 0);
|
||||
}
|
||||
|
||||
public function setRotate($angle) {
|
||||
$this->setFullMatrix(cos(deg2rad($angle)), sin(deg2rad($angle)), -sin(deg2rad($angle)), cos(deg2rad($angle)), 0, 0);
|
||||
}
|
||||
|
||||
public function setSkewX($angle) {
|
||||
$this->setFullMatrix(1, 0, tan(deg2rad($angle)), 1, 0, 0);
|
||||
}
|
||||
|
||||
public function setSkewY($angle) {
|
||||
$this->setFullMatrix(1, tan(deg2rad($angle)), 0, 1, 0, 0);
|
||||
}
|
||||
|
||||
public function applyToX($x, $y) {
|
||||
return $this->xx * $x + $this->xy * $y + $this->dx;
|
||||
}
|
||||
|
||||
public function applyToY($x, $y) {
|
||||
return $this->yx * $x + $this->yy * $y + $this->dy;
|
||||
}
|
||||
|
||||
//does multiplication of the form [$this]*[$other]
|
||||
//and stores the result in $this
|
||||
public function multiplyBy($other) {
|
||||
$xx = ($this->xx*$other->xx + $this->xy*$other->yx);
|
||||
$xy = ($this->xx*$other->xy + $this->xy*$other->yy);
|
||||
$dx = ($this->xx*$other->dx + $this->xy*$other->dy + $this->dx);
|
||||
$yx = ($this->yx*$other->xx + $this->yy*$other->yx);
|
||||
$yy = ($this->yx*$other->xy + $this->yy*$other->yy);
|
||||
$dy = ($this->yx*$other->yx + $this->yy*$other->dy + $this->dy);
|
||||
$this->setFullMatrix($xx, $xy, $yx, $yy, $dx, $dy);
|
||||
}
|
||||
|
||||
public function isIdentity() {
|
||||
return ($this->xx == 1 && $this->xy == 0 && $this->yx == 0 && $this->yy == 1 && $this->dx == 0 && $this->dy == 0);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user