You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by ca...@apache.org on 2006/08/02 10:59:47 UTC

svn commit: r427932 - /xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/

Author: cam
Date: Wed Aug  2 01:59:46 2006
New Revision: 427932

URL: http://svn.apache.org/viewvc?rev=427932&view=rev
Log:
1. Fixed problem with animating CSS properties where values would be
   stringified using scientific notation instead of plain decimal.
2. o.a.b.anim package now does not depend on anything in o.a.b.dom.svg.

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableAngleValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthListValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableMotionPointValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOptionalNumberValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOrPercentageValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePathDataValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePreserveAspectRatioValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableRectValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableTransformListValue.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableValue.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableAngleValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableAngleValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableAngleValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableAngleValue.java Wed Aug  2 01:59:46 2006
@@ -30,6 +30,13 @@
 public class AnimatableAngleValue extends AnimatableNumberValue {
 
     /**
+     * The unit string representations.
+     */
+    protected final static String[] UNITS = {
+        "", "", "deg", "rad", "grad"
+    };
+
+    /**
      * The angle unit.
      */
     protected short unit;
@@ -116,6 +123,13 @@
     public AnimatableValue getZeroValue() {
         return new AnimatableAngleValue
             (target, 0, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
+    }
+
+    /**
+     * Returns the CSS text representation of the value.
+     */
+    public String getCssText() {
+        return super.getCssText() + UNITS[unit];
     }
 
     /**

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthListValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthListValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthListValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthListValue.java Wed Aug  2 01:59:46 2006
@@ -210,20 +210,12 @@
     public String getCssText() {
         StringBuffer sb = new StringBuffer();
         if (lengthValues.length > 0) {
-            String s = String.valueOf(lengthValues[0]);
-            if (s.endsWith(".0")) {
-                s = s.substring(0, s.length() - 2);
-            }
-            sb.append(s);
+            sb.append(formatNumber(lengthValues[0]));
             sb.append(AnimatableLengthValue.UNITS[lengthTypes[0] - 1]);
         }
         for (int i = 1; i < lengthValues.length; i++) {
             sb.append(',');
-            String s = String.valueOf(lengthValues[i]);
-            if (s.endsWith(".0")) {
-                s = s.substring(0, s.length() - 2);
-            }
-            sb.append(s);
+            sb.append(formatNumber(lengthValues[i]));
             sb.append(AnimatableLengthValue.UNITS[lengthTypes[i] - 1]);
         }
         return sb.toString();

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableLengthValue.java Wed Aug  2 01:59:46 2006
@@ -208,10 +208,6 @@
      * want a dependency on the CSS package.
      */
     public String getCssText() {
-        String s = String.valueOf(lengthValue);
-        if (s.endsWith(".0")) {
-            s = s.substring(0, s.length() - 2);
-        }
-        return s + UNITS[lengthType - 1];
+        return formatNumber(lengthValue) + UNITS[lengthType - 1];
     }
 }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableMotionPointValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableMotionPointValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableMotionPointValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableMotionPointValue.java Wed Aug  2 01:59:46 2006
@@ -153,30 +153,16 @@
     }
 
     /**
-     * Returns the CSS text representation of the value.
+     * Returns a string representation of this object.
      */
-    public String getCssText() {
+    public String toStringRep() {
         StringBuffer sb = new StringBuffer();
-        String s = Float.toString(x);
-        if (s.endsWith(".0")) {
-            sb.append(s.substring(0, s.length() - 2));
-        } else {
-            sb.append(s);
-        }
+        sb.append(formatNumber(x));
         sb.append(',');
-        s = Float.toString(y);
-        if (s.endsWith(".0")) {
-            sb.append(s.substring(0, s.length() - 2));
-        } else {
-            sb.append(s);
-        }
+        sb.append(formatNumber(y));
         sb.append(',');
-        s = Float.toString(angle);
-        if (s.endsWith(".0")) {
-            sb.append(s.substring(0, s.length() - 2));
-        } else {
-            sb.append(s);
-        }
+        sb.append(formatNumber(angle));
+        sb.append("rad");
         return sb.toString();
     }
 }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOptionalNumberValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOptionalNumberValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOptionalNumberValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOptionalNumberValue.java Wed Aug  2 01:59:46 2006
