font/sprite: align quadrants better with other glyphs
Use `xHalfs` and `yHalfs` so that the dimensions of each quadrant are appropriately aligned with block elements like the one half block, which could be 1px taller than the bottom quadrants before this change. This is in line with what we do for sextants, the fact that on odd-sized cells there's a 1px overlap is considered acceptable there so I assume it's acceptable here too.pull/7755/head
parent
0414e9e281
commit
b4d83e6349
|
|
@ -15,6 +15,8 @@ const common = @import("common.zig");
|
||||||
const Shade = common.Shade;
|
const Shade = common.Shade;
|
||||||
const Quads = common.Quads;
|
const Quads = common.Quads;
|
||||||
const Alignment = common.Alignment;
|
const Alignment = common.Alignment;
|
||||||
|
const xHalfs = common.xHalfs;
|
||||||
|
const yHalfs = common.yHalfs;
|
||||||
const rect = common.rect;
|
const rect = common.rect;
|
||||||
|
|
||||||
const font = @import("../../main.zig");
|
const font = @import("../../main.zig");
|
||||||
|
|
@ -174,11 +176,11 @@ fn quadrant(
|
||||||
canvas: *font.sprite.Canvas,
|
canvas: *font.sprite.Canvas,
|
||||||
comptime quads: Quads,
|
comptime quads: Quads,
|
||||||
) void {
|
) void {
|
||||||
const center_x = metrics.cell_width / 2 + metrics.cell_width % 2;
|
const x_halfs = xHalfs(metrics);
|
||||||
const center_y = metrics.cell_height / 2 + metrics.cell_height % 2;
|
const y_halfs = yHalfs(metrics);
|
||||||
|
|
||||||
if (quads.tl) rect(metrics, canvas, 0, 0, center_x, center_y);
|
if (quads.tl) rect(metrics, canvas, 0, 0, x_halfs[0], y_halfs[0]);
|
||||||
if (quads.tr) rect(metrics, canvas, center_x, 0, metrics.cell_width, center_y);
|
if (quads.tr) rect(metrics, canvas, x_halfs[1], 0, metrics.cell_width, y_halfs[0]);
|
||||||
if (quads.bl) rect(metrics, canvas, 0, center_y, center_x, metrics.cell_height);
|
if (quads.bl) rect(metrics, canvas, 0, y_halfs[1], x_halfs[0], metrics.cell_height);
|
||||||
if (quads.br) rect(metrics, canvas, center_x, center_y, metrics.cell_width, metrics.cell_height);
|
if (quads.br) rect(metrics, canvas, x_halfs[1], y_halfs[1], metrics.cell_width, metrics.cell_height);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,14 @@ pub fn xHalfs(metrics: font.Metrics) [2]u32 {
|
||||||
return .{ half_width, metrics.cell_width - half_width };
|
return .{ half_width, metrics.cell_width - half_width };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// yHalfs[0] should be used as the bottom edge of a top-aligned half.
|
||||||
|
/// yHalfs[1] should be used as the top edge of a bottom-aligned half.
|
||||||
|
pub fn yHalfs(metrics: font.Metrics) [2]u32 {
|
||||||
|
const float_height: f64 = @floatFromInt(metrics.cell_height);
|
||||||
|
const half_height: u32 = @intFromFloat(@round(0.5 * float_height));
|
||||||
|
return .{ half_height, metrics.cell_height - half_height };
|
||||||
|
}
|
||||||
|
|
||||||
/// Use these values as such:
|
/// Use these values as such:
|
||||||
/// yThirds[0] bottom edge of the first third.
|
/// yThirds[0] bottom edge of the first third.
|
||||||
/// yThirds[1] top edge of the second third.
|
/// yThirds[1] top edge of the second third.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue