diff options
author | kitfox | 2008-02-26 08:24:46 +0100 |
---|---|---|
committer | kitfox | 2008-02-26 08:24:46 +0100 |
commit | 020a2932ddcaba2d128ebcc2fc7a870d27cdab40 (patch) | |
tree | 53a4e23956930b9568dfc0ace6eb717214273883 | |
parent | Changed InputStream readers to handle European characters. Reorganised build... (diff) | |
download | svg-salamander-core-020a2932ddcaba2d128ebcc2fc7a870d27cdab40.tar.gz svg-salamander-core-020a2932ddcaba2d128ebcc2fc7a870d27cdab40.tar.xz svg-salamander-core-020a2932ddcaba2d128ebcc2fc7a870d27cdab40.zip |
Updated color parsing to handle rgb percentages
git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@50 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b
-rw-r--r-- | src/main/java/com/kitfox/svg/xml/ColorTable.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/main/java/com/kitfox/svg/xml/ColorTable.java b/src/main/java/com/kitfox/svg/xml/ColorTable.java index 0afea87..5152823 100644 --- a/src/main/java/com/kitfox/svg/xml/ColorTable.java +++ b/src/main/java/com/kitfox/svg/xml/ColorTable.java @@ -229,15 +229,19 @@ public class ColorTable }
else
{
- final Matcher rgbMatch = Pattern.compile("rgb\\((\\d+),(\\d+),(\\d+)\\)", Pattern.CASE_INSENSITIVE).matcher("");
+ final String number = "\\s*(((\\d+)(\\.\\d*)?)|(\\.\\d+))(%)?\\s*";
+ final Matcher rgbMatch = Pattern.compile("rgb\\(" + number + "," + number + "," + number + "\\)", Pattern.CASE_INSENSITIVE).matcher("");
rgbMatch.reset(val);
if (rgbMatch.matches())
{
- int r = Integer.parseInt(rgbMatch.group(1));
- int g = Integer.parseInt(rgbMatch.group(2));
- int b = Integer.parseInt(rgbMatch.group(3));
- retVal = new Color(r, g, b);
+ float rr = Float.parseFloat(rgbMatch.group(1));
+ float gg = Float.parseFloat(rgbMatch.group(7));
+ float bb = Float.parseFloat(rgbMatch.group(13));
+ rr /= "%".equals(rgbMatch.group(6)) ? 100 : 255;
+ gg /= "%".equals(rgbMatch.group(12)) ? 100 : 255;
+ bb /= "%".equals(rgbMatch.group(18)) ? 100 : 255;
+ retVal = new Color(rr, gg, bb);
}
else
{
|