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 3.1KB

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