From f393049988be016dd46525492e1d51673954a99a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 8 Oct 2022 11:25:54 -0700 Subject: [PATCH] fix compilation --- src/font/DeferredFace.zig | 2 +- src/font/face.zig | 26 ++++++++++++++++++++++++-- src/font/face/freetype.zig | 26 ++------------------------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/font/DeferredFace.zig b/src/font/DeferredFace.zig index a3131d558..ed4a4517d 100644 --- a/src/font/DeferredFace.zig +++ b/src/font/DeferredFace.zig @@ -114,7 +114,7 @@ pub fn load( // It is possible to use CoreText with Freetype so we support // both here. switch (font.Face) { - font.face.freetype.Face => try self.loadCoreTextFreetype(lib, size), + @import("face/freetype.zig").Face => try self.loadCoreTextFreetype(lib, size), else => unreachable, } diff --git a/src/font/face.zig b/src/font/face.zig index f3b4c47d9..d4d4ba1d2 100644 --- a/src/font/face.zig +++ b/src/font/face.zig @@ -1,7 +1,7 @@ const builtin = @import("builtin"); const options = @import("main.zig").options; -pub const freetype = @import("face/freetype.zig"); -pub const coretext = @import("face/coretext.zig"); +const freetype = @import("face/freetype.zig"); +const coretext = @import("face/coretext.zig"); /// Face implementation for the compile options. pub const Face = switch (options.backend) { @@ -32,6 +32,28 @@ pub const DesiredSize = struct { } }; +/// Metrics associated with the font that are useful for renderers to know. +pub const Metrics = struct { + /// Recommended cell width and height for a monospace grid using this font. + cell_width: f32, + cell_height: f32, + + /// For monospace grids, the recommended y-value from the bottom to set + /// the baseline for font rendering. This is chosen so that things such + /// as the bottom of a "g" or "y" do not drop below the cell. + cell_baseline: f32, + + /// The position of the underline from the top of the cell and the + /// thickness in pixels. + underline_position: f32, + underline_thickness: f32, + + /// The position and thickness of a strikethrough. Same units/style + /// as the underline fields. + strikethrough_position: f32, + strikethrough_thickness: f32, +}; + pub const Foo = if (options.backend == .coretext) coretext.Face else void; test { diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index d0fa1f966..9542414d5 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -31,7 +31,7 @@ pub const Face = struct { presentation: Presentation, /// Metrics for this font face. These are useful for renderers. - metrics: Metrics, + metrics: font.face.Metrics, /// Initialize a new font face with the given source in-memory. pub fn initFile(lib: Library, path: [:0]const u8, index: i32, size: font.face.DesiredSize) !Face { @@ -235,28 +235,6 @@ pub const Face = struct { return @intToFloat(f32, v >> 6); } - /// Metrics associated with the font that are useful for renderers to know. - pub const Metrics = struct { - /// Recommended cell width and height for a monospace grid using this font. - cell_width: f32, - cell_height: f32, - - /// For monospace grids, the recommended y-value from the bottom to set - /// the baseline for font rendering. This is chosen so that things such - /// as the bottom of a "g" or "y" do not drop below the cell. - cell_baseline: f32, - - /// The position of the underline from the top of the cell and the - /// thickness in pixels. - underline_position: f32, - underline_thickness: f32, - - /// The position and thickness of a strikethrough. Same units/style - /// as the underline fields. - strikethrough_position: f32, - strikethrough_thickness: f32, - }; - /// Calculate the metrics associated with a face. This is not public because /// the metrics are calculated for every face and cached since they're /// frequently required for renderers and take up next to little memory space @@ -266,7 +244,7 @@ pub const Face = struct { /// the faces with DeferredFaces and reload on demand. A Face can't be converted /// into a DeferredFace but a Face that comes from a DeferredFace can be /// deinitialized anytime and reloaded with the deferred face. - fn calcMetrics(face: freetype.Face) Metrics { + fn calcMetrics(face: freetype.Face) font.face.Metrics { const size_metrics = face.handle.*.size.*.metrics; // Cell width is calculated by preferring to use 'M' as the width of a