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