Source Code Cross Referenced for GlyphVector.java in  » 6.0-JDK-Core » AWT » java » awt » font » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt.font 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        /*
027         * @author Charlton Innovations, Inc.
028         */
029
030        package java.awt.font;
031
032        import java.awt.Graphics2D;
033        import java.awt.Font;
034        import java.awt.Polygon; // remind - need a floating point version
035        import java.awt.Rectangle;
036        import java.awt.geom.Point2D;
037        import java.awt.geom.Rectangle2D;
038        import java.awt.geom.AffineTransform;
039        import java.awt.Shape;
040        import java.awt.font.GlyphMetrics;
041        import java.awt.font.GlyphJustificationInfo;
042
043        /**
044         * A <code>GlyphVector</code> object is a collection of glyphs
045         * containing geometric information for the placement of each glyph 
046         * in a transformed coordinate space which corresponds to the
047         * device on which the <code>GlyphVector</code> is ultimately 
048         * displayed. 
049         * <p>
050         * The <code>GlyphVector</code> does not attempt any interpretation of
051         * the sequence of glyphs it contains.  Relationships between adjacent
052         * glyphs in sequence are solely used to determine the placement of
053         * the glyphs in the visual coordinate space.
054         * <p>
055         * Instances of <code>GlyphVector</code> are created by a {@link Font}.
056         * <p>
057         * In a text processing application that can cache intermediate
058         * representations of text, creation and subsequent caching of a 
059         * <code>GlyphVector</code> for use during rendering is the fastest
060         * method to present the visual representation of characters to a user.
061         * <p>
062         * A <code>GlyphVector</code> is associated with exactly one 
063         * <code>Font</code>, and can provide data useful only in relation to
064         * this <code>Font</code>.  In addition, metrics obtained from a
065         * <code>GlyphVector</code> are not generally geometrically scaleable
066         * since the pixelization and spacing are dependent on grid-fitting
067         * algorithms within a <code>Font</code>.  To facilitate accurate
068         * measurement of a <code>GlyphVector</code> and its component
069         * glyphs, you must specify a scaling transform, anti-alias mode, and
070         * fractional metrics mode when creating the <code>GlyphVector</code>.
071         * These characteristics can be derived from the destination device.
072         * <p>
073         * For each glyph in the <code>GlyphVector</code>, you can obtain:
074         * <ul>
075         * <li>the position of the glyph
076         * <li>the transform associated with the glyph
077         * <li>the metrics of the glyph in the context of the 
078         *   <code>GlyphVector</code>.  The metrics of the glyph may be
079         *   different under different transforms, application specified
080         *   rendering hints, and the specific instance of the glyph within
081         *   the <code>GlyphVector</code>.
082         * </ul>
083         * <p>
084         * Altering the data used to create the <code>GlyphVector</code> does not
085         * alter the state of the <code>GlyphVector</code>.
086         * <p>
087         * Methods are provided to adjust the positions of the glyphs
088         * within the <code>GlyphVector</code>.  These methods are most
089         * appropriate for applications that are performing justification
090         * operations for the presentation of the glyphs.
091         * <p>
092         * Methods are provided to transform individual glyphs within the
093         * <code>GlyphVector</code>.  These methods are primarily useful for
094         * special effects.
095         * <p>
096         * Methods are provided to return both the visual, logical, and pixel bounds
097         * of the entire <code>GlyphVector</code> or of individual glyphs within
098         * the <code>GlyphVector</code>.
099         * <p>
100         * Methods are provided to return a {@link Shape} for the 
101         * <code>GlyphVector</code>, and for individual glyphs within the
102         * <code>GlyphVector</code>.
103         * @see Font
104         * @see GlyphMetrics
105         * @see TextLayout
106         * @version 19 Mar 1998
107         * @author Charlton Innovations, Inc.
108         */
109
110        public abstract class GlyphVector implements  Cloneable {
111
112            //
113            // methods associated with creation-time state
114            //
115
116            /**
117             * Returns the <code>Font</code> associated with this
118             * <code>GlyphVector</code>.  
119             * @return <code>Font</code> used to create this 
120             * <code>GlyphVector</code>.  
121             * @see Font
122             */
123            public abstract Font getFont();
124
125            /**
126             * Returns the {@link FontRenderContext} associated with this
127             * <code>GlyphVector</code>.
128             * @return <code>FontRenderContext</code> used to create this
129             * <code>GlyphVector</code>.
130             * @see FontRenderContext
131             * @see Font
132             */
133            public abstract FontRenderContext getFontRenderContext();
134
135            //
136            // methods associated with the GlyphVector as a whole
137            //
138
139            /**
140             * Assigns default positions to each glyph in this 
141             * <code>GlyphVector</code>. This can destroy information
142             * generated during initial layout of this <code>GlyphVector</code>.
143             */
144            public abstract void performDefaultLayout();
145
146            /**
147             * Returns the number of glyphs in this <code>GlyphVector</code>.
148             * @return number of glyphs in this <code>GlyphVector</code>.
149             */
150            public abstract int getNumGlyphs();
151
152            /**
153             * Returns the glyphcode of the specified glyph.
154             * This return value is meaningless to anything other
155             * than the <code>Font</code> object that created this 
156             * <code>GlyphVector</code>.
157             * @param glyphIndex the index into this <code>GlyphVector</code>
158             * that corresponds to the glyph from which to retrieve the 
159             * glyphcode.
160             * @return the glyphcode of the glyph at the specified
161             * <code>glyphIndex</code>.
162             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
163             * is less than 0 or greater than or equal to the 
164             * number of glyphs in this <code>GlyphVector</code>
165             */
166            public abstract int getGlyphCode(int glyphIndex);
167
168            /**
169             * Returns an array of glyphcodes for the specified glyphs.
170             * The contents of this return value are meaningless to anything other
171             * than the <code>Font</code> used to create this 
172             * <code>GlyphVector</code>.  This method is used
173             * for convenience and performance when processing glyphcodes.
174             * If no array is passed in, a new array is created.
175             * @param beginGlyphIndex the index into this
176             *   <code>GlyphVector</code> at which to start retrieving glyphcodes
177             * @param numEntries the number of glyphcodes to retrieve
178             * @param codeReturn the array that receives the glyphcodes and is
179             *   then returned
180             * @return an array of glyphcodes for the specified glyphs.
181             * @throws IllegalArgumentException if <code>numEntries</code> is 
182             *   less than 0
183             * @throws IndexOutOfBoundsException if <code>beginGlyphIndex</code> 
184             *   is less than 0
185             * @throws IndexOutOfBoundsException if the sum of 
186             *   <code>beginGlyphIndex</code> and <code>numEntries</code> is 
187             *   greater than the number of glyphs in this
188             *   <code>GlyphVector</code>
189             */
190            public abstract int[] getGlyphCodes(int beginGlyphIndex,
191                    int numEntries, int[] codeReturn);
192
193            /**
194             * Returns the character index of the specified glyph.
195             * The character index is the index of the first logical 
196             * character represented by the glyph.  The default 
197             * implementation assumes a one-to-one, left-to-right mapping
198             * of glyphs to characters.
199             * @param glyphIndex the index of the glyph
200             * @return the index of the first character represented by the glyph
201             * @since 1.4
202             */
203            public int getGlyphCharIndex(int glyphIndex) {
204                return glyphIndex;
205            }
206
207            /**
208             * Returns the character indices of the specified glyphs.
209             * The character index is the index of the first logical
210             * character represented by the glyph.  Indices are returned
211             * in glyph order.  The default implementation invokes
212             * getGlyphCharIndex for each glyph, and subclassers will probably
213             * want to override this implementation for performance reasons.
214             * Use this method for convenience and performance
215             * in processing of glyphcodes. If no array is passed in,
216             * a new array is created.
217             * @param beginGlyphIndex the index of the first glyph 
218             * @param numEntries the number of glyph indices
219             * @param codeReturn the array into which to return the character indices
220             * @return an array of character indices, one per glyph.
221             * @since 1.4
222             */
223            public int[] getGlyphCharIndices(int beginGlyphIndex,
224                    int numEntries, int[] codeReturn) {
225                if (codeReturn == null) {
226                    codeReturn = new int[numEntries];
227                }
228                for (int i = 0, j = beginGlyphIndex; i < numEntries; ++i, ++j) {
229                    codeReturn[i] = getGlyphCharIndex(j);
230                }
231                return codeReturn;
232            }
233
234            /**
235             * Returns the logical bounds of this <code>GlyphVector</code>.
236             * This method is used when positioning this <code>GlyphVector</code> 
237             * in relation to visually adjacent <code>GlyphVector</code> objects.
238             * @return a {@link Rectangle2D} that is the logical bounds of this
239             * <code>GlyphVector</code>.
240             */
241            public abstract Rectangle2D getLogicalBounds();
242
243            /**
244             * Returns the visual bounds of this <code>GlyphVector</code>
245             * The visual bounds is the bounding box of the outline of this
246             * <code>GlyphVector</code>.  Because of rasterization and 
247             * alignment of pixels, it is possible that this box does not
248             * enclose all pixels affected by rendering this <code>GlyphVector</code>.
249             * @return a <code>Rectangle2D</code> that is the bounding box
250             * of this <code>GlyphVector</code>.
251             */
252            public abstract Rectangle2D getVisualBounds();
253
254            /**
255             * Returns the pixel bounds of this <code>GlyphVector</code> when
256             * rendered in a graphics with the given
257             * <code>FontRenderContext</code> at the given location.  The
258             * renderFRC need not be the same as the
259             * <code>FontRenderContext</code> of this
260             * <code>GlyphVector</code>, and can be null.  If it is null, the
261             * <code>FontRenderContext</code> of this <code>GlyphVector</code>
262             * is used.  The default implementation returns the visual bounds, 
263             * offset to x, y and rounded out to the next integer value (i.e. returns an
264             * integer rectangle which encloses the visual bounds) and
265             * ignores the FRC.  Subclassers should override this method.
266             * @param renderFRC the <code>FontRenderContext</code> of the <code>Graphics</code>.
267             * @param x the x-coordinate at which to render this <code>GlyphVector</code>.
268             * @param y the y-coordinate at which to render this <code>GlyphVector</code>.
269             * @return a <code>Rectangle</code> bounding the pixels that would be affected.
270             * @since 1.4
271             */
272            public Rectangle getPixelBounds(FontRenderContext renderFRC,
273                    float x, float y) {
274                Rectangle2D rect = getVisualBounds();
275                int l = (int) Math.floor(rect.getX() + x);
276                int t = (int) Math.floor(rect.getY() + y);
277                int r = (int) Math.ceil(rect.getMaxX() + x);
278                int b = (int) Math.ceil(rect.getMaxY() + y);
279                return new Rectangle(l, t, r - l, b - t);
280            }
281
282            /**
283             * Returns a <code>Shape</code> whose interior corresponds to the
284             * visual representation of this <code>GlyphVector</code>.
285             * @return a <code>Shape</code> that is the outline of this
286             * <code>GlyphVector</code>.
287             */
288            public abstract Shape getOutline();
289
290            /**
291             * Returns a <code>Shape</code> whose interior corresponds to the
292             * visual representation of this <code>GlyphVector</code> when
293             * rendered at x,&nbsp;y.
294             * @param x the X coordinate of this <code>GlyphVector</code>.
295             * @param y the Y coordinate of this <code>GlyphVector</code>.
296             * @return a <code>Shape</code> that is the outline of this
297             *   <code>GlyphVector</code> when rendered at the specified
298             *   coordinates.
299             */
300            public abstract Shape getOutline(float x, float y);
301
302            /**
303             * Returns a <code>Shape</code> whose interior corresponds to the
304             * visual representation of the specified glyph
305             * within this <code>GlyphVector</code>.
306             * The outline returned by this method is positioned around the
307             * origin of each individual glyph.
308             * @param glyphIndex the index into this <code>GlyphVector</code>
309             * @return a <code>Shape</code> that is the outline of the glyph
310             *   at the specified <code>glyphIndex</code> of this
311             *	 <code>GlyphVector</code>.
312             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
313             *   is less than 0 or greater than or equal to the number
314             *   of glyphs in this <code>GlyphVector</code>
315             */
316            public abstract Shape getGlyphOutline(int glyphIndex);
317
318            /**
319             * Returns a <code>Shape</code> whose interior corresponds to the
320             * visual representation of the specified glyph
321             * within this <code>GlyphVector</code>, offset to x,&nbsp;y.
322             * The outline returned by this method is positioned around the
323             * origin of each individual glyph.
324             * @param glyphIndex the index into this <code>GlyphVector</code>
325             * @param x the X coordinate of the location of this {@code GlyphVector}
326             * @param y the Y coordinate of the location of this {@code GlyphVector}
327             * @return a <code>Shape</code> that is the outline of the glyph
328             *   at the specified <code>glyphIndex</code> of this
329             *	 <code>GlyphVector</code> when rendered at the specified
330             *   coordinates.
331             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
332             *   is less than 0 or greater than or equal to the number
333             *   of glyphs in this <code>GlyphVector</code>
334             * @since 1.4
335             */
336            public Shape getGlyphOutline(int glyphIndex, float x, float y) {
337                Shape s = getGlyphOutline(glyphIndex);
338                AffineTransform at = AffineTransform.getTranslateInstance(x, y);
339                return at.createTransformedShape(s);
340            }
341
342            /**
343             * Returns the position of the specified glyph relative to the
344             * origin of this <code>GlyphVector</code>.
345             * If <code>glyphIndex</code> equals the number of of glyphs in 
346             * this <code>GlyphVector</code>, this method returns the position after
347             * the last glyph. This position is used to define the advance of 
348             * the entire <code>GlyphVector</code>.
349             * @param glyphIndex the index into this <code>GlyphVector</code>
350             * @return a {@link Point2D} object that is the position of the glyph
351             *	 at the specified <code>glyphIndex</code>.
352             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
353             *   is less than 0 or greater than the number of glyphs
354             *   in this <code>GlyphVector</code>
355             * @see #setGlyphPosition 
356             */
357            public abstract Point2D getGlyphPosition(int glyphIndex);
358
359            /**
360             * Sets the position of the specified glyph within this
361             * <code>GlyphVector</code>.
362             * If <code>glyphIndex</code> equals the number of of glyphs in 
363             * this <code>GlyphVector</code>, this method sets the position after
364             * the last glyph. This position is used to define the advance of 
365             * the entire <code>GlyphVector</code>.
366             * @param glyphIndex the index into this <code>GlyphVector</code>
367             * @param newPos the <code>Point2D</code> at which to position the
368             *	 glyph at the specified <code>glyphIndex</code>
369             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
370             *   is less than 0 or greater than the number of glyphs
371             *   in this <code>GlyphVector</code>
372             * @see #getGlyphPosition
373             */
374            public abstract void setGlyphPosition(int glyphIndex, Point2D newPos);
375
376            /**
377             * Returns the transform of the specified glyph within this
378             * <code>GlyphVector</code>.  The transform is relative to the
379             * glyph position.  If no special transform has been applied, 
380             * <code>null</code> can be returned.  A null return indicates
381             * an identity transform.
382             * @param glyphIndex the index into this <code>GlyphVector</code>
383             * @return an {@link AffineTransform} that is the transform of
384             *	 the glyph at the specified <code>glyphIndex</code>.
385             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
386             *   is less than 0 or greater than or equal to the number 
387             *   of glyphs in this <code>GlyphVector</code>
388             * @see #setGlyphTransform
389             */
390            public abstract AffineTransform getGlyphTransform(int glyphIndex);
391
392            /**
393             * Sets the transform of the specified glyph within this
394             * <code>GlyphVector</code>.  The transform is relative to the glyph
395             * position.  A <code>null</code> argument for <code>newTX</code>
396             * indicates that no special transform is applied for the specified
397             * glyph.
398             * This method can be used to rotate, mirror, translate and scale the
399             * glyph.  Adding a transform can result in signifant performance changes.
400             * @param glyphIndex the index into this <code>GlyphVector</code>
401             * @param newTX the new transform of the glyph at <code>glyphIndex</code>
402             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
403             *   is less than 0 or greater than or equal to the number 
404             *   of glyphs in this <code>GlyphVector</code>
405             * @see #getGlyphTransform
406             */
407            public abstract void setGlyphTransform(int glyphIndex,
408                    AffineTransform newTX);
409
410            /**
411             * Returns flags describing the global state of the GlyphVector.
412             * Flags not described below are reserved.  The default 
413             * implementation returns 0 (meaning false) for the position adjustments,
414             * transforms, rtl, and complex flags.
415             * Subclassers should override this method, and make sure
416             * it correctly describes the GlyphVector and corresponds
417             * to the results of related calls.
418             * @return an int containing the flags describing the state
419             * @see #FLAG_HAS_POSITION_ADJUSTMENTS
420             * @see #FLAG_HAS_TRANSFORMS
421             * @see #FLAG_RUN_RTL
422             * @see #FLAG_COMPLEX_GLYPHS
423             * @see #FLAG_MASK
424             * @since 1.4
425             */
426            public int getLayoutFlags() {
427                return 0;
428            }
429
430            /**
431             * A flag used with getLayoutFlags that indicates that this <code>GlyphVector</code> has
432             * per-glyph transforms.
433             * @since 1.4
434             */
435            public static final int FLAG_HAS_TRANSFORMS = 1;
436
437            /**
438             * A flag used with getLayoutFlags that indicates that this <code>GlyphVector</code> has
439             * position adjustments.  When this is true, the glyph positions don't match the
440             * accumulated default advances of the glyphs (for example, if kerning has been done).
441             * @since 1.4
442             */
443            public static final int FLAG_HAS_POSITION_ADJUSTMENTS = 2;
444
445            /**
446             * A flag used with getLayoutFlags that indicates that this <code>GlyphVector</code> has
447             * a right-to-left run direction.  This refers to the glyph-to-char mapping and does
448             * not imply that the visual locations of the glyphs are necessarily in this order,
449             * although generally they will be.
450             * @since 1.4
451             */
452            public static final int FLAG_RUN_RTL = 4;
453
454            /**
455             * A flag used with getLayoutFlags that indicates that this <code>GlyphVector</code> has
456             * a complex glyph-to-char mapping (one that does not map glyphs to chars one-to-one in
457             * strictly ascending or descending order matching the run direction).
458             * @since 1.4
459             */
460            public static final int FLAG_COMPLEX_GLYPHS = 8;
461
462            /**
463             * A mask for supported flags from getLayoutFlags.  Only bits covered by the mask
464             * should be tested.
465             * @since 1.4
466             */
467            public static final int FLAG_MASK = FLAG_HAS_TRANSFORMS
468                    | FLAG_HAS_POSITION_ADJUSTMENTS | FLAG_RUN_RTL
469                    | FLAG_COMPLEX_GLYPHS;
470
471            /**
472             * Returns an array of glyph positions for the specified glyphs.
473             * This method is used for convenience and performance when
474             * processing glyph positions.
475             * If no array is passed in, a new array is created.
476             * Even numbered array entries beginning with position zero are the X
477             * coordinates of the glyph numbered <code>beginGlyphIndex + position/2</code>.  
478             * Odd numbered array entries beginning with position one are the Y
479             * coordinates of the glyph numbered <code>beginGlyphIndex + (position-1)/2</code>.
480             * If <code>beginGlyphIndex</code> equals the number of of glyphs in 
481             * this <code>GlyphVector</code>, this method gets the position after
482             * the last glyph and this position is used to define the advance of 
483             * the entire <code>GlyphVector</code>.
484             * @param beginGlyphIndex the index at which to begin retrieving
485             *   glyph positions
486             * @param numEntries the number of glyphs to retrieve
487             * @param positionReturn the array that receives the glyph positions
488             *   and is then returned.
489             * @return an array of glyph positions specified by
490             *	<code>beginGlyphIndex</code> and <code>numEntries</code>.
491             * @throws IllegalArgumentException if <code>numEntries</code> is
492             *   less than 0
493             * @throws IndexOutOfBoundsException if <code>beginGlyphIndex</code>
494             *   is less than 0
495             * @throws IndexOutOfBoundsException if the sum of 
496             *   <code>beginGlyphIndex</code> and <code>numEntries</code> 
497             *   is greater than the number of glyphs in this 
498             *   <code>GlyphVector</code> plus one
499             */
500            public abstract float[] getGlyphPositions(int beginGlyphIndex,
501                    int numEntries, float[] positionReturn);
502
503            /**
504             * Returns the logical bounds of the specified glyph within this
505             * <code>GlyphVector</code>.
506             * These logical bounds have a total of four edges, with two edges
507             * parallel to the baseline under the glyph's transform and the other two
508             * edges are shared with adjacent glyphs if they are present.  This
509             * method is useful for hit-testing of the specified glyph,
510             * positioning of a caret at the leading or trailing edge of a glyph,
511             * and for drawing a highlight region around the specified glyph.
512             * @param glyphIndex the index into this <code>GlyphVector</code>
513             *   that corresponds to the glyph from which to retrieve its logical
514             *   bounds
515             * @return  a <code>Shape</code> that is the logical bounds of the
516             *	 glyph at the specified <code>glyphIndex</code>.
517             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
518             *   is less than 0 or greater than or equal to the number 
519             *   of glyphs in this <code>GlyphVector</code>
520             * @see #getGlyphVisualBounds
521             */
522            public abstract Shape getGlyphLogicalBounds(int glyphIndex);
523
524            /**
525             * Returns the visual bounds of the specified glyph within the
526             * <code>GlyphVector</code>.
527             * The bounds returned by this method is positioned around the
528             * origin of each individual glyph.
529             * @param glyphIndex the index into this <code>GlyphVector</code>
530             *   that corresponds to the glyph from which to retrieve its visual
531             *   bounds
532             * @return a <code>Shape</code> that is the visual bounds of the
533             *   glyph at the specified <code>glyphIndex</code>.
534             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
535             *   is less than 0 or greater than or equal to the number 
536             *   of glyphs in this <code>GlyphVector</code>
537             * @see #getGlyphLogicalBounds
538             */
539            public abstract Shape getGlyphVisualBounds(int glyphIndex);
540
541            /**
542             * Returns the pixel bounds of the glyph at index when this
543             * <code>GlyphVector</code> is rendered in a <code>Graphics</code> with the
544             * given <code>FontRenderContext</code> at the given location. The
545             * renderFRC need not be the same as the
546             * <code>FontRenderContext</code> of this
547             * <code>GlyphVector</code>, and can be null.  If it is null, the
548             * <code>FontRenderContext</code> of this <code>GlyphVector</code>
549             * is used.  The default implementation returns the visual bounds of the glyph, 
550             * offset to x, y and rounded out to the next integer value, and
551             * ignores the FRC.  Subclassers should override this method.
552             * @param index the index of the glyph.
553             * @param renderFRC the <code>FontRenderContext</code> of the <code>Graphics</code>.
554             * @param x the X position at which to render this <code>GlyphVector</code>.
555             * @param y the Y position at which to render this <code>GlyphVector</code>.
556             * @return a <code>Rectangle</code> bounding the pixels that would be affected.
557             * @since 1.4
558             */
559            public Rectangle getGlyphPixelBounds(int index,
560                    FontRenderContext renderFRC, float x, float y) {
561                Rectangle2D rect = getGlyphVisualBounds(index).getBounds2D();
562                int l = (int) Math.floor(rect.getX() + x);
563                int t = (int) Math.floor(rect.getY() + y);
564                int r = (int) Math.ceil(rect.getMaxX() + x);
565                int b = (int) Math.ceil(rect.getMaxY() + y);
566                return new Rectangle(l, t, r - l, b - t);
567            }
568
569            /**
570             * Returns the metrics of the glyph at the specified index into
571             * this <code>GlyphVector</code>.
572             * @param glyphIndex the index into this <code>GlyphVector</code>
573             *   that corresponds to the glyph from which to retrieve its metrics
574             * @return a {@link GlyphMetrics} object that represents the
575             *	 metrics of the glyph at the specified <code>glyphIndex</code> 
576             *	 into this <code>GlyphVector</code>.
577             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
578             *   is less than 0 or greater than or equal to the number 
579             *   of glyphs in this <code>GlyphVector</code>
580             */
581            public abstract GlyphMetrics getGlyphMetrics(int glyphIndex);
582
583            /**
584             * Returns the justification information for the glyph at
585             * the specified index into this <code>GlyphVector</code>.
586             * @param glyphIndex the index into this <code>GlyphVector</code>
587             *	 that corresponds to the glyph from which to retrieve its 
588             *	 justification properties
589             * @return a {@link GlyphJustificationInfo} object that
590             *	 represents the justification properties of the glyph at the
591             *	 specified <code>glyphIndex</code> into this
592             *	 <code>GlyphVector</code>.
593             * @throws IndexOutOfBoundsException if <code>glyphIndex</code>
594             *   is less than 0 or greater than or equal to the number 
595             *   of glyphs in this <code>GlyphVector</code>
596             */
597            public abstract GlyphJustificationInfo getGlyphJustificationInfo(
598                    int glyphIndex);
599
600            //
601            // general utility methods
602            //
603
604            /**
605             * Tests if the specified <code>GlyphVector</code> exactly
606             * equals this <code>GlyphVector</code>.
607             * @param set the specified <code>GlyphVector</code> to test
608             * @return <code>true</code> if the specified
609             *	 <code>GlyphVector</code> equals this <code>GlyphVector</code>;
610             *	 <code>false</code> otherwise.
611             */
612            public abstract boolean equals(GlyphVector set);
613        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.