# Font Rendering - MapLibre Rust Documentation

# Font Rendering

There exists no universally perfect solution to font rendering. Depending on the runtime environment a method needs to be chosen. This StackOverflow post outlines some state-of-the-art methods. Some more approaches are described here.

From my perspective the following approaches could work potentially:

1. Tessellate Fonts
2. SDF Font Rendering
3. GPU Text Rendering directly from Bezier Curves
4. Draw text using a Web Canvas and load them to GPU

There is a thesis which summarizes some methods here. A link collection about font related projects can be viewed here.

## Approaches

### Tessellate Fonts

There is ttf2mesh which generates meshes. I was already able to generate about 1k glyphs with ~40FPS.

### SDF Font Rendering

There is a blogpost by Mapbox here. Some more implementation documents are available here. A good foundation for SDF fonts was created by Chlumsky with msdfgen.

### GPU Text Rendering from Bezier Curves

The solutions exist:

- By Will Dobbie with an implementation here
- Slug Library which is patented and probably therefore not usable

Here is the whitepaper of the Slug library. There is also a poster about it. There also exists an open implementation.

### Draw text using a Web Canvas

This approach has the downside that we can not dynamically scale rendered fonts according to the current zoom level.

## Other Approaches

- 16x AA font rendering using coverage masks