Class SimpleTextLayout

  • Direct Known Subclasses:
    SimpleTextLayoutCenter

    public class SimpleTextLayout
    extends Object
    Performs simple text layout so text can be wrapped in small areas or broken on words or newlines. This implementation currently makes the following assumptions which are valid for latin text:

    • mapping chars to glyphs is 1:1 in order, (no Unicode surrogate pairs or multi-glyph characters)
    • left-to-right and top-to-bottom text layout

    All coordinates are in the same space as the text is being drawn (typically pixels).

    Author:
    borkholder
    • Constructor Detail

      • SimpleTextLayout

        public SimpleTextLayout​(Font font,
                                FontRenderContext frc)
        Parameters:
        font - The font to use for the layout
        frc - The FontRenderContext used to rasterize the font. This will help define the character bounds
      • SimpleTextLayout

        public SimpleTextLayout​(Font font,
                                FontRenderContext frc,
                                BreakIterator breaker)
        Parameters:
        font - The font to use for the layout
        frc - The FontRenderContext used to rasterize the font. This will help define the character bounds
        breaker - The BreakIterator that is used to break the text (also see forceBreakAfter(int))
    • Method Detail

      • getLineHeight

        public double getLineHeight()
      • getDescent

        public double getDescent()
      • getAscent

        public double getAscent()
      • setAscent

        public void setAscent​(float ascent)
      • setBreakOnEol

        public void setBreakOnEol​(boolean breakOnEol)
      • getBreakOnEol

        public boolean getBreakOnEol()
        Whether to force a break on the end of line characters (\r \f \n).
      • setLineSpacing

        public void setLineSpacing​(float lineSpacing)
      • getLineSpacing

        public float getLineSpacing()
        The spacing between the bottom (descent) of one line of text to the top (ascent) of the next line.
      • doLayout

        public void doLayout​(String text,
                             float leftX,
                             float topY,
                             float maxWidth)
        Takes the text and performs the layout. The provided constraints determine the top-left position of the text and the maximum width. See numberOfLines(), getLine(int) and #getBounds(int) for the results of the layout.
        Parameters:
        text - The text to lay out
        leftX - The leftmost X value of any pixel of text
        topY - The topmost Y value of any pixel of text
        maxWidth - The suggested maximum width of any line of the text
      • getSourceText

        public String getSourceText()
      • numberOfLines

        public int numberOfLines()