docs: Actualizar REFERENCE.md con API TTF completa
- Reemplazar nota de placeholder con documentación real - Añadir ejemplos de código para cargar y usar TTF - Documentar FontRef para API unificada bitmap/TTF - Listar fuentes recomendadas con rutas en Fedora - Documentar features: AA, cache, alpha blending 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f2900d9dc2
commit
0625e18e77
1 changed files with 46 additions and 6 deletions
52
REFERENCE.md
52
REFERENCE.md
|
|
@ -645,20 +645,60 @@ renderer.setDefaultFont(@constCast(&render.font_8x16_latin1));
|
|||
```
|
||||
|
||||
**TrueType Fonts** (`src/render/ttf.zig`):
|
||||
|
||||
TTF fonts are fully supported with real glyph rasterization and antialiasing.
|
||||
|
||||
```zig
|
||||
const TtfFont = zcatgui.render.TtfFont;
|
||||
const FontRef = zcatgui.render.FontRef;
|
||||
|
||||
var ttf = try TtfFont.loadFromFile(allocator, "font.ttf");
|
||||
// Load TTF from file
|
||||
var ttf = try TtfFont.loadFromFile(allocator, "/usr/share/fonts/adwaita-sans-fonts/AdwaitaSans-Regular.ttf");
|
||||
defer ttf.deinit();
|
||||
|
||||
ttf.setSize(16); // Set render size
|
||||
// Set render size (glyphs cached per size)
|
||||
ttf.setSize(14); // 14pt
|
||||
|
||||
// Get metrics
|
||||
const metrics = ttf.getGlyphMetrics('A');
|
||||
ttf.textWidth("Hello");
|
||||
const width = ttf.textWidth("Hello");
|
||||
const height = ttf.lineHeight();
|
||||
const asc = ttf.ascent(); // Baseline to top
|
||||
const desc = ttf.descent(); // Baseline to bottom
|
||||
|
||||
// Draw text directly
|
||||
ttf.drawText(&framebuffer, x, y, "¡Hola, España!", color, clip);
|
||||
|
||||
// Or use FontRef for unified bitmap/TTF API
|
||||
const font_ref = FontRef{ .ttf = &ttf };
|
||||
font_ref.drawText(&framebuffer, x, y, "Hello", color, clip);
|
||||
```
|
||||
|
||||
> **Note**: TTF rendering currently uses placeholder glyphs. Full TTF rasterization
|
||||
> (bezier curve rendering) is planned for future releases. For production use,
|
||||
> prefer the bitmap fonts which have complete glyph rendering.
|
||||
**Features:**
|
||||
- Real bezier curve rasterization (quadratic beziers)
|
||||
- Antialiasing via 2x supersampling
|
||||
- Glyph caching (by codepoint + size)
|
||||
- Alpha blending for smooth edges
|
||||
- Full Unicode support (BMP via cmap format 4, full via format 12)
|
||||
|
||||
**Recommended fonts (free, good Latin-1 support):**
|
||||
| Font | Location (Fedora) | Notes |
|
||||
|------|-------------------|-------|
|
||||
| AdwaitaSans | `/usr/share/fonts/adwaita-sans-fonts/` | GNOME default, modern |
|
||||
| DejaVu Sans | `/usr/share/fonts/dejavu-sans-fonts/` | Very complete |
|
||||
| Droid Sans | `/usr/share/fonts/google-droid-sans-fonts/` | Android default |
|
||||
|
||||
**Switching between Bitmap and TTF:**
|
||||
```zig
|
||||
// Use FontRef to switch fonts without changing widget code
|
||||
var current_font: FontRef = .{ .bitmap = &render.font_8x16_latin1 };
|
||||
|
||||
// Later, switch to TTF
|
||||
current_font = .{ .ttf = &ttf_font };
|
||||
|
||||
// Widget code stays the same
|
||||
current_font.drawText(fb, x, y, text, color, clip);
|
||||
```
|
||||
|
||||
### UTF-8 Text Rendering
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue