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: LabelEndFunction.java 495371 2007-01-11 21:03:07Z adelmelle $ */
19:
20: package org.apache.fop.fo.expr;
21:
22: import org.apache.fop.datatypes.Numeric;
23: import org.apache.fop.datatypes.Length;
24: import org.apache.fop.datatypes.LengthBase;
25: import org.apache.fop.fo.Constants;
26: import org.apache.fop.fo.PropertyList;
27: import org.apache.fop.fo.flow.ListItem;
28: import org.apache.fop.fo.properties.PercentLength;
29: import org.apache.fop.fo.properties.Property;
30:
31: /**
32: * Class modelling the label-end Property Value function. See Sec. 5.10.4 of the
33: * XSL-FO spec.
34: */
35: public class LabelEndFunction extends FunctionBase {
36:
37: /**
38: * @return 0 (the number of arguments required for the label-end function)
39: */
40: public int nbArgs() {
41: return 0;
42: }
43:
44: /**
45: *
46: * @param args array of arguments for the function (none are needed, but
47: * required for the Function interface)
48: * @param pInfo PropertyInfo object for the function
49: * @return the calculated label-end value for the list
50: * @throws PropertyException if called from outside of an fo:list-item
51: */
52: public Property eval(Property[] args, PropertyInfo pInfo)
53: throws PropertyException {
54:
55: Length distance = pInfo.getPropertyList().get(
56: Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS)
57: .getLength();
58: Length separation = pInfo.getPropertyList()
59: .getNearestSpecified(
60: Constants.PR_PROVISIONAL_LABEL_SEPARATION)
61: .getLength();
62:
63: PropertyList pList = pInfo.getPropertyList();
64: while (pList != null && !(pList.getFObj() instanceof ListItem)) {
65: pList = pList.getParentPropertyList();
66: }
67: if (pList == null) {
68: throw new PropertyException(
69: "label-end() called from outside an fo:list-item");
70: }
71: Length startIndent = pList.get(Constants.PR_START_INDENT)
72: .getLength();
73:
74: LengthBase base = new LengthBase(pInfo.getPropertyList(),
75: LengthBase.CONTAINING_REFAREA_WIDTH);
76: PercentLength refWidth = new PercentLength(1.0, base);
77:
78: Numeric labelEnd = distance;
79: labelEnd = NumericOp.addition(labelEnd, startIndent);
80: //TODO add start-intrusion-adjustment
81: labelEnd = NumericOp.subtraction(labelEnd, separation);
82:
83: labelEnd = NumericOp.subtraction(refWidth, labelEnd);
84:
85: return (Property) labelEnd;
86: }
87:
88: }
|