mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
Merge pull request #1713 from BvngeeCord/main
sprites: dont thicken via font-thicken, add cursor thickness adjustment
This commit is contained in:
@ -184,6 +184,7 @@ const c = @cImport({
|
|||||||
@"adjust-underline-thickness": ?MetricModifier = null,
|
@"adjust-underline-thickness": ?MetricModifier = null,
|
||||||
@"adjust-strikethrough-position": ?MetricModifier = null,
|
@"adjust-strikethrough-position": ?MetricModifier = null,
|
||||||
@"adjust-strikethrough-thickness": ?MetricModifier = null,
|
@"adjust-strikethrough-thickness": ?MetricModifier = null,
|
||||||
|
@"adjust-cursor-thickness": ?MetricModifier = null,
|
||||||
|
|
||||||
/// The method to use for calculating the cell width of a grapheme cluster.
|
/// The method to use for calculating the cell width of a grapheme cluster.
|
||||||
/// The default value is `unicode` which uses the Unicode standard to determine
|
/// The default value is `unicode` which uses the Unicode standard to determine
|
||||||
|
@ -73,7 +73,6 @@ lock: std.Thread.RwLock,
|
|||||||
pub fn init(
|
pub fn init(
|
||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
resolver: CodepointResolver,
|
resolver: CodepointResolver,
|
||||||
thicken: bool,
|
|
||||||
) !SharedGrid {
|
) !SharedGrid {
|
||||||
// We need to support loading options since we use the size data
|
// We need to support loading options since we use the size data
|
||||||
assert(resolver.collection.load_options != null);
|
assert(resolver.collection.load_options != null);
|
||||||
@ -97,7 +96,7 @@ pub fn init(
|
|||||||
try result.glyphs.ensureTotalCapacity(alloc, 128);
|
try result.glyphs.ensureTotalCapacity(alloc, 128);
|
||||||
|
|
||||||
// Initialize our metrics.
|
// Initialize our metrics.
|
||||||
try result.reloadMetrics(thicken);
|
try result.reloadMetrics();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -111,7 +110,7 @@ pub fn deinit(self: *SharedGrid, alloc: Allocator) void {
|
|||||||
self.resolver.deinit(alloc);
|
self.resolver.deinit(alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reloadMetrics(self: *SharedGrid, thicken: bool) !void {
|
fn reloadMetrics(self: *SharedGrid) !void {
|
||||||
// Get our cell metrics based on a regular font ascii 'M'. Why 'M'?
|
// Get our cell metrics based on a regular font ascii 'M'. Why 'M'?
|
||||||
// Doesn't matter, any normal ASCII will do we're just trying to make
|
// Doesn't matter, any normal ASCII will do we're just trying to make
|
||||||
// sure we use the regular font.
|
// sure we use the regular font.
|
||||||
@ -126,8 +125,7 @@ fn reloadMetrics(self: *SharedGrid, thicken: bool) !void {
|
|||||||
self.resolver.sprite = .{
|
self.resolver.sprite = .{
|
||||||
.width = self.metrics.cell_width,
|
.width = self.metrics.cell_width,
|
||||||
.height = self.metrics.cell_height,
|
.height = self.metrics.cell_height,
|
||||||
.thickness = self.metrics.underline_thickness *
|
.thickness = self.metrics.underline_thickness,
|
||||||
@as(u32, if (thicken) 2 else 1),
|
|
||||||
.underline_position = self.metrics.underline_position,
|
.underline_position = self.metrics.underline_position,
|
||||||
.strikethrough_position = self.metrics.strikethrough_position,
|
.strikethrough_position = self.metrics.strikethrough_position,
|
||||||
};
|
};
|
||||||
@ -326,7 +324,7 @@ fn testGrid(mode: TestMode, alloc: Allocator, lib: Library) !SharedGrid {
|
|||||||
var r: CodepointResolver = .{ .collection = c };
|
var r: CodepointResolver = .{ .collection = c };
|
||||||
errdefer r.deinit(alloc);
|
errdefer r.deinit(alloc);
|
||||||
|
|
||||||
return try init(alloc, r, false);
|
return try init(alloc, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
test getIndex {
|
test getIndex {
|
||||||
|
@ -144,7 +144,7 @@ pub fn ref(
|
|||||||
.discover = try self.discover(),
|
.discover = try self.discover(),
|
||||||
.codepoint_map = key.codepoint_map,
|
.codepoint_map = key.codepoint_map,
|
||||||
};
|
};
|
||||||
}, config.@"font-thicken");
|
});
|
||||||
errdefer grid.deinit(self.alloc);
|
errdefer grid.deinit(self.alloc);
|
||||||
|
|
||||||
return .{ gop.key_ptr.*, gop.value_ptr.grid };
|
return .{ gop.key_ptr.*, gop.value_ptr.grid };
|
||||||
@ -358,7 +358,6 @@ pub const DerivedConfig = struct {
|
|||||||
@"font-variation-italic": configpkg.RepeatableFontVariation,
|
@"font-variation-italic": configpkg.RepeatableFontVariation,
|
||||||
@"font-variation-bold-italic": configpkg.RepeatableFontVariation,
|
@"font-variation-bold-italic": configpkg.RepeatableFontVariation,
|
||||||
@"font-codepoint-map": configpkg.RepeatableCodepointMap,
|
@"font-codepoint-map": configpkg.RepeatableCodepointMap,
|
||||||
@"font-thicken": bool,
|
|
||||||
@"adjust-cell-width": ?Metrics.Modifier,
|
@"adjust-cell-width": ?Metrics.Modifier,
|
||||||
@"adjust-cell-height": ?Metrics.Modifier,
|
@"adjust-cell-height": ?Metrics.Modifier,
|
||||||
@"adjust-font-baseline": ?Metrics.Modifier,
|
@"adjust-font-baseline": ?Metrics.Modifier,
|
||||||
@ -366,6 +365,7 @@ pub const DerivedConfig = struct {
|
|||||||
@"adjust-underline-thickness": ?Metrics.Modifier,
|
@"adjust-underline-thickness": ?Metrics.Modifier,
|
||||||
@"adjust-strikethrough-position": ?Metrics.Modifier,
|
@"adjust-strikethrough-position": ?Metrics.Modifier,
|
||||||
@"adjust-strikethrough-thickness": ?Metrics.Modifier,
|
@"adjust-strikethrough-thickness": ?Metrics.Modifier,
|
||||||
|
@"adjust-cursor-thickness": ?Metrics.Modifier,
|
||||||
|
|
||||||
/// Initialize a DerivedConfig. The config should be either a
|
/// Initialize a DerivedConfig. The config should be either a
|
||||||
/// config.Config or another DerivedConfig to clone from.
|
/// config.Config or another DerivedConfig to clone from.
|
||||||
@ -388,7 +388,6 @@ pub const DerivedConfig = struct {
|
|||||||
.@"font-variation-italic" = try config.@"font-variation-italic".clone(alloc),
|
.@"font-variation-italic" = try config.@"font-variation-italic".clone(alloc),
|
||||||
.@"font-variation-bold-italic" = try config.@"font-variation-bold-italic".clone(alloc),
|
.@"font-variation-bold-italic" = try config.@"font-variation-bold-italic".clone(alloc),
|
||||||
.@"font-codepoint-map" = try config.@"font-codepoint-map".clone(alloc),
|
.@"font-codepoint-map" = try config.@"font-codepoint-map".clone(alloc),
|
||||||
.@"font-thicken" = config.@"font-thicken",
|
|
||||||
.@"adjust-cell-width" = config.@"adjust-cell-width",
|
.@"adjust-cell-width" = config.@"adjust-cell-width",
|
||||||
.@"adjust-cell-height" = config.@"adjust-cell-height",
|
.@"adjust-cell-height" = config.@"adjust-cell-height",
|
||||||
.@"adjust-font-baseline" = config.@"adjust-font-baseline",
|
.@"adjust-font-baseline" = config.@"adjust-font-baseline",
|
||||||
@ -396,6 +395,7 @@ pub const DerivedConfig = struct {
|
|||||||
.@"adjust-underline-thickness" = config.@"adjust-underline-thickness",
|
.@"adjust-underline-thickness" = config.@"adjust-underline-thickness",
|
||||||
.@"adjust-strikethrough-position" = config.@"adjust-strikethrough-position",
|
.@"adjust-strikethrough-position" = config.@"adjust-strikethrough-position",
|
||||||
.@"adjust-strikethrough-thickness" = config.@"adjust-strikethrough-thickness",
|
.@"adjust-strikethrough-thickness" = config.@"adjust-strikethrough-thickness",
|
||||||
|
.@"adjust-cursor-thickness" = config.@"adjust-cursor-thickness",
|
||||||
|
|
||||||
// This must be last so the arena contains all our allocations
|
// This must be last so the arena contains all our allocations
|
||||||
// from above since Zig does assignment in order.
|
// from above since Zig does assignment in order.
|
||||||
@ -532,6 +532,7 @@ pub const Key = struct {
|
|||||||
if (config.@"adjust-underline-thickness") |m| try set.put(alloc, .underline_thickness, m);
|
if (config.@"adjust-underline-thickness") |m| try set.put(alloc, .underline_thickness, m);
|
||||||
if (config.@"adjust-strikethrough-position") |m| try set.put(alloc, .strikethrough_position, m);
|
if (config.@"adjust-strikethrough-position") |m| try set.put(alloc, .strikethrough_position, m);
|
||||||
if (config.@"adjust-strikethrough-thickness") |m| try set.put(alloc, .strikethrough_thickness, m);
|
if (config.@"adjust-strikethrough-thickness") |m| try set.put(alloc, .strikethrough_thickness, m);
|
||||||
|
if (config.@"adjust-cursor-thickness") |m| try set.put(alloc, .cursor_thickness, m);
|
||||||
break :set set;
|
break :set set;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,6 +21,10 @@ underline_thickness: u32,
|
|||||||
strikethrough_position: u32,
|
strikethrough_position: u32,
|
||||||
strikethrough_thickness: u32,
|
strikethrough_thickness: u32,
|
||||||
|
|
||||||
|
/// The thickness in pixels of the cursor sprite. This has a default value
|
||||||
|
/// because it is not determined by fonts but rather by user configuration.
|
||||||
|
cursor_thickness: u32 = 1,
|
||||||
|
|
||||||
/// Original cell width and height. These are used to render the cursor
|
/// Original cell width and height. These are used to render the cursor
|
||||||
/// in the original cell size after modification.
|
/// in the original cell size after modification.
|
||||||
original_cell_width: ?u32 = null,
|
original_cell_width: ?u32 = null,
|
||||||
|
@ -1544,7 +1544,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
|||||||
|
|
||||||
const grid_ptr = try alloc.create(SharedGrid);
|
const grid_ptr = try alloc.create(SharedGrid);
|
||||||
errdefer alloc.destroy(grid_ptr);
|
errdefer alloc.destroy(grid_ptr);
|
||||||
grid_ptr.* = try SharedGrid.init(alloc, .{ .collection = c }, false);
|
grid_ptr.* = try SharedGrid.init(alloc, .{ .collection = c });
|
||||||
errdefer grid_ptr.*.deinit(alloc);
|
errdefer grid_ptr.*.deinit(alloc);
|
||||||
|
|
||||||
var shaper = try Shaper.init(alloc, .{});
|
var shaper = try Shaper.init(alloc, .{});
|
||||||
|
@ -1242,7 +1242,7 @@ fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
|
|||||||
|
|
||||||
const grid_ptr = try alloc.create(SharedGrid);
|
const grid_ptr = try alloc.create(SharedGrid);
|
||||||
errdefer alloc.destroy(grid_ptr);
|
errdefer alloc.destroy(grid_ptr);
|
||||||
grid_ptr.* = try SharedGrid.init(alloc, .{ .collection = c }, false);
|
grid_ptr.* = try SharedGrid.init(alloc, .{ .collection = c });
|
||||||
errdefer grid_ptr.*.deinit(alloc);
|
errdefer grid_ptr.*.deinit(alloc);
|
||||||
|
|
||||||
var shaper = try Shaper.init(alloc, .{});
|
var shaper = try Shaper.init(alloc, .{});
|
||||||
|
@ -74,12 +74,20 @@ pub fn renderGlyph(
|
|||||||
// Safe to ".?" because of the above assertion.
|
// Safe to ".?" because of the above assertion.
|
||||||
return switch (Kind.init(cp).?) {
|
return switch (Kind.init(cp).?) {
|
||||||
.box => box: {
|
.box => box: {
|
||||||
|
const thickness = switch (cp) {
|
||||||
|
@intFromEnum(Sprite.cursor_rect),
|
||||||
|
@intFromEnum(Sprite.cursor_hollow_rect),
|
||||||
|
@intFromEnum(Sprite.cursor_bar),
|
||||||
|
=> if (opts.grid_metrics) |m| m.cursor_thickness else self.thickness,
|
||||||
|
else => self.thickness,
|
||||||
|
};
|
||||||
|
|
||||||
const f: Box, const y_offset: u32 = face: {
|
const f: Box, const y_offset: u32 = face: {
|
||||||
// Expected, usual values.
|
// Expected, usual values.
|
||||||
var f: Box = .{
|
var f: Box = .{
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = self.height,
|
.height = self.height,
|
||||||
.thickness = self.thickness,
|
.thickness = thickness,
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the codepoint is unadjusted then we want to adjust
|
// If the codepoint is unadjusted then we want to adjust
|
||||||
|
Reference in New Issue
Block a user