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.

LengthProperty.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.properties;
  19. import org.apache.fop.datatypes.Length;
  20. import org.apache.fop.datatypes.Numeric;
  21. import org.apache.fop.fo.FObj;
  22. import org.apache.fop.fo.PropertyList;
  23. import org.apache.fop.fo.expr.PropertyException;
  24. /**
  25. * Superclass for properties wrapping a Length value.
  26. */
  27. public abstract class LengthProperty extends Property
  28. implements Length, Numeric {
  29. /**
  30. * Inner class for making instances of LengthProperty
  31. */
  32. public static class Maker extends PropertyMaker {
  33. /**
  34. * Constructor
  35. *
  36. * @param propId the id of the property for which a Maker should be created
  37. */
  38. public Maker(int propId) {
  39. super(propId);
  40. }
  41. /** {@inheritDoc} */
  42. public Property convertProperty(Property p,
  43. PropertyList propertyList,
  44. FObj fo) throws PropertyException {
  45. if (p instanceof EnumProperty) {
  46. return new EnumLength(p);
  47. }
  48. if (p instanceof LengthProperty) {
  49. return p;
  50. }
  51. if (p instanceof NumberProperty) {
  52. //Assume pixels (like in HTML) when there's no unit
  53. return FixedLength.getInstance(
  54. p.getNumeric().getNumericValue(), "px",
  55. propertyList.getFObj().getUserAgent().getSourceResolution() / 72.0f);
  56. }
  57. Length val = p.getLength();
  58. if (val != null) {
  59. return (Property) val;
  60. }
  61. /* always null ?? */
  62. return convertPropertyDatatype(p, propertyList, fo);
  63. }
  64. }
  65. /** @return the numeric dimension. Length always a dimension of 1 */
  66. public int getDimension() {
  67. return 1;
  68. }
  69. /** @return this.length cast as a Numeric */
  70. public Numeric getNumeric() {
  71. return this;
  72. }
  73. /** @return this.length */
  74. public Length getLength() {
  75. return this;
  76. }
  77. /** @return this.length cast as an Object */
  78. public Object getObject() {
  79. return this;
  80. }
  81. }