IN THIS ARTICLE
Configuring Font Properties
You can define the appearance of your UI font by configuring various properties that affect the font’s appearance and usage.
You define your font’s properties in the .font
file, which is an XML file. The following example shows the default UI font XML file, located in Engine/Fonts/default-ui.font
.
<fontshader>
<font path="Vera.ttf" fontsize="32"/>
<effect name="default">
<pass>
</pass>
</effect>
<effect name="drop_shadow">
<pass>
</pass>
<pass>
<color r="0" g="0" b="0" a="1"/>
<pos x="1" y="1"/>
</pass>
</effect>
</fontshader>
The default UI font XML uses the Vera font. It defines a font texture that can hold 128 unique character or glyphs that are 32x32 pixels. The font includes two representations that are defined with the effect tags default
and drop_shadow
. For the default
effect, the font is rendered as is. For the drop_shadow
effect, the font is first rendered as is. A second render pass produces the font in black with a 1-pixel offset from the first pass. This creates a basic shadowing effect of the characters.
Note:Fonts can be part of a font family (with a.fontfamily
extension), though you can use a standalone font that isn’t in a font family. For more information on font families, see Creating Font Families.
Use the following tags, attributes, and values to define key features of your font.
Tag | Description | Attributes |
---|---|---|
font | Contains critical attributes that define the path to the asset, size, and other font qualities. | See Font Tag Attributes. |
effect | Acts as a parent tag to pass children tags. Groups the pass tags that comprises the effect. | name – Name of the effect. |
effectfile | Specifies the path to an XML file that contains effect tags. | path – String that specifies the path to an XML file containing effect tags. |
pass | A child tag of an effect tag. You can add multiple pass tags as the children of a single effect tag. Defines a render pass of the text with various parameters that affect the text’s rendering. The pass tags can be layered on top of each other, giving the effect a unique look. | Doesn’t have attributes. Parents the following child tags that define text effects: |
color | A text effect that is a child tag of the pass tag. Defines the text color. | Uses the following attributes to define the effect’s intensity with float point values:0.0 1.0f 0 is transparent. 1.0f is opaque) |
pos or offset | A text effect that is a child tag of the pass tag. Sets the position of the text. | Uses the following attributes to set text position with integer values: |
blend or blending | A text effect that is a child tag of the pass tag. Defines alpha blending behavior of the text. | Uses the following attributes to define the text’s alpha blending behavior:zero one srcalpha or src_alpha invsrcalpha or inv_src_alpha dstalpha or dst_alpha invdstalpha or inv_dst_alpha dstcolor or dst_color srccolor or src_color invdstcolor or inv_dst_color invsrccolor or inv_src_color modulate-src_alpha and inv_src_alpha (one minus source alpha) blendingadditive-src_alpha and one (for destination) blending |
Font Tag Attributes
Font tag attributes define critical attributes for a font, such as the path to the TTF/OTF asset used to display the font, and other attributes affecting font render quality.
Note:Most of these attributes have a direct impact on font rendering quality. For more information, see Configuring Font Rendering Quality.
Attribute | Example | Description |
---|---|---|
path | <font path=“Vera.ttf” … /> | String |
fontsize | < … fontsize=“32”/> | Integer |
w | < … w=“512” h=“256” /> | Integer |
h | < … w=“512” h=“256” /> | Integer |
widthslots | … widthslots=“8” heightslots=“8” /> | Integer 16 512x512 . The widthslots and heightslots are set to 8 . This gives a space of 64x64 for each character. |
heightslots | < … widthslots=“8” heightslots=“8” /> | Integer 8 |
sizeratio | < … sizeratio=“0.6” /> | Float 0.8 |
sizebehavior | < … sizebehavior=“rerender” /> | String rerender |
hintbehavior | < … hintbehavior=“nohinting” /> | String default – Hinting behavior as provided by the font. You can also omit the hintbehavior tag to use the default hinting.nohinting – Disable hinting.autohint – Hinting behavior procedurally derived from the font. |
hintstyle | < … hintstyle=“light” /> | String normal – Appearance as provided by the font. You can also omit the hintsytle tag to use the default hinting.light – Fuzzier appearance that might more accurately represent the shape of glyphs in the font. |
smooth | < … smooth=“blur” smooth_amount=“3” /> | String blur – Applies a simple burring effect to characters or glyphs stored in the font texture. Use smooth_amount to set the number of iterations to use for blurring.supersample – Super samples characters or glyphs in the font texture by smooth_amount: 1 for 2x, and 2 for 4x.none – Default. No smoothing applied. |
smooth_amount | < … smooth=“supersample” smooth_amount=“1” /> | Integer |