]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
added stroke-dasharray value list
authorKeiron Liddle <keiron@apache.org>
Mon, 13 Nov 2000 05:14:30 +0000 (05:14 +0000)
committerKeiron Liddle <keiron@apache.org>
Mon, 13 Nov 2000 05:14:30 +0000 (05:14 +0000)
general cleanup

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193794 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/dom/css/CSSStyleDeclarationImpl.java

index 7e4958727c3310ba2703e3dd22d9445f3b95f20a..194add27292c77d628aead69b593d46761591547 100644 (file)
@@ -1,36 +1,36 @@
-/*-- $Id$ -- 
+/*-- $Id$ --
 
  ============================================================================
                    The Apache Software License, Version 1.1
  ============================================================================
+
     Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+
  Redistribution and use in source and binary forms, with or without modifica-
  tion, are permitted provided that the following conditions are met:
+
  1. Redistributions of  source code must  retain the above copyright  notice,
     this list of conditions and the following disclaimer.
+
  2. Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
+
  3. The end-user documentation included with the redistribution, if any, must
     include  the following  acknowledgment:  "This product includes  software
     developed  by the  Apache Software Foundation  (http://www.apache.org/)."
     Alternately, this  acknowledgment may  appear in the software itself,  if
     and wherever such third-party acknowledgments normally appear.
+
  4. The names "FOP" and  "Apache Software Foundation"  must not be used to
     endorse  or promote  products derived  from this  software without  prior
     written permission. For written permission, please contact
     apache@apache.org.
+
  5. Products  derived from this software may not  be called "Apache", nor may
     "Apache" appear  in their name,  without prior written permission  of the
     Apache Software Foundation.
+
  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
  This software  consists of voluntary contributions made  by many individuals
  on  behalf of the Apache Software  Foundation and was  originally created by
- James Tauber <jtauber@jtauber.com>. For more  information on the Apache 
+ James Tauber <jtauber@jtauber.com>. For more  information on the Apache
  Software Foundation, please see <http://www.apache.org/>.
+
  */
 
 package org.apache.fop.dom.css;
