mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-20 02:36:22 +03:00
font: CodepointMap supports clone
This commit is contained in:
@ -2965,11 +2965,7 @@ pub const RepeatableCodepointMap = struct {
|
||||
|
||||
/// Deep copy of the struct. Required by Config.
|
||||
pub fn clone(self: *const Self, alloc: Allocator) !Self {
|
||||
// TODO(fontmem): clone the codemap descriptors
|
||||
|
||||
return .{
|
||||
.map = .{ .list = try self.map.list.clone(alloc) },
|
||||
};
|
||||
return .{ .map = try self.map.clone(alloc) };
|
||||
}
|
||||
|
||||
/// Compare if two of our value are requal. Required by Config.
|
||||
|
@ -30,6 +30,18 @@ pub fn deinit(self: *CodepointMap, alloc: Allocator) void {
|
||||
self.list.deinit(alloc);
|
||||
}
|
||||
|
||||
/// Deep copy of the struct. The given allocator is expected to
|
||||
/// be an arena allocator of some sort since the struct itself
|
||||
/// doesn't support fine-grained deallocation of fields.
|
||||
pub fn clone(self: *const CodepointMap, alloc: Allocator) !CodepointMap {
|
||||
var list = try self.list.clone(alloc);
|
||||
for (list.items(.descriptor)) |*d| {
|
||||
d.* = try d.clone(alloc);
|
||||
}
|
||||
|
||||
return .{ .list = list };
|
||||
}
|
||||
|
||||
/// Add an entry to the map.
|
||||
///
|
||||
/// For conflicting codepoints, entries added later take priority over
|
||||
|
@ -86,6 +86,21 @@ pub const Descriptor = struct {
|
||||
return hasher.final();
|
||||
}
|
||||
|
||||
/// Deep copy of the struct. The given allocator is expected to
|
||||
/// be an arena allocator of some sort since the descriptor
|
||||
/// itself doesn't support fine-grained deallocation of fields.
|
||||
pub fn clone(self: *const Descriptor, alloc: Allocator) !Descriptor {
|
||||
// We can't do any errdefer cleanup in here. As documented we
|
||||
// expect the allocator to be an arena so any errors should be
|
||||
// cleaned up somewhere else.
|
||||
|
||||
var copy = self.*;
|
||||
copy.family = if (self.family) |src| try alloc.dupeZ(u8, src) else null;
|
||||
copy.style = if (self.style) |src| try alloc.dupeZ(u8, src) else null;
|
||||
copy.variations = try alloc.dupe(Variation, self.variations);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// Convert to Fontconfig pattern to use for lookup. The pattern does
|
||||
/// not have defaults filled/substituted (Fontconfig thing) so callers
|
||||
/// must still do this.
|
||||
|
Reference in New Issue
Block a user