Package playn.core
Class TextBlock
java.lang.Object
playn.core.TextBlock
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
-
Field Summary
Modifier and TypeFieldDescriptionfinal IRectangle
The bounds of this block of text.final TextLayout[]
The individual lines of text in this block. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
fill
(Canvas canvas, TextBlock.Align align, float x, float y) Fillslines
intocanvas
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) Strokeslines
intocanvas
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.
-
Field Details
-
lines
The individual lines of text in this block. Obtained by a call toGraphics.layoutText(String,TextFormat,TextWrap)
. -
bounds
The bounds of this block of text. Thex
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. Thestroke(playn.core.Canvas, playn.core.TextBlock.Align, float, float)
andfill(playn.core.Canvas, playn.core.TextBlock.Align, float, float)
methods automatically take into account this x coordinate, the caller need only account for it if they choose to renderlines
manually.
-
-
Constructor Details
-
TextBlock
Creates a text block with the suppliedlines
.
-
-
Method Details
-
getBounds
Computes the bounds of a block of text. Thex
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
Fillslines
intocanvas
at the specified coordinates, using the specified alignment. -
stroke
Strokeslines
intocanvas
at the specified coordinates, using the specified alignment. -
toCanvas
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.
-