Dali 3D User Interface Engine
font-selection

Font Selection

By default TextLabel or TextField will automatically select a suitable font from the platform. Typically fonts do not support all scripts, for example Latin fonts often do not provide Arabic glyphs. Therefore you should expect the text control to select different fonts for each script.

Alternatively a font may be requested using either or all of FONT_FAMILY, FONT_STYLE, and POINT_SIZE properties:

// C++
label.SetProperty( TextLabel::Property::FONT_FAMILY, "FreeSerif" );
label.SetProperty( TextLabel::Property::FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
label.SetProperty( TextLabel::Property::POINT_SIZE, 12.0f );
// JavaScript
label.fontFamily = "FreeSerif";
label.fontStyle = "{\"weight\":\"bold\",\"slant\":\"italic\"}";
label.pointSize = 12;

However the text control will fall-back to using the default font, if the requested font does not support the required scripts.

Font Styles

Setting a font size programmatically is not ideal for applications which support multiple screen resolutions etc. A more flexible approach is to prepare various JSON stylesheets, and request a different style for each platform:

// C++
StyleManager styleManager = StyleManager::Get();
styleManager.RequestThemeChange( "example-path/example.json" );

To change the font for standard text controls, this JSON syntax can be used:

{
"styles":
{
"textlabel":
{
"fontFamily":"FreeSerif",
"fontStyle":"{\"weight\":\"bold\",\"slant\":\"italic\"}",
"pointSize":8
}
}
}

However the same pointSize is unlikely to be suitable for all text controls in an application. To set custom sizes simply set a "style name" for each case, and then provide a style override in JSON:

// C++
label.SetProperty( Control::Property::STYLE_NAME, "custom" );
// JavaScript
label.styleName = "custom"';
{
"styles":
{
"textlabel":
{
"fontFamily":"FreeSerif",
"fontStyle":"{\"weight\":\"bold\",\"slant\":\"italic\"}",
"pointSize":8
},
"custom":
{
"pointSize":10
}
}
}

In the example above, standard text labels will have pointSize 8, and "custom" labels will have pointSize 10.

*/

Dali Docs Home
Read more about Dali