java.awt.font
Class TextLayout

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.font.TextLayout
All Implemented Interfaces:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

public final class TextLayout
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

TextLayout is an immutable graphical representation of styled character data.

It provides the following capabilities:

A TextLayout object can be rendered using its draw method.

TextLayout can be constructed either directly or through the use of a LineBreakMeasurer sample code for java.awt.font.LineBreakMeasurer definition code for java.awt.font.LineBreakMeasurer . When constructed directly, the source text represents a single paragraph. LineBreakMeasurer allows styled text to be broken into lines that fit within a particular width. See the LineBreakMeasurer documentation for more information.

TextLayout construction logically proceeds as follows:

All graphical information returned from a TextLayout object's methods is relative to the origin of the TextLayout, which is the intersection of the TextLayout object's baseline with its left edge. Also, coordinates passed into a TextLayout object's methods are assumed to be relative to the TextLayout object's origin. Clients usually need to translate between a TextLayout object's coordinate system and the coordinate system in another object (such as a Graphics sample code for java.awt.Graphics definition code for java.awt.Graphics object).

TextLayout objects are constructed from styled text, but they do not retain a reference to their source text. Thus, changes in the text previously used to generate a TextLayout do not affect the TextLayout.

Three methods on a TextLayout object (getNextRightHit, getNextLeftHit, and hitTestChar) return instances of TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo . The offsets contained in these TextHitInfo objects are relative to the start of the TextLayout, not to the text used to create the TextLayout. Similarly, TextLayout methods that accept TextHitInfo instances as parameters expect the TextHitInfo object's offsets to be relative to the TextLayout, not to any underlying text storage model.

Examples:

Constructing and drawing a TextLayout and its bounding rectangle:

   Graphics2D g = ...;
   Point2D loc = ...;
   Font font = Font.getFont("Helvetica-bold-italic");
   FontRenderContext frc = g.getFontRenderContext();
   TextLayout layout = new TextLayout("This is a string", font, frc);
   layout.draw(g, (float)loc.getX(), (float)loc.getY());

   Rectangle2D bounds = layout.getBounds();
   bounds.setRect(bounds.getX()+loc.getX(),
                  bounds.getY()+loc.getY(),
                  bounds.getWidth(),
                  bounds.getHeight());
   g.draw(bounds);
 

Hit-testing a TextLayout (determining which character is at a particular graphical location):

   Point2D click = ...;
   TextHitInfo hit = layout.hitTestChar(
                         (float) (click.getX() - loc.getX()),
                         (float) (click.getY() - loc.getY()));
 

Responding to a right-arrow key press:

   int insertionIndex = ...;
   TextHitInfo next = layout.getNextRightHit(insertionIndex);
   if (next != null) {
       // translate graphics to origin of layout on screen
       g.translate(loc.getX(), loc.getY());
       Shape[] carets = layout.getCaretShapes(next.getInsertionIndex());
       g.draw(carets[0]);
       if (carets[1] != null) {
           g.draw(carets[1]);
       }
   }
 

Drawing a selection range corresponding to a substring in the source text. The selected area may not be visually contiguous:

   // selStart, selLimit should be relative to the layout,
   // not to the source text

   int selStart = ..., selLimit = ...;
   Color selectionColor = ...;
   Shape selection = layout.getLogicalHighlightShape(selStart, selLimit);
   // selection may consist of disjoint areas
   // graphics is assumed to be tranlated to origin of layout
   g.setColor(selectionColor);
   g.fill(selection);
 

Drawing a visually contiguous selection range. The selection range may correspond to more than one substring in the source text. The ranges of the corresponding source text substrings can be obtained with getLogicalRangesForVisualSelection():

   TextHitInfo selStart = ..., selLimit = ...;
   Shape selection = layout.getVisualHighlightShape(selStart, selLimit);
   g.setColor(selectionColor);
   g.fill(selection);
   int[] ranges = getLogicalRangesForVisualSelection(selStart, selLimit);
   // ranges[0], ranges[1] is the first selection range,
   // ranges[2], ranges[3] is the second selection range, etc.
 

See Also:
LineBreakMeasurer sample code for java.awt.font.LineBreakMeasurer definition code for java.awt.font.LineBreakMeasurer , TextAttribute sample code for java.awt.font.TextAttribute definition code for java.awt.font.TextAttribute , TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo

Nested Class Summary
static class TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy
          Defines a policy for determining the strong caret location.
 
Field Summary
static TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy DEFAULT_CARET_POLICY sample code for java.awt.font.TextLayout.DEFAULT_CARET_POLICY definition code for java.awt.font.TextLayout.DEFAULT_CARET_POLICY
          This CaretPolicy is used when a policy is not specified by the client.
 
