You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LabelEndFunction.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * 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. /* $Id$ */
  18. package org.apache.fop.fo.expr;
  19. import org.apache.fop.datatypes.Length;
  20. import org.apache.fop.datatypes.LengthBase;
  21. import org.apache.fop.datatypes.Numeric;
  22. import org.apache.fop.fo.Constants;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.flow.ListItem;
  25. import org.apache.fop.fo.properties.PercentLength;
  26. import org.apache.fop.fo.properties.Property;
  27. /**
  28. * Class modelling the label-end Property Value function. See Sec. 5.10.4 of the
  29. * XSL-FO spec.
  30. */
  31. public class LabelEndFunction extends FunctionBase {
  32. /** {@inheritDoc} */
  33. public int getRequiredArgsCount() {
  34. return 0;
  35. }
  36. /** {@inheritDoc} */
  37. public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException {
  38. Length distance = pInfo.getPropertyList().get(
  39. Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS).getLength();
  40. Length separation = pInfo.getPropertyList().getNearestSpecified(
  41. Constants.PR_PROVISIONAL_LABEL_SEPARATION).getLength();
  42. PropertyList pList = pInfo.getPropertyList();
  43. while (pList != null && !(pList.getFObj() instanceof ListItem)) {
  44. pList = pList.getParentPropertyList();
  45. }
  46. if (pList == null) {
  47. throw new PropertyException("label-end() called from outside an fo:list-item");
  48. }
  49. Length startIndent = pList.get(Constants.PR_START_INDENT).getLength();
  50. LengthBase base = new LengthBase(pInfo.getPropertyList(),
  51. LengthBase.CONTAINING_REFAREA_WIDTH);
  52. PercentLength refWidth = new PercentLength(1.0, base);
  53. Numeric labelEnd = distance;
  54. labelEnd = NumericOp.addition(labelEnd, startIndent);
  55. //TODO add start-intrusion-adjustment
  56. labelEnd = NumericOp.subtraction(labelEnd, separation);
  57. labelEnd = NumericOp.subtraction(refWidth, labelEnd);
  58. return (Property) labelEnd;
  59. }
  60. }