diff options
author | Jeremias Maerki <jeremias@apache.org> | 2006-02-11 20:23:47 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2006-02-11 20:23:47 +0000 |
commit | ebbf1fb43bc9974f2aead1afd06d6104eec579dd (patch) | |
tree | 31b7018d76128abd1fb2f01cbf8cdf89d9e8eb1f /src/java/org/apache/fop/fo/expr | |
parent | 17094f3329733ab1e0b68b8e9b3c302382572f25 (diff) | |
download | xmlgraphics-fop-ebbf1fb43bc9974f2aead1afd06d6104eec579dd.tar.gz xmlgraphics-fop-ebbf1fb43bc9974f2aead1afd06d6104eec579dd.zip |
Bugzilla #38618:
cleanup of rgb() and implementation of system-color()
Submitted by: Max Berger <max.at.berger.name>
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@377045 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fo/expr')
-rw-r--r-- | src/java/org/apache/fop/fo/expr/PropertyParser.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/expr/RGBColorFunction.java | 29 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/expr/SystemColorFunction.java | 41 |
3 files changed, 51 insertions, 21 deletions
diff --git a/src/java/org/apache/fop/fo/expr/PropertyParser.java b/src/java/org/apache/fop/fo/expr/PropertyParser.java index d08f7631c..67cee2d0c 100644 --- a/src/java/org/apache/fop/fo/expr/PropertyParser.java +++ b/src/java/org/apache/fop/fo/expr/PropertyParser.java @@ -50,6 +50,7 @@ public final class PropertyParser extends PropertyTokenizer { FUNCTION_TABLE.put("max", new MaxFunction()); FUNCTION_TABLE.put("abs", new AbsFunction()); FUNCTION_TABLE.put("rgb", new RGBColorFunction()); + FUNCTION_TABLE.put("system-color", new SystemColorFunction()); FUNCTION_TABLE.put("from-table-column", new FromTableColumnFunction()); FUNCTION_TABLE.put("inherited-property-value", new InheritedPropFunction()); @@ -66,7 +67,6 @@ public final class PropertyParser extends PropertyTokenizer { /** * * NOT YET IMPLEMENTED!!! * FUNCTION_TABLE.put("icc-color", new ICCcolorFunction()); - * FUNCTION_TABLE.put("system-color", new SystemColorFunction()); * FUNCTION_TABLE.put("system-font", new SystemFontFunction()); * * FUNCTION_TABLE.put("merge-property-values", new MergePropsFunction()); diff --git a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java index 4e050bd08..976933d97 100644 --- a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java +++ b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,19 +18,23 @@ package org.apache.fop.fo.expr; - import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.properties.ColorTypeProperty; import org.apache.fop.fo.properties.Property; +/** + * Implements the rgb() function. + */ class RGBColorFunction extends FunctionBase { + + /** @see org.apache.fop.fo.expr.Function#nbArgs() */ public int nbArgs() { return 3; } /** - * Return an object which implements the PercentBase interface. + * @return an object which implements the PercentBase interface. * Percents in arguments to this function are interpreted relative * to 255. */ @@ -38,25 +42,10 @@ class RGBColorFunction extends FunctionBase { return new RGBPercentBase(); } + /** @see org.apache.fop.fo.expr.Function */ public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { - // Using CSS rules, numbers are either supposed to be 0-255 - // or percentage values. If percentages value, they've already - // been converted to reals. - float[] cfvals = new float[3]; // RGB - for (int i = 0; i < 3; i++) { - Number cval = args[i].getNumber(); - if (cval == null) { - throw new PropertyException("Argument to rgb() must be a Number"); - } - float colorVal = cval.floatValue() / 255f; - if (colorVal < 0.0 || colorVal > 255.0) { - throw new PropertyException( - "Arguments to rgb() must normalize to the range 0 to 1"); - } - cfvals[i] = colorVal; - } - return new ColorTypeProperty(cfvals[0], cfvals[1], cfvals[2]); + return new ColorTypeProperty("rgb(" + args[0] + "," + args[1] + "," + args[2] + ")"); } diff --git a/src/java/org/apache/fop/fo/expr/SystemColorFunction.java b/src/java/org/apache/fop/fo/expr/SystemColorFunction.java new file mode 100644 index 000000000..bae217165 --- /dev/null +++ b/src/java/org/apache/fop/fo/expr/SystemColorFunction.java @@ -0,0 +1,41 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.properties.ColorTypeProperty; +import org.apache.fop.fo.properties.Property; + +/** + * Implements the system-color() function. + */ +class SystemColorFunction extends FunctionBase { + + /** @see org.apache.fop.fo.expr.Function#nbArgs() */ + public int nbArgs() { + return 1; + } + + /** @see org.apache.fop.fo.expr.Function */ + public Property eval(Property[] args, + PropertyInfo pInfo) throws PropertyException { + return new ColorTypeProperty("system-color(" + args[0] + ")"); + + } + +} |