summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkitfox2013-03-19 06:20:37 +0100
committerkitfox2013-03-19 06:20:37 +0100
commit6776ed9f1a81e517139d85eb6d2e28911fd0fc35 (patch)
treee169f598f518670f5434d75d1b76ceb3c0765d32
parentError handling now sends warnings to Logger. (diff)
downloadsvg-salamander-core-6776ed9f1a81e517139d85eb6d2e28911fd0fc35.tar.gz
svg-salamander-core-6776ed9f1a81e517139d85eb6d2e28911fd0fc35.tar.xz
svg-salamander-core-6776ed9f1a81e517139d85eb6d2e28911fd0fc35.zip
Adding support for style sheets.
git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@153 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b
-rw-r--r--src/main/java/com/kitfox/svg/A.java21
-rw-r--r--src/main/java/com/kitfox/svg/Circle.java85
-rw-r--r--src/main/java/com/kitfox/svg/ClipPath.java84
-rw-r--r--src/main/java/com/kitfox/svg/Defs.java28
-rw-r--r--src/main/java/com/kitfox/svg/Desc.java24
-rw-r--r--src/main/java/com/kitfox/svg/Ellipse.java112
-rw-r--r--src/main/java/com/kitfox/svg/FeDistantLight.java62
-rw-r--r--src/main/java/com/kitfox/svg/FeLight.java25
-rw-r--r--src/main/java/com/kitfox/svg/FePointLight.java77
-rw-r--r--src/main/java/com/kitfox/svg/FeSpotLight.java138
-rw-r--r--src/main/java/com/kitfox/svg/FillElement.java21
-rw-r--r--src/main/java/com/kitfox/svg/Filter.java150
-rw-r--r--src/main/java/com/kitfox/svg/FilterEffects.java194
-rw-r--r--src/main/java/com/kitfox/svg/Font.java272
-rw-r--r--src/main/java/com/kitfox/svg/FontFace.java170
-rw-r--r--src/main/java/com/kitfox/svg/Glyph.java62
-rw-r--r--src/main/java/com/kitfox/svg/Gradient.java182
-rw-r--r--src/main/java/com/kitfox/svg/Group.java120
-rw-r--r--src/main/java/com/kitfox/svg/Hkern.java24
-rw-r--r--src/main/java/com/kitfox/svg/ImageSVG.java197
-rw-r--r--src/main/java/com/kitfox/svg/Line.java72
-rw-r--r--src/main/java/com/kitfox/svg/LinearGradient.java108
-rw-r--r--src/main/java/com/kitfox/svg/Marker.java79
-rw-r--r--src/main/java/com/kitfox/svg/Metadata.java19
-rw-r--r--src/main/java/com/kitfox/svg/MissingGlyph.java151
-rw-r--r--src/main/java/com/kitfox/svg/Path.java78
-rw-r--r--src/main/java/com/kitfox/svg/PatternSVG.java144
-rw-r--r--src/main/java/com/kitfox/svg/Polygon.java91
-rw-r--r--src/main/java/com/kitfox/svg/Polyline.java69
-rw-r--r--src/main/java/com/kitfox/svg/RadialGradient.java114
-rw-r--r--src/main/java/com/kitfox/svg/Rect.java168
-rw-r--r--src/main/java/com/kitfox/svg/RenderableElement.java60
-rw-r--r--src/main/java/com/kitfox/svg/SVGElement.java496
-rw-r--r--src/main/java/com/kitfox/svg/SVGRoot.java130
-rw-r--r--src/main/java/com/kitfox/svg/Stop.java77
-rw-r--r--src/main/java/com/kitfox/svg/Style.java41
-rw-r--r--src/main/java/com/kitfox/svg/Symbol.java65
-rw-r--r--src/main/java/com/kitfox/svg/Text.java297
-rw-r--r--src/main/java/com/kitfox/svg/Title.java31
-rw-r--r--src/main/java/com/kitfox/svg/TransformableElement.java65
-rw-r--r--src/main/java/com/kitfox/svg/Tspan.java183
-rw-r--r--src/main/java/com/kitfox/svg/Use.java79
-rw-r--r--src/main/java/com/kitfox/svg/animation/Animate.java9
-rw-r--r--src/main/java/com/kitfox/svg/animation/AnimateColor.java9
-rw-r--r--src/main/java/com/kitfox/svg/animation/AnimateMotion.java9
-rw-r--r--src/main/java/com/kitfox/svg/animation/AnimateTransform.java7
-rw-r--r--src/main/java/com/kitfox/svg/animation/SetSmil.java9
-rw-r--r--src/main/java/com/kitfox/svg/xml/StyleAttribute.java16
-rw-r--r--src/main/java/com/kitfox/svg/xml/StyleSheet.java56
-rw-r--r--src/main/java/com/kitfox/svg/xml/StyleSheetRule.java59
50 files changed, 2676 insertions, 2163 deletions
diff --git a/src/main/java/com/kitfox/svg/A.java b/src/main/java/com/kitfox/svg/A.java
index 0609e58..7283557 100644
--- a/src/main/java/com/kitfox/svg/A.java
+++ b/src/main/java/com/kitfox/svg/A.java
@@ -37,33 +37,28 @@
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.*;
import java.net.URI;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class A extends Group {
+public class A extends Group
+{
+ public static final String TAG_NAME = "a";
URI href;
String title;
/** Creates a new instance of Stop */
- public A() {
- }
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ public A()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String offset = attrs.getValue("offset");
- this.offset = (float)XMLParseUtil.parseRatio(offset);
+ }
- buildStop();
+ public String getTagName()
+ {
+ return TAG_NAME;
}
- */
protected void build() throws SVGException
{
diff --git a/src/main/java/com/kitfox/svg/Circle.java b/src/main/java/com/kitfox/svg/Circle.java
index 7c76b9f..6c2eff8 100644
--- a/src/main/java/com/kitfox/svg/Circle.java
+++ b/src/main/java/com/kitfox/svg/Circle.java
@@ -33,7 +33,6 @@
*
* Created on January 26, 2004, 5:25 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
@@ -46,59 +45,48 @@ import java.awt.geom.Rectangle2D;
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Circle extends ShapeElement
+public class Circle extends ShapeElement
{
+ public static final String TAG_NAME = "circle";
float cx = 0f;
float cy = 0f;
float r = 0f;
-
-
Ellipse2D.Float circle = new Ellipse2D.Float();
- /** Creates a new instance of Rect */
- public Circle() {
- }
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ /**
+ * Creates a new instance of Rect
+ */
+ public Circle()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String cx = attrs.getValue("cx");
- String cy = attrs.getValue("cy");
- String r = attrs.getValue("r");
-
- this.cx = XMLParseUtil.parseFloat(cx);
- this.cy = XMLParseUtil.parseFloat(cy);
- this.r = XMLParseUtil.parseFloat(r);
-
- build();
-
- //setBounds(this.cx - this.r, this.cy - this.r, this.r * 2.0, this.r * 2.0);
}
-*/
- /*
- public void loaderEndElement(SVGLoaderHelper helper)
- {
-// super.loaderEndElement(helper);
-// build();
+ public String getTagName()
+ {
+ return TAG_NAME;
}
- */
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("r"))) r = sty.getFloatValueWithUnits();
-
+
+ if (getPres(sty.setName("cx")))
+ {
+ cx = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("cy")))
+ {
+ cy = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("r")))
+ {
+ r = sty.getFloatValueWithUnits();
+ }
+
circle.setFrame(cx - r, cy - r, r * 2f, r * 2f);
}
@@ -120,8 +108,9 @@ public class Circle extends ShapeElement
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -133,7 +122,7 @@ public class Circle extends ShapeElement
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("cx")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -143,7 +132,7 @@ public class Circle extends ShapeElement
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("cy")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -153,7 +142,7 @@ public class Circle extends ShapeElement
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("r")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -163,18 +152,14 @@ public class Circle extends ShapeElement
shapeChange = true;
}
}
-
+
if (shapeChange)
{
build();
// circle.setFrame(cx - r, cy - r, r * 2f, r * 2f);
// return true;
}
-
+
return changeState || shapeChange;
}
-
}
-
-
-
diff --git a/src/main/java/com/kitfox/svg/ClipPath.java b/src/main/java/com/kitfox/svg/ClipPath.java
index f7f5563..417def2 100644
--- a/src/main/java/com/kitfox/svg/ClipPath.java
+++ b/src/main/java/com/kitfox/svg/ClipPath.java
@@ -33,7 +33,6 @@
*
* Created on January 26, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
@@ -45,61 +44,47 @@ import java.util.Iterator;
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class ClipPath extends SVGElement
+public class ClipPath extends SVGElement
{
+ public static final String TAG_NAME = "clippath";
public static final int CP_USER_SPACE_ON_USE = 0;
public static final int CP_OBJECT_BOUNDING_BOX = 1;
-
int clipPathUnits = CP_USER_SPACE_ON_USE;
- /** Creates a new instance of Stop */
- public ClipPath() {
- }
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ /**
+ * Creates a new instance of Stop
+ */
+ public ClipPath()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String clipPathUnits = attrs.getValue("clipPathUnits");
-
- if (clipPathUnits.equals("objectBoundingBox")) this.clipPathUnits = CP_OBJECT_BOUNDING_BOX;
+ }
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-*/
+
/**
* Called after the start element but before the end element to indicate
* each child tag that has been processed
*/
public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
{
- super.loaderAddChild(helper, child);
-
-// if (child instanceof ShapeElement) members.add(child);
+ super.loaderAddChild(helper, child);
}
- /*
- public void loaderEndElement(SVGLoaderHelper helper)
- {
-// super.loaderEndElement(helper);
-
-// build();
- }
- */
-
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
+
clipPathUnits = (getPres(sty.setName("clipPathUnits"))
- && sty.getStringValue().equals("objectBoundingBox"))
- ? CP_OBJECT_BOUNDING_BOX
+ && sty.getStringValue().equals("objectBoundingBox"))
+ ? CP_OBJECT_BOUNDING_BOX
: CP_USER_SPACE_ON_USE;
}
-
+
public int getClipPathUnits()
{
return clipPathUnits;
@@ -107,50 +92,61 @@ public class ClipPath extends SVGElement
public Shape getClipPathShape()
{
- if (children.size() == 0) return null;
- if (children.size() == 1) return ((ShapeElement)children.get(0)).getShape();
+ if (children.isEmpty())
+ {
+ return null;
+ }
+ if (children.size() == 1)
+ {
+ return ((ShapeElement) children.get(0)).getShape();
+ }
Area clipArea = null;
for (Iterator it = children.iterator(); it.hasNext();)
{
- ShapeElement se = (ShapeElement)it.next();
+ ShapeElement se = (ShapeElement) it.next();
if (clipArea == null)
{
Shape shape = se.getShape();
- if (shape != null) clipArea = new Area(se.getShape());
+ if (shape != null)
+ {
+ clipArea = new Area(se.getShape());
+ }
continue;
}
Shape shape = se.getShape();
- if (shape != null) clipArea.intersect(new Area(shape));
+ if (shape != null)
+ {
+ clipArea.intersect(new Area(shape));
+ }
}
return clipArea;
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
public boolean updateTime(double curTime) throws SVGException
{
-// if (trackManager.getNumTracks() == 0) return false;
-
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("clipPathUnits")))
{
String newUnitsStrn = sty.getStringValue();
int newUnits = newUnitsStrn.equals("objectBoundingBox")
- ? CP_OBJECT_BOUNDING_BOX
+ ? CP_OBJECT_BOUNDING_BOX
: CP_USER_SPACE_ON_USE;
-
+
if (newUnits != clipPathUnits)
{
clipPathUnits = newUnits;
diff --git a/src/main/java/com/kitfox/svg/Defs.java b/src/main/java/com/kitfox/svg/Defs.java
index 33da194..0d70284 100644
--- a/src/main/java/com/kitfox/svg/Defs.java
+++ b/src/main/java/com/kitfox/svg/Defs.java
@@ -33,15 +33,9 @@
*
* Created on January 26, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
-import java.awt.*;
-import java.awt.geom.*;
-import java.util.*;
-
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
+import java.util.Iterator;
/**
* @author Mark McKay
@@ -50,8 +44,18 @@ import org.xml.sax.*;
public class Defs extends TransformableElement
{
- /** Creates a new instance of Stop */
- public Defs() {
+ public static final String TAG_NAME = "defs";
+
+ /**
+ * Creates a new instance of Stop
+ */
+ public Defs()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
/**
@@ -60,7 +64,7 @@ public class Defs extends TransformableElement
*/
public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
{
- super.loaderAddChild(helper, child);
+ super.loaderAddChild(helper, child);
// members.add(child);
}
@@ -70,10 +74,10 @@ public class Defs extends TransformableElement
boolean stateChange = false;
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
stateChange = stateChange || ele.updateTime(curTime);
}
-
+
return super.updateTime(curTime) || stateChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/Desc.java b/src/main/java/com/kitfox/svg/Desc.java
index 8522eff..e717f5e 100644
--- a/src/main/java/com/kitfox/svg/Desc.java
+++ b/src/main/java/com/kitfox/svg/Desc.java
@@ -33,7 +33,6 @@
*
* Created on September 19, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
/**
@@ -42,12 +41,22 @@ package com.kitfox.svg;
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Desc extends SVGElement {
+public class Desc extends SVGElement
+{
+ public static final String TAG_NAME = "desc";
StringBuffer text = new StringBuffer();
- /** Creates a new instance of Stop */
- public Desc() {
+ /**
+ * Creates a new instance of Stop
+ */
+ public Desc()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
/**
@@ -58,8 +67,11 @@ public class Desc extends SVGElement {
this.text.append(text);
}
- public String getText() { return text.toString(); }
-
+ public String getText()
+ {
+ return text.toString();
+ }
+
public boolean updateTime(double curTime)
{
return false;
diff --git a/src/main/java/com/kitfox/svg/Ellipse.java b/src/main/java/com/kitfox/svg/Ellipse.java
index 59cd635..6051d3f 100644
--- a/src/main/java/com/kitfox/svg/Ellipse.java
+++ b/src/main/java/com/kitfox/svg/Ellipse.java
@@ -33,87 +33,66 @@
*
* Created on January 26, 2004, 5:25 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
-
-import java.awt.*;
-import java.awt.geom.*;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Rectangle2D;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Ellipse extends ShapeElement {
+public class Ellipse extends ShapeElement
+{
+ public static final String TAG_NAME = "ellipse";
float cx = 0.0f;
float cy = 0.0f;
float rx = 0.0f;
float ry = 0.0f;
-
Ellipse2D.Float ellipse = new Ellipse2D.Float();
- /** Creates a new instance of Rect */
- public Ellipse() {
+ /**
+ * Creates a new instance of Rect
+ */
+ public Ellipse()
+ {
}
-/*
- protected void init(String idIn, Style parentStyle, String cx, String cy, String rx, String ry) {
- super.init(idIn, parentStyle);
-
- this.cx = parseDouble(cx);
- this.cy = parseDouble(cy);
- this.rx = parseDouble(rx);
- this.ry = parseDouble(ry);
- setBounds(this.cx - this.rx, this.cy - this.ry, this.rx * 2.0, this.ry * 2.0);
- }
-*/
- /*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ public String getTagName()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String cx = attrs.getValue("cx");
- String cy = attrs.getValue("cy");
- String rx = attrs.getValue("rx");
- String ry = attrs.getValue("ry");
-
- this.cx = XMLParseUtil.parseDouble(cx);
- this.cy = XMLParseUtil.parseDouble(cy);
- this.rx = XMLParseUtil.parseDouble(rx);
- this.ry = XMLParseUtil.parseDouble(ry);
-
- build();
+ return TAG_NAME;
}
- */
-
- /*
- public void loaderEndElement(SVGLoaderHelper helper)
- {
- super.loaderEndElement(helper);
- build();
- }
- */
-
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("rx"))) rx = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("ry"))) ry = sty.getFloatValueWithUnits();
-
+
+ if (getPres(sty.setName("cx")))
+ {
+ cx = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("cy")))
+ {
+ cy = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("rx")))
+ {
+ rx = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("ry")))
+ {
+ ry = sty.getFloatValueWithUnits();
+ }
+
ellipse.setFrame(cx - rx, cy - ry, rx * 2f, ry * 2f);
}
@@ -133,10 +112,11 @@ public class Ellipse extends ShapeElement {
{
return boundsToParent(includeStrokeInBounds(ellipse.getBounds2D()));
}
-
+
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -148,7 +128,7 @@ public class Ellipse extends ShapeElement {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("cx")))
{
float newCx = sty.getFloatValueWithUnits();
@@ -158,7 +138,7 @@ public class Ellipse extends ShapeElement {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("cy")))
{
float newCy = sty.getFloatValueWithUnits();
@@ -168,7 +148,7 @@ public class Ellipse extends ShapeElement {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("rx")))
{
float newRx = sty.getFloatValueWithUnits();
@@ -178,7 +158,7 @@ public class Ellipse extends ShapeElement {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("ry")))
{
float newRy = sty.getFloatValueWithUnits();
@@ -188,14 +168,14 @@ public class Ellipse extends ShapeElement {
shapeChange = true;
}
}
-
+
if (shapeChange)
{
build();
// ellipse.setFrame(cx - rx, cy - ry, rx * 2f, ry * 2f);
// return true;
}
-
+
return changeState || shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/FeDistantLight.java b/src/main/java/com/kitfox/svg/FeDistantLight.java
index 5119e25..1581b2d 100644
--- a/src/main/java/com/kitfox/svg/FeDistantLight.java
+++ b/src/main/java/com/kitfox/svg/FeDistantLight.java
@@ -33,48 +33,61 @@
*
* Created on March 18, 2004, 6:52 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.*;
-import java.awt.geom.*;
-import java.net.*;
-import java.util.*;
-
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class FeDistantLight extends FeLight
+public class FeDistantLight extends FeLight
{
+
+ public static final String TAG_NAME = "fedistantlight";
float azimuth = 0f;
float elevation = 0f;
-
- /** Creates a new instance of FillElement */
- public FeDistantLight() {
+ /**
+ * Creates a new instance of FillElement
+ */
+ public FeDistantLight()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
String strn;
-
- if (getPres(sty.setName("azimuth"))) azimuth = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("elevation"))) elevation = sty.getFloatValueWithUnits();
+
+ if (getPres(sty.setName("azimuth")))
+ {
+ azimuth = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("elevation")))
+ {
+ elevation = sty.getFloatValueWithUnits();
+ }
+ }
+
+ public float getAzimuth()
+ {
+ return azimuth;
+ }
+
+ public float getElevation()
+ {
+ return elevation;
}
- public float getAzimuth() { return azimuth; }
- public float getElevation() { return elevation; }
-
public boolean updateTime(double curTime) throws SVGException
{
// if (trackManager.getNumTracks() == 0) return false;
@@ -82,7 +95,7 @@ public class FeDistantLight extends FeLight
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean stateChange = false;
-
+
if (getPres(sty.setName("azimuth")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -92,7 +105,7 @@ public class FeDistantLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("elevation")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -102,8 +115,7 @@ public class FeDistantLight extends FeLight
stateChange = true;
}
}
-
+
return stateChange;
}
}
-
diff --git a/src/main/java/com/kitfox/svg/FeLight.java b/src/main/java/com/kitfox/svg/FeLight.java
index 3df4492..3a69371 100644
--- a/src/main/java/com/kitfox/svg/FeLight.java
+++ b/src/main/java/com/kitfox/svg/FeLight.java
@@ -33,27 +33,26 @@
*
* Created on March 18, 2004, 6:52 AM
*/
-
package com.kitfox.svg;
-import java.awt.*;
-import java.awt.geom.*;
-import java.net.*;
-import java.util.*;
-
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
-
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-abstract public class FeLight extends FilterEffects
+abstract public class FeLight extends FilterEffects
{
- /** Creates a new instance of FillElement */
- public FeLight() {
+ public static final String TAG_NAME = "feLight";
+
+ /**
+ * Creates a new instance of FillElement
+ */
+ public FeLight()
+ {
}
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
}
-
diff --git a/src/main/java/com/kitfox/svg/FePointLight.java b/src/main/java/com/kitfox/svg/FePointLight.java
index 4b316fe..264d696 100644
--- a/src/main/java/com/kitfox/svg/FePointLight.java
+++ b/src/main/java/com/kitfox/svg/FePointLight.java
@@ -33,52 +33,72 @@
*
* Created on March 18, 2004, 6:52 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.*;
-import java.awt.geom.*;
-import java.net.*;
-import java.util.*;
-
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class FePointLight extends FeLight
+public class FePointLight extends FeLight
{
+
+ public static final String TAG_NAME = "fepointlight";
float x = 0f;
float y = 0f;
float z = 0f;
-
- /** Creates a new instance of FillElement */
- public FePointLight() {
+ /**
+ * Creates a new instance of FillElement
+ */
+ public FePointLight()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
String strn;
-
- if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("z"))) z = sty.getFloatValueWithUnits();
+
+ if (getPres(sty.setName("x")))
+ {
+ x = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("y")))
+ {
+ y = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("z")))
+ {
+ z = sty.getFloatValueWithUnits();
+ }
+ }
+
+ public float getX()
+ {
+ return x;
+ }
+
+ public float getY()
+ {
+ return y;
+ }
+
+ public float getZ()
+ {
+ return z;
}
- public float getX() { return x; }
- public float getY() { return y; }
- public float getZ() { return z; }
-
public boolean updateTime(double curTime) throws SVGException
{
// if (trackManager.getNumTracks() == 0) return false;
@@ -86,7 +106,7 @@ public class FePointLight extends FeLight
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean stateChange = false;
-
+
if (getPres(sty.setName("x")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -96,7 +116,7 @@ public class FePointLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("y")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -106,7 +126,7 @@ public class FePointLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("z")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -116,8 +136,7 @@ public class FePointLight extends FeLight
stateChange = true;
}
}
-
+
return stateChange;
}
}
-
diff --git a/src/main/java/com/kitfox/svg/FeSpotLight.java b/src/main/java/com/kitfox/svg/FeSpotLight.java
index 186ebe2..81fd088 100644
--- a/src/main/java/com/kitfox/svg/FeSpotLight.java
+++ b/src/main/java/com/kitfox/svg/FeSpotLight.java
@@ -33,24 +33,18 @@
*
* Created on March 18, 2004, 6:52 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.*;
-import java.awt.geom.*;
-import java.net.*;
-import java.util.*;
-
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class FeSpotLight extends FeLight
+public class FeSpotLight extends FeLight
{
+
+ public static final String TAG_NAME = "fespotlight";
float x = 0f;
float y = 0f;
float z = 0f;
@@ -59,39 +53,100 @@ public class FeSpotLight extends FeLight
float pointsAtZ = 0f;
float specularComponent = 0f;
float limitingConeAngle = 0f;
-
- /** Creates a new instance of FillElement */
- public FeSpotLight() {
+ /**
+ * Creates a new instance of FillElement
+ */
+ public FeSpotLight()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
String strn;
-
- if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("z"))) z = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("pointsAtX"))) pointsAtX = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("pointsAtY"))) pointsAtY = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("pointsAtZ"))) pointsAtZ = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("specularComponent"))) specularComponent = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("limitingConeAngle"))) limitingConeAngle = sty.getFloatValueWithUnits();
+
+ if (getPres(sty.setName("x")))
+ {
+ x = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("y")))
+ {
+ y = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("z")))
+ {
+ z = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("pointsAtX")))
+ {
+ pointsAtX = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("pointsAtY")))
+ {
+ pointsAtY = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("pointsAtZ")))
+ {
+ pointsAtZ = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("specularComponent")))
+ {
+ specularComponent = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("limitingConeAngle")))
+ {
+ limitingConeAngle = sty.getFloatValueWithUnits();
+ }
+ }
+
+ public float getX()
+ {
+ return x;
+ }
+
+ public float getY()
+ {
+ return y;
+ }
+
+ public float getZ()
+ {
+ return z;
+ }
+
+ public float getPointsAtX()
+ {
+ return pointsAtX;
+ }
+
+ public float getPointsAtY()
+ {
+ return pointsAtY;
+ }
+
+ public float getPointsAtZ()
+ {
+ return pointsAtZ;
+ }
+
+ public float getSpecularComponent()
+ {
+ return specularComponent;
+ }
+
+ public float getLimitingConeAngle()
+ {
+ return limitingConeAngle;
}
- public float getX() { return x; }
- public float getY() { return y; }
- public float getZ() { return z; }
- public float getPointsAtX() { return pointsAtX; }
- public float getPointsAtY() { return pointsAtY; }
- public float getPointsAtZ() { return pointsAtZ; }
- public float getSpecularComponent() { return specularComponent; }
- public float getLimitingConeAngle() { return limitingConeAngle; }
-
public boolean updateTime(double curTime) throws SVGException
{
// if (trackManager.getNumTracks() == 0) return false;
@@ -99,7 +154,7 @@ public class FeSpotLight extends FeLight
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean stateChange = false;
-
+
if (getPres(sty.setName("x")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -109,7 +164,7 @@ public class FeSpotLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("y")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -119,7 +174,7 @@ public class FeSpotLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("z")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -129,7 +184,7 @@ public class FeSpotLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("pointsAtX")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -139,7 +194,7 @@ public class FeSpotLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("pointsAtY")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -149,7 +204,7 @@ public class FeSpotLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("pointsAtZ")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -159,7 +214,7 @@ public class FeSpotLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("specularComponent")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -169,7 +224,7 @@ public class FeSpotLight extends FeLight
stateChange = true;
}
}
-
+
if (getPres(sty.setName("limitingConeAngle")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -179,8 +234,7 @@ public class FeSpotLight extends FeLight
stateChange = true;
}
}
-
+
return stateChange;
}
}
-
diff --git a/src/main/java/com/kitfox/svg/FillElement.java b/src/main/java/com/kitfox/svg/FillElement.java
index a09f69a..1bc6cf8 100644
--- a/src/main/java/com/kitfox/svg/FillElement.java
+++ b/src/main/java/com/kitfox/svg/FillElement.java
@@ -33,7 +33,6 @@
*
* Created on March 18, 2004, 6:52 AM
*/
-
package com.kitfox.svg;
import java.awt.*;
@@ -43,18 +42,22 @@ import java.awt.geom.*;
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-abstract public class FillElement extends SVGElement {
-
- /** Creates a new instance of FillElement */
- public FillElement() {
+abstract public class FillElement extends SVGElement
+{
+ /**
+ * Creates a new instance of FillElement
+ */
+ public FillElement()
+ {
}
/**
- * Requests the paint defined by this element. Passes in information
- * to allow paint to be customized
+ * Requests the paint defined by this element. Passes in information to
+ * allow paint to be customized
+ *
* @param bounds - bounding box of shape being rendered
- * @param xform - The current transformation that the shape is being rendered
- * under.
+ * @param xform - The current transformation that the shape is being
+ * rendered under.
*/
abstract public Paint getPaint(Rectangle2D bounds, AffineTransform xform);
}
diff --git a/src/main/java/com/kitfox/svg/Filter.java b/src/main/java/com/kitfox/svg/Filter.java
index 590fe60..d55c643 100644
--- a/src/main/java/com/kitfox/svg/Filter.java
+++ b/src/main/java/com/kitfox/svg/Filter.java
@@ -33,44 +33,46 @@
*
* Created on March 18, 2004, 6:52 AM
*/
-
package com.kitfox.svg;
-import java.awt.geom.*;
-import java.net.*;
-import java.util.*;
-
-import com.kitfox.svg.xml.*;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.geom.Point2D;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Filter extends SVGElement
+public class Filter extends SVGElement
{
+
+ public static final String TAG_NAME = "filter";
public static final int FU_OBJECT_BOUNDING_BOX = 0;
public static final int FU_USER_SPACE_ON_USE = 1;
-
protected int filterUnits = FU_OBJECT_BOUNDING_BOX;
-
public static final int PU_OBJECT_BOUNDING_BOX = 0;
public static final int PU_USER_SPACE_ON_USE = 1;
-
protected int primitiveUnits = PU_OBJECT_BOUNDING_BOX;
-
float x = 0f;
float y = 0f;
float width = 1f;
float height = 1f;
-
Point2D filterRes = new Point2D.Double();
-
URL href = null;
-
final ArrayList filterEffects = new ArrayList();
- /** Creates a new instance of FillElement */
- public Filter() {
+ /**
+ * Creates a new instance of FillElement
+ */
+ public Filter()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
/**
@@ -86,55 +88,92 @@ public class Filter extends SVGElement
filterEffects.add(child);
}
}
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
String strn;
-
+
if (getPres(sty.setName("filterUnits")))
{
strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
- else filterUnits = FU_OBJECT_BOUNDING_BOX;
+ if (strn.equals("userspaceonuse"))
+ {
+ filterUnits = FU_USER_SPACE_ON_USE;
+ } else
+ {
+ filterUnits = FU_OBJECT_BOUNDING_BOX;
+ }
}
if (getPres(sty.setName("primitiveUnits")))
{
strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
- else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
+ if (strn.equals("userspaceonuse"))
+ {
+ primitiveUnits = PU_USER_SPACE_ON_USE;
+ } else
+ {
+ primitiveUnits = PU_OBJECT_BOUNDING_BOX;
+ }
}
- if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("x")))
+ {
+ x = sty.getFloatValueWithUnits();
+ }
- if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("y")))
+ {
+ y = sty.getFloatValueWithUnits();
+ }
- if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("width")))
+ {
+ width = sty.getFloatValueWithUnits();
+ }
- if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("height")))
+ {
+ height = sty.getFloatValueWithUnits();
+ }
- try {
+ try
+ {
if (getPres(sty.setName("xlink:href")))
{
URI src = sty.getURIValue(getXMLBase());
href = src.toURL();
}
- }
- catch (Exception e)
+ } catch (Exception e)
{
throw new SVGException(e);
}
}
- public float getX() { return x; }
- public float getY() { return y; }
- public float getWidth() { return width; }
- public float getHeight() { return height; }
-
+ public float getX()
+ {
+ return x;
+ }
+
+ public float getY()
+ {
+ return y;
+ }
+
+ public float getWidth()
+ {
+ return width;
+ }
+
+ public float getHeight()
+ {
+ return height;
+ }
+
public boolean updateTime(double curTime) throws SVGException
{
// if (trackManager.getNumTracks() == 0) return false;
@@ -142,7 +181,7 @@ public class Filter extends SVGElement
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean stateChange = false;
-
+
if (getPres(sty.setName("x")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -152,7 +191,7 @@ public class Filter extends SVGElement
stateChange = true;
}
}
-
+
if (getPres(sty.setName("y")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -162,7 +201,7 @@ public class Filter extends SVGElement
stateChange = true;
}
}
-
+
if (getPres(sty.setName("width")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -172,7 +211,7 @@ public class Filter extends SVGElement
stateChange = true;
}
}
-
+
if (getPres(sty.setName("height")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -182,21 +221,21 @@ public class Filter extends SVGElement
stateChange = true;
}
}
-
- try {
+
+ try
+ {
if (getPres(sty.setName("xlink:href")))
{
URI src = sty.getURIValue(getXMLBase());
URL newVal = src.toURL();
-
+
if (!newVal.equals(href))
{
href = newVal;
stateChange = true;
}
}
- }
- catch (Exception e)
+ } catch (Exception e)
{
throw new SVGException(e);
}
@@ -205,8 +244,13 @@ public class Filter extends SVGElement
{
int newVal;
String strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
- else newVal = FU_OBJECT_BOUNDING_BOX;
+ if (strn.equals("userspaceonuse"))
+ {
+ newVal = FU_USER_SPACE_ON_USE;
+ } else
+ {
+ newVal = FU_OBJECT_BOUNDING_BOX;
+ }
if (newVal != filterUnits)
{
filterUnits = newVal;
@@ -218,8 +262,13 @@ public class Filter extends SVGElement
{
int newVal;
String strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
- else newVal = PU_OBJECT_BOUNDING_BOX;
+ if (strn.equals("userspaceonuse"))
+ {
+ newVal = PU_USER_SPACE_ON_USE;
+ } else
+ {
+ newVal = PU_OBJECT_BOUNDING_BOX;
+ }
if (newVal != filterUnits)
{
primitiveUnits = newVal;
@@ -227,9 +276,8 @@ public class Filter extends SVGElement
}
}
-
-
+
+
return stateChange;
}
}
-
diff --git a/src/main/java/com/kitfox/svg/FilterEffects.java b/src/main/java/com/kitfox/svg/FilterEffects.java
index c1a3004..d78c60a 100644
--- a/src/main/java/com/kitfox/svg/FilterEffects.java
+++ b/src/main/java/com/kitfox/svg/FilterEffects.java
@@ -33,24 +33,20 @@
*
* Created on March 18, 2004, 6:52 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.*;
-import java.awt.geom.*;
-import java.net.*;
-import java.util.*;
-
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
+import java.net.URI;
+import java.net.URL;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class FilterEffects extends SVGElement
+public class FilterEffects extends SVGElement
{
+ public static final String TAG_NAME = "filtereffects";
+
public static final int FP_SOURCE_GRAPHIC = 0;
public static final int FP_SOURCE_ALPHA = 1;
public static final int FP_BACKGROUND_IMAGE = 2;
@@ -58,25 +54,25 @@ public class FilterEffects extends SVGElement
public static final int FP_FILL_PAINT = 4;
public static final int FP_STROKE_PAINT = 5;
public static final int FP_CUSTOM = 5;
-
private int filterPrimitiveTypeIn;
private String filterPrimitiveRefIn;
-
-
float x = 0f;
float y = 0f;
float width = 1f;
float height = 1f;
-
String result = "defaultFilterName";
-
-
-
URL href = null;
+ /**
+ * Creates a new instance of FillElement
+ */
+ public FilterEffects()
+ {
+ }
- /** Creates a new instance of FillElement */
- public FilterEffects() {
+ public String getTagName()
+ {
+ return TAG_NAME;
}
/**
@@ -92,55 +88,70 @@ public class FilterEffects extends SVGElement
// filterEffects.add(child);
}
}
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
String strn;
/*
- if (getPres(sty.setName("filterUnits")))
- {
- strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
- else filterUnits = FU_OBJECT_BOUNDING_BOX;
- }
-
- if (getPres(sty.setName("primitiveUnits")))
- {
- strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
- else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
- }
-
- if (getPres(sty.setName("x"))) x = sty.getFloatValue();
+ if (getPres(sty.setName("filterUnits")))
+ {
+ strn = sty.getStringValue().toLowerCase();
+ if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
+ else filterUnits = FU_OBJECT_BOUNDING_BOX;
+ }
+
+ if (getPres(sty.setName("primitiveUnits")))
+ {
+ strn = sty.getStringValue().toLowerCase();
+ if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
+ else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
+ }
+
+ if (getPres(sty.setName("x"))) x = sty.getFloatValue();
+
+ if (getPres(sty.setName("y"))) y = sty.getFloatValue();
+
+ if (getPres(sty.setName("width"))) width = sty.getFloatValue();
+
+ if (getPres(sty.setName("height"))) height = sty.getFloatValue();
+
+ try {
+ if (getPres(sty.setName("xlink:href")))
+ {
+ URI src = sty.getURIValue(getXMLBase());
+ href = src.toURL();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new SVGException(e);
+ }
+ */
+ }
- if (getPres(sty.setName("y"))) y = sty.getFloatValue();
+ public float getX()
+ {
+ return x;
+ }
- if (getPres(sty.setName("width"))) width = sty.getFloatValue();
+ public float getY()
+ {
+ return y;
+ }
- if (getPres(sty.setName("height"))) height = sty.getFloatValue();
+ public float getWidth()
+ {
+ return width;
+ }
- try {
- if (getPres(sty.setName("xlink:href")))
- {
- URI src = sty.getURIValue(getXMLBase());
- href = src.toURL();
- }
- }
- catch (Exception e)
- {
- throw new SVGException(e);
- }
-*/
+ public float getHeight()
+ {
+ return height;
}
- public float getX() { return x; }
- public float getY() { return y; }
- public float getWidth() { return width; }
- public float getHeight() { return height; }
-
public boolean updateTime(double curTime) throws SVGException
{
// if (trackManager.getNumTracks() == 0) return false;
@@ -148,7 +159,7 @@ public class FilterEffects extends SVGElement
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean stateChange = false;
-
+
if (getPres(sty.setName("x")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -158,7 +169,7 @@ public class FilterEffects extends SVGElement
stateChange = true;
}
}
-
+
if (getPres(sty.setName("y")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -168,7 +179,7 @@ public class FilterEffects extends SVGElement
stateChange = true;
}
}
-
+
if (getPres(sty.setName("width")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -178,7 +189,7 @@ public class FilterEffects extends SVGElement
stateChange = true;
}
}
-
+
if (getPres(sty.setName("height")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -188,55 +199,54 @@ public class FilterEffects extends SVGElement
stateChange = true;
}
}
-
- try {
+
+ try
+ {
if (getPres(sty.setName("xlink:href")))
{
URI src = sty.getURIValue(getXMLBase());
URL newVal = src.toURL();
-
+
if (!newVal.equals(href))
{
href = newVal;
stateChange = true;
}
}
- }
- catch (Exception e)
+ } catch (Exception e)
{
throw new SVGException(e);
}
/*
- if (getPres(sty.setName("filterUnits")))
- {
- int newVal;
- String strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
- else newVal = FU_OBJECT_BOUNDING_BOX;
- if (newVal != filterUnits)
- {
- filterUnits = newVal;
- stateChange = true;
- }
- }
+ if (getPres(sty.setName("filterUnits")))
+ {
+ int newVal;
+ String strn = sty.getStringValue().toLowerCase();
+ if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
+ else newVal = FU_OBJECT_BOUNDING_BOX;
+ if (newVal != filterUnits)
+ {
+ filterUnits = newVal;
+ stateChange = true;
+ }
+ }
+
+ if (getPres(sty.setName("primitiveUnits")))
+ {
+ int newVal;
+ String strn = sty.getStringValue().toLowerCase();
+ if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
+ else newVal = PU_OBJECT_BOUNDING_BOX;
+ if (newVal != filterUnits)
+ {
+ primitiveUnits = newVal;
+ stateChange = true;
+ }
+ }
+
+ */
- if (getPres(sty.setName("primitiveUnits")))
- {
- int newVal;
- String strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
- else newVal = PU_OBJECT_BOUNDING_BOX;
- if (newVal != filterUnits)
- {
- primitiveUnits = newVal;
- stateChange = true;
- }
- }
-
- */
-
return stateChange;
}
}
-
diff --git a/src/main/java/com/kitfox/svg/Font.java b/src/main/java/com/kitfox/svg/Font.java
index f6e96a0..8d782de 100644
--- a/src/main/java/com/kitfox/svg/Font.java
+++ b/src/main/java/com/kitfox/svg/Font.java
@@ -33,14 +33,10 @@
*
* Created on February 20, 2004, 10:00 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
-
-import java.util.*;
+import java.util.HashMap;
/**
* Implements an embedded font.
@@ -52,62 +48,47 @@ import java.util.*;
*/
public class Font extends SVGElement
{
+
+ public static final String TAG_NAME = "font";
int horizOriginX = 0;
int horizOriginY = 0;
int horizAdvX = -1; //Must be specified
int vertOriginX = -1; //Defaults to horizAdvX / 2
int vertOriginY = -1; //Defaults to font's ascent
int vertAdvY = -1; //Defaults to one 'em'. See font-face
-
FontFace fontFace = null;
MissingGlyph missingGlyph = null;
final HashMap glyphs = new HashMap();
- /** Creates a new instance of Font */
+ /**
+ * Creates a new instance of Font
+ */
public Font()
{
}
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String horizOriginX = attrs.getValue("horiz-origin-x");
- String horizOriginY = attrs.getValue("horiz-origin-y");
- String horizAdvX = attrs.getValue("horiz-adv-x");
- String vertOriginX = attrs.getValue("vert-origin-x");
- String vertOriginY = attrs.getValue("vert-origin-y");
- String vertAdvY = attrs.getValue("vert-adv-y");
-
- if (horizOriginX != null) this.horizOriginX = XMLParseUtil.parseInt(horizOriginX);
- if (horizOriginY != null) this.horizOriginY = XMLParseUtil.parseInt(horizOriginY);
- if (horizAdvX != null) this.horizAdvX = XMLParseUtil.parseInt(horizAdvX);
- if (vertOriginX != null) this.vertOriginX = XMLParseUtil.parseInt(vertOriginX);
- if (vertOriginY != null) this.vertOriginY = XMLParseUtil.parseInt(vertOriginY);
- if (vertAdvY != null) this.vertAdvY = XMLParseUtil.parseInt(vertAdvY);
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-*/
+
/**
* Called after the start element but before the end element to indicate
* each child tag that has been processed
*/
public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
{
- super.loaderAddChild(helper, child);
+ super.loaderAddChild(helper, child);
if (child instanceof Glyph)
{
- glyphs.put(((Glyph)child).getUnicode(), child);
- }
- else if (child instanceof MissingGlyph)
+ glyphs.put(((Glyph) child).getUnicode(), child);
+ } else if (child instanceof MissingGlyph)
{
- missingGlyph = (MissingGlyph)child;
- }
- else if (child instanceof FontFace)
+ missingGlyph = (MissingGlyph) child;
+ } else if (child instanceof FontFace)
{
- fontFace = (FontFace)child;
+ fontFace = (FontFace) child;
}
}
@@ -116,66 +97,111 @@ public class Font extends SVGElement
super.loaderEndElement(helper);
//build();
-
+
helper.universe.registerFont(this);
}
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("horiz-origin-x"))) horizOriginX = sty.getIntValue();
-
- if (getPres(sty.setName("horiz-origin-y"))) horizOriginY = sty.getIntValue();
-
- if (getPres(sty.setName("horiz-adv-x"))) horizAdvX = sty.getIntValue();
-
- if (getPres(sty.setName("vert-origin-x"))) vertOriginX = sty.getIntValue();
-
- if (getPres(sty.setName("vert-origin-y"))) vertOriginY = sty.getIntValue();
-
- if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue();
+
+ if (getPres(sty.setName("horiz-origin-x")))
+ {
+ horizOriginX = sty.getIntValue();
+ }
+
+ if (getPres(sty.setName("horiz-origin-y")))
+ {
+ horizOriginY = sty.getIntValue();
+ }
+
+ if (getPres(sty.setName("horiz-adv-x")))
+ {
+ horizAdvX = sty.getIntValue();
+ }
+
+ if (getPres(sty.setName("vert-origin-x")))
+ {
+ vertOriginX = sty.getIntValue();
+ }
+
+ if (getPres(sty.setName("vert-origin-y")))
+ {
+ vertOriginY = sty.getIntValue();
+ }
+
+ if (getPres(sty.setName("vert-adv-y")))
+ {
+ vertAdvY = sty.getIntValue();
+ }
+ }
+
+ public FontFace getFontFace()
+ {
+ return fontFace;
}
-
- public FontFace getFontFace() { return fontFace; }
public MissingGlyph getGlyph(String unicode)
{
- Glyph retVal = (Glyph)glyphs.get(unicode);
- if (retVal == null) return missingGlyph;
+ Glyph retVal = (Glyph) glyphs.get(unicode);
+ if (retVal == null)
+ {
+ return missingGlyph;
+ }
return retVal;
}
- public int getHorizOriginX() { return horizOriginX; }
- public int getHorizOriginY() { return horizOriginY; }
- public int getHorizAdvX() { return horizAdvX; }
+ public int getHorizOriginX()
+ {
+ return horizOriginX;
+ }
+
+ public int getHorizOriginY()
+ {
+ return horizOriginY;
+ }
+
+ public int getHorizAdvX()
+ {
+ return horizAdvX;
+ }
public int getVertOriginX()
{
- if (vertOriginX != -1) return vertOriginX;
+ if (vertOriginX != -1)
+ {
+ return vertOriginX;
+ }
vertOriginX = getHorizAdvX() / 2;
return vertOriginX;
}
public int getVertOriginY()
{
- if (vertOriginY != -1) return vertOriginY;
+ if (vertOriginY != -1)
+ {
+ return vertOriginY;
+ }
vertOriginY = fontFace.getAscent();
return vertOriginY;
}
public int getVertAdvY()
{
- if (vertAdvY != -1) return vertAdvY;
+ if (vertAdvY != -1)
+ {
+ return vertAdvY;
+ }
vertAdvY = fontFace.getUnitsPerEm();
return vertAdvY;
}
-
+
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -184,73 +210,73 @@ public class Font extends SVGElement
//Fonts can't change
return false;
/*
- if (trackManager.getNumTracks() == 0) return false;
+ if (trackManager.getNumTracks() == 0) return false;
- //Get current values for parameters
- StyleAttribute sty = new StyleAttribute();
- boolean stateChange = false;
+ //Get current values for parameters
+ StyleAttribute sty = new StyleAttribute();
+ boolean stateChange = false;
- if (getPres(sty.setName("horiz-origin-x")))
- {
- int newVal = sty.getIntValue();
- if (newVal != horizOriginX)
- {
- horizOriginX = newVal;
- stateChange = true;
- }
- }
+ if (getPres(sty.setName("horiz-origin-x")))
+ {
+ int newVal = sty.getIntValue();
+ if (newVal != horizOriginX)
+ {
+ horizOriginX = newVal;
+ stateChange = true;
+ }
+ }
- if (getPres(sty.setName("horiz-origin-y")))
- {
- int newVal = sty.getIntValue();
- if (newVal != horizOriginY)
- {
- horizOriginY = newVal;
- stateChange = true;
- }
- }
+ if (getPres(sty.setName("horiz-origin-y")))
+ {
+ int newVal = sty.getIntValue();
+ if (newVal != horizOriginY)
+ {
+ horizOriginY = newVal;
+ stateChange = true;
+ }
+ }
- if (getPres(sty.setName("horiz-adv-x")))
- {
- int newVal = sty.getIntValue();
- if (newVal != horizAdvX)
- {
- horizAdvX = newVal;
- stateChange = true;
- }
- }
+ if (getPres(sty.setName("horiz-adv-x")))
+ {
+ int newVal = sty.getIntValue();
+ if (newVal != horizAdvX)
+ {
+ horizAdvX = newVal;
+ stateChange = true;
+ }
+ }
- if (getPres(sty.setName("vert-origin-x")))
- {
- int newVal = sty.getIntValue();
- if (newVal != vertOriginX)
- {
- vertOriginX = newVal;
- stateChange = true;
- }
- }
+ if (getPres(sty.setName("vert-origin-x")))
+ {
+ int newVal = sty.getIntValue();
+ if (newVal != vertOriginX)
+ {
+ vertOriginX = newVal;
+ stateChange = true;
+ }
+ }
- if (getPres(sty.setName("vert-origin-y")))
- {
- int newVal = sty.getIntValue();
- if (newVal != vertOriginY)
- {
- vertOriginY = newVal;
- stateChange = true;
- }
- }
+ if (getPres(sty.setName("vert-origin-y")))
+ {
+ int newVal = sty.getIntValue();
+ if (newVal != vertOriginY)
+ {
+ vertOriginY = newVal;
+ stateChange = true;
+ }
+ }
- if (getPres(sty.setName("vert-adv-y")))
- {
- int newVal = sty.getIntValue();
- if (newVal != vertAdvY)
- {
- vertAdvY = newVal;
- stateChange = true;
- }
- }
+ if (getPres(sty.setName("vert-adv-y")))
+ {
+ int newVal = sty.getIntValue();
+ if (newVal != vertAdvY)
+ {
+ vertAdvY = newVal;
+ stateChange = true;
+ }
+ }
- return shapeChange;
- */
+ return shapeChange;
+ */
}
}
diff --git a/src/main/java/com/kitfox/svg/FontFace.java b/src/main/java/com/kitfox/svg/FontFace.java
index e5b2938..b9d8748 100644
--- a/src/main/java/com/kitfox/svg/FontFace.java
+++ b/src/main/java/com/kitfox/svg/FontFace.java
@@ -33,16 +33,9 @@
*
* Created on February 20, 2004, 10:00 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
-
-import java.awt.geom.*;
-import java.awt.*;
-
/**
* Implements an embedded font.
@@ -54,15 +47,16 @@ import java.awt.*;
*/
public class FontFace extends SVGElement
{
- String fontFamily;
- /** Em size of coordinate system font is defined in */
+ public static final String TAG_NAME = "fontface";
+ String fontFamily;
+ /**
+ * Em size of coordinate system font is defined in
+ */
int unitsPerEm = 1000;
-
int ascent = -1;
int descent = -1;
int accentHeight = -1;
-
int underlinePosition = -1;
int underlineThickness = -1;
int strikethroughPosition = -1;
@@ -70,149 +64,167 @@ public class FontFace extends SVGElement
int overlinePosition = -1;
int overlineThickness = -1;
- /** Creates a new instance of Font */
+ /**
+ * Creates a new instance of Font
+ */
public FontFace()
{
}
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- fontFamily = attrs.getValue("font-family");
-
- String unitsPerEm = attrs.getValue("units-per-em");
- String ascent = attrs.getValue("ascent");
- String descent = attrs.getValue("descent");
- String accentHeight = attrs.getValue("accent-height");
-
- String underlinePosition = attrs.getValue("underline-position");
- String underlineThickness = attrs.getValue("underline-thickness");
- String strikethroughPosition = attrs.getValue("strikethrough-position");
- String strikethroughThickness = attrs.getValue("strikethrough-thickness");
- String overlinePosition = attrs.getValue("overline-position");
- String overlineThickness = attrs.getValue("overline-thickness");
-
- if (unitsPerEm != null) this.unitsPerEm = XMLParseUtil.parseInt(unitsPerEm);
- if (ascent != null) this.ascent = XMLParseUtil.parseInt(ascent);
- if (descent != null) this.descent = XMLParseUtil.parseInt(descent);
- if (accentHeight != null) this.accentHeight = XMLParseUtil.parseInt(accentHeight);
-
- if (underlinePosition != null) this.underlinePosition = XMLParseUtil.parseInt(underlinePosition);
- if (underlineThickness != null) this.underlineThickness = XMLParseUtil.parseInt(underlineThickness);
- if (strikethroughPosition != null) this.strikethroughPosition = XMLParseUtil.parseInt(strikethroughPosition);
- if (strikethroughThickness != null) this.strikethroughThickness = XMLParseUtil.parseInt(strikethroughThickness);
- if (overlinePosition != null) this.overlinePosition = XMLParseUtil.parseInt(overlinePosition);
- if (overlineThickness != null) this.overlineThickness = XMLParseUtil.parseInt(overlineThickness);
-
-// unitFontXform.setToScale(1.0 / (double)unitsPerEm, 1.0 / (double)unitsPerEm);
- }
- */
- /*
- public void loaderEndElement(SVGLoaderHelper helper)
+ public String getTagName()
{
- super.loaderEndElement(helper);
-
- build();
-
-// unitFontXform.setToScale(1.0 / (double)unitsPerEm, 1.0 / (double)unitsPerEm);
+ return TAG_NAME;
}
- */
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("font-family"))) fontFamily = sty.getStringValue();
-
- if (getPres(sty.setName("units-per-em"))) unitsPerEm = sty.getIntValue();
- if (getPres(sty.setName("ascent"))) ascent = sty.getIntValue();
- if (getPres(sty.setName("descent"))) descent = sty.getIntValue();
- if (getPres(sty.setName("accent-height"))) accentHeight = sty.getIntValue();
-
- if (getPres(sty.setName("underline-position"))) underlinePosition = sty.getIntValue();
- if (getPres(sty.setName("underline-thickness"))) underlineThickness = sty.getIntValue();
- if (getPres(sty.setName("strikethrough-position"))) strikethroughPosition = sty.getIntValue();
- if (getPres(sty.setName("strikethrough-thickenss"))) strikethroughThickness = sty.getIntValue();
- if (getPres(sty.setName("overline-position"))) overlinePosition = sty.getIntValue();
- if (getPres(sty.setName("overline-thickness"))) overlineThickness = sty.getIntValue();
- }
+ if (getPres(sty.setName("font-family")))
+ {
+ fontFamily = sty.getStringValue();
+ }
+
+ if (getPres(sty.setName("units-per-em")))
+ {
+ unitsPerEm = sty.getIntValue();
+ }
+ if (getPres(sty.setName("ascent")))
+ {
+ ascent = sty.getIntValue();
+ }
+ if (getPres(sty.setName("descent")))
+ {
+ descent = sty.getIntValue();
+ }
+ if (getPres(sty.setName("accent-height")))
+ {
+ accentHeight = sty.getIntValue();
+ }
+
+ if (getPres(sty.setName("underline-position")))
+ {
+ underlinePosition = sty.getIntValue();
+ }
+ if (getPres(sty.setName("underline-thickness")))
+ {
+ underlineThickness = sty.getIntValue();
+ }
+ if (getPres(sty.setName("strikethrough-position")))
+ {
+ strikethroughPosition = sty.getIntValue();
+ }
+ if (getPres(sty.setName("strikethrough-thickenss")))
+ {
+ strikethroughThickness = sty.getIntValue();
+ }
+ if (getPres(sty.setName("overline-position")))
+ {
+ overlinePosition = sty.getIntValue();
+ }
+ if (getPres(sty.setName("overline-thickness")))
+ {
+ overlineThickness = sty.getIntValue();
+ }
+ }
- public String getFontFamily() { return fontFamily; }
+ public String getFontFamily()
+ {
+ return fontFamily;
+ }
- public int getUnitsPerEm() { return unitsPerEm; }
+ public int getUnitsPerEm()
+ {
+ return unitsPerEm;
+ }
public int getAscent()
{
if (ascent == -1)
- ascent = unitsPerEm - ((Font)parent).getVertOriginY();
+ {
+ ascent = unitsPerEm - ((Font) parent).getVertOriginY();
+ }
return ascent;
}
public int getDescent()
{
if (descent == -1)
- descent = ((Font)parent).getVertOriginY();
+ {
+ descent = ((Font) parent).getVertOriginY();
+ }
return descent;
}
public int getAccentHeight()
{
if (accentHeight == -1)
+ {
accentHeight = getAscent();
+ }
return accentHeight;
}
public int getUnderlinePosition()
{
if (underlinePosition == -1)
+ {
underlinePosition = unitsPerEm * 5 / 6;
+ }
return underlinePosition;
}
public int getUnderlineThickness()
{
if (underlineThickness == -1)
+ {
underlineThickness = unitsPerEm / 20;
+ }
return underlineThickness;
}
public int getStrikethroughPosition()
{
if (strikethroughPosition == -1)
+ {
strikethroughPosition = unitsPerEm * 3 / 6;
+ }
return strikethroughPosition;
}
public int getStrikethroughThickness()
{
if (strikethroughThickness == -1)
+ {
strikethroughThickness = unitsPerEm / 20;
+ }
return strikethroughThickness;
}
public int getOverlinePosition()
{
if (overlinePosition == -1)
+ {
overlinePosition = unitsPerEm * 5 / 6;
+ }
return overlinePosition;
}
public int getOverlineThickness()
{
if (overlineThickness == -1)
+ {
overlineThickness = unitsPerEm / 20;
+ }
return overlineThickness;
}
-
+
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
diff --git a/src/main/java/com/kitfox/svg/Glyph.java b/src/main/java/com/kitfox/svg/Glyph.java
index c1610df..f184a9a 100644
--- a/src/main/java/com/kitfox/svg/Glyph.java
+++ b/src/main/java/com/kitfox/svg/Glyph.java
@@ -33,19 +33,9 @@
*
* Created on February 20, 2004, 10:00 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
-
-import java.awt.*;
-import java.awt.geom.*;
-import java.util.*;
-
-import com.kitfox.svg.pathcmd.*;
-//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
/**
* Implements an embedded font.
@@ -57,49 +47,47 @@ import com.kitfox.svg.pathcmd.*;
*/
public class Glyph extends MissingGlyph
{
+
+ public static final String TAG_NAME = "missingglyph";
/**
- * One or more characters indicating the unicode sequence that denotes
- * this glyph.
+ * One or more characters indicating the unicode sequence that denotes this
+ * glyph.
*/
String unicode;
- /** Creates a new instance of Font */
+ /**
+ * Creates a new instance of Font
+ */
public Glyph()
{
}
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
- //Get unicode sequence that maps to this glyph
- unicode = attrs.getValue("unicode");
- }
-*/
- /*
- public void loaderEndElement(SVGLoaderHelper helper)
+ public String getTagName()
{
- super.loaderEndElement(helper);
-
- build();
+ return TAG_NAME;
}
- */
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("unicode"))) unicode = sty.getStringValue();
+
+ if (getPres(sty.setName("unicode")))
+ {
+ unicode = sty.getStringValue();
+ }
}
-
- public String getUnicode() { return unicode; }
-
+
+ public String getUnicode()
+ {
+ return unicode;
+ }
+
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
diff --git a/src/main/java/com/kitfox/svg/Gradient.java b/src/main/java/com/kitfox/svg/Gradient.java
index 5cd17e9..8901930 100644
--- a/src/main/java/com/kitfox/svg/Gradient.java
+++ b/src/main/java/com/kitfox/svg/Gradient.java
@@ -33,17 +33,14 @@
*
* Created on January 26, 2004, 3:25 AM
*/
-
package com.kitfox.svg;
-import java.net.*;
-import java.util.*;
-import java.awt.geom.*;
-import java.awt.*;
-
-import com.kitfox.svg.xml.*;
-import java.io.BufferedReader;
-import java.io.IOException;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.Color;
+import java.awt.geom.AffineTransform;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -53,34 +50,37 @@ import java.util.logging.Logger;
*/
abstract public class Gradient extends FillElement
{
-
+ public static final String TAG_NAME = "gradient";
+
public static final int SM_PAD = 0;
public static final int SM_REPEAT = 1;
public static final int SM_REFLECT = 2;
-
int spreadMethod = SM_PAD;
-
public static final int GU_OBJECT_BOUNDING_BOX = 0;
public static final int GU_USER_SPACE_ON_USE = 1;
-
protected int gradientUnits = GU_OBJECT_BOUNDING_BOX;
-
//Either this gradient contains a list of stops, or it will take it's
// stops from the referenced gradient
ArrayList stops = new ArrayList();
URI stopRef = null;
-// Gradient stopRef = null;
-
protected AffineTransform gradientTransform = null;
-
+
//Cache arrays of stop values here
float[] stopFractions;
Color[] stopColors;
- /** Creates a new instance of Gradient */
- public Gradient() {
+ /**
+ * Creates a new instance of Gradient
+ */
+ public Gradient()
+ {
}
-
+
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
+
/**
* Called after the start element but before the end element to indicate
* each child tag that has been processed
@@ -89,70 +89,97 @@ abstract public class Gradient extends FillElement
{
super.loaderAddChild(helper, child);
- if (!(child instanceof Stop)) return;
- appendStop((Stop)child);
+ if (!(child instanceof Stop))
+ {
+ return;
+ }
+ appendStop((Stop) child);
}
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
String strn;
-
+
if (getPres(sty.setName("spreadMethod")))
{
strn = sty.getStringValue().toLowerCase();
- if (strn.equals("repeat")) spreadMethod = SM_REPEAT;
- else if (strn.equals("reflect")) spreadMethod = SM_REFLECT;
- else spreadMethod = SM_PAD;
+ if (strn.equals("repeat"))
+ {
+ spreadMethod = SM_REPEAT;
+ } else if (strn.equals("reflect"))
+ {
+ spreadMethod = SM_REFLECT;
+ } else
+ {
+ spreadMethod = SM_PAD;
+ }
}
if (getPres(sty.setName("gradientUnits")))
{
strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) gradientUnits = GU_USER_SPACE_ON_USE;
- else gradientUnits = GU_OBJECT_BOUNDING_BOX;
+ if (strn.equals("userspaceonuse"))
+ {
+ gradientUnits = GU_USER_SPACE_ON_USE;
+ } else
+ {
+ gradientUnits = GU_OBJECT_BOUNDING_BOX;
+ }
}
- if (getPres(sty.setName("gradientTransform"))) gradientTransform = parseTransform(sty.getStringValue());
+ if (getPres(sty.setName("gradientTransform")))
+ {
+ gradientTransform = parseTransform(sty.getStringValue());
+ }
//If we still don't have one, set it to identity
- if (gradientTransform == null) gradientTransform = new AffineTransform();
+ if (gradientTransform == null)
+ {
+ gradientTransform = new AffineTransform();
+ }
+
-
//Check to see if we're using our own stops or referencing someone else's
if (getPres(sty.setName("xlink:href")))
{
- try {
+ try
+ {
stopRef = sty.getURIValue(getXMLBase());
//System.err.println("Gradient: " + sty.getStringValue() + ", " + getXMLBase() + ", " + src);
// URI src = getXMLBase().resolve(href);
// stopRef = (Gradient)diagram.getUniverse().getElement(src);
- }
- catch (Exception e)
+ } catch (Exception e)
{
throw new SVGException("Could not resolve relative URL in Gradient: " + sty.getStringValue() + ", " + getXMLBase(), e);
}
}
}
-
+
public float[] getStopFractions()
{
if (stopRef != null)
{
- Gradient grad = (Gradient)diagram.getUniverse().getElement(stopRef);
+ Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef);
return grad.getStopFractions();
}
- if (stopFractions != null) return stopFractions;
+ if (stopFractions != null)
+ {
+ return stopFractions;
+ }
stopFractions = new float[stops.size()];
int idx = 0;
for (Iterator it = stops.iterator(); it.hasNext();)
{
- Stop stop = (Stop)it.next();
+ Stop stop = (Stop) it.next();
float val = stop.offset;
- if (idx != 0 && val < stopFractions[idx - 1]) val = stopFractions[idx - 1];
+ if (idx != 0 && val < stopFractions[idx - 1])
+ {
+ val = stopFractions[idx - 1];
+ }
stopFractions[idx++] = val;
}
@@ -163,44 +190,53 @@ abstract public class Gradient extends FillElement
{
if (stopRef != null)
{
- Gradient grad = (Gradient)diagram.getUniverse().getElement(stopRef);
+ Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef);
return grad.getStopColors();
}
- if (stopColors != null) return stopColors;
+ if (stopColors != null)
+ {
+ return stopColors;
+ }
stopColors = new Color[stops.size()];
int idx = 0;
for (Iterator it = stops.iterator(); it.hasNext();)
{
- Stop stop = (Stop)it.next();
+ Stop stop = (Stop) it.next();
int stopColorVal = stop.color.getRGB();
- Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int)(stop.opacity * 255), 0, 255));
+ Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255));
stopColors[idx++] = stopColor;
}
return stopColors;
}
-
+
public void setStops(Color[] colors, float[] fractions)
{
if (colors.length != fractions.length)
{
throw new IllegalArgumentException();
}
-
+
this.stopColors = colors;
this.stopFractions = fractions;
stopRef = null;
}
-
+
private int clamp(int val, int min, int max)
{
- if (val < min) return min;
- if (val > max) return max;
+ if (val < min)
+ {
+ return min;
+ }
+ if (val > max)
+ {
+ return max;
+ }
return val;
}
-
+
public void setStopRef(URI grad)
{
stopRef = grad;
@@ -212,8 +248,9 @@ abstract public class Gradient extends FillElement
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -226,28 +263,40 @@ abstract public class Gradient extends FillElement
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
String strn;
-
+
if (getPres(sty.setName("spreadMethod")))
{
int newVal;
strn = sty.getStringValue().toLowerCase();
- if (strn.equals("repeat")) newVal = SM_REPEAT;
- else if (strn.equals("reflect")) newVal = SM_REFLECT;
- else newVal = SM_PAD;
+ if (strn.equals("repeat"))
+ {
+ newVal = SM_REPEAT;
+ } else if (strn.equals("reflect"))
+ {
+ newVal = SM_REFLECT;
+ } else
+ {
+ newVal = SM_PAD;
+ }
if (spreadMethod != newVal)
{
spreadMethod = newVal;
stateChange = true;
}
}
-
+
if (getPres(sty.setName("gradientUnits")))
{
int newVal;
strn = sty.getStringValue().toLowerCase();
- if (strn.equals("userspaceonuse")) newVal = GU_USER_SPACE_ON_USE;
- else newVal = GU_OBJECT_BOUNDING_BOX;
+ if (strn.equals("userspaceonuse"))
+ {
+ newVal = GU_USER_SPACE_ON_USE;
+ } else
+ {
+ newVal = GU_OBJECT_BOUNDING_BOX;
+ }
if (newVal != gradientUnits)
{
gradientUnits = newVal;
@@ -265,21 +314,21 @@ abstract public class Gradient extends FillElement
}
}
-
+
//Check to see if we're using our own stops or referencing someone else's
if (getPres(sty.setName("xlink:href")))
{
- try {
+ try
+ {
URI newVal = sty.getURIValue(getXMLBase());
if ((newVal == null && stopRef != null) || !newVal.equals(stopRef))
{
stopRef = newVal;
stateChange = true;
}
- }
- catch (Exception e)
+ } catch (Exception e)
{
- Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+ Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
"Could not parse xlink:href", e);
}
}
@@ -287,7 +336,7 @@ abstract public class Gradient extends FillElement
//Check stops, if any
for (Iterator it = stops.iterator(); it.hasNext();)
{
- Stop stop = (Stop)it.next();
+ Stop stop = (Stop) it.next();
if (stop.updateTime(curTime))
{
stateChange = true;
@@ -295,8 +344,7 @@ abstract public class Gradient extends FillElement
stopColors = null;
}
}
-
+
return stateChange;
}
-
}
diff --git a/src/main/java/com/kitfox/svg/Group.java b/src/main/java/com/kitfox/svg/Group.java
index 5fa1e92..78320ff 100644
--- a/src/main/java/com/kitfox/svg/Group.java
+++ b/src/main/java/com/kitfox/svg/Group.java
@@ -33,12 +33,10 @@
*
* Created on January 26, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
import java.awt.Graphics2D;
-import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
@@ -48,34 +46,29 @@ import java.awt.geom.Rectangle2D;
import java.util.Iterator;
import java.util.List;
-
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
public class Group extends ShapeElement
{
-
+ public static final String TAG_NAME = "group";
+
//Cache bounding box for faster clip testing
Rectangle2D boundingBox;
Shape cachedShape;
- //Cache clip bounds
-// final Rectangle clipBounds = new Rectangle();
-
- /** Creates a new instance of Stop */
- public Group() {
+ /**
+ * Creates a new instance of Stop
+ */
+ public Group()
+ {
}
- /*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ public String getTagName()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- //String transform = attrs.getValue("transform");
+ return TAG_NAME;
}
- */
/**
* Called after the start element but before the end element to indicate
@@ -84,8 +77,6 @@ public class Group extends ShapeElement
public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
{
super.loaderAddChild(helper, child);
-
-// members.add(child);
}
protected boolean outsideClip(Graphics2D g) throws SVGException
@@ -98,12 +89,6 @@ public class Group extends ShapeElement
//g.getClipBounds(clipBounds);
Rectangle2D rect = getBoundingBox();
-//if (rect == null)
-//{
-// rect = getBoundingBox();
-//}
-
-// if (rect.intersects(clipBounds))
if (clip.intersects(rect))
{
return false;
@@ -120,21 +105,20 @@ public class Group extends ShapeElement
try
{
xform.inverseTransform(point, xPoint);
- }
- catch (NoninvertibleTransformException ex)
+ } catch (NoninvertibleTransformException ex)
{
throw new SVGException(ex);
}
}
-
-
+
+
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
- RenderableElement rendEle = (RenderableElement)ele;
-
+ RenderableElement rendEle = (RenderableElement) ele;
+
rendEle.pick(xPoint, boundingBox, retVec);
}
}
@@ -147,15 +131,15 @@ public class Group extends ShapeElement
ltw = new AffineTransform(ltw);
ltw.concatenate(xform);
}
-
-
+
+
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
- RenderableElement rendEle = (RenderableElement)ele;
-
+ RenderableElement rendEle = (RenderableElement) ele;
+
rendEle.pick(pickArea, ltw, boundingBox, retVec);
}
}
@@ -167,12 +151,15 @@ public class Group extends ShapeElement
StyleAttribute styleAttrib = new StyleAttribute();
if (getStyle(styleAttrib.setName("visibility")))
{
- if (!styleAttrib.getStringValue().equals("visible")) return;
+ if (!styleAttrib.getStringValue().equals("visible"))
+ {
+ return;
+ }
}
-
+
//Do not process offscreen groups
boolean ignoreClip = diagram.ignoringClipHeuristic();
- if (!ignoreClip && outsideClip(g))
+ if (!ignoreClip && outsideClip(g))
{
return;
}
@@ -195,18 +182,18 @@ public class Group extends ShapeElement
Shape clip = g.getClip();
while (it.hasNext())
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
- RenderableElement rendEle = (RenderableElement)ele;
+ RenderableElement rendEle = (RenderableElement) ele;
// if (shapeEle == null) continue;
if (!(ele instanceof Group))
{
//Skip if clipping area is outside our bounds
- if (!ignoreClip && clip != null
- && !clip.intersects(rendEle.getBoundingBox()))
+ if (!ignoreClip && clip != null
+ && !clip.intersects(rendEle.getBoundingBox()))
{
continue;
}
@@ -219,13 +206,15 @@ public class Group extends ShapeElement
finishLayer(g);
}
-
/**
* Retrieves the cached bounding box of this group
*/
public Shape getShape()
{
- if (cachedShape == null) calcShape();
+ if (cachedShape == null)
+ {
+ calcShape();
+ }
return cachedShape;
}
@@ -235,11 +224,11 @@ public class Group extends ShapeElement
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof ShapeElement)
{
- ShapeElement shpEle = (ShapeElement)ele;
+ ShapeElement shpEle = (ShapeElement) ele;
Shape shape = shpEle.getShape();
if (shape != null)
{
@@ -256,14 +245,17 @@ public class Group extends ShapeElement
*/
public Rectangle2D getBoundingBox() throws SVGException
{
- if (boundingBox == null) calcBoundingBox();
+ if (boundingBox == null)
+ {
+ calcBoundingBox();
+ }
// calcBoundingBox();
return boundingBox;
}
/**
* Recalculates the bounding box by taking the union of the bounding boxes
- * of all children. Caches the result.
+ * of all children. Caches the result.
*/
public void calcBoundingBox() throws SVGException
{
@@ -272,16 +264,21 @@ public class Group extends ShapeElement
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
- RenderableElement rendEle = (RenderableElement)ele;
+ RenderableElement rendEle = (RenderableElement) ele;
Rectangle2D bounds = rendEle.getBoundingBox();
if (bounds != null)
{
- if (retRect == null) retRect = bounds;
- else retRect = retRect.createUnion(bounds);
+ if (retRect == null)
+ {
+ retRect = bounds;
+ } else
+ {
+ retRect = retRect.createUnion(bounds);
+ }
}
}
}
@@ -292,7 +289,10 @@ public class Group extends ShapeElement
// }
//If no contents, use degenerate rectangle
- if (retRect == null) retRect = new Rectangle2D.Float();
+ if (retRect == null)
+ {
+ retRect = new Rectangle2D.Float();
+ }
boundingBox = boundsToParent(retRect);
}
@@ -305,14 +305,20 @@ public class Group extends ShapeElement
//Distribute message to all members of this group
while (it.hasNext())
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
boolean updateVal = ele.updateTime(curTime);
changeState = changeState || updateVal;
//Update our shape if shape aware children change
- if (ele instanceof ShapeElement) cachedShape = null;
- if (ele instanceof RenderableElement) boundingBox = null;
+ if (ele instanceof ShapeElement)
+ {
+ cachedShape = null;
+ }
+ if (ele instanceof RenderableElement)
+ {
+ boundingBox = null;
+ }
}
return changeState;
diff --git a/src/main/java/com/kitfox/svg/Hkern.java b/src/main/java/com/kitfox/svg/Hkern.java
index b88ddbe..0333e22 100644
--- a/src/main/java/com/kitfox/svg/Hkern.java
+++ b/src/main/java/com/kitfox/svg/Hkern.java
@@ -33,7 +33,6 @@
*
* Created on February 20, 2004, 10:00 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
@@ -44,10 +43,16 @@ import com.kitfox.svg.xml.StyleAttribute;
*/
public class Hkern extends SVGElement
{
+
+ public static final String TAG_NAME = "hkern";
String u1;
String u2;
int k;
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
protected void build() throws SVGException
{
@@ -57,11 +62,20 @@ public class Hkern extends SVGElement
//Read glyph spacing info
- if (getPres(sty.setName("u1"))) u1 = sty.getStringValue();
+ if (getPres(sty.setName("u1")))
+ {
+ u1 = sty.getStringValue();
+ }
- if (getPres(sty.setName("u2"))) u2 = sty.getStringValue();
+ if (getPres(sty.setName("u2")))
+ {
+ u2 = sty.getStringValue();
+ }
- if (getPres(sty.setName("k"))) k = sty.getIntValue();
+ if (getPres(sty.setName("k")))
+ {
+ k = sty.getIntValue();
+ }
}
public boolean updateTime(double curTime) throws SVGException
@@ -69,6 +83,4 @@ public class Hkern extends SVGElement
//Fonts can't change
return false;
}
-
-
}
diff --git a/src/main/java/com/kitfox/svg/ImageSVG.java b/src/main/java/com/kitfox/svg/ImageSVG.java
index 5ac93d3..5b4c66f 100644
--- a/src/main/java/com/kitfox/svg/ImageSVG.java
+++ b/src/main/java/com/kitfox/svg/ImageSVG.java
@@ -33,16 +33,19 @@
*
* Created on February 20, 2004, 10:00 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.app.data.Handler;
-import com.kitfox.svg.xml.*;
-
-import java.awt.*;
-import java.awt.geom.*;
-import java.awt.image.*;
-import java.net.*;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.AlphaComposite;
+import java.awt.Composite;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.net.URI;
+import java.net.URL;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -55,66 +58,84 @@ import java.util.logging.Logger;
*/
public class ImageSVG extends RenderableElement
{
+ public static final String TAG_NAME = "image";
+
float x = 0f;
float y = 0f;
float width = 0f;
float height = 0f;
-
// BufferedImage href = null;
URL imageSrc = null;
-
AffineTransform xform;
Rectangle2D bounds;
- /** Creates a new instance of Font */
+ /**
+ * Creates a new instance of Font
+ */
public ImageSVG()
{
}
-
+
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("x")))
+ {
+ x = sty.getFloatValueWithUnits();
+ }
- if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("y")))
+ {
+ y = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("width")))
+ {
+ width = sty.getFloatValueWithUnits();
+ }
- if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("height")))
+ {
+ height = sty.getFloatValueWithUnits();
+ }
- try {
+ try
+ {
if (getPres(sty.setName("xlink:href")))
{
URI src = sty.getURIValue(getXMLBase());
if ("data".equals(src.getScheme()))
{
imageSrc = new URL(null, src.toASCIIString(), new Handler());
- }
- else
+ } else
{
- try {
+ try
+ {
imageSrc = src.toURL();
- }
- catch (Exception e)
+ } catch (Exception e)
{
- Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+ Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
"Could not parse xlink:href", e);
// e.printStackTrace();
imageSrc = null;
}
}
}
- }
- catch (Exception e)
+ } catch (Exception e)
{
throw new SVGException(e);
}
diagram.getUniverse().registerImage(imageSrc);
-
+
//Set widths if not set
BufferedImage img = diagram.getUniverse().getImage(imageSrc);
if (img == null)
@@ -123,26 +144,45 @@ public class ImageSVG extends RenderableElement
bounds = new Rectangle2D.Float();
return;
}
-
- if (width == 0) width = img.getWidth();
- if (height == 0) height = img.getHeight();
-
+
+ if (width == 0)
+ {
+ width = img.getWidth();
+ }
+ if (height == 0)
+ {
+ height = img.getHeight();
+ }
+
//Determine image xform
xform = new AffineTransform();
// xform.setToScale(this.width / img.getWidth(), this.height / img.getHeight());
// xform.translate(this.x, this.y);
xform.translate(this.x, this.y);
xform.scale(this.width / img.getWidth(), this.height / img.getHeight());
-
+
bounds = new Rectangle2D.Float(this.x, this.y, this.width, this.height);
}
-
-
-
- public float getX() { return x; }
- public float getY() { return y; }
- public float getWidth() { return width; }
- public float getHeight() { return height; }
+
+ public float getX()
+ {
+ return x;
+ }
+
+ public float getY()
+ {
+ return y;
+ }
+
+ public float getWidth()
+ {
+ return width;
+ }
+
+ public float getHeight()
+ {
+ return height;
+ }
void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException
{
@@ -165,50 +205,63 @@ public class ImageSVG extends RenderableElement
StyleAttribute styleAttrib = new StyleAttribute();
if (getStyle(styleAttrib.setName("visibility")))
{
- if (!styleAttrib.getStringValue().equals("visible")) return;
+ if (!styleAttrib.getStringValue().equals("visible"))
+ {
+ return;
+ }
}
-
+
beginLayer(g);
-
+
float opacity = 1f;
if (getStyle(styleAttrib.setName("opacity")))
{
opacity = styleAttrib.getRatioValue();
}
-
- if (opacity <= 0) return;
+
+ if (opacity <= 0)
+ {
+ return;
+ }
Composite oldComp = null;
-
+
if (opacity < 1)
{
oldComp = g.getComposite();
Composite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
g.setComposite(comp);
}
-
+
BufferedImage img = diagram.getUniverse().getImage(imageSrc);
- if (img == null) return;
-
+ if (img == null)
+ {
+ return;
+ }
+
AffineTransform curXform = g.getTransform();
g.transform(xform);
-
+
g.drawImage(img, 0, 0, null);
-
+
g.setTransform(curXform);
- if (oldComp != null) g.setComposite(oldComp);
-
+ if (oldComp != null)
+ {
+ g.setComposite(oldComp);
+ }
+
finishLayer(g);
}
-
+
public Rectangle2D getBoundingBox()
{
return boundsToParent(bounds);
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -220,7 +273,7 @@ public class ImageSVG extends RenderableElement
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("x")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -230,7 +283,7 @@ public class ImageSVG extends RenderableElement
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("y")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -240,7 +293,7 @@ public class ImageSVG extends RenderableElement
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("width")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -250,7 +303,7 @@ public class ImageSVG extends RenderableElement
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("height")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -260,8 +313,9 @@ public class ImageSVG extends RenderableElement
shapeChange = true;
}
}
-
- try {
+
+ try
+ {
if (getPres(sty.setName("xlink:href")))
{
URI src = sty.getURIValue(getXMLBase());
@@ -270,32 +324,29 @@ public class ImageSVG extends RenderableElement
if ("data".equals(src.getScheme()))
{
newVal = new URL(null, src.toASCIIString(), new Handler());
- }
- else
+ } else
{
newVal = src.toURL();
}
-
+
if (!newVal.equals(imageSrc))
{
imageSrc = newVal;
shapeChange = true;
}
}
- }
- catch (IllegalArgumentException ie)
+ } catch (IllegalArgumentException ie)
{
- Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
- "Image provided with illegal value for href: \""
+ Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+ "Image provided with illegal value for href: \""
+ sty.getStringValue() + '"', ie);
- }
- catch (Exception e)
+ } catch (Exception e)
{
- Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+ Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
"Could not parse xlink:href", e);
}
-
+
if (shapeChange)
{
build();
@@ -325,7 +376,7 @@ public class ImageSVG extends RenderableElement
//
// return true;
}
-
+
return changeState || shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/Line.java b/src/main/java/com/kitfox/svg/Line.java
index c01e7a7..84486c9 100644
--- a/src/main/java/com/kitfox/svg/Line.java
+++ b/src/main/java/com/kitfox/svg/Line.java
@@ -33,7 +33,6 @@
*
* Created on January 26, 2004, 5:25 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
@@ -46,56 +45,56 @@ import java.awt.geom.Rectangle2D;
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Line extends ShapeElement {
-
+public class Line extends ShapeElement
+{
+ public static final String TAG_NAME = "line";
+
float x1 = 0f;
float y1 = 0f;
float x2 = 0f;
float y2 = 0f;
-
Line2D.Float line;
-// RectangularShape rect;
- /** Creates a new instance of Rect */
- public Line() {
+ /**
+ * Creates a new instance of Rect
+ */
+ public Line()
+ {
}
- /*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ public String getTagName()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String x1 = attrs.getValue("x1");
- String y1 = attrs.getValue("y1");
- String x2 = attrs.getValue("x2");
- String y2 = attrs.getValue("y2");
-
- this.x1 = XMLParseUtil.parseFloat(x1);
- this.y1 = XMLParseUtil.parseFloat(y1);
- this.x2 = XMLParseUtil.parseFloat(x2);
- this.y2 = XMLParseUtil.parseFloat(y2);
-
- build();
+ return TAG_NAME;
}
-*/
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("x1"))) x1 = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("y1"))) y1 = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("x1")))
+ {
+ x1 = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("y1")))
+ {
+ y1 = sty.getFloatValueWithUnits();
+ }
- if (getPres(sty.setName("x2"))) x2 = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("x2")))
+ {
+ x2 = sty.getFloatValueWithUnits();
+ }
- if (getPres(sty.setName("y2"))) y2 = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("y2")))
+ {
+ y2 = sty.getFloatValueWithUnits();
+ }
line = new Line2D.Float(x1, y1, x2, y2);
}
-
public void render(Graphics2D g) throws SVGException
{
@@ -115,8 +114,9 @@ public class Line extends ShapeElement {
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -128,7 +128,7 @@ public class Line extends ShapeElement {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("x1")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -172,10 +172,8 @@ public class Line extends ShapeElement {
if (shapeChange)
{
build();
-// line = new Line2D.Float(x1, y1, x2, y2);
-// return true;
}
-
+
return changeState || shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/LinearGradient.java b/src/main/java/com/kitfox/svg/LinearGradient.java
index 969bec0..ffe5fa1 100644
--- a/src/main/java/com/kitfox/svg/LinearGradient.java
+++ b/src/main/java/com/kitfox/svg/LinearGradient.java
@@ -33,72 +33,67 @@
*
* Created on January 26, 2004, 1:54 AM
*/
-
package com.kitfox.svg;
-import java.awt.geom.*;
-import java.awt.*;
-
-import com.kitfox.svg.xml.*;
-
-//import org.apache.batik.ext.awt.*;
-
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.Color;
+import java.awt.Paint;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class LinearGradient extends Gradient {
-
+public class LinearGradient extends Gradient
+{
+ public static final String TAG_NAME = "lineargradient";
+
float x1 = 0f;
float y1 = 0f;
float x2 = 1f;
float y2 = 0f;
- /** Creates a new instance of LinearGradient */
- public LinearGradient() {
- }
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ /**
+ * Creates a new instance of LinearGradient
+ */
+ public LinearGradient()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String x1 = attrs.getValue("x1");
- String x2 = attrs.getValue("x2");
- String y1 = attrs.getValue("y1");
- String y2 = attrs.getValue("y2");
-
- if (x1 != null) this.x1 = (float)XMLParseUtil.parseRatio(x1);
- if (y1 != null) this.y1 = (float)XMLParseUtil.parseRatio(y1);
- if (x2 != null) this.x2 = (float)XMLParseUtil.parseRatio(x2);
- if (y2 != null) this.y2 = (float)XMLParseUtil.parseRatio(y2);
}
-*/
- /*
- public void loaderEndElement(SVGLoaderHelper helper)
+
+ public String getTagName()
{
- super.loaderEndElement(helper);
-
- build();
+ return TAG_NAME;
}
- */
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("x1"))) x1 = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("y1"))) y1 = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("x2"))) x2 = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("y2"))) y2 = sty.getFloatValueWithUnits();
+
+ if (getPres(sty.setName("x1")))
+ {
+ x1 = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("y1")))
+ {
+ y1 = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("x2")))
+ {
+ x2 = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("y2")))
+ {
+ y2 = sty.getFloatValueWithUnits();
+ }
}
-
+
public Paint getPaint(Rectangle2D bounds, AffineTransform xform)
{
com.kitfox.svg.batik.MultipleGradientPaint.CycleMethodEnum method;
@@ -123,8 +118,7 @@ public class LinearGradient extends Gradient {
{
Color[] colors = getStopColors();
paint = colors.length > 0 ? colors[0] : Color.black;
- }
- else if (gradientUnits == GU_USER_SPACE_ON_USE)
+ } else if (gradientUnits == GU_USER_SPACE_ON_USE)
{
paint = new com.kitfox.svg.batik.LinearGradientPaint(
pt1,
@@ -133,15 +127,14 @@ public class LinearGradient extends Gradient {
getStopColors(),
method,
com.kitfox.svg.batik.MultipleGradientPaint.SRGB,
- gradientTransform == null
- ? new AffineTransform()
- : gradientTransform);
- }
- else
+ gradientTransform == null
+ ? new AffineTransform()
+ : gradientTransform);
+ } else
{
AffineTransform viewXform = new AffineTransform();
viewXform.translate(bounds.getX(), bounds.getY());
-
+
//This is a hack to get around shapes that have a width or height of 0. Should be close enough to the true answer.
double width = Math.max(1, bounds.getWidth());
double height = Math.max(1, bounds.getHeight());
@@ -164,10 +157,11 @@ public class LinearGradient extends Gradient {
return paint;
}
-
+
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -179,7 +173,7 @@ public class LinearGradient extends Gradient {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("x1")))
{
float newVal = sty.getFloatValueWithUnits();
diff --git a/src/main/java/com/kitfox/svg/Marker.java b/src/main/java/com/kitfox/svg/Marker.java
index 1c1755c..f195c07 100644
--- a/src/main/java/com/kitfox/svg/Marker.java
+++ b/src/main/java/com/kitfox/svg/Marker.java
@@ -31,7 +31,6 @@
* Mark McKay can be contacted at mark@kitfox.com. Salamander and other
* projects can be found at http://www.kitfox.com
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
@@ -49,10 +48,11 @@ import java.util.ArrayList;
*/
public class Marker extends Group
{
+ public static final String TAG_NAME = "marker";
+
AffineTransform viewXform;
AffineTransform markerXform;
Rectangle2D viewBox;
-
float refX;
float refY;
float markerWidth = 3;
@@ -60,24 +60,40 @@ public class Marker extends Group
float orient = Float.NaN;
boolean markerUnitsStrokeWidth = true; //if set to false 'userSpaceOnUse' is assumed
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
+
protected void build() throws SVGException
{
super.build();
StyleAttribute sty = new StyleAttribute();
- if (getPres(sty.setName("refX"))) refX = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("refY"))) refY = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("markerWidth"))) markerWidth = sty.getFloatValueWithUnits();
- if (getPres(sty.setName("markerHeight"))) markerHeight = sty.getFloatValueWithUnits();
+ if (getPres(sty.setName("refX")))
+ {
+ refX = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("refY")))
+ {
+ refY = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("markerWidth")))
+ {
+ markerWidth = sty.getFloatValueWithUnits();
+ }
+ if (getPres(sty.setName("markerHeight")))
+ {
+ markerHeight = sty.getFloatValueWithUnits();
+ }
if (getPres(sty.setName("orient")))
{
if ("auto".equals(sty.getStringValue()))
{
orient = Float.NaN;
- }
- else
+ } else
{
orient = sty.getFloatValue();
}
@@ -169,8 +185,9 @@ public class Marker extends Group
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -181,7 +198,7 @@ public class Marker extends Group
//Marker properties do not change
return changeState;
}
-
+
//--------------------------------
public static final int MARKER_START = 0;
public static final int MARKER_MID = 1;
@@ -189,6 +206,7 @@ public class Marker extends Group
public static class MarkerPos
{
+
int type;
double x;
double y;
@@ -207,6 +225,7 @@ public class Marker extends Group
public static class MarkerLayout
{
+
private ArrayList markerList = new ArrayList();
boolean started = false;
@@ -216,7 +235,7 @@ public class Marker extends Group
double py = 0;
double[] coords = new double[6];
for (PathIterator it = shape.getPathIterator(null);
- !it.isDone(); it.next())
+ !it.isDone(); it.next())
{
switch (it.currentSegment(coords))
{
@@ -244,28 +263,26 @@ public class Marker extends Group
double k0y = coords[1];
double x = coords[2];
double y = coords[3];
-
-
+
+
//Best in tangent
if (px != k0x || py != k0y)
{
markerIn(px, py, k0x - px, k0y - py);
- }
- else
+ } else
{
markerIn(px, py, x - px, y - py);
}
-
+
//Best out tangent
if (x != k0x || y != k0y)
{
markerOut(x, y, x - k0x, y - k0y);
- }
- else
+ } else
{
markerOut(x, y, x - px, y - py);
}
-
+
markerIn(px, py, k0x - px, k0y - py);
markerOut(x, y, x - k0x, y - k0y);
px = x;
@@ -280,31 +297,27 @@ public class Marker extends Group
double k1y = coords[3];
double x = coords[4];
double y = coords[5];
-
+
//Best in tangent
if (px != k0x || py != k0y)
{
markerIn(px, py, k0x - px, k0y - py);
- }
- else if (px != k1x || py != k1y)
+ } else if (px != k1x || py != k1y)
{
markerIn(px, py, k1x - px, k1y - py);
- }
- else
+ } else
{
markerIn(px, py, x - px, y - py);
}
-
+
//Best out tangent
if (x != k1x || y != k1y)
{
markerOut(x, y, x - k1x, y - k1y);
- }
- else if (x != k0x || y != k0y)
+ } else if (x != k0x || y != k0y)
{
markerOut(x, y, x - k0x, y - k0y);
- }
- else
+ } else
{
markerOut(x, y, x - px, y - py);
}
@@ -317,15 +330,15 @@ public class Marker extends Group
for (int i = 1; i < markerList.size(); ++i)
{
- MarkerPos prev = (MarkerPos)markerList.get(i - 1);
- MarkerPos cur = (MarkerPos)markerList.get(i);
+ MarkerPos prev = (MarkerPos) markerList.get(i - 1);
+ MarkerPos cur = (MarkerPos) markerList.get(i);
if (cur.type == MARKER_START)
{
prev.type = MARKER_END;
}
}
- MarkerPos last = (MarkerPos)markerList.get(markerList.size() - 1);
+ MarkerPos last = (MarkerPos) markerList.get(markerList.size() - 1);
last.type = MARKER_END;
}
diff --git a/src/main/java/com/kitfox/svg/Metadata.java b/src/main/java/com/kitfox/svg/Metadata.java
index ea1962d..9f2fe4e 100644
--- a/src/main/java/com/kitfox/svg/Metadata.java
+++ b/src/main/java/com/kitfox/svg/Metadata.java
@@ -33,19 +33,28 @@
*
* Created on September 19, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
/**
- * Does not hold any information. Included to allow metadata tag to be parsed.
+ * Does not hold any information. Included to allow metadata tag to be parsed.
*
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Metadata extends SVGElement
+public class Metadata extends SVGElement
{
- /** Creates a new instance of Stop */
- public Metadata() {
+ public static final String TAG_NAME = "metadata";
+
+ /**
+ * Creates a new instance of Stop
+ */
+ public Metadata()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
public boolean updateTime(double curTime)
diff --git a/src/main/java/com/kitfox/svg/MissingGlyph.java b/src/main/java/com/kitfox/svg/MissingGlyph.java
index e11fd0a..cf041b5 100644
--- a/src/main/java/com/kitfox/svg/MissingGlyph.java
+++ b/src/main/java/com/kitfox/svg/MissingGlyph.java
@@ -33,17 +33,17 @@
*
* Created on February 20, 2004, 10:00 PM
*/
-
package com.kitfox.svg;
-import com.kitfox.svg.xml.*;
-
-import java.awt.*;
-import java.awt.geom.*;
-import java.util.*;
-
-import com.kitfox.svg.pathcmd.*;
-//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import com.kitfox.svg.pathcmd.BuildHistory;
+import com.kitfox.svg.pathcmd.PathCommand;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
+import java.util.Iterator;
/**
* Implements an embedded font.
@@ -55,69 +55,28 @@ import com.kitfox.svg.pathcmd.*;
*/
public class MissingGlyph extends ShapeElement
{
+ public static final String TAG_NAME = "missingglyph";
+
//We may define a path
-// ExtendedGeneralPath path = null;
Shape path = null;
-
//Alternately, we may have child graphical elements
-
int horizAdvX = -1; //Inherits font's value if not set
int vertOriginX = -1; //Inherits font's value if not set
int vertOriginY = -1; //Inherits font's value if not set
int vertAdvY = -1; //Inherits font's value if not set
- /** Creates a new instance of Font */
+ /**
+ * Creates a new instance of Font
+ */
public MissingGlyph()
{
}
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- //If glyph path was specified, calculate it
- String commandList = attrs.getValue("d");
- if (commandList != null)
- {
- StyleAttribute atyleAttrib = getStyle("fill-rule");
- String fillRule = (atyleAttrib == null) ? "nonzero" : atyleAttrib.getStringValue();
-
- PathCommand[] commands = parsePathList(commandList);
-
-// ExtendedGeneralPath buildPath = new ExtendedGeneralPath(
- GeneralPath buildPath = new GeneralPath(
- fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO,
- commands.length);
-
- BuildHistory hist = new BuildHistory();
-
- for (int i = 0; i < commands.length; i++)
- {
- PathCommand cmd = commands[i];
- cmd.appendPath(buildPath, hist);
- }
-
- //Reflect glyph path to put it in user coordinate system
- AffineTransform at = new AffineTransform();
- at.scale(1, -1);
- path = at.createTransformedShape(buildPath);
- }
-
-
- //Read glyph spacing info
- String horizAdvX = attrs.getValue("horiz-adv-x");
- String vertOriginX = attrs.getValue("vert-origin-x");
- String vertOriginY = attrs.getValue("vert-origin-y");
- String vertAdvY = attrs.getValue("vert-adv-y");
-
- if (horizAdvX != null) this.horizAdvX = XMLParseUtil.parseInt(horizAdvX);
- if (vertOriginX != null) this.vertOriginX = XMLParseUtil.parseInt(vertOriginX);
- if (vertOriginY != null) this.vertOriginY = XMLParseUtil.parseInt(vertOriginY);
- if (vertAdvY != null) this.vertAdvY = XMLParseUtil.parseInt(vertAdvY);
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-*/
+
/**
* Called after the start element but before the end element to indicate
* each child tag that has been processed
@@ -127,26 +86,26 @@ public class MissingGlyph extends ShapeElement
super.loaderAddChild(helper, child);
}
-
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
+
String commandList = "";
- if (getPres(sty.setName("d"))) commandList = sty.getStringValue();
+ if (getPres(sty.setName("d")))
+ {
+ commandList = sty.getStringValue();
+ }
+
-
//If glyph path was specified, calculate it
if (commandList != null)
{
-// StyleAttribute atyleAttrib = getStyle("fill-rule");
String fillRule = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero";
PathCommand[] commands = parsePathList(commandList);
-// ExtendedGeneralPath buildPath = new ExtendedGeneralPath(
GeneralPath buildPath = new GeneralPath(
fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO,
commands.length);
@@ -167,13 +126,25 @@ public class MissingGlyph extends ShapeElement
//Read glyph spacing info
- if (getPres(sty.setName("horiz-adv-x"))) horizAdvX = sty.getIntValue();
+ if (getPres(sty.setName("horiz-adv-x")))
+ {
+ horizAdvX = sty.getIntValue();
+ }
- if (getPres(sty.setName("vert-origin-x"))) vertOriginX = sty.getIntValue();
+ if (getPres(sty.setName("vert-origin-x")))
+ {
+ vertOriginX = sty.getIntValue();
+ }
- if (getPres(sty.setName("vert-origin-y"))) vertOriginY = sty.getIntValue();
+ if (getPres(sty.setName("vert-origin-y")))
+ {
+ vertOriginY = sty.getIntValue();
+ }
- if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue();
+ if (getPres(sty.setName("vert-adv-y")))
+ {
+ vertAdvY = sty.getIntValue();
+ }
}
public Shape getPath()
@@ -185,15 +156,18 @@ public class MissingGlyph extends ShapeElement
{
//Do not push or pop stack
- if (path != null) renderShape(g, path);
-
+ if (path != null)
+ {
+ renderShape(g, path);
+ }
+
Iterator it = children.iterator();
while (it.hasNext())
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
- ((RenderableElement)ele).render(g);
+ ((RenderableElement) ele).render(g);
}
}
@@ -203,47 +177,62 @@ public class MissingGlyph extends ShapeElement
public int getHorizAdvX()
{
if (horizAdvX == -1)
- horizAdvX = ((Font)parent).getHorizAdvX();
+ {
+ horizAdvX = ((Font) parent).getHorizAdvX();
+ }
return horizAdvX;
}
public int getVertOriginX()
{
if (vertOriginX == -1)
+ {
vertOriginX = getHorizAdvX() / 2;
+ }
return vertOriginX;
}
public int getVertOriginY()
{
if (vertOriginY == -1)
- vertOriginY = ((Font)parent).getFontFace().getAscent();
+ {
+ vertOriginY = ((Font) parent).getFontFace().getAscent();
+ }
return vertOriginY;
}
public int getVertAdvY()
{
if (vertAdvY == -1)
- vertAdvY = ((Font)parent).getFontFace().getUnitsPerEm();
+ {
+ vertAdvY = ((Font) parent).getFontFace().getUnitsPerEm();
+ }
return vertAdvY;
}
public Shape getShape()
{
- if (path != null) return shapeToParent(path);
+ if (path != null)
+ {
+ return shapeToParent(path);
+ }
return null;
}
public Rectangle2D getBoundingBox() throws SVGException
{
- if (path != null) return boundsToParent(includeStrokeInBounds(path.getBounds2D()));
+ if (path != null)
+ {
+ return boundsToParent(includeStrokeInBounds(path.getBounds2D()));
+ }
return null;
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
diff --git a/src/main/java/com/kitfox/svg/Path.java b/src/main/java/com/kitfox/svg/Path.java
index c4c0b0d..7d8db66 100644
--- a/src/main/java/com/kitfox/svg/Path.java
+++ b/src/main/java/com/kitfox/svg/Path.java
@@ -33,70 +33,59 @@
*
* Created on January 26, 2004, 5:25 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.*;
-import java.awt.geom.*;
-
-import com.kitfox.svg.pathcmd.*;
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
-
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Path extends ShapeElement {
+public class Path extends ShapeElement
+{
+ public static final String TAG_NAME = "path";
// PathCommand[] commands = null;
-
int fillRule = GeneralPath.WIND_NON_ZERO;
String d = "";
// ExtendedGeneralPath path;
GeneralPath path;
- /** Creates a new instance of Rect */
- public Path() {
+ /**
+ * Creates a new instance of Rect
+ */
+ public Path()
+ {
}
- /*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ public String getTagName()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- StyleAttribute styleAttrib = getStyle("fill-rule");
- String fillRule = (styleAttrib == null) ? "nonzero" : styleAttrib.getStringValue();
-
- String d = attrs.getValue("d");
- path = buildPath(d, fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO);
+ return TAG_NAME;
}
- */
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
-
- String fillRuleStrn = (getStyle(sty.setName("fill-rule"))) ? sty.getStringValue() : "nonzero";
+
+
+ String fillRuleStrn = (getStyle(sty.setName("fill-rule"))) ? sty.getStringValue() : "nonzero";
fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO;
-
-// String d = "";
- if (getPres(sty.setName("d"))) d = sty.getStringValue();
-//System.err.println(d);
-
+ if (getPres(sty.setName("d")))
+ {
+ d = sty.getStringValue();
+ }
+
path = buildPath(d, fillRule);
-
-//System.err.println(d);
}
-
+
public void render(Graphics2D g) throws SVGException
{
beginLayer(g);
@@ -115,8 +104,9 @@ public class Path extends ShapeElement {
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -128,11 +118,11 @@ public class Path extends ShapeElement {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getStyle(sty.setName("fill-rule")))
{
- int newVal = sty.getStringValue().equals("evenodd")
- ? GeneralPath.WIND_EVEN_ODD
+ int newVal = sty.getStringValue().equals("evenodd")
+ ? GeneralPath.WIND_EVEN_ODD
: GeneralPath.WIND_NON_ZERO;
if (newVal != fillRule)
{
@@ -140,7 +130,7 @@ public class Path extends ShapeElement {
changeState = true;
}
}
-
+
if (getPres(sty.setName("d")))
{
String newVal = sty.getStringValue();
@@ -150,14 +140,14 @@ public class Path extends ShapeElement {
shapeChange = true;
}
}
-
+
if (shapeChange)
{
build();
// path = buildPath(d, fillRule);
// return true;
}
-
+
return changeState || shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/PatternSVG.java b/src/main/java/com/kitfox/svg/PatternSVG.java
index c413f5b..4e3da4f 100644
--- a/src/main/java/com/kitfox/svg/PatternSVG.java
+++ b/src/main/java/com/kitfox/svg/PatternSVG.java
@@ -33,7 +33,6 @@
*
* Created on January 26, 2004, 3:25 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.pattern.PatternPaint;
@@ -51,30 +50,35 @@ import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
-
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class PatternSVG extends FillElement {
-
+public class PatternSVG extends FillElement
+{
+ public static final String TAG_NAME = "pattern";
+
public static final int GU_OBJECT_BOUNDING_BOX = 0;
public static final int GU_USER_SPACE_ON_USE = 1;
-
int gradientUnits = GU_OBJECT_BOUNDING_BOX;
-
float x;
float y;
float width;
float height;
-
AffineTransform patternXform = new AffineTransform();
Rectangle2D.Float viewBox;
-
Paint texPaint;
- /** Creates a new instance of Gradient */
- public PatternSVG() {
+ /**
+ * Creates a new instance of Gradient
+ */
+ public PatternSVG()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
/**
@@ -84,27 +88,29 @@ public class PatternSVG extends FillElement {
public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
{
super.loaderAddChild(helper, child);
-
-// members.add(child);
}
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- //Load style string
+
+ //Load style string
String href = null;
- if (getPres(sty.setName("xlink:href"))) href = sty.getStringValue();
+ if (getPres(sty.setName("xlink:href")))
+ {
+ href = sty.getStringValue();
+ }
//String href = attrs.getValue("xlink:href");
//If we have a link to another pattern, initialize ourselves with it's values
if (href != null)
{
//System.err.println("Gradient.loaderStartElement() href '" + href + "'");
- try {
+ try
+ {
URI src = getXMLBase().resolve(href);
- PatternSVG patSrc = (PatternSVG)diagram.getUniverse().getElement(src);
+ PatternSVG patSrc = (PatternSVG) diagram.getUniverse().getElement(src);
gradientUnits = patSrc.gradientUnits;
x = patSrc.x;
@@ -114,61 +120,82 @@ public class PatternSVG extends FillElement {
viewBox = patSrc.viewBox;
patternXform.setTransform(patSrc.patternXform);
children.addAll(patSrc.children);
- }
- catch (Exception e)
+ } catch (Exception e)
{
- Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+ Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
"Could not parse xlink:href", e);
}
}
String gradientUnits = "";
- if (getPres(sty.setName("gradientUnits"))) gradientUnits = sty.getStringValue().toLowerCase();
- if (gradientUnits.equals("userspaceonuse")) this.gradientUnits = GU_USER_SPACE_ON_USE;
- else this.gradientUnits = GU_OBJECT_BOUNDING_BOX;
+ if (getPres(sty.setName("gradientUnits")))
+ {
+ gradientUnits = sty.getStringValue().toLowerCase();
+ }
+ if (gradientUnits.equals("userspaceonuse"))
+ {
+ this.gradientUnits = GU_USER_SPACE_ON_USE;
+ } else
+ {
+ this.gradientUnits = GU_OBJECT_BOUNDING_BOX;
+ }
String patternTransform = "";
- if (getPres(sty.setName("patternTransform"))) patternTransform = sty.getStringValue();
+ if (getPres(sty.setName("patternTransform")))
+ {
+ patternTransform = sty.getStringValue();
+ }
patternXform = parseTransform(patternTransform);
-
- if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
-
+
+ if (getPres(sty.setName("x")))
+ {
+ x = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("y")))
+ {
+ y = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("width")))
+ {
+ width = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("height")))
+ {
+ height = sty.getFloatValueWithUnits();
+ }
+
if (getPres(sty.setName("viewBox")))
{
float[] dim = sty.getFloatList();
viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
}
-
+
preparePattern();
}
-
-/*
- public void loaderEndElement(SVGLoaderHelper helper)
- {
- build();
- }
- */
+ /*
+ public void loaderEndElement(SVGLoaderHelper helper)
+ {
+ build();
+ }
+ */
protected void preparePattern() throws SVGException
{
//For now, treat all fills as UserSpaceOnUse. Otherwise, we'll need
// a different paint for every object.
- int tileWidth = (int)width;
- int tileHeight = (int)height;
+ int tileWidth = (int) width;
+ int tileHeight = (int) height;
float stretchX = 1f, stretchY = 1f;
if (!patternXform.isIdentity())
{
//Scale our source tile so that we can have nice sampling from it.
- float xlateX = (float)patternXform.getTranslateX();
- float xlateY = (float)patternXform.getTranslateY();
+ float xlateX = (float) patternXform.getTranslateX();
+ float xlateY = (float) patternXform.getTranslateY();
Point2D.Float pt = new Point2D.Float(), pt2 = new Point2D.Float();
@@ -176,24 +203,24 @@ public class PatternSVG extends FillElement {
patternXform.transform(pt, pt2);
pt2.x -= xlateX;
pt2.y -= xlateY;
- stretchX = (float)Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / width;
+ stretchX = (float) Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / width;
pt.setLocation(height, 0);
patternXform.transform(pt, pt2);
pt2.x -= xlateX;
pt2.y -= xlateY;
- stretchY = (float)Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / height;
+ stretchY = (float) Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / height;
tileWidth *= stretchX;
tileHeight *= stretchY;
}
- if (tileWidth == 0 || tileHeight == 0)
+ if (tileWidth == 0 || tileHeight == 0)
{
//Use defaults if tile has degenerate size
return;
}
-
+
BufferedImage buf = new BufferedImage(tileWidth, tileHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = buf.createGraphics();
g.setClip(0, 0, tileWidth, tileHeight);
@@ -201,7 +228,7 @@ public class PatternSVG extends FillElement {
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
AffineTransform xform = new AffineTransform();
@@ -209,15 +236,14 @@ public class PatternSVG extends FillElement {
if (viewBox == null)
{
xform.translate(-x, -y);
- }
- else
+ } else
{
xform.scale(tileWidth / viewBox.width, tileHeight / viewBox.height);
xform.translate(-viewBox.x, -viewBox.y);
}
g.setTransform(xform);
- ((RenderableElement)ele).render(g);
+ ((RenderableElement) ele).render(g);
}
}
@@ -230,8 +256,7 @@ public class PatternSVG extends FillElement {
if (patternXform.isIdentity())
{
texPaint = new TexturePaint(buf, new Rectangle2D.Float(x, y, width, height));
- }
- else
+ } else
{
patternXform.scale(1 / stretchX, 1 / stretchY);
texPaint = new PatternPaint(buf, patternXform);
@@ -244,8 +269,9 @@ public class PatternSVG extends FillElement {
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
diff --git a/src/main/java/com/kitfox/svg/Polygon.java b/src/main/java/com/kitfox/svg/Polygon.java
index a3a5888..58ec1cc 100644
--- a/src/main/java/com/kitfox/svg/Polygon.java
+++ b/src/main/java/com/kitfox/svg/Polygon.java
@@ -33,78 +33,56 @@
*
* Created on January 26, 2004, 5:25 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
import com.kitfox.svg.xml.XMLParseUtil;
-import java.awt.geom.*;
-import java.awt.*;
-
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Polygon extends ShapeElement {
+public class Polygon extends ShapeElement
+{
+ public static final String TAG_NAME = "polygon";
int fillRule = GeneralPath.WIND_NON_ZERO;
String pointsStrn = "";
-// float[] points = null;
GeneralPath path;
- /** Creates a new instance of Rect */
- public Polygon() {
- }
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ /**
+ * Creates a new instance of Rect
+ */
+ public Polygon()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
-
- points = XMLParseUtil.parseFloatList(attrs.getValue("points"));
-
- build();
}
-*/
-/*
- public void build()
- {
- StyleAttribute styleAttrib = getStyle("fill-rule");
- String fillRule = (styleAttrib == null) ? "nonzero" : styleAttrib.getStringValue();
-
- path = new GeneralPath(
- fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO,
- points.length / 2);
- path.moveTo(points[0], points[1]);
- for (int i = 2; i < points.length; i += 2)
- {
- path.lineTo(points[i], points[i + 1]);
- }
- path.closePath();
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-*/
-
-//static int yyyyy = 0;
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("points"))) pointsStrn = sty.getStringValue();
-
+
+ if (getPres(sty.setName("points")))
+ {
+ pointsStrn = sty.getStringValue();
+ }
+
String fillRuleStrn = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero";
fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO;
buildPath();
}
-
+
protected void buildPath()
{
float[] points = XMLParseUtil.parseFloatList(pointsStrn);
@@ -117,7 +95,7 @@ public class Polygon extends ShapeElement {
}
path.closePath();
}
-
+
public void render(Graphics2D g) throws SVGException
{
beginLayer(g);
@@ -125,7 +103,6 @@ public class Polygon extends ShapeElement {
finishLayer(g);
}
-
public Shape getShape()
{
return shapeToParent(path);
@@ -136,10 +113,10 @@ public class Polygon extends ShapeElement {
return boundsToParent(includeStrokeInBounds(path.getBounds2D()));
}
-
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -151,11 +128,11 @@ public class Polygon extends ShapeElement {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getStyle(sty.setName("fill-rule")))
{
- int newVal = sty.getStringValue().equals("evenodd")
- ? GeneralPath.WIND_EVEN_ODD
+ int newVal = sty.getStringValue().equals("evenodd")
+ ? GeneralPath.WIND_EVEN_ODD
: GeneralPath.WIND_NON_ZERO;
if (newVal != fillRule)
{
@@ -163,7 +140,7 @@ public class Polygon extends ShapeElement {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("points")))
{
String newVal = sty.getStringValue();
@@ -173,15 +150,15 @@ public class Polygon extends ShapeElement {
shapeChange = true;
}
}
-
-
+
+
if (shapeChange)
{
build();
// buildPath();
// return true;
}
-
+
return changeState || shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/Polyline.java b/src/main/java/com/kitfox/svg/Polyline.java
index b661e05..a62ea4c 100644
--- a/src/main/java/com/kitfox/svg/Polyline.java
+++ b/src/main/java/com/kitfox/svg/Polyline.java
@@ -33,56 +33,56 @@
*
* Created on January 26, 2004, 5:25 PM
*/
-
package com.kitfox.svg;
-import java.awt.geom.*;
-import java.awt.*;
-
-import com.kitfox.svg.xml.*;
+import com.kitfox.svg.xml.StyleAttribute;
+import com.kitfox.svg.xml.XMLParseUtil;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Polyline extends ShapeElement {
-
+public class Polyline extends ShapeElement
+{
+ public static final String TAG_NAME = "polyline";
+
int fillRule = GeneralPath.WIND_NON_ZERO;
String pointsStrn = "";
-// float[] points = null;
GeneralPath path;
- /** Creates a new instance of Rect */
- public Polyline() {
+ /**
+ * Creates a new instance of Rect
+ */
+ public Polyline()
+ {
}
- /*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ public String getTagName()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
-
- points = XMLParseUtil.parseFloatList(attrs.getValue("points"));
-
- build();
+ return TAG_NAME;
}
- */
public void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("points"))) pointsStrn = sty.getStringValue();
-
+
+ if (getPres(sty.setName("points")))
+ {
+ pointsStrn = sty.getStringValue();
+ }
+
String fillRuleStrn = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero";
fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO;
buildPath();
}
-
+
protected void buildPath()
{
float[] points = XMLParseUtil.parseFloatList(pointsStrn);
@@ -113,8 +113,9 @@ public class Polyline extends ShapeElement {
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -126,11 +127,11 @@ public class Polyline extends ShapeElement {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getStyle(sty.setName("fill-rule")))
{
- int newVal = sty.getStringValue().equals("evenodd")
- ? GeneralPath.WIND_EVEN_ODD
+ int newVal = sty.getStringValue().equals("evenodd")
+ ? GeneralPath.WIND_EVEN_ODD
: GeneralPath.WIND_NON_ZERO;
if (newVal != fillRule)
{
@@ -138,7 +139,7 @@ public class Polyline extends ShapeElement {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("points")))
{
String newVal = sty.getStringValue();
@@ -148,15 +149,15 @@ public class Polyline extends ShapeElement {
shapeChange = true;
}
}
-
-
+
+
if (shapeChange)
{
build();
// buildPath();
// return true;
}
-
+
return changeState || shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/RadialGradient.java b/src/main/java/com/kitfox/svg/RadialGradient.java
index 4ef04fe..b93612c 100644
--- a/src/main/java/com/kitfox/svg/RadialGradient.java
+++ b/src/main/java/com/kitfox/svg/RadialGradient.java
@@ -33,22 +33,22 @@
*
* Created on January 26, 2004, 1:55 AM
*/
-
package com.kitfox.svg;
-import java.awt.geom.*;
-import java.awt.*;
-
-import com.kitfox.svg.xml.*;
-
-//import org.apache.batik.ext.awt.*;
-
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.Color;
+import java.awt.Paint;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class RadialGradient extends Gradient {
+public class RadialGradient extends Gradient
+{
+ public static final String TAG_NAME = "radialgradient";
float cx = 0.5f;
float cy = 0.5f;
@@ -56,55 +56,50 @@ public class RadialGradient extends Gradient {
float fy = 0.5f;
float r = 0.5f;
- /** Creates a new instance of RadialGradient */
- public RadialGradient() {
- }
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ /**
+ * Creates a new instance of RadialGradient
+ */
+ public RadialGradient()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String cx = attrs.getValue("cx");
- String cy = attrs.getValue("cy");
- String fx = attrs.getValue("fx");
- String fy = attrs.getValue("fy");
- String r = attrs.getValue("r");
-
- if (cx != null) this.cx = (float)XMLParseUtil.parseRatio(cx);
- if (cy != null) this.cy = (float)XMLParseUtil.parseRatio(cy);
- if (fx != null) this.fx = (float)XMLParseUtil.parseRatio(fx);
- if (fy != null) this.fy = (float)XMLParseUtil.parseRatio(fy);
- if (r != null) this.r = (float)XMLParseUtil.parseRatio(r);
}
- */
- /*
- public void loaderEndElement(SVGLoaderHelper helper)
+ public String getTagName()
{
- super.loaderEndElement(helper);
-
- build();
+ return TAG_NAME;
}
- */
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("fx"))) fx = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("fy"))) fy = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("r"))) r = sty.getFloatValueWithUnits();
+
+ if (getPres(sty.setName("cx")))
+ {
+ cx = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("cy")))
+ {
+ cy = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("fx")))
+ {
+ fx = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("fy")))
+ {
+ fy = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("r")))
+ {
+ r = sty.getFloatValueWithUnits();
+ }
}
-
+
public Paint getPaint(Rectangle2D bounds, AffineTransform xform)
{
com.kitfox.svg.batik.MultipleGradientPaint.CycleMethodEnum method;
@@ -129,8 +124,7 @@ public class RadialGradient extends Gradient {
{
Color[] colors = getStopColors();
paint = colors.length > 0 ? colors[0] : Color.black;
- }
- else if (gradientUnits == GU_USER_SPACE_ON_USE)
+ } else if (gradientUnits == GU_USER_SPACE_ON_USE)
{
paint = new com.kitfox.svg.batik.RadialGradientPaint(
pt1,
@@ -141,8 +135,7 @@ public class RadialGradient extends Gradient {
method,
com.kitfox.svg.batik.MultipleGradientPaint.SRGB,
gradientTransform);
- }
- else
+ } else
{
AffineTransform viewXform = new AffineTransform();
viewXform.translate(bounds.getX(), bounds.getY());
@@ -165,8 +158,9 @@ public class RadialGradient extends Gradient {
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -178,7 +172,7 @@ public class RadialGradient extends Gradient {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("cx")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -188,7 +182,7 @@ public class RadialGradient extends Gradient {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("cy")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -198,7 +192,7 @@ public class RadialGradient extends Gradient {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("fx")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -208,7 +202,7 @@ public class RadialGradient extends Gradient {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("fy")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -218,7 +212,7 @@ public class RadialGradient extends Gradient {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("r")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -228,7 +222,7 @@ public class RadialGradient extends Gradient {
shapeChange = true;
}
}
-
+
return changeState;
}
}
diff --git a/src/main/java/com/kitfox/svg/Rect.java b/src/main/java/com/kitfox/svg/Rect.java
index fb9ea0e..87553a8 100644
--- a/src/main/java/com/kitfox/svg/Rect.java
+++ b/src/main/java/com/kitfox/svg/Rect.java
@@ -33,13 +33,14 @@
*
* Created on January 26, 2004, 5:25 PM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-
-import java.awt.*;
-import java.awt.geom.*;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.Rectangle2D;
+import java.awt.geom.RectangularShape;
+import java.awt.geom.RoundRectangle2D;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -48,7 +49,9 @@ import java.io.ObjectOutputStream;
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Rect extends ShapeElement {
+public class Rect extends ShapeElement
+{
+ public static final String TAG_NAME = "rect";
float x = 0f;
float y = 0f;
@@ -56,14 +59,21 @@ public class Rect extends ShapeElement {
float height = 0f;
float rx = 0f;
float ry = 0f;
-
RectangularShape rect;
- /** Creates a new instance of Rect */
- public Rect() {
+ /**
+ * Creates a new instance of Rect
+ */
+ public Rect()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
- private void writeObject(ObjectOutputStream out) throws IOException
+ private void writeObject(ObjectOutputStream out) throws IOException
{
out.writeFloat(x);
out.writeFloat(y);
@@ -72,7 +82,7 @@ public class Rect extends ShapeElement {
out.writeFloat(rx);
out.writeFloat(ry);
}
-
+
private void readObject(ObjectInputStream in) throws IOException
{
x = in.readFloat();
@@ -81,54 +91,52 @@ public class Rect extends ShapeElement {
height = in.readFloat();
rx = in.readFloat();
ry = in.readFloat();
-
+
if (rx == 0f && ry == 0f)
{
rect = new Rectangle2D.Float(x, y, width, height);
- }
- else
+ } else
{
rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2);
}
}
-
+
/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String x = attrs.getValue("x");
- String y = attrs.getValue("y");
- String width = attrs.getValue("width");
- String height = attrs.getValue("height");
- String rx = attrs.getValue("rx");
- String ry = attrs.getValue("ry");
-
- if (rx == null) rx = ry;
- if (ry == null) ry = rx;
-
- this.x = XMLParseUtil.parseFloat(x);
- this.y = XMLParseUtil.parseFloat(y);
- this.width = XMLParseUtil.parseFloat(width);
- this.height = XMLParseUtil.parseFloat(height);
- if (rx != null)
- {
- this.rx = XMLParseUtil.parseFloat(rx);
- this.ry = XMLParseUtil.parseFloat(ry);
- }
+ public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ {
+ //Load style string
+ super.loaderStartElement(helper, attrs, parent);
- build();
-// setBounds(this.x, this.y, this.width, this.height);
- }
-*/
-
+ String x = attrs.getValue("x");
+ String y = attrs.getValue("y");
+ String width = attrs.getValue("width");
+ String height = attrs.getValue("height");
+ String rx = attrs.getValue("rx");
+ String ry = attrs.getValue("ry");
+
+ if (rx == null) rx = ry;
+ if (ry == null) ry = rx;
+
+ this.x = XMLParseUtil.parseFloat(x);
+ this.y = XMLParseUtil.parseFloat(y);
+ this.width = XMLParseUtil.parseFloat(width);
+ this.height = XMLParseUtil.parseFloat(height);
+ if (rx != null)
+ {
+ this.rx = XMLParseUtil.parseFloat(rx);
+ this.ry = XMLParseUtil.parseFloat(ry);
+ }
+
+ build();
+ // setBounds(this.x, this.y, this.width, this.height);
+ }
+ */
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
+
// SVGElement parent = this.getParent();
// if (parent instanceof RenderableElement)
// {
@@ -136,31 +144,56 @@ public class Rect extends ShapeElement {
// Rectangle2D bounds = re.getBoundingBox();
// bounds = null;
// }
-
-
- if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
+
+
+ if (getPres(sty.setName("x")))
+ {
+ x = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("y")))
+ {
+ y = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("width")))
+ {
+ width = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("height")))
+ {
+ height = sty.getFloatValueWithUnits();
+ }
boolean rxSet = false;
- if (getPres(sty.setName("rx"))) { rx = sty.getFloatValueWithUnits(); rxSet = true; }
-
+ if (getPres(sty.setName("rx")))
+ {
+ rx = sty.getFloatValueWithUnits();
+ rxSet = true;
+ }
+
boolean rySet = false;
- if (getPres(sty.setName("ry"))) { ry = sty.getFloatValueWithUnits(); rySet = true; }
-
- if (!rxSet) rx = ry;
- if (!rySet) ry = rx;
+ if (getPres(sty.setName("ry")))
+ {
+ ry = sty.getFloatValueWithUnits();
+ rySet = true;
+ }
+
+ if (!rxSet)
+ {
+ rx = ry;
+ }
+ if (!rySet)
+ {
+ ry = rx;
+ }
+
-
if (rx == 0f && ry == 0f)
{
rect = new Rectangle2D.Float(x, y, width, height);
- }
- else
+ } else
{
rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2);
}
@@ -184,8 +217,9 @@ public class Rect extends ShapeElement {
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -197,7 +231,7 @@ public class Rect extends ShapeElement {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("x")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -271,7 +305,7 @@ public class Rect extends ShapeElement {
// }
// return true;
}
-
+
return changeState || shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/RenderableElement.java b/src/main/java/com/kitfox/svg/RenderableElement.java
index 0928454..8ae0bfc 100644
--- a/src/main/java/com/kitfox/svg/RenderableElement.java
+++ b/src/main/java/com/kitfox/svg/RenderableElement.java
@@ -33,7 +33,6 @@
*
* Created on January 26, 2004, 9:00 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
@@ -46,26 +45,26 @@ import java.awt.geom.Rectangle2D;
import java.net.URI;
import java.util.List;
-
-
/**
* Maintains bounding box for this element
*
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-abstract public class RenderableElement extends TransformableElement
+abstract public class RenderableElement extends TransformableElement
{
-
AffineTransform cachedXform = null;
- Shape cachedClip = null;
+ Shape cachedClip = null;
public static final int VECTOR_EFFECT_NONE = 0;
public static final int VECTOR_EFFECT_NON_SCALING_STROKE = 1;
int vectorEffect;
- /** Creates a new instance of BoundedElement */
- public RenderableElement() {
+ /**
+ * Creates a new instance of BoundedElement
+ */
+ public RenderableElement()
+ {
}
public RenderableElement(String id, SVGElement parent)
@@ -76,39 +75,38 @@ abstract public class RenderableElement extends TransformableElement
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
+
if (getPres(sty.setName("vector-effect")))
{
if ("non-scaling-stroke".equals(sty.getStringValue()))
{
vectorEffect = VECTOR_EFFECT_NON_SCALING_STROKE;
- }
- else
+ } else
{
vectorEffect = VECTOR_EFFECT_NONE;
}
- }
- else
+ } else
{
vectorEffect = VECTOR_EFFECT_NONE;
}
}
-
+
abstract public void render(Graphics2D g) throws SVGException;
-
+
abstract void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException;
-
+
abstract void pick(Rectangle2D pickArea, AffineTransform ltw, boolean boundingBox, List retVec) throws SVGException;
-
+
abstract public Rectangle2D getBoundingBox() throws SVGException;
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- super.loaderStartElement(helper, attrs, parent);
- }
-*/
+ /*
+ public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ {
+ super.loaderStartElement(helper, attrs, parent);
+ }
+ */
+
/**
* Pushes transform stack, transforms to local coordinates and sets up
* clipping mask.
@@ -122,7 +120,7 @@ abstract public class RenderableElement extends TransformableElement
}
StyleAttribute styleAttrib = new StyleAttribute();
-
+
//Get clipping path
// StyleAttribute styleAttrib = getStyle("clip-path", false);
Shape clipPath = null;
@@ -132,7 +130,7 @@ abstract public class RenderableElement extends TransformableElement
URI uri = styleAttrib.getURIValue(getXMLBase());
if (uri != null)
{
- ClipPath ele = (ClipPath)diagram.getUniverse().getElement(uri);
+ ClipPath ele = (ClipPath) diagram.getUniverse().getElement(uri);
clipPath = ele.getClipPathShape();
clipPathUnits = ele.getClipPathUnits();
}
@@ -143,7 +141,7 @@ abstract public class RenderableElement extends TransformableElement
{
if (clipPathUnits == ClipPath.CP_OBJECT_BOUNDING_BOX && (this instanceof ShapeElement))
{
- Rectangle2D rect = ((ShapeElement)this).getBoundingBox();
+ Rectangle2D rect = ((ShapeElement) this).getBoundingBox();
AffineTransform at = new AffineTransform();
at.scale(rect.getWidth(), rect.getHeight());
clipPath = at.createTransformedShape(clipPath);
@@ -153,8 +151,7 @@ abstract public class RenderableElement extends TransformableElement
if (cachedClip == null)
{
g.setClip(clipPath);
- }
- else
+ } else
{
Area newClip = new Area(cachedClip);
newClip.intersect(new Area(clipPath));
@@ -164,8 +161,8 @@ abstract public class RenderableElement extends TransformableElement
}
/**
- * Restores transform and clipping values to the way they were before
- * this layer was drawn.
+ * Restores transform and clipping values to the way they were before this
+ * layer was drawn.
*/
protected void finishLayer(Graphics2D g)
{
@@ -179,5 +176,4 @@ abstract public class RenderableElement extends TransformableElement
g.setTransform(cachedXform);
}
}
-
}
diff --git a/src/main/java/com/kitfox/svg/SVGElement.java b/src/main/java/com/kitfox/svg/SVGElement.java
index e1bdb31..377ac5f 100644
--- a/src/main/java/com/kitfox/svg/SVGElement.java
+++ b/src/main/java/com/kitfox/svg/SVGElement.java
@@ -33,9 +33,9 @@
*
* Created on January 26, 2004, 1:59 AM
*/
-
package com.kitfox.svg;
+import com.kitfox.svg.xml.StyleSheet;
import java.util.*;
import java.util.regex.*;
import java.net.*;
@@ -53,36 +53,31 @@ import java.io.Serializable;
*/
abstract public class SVGElement implements Serializable
{
+
public static final long serialVersionUID = 0;
-
public static final String SVG_NS = "http://www.w3.org/2000/svg";
-
protected SVGElement parent = null;
-
protected final ArrayList children = new ArrayList();
-
protected String id = null;
/**
- * CSS class. Used for applying style sheet information.
+ * CSS class. Used for applying style sheet information.
*/
protected String cssClass = null;
-
/**
* Styles defined for this elemnt via the <b>style</b> attribute.
*/
protected final HashMap inlineStyles = new HashMap();
-
/**
- * Presentation attributes set for this element. Ie, any attribute other
+ * Presentation attributes set for this element. Ie, any attribute other
* than the <b>style</b> attribute.
*/
protected final HashMap presAttribs = new HashMap();
-
/**
* A list of presentation attributes to not include in the presentation
* attribute set.
*/
protected static final Set ignorePresAttrib;
+
static
{
HashSet set = new HashSet();
@@ -90,17 +85,15 @@ abstract public class SVGElement implements Serializable
// set.add("class");
// set.add("style");
// set.add("xml:base");
-
+
ignorePresAttrib = Collections.unmodifiableSet(set);
}
-
/**
- * This element may override the URI we resolve against with an
- * xml:base attribute. If so, a copy is placed here. Otherwise, we defer
- * to our parent for the reolution base
+ * This element may override the URI we resolve against with an xml:base
+ * attribute. If so, a copy is placed here. Otherwise, we defer to our
+ * parent for the reolution base
*/
protected URI xmlBase = null;
-
/**
* The diagram this element belongs to
*/
@@ -108,74 +101,78 @@ abstract public class SVGElement implements Serializable
/**
* Link to the universe we reside in
*/
-// protected SVGUniverse universe;
-
protected final TrackManager trackManager = new TrackManager();
-
boolean dirty = true;
-// public static final Matcher adobeId = Pattern.compile("(.*)_1_").matcher("");
-// static final String fpNumRe = "[-+]?((\\d+)|(\\d*\\.\\d+))([-+]?[eE]\\d+)?";
-
- /** Creates a new instance of SVGElement */
+ /**
+ * Creates a new instance of SVGElement
+ */
public SVGElement()
{
this(null, null, null);
}
-
+
public SVGElement(String id, SVGElement parent)
{
this(id, null, parent);
}
-
+
public SVGElement(String id, String cssClass, SVGElement parent)
{
this.id = id;
this.cssClass = cssClass;
this.parent = parent;
}
-
+
+ abstract public String getTagName();
+
public SVGElement getParent()
{
return parent;
}
-
+
void setParent(SVGElement parent)
{
this.parent = parent;
}
-
+
/**
* @return an ordered list of nodes from the root of the tree to this node
*/
public List getPath(List retVec)
{
- if (retVec == null) retVec = new ArrayList();
-
+ if (retVec == null)
+ {
+ retVec = new ArrayList();
+ }
+
if (parent != null)
{
parent.getPath(retVec);
}
retVec.add(this);
-
+
return retVec;
}
-
+
/**
- * @param retVec - A list to add all children to. If null, a new list is
+ * @param retVec - A list to add all children to. If null, a new list is
* created and children of this group are added.
*
* @return The list containing the children of this group
*/
public List getChildren(List retVec)
{
- if (retVec == null) retVec = new ArrayList();
-
+ if (retVec == null)
+ {
+ retVec = new ArrayList();
+ }
+
retVec.addAll(children);
-
+
return retVec;
}
-
+
/**
* @param id - Id of svg element to return
* @return the child of the given id, or null if no such child exists.
@@ -184,25 +181,29 @@ abstract public class SVGElement implements Serializable
{
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
String eleId = ele.getId();
- if (eleId != null && eleId.equals(id)) return ele;
+ if (eleId != null && eleId.equals(id))
+ {
+ return ele;
+ }
}
-
+
return null;
}
-
+
/**
- * Searches children for given element. If found, returns index of child.
+ * Searches children for given element. If found, returns index of child.
* Otherwise returns -1.
*/
public int indexOfChild(SVGElement child)
{
return children.indexOf(child);
}
-
+
/**
* Swaps 2 elements in children.
+ *
* @i index of first
* @j index of second
*
@@ -214,65 +215,68 @@ abstract public class SVGElement implements Serializable
{
return;
}
-
+
Object temp = children.get(i);
children.set(i, children.get(j));
children.set(j, temp);
build();
}
-
+
/**
- * Called during SAX load process to notify that this tag has begun the process
- * of being loaded
+ * Called during SAX load process to notify that this tag has begun the
+ * process of being loaded
+ *
* @param attrs - Attributes of this tag
- * @param helper - An object passed to all SVG elements involved in this build
- * process to aid in sharing information.
+ * @param helper - An object passed to all SVG elements involved in this
+ * build process to aid in sharing information.
*/
public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) throws SAXException
{
//Set identification info
this.parent = parent;
this.diagram = helper.diagram;
-
+
this.id = attrs.getValue("id");
if (this.id != null && !this.id.equals(""))
{
diagram.setElement(this.id, this);
}
-
+
String className = attrs.getValue("class");
this.cssClass = (className == null || className.equals("")) ? null : className;
//docRoot = helper.docRoot;
//universe = helper.universe;
-
+
//Parse style string, if any
String style = attrs.getValue("style");
if (style != null)
{
HashMap map = XMLParseUtil.parseStyle(style, inlineStyles);
}
-
+
String base = attrs.getValue("xml:base");
if (base != null && !base.equals(""))
{
try
{
xmlBase = new URI(base);
- }
- catch (Exception e)
+ } catch (Exception e)
{
throw new SAXException(e);
}
}
-
+
//Place all other attributes into the presentation attribute list
int numAttrs = attrs.getLength();
for (int i = 0; i < numAttrs; i++)
{
String name = attrs.getQName(i);
- if (ignorePresAttrib.contains(name)) continue;
+ if (ignorePresAttrib.contains(name))
+ {
+ continue;
+ }
String value = attrs.getValue(i);
-
+
presAttribs.put(name, new StyleAttribute(name, value));
}
}
@@ -292,8 +296,11 @@ abstract public class SVGElement implements Serializable
public void addAttribute(String name, int attribType, String value) throws SVGElementException
{
- if (hasAttribute(name, attribType)) throw new SVGElementException(this, "Attribute " + name + "(" + AnimationElement.animationElementToString(attribType) + ") already exists");
-
+ if (hasAttribute(name, attribType))
+ {
+ throw new SVGElementException(this, "Attribute " + name + "(" + AnimationElement.animationElementToString(attribType) + ") already exists");
+ }
+
//Alter layout for id attribute
if ("id".equals(name))
{
@@ -304,7 +311,7 @@ abstract public class SVGElement implements Serializable
}
this.id = value;
}
-
+
switch (attribType)
{
case AnimationElement.AT_CSS:
@@ -314,10 +321,10 @@ abstract public class SVGElement implements Serializable
presAttribs.put(name, new StyleAttribute(name, value));
return;
}
-
+
throw new SVGElementException(this, "Invalid attribute type " + attribType);
}
-
+
public boolean hasAttribute(String name, int attribType) throws SVGElementException
{
switch (attribType)
@@ -329,10 +336,10 @@ abstract public class SVGElement implements Serializable
case AnimationElement.AT_AUTO:
return inlineStyles.containsKey(name) || presAttribs.containsKey(name);
}
-
+
throw new SVGElementException(this, "Invalid attribute type " + attribType);
}
-
+
/**
* @return a set of Strings that corespond to CSS attributes on this element
*/
@@ -340,7 +347,7 @@ abstract public class SVGElement implements Serializable
{
return inlineStyles.keySet();
}
-
+
/**
* @return a set of Strings that corespond to XML attributes on this element
*/
@@ -348,7 +355,7 @@ abstract public class SVGElement implements Serializable
{
return presAttribs.keySet();
}
-
+
/**
* Called after the start element but before the end element to indicate
* each child tag that has been processed
@@ -358,45 +365,45 @@ abstract public class SVGElement implements Serializable
children.add(child);
child.parent = this;
child.setDiagram(diagram);
-
+
//Add info to track if we've scanned animation element
if (child instanceof AnimationElement)
{
- trackManager.addTrackElement((AnimationElement)child);
+ trackManager.addTrackElement((AnimationElement) child);
}
}
-
+
protected void setDiagram(SVGDiagram diagram)
{
this.diagram = diagram;
diagram.setElement(id, this);
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
ele.setDiagram(diagram);
}
}
-
+
public void removeChild(SVGElement child) throws SVGElementException
{
if (!children.contains(child))
{
throw new SVGElementException(this, "Element does not contain child " + child);
}
-
+
children.remove(child);
}
-
+
/**
* Called during load process to add text scanned within a tag
*/
public void loaderAddText(SVGLoaderHelper helper, String text)
{
}
-
+
/**
- * Called to indicate that this tag and the tags it contains have been completely
- * processed, and that it should finish any load processes.
+ * Called to indicate that this tag and the tags it contains have been
+ * completely processed, and that it should finish any load processes.
*/
public void loaderEndElement(SVGLoaderHelper helper) throws SVGParseException
{
@@ -409,15 +416,15 @@ abstract public class SVGElement implements Serializable
// throw new SVGParseException(se);
// }
}
-
+
/**
- * Called by internal processes to rebuild the geometry of this node
- * from it's presentation attributes, style attributes and animated tracks.
+ * Called by internal processes to rebuild the geometry of this node from
+ * it's presentation attributes, style attributes and animated tracks.
*/
protected void build() throws SVGException
{
StyleAttribute sty = new StyleAttribute();
-
+
if (getPres(sty.setName("id")))
{
String newId = sty.getStringValue();
@@ -428,36 +435,40 @@ abstract public class SVGElement implements Serializable
diagram.setElement(this.id, this);
}
}
- if (getPres(sty.setName("class"))) cssClass = sty.getStringValue();
- if (getPres(sty.setName("xml:base"))) xmlBase = sty.getURIValue();
-
+ 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);
+ SVGElement ele = (SVGElement) children.get(i);
ele.build();
}
}
-
+
public URI getXMLBase()
{
- return xmlBase != null ? xmlBase :
- (parent != null ? parent.getXMLBase() : diagram.getXMLBase());
+ return xmlBase != null ? xmlBase
+ : (parent != null ? parent.getXMLBase() : diagram.getXMLBase());
}
/**
- * @return the id assigned to this node. Null if no id explicitly set.
+ * @return the id assigned to this node. Null if no id explicitly set.
*/
public String getId()
{
- return id;
+ return id;
}
-
-
LinkedList contexts = new LinkedList();
-
+
/**
- * Hack to allow nodes to temporarily change their parents. The Use tag will
+ * Hack to allow nodes to temporarily change their parents. The Use tag will
* need this so it can alter the attributes that a particular node uses.
*/
protected void pushParentContext(SVGElement context)
@@ -467,14 +478,19 @@ abstract public class SVGElement implements Serializable
protected SVGElement popParentContext()
{
- return (SVGElement)contexts.removeLast();
+ return (SVGElement) contexts.removeLast();
}
-
+
protected SVGElement getParentContext()
{
- return contexts.isEmpty() ? null : (SVGElement)contexts.getLast();
+ return contexts.isEmpty() ? null : (SVGElement) contexts.getLast();
}
-
+
+ public SVGRoot getRoot()
+ {
+ return parent == null ? null : parent.getRoot();
+ }
+
/*
* Returns the named style attribute. Checks for inline styles first, then
* internal and extranal style sheets, and finally checks for presentation
@@ -488,44 +504,43 @@ abstract public class SVGElement implements Serializable
{
return getStyle(attrib, true);
}
-
-
+
public void setAttribute(String name, int attribType, String value) throws SVGElementException
{
StyleAttribute styAttr;
-
-
+
+
switch (attribType)
{
case AnimationElement.AT_CSS:
{
- styAttr = (StyleAttribute)inlineStyles.get(name);
+ styAttr = (StyleAttribute) inlineStyles.get(name);
break;
}
case AnimationElement.AT_XML:
{
- styAttr = (StyleAttribute)presAttribs.get(name);
+ styAttr = (StyleAttribute) presAttribs.get(name);
break;
}
case AnimationElement.AT_AUTO:
{
- styAttr = (StyleAttribute)inlineStyles.get(name);
-
+ styAttr = (StyleAttribute) inlineStyles.get(name);
+
if (styAttr == null)
{
- styAttr = (StyleAttribute)presAttribs.get(name);
+ styAttr = (StyleAttribute) presAttribs.get(name);
}
break;
}
default:
throw new SVGElementException(this, "Invalid attribute type " + attribType);
}
-
+
if (styAttr == null)
{
throw new SVGElementException(this, "Could not find attribute " + name + "(" + AnimationElement.animationElementToString(attribType) + "). Make sure to create attribute before setting it.");
}
-
+
//Alter layout for relevant attributes
if ("id".equals(styAttr.getName()))
{
@@ -536,29 +551,30 @@ abstract public class SVGElement implements Serializable
}
this.id = value;
}
-
+
styAttr.setStringValue(value);
}
-
+
/**
- * Copies the current style into the passed style attribute. Checks for
- * inline styles first, then internal and extranal style sheets, and
- * finally checks for presentation attributes. Recursively checks parents.
- * @param attrib - Attribute to write style data to. Must have it's name
- * set to the name of the style being queried.
- * @param recursive - If true and this object does not contain the
- * named style attribute, checks attributes of parents back to root until
- * one found.
+ * Copies the current style into the passed style attribute. Checks for
+ * inline styles first, then internal and extranal style sheets, and finally
+ * checks for presentation attributes. Recursively checks parents.
+ *
+ * @param attrib - Attribute to write style data to. Must have it's name set
+ * to the name of the style being queried.
+ * @param recursive - If true and this object does not contain the named
+ * style attribute, checks attributes of parents back to root until one
+ * found.
*/
public boolean getStyle(StyleAttribute attrib, boolean recursive) throws SVGException
{
String styName = attrib.getName();
-
+
//Check for local inline styles
- StyleAttribute styAttr = (StyleAttribute)inlineStyles.get(styName);
-
+ StyleAttribute styAttr = (StyleAttribute) inlineStyles.get(styName);
+
attrib.setStringValue(styAttr == null ? "" : styAttr.getStringValue());
-
+
//Evalutate coresponding track, if one exists
TrackBase track = trackManager.getTrack(styName, AnimationElement.AT_CSS);
if (track != null)
@@ -566,19 +582,22 @@ abstract public class SVGElement implements Serializable
track.getValue(attrib, diagram.getUniverse().getCurTime());
return true;
}
-
+
//Return if we've found a non animated style
- if (styAttr != null) return true;
-
-
-
+ if (styAttr != null)
+ {
+ return true;
+ }
+
+
+
//Implement style sheet lookup later
-
+
//Check for presentation attribute
- StyleAttribute presAttr = (StyleAttribute)presAttribs.get(styName);
-
+ StyleAttribute presAttr = (StyleAttribute) presAttribs.get(styName);
+
attrib.setStringValue(presAttr == null ? "" : presAttr.getStringValue());
-
+
//Evalutate coresponding track, if one exists
track = trackManager.getTrack(styName, AnimationElement.AT_XML);
if (track != null)
@@ -586,48 +605,68 @@ abstract public class SVGElement implements Serializable
track.getValue(attrib, diagram.getUniverse().getCurTime());
return true;
}
-
+
//Return if we've found a presentation attribute instead
- if (presAttr != null) return true;
-
-
+ if (presAttr != null)
+ {
+ return true;
+ }
+
+ //Check for style sheet
+ SVGRoot root = getRoot();
+ if (root != null)
+ {
+ StyleSheet ss = root.getStyleSheet();
+ if (ss != null)
+ {
+ return ss.getStyle(attrib, getTagName(), cssClass);
+ }
+ }
+
//If we're recursive, check parents
if (recursive)
{
SVGElement parentContext = getParentContext();
- if (parentContext != null) return parentContext.getStyle(attrib, true);
- if (parent != null) return parent.getStyle(attrib, true);
+ if (parentContext != null)
+ {
+ return parentContext.getStyle(attrib, true);
+ }
+ if (parent != null)
+ {
+ return parent.getStyle(attrib, true);
+ }
}
-
+
//Unsuccessful reading style attribute
return false;
}
-
+
/**
- * @return the raw style value of this attribute. Does not take the
- * presentation value or animation into consideration. Used by animations
- * to determine the base to animate from.
+ * @return the raw style value of this attribute. Does not take the
+ * presentation value or animation into consideration. Used by animations to
+ * determine the base to animate from.
*/
public StyleAttribute getStyleAbsolute(String styName)
{
//Check for local inline styles
- return (StyleAttribute)inlineStyles.get(styName);
+ return (StyleAttribute) inlineStyles.get(styName);
}
-
+
/**
* Copies the presentation attribute into the passed one.
+ *
* @return - True if attribute was read successfully
*/
public boolean getPres(StyleAttribute attrib) throws SVGException
{
String presName = attrib.getName();
-
+
//Make sure we have a coresponding presentation attribute
- StyleAttribute presAttr = (StyleAttribute)presAttribs.get(presName);
-
+ StyleAttribute presAttr = (StyleAttribute) presAttribs.get(presName);
+
//Copy presentation value directly
attrib.setStringValue(presAttr == null ? "" : presAttr.getStringValue());
-
+
//Evalutate coresponding track, if one exists
TrackBase track = trackManager.getTrack(presName, AnimationElement.AT_XML);
if (track != null)
@@ -635,151 +674,152 @@ abstract public class SVGElement implements Serializable
track.getValue(attrib, diagram.getUniverse().getCurTime());
return true;
}
-
+
//Return if we found presentation attribute
- if (presAttr != null) return true;
-
+ if (presAttr != null)
+ {
+ return true;
+ }
+
return false;
}
-
+
/**
- * @return the raw presentation value of this attribute. Ignores any
- * modifications applied by style attributes or animation. Used by
+ * @return the raw presentation value of this attribute. Ignores any
+ * modifications applied by style attributes or animation. Used by
* animations to determine the starting point to animate from
*/
public StyleAttribute getPresAbsolute(String styName)
{
//Check for local inline styles
- return (StyleAttribute)presAttribs.get(styName);
+ return (StyleAttribute) presAttribs.get(styName);
}
-
+
static protected AffineTransform parseTransform(String val) throws SVGException
{
final Matcher matchExpression = Pattern.compile("\\w+\\([^)]*\\)").matcher("");
-
+
AffineTransform retXform = new AffineTransform();
-
+
matchExpression.reset(val);
while (matchExpression.find())
{
retXform.concatenate(parseSingleTransform(matchExpression.group()));
}
-
+
return retXform;
}
-
+
static public AffineTransform parseSingleTransform(String val) throws SVGException
{
final Matcher matchWord = Pattern.compile("[-.\\w]+").matcher("");
-
+
AffineTransform retXform = new AffineTransform();
-
+
matchWord.reset(val);
if (!matchWord.find())
{
//Return identity transformation if no data present (eg, empty string)
return retXform;
}
-
+
String function = matchWord.group().toLowerCase();
-
+
LinkedList termList = new LinkedList();
while (matchWord.find())
{
termList.add(matchWord.group());
}
-
-
+
+
double[] terms = new double[termList.size()];
Iterator it = termList.iterator();
int count = 0;
while (it.hasNext())
{
- terms[count++] = XMLParseUtil.parseDouble((String)it.next());
+ terms[count++] = XMLParseUtil.parseDouble((String) it.next());
}
-
+
//Calculate transformation
if (function.equals("matrix"))
{
retXform.setTransform(terms[0], terms[1], terms[2], terms[3], terms[4], terms[5]);
- }
- else if (function.equals("translate"))
+ } else if (function.equals("translate"))
{
if (terms.length == 1)
{
retXform.setToTranslation(terms[0], 0);
- }
- else
+ } else
{
retXform.setToTranslation(terms[0], terms[1]);
}
- }
- else if (function.equals("scale"))
+ } else if (function.equals("scale"))
{
if (terms.length > 1)
+ {
retXform.setToScale(terms[0], terms[1]);
- else
+ } else
+ {
retXform.setToScale(terms[0], terms[0]);
- }
- else if (function.equals("rotate"))
+ }
+ } else if (function.equals("rotate"))
{
if (terms.length > 2)
+ {
retXform.setToRotation(Math.toRadians(terms[0]), terms[1], terms[2]);
- else
+ } else
+ {
retXform.setToRotation(Math.toRadians(terms[0]));
- }
- else if (function.equals("skewx"))
+ }
+ } else if (function.equals("skewx"))
{
retXform.setToShear(Math.toRadians(terms[0]), 0.0);
- }
- else if (function.equals("skewy"))
+ } else if (function.equals("skewy"))
{
retXform.setToShear(0.0, Math.toRadians(terms[0]));
- }
- else
+ } else
{
throw new SVGException("Unknown transform type");
}
-
+
return retXform;
}
-
+
static protected float nextFloat(LinkedList l)
{
- String s = (String)l.removeFirst();
+ String s = (String) l.removeFirst();
return Float.parseFloat(s);
}
-
+
static protected PathCommand[] parsePathList(String list)
{
final Matcher matchPathCmd = Pattern.compile("([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)").matcher(list);
-
+
//Tokenize
LinkedList tokens = new LinkedList();
while (matchPathCmd.find())
{
tokens.addLast(matchPathCmd.group());
}
-
-
+
+
boolean defaultRelative = false;
LinkedList cmdList = new LinkedList();
char curCmd = 'Z';
while (tokens.size() != 0)
{
- String curToken = (String)tokens.removeFirst();
+ String curToken = (String) tokens.removeFirst();
char initChar = curToken.charAt(0);
- if ((initChar >= 'A' && initChar <='Z') || (initChar >= 'a' && initChar <='z'))
+ if ((initChar >= 'A' && initChar <= 'Z') || (initChar >= 'a' && initChar <= 'z'))
{
curCmd = initChar;
- }
- else
+ } else
{
tokens.addFirst(curToken);
}
-
+
PathCommand cmd = null;
-
+
switch (curCmd)
{
case 'M':
@@ -810,23 +850,23 @@ abstract public class SVGElement implements Serializable
break;
case 'A':
cmd = new Arc(false, nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens),
- nextFloat(tokens) == 1f, nextFloat(tokens) == 1f,
- nextFloat(tokens), nextFloat(tokens));
+ nextFloat(tokens),
+ nextFloat(tokens) == 1f, nextFloat(tokens) == 1f,
+ nextFloat(tokens), nextFloat(tokens));
break;
case 'a':
cmd = new Arc(true, nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens),
- nextFloat(tokens) == 1f, nextFloat(tokens) == 1f,
- nextFloat(tokens), nextFloat(tokens));
+ nextFloat(tokens),
+ nextFloat(tokens) == 1f, nextFloat(tokens) == 1f,
+ nextFloat(tokens), nextFloat(tokens));
break;
case 'Q':
cmd = new Quadratic(false, nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens), nextFloat(tokens));
+ nextFloat(tokens), nextFloat(tokens));
break;
case 'q':
cmd = new Quadratic(true, nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens), nextFloat(tokens));
+ nextFloat(tokens), nextFloat(tokens));
break;
case 'T':
cmd = new QuadraticSmooth(false, nextFloat(tokens), nextFloat(tokens));
@@ -836,21 +876,21 @@ abstract public class SVGElement implements Serializable
break;
case 'C':
cmd = new Cubic(false, nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens), nextFloat(tokens));
+ nextFloat(tokens), nextFloat(tokens),
+ nextFloat(tokens), nextFloat(tokens));
break;
case 'c':
cmd = new Cubic(true, nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens), nextFloat(tokens));
+ nextFloat(tokens), nextFloat(tokens),
+ nextFloat(tokens), nextFloat(tokens));
break;
case 'S':
cmd = new CubicSmooth(false, nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens), nextFloat(tokens));
+ nextFloat(tokens), nextFloat(tokens));
break;
case 's':
cmd = new CubicSmooth(true, nextFloat(tokens), nextFloat(tokens),
- nextFloat(tokens), nextFloat(tokens));
+ nextFloat(tokens), nextFloat(tokens));
break;
case 'Z':
case 'z':
@@ -859,45 +899,44 @@ abstract public class SVGElement implements Serializable
default:
throw new RuntimeException("Invalid path element");
}
-
+
cmdList.add(cmd);
defaultRelative = cmd.isRelative;
}
-
+
PathCommand[] retArr = new PathCommand[cmdList.size()];
cmdList.toArray(retArr);
return retArr;
}
-
+
static protected GeneralPath buildPath(String text, int windingRule)
{
PathCommand[] commands = parsePathList(text);
-
+
int numKnots = 2;
for (int i = 0; i < commands.length; i++)
{
numKnots += commands[i].getNumKnotsAdded();
}
-
-
+
+
GeneralPath path = new GeneralPath(windingRule, numKnots);
-
+
BuildHistory hist = new BuildHistory();
-
+
for (int i = 0; i < commands.length; i++)
{
PathCommand cmd = commands[i];
cmd.appendPath(path, hist);
}
-
+
return path;
}
-
-
-
+
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -910,12 +949,11 @@ abstract public class SVGElement implements Serializable
public SVGElement getChild(int i)
{
- return (SVGElement)children.get(i);
+ return (SVGElement) children.get(i);
}
-
+
public double lerp(double t0, double t1, double alpha)
{
return (1 - alpha) * t0 + alpha * t1;
}
-
}
diff --git a/src/main/java/com/kitfox/svg/SVGRoot.java b/src/main/java/com/kitfox/svg/SVGRoot.java
index 1751af2..08740b9 100644
--- a/src/main/java/com/kitfox/svg/SVGRoot.java
+++ b/src/main/java/com/kitfox/svg/SVGRoot.java
@@ -36,6 +36,7 @@
package com.kitfox.svg;
+import com.kitfox.svg.xml.StyleSheet;
import com.kitfox.svg.xml.NumberWithUnits;
import com.kitfox.svg.xml.StyleAttribute;
import java.awt.*;
@@ -49,13 +50,13 @@ import java.awt.geom.*;
*/
public class SVGRoot extends Group
{
+ public static final String TAG_NAME = "svg";
+
NumberWithUnits x;
NumberWithUnits y;
NumberWithUnits width;
NumberWithUnits height;
-
-// final Rectangle2D.Float viewBox = new Rectangle2D.Float();
Rectangle2D.Float viewBox = null;
public static final int PA_X_NONE = 0;
@@ -78,57 +79,17 @@ public class SVGRoot extends Group
final AffineTransform viewXform = new AffineTransform();
final Rectangle2D.Float clipRect = new Rectangle2D.Float();
+ private StyleSheet styleSheet;
+
/** Creates a new instance of SVGRoot */
public SVGRoot()
{
}
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- x = XMLParseUtil.parseNumberWithUnits(attrs.getValue("x"));
- y = XMLParseUtil.parseNumberWithUnits(attrs.getValue("y"));
- width = XMLParseUtil.parseNumberWithUnits(attrs.getValue("width"));
- height = XMLParseUtil.parseNumberWithUnits(attrs.getValue("height"));
-
- String viewBox = attrs.getValue("viewBox");
- float[] coords = XMLParseUtil.parseFloatList(viewBox);
-
- if (coords == null)
- {
- //this.viewBox.setRect(0, 0, width.getValue(), height.getValue());
- this.viewBox = null;
- }
- else
- {
- this.viewBox = new Rectangle2D.Float(coords[0], coords[1], coords[2], coords[3]);
- }
- String par = attrs.getValue("preserveAspectRatio");
- if (par != null)
- {
- String[] parList = XMLParseUtil.parseStringList(par);
-
- if (parList[0].equals("none")) { parAlignX = PA_X_NONE; parAlignY = PA_Y_NONE; }
- else if (parList[0].equals("xMinYMin")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MIN; }
- else if (parList[0].equals("xMidYMin")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MIN; }
- else if (parList[0].equals("xMaxYMin")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MIN; }
- else if (parList[0].equals("xMinYMid")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MID; }
- else if (parList[0].equals("xMidYMid")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MID; }
- else if (parList[0].equals("xMaxYMid")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MID; }
- else if (parList[0].equals("xMinYMax")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MAX; }
- else if (parList[0].equals("xMidYMax")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MAX; }
- else if (parList[0].equals("xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; }
-
- if (parList[1].equals("meet")) parSpecifier = PS_MEET;
- else if (parList[1].equals("slice")) parSpecifier = PS_SLICE;
- }
-
- build();
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-*/
public void build() throws SVGException
{
@@ -136,13 +97,25 @@ public class SVGRoot extends Group
StyleAttribute sty = new StyleAttribute();
- if (getPres(sty.setName("x"))) x = sty.getNumberWithUnits();
+ if (getPres(sty.setName("x")))
+ {
+ x = sty.getNumberWithUnits();
+ }
- if (getPres(sty.setName("y"))) y = sty.getNumberWithUnits();
+ if (getPres(sty.setName("y")))
+ {
+ y = sty.getNumberWithUnits();
+ }
- if (getPres(sty.setName("width"))) width = sty.getNumberWithUnits();
+ if (getPres(sty.setName("width")))
+ {
+ width = sty.getNumberWithUnits();
+ }
- if (getPres(sty.setName("height"))) height = sty.getNumberWithUnits();
+ if (getPres(sty.setName("height")))
+ {
+ height = sty.getNumberWithUnits();
+ }
if (getPres(sty.setName("viewBox")))
{
@@ -165,26 +138,11 @@ public class SVGRoot extends Group
else if (contains(preserve, "xMidYMax")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MAX; }
else if (contains(preserve, "xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; }
- if (contains(preserve, "meet")) parSpecifier = PS_MEET;
+ if (contains(preserve, "meet"))
+ {
+ parSpecifier = PS_MEET;
+ }
else if (contains(preserve, "slice")) parSpecifier = PS_SLICE;
-
- /*
- String[] parList = sty.getStringList();
-
- if (parList[0].equals("none")) { parAlignX = PA_X_NONE; parAlignY = PA_Y_NONE; }
- else if (parList[0].equals("xMinYMin")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MIN; }
- else if (parList[0].equals("xMidYMin")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MIN; }
- else if (parList[0].equals("xMaxYMin")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MIN; }
- else if (parList[0].equals("xMinYMid")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MID; }
- else if (parList[0].equals("xMidYMid")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MID; }
- else if (parList[0].equals("xMaxYMid")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MID; }
- else if (parList[0].equals("xMinYMax")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MAX; }
- else if (parList[0].equals("xMidYMax")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MAX; }
- else if (parList[0].equals("xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; }
-
- if (parList[1].equals("meet")) parSpecifier = PS_MEET;
- else if (parList[1].equals("slice")) parSpecifier = PS_SLICE;
- */
}
prepareViewport();
@@ -194,6 +152,11 @@ public class SVGRoot extends Group
{
return (text.indexOf(find) != -1);
}
+
+ public SVGRoot getRoot()
+ {
+ return this;
+ }
protected void prepareViewport()
{
@@ -203,7 +166,8 @@ public class SVGRoot extends Group
try
{
defaultBounds = getBoundingBox();
- } catch (SVGException ex)
+ }
+ catch (SVGException ex)
{
defaultBounds= new Rectangle2D.Float();
}
@@ -221,8 +185,6 @@ public class SVGRoot extends Group
{
ww = StyleAttribute.convertUnitsToPixels(width.getUnits(), width.getValue());
}
-// setAttribute("x", AnimationElement.AT_XML, "" + xx);
-// setAttribute("width", AnimationElement.AT_XML, "" + ww);
}
else if (viewBox != null)
{
@@ -281,12 +243,6 @@ public class SVGRoot extends Group
viewXform.scale(1 / viewBox.width, 1 / viewBox.height);
viewXform.translate(-viewBox.x, -viewBox.y);
}
-
-
- //For now, treat all preserveAspectRatio as 'none'
-// viewXform.setToTranslation(viewBox.x, viewBox.y);
-// viewXform.scale(clipRect.width / viewBox.width, clipRect.height / viewBox.height);
-// viewXform.translate(-clipRect.x, -clipRect.y);
}
public void render(Graphics2D g) throws SVGException
@@ -401,4 +357,20 @@ public class SVGRoot extends Group
return changeState || shapeChange;
}
+ /**
+ * @return the styleSheet
+ */
+ public StyleSheet getStyleSheet()
+ {
+ return styleSheet;
+ }
+
+ /**
+ * @param styleSheet the styleSheet to set
+ */
+ public void setStyleSheet(StyleSheet styleSheet)
+ {
+ this.styleSheet = styleSheet;
+ }
+
}
diff --git a/src/main/java/com/kitfox/svg/Stop.java b/src/main/java/com/kitfox/svg/Stop.java
index 6ca0bbd..028e07e 100644
--- a/src/main/java/com/kitfox/svg/Stop.java
+++ b/src/main/java/com/kitfox/svg/Stop.java
@@ -33,65 +33,74 @@
*
* Created on January 26, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.*;
-import java.util.*;
-
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
+import java.awt.Color;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Stop extends SVGElement {
+public class Stop extends SVGElement
+{
+ public static final String TAG_NAME = "stop";
float offset = 0f;
float opacity = 1f;
Color color = Color.black;
- /** Creates a new instance of Stop */
- public Stop() {
- }
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ /**
+ * Creates a new instance of Stop
+ */
+ public Stop()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String offset = attrs.getValue("offset");
- this.offset = (float)XMLParseUtil.parseRatio(offset);
+ }
- buildStop();
+ public String getTagName()
+ {
+ return TAG_NAME;
}
- */
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
+
if (getPres(sty.setName("offset")))
{
offset = sty.getFloatValue();
String units = sty.getUnits();
- if (units != null && units.equals("%")) offset /= 100f;
- if (offset > 1) offset = 1;
- if (offset < 0) offset = 0;
+ if (units != null && units.equals("%"))
+ {
+ offset /= 100f;
+ }
+ if (offset > 1)
+ {
+ offset = 1;
+ }
+ if (offset < 0)
+ {
+ offset = 0;
+ }
+ }
+
+ if (getStyle(sty.setName("stop-color")))
+ {
+ color = sty.getColorValue();
}
-
- if (getStyle(sty.setName("stop-color"))) color = sty.getColorValue();
- if (getStyle(sty.setName("stop-opacity"))) opacity = sty.getRatioValue();
+ if (getStyle(sty.setName("stop-opacity")))
+ {
+ opacity = sty.getRatioValue();
+ }
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -102,7 +111,7 @@ public class Stop extends SVGElement {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("offset")))
{
float newVal = sty.getFloatValue();
@@ -112,7 +121,7 @@ public class Stop extends SVGElement {
shapeChange = true;
}
}
-
+
if (getStyle(sty.setName("stop-color")))
{
Color newVal = sty.getColorValue();
@@ -122,7 +131,7 @@ public class Stop extends SVGElement {
shapeChange = true;
}
}
-
+
if (getStyle(sty.setName("stop-opacity")))
{
float newVal = sty.getFloatValue();
@@ -132,7 +141,7 @@ public class Stop extends SVGElement {
shapeChange = true;
}
}
-
+
return shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/Style.java b/src/main/java/com/kitfox/svg/Style.java
index 65f99af..24bf2cd 100644
--- a/src/main/java/com/kitfox/svg/Style.java
+++ b/src/main/java/com/kitfox/svg/Style.java
@@ -33,13 +33,9 @@
*
* Created on September 19, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
-
/**
* Holds title textual information within tree
@@ -47,24 +43,26 @@ import org.xml.sax.*;
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Style extends SVGElement {
+public class Style extends SVGElement
+{
+ public static final String TAG_NAME = "style";
//Should be set to "text/css"
String type;
StringBuffer text = new StringBuffer();
- /** Creates a new instance of Stop */
- public Style() {
- }
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ /**
+ * Creates a new instance of Stop
+ */
+ public Style()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
+ }
- this.type = attrs.getValue("type");
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-*/
+
/**
* Called during load process to add text scanned within a tag
*/
@@ -73,20 +71,21 @@ public class Style extends SVGElement {
this.text.append(text);
}
-
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("type"))) type = sty.getStringValue();
+
+ if (getPres(sty.setName("type")))
+ {
+ type = sty.getStringValue();
+ }
}
-
+
public boolean updateTime(double curTime) throws SVGException
{
//Style sheet doesn't change
return false;
- }
-
+ }
}
diff --git a/src/main/java/com/kitfox/svg/Symbol.java b/src/main/java/com/kitfox/svg/Symbol.java
index 6530723..3ad21c2 100644
--- a/src/main/java/com/kitfox/svg/Symbol.java
+++ b/src/main/java/com/kitfox/svg/Symbol.java
@@ -33,13 +33,14 @@
*
* Created on January 26, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
-import java.awt.*;
-import java.awt.geom.*;
-
-import com.kitfox.svg.xml.*;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
/**
* @author Mark McKay
@@ -47,47 +48,29 @@ import com.kitfox.svg.xml.*;
*/
public class Symbol extends Group
{
+
+ public static final String TAG_NAME = "symbol";
AffineTransform viewXform;
Rectangle2D viewBox;
- /** Creates a new instance of Stop */
- public Symbol() {
- }
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ /**
+ * Creates a new instance of Stop
+ */
+ public Symbol()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String viewBoxStrn = attrs.getValue("viewBox");
- if (viewBoxStrn != null)
- {
- float[] dim = XMLParseUtil.parseFloatList(viewBoxStrn);
- viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
- }
}
-*/
- /*
- public void loaderEndElement(SVGLoaderHelper helper)
- {
- if (viewBox == null)
- {
- viewBox = super.getBoundingBox();
- }
- //Transform pattern onto unit square
- viewXform = new AffineTransform();
- viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight());
- viewXform.translate(-viewBox.getX(), -viewBox.getY());
+ public String getTagName()
+ {
+ return TAG_NAME;
}
-*/
-
+
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
+
// sty = getPres("unicode");
// if (sty != null) unicode = sty.getStringValue();
@@ -97,7 +80,7 @@ public class Symbol extends Group
float[] dim = sty.getFloatList();
viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
}
-
+
if (viewBox == null)
{
// viewBox = super.getBoundingBox();
@@ -147,8 +130,9 @@ public class Symbol extends Group
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -156,10 +140,9 @@ public class Symbol extends Group
{
// if (trackManager.getNumTracks() == 0) return false;
boolean changeState = super.updateTime(curTime);
-
+
//View box properties do not change
-
+
return changeState;
}
-
}
diff --git a/src/main/java/com/kitfox/svg/Text.java b/src/main/java/com/kitfox/svg/Text.java
index 1b9087c..713f29c 100644
--- a/src/main/java/com/kitfox/svg/Text.java
+++ b/src/main/java/com/kitfox/svg/Text.java
@@ -33,47 +33,45 @@
*
* Created on January 26, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.*;
-import java.awt.font.*;
-import java.awt.geom.*;
-import java.util.*;
-import java.util.regex.*;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.font.FontRenderContext;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
-
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
public class Text extends ShapeElement
{
+ public static final String TAG_NAME = "text";
float x = 0;
float y = 0;
AffineTransform transform = null;
-
String fontFamily;
float fontSize;
-
//List of strings and tspans containing the content of this node
LinkedList content = new LinkedList();
-
Shape textShape;
-
public static final int TXAN_START = 0;
public static final int TXAN_MIDDLE = 1;
public static final int TXAN_END = 2;
int textAnchor = TXAN_START;
-
public static final int TXST_NORMAL = 0;
public static final int TXST_ITALIC = 1;
public static final int TXST_OBLIQUE = 2;
int fontStyle;
-
public static final int TXWE_NORMAL = 0;
public static final int TXWE_BOLD = 1;
public static final int TXWE_BOLDER = 2;
@@ -88,24 +86,30 @@ public class Text extends ShapeElement
public static final int TXWE_800 = 11;
public static final int TXWE_900 = 12;
int fontWeight;
-
- /** Creates a new instance of Stop */
+
+ /**
+ * Creates a new instance of Stop
+ */
public Text()
{
}
-
+
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
+
public void appendText(String text)
{
content.addLast(text);
}
-
+
public void appendTspan(Tspan tspan) throws SVGElementException
{
super.loaderAddChild(null, tspan);
content.addLast(tspan);
-// tspan.setParent(this);
}
-
+
/**
* Discard cached information
*/
@@ -113,25 +117,12 @@ public class Text extends ShapeElement
{
build();
}
-
+
public java.util.List getContent()
{
return content;
}
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String x = attrs.getValue("x");
- String y = attrs.getValue("y");
- //String transform = attrs.getValue("transform");
-
- this.x = XMLParseUtil.parseFloat(x);
- this.y = XMLParseUtil.parseFloat(y);
- }
- */
+
/**
* Called after the start element but before the end element to indicate
* each child tag that has been processed
@@ -139,83 +130,112 @@ public class Text extends ShapeElement
public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
{
super.loaderAddChild(helper, child);
-
+
content.addLast(child);
}
-
+
/**
* Called during load process to add text scanned within a tag
*/
public void loaderAddText(SVGLoaderHelper helper, String text)
{
Matcher matchWs = Pattern.compile("\\s*").matcher(text);
- if (!matchWs.matches()) content.addLast(text);
+ if (!matchWs.matches())
+ {
+ content.addLast(text);
+ }
}
-
+
public void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
-
- if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
-
- if (getStyle(sty.setName("font-family"))) fontFamily = sty.getStringValue();
- else fontFamily = "Sans Serif";
-
- if (getStyle(sty.setName("font-size"))) fontSize = sty.getFloatValueWithUnits();
- else fontSize = 12f;
-
+
+ if (getPres(sty.setName("x")))
+ {
+ x = sty.getFloatValueWithUnits();
+ }
+
+ if (getPres(sty.setName("y")))
+ {
+ y = sty.getFloatValueWithUnits();
+ }
+
+ if (getStyle(sty.setName("font-family")))
+ {
+ fontFamily = sty.getStringValue();
+ } else
+ {
+ fontFamily = "Sans Serif";
+ }
+
+ if (getStyle(sty.setName("font-size")))
+ {
+ fontSize = sty.getFloatValueWithUnits();
+ } else
+ {
+ fontSize = 12f;
+ }
+
if (getStyle(sty.setName("font-style")))
{
String s = sty.getStringValue();
if ("normal".equals(s))
{
fontStyle = TXST_NORMAL;
- }
- else if ("italic".equals(s))
+ } else if ("italic".equals(s))
{
fontStyle = TXST_ITALIC;
- }
- else if ("oblique".equals(s))
+ } else if ("oblique".equals(s))
{
fontStyle = TXST_OBLIQUE;
}
+ } else
+ {
+ fontStyle = TXST_NORMAL;
}
- else fontStyle = TXST_NORMAL;
-
+
if (getStyle(sty.setName("font-weight")))
{
String s = sty.getStringValue();
if ("normal".equals(s))
{
fontWeight = TXWE_NORMAL;
- }
- else if ("bold".equals(s))
+ } else if ("bold".equals(s))
{
fontWeight = TXWE_BOLD;
}
+ } else
+ {
+ fontWeight = TXWE_BOLD;
}
- else fontWeight = TXWE_BOLD;
-
+
if (getStyle(sty.setName("text-anchor")))
{
String s = sty.getStringValue();
- if (s.equals("middle")) textAnchor = TXAN_MIDDLE;
- else if (s.equals("end")) textAnchor = TXAN_END;
- else textAnchor = TXAN_START;
+ if (s.equals("middle"))
+ {
+ textAnchor = TXAN_MIDDLE;
+ } else if (s.equals("end"))
+ {
+ textAnchor = TXAN_END;
+ } else
+ {
+ textAnchor = TXAN_START;
+ }
+ } else
+ {
+ textAnchor = TXAN_START;
}
- else textAnchor = TXAN_START;
-
+
//text anchor
//text-decoration
//text-rendering
-
+
buildFont();
}
-
+
protected void buildFont() throws SVGException
{
int style;
@@ -240,58 +260,58 @@ public class Text extends ShapeElement
weight = java.awt.Font.PLAIN;
break;
}
-
+
//Get font
Font font = diagram.getUniverse().getFont(fontFamily);
if (font == null)
{
// System.err.println("Could not load font");
-
- java.awt.Font sysFont = new java.awt.Font(fontFamily, style | weight, (int)fontSize);
+
+ java.awt.Font sysFont = new java.awt.Font(fontFamily, style | weight, (int) fontSize);
buildSysFont(sysFont);
return;
}
-
+
// font = new java.awt.Font(font.getFamily(), style | weight, font.getSize());
-
+
// Area textArea = new Area();
GeneralPath textPath = new GeneralPath();
textShape = textPath;
-
+
float cursorX = x, cursorY = y;
-
+
FontFace fontFace = font.getFontFace();
//int unitsPerEm = fontFace.getUnitsPerEm();
int ascent = fontFace.getAscent();
- float fontScale = fontSize / (float)ascent;
-
+ float fontScale = fontSize / (float) ascent;
+
// AffineTransform oldXform = g.getTransform();
AffineTransform xform = new AffineTransform();
-
+
for (Iterator it = content.iterator(); it.hasNext();)
{
Object obj = it.next();
-
+
if (obj instanceof String)
{
- String text = (String)obj;
+ String text = (String) obj;
if (text != null)
{
text = text.trim();
}
-
+
strokeWidthScalar = 1f / fontScale;
-
+
for (int i = 0; i < text.length(); i++)
{
xform.setToIdentity();
xform.setToTranslation(cursorX, cursorY);
xform.scale(fontScale, fontScale);
// g.transform(xform);
-
+
String unicode = text.substring(i, i + 1);
MissingGlyph glyph = font.getGlyph(unicode);
-
+
Shape path = glyph.getPath();
if (path != null)
{
@@ -299,24 +319,23 @@ public class Text extends ShapeElement
textPath.append(path, false);
}
// else glyph.render(g);
-
+
cursorX += fontScale * glyph.getHorizAdvX();
-
+
// g.setTransform(oldXform);
}
-
+
strokeWidthScalar = 1f;
- }
- else if (obj instanceof Tspan)
+ } else if (obj instanceof Tspan)
{
- Tspan tspan = (Tspan)obj;
-
+ Tspan tspan = (Tspan) obj;
+
xform.setToIdentity();
xform.setToTranslation(cursorX, cursorY);
xform.scale(fontScale, fontScale);
// tspan.setCursorX(cursorX);
// tspan.setCursorY(cursorY);
-
+
Shape tspanShape = tspan.getShape();
tspanShape = xform.createTransformedShape(tspanShape);
textPath.append(tspanShape, false);
@@ -324,9 +343,9 @@ public class Text extends ShapeElement
// cursorX = tspan.getCursorX();
// cursorY = tspan.getCursorY();
}
-
+
}
-
+
switch (textAnchor)
{
case TXAN_MIDDLE:
@@ -345,67 +364,66 @@ public class Text extends ShapeElement
}
}
}
-
+
private void buildSysFont(java.awt.Font font) throws SVGException
{
GeneralPath textPath = new GeneralPath();
textShape = textPath;
-
+
float cursorX = x, cursorY = y;
-
+
// FontMetrics fm = g.getFontMetrics(font);
FontRenderContext frc = new FontRenderContext(null, true, true);
-
+
// FontFace fontFace = font.getFontFace();
//int unitsPerEm = fontFace.getUnitsPerEm();
// int ascent = fm.getAscent();
// float fontScale = fontSize / (float)ascent;
-
+
// AffineTransform oldXform = g.getTransform();
AffineTransform xform = new AffineTransform();
-
+
for (Iterator it = content.iterator(); it.hasNext();)
{
Object obj = it.next();
-
+
if (obj instanceof String)
{
- String text = (String)obj;
-
+ String text = (String) obj;
+
Shape textShape = font.createGlyphVector(frc, text).getOutline(cursorX, cursorY);
textPath.append(textShape, false);
// renderShape(g, textShape);
// g.drawString(text, cursorX, cursorY);
-
+
Rectangle2D rect = font.getStringBounds(text, frc);
- cursorX += (float)rect.getWidth();
- }
- else if (obj instanceof Tspan)
+ cursorX += (float) rect.getWidth();
+ } else if (obj instanceof Tspan)
{
/*
- Tspan tspan = (Tspan)obj;
+ Tspan tspan = (Tspan)obj;
- xform.setToIdentity();
- xform.setToTranslation(cursorX, cursorY);
+ xform.setToIdentity();
+ xform.setToTranslation(cursorX, cursorY);
- Shape tspanShape = tspan.getShape();
- tspanShape = xform.createTransformedShape(tspanShape);
- textArea.add(new Area(tspanShape));
+ Shape tspanShape = tspan.getShape();
+ tspanShape = xform.createTransformedShape(tspanShape);
+ textArea.add(new Area(tspanShape));
- cursorX += tspanShape.getBounds2D().getWidth();
+ cursorX += tspanShape.getBounds2D().getWidth();
*/
-
-
- Tspan tspan = (Tspan)obj;
+
+
+ Tspan tspan = (Tspan) obj;
tspan.setCursorX(cursorX);
tspan.setCursorY(cursorY);
tspan.addShape(textPath);
cursorX = tspan.getCursorX();
cursorY = tspan.getCursorY();
-
+
}
}
-
+
switch (textAnchor)
{
case TXAN_MIDDLE:
@@ -424,28 +442,28 @@ public class Text extends ShapeElement
}
}
}
-
-
+
public void render(Graphics2D g) throws SVGException
{
beginLayer(g);
renderShape(g, textShape);
finishLayer(g);
}
-
+
public Shape getShape()
{
return shapeToParent(textShape);
}
-
+
public Rectangle2D getBoundingBox() throws SVGException
{
return boundsToParent(includeStrokeInBounds(textShape.getBounds2D()));
}
-
+
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -453,11 +471,11 @@ public class Text extends ShapeElement
{
// if (trackManager.getNumTracks() == 0) return false;
boolean changeState = super.updateTime(curTime);
-
+
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("x")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -467,7 +485,7 @@ public class Text extends ShapeElement
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("y")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -477,7 +495,7 @@ public class Text extends ShapeElement
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("font-family")))
{
String newVal = sty.getStringValue();
@@ -487,7 +505,7 @@ public class Text extends ShapeElement
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("font-size")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -497,8 +515,8 @@ public class Text extends ShapeElement
shapeChange = true;
}
}
-
-
+
+
if (getStyle(sty.setName("font-style")))
{
String s = sty.getStringValue();
@@ -506,12 +524,10 @@ public class Text extends ShapeElement
if ("normal".equals(s))
{
newVal = TXST_NORMAL;
- }
- else if ("italic".equals(s))
+ } else if ("italic".equals(s))
{
newVal = TXST_ITALIC;
- }
- else if ("oblique".equals(s))
+ } else if ("oblique".equals(s))
{
newVal = TXST_OBLIQUE;
}
@@ -521,7 +537,7 @@ public class Text extends ShapeElement
shapeChange = true;
}
}
-
+
if (getStyle(sty.setName("font-weight")))
{
String s = sty.getStringValue();
@@ -529,8 +545,7 @@ public class Text extends ShapeElement
if ("normal".equals(s))
{
newVal = TXWE_NORMAL;
- }
- else if ("bold".equals(s))
+ } else if ("bold".equals(s))
{
newVal = TXWE_BOLD;
}
@@ -540,14 +555,14 @@ public class Text extends ShapeElement
shapeChange = true;
}
}
-
+
if (shapeChange)
{
build();
// buildFont();
// return true;
}
-
+
return changeState || shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/Title.java b/src/main/java/com/kitfox/svg/Title.java
index 3f4305b..57aa006 100644
--- a/src/main/java/com/kitfox/svg/Title.java
+++ b/src/main/java/com/kitfox/svg/Title.java
@@ -33,7 +33,6 @@
*
* Created on September 19, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
/**
@@ -42,12 +41,22 @@ package com.kitfox.svg;
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Title extends SVGElement {
-
+public class Title extends SVGElement
+{
+ public static final String TAG_NAME = "title";
+
StringBuffer text = new StringBuffer();
- /** Creates a new instance of Stop */
- public Title() {
+ /**
+ * Creates a new instance of Stop
+ */
+ public Title()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
/**
@@ -58,11 +67,15 @@ public class Title extends SVGElement {
this.text.append(text);
}
- public String getText() { return text.toString(); }
-
+ public String getText()
+ {
+ return text.toString();
+ }
+
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
diff --git a/src/main/java/com/kitfox/svg/TransformableElement.java b/src/main/java/com/kitfox/svg/TransformableElement.java
index f506033..f5a3e58 100644
--- a/src/main/java/com/kitfox/svg/TransformableElement.java
+++ b/src/main/java/com/kitfox/svg/TransformableElement.java
@@ -33,7 +33,6 @@
*
* Created on January 26, 2004, 9:00 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
@@ -41,20 +40,19 @@ import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
-
/**
* Maintains bounding box for this element
*
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class TransformableElement extends SVGElement
+abstract public class TransformableElement extends SVGElement
{
-
AffineTransform xform = null;
-// AffineTransform invXform = null;
- /** Creates a new instance of BoundedElement */
+ /**
+ * Creates a new instance of BoundedElement
+ */
public TransformableElement()
{
}
@@ -65,8 +63,8 @@ public class TransformableElement extends SVGElement
}
/**
- * Fetches a copy of the cached AffineTransform. Note that this
- * value will only be valid after the node has been updated.
+ * Fetches a copy of the cached AffineTransform. Note that this value will
+ * only be valid after the node has been updated.
*
* @return
*/
@@ -74,54 +72,61 @@ public class TransformableElement extends SVGElement
{
return new AffineTransform(xform);
}
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
+ /*
+ public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ {
+ //Load style string
+ super.loaderStartElement(helper, attrs, parent);
+
+ String transform = attrs.getValue("transform");
+ if (transform != null)
+ {
+ xform = parseTransform(transform);
+ }
+ }
+ */
- String transform = attrs.getValue("transform");
- if (transform != null)
- {
- xform = parseTransform(transform);
- }
- }
-*/
-
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
+
if (getPres(sty.setName("transform")))
{
xform = parseTransform(sty.getStringValue());
}
}
-
+
protected Shape shapeToParent(Shape shape)
{
- if (xform == null) return shape;
+ if (xform == null)
+ {
+ return shape;
+ }
return xform.createTransformedShape(shape);
}
protected Rectangle2D boundsToParent(Rectangle2D rect)
{
- if (xform == null) return rect;
+ if (xform == null)
+ {
+ return rect;
+ }
return xform.createTransformedShape(rect).getBounds2D();
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
public boolean updateTime(double curTime) throws SVGException
{
StyleAttribute sty = new StyleAttribute();
-
+
if (getPres(sty.setName("transform")))
{
AffineTransform newXform = parseTransform(sty.getStringValue());
@@ -131,7 +136,7 @@ public class TransformableElement extends SVGElement
return true;
}
}
-
+
return false;
}
}
diff --git a/src/main/java/com/kitfox/svg/Tspan.java b/src/main/java/com/kitfox/svg/Tspan.java
index 0dd6e37..1dbc734 100644
--- a/src/main/java/com/kitfox/svg/Tspan.java
+++ b/src/main/java/com/kitfox/svg/Tspan.java
@@ -33,45 +33,57 @@
*
* Created on January 26, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
-import java.awt.*;
-import java.awt.font.*;
-import java.awt.geom.*;
-import java.util.*;
-
-import com.kitfox.svg.xml.*;
-import org.xml.sax.*;
-
-//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphMetrics;
+import java.awt.font.GlyphVector;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Tspan extends ShapeElement {
-
+public class Tspan extends ShapeElement
+{
+ public static final String TAG_NAME = "tspan";
+
float[] x = null;
float[] y = null;
float[] dx = null;
float[] dy = null;
float[] rotate = null;
-
private String text = "";
-
float cursorX;
float cursorY;
// Shape tspanShape;
+ /**
+ * Creates a new instance of Stop
+ */
+ public Tspan()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
- /** Creates a new instance of Stop */
- public Tspan() {
+ public float getCursorX()
+ {
+ return cursorX;
}
- public float getCursorX() { return cursorX; }
- public float getCursorY() { return cursorY; }
+ public float getCursorY()
+ {
+ return cursorY;
+ }
public void setCursorX(float cursorX)
{
@@ -82,30 +94,30 @@ public class Tspan extends ShapeElement {
{
this.cursorY = cursorY;
}
-/*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
- {
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- String x = attrs.getValue("x");
- String y = attrs.getValue("y");
- String dx = attrs.getValue("dx");
- String dy = attrs.getValue("dy");
- String rotate = attrs.getValue("rotate");
-
- if (x != null) this.x = XMLParseUtil.parseFloatList(x);
- if (y != null) this.y = XMLParseUtil.parseFloatList(y);
- if (dx != null) this.dx = XMLParseUtil.parseFloatList(dx);
- if (dy != null) this.dy = XMLParseUtil.parseFloatList(dy);
- if (rotate != null)
- {
- this.rotate = XMLParseUtil.parseFloatList(rotate);
- for (int i = 0; i < this.rotate.length; i++)
- this.rotate[i] = (float)Math.toRadians(this.rotate[i]);
- }
- }
- */
+ /*
+ public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ {
+ //Load style string
+ super.loaderStartElement(helper, attrs, parent);
+
+ String x = attrs.getValue("x");
+ String y = attrs.getValue("y");
+ String dx = attrs.getValue("dx");
+ String dy = attrs.getValue("dy");
+ String rotate = attrs.getValue("rotate");
+
+ if (x != null) this.x = XMLParseUtil.parseFloatList(x);
+ if (y != null) this.y = XMLParseUtil.parseFloatList(y);
+ if (dx != null) this.dx = XMLParseUtil.parseFloatList(dx);
+ if (dy != null) this.dy = XMLParseUtil.parseFloatList(dy);
+ if (rotate != null)
+ {
+ this.rotate = XMLParseUtil.parseFloatList(rotate);
+ for (int i = 0; i < this.rotate.length; i++)
+ this.rotate[i] = (float)Math.toRadians(this.rotate[i]);
+ }
+ }
+ */
/**
* Called during load process to add text scanned within a tag
@@ -115,47 +127,57 @@ public class Tspan extends ShapeElement {
this.text += text;
}
-
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("x"))) x = sty.getFloatList();
- if (getPres(sty.setName("y"))) y = sty.getFloatList();
+ if (getPres(sty.setName("x")))
+ {
+ x = sty.getFloatList();
+ }
- if (getPres(sty.setName("dx"))) dx = sty.getFloatList();
+ if (getPres(sty.setName("y")))
+ {
+ y = sty.getFloatList();
+ }
- if (getPres(sty.setName("dy"))) dy = sty.getFloatList();
+ if (getPres(sty.setName("dx")))
+ {
+ dx = sty.getFloatList();
+ }
+
+ if (getPres(sty.setName("dy")))
+ {
+ dy = sty.getFloatList();
+ }
if (getPres(sty.setName("rotate")))
{
rotate = sty.getFloatList();
for (int i = 0; i < this.rotate.length; i++)
{
- rotate[i] = (float)Math.toRadians(this.rotate[i]);
+ rotate[i] = (float) Math.toRadians(this.rotate[i]);
}
-
+
}
}
-
+
public void addShape(GeneralPath addShape) throws SVGException
{
if (x != null)
{
cursorX = x[0];
cursorY = y[0];
- }
- else if (dx != null)
+ } else if (dx != null)
{
cursorX += dx[0];
cursorY += dy[0];
}
StyleAttribute sty = new StyleAttribute();
-
+
String fontFamily = null;
if (getStyle(sty.setName("font-family")))
{
@@ -168,13 +190,13 @@ public class Tspan extends ShapeElement {
{
fontSize = sty.getFloatValueWithUnits();
}
-
+
float letterSpacing = 0;
if (getStyle(sty.setName("letter-spacing")))
{
letterSpacing = sty.getFloatValueWithUnits();
}
-
+
//Get font
Font font = diagram.getUniverse().getFont(fontFamily);
@@ -186,7 +208,7 @@ public class Tspan extends ShapeElement {
FontFace fontFace = font.getFontFace();
int ascent = fontFace.getAscent();
- float fontScale = fontSize / (float)ascent;
+ float fontScale = fontSize / (float) ascent;
AffineTransform xform = new AffineTransform();
@@ -199,7 +221,10 @@ public class Tspan extends ShapeElement {
xform.setToIdentity();
xform.setToTranslation(cursorX, cursorY);
xform.scale(fontScale, fontScale);
- if (rotate != null) xform.rotate(rotate[posPtr]);
+ if (rotate != null)
+ {
+ xform.rotate(rotate[posPtr]);
+ }
String unicode = text.substring(i, i + 1);
MissingGlyph glyph = font.getGlyph(unicode);
@@ -215,8 +240,7 @@ public class Tspan extends ShapeElement {
{
cursorX = x[posPtr];
cursorY = y[posPtr++];
- }
- else if (dx != null && posPtr < dx.length)
+ } else if (dx != null && posPtr < dx.length)
{
cursorX += dx[posPtr];
cursorY += dy[posPtr++];
@@ -228,10 +252,10 @@ public class Tspan extends ShapeElement {
strokeWidthScalar = 1f;
}
- private void addShapeSysFont(GeneralPath addShape, Font font,
- String fontFamily, float fontSize, float letterSpacing)
+ private void addShapeSysFont(GeneralPath addShape, Font font,
+ String fontFamily, float fontSize, float letterSpacing)
{
- java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int)fontSize);
+ java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize);
FontRenderContext frc = new FontRenderContext(null, true, true);
GlyphVector textVector = sysFont.createGlyphVector(frc, text);
@@ -243,7 +267,10 @@ public class Tspan extends ShapeElement {
{
xform.setToIdentity();
xform.setToTranslation(cursorX + i * letterSpacing, cursorY);
- if (rotate != null) xform.rotate(rotate[Math.min(i, rotate.length - 1)]);
+ if (rotate != null)
+ {
+ xform.rotate(rotate[Math.min(i, rotate.length - 1)]);
+ }
String unicode = text.substring(i, i + 1);
Shape glyphOutline = textVector.getGlyphOutline(i);
@@ -256,8 +283,7 @@ public class Tspan extends ShapeElement {
{
cursorX = x[posPtr];
cursorY = y[posPtr++];
- }
- else if (dx != null && posPtr < dx.length)
+ } else if (dx != null && posPtr < dx.length)
{
cursorX += dx[posPtr];
cursorY += dy[posPtr++];
@@ -271,15 +297,14 @@ public class Tspan extends ShapeElement {
{
cursorX = x[0];
cursorY = y[0];
- }
- else if (dx != null)
+ } else if (dx != null)
{
cursorX += dx[0];
cursorY += dy[0];
}
StyleAttribute sty = new StyleAttribute();
-
+
String fontFamily = null;
if (getPres(sty.setName("font-family")))
{
@@ -298,7 +323,7 @@ public class Tspan extends ShapeElement {
if (font == null)
{
System.err.println("Could not load font");
- java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int)fontSize);
+ java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize);
renderSysFont(g, sysFont);
return;
}
@@ -306,7 +331,7 @@ public class Tspan extends ShapeElement {
FontFace fontFace = font.getFontFace();
int ascent = fontFace.getAscent();
- float fontScale = fontSize / (float)ascent;
+ float fontScale = fontSize / (float) ascent;
AffineTransform oldXform = g.getTransform();
AffineTransform xform = new AffineTransform();
@@ -328,15 +353,16 @@ public class Tspan extends ShapeElement {
if (path != null)
{
renderShape(g, path);
+ } else
+ {
+ glyph.render(g);
}
- else glyph.render(g);
if (x != null && posPtr < x.length)
{
cursorX = x[posPtr];
cursorY = y[posPtr++];
- }
- else if (dx != null && posPtr < dx.length)
+ } else if (dx != null && posPtr < dx.length)
{
cursorX += dx[posPtr];
cursorY += dy[posPtr++];
@@ -358,7 +384,7 @@ public class Tspan extends ShapeElement {
Shape textShape = font.createGlyphVector(frc, text).getOutline(cursorX, cursorY);
renderShape(g, textShape);
Rectangle2D rect = font.getStringBounds(text, frc);
- cursorX += (float)rect.getWidth();
+ cursorX += (float) rect.getWidth();
}
public Shape getShape()
@@ -374,8 +400,9 @@ public class Tspan extends ShapeElement {
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
diff --git a/src/main/java/com/kitfox/svg/Use.java b/src/main/java/com/kitfox/svg/Use.java
index f323154..f217b88 100644
--- a/src/main/java/com/kitfox/svg/Use.java
+++ b/src/main/java/com/kitfox/svg/Use.java
@@ -33,7 +33,6 @@
*
* Created on January 26, 2004, 1:54 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
@@ -47,29 +46,37 @@ import java.net.URI;
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
-public class Use extends ShapeElement {
-
+public class Use extends ShapeElement
+{
+ public static final String TAG_NAME = "use";
+
float x = 0f;
float y = 0f;
float width = 1f;
float height = 1f;
-
// SVGElement href = null;
URI href = null;
-
AffineTransform refXform;
- /** Creates a new instance of LinearGradient */
- public Use() {
+ /**
+ * Creates a new instance of LinearGradient
+ */
+ public Use()
+ {
+ }
+
+ public String getTagName()
+ {
+ return TAG_NAME;
}
protected void build() throws SVGException
{
super.build();
-
+
StyleAttribute sty = new StyleAttribute();
-
- if (getPres(sty.setName("x")))
+
+ if (getPres(sty.setName("x")))
{
x = sty.getFloatValueWithUnits();
}
@@ -79,7 +86,7 @@ public class Use extends ShapeElement {
y = sty.getFloatValueWithUnits();
}
- if (getPres(sty.setName("width")))
+ if (getPres(sty.setName("width")))
{
width = sty.getFloatValueWithUnits();
}
@@ -95,12 +102,12 @@ public class Use extends ShapeElement {
href = src;
// href = diagram.getUniverse().getElement(src);
}
-
+
//Determine use offset/scale
refXform = new AffineTransform();
refXform.translate(this.x, this.y);
}
-
+
public void render(Graphics2D g) throws SVGException
{
beginLayer(g);
@@ -111,9 +118,12 @@ public class Use extends ShapeElement {
SVGElement ref = diagram.getUniverse().getElement(href);
- if (ref == null || !(ref instanceof RenderableElement)) return;
+ if (ref == null || !(ref instanceof RenderableElement))
+ {
+ return;
+ }
- RenderableElement rendEle = (RenderableElement)ref;
+ RenderableElement rendEle = (RenderableElement) ref;
rendEle.pushParentContext(this);
rendEle.render(g);
rendEle.popParentContext();
@@ -128,7 +138,7 @@ public class Use extends ShapeElement {
SVGElement ref = diagram.getUniverse().getElement(href);
if (ref instanceof ShapeElement)
{
- Shape shape = ((ShapeElement)ref).getShape();
+ Shape shape = ((ShapeElement) ref).getShape();
shape = refXform.createTransformedShape(shape);
shape = shapeToParent(shape);
return shape;
@@ -142,11 +152,11 @@ public class Use extends ShapeElement {
SVGElement ref = diagram.getUniverse().getElement(href);
if (ref instanceof ShapeElement)
{
- ShapeElement shapeEle = (ShapeElement)ref;
+ ShapeElement shapeEle = (ShapeElement) ref;
shapeEle.pushParentContext(this);
Rectangle2D bounds = shapeEle.getBoundingBox();
shapeEle.popParentContext();
-
+
bounds = refXform.createTransformedShape(bounds).getBounds2D();
bounds = boundsToParent(bounds);
@@ -157,8 +167,9 @@ public class Use extends ShapeElement {
}
/**
- * Updates all attributes in this diagram associated with a time event.
- * Ie, all attributes with track information.
+ * Updates all attributes in this diagram associated with a time event. Ie,
+ * all attributes with track information.
+ *
* @return - true if this node has changed state as a result of the time
* update
*/
@@ -170,7 +181,7 @@ public class Use extends ShapeElement {
//Get current values for parameters
StyleAttribute sty = new StyleAttribute();
boolean shapeChange = false;
-
+
if (getPres(sty.setName("x")))
{
float newVal = sty.getFloatValueWithUnits();
@@ -210,7 +221,7 @@ public class Use extends ShapeElement {
shapeChange = true;
}
}
-
+
if (getPres(sty.setName("xlink:href")))
{
URI src = sty.getURIValue(getXMLBase());
@@ -221,18 +232,18 @@ public class Use extends ShapeElement {
shapeChange = true;
}
}
-/*
- if (getPres(sty.setName("xlink:href")))
- {
- URI src = sty.getURIValue(getXMLBase());
- href = diagram.getUniverse().getElement(src);
- }
+ /*
+ if (getPres(sty.setName("xlink:href")))
+ {
+ URI src = sty.getURIValue(getXMLBase());
+ href = diagram.getUniverse().getElement(src);
+ }
- //Determine use offset/scale
- refXform = new AffineTransform();
- refXform.translate(this.x, this.y);
- refXform.scale(this.width, this.height);
-*/
+ //Determine use offset/scale
+ refXform = new AffineTransform();
+ refXform.translate(this.x, this.y);
+ refXform.scale(this.width, this.height);
+ */
if (shapeChange)
{
build();
@@ -241,7 +252,7 @@ public class Use extends ShapeElement {
// refXform.scale(this.width, this.height);
// return true;
}
-
+
return changeState || shapeChange;
}
}
diff --git a/src/main/java/com/kitfox/svg/animation/Animate.java b/src/main/java/com/kitfox/svg/animation/Animate.java
index d65bdfc..3ef5287 100644
--- a/src/main/java/com/kitfox/svg/animation/Animate.java
+++ b/src/main/java/com/kitfox/svg/animation/Animate.java
@@ -60,6 +60,8 @@ import org.xml.sax.SAXException;
*/
public class Animate extends AnimateBase implements AnimateColorIface
{
+ public static final String TAG_NAME = "animate";
+
// StyleAttribute retAttrib = new StyleAttribute
public static final int DT_REAL = 0;
public static final int DT_COLOR = 1;
@@ -81,7 +83,12 @@ public class Animate extends AnimateBase implements AnimateColorIface
public Animate()
{
}
-
+
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
+
public int getDataType()
{
return dataType;
diff --git a/src/main/java/com/kitfox/svg/animation/AnimateColor.java b/src/main/java/com/kitfox/svg/animation/AnimateColor.java
index a5f59f8..a88bbdc 100644
--- a/src/main/java/com/kitfox/svg/animation/AnimateColor.java
+++ b/src/main/java/com/kitfox/svg/animation/AnimateColor.java
@@ -53,6 +53,8 @@ import org.xml.sax.SAXException;
*/
public class AnimateColor extends AnimateBase implements AnimateColorIface
{
+ public static final String TAG_NAME = "animateColor";
+
protected Color fromValue;
protected Color toValue;
@@ -61,7 +63,12 @@ public class AnimateColor extends AnimateBase implements AnimateColorIface
public AnimateColor()
{
}
-
+
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
+
public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) throws SAXException
{
//Load style string
diff --git a/src/main/java/com/kitfox/svg/animation/AnimateMotion.java b/src/main/java/com/kitfox/svg/animation/AnimateMotion.java
index 8d3fa3a..8b543d5 100644
--- a/src/main/java/com/kitfox/svg/animation/AnimateMotion.java
+++ b/src/main/java/com/kitfox/svg/animation/AnimateMotion.java
@@ -59,6 +59,8 @@ import org.xml.sax.SAXException;
*/
public class AnimateMotion extends AnimateXform
{
+ public static final String TAG_NAME = "animateMotion";
+
static final Matcher matchPoint = Pattern.compile("\\s*(\\d+)[^\\d]+(\\d+)\\s*").matcher("");
// protected double fromValue;
@@ -77,7 +79,12 @@ public class AnimateMotion extends AnimateXform
public AnimateMotion()
{
}
-
+
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
+
public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) throws SAXException
{
//Load style string
diff --git a/src/main/java/com/kitfox/svg/animation/AnimateTransform.java b/src/main/java/com/kitfox/svg/animation/AnimateTransform.java
index 1857f55..808ef54 100644
--- a/src/main/java/com/kitfox/svg/animation/AnimateTransform.java
+++ b/src/main/java/com/kitfox/svg/animation/AnimateTransform.java
@@ -54,6 +54,8 @@ import org.xml.sax.SAXException;
*/
public class AnimateTransform extends AnimateXform
{
+ public static final String TAG_NAME = "animateTransform";
+
// protected AffineTransform fromValue;
// protected AffineTransform toValue;
// protected double[] fromValue; //Transform parameters
@@ -80,6 +82,11 @@ public class AnimateTransform extends AnimateXform
{
}
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
+
public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) throws SAXException
{
//Load style string
diff --git a/src/main/java/com/kitfox/svg/animation/SetSmil.java b/src/main/java/com/kitfox/svg/animation/SetSmil.java
index 24a4bc0..2073456 100644
--- a/src/main/java/com/kitfox/svg/animation/SetSmil.java
+++ b/src/main/java/com/kitfox/svg/animation/SetSmil.java
@@ -53,13 +53,20 @@ import org.xml.sax.SAXException;
*/
public class SetSmil extends AnimationElement
{
+ public static final String TAG_NAME = "set";
+
String toValue;
/** Creates a new instance of Set */
public SetSmil()
{
}
-
+
+ public String getTagName()
+ {
+ return TAG_NAME;
+ }
+
public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) throws SAXException
{
//Load style string
diff --git a/src/main/java/com/kitfox/svg/xml/StyleAttribute.java b/src/main/java/com/kitfox/svg/xml/StyleAttribute.java
index 2566724..b60a1bd 100644
--- a/src/main/java/com/kitfox/svg/xml/StyleAttribute.java
+++ b/src/main/java/com/kitfox/svg/xml/StyleAttribute.java
@@ -79,10 +79,20 @@ public class StyleAttribute implements Serializable
this.stringValue = stringValue;
}
- public String getName() { return name; }
- public StyleAttribute setName(String name) { this.name = name; return this; }
+ public String getName() {
+ return name;
+ }
- public String getStringValue() { return stringValue; }
+ public StyleAttribute setName(String name)
+ {
+ this.name = name;
+ return this;
+ }
+
+ public String getStringValue()
+ {
+ return stringValue;
+ }
public String[] getStringList()
{
diff --git a/src/main/java/com/kitfox/svg/xml/StyleSheet.java b/src/main/java/com/kitfox/svg/xml/StyleSheet.java
new file mode 100644
index 0000000..da3db2e
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/xml/StyleSheet.java
@@ -0,0 +1,56 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.kitfox.svg.xml;
+
+import java.util.HashMap;
+
+/**
+ *
+ * @author kitfox
+ */
+public class StyleSheet
+{
+ HashMap ruleMap = new HashMap();
+
+ public void addStyleRule(StyleSheetRule rule, String value)
+ {
+ ruleMap.put(rule, value);
+ }
+
+ public boolean getStyle(StyleAttribute attrib, String tagName, String cssClass)
+ {
+ StyleSheetRule rule = new StyleSheetRule(attrib.getName(), tagName, cssClass);
+ String value = (String)ruleMap.get(rule);
+
+ if (value != null)
+ {
+ attrib.setStringValue(value);
+ return true;
+ }
+
+ //Try again using just class name
+ rule = new StyleSheetRule(attrib.getName(), null, cssClass);
+ value = (String)ruleMap.get(rule);
+
+ if (value != null)
+ {
+ attrib.setStringValue(value);
+ return true;
+ }
+
+ //Try again using just tag name
+ rule = new StyleSheetRule(attrib.getName(), tagName, null);
+ value = (String)ruleMap.get(rule);
+
+ if (value != null)
+ {
+ attrib.setStringValue(value);
+ return true;
+ }
+
+ return false;
+ }
+
+}
diff --git a/src/main/java/com/kitfox/svg/xml/StyleSheetRule.java b/src/main/java/com/kitfox/svg/xml/StyleSheetRule.java
new file mode 100644
index 0000000..5389c2d
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/xml/StyleSheetRule.java
@@ -0,0 +1,59 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.kitfox.svg.xml;
+
+/**
+ *
+ * @author kitfox
+ */
+public class StyleSheetRule
+{
+ final String styleName;
+ final String tag;
+ final String className;
+
+ public StyleSheetRule(String styleName, String tag, String className)
+ {
+ this.styleName = styleName;
+ this.tag = tag;
+ this.className = className;
+ }
+
+ public int hashCode()
+ {
+ int hash = 7;
+ hash = 13 * hash + (this.styleName != null ? this.styleName.hashCode() : 0);
+ hash = 13 * hash + (this.tag != null ? this.tag.hashCode() : 0);
+ hash = 13 * hash + (this.className != null ? this.className.hashCode() : 0);
+ return hash;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ final StyleSheetRule other = (StyleSheetRule) obj;
+ if ((this.styleName == null) ? (other.styleName != null) : !this.styleName.equals(other.styleName))
+ {
+ return false;
+ }
+ if ((this.tag == null) ? (other.tag != null) : !this.tag.equals(other.tag))
+ {
+ return false;
+ }
+ if ((this.className == null) ? (other.className != null) : !this.className.equals(other.className))
+ {
+ return false;
+ }
+ return true;
+ }
+
+}