public class WordWrapper
extends java.lang.Object
| Constructor and Description |
|---|
WordWrapper() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.List<java.lang.String> |
wordWrap(java.lang.String text,
int width,
processing.core.PApplet sketch)
Works out where a string of text needs to wrap to fit into a given width
in pixels and returns as a list of strings, each of which will not exceed
the given width.
|
static java.util.List<java.lang.String> |
wordWrap(java.lang.String textToWrap,
int width,
processing.core.PGraphics pGraphics)
Works out where a string of text needs to wrap to fit into a given width
in pixels and returns as a list of strings, each of which will not exceed
the given width.
|
static java.util.List<WrappedToken> |
wordWrapAndTokenise(java.lang.String text,
float x,
float y,
float width,
processing.core.PApplet sketch)
Tokenises the input string and return a list of these tokens and where they should be
drawn.
|
static java.util.List<WrappedToken> |
wordWrapAndTokenise(java.lang.String textToTokenize,
float x,
float y,
float width,
processing.core.PGraphics pGraphics)
Tokenises the input string and return a list of these tokens and where they should be
drawn.
|
public static java.util.List<java.lang.String> wordWrap(java.lang.String text,
int width,
processing.core.PApplet sketch)
\t characters are converted to single spaces\n are honouredtextFont and textSize.
Wraps on ' ' and '-'.text - Text to wrapwidth - Width to wrap text tosketch - The sketch (uses current font)public static java.util.List<java.lang.String> wordWrap(java.lang.String textToWrap,
int width,
processing.core.PGraphics pGraphics)
\t characters are converted to single spaces\n are honoured pGraphics's current textFont and textSize.
Wraps on ' ' and '-'.textToWrap - Text to wrap.width - Width to wrap text to.pGraphics - The graphic context doing the text drawing.public static java.util.List<WrappedToken> wordWrapAndTokenise(java.lang.String text, float x, float y, float width, processing.core.PApplet sketch)
"{other}The {adjective}quick{other} {adjective}brown{other} fox jumped over the
{adjective}lazy{other} dog"
' and '-'.
Uses the sketch's current textFont, textSize, textLeading
(line spacing) and textAlign.
The token positions returned can be used directly in the PApplet's text(text,x,y) method.text - The text to tokenise.x - The x position of the text block placement.y - The y position of the text block placement.width - The width of the area within which to wrap text.sketch - The sketch doing the text drawing.WrappedTokens that contain the information required to display these on screen.public static java.util.List<WrappedToken> wordWrapAndTokenise(java.lang.String textToTokenize, float x, float y, float width, processing.core.PGraphics pGraphics)
"{other}The {adjective}quick{other} {adjective}brown{other} fox jumped over the
{adjective}lazy{other} dog"
' and '-'.
Uses the pGraphics's current textFont, textSize, textLeading
(line spacing) and textAlign. The token positions returned can be used directly in the
PApplet's text(text,x,y) method.textToTokenize - The text to tokenise.x - x position of the text placement.y - y position of the text placement.width - Width within to wrap text.pGraphics - Graphics context doing the text drawing.