diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-16 22:56:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | afc60e735274b0de5423ac375a9ea582f64b516f (patch) | |
| tree | 5cbf276d99f7963ec4cff4e73838b0679bfd8717 /src/gui/gui.zig | |
| parent | f2b02c455f2bcdfb905a015eefbb630a28b4b12e (diff) | |
| download | pardes-afc60e735274b0de5423ac375a9ea582f64b516f.tar.gz pardes-afc60e735274b0de5423ac375a9ea582f64b516f.zip | |
test: the GPU move's gates, before a line of the renderer moves: window.zig's frame corpus, run when PARDES_GUI_CORPUS names a directory (zig build process-test -Dplatform=gui -- 'window: its frame corpus', the snake addon's library in PARDES_GUI_CORPUS_SNAKE): the move's twelve scenes on the hidden window under the virtual clock, one input a step and then idle and idle again once a worker had time to land (a PDF page, a highlighted file), every frame of a motion (a wheel's glide, a click's caret, a jump's trail) and the one that stays of the rest, the snake's first ten in a window of its own (its picture breathes on the clock, and a long session's clock has seen the machine's timing), each kept as frame-NNNNN.ppm with its sha256 and its scene; a build against a build on one machine, never a golden; gui.zig: the atlas's bytes, a fixed key list (ASCII plain, bold, in the five underlines and struck, taglines, an underlined space, the eleven rules, centred grips, Nerd icons, ligature strips shaped as a frame shapes them) at 27 px and at 54 px at 2x, its stage and its sorted slots hashed to constants recorded now, the same on any machine (the repo's faces, the build's FreeType and HarfBuzz)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/gui/gui.zig')
| -rw-r--r-- | src/gui/gui.zig | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 51ec6bbf..a67602e8 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -9206,3 +9206,87 @@ fn prepareAddonGpu(g: *Gui, gpa: std.mem.Allocator, cmd: *c.SDL_GPUCommandBuffer } if (g.addon_gpu) |*gpu| gpu.endFrame(); } + +test "the atlas's bytes: a fixed key list at 27 px and at 54 px (2x) rasterizes to the recorded stage and slots" { + // The glyph atlas the frames sample, byte for byte and on any machine: + // FreeType and HarfBuzz are the build's, the faces the repo's (the + // embedded Adwaita Mono, assets/MapleMono-NF for ligatures and Nerd + // icons). CJK has no face of the repo's and no fallback of pardes's + // list: the frame corpus draws its .notdef. Recorded before the GPU + // move (.scratch/sketch/briefs/gpu-s0.md); a change here is a change + // to every frame. + const want = [2][2]u64{ .{ 0xa03053f14e2c5472, 0x9029886b638b07d5 }, .{ 0xcbaa53a0103aaff5, 0x7563d69768f7d867 } }; + const maple = try filesystem.readFile(std.testing.allocator, "assets/MapleMono-NF-Regular.ttf"); + defer std.testing.allocator.free(maple); + defer display_scale = 1; + var got: [2][2]u64 = undefined; + for ([_]f32{ 27, 54 }, [_]f32{ 1, 2 }, &got) |px, scale, *hashes| { + display_scale = scale; + var stage_hash = std.hash.Wyhash.init(0); + var slots_hash = std.hash.Wyhash.init(0); + // 0: Adwaita Mono, Maple its fallback; 1: Maple, whose ligatures shape. + for ([_][]const u8{ font_ttf, maple }) |primary| { + const font = c.ui_font_new(primary.ptr, @intCast(primary.len)) orelse return error.FontInit; + defer c.ui_font_free(font); + const fallback = c.ui_font_new(maple.ptr, @intCast(maple.len)) orelse return error.FontInit; + defer c.ui_font_free(fallback); + var g = try textTestGui(font, px); + defer font_allocator = std.heap.smp_allocator; + defer std.testing.allocator.free(g.atlas_stage); + defer g.glyphs.deinit(); + defer g.words.deinit(std.testing.allocator); + g.fallbacks[0] = .{ .face = fallback }; + g.fallback_count = 1; + try std.testing.expect(fitTaglineFont(&g, 80)); + const decorations = [_]GlyphDecoration{ + .{}, + .{ .bold = true }, + .{ .underline = .single }, + .{ .underline = .double }, + .{ .underline = .curly }, + .{ .underline = .dotted }, + .{ .underline = .dashed }, + .{ .strikethrough = true }, + }; + for (0x21..0x7f) |cp| { + const drawn = glyphForCodepoint(&g, @intCast(cp)); + for (decorations) |decoration| _ = cachedGlyph(&g, .{ .face = drawn.face, .glyph = drawn.glyph, .role = .body, .decoration = decoration }) orelse return error.AtlasFull; + for (decorations[0..2]) |decoration| _ = cachedGlyph(&g, .{ .face = drawn.face, .glyph = drawn.glyph, .role = .tagline, .decoration = decoration }) orelse return error.AtlasFull; + } + const space = glyphForCodepoint(&g, ' '); + _ = cachedGlyph(&g, .{ .face = space.face, .glyph = space.glyph, .role = .body, .decoration = .{ .underline = .single } }) orelse return error.AtlasFull; + for ([_]u32{ 0x2500, 0x2502, 0x250c, 0x2510, 0x2514, 0x2518, 0x251c, 0x2524, 0x252c, 0x2534, 0x253c }) |cp| for ([_]pardes.FontRole{ .body, .tagline }) |role| { + _ = cachedGlyph(&g, .{ .face = 0, .glyph = cp, .role = role, .rule = true }) orelse return error.AtlasFull; + }; + for ([_]u32{ '$', '^', 'j' }) |cp| for ([_]bool{ false, true }) |bold| { + const drawn = glyphForCodepoint(&g, cp); + _ = cachedGlyph(&g, .{ .face = drawn.face, .glyph = drawn.glyph, .role = .tagline, .decoration = .{ .bold = bold }, .centered = true }) orelse return error.AtlasFull; + }; + // Nerd icons (Yazi's folder, a file, powerline's arrow): Maple's, + // the primary's or the fallback's. + for ([_]u32{ 0xe5ff, 0xf07b, 0xe0b0 }) |cp| { + const drawn = glyphForCodepoint(&g, cp); + try std.testing.expect(drawn.glyph != 0); + _ = cachedGlyph(&g, .{ .face = drawn.face, .glyph = drawn.glyph, .role = .body }) orelse return error.AtlasFull; + } + // Ligature strips, shaped by the words' cache as a frame shapes them. + const line = textTestLine("a->b => != <= >= == === !== |> <| :: ++ -- www office"); + for (0..line.len) |i| _ = cellSlot(&g, &line, i, null, .body); + stage_hash.update(g.atlas_stage); + const Entry = struct { key: u64, u: u32, v: u32 }; + var entries: std.ArrayList(Entry) = .empty; + defer entries.deinit(std.testing.allocator); + var it = g.glyphs.iterator(); + while (it.next()) |e| try entries.append(std.testing.allocator, .{ .key = @bitCast(e.key_ptr.*), .u = e.value_ptr.u, .v = e.value_ptr.v }); + std.mem.sort(Entry, entries.items, {}, struct { + fn less(_: void, x: Entry, y: Entry) bool { + return x.key < y.key; + } + }.less); + for (entries.items) |e| slots_hash.update(std.mem.asBytes(&e)); + } + hashes.* = .{ stage_hash.final(), slots_hash.final() }; + } + if (!std.meta.eql(want, got)) std.debug.print("atlas hashes: .{{ .{{ 0x{x}, 0x{x} }}, .{{ 0x{x}, 0x{x} }} }}\n", .{ got[0][0], got[0][1], got[1][0], got[1][1] }); + try std.testing.expectEqual(want, got); +} |
