refactor(font): move Metrics out of face

in preparation to move ownership of metrics from faces to collections
This commit is contained in:
Qwerasd
2025-01-06 17:39:53 -05:00
parent 037de64ea2
commit 540fcc0b69
12 changed files with 24 additions and 24 deletions

View File

@ -32,7 +32,7 @@ const url = @import("url.zig");
const Key = @import("key.zig").Key;
const KeyValue = @import("key.zig").Value;
const ErrorList = @import("ErrorList.zig");
const MetricModifier = fontpkg.face.Metrics.Modifier;
const MetricModifier = fontpkg.Metrics.Modifier;
const help_strings = @import("help_strings");
const log = std.log.scoped(.config);

View File

@ -25,7 +25,7 @@ const DeferredFace = font.DeferredFace;
const DesiredSize = font.face.DesiredSize;
const Face = font.Face;
const Library = font.Library;
const Metrics = font.face.Metrics;
const Metrics = font.Metrics;
const Presentation = font.Presentation;
const Style = font.Style;

View File

@ -355,7 +355,7 @@ pub const Modifier = union(enum) {
}
test "formatConfig percent" {
const configpkg = @import("../../config.zig");
const configpkg = @import("../config.zig");
const testing = std.testing;
var buf = std.ArrayList(u8).init(testing.allocator);
defer buf.deinit();
@ -366,7 +366,7 @@ pub const Modifier = union(enum) {
}
test "formatConfig absolute" {
const configpkg = @import("../../config.zig");
const configpkg = @import("../config.zig");
const testing = std.testing;
var buf = std.ArrayList(u8).init(testing.allocator);
defer buf.deinit();

View File

@ -29,7 +29,7 @@ const Collection = font.Collection;
const Face = font.Face;
const Glyph = font.Glyph;
const Library = font.Library;
const Metrics = font.face.Metrics;
const Metrics = font.Metrics;
const Presentation = font.Presentation;
const Style = font.Style;
const RenderOptions = font.face.RenderOptions;

View File

@ -20,7 +20,7 @@ const Collection = font.Collection;
const Discover = font.Discover;
const Style = font.Style;
const Library = font.Library;
const Metrics = font.face.Metrics;
const Metrics = font.Metrics;
const CodepointMap = font.CodepointMap;
const DesiredSize = font.face.DesiredSize;
const Face = font.Face;

View File

@ -1,7 +1,7 @@
const std = @import("std");
const builtin = @import("builtin");
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 freetype = @import("face/freetype.zig");
const coretext = @import("face/coretext.zig");

View File

@ -19,7 +19,7 @@ pub const Face = struct {
hb_font: if (harfbuzz_shaper) harfbuzz.Font else void,
/// Metrics for this font face. These are useful for renderers.
metrics: font.face.Metrics,
metrics: font.Metrics,
/// Set quirks.disableDefaultFontFeatures
quirks_disable_default_font_features: bool = false,
@ -513,7 +513,7 @@ pub const Face = struct {
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.
const head: opentype.Head = head: {
// macOS bitmap-only fonts use a 'bhed' tag rather than 'head', but
@ -731,7 +731,7 @@ pub const Face = struct {
break :cell_width max;
};
return font.face.Metrics.calc(.{
return font.Metrics.calc(.{
.cell_width = cell_width,
.ascent = ascent,
.descent = descent,
@ -1032,7 +1032,7 @@ test "coretext: metrics" {
);
defer ct_font.deinit();
try std.testing.expectEqual(font.face.Metrics{
try std.testing.expectEqual(font.Metrics{
.cell_width = 8,
// The cell height is 17 px because the calculation is
//
@ -1060,7 +1060,7 @@ test "coretext: metrics" {
// Resize should change metrics
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_height = 34,
.cell_baseline = 6,

View File

@ -39,7 +39,7 @@ pub const Face = struct {
hb_font: harfbuzz.Font,
/// Metrics for this font face. These are useful for renderers.
metrics: font.face.Metrics,
metrics: font.Metrics,
/// Freetype load flags for this font face.
load_flags: font.face.FreetypeLoadFlags,
@ -604,8 +604,8 @@ pub const Face = struct {
/// deinitialized anytime and reloaded with the deferred face.
fn calcMetrics(
face: freetype.Face,
modifiers: ?*const font.face.Metrics.ModifierSet,
) CalcMetricsError!font.face.Metrics {
modifiers: ?*const font.Metrics.ModifierSet,
) CalcMetricsError!font.Metrics {
const size_metrics = face.handle.*.size.*.metrics;
// 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,
.ascent = ascent,
@ -921,7 +921,7 @@ test "metrics" {
);
defer ft_font.deinit();
try testing.expectEqual(font.face.Metrics{
try testing.expectEqual(font.Metrics{
.cell_width = 8,
// The cell height is 17 px because the calculation is
//
@ -949,7 +949,7 @@ test "metrics" {
// Resize should change metrics
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_height = 34,
.cell_baseline = 6,

View File

@ -27,7 +27,7 @@ pub const Face = struct {
presentation: font.Presentation,
/// 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
canvas: js.Object,
@ -273,7 +273,7 @@ pub const Face = struct {
const underline_position = cell_height - 1;
const underline_thickness: f32 = 1;
const result = font.face.Metrics{
const result = font.Metrics{
.cell_width = @intFromFloat(cell_width),
.cell_height = @intFromFloat(cell_height),
.cell_baseline = @intFromFloat(cell_baseline),

View File

@ -14,7 +14,7 @@ pub const Collection = @import("Collection.zig");
pub const DeferredFace = @import("DeferredFace.zig");
pub const Face = face.Face;
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 shape = @import("shape.zig");
pub const Shaper = shape.Shaper;

View File

@ -68,7 +68,7 @@ config: DerivedConfig,
surface_mailbox: apprt.surface.Mailbox,
/// Current font metrics defining our grid.
grid_metrics: font.face.Metrics,
grid_metrics: font.Metrics,
/// The size of everything.
size: renderer.Size,

View File

@ -49,7 +49,7 @@ alloc: std.mem.Allocator,
config: DerivedConfig,
/// Current font metrics defining our grid.
grid_metrics: font.face.Metrics,
grid_metrics: font.Metrics,
/// The size of everything.
size: renderer.Size,
@ -231,7 +231,7 @@ const SetScreenSize = struct {
};
const SetFontSize = struct {
metrics: font.face.Metrics,
metrics: font.Metrics,
fn apply(self: SetFontSize, r: *const OpenGL) !void {
const gl_state = r.gl_state orelse return error.OpenGLUninitialized;