test(ttf): Añadir tests con AdwaitaSans real

- Test carga fuente del sistema
- Verificar parsing de contornos para 'A'
- Verificar rasterización produce bitmap con datos
- Test múltiples caracteres (AaBb0123)
- Tests skip gracefully si fuente no disponible

🤖 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 00:42:51 +01:00
parent 69745ba857
commit f2900d9dc2

View file

@ -1062,3 +1062,83 @@ test "readU32Big" {
const data = [_]u8{ 0x12, 0x34, 0x56, 0x78 }; const data = [_]u8{ 0x12, 0x34, 0x56, 0x78 };
try std.testing.expectEqual(@as(u32, 0x12345678), readU32Big(&data, 0)); try std.testing.expectEqual(@as(u32, 0x12345678), readU32Big(&data, 0));
} }
test "TTF load and rasterize AdwaitaSans" {
const allocator = std.testing.allocator;
// Try to load AdwaitaSans from system
var font = TtfFont.loadFromFile(allocator, "/usr/share/fonts/adwaita-sans-fonts/AdwaitaSans-Regular.ttf") catch {
// Font not available on this system, skip test
return;
};
defer font.deinit();
// Verify font was parsed correctly
try std.testing.expect(font.num_glyphs > 0);
try std.testing.expect(font.metrics.units_per_em > 0);
// Get glyph index for 'A'
const glyph_index = font.getGlyphIndex('A');
try std.testing.expect(glyph_index > 0);
// Get glyph outline
if (font.getGlyphOutline(glyph_index)) |outline| {
var outline_mut = outline;
defer outline_mut.deinit();
// 'A' should have contours (typically 2: outer and inner)
try std.testing.expect(outline.contours.len > 0);
// Rasterize
font.setSize(24);
if (rasterizeGlyph(allocator, outline, font.scale, 2)) |bitmap| {
var bitmap_mut = bitmap;
defer bitmap_mut.deinit();
// Should produce a bitmap with non-zero dimensions
try std.testing.expect(bitmap.width > 0);
try std.testing.expect(bitmap.height > 0);
// Should have some non-zero alpha values (actual glyph data)
var has_content = false;
for (bitmap.data) |alpha| {
if (alpha > 0) {
has_content = true;
break;
}
}
try std.testing.expect(has_content);
}
}
}
test "TTF rasterize multiple characters" {
const allocator = std.testing.allocator;
var font = TtfFont.loadFromFile(allocator, "/usr/share/fonts/adwaita-sans-fonts/AdwaitaSans-Regular.ttf") catch {
return; // Skip if font not available
};
defer font.deinit();
font.setSize(16);
// Test several characters
const test_chars = "AaBb0123";
for (test_chars) |c| {
const glyph_index = font.getGlyphIndex(c);
if (glyph_index == 0) continue;
if (font.getGlyphOutline(glyph_index)) |outline| {
var outline_mut = outline;
defer outline_mut.deinit();
if (rasterizeGlyph(allocator, outline, font.scale, 2)) |bitmap| {
var bitmap_mut = bitmap;
defer bitmap_mut.deinit();
try std.testing.expect(bitmap.width > 0);
try std.testing.expect(bitmap.height > 0);
}
}
}
}