All Packages  Class Hierarchy  This Package  Previous  Next  Index  

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

Variable Index

 o LEFT_TO_RIGHT
An argument to setDirection indicating LEFT_TO_RIGHT glyphs.
 o RIGHT_TO_LEFT
An argument to setDirection indicating RIGHT_TO_LEFT glyphs.

Constructor Index

 o GlyphSet()

Method Index

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

Variables

 o LEFT_TO_RIGHT
public static final boolean LEFT_TO_RIGHT
An argument to setDirection indicating LEFT_TO_RIGHT glyphs.

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

See Also:
setDirection

Constructors

 o GlyphSet
public GlyphSet()

Methods

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

 o 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
 o 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
 o getFont
public abstract Font getFont()
Return the font that created this glyphset.

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

 o 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.

 o getGlyphCode
public abstract int getGlyphCode(int index)
Return the glyphcode at the given logical position in this glyphset.

See Also:
getNumGlyphs
 o 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
 o 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
 o getGlyphXAdvance
public abstract float getGlyphXAdvance(int index)
Return the x-direction advance of the glyph at the given logical position.

See Also:
getGlyphYAdvance, getNumGlyphs
 o 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
 o getGlyphYAdvance
public abstract float getGlyphYAdvance(int index)
Return the y-direction advance of the glyph at the given logical position.

See Also:
getGlyphXAdvance, getNumGlyphs
 o 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.

 o 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
 o 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
 o 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
 o 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).
 o 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
 o 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.

 o 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
 o 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.
 o 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.
 o 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
 o draw
public abstract void draw(Graphics2D graphics,
                          float x,
                          float y)
Draw this glyphset at the provided position.

 o 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
 o hashCode
public abstract int hashCode()
Return a hashCode for this glyphset.

Overrides:
hashCode in class Object
 o equals
public abstract boolean equals(GlyphSet set)
Test for full equality. Font, glyphs, baseline, advances, adjusts, order, levels, count must all match.

 o 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.

 o 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.

 o 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[].

 o getGlyphCodes
public abstract int[] getGlyphCodes()

All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Submit a bug or feature