summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/kitfox/svg/SVGElement.java7
-rw-r--r--src/main/java/com/kitfox/svg/SVGRoot.java2
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Arc.java20
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/BuildHistory.java59
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Cubic.java19
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/CubicSmooth.java21
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Horizontal.java12
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/LineTo.java12
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/MoveTo.java16
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Quadratic.java13
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/QuadraticSmooth.java20
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Terminal.java8
-rw-r--r--src/main/java/com/kitfox/svg/pathcmd/Vertical.java12
13 files changed, 161 insertions, 60 deletions
diff --git a/src/main/java/com/kitfox/svg/SVGElement.java b/src/main/java/com/kitfox/svg/SVGElement.java
index 5f849a4..ee2dcf6 100644
--- a/src/main/java/com/kitfox/svg/SVGElement.java
+++ b/src/main/java/com/kitfox/svg/SVGElement.java
@@ -421,6 +421,13 @@ abstract public class SVGElement implements Serializable
}
if (getPres(sty.setName("class"))) cssClass = sty.getStringValue();
if (getPres(sty.setName("xml:base"))) xmlBase = sty.getURIValue();
+
+ //Build children
+ for (int i = 0; i < children.size(); ++i)
+ {
+ SVGElement ele = (SVGElement)children.get(i);
+ ele.build();
+ }
}
public URI getXMLBase()
diff --git a/src/main/java/com/kitfox/svg/SVGRoot.java b/src/main/java/com/kitfox/svg/SVGRoot.java
index daa211f..16e3009 100644
--- a/src/main/java/com/kitfox/svg/SVGRoot.java
+++ b/src/main/java/com/kitfox/svg/SVGRoot.java
@@ -29,8 +29,8 @@ package com.kitfox.svg;
import com.kitfox.svg.xml.NumberWithUnits;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.geom.*;
import java.awt.*;
+import java.awt.geom.*;
/**
* The root element of an SVG tree.
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Arc.java b/src/main/java/com/kitfox/svg/pathcmd/Arc.java
index c48d149..cab03f8 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/Arc.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/Arc.java
@@ -69,12 +69,16 @@ public class Arc extends PathCommand
// 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 offx = isRelative ? hist.lastPoint.x : 0f;
+ float offy = isRelative ? hist.lastPoint.y : 0f;
- arcTo(path, rx, ry, xAxisRot, largeArc, sweep, x + offx, y + offy, hist.history[0].x, hist.history[0].y);
+ arcTo(path, rx, ry, xAxisRot, largeArc, sweep,
+ x + offx, y + offy,
+ hist.lastPoint.x, hist.lastPoint.y);
// path.lineTo(x + offx, y + offy);
- hist.setPoint(x + offx, y + offy);
+// hist.setPoint(x + offx, y + offy);
+ hist.setLastPoint(x + offx, y + offy);
+ hist.setLastKnot(x + offx, y + offy);
}
public int getNumKnotsAdded()
@@ -242,4 +246,12 @@ public class Arc extends PathCommand
return arc;
}
+
+ public String toString()
+ {
+ return "A " + rx + " " + ry
+ + " " + xAxisRot + " " + largeArc
+ + " " + sweep
+ + " " + x + " " + y;
+ }
}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/BuildHistory.java b/src/main/java/com/kitfox/svg/pathcmd/BuildHistory.java
index ff00120..51ebd80 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/BuildHistory.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/BuildHistory.java
@@ -24,45 +24,64 @@
*
* 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
+ * (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 {
+public class BuildHistory
+{
// Point2D.Float[] history = new Point2D.Float[2];
- Point2D.Float[] history = {new Point2D.Float(), new Point2D.Float()};
- Point2D.Float start = new Point2D.Float();
- int length = 0;
+// Point2D.Float[] history = {new Point2D.Float(), new Point2D.Float()};
+// Point2D.Float start = new Point2D.Float();
+ Point2D.Float startPoint = new Point2D.Float();
+ Point2D.Float lastPoint = new Point2D.Float();
+ Point2D.Float lastKnot = new Point2D.Float();
+ boolean init;
+ //int length = 0;
- /** Creates a new instance of BuildHistory */
- public BuildHistory() {
+ /**
+ * Creates a new instance of BuildHistory
+ */
+ public BuildHistory()
+ {
}
-
- public void setPoint(float x, float y)
+
+ public void setStartPoint(float x, float y)
{
- history[0].setLocation(x, y);
- length = 1;
+ startPoint.setLocation(x, y);
}
-
- public void setStart(float x, float y)
+
+ public void setLastPoint(float x, float y)
{
- start.setLocation(x, y);
+ lastPoint.setLocation(x, y);
}
-
- public void setPointAndKnot(float x, float y, float kx, float ky)
+
+ public void setLastKnot(float x, float y)
{
- history[0].setLocation(x, y);
- history[1].setLocation(kx, ky);
- length = 2;
+ lastKnot.setLocation(x, y);
}
+// public void setPoint(float x, float y)
+// {
+// history[0].setLocation(x, y);
+// length = 1;
+// }
+// public void setStart(float x, float y)
+// {
+// start.setLocation(x, y);
+// }
+// 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
index f61ec4f..8cbdc86 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/Cubic.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/Cubic.java
@@ -47,6 +47,13 @@ public class Cubic extends PathCommand {
public Cubic() {
}
+ public String toString()
+ {
+ return "C " + k1x + " " + k1y
+ + " " + k2x + " " + k2y
+ + " " + x + " " + y;
+ }
+
public Cubic(boolean isRelative, float k1x, float k1y, float k2x, float k2y, float x, float y) {
super(isRelative);
this.k1x = k1x;
@@ -60,11 +67,15 @@ public class Cubic extends PathCommand {
// 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 offx = isRelative ? hist.lastPoint.x : 0f;
+ float offy = isRelative ? hist.lastPoint.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);
+ path.curveTo(k1x + offx, k1y + offy,
+ k2x + offx, k2y + offy,
+ x + offx, y + offy);
+// hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy);
+ hist.setLastPoint(x + offx, y + offy);
+ hist.setLastKnot(k2x + offx, k2y + offy);
}
public int getNumKnotsAdded()
diff --git a/src/main/java/com/kitfox/svg/pathcmd/CubicSmooth.java b/src/main/java/com/kitfox/svg/pathcmd/CubicSmooth.java
index a54b9e4..9128452 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/CubicSmooth.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/CubicSmooth.java
@@ -56,23 +56,30 @@ public class CubicSmooth extends PathCommand {
// 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 offx = isRelative ? hist.lastPoint.x : 0f;
+ float offy = isRelative ? hist.lastPoint.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;
+ float oldKx = hist.lastKnot.x;
+ float oldKy = hist.lastKnot.y;
+ float oldX = hist.lastPoint.x;
+ float oldY = hist.lastPoint.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);
+ hist.setLastPoint(x + offx, y + offy);
+ hist.setLastKnot(k2x + offx, k2y + offy);
}
public int getNumKnotsAdded()
{
return 6;
}
+
+ public String toString()
+ {
+ return "S " + k2x + " " + k2y
+ + " " + x + " " + y;
+ }
}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Horizontal.java b/src/main/java/com/kitfox/svg/pathcmd/Horizontal.java
index 5aa6c37..c25d94c 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/Horizontal.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/Horizontal.java
@@ -42,6 +42,11 @@ public class Horizontal extends PathCommand {
public Horizontal() {
}
+ public String toString()
+ {
+ return "H " + x;
+ }
+
public Horizontal(boolean isRelative, float x) {
super(isRelative);
this.x = x;
@@ -51,11 +56,12 @@ public class Horizontal extends PathCommand {
// 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;
+ float offx = isRelative ? hist.lastPoint.x : 0f;
+ float offy = hist.lastPoint.y;
path.lineTo(x + offx, offy);
- hist.setPoint(x + offx, offy);
+ hist.setLastPoint(x + offx, offy);
+ hist.setLastKnot(x + offx, offy);
}
public int getNumKnotsAdded()
diff --git a/src/main/java/com/kitfox/svg/pathcmd/LineTo.java b/src/main/java/com/kitfox/svg/pathcmd/LineTo.java
index 2c76508..4ff4442 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/LineTo.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/LineTo.java
@@ -53,15 +53,21 @@ public class LineTo extends PathCommand {
// 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 offx = isRelative ? hist.lastPoint.x : 0f;
+ float offy = isRelative ? hist.lastPoint.y : 0f;
path.lineTo(x + offx, y + offy);
- hist.setPoint(x + offx, y + offy);
+ hist.setLastPoint(x + offx, y + offy);
+ hist.setLastKnot(x + offx, y + offy);
}
public int getNumKnotsAdded()
{
return 2;
}
+
+ public String toString()
+ {
+ return "L " + x + " " + y;
+ }
}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/MoveTo.java b/src/main/java/com/kitfox/svg/pathcmd/MoveTo.java
index e2246a5..74936fb 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/MoveTo.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/MoveTo.java
@@ -52,16 +52,24 @@ public class MoveTo extends PathCommand {
// 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 offx = isRelative ? hist.lastPoint.x : 0f;
+ float offy = isRelative ? hist.lastPoint.y : 0f;
path.moveTo(x + offx, y + offy);
- hist.setPoint(x + offx, y + offy);
- hist.setStart(x + offx, y + offy);
+ hist.setStartPoint(x + offx, y + offy);
+ hist.setLastPoint(x + offx, y + offy);
+ hist.setLastKnot(x + offx, y + offy);
}
public int getNumKnotsAdded()
{
return 2;
}
+
+ public String toString()
+ {
+ return "M " + x + " " + y;
+ }
+
+
}
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Quadratic.java b/src/main/java/com/kitfox/svg/pathcmd/Quadratic.java
index 34ace18..502f4e1 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/Quadratic.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/Quadratic.java
@@ -45,6 +45,12 @@ public class Quadratic extends PathCommand {
public Quadratic() {
}
+ public String toString()
+ {
+ return "Q " + kx + " " + ky
+ + " " + x + " " + y;
+ }
+
public Quadratic(boolean isRelative, float kx, float ky, float x, float y) {
super(isRelative);
this.kx = kx;
@@ -56,11 +62,12 @@ public class Quadratic extends PathCommand {
// 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 offx = isRelative ? hist.lastPoint.x : 0f;
+ float offy = isRelative ? hist.lastPoint.y : 0f;
path.quadTo(kx + offx, ky + offy, x + offx, y + offy);
- hist.setPointAndKnot(x + offx, y + offy, kx + offx, ky + offy);
+ hist.setLastPoint(x + offx, y + offy);
+ hist.setLastKnot(kx + offx, ky + offy);
}
public int getNumKnotsAdded()
diff --git a/src/main/java/com/kitfox/svg/pathcmd/QuadraticSmooth.java b/src/main/java/com/kitfox/svg/pathcmd/QuadraticSmooth.java
index 2bbc6bf..18e8ddd 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/QuadraticSmooth.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/QuadraticSmooth.java
@@ -43,6 +43,11 @@ public class QuadraticSmooth extends PathCommand {
public QuadraticSmooth() {
}
+ public String toString()
+ {
+ return "T " + x + " " + y;
+ }
+
public QuadraticSmooth(boolean isRelative, float x, float y) {
super(isRelative);
this.x = x;
@@ -52,19 +57,20 @@ public class QuadraticSmooth extends PathCommand {
// 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 offx = isRelative ? hist.lastPoint.x : 0f;
+ float offy = isRelative ? hist.lastPoint.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;
+ float oldKx = hist.lastKnot.x;
+ float oldKy = hist.lastKnot.y;
+ float oldX = hist.lastPoint.x;
+ float oldY = hist.lastPoint.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);
+ hist.setLastPoint(x + offx, y + offy);
+ hist.setLastKnot(kx, ky);
}
public int getNumKnotsAdded()
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Terminal.java b/src/main/java/com/kitfox/svg/pathcmd/Terminal.java
index 1cdacf2..beb7f0f 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/Terminal.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/Terminal.java
@@ -42,12 +42,18 @@ public class Terminal extends PathCommand {
public Terminal() {
}
+ public String toString()
+ {
+ return "Z";
+ }
+
// public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
public void appendPath(GeneralPath path, BuildHistory hist)
{
path.closePath();
- hist.setPoint(hist.start.x, hist.start.y);
+ hist.setLastPoint(hist.startPoint.x, hist.startPoint.y);
+ hist.setLastKnot(hist.startPoint.x, hist.startPoint.y);
}
public int getNumKnotsAdded()
diff --git a/src/main/java/com/kitfox/svg/pathcmd/Vertical.java b/src/main/java/com/kitfox/svg/pathcmd/Vertical.java
index ca7bda4..cf7bc4d 100644
--- a/src/main/java/com/kitfox/svg/pathcmd/Vertical.java
+++ b/src/main/java/com/kitfox/svg/pathcmd/Vertical.java
@@ -42,6 +42,11 @@ public class Vertical extends PathCommand {
public Vertical() {
}
+ public String toString()
+ {
+ return "V " + y;
+ }
+
public Vertical(boolean isRelative, float y) {
super(isRelative);
this.y = y;
@@ -50,11 +55,12 @@ public class Vertical extends PathCommand {
// 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;
+ float offx = hist.lastPoint.x;
+ float offy = isRelative ? hist.lastPoint.y : 0f;
path.lineTo(offx, y + offy);
- hist.setPoint(offx, y + offy);
+ hist.setLastPoint(offx, y + offy);
+ hist.setLastKnot(offx, y + offy);
}
public int getNumKnotsAdded()