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: RGBColorFunction.java 474225 2006-11-13 10:08:19Z jeremias $ */
19:
20: package org.apache.fop.fo.expr;
21:
22: import org.apache.fop.apps.FOUserAgent;
23: import org.apache.fop.datatypes.PercentBaseContext;
24: import org.apache.fop.datatypes.PercentBase;
25: import org.apache.fop.fo.properties.ColorProperty;
26: import org.apache.fop.fo.properties.Property;
27:
28: /**
29: * Implements the rgb() function.
30: */
31: class RGBColorFunction extends FunctionBase {
32:
33: /** @see org.apache.fop.fo.expr.Function#nbArgs() */
34: public int nbArgs() {
35: return 3;
36: }
37:
38: /**
39: * @return an object which implements the PercentBase interface.
40: * Percents in arguments to this function are interpreted relative
41: * to 255.
42: */
43: public PercentBase getPercentBase() {
44: return new RGBPercentBase();
45: }
46:
47: /** @see org.apache.fop.fo.expr.Function */
48: public Property eval(Property[] args, PropertyInfo pInfo)
49: throws PropertyException {
50: FOUserAgent ua = (pInfo == null) ? null
51: : (pInfo.getFO() == null ? null : pInfo.getFO()
52: .getUserAgent());
53: return new ColorProperty(ua, "rgb(" + args[0] + "," + args[1]
54: + "," + args[2] + ")");
55:
56: }
57:
58: static class RGBPercentBase implements PercentBase {
59: public int getDimension() {
60: return 0;
61: }
62:
63: public double getBaseValue() {
64: return 255f;
65: }
66:
67: public int getBaseLength(PercentBaseContext context) {
68: return 0;
69: }
70:
71: }
72: }
|