feat: Embeber fuente AdwaitaSans-Regular.ttf

- Añadir src/render/fonts/AdwaitaSans-Regular.ttf (860KB)
- Crear src/render/embedded_font.zig con @embedFile
- Añadir TtfFont.initEmbedded() para carga sin dependencias
- Exportar embedded_font en zcatgui.zig

Ahora cualquier programa que use zcatgui tiene TTF
disponible automáticamente sin archivos externos.

Licencia: SIL Open Font License (redistribución OK)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
reugenio 2025-12-16 01:21:28 +01:00
parent a11e1ea842
commit 22d5e51769
4 changed files with 72 additions and 0 deletions

View file

@ -0,0 +1,64 @@
//! Fuente TTF embebida para uso sin dependencias externas
//!
//! Incluye AdwaitaSans-Regular para renderizado de texto con antialiasing.
//! Licencia: SIL Open Font License (permite redistribución embebida).
const std = @import("std");
const TtfFont = @import("ttf.zig").TtfFont;
/// Datos binarios de la fuente embebida (cargados en tiempo de compilación)
pub const adwaita_sans_data: []const u8 = @embedFile("fonts/AdwaitaSans-Regular.ttf");
/// Tamaño de la fuente embebida en bytes
pub const adwaita_sans_size: usize = adwaita_sans_data.len;
/// Inicializa TtfFont desde la fuente embebida AdwaitaSans-Regular
///
/// Ejemplo:
/// ```zig
/// var ttf = try embedded_font.initEmbeddedFont(allocator);
/// defer ttf.deinit();
/// ttf.setSize(14);
/// renderer.setTtfFont(&ttf);
/// ```
pub fn initEmbeddedFont(allocator: std.mem.Allocator) !TtfFont {
return TtfFont.initFromMemory(allocator, adwaita_sans_data);
}
test "embedded font data is valid" {
const testing = std.testing;
// Verificar que hay datos
try testing.expect(adwaita_sans_data.len > 0);
// Verificar que parece un TTF válido (magic number)
// TTF/OTF comienza con 0x00010000 o 'OTTO' o 'true' o 'typ1'
try testing.expect(adwaita_sans_data.len >= 4);
// 0x00010000 = TrueType
const is_truetype = adwaita_sans_data[0] == 0x00 and
adwaita_sans_data[1] == 0x01 and
adwaita_sans_data[2] == 0x00 and
adwaita_sans_data[3] == 0x00;
// 'OTTO' = OpenType con CFF
const is_opentype = adwaita_sans_data[0] == 'O' and
adwaita_sans_data[1] == 'T' and
adwaita_sans_data[2] == 'T' and
adwaita_sans_data[3] == 'O';
try testing.expect(is_truetype or is_opentype);
}
test "embedded font can be loaded" {
const allocator = std.testing.allocator;
var ttf = try initEmbeddedFont(allocator);
defer ttf.deinit();
// Verificar que se puede usar
ttf.setSize(14);
// Verificar que tiene la tabla cmap
try std.testing.expect(ttf.cmap_offset > 0);
}

Binary file not shown.

View file

@ -388,6 +388,13 @@ pub const TtfFont = struct {
return self; return self;
} }
/// Initialize from embedded font (AdwaitaSans)
/// Convenience function for zero external dependencies
pub fn initEmbedded(allocator: Allocator) !Self {
const embedded = @import("embedded_font.zig");
return initFromMemory(allocator, embedded.adwaita_sans_data);
}
/// Deinitialize font /// Deinitialize font
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
// Free cached glyphs // Free cached glyphs

View file

@ -95,6 +95,7 @@ pub const render = struct {
pub const ttf = @import("render/ttf.zig"); pub const ttf = @import("render/ttf.zig");
pub const TtfFont = ttf.TtfFont; pub const TtfFont = ttf.TtfFont;
pub const FontRef = ttf.FontRef; pub const FontRef = ttf.FontRef;
pub const embedded_font = @import("render/embedded_font.zig");
pub const animation = @import("render/animation.zig"); pub const animation = @import("render/animation.zig");
pub const effects = @import("render/effects.zig"); pub const effects = @import("render/effects.zig");
pub const antialiasing = @import("render/antialiasing.zig"); pub const antialiasing = @import("render/antialiasing.zig");