KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > font > GlyphJustificationInfo


1 /*
2  * @(#)GlyphJustificationInfo.java 1.24 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /*
9  * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
10  * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
11  *
12  * The original version of this source code and documentation is
13  * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
14  * of IBM. These materials are provided under terms of a License
15  * Agreement between Taligent and Sun. This technology is protected
16  * by multiple US and International patents.
17  *
18  * This notice and attribution to Taligent may not be removed.
19  * Taligent is a registered trademark of Taligent, Inc.
20  */

21
22 package java.awt.font;
23
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
59 public final class GlyphJustificationInfo {
60
61     /**
62      * Constructs information about the justification properties of a
63      * glyph.
64      * @param weight the weight of this glyph when allocating space. Must be non-negative.
65      * @param growAbsorb if <code>true</code> this glyph absorbs
66      * all extra space at this priority and lower priority levels when it
67      * grows
68      * @param growPriority the priority level of this glyph when it
69      * grows
70      * @param growLeftLimit the maximum amount by which the left side of this
71      * glyph can grow. Must be non-negative.
72      * @param growRightLimit the maximum amount by which the right side of this
73      * glyph can grow. Must be non-negative.
74      * @param shrinkAbsorb if <code>true</code>, this glyph absorbs all
75      * remaining shrinkage at this and lower priority levels when it
76      * shrinks
77      * @param shrinkPriority the priority level of this glyph when
78      * it shrinks
79      * @param shrinkLeftLimit the maximum amount by which the left side of this
80      * glyph can shrink. Must be non-negative.
81      * @param shrinkRightLimit the maximum amount by which the right side
82      * of this glyph can shrink. Must be non-negative.
83      */

84      public GlyphJustificationInfo(float weight,
85                                   boolean growAbsorb,
86                                   int growPriority,
87                                   float growLeftLimit,
88                                   float growRightLimit,
89                                   boolean shrinkAbsorb,
90                                   int shrinkPriority,
91                                   float shrinkLeftLimit,
92                                   float shrinkRightLimit)
93     {
94         if (weight < 0) {
95             throw new IllegalArgumentException JavaDoc("weight is negative");
96         }
97
98         if (!priorityIsValid(growPriority)) {
99             throw new IllegalArgumentException JavaDoc("Invalid grow priority");
100         }
101         if (growLeftLimit < 0) {
102             throw new IllegalArgumentException JavaDoc("growLeftLimit is negative");
103         }
104         if (growRightLimit < 0) {
105             throw new IllegalArgumentException JavaDoc("growRightLimit is negative");
106         }
107
108         if (!priorityIsValid(shrinkPriority)) {
109             throw new IllegalArgumentException JavaDoc("Invalid shrink priority");
110         }
111         if (shrinkLeftLimit < 0) {
112             throw new IllegalArgumentException JavaDoc("shrinkLeftLimit is negative");
113         }
114         if (shrinkRightLimit < 0) {
115             throw new IllegalArgumentException JavaDoc("shrinkRightLimit is negative");
116         }
117
118         this.weight = weight;
119         this.growAbsorb = growAbsorb;
120         this.growPriority = growPriority;
121         this.growLeftLimit = growLeftLimit;
122         this.growRightLimit = growRightLimit;
123         this.shrinkAbsorb = shrinkAbsorb;
124         this.shrinkPriority = shrinkPriority;
125         this.shrinkLeftLimit = shrinkLeftLimit;
126         this.shrinkRightLimit = shrinkRightLimit;
127     }
128
129     private static boolean priorityIsValid(int priority) {
130
131         return priority >= PRIORITY_KASHIDA && priority <= PRIORITY_NONE;
132     }
133
134     /** The highest justification priority. */
135     public static final int PRIORITY_KASHIDA = 0;
136
137     /** The second highest justification priority. */
138     public static final int PRIORITY_WHITESPACE = 1;
139
140     /** The second lowest justification priority. */
141     public static final int PRIORITY_INTERCHAR = 2;
142
143     /** The lowest justification priority. */
144     public static final int PRIORITY_NONE = 3;
145
146     /**
147      * The weight of this glyph.
148      */

149     public final float weight;
150     
151     /**
152      * The priority level of this glyph as it is growing.
153      */

154     public final int growPriority;
155     
156     /**
157      * If <code>true</code>, this glyph absorbs all extra
158      * space at this and lower priority levels when it grows.
159      */

160     public final boolean growAbsorb;
161     
162     /**
163      * The maximum amount by which the left side of this glyph can grow.
164      */

165     public final float growLeftLimit;
166     
167     /**
168      * The maximum amount by which the right side of this glyph can grow.
169      */

170     public final float growRightLimit;
171     
172     /**
173      * The priority level of this glyph as it is shrinking.
174      */

175     public final int shrinkPriority;
176     
177     /**
178      * If <code>true</code>,this glyph absorbs all remaining shrinkage at
179      * this and lower priority levels as it shrinks.
180      */

181     public final boolean shrinkAbsorb;
182     
183     /**
184      * The maximum amount by which the left side of this glyph can shrink
185      * (a positive number).
186      */

187     public final float shrinkLeftLimit;
188     
189     /**
190      * The maximum amount by which the right side of this glyph can shrink
191      * (a positive number).
192      */

193     public final float shrinkRightLimit;
194 }
195
Popular Tags