@@ -163,20 +163,10 @@
      */
     public String getCssText() {
         StringBuffer sb = new StringBuffer();
-        String s = Float.toString(number);
-        if (s.endsWith(".0")) {
-            sb.append(s.substring(0, s.length() - 2));
-        } else {
-            sb.append(s);
-        }
+        sb.append(formatNumber(number));
         if (hasOptionalNumber) {
             sb.append(' ');
-            s = Float.toString(optionalNumber);
-            if (s.endsWith(".0")) {
-                sb.append(s.substring(0, s.length() - 2));
-            } else {
-                sb.append(s);
-            }
+            sb.append(formatNumber(optionalNumber));
         }
         return sb.toString();
     }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOrPercentageValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOrPercentageValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOrPercentageValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberOrPercentageValue.java Wed Aug  2 01:59:46 2006
@@ -145,12 +145,7 @@
      */
     public String getCssText() {
         StringBuffer sb = new StringBuffer();
-        String s = Float.toString(value);
-        if (s.endsWith(".0")) {
-            sb.append(s.substring(0, s.length() - 2));
-        } else {
-            sb.append(s);
-        }
+        sb.append(formatNumber(value));
         if (isPercentage) {
             sb.append('%');
         }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableNumberValue.java Wed Aug  2 01:59:46 2006
@@ -114,10 +114,6 @@
      * Returns the CSS text representation of the value.
      */
     public String getCssText() {
-        String s = Float.toString(value);
-        if (s.endsWith(".0")) {
-            return s.substring(0, s.length() - 2);
-        }
-        return s;
+        return formatNumber(value);
     }
 }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePathDataValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePathDataValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePathDataValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePathDataValue.java Wed Aug  2 01:59:46 2006
@@ -165,9 +165,33 @@
     }
 
     /**
-     * Returns the CSS text representation of the value.
+     * The path data commands.
      */
-    public String getCssText() {
-        return null;
+    protected static final char[] PATH_COMMANDS = {
+        ' ', 'z', 'M', 'm', 'L', 'l', 'C', 'c', 'Q', 'q', 'A', 'a', 'H', 'h',
+        'V', 'v', 'S', 's', 'T', 't'
+    };
+
+    /**
+     * The number of parameters for each path command.
+     */
+    protected static final int[] PATH_PARAMS = {
+        0, 0, 2, 2, 2, 2, 6, 6, 4, 4, 7, 7, 1, 1, 1, 1, 4, 4, 2, 2
+    };
+
+    /**
+     * Returns a string representation of this object.
+     */
+    public String toStringRep() {
+        StringBuffer sb = new StringBuffer();
+        int k = 0;
+        for (int i = 0; i < commands.length; i++) {
+            sb.append(PATH_COMMANDS[commands[i]]);
+            for (int j = 0; j < PATH_PARAMS[commands[i]]; j++) {
+                sb.append(' ');
+                sb.append(parameters[k++]);
+            }
+        }
+        return sb.toString();
     }
 }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePreserveAspectRatioValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePreserveAspectRatioValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePreserveAspectRatioValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatablePreserveAspectRatioValue.java Wed Aug  2 01:59:46 2006
@@ -18,7 +18,7 @@
 package org.apache.batik.anim.values;
 
 import org.apache.batik.anim.AnimationTarget;
-import org.apache.batik.dom.svg.AbstractSVGPreserveAspectRatio;
+import org.apache.batik.util.SVGConstants;
 
 import org.w3c.dom.svg.SVGPreserveAspectRatio;
 
