Use em size as nerd font reference metric

This commit is contained in:
Daniel Wennberg
2025-07-15 13:04:51 -07:00
parent e7d28a85c8
commit ce507f35df
3 changed files with 7 additions and 25 deletions

View File

@ -531,7 +531,7 @@ pub fn add(
const nf_symbols = b.dependency("nerd_fonts_symbols_only", .{});
step.root_module.addAnonymousImport(
"nerd_fonts_symbols_only",
.{ .root_source_file = nf_symbols.path("SymbolsNerdFontMono-Regular.ttf") },
.{ .root_source_file = nf_symbols.path("SymbolsNerdFont-Regular.ttf") },
);
}

View File

@ -299,14 +299,17 @@ fn collection(
);
// Nerd-font symbols fallback.
// For proper icon scaling, this should be loaded at the same point
// size as the primary font and not undergo size normalization,
// hence we use the em size as scale reference.
_ = try c.add(
self.alloc,
.regular,
.init(.{ .fallback_loaded = try Face.init(
.initWithScaleReference(.{ .fallback_loaded = try .init(
self.font_lib,
font.embedded.symbols_nerd_font,
load_options.faceOptions(),
) }),
) }, .em_size),
);
// On macOS, always search for and add the Apple Emoji font

View File

@ -222,7 +222,7 @@ pub const RenderOptions = struct {
) GlyphSize {
var g = glyph;
var available_width: f64 = @floatFromInt(
const available_width: f64 = @floatFromInt(
metrics.cell_width * @min(
self.max_constraint_width,
constraint_width,
@ -233,22 +233,6 @@ pub const RenderOptions = struct {
.icon => metrics.icon_height,
});
// We make the opinionated choice here to reduce the width
// of icon-height symbols by the same amount horizontally,
// since otherwise wide aspect ratio icons like folders end
// up far too wide.
//
// But we *only* do this if the constraint width is 2, since
// otherwise it would make them way too small when sized for
// a single cell.
const is_icon_width = self.height == .icon and @min(self.max_constraint_width, constraint_width) > 1;
const orig_avail_width = available_width;
if (is_icon_width) {
const cell_height: f64 = @floatFromInt(metrics.cell_height);
const ratio = available_height / cell_height;
available_width *= ratio;
}
const w = available_width -
self.pad_left * available_width -
self.pad_right * available_width;
@ -372,11 +356,6 @@ pub const RenderOptions = struct {
.center => g.y = (h - g.height) / 2,
}
// Add offset for icon width restriction, to keep it centered.
if (is_icon_width) {
g.x += (orig_avail_width - available_width) / 2;
}
// Re-add our padding before returning.
g.x += self.pad_left * available_width;
g.y += self.pad_bottom * available_height;