diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 12:53:22 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-12 13:22:02 -0300 |
| commit | 45f705a5e590c3dfddc0a544e66beb9bf6205a4d (patch) | |
| tree | c98d19a1b2dfc4808a46b41cf1b931703ff467b1 /test | |
| parent | f8d3a32f4f995eeb7e162b0702998b0565c11e4e (diff) | |
| download | sketchbook-45f705a5e590c3dfddc0a544e66beb9bf6205a4d.tar.gz sketchbook-45f705a5e590c3dfddc0a544e66beb9bf6205a4d.zip | |
sketchbook: text rasterized at one scale and drawn at another (f.textScaled), steady under a moving camera
Diffstat (limited to 'test')
| -rw-r--r-- | test/text.script | 4 | ||||
| -rw-r--r-- | test/text.zig | 13 |
2 files changed, 14 insertions, 3 deletions
diff --git a/test/text.script b/test/text.script index 4381f94..c27df2a 100644 --- a/test/text.script +++ b/test/text.script @@ -11,3 +11,7 @@ expect-pixel .zig-cache/text/native.png 66 198 32 64 96 255 expect-pixel .zig-cache/text/native.png 80 185 16 16 16 255 expect-pixel .zig-cache/text/native.png 168 236 32 64 96 255 expect-pixel .zig-cache/text/native.png 180 222 16 16 16 255 +# Rasterized at scale 3 and drawn at 1.5, ten digits cover 115 px (half +# of scale 3's 230), not the 120 that scale 1.5 would shape. +expect-pixel .zig-cache/text/native.png 123 265 32 64 96 255 +expect-pixel .zig-cache/text/native.png 127 256 16 16 16 255 diff --git a/test/text.zig b/test/text.zig index e47e788..74bbaed 100644 --- a/test/text.zig +++ b/test/text.zig @@ -5,7 +5,7 @@ const sk = @import("sketch"); pub const width = 640; pub const height = 360; -const lines = [_]struct { scale: f32, text: []const u8, face: sk.Face = .mono }{ +const lines = [_]struct { scale: f32, text: []const u8, face: sk.Face = .mono, raster: f32 = 0 }{ .{ .scale = 1, .text = "0123456789" }, .{ .scale = 1.5, .text = "mov rax, [rbp-0x18] ; 1.5" }, .{ .scale = 2.25, .text = "0x7ffed849acf0 i -> W" }, @@ -13,6 +13,9 @@ const lines = [_]struct { scale: f32, text: []const u8, face: sk.Face = .mono }{ // The other faces: the sans is proportional, the bold mono is not. .{ .scale = 2, .text = "iiiiiiiiii", .face = .sans }, .{ .scale = 2, .text = "iiiiiiiiii", .face = .mono_bold }, + // Rasterized at 3 and drawn at 1.5: half of what scale 3 covers (115 px + // for ten digits), not what scale 1.5 would shape (120). + .{ .scale = 1.5, .text = "0123456789", .raster = 3 }, }; pub fn draw(f: *sk.Frame) void { @@ -21,9 +24,13 @@ pub fn draw(f: *sk.Frame) void { const k = f.in.window_height / height; var y: f32 = 10 * k; for (lines) |line| { - const size = f.host.textSizeIn(line.face, line.scale * k, line.text); + var size = f.host.textSizeIn(line.face, line.scale * k, line.text); + if (line.raster > 0) { + const at = f.host.textSizeIn(line.face, line.raster * k, line.text); + size = .{ at[0] * line.scale / line.raster, at[1] * line.scale / line.raster }; + } f.fill(sk.Rect{ .x = 10 * k, .y = y, .w = size[0], .h = size[1] }, 0x204060); - f.textIn(line.face, 10 * k, y, line.scale * k, line.text, 0xffffff); + if (line.raster > 0) f.textScaled(line.face, 10 * k, y, line.scale * k, line.raster * k, line.text, 0xffffff) else f.textIn(line.face, 10 * k, y, line.scale * k, line.text, 0xffffff); y += size[1] + 6 * k; } } |
