diff options
Diffstat (limited to 'test/text.zig')
| -rw-r--r-- | test/text.zig | 13 |
1 files changed, 10 insertions, 3 deletions
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; } } |
