1. /*
  2. * @(#)GlyphJustificationInfo.java 1.21 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. /*
  11. * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
  12. * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
  13. *
  14. * The original version of this source code and documentation is
  15. * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
  16. * of IBM. These materials are provided under terms of a License
  17. * Agreement between Taligent and Sun. This technology is protected
  18. * by multiple US and International patents.
  19. *
  20. * This notice and attribution to Taligent may not be removed.
  21. * Taligent is a registered trademark of Taligent, Inc.
  22. */
  23. package java.awt.font;
  24. /**
  25. * The <code>GlyphJustificationInfo</code> class represents information
  26. * about the justification properties of a glyph. A glyph is the visual
  27. * representation of one or more characters. Many different glyphs can
  28. * be used to represent a single character or combination of characters.
  29. * The four justification properties represented by
  30. * <code>GlyphJustificationInfo</code> are weight, priority, absorb and
  31. * limit.
  32. * <p>
  33. * Weight is the overall 'weight' of the glyph in the line. Generally it is
  34. * proportional to the size of the font. Glyphs with larger weight are
  35. * allocated a correspondingly larger amount of the change in space.
  36. * <p>
  37. * Priority determines the justification phase in which this glyph is used.
  38. * All glyphs of the same priority are examined before glyphs of the next
  39. * priority. If all the change in space can be allocated to these glyphs
  40. * without exceeding their limits, then glyphs of the next priority are not
  41. * examined. There are four priorities, kashida, whitespace, interchar,
  42. * and none. KASHIDA is the first priority examined. NONE is the last
  43. * priority examined.
  44. * <p>
  45. * Absorb determines whether a glyph absorbs all change in space. Within a
  46. * given priority, some glyphs may absorb all the change in space. If any of
  47. * these glyphs are present, no glyphs of later priority are examined.
  48. * <p>
  49. * Limit determines the maximum or minimum amount by which the glyph can
  50. * change. Left and right sides of the glyph can have different limits.
  51. * <p>
  52. * Each <code>GlyphJustificationInfo</code> represents two sets of
  53. * metrics, which are <i>growing</i> and <i>shrinking</i>. Growing
  54. * metrics are used when the glyphs on a line are to be
  55. * spread apart to fit a larger width. Shrinking metrics are used when
  56. * the glyphs are to be moved together to fit a smaller width.
  57. */
  58. public final class GlyphJustificationInfo {
  59. /**
  60. * Constructs information about the justification properties of a
  61. * glyph.
  62. * @param weight the weight of this glyph when allocating space. Must be non-negative.
  63. * @param growAbsorb if <code>true</code> this glyph absorbs
  64. * all extra space at this priority and lower priority levels when it
  65. * grows
  66. * @param growPriority the priority level of this glyph when it
  67. * grows
  68. * @param growLeftLimit the maximum amount by which the left side of this
  69. * glyph can grow. Must be non-negative.
  70. * @param growRightLimit the maximum amount by which the right side of this
  71. * glyph can grow. Must be non-negative.
  72. * @param shrinkAbsorb if <code>true</code>, this glyph absorbs all
  73. * remaining shrinkage at this and lower priority levels when it
  74. * shrinks
  75. * @param shrinkPriority the priority level of this glyph when
  76. * it shrinks
  77. * @param shrinkLeftLimit the maximum amount by which the left side of this
  78. * glyph can shrink. Must be non-negative.
  79. * @param shrinkRightLimit the maximum amount by which the right side
  80. * of this glyph can shrink. Must be non-negative.
  81. */
  82. public GlyphJustificationInfo(float weight,
  83. boolean growAbsorb,
  84. int growPriority,
  85. float growLeftLimit,
  86. float growRightLimit,
  87. boolean shrinkAbsorb,
  88. int shrinkPriority,
  89. float shrinkLeftLimit,
  90. float shrinkRightLimit)
  91. {
  92. if (weight < 0) {
  93. throw new IllegalArgumentException("weight is negative");
  94. }
  95. if (!priorityIsValid(growPriority)) {
  96. throw new IllegalArgumentException("Invalid grow priority");
  97. }
  98. if (growLeftLimit < 0) {
  99. throw new IllegalArgumentException("growLeftLimit is negative");
  100. }
  101. if (growRightLimit < 0) {
  102. throw new IllegalArgumentException("growRightLimit is negative");
  103. }
  104. if (!priorityIsValid(shrinkPriority)) {
  105. throw new IllegalArgumentException("Invalid shrink priority");
  106. }
  107. if (shrinkLeftLimit < 0) {
  108. throw new IllegalArgumentException("shrinkLeftLimit is negative");
  109. }
  110. if (shrinkRightLimit < 0) {
  111. throw new IllegalArgumentException("shrinkRightLimit is negative");
  112. }
  113. this.weight = weight;
  114. this.growAbsorb = growAbsorb;
  115. this.growPriority = growPriority;
  116. this.growLeftLimit = growLeftLimit;
  117. this.growRightLimit = growRightLimit;
  118. this.shrinkAbsorb = shrinkAbsorb;
  119. this.shrinkPriority = shrinkPriority;
  120. this.shrinkLeftLimit = shrinkLeftLimit;
  121. this.shrinkRightLimit = shrinkRightLimit;
  122. }
  123. private static boolean priorityIsValid(int priority) {
  124. return priority >= PRIORITY_KASHIDA && priority <= PRIORITY_NONE;
  125. }
  126. /** The highest justification priority. */
  127. public static final int PRIORITY_KASHIDA = 0;
  128. /** The second highest justification priority. */
  129. public static final int PRIORITY_WHITESPACE = 1;
  130. /** The second lowest justification priority. */
  131. public static final int PRIORITY_INTERCHAR = 2;
  132. /** The lowest justification priority. */
  133. public static final int PRIORITY_NONE = 3;
  134. /**
  135. * The weight of this glyph.
  136. */
  137. public final float weight;
  138. /**
  139. * The priority level of this glyph as it is growing.
  140. */
  141. public final int growPriority;
  142. /**
  143. * If <code>true</code>, this glyph absorbs all extra
  144. * space at this and lower priority levels when it grows.
  145. */
  146. public final boolean growAbsorb;
  147. /**
  148. * The maximum amount by which the left side of this glyph can grow.
  149. */
  150. public final float growLeftLimit;
  151. /**
  152. * The maximum amount by which the right side of this glyph can grow.
  153. */
  154. public final float growRightLimit;
  155. /**
  156. * The priority level of this glyph as it is shrinking.
  157. */
  158. public final int shrinkPriority;
  159. /**
  160. * If <code>true</code>,this glyph absorbs all remaining shrinkage at
  161. * this and lower priority levels as it shrinks.
  162. */
  163. public final boolean shrinkAbsorb;
  164. /**
  165. * The maximum amount by which the left side of this glyph can shrink
  166. * (a positive number).
  167. */
  168. public final float shrinkLeftLimit;
  169. /**
  170. * The maximum amount by which the right side of this glyph can shrink
  171. * (a positive number).
  172. */
  173. public final float shrinkRightLimit;
  174. }