summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkitfox2009-04-23 23:44:56 +0200
committerkitfox2009-04-23 23:44:56 +0200
commit71d652c248ea25c91281e127ddde85c6ff7e7683 (patch)
tree13ff926d8bc121964d9e1a4134a8d04d082fd49d
parentGradient references are now handled as URIs rather than being referenced dire... (diff)
downloadsvg-salamander-core-71d652c248ea25c91281e127ddde85c6ff7e7683.tar.gz
svg-salamander-core-71d652c248ea25c91281e127ddde85c6ff7e7683.tar.xz
svg-salamander-core-71d652c248ea25c91281e127ddde85c6ff7e7683.zip
Added rebuild() to AnimateElement that will allow the user to change the xml values of animation elements.
git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@64 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b
-rw-r--r--src/main/java/com/kitfox/svg/animation/Animate.java77
-rw-r--r--src/main/java/com/kitfox/svg/animation/AnimateBase.java53
-rw-r--r--src/main/java/com/kitfox/svg/animation/AnimateColor.java32
-rw-r--r--src/main/java/com/kitfox/svg/animation/AnimateMotion.java126
-rw-r--r--src/main/java/com/kitfox/svg/animation/AnimateTransform.java87
-rw-r--r--src/main/java/com/kitfox/svg/animation/AnimateXform.java10
-rw-r--r--src/main/java/com/kitfox/svg/animation/AnimationElement.java86
-rw-r--r--src/main/java/com/kitfox/svg/animation/SetSmil.java22
8 files changed, 423 insertions, 70 deletions
diff --git a/src/main/java/com/kitfox/svg/animation/Animate.java b/src/main/java/com/kitfox/svg/animation/Animate.java
index 051c526..df34437 100644
--- a/src/main/java/com/kitfox/svg/animation/Animate.java
+++ b/src/main/java/com/kitfox/svg/animation/Animate.java
@@ -26,14 +26,20 @@
package com.kitfox.svg.animation;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.SVGLoaderHelper;
+import com.kitfox.svg.animation.parser.AnimTimeParser;
+import com.kitfox.svg.xml.ColorTable;
+import com.kitfox.svg.xml.StyleAttribute;
import com.kitfox.svg.xml.XMLParseUtil;
-import org.xml.sax.*;
+import java.awt.Color;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.PathIterator;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
-import com.kitfox.svg.*;
-import com.kitfox.svg.xml.*;
-
-import java.awt.*;
-import java.awt.geom.*;
/**
* Animate is a really annoying morphic tag that could represent a real value,
@@ -350,5 +356,64 @@ public class Animate extends AnimateBase implements AnimateColorIface
//Should not reach this line
return 0;
}
+
+ protected void rebuild(AnimTimeParser animTimeParser) throws SVGException
+ {
+ super.rebuild(animTimeParser);
+
+ StyleAttribute sty = new StyleAttribute();
+
+ if (getPres(sty.setName("from")))
+ {
+ String strn = sty.getStringValue();
+ if (XMLParseUtil.isDouble(strn))
+ {
+ fromValue = XMLParseUtil.parseDouble(strn);
+ }
+ else
+ {
+ fromColor = ColorTable.parseColor(strn);
+ if (fromColor == null)
+ {
+ //Try path
+ fromPath = this.buildPath(strn, GeneralPath.WIND_EVEN_ODD);
+ dataType = DT_PATH;
+ }
+ else dataType = DT_COLOR;
+ }
+ }
+
+ if (getPres(sty.setName("to")))
+ {
+ String strn = sty.getStringValue();
+ if (XMLParseUtil.isDouble(strn))
+ {
+ toValue = XMLParseUtil.parseDouble(strn);
+ }
+ else
+ {
+ toColor = ColorTable.parseColor(strn);
+ if (toColor == null)
+ {
+ //Try path
+ toPath = this.buildPath(strn, GeneralPath.WIND_EVEN_ODD);
+ dataType = DT_PATH;
+ }
+ else dataType = DT_COLOR;
+ }
+ }
+
+ if (getPres(sty.setName("by")))
+ {
+ String strn = sty.getStringValue();
+ if (strn != null) byValue = XMLParseUtil.parseDouble(strn);
+ }
+
+ if (getPres(sty.setName("values")))
+ {
+ String strn = sty.getStringValue();
+ if (strn != null) valuesValue = XMLParseUtil.parseDoubleList(strn);
+ }
+ }
}
diff --git a/src/main/java/com/kitfox/svg/animation/AnimateBase.java b/src/main/java/com/kitfox/svg/animation/AnimateBase.java
index 53a6117..59c551f 100644
--- a/src/main/java/com/kitfox/svg/animation/AnimateBase.java
+++ b/src/main/java/com/kitfox/svg/animation/AnimateBase.java
@@ -26,10 +26,15 @@
package com.kitfox.svg.animation;
-import java.io.*;
-import org.xml.sax.*;
-
-import com.kitfox.svg.*;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.SVGLoaderHelper;
+import com.kitfox.svg.animation.parser.AnimTimeParser;
+import com.kitfox.svg.animation.parser.ParseException;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.io.StringReader;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
/**
* @author Mark McKay
@@ -71,8 +76,6 @@ abstract public class AnimateBase extends AnimationElement
throw new SAXException(e);
}
-// this.repeatDur = TimeBase.parseTime(repeatDurTime);
-
String strn = attrs.getValue("repeatCount");
if (strn == null)
{
@@ -89,4 +92,42 @@ abstract public class AnimateBase extends AnimationElement
}
}
+ protected void rebuild(AnimTimeParser animTimeParser) throws SVGException
+ {
+ super.rebuild(animTimeParser);
+
+ StyleAttribute sty = new StyleAttribute();
+
+ if (getPres(sty.setName("repeatDur")))
+ {
+ String strn = sty.getStringValue();
+ if (strn != null)
+ {
+ animTimeParser.ReInit(new StringReader(strn));
+ try {
+ this.repeatDur = animTimeParser.Expr();
+ } catch (ParseException ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ if (getPres(sty.setName("repeatCount")))
+ {
+ String strn = sty.getStringValue();
+ if (strn == null)
+ {
+ repeatCount = 1;
+ }
+ else if ("indefinite".equals(strn))
+ {
+ repeatCount = Double.POSITIVE_INFINITY;
+ }
+ else
+ {
+ try { repeatCount = Double.parseDouble(strn); }
+ catch (Exception e) { repeatCount = Double.NaN; }
+ }
+ }
+ }
}
diff --git a/src/main/java/com/kitfox/svg/animation/AnimateColor.java b/src/main/java/com/kitfox/svg/animation/AnimateColor.java
index a63ecad..4f39f02 100644
--- a/src/main/java/com/kitfox/svg/animation/AnimateColor.java
+++ b/src/main/java/com/kitfox/svg/animation/AnimateColor.java
@@ -26,11 +26,16 @@
package com.kitfox.svg.animation;
-import org.xml.sax.*;
-import java.awt.*;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.SVGLoaderHelper;
+import com.kitfox.svg.animation.parser.AnimTimeParser;
+import com.kitfox.svg.xml.ColorTable;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.Color;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
-import com.kitfox.svg.*;
-import com.kitfox.svg.xml.*;
/**
* @author Mark McKay
@@ -78,4 +83,23 @@ public class AnimateColor extends AnimateBase implements AnimateColorIface
(int)(g1 * invInterp + g2 * interp),
(int)(b1 * invInterp + b2 * interp));
}
+
+ protected void rebuild(AnimTimeParser animTimeParser) throws SVGException
+ {
+ super.rebuild(animTimeParser);
+
+ StyleAttribute sty = new StyleAttribute();
+
+ if (getPres(sty.setName("from")))
+ {
+ String strn = sty.getStringValue();
+ fromValue = ColorTable.parseColor(strn);
+ }
+
+ if (getPres(sty.setName("to")))
+ {
+ String strn = sty.getStringValue();
+ toValue = ColorTable.parseColor(strn);
+ }
+ }
}
diff --git a/src/main/java/com/kitfox/svg/animation/AnimateMotion.java b/src/main/java/com/kitfox/svg/animation/AnimateMotion.java
index c96f45e..f4adcdc 100644
--- a/src/main/java/com/kitfox/svg/animation/AnimateMotion.java
+++ b/src/main/java/com/kitfox/svg/animation/AnimateMotion.java
@@ -26,13 +26,22 @@
package com.kitfox.svg.animation;
-import org.xml.sax.*;
-import java.util.regex.*;
-import java.awt.geom.*;
-import java.awt.*;
-import java.util.*;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.SVGLoaderHelper;
+import com.kitfox.svg.animation.parser.AnimTimeParser;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.PathIterator;
+import java.awt.geom.Point2D;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
-import com.kitfox.svg.*;
/**
* @author Mark McKay
@@ -73,33 +82,6 @@ public class AnimateMotion extends AnimateXform
}
- //Determine path
- String from = attrs.getValue("from");
- String to = attrs.getValue("to");
- if (from != null && to != null)
- {
- Point2D.Float ptFrom = new Point2D.Float(), ptTo = new Point2D.Float();
-
- matchPoint.reset(from);
- if (matchPoint.matches())
- {
- setPoint(ptFrom, matchPoint.group(1), matchPoint.group(2));
- }
-
- matchPoint.reset(to);
- if (matchPoint.matches())
- {
- setPoint(ptFrom, matchPoint.group(1), matchPoint.group(2));
- }
-
- if (ptFrom != null && ptTo != null)
- {
- path = new GeneralPath();
- path.moveTo(ptFrom.x, ptFrom.y);
- path.lineTo(ptTo.x, ptTo.y);
- }
- }
-
String path = attrs.getValue("path");
if (path != null)
{
@@ -119,8 +101,12 @@ public class AnimateMotion extends AnimateXform
try { this.rotate = Math.toRadians(Float.parseFloat(rotate)); } catch (Exception e) {}
}
}
-
- paramaterizePath();
+
+ //Determine path
+ String from = attrs.getValue("from");
+ String to = attrs.getValue("to");
+
+ buildPath(from, to);
}
protected static void setPoint(Point2D.Float pt, String x, String y)
@@ -130,6 +116,34 @@ public class AnimateMotion extends AnimateXform
try { pt.y = Float.parseFloat(y); } catch (Exception e) {};
}
+ private void buildPath(String from, String to)
+ {
+ if (from != null && to != null)
+ {
+ Point2D.Float ptFrom = new Point2D.Float(), ptTo = new Point2D.Float();
+
+ matchPoint.reset(from);
+ if (matchPoint.matches())
+ {
+ setPoint(ptFrom, matchPoint.group(1), matchPoint.group(2));
+ }
+
+ matchPoint.reset(to);
+ if (matchPoint.matches())
+ {
+ setPoint(ptFrom, matchPoint.group(1), matchPoint.group(2));
+ }
+
+ if (ptFrom != null && ptTo != null)
+ {
+ path = new GeneralPath();
+ path.moveTo(ptFrom.x, ptFrom.y);
+ path.lineTo(ptTo.x, ptTo.y);
+ }
+ }
+
+ paramaterizePath();
+ }
private void paramaterizePath()
{
@@ -225,10 +239,44 @@ public class AnimateMotion extends AnimateXform
return xform;
}
- public static void main(String[] argv)
+
+ protected void rebuild(AnimTimeParser animTimeParser) throws SVGException
{
- AnimateMotion a = new AnimateMotion();
- a.path = buildPath("M0 0 L-400, 0", GeneralPath.WIND_NON_ZERO);
- a.paramaterizePath();
+ super.rebuild(animTimeParser);
+
+ StyleAttribute sty = new StyleAttribute();
+
+ if (getPres(sty.setName("path")))
+ {
+ String strn = sty.getStringValue();
+ this.path = buildPath(strn, GeneralPath.WIND_NON_ZERO);
+ }
+
+ if (getPres(sty.setName("rotate")))
+ {
+ String strn = sty.getStringValue();
+ if (strn.equals("auto"))
+ {
+ this.rotateType = RT_AUTO;
+ }
+ else
+ {
+ try { this.rotate = Math.toRadians(Float.parseFloat(strn)); } catch (Exception e) {}
+ }
+ }
+
+ String from = null;
+ if (getPres(sty.setName("from")))
+ {
+ from = sty.getStringValue();
+ }
+
+ String to = null;
+ if (getPres(sty.setName("to")))
+ {
+ to = sty.getStringValue();
+ }
+
+ buildPath(from, to);
}
}
diff --git a/src/main/java/com/kitfox/svg/animation/AnimateTransform.java b/src/main/java/com/kitfox/svg/animation/AnimateTransform.java
index efce6fc..61d73b2 100644
--- a/src/main/java/com/kitfox/svg/animation/AnimateTransform.java
+++ b/src/main/java/com/kitfox/svg/animation/AnimateTransform.java
@@ -26,13 +26,17 @@
package com.kitfox.svg.animation;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.SVGLoaderHelper;
+import com.kitfox.svg.animation.parser.AnimTimeParser;
+import com.kitfox.svg.xml.StyleAttribute;
import com.kitfox.svg.xml.XMLParseUtil;
-import org.xml.sax.*;
-import java.awt.geom.*;
-
-import com.kitfox.svg.*;
-import com.kitfox.svg.xml.*;
+import java.awt.geom.AffineTransform;
import java.util.regex.Pattern;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
/**
* @author Mark McKay
@@ -222,4 +226,77 @@ public class AnimateTransform extends AnimateXform
return xform;
}
+
+ protected void rebuild(AnimTimeParser animTimeParser) throws SVGException
+ {
+ super.rebuild(animTimeParser);
+
+ StyleAttribute sty = new StyleAttribute();
+
+ if (getPres(sty.setName("type")))
+ {
+ String strn = sty.getStringValue().toLowerCase();
+ if (strn.equals("translate")) xformType = TR_TRANSLATE;
+ if (strn.equals("rotate")) xformType = TR_ROTATE;
+ if (strn.equals("scale")) xformType = TR_SCALE;
+ if (strn.equals("skewx")) xformType = TR_SKEWX;
+ if (strn.equals("skewy")) xformType = TR_SKEWY;
+ }
+
+ String fromStrn = null;
+ if (getPres(sty.setName("from")))
+ {
+ fromStrn = sty.getStringValue();
+ }
+
+ String toStrn = null;
+ if (getPres(sty.setName("to")))
+ {
+ toStrn = sty.getStringValue();
+ }
+
+ if (fromStrn != null && toStrn != null)
+ {
+ double[] fromValue = XMLParseUtil.parseDoubleList(fromStrn);
+ fromValue = validate(fromValue);
+
+ double[] toValue = XMLParseUtil.parseDoubleList(toStrn);
+ toValue = validate(toValue);
+
+ values = new double[][]{fromValue, toValue};
+ }
+
+ String keyTimeStrn = null;
+ if (getPres(sty.setName("keyTimes")))
+ {
+ keyTimeStrn = sty.getStringValue();
+ }
+
+ String valuesStrn = null;
+ if (getPres(sty.setName("values")))
+ {
+ valuesStrn = sty.getStringValue();
+ }
+
+ if (keyTimeStrn != null && valuesStrn != null)
+ {
+ keyTimes = XMLParseUtil.parseDoubleList(keyTimeStrn);
+
+ String[] valueList = Pattern.compile(";").split(valuesStrn);
+ values = new double[valueList.length][];
+ for (int i = 0; i < valueList.length; i++)
+ {
+ double[] list = XMLParseUtil.parseDoubleList(valueList[i]);
+ values[i] = validate(list);
+ }
+ }
+
+ //Check our additive state
+
+ if (getPres(sty.setName("additive")))
+ {
+ String strn = sty.getStringValue().toLowerCase();
+ if (strn.equals("sum")) this.additive = AT_SUM;
+ }
+ }
}
diff --git a/src/main/java/com/kitfox/svg/animation/AnimateXform.java b/src/main/java/com/kitfox/svg/animation/AnimateXform.java
index d373d13..f9d0240 100644
--- a/src/main/java/com/kitfox/svg/animation/AnimateXform.java
+++ b/src/main/java/com/kitfox/svg/animation/AnimateXform.java
@@ -26,11 +26,13 @@
package com.kitfox.svg.animation;
-import org.xml.sax.*;
-import java.awt.geom.*;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGLoaderHelper;
+import java.awt.geom.AffineTransform;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
-import com.kitfox.svg.xml.*;
-import com.kitfox.svg.*;
/**
*
diff --git a/src/main/java/com/kitfox/svg/animation/AnimationElement.java b/src/main/java/com/kitfox/svg/animation/AnimationElement.java
index e1c7cd9..7387bca 100644
--- a/src/main/java/com/kitfox/svg/animation/AnimationElement.java
+++ b/src/main/java/com/kitfox/svg/animation/AnimationElement.java
@@ -26,10 +26,16 @@
package com.kitfox.svg.animation;
-import java.io.*;
-import org.xml.sax.*;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.SVGLoaderHelper;
+import com.kitfox.svg.animation.parser.AnimTimeParser;
+import com.kitfox.svg.animation.parser.ParseException;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.io.StringReader;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
-import com.kitfox.svg.*;
/**
* @author Mark McKay
@@ -333,4 +339,76 @@ public abstract class AnimationElement extends SVGElement
{
//Animation elements to not change with time
return false;
- }}
+ }
+
+ public void rebuild() throws SVGException
+ {
+ AnimTimeParser animTimeParser = new AnimTimeParser(new StringReader(""));
+
+ rebuild(animTimeParser);
+ }
+
+ protected void rebuild(AnimTimeParser animTimeParser) throws SVGException
+ {
+ StyleAttribute sty = new StyleAttribute();
+
+ if (getPres(sty.setName("begin")))
+ {
+ String newVal = sty.getStringValue();
+ animTimeParser.ReInit(new StringReader(newVal));
+ try {
+ this.beginTime = animTimeParser.Expr();
+ } catch (ParseException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ if (getPres(sty.setName("dur")))
+ {
+ String newVal = sty.getStringValue();
+ animTimeParser.ReInit(new StringReader(newVal));
+ try {
+ this.durTime = animTimeParser.Expr();
+ } catch (ParseException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ if (getPres(sty.setName("end")))
+ {
+ String newVal = sty.getStringValue();
+ animTimeParser.ReInit(new StringReader(newVal));
+ try {
+ this.endTime = animTimeParser.Expr();
+ } catch (ParseException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ if (getPres(sty.setName("fill")))
+ {
+ String newVal = sty.getStringValue();
+ if (newVal.equals("remove")) this.fillType = FT_REMOVE;
+ if (newVal.equals("freeze")) this.fillType = FT_FREEZE;
+ if (newVal.equals("hold")) this.fillType = FT_HOLD;
+ if (newVal.equals("transiton")) this.fillType = FT_TRANSITION;
+ if (newVal.equals("auto")) this.fillType = FT_AUTO;
+ if (newVal.equals("default")) this.fillType = FT_DEFAULT;
+ }
+
+ if (getPres(sty.setName("additive")))
+ {
+ String newVal = sty.getStringValue();
+ if (newVal.equals("replace")) this.additiveType = AD_REPLACE;
+ if (newVal.equals("sum")) this.additiveType = AD_SUM;
+ }
+
+ if (getPres(sty.setName("accumulate")))
+ {
+ String newVal = sty.getStringValue();
+ if (newVal.equals("replace")) this.accumulateType = AC_REPLACE;
+ if (newVal.equals("sum")) this.accumulateType = AC_SUM;
+ }
+
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/animation/SetSmil.java b/src/main/java/com/kitfox/svg/animation/SetSmil.java
index 3ada7c9..d821d4c 100644
--- a/src/main/java/com/kitfox/svg/animation/SetSmil.java
+++ b/src/main/java/com/kitfox/svg/animation/SetSmil.java
@@ -26,9 +26,14 @@
package com.kitfox.svg.animation;
-import org.xml.sax.*;
+import com.kitfox.svg.SVGElement;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.SVGLoaderHelper;
+import com.kitfox.svg.animation.parser.AnimTimeParser;
+import com.kitfox.svg.xml.StyleAttribute;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
-import com.kitfox.svg.*;
/**
* Set is used to set a textual value; most likely for a style element.
@@ -52,4 +57,17 @@ public class SetSmil extends AnimationElement
toValue = attrs.getValue("to");
}
+
+ protected void rebuild(AnimTimeParser animTimeParser) throws SVGException
+ {
+ super.rebuild(animTimeParser);
+
+ StyleAttribute sty = new StyleAttribute();
+
+ if (getPres(sty.setName("to")))
+ {
+ String newVal = sty.getStringValue();
+ toValue = newVal;
+ }
+ }
}