summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/kitfox/svg/pathcmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/kitfox/svg/pathcmd')
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Arc.java245
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/BuildHistory.java62
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Cubic.java74
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/CubicSmooth.java78
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Horizontal.java65
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/LineTo.java67
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/MoveTo.java66
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/PathCommand.java56
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/PathUtil.java72
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Quadratic.java70
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/QuadraticSmooth.java74
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Terminal.java56
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Vertical.java64
13 files changed, 1049 insertions, 0 deletions
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Arc.java b/src/main/java/com/kitfox/svg/pathcmd/Arc.java
new file mode 100644
index 0000000..c48d149
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/Arc.java
@@ -0,0 +1,245 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.*;
+import java.awt.geom.*;
+
+/**
+ * This is a little used SVG function, as most editors will save curves as
+ * Beziers. To reduce the need to rely on the Batik library, this functionallity
+ * is being bypassed for the time being. In the future, it would be nice to
+ * extend the GeneralPath command to include the arcTo ability provided by Batik.
+ *
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class Arc extends PathCommand
+{
+
+ public float rx = 0f;
+ public float ry = 0f;
+ public float xAxisRot = 0f;
+ public boolean largeArc = false;
+ public boolean sweep = false;
+ public float x = 0f;
+ public float y = 0f;
+
+ /** Creates a new instance of MoveTo */
+ public Arc() {
+ }
+
+ public Arc(boolean isRelative, float rx, float ry, float xAxisRot, boolean largeArc, boolean sweep, float x, float y) {
+ super(isRelative);
+ this.rx = rx;
+ this.ry = ry;
+ this.xAxisRot = xAxisRot;
+ this.largeArc = largeArc;
+ this.sweep = sweep;
+ this.x = x;
+ this.y = y;
+ }
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ float offx = isRelative ? hist.history[0].x : 0f;
+ float offy = isRelative ? hist.history[0].y : 0f;
+
+ arcTo(path, rx, ry, xAxisRot, largeArc, sweep, x + offx, y + offy, hist.history[0].x, hist.history[0].y);
+// path.lineTo(x + offx, y + offy);
+ hist.setPoint(x + offx, y + offy);
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 6;
+ }
+
+ /**
+ * Adds an elliptical arc, defined by two radii, an angle from the
+ * x-axis, a flag to choose the large arc or not, a flag to
+ * indicate if we increase or decrease the angles and the final
+ * point of the arc.
+ *
+ * @param rx the x radius of the ellipse
+ * @param ry the y radius of the ellipse
+ *
+ * @param angle the angle from the x-axis of the current
+ * coordinate system to the x-axis of the ellipse in degrees.
+ *
+ * @param largeArcFlag the large arc flag. If true the arc
+ * spanning less than or equal to 180 degrees is chosen, otherwise
+ * the arc spanning greater than 180 degrees is chosen
+ *
+ * @param sweepFlag the sweep flag. If true the line joining
+ * center to arc sweeps through decreasing angles otherwise it
+ * sweeps through increasing angles
+ *
+ * @param x the absolute x coordinate of the final point of the arc.
+ * @param y the absolute y coordinate of the final point of the arc.
+ * @param x0 - The absolute x coordinate of the initial point of the arc.
+ * @param y0 - The absolute y coordinate of the initial point of the arc.
+ */
+ public void arcTo(GeneralPath path, float rx, float ry,
+ float angle,
+ boolean largeArcFlag,
+ boolean sweepFlag,
+ float x, float y, float x0, float y0)
+ {
+
+ // Ensure radii are valid
+ if (rx == 0 || ry == 0) {
+ path.lineTo((float) x, (float) y);
+ return;
+ }
+
+ if (x0 == x && y0 == y) {
+ // If the endpoints (x, y) and (x0, y0) are identical, then this
+ // is equivalent to omitting the elliptical arc segment entirely.
+ return;
+ }
+
+ Arc2D arc = computeArc(x0, y0, rx, ry, angle,
+ largeArcFlag, sweepFlag, x, y);
+ if (arc == null) return;
+
+ AffineTransform t = AffineTransform.getRotateInstance
+ (Math.toRadians(angle), arc.getCenterX(), arc.getCenterY());
+ Shape s = t.createTransformedShape(arc);
+ path.append(s, true);
+ }
+
+
+ /**
+ * This constructs an unrotated Arc2D from the SVG specification of an
+ * Elliptical arc. To get the final arc you need to apply a rotation
+ * transform such as:
+ *
+ * AffineTransform.getRotateInstance
+ * (angle, arc.getX()+arc.getWidth()/2, arc.getY()+arc.getHeight()/2);
+ */
+ public static Arc2D computeArc(double x0, double y0,
+ double rx, double ry,
+ double angle,
+ boolean largeArcFlag,
+ boolean sweepFlag,
+ double x, double y) {
+ //
+ // Elliptical arc implementation based on the SVG specification notes
+ //
+
+ // Compute the half distance between the current and the final point
+ double dx2 = (x0 - x) / 2.0;
+ double dy2 = (y0 - y) / 2.0;
+ // Convert angle from degrees to radians
+ angle = Math.toRadians(angle % 360.0);
+ double cosAngle = Math.cos(angle);
+ double sinAngle = Math.sin(angle);
+
+ //
+ // Step 1 : Compute (x1, y1)
+ //
+ double x1 = (cosAngle * dx2 + sinAngle * dy2);
+ double y1 = (-sinAngle * dx2 + cosAngle * dy2);
+ // Ensure radii are large enough
+ rx = Math.abs(rx);
+ ry = Math.abs(ry);
+ double Prx = rx * rx;
+ double Pry = ry * ry;
+ double Px1 = x1 * x1;
+ double Py1 = y1 * y1;
+ // check that radii are large enough
+ double radiiCheck = Px1/Prx + Py1/Pry;
+ if (radiiCheck > 1) {
+ rx = Math.sqrt(radiiCheck) * rx;
+ ry = Math.sqrt(radiiCheck) * ry;
+ Prx = rx * rx;
+ Pry = ry * ry;
+ }
+
+ //
+ // Step 2 : Compute (cx1, cy1)
+ //
+ double sign = (largeArcFlag == sweepFlag) ? -1 : 1;
+ double sq = ((Prx*Pry)-(Prx*Py1)-(Pry*Px1)) / ((Prx*Py1)+(Pry*Px1));
+ sq = (sq < 0) ? 0 : sq;
+ double coef = (sign * Math.sqrt(sq));
+ double cx1 = coef * ((rx * y1) / ry);
+ double cy1 = coef * -((ry * x1) / rx);
+
+ //
+ // Step 3 : Compute (cx, cy) from (cx1, cy1)
+ //
+ double sx2 = (x0 + x) / 2.0;
+ double sy2 = (y0 + y) / 2.0;
+ double cx = sx2 + (cosAngle * cx1 - sinAngle * cy1);
+ double cy = sy2 + (sinAngle * cx1 + cosAngle * cy1);
+
+ //
+ // Step 4 : Compute the angleStart (angle1) and the angleExtent (dangle)
+ //
+ double ux = (x1 - cx1) / rx;
+ double uy = (y1 - cy1) / ry;
+ double vx = (-x1 - cx1) / rx;
+ double vy = (-y1 - cy1) / ry;
+ double p, n;
+ // Compute the angle start
+ n = Math.sqrt((ux * ux) + (uy * uy));
+ p = ux; // (1 * ux) + (0 * uy)
+ sign = (uy < 0) ? -1d : 1d;
+ double angleStart = Math.toDegrees(sign * Math.acos(p / n));
+
+ // Compute the angle extent
+ n = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
+ p = ux * vx + uy * vy;
+ sign = (ux * vy - uy * vx < 0) ? -1d : 1d;
+ double angleExtent = Math.toDegrees(sign * Math.acos(p / n));
+ if(!sweepFlag && angleExtent > 0) {
+ angleExtent -= 360f;
+ } else if (sweepFlag && angleExtent < 0) {
+ angleExtent += 360f;
+ }
+ angleExtent %= 360f;
+ angleStart %= 360f;
+
+ //
+ // We can now build the resulting Arc2D in double precision
+ //
+ Arc2D.Double arc = new Arc2D.Double();
+ arc.x = cx - rx;
+ arc.y = cy - ry;
+ arc.width = rx * 2.0;
+ arc.height = ry * 2.0;
+ arc.start = -angleStart;
+ arc.extent = -angleExtent;
+
+ return arc;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/BuildHistory.java b/src/main/java/com/kitfox/svg/pathcmd/BuildHistory.java
new file mode 100644
index 0000000..d16c11a
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/BuildHistory.java
@@ -0,0 +1,62 @@
+/*
+ * BuildHistory.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 9:18 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+import java.awt.geom.Point2D;
+
+/**
+ * When building a path from command segments, most need to cache information
+ * (such as the point finished at) for future commands. This structure allows
+ * that
+ *
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class BuildHistory {
+
+// Point2D.Float[] history = new Point2D.Float[2];
+ Point2D.Float[] history = {new Point2D.Float(), new Point2D.Float()};
+ int length = 0;
+
+ /** Creates a new instance of BuildHistory */
+ public BuildHistory() {
+ }
+
+ public void setPoint(float x, float y)
+ {
+ history[0].setLocation(x, y);
+ length = 1;
+ }
+
+ public void setPointAndKnot(float x, float y, float kx, float ky)
+ {
+ history[0].setLocation(x, y);
+ history[1].setLocation(kx, ky);
+ length = 2;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Cubic.java b/src/main/java/com/kitfox/svg/pathcmd/Cubic.java
new file mode 100644
index 0000000..f61ec4f
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/Cubic.java
@@ -0,0 +1,74 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class Cubic extends PathCommand {
+
+ public float k1x = 0f;
+ public float k1y = 0f;
+ public float k2x = 0f;
+ public float k2y = 0f;
+ public float x = 0f;
+ public float y = 0f;
+
+ /** Creates a new instance of MoveTo */
+ public Cubic() {
+ }
+
+ public Cubic(boolean isRelative, float k1x, float k1y, float k2x, float k2y, float x, float y) {
+ super(isRelative);
+ this.k1x = k1x;
+ this.k1y = k1y;
+ this.k2x = k2x;
+ this.k2y = k2y;
+ this.x = x;
+ this.y = y;
+ }
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ float offx = isRelative ? hist.history[0].x : 0f;
+ float offy = isRelative ? hist.history[0].y : 0f;
+
+ path.curveTo(k1x + offx, k1y + offy, k2x + offx, k2y + offy, x + offx, y + offy);
+ hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy);
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 6;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/CubicSmooth.java b/src/main/java/com/kitfox/svg/pathcmd/CubicSmooth.java
new file mode 100644
index 0000000..a54b9e4
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/CubicSmooth.java
@@ -0,0 +1,78 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class CubicSmooth extends PathCommand {
+
+ public float x = 0f;
+ public float y = 0f;
+ public float k2x = 0f;
+ public float k2y = 0f;
+
+ /** Creates a new instance of MoveTo */
+ public CubicSmooth() {
+ }
+
+ public CubicSmooth(boolean isRelative, float k2x, float k2y, float x, float y) {
+ super(isRelative);
+ this.k2x = k2x;
+ this.k2y = k2y;
+ this.x = x;
+ this.y = y;
+ }
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ float offx = isRelative ? hist.history[0].x : 0f;
+ float offy = isRelative ? hist.history[0].y : 0f;
+
+ float oldKx = hist.history.length >= 2 ? hist.history[1].x : hist.history[0].x;
+ float oldKy = hist.history.length >= 2 ? hist.history[1].y : hist.history[0].y;
+ float oldX = hist.history[0].x;
+ float oldY = hist.history[0].y;
+ //Calc knot as reflection of old knot
+ float k1x = oldX * 2f - oldKx;
+ float k1y = oldY * 2f - oldKy;
+
+ path.curveTo(k1x, k1y, k2x + offx, k2y + offy, x + offx, y + offy);
+ hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy);
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 6;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Horizontal.java b/src/main/java/com/kitfox/svg/pathcmd/Horizontal.java
new file mode 100644
index 0000000..5aa6c37
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/Horizontal.java
@@ -0,0 +1,65 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class Horizontal extends PathCommand {
+
+ public float x = 0f;
+
+ /** Creates a new instance of MoveTo */
+ public Horizontal() {
+ }
+
+ public Horizontal(boolean isRelative, float x) {
+ super(isRelative);
+ this.x = x;
+ }
+
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ float offx = isRelative ? hist.history[0].x : 0f;
+ float offy = hist.history[0].y;
+
+ path.lineTo(x + offx, offy);
+ hist.setPoint(x + offx, offy);
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 2;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/LineTo.java b/src/main/java/com/kitfox/svg/pathcmd/LineTo.java
new file mode 100644
index 0000000..2c76508
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/LineTo.java
@@ -0,0 +1,67 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class LineTo extends PathCommand {
+
+ public float x = 0f;
+ public float y = 0f;
+
+ /** Creates a new instance of MoveTo */
+ public LineTo() {
+ }
+
+ public LineTo(boolean isRelative, float x, float y) {
+ super(isRelative);
+ this.x = x;
+ this.y = y;
+ }
+
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ float offx = isRelative ? hist.history[0].x : 0f;
+ float offy = isRelative ? hist.history[0].y : 0f;
+
+ path.lineTo(x + offx, y + offy);
+ hist.setPoint(x + offx, y + offy);
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 2;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/MoveTo.java b/src/main/java/com/kitfox/svg/pathcmd/MoveTo.java
new file mode 100644
index 0000000..7339607
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/MoveTo.java
@@ -0,0 +1,66 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class MoveTo extends PathCommand {
+
+ public float x = 0f;
+ public float y = 0f;
+
+ /** Creates a new instance of MoveTo */
+ public MoveTo() {
+ }
+
+ public MoveTo(boolean isRelative, float x, float y) {
+ super(isRelative);
+ this.x = x;
+ this.y = y;
+ }
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ float offx = isRelative ? hist.history[0].x : 0f;
+ float offy = isRelative ? hist.history[0].y : 0f;
+
+ path.moveTo(x + offx, y + offy);
+ hist.setPoint(x + offx, y + offy);
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 2;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/PathCommand.java b/src/main/java/com/kitfox/svg/pathcmd/PathCommand.java
new file mode 100644
index 0000000..33faca1
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/PathCommand.java
@@ -0,0 +1,56 @@
+/*
+ * PathCommand.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:39 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * This is the element of a path and contains instructions for rendering a
+ * portion of the path
+ *
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+abstract public class PathCommand {
+
+ public boolean isRelative = false;
+
+ /** Creates a new instance of PathCommand */
+ public PathCommand() {
+ }
+
+ public PathCommand(boolean isRelative) {
+ this.isRelative = isRelative;
+ }
+
+// abstract public void appendPath(ExtendedGeneralPath path, BuildHistory hist);
+ abstract public void appendPath(GeneralPath path, BuildHistory hist);
+
+ abstract public int getNumKnotsAdded();
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/PathUtil.java b/src/main/java/com/kitfox/svg/pathcmd/PathUtil.java
new file mode 100644
index 0000000..afd562d
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/PathUtil.java
@@ -0,0 +1,72 @@
+/*
+ * PathUtil.java
+ *
+ * Created on May 10, 2005, 5:56 AM
+ *
+ * To change this template, choose Tools | Options and locate the template under
+ * the Source Creation and Management node. Right-click the template and choose
+ * Open. You can then make changes to the template in the Source Editor.
+ */
+
+package com.kitfox.svg.pathcmd;
+
+import java.awt.geom.*;
+
+/**
+ *
+ * @author kitfox
+ */
+public class PathUtil
+{
+
+ /** Creates a new instance of PathUtil */
+ public PathUtil()
+ {
+ }
+
+ /**
+ * Converts a GeneralPath into an SVG representation
+ */
+ public static String buildPathString(GeneralPath path)
+ {
+ float[] coords = new float[6];
+
+ StringBuffer sb = new StringBuffer();
+
+ for (PathIterator pathIt = path.getPathIterator(new AffineTransform()); !pathIt.isDone(); pathIt.next())
+ {
+ int segId = pathIt.currentSegment(coords);
+
+ switch (segId)
+ {
+ case PathIterator.SEG_CLOSE:
+ {
+ sb.append(" Z");
+ break;
+ }
+ case PathIterator.SEG_CUBICTO:
+ {
+ sb.append(" C " + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3] + " " + coords[4] + " " + coords[5]);
+ break;
+ }
+ case PathIterator.SEG_LINETO:
+ {
+ sb.append(" L " + coords[0] + " " + coords[1]);
+ break;
+ }
+ case PathIterator.SEG_MOVETO:
+ {
+ sb.append(" M " + coords[0] + " " + coords[1]);
+ break;
+ }
+ case PathIterator.SEG_QUADTO:
+ {
+ sb.append(" Q " + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3]);
+ break;
+ }
+ }
+ }
+
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Quadratic.java b/src/main/java/com/kitfox/svg/pathcmd/Quadratic.java
new file mode 100644
index 0000000..34ace18
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/Quadratic.java
@@ -0,0 +1,70 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class Quadratic extends PathCommand {
+
+ public float kx = 0f;
+ public float ky = 0f;
+ public float x = 0f;
+ public float y = 0f;
+
+ /** Creates a new instance of MoveTo */
+ public Quadratic() {
+ }
+
+ public Quadratic(boolean isRelative, float kx, float ky, float x, float y) {
+ super(isRelative);
+ this.kx = kx;
+ this.ky = ky;
+ this.x = x;
+ this.y = y;
+ }
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ float offx = isRelative ? hist.history[0].x : 0f;
+ float offy = isRelative ? hist.history[0].y : 0f;
+
+ path.quadTo(kx + offx, ky + offy, x + offx, y + offy);
+ hist.setPointAndKnot(x + offx, y + offy, kx + offx, ky + offy);
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 4;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/QuadraticSmooth.java b/src/main/java/com/kitfox/svg/pathcmd/QuadraticSmooth.java
new file mode 100644
index 0000000..2bbc6bf
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/QuadraticSmooth.java
@@ -0,0 +1,74 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class QuadraticSmooth extends PathCommand {
+
+ public float x = 0f;
+ public float y = 0f;
+
+ /** Creates a new instance of MoveTo */
+ public QuadraticSmooth() {
+ }
+
+ public QuadraticSmooth(boolean isRelative, float x, float y) {
+ super(isRelative);
+ this.x = x;
+ this.y = y;
+ }
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ float offx = isRelative ? hist.history[0].x : 0f;
+ float offy = isRelative ? hist.history[0].y : 0f;
+
+ float oldKx = hist.history.length >= 2 ? hist.history[1].x : hist.history[0].x;
+ float oldKy = hist.history.length >= 2 ? hist.history[1].y : hist.history[0].y;
+ float oldX = hist.history[0].x;
+ float oldY = hist.history[0].y;
+ //Calc knot as reflection of old knot
+ float kx = oldX * 2f - oldKx;
+ float ky = oldY * 2f - oldKy;
+
+ path.quadTo(kx, ky, x + offx, y + offy);
+ hist.setPointAndKnot(x + offx, y + offy, kx, ky);
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 4;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Terminal.java b/src/main/java/com/kitfox/svg/pathcmd/Terminal.java
new file mode 100644
index 0000000..a9d1c9f
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/Terminal.java
@@ -0,0 +1,56 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * Finishes a path
+ *
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class Terminal extends PathCommand {
+
+ /** Creates a new instance of MoveTo */
+ public Terminal() {
+ }
+
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ path.closePath();
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 0;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Vertical.java b/src/main/java/com/kitfox/svg/pathcmd/Vertical.java
new file mode 100644
index 0000000..ca7bda4
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/pathcmd/Vertical.java
@@ -0,0 +1,64 @@
+/*
+ * MoveTo.java
+ *
+ *
+ * The Salamander Project - 2D and 3D graphics libraries in Java
+ * Copyright (C) 2004 Mark McKay
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
+ * projects can be found at http://www.kitfox.com
+ *
+ * Created on January 26, 2004, 8:40 PM
+ */
+
+package com.kitfox.svg.pathcmd;
+
+//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.geom.*;
+
+/**
+ * @author Mark McKay
+ * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
+ */
+public class Vertical extends PathCommand {
+
+ public float y = 0f;
+
+ /** Creates a new instance of MoveTo */
+ public Vertical() {
+ }
+
+ public Vertical(boolean isRelative, float y) {
+ super(isRelative);
+ this.y = y;
+ }
+
+// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
+ public void appendPath(GeneralPath path, BuildHistory hist)
+ {
+ float offx = hist.history[0].x;
+ float offy = isRelative ? hist.history[0].y : 0f;
+
+ path.lineTo(offx, y + offy);
+ hist.setPoint(offx, y + offy);
+ }
+
+ public int getNumKnotsAdded()
+ {
+ return 2;
+ }
+}