The DrawText class provides functionality of setting text, parsing HTML, formatting and rendering text.
SetText method sets UTF-8, UCS-2 or Scaleform::String text value to the text object. The optional parameter ‘lengthInBytes’ specifies number of bytes in the UTF-8 string; ‘lengthInChars’ specifies number of characters in wide character string. If these parameters are not specified then the UTF-8 and UCS-2 strings should be null-terminated.
void SetText(const char* putf8Str, UPInt lengthInBytes = UPInt(-1)); void SetText(const wchar_t* pstr, UPInt lengthInChars = UPInt(-1)); void SetText(const String& str);
GetText method returns currently set text in UTF-8 format. It returns plain text value; even if HTML is used, it returns the string with all HTML tags stripped out.
String GetText() const;
SetHtmlText method parses UTF-8, UCS-2 or Scaleform::String encoded HTML and initializes the text object by the parsed HTML text. The optional parameter ‘lengthInBytes’ specifies number of bytes in the UTF-8 string; ‘lengthInChars’ specifies number of characters in wide character string. If these parameters are not specified then the UTF-8 and UCS-2 strings should be null-terminated.
void SetHtmlText(const char* putf8Str, UPInt lengthInBytes = UPInt(-1)); void SetHtmlText(const wchar_t* pstr, UPInt lengthInChars = UPInt(-1)); void SetHtmlText(const String& str);
GetHtmlText method returns currently set text in HTML format. If plain text is used with setting formatting by calling methods, such as SetColor, SetFont, etc, then this text will be converted to appropriate HTML format by this method.
String GetHtmlText() const;
There are several methods for setting and getting text format.
void SetColor(Color c, UPInt startPos = 0, UPInt endPos = UPInt(-1));
Sets color (R, G, B, A) to whole text or to the part of text in interval [startPos..endPos]. Both ‘startPos’ and ‘endPos’ parameters are optional.
void SetFont (const char* pfontName, UPInt startPos = 0, UPInt endPos = UPInt(-1))
Sets font to whole text or to the part of text in interval [startPos..endPos]. Both ‘startPos’ and ‘endPos’ parameters are optional.
void SetFontSize(float fontSize, UPInt startPos = 0, UPInt endPos = UPInt(-1))
Sets font size to whole text or to the part of text in interval [startPos..endPos]. Both ‘startPos’ and ‘endPos’ parameters are optional.
void SetFontStyle(FontStyle, UPInt startPos = 0, UPInt endPos = UPInt(-1));
enum FontStyle { Normal, Bold, Italic, BoldItalic, ItalicBold = BoldItalic };
Sets font style to whole text or to the part of text in interval [startPos..endPos]. Both ‘startPos’ and ‘endPos’ parameters are optional.
void SetUnderline(bool underline, UPInt startPos = 0, UPInt endPos = UPInt(-1))
Sets or clears underline to whole text or to the part of text in interval [startPos..endPos]. Both ‘startPos’ and ‘endPos’ parameters are optional.
void SetMultiline(bool multiline);
Sets multiline (parameter ‘multiline’ is set to true) or singleline (false) type of the text.
bool IsMultiline() const;
Returns 'true' if the text is multiline; ‘false’ otherwise.
void SetWordWrap(bool wordWrap);
Turns wordwrapping on/off.
bool Wrap() const;
Returns state of wordwrapping.
Type definitions for Alignment and VAlignment:
enum Alignment { Align_Left, Align_Default = Align_Left, Align_Right, Align_Center, Align_Justify }; enum VAlignment { VAlign_Top, VAlign_Default = VAlign_Top, VAlign_Center, VAlign_Bottom };
The different methods for aligning the text methods are given below.
void SetAlignment(Alignment);
Sets horizontal text alignment (right, left, center).
Alignment GetAlignment() const;
Returns horizontal text alignment (right, left, center).
void SetVAlignment(VAlignment);
Sets vertical text alignment (top, bottom, center).
VAlignment GetVAlignment() const;
Returns vertical text alignment (top, bottom, center).
The DrawText class has various methods for positioning and orienting the text object.
void SetRect(const RectF& viewRect);
Sets view rectangle, coordinates are in pixels.
RectF GetRect() const;
Returns currently used view rectangle, coordinates are in pixels.
void SetMatrix(const Matrix& matrix);
Sets transformation matrix to the text object.
const Matrix GetMatrix() const;
Returns the currently using transformation matrix.
void SetCxform(const Cxform& cx);
Set color transformation matrix to the text object.
const Cxform& GetCxform() const;
Returns the currently using color transformation matrix.