Constructor Summary
TextLayout sample code for java.awt.font.TextLayout.TextLayout(java.text.AttributedCharacterIterator, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout.TextLayout(java.text.AttributedCharacterIterator, java.awt.font.FontRenderContext) (AttributedCharacterIterator sample code for java.text.AttributedCharacterIterator definition code for java.text.AttributedCharacterIterator  text, FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
          Constructs a TextLayout from an iterator over styled text.
TextLayout sample code for java.awt.font.TextLayout.TextLayout(java.lang.String, java.awt.Font, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout.TextLayout(java.lang.String, java.awt.Font, java.awt.font.FontRenderContext) (String sample code for java.lang.String definition code for java.lang.String  string, Font sample code for java.awt.Font definition code for java.awt.Font  font, FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
          Constructs a TextLayout from a String and a Font sample code for java.awt.Font definition code for java.awt.Font .
TextLayout sample code for java.awt.font.TextLayout.TextLayout(java.lang.String, java.util.Map, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout.TextLayout(java.lang.String, java.util.Map, java.awt.font.FontRenderContext) (String sample code for java.lang.String definition code for java.lang.String  string, Map sample code for java.util.Map definition code for java.util.Map <? extends AttributedCharacterIterator.Attribute sample code for java.text.AttributedCharacterIterator.Attribute definition code for java.text.AttributedCharacterIterator.Attribute ,?> attributes, FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
          Constructs a TextLayout from a String and an attribute set.
 
Method Summary
protected  Object sample code for java.lang.Object definition code for java.lang.Object clone sample code for java.awt.font.TextLayout.clone() definition code for java.awt.font.TextLayout.clone() ()
          Creates a copy of this TextLayout.
 void draw sample code for java.awt.font.TextLayout.draw(java.awt.Graphics2D, float, float) definition code for java.awt.font.TextLayout.draw(java.awt.Graphics2D, float, float) (Graphics2D sample code for java.awt.Graphics2D definition code for java.awt.Graphics2D  g2, float x, float y)
          Renders this TextLayout at the specified location in the specified Graphics2D sample code for java.awt.Graphics2D definition code for java.awt.Graphics2D context.
 boolean equals sample code for java.awt.font.TextLayout.equals(java.lang.Object) definition code for java.awt.font.TextLayout.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Returns true if the specified Object is a TextLayout object and if the specified Object equals this TextLayout.
 boolean equals sample code for java.awt.font.TextLayout.equals(java.awt.font.TextLayout) definition code for java.awt.font.TextLayout.equals(java.awt.font.TextLayout) (TextLayout sample code for java.awt.font.TextLayout definition code for java.awt.font.TextLayout  rhs)
          Returns true if the two layouts are equal.
 float getAdvance sample code for java.awt.font.TextLayout.getAdvance() definition code for java.awt.font.TextLayout.getAdvance() ()
          Returns the advance of this TextLayout.
 float getAscent sample code for java.awt.font.TextLayout.getAscent() definition code for java.awt.font.TextLayout.getAscent() ()
          Returns the ascent of this TextLayout.
 byte getBaseline sample code for java.awt.font.TextLayout.getBaseline() definition code for java.awt.font.TextLayout.getBaseline() ()
          Returns the baseline for this TextLayout.
 float[] getBaselineOffsets sample code for java.awt.font.TextLayout.getBaselineOffsets() definition code for java.awt.font.TextLayout.getBaselineOffsets() ()
          Returns the offsets array for the baselines used for this TextLayout.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getBlackBoxBounds sample code for java.awt.font.TextLayout.getBlackBoxBounds(int, int) definition code for java.awt.font.TextLayout.getBlackBoxBounds(int, int) (int firstEndpoint, int secondEndpoint)
          Returns the black box bounds of the characters in the specified range.
 Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D getBounds sample code for java.awt.font.TextLayout.getBounds() definition code for java.awt.font.TextLayout.getBounds() ()
          Returns the bounds of this TextLayout.
 float[] getCaretInfo sample code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns information about the caret corresponding to hit.
 float[] getCaretInfo sample code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns information about the caret corresponding to hit.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getCaretShape sample code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns a Shape representing the caret at the specified hit inside the natural bounds of this TextLayout.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getCaretShape sample code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns a Shape sample code for java.awt.Shape definition code for java.awt.Shape representing the caret at the specified hit inside the specified bounds.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape [] getCaretShapes sample code for java.awt.font.TextLayout.getCaretShapes(int) definition code for java.awt.font.TextLayout.getCaretShapes(int) (int offset)
          Returns two paths corresponding to the strong and weak caret.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape [] getCaretShapes sample code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D) (int offset, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns two paths corresponding to the strong and weak caret.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape [] getCaretShapes sample code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D, java.awt.font.TextLayout.CaretPolicy) (int offset, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds, TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  policy)
          Returns two paths corresponding to the strong and weak caret.
 int getCharacterCount sample code for java.awt.font.TextLayout.getCharacterCount() definition code for java.awt.font.TextLayout.getCharacterCount() ()
          Returns the number of characters represented by this TextLayout.
 byte getCharacterLevel sample code for java.awt.font.TextLayout.getCharacterLevel(int) definition code for java.awt.font.TextLayout.getCharacterLevel(int) (int index)
          Returns the level of the character at index.
 float getDescent sample code for java.awt.font.TextLayout.getDescent() definition code for java.awt.font.TextLayout.getDescent() ()
          Returns the descent of this TextLayout.
 TextLayout sample code for java.awt.font.TextLayout definition code for java.awt.font.TextLayout getJustifiedLayout sample code for java.awt.font.TextLayout.getJustifiedLayout(float) definition code for java.awt.font.TextLayout.getJustifiedLayout(float) (float justificationWidth)
          Creates a copy of this TextLayout justified to the specified width.
 float getLeading sample code for java.awt.font.TextLayout.getLeading() definition code for java.awt.font.TextLayout.getLeading() ()
          Returns the leading of the TextLayout.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getLogicalHighlightShape sample code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int) definition code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int) (int firstEndpoint, int secondEndpoint)
          Returns a Shape enclosing the logical selection in the specified range, extended to the natural bounds of this TextLayout.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getLogicalHighlightShape sample code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int, java.awt.geom.Rectangle2D) (int firstEndpoint, int secondEndpoint, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns a Shape enclosing the logical selection in the specified range, extended to the specified bounds.
 int[] getLogicalRangesForVisualSelection sample code for java.awt.font.TextLayout.getLogicalRangesForVisualSelection(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getLogicalRangesForVisualSelection(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  firstEndpoint, TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  secondEndpoint)
          Returns the logical ranges of text corresponding to a visual selection.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextLeftHit sample code for java.awt.font.TextLayout.getNextLeftHit(int) definition code for java.awt.font.TextLayout.getNextLeftHit(int) (int offset)
          Returns the hit for the next caret to the left (top); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextLeftHit sample code for java.awt.font.TextLayout.getNextLeftHit(int, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getNextLeftHit(int, java.awt.font.TextLayout.CaretPolicy) (int offset, TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  policy)
          Returns the hit for the next caret to the left (top); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextLeftHit sample code for java.awt.font.TextLayout.getNextLeftHit(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getNextLeftHit(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns the hit for the next caret to the left (top); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextRightHit sample code for java.awt.font.TextLayout.getNextRightHit(int) definition code for java.awt.font.TextLayout.getNextRightHit(int) (int offset)
          Returns the hit for the next caret to the right (bottom); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextRightHit sample code for java.awt.font.TextLayout.getNextRightHit(int, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getNextRightHit(int, java.awt.font.TextLayout.CaretPolicy) (int offset, TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  policy)
          Returns the hit for the next caret to the right (bottom); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextRightHit sample code for java.awt.font.TextLayout.getNextRightHit(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getNextRightHit(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns the hit for the next caret to the right (bottom); if there is no such hit, returns null.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getOutline sample code for java.awt.font.TextLayout.getOutline(java.awt.geom.AffineTransform) definition code for java.awt.font.TextLayout.getOutline(java.awt.geom.AffineTransform) (AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform  tx)
          Returns a Shape representing the outline of this TextLayout.
 float getVisibleAdvance sample code for java.awt.font.TextLayout.getVisibleAdvance() definition code for java.awt.font.TextLayout.getVisibleAdvance() ()
          Returns the advance of this TextLayout, minus trailing whitespace.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getVisualHighlightShape sample code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  firstEndpoint, TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  secondEndpoint)
          Returns a Shape enclosing the visual selection in the specified range, extended to the bounds.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getVisualHighlightShape sample code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  firstEndpoint, TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  secondEndpoint, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns a path enclosing the visual selection in the specified range, extended to bounds.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getVisualOtherHit sample code for java.awt.font.TextLayout.getVisualOtherHit(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getVisualOtherHit(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns the hit on the opposite side of the specified hit's caret.
protected  void handleJustify sample code for java.awt.font.TextLayout.handleJustify(float) definition code for java.awt.font.TextLayout.handleJustify(float) (float justificationWidth)
          Justify this layout.
 int hashCode sample code for java.awt.font.TextLayout.hashCode() definition code for java.awt.font.TextLayout.hashCode() ()
          Returns the hash code of this TextLayout.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo hitTestChar sample code for java.awt.font.TextLayout.hitTestChar(float, float) definition code for java.awt.font.TextLayout.hitTestChar(float, float) (float x, float y)
          Returns a TextHitInfo corresponding to the specified point.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo hitTestChar sample code for java.awt.font.TextLayout.hitTestChar(float, float, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.hitTestChar(float, float, java.awt.geom.Rectangle2D) (float x, float y, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns a TextHitInfo corresponding to the specified point.
 boolean isLeftToRight sample code for java.awt.font.TextLayout.isLeftToRight() definition code for java.awt.font.TextLayout.isLeftToRight() ()
          Returns true if this TextLayout has a left-to-right base direction or false if it has a right-to-left base direction.
 boolean isVertical sample code for java.awt.font.TextLayout.isVertical() definition code for java.awt.font.TextLayout.isVertical() ()
          Returns true if this TextLayout is vertical.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.awt.font.TextLayout.toString() definition code for java.awt.font.TextLayout.toString() ()
          Returns debugging information for this TextLayout.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

DEFAULT_CARET_POLICY sample code for java.awt.font.TextLayout.DEFAULT_CARET_POLICY

public static final TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  DEFAULT_CARET_POLICY
This CaretPolicy is used when a policy is not specified by the client. With this policy, a hit on a character whose direction is the same as the line direction is stronger than a hit on a counterdirectional character. If the characters' directions are the same, a hit on the leading edge of a character is stronger than a hit on the trailing edge of a character.

Constructor Detail

TextLayout sample code for java.awt.font.TextLayout(java.lang.String, java.awt.Font, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout(java.lang.String, java.awt.Font, java.awt.font.FontRenderContext)

public TextLayout(String sample code for java.lang.String definition code for java.lang.String  string,
                  Font sample code for java.awt.Font definition code for java.awt.Font  font,
                  FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
Constructs a TextLayout from a String and a Font sample code for java.awt.Font definition code for java.awt.Font . All the text is styled using the specified Font.

The String must specify a single paragraph of text, because an entire paragraph is required for the bidirectional algorithm.

Parameters:
string - the text to display
font - a Font used to style the text
frc - contains information about a graphics device which is needed to measure the text correctly. Text measurements can vary slightly depending on the device resolution, and attributes such as antialiasing. This parameter does not specify a translation between the TextLayout and user space.

TextLayout sample code for java.awt.font.TextLayout(java.lang.String, java.util.Map<? extends java.text.AttributedCharacterIterator.Attribute, ?>, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout(java.lang.String, java.util.Map<? extends java.text.AttributedCharacterIterator.Attribute, ?>, java.awt.font.FontRenderContext)

public TextLayout(String sample code for java.lang.String definition code for java.lang.String  string,
                  Map sample code for java.util.Map definition code for java.util.Map <? extends AttributedCharacterIterator.Attribute sample code for java.text.AttributedCharacterIterator.Attribute definition code for java.text.AttributedCharacterIterator.Attribute ,?> attributes,
                  FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
Constructs a TextLayout from a String and an attribute set.

All the text is styled using the provided attributes.

string must specify a single paragraph of text because an entire paragraph is required for the bidirectional algorithm.

Parameters:
string - the text to display
attributes - the attributes used to style the text
frc - contains information about a graphics device which is needed to measure the text correctly. Text measurements can vary slightly depending on the device resolution, and attributes such as antialiasing. This parameter does not specify a translation between the TextLayout and user space.

TextLayout sample code for java.awt.font.TextLayout(java.text.AttributedCharacterIterator, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout(java.text.AttributedCharacterIterator, java.awt.font.FontRenderContext)

public TextLayout(AttributedCharacterIterator sample code for java.text.AttributedCharacterIterator definition code for java.text.AttributedCharacterIterator  text,
                  FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
Constructs a TextLayout from an iterator over styled text.

The iterator must specify a single paragraph of text because an entire paragraph is required for the bidirectional algorithm.

Parameters:
text - the styled text to display
frc - contains information about a graphics device which is needed to measure the text correctly. Text measurements can vary slightly depending on the device resolution, and attributes such as antialiasing. This parameter does not specify a translation between the TextLayout and user space.
Method Detail

clone sample code for java.awt.font.TextLayout.clone() definition code for java.awt.font.TextLayout.clone()

protected Object sample code for java.lang.Object definition code for java.lang.Object  clone()
Creates a copy of this TextLayout.

Overrides:
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a clone of this instance.
See Also:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

getJustifiedLayout sample code for java.awt.font.TextLayout.getJustifiedLayout(float) definition code for java.awt.font.TextLayout.getJustifiedLayout(float)

public TextLayout sample code for java.awt.font.TextLayout definition code for java.awt.font.TextLayout  getJustifiedLayout(float justificationWidth)
Creates a copy of this TextLayout justified to the specified width.

If this TextLayout has already been justified, an exception is thrown. If this TextLayout object's justification ratio is zero, a TextLayout identical to this TextLayout is returned.

Parameters:
justificationWidth - the width to use when justifying the line. For best results, it should not be too different from the current advance of the line.
Returns:
a TextLayout justified to the specified width.
Throws:
Error sample code for java.lang.Error definition code for java.lang.Error - if this layout has already been justified, an Error is thrown.

handleJustify sample code for java.awt.font.TextLayout.handleJustify(float) definition code for java.awt.font.TextLayout.handleJustify(float)

protected void handleJustify(float justificationWidth)
Justify this layout. Overridden by subclassers to control justification (if there were subclassers, that is...) The layout will only justify if the paragraph attributes (from the source text, possibly defaulted by the layout attributes) indicate a non-zero justification ratio. The text will be justified to the indicated width. The current implementation also adjusts hanging punctuation and trailing whitespace to overhang the justification width. Once justified, the layout may not be rejustified.

Some code may rely on immutablity of layouts. Subclassers should not call this directly, but instead should call getJustifiedLayout, which will call this method on a clone of this layout, preserving the original.

Parameters:
justificationWidth - the width to use when justifying the line. For best results, it should not be too different from the current advance of the line.
See Also:
getJustifiedLayout(float) sample code for java.awt.font.TextLayout.getJustifiedLayout(float) definition code for java.awt.font.TextLayout.getJustifiedLayout(float)

getBaseline sample code for java.awt.font.TextLayout.getBaseline() definition code for java.awt.font.TextLayout.getBaseline()

public byte getBaseline()
Returns the baseline for this TextLayout. The baseline is one of the values defined in Font, which are roman, centered and hanging. Ascent and descent are relative to this baseline. The baselineOffsets are also relative to this baseline.

Returns:
the baseline of this TextLayout.
See Also:
getBaselineOffsets() sample code for java.awt.font.TextLayout.getBaselineOffsets() definition code for java.awt.font.TextLayout.getBaselineOffsets() , Font sample code for java.awt.Font definition code for java.awt.Font

getBaselineOffsets sample code for java.awt.font.TextLayout.getBaselineOffsets() definition code for java.awt.font.TextLayout.getBaselineOffsets()

public float[] getBaselineOffsets()
Returns the offsets array for the baselines used for this TextLayout.

The array is indexed by one of the values defined in Font, which are roman, centered and hanging. The values are relative to this TextLayout object's baseline, so that getBaselineOffsets[getBaseline()] == 0. Offsets are added to the position of the TextLayout object's baseline to get the position for the new baseline.

Returns:
the offsets array containing the baselines used for this TextLayout.
See Also:
getBaseline() sample code for java.awt.font.TextLayout.getBaseline() definition code for java.awt.font.TextLayout.getBaseline() , Font sample code for java.awt.Font definition code for java.awt.Font

getAdvance sample code for java.awt.font.TextLayout.getAdvance() definition code for java.awt.font.TextLayout.getAdvance()

public float getAdvance()
Returns the advance of this TextLayout. The advance is the distance from the origin to the advance of the rightmost (bottommost) character measuring in the line direction.

Returns:
the advance of this TextLayout.

getVisibleAdvance sample code for java.awt.font.TextLayout.getVisibleAdvance() definition code for java.awt.font.TextLayout.getVisibleAdvance()

public float getVisibleAdvance()
Returns the advance of this TextLayout, minus trailing whitespace.

Returns:
the advance of this TextLayout without the trailing whitespace.
See Also:
getAdvance() sample code for java.awt.font.TextLayout.getAdvance() definition code for java.awt.font.TextLayout.getAdvance()

getAscent sample code for java.awt.font.TextLayout.getAscent() definition code for java.awt.font.TextLayout.getAscent()

public float getAscent()
Returns the ascent of this TextLayout. The ascent is the distance from the top (right) of the TextLayout to the baseline. It is always either positive or zero. The ascent is sufficient to accomodate superscripted text and is the maximum of the sum of the ascent, offset, and baseline of each glyph.

Returns:
the ascent of this TextLayout.

getDescent sample code for java.awt.font.TextLayout.getDescent() definition code for java.awt.font.TextLayout.getDescent()

public float getDescent()
Returns the descent of this TextLayout. The descent is the distance from the baseline to the bottom (left) of the TextLayout. It is always either positive or zero. The descent is sufficient to accomodate subscripted text and is the maximum of the sum of the descent, offset, and baseline of each glyph.

Returns:
the descent of this TextLayout.

getLeading sample code for java.awt.font.TextLayout.getLeading() definition code for java.awt.font.TextLayout.getLeading()

public float getLeading()
Returns the leading of the TextLayout. The leading is the suggested interline spacing for this TextLayout.

The leading is computed from the leading, descent, and baseline of all glyphvectors in the TextLayout. The algorithm is roughly as follows:

 maxD = 0;
 maxDL = 0;
 for (GlyphVector g in all glyphvectors) {
    maxD = max(maxD, g.getDescent() + offsets[g.getBaseline()]);
    maxDL = max(maxDL, g.getDescent() + g.getLeading() +
                       offsets[g.getBaseline()]);
 }
 return maxDL - maxD;
 

Returns:
the leading of this TextLayout.

getBounds sample code for java.awt.font.TextLayout.getBounds() definition code for java.awt.font.TextLayout.getBounds()

public Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  getBounds()
Returns the bounds of this TextLayout. The bounds contains all of the pixels the TextLayout can draw. It might not coincide exactly with the ascent, descent, origin or advance of the TextLayout.

Returns:
a Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D that is the bounds of this TextLayout.

isLeftToRight sample code for java.awt.font.TextLayout.isLeftToRight() definition code for java.awt.font.TextLayout.isLeftToRight()

public boolean isLeftToRight()
Returns true if this TextLayout has a left-to-right base direction or false if it has a right-to-left base direction. The TextLayout has a base direction of either left-to-right (LTR) or right-to-left (RTL). The base direction is independent of the actual direction of text on the line, which may be either LTR, RTL, or mixed. Left-to-right layouts by default should position flush left. If the layout is on a tabbed line, the tabs run left to right, so that logically successive layouts position left to right. The opposite is true for RTL layouts. By default they should position flush left, and tabs run right-to-left.

Returns:
true if the base direction of this TextLayout is left-to-right; false otherwise.

isVertical sample code for java.awt.font.TextLayout.isVertical() definition code for java.awt.font.TextLayout.isVertical()

public boolean isVertical()
Returns true if this TextLayout is vertical.

Returns:
true if this TextLayout is vertical; false otherwise.

getCharacterCount sample code for java.awt.font.TextLayout.getCharacterCount() definition code for java.awt.font.TextLayout.getCharacterCount()

public int getCharacterCount()
Returns the number of characters represented by this TextLayout.

Returns:
the number of characters in this TextLayout.

getCaretInfo sample code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D)

public float[] getCaretInfo(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit,
                            Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
Returns information about the caret corresponding to hit. The first element of the array is the intersection of the caret with the baseline. The second element of the array is the inverse slope (run/rise) of the caret.

This method is meant for informational use. To display carets, it is better to use getCaretShapes.

Parameters:
hit - a hit on a character in this TextLayout
bounds - the bounds to which the caret info is constructed
Returns:
a two-element array containing the position and slope of the caret.
See Also:
getCaretShapes(int, Rectangle2D, TextLayout.CaretPolicy) sample code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D, java.awt.font.TextLayout.CaretPolicy) , Font.getItalicAngle() sample code for java.awt.Font.getItalicAngle() definition code for java.awt.Font.getItalicAngle()

getCaretInfo sample code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo)

public float[] getCaretInfo(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
Returns information about the caret corresponding to hit. This method is a convenience overload of getCaretInfo and uses the natural bounds of this TextLayout.

Parameters:
hit - a hit on a character in this TextLayout
Returns:
the information about a caret corresponding to a hit.

getNextRightHit sample code for java.awt.font.TextLayout.getNextRightHit(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getNextRightHit(java.awt.font.TextHitInfo)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  getNextRightHit(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
Returns the hit for the next caret to the right (bottom); if there is no such hit, returns null. If the hit character index is out of bounds, an IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException is thrown.

Parameters:
hit - a hit on a character in this layout
Returns:
a hit whose caret appears at the next position to the right (bottom) of the caret of the provided hit or null.

getNextRightHit sample code for java.awt.font.TextLayout.getNextRightHit(int, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getNextRightHit(int, java.awt.font.TextLayout.CaretPolicy)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  getNextRightHit(int offset,
                                   TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  policy)
Returns the hit for the next caret to the right (bottom); if no such hit, returns null. The hit is to the right of the strong caret at the specified offset, as determined by the specified policy. The returned hit is the stronger of the two possible hits, as determined by the specified policy.

Parameters:
offset - an insertion offset in this TextLayout. Cannot be less than 0 or greater than this TextLayout object's character count.
policy - the policy used to select the strong caret
Returns:
a hit whose caret appears at the next position to the right (bottom) of the caret of the provided hit, or null.

getNextRightHit sample code for java.awt.font.TextLayout.getNextRightHit(int) definition code for java.awt.font.TextLayout.getNextRightHit(int)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  getNextRightHit(int offset)
Returns the hit for the next caret to the right (bottom); if no such hit, returns null. The hit is to the right of the strong caret at the specified offset, as determined by the default policy. The returned hit is the stronger of the two possible hits, as determined by the default policy.

Parameters:
offset - an insertion offset in this TextLayout. Cannot be less than 0 or greater than the TextLayout object's character count.
Returns:
a hit whose caret appears at the next position to the right (bottom) of the caret of the provided hit, or null.

getNextLeftHit sample code for java.awt.font.TextLayout.getNextLeftHit(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getNextLeftHit(java.awt.font.TextHitInfo)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  getNextLeftHit(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
Returns the hit for the next caret to the left (top); if no such hit, returns null. If the hit character index is out of bounds, an IllegalArgumentException is thrown.

Parameters:
hit - a hit on a character in this TextLayout.
Returns:
a hit whose caret appears at the next position to the left (top) of the caret of the provided hit, or null.

getNextLeftHit sample code for java.awt.font.TextLayout.getNextLeftHit(int, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getNextLeftHit(int, java.awt.font.TextLayout.CaretPolicy)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  getNextLeftHit(int offset,
                                  TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  policy)
Returns the hit for the next caret to the left (top); if no such hit, returns null. The hit is to the left of the strong caret at the specified offset, as determined by the specified policy. The returned hit is the stronger of the two possible hits, as determined by the specified policy.

Parameters:
offset - an insertion offset in this TextLayout. Cannot be less than 0 or greater than this TextLayout object's character count.
policy - the policy used to select the strong caret
Returns:
a hit whose caret appears at the next position to the left (top) of the caret of the provided hit, or null.

getNextLeftHit sample code for java.awt.font.TextLayout.getNextLeftHit(int) definition code for java.awt.font.TextLayout.getNextLeftHit(int)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  getNextLeftHit(int offset)
Returns the hit for the next caret to the left (top); if no such hit, returns null. The hit is to the left of the strong caret at the specified offset, as determined by the default policy. The returned hit is the stronger of the two possible hits, as determined by the default policy.

Parameters:
offset - an insertion offset in this TextLayout. Cannot be less than 0 or greater than this TextLayout object's character count.
Returns:
a hit whose caret appears at the next position to the left (top) of the caret of the provided hit, or null.

getVisualOtherHit sample code for java.awt.font.TextLayout.getVisualOtherHit(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getVisualOtherHit(java.awt.font.TextHitInfo)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  getVisualOtherHit(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
Returns the hit on the opposite side of the specified hit's caret.

Parameters:
hit - the specified hit
Returns:
a hit that is on the opposite side of the specified hit's caret.

getCaretShape sample code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape  getCaretShape(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit,
                           Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
Returns a Shape sample code for java.awt.Shape definition code for java.awt.Shape representing the caret at the specified hit inside the specified bounds.

Parameters:
hit - the hit at which to generate the caret
bounds - the bounds of the TextLayout to use in generating the caret.
Returns:
a Shape representing the caret.

getCaretShape sample code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape  getCaretShape(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
Returns a Shape representing the caret at the specified hit inside the natural bounds of this TextLayout.

Parameters:
hit - the hit at which to generate the caret
Returns:
a Shape representing the caret.

getCharacterLevel sample code for java.awt.font.TextLayout.getCharacterLevel(int) definition code for java.awt.font.TextLayout.getCharacterLevel(int)

public byte getCharacterLevel(int index)
Returns the level of the character at index. Indices -1 and characterCount are assigned the base level of this TextLayout.

Parameters:
index - the index of the character from which to get the level
Returns:
the level of the character at the specified index.

getCaretShapes sample code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D, java.awt.font.TextLayout.CaretPolicy)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape [] getCaretShapes(int offset,
                              Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds,
                              TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  policy)
Returns two paths corresponding to the strong and weak caret.

Parameters:
offset - an offset in this TextLayout
bounds - the bounds to which to extend the carets
policy - the specified CaretPolicy
Returns:
an array of two paths. Element zero is the strong caret. If there are two carets, element one is the weak caret, otherwise it is null.

getCaretShapes sample code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape [] getCaretShapes(int offset,
                              Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
Returns two paths corresponding to the strong and weak caret. This method is a convenience overload of getCaretShapes that uses the default caret policy.

Parameters:
offset - an offset in this TextLayout
bounds - the bounds to which to extend the carets
Returns:
two paths corresponding to the strong and weak caret as defined by the DEFAULT_CARET_POLICY

getCaretShapes sample code for java.awt.font.TextLayout.getCaretShapes(int) definition code for java.awt.font.TextLayout.getCaretShapes(int)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape [] getCaretShapes(int offset)
Returns two paths corresponding to the strong and weak caret. This method is a convenience overload of getCaretShapes that uses the default caret policy and this TextLayout object's natural bounds.

Parameters:
offset - an offset in this TextLayout
Returns:
two paths corresponding to the strong and weak caret as defined by the DEFAULT_CARET_POLICY

getLogicalRangesForVisualSelection sample code for java.awt.font.TextLayout.getLogicalRangesForVisualSelection(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getLogicalRangesForVisualSelection(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo)

public int[] getLogicalRangesForVisualSelection(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  firstEndpoint,
                                                TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  secondEndpoint)
Returns the logical ranges of text corresponding to a visual selection.

Parameters:
firstEndpoint - an endpoint of the visual range
secondEndpoint - the other endpoint of the visual range. This endpoint can be less than firstEndpoint.
Returns:
an array of integers representing start/limit pairs for the selected ranges.
See Also:
getVisualHighlightShape(TextHitInfo, TextHitInfo, Rectangle2D) sample code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D)

getVisualHighlightShape sample code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape  getVisualHighlightShape(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  firstEndpoint,
                                     TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  secondEndpoint,
                                     Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
Returns a path enclosing the visual selection in the specified range, extended to bounds.

If the selection includes the leftmost (topmost) position, the selection is extended to the left (top) of bounds. If the selection includes the rightmost (bottommost) position, the selection is extended to the right (bottom) of the bounds. The height (width on vertical lines) of the selection is always extended to bounds.

Although the selection is always contiguous, the logically selected text can be discontiguous on lines with mixed-direction text. The logical ranges of text selected can be retrieved using getLogicalRangesForVisualSelection. For example, consider the text 'ABCdef' where capital letters indicate right-to-left text, rendered on a right-to-left line, with a visual selection from 0L (the leading edge of 'A') to 3T (the trailing edge of 'd'). The text appears as follows, with bold underlined areas representing the selection:

    defCBA  
 
The logical selection ranges are 0-3, 4-6 (ABC, ef) because the visually contiguous text is logically discontiguous. Also note that since the rightmost position on the layout (to the right of 'A') is selected, the selection is extended to the right of the bounds.

Parameters:
firstEndpoint - one end of the visual selection
secondEndpoint - the other end of the visual selection
bounds - the bounding rectangle to which to extend the selection
Returns:
a Shape enclosing the selection.
See Also:
getLogicalRangesForVisualSelection(TextHitInfo, TextHitInfo) sample code for java.awt.font.TextLayout.getLogicalRangesForVisualSelection(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getLogicalRangesForVisualSelection(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) , getLogicalHighlightShape(int, int, Rectangle2D) sample code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int, java.awt.geom.Rectangle2D)

getVisualHighlightShape sample code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape  getVisualHighlightShape(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  firstEndpoint,
                                     TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  secondEndpoint)
Returns a Shape enclosing the visual selection in the specified range, extended to the bounds. This method is a convenience overload of getVisualHighlightShape that uses the natural bounds of this TextLayout.

Parameters:
firstEndpoint - one end of the visual selection
secondEndpoint - the other end of the visual selection
Returns:
a Shape enclosing the selection.

getLogicalHighlightShape sample code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int, java.awt.geom.Rectangle2D)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape  getLogicalHighlightShape(int firstEndpoint,
                                      int secondEndpoint,
                                      Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
Returns a Shape enclosing the logical selection in the specified range, extended to the specified bounds.

If the selection range includes the first logical character, the selection is extended to the portion of bounds before the start of this TextLayout. If the range includes the last logical character, the selection is extended to the portion of bounds after the end of this TextLayout. The height (width on vertical lines) of the selection is always extended to bounds.

The selection can be discontiguous on lines with mixed-direction text. Only those characters in the logical range between start and limit appear selected. For example, consider the text 'ABCdef' where capital letters indicate right-to-left text, rendered on a right-to-left line, with a logical selection from 0 to 4 ('ABCd'). The text appears as follows, with bold standing in for the selection, and underlining for the extension:

    defCBA  
 
The selection is discontiguous because the selected characters are visually discontiguous. Also note that since the range includes the first logical character (A), the selection is extended to the portion of the bounds before the start of the layout, which in this case (a right-to-left line) is the right portion of the bounds.

Parameters:
firstEndpoint - an endpoint in the range of characters to select
secondEndpoint - the other endpoint of the range of characters to select. Can be less than firstEndpoint. The range includes the character at min(firstEndpoint, secondEndpoint), but excludes max(firstEndpoint, secondEndpoint).
bounds - the bounding rectangle to which to extend the selection
Returns:
an area enclosing the selection.
See Also:
getVisualHighlightShape(TextHitInfo, TextHitInfo, Rectangle2D) sample code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D)

getLogicalHighlightShape sample code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int) definition code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape  getLogicalHighlightShape(int firstEndpoint,
                                      int secondEndpoint)
Returns a Shape enclosing the logical selection in the specified range, extended to the natural bounds of this TextLayout. This method is a convenience overload of getLogicalHighlightShape that uses the natural bounds of this TextLayout.

Parameters:
firstEndpoint - an endpoint in the range of characters to select
secondEndpoint - the other endpoint of the range of characters to select. Can be less than firstEndpoint. The range includes the character at min(firstEndpoint, secondEndpoint), but excludes max(firstEndpoint, secondEndpoint).
Returns:
a Shape enclosing the selection.

getBlackBoxBounds sample code for java.awt.font.TextLayout.getBlackBoxBounds(int, int) definition code for java.awt.font.TextLayout.getBlackBoxBounds(int, int)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape  getBlackBoxBounds(int firstEndpoint,
                               int secondEndpoint)
Returns the black box bounds of the characters in the specified range. The black box bounds is an area consisting of the union of the bounding boxes of all the glyphs corresponding to the characters between start and limit. This path may be disjoint.

Parameters:
firstEndpoint - one end of the character range
secondEndpoint - the other end of the character range. Can be less than firstEndpoint.
Returns:
a path enclosing the black box bounds.

hitTestChar sample code for java.awt.font.TextLayout.hitTestChar(float, float, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.hitTestChar(float, float, java.awt.geom.Rectangle2D)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hitTestChar(float x,
                               float y,
                               Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
Returns a TextHitInfo corresponding to the specified point. Coordinates outside the bounds of the TextLayout map to hits on the leading edge of the first logical character, or the trailing edge of the last logical character, as appropriate, regardless of the position of that character in the line. Only the direction along the baseline is used to make this evaluation.

Parameters:
x - the x offset from the origin of this TextLayout
y - the y offset from the origin of this TextLayout
bounds - the bounds of the TextLayout
Returns:
a hit describing the character and edge (leading or trailing) under the specified point.

hitTestChar sample code for java.awt.font.TextLayout.hitTestChar(float, float) definition code for java.awt.font.TextLayout.hitTestChar(float, float)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hitTestChar(float x,
                               float y)
Returns a TextHitInfo corresponding to the specified point. This method is a convenience overload of hitTestChar that uses the natural bounds of this TextLayout.

Parameters:
x - the x offset from the origin of this TextLayout
y - the y offset from the origin of this TextLayout
Returns:
a hit describing the character and edge (leading or trailing) under the specified point.

hashCode sample code for java.awt.font.TextLayout.hashCode() definition code for java.awt.font.TextLayout.hashCode()

public int hashCode()
Returns the hash code of this TextLayout.

Overrides:
hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
the hash code of this TextLayout.
See Also:
Object.equals(java.lang.Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

equals sample code for java.awt.font.TextLayout.equals(java.lang.Object) definition code for java.awt.font.TextLayout.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.Object  obj)
Returns true if the specified Object is a TextLayout object and if the specified Object equals this TextLayout.

Overrides:
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) in class Object sample code for java.lang.Object definition code for java.lang.Object
Parameters:
obj - an Object to test for equality
Returns:
true if the specified Object equals this TextLayout; false otherwise.
See Also:
Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

equals sample code for java.awt.font.TextLayout.equals(java.awt.font.TextLayout) definition code for java.awt.font.TextLayout.equals(java.awt.font.TextLayout)

public boolean equals(TextLayout sample code for java.awt.font.TextLayout definition code for java.awt.font.TextLayout  rhs)
Returns true if the two layouts are equal. Two layouts are equal if they contain equal glyphvectors in the same order.

Parameters:
rhs - the TextLayout to compare to this TextLayout
Returns:
true if the specified TextLayout equals this TextLayout.

toString sample code for java.awt.font.TextLayout.toString() definition code for java.awt.font.TextLayout.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns debugging information for this TextLayout.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
the textLine of this TextLayout as a String.

draw sample code for java.awt.font.TextLayout.draw(java.awt.Graphics2D, float, float) definition code for java.awt.font.TextLayout.draw(java.awt.Graphics2D, float, float)

public void draw(Graphics2D sample code for java.awt.Graphics2D definition code for java.awt.Graphics2D  g2,
                 float x,
                 float y)
Renders this TextLayout at the specified location in the specified Graphics2D sample code for java.awt.Graphics2D definition code for java.awt.Graphics2D context. The origin of the layout is placed at x, y. Rendering may touch any point within getBounds() of this position. This leaves the g2 unchanged.

Parameters:
g2 - the Graphics2D context into which to render the layout
x, y - the coordinates of the origin of this TextLayout
See Also:
getBounds() sample code for java.awt.font.TextLayout.getBounds() definition code for java.awt.font.TextLayout.getBounds()

getOutline sample code for java.awt.font.TextLayout.getOutline(java.awt.geom.AffineTransform) definition code for java.awt.font.TextLayout.getOutline(java.awt.geom.AffineTransform)

public Shape sample code for java.awt.Shape definition code for java.awt.Shape  getOutline(AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform  tx)
Returns a Shape representing the outline of this TextLayout.

Parameters:
tx - an optional AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform to apply to the outline of this TextLayout.
Returns:
a Shape that is the outline of this TextLayout.