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.

PPColWidthFunction.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.PercentBase;
  20. import org.apache.fop.datatypes.PercentBaseContext;
  21. import org.apache.fop.fo.PropertyList;
  22. import org.apache.fop.fo.flow.table.Table;
  23. import org.apache.fop.fo.properties.Property;
  24. import org.apache.fop.fo.properties.TableColLength;
  25. /**
  26. * Class modelling the proportional-column-width function. See Sec. 5.10.4 of
  27. * the XSL-FO standard.
  28. */
  29. public class PPColWidthFunction extends FunctionBase {
  30. /** {@inheritDoc} */
  31. public int getRequiredArgsCount() {
  32. return 1;
  33. }
  34. @Override
  35. /** {@inheritDoc} */
  36. public PercentBase getPercentBase() {
  37. return new PPColWidthPercentBase();
  38. }
  39. /** {@inheritDoc} */
  40. public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException {
  41. Number d = args[0].getNumber();
  42. if (d == null) {
  43. throw new PropertyException("Non numeric operand to "
  44. + "proportional-column-width() function.");
  45. }
  46. PropertyList pList = pInfo.getPropertyList();
  47. if (!"fo:table-column".equals(pList.getFObj().getName())) {
  48. throw new PropertyException("proportional-column-width() function "
  49. + "may only be used on fo:table-column.");
  50. }
  51. Table t = (Table) pList.getParentFObj();
  52. if (t.isAutoLayout()) {
  53. throw new PropertyException("proportional-column-width() function "
  54. + "may only be used when fo:table has "
  55. + "table-layout=\"fixed\".");
  56. }
  57. return new TableColLength(d.doubleValue(), pInfo.getFO());
  58. }
  59. private static class PPColWidthPercentBase implements PercentBase {
  60. /** {@inheritDoc} */
  61. public int getBaseLength(PercentBaseContext context) throws PropertyException {
  62. return 0;
  63. }
  64. /** {@inheritDoc} */
  65. public double getBaseValue() {
  66. //make sure percentage-arguments are interpreted
  67. //as numerics (1% = 1 * 0.01)
  68. return 1;
  69. }
  70. /** {@inheritDoc} */
  71. public int getDimension() {
  72. return 0;
  73. }
  74. }
  75. }