From a249e5973d367f48168078b5cb8c945fd6055555 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 28 Oct 2023 10:40:51 -0700 Subject: [PATCH] font/underline: some additional type annotations --- build.zig | 1 - src/font/sprite/underline.zig | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index 4b2c52712..cc914dca2 100644 --- a/build.zig +++ b/build.zig @@ -714,7 +714,6 @@ fn addDeps( step.addModule("freetype", freetype_dep.module("freetype")); step.addModule("harfbuzz", harfbuzz_dep.module("harfbuzz")); step.addModule("xev", libxev_dep.module("xev")); - step.addModule("zig-js", js_dep.module("zig-js")); step.addModule("pixman", pixman_dep.module("pixman")); step.addModule("utf8proc", utf8proc_dep.module("utf8proc")); diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index 0bb91a262..cadd8ce29 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -174,18 +174,18 @@ const Draw = struct { // Some fonts put the underline too close to the bottom of the // cell height and this doesn't allow us to make a high enough // wave. This constant is arbitrary, change it for aesthetics. - const pos = pos: { + const pos: u32 = pos: { const MIN_HEIGHT = 5; const clamped_pos = @min(y_max, self.pos); const height = y_max - clamped_pos; break :pos if (height < MIN_HEIGHT) clamped_pos -| MIN_HEIGHT else clamped_pos; }; - // The full heightof the wave can be from the bottom to the + // The full height of the wave can be from the bottom to the // underline position. We also calculate our starting y which is // slightly below our descender since our wave will move about that. - const wave_height = @as(f64, @floatFromInt(y_max - pos)); - const half_height = @max(1, wave_height / 4); + const wave_height: f64 = @floatFromInt(y_max - pos); + const half_height: f64 = @max(1, wave_height / 4); const y_pos = @as(i32, @intCast(pos)) + @as(i32, @intFromFloat(2 * half_height)); // follow Xiaolin Wu's antialias algorithm to draw the curve @@ -194,7 +194,7 @@ const Draw = struct { const y0 = half_height * @cos(@as(f64, @floatFromInt(x)) * x_factor); const y1 = y_pos + @as(i32, @intFromFloat(@floor(y0))); const y3 = y1 - 1 + @as(i32, @intCast(self.thickness)); - const alpha = @as(u8, @intFromFloat(255 * @abs(y0 - @floor(y0)))); + const alpha: u8 = @intFromFloat(255 * @abs(y0 - @floor(y0))); // upper and lower bounds canvas.pixel(x, @min(@as(u32, @intCast(y1)), y_max), @enumFromInt(255 - alpha));