@@ -29,6 +29,32 @@
  * @version $Id$
  */
 public class AnimatablePreserveAspectRatioValue extends AnimatableValue {
+    
+    /**
+     * Strings for the 'align' values.
+     */
+    protected static final String[] ALIGN_VALUES = {
+        null,
+        SVGConstants.SVG_NONE_VALUE,
+        SVGConstants.SVG_XMINYMIN_VALUE,
+        SVGConstants.SVG_XMIDYMIN_VALUE,
+        SVGConstants.SVG_XMAXYMIN_VALUE,
+        SVGConstants.SVG_XMINYMID_VALUE,
+        SVGConstants.SVG_XMIDYMID_VALUE,
+        SVGConstants.SVG_XMAXYMID_VALUE,
+        SVGConstants.SVG_XMINYMAX_VALUE,
+        SVGConstants.SVG_XMIDYMAX_VALUE,
+        SVGConstants.SVG_XMAXYMAX_VALUE
+    };
+
+    /**
+     * Strings for the 'meet-or-slice' values.
+     */
+    protected static final String[] MEET_OR_SLICE_VALUES = {
+        null,
+        SVGConstants.SVG_MEET_VALUE,
+        SVGConstants.SVG_SLICE_VALUE
+    };
 
     /**
      * The align value.
@@ -131,10 +157,19 @@
     }
 
     /**
-     * Returns the CSS text representation of the value.
+     * Returns a string representation of this object.
      */
-    public String getCssText() {
-        return AbstractSVGPreserveAspectRatio.getValueAsString
-            (align, meetOrSlice);
+    public String toStringRep() {
+        if (align < 1 || align > 10) {
+            return null;
+        }
+        String value = ALIGN_VALUES[align];
+        if (align == SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE) {
+            return value;
+        }
+        if (meetOrSlice < 1 || meetOrSlice > 2) {
+            return null;
+        }
+        return value + ' ' + MEET_OR_SLICE_VALUES[meetOrSlice];
     }
 }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableRectValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableRectValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableRectValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableRectValue.java Wed Aug  2 01:59:46 2006
@@ -158,9 +158,17 @@
     }
 
     /**
-     * Returns the CSS text representation of the value.
+     * Returns a string representation of this object.
      */
-    public String getCssText() {
-        return null;
+    public String toStringRep() {
+        StringBuffer sb = new StringBuffer();
+        sb.append(x);
+        sb.append(',');
+        sb.append(y);
+        sb.append(',');
+        sb.append(width);
+        sb.append(',');
+        sb.append(height);
+        return sb.toString();
     }
 }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableTransformListValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableTransformListValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableTransformListValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableTransformListValue.java Wed Aug  2 01:59:46 2006
@@ -261,8 +261,9 @@
 
     /**
      * Returns the CSS text representation of the value.
+     * XXX To be done; not so important, just for debugging.
      */
-    public String getCssText() {
+    public String toStringRep() {
         return null;
     }
 }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableValue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableValue.java?rev=427932&r1=427931&r2=427932&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableValue.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/anim/values/AnimatableValue.java Wed Aug  2 01:59:46 2006
@@ -17,6 +17,8 @@
  */
 package org.apache.batik.anim.values;
 
+import java.text.DecimalFormat;
+
 import org.apache.batik.anim.AnimationTarget;
 
 /**
@@ -28,6 +30,12 @@
 public abstract class AnimatableValue {
 
     /**
+     * A formatting object to get CSS compatible float strings.
+     */
+    protected static DecimalFormat decimalFormat = new DecimalFormat
+        ("0.0###########################################################");
+
+    /**
      * The target of the animation.
      */
     protected AnimationTarget target;
@@ -47,6 +55,13 @@
     }
 
     /**
+     * Returns a CSS compatible string version of the specified float.
+     */
+    public static String formatNumber(float f) {
+        return decimalFormat.format(f);
+    }
+
+    /**
      * Performs interpolation to the given value.
      * @param result the object in which to store the result of the
      *               interpolation, or null if a new object should be created
@@ -84,7 +99,9 @@
     /**
      * Returns the CSS text representation of the value.
      */
-    public abstract String getCssText();
+    public String getCssText() {
+        return null;
+    }
     
     /**
      * Returns whether the value in this AnimatableValue has been modified.
@@ -96,9 +113,18 @@
     }
 
     /**
-     * Returns a string representation of this object.
+     * Returns a string representation of this object.  This should be
+     * overridden in classes that do not have a CSS representation.
+     */
+    public String toStringRep() {
+        return getCssText();
+    }
+
+    /**
+     * Returns a string representation of this object prefixed with its
+     * class name.
      */
     public String toString() {
-        return getClass().getName() + "[" + getCssText() + "]";
+        return getClass().getName() + "[" + toStringRep() + "]";
     }
 }