4 # Font Selection {#font-selection}
6 By default TextLabel or TextField will automatically select a suitable font from the platform.
7 Typically fonts do not support all scripts, for example Latin fonts often do not provide Arabic glyphs.
8 Therefore you should expect the text control to select different fonts for each script.
10 Alternatively a font may be requested using either or all of FONT_FAMILY, FONT_STYLE, and POINT_SIZE properties:
13 Is a string with the font's family name. i.e. *FreeSerif*
15 Is a json formatted string with the font's style. Possible *key, value* pairs are:
16 + *width* Modifies the space between glyphs. Possible values are:
26 + *weight* Modifies the thickness or darkness of the glyphs. Possible values are:
45 + *slant* Whether to use italics. Usually *italic* is a different font whilst the *oblique* has been generated by slanting the *normal* one. Possible values are:
47 - *roman* Same as *normal*
51 Is a float with the font's size in points. To get the point size from pixels, could use the formula: <em>point_size = 72 * pixels / vertical_dpi</em> where <em>vertical_dpi</em> is the device's vertical resolution in dots per inch.
56 label.SetProperty( TextLabel::Property::FONT_FAMILY, "FreeSerif" );
57 label.SetProperty( TextLabel::Property::FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
58 label.SetProperty( TextLabel::Property::POINT_SIZE, 12.0f );
64 label.fontFamily = "FreeSerif";
65 label.fontStyle = "{\"weight\":\"bold\",\"slant\":\"italic\"}";
69 However the text control will fall-back to using the default font, if the requested font does not support the required scripts.
73 Setting a font size programmatically is not ideal for applications which support multiple screen resolutions etc.
74 A more flexible approach is to prepare various JSON stylesheets, and request a different style for each platform:
78 StyleManager styleManager = StyleManager::Get();
79 styleManager.RequestThemeChange( "example-path/example.json" );
82 To change the font for standard text controls, this JSON syntax can be used:
90 "fontFamily":"FreeSerif",
91 "fontStyle":"{\"weight\":\"bold\",\"slant\":\"italic\"}",
98 However the same pointSize is unlikely to be suitable for all text controls in an application.
99 To set custom sizes simply set a "style name" for each case, and then provide a style override in JSON:
104 label.SetProperty( Control::Property::STYLE_NAME, "custom" );
109 label.styleName = "custom"';
118 "fontFamily":"FreeSerif",
119 "fontStyle":"{\"weight\":\"bold\",\"slant\":\"italic\"}",
131 In the example above, standard text labels will have pointSize 8, and "custom" labels will have pointSize 10.