Skip to content
lukemalcolm edited this page Sep 14, 2010 · 8 revisions

= Introduction =

ofxTextSuite provides a number of text functions for re-use.

= Functions =

ofxTextBlock is a text wrapping manager that provides the following features:

  • Text wrapping:
  • Horiztonal Wrapping
  • Area wrap and resize (fit to area)
  • Force number of lines of wrap
  • Text drawing alignment:
  • Left
  • Right
  • Center
  • Justified
  • Independent word colouring. E.g. each word can be a different colour.
  • Word level access to text.

= Usage =

=1. Create ofxTextBlock object:=

e.g. In header: `ofxTextBlock myText;`

=2. Set up a text block:=

`void init(string fontLocation, float fontSize);`

e.g. In setup(): `myText.init(“frabk.ttf”, 80);`

=3. Insert text into block=

`void setText(string _inputText);` e.g. In update(): `myText.setText(“The rain in spain rains mainly on the plain.”)`

=4. Utilise a wrapping method:=

==Wrap Horizontally==

`int wrapTextX(float lineWidth);`
`linewidth` is the number of pixels wide to wrap to. This will use the default font size specified during ofxTextBlock.init for it’s calculations. `ofxTextBlock.scale` will be set to `1.0f`; Returns the number of lines it formed.

==Wrap to Area==

`void wrapTextArea(float rWidth, float rHeight);`
This function will wrap and resize the text block to `rWidth` and `rHeight`, scaling the text to the largest possible size it can. The function sets the float value of `ofxTextBlock.scale` and then uses it during drawing.

==Wrap to a designated number of lines==

`bool wrapTextForceLines(int linesN);`
This evenly spreads the text over a number of lines: `linesN`. `ofxTextBlock.scale` will be set to `1.0f`;

5. Draw Text Block

==Draw Default (Left)==

`void draw(float x, float y);`
Draws the text block left aligned, with the upper left point of the text block at coordinates `x, y`.

==Draw Left Aligned==

`void drawLeft(float x, float y);`
Draws the text block left aligned, with the upper left point of the text block at coordinates `x, y`.

==Draw Right Aligned==

`void drawRight(float x, float y);`
Draws the text block right aligned, with the upper right point of the text block at coordinates `x, y`.

==Draw Center Aligned==

`void drawCenter(float x, float y);`
Draws the text block center aligned, with the upper center point of the text block at coordinates `x, y`.

==Draw Center Aligned==

`void drawJustified(float x, float y, float boxWidth);`
Draws the text block justified, with the upper left point of the text block at coordinates `x, y` and the width of text area specified by `boxWidth`.

Other functions

`void setLineHeight(float lineHeight);`
Sets the line height with which to render the text. `lineHeight` is specified PRE scaling and hence is proportional to the font size specified in `ofxTextBlock.init`.

`void setColor(int r, int g, int b, int a);`
Sets the color of all words in the text block. Individual word colors can be changed by accessing the `words` vector directly.

`float getWidth();`
Returns the width of the text block, taking into consideration scale.

`float getHeight();`
Returns the height of the text block, taking into consideration scale.

`void forceScale(float _scale);`
Force scale can manually be used after a wrap function to force the text block to a different scale.