]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
This is Kieron's patch to allow percentage specified colors. Shouldn't
authorSteve Coffman <gears@apache.org>
Mon, 17 Apr 2000 19:07:31 +0000 (19:07 +0000)
committerSteve Coffman <gears@apache.org>
Mon, 17 Apr 2000 19:07:31 +0000 (19:07 +0000)
affect any existing stuff.

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

src/org/apache/fop/datatypes/ColorType.java

index 5c99d044a260f5bc694c0fe23e48d35dabb5d6e2..036f201901f88215aef93271383f0a4e7effada7 100644 (file)
@@ -50,6 +50,8 @@
  */
 package org.apache.fop.datatypes;
 
+import java.util.*;
+
 /**
  * a colour quantity in XSL
  */
@@ -96,6 +98,46 @@ public class ColorType {
                this.blue = 0;
                System.err.println("ERROR: unknown colour format. Must be #RGB or #RRGGBB");
            }
+       } else if (value.startsWith("rgb(")) {
+               int poss = value.indexOf("(");
+               int pose = value.indexOf(")");
+               if(poss != -1 && pose != -1) {
+                       value = value.substring(poss + 1, pose);
+                       StringTokenizer st = new StringTokenizer(value, ",");
+                       try {
+                               if(st.hasMoreTokens()) {
+                                       String str = st.nextToken().trim();
+                                       if(str.endsWith("%")) {
+                                               this.red = Integer.parseInt(str.substring(0, str.length() - 1)) * 2.55f;
+                                       } else {
+                                           this.red = Integer.parseInt(str)/255f;
+                                   }
+                               }
+                               if(st.hasMoreTokens()) {
+                                       String str = st.nextToken().trim();
+                                       if(str.endsWith("%")) {
+                                               this.green = Integer.parseInt(str.substring(0, str.length() - 1)) * 2.55f;
+                                       } else {
+                                           this.green = Integer.parseInt(str)/255f;
+                                   }
+                               }
+                               if(st.hasMoreTokens()) {
+                                       String str = st.nextToken().trim();
+                                       if(str.endsWith("%")) {
+                                               this.blue = Integer.parseInt(str.substring(0, str.length() - 1)) * 2.55f;
+                                       } else {
+                                           this.blue = Integer.parseInt(str)/255f;
+                                   }
+                               }
+                   } catch (Exception e) {
+                               this.red = 0;
+                               this.green = 0;
+                               this.blue = 0;
+                               System.err.println("ERROR: unknown colour format. Must be #RGB or #RRGGBB");
+                   }
+           }
+       } else if (value.startsWith("url(")) {
+               // refers to a gradient
        } else {
            if (value.toLowerCase().equals("black")) {
                this.red = 0;