mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
Use em size as nerd font reference metric
This commit is contained in:
@ -531,7 +531,7 @@ pub fn add(
|
|||||||
const nf_symbols = b.dependency("nerd_fonts_symbols_only", .{});
|
const nf_symbols = b.dependency("nerd_fonts_symbols_only", .{});
|
||||||
step.root_module.addAnonymousImport(
|
step.root_module.addAnonymousImport(
|
||||||
"nerd_fonts_symbols_only",
|
"nerd_fonts_symbols_only",
|
||||||
.{ .root_source_file = nf_symbols.path("SymbolsNerdFontMono-Regular.ttf") },
|
.{ .root_source_file = nf_symbols.path("SymbolsNerdFont-Regular.ttf") },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,14 +299,17 @@ fn collection(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Nerd-font symbols fallback.
|
// 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(
|
_ = try c.add(
|
||||||
self.alloc,
|
self.alloc,
|
||||||
.regular,
|
.regular,
|
||||||
.init(.{ .fallback_loaded = try Face.init(
|
.initWithScaleReference(.{ .fallback_loaded = try .init(
|
||||||
self.font_lib,
|
self.font_lib,
|
||||||
font.embedded.symbols_nerd_font,
|
font.embedded.symbols_nerd_font,
|
||||||
load_options.faceOptions(),
|
load_options.faceOptions(),
|
||||||
) }),
|
) }, .em_size),
|
||||||
);
|
);
|
||||||
|
|
||||||
// On macOS, always search for and add the Apple Emoji font
|
// On macOS, always search for and add the Apple Emoji font
|
||||||
|
@ -222,7 +222,7 @@ pub const RenderOptions = struct {
|
|||||||
) GlyphSize {
|
) GlyphSize {
|
||||||
var g = glyph;
|
var g = glyph;
|
||||||
|
|
||||||
var available_width: f64 = @floatFromInt(
|
const available_width: f64 = @floatFromInt(
|
||||||
metrics.cell_width * @min(
|
metrics.cell_width * @min(
|
||||||
self.max_constraint_width,
|
self.max_constraint_width,
|
||||||
constraint_width,
|
constraint_width,
|
||||||
@ -233,22 +233,6 @@ pub const RenderOptions = struct {
|
|||||||
.icon => metrics.icon_height,
|
.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 -
|
const w = available_width -
|
||||||
self.pad_left * available_width -
|
self.pad_left * available_width -
|
||||||
self.pad_right * available_width;
|
self.pad_right * available_width;
|
||||||
@ -372,11 +356,6 @@ pub const RenderOptions = struct {
|
|||||||
.center => g.y = (h - g.height) / 2,
|
.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.
|
// Re-add our padding before returning.
|
||||||
g.x += self.pad_left * available_width;
|
g.x += self.pad_left * available_width;
|
||||||
g.y += self.pad_bottom * available_height;
|
g.y += self.pad_bottom * available_height;
|
||||||
|
Reference in New Issue
Block a user