Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Class java.awt.font.GlyphSet

java.lang.Object
    |
    +----java.awt.font.GlyphSet

public abstract class GlyphSet
extends Object
implements Cloneable
GlyphSet is a graphical representation of text with bidirectional ordering. Instances of GlyphSet are produced by Font (or subclasses of Font) and contain a sequence of integer glyph codes, used by the Font to represent text graphically. The glyph codes are not characters; they are meaningful only to the Font which produced them. GlyphSets may be displayed on a graphics device. Metrics for the entire GlyphSet or for individual glyphs may be queried. Additionally, new GlyphSets may be produced from old ones for operations such as taking a subset of a glyphset, justification, changing a single character in the source text, and setting the direction of the glyphs in a GlyphSet.

GlyphSets are immutable; once created, their state never changes. In particular, changes to the text from which they were created do not affect existing GlyphSets.

The glyphs in a GlyphSet are stored in logical order; that is, they are stored in the same order as the characters from which they were generated. GlyphSets also maintain a visual order for their glyphs. The visual order is the order, from left to right, in which the glyphs will be displayed. For text with right-to-left or bidirectional ordering, the logical order will not be the same as the visual order. Glyphs are available in logical order directly from the GlyphSet. Additionally, visualToLogicalIndex will convert a visual position to a logical position.

A GlyphSet may contain more glyphs than the number of characters in the sequence it represents (but never less). Methods on GlyphSet which return information on glyphs require a glyph index. Other methods on GlyphSet are commonly associated with text editing (such as inserting or deleting a character, or taking a subset). These operations used character indices.

Example:

Examine glyphs in visual order

 GlyphSet glyphSet = ...;
 for (int i=0; i < getNumGlyphs(); i++) {
     int logIndex = glyphSet.visualToLogicalIndex(i);
     int glyphCode = glyphSet.getGlyphCode(logIndex);
     // do something with glyphCode...
 }
 

See Also:
Font, GlyphMetrics, TextLayout

Field Summary
static boolean  LEFT_TO_RIGHT
An argument to setDirection indicating LEFT_TO_RIGHT glyphs.
static boolean  RIGHT_TO_LEFT
An argument to setDirection indicating RIGHT_TO_LEFT glyphs.
 

Constructor Summary
 GlyphSet()
 
 

Method Summary
GlyphSet  applyJustification(float[] deltas, int index, boolean[] flags)
Return a justified copy of this glyphset.
GlyphSet  deleteChar(AttributedCharacterIterator newText, int start, int limit, int deletePos, int[] order, byte[] levels)
Return a new GlyphSet which is an incremental modification of this one.
void  draw(Graphics2D graphics, float x, float y)
Draw this glyphset at the provided position.
boolean  equals(GlyphSet set)
Test for full equality.
float  getAdvance()
Return the advance of the glyphset.
float  getAdvanceBetween(int start, int limit)
Return the sum of the advances for the glyphs corresponding to characters in logical positions from start up to limit.
float  getAscent()
Return the ascent of the glyphset relative to the baseline.
byte  getBaseline()
Return the baseline used by this glyphset.
Rectangle2D  getBounds()
Return the bounds in which contains all of the bits drawn by this GlyphSet.
static int[]  getContiguousOrder(int[] values)
Return an array containing contiguous values from 0 to length having the same ordering as the source array.
float  getDescent()
return the descent of the glyphset relative to the baseline.
Font  getFont()
Return the font that created this glyphset.
float  getGlyphAdvance(int index)
Return the advance for the glyph at the given logical position.
int  getGlyphCode(int index)
Return the glyphcode at the given logical position in this glyphset.
int[]  getGlyphCodes()
 
float  getGlyphXAdvance(int index)
Return the x-direction advance of the glyph at the given logical position.
float  getGlyphYAdvance(int index)
Return the y-direction advance of the glyph at the given logical position.
static int[]  getInverseOrder(int[] values)
Return the inverse array, source array must map 1-1 i.e.
byte  getLevel(int index)
Return the bidirection level of the glyph at the given logical position.
int  getLineBreakIndex(int start, float hitAdvance)
Return the logical position of a possible break.
static int[]  getNormalizedOrder(int[] values, byte[] levels, int start, int limit)
Return an array containing the values from start up to limit, normalized to fall within the range from 0 up to limit - start.
int  getNumCharacters()
Return the number of characters represented by this glyphset.
int  getNumGlyphs()
Return the number of glyphs in this glyphset.
float  getXAdjust()
Return the x position of the first visual glyph in the glyphset.
float  getYAdjust()
Return the y position of the first visual glyph in the glyphset.
int  hashCode()
Return a hashCode for this glyphset.
GlyphSet  insertChar(AttributedCharacterIterator newText, int start, int limit, int insertPos, int[] order, byte[] levels)
Return a new GlyphSet which is an incremental modification of this one.
boolean  isCompletelyLTR()
Return true if every glyph in the glyphset is left-to-right, and the glyphs all run from left to right.
GlyphSet  reshape(AttributedCharacterIterator newText, int start, int limit, int changePos, int[] order, byte[] levels)
Reshape a glyph set after a change to neighboring text.
GlyphSet  setDirection(boolean leftToRight)
Return a GlyphSet identical to this one, except with all glyphs going in the same direction.
GlyphSet  subset(int start, int limit)
Generate a GlyphSet that contains the subset of this from logical start up to limit.
int  visualToLogicalIndex(int index)
Map from visual position to logical position.
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT_TO_RIGHT

