Package playn.core

Class TextBlock

java.lang.Object
playn.core.TextBlock

public class TextBlock extends Object
Encapsulates a block of multi-line text. This code handles all the fiddly "fonts sometimes extend outside their reported bounds" hackery that was once embedded into the various backend code. It also handles text alignment.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Used to align a block of text.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The bounds of this block of text.
    final TextLayout[]
    The individual lines of text in this block.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a text block with the supplied lines.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    fill(Canvas canvas, TextBlock.Align align, float x, float y)
    Fills lines into canvas at the specified coordinates, using the specified alignment.
    static Rectangle
    getBounds(TextLayout[] lines, Rectangle into)
    Computes the bounds of a block of text.
    void
    stroke(Canvas canvas, TextBlock.Align align, float x, float y)
    Strokes lines into canvas at the specified coordinates, using the specified alignment.
    float
    Returns the width of the rendered text.
    toCanvas(Graphics gfx, TextBlock.Align align, int fillColor)
    Creates a canvas image large enough to accommodate this text block and renders the lines into it.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • TextBlock

      public TextBlock(TextLayout[] lines)
      Creates a text block with the supplied lines.
  • Method Details

    • getBounds

      public static Rectangle getBounds(TextLayout[] lines, Rectangle into)
      Computes the bounds of a block of text. The x component of the bounds may be positive, indicating that the text should be rendered at that offset. This is to account for the fact that some text renders to the left of its reported origin due to font extravagance.
    • textWidth

      public float textWidth()
      Returns the width of the rendered text. This is the width that should be used when computing alignment for text in this block.
    • fill

      public void fill(Canvas canvas, TextBlock.Align align, float x, float y)
      Fills lines into canvas at the specified coordinates, using the specified alignment.
    • stroke

      public void stroke(Canvas canvas, TextBlock.Align align, float x, float y)
      Strokes lines into canvas at the specified coordinates, using the specified alignment.
    • toCanvas

      public Canvas toCanvas(Graphics gfx, TextBlock.Align align, int fillColor)
      Creates a canvas image large enough to accommodate this text block and renders the lines into it. The image will include padding around the edge to ensure that antialiasing has a bit of extra space to do its work.