mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-20 06:20:32 +00:00
font: freetype eliminate some duplicated work on init
This commit is contained in:
@@ -40,24 +40,17 @@ pub const Face = struct {
|
||||
pub fn initFile(lib: Library, path: [:0]const u8, index: i32, size: font.face.DesiredSize) !Face {
|
||||
const face = try lib.lib.initFace(path, index);
|
||||
errdefer face.deinit();
|
||||
try face.selectCharmap(.unicode);
|
||||
try setSize_(face, size);
|
||||
|
||||
const hb_font = try harfbuzz.freetype.createFont(face.handle);
|
||||
errdefer hb_font.destroy();
|
||||
|
||||
return Face{
|
||||
.face = face,
|
||||
.hb_font = hb_font,
|
||||
.presentation = if (face.hasColor()) .emoji else .text,
|
||||
.metrics = calcMetrics(face),
|
||||
};
|
||||
return try initFace(face, size);
|
||||
}
|
||||
|
||||
/// Initialize a new font face with the given source in-memory.
|
||||
pub fn init(lib: Library, source: [:0]const u8, size: font.face.DesiredSize) !Face {
|
||||
const face = try lib.lib.initMemoryFace(source, 0);
|
||||
errdefer face.deinit();
|
||||
return try initFace(face, size);
|
||||
}
|
||||
|
||||
fn initFace(face: freetype.Face, size: font.face.DesiredSize) !Face {
|
||||
try face.selectCharmap(.unicode);
|
||||
try setSize_(face, size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user