Package snap.text

Class TextLine

java.lang.Object
snap.text.TextLine
All Implemented Interfaces:
CharSequence, Cloneable, CharSequenceX

public class TextLine extends Object implements CharSequenceX, Cloneable
This class represents a line of text in a Text.
  • Field Details

    • _textBlock

      protected TextBlock _textBlock
    • _sb

      protected StringBuilder _sb
    • _startCharIndex

      protected int _startCharIndex
    • _runs

      protected TextRun[] _runs
    • _tokens

      protected TextToken[] _tokens
    • _lineStyle

      protected TextLineStyle _lineStyle
    • _lineIndex

      protected int _lineIndex
    • _x

      protected double _x
    • _y

      protected double _y
    • _width

      protected double _width
    • _height

      protected double _height
    • EMPTY_RUNS

      protected static final TextRun[] EMPTY_RUNS
  • Constructor Details

    • TextLine

      public TextLine(TextBlock aTextBlock)
      Constructor.
  • Method Details

    • getTextBlock

      public TextBlock getTextBlock()
      Returns the TextBlock.
    • length

      public int length()
      Returns the length of this text line.
      Specified by:
      length in interface CharSequence
    • charAt

      public char charAt(int anIndex)
      Returns the char value at the specified index.
      Specified by:
      charAt in interface CharSequence
    • subSequence

      public CharSequence subSequence(int aStart, int anEnd)
      Returns a new char sequence that is a subsequence of this sequence.
      Specified by:
      subSequence in interface CharSequence
    • indexOf

      public int indexOf(String aStr, int aStart)
      Returns the index of given string in line.
    • getString

      public String 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

      protected void addCharsWithStyle(CharSequence theChars, TextStyle aStyle, int anIndex)
      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

      public TextRun getRun(int anIndex)
      Returns the individual run at given index.
    • getRuns

      public TextRun[] getRuns()
      Returns the line runs.
    • addRun

      protected void addRun(TextRun aRun, int anIndex)
      Adds a run to line.
    • removeRun

      protected void removeRun(int anIndex)
      Removes the run at given index.
    • createRun

      protected TextRun createRun()
      Creates a new run.
    • getRunForCharIndex

      public TextRun getRunForCharIndex(int anIndex)
      Returns the head run for the line.
    • getRunForCharRange

      public TextRun 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).
    • getLastRun

      public TextRun getLastRun()
      Returns the last run (or null if none).
    • setTextStyle

      protected void setTextStyle(TextStyle textStyle)
      Sets the style for the line (propagates to runs).
    • setTextStyle

      protected void setTextStyle(TextStyle textStyle, int startCharIndex, int endCharIndex)
      Sets the style for the given range.
    • getLineStyle

      public TextLineStyle getLineStyle()
      Returns the line style.
    • setLineStyle

      public void setLineStyle(TextLineStyle aLineStyle)
      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

      public TextToken getToken(int anIndex)
      Returns the individual token at given index.
    • getTokens

      public TextToken[] getTokens()
      Returns the tokens.
    • createTokens

      protected TextToken[] createTokens()
      Creates the tokens (via TextBlock.createTokensForTextLine() to provide another hook).
    • getLastToken

      public TextToken getLastToken()
      Returns the last token.
    • getMetrics

      public TextMetrics getMetrics()
      Returns the text metrics for line text.
    • getTokenForCharIndex

      public TextToken getTokenForCharIndex(int charIndex)
      Returns the token at given char index.
    • getLastTokenForCharIndex

      public TextToken getLastTokenForCharIndex(int charIndex)
      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

      public TextToken getTokenForX(double anX)
      Returns the token at index.
    • getCharIndexForX

      public int getCharIndexForX(double anX)
      Returns the character index for the given x/y point.
    • getNext

      public TextLine getNext()
      Returns the next line, if available.
    • getPrevious

      public TextLine getPrevious()
      Returns the previous line, if available.
    • getAlignX

      public HPos getAlignX()
      Returns the alignment associated with this line.
    • setAlignX

      public void setAlignX(HPos anAlign)
      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

      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).
    • copyForRange

      public TextLine copyForRange(int aStart, int aEnd)
      Returns a copy of this line for given char range.
    • clone

      public TextLine clone()
      Standard clone implementation.
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Standard toString implementation.
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • toStringProps

      public String toStringProps()
      Standard toStringProps implementation.