mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
bold font rendering
This commit is contained in:
13
src/Grid.zig
13
src/Grid.zig
@ -106,6 +106,7 @@ pub fn init(alloc: Allocator) !Grid {
|
|||||||
var fam = try font.Family.init(atlas);
|
var fam = try font.Family.init(atlas);
|
||||||
errdefer fam.deinit(alloc);
|
errdefer fam.deinit(alloc);
|
||||||
try fam.loadFaceFromMemory(.regular, face_ttf, 32);
|
try fam.loadFaceFromMemory(.regular, face_ttf, 32);
|
||||||
|
try fam.loadFaceFromMemory(.bold, face_bold_ttf, 32);
|
||||||
|
|
||||||
// Load all visible ASCII characters and build our cell width based on
|
// Load all visible ASCII characters and build our cell width based on
|
||||||
// the widest character that we see.
|
// the widest character that we see.
|
||||||
@ -310,13 +311,19 @@ pub fn updateCells(self: *Grid, term: Terminal) !void {
|
|||||||
// If the cell is empty then we draw nothing in the box.
|
// If the cell is empty then we draw nothing in the box.
|
||||||
if (cell.empty()) continue;
|
if (cell.empty()) continue;
|
||||||
|
|
||||||
|
// Determine our glyph styling
|
||||||
|
const style: font.Style = if (cell.attrs.bold == 1)
|
||||||
|
.bold
|
||||||
|
else
|
||||||
|
.regular;
|
||||||
|
|
||||||
// Get our glyph
|
// Get our glyph
|
||||||
// TODO: if we add a glyph, I think we need to rerender the texture.
|
// TODO: if we add a glyph, I think we need to rerender the texture.
|
||||||
const glyph = if (self.font_atlas.getGlyph(cell.char, .regular)) |glyph|
|
const glyph = if (self.font_atlas.getGlyph(cell.char, style)) |glyph|
|
||||||
glyph
|
glyph
|
||||||
else glyph: {
|
else glyph: {
|
||||||
self.atlas_dirty = true;
|
self.atlas_dirty = true;
|
||||||
break :glyph try self.font_atlas.addGlyph(self.alloc, cell.char, .regular);
|
break :glyph try self.font_atlas.addGlyph(self.alloc, cell.char, style);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fg = cell.fg orelse self.foreground;
|
const fg = cell.fg orelse self.foreground;
|
||||||
@ -509,4 +516,4 @@ test "GridSize update rounding" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const face_ttf = @embedFile("../fonts/FiraCode-Regular.ttf");
|
const face_ttf = @embedFile("../fonts/FiraCode-Regular.ttf");
|
||||||
//const face_ttf = @embedFile("../fonts/Inconsolata-Regular.ttf");
|
const face_bold_ttf = @embedFile("../fonts/FiraCode-Bold.ttf");
|
||||||
|
@ -32,6 +32,7 @@ glyphs: std.AutoHashMapUnmanaged(GlyphKey, Glyph) = .{},
|
|||||||
/// The font faces representing all the styles in this family.
|
/// The font faces representing all the styles in this family.
|
||||||
/// These should be set directly or via various loader functions.
|
/// These should be set directly or via various loader functions.
|
||||||
regular: ?Face = null,
|
regular: ?Face = null,
|
||||||
|
bold: ?Face = null,
|
||||||
|
|
||||||
/// This struct is used for the hash key for glyphs.
|
/// This struct is used for the hash key for glyphs.
|
||||||
const GlyphKey = struct {
|
const GlyphKey = struct {
|
||||||
@ -55,6 +56,7 @@ pub fn deinit(self: *Family, alloc: Allocator) void {
|
|||||||
self.glyphs.deinit(alloc);
|
self.glyphs.deinit(alloc);
|
||||||
|
|
||||||
if (self.regular) |*face| face.deinit();
|
if (self.regular) |*face| face.deinit();
|
||||||
|
if (self.bold) |*face| face.deinit();
|
||||||
|
|
||||||
if (ftc.FT_Done_FreeType(self.ft_library) != ftok)
|
if (ftc.FT_Done_FreeType(self.ft_library) != ftok)
|
||||||
log.err("failed to clean up FreeType", .{});
|
log.err("failed to clean up FreeType", .{});
|
||||||
@ -77,7 +79,7 @@ pub fn loadFaceFromMemory(
|
|||||||
|
|
||||||
@field(self, switch (style) {
|
@field(self, switch (style) {
|
||||||
.regular => "regular",
|
.regular => "regular",
|
||||||
.bold => unreachable,
|
.bold => "bold",
|
||||||
.italic => unreachable,
|
.italic => unreachable,
|
||||||
.bold_italic => unreachable,
|
.bold_italic => unreachable,
|
||||||
}) = face;
|
}) = face;
|
||||||
@ -106,7 +108,7 @@ pub fn addGlyph(self: *Family, alloc: Allocator, v: anytype, style: Style) !*Gly
|
|||||||
// Real is the face we SHOULD use for this style.
|
// Real is the face we SHOULD use for this style.
|
||||||
var real = switch (style) {
|
var real = switch (style) {
|
||||||
.regular => self.regular,
|
.regular => self.regular,
|
||||||
.bold => unreachable,
|
.bold => self.bold,
|
||||||
.italic => unreachable,
|
.italic => unreachable,
|
||||||
.bold_italic => unreachable,
|
.bold_italic => unreachable,
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,7 @@ pub const Cell = struct {
|
|||||||
/// On/off attributes that can be set
|
/// On/off attributes that can be set
|
||||||
/// TODO: pack it
|
/// TODO: pack it
|
||||||
attrs: struct {
|
attrs: struct {
|
||||||
|
bold: u1 = 0,
|
||||||
inverse: u1 = 0,
|
inverse: u1 = 0,
|
||||||
} = .{},
|
} = .{},
|
||||||
|
|
||||||
|
@ -150,6 +150,10 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
|
|||||||
self.cursor.pen.attrs = .{};
|
self.cursor.pen.attrs = .{};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.bold => {
|
||||||
|
self.cursor.pen.attrs.bold = 1;
|
||||||
|
},
|
||||||
|
|
||||||
.inverse => {
|
.inverse => {
|
||||||
self.cursor.pen.attrs.inverse = 1;
|
self.cursor.pen.attrs.inverse = 1;
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user