The Scaleform SDK implementation contains a powerful font rendering and text formatting engine, primarily used for rendering text displayed as a part of the Flash® based UI. Text rendering in Scaleform supports a number of advanced features such as on-the-fly rasterization and caching of screen-pixel aligned glyphs, scrollable text fields with paragraph alignment, and rich HTML-tag formatted text with fonts obtained from either system font providers or the SWF/GFX embedded file data.
In most cases, Scaleform text rendering system is used automatically when playing Flash files, with text fields arranged visually by the artist in the Flash Studio. For additional control, text formatting is exposed through the TextField and TextFormat ActionScript (AS) classes, which provide a preferred way of interfacing with text. With these APIs in place, it is rarely necessary to use the C++ APIs for this purpose.
There are, however, occasional situations when going through ActionScript for text rendering can be inconvenient, or the associated overhead undesirable. Rendering of name billboards over moving avatars on screen or text labels next to items on a radar can often be done more efficiently through C++ if your game can not afford having full-fledge Flash UI for those items. Furthermore, if your game combines the Scaleform based menu system with a 3D engine rendered HUD, it is still desirable to use the same font system in both cases.
Scaleform 4.0 includes a C++ driven DrawText API, exposing the Scaleform font rendering and text formatting engines outside of the movie view sandbox. The text API still uses the same Render::Renderer2D interface as the rest of Scaleform player; however, it does not require creation of the GFx::Movie object, allowing developers to position and manipulate text fields directly within the viewport without the associated ActionScript overhead.
There are two possible sources of fonts for the DrawText API: system fonts and fonts loaded from SWF/GFX files. In the first case, the system font provider should be used. In the second case, the SWF file with fonts should be loaded as a GFx::MovieDef (using the GFx::Loader::CreateMovie method) and then the created MovieDef could be passed as a parameter to GFx::DrawTextManager constructor.
The two C++ that classes that provide text rendering functionality are GFx::DrawTextManager and GFx::DrawText; their use is outlined below and then explained in detail through the rest of this document.
GFx::DrawTextManager - Creates instances of the DrawText class. It is used to initialize text rendering and viewport, configure fonts, and to start/stop rendering the text.
GFx::DrawText – Represents an individual rectangular text field on screen, exposing text formatting and rendering capabilities. This class can either parse Flash HTML tags or use plain text with supplementary formatting data. Text field attributes can be changed through member functions such as SetColor, SetFont, and SetFontStyle.