@@ -65,246 +65,254 @@ import java.util.*;
  *
  */
 public class CSSStyleDeclarationImpl implements CSSStyleDeclaration {
-       Hashtable table = new Hashtable();
+    Hashtable table = new Hashtable();
 
-       public CSSStyleDeclarationImpl()
-       {
-       }
+    public CSSStyleDeclarationImpl() {
+    }
 
-    public String removeProperty(String str)
-    {
+    public String removeProperty(String str) {
         return null;
     }
 
-    public String getCssText()
-    {
+    public String getCssText() {
         return null;
     }
 
-    public void setCssText(String str)
-    {
-               try {
-               parseStyleText(str);
-               } catch(Exception e) {
-                       e.printStackTrace();
-               }
+    public void setCssText(String str) {
+        try {
+            parseStyleText(str);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    protected void parseStyleText(String len) {
+        StringTokenizer st = new StringTokenizer(len, ";");
+        while (st.hasMoreTokens()) {
+            String str = st.nextToken();
+            int pos;
+            pos = str.indexOf(":");
+            if (pos != -1) {
+                String type = str.substring(0, pos).trim();
+                String value = str.substring(pos + 1, str.length()).trim();
+                if (type.equals("stroke-width")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("stroke")) {
+                    CSSPrimitiveValue primval = new RGBColorValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("color")) {
+                    CSSPrimitiveValue primval = new RGBColorValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("stroke-linecap")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("stroke-linejoin")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("stroke-miterlimit")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("stroke-dasharray")) {
+                    // array of space or comma separated numbers
+                    if (!value.equals("none")) {
+                        CSSValueListImpl list = new CSSValueListImpl();
+                        StringTokenizer array =
+                          new StringTokenizer(value, " ,");
+                        while (array.hasMoreTokens()) {
+                            CSSPrimitiveValue primval = new LengthValue();
+                            primval.setCssText(array.nextToken());
+                            list.addValue(primval);
+                        }
+                        table.put(type, list);
+                    } else {
+                        CSSPrimitiveValue primval = new StringValue();
+                        primval.setCssText(value);
+                        table.put(type, primval);
+                    }
+                } else if (type.equals("stroke-dashoffset")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("stroke-opacity")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("fill")) {
+                    CSSPrimitiveValue primval = new RGBColorValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("fill-rule")) {
+                    // nonzero
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("font")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("font-size")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("font-family")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("font-weight")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("font-style")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("font-variant")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("font-stretch")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("font-size-adjust")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("letter-spacing")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("word-spacing")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("text-decoration")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("mask")) {
+                    CSSPrimitiveValue primval = new URIValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("fill-opacity")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("opacity")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("filter")) {
+                    //                                 table.put(type, new Filter(value));
+                } else if (type.equals("stop-color")) {
+                    CSSPrimitiveValue primval = new RGBColorValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("stop-opacity")) {
+                    CSSPrimitiveValue primval = new LengthValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("overflow")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("clip-rule")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("clip-path")) {
+                    CSSPrimitiveValue primval = new URIValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("clip")) {
+                    CSSPrimitiveValue primval = new URIValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("marker-start")) {
+                    CSSPrimitiveValue primval = new URIValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("marker-mid")) {
+                    CSSPrimitiveValue primval = new URIValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("marker-end")) {
+                    CSSPrimitiveValue primval = new URIValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("text-antialiasing")) {
+                    //                                 boolean
+                } else if (type.equals("stroke-antialiasing")) {
+                    //                                 boolean
+                } else if (type.equals("writing-mode")) {
+                } else if (type.equals("glyph-orientation-vertical")) {
+                } else if (type.equals("glyph-orientation-horizontal")) {
+                } else if (type.equals("direction")) {
+                } else if (type.equals("unicode-bidi")) {
+                } else if (type.equals("text-anchor")) {
+                    CSSPrimitiveValue primval = new StringValue();
+                    primval.setCssText(value);
+                    table.put(type, primval);
+                } else if (type.equals("dominant-baseline")) {
+                } else if (type.equals("baseline-identifier")) {
+                } else if (type.equals("baseline-shift")) {
+                } else if (type.equals("font-size-adjust")) {
+                } else {
+                    MessageHandler.logln(
+                      "WARNING: Unknown style element : " + type);
+                }
+            } else {
+                if (!"".equals(str.trim()))
+                    MessageHandler.errorln(
+                      "ERROR: Invalid style element " + str);
+            }
+        }
     }
 
-       protected void parseStyleText(String len) {
-               StringTokenizer st = new StringTokenizer(len, ";");
-               while(st.hasMoreTokens()) {
-                       String str = st.nextToken();
-                       int pos;
-                       pos = str.indexOf(":");
-                       if(pos != -1) {
-                               String type = str.substring(0, pos).trim();
-                               String value = str.substring(pos + 1, str.length()).trim();
-                               if(type.equals("stroke-width")) {
-                                       CSSPrimitiveValue primval = new LengthValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("stroke")) {
-                                       CSSPrimitiveValue primval = new RGBColorValue();
-                                       primval.setCssText(value);
-                                   table.put(type, primval);
-/*                                     if(value.startsWith("url(")) {
-                                               table.put(type, new String(value));
-                                       } else if(!value.equals("none")) {
-                                               table.put(type, new ColorType(value));
-                                       } else if(value.equals("none")) {
-                                               table.put(type, value);
-                                       }*/
-                               } else if(type.equals("color")) {
-                                       CSSPrimitiveValue primval = new RGBColorValue();
-                                       primval.setCssText(value);
-                                   table.put(type, primval);
-//                                     if(!value.equals("none"))
-//                                             table.put("stroke", new ColorType(value));//??
-//                                     table.put(type, new ColorType(value));//??
-                               } else if(type.equals("stroke-linecap")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("stroke-linejoin")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("stroke-miterlimit")) {
-                                       CSSPrimitiveValue primval = new LengthValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-//                                     table.put(type, new SVGLengthImpl(value));
-                               } else if(type.equals("stroke-dasharray")) {
-                                       // array of space or comma separated numbers
-/*                                     if(!value.equals("none")) {
-                                               Vector list = new Vector();
-                                               StringTokenizer array = new StringTokenizer(value, " ,");
-                                               while(array.hasMoreTokens()) {
-                                                       String intstr = array.nextToken();
-                                                       list.addElement(new Integer(Integer.parseInt(intstr)));
-                                               }
-                                               table.put(type, list);
-                                       }*/
-                                       // else leave ??
-                               } else if(type.equals("stroke-dashoffset")) {
-                                       CSSPrimitiveValue primval = new LengthValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("stroke-opacity")) {
-                               } else if(type.equals("fill")) {
-                                       CSSPrimitiveValue primval = new RGBColorValue();
-                                       primval.setCssText(value);
-                                   table.put(type, primval);
-/*                                     if(value.startsWith("url(")) {
-                                               table.put(type, new String(value));
-                                       } else if(!value.equals("none")) {
-                                               table.put(type, new ColorType(value));
-                                       } else {
-                                               table.put(type, value);
-                                       }*/
-                               } else if(type.equals("fill-rule")) {
-                                       // nonzero
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("font")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("font-size")) {
-                                       CSSPrimitiveValue primval = new LengthValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("font-family")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("font-weight")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("font-style")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("font-variant")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("font-stretch")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("font-size-adjust")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("letter-spacing")) {
-//                                     table.put(type, new SVGLengthImpl(value));
-                               } else if(type.equals("word-spacing")) {
-//                                     table.put(type, new SVGLengthImpl(value));
-                               } else if(type.equals("text-decoration")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("mask")) {
-//                                     if(value.startsWith("url(")) {
-//                                             value = value.substring(4, value.length() - 1);
-//                                     }
-//                                     table.put(type, value);
-                               } else if(type.equals("fill-opacity")) {
-                                       CSSPrimitiveValue primval = new LengthValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-//                                     table.put(type, new SVGLengthImpl(value));
-                               } else if(type.equals("opacity")) {
-                                       CSSPrimitiveValue primval = new LengthValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-//                                     table.put(type, new SVGLengthImpl(value));
-                               } else if(type.equals("filter")) {
-//                                     table.put(type, new Filter(value));
-                               } else if(type.equals("stop-color")) {
-                                       CSSPrimitiveValue primval = new RGBColorValue();
-                                       primval.setCssText(value);
-                                   table.put(type, primval);
-                               } else if(type.equals("marker-start")) {
-//                                     table.put(type, new URLValue(value));
-                               } else if(type.equals("marker-mid")) {
-//                                     table.put(type, new URLValue(value));
-                               } else if(type.equals("marker-end")) {
-//                                     table.put(type, new URLValue(value));
-                               } else if(type.equals("text-antialiasing")) {
-//                                     boolean
-                               } else if(type.equals("stroke-antialiasing")) {
-//                                     boolean
-                               } else if(type.equals("writing-mode")) {
-                               } else if(type.equals("glyph-orientation-vertical")) {
-                               } else if(type.equals("glyph-orientation-horizontal")) {
-                               } else if(type.equals("direction")) {
-                               } else if(type.equals("unicode-bidi")) {
-                               } else if(type.equals("text-anchor")) {
-                                       CSSPrimitiveValue primval = new StringValue();
-                                       primval.setCssText(value);
-                                       table.put(type, primval);
-                               } else if(type.equals("dominant-baseline")) {
-                               } else if(type.equals("baseline-identifier")) {
-                               } else if(type.equals("baseline-shift")) {
-                               } else if(type.equals("font-size-adjust")) {
-                               } else {
-                                       MessageHandler.logln("WARNING: Unknown style element : " + type);
-                               }
-                       } else {
-                               MessageHandler.errorln("ERROR: Invalid style element " + str);
-                       }
-               }
-       }
-
-    public String getPropertyValue(String str)
-    {
+    public String getPropertyValue(String str) {
         return getPropertyCSSValue(str).getCssText();
     }
 
-    public void setProperty(String a, String b, String c)
-    {
+    public void setProperty(String a, String b, String c) {
     }
 
-    public String item(int n)
-    {
+    public String item(int n) {
         return null;
     }
 
-    public CSSRule getParentRule()
-    {
+    public CSSRule getParentRule() {
         return null;
     }
 
-    public String getPropertyPriority(String str)
-    {
+    public String getPropertyPriority(String str) {
         return null;
     }
 
-    public CSSValue getPropertyCSSValue(String str)
-    {
-        return (CSSValue)table.get(str);
+    public CSSValue getPropertyCSSValue(String str) {
+        return (CSSValue) table.get(str);
     }
 
-    public int getLength()
-    {
+    public int getLength() {
         return table.size();
     }
 
     class RGBColorValue extends CSSPrimitiveValueImpl {
         RGBColor col = null;
 
-        public void setCssText(String str)
-        {
+        public void setCssText(String str) {
             super.setCssText(str);
-                       if(str.startsWith("url(")) {
-                           primType = CSS_URI;
-                       } else if(str.equals("currentColor")) {
+            if (str.startsWith("url(")) {
+                primType = CSS_URI;
+            } else if (str.equals("currentColor")) {
                 primType = CSS_STRING;
-                       } else if(!str.equals("none")) {
+            } else if (!str.equals("none")) {
                 float red;
                 float green;
                 float blue;
@@ -319,9 +327,8 @@ public class CSSStyleDeclarationImpl implements CSSStyleDeclaration {
             }
         }
 
-        public RGBColor getRGBColorValue()
-        {
-            if(primType != CSS_RGBCOLOR) {
+        public RGBColor getRGBColorValue() {
+            if (primType != CSS_RGBCOLOR) {
                 // throw exception
             }
             return col;
@@ -329,53 +336,59 @@ public class CSSStyleDeclarationImpl implements CSSStyleDeclaration {
     }
 
     /*
-     * This should probalby be moved to dom.svg...
+     * This should probably be moved to dom.svg...
      */
     class LengthValue extends CSSPrimitiveValueImpl {
 
-        public void setCssText(String str)
-        {
+        public void setCssText(String str) {
             super.setCssText(str);
             SVGLength length = new SVGLengthImpl(str);
             floatVal = length.getValue();
-            switch(length.getUnitType()) {
+            switch (length.getUnitType()) {
                 case SVGLength.SVG_LENGTHTYPE_IN:
                     primType = CSS_IN;
-                break;
+                    break;
                 case SVGLength.SVG_LENGTHTYPE_CM:
                     primType = CSS_CM;
-                break;
+                    break;
                 case SVGLength.SVG_LENGTHTYPE_MM:
                     primType = CSS_MM;
-                break;
+                    break;
                 case SVGLength.SVG_LENGTHTYPE_PT:
                     primType = CSS_PT;
-                break;
+                    break;
                 case SVGLength.SVG_LENGTHTYPE_PC:
                     primType = CSS_PC;
-                break;
+                    break;
                 case SVGLength.SVG_LENGTHTYPE_EMS:
                     primType = CSS_EMS;
-                break;
+                    break;
                 case SVGLength.SVG_LENGTHTYPE_PX:
                     primType = CSS_PX;
-                break;
+                    break;
                 case SVGLength.SVG_LENGTHTYPE_PERCENTAGE:
                     primType = CSS_PERCENTAGE;
-                break;
+                    break;
                 case SVGLength.SVG_LENGTHTYPE_NUMBER:
                     primType = CSS_NUMBER;
-                break;
+                    break;
             }
         }
     }
 
     class StringValue extends CSSPrimitiveValueImpl {
 
-        public void setCssText(String str)
-        {
+        public void setCssText(String str) {
             super.setCssText(str);
             primType = CSS_STRING;
         }
     }
+
+    class URIValue extends CSSPrimitiveValueImpl {
+
+        public void setCssText(String str) {
+            super.setCssText(str);
+            primType = CSS_URI;
+        }
+    }
 }