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.

LengthBase.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.datatypes;
  18. import org.apache.fop.fo.FObj;
  19. import org.apache.fop.fo.Constants;
  20. import org.apache.fop.fo.PropertyList;
  21. /**
  22. * Models a length which can be used as a factor in a percentage length
  23. * calculation
  24. */
  25. public class LengthBase implements PercentBase {
  26. // Standard kinds of percent-based length
  27. /** constant for a custom percent-based length */
  28. public static final int CUSTOM_BASE = 0;
  29. /** constant for a font-size percent-based length */
  30. public static final int FONTSIZE = 1;
  31. /** constant for an inh font-size percent-based length */
  32. public static final int INH_FONTSIZE = 2;
  33. /** constant for a containing box percent-based length */
  34. public static final int CONTAINING_BOX = 3;
  35. /** constant for a containing refarea percent-based length */
  36. public static final int CONTAINING_REFAREA = 4;
  37. /** constant for a containing block percent-based length */
  38. public static final int BLOCK_WIDTH = 5;
  39. /** constant for a containing block percent-based length */
  40. public static final int BLOCK_HEIGHT = 6;
  41. /** array of valid percent-based length types */
  42. public static final int[] PERCENT_BASED_LENGTH_TYPES
  43. = { CUSTOM_BASE, FONTSIZE, INH_FONTSIZE, CONTAINING_BOX,
  44. CONTAINING_REFAREA } ;
  45. /**
  46. * FO parent of the FO for which this property is to be calculated.
  47. */
  48. protected /* final */ FObj parentFO;
  49. /**
  50. * PropertyList for the FO where this property is calculated.
  51. */
  52. private /* final */ PropertyList propertyList;
  53. /**
  54. * One of the defined types of LengthBase
  55. */
  56. private /* final */ int iBaseType;
  57. /**
  58. * Constructor
  59. * @param parentFO parent FO for this
  60. * @param plist property list for this
  61. * @param iBaseType a member of {@link #PERCENT_BASED_LENGTH_TYPES}
  62. */
  63. public LengthBase(FObj parentFO, PropertyList plist, int iBaseType) {
  64. this.parentFO = parentFO;
  65. this.propertyList = plist;
  66. this.iBaseType = iBaseType;
  67. }
  68. /**
  69. * Accessor for parentFO object from subclasses which define
  70. * custom kinds of LengthBase calculations.
  71. * @return this object's parent FO
  72. */
  73. protected FObj getParentFO() {
  74. return parentFO;
  75. }
  76. /**
  77. * Accessor for propertyList object from subclasses which define
  78. * custom kinds of LengthBase calculations.
  79. * @return this object's PropertyList
  80. */
  81. protected PropertyList getPropertyList() {
  82. return propertyList;
  83. }
  84. /**
  85. * @return the dimension of this object (always 1)
  86. */
  87. public int getDimension() {
  88. return 1;
  89. }
  90. /**
  91. * @return the base value of this object (always 1.0)
  92. */
  93. public double getBaseValue() {
  94. return 1.0;
  95. }
  96. /**
  97. * @return the base length (in millipoints ??) of this object
  98. */
  99. public int getBaseLength() {
  100. switch (iBaseType) {
  101. case FONTSIZE:
  102. return propertyList.get(Constants.PR_FONT_SIZE).getLength().getValue();
  103. case INH_FONTSIZE:
  104. return propertyList.getInherited(Constants.PR_FONT_SIZE).getLength().getValue();
  105. case BLOCK_WIDTH:
  106. return parentFO.getLayoutDimension(PercentBase.BLOCK_IPD).intValue();
  107. case BLOCK_HEIGHT:
  108. return parentFO.getLayoutDimension(PercentBase.BLOCK_BPD).intValue();
  109. case CONTAINING_REFAREA: // example: start-indent, end-indent
  110. {
  111. //FONode fo;
  112. //for (fo = parentFO; fo != null && !fo.generatesReferenceAreas();
  113. // fo = fo.getParent());
  114. //return (((fo != null) && (fo instanceof FObj)) ? ((FObj)fo).getContentWidth() : 0);
  115. return 0;
  116. }
  117. case CUSTOM_BASE:
  118. //log.debug("!!! LengthBase.getBaseLength() called on CUSTOM_BASE type !!!");
  119. return 0;
  120. default:
  121. //log.error("Unknown base type for LengthBase.");
  122. return 0;
  123. }
  124. }
  125. }