How to render text onto images with the Font framework.
This page describes the font rendering system, the available renderers, and how to choose between them.
All font renderers derive from the Font abstract base class, which manages common state (font filename, size, colors, paint engine, kerning) and defines the rendering interface.
Font — Abstract base. Requires a PaintEngine at construction. Provides setters, getters, and the pure virtual drawText() / measureText() / metrics interface.FastFont — Cached opaque renderer. Pre-renders each glyph into the target pixel format for maximum throughput.BasicFont — Alpha-compositing renderer. Composites each glyph pixel-by-pixel for correct transparency.| Aspect | FastFont | BasicFont |
|---|---|---|
| Rendering strategy | Cached opaque blit (memcpy) | Per-pixel alpha compositing |
| Speed | Very fast for repeated draws | Slower; re-composites every draw |
| Memory | Higher (per-glyph image cache) | Minimal (no cache) |
| Transparency | No — glyph cells are opaque | Yes — composites over existing content |
| Background color | Fills glyph cell | Ignored |
| Best for | HUD overlays, timecodes, titles | Transparent overlays, one-off renders |
Use FastFont when the same text (or the same character set) is drawn many times at the same size and color, such as burning timecodes into a video stream. Use BasicFont when text must blend smoothly over a varying background, or when rendering is infrequent and memory matters more than speed.
Both renderers accept foreground and background colors via the Font base class. Their interpretation differs:
Both renderers support optional kerning via Font::setKerningEnabled(). When enabled, the renderer queries FreeType's kerning tables to adjust horizontal spacing between glyph pairs. Kerning is disabled by default.
After configuring a font (filename, size, and paint engine), the following metrics are available via lazy loading:
Font::ascender() — distance from baseline to top of cell.Font::descender() — distance from baseline to bottom of cell.Font::lineHeight() — full cell height (ascender + descender).These methods trigger font loading on first call. They return 0 if the font cannot be loaded.
A PaintEngine is required at construction and determines the target pixel format. It can be changed later via Font::setPaintEngine(). Switching to a PaintEngine with the same pixel format pointer is cheap — no cache invalidation occurs. Switching pixel formats triggers a full invalidation in subclasses.