public static final boolean LEFT_TO_RIGHT
An argument to setDirection indicating LEFT_TO_RIGHT glyphs.
See Also:
setDirection

RIGHT_TO_LEFT

public static final boolean RIGHT_TO_LEFT
An argument to setDirection indicating RIGHT_TO_LEFT glyphs.
See Also:
setDirection
Constructor Detail

GlyphSet

public GlyphSet()
Method Detail

getAdvance

public abstract float getAdvance()
Return the advance of the glyphset.

getAscent

public abstract float getAscent()
Return the ascent of the glyphset relative to the baseline. This is the distance above (to the right of) the baseline. The ascent is always positive or zero.
See Also:
getBaseline

getDescent

public abstract float getDescent()
return the descent of the glyphset relative to the baseline. This is the distance below (to the left of) the baseline. The descent is always positive or zero.
See Also:
getBaseline

getFont

public abstract Font getFont()
Return the font that created this glyphset.

getNumGlyphs

public abstract int getNumGlyphs()
Return the number of glyphs in this glyphset.

getNumCharacters

public abstract int getNumCharacters()
Return the number of characters represented by this glyphset. Some fonts may use several glyphs to represent a single character. There are never fewer glyphs than characters. Glyphs representing more than one character are always followed (logically) by an invisible combining glyph for each additional character.

getGlyphCode

public abstract int getGlyphCode(int index)
Return the glyphcode at the given logical position in this glyphset.
See Also:
getNumGlyphs

getBaseline

public abstract byte getBaseline()
Return the baseline used by this glyphset. All glyphs in a single glyphset align to the same baseline.
See Also:
getBaselineFor

getXAdjust

public abstract float getXAdjust()
Return the x position of the first visual glyph in the glyphset. The first visual glyph in the glyphset is offset by x, y from the origin of the glyphset. This supports attributes like superscript.
See Also:
getYAdjust

getGlyphXAdvance

public abstract float getGlyphXAdvance(int index)
Return the x-direction advance of the glyph at the given logical position.
See Also:
getGlyphYAdvance, getNumGlyphs

getYAdjust

public abstract float getYAdjust()
Return the y position of the first visual glyph in the glyphset. The first visual glyph in the glyphset is offset by x, y from the origin of the glyphset. This supports attributes like superscript.
See Also:
getXAdjust

getGlyphYAdvance

public abstract float getGlyphYAdvance(int index)
Return the y-direction advance of the glyph at the given logical position.
See Also:
getGlyphXAdvance, getNumGlyphs

getGlyphAdvance

public abstract float getGlyphAdvance(int index)
Return the advance for the glyph at the given logical position. The X-advance is returned on a horizontal line; the Y-advance is returned on a vertical line.

visualToLogicalIndex

public abstract int visualToLogicalIndex(int index)
Map from visual position to logical position. For example, visualToLogicalIndex(0) = 5 means that the first glyph drawn is at position five in the glyphCodes, levels, and advances arrays.
See Also:
getNumGlyphs

getLevel

public abstract byte getLevel(int index)
Return the bidirection level of the glyph at the given logical position. Glyphs whose level is even are left to right (top to bottom), glyphs whose level is odd are right to left (bottom to top).
See Also:
getNumGlyphs

isCompletelyLTR

public abstract boolean isCompletelyLTR()
Return true if every glyph in the glyphset is left-to-right, and the glyphs all run from left to right.
See Also:
getLevel

applyJustification

public abstract GlyphSet applyJustification(float[] deltas,
                                            int index,
                                            boolean[] flags)
Return a justified copy of this glyphset.
Parameters:
deltas - an array of amounts by which to change the left and right sides of each glyph, in visual order. The array has at least twice as many entries as there are glyphs in the glyphset. For example, deltas[index] is the delta for the left side of the visually leftmost glyph, deltas[index+1] is for the right side of the visually leftmost glyph, deltas[index+2] is for the left side of the visually second leftmost glyph, and so on.
index - the starting position in the deltas array. It corresponds to the left side of the leftmost glyph.
shouldRejustify - an array containing a single input/output boolean value. On entry, it indicates whether the returned glyphset is allowed to cause rejustification, for example, if a ligature can be formed or broken. On exit, it indicates whether the returned glyphset will require rejustification (for example, due to the formation or removal of a ligature).

getAdvanceBetween

public abstract float getAdvanceBetween(int start,
                                        int limit)
Return the sum of the advances for the glyphs corresponding to characters in logical positions from start up to limit. Note these are character indices, not glyph indices. They will be mapped internally to glyph indices.
Parameters:
start - the character index at which to start measuring
limit - the character index at which to stop measuring

getLineBreakIndex

public abstract int getLineBreakIndex(int start,
                                      float hitAdvance)
