mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
refactor(font): move Metrics
out of face
in preparation to move ownership of metrics from faces to collections
This commit is contained in:
@ -32,7 +32,7 @@ const url = @import("url.zig");
|
|||||||
const Key = @import("key.zig").Key;
|
const Key = @import("key.zig").Key;
|
||||||
const KeyValue = @import("key.zig").Value;
|
const KeyValue = @import("key.zig").Value;
|
||||||
const ErrorList = @import("ErrorList.zig");
|
const ErrorList = @import("ErrorList.zig");
|
||||||
const MetricModifier = fontpkg.face.Metrics.Modifier;
|
const MetricModifier = fontpkg.Metrics.Modifier;
|
||||||
const help_strings = @import("help_strings");
|
const help_strings = @import("help_strings");
|
||||||
|
|
||||||
const log = std.log.scoped(.config);
|
const log = std.log.scoped(.config);
|
||||||
|
@ -25,7 +25,7 @@ const DeferredFace = font.DeferredFace;
|
|||||||
const DesiredSize = font.face.DesiredSize;
|
const DesiredSize = font.face.DesiredSize;
|
||||||
const Face = font.Face;
|
const Face = font.Face;
|
||||||
const Library = font.Library;
|
const Library = font.Library;
|
||||||
const Metrics = font.face.Metrics;
|
const Metrics = font.Metrics;
|
||||||
const Presentation = font.Presentation;
|
const Presentation = font.Presentation;
|
||||||
const Style = font.Style;
|
const Style = font.Style;
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ pub const Modifier = union(enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "formatConfig percent" {
|
test "formatConfig percent" {
|
||||||
const configpkg = @import("../../config.zig");
|
const configpkg = @import("../config.zig");
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
var buf = std.ArrayList(u8).init(testing.allocator);
|
var buf = std.ArrayList(u8).init(testing.allocator);
|
||||||
defer buf.deinit();
|
defer buf.deinit();
|
||||||
@ -366,7 +366,7 @@ pub const Modifier = union(enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "formatConfig absolute" {
|
test "formatConfig absolute" {
|
||||||
const configpkg = @import("../../config.zig");
|
const configpkg = @import("../config.zig");
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
var buf = std.ArrayList(u8).init(testing.allocator);
|
var buf = std.ArrayList(u8).init(testing.allocator);
|
||||||
defer buf.deinit();
|
defer buf.deinit();
|
@ -29,7 +29,7 @@ const Collection = font.Collection;
|
|||||||
const Face = font.Face;
|
const Face = font.Face;
|
||||||
const Glyph = font.Glyph;
|
const Glyph = font.Glyph;
|
||||||
const Library = font.Library;
|
const Library = font.Library;
|
||||||
const Metrics = font.face.Metrics;
|
const Metrics = font.Metrics;
|
||||||
const Presentation = font.Presentation;
|
const Presentation = font.Presentation;
|
||||||
const Style = font.Style;
|
const Style = font.Style;
|
||||||
const RenderOptions = font.face.RenderOptions;
|
const RenderOptions = font.face.RenderOptions;
|
||||||
|
@ -20,7 +20,7 @@ const Collection = font.Collection;
|
|||||||
const Discover = font.Discover;
|
const Discover = font.Discover;
|
||||||
const Style = font.Style;
|
const Style = font.Style;
|
||||||
const Library = font.Library;
|
const Library = font.Library;
|
||||||
const Metrics = font.face.Metrics;
|
const Metrics = font.Metrics;
|
||||||
const CodepointMap = font.CodepointMap;
|
const CodepointMap = font.CodepointMap;
|
||||||
const DesiredSize = font.face.DesiredSize;
|
const DesiredSize = font.face.DesiredSize;
|
||||||
const Face = font.Face;
|
const Face = font.Face;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const options = @import("main.zig").options;
|
const options = @import("main.zig").options;
|
||||||
pub const Metrics = @import("face/Metrics.zig");
|
const Metrics = @import("main.zig").Metrics;
|
||||||
const config = @import("../config.zig");
|
const config = @import("../config.zig");
|
||||||
const freetype = @import("face/freetype.zig");
|
const freetype = @import("face/freetype.zig");
|
||||||
const coretext = @import("face/coretext.zig");
|
const coretext = @import("face/coretext.zig");
|
||||||
|
@ -19,7 +19,7 @@ pub const Face = struct {
|
|||||||
hb_font: if (harfbuzz_shaper) harfbuzz.Font else void,
|
hb_font: if (harfbuzz_shaper) harfbuzz.Font else void,
|
||||||
|
|
||||||
/// Metrics for this font face. These are useful for renderers.
|
/// Metrics for this font face. These are useful for renderers.
|
||||||
metrics: font.face.Metrics,
|
metrics: font.Metrics,
|
||||||
|
|
||||||
/// Set quirks.disableDefaultFontFeatures
|
/// Set quirks.disableDefaultFontFeatures
|
||||||
quirks_disable_default_font_features: bool = false,
|
quirks_disable_default_font_features: bool = false,
|
||||||
@ -513,7 +513,7 @@ pub const Face = struct {
|
|||||||
InvalidHheaTable,
|
InvalidHheaTable,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn calcMetrics(ct_font: *macos.text.Font) CalcMetricsError!font.face.Metrics {
|
pub fn calcMetrics(ct_font: *macos.text.Font) CalcMetricsError!font.Metrics {
|
||||||
// Read the 'head' table out of the font data.
|
// Read the 'head' table out of the font data.
|
||||||
const head: opentype.Head = head: {
|
const head: opentype.Head = head: {
|
||||||
// macOS bitmap-only fonts use a 'bhed' tag rather than 'head', but
|
// macOS bitmap-only fonts use a 'bhed' tag rather than 'head', but
|
||||||
@ -731,7 +731,7 @@ pub const Face = struct {
|
|||||||
break :cell_width max;
|
break :cell_width max;
|
||||||
};
|
};
|
||||||
|
|
||||||
return font.face.Metrics.calc(.{
|
return font.Metrics.calc(.{
|
||||||
.cell_width = cell_width,
|
.cell_width = cell_width,
|
||||||
.ascent = ascent,
|
.ascent = ascent,
|
||||||
.descent = descent,
|
.descent = descent,
|
||||||
@ -1032,7 +1032,7 @@ test "coretext: metrics" {
|
|||||||
);
|
);
|
||||||
defer ct_font.deinit();
|
defer ct_font.deinit();
|
||||||
|
|
||||||
try std.testing.expectEqual(font.face.Metrics{
|
try std.testing.expectEqual(font.Metrics{
|
||||||
.cell_width = 8,
|
.cell_width = 8,
|
||||||
// The cell height is 17 px because the calculation is
|
// The cell height is 17 px because the calculation is
|
||||||
//
|
//
|
||||||
@ -1060,7 +1060,7 @@ test "coretext: metrics" {
|
|||||||
|
|
||||||
// Resize should change metrics
|
// Resize should change metrics
|
||||||
try ct_font.setSize(.{ .size = .{ .points = 24, .xdpi = 96, .ydpi = 96 } });
|
try ct_font.setSize(.{ .size = .{ .points = 24, .xdpi = 96, .ydpi = 96 } });
|
||||||
try std.testing.expectEqual(font.face.Metrics{
|
try std.testing.expectEqual(font.Metrics{
|
||||||
.cell_width = 16,
|
.cell_width = 16,
|
||||||
.cell_height = 34,
|
.cell_height = 34,
|
||||||
.cell_baseline = 6,
|
.cell_baseline = 6,
|
||||||
|
@ -39,7 +39,7 @@ pub const Face = struct {
|
|||||||
hb_font: harfbuzz.Font,
|
hb_font: harfbuzz.Font,
|
||||||
|
|
||||||
/// Metrics for this font face. These are useful for renderers.
|
/// Metrics for this font face. These are useful for renderers.
|
||||||
metrics: font.face.Metrics,
|
metrics: font.Metrics,
|
||||||
|
|
||||||
/// Freetype load flags for this font face.
|
/// Freetype load flags for this font face.
|
||||||
load_flags: font.face.FreetypeLoadFlags,
|
load_flags: font.face.FreetypeLoadFlags,
|
||||||
@ -604,8 +604,8 @@ pub const Face = struct {
|
|||||||
/// deinitialized anytime and reloaded with the deferred face.
|
/// deinitialized anytime and reloaded with the deferred face.
|
||||||
fn calcMetrics(
|
fn calcMetrics(
|
||||||
face: freetype.Face,
|
face: freetype.Face,
|
||||||
modifiers: ?*const font.face.Metrics.ModifierSet,
|
modifiers: ?*const font.Metrics.ModifierSet,
|
||||||
) CalcMetricsError!font.face.Metrics {
|
) CalcMetricsError!font.Metrics {
|
||||||
const size_metrics = face.handle.*.size.*.metrics;
|
const size_metrics = face.handle.*.size.*.metrics;
|
||||||
|
|
||||||
// This code relies on this assumption, and it should always be
|
// This code relies on this assumption, and it should always be
|
||||||
@ -793,7 +793,7 @@ pub const Face = struct {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = font.face.Metrics.calc(.{
|
var result = font.Metrics.calc(.{
|
||||||
.cell_width = cell_width,
|
.cell_width = cell_width,
|
||||||
|
|
||||||
.ascent = ascent,
|
.ascent = ascent,
|
||||||
@ -921,7 +921,7 @@ test "metrics" {
|
|||||||
);
|
);
|
||||||
defer ft_font.deinit();
|
defer ft_font.deinit();
|
||||||
|
|
||||||
try testing.expectEqual(font.face.Metrics{
|
try testing.expectEqual(font.Metrics{
|
||||||
.cell_width = 8,
|
.cell_width = 8,
|
||||||
// The cell height is 17 px because the calculation is
|
// The cell height is 17 px because the calculation is
|
||||||
//
|
//
|
||||||
@ -949,7 +949,7 @@ test "metrics" {
|
|||||||
|
|
||||||
// Resize should change metrics
|
// Resize should change metrics
|
||||||
try ft_font.setSize(.{ .size = .{ .points = 24, .xdpi = 96, .ydpi = 96 } });
|
try ft_font.setSize(.{ .size = .{ .points = 24, .xdpi = 96, .ydpi = 96 } });
|
||||||
try testing.expectEqual(font.face.Metrics{
|
try testing.expectEqual(font.Metrics{
|
||||||
.cell_width = 16,
|
.cell_width = 16,
|
||||||
.cell_height = 34,
|
.cell_height = 34,
|
||||||
.cell_baseline = 6,
|
.cell_baseline = 6,
|
||||||
|
@ -27,7 +27,7 @@ pub const Face = struct {
|
|||||||
presentation: font.Presentation,
|
presentation: font.Presentation,
|
||||||
|
|
||||||
/// Metrics for this font face. These are useful for renderers.
|
/// Metrics for this font face. These are useful for renderers.
|
||||||
metrics: font.face.Metrics,
|
metrics: font.Metrics,
|
||||||
|
|
||||||
/// The canvas element that we will reuse to render glyphs
|
/// The canvas element that we will reuse to render glyphs
|
||||||
canvas: js.Object,
|
canvas: js.Object,
|
||||||
@ -273,7 +273,7 @@ pub const Face = struct {
|
|||||||
const underline_position = cell_height - 1;
|
const underline_position = cell_height - 1;
|
||||||
const underline_thickness: f32 = 1;
|
const underline_thickness: f32 = 1;
|
||||||
|
|
||||||
const result = font.face.Metrics{
|
const result = font.Metrics{
|
||||||
.cell_width = @intFromFloat(cell_width),
|
.cell_width = @intFromFloat(cell_width),
|
||||||
.cell_height = @intFromFloat(cell_height),
|
.cell_height = @intFromFloat(cell_height),
|
||||||
.cell_baseline = @intFromFloat(cell_baseline),
|
.cell_baseline = @intFromFloat(cell_baseline),
|
||||||
|
@ -14,7 +14,7 @@ pub const Collection = @import("Collection.zig");
|
|||||||
pub const DeferredFace = @import("DeferredFace.zig");
|
pub const DeferredFace = @import("DeferredFace.zig");
|
||||||
pub const Face = face.Face;
|
pub const Face = face.Face;
|
||||||
pub const Glyph = @import("Glyph.zig");
|
pub const Glyph = @import("Glyph.zig");
|
||||||
pub const Metrics = face.Metrics;
|
pub const Metrics = @import("Metrics.zig");
|
||||||
pub const opentype = @import("opentype.zig");
|
pub const opentype = @import("opentype.zig");
|
||||||
pub const shape = @import("shape.zig");
|
pub const shape = @import("shape.zig");
|
||||||
pub const Shaper = shape.Shaper;
|
pub const Shaper = shape.Shaper;
|
||||||
|
@ -68,7 +68,7 @@ config: DerivedConfig,
|
|||||||
surface_mailbox: apprt.surface.Mailbox,
|
surface_mailbox: apprt.surface.Mailbox,
|
||||||
|
|
||||||
/// Current font metrics defining our grid.
|
/// Current font metrics defining our grid.
|
||||||
grid_metrics: font.face.Metrics,
|
grid_metrics: font.Metrics,
|
||||||
|
|
||||||
/// The size of everything.
|
/// The size of everything.
|
||||||
size: renderer.Size,
|
size: renderer.Size,
|
||||||
|
@ -49,7 +49,7 @@ alloc: std.mem.Allocator,
|
|||||||
config: DerivedConfig,
|
config: DerivedConfig,
|
||||||
|
|
||||||
/// Current font metrics defining our grid.
|
/// Current font metrics defining our grid.
|
||||||
grid_metrics: font.face.Metrics,
|
grid_metrics: font.Metrics,
|
||||||
|
|
||||||
/// The size of everything.
|
/// The size of everything.
|
||||||
size: renderer.Size,
|
size: renderer.Size,
|
||||||
@ -231,7 +231,7 @@ const SetScreenSize = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const SetFontSize = struct {
|
const SetFontSize = struct {
|
||||||
metrics: font.face.Metrics,
|
metrics: font.Metrics,
|
||||||
|
|
||||||
fn apply(self: SetFontSize, r: *const OpenGL) !void {
|
fn apply(self: SetFontSize, r: *const OpenGL) !void {
|
||||||
const gl_state = r.gl_state orelse return error.OpenGLUninitialized;
|
const gl_state = r.gl_state orelse return error.OpenGLUninitialized;
|
||||||
|
Reference in New Issue
Block a user