Package snap.text
Class TextLine
java.lang.Object
snap.text.TextLine
- All Implemented Interfaces:
CharSequence
,Cloneable
,CharSequenceX
This class represents a line of text in a Text.
-
Field Summary
Modifier and TypeFieldDescriptionprotected double
protected int
protected TextLineStyle
protected TextRun[]
protected StringBuilder
protected int
protected TextBlock
protected TextToken[]
protected double
protected double
protected double
protected static final TextRun[]
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCharsWithStyle
(CharSequence theChars, TextStyle aStyle, int anIndex) Adds characters with text style to this line at given index.protected void
Adds a run to line.char
charAt
(int anIndex) Returns the char value at the specified index.clone()
Standard clone implementation.copyForRange
(int aStart, int aEnd) Returns a copy of this line for given char range.protected TextRun
Creates a new run.protected TextToken[]
Creates the tokens (via TextBlock.createTokensForTextLine() to provide another hook).Returns the alignment associated with this line.double
Returns the y position for this line (in same coords as the layout frame).int
getCharIndexForX
(double anX) Returns the character index for the given x/y point.int
Returns the end char index of this line in text.double
Returns the height of line.Returns the last run (or null if none).Returns the last token.getLastTokenForCharIndex
(int charIndex) Returns the token at or before given char index.int
Returns the index of this line in text.Returns the line style.double
getMaxX()
Returns the max X.double
getMaxY()
Returns the max Y.Returns the text metrics for line text.getNext()
Returns the next line, if available.Returns the previous line, if available.getRun
(int anIndex) Returns the individual run at given index.int
Returns the number of runs for this line.getRunForCharIndex
(int anIndex) Returns the head run for the line.getRunForCharRange
(int startIndex, int endIndex) Returns the TextRun for the given char range (usually just run for start, but can be next run if at boundary).TextRun[]
getRuns()
Returns the line runs.int
Returns the start char index of this line in text.Returns the string for the line.double
Returns the y position for this line (in same coords as the layout frame).Returns the TextBlock.double
Returns the max X.double
Returns the max Y.double
getTextX()
Returns the line x in text block coords.double
getTextXForCharIndex
(int anIndex) Returns the X coord for given char index.double
getTextY()
Returns the line y.getToken
(int anIndex) Returns the individual token at given index.int
Returns the number of tokens.getTokenForCharIndex
(int charIndex) Returns the token at given char index.getTokenForX
(double anX) Returns the token at index.Returns the tokens.double
Returns the width of the trailing whitespace.double
Returns the max stroke width of any underlined chars in this line.double
Returns the Y position of any underlined chars in this line.double
getWidth()
Returns the width of line.double
getWidthForStartCharIndex
(int startCharIndex) Returns the width of line from given index.double
getX()
Returns the line x.double
getXForCharIndex
(int anIndex) Returns the X coord for given char index.protected double
getXForTabAtIndexAndX
(int charIndex, double aX) Returns the x for tab at given x.double
getY()
Returns the line y.int
Returns the index of given string in line.boolean
Returns whether line ends with hyphen.boolean
Returns whether line contains an underlined run.int
length()
Returns the length of this text line.void
removeChars
(int aStart, int anEnd) Removes characters in given range.protected void
removeRun
(int anIndex) Removes the run at given index.void
Sets the alignment associated with this line.void
setLineStyle
(TextLineStyle aLineStyle) Sets the line style.protected void
setTextStyle
(TextStyle textStyle) Sets the style for the line (propagates to runs).protected void
setTextStyle
(TextStyle textStyle, int startCharIndex, int endCharIndex) Sets the style for the given range.protected TextRun
splitRunForCharIndex
(TextRun aRun, int anIndex) Splits given run at given char index and returns the run containing the remaining chars (and identical attributes).subSequence
(int aStart, int anEnd) Returns a new char sequence that is a subsequence of this sequence.toString()
Standard toString implementation.Standard toStringProps implementation.protected void
Update line/token x for center/right alignment or justify.protected void
Updates line style.protected void
updateRuns
(int aRunIndex) Updates length due to change in given run.protected void
Updates text.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
Methods inherited from interface snap.util.CharSequenceX
getIndentLength, getIndentString, getLastChar, indexAfterNewline, indexAfterNewlineOrEnd, indexOfNewline, isAfterLineEnd, isLastCharNewline, isLineEnd, isLineEndChar, isWhiteSpace, lastIndexAfterNewline, lastIndexOfNewline, startsWith
-
Field Details
-
_textBlock
-
_sb
-
_startCharIndex
protected int _startCharIndex -
_runs
-
_tokens
-
_lineStyle
-
_lineIndex
protected int _lineIndex -
_x
protected double _x -
_y
protected double _y -
_width
protected double _width -
_height
protected double _height -
EMPTY_RUNS
-
-
Constructor Details
-
TextLine
Constructor.
-
-
Method Details
-
getTextBlock
Returns the TextBlock. -
length
public int length()Returns the length of this text line.- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int anIndex) Returns the char value at the specified index.- Specified by:
charAt
in interfaceCharSequence
-
subSequence
Returns a new char sequence that is a subsequence of this sequence.- Specified by:
subSequence
in interfaceCharSequence
-
indexOf
Returns the index of given string in line. -
getString
Returns the string for the line. -
getStartCharIndex
public int getStartCharIndex()Returns the start char index of this line in text. -
getEndCharIndex
public int getEndCharIndex()Returns the end char index of this line in text. -
getLineIndex
public int getLineIndex()Returns the index of this line in text. -
addCharsWithStyle
Adds characters with text style to this line at given index. -
removeChars
public void removeChars(int aStart, int anEnd) Removes characters in given range. -
getRunCount
public int getRunCount()Returns the number of runs for this line. -
getRun
Returns the individual run at given index. -
getRuns
Returns the line runs. -
addRun
Adds a run to line. -
removeRun
protected void removeRun(int anIndex) Removes the run at given index. -
createRun
Creates a new run. -
getRunForCharIndex
Returns the head run for the line. -
getRunForCharRange
Returns the TextRun for the given char range (usually just run for start, but can be next run if at boundary). -
getLastRun
Returns the last run (or null if none). -
setTextStyle
Sets the style for the line (propagates to runs). -
setTextStyle
Sets the style for the given range. -
getLineStyle
Returns the line style. -
setLineStyle
Sets the line style. -
getX
public double getX()Returns the line x. -
getY
public double getY()Returns the line y. -
getWidth
public double getWidth()Returns the width of line. -
getHeight
public double getHeight()Returns the height of line. -
getWidthForStartCharIndex
public double getWidthForStartCharIndex(int startCharIndex) Returns the width of line from given index. -
getTrailingWhitespaceWidth
public double getTrailingWhitespaceWidth()Returns the width of the trailing whitespace. -
getBaseline
public double getBaseline()Returns the y position for this line (in same coords as the layout frame). -
getMaxX
public double getMaxX()Returns the max X. -
getMaxY
public double getMaxY()Returns the max Y. -
getTextX
public double getTextX()Returns the line x in text block coords. -
getTextY
public double getTextY()Returns the line y. -
getTextBaseline
public double getTextBaseline()Returns the y position for this line (in same coords as the layout frame). -
getTextMaxX
public double getTextMaxX()Returns the max X. -
getTextMaxY
public double getTextMaxY()Returns the max Y. -
getXForTabAtIndexAndX
protected double getXForTabAtIndexAndX(int charIndex, double aX) Returns the x for tab at given x. -
getTokenCount
public int getTokenCount()Returns the number of tokens. -
getToken
Returns the individual token at given index. -
getTokens
Returns the tokens. -
createTokens
Creates the tokens (via TextBlock.createTokensForTextLine() to provide another hook). -
getLastToken
Returns the last token. -
getMetrics
Returns the text metrics for line text. -
getTokenForCharIndex
Returns the token at given char index. -
getLastTokenForCharIndex
Returns the token at or before given char index. -
getXForCharIndex
public double getXForCharIndex(int anIndex) Returns the X coord for given char index. -
getTextXForCharIndex
public double getTextXForCharIndex(int anIndex) Returns the X coord for given char index. -
getTokenForX
Returns the token at index. -
getCharIndexForX
public int getCharIndexForX(double anX) Returns the character index for the given x/y point. -
getNext
Returns the next line, if available. -
getPrevious
Returns the previous line, if available. -
getAlignX
Returns the alignment associated with this line. -
setAlignX
Sets the alignment associated with this line. -
isUnderlined
public boolean isUnderlined()Returns whether line contains an underlined run. -
isHyphenated
public boolean isHyphenated()Returns whether line ends with hyphen. -
getUnderlineStroke
public double getUnderlineStroke()Returns the max stroke width of any underlined chars in this line. -
getUnderlineY
public double getUnderlineY()Returns the Y position of any underlined chars in this line. -
updateRuns
protected void updateRuns(int aRunIndex) Updates length due to change in given run. -
updateLineStyle
protected void updateLineStyle()Updates line style. -
updateText
protected void updateText()Updates text. -
updateAlignmentAndJustify
protected void updateAlignmentAndJustify()Update line/token x for center/right alignment or justify. -
splitRunForCharIndex
Splits given run at given char index and returns the run containing the remaining chars (and identical attributes). -
copyForRange
Returns a copy of this line for given char range. -
clone
Standard clone implementation. -
toString
Standard toString implementation.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
toStringProps
Standard toStringProps implementation.
-