font/underline: some additional type annotations

This commit is contained in:
Mitchell Hashimoto
2023-10-28 10:40:51 -07:00
parent 6d971de87a
commit a249e5973d
2 changed files with 5 additions and 6 deletions

View File

@ -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"));

View File

@ -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));