aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fo/expr
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/fo/expr')
-rw-r--r--src/java/org/apache/fop/fo/expr/CMYKcolorFunction.java50
-rw-r--r--src/java/org/apache/fop/fo/expr/ICCColorFunction.java77
-rw-r--r--src/java/org/apache/fop/fo/expr/NCnameProperty.java11
-rw-r--r--src/java/org/apache/fop/fo/expr/NumericProperty.java6
-rw-r--r--src/java/org/apache/fop/fo/expr/PropertyParser.java67
-rw-r--r--src/java/org/apache/fop/fo/expr/RGBColorFunction.java6
-rw-r--r--src/java/org/apache/fop/fo/expr/SystemColorFunction.java6
7 files changed, 212 insertions, 11 deletions
diff --git a/src/java/org/apache/fop/fo/expr/CMYKcolorFunction.java b/src/java/org/apache/fop/fo/expr/CMYKcolorFunction.java
new file mode 100644
index 000000000..a66e8492a
--- /dev/null
+++ b/src/java/org/apache/fop/fo/expr/CMYKcolorFunction.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apps.FOUserAgent;
+import org.apache.fop.fo.properties.ColorProperty;
+import org.apache.fop.fo.properties.Property;
+
+/**
+ * Implements the cmyk() function.
+ */
+class CMYKcolorFunction extends FunctionBase {
+
+ /**
+ * cmyk takes four arguments.
+ * @see org.apache.fop.fo.expr.Function#nbArgs()
+ */
+ public int nbArgs() {
+ return 4;
+ }
+
+ /** @see org.apache.fop.fo.expr.Function */
+ public Property eval(Property[] args,
+ PropertyInfo pInfo) throws PropertyException {
+ StringBuffer sb = new StringBuffer();
+ sb.append("cmyk(" + args[0] + "," + args[1] + "," + args[2] + "," + args[3] + ")");
+ FOUserAgent ua = (pInfo == null)
+ ? null
+ : (pInfo.getFO() == null ? null : pInfo.getFO().getUserAgent());
+ return new ColorProperty(ua, sb.toString());
+ }
+
+
+}
diff --git a/src/java/org/apache/fop/fo/expr/ICCColorFunction.java b/src/java/org/apache/fop/fo/expr/ICCColorFunction.java
new file mode 100644
index 000000000..fce073467
--- /dev/null
+++ b/src/java/org/apache/fop/fo/expr/ICCColorFunction.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apps.FOUserAgent;
+import org.apache.fop.fo.pagination.ColorProfile;
+import org.apache.fop.fo.pagination.Declarations;
+import org.apache.fop.fo.properties.ColorProperty;
+import org.apache.fop.fo.properties.Property;
+
+/**
+ * Implements the rgb-icc() function.
+ */
+class ICCColorFunction extends FunctionBase {
+
+ /**
+ * rgb-icc takes a variable number of arguments.
+ * At least 4 should be passed - returns -4
+ * @see org.apache.fop.fo.expr.Function#nbArgs()
+ */
+ public int nbArgs() {
+ return -4;
+ }
+
+ /** @see org.apache.fop.fo.expr.Function */
+ public Property eval(Property[] args,
+ PropertyInfo pInfo) throws PropertyException {
+ StringBuffer sb = new StringBuffer();
+
+ // Map color profile NCNAME to src from declarations/color-profile element
+ String colorProfileName = args[3].getString();
+ Declarations decls = pInfo.getFO().getRoot().getDeclarations();
+ ColorProfile cp = decls.getColorProfile(colorProfileName);
+ if (cp == null) {
+ PropertyException pe = new PropertyException("The " + colorProfileName
+ + " color profile was not declared");
+ pe.setPropertyInfo(pInfo);
+ throw pe;
+ }
+ String src = cp.getSrc();
+
+ // rgb-icc is replaced with fop-rgb-icc which has an extra fifth argument containing the
+ // color profile src attribute as it is defined in the color-profile declarations element.
+ sb.append("fop-rgb-icc(" + args[0]);
+ for (int ix = 1; ix < args.length; ix++) {
+ if (ix == 3) {
+ sb.append("," + colorProfileName);
+ sb.append(",\"" + src + "\"");
+ } else {
+ sb.append("," + args[ix]);
+ }
+ }
+ sb.append(")");
+ FOUserAgent ua = (pInfo == null
+ ? null
+ : (pInfo.getFO() == null ? null : pInfo.getFO().getUserAgent()));
+ return new ColorProperty(ua, sb.toString());
+ }
+
+
+}
diff --git a/src/java/org/apache/fop/fo/expr/NCnameProperty.java b/src/java/org/apache/fop/fo/expr/NCnameProperty.java
index 7188fb953..8e2f8e27f 100644
--- a/src/java/org/apache/fop/fo/expr/NCnameProperty.java
+++ b/src/java/org/apache/fop/fo/expr/NCnameProperty.java
@@ -21,6 +21,7 @@ package org.apache.fop.fo.expr;
import java.awt.Color;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.properties.Property;
import org.apache.fop.util.ColorUtil;
@@ -42,13 +43,17 @@ public class NCnameProperty extends Property {
/**
* If a system color, return the corresponding value.
*
+ * @param foUserAgent
+ * Reference to FOP user agent - keeps track of cached ColorMaps for ICC colors
* @return Color object corresponding to the NCName
*/
- public Color getColor() {
+ public Color getColor(FOUserAgent foUserAgent) {
try {
- return ColorUtil.parseColorString(ncName);
+ return ColorUtil.parseColorString(foUserAgent, ncName);
} catch (PropertyException e) {
- //TODO: This should probably print an error message?
+ //Not logging this error since for properties like "border" you would get an awful
+ //lot of error messages for things like "solid" not being valid colors.
+ //log.error("Can't create color value: " + e.getMessage());
return null;
}
}
diff --git a/src/java/org/apache/fop/fo/expr/NumericProperty.java b/src/java/org/apache/fop/fo/expr/NumericProperty.java
index f00b9951c..4c112964d 100644
--- a/src/java/org/apache/fop/fo/expr/NumericProperty.java
+++ b/src/java/org/apache/fop/fo/expr/NumericProperty.java
@@ -20,6 +20,8 @@
package org.apache.fop.fo.expr;
import java.awt.Color;
+
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.PercentBaseContext;
import org.apache.fop.datatypes.Numeric;
@@ -105,8 +107,8 @@ public class NumericProperty extends Property implements Numeric, Length {
return null;
}
- /** @see org.apache.fop.fo.properties.Property#getColor() */
- public Color getColor() {
+ /** @see org.apache.fop.fo.properties.Property#getColor(FOUserAgent) */
+ public Color getColor(FOUserAgent foUserAgent) {
// TODO: try converting to numeric number and then to color
return null;
}
diff --git a/src/java/org/apache/fop/fo/expr/PropertyParser.java b/src/java/org/apache/fop/fo/expr/PropertyParser.java
index 699094cc7..5b5956f44 100644
--- a/src/java/org/apache/fop/fo/expr/PropertyParser.java
+++ b/src/java/org/apache/fop/fo/expr/PropertyParser.java
@@ -19,6 +19,7 @@
package org.apache.fop.fo.expr;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.datatypes.Numeric;
import org.apache.fop.datatypes.PercentBase;
import org.apache.fop.fo.properties.ColorProperty;
@@ -30,6 +31,8 @@ import org.apache.fop.fo.properties.Property;
import org.apache.fop.fo.properties.StringProperty;
import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
/**
* Class to parse XSL-FO property expressions.
@@ -62,12 +65,12 @@ public final class PropertyParser extends PropertyTokenizer {
new PPColWidthFunction());
FUNCTION_TABLE.put("label-end", new LabelEndFunction());
FUNCTION_TABLE.put("body-start", new BodyStartFunction());
+ FUNCTION_TABLE.put("rgb-icc", new ICCColorFunction());
+ FUNCTION_TABLE.put("cmyk", new CMYKcolorFunction()); //non-standard!!!
/**
* * NOT YET IMPLEMENTED!!!
- * FUNCTION_TABLE.put("icc-color", new ICCcolorFunction());
* FUNCTION_TABLE.put("system-font", new SystemFontFunction());
- *
* FUNCTION_TABLE.put("merge-property-values", new MergePropsFunction());
*/
}
@@ -295,7 +298,10 @@ public final class PropertyParser extends PropertyTokenizer {
break;
case TOK_COLORSPEC:
- prop = new ColorProperty(currentTokenValue);
+ FOUserAgent ua = (propInfo == null)
+ ? null
+ : (propInfo.getFO() == null ? null : propInfo.getFO().getUserAgent());
+ prop = new ColorProperty(ua, currentTokenValue);
break;
case TOK_FUNCTION_LPAR:
@@ -307,7 +313,12 @@ public final class PropertyParser extends PropertyTokenizer {
next();
// Push new function (for function context: getPercentBase())
propInfo.pushFunction(function);
- prop = function.eval(parseArgs(function), propInfo);
+ if (function.nbArgs() < 0) {
+ // Negative nbArgs --> function with variable number of arguments
+ prop = function.eval(parseVarArgs(function), propInfo);
+ } else {
+ prop = function.eval(parseArgs(function), propInfo);
+ }
propInfo.popFunction();
return prop;
@@ -362,6 +373,54 @@ public final class PropertyParser extends PropertyTokenizer {
}
return args;
}
+
+ /**
+ *
+ * Parse a comma separated list of function arguments. Each argument
+ * may itself be an expression. This method consumes the closing right
+ * parenthesis of the argument list.
+ *
+ * The method differs from parseArgs in that it accepts a variable
+ * number of arguments.
+ *
+ * @param function The function object for which the arguments are
+ * collected.
+ * @return An array of Property objects representing the arguments
+ * found.
+ * @throws PropertyException If the number of arguments found isn't equal
+ * to the number expected.
+ *
+ * TODO Merge this with parseArgs?
+ */
+ Property[] parseVarArgs(Function function) throws PropertyException {
+ // For variable argument functions the minimum number of arguments is returned as a
+ // negative integer from the nbArgs method
+ int nbArgs = -function.nbArgs();
+ List args = new LinkedList();
+ Property prop;
+ if (currentToken == TOK_RPAR) {
+ // No args: func()
+ next();
+ } else {
+ while (true) {
+ prop = parseAdditiveExpr();
+ args.add(prop);
+ // ignore extra args
+ if (currentToken != TOK_COMMA) {
+ break;
+ }
+ next();
+ }
+ expectRpar();
+ }
+ if (nbArgs > args.size()) {
+ throw new PropertyException("Expected at least " + nbArgs
+ + ", but got " + args.size() + " args for function");
+ }
+ Property[] propArray = new Property[args.size()];
+ args.toArray(propArray);
+ return propArray;
+ }
/**
diff --git a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java
index d74d1b7f4..805d8014f 100644
--- a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java
+++ b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java
@@ -19,6 +19,7 @@
package org.apache.fop.fo.expr;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.datatypes.PercentBaseContext;
import org.apache.fop.datatypes.PercentBase;
import org.apache.fop.fo.properties.ColorProperty;
@@ -46,7 +47,10 @@ class RGBColorFunction extends FunctionBase {
/** @see org.apache.fop.fo.expr.Function */
public Property eval(Property[] args,
PropertyInfo pInfo) throws PropertyException {
- return new ColorProperty("rgb(" + args[0] + "," + args[1] + "," + args[2] + ")");
+ FOUserAgent ua = (pInfo == null)
+ ? null
+ : (pInfo.getFO() == null ? null : pInfo.getFO().getUserAgent());
+ return new ColorProperty(ua, "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
index 678a56ef8..ea9e4562e 100644
--- a/src/java/org/apache/fop/fo/expr/SystemColorFunction.java
+++ b/src/java/org/apache/fop/fo/expr/SystemColorFunction.java
@@ -19,6 +19,7 @@
package org.apache.fop.fo.expr;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.properties.ColorProperty;
import org.apache.fop.fo.properties.Property;
@@ -35,7 +36,10 @@ class SystemColorFunction extends FunctionBase {
/** @see org.apache.fop.fo.expr.Function */
public Property eval(Property[] args,
PropertyInfo pInfo) throws PropertyException {
- return new ColorProperty("system-color(" + args[0] + ")");
+ FOUserAgent ua = (pInfo == null)
+ ? null
+ : (pInfo.getFO() == null ? null : pInfo.getFO().getUserAgent());
+ return new ColorProperty(ua, "system-color(" + args[0] + ")");
}