Starling extension for using bitmap fonts with simplified html tags for styling texts
sorry all asdoc and comments are in french, i will change it soon
HTMLTextField
is a Starling TextField for using with simplified html notation (just for styling: no links, no images...).
- bold :
<b></b>
; - italic :
<i></i>
; - size :
<size="10"></size>
or<s="10"></s>
; - colors : don't forget '0x' or '#' !
- solid :
<color="0xFF0000"></color>
or
<c="0xFF0000"></c>
; - gradient up / down :
<color="0xFF0000,0xFFFFFF"></color>
or
<c="0xFF00000xFFFFFF"></c>;
- gradient up-left/up-right/down-left/down-right :
<color="0xFF0000,0xFFFFFF,0x000000,0x0000FF"></color>
or
<c="0xFF0000,0xFFFFFF,0x000000,0x0000FF"></c>
HTMLTextField uses HTMLBitmapFonts instead of the tradtional BitmapFont.
To add a font for use with HTMLtextField you must add them to HTMLTextField with the static method HTMLTextField.registerBitmapFont
this fonction accept as xml value the same XML as traditional BitmapFont.
They can be generated with tools like :
Personnaly i use AssetManager for loading fonts and i just modified it like this:
in loadQueue -> processXML :
// if I parse fontHTML -> load the font for HTMLTextFields
else if( rootNode == "fontHTML" )
{
name = [email protected]();
fileName = getName([email protected]());
isBold = xml.info.@bold == 1;
isItalic = xml.info.@italic == 1;
log("Adding html bitmap font '" + name + "'" + " _bold: " + isBold + " _italic: " + isItalic );
fontTexture = getTexture( fileName );
HTMLTextField.registerBitmapFont( fontTexture, xml, xml.info.@size, isBold, isItalic, name.toLowerCase() );
removeTexture( fileName, false );
mLoadedHTMLFonts.push( name.toLowerCase() );
}
- Only one font name can be used in the HTMLTextField, it can only change size, bold, italic, and color
- All font styles must be on the same atlas as the textField is drawed on a QuadBatch
- No scales are applied on the texts, when adapting the font size it just search within the available sizes
- HTMLBitmapFont has a static property globalScale (default 1), you can set it to the scale applied on the starling viewport. It will search the best font size to adapt the desired font size without scaling them.