From f2900d9dc2a0ebc9dcc65aa73930374b48d95074 Mon Sep 17 00:00:00 2001 From: reugenio Date: Tue, 16 Dec 2025 00:42:51 +0100 Subject: [PATCH] =?UTF-8?q?test(ttf):=20A=C3=B1adir=20tests=20con=20Adwait?= =?UTF-8?q?aSans=20real?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/render/ttf.zig | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/render/ttf.zig b/src/render/ttf.zig index 5d22c81..58b9163 100644 --- a/src/render/ttf.zig +++ b/src/render/ttf.zig @@ -1062,3 +1062,83 @@ test "readU32Big" { const data = [_]u8{ 0x12, 0x34, 0x56, 0x78 }; 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); + } + } + } +}