View Javadoc
1   /*
2    * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  /*
27   * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
28   * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
29   *
30   * The original version of this source code and documentation is
31   * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
32   * of IBM. These materials are provided under terms of a License
33   * Agreement between Taligent and Sun. This technology is protected
34   * by multiple US and International patents.
35   *
36   * This notice and attribution to Taligent may not be removed.
37   * Taligent is a registered trademark of Taligent, Inc.
38   */
39  
40  package java.awt.font;
41  
42  /**
43   * The <code>GlyphJustificationInfo</code> class represents information
44   * about the justification properties of a glyph.  A glyph is the visual
45   * representation of one or more characters.  Many different glyphs can
46   * be used to represent a single character or combination of characters.
47   * The four justification properties represented by
48   * <code>GlyphJustificationInfo</code> are weight, priority, absorb and
49   * limit.
50   * <p>
51   * Weight is the overall 'weight' of the glyph in the line.  Generally it is
52   * proportional to the size of the font.  Glyphs with larger weight are
53   * allocated a correspondingly larger amount of the change in space.
54   * <p>
55   * Priority determines the justification phase in which this glyph is used.
56   * All glyphs of the same priority are examined before glyphs of the next
57   * priority.  If all the change in space can be allocated to these glyphs
58   * without exceeding their limits, then glyphs of the next priority are not
59   * examined. There are four priorities, kashida, whitespace, interchar,
60   * and none.  KASHIDA is the first priority examined. NONE is the last
61   * priority examined.
62   * <p>
63   * Absorb determines whether a glyph absorbs all change in space.  Within a
64   * given priority, some glyphs may absorb all the change in space.  If any of
65   * these glyphs are present, no glyphs of later priority are examined.
66   * <p>
67   * Limit determines the maximum or minimum amount by which the glyph can
68   * change. Left and right sides of the glyph can have different limits.
69   * <p>
70   * Each <code>GlyphJustificationInfo</code> represents two sets of
71   * metrics, which are <i>growing</i> and <i>shrinking</i>.  Growing
72   * metrics are used when the glyphs on a line are to be
73   * spread apart to fit a larger width.  Shrinking metrics are used when
74   * the glyphs are to be moved together to fit a smaller width.
75   */
76  
77  public final class GlyphJustificationInfo {
78  
79      /**
80       * Constructs information about the justification properties of a
81       * glyph.
82       * @param weight the weight of this glyph when allocating space.  Must be non-negative.
83       * @param growAbsorb if <code>true</code> this glyph absorbs
84       * all extra space at this priority and lower priority levels when it
85       * grows
86       * @param growPriority the priority level of this glyph when it
87       * grows
88       * @param growLeftLimit the maximum amount by which the left side of this
89       * glyph can grow.  Must be non-negative.
90       * @param growRightLimit the maximum amount by which the right side of this
91       * glyph can grow.  Must be non-negative.
92       * @param shrinkAbsorb if <code>true</code>, this glyph absorbs all
93       * remaining shrinkage at this and lower priority levels when it
94       * shrinks
95       * @param shrinkPriority the priority level of this glyph when
96       * it shrinks
97       * @param shrinkLeftLimit the maximum amount by which the left side of this
98       * glyph can shrink.  Must be non-negative.
99       * @param shrinkRightLimit the maximum amount by which the right side
100      * of this glyph can shrink.  Must be non-negative.
101      */
102      public GlyphJustificationInfo(float weight,
103                                   boolean growAbsorb,
104                                   int growPriority,
105                                   float growLeftLimit,
106                                   float growRightLimit,
107                                   boolean shrinkAbsorb,
108                                   int shrinkPriority,
109                                   float shrinkLeftLimit,
110                                   float shrinkRightLimit)
111     {
112         if (weight < 0) {
113             throw new IllegalArgumentException("weight is negative");
114         }
115 
116         if (!priorityIsValid(growPriority)) {
117             throw new IllegalArgumentException("Invalid grow priority");
118         }
119         if (growLeftLimit < 0) {
120             throw new IllegalArgumentException("growLeftLimit is negative");
121         }
122         if (growRightLimit < 0) {
123             throw new IllegalArgumentException("growRightLimit is negative");
124         }
125 
126         if (!priorityIsValid(shrinkPriority)) {
127             throw new IllegalArgumentException("Invalid shrink priority");
128         }
129         if (shrinkLeftLimit < 0) {
130             throw new IllegalArgumentException("shrinkLeftLimit is negative");
131         }
132         if (shrinkRightLimit < 0) {
133             throw new IllegalArgumentException("shrinkRightLimit is negative");
134         }
135 
136         this.weight = weight;
137         this.growAbsorb = growAbsorb;
138         this.growPriority = growPriority;
139         this.growLeftLimit = growLeftLimit;
140         this.growRightLimit = growRightLimit;
141         this.shrinkAbsorb = shrinkAbsorb;
142         this.shrinkPriority = shrinkPriority;
143         this.shrinkLeftLimit = shrinkLeftLimit;
144         this.shrinkRightLimit = shrinkRightLimit;
145     }
146 
147     private static boolean priorityIsValid(int priority) {
148 
149         return priority >= PRIORITY_KASHIDA && priority <= PRIORITY_NONE;
150     }
151 
152     /** The highest justification priority. */
153     public static final int PRIORITY_KASHIDA = 0;
154 
155     /** The second highest justification priority. */
156     public static final int PRIORITY_WHITESPACE = 1;
157 
158     /** The second lowest justification priority. */
159     public static final int PRIORITY_INTERCHAR = 2;
160 
161     /** The lowest justification priority. */
162     public static final int PRIORITY_NONE = 3;
163 
164     /**
165      * The weight of this glyph.
166      */
167     public final float weight;
168 
169     /**
170      * The priority level of this glyph as it is growing.
171      */
172     public final int growPriority;
173 
174     /**
175      * If <code>true</code>, this glyph absorbs all extra
176      * space at this and lower priority levels when it grows.
177      */
178     public final boolean growAbsorb;
179 
180     /**
181      * The maximum amount by which the left side of this glyph can grow.
182      */
183     public final float growLeftLimit;
184 
185     /**
186      * The maximum amount by which the right side of this glyph can grow.
187      */
188     public final float growRightLimit;
189 
190     /**
191      * The priority level of this glyph as it is shrinking.
192      */
193     public final int shrinkPriority;
194 
195     /**
196      * If <code>true</code>,this glyph absorbs all remaining shrinkage at
197      * this and lower priority levels as it shrinks.
198      */
199     public final boolean shrinkAbsorb;
200 
201     /**
202      * The maximum amount by which the left side of this glyph can shrink
203      * (a positive number).
204      */
205     public final float shrinkLeftLimit;
206 
207     /**
208      * The maximum amount by which the right side of this glyph can shrink
209      * (a positive number).
210      */
211     public final float shrinkRightLimit;
212 }