## Use font_api with display_api (to display text on nodes)
### Base setup
Font_api offers a direct integration with display_api to display text on nodes.
First of all, create a display node with an entity.
To do this, refer to API.md in display_api mod, in particular "Howto register a display node".
The only requirement then is to connect the `on_display_update` callback of the display entity to `font_api.on_display_update`:
```
minetest.register_node("mymod:test_text_node", {
...
paramtype2 = "facedir",
...
groups = { display_api = 1, ... },
...
display_entities = {
["mymod:text"] = {
depth = -0.5 - display_api.entity_spacing,
on_display_update = font_api.on_display_update },
}
...
on_place = display_api.on_place,
on_construct = display_api.on_construct,
on_destruct = display_api.on_destruct,
on_rotate = display_api.on_rotate,
...
})
```
At this step, your node already displays text form "display_text" (hardcoded) node meta.
But it uses defaults (default font, default size, default color). Likely you need something more.
### Style your text
Font style and size can be chosen by adding some more entries to the display_entities definition table.
#### Font size
Font size can be defined in various ways (maybe more in the future).
Start with a number of lines, and font_api will make it fit to the entity size.
*`maxlines` or `lines`: Number of maximum lines of text to be displayed. The font height will be adjusted accordingly.
Then specify the char width. Two methods available:
*`aspect_ratio`: Defines the aspect ratio of chars. Works with all fonts. Should not be used if `columns` is specified.
*`columns`: Only if using a fixed width font, specifies the number of columns to display.
#### Font style
*`font_name`: name of the font to use. Should correspond to a registered font (from a font mod). If not specified or font not found, default font is used.
*`color`: color to be used (default black).
*`halign`: Horizontal alignment: "left", "center" or "right" (default "center").
*`valign`: Vertical alignement: "top", "middle" or "bottom" (default "middle").
To ease that declaration (specially to build the **widths** array), a shell is provided to build a {font\_name}.lua file from the texture files (see provided tools).
This scripts takes a .ttf file as input and create one .png file per char, that can be used as font texture. Launch it from your future font mod directory.
This script works much better with pixels font, providing the correct height. There is no antialiasing at all, vector fonts and bad heights gives very ugly results.
This script analyses textures in textures directory and creates a font\_{font\_name}.lua files with a call to register_font with images information. Launch it from your future font mod directory.