01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /* $Id$ */
19:
20: package org.apache.fop.fo.expr;
21:
22: import org.apache.fop.apps.FOUserAgent;
23: import org.apache.fop.fo.pagination.ColorProfile;
24: import org.apache.fop.fo.pagination.Declarations;
25: import org.apache.fop.fo.properties.ColorProperty;
26: import org.apache.fop.fo.properties.Property;
27:
28: /**
29: * Implements the rgb-icc() function.
30: */
31: class ICCColorFunction extends FunctionBase {
32:
33: /**
34: * rgb-icc takes a variable number of arguments.
35: * At least 4 should be passed - returns -4
36: * @see org.apache.fop.fo.expr.Function#nbArgs()
37: */
38: public int nbArgs() {
39: return -4;
40: }
41:
42: /** @see org.apache.fop.fo.expr.Function */
43: public Property eval(Property[] args, PropertyInfo pInfo)
44: throws PropertyException {
45: StringBuffer sb = new StringBuffer();
46:
47: // Map color profile NCNAME to src from declarations/color-profile element
48: String colorProfileName = args[3].getString();
49: Declarations decls = pInfo.getFO().getRoot().getDeclarations();
50: ColorProfile cp = decls.getColorProfile(colorProfileName);
51: if (cp == null) {
52: PropertyException pe = new PropertyException("The "
53: + colorProfileName
54: + " color profile was not declared");
55: pe.setPropertyInfo(pInfo);
56: throw pe;
57: }
58: String src = cp.getSrc();
59:
60: // rgb-icc is replaced with fop-rgb-icc which has an extra fifth argument containing the
61: // color profile src attribute as it is defined in the color-profile declarations element.
62: sb.append("fop-rgb-icc(" + args[0]);
63: for (int ix = 1; ix < args.length; ix++) {
64: if (ix == 3) {
65: sb.append("," + colorProfileName);
66: sb.append(",\"" + src + "\"");
67: } else {
68: sb.append("," + args[ix]);
69: }
70: }
71: sb.append(")");
72: FOUserAgent ua = (pInfo == null ? null
73: : (pInfo.getFO() == null ? null : pInfo.getFO()
74: .getUserAgent()));
75: return new ColorProperty(ua, sb.toString());
76: }
77:
78: }
|