public class TextScanner
extends java.lang.Object
TextScanner class scans text to lay out text, to draw
text, and to compute the position of text.| 修飾子とタイプ | フィールドと説明 |
|---|---|
static int |
ATTACHMENT
The stop condition constant that shows the character encountered
is an attachment mark.
|
protected VArray |
attachments
The scanned text attachents.
|
int |
baseline
The baseline of a line.
|
static int |
CHAR_NOT_IN_FONT
The stop condition constant that shows the character encountered
is not defined in the current font.
|
static int |
CROSSED_X
The stop condition constant that shows the scanning runs across the
the right edge.
|
int |
destX
The current x position.
|
static int |
END_OF_RUN
The stop condition constant that shows the scanning runs to the end.
|
protected static int |
IGNORE
The stop condition that shows the character encountered must be
ignored.
|
static int[] |
JAVA_BREAK_STOPS
The stop conditions for the first 256 characters.
|
static int[] |
JAVA_STOPS
The stop conditions for the first 256 characters.
|
int |
lastCondition
The last stop condition scanned.
|
int |
lastIndex
The last index scanned.
|
int |
leftMargin
The left margin for scanning.
|
static int |
LINE_BREAK
The stop condition constant that shows the character encountered
is a line break.
|
static int |
LINE_SEPARATOR
The stop condition constant that shows the character encountered
is a line separator.
|
int |
lineBegin
The beginning index of a line (inclusive).
|
int |
lineEnd
The ending index of a line (exclusive).
|
int |
lineHeight
The height of a line.
|
protected int |
lineWrap
The line wrapping style.
|
static int[] |
LIST_STOPS
The stop conditions for the first 256 characters.
|
protected java.util.Locale |
locale
The locale of the text that is used for word breaking.
|
protected java.awt.FontMetrics |
metrics
The current font metrics.
|
static int[] |
NO_STOPS
The stop conditions for the first 256 characters.
|
protected char |
notInFontChar
The character displayed instead of a character that is not
defined in the current font.
|
protected java.lang.String |
notInFontCharString
The string representation of the
notInFontChar. |
protected int |
notInFontCharWidth
The current width of
notInFontChar. |
protected RichTextStyle |
richTextStyle
The rich text style that knows a text wrapping mode.
|
int |
rightMargin
The right margin (edge) for scanning.
|
int |
runEnd
The ending index in the text for scanning (exclusive).
|
static int[] |
SIMPLE_STOPS
The stop conditions for the first 256 characters.
|
static int |
TAB
The stop condition constant that shows the character encountered
is a tab character.
|
protected int |
tabWidth
The current width of a tab.
|
protected Text |
text
The text to be scanned.
|
protected int[] |
widths
The widths of the first 256 characters from the current font metrics.
|
| コンストラクタと説明 |
|---|
TextScanner(RichText richText,
int lineWrap,
java.util.Locale locale)
Constructs a text scanner with the rich text to be scanned, the
line wrapping style, and the locale of the text.
|
TextScanner(Text text,
RichTextStyle richTextStyle,
int lineWrap,
java.util.Locale locale)
Constructs a text scanner with the text to be scanned, the rich
text style, the line wrapping style, and the locale of the text.
|
| 修飾子とタイプ | メソッドと説明 |
|---|---|
int |
charWidth(char ch)
Returns the advance width of the specified character in the text.
|
int |
charWidth(int ch)
Returns the advance width of the specified character in the text.
|
int |
charWidthAt(int textIndex,
int startX,
int layoutWidth,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
Returns the advance width of a character in the specified index of
the text with the specified scanning context.
|
protected int |
doDrawLineStop(int stop,
java.awt.Graphics g,
java.awt.Point offset,
int drawY,
int rStart,
int rEnd,
TextStyle tStyle)
Handles the stop condition for drawing a line.
|
int |
doLayoutLine(int beginIndex,
int startX,
int leftMgn,
int rightMgn,
int tabW,
int lineTop,
ParagraphStyle pStyle,
int[] stops,
TextLineInfo lineInfo)
Breaks text into a line.
|
int |
doLayoutLine(int beginIndex,
int startX,
int leftMgn,
int rightMgn,
int tabW,
int lineTop,
ParagraphStyle pStyle,
TextLineInfo lineInfo)
Breaks text into a line.
|
int |
doLayoutLine(int beginIndex,
int startX,
int compositionWidth,
int lineTop,
ParagraphStyle pStyle,
TextLineInfo lineInfo)
Breaks text into a line.
|
int |
doLayoutLine(int beginIndex,
int compositionWidth,
int lineTop,
ParagraphStyle pStyle,
TextLineInfo lineInfo)
Breaks text into a line.
|
protected int |
doLayoutLineStop(int stop)
Handles the stop condition for breaking text into a line.
|
protected int |
doTextPositionStop(int stop)
Handles the stop condition for computing a position of character.
|
void |
drawLine(java.awt.Graphics g,
java.awt.Point offset,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
Draws a line.
|
void |
drawLineFromTo(java.awt.Graphics g,
java.awt.Point offset,
int startX,
int beginIndex,
int endIndex,
int lineHeight,
int baseline,
int leftMgn,
int tabW)
Draws a line from the beginning index to the ending index of text.
|
void |
drawLineFromTo(java.awt.Graphics g,
java.awt.Point offset,
int startX,
int beginIndex,
int endIndex,
int lineHeight,
int baseline,
int leftMgn,
int tabW,
int[] stops)
Draws a line from the beginning index to the ending index of text.
|
void |
drawLineFromTo(java.awt.Graphics g,
java.awt.Point offset,
int startX,
int beginIndex,
int endIndex,
int remainWidth,
int lineHeight,
int baseline,
ParagraphStyle pStyle)
Draws a line from the beginning index to the ending index of text.
|
void |
drawLineFromTo(java.awt.Graphics g,
java.awt.Point offset,
int startX,
int beginIndex,
int endIndex,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
Draws a line from the beginning index to the ending index of text.
|
void |
drawLineTo(java.awt.Graphics g,
java.awt.Point offset,
int lineBegin,
int endIndex,
int remainWidth,
int lineHeight,
int baseline,
ParagraphStyle pStyle)
Draws a line to the specified ending index of text.
|
void |
drawLineTo(java.awt.Graphics g,
java.awt.Point offset,
int endIndex,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
Draws a line to the specified ending index of text.
|
protected int |
fastScanChars(int begin,
int end,
char[] chars,
int rightX,
int[] stops,
int bufferSize)
Scans the array of characters and returns the stop condition
if the scanning runs to the
end, the scanning runs
across the rightX, or the scanning encounters the
stop condition defined in the stops. |
protected void |
fastScanCharsForMultiBytes(int begin,
int end,
char[] chars,
int rightX)
Scans the array of characters that are larger than 256 until
the scanning runs across the
rightX. |
protected int[] |
getStops()
Returns the stop conditions.
|
int[] |
linePositionAt(int textIndex,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
Computes the positin of the character in the text.
|
int[] |
linePositionAt(java.awt.Point point,
int startX,
int beginIndex,
int endIndex,
int leftMgn,
int tabW)
Computes the positin of the character in the text.
|
int[] |
linePositionAt(java.awt.Point point,
int startX,
int beginIndex,
int endIndex,
int leftMgn,
int tabW,
int[] stops)
Computes the positin of the character in the text.
|
int[] |
linePositionAt(java.awt.Point point,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
Computes the positin of the character in the text.
|
protected int |
nextTab(int x)
Returns a next tab position form the specified x position.
|
protected int |
prevTab(int x)
Returns a previous tab position form the specified x position.
|
protected int |
scanChars(int begin,
int end,
char[] chars,
int rightX,
int[] stops)
Scans the array of characters and returns the stop condition
if the scanning runs to the
end, the scanning runs
across the rightX, or the scanning encounters the
stop condition defined in the stops. |
protected void |
setFontMetrics(java.awt.FontMetrics metrics)
Sets the font metrics.
|
protected void |
setLineWrap(int lineWrap)
Sets the line wrapping style.
|
void |
setNotInFontChar(char ch)
Sets the character displayed instead of a character that is not
defined in the current font.
|
protected int |
slowScanChars(int begin,
int end,
char[] chars,
int rightX,
int[] stops)
Scans the array of characters and returns the stop condition
if the scanning runs to the
end, the scanning runs
across the rightX, or the scanning encounters the
stop condition defined in the stops. |
protected Text text
protected RichTextStyle richTextStyle
protected int lineWrap
protected java.util.Locale locale
public int destX
public int lastIndex
public int leftMargin
public int rightMargin
public int runEnd
public int lineBegin
public int lineEnd
public int lineHeight
public int baseline
public int lastCondition
protected VArray attachments
protected java.awt.FontMetrics metrics
protected int[] widths
protected int tabWidth
protected char notInFontChar
protected java.lang.String notInFontCharString
notInFontChar.protected int notInFontCharWidth
notInFontChar.public static final int END_OF_RUN
public static final int CROSSED_X
public static final int TAB
public static final int LINE_SEPARATOR
Text.LINE_SEPARATOR_CHAR,
定数フィールド値public static final int LINE_BREAK
Text.LINE_BREAK_CHAR,
定数フィールド値public static final int CHAR_NOT_IN_FONT
public static final int ATTACHMENT
Text.ATTACHMENT_CHAR,
定数フィールド値protected static final int IGNORE
public static final int[] NO_STOPS
public static final int[] SIMPLE_STOPS
public static final int[] JAVA_STOPS
Text.LINE_SEPARATOR_CHAR) as
LINE_SEPARATOR.public static final int[] JAVA_BREAK_STOPS
Text.LINE_SEPARATOR_CHAR) as
LINE_SEPARATOR, and '\r'
(Text.LINE_BREAK_CHAR) as LINE_BREAK.public static final int[] LIST_STOPS
public TextScanner(RichText richText, int lineWrap, java.util.Locale locale)
richText - the rich text style.lineWrap - the line wrapping style.locale - the locale of the text.public TextScanner(Text text, RichTextStyle richTextStyle, int lineWrap, java.util.Locale locale)
text - the text to be scanned.richTextStyle - the rich text style.lineWrap - the line wrapping style.locale - the locale of the text.public int doLayoutLine(int beginIndex,
int compositionWidth,
int lineTop,
ParagraphStyle pStyle,
TextLineInfo lineInfo)
beginIndex - the beginning index of text to scan.compositionWidth - the composition width of a line.lineTop - the top position of a line.pStyle - the paragraph style of a line.lineInfo - the line information into which the scanning
results are stored.-1 if no more
layout needed.public int doLayoutLine(int beginIndex,
int startX,
int compositionWidth,
int lineTop,
ParagraphStyle pStyle,
TextLineInfo lineInfo)
beginIndex - the beginning index of text to scan.startX - the starting x position to scan.compositionWidth - the composition width of a line.lineTop - the top position of a line.pStyle - the paragraph style of a line.lineInfo - the line information into which the scanning
results are stored.-1 if no more
layout needed.public int doLayoutLine(int beginIndex,
int startX,
int leftMgn,
int rightMgn,
int tabW,
int lineTop,
ParagraphStyle pStyle,
TextLineInfo lineInfo)
beginIndex - the beginning index of text to scan.startX - the starting x position to scan.leftMgn - the left margin of a line.rightMgn - the right margin (edge) of a line.tabW - the tab width used to scan.lineTop - the top position of a line.pStyle - the paragraph style of a line.lineInfo - the line information into which the scanning
results are stored.-1 if no more
layout needed.public int doLayoutLine(int beginIndex,
int startX,
int leftMgn,
int rightMgn,
int tabW,
int lineTop,
ParagraphStyle pStyle,
int[] stops,
TextLineInfo lineInfo)
beginIndex - the beginning index of text to scan.startX - the starting x position to scan.leftMgn - the left margin of a line.rightMgn - the right margin (edge) of a line.tabW - the tab width used to scan.lineTop - the top position of a line.pStyle - the paragraph style of a line.stops - the stop conditions for scanning.lineInfo - the line information into which the scanning
results are stored.-1 if no more
layout needed.public void drawLine(java.awt.Graphics g,
java.awt.Point offset,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
g - the graphics.offset - the offset position to draw.lineInfo - the line information of a line to be drawn.pStyle - the paragraph style of a line.public void drawLineTo(java.awt.Graphics g,
java.awt.Point offset,
int endIndex,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
g - the graphics.offset - the offset position to draw.endIndex - the ending index of text to draw. (exclusive)lineInfo - the line information of a line to be drawn.pStyle - the paragraph style of a line.public void drawLineTo(java.awt.Graphics g,
java.awt.Point offset,
int lineBegin,
int endIndex,
int remainWidth,
int lineHeight,
int baseline,
ParagraphStyle pStyle)
g - the graphics.offset - the offset position to draw.lineBegin - the beginning index of a line. (inclusive)endIndex - the ending index of text to draw. (exclusive)remainWidth - the remaining width (space) of a line.lineHeight - the height of a line.baseline - the baseline of a line.pStyle - the paragraph style of a line.public void drawLineFromTo(java.awt.Graphics g,
java.awt.Point offset,
int startX,
int beginIndex,
int endIndex,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
g - the graphics.offset - the offset position to draw.startX - the starting x position to draw.beginIndex - the beginning index of text to draw. (inclusive)endIndex - the ending index of text to draw. (exclusive)lineInfo - the line information of a line to be drawn.pStyle - the paragraph style of a line.public void drawLineFromTo(java.awt.Graphics g,
java.awt.Point offset,
int startX,
int beginIndex,
int endIndex,
int remainWidth,
int lineHeight,
int baseline,
ParagraphStyle pStyle)
g - the graphics.offset - the offset position to draw.startX - the starting x position to draw.beginIndex - the beginning index of text to draw. (inclusive)endIndex - the ending index of text to draw. (exclusive)remainWidth - the remaining width (space) of a line.lineHeight - the height of a line.baseline - the baseline of a line.pStyle - the paragraph style of a line.public void drawLineFromTo(java.awt.Graphics g,
java.awt.Point offset,
int startX,
int beginIndex,
int endIndex,
int lineHeight,
int baseline,
int leftMgn,
int tabW)
g - the graphics.offset - the offset position to draw.startX - the starting x position to draw.beginIndex - the beginning index of text to draw. (inclusive)endIndex - the ending index of text to draw. (exclusive)lineHeight - the height of a line.baseline - the baseline of a line.leftMgn - the left margin of a line.tabW - the tab width used to scan.public void drawLineFromTo(java.awt.Graphics g,
java.awt.Point offset,
int startX,
int beginIndex,
int endIndex,
int lineHeight,
int baseline,
int leftMgn,
int tabW,
int[] stops)
g - the graphics.offset - the offset position to draw.startX - the starting x position to draw.beginIndex - the beginning index of text to draw. (inclusive)endIndex - the ending index of text to draw. (exclusive)lineHeight - the height of a line.baseline - the baseline of a line.leftMgn - the left margin of a line.tabW - the tab width used to scan.stops - the stop conditions for scanning.public int[] linePositionAt(int textIndex,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
textIndex - thealineInfo - the information of a line where the character is in.pStyle - the paragraph style of a line.public int[] linePositionAt(java.awt.Point point,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
point - the character position in the text.lineInfo - the information of a line where the character is in.pStyle - the paragraph style of a line.public int[] linePositionAt(java.awt.Point point,
int startX,
int beginIndex,
int endIndex,
int leftMgn,
int tabW)
point - the character position in the text.startX - the starting x position to scan.beginIndex - the beginning index of a line where the character
is in.endIndex - the ending index of a line where the character is in.leftMgn - the left margin of a line.tabW - the tab width used to scan.public int[] linePositionAt(java.awt.Point point,
int startX,
int beginIndex,
int endIndex,
int leftMgn,
int tabW,
int[] stops)
point - the character position in the text.startX - the starting x position to scan.beginIndex - the beginning index of a line where the character
is in.endIndex - the ending index of a line where the character is in.leftMgn - the left margin of a line.tabW - the tab width used to scan.stops - the stop conditions for scanning.public void setNotInFontChar(char ch)
public int charWidth(int ch)
ch - the character to be measured.public int charWidth(char ch)
ch - the character to be measured.public int charWidthAt(int textIndex,
int startX,
int layoutWidth,
TextLineInfo lineInfo,
ParagraphStyle pStyle)
textIndex - the index of a character to be measured.startX - the starting x position to scan.layoutWidth - the composition width.lineInfo - the information of a line where a character is in.pStyle - the paragraph style of a line.protected int doLayoutLineStop(int stop)
stop - the stop condition.-1 if the scanning runs to the end;
1 if the scanning runs across the right edge or
the scanning encounters a line separator or a line break;
0 otherwise.protected int doDrawLineStop(int stop,
java.awt.Graphics g,
java.awt.Point offset,
int drawY,
int rStart,
int rEnd,
TextStyle tStyle)
stop - the stop condition.g - the graphics.offset - the offset position to draw.drawY - the current y position.rStart - the run start index.rEnd - the run end index.tStyle - the current text style.-1 if the scanning runs to the end;
0 otherwise.protected int doTextPositionStop(int stop)
stop - the stop condition.-1 if the scanning runs to the end;
1 if the scanning runs across the right edge or
the scanning encounters a line separator or a line break;
0 otherwise.protected int scanChars(int begin,
int end,
char[] chars,
int rightX,
int[] stops)
end, the scanning runs
across the rightX, or the scanning encounters the
stop condition defined in the stops.begin - the beginning index of scanning. (inclusive)end - the ending index of scanning. (exclusive)chars - the array of characters to be scanned.rightX - the right edge for scanning.stops - the stop conditions for scanning.protected final int fastScanChars(int begin,
int end,
char[] chars,
int rightX,
int[] stops,
int bufferSize)
end, the scanning runs
across the rightX, or the scanning encounters the
stop condition defined in the stops.
This operation is efficient even if all characters in the array are larger than 256.
begin - the beginning index of scanning. (inclusive)end - the ending index of scanning. (exclusive)chars - the array of characters to be scanned.rightX - the right edge for scanning.stops - the stop conditions for scanning.bufferSize - the buffer size for calling
FontMetrics#charsWidth(char[], int, int)protected final void fastScanCharsForMultiBytes(int begin,
int end,
char[] chars,
int rightX)
rightX.begin - the beginning index of scanning. (inclusive)end - the ending index of scanning. (exclusive)chars - the array of characters to be scanned.rightX - the right edge for scanning.protected final int slowScanChars(int begin,
int end,
char[] chars,
int rightX,
int[] stops)
end, the scanning runs
across the rightX, or the scanning encounters the
stop condition defined in the stops.
This operation is not efficient because it calls FontMetrics#charsWidth(char) at each character.
begin - the beginning index of scanning. (inclusive)end - the ending index of scanning. (exclusive)chars - the array of characters to be scanned.rightX - the right edge for scanning.stops - the stop conditions for scanning.protected void setLineWrap(int lineWrap)
protected void setFontMetrics(java.awt.FontMetrics metrics)
metrics - the font metrics.protected int[] getStops()
protected int nextTab(int x)
x - the specified x position.protected int prevTab(int x)
x - the specified x position.