public final class TextLayout extends Resource
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.
Modifier and Type | Class and Description |
---|---|
(package private) class |
TextLayout.StyleItem |
Modifier and Type | Field and Description |
---|---|
(package private) int |
alignment |
(package private) TextLayout.StyleItem[] |
allRuns |
(package private) int |
ascent |
(package private) static byte[] |
CLSID_CMultiLanguage |
(package private) int |
descent |
(package private) Font |
font |
(package private) static int |
GOFFSET_SIZEOF |
(package private) static byte[] |
IID_IMLangFontLink2 |
(package private) int |
indent |
(package private) boolean |
justify |
(package private) int[] |
lineOffset |
(package private) int |
lineSpacing |
(package private) int[] |
lineWidth |
(package private) int[] |
lineY |
(package private) static char |
LTR_MARK |
(package private) static int |
MERGE_MAX |
(package private) int |
mLangFontLink2 |
(package private) int |
orientation |
(package private) static char |
RTL_MARK |
(package private) TextLayout.StyleItem[][] |
runs |
(package private) static int |
SCRIPT_VISATTR_SIZEOF |
(package private) int[] |
segments |
(package private) char[] |
segmentsChars |
(package private) java.lang.String |
segmentsText |
(package private) TextLayout.StyleItem[] |
styles |
(package private) int |
stylesCount |
(package private) int[] |
tabs |
(package private) java.lang.String |
text |
(package private) static int |
TOO_MANY_RUNS |
(package private) static int |
UNDERLINE_IME_DASH |
(package private) static int |
UNDERLINE_IME_DOT |
(package private) static int |
UNDERLINE_IME_THICK |
(package private) int |
wrapIndent |
(package private) int |
wrapWidth |
Constructor and Description |
---|
TextLayout(Device device)
Constructs a new instance of this class on the given device.
|
Modifier and Type | Method and Description |
---|---|
(package private) int |
_getOffset(int offset,
int movement,
boolean forward) |
(package private) RECT |
addClipRect(TextLayout.StyleItem run,
RECT clipRect,
RECT rect,
int selectionStart,
int selectionEnd) |
(package private) void |
breakRun(TextLayout.StyleItem run) |
(package private) void |
checkLayout() |
(package private) SCRIPT_ANALYSIS |
cloneScriptAnalysis(SCRIPT_ANALYSIS src) |
(package private) int[] |
computePolyline(int left,
int top,
int right,
int bottom) |
(package private) void |
computeRuns(GC gc) |
(package private) int |
createGdipBrush(Color color,
int alpha) |
(package private) int |
createGdipBrush(int pixel,
int alpha) |
(package private) void |
destroy() |
void |
draw(GC gc,
int x,
int y)
Draws the receiver's text using the specified GC at the specified
point.
|
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.
|
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.
|
(package private) RECT |
drawBorder(int hdc,
int x,
int y,
int lineHeight,
TextLayout.StyleItem[] line,
int index,
int color,
int selectionColor,
RECT clipRect,
RECT pRect,
int selectionStart,
int selectionEnd,
Rectangle drawClip) |
(package private) RECT |
drawBorderGDIP(int graphics,
int x,
int y,
int lineHeight,
TextLayout.StyleItem[] line,
int index,
int color,
int selectionColor,
RECT clipRect,
RECT pRect,
int selectionStart,
int selectionEnd,
int alpha,
Rectangle drawClip) |
(package private) void |
drawRunBackground(TextLayout.StyleItem run,
int hdc,
RECT rect,
int selectionStart,
int selectionEnd,
int selBrush,
boolean hasSelection) |
(package private) void |
drawRunBackgroundGDIP(TextLayout.StyleItem run,
int graphics,
RECT rect,
int selectionStart,
int selectionEnd,
int alpha,
int selBrush,
boolean hasSelection) |
(package private) RECT |
drawRunText(int hdc,
TextLayout.StyleItem run,
RECT rect,
int baseline,
int color,
int selectionColor,
int selectionStart,
int selectionEnd) |
(package private) RECT |
drawRunTextGDIP(int graphics,
TextLayout.StyleItem run,
RECT rect,
int gdipFont,
int baseline,
int color,
int selectionColor,
int selectionStart,
int selectionEnd,
int alpha) |
(package private) RECT |
drawRunTextGDIPRaster(int graphics,
TextLayout.StyleItem run,
RECT rect,
int baseline,
int color,
int selectionColor,
int selectionStart,
int selectionEnd) |
(package private) RECT |
drawStrikeout(int hdc,
int x,
int baseline,
TextLayout.StyleItem[] line,
int index,
int color,
int selectionColor,
RECT clipRect,
RECT pRect,
int selectionStart,
int selectionEnd,
Rectangle drawClip) |
(package private) RECT |
drawStrikeoutGDIP(int graphics,
int x,
int baseline,
TextLayout.StyleItem[] line,
int index,
int color,
int selectionColor,
RECT clipRect,
RECT pRect,
int selectionStart,
int selectionEnd,
int alpha,
Rectangle drawClip) |
(package private) RECT |
drawUnderline(int hdc,
int x,
int baseline,
int lineUnderlinePos,
int lineBottom,
TextLayout.StyleItem[] line,
int index,
int color,
int selectionColor,
RECT clipRect,
RECT pRect,
int selectionStart,
int selectionEnd,
Rectangle drawClip) |
(package private) RECT |
drawUnderlineGDIP(int graphics,
int x,
int baseline,
int lineUnderlinePos,
int lineBottom,
TextLayout.StyleItem[] line,
int index,
int color,
int selectionColor,
RECT clipRect,
RECT pRect,
int selectionStart,
int selectionEnd,
int alpha,
Rectangle drawClip) |
(package private) void |
freeRuns() |
int |
getAlignment()
Returns the receiver's horizontal text alignment, which will be one
of
SWT.LEFT , SWT.CENTER or
SWT.RIGHT . |
int |
getAscent()
Returns the ascent of the receiver.
|
Rectangle |
getBounds()
Returns the bounds of the receiver.
|
Rectangle |
getBounds(int start,
int end)
Returns the bounds for the specified range of characters.
|
int |
getDescent()
Returns the descent of the receiver.
|
Font |
getFont()
Returns the default font currently being used by the receiver
to draw and measure text.
|
int |
getIndent()
Returns the receiver's indent.
|
(package private) int |
getItemFont(TextLayout.StyleItem item) |
boolean |
getJustify()
Returns the receiver's justification.
|
int |
getLevel(int offset)
Returns the embedding level for the specified character offset.
|
Rectangle |
getLineBounds(int lineIndex)
Returns the bounds of the line for the specified line index.
|
int |
getLineCount()
Returns the receiver's line count.
|
(package private) int |
getLineIndent(int lineIndex) |
int |
getLineIndex(int offset)
Returns the index of the line that contains the specified
character offset.
|
FontMetrics |
getLineMetrics(int lineIndex)
Returns the font metrics for the specified line index.
|
int[] |
getLineOffsets()
Returns the line offsets.
|
Point |
getLocation(int offset,
boolean trailing)
Returns the location for the specified character offset.
|
int |
getNextOffset(int offset,
int movement)
Returns the next offset for the specified offset and movement
type.
|
int |
getOffset(int x,
int y,
int[] trailing)
Returns the character offset for the specified point.
|
int |
getOffset(Point point,
int[] trailing)
Returns the character offset for the specified point.
|
int |
getOrientation()
Returns the orientation of the receiver.
|
(package private) void |
getPartialSelection(TextLayout.StyleItem run,
int selectionStart,
int selectionEnd,
RECT rect) |
int |
getPreviousOffset(int offset,
int movement)
Returns the previous offset for the specified offset and movement
type.
|
int[] |
getRanges()
Gets the ranges of text that are associated with a
TextStyle . |
int[] |
getSegments()
Returns the text segments offsets of the receiver.
|
char[] |
getSegmentsChars()
Returns the segments characters of the receiver.
|
(package private) java.lang.String |
getSegmentsText() |
int |
getSpacing()
Returns the line spacing of the receiver.
|
TextStyle |
getStyle(int offset)
Gets the style of the receiver at the specified character offset.
|
TextStyle[] |
getStyles()
Gets all styles of the receiver.
|
int[] |
getTabs()
Returns the tab list of the receiver.
|
java.lang.String |
getText()
Gets the receiver's text, which will be an empty
string if it has never been set.
|
int |
getWidth()
Returns the width of the receiver.
|
int |
getWrapIndent()
Returns the receiver's wrap indent.
|
boolean |
isDisposed()
Returns
true if the text layout has been disposed,
and false otherwise. |
(package private) TextLayout.StyleItem[] |
itemize() |
(package private) TextLayout.StyleItem[] |
merge(int items,
int itemCount) |
(package private) TextLayout.StyleItem[] |
reorder(TextLayout.StyleItem[] runs,
boolean terminate) |
void |
setAlignment(int alignment)
Sets the text alignment for the receiver.
|
void |
setAscent(int ascent)
Sets the ascent of the receiver.
|
void |
setDescent(int descent)
Sets the descent of the receiver.
|
void |
setFont(Font font)
Sets the default font which will be used by the receiver
to draw and measure text.
|
void |
setIndent(int indent)
Sets the indent of the receiver.
|
void |
setJustify(boolean justify)
Sets the justification of the receiver.
|
void |
setOrientation(int orientation)
Sets the orientation of the receiver, which must be one
of
SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT . |
void |
setSegments(int[] segments)
Sets the offsets of the receiver's text segments.
|
void |
setSegmentsChars(char[] segmentsChars)
Sets the characters to be used in the segments boundaries.
|
void |
setSpacing(int spacing)
Sets the line spacing of the receiver.
|
void |
setStyle(TextStyle style,
int start,
int end)
Sets the style of the receiver for the specified range.
|
void |
setTabs(int[] tabs)
Sets the receiver's tab list.
|
void |
setText(java.lang.String text)
Sets the receiver's text.
|
void |
setWidth(int width)
Sets the line width of the receiver, which determines how
text should be wrapped and aligned.
|
void |
setWrapIndent(int wrapIndent)
Sets the wrap indent of the receiver.
|
(package private) void |
shape(int hdc,
TextLayout.StyleItem run) |
(package private) boolean |
shape(int hdc,
TextLayout.StyleItem run,
char[] chars,
int[] glyphCount,
int maxGlyphs,
SCRIPT_PROPERTIES sp) |
java.lang.String |
toString()
Returns a string containing a concise, human-readable
description of the receiver.
|
(package private) int |
translateOffset(int offset) |
(package private) int |
untranslateOffset(int offset) |
(package private) int |
validadeOffset(int offset,
int step) |
Font font
java.lang.String text
java.lang.String segmentsText
int lineSpacing
int ascent
int descent
int alignment
int wrapWidth
int orientation
int indent
int wrapIndent
boolean justify
int[] tabs
int[] segments
char[] segmentsChars
TextLayout.StyleItem[] styles
int stylesCount
TextLayout.StyleItem[] allRuns
TextLayout.StyleItem[][] runs
int[] lineOffset
int[] lineY
int[] lineWidth
int mLangFontLink2
static final char LTR_MARK
static final char RTL_MARK
static final int SCRIPT_VISATTR_SIZEOF
static final int GOFFSET_SIZEOF
static final byte[] CLSID_CMultiLanguage
static final byte[] IID_IMLangFontLink2
static final int MERGE_MAX
static final int TOO_MANY_RUNS
static final int UNDERLINE_IME_DOT
static final int UNDERLINE_IME_DASH
static final int UNDERLINE_IME_THICK
public TextLayout(Device device)
You must dispose the text layout when it is no longer required.
device
- the device on which to allocate the text layoutjava.lang.IllegalArgumentException
- Resource.dispose()
RECT addClipRect(TextLayout.StyleItem run, RECT clipRect, RECT rect, int selectionStart, int selectionEnd)
void breakRun(TextLayout.StyleItem run)
void checkLayout()
void computeRuns(GC gc)
SCRIPT_ANALYSIS cloneScriptAnalysis(SCRIPT_ANALYSIS src)
int[] computePolyline(int left, int top, int right, int bottom)
int createGdipBrush(int pixel, int alpha)
int createGdipBrush(Color color, int alpha)
public void draw(GC gc, int x, int y)
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 drawnSWTException
- java.lang.IllegalArgumentException
- public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground)
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 colorSWTException
- java.lang.IllegalArgumentException
- public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags)
The parameter flags
can include one of SWT.DELIMITER_SELECTION
or SWT.FULL_SELECTION
to specify the selection behavior on all lines except
for the last line, and can also include SWT.LAST_LINE_SELECTION
to extend
the specified selection behavior to the last line.
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 optionsSWTException
- java.lang.IllegalArgumentException
- RECT drawBorder(int hdc, int x, int y, int lineHeight, TextLayout.StyleItem[] line, int index, int color, int selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd, Rectangle drawClip)
RECT drawBorderGDIP(int graphics, int x, int y, int lineHeight, TextLayout.StyleItem[] line, int index, int color, int selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd, int alpha, Rectangle drawClip)
void drawRunBackground(TextLayout.StyleItem run, int hdc, RECT rect, int selectionStart, int selectionEnd, int selBrush, boolean hasSelection)
void drawRunBackgroundGDIP(TextLayout.StyleItem run, int graphics, RECT rect, int selectionStart, int selectionEnd, int alpha, int selBrush, boolean hasSelection)
RECT drawRunText(int hdc, TextLayout.StyleItem run, RECT rect, int baseline, int color, int selectionColor, int selectionStart, int selectionEnd)
RECT drawRunTextGDIP(int graphics, TextLayout.StyleItem run, RECT rect, int gdipFont, int baseline, int color, int selectionColor, int selectionStart, int selectionEnd, int alpha)
RECT drawRunTextGDIPRaster(int graphics, TextLayout.StyleItem run, RECT rect, int baseline, int color, int selectionColor, int selectionStart, int selectionEnd)
RECT drawStrikeout(int hdc, int x, int baseline, TextLayout.StyleItem[] line, int index, int color, int selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd, Rectangle drawClip)
RECT drawStrikeoutGDIP(int graphics, int x, int baseline, TextLayout.StyleItem[] line, int index, int color, int selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd, int alpha, Rectangle drawClip)
RECT drawUnderline(int hdc, int x, int baseline, int lineUnderlinePos, int lineBottom, TextLayout.StyleItem[] line, int index, int color, int selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd, Rectangle drawClip)
RECT drawUnderlineGDIP(int graphics, int x, int baseline, int lineUnderlinePos, int lineBottom, TextLayout.StyleItem[] line, int index, int color, int selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd, int alpha, Rectangle drawClip)
void freeRuns()
public int getAlignment()
SWT.LEFT
, SWT.CENTER
or
SWT.RIGHT
.SWTException
- public int getAscent()
SWTException
- getDescent()
,
setDescent(int)
,
setAscent(int)
,
getLineMetrics(int)
public Rectangle getBounds()
setWidth(int)
.
To obtain the text bounds of a line use getLineBounds(int)
.SWTException
- setWidth(int)
,
getLineBounds(int)
public Rectangle getBounds(int start, int end)
start
- the start offsetend
- the end offsetSWTException
- public int getDescent()
SWTException
- getAscent()
,
setAscent(int)
,
setDescent(int)
,
getLineMetrics(int)
public Font getFont()
SWTException
- public int getIndent()
SWTException
- public boolean getJustify()
SWTException
- int getItemFont(TextLayout.StyleItem item)
public int getLevel(int offset)
offset
- the character offsetjava.lang.IllegalArgumentException
- SWTException
- public Rectangle getLineBounds(int lineIndex)
lineIndex
- the line indexjava.lang.IllegalArgumentException
- SWTException
- public int getLineCount()
SWTException
- int getLineIndent(int lineIndex)
public int getLineIndex(int offset)
offset
- the character offsetjava.lang.IllegalArgumentException
- SWTException
- public FontMetrics getLineMetrics(int lineIndex)
lineIndex
- the line indexjava.lang.IllegalArgumentException
- SWTException
- public int[] getLineOffsets()
SWTException
- public Point getLocation(int offset, boolean trailing)
trailing
argument indicates whether the offset
corresponds to the leading or trailing edge of the cluster.offset
- the character offsettrailing
- the trailing flagSWTException
- getOffset(Point, int[])
,
getOffset(int, int, int[])
public int getNextOffset(int offset, int movement)
SWT.MOVEMENT_CHAR
,
SWT.MOVEMENT_CLUSTER
, SWT.MOVEMENT_WORD
,
SWT.MOVEMENT_WORD_END
or SWT.MOVEMENT_WORD_START
.offset
- the start offsetmovement
- the movement typejava.lang.IllegalArgumentException
- SWTException
- getPreviousOffset(int, int)
int _getOffset(int offset, int movement, boolean forward)
public int getOffset(Point point, int[] trailing)
point
- the pointtrailing
- the trailing bufferjava.lang.IllegalArgumentException
- 1
SWTException
- getLocation(int, boolean)
public int getOffset(int x, int y, int[] trailing)
x
- the x coordinate of the pointy
- the y coordinate of the pointtrailing
- the trailing bufferjava.lang.IllegalArgumentException
- 1
SWTException
- getLocation(int, boolean)
public int getOrientation()
SWTException
- void getPartialSelection(TextLayout.StyleItem run, int selectionStart, int selectionEnd, RECT rect)
public int getPreviousOffset(int offset, int movement)
SWT.MOVEMENT_CHAR
,
SWT.MOVEMENT_CLUSTER
or SWT.MOVEMENT_WORD
,
SWT.MOVEMENT_WORD_END
or SWT.MOVEMENT_WORD_START
.offset
- the start offsetmovement
- the movement typejava.lang.IllegalArgumentException
- SWTException
- getNextOffset(int, int)
public int[] getRanges()
TextStyle
.SWTException
- getStyles()
public int[] getSegments()
SWTException
- public char[] getSegmentsChars()
SWTException
- java.lang.String getSegmentsText()
public int getSpacing()
SWTException
- public TextStyle getStyle(int offset)
offset
- the text offsetnull
if not setjava.lang.IllegalArgumentException
- SWTException
- public TextStyle[] getStyles()
SWTException
- getRanges()
public int[] getTabs()
SWTException
- public java.lang.String getText()
SWTException
- public int getWidth()
SWTException
- public int getWrapIndent()
SWTException
- public boolean isDisposed()
true
if the text layout has been disposed,
and false
otherwise.
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.
isDisposed
in class Resource
true
when the text layout is disposed and false
otherwiseTextLayout.StyleItem[] itemize()
TextLayout.StyleItem[] merge(int items, int itemCount)
TextLayout.StyleItem[] reorder(TextLayout.StyleItem[] runs, boolean terminate)
public void setAlignment(int alignment)
SWT.LEFT
, SWT.RIGHT
or SWT.CENTER
.
The default alignment is SWT.LEFT
. Note that the receiver's
width must be set in order to use SWT.RIGHT
or SWT.CENTER
alignment.
alignment
- the new alignmentSWTException
- setWidth(int)
public void setAscent(int ascent)
-1
which means that the
ascent is calculated from the line fonts.ascent
- the new ascentjava.lang.IllegalArgumentException
- -1
SWTException
- setDescent(int)
,
getLineMetrics(int)
public void setDescent(int descent)
-1
which means that the
descent is calculated from the line fonts.descent
- the new descentjava.lang.IllegalArgumentException
- -1
SWTException
- setAscent(int)
,
getLineMetrics(int)
public void setFont(Font font)
font
- the new font for the receiver, or null to indicate a default fontjava.lang.IllegalArgumentException
- SWTException
- public void setIndent(int indent)
indent
- new indentSWTException
- setWrapIndent(int)
public void setJustify(boolean justify)
justify
- new justifySWTException
- public void setOrientation(int orientation)
SWT.LEFT_TO_RIGHT
or SWT.RIGHT_TO_LEFT
.orientation
- new orientation styleSWTException
- public void setSegments(int[] segments)
Each text segment is determined by two consecutive offsets in the
segments
arrays. 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.
segments
- the text segments offsetSWTException
- setSegmentsChars(char[])
public void setSegmentsChars(char[] segmentsChars)
setSegments(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 in TextLayout
.segmentsChars
- the segments charactersSWTException
- setSegments(int[])
public void setSpacing(int spacing)
spacing
- the new line spacingjava.lang.IllegalArgumentException
- SWTException
- public void setStyle(TextStyle style, int start, int end)
style
- the stylestart
- the start offsetend
- the end offsetSWTException
- public void setTabs(int[] tabs)
tabs
- the new tab listSWTException
- public void setText(java.lang.String 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.
text
- the new textjava.lang.IllegalArgumentException
- SWTException
- public void setWidth(int width)
-1
which means wrapping is disabled.width
- the new widthjava.lang.IllegalArgumentException
- 0
or less than -1
SWTException
- setAlignment(int)
public void setWrapIndent(int wrapIndent)
wrapIndent
- new wrap indentSWTException
- setIndent(int)
boolean shape(int hdc, TextLayout.StyleItem run, char[] chars, int[] glyphCount, int maxGlyphs, SCRIPT_PROPERTIES sp)
void shape(int hdc, TextLayout.StyleItem run)
int validadeOffset(int offset, int step)
public java.lang.String toString()
toString
in class java.lang.Object
int translateOffset(int offset)
int untranslateOffset(int offset)