Return the logical position of a possible break. This adds up advances of glyphs in logical order starting from the glyph for the character at start, stopping before the first spacing glyph whose advance would cause hitAdvance to be exceeded. The character position of that glyph is returned. If no glyph would reach the hitAdvance, the number of characters in the set is returned. This will not break between combining or component glyphs and their base glyph.

subset

public abstract GlyphSet subset(int start,
                                int limit)
Generate a GlyphSet that contains the subset of this from logical start up to limit. The new glyphset shares the same baseline, xAdjust, and yAdjust as the previous one.
Parameters:
start - the character index where the subset will begin
limit - the character index immediately after the end of the subset

insertChar

public abstract GlyphSet insertChar(AttributedCharacterIterator newText,
                                    int start,
                                    int limit,
                                    int insertPos,
                                    int[] order,
                                    byte[] levels)
Return a new GlyphSet which is an incremental modification of this one. This glyphset must have been generated from text identical to newText, with exactly one difference: an inserted character at insertPos at newText.
Parameters:
newText - the text for the new glyphset. This represents the text after the insertion occurred. The new glyphset will represent the text beginning at start, up to (but not including) limit.
start - the start of the subrange in newText for the glyphset
limit - the limit of the subrange in newText for the glyphset, including the inserted character.
insertPos - the character position in the glyphset at which the single character was inserted.
order - the logical-to-visual mapping array for newText. If null, left-to-right is assumed.
levels - the bidirection level of each character in newText. If null, all levels are assumed to be 0.
Returns:
a new GlyphSet representing newText.

deleteChar

public abstract GlyphSet deleteChar(AttributedCharacterIterator newText,
                                    int start,
                                    int limit,
                                    int deletePos,
                                    int[] order,
                                    byte[] levels)
Return a new GlyphSet which is an incremental modification of this one. This glyphset must have been generated from text identical to newText, with exactly one difference: a deleted character at deletePos at newText.
Parameters:
newText - the text for the new glyphset. This represents the text after the deletion occurred. The new glyphset will represent the text beginning at start, up to (but not including) limit.
start - the start of the subrange in newText for the glyphset.
limit - the limit of the subrange in newText for the glyphset, not including the deleted character.
deletePos - the character position in the glyphset at which the single character was deleted.
order - the logical-to-visual mapping array for newText. If null, left-to-right is assumed.
levels - the bidirection level of each character in newText. If null, all levels are assumed to be 0.
Returns:
a new GlyphSet representing newText.

reshape

public abstract GlyphSet reshape(AttributedCharacterIterator newText,
                                 int start,
                                 int limit,
                                 int changePos,
                                 int[] order,
                                 byte[] levels)
Reshape a glyph set after a change to neighboring text. If this GlyphSet's font does context-sensitive glyph shaping, then a change in a character can affect the glyphs before and after it. This method allows the Font to inspect the new text and (possibly) return a new glyphset with different shaping. This method is used in conjunction with insertChar and deleteChar.
Parameters:
newText - styled text represented by this GlyphSet over the range start, limit.
start - the start of the range in newText represented by this GlyphSet.
limit - the limit of the range in newText represented by this GlyphSet.
changePos - the position in newText that has changed since this GlyphSet was created. This parameter must be either start-1 or limit.
order - the logical-to-visual mapping array for newText. If null, left-to-right is assumed.
levels - the bidirection level of each character in newText. If null, all levels are assumed to be 0.
Returns:
a GlyphSet representing newText over the range start, limit, with updated glyph shaping (if any).
See Also:
insertChar, deleteChar

draw

public abstract void draw(Graphics2D graphics,
                          float x,
                          float y)
Draw this glyphset at the provided position.

getBounds

public abstract Rectangle2D getBounds()
Return the bounds in which contains all of the bits drawn by this GlyphSet.

setDirection

public abstract GlyphSet setDirection(boolean leftToRight)
Return a GlyphSet identical to this one, except with all glyphs going in the same direction.
See Also:
LEFT_TO_RIGHT, RIGHT_TO_LEFT

hashCode

public abstract int hashCode()
Return a hashCode for this glyphset.
Overrides:
hashCode in class Object

equals

public abstract boolean equals(GlyphSet set)
Test for full equality. Font, glyphs, baseline, advances, adjusts, order, levels, count must all match.

getInverseOrder

public static int[] getInverseOrder(int[] values)
Return the inverse array, source array must map 1-1 i.e. if values[i] = j, then inverse[j] = i.

getContiguousOrder

public static int[] getContiguousOrder(int[] values)
Return an array containing contiguous values from 0 to length having the same ordering as the source array. If this would be a canonical ltr ordering, return null. values[] is NOT required to be a permutation.

getNormalizedOrder

public static int[] getNormalizedOrder(int[] values,
                                       byte[] levels,
                                       int start,
                                       int limit)
Return an array containing the values from start up to limit, normalized to fall within the range from 0 up to limit - start. If this would be a canonical ltr ordering, return null. NOTE: This method assumes that values[] is a permutation generated from levels[].

getGlyphCodes

public abstract int[] getGlyphCodes()

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.