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: PPColWidthFunction.java 432362 2006-08-17 19:41:34Z adelmelle $ */
19:
20: package org.apache.fop.fo.expr;
21:
22: import org.apache.fop.fo.PropertyList;
23: import org.apache.fop.fo.flow.Table;
24: import org.apache.fop.fo.properties.Property;
25: import org.apache.fop.fo.properties.TableColLength;
26:
27: /**
28: * Class modelling the proportional-column-width function. See Sec. 5.10.4 of
29: * the XSL-FO standard.
30: */
31: public class PPColWidthFunction extends FunctionBase {
32:
33: /**
34: * @return 1 (the number of arguments for the proportional-column-width
35: * function)
36: */
37: public int nbArgs() {
38: return 1;
39: }
40:
41: /**
42: *
43: * @param args array of arguments for this function
44: * @param pInfo PropertyInfo for this function
45: * @return numeric Property containing the units of proportional measure
46: * for this column
47: * @throws PropertyException for non-numeric operand, or if the parent
48: * element is not a table-column
49: */
50: public Property eval(Property[] args, PropertyInfo pInfo)
51: throws PropertyException {
52: Number d = args[0].getNumber();
53: if (d == null) {
54: throw new PropertyException("Non numeric operand to "
55: + "proportional-column-width() function.");
56: }
57: PropertyList pList = pInfo.getPropertyList();
58: if (!"fo:table-column".equals(pList.getFObj().getName())) {
59: throw new PropertyException(
60: "proportional-column-width() function "
61: + "may only be used on fo:table-column.");
62: }
63:
64: Table t = (Table) pList.getParentFObj();
65: if (t.isAutoLayout()) {
66: throw new PropertyException(
67: "proportional-column-width() function "
68: + "may only be used when fo:table has "
69: + "table-layout=\"fixed\".");
70: }
71: return new TableColLength(d.doubleValue(), pInfo.getFO());
72: }
73:
74: }
|