Class TextLayout
TextLayout is a graphic object that represents
styled text.
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.
Application code must explicitly invoke the TextLayout#dispose()
method to release the operating system resources managed by each instance
when those instances are no longer required.
- Since:
- 3.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classAdapts necessary Pango APIs to enforce fixed line metrics (when set)(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) long(package private) long(package private) int(package private) Font(package private) int(package private) int[](package private) long(package private) static final char(package private) TextLayout.MetricsAdapter(package private) static final char(package private) int[](package private) char[](package private) long(package private) TextLayout.StyleItem[](package private) int(package private) int[](package private) String(package private) int(package private) int(package private) int(package private) static final char(package private) static final char -
Constructor Summary
ConstructorsConstructorDescriptionTextLayout(Device device) Constructs a new instance of this class on the given device. -
Method Summary
Modifier and TypeMethodDescription(package private) int_getOffset(int offset, int movement, boolean forward) (package private) void(package private) int[]computePolyline(int left, int top, int right, int bottom) (package private) void(package private) voiddestroy()voidDraws the receiver's text using the specified GC at the specified point.voiddraw(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.voiddraw(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.(package private) voiddrawBorder(GC gc, int x, int y, GdkRGBA selectionColor) (package private) voiddrawInPixels(GC gc, int x, int y) (package private) voiddrawInPixels(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) (package private) voiddrawInPixels(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) (package private) voiddrawWithCairo(GC gc, int x, int y, int start, int end, int yExtent, boolean fullSelection, GdkRGBA fg, GdkRGBA bg) (package private) voidfreeRuns()intReturns the receiver's horizontal text alignment, which will be one ofSWT.LEFT,SWT.CENTERorSWT.RIGHT.intReturns the ascent of the receiver.Returns the bounds of the receiver.getBounds(int start, int end) Returns the bounds for the specified range of characters.(package private) RectanglegetBoundsInPixels(int spacingInPixels) (package private) RectanglegetBoundsInPixels(int start, int end) intReturns the descent of the receiver.getFont()Returns the default font currently being used by the receiver to draw and measure text.intReturns the receiver's indent.(package private) intbooleanReturns the receiver's justification.intgetLevel(int offset) Returns the embedding level for the specified character offset.getLineBounds(int lineIndex) Returns the bounds of the line for the specified line index.(package private) RectanglegetLineBoundsInPixels(int lineIndex) private RectanglegetLineBoundsInPixels(int lineIndex, long iter) intReturns the receiver's line count.intgetLineIndex(int offset) Returns the index of the line that contains the specified character offset.getLineMetrics(int lineIndex) Returns the font metrics for the specified line index.int[]Returns the line offsets.getLocation(int offset, boolean trailing) Returns the location for the specified character offset.(package private) PointgetLocationInPixels(int offset, boolean trailing) intgetNextOffset(int offset, int movement) Returns the next offset for the specified offset and movement type.intgetOffset(int x, int y, int[] trailing) Returns the character offset for the specified point.intReturns the character offset for the specified point.(package private) intgetOffsetInPixels(int x, int y, int[] trailing) (package private) intgetOffsetInPixels(Point point, int[] trailing) intReturns the orientation of the receiver.intgetPreviousOffset(int offset, int movement) Returns the previous offset for the specified offset and movement type.int[]Gets the ranges of text that are associated with aTextStyle.private intReturns the scaled vertical indent.int[]Returns the text segments offsets of the receiver.char[]Returns the segments characters of the receiver.(package private) StringintReturns the line spacing of the receiver.(package private) intgetStyle(int offset) Gets the style of the receiver at the specified character offset.Gets all styles of the receiver.int[]getTabs()Returns the tab list of the receiver.(package private) int[]getText()Gets the receiver's text, which will be an empty string if it has never been set.intReturns the text direction of the receiver.intReturns the vertical indent of the receiver.intgetWidth()Returns the width of the receiver.(package private) intintReturns the receiver's wrap indent.(package private) int(package private) static final booleanisAlef(int ch) booleanReturnstrueif the text layout has been disposed, andfalseotherwise.(package private) static final booleanisLam(int ch) voidsetAlignment(int alignment) Sets the text alignment for the receiver.voidsetAscent(int ascent) Sets the ascent of the receiver.voidsetDefaultTabWidth(int tabLength) Sets Default Tab Width in terms if number of space characters.voidsetDescent(int descent) Sets the descent of the receiver.voidsetFixedLineMetrics(FontMetrics metrics) Forces line heights in receiver to obey provided value.voidSets the default font which will be used by the receiver to draw and measure text.voidsetIndent(int indent) Sets the indent of the receiver.(package private) voidsetIndentInPixels(int indent) voidsetJustify(boolean justify) Sets the justification of the receiver.voidsetOrientation(int orientation) Sets the orientation of the receiver, which must be one ofSWT.LEFT_TO_RIGHTorSWT.RIGHT_TO_LEFT.voidsetSegments(int[] segments) Sets the offsets of the receiver's text segments.voidsetSegmentsChars(char[] segmentsChars) Sets the characters to be used in the segments boundaries.voidsetSpacing(int spacing) Sets the line spacing of the receiver.(package private) voidsetSpacingInPixels(int spacing) voidSets the style of the receiver for the specified range.voidsetTabs(int[] tabs) Sets the receiver's tab list.(package private) voidsetTabsInPixels(int[] tabs) voidSets the receiver's text.voidsetTextDirection(int textDirection) Sets the text direction of the receiver, which must be one ofSWT.LEFT_TO_RIGHT,SWT.RIGHT_TO_LEFTorSWT.AUTO_TEXT_DIRECTION.voidsetVerticalIndent(int verticalIndent) Sets the vertical indent of the receiver.(package private) voidsetWidth()voidsetWidth(int width) Sets the line width of the receiver, which determines how text should be wrapped and aligned.(package private) voidsetWidthInPixels(int width) voidsetWrapIndent(int wrapIndent) Sets the wrap indent of the receiver.(package private) voidsetWrapIndentInPixels(int wrapIndent) toString()Returns a string containing a concise, human-readable description of the receiver.(package private) inttranslateOffset(int offset) (package private) intuntranslateOffset(int offset) (package private) intwidth()Methods inherited from class Resource
destroyHandlesExcept, dispose, getDevice, ignoreNonDisposed, init, initNonDisposeTracking, setNonDisposeHandler
-
Field Details
-
font
Font font -
text
String text -
ascentInPoints
int ascentInPoints -
descentInPoints
int descentInPoints -
indent
int indent -
wrapIndent
int wrapIndent -
wrapWidth
int wrapWidth -
segments
int[] segments -
segmentsChars
char[] segmentsChars -
tabs
int[] tabs -
styles
TextLayout.StyleItem[] styles -
stylesCount
int stylesCount -
layout
long layout -
context
long context -
attrList
long attrList -
selAttrList
long selAttrList -
invalidOffsets
int[] invalidOffsets -
verticalIndentInPoints
int verticalIndentInPoints -
metricsAdapter
TextLayout.MetricsAdapter metricsAdapter -
LTR_MARK
static final char LTR_MARK- See Also:
-
RTL_MARK
static final char RTL_MARK- See Also:
-
ZWS
static final char ZWS- See Also:
-
ZWNBS
static final char ZWNBS- See Also:
-
-
Constructor Details
-
TextLayout
Constructs a new instance of this class on the given device.You must dispose the text layout when it is no longer required.
- Parameters:
device- the device on which to allocate the text layout- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT - if device is null and there is no current device
- See Also:
-
-
Method Details
-
checkLayout
void checkLayout() -
computeRuns
void computeRuns() -
computePolyline
int[] computePolyline(int left, int top, int right, int bottom) -
destroy
-
draw
Draws the receiver's text using the specified GC at the specified point.- Parameters:
gc- the GC to drawx- the x coordinate of the top left corner of the rectangular area where the text is to be drawny- the y coordinate of the top left corner of the rectangular area where the text is to be drawn- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the gc is null
-
drawInPixels
-
draw
public 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.- Parameters:
gc- the GC to drawx- the x coordinate of the top left corner of the rectangular area where the text is to be drawny- the y coordinate of the top left corner of the rectangular area where the text is to be drawnselectionStart- the offset where the selections starts, or -1 indicating no selectionselectionEnd- the offset where the selections ends, or -1 indicating no selectionselectionForeground- selection foreground, or NULL to use the system default colorselectionBackground- selection background, or NULL to use the system default color- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the gc is null
-
drawInPixels
-
draw
public 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.The parameter
flagscan include one ofSWT.DELIMITER_SELECTIONorSWT.FULL_SELECTIONto specify the selection behavior on all lines except for the last line, and can also includeSWT.LAST_LINE_SELECTIONto extend the specified selection behavior to the last line.- Parameters:
gc- the GC to drawx- the x coordinate of the top left corner of the rectangular area where the text is to be drawny- the y coordinate of the top left corner of the rectangular area where the text is to be drawnselectionStart- the offset where the selections starts, or -1 indicating no selectionselectionEnd- the offset where the selections ends, or -1 indicating no selectionselectionForeground- selection foreground, or NULL to use the system default colorselectionBackground- selection background, or NULL to use the system default colorflags- drawing options- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the gc is null
- Since:
- 3.3
-
drawInPixels
-
drawWithCairo
-
drawBorder
-
freeRuns
void freeRuns() -
getAlignment
public int getAlignment()Returns the receiver's horizontal text alignment, which will be one ofSWT.LEFT,SWT.CENTERorSWT.RIGHT.- Returns:
- the alignment used to positioned text horizontally
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getAscent
public int getAscent()Returns the ascent of the receiver.- Returns:
- the ascent
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
getBounds
Returns the bounds of the receiver. The width returned is either the width of the longest line or the width set usingsetWidth(int). To obtain the text bounds of a line usegetLineBounds(int).- Returns:
- the bounds of the receiver
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
getBoundsInPixels
-
getBounds
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.- Parameters:
start- the start offsetend- the end offset- Returns:
- the bounds of the character range
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getBoundsInPixels
-
getDescent
public int getDescent()Returns the descent of the receiver.- Returns:
- the descent
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
getFont
Returns the default font currently being used by the receiver to draw and measure text.- Returns:
- the receiver's font
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getIndent
public int getIndent()Returns the receiver's indent.- Returns:
- the receiver's indent
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.2
-
getIndentInPixels
int getIndentInPixels() -
getJustify
public boolean getJustify()Returns the receiver's justification.- Returns:
- the receiver's justification
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.2
-
getLevel
public 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.- Parameters:
offset- the character offset- Returns:
- the embedding level
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the character offset is out of range
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getLineBounds
Returns the bounds of the line for the specified line index.- Parameters:
lineIndex- the line index- Returns:
- the line bounds
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the line index is out of range
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getLineBoundsInPixels
-
getLineBoundsInPixels
-
getLineCount
public int getLineCount()Returns the receiver's line count. This includes lines caused by wrapping.- Returns:
- the line count
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getLineIndex
public int getLineIndex(int offset) Returns the index of the line that contains the specified character offset.- Parameters:
offset- the character offset- Returns:
- the line index
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the character offset is out of range
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getLineMetrics
Returns the font metrics for the specified line index.- Parameters:
lineIndex- the line index- Returns:
- the font metrics
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the line index is out of range
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getLineOffsets
public 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.- Returns:
- the line offsets
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getLocation
Returns the location for the specified character offset. Thetrailingargument indicates whether the offset corresponds to the leading or trailing edge of the cluster.- Parameters:
offset- the character offsettrailing- the trailing flag- Returns:
- the location of the character offset
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
getLocationInPixels
-
getNextOffset
public int getNextOffset(int offset, int movement) Returns the next offset for the specified offset and movement type. The movement is one ofSWT.MOVEMENT_CHAR,SWT.MOVEMENT_CLUSTER,SWT.MOVEMENT_WORD,SWT.MOVEMENT_WORD_ENDorSWT.MOVEMENT_WORD_START.- Parameters:
offset- the start offsetmovement- the movement type- Returns:
- the next offset
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the offset is out of range
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
_getOffset
int _getOffset(int offset, int movement, boolean forward) -
getOffset
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.- Parameters:
point- the pointtrailing- the trailing buffer- Returns:
- the character offset
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the trailing length is less than
1 - ERROR_NULL_ARGUMENT - if the point is null
- ERROR_INVALID_ARGUMENT - if the trailing length is less than
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
getOffsetInPixels
-
getOffset
public 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.- Parameters:
x- the x coordinate of the pointy- the y coordinate of the pointtrailing- the trailing buffer- Returns:
- the character offset
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the trailing length is less than
1
- ERROR_INVALID_ARGUMENT - if the trailing length is less than
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
getOffsetInPixels
int getOffsetInPixels(int x, int y, int[] trailing) -
getOrientation
public int getOrientation()Returns the orientation of the receiver.- Returns:
- the orientation style
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getPreviousOffset
public int getPreviousOffset(int offset, int movement) Returns the previous offset for the specified offset and movement type. The movement is one ofSWT.MOVEMENT_CHAR,SWT.MOVEMENT_CLUSTERorSWT.MOVEMENT_WORD,SWT.MOVEMENT_WORD_ENDorSWT.MOVEMENT_WORD_START.- Parameters:
offset- the start offsetmovement- the movement type- Returns:
- the previous offset
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the offset is out of range
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
getRanges
public int[] getRanges()Gets the ranges of text that are associated with aTextStyle.- Returns:
- the ranges, an array of offsets representing the start and end of each text style.
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.2
- See Also:
-
getSegments
public int[] getSegments()Returns the text segments offsets of the receiver.- Returns:
- the text segments offsets
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getSegmentsChars
public char[] getSegmentsChars()Returns the segments characters of the receiver.- Returns:
- the segments characters
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.6
-
getSegmentsText
String getSegmentsText() -
getSpacing
public int getSpacing()Returns the line spacing of the receiver.- Returns:
- the line spacing
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getSpacingInPixels
int getSpacingInPixels() -
getVerticalIndent
public int getVerticalIndent()Returns the vertical indent of the receiver.- Returns:
- the vertical indent
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.109
-
getScaledVerticalIndent
private int getScaledVerticalIndent()Returns the scaled vertical indent.- Returns:
- the scaled vertical indent.
- Since:
- 3.109
-
getStyle
Gets the style of the receiver at the specified character offset.- Parameters:
offset- the text offset- Returns:
- the style or
nullif not set - Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the character offset is out of range
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getStyles
Gets all styles of the receiver.- Returns:
- the styles
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.2
- See Also:
-
getTabs
public int[] getTabs()Returns the tab list of the receiver.- Returns:
- the tab list
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getTabsInPixels
int[] getTabsInPixels() -
getText
Gets the receiver's text, which will be an empty string if it has never been set.- Returns:
- the receiver's text
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getTextDirection
public int getTextDirection()Returns the text direction of the receiver.- Returns:
- the text direction value
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.103
-
getWidth
public int getWidth()Returns the width of the receiver.- Returns:
- the width
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
getWidthInPixels
int getWidthInPixels() -
getWrapIndent
public int getWrapIndent()Returns the receiver's wrap indent.- Returns:
- the receiver's wrap indent
- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.6
-
getWrapIndentInPixels
int getWrapIndentInPixels() -
isDisposed
public boolean isDisposed()Returnstrueif the text layout has been disposed, andfalseotherwise.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 (except
Resource.dispose()) using the text layout.- Specified by:
isDisposedin classResource- Returns:
truewhen the text layout is disposed andfalseotherwise
-
setAlignment
public 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 ofSWT.LEFT,SWT.RIGHTorSWT.CENTER.The default alignment is
SWT.LEFT. Note that the receiver's width must be set in order to useSWT.RIGHTorSWT.CENTERalignment.- Parameters:
alignment- the new alignment- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
setAscent
public void setAscent(int ascent) Sets the ascent of the receiver. The ascent is distance in points from the baseline to the top of the line and it is applied to all lines. The default value is-1which means that the ascent is calculated from the line fonts.- Parameters:
ascent- the new ascent- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the ascent is less than
-1
- ERROR_INVALID_ARGUMENT - if the ascent is less than
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
setDescent
public void setDescent(int descent) Sets the descent of the receiver. The descent is distance in points from the baseline to the bottom of the line and it is applied to all lines. The default value is-1which means that the descent is calculated from the line fonts.- Parameters:
descent- the new descent- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the descent is less than
-1
- ERROR_INVALID_ARGUMENT - if the descent is less than
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
setFixedLineMetrics
Forces line heights in receiver to obey provided value. This is useful with texts that contain glyphs from different scripts, such as mixing latin glyphs with hieroglyphs or emojis.Text lines with different metrics will be forced to fit. This means painting text in such a way that its baseline is where specified by given 'metrics'. This can sometimes introduce small visual artifacs, such as taller lines overpainting or being clipped by content above and below.
The possible ways to set FontMetrics include:- Obtaining 'FontMetrics' via
GC.getFontMetrics(). Note that this will only obtain metrics for currently selected font and will not account for font fallbacks (for example, with a latin font selected, painting hieroglyphs usually involves a fallback font). - Obtaining 'FontMetrics' via a temporary 'TextLayout'. This would
involve setting a desired text sample to 'TextLayout', then measuring
it with
getLineMetrics(int). This approach will also take fallback fonts into account.
- Since:
- 3.125
- Obtaining 'FontMetrics' via
-
setFont
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.- Parameters:
font- the new font for the receiver, or null to indicate a default font- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the font has been disposed
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
setIndent
public void setIndent(int indent) Sets the indent of the receiver. This indent is applied to the first line of each paragraph.- Parameters:
indent- new indent- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.2
- See Also:
-
setIndentInPixels
void setIndentInPixels(int indent) -
setJustify
public void setJustify(boolean justify) Sets the justification of the receiver. Note that the receiver's width must be set in order to use justification.- Parameters:
justify- new justify- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.2
-
setOrientation
public void setOrientation(int orientation) Sets the orientation of the receiver, which must be one ofSWT.LEFT_TO_RIGHTorSWT.RIGHT_TO_LEFT.- Parameters:
orientation- new orientation style- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
setSpacing
public void setSpacing(int spacing) Sets the line spacing of the receiver. The line spacing is the space left between lines.- Parameters:
spacing- the new line spacing- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the spacing is negative
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
setSpacingInPixels
void setSpacingInPixels(int spacing) -
setVerticalIndent
public void setVerticalIndent(int verticalIndent) Sets the vertical indent of the receiver. The vertical indent is the space left before the first line.- Parameters:
verticalIndent- the new vertical indent- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the vertical indent is negative
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.109
-
setSegments
public void setSegments(int[] segments) Sets the offsets of the receiver's text segments. Text segments are used to override the default behavior of the bidirectional algorithm. Bidirectional reordering can happen within a text segment but not between two adjacent segments.Each text segment is determined by two consecutive offsets in the
segmentsarrays. The first element of the array should always be zero and the last one should always be equals to length of the text.When segments characters are set, the segments are the offsets where the characters are inserted in the text.
- Parameters:
segments- the text segments offset- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
setSegmentsChars
public void setSegmentsChars(char[] segmentsChars) Sets the characters to be used in the segments boundaries. The segments are set by callingsetSegments(int[]). The application can use this API to insert Unicode Control Characters in the text to control the display of the text and bidi reordering. The characters are not accessible by any other API inTextLayout.- Parameters:
segmentsChars- the segments characters- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.6
- See Also:
-
setStyle
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.- Parameters:
style- the stylestart- the start offsetend- the end offset- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
setTabs
public void setTabs(int[] tabs) Sets the receiver's tab list. Each value in the tab list specifies the space in points from the origin of the text layout to the respective tab stop. The last tab stop width is repeated continuously.- Parameters:
tabs- the new tab list- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
setTabsInPixels
void setTabsInPixels(int[] tabs) -
setText
Sets the receiver's text.Note: Setting the text also clears all the styles. This method returns without doing anything if the new text is the same as the current text.
- Parameters:
text- the new text- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the text is null
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
-
setTextDirection
public void setTextDirection(int textDirection) Sets the text direction of the receiver, which must be one ofSWT.LEFT_TO_RIGHT,SWT.RIGHT_TO_LEFTorSWT.AUTO_TEXT_DIRECTION.Warning: This API is currently only implemented on Windows. It doesn't set the base text direction on GTK and Cocoa.
- Parameters:
textDirection- the new text direction- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.103
-
setWidth
public void setWidth(int width) Sets the line width of the receiver, which determines how text should be wrapped and aligned. The default value is-1which means wrapping is disabled.- Parameters:
width- the new width- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the width is
0or less than-1
- ERROR_INVALID_ARGUMENT - if the width is
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- See Also:
-
setWidthInPixels
void setWidthInPixels(int width) -
setWidth
void setWidth() -
setWrapIndent
public void setWrapIndent(int wrapIndent) Sets the wrap indent of the receiver. This indent is applied to all lines in the paragraph except the first line.- Parameters:
wrapIndent- new wrap indent- Throws:
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.6
- See Also:
-
setWrapIndentInPixels
void setWrapIndentInPixels(int wrapIndent) -
isLam
static final boolean isLam(int ch) -
isAlef
static final boolean isAlef(int ch) -
toString
-
translateOffset
int translateOffset(int offset) -
untranslateOffset
int untranslateOffset(int offset) -
width
int width() -
setDefaultTabWidth
public void setDefaultTabWidth(int tabLength) Sets Default Tab Width in terms if number of space characters.- Parameters:
tabLength- in number of characters- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the tabLength is less than
0
- ERROR_INVALID_ARGUMENT - if the tabLength is less than
SWTException-- ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
- Since:
- 3.107
-