TextLayout

<code>TextLayout</code> is a graphic object that represents styled text. <p> Instances of this class provide support for drawing, cursor navigation, hit testing, text wrapping, alignment, tab expansion line breaking, etc. These are aspects required for rendering internationalized text. </p><p> Application code must explicitly invoke the <code>TextLayout#dispose()</code> method to release the operating system resources managed by each instance when those instances are no longer required. </p>

@see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a> @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample, StyledText tab</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>

@since 3.0

final
class TextLayout : Resource {
Font font;
String text;
int ascent;
int descent;
int[] segments;
int[] tabs;
StyleItem[] styles;
PangoLayout* layout;
PangoContext* context;
PangoAttrList* attrList;
int[] invalidOffsets;
dchar LTR_MARK;
dchar RTL_MARK;
dchar ZWS;
dchar ZWNBS;
String STR_LTR_MARK;
String STR_RTL_MARK;
String STR_ZWS;
String STR_ZWNBS;
}

Constructors

this
this(Device device)

Constructs a new instance of this class on the given device. <p> You must dispose the text layout when it is no longer required. </p>

Members

Functions

draw
void draw(GC gc, int x, int y)

Draws the receiver's text using the specified GC at the specified point.

draw
void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground)

Draws the receiver's text using the specified GC at the specified point.

draw
void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags)

Draws the receiver's text using the specified GC at the specified point. <p> The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code> or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend the specified selection behavior to the last line. </p> @param gc the GC to draw @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn @param selectionStart the offset where the selections starts, or -1 indicating no selection @param selectionEnd the offset where the selections ends, or -1 indicating no selection @param selectionForeground selection foreground, or NULL to use the system default color @param selectionBackground selection background, or NULL to use the system default color @param flags drawing options

getAlignment
int getAlignment()

Returns the receiver's horizontal text alignment, which will be one of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or <code>SWT.RIGHT</code>.

getAscent
int getAscent()

Returns the ascent of the receiver.

getBounds
Rectangle getBounds()

Returns the bounds of the receiver. The width returned is either the width of the longest line or the width set using {@link TextLayout#setWidth(int)}. To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}.

getBounds
Rectangle getBounds(int start, int end)

Returns the bounds for the specified range of characters. The bounds is the smallest rectangle that encompasses all characters in the range. The start and end offsets are inclusive and will be clamped if out of range.

getDescent
int getDescent()

Returns the descent of the receiver.

getFont
Font getFont()

Returns the default font currently being used by the receiver to draw and measure text.

getIndent
int getIndent()

Returns the receiver's indent. * @return the receiver's indent * @exception SWTException <ul> <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> </ul> * @since 3.2

getJustify
bool getJustify()

Returns the receiver's justification. * @return the receiver's justification * @exception SWTException <ul> <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> </ul> * @since 3.2

getLevel
int getLevel(int offset)

Returns the embedding level for the specified character offset. The embedding level is usually used to determine the directionality of a character in bidirectional text.

getLineBounds
Rectangle getLineBounds(int lineIndex)

Returns the bounds of the line for the specified line index.

getLineCount
int getLineCount()

Returns the receiver's line count. This includes lines caused by wrapping.

getLineIndex
int getLineIndex(int offset)

Returns the index of the line that contains the specified character offset.

getLineMetrics
FontMetrics getLineMetrics(int lineIndex)

Returns the font metrics for the specified line index.

getLineOffsets
int[] getLineOffsets()

Returns the line offsets. Each value in the array is the offset for the first character in a line except for the last value, which contains the length of the text.

getLocation
Point getLocation(int offset, bool trailing)

Returns the location for the specified character offset. The <code>trailing</code> argument indicates whether the offset corresponds to the leading or trailing edge of the cluster.

getNextOffset
int getNextOffset(int offset, int movement)

Returns the next offset for the specified offset and movement type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>, <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>, <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.

getOffset
int getOffset(Point point, int[] trailing)

Returns the character offset for the specified point. For a typical character, the trailing argument will be filled in to indicate whether the point is closer to the leading edge (0) or the trailing edge (1). When the point is over a cluster composed of multiple characters, the trailing argument will be filled with the position of the character in the cluster that is closest to the point.

getOffset
int getOffset(int x, int y, int[] trailing)

Returns the character offset for the specified point. For a typical character, the trailing argument will be filled in to indicate whether the point is closer to the leading edge (0) or the trailing edge (1). When the point is over a cluster composed of multiple characters, the trailing argument will be filled with the position of the character in the cluster that is closest to the point.

getOrientation
int getOrientation()

Returns the orientation of the receiver.

getPreviousOffset
int getPreviousOffset(int index, int movement)

Returns the previous offset for the specified offset and movement type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>, <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>, <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.

getRanges
int[] getRanges()

Gets the ranges of text that are associated with a <code>TextStyle</code>.

getSegments
int[] getSegments()

Returns the text segments offsets of the receiver.

getSpacing
int getSpacing()

Returns the line spacing of the receiver.

getStyle
TextStyle getStyle(int offset)

Gets the style of the receiver at the specified character offset.

getStyles
TextStyle[] getStyles()

Gets all styles of the receiver.

getTabs
int[] getTabs()

Returns the tab list of the receiver.

getText
String getText()

Gets the receiver's text, which will be an empty string if it has never been set.

getWidth
int getWidth()

Returns the width of the receiver.

isDisposed
bool isDisposed()

Returns <code>true</code> if the text layout has been disposed, and <code>false</code> otherwise. <p> This method gets the dispose state for the text layout. When a text layout has been disposed, it is an error to invoke any other method using the text layout. </p>

setAlignment
void setAlignment(int alignment)

Sets the text alignment for the receiver. The alignment controls how a line of text is positioned horizontally. The argument should be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>. <p> The default alignment is <code>SWT.LEFT</code>. Note that the receiver's width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code> alignment. </p>

setAscent
void setAscent(int ascent)

Sets the ascent of the receiver. The ascent is distance in pixels from the baseline to the top of the line and it is applied to all lines. The default value is <code>-1</code> which means that the ascent is calculated from the line fonts.

setDescent
void setDescent(int descent)

Sets the descent of the receiver. The descent is distance in pixels from the baseline to the bottom of the line and it is applied to all lines. The default value is <code>-1</code> which means that the descent is calculated from the line fonts.

setFont
void setFont(Font font)

Sets the default font which will be used by the receiver to draw and measure text. If the argument is null, then a default font appropriate for the platform will be used instead. Note that a text style can override the default font.

setIndent
void setIndent(int indent)

Sets the indent of the receiver. This indent it applied of the first line of each paragraph.

setJustify
void setJustify(bool justify)

Sets the justification of the receiver. Note that the receiver's width must be set in order to use justification.

setOrientation
void setOrientation(int orientation)

Sets the orientation of the receiver, which must be one of <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.

setSegments
void setSegments(int[] segments)

Sets the offsets of the receiver's text segments. Text segments are used to override the default behaviour of the bidirectional algorithm. Bidirectional reordering can happen within a text segment but not between two adjacent segments. <p> Each text segment is determined by two consecutive offsets in the <code>segments</code> arrays. The first element of the array should always be zero and the last one should always be equals to length of the text. </p>

setSpacing
void setSpacing(int spacing)

Sets the line spacing of the receiver. The line spacing is the space left between lines.

setStyle
void setStyle(TextStyle style, int start, int end)

Sets the style of the receiver for the specified range. Styles previously set for that range will be overwritten. The start and end offsets are inclusive and will be clamped if out of range.

setTabs
void setTabs(int[] tabs)

Sets the receiver's tab list. Each value in the tab list specifies the space in pixels from the origin of the text layout to the respective tab stop. The last tab stop width is repeated continuously.

setText
void setText(String text)

Sets the receiver's text.

setWidth
void setWidth(int width)

Sets the line width of the receiver, which determines how text should be wrapped and aligned. The default value is <code>-1</code> which means wrapping is disabled.

toString
String toString()

Returns a string containing a concise, human-readable description of the receiver.

Inherited Members

From Resource

device
Device device;

the device where this resource was created

dispose
void dispose()

Disposes of the operating system resources associated with this resource. Applications must dispose of all resources which they allocate.

getDevice
Device getDevice()

Returns the <code>Device</code> where this resource was created.

isDisposed
bool isDisposed()

Returns <code>true</code> if the resource has been disposed, and <code>false</code> otherwise. <p> This method gets the dispose state for the resource. When a resource has been disposed, it is an error to invoke any other method using the resource.

Meta