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: BodyStartFunction.java 426576 2006-07-28 15:44:37Z jeremias $ */
19:
20: package org.apache.fop.fo.expr;
21:
22: import org.apache.fop.datatypes.Numeric;
23: import org.apache.fop.fo.Constants;
24: import org.apache.fop.fo.PropertyList;
25: import org.apache.fop.fo.flow.ListItem;
26: import org.apache.fop.fo.properties.Property;
27:
28: /**
29: * Class corresponding to the body-start Property Value function. See Sec.
30: * 5.10.4 of the XSL-FO spec.
31: */
32: public class BodyStartFunction extends FunctionBase {
33:
34: /**
35: * @return 0 (there are no arguments for body-start)
36: */
37: public int nbArgs() {
38: return 0;
39: }
40:
41: /**
42: * @param args array of arguments (none are used, but this is required by
43: * the Function interface)
44: * @param pInfo PropertyInfo object to be evaluated
45: * @return numeric object containing the calculated body-start value
46: * @throws PropertyException if called from outside of an fo:list-item
47: */
48: public Property eval(Property[] args, PropertyInfo pInfo)
49: throws PropertyException {
50: Numeric distance = pInfo.getPropertyList().get(
51: Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS)
52: .getNumeric();
53:
54: PropertyList pList = pInfo.getPropertyList();
55: while (pList != null && !(pList.getFObj() instanceof ListItem)) {
56: pList = pList.getParentPropertyList();
57: }
58: if (pList == null) {
59: throw new PropertyException(
60: "body-start() called from outside an fo:list-item");
61: }
62:
63: Numeric startIndent = pList.get(Constants.PR_START_INDENT)
64: .getNumeric();
65:
66: return (Property) NumericOp.addition(distance, startIndent);
67: }
68:
69: }
|