From abd782a7aa45a06221b921746a240b32fe34fd54 Mon Sep 17 00:00:00 2001 From: Gordon Cassie Date: Wed, 24 Apr 2024 21:07:50 -0700 Subject: [PATCH 1/4] Fix typo. --- pkg/macos/text/font.zig | 6 +++--- src/font/face/coretext.zig | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/macos/text/font.zig b/pkg/macos/text/font.zig index 1141ab1fa..c26a0f32f 100644 --- a/pkg/macos/text/font.zig +++ b/pkg/macos/text/font.zig @@ -81,7 +81,7 @@ pub const Font = opaque { ); } - pub fn getBoundingRectForGlyphs( + pub fn getBoundingRectsForGlyphs( self: *Font, orientation: FontOrientation, glyphs: []const graphics.Glyph, @@ -197,11 +197,11 @@ test { // Bounding rect { - var rect = font.getBoundingRectForGlyphs(.horizontal, &glyphs, null); + var rect = font.getBoundingRectsForGlyphs(.horizontal, &glyphs, null); try testing.expect(rect.size.width > 0); var singles: [1]graphics.Rect = undefined; - rect = font.getBoundingRectForGlyphs(.horizontal, &glyphs, &singles); + rect = font.getBoundingRectsForGlyphs(.horizontal, &glyphs, &singles); try testing.expect(rect.size.width > 0); try testing.expect(singles[0].size.width > 0); } diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index e3177e888..7e305f968 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -242,7 +242,7 @@ pub const Face = struct { var glyphs = [_]macos.graphics.Glyph{@intCast(glyph_index)}; // Get the bounding rect for rendering this glyph. - const rect = self.font.getBoundingRectForGlyphs(.horizontal, &glyphs, null); + const rect = self.font.getBoundingRectsForGlyphs(.horizontal, &glyphs, null); // The x/y that we render the glyph at. The Y value has to be flipped // because our coordinates in 3D space are (0, 0) bottom left with From b76f5976ee29aa0cf29b632b61be8db861c2f23a Mon Sep 17 00:00:00 2001 From: Gordon Cassie Date: Thu, 25 Apr 2024 15:38:21 -0700 Subject: [PATCH 2/4] Remove unnecessary allocation. --- src/font/face/coretext.zig | 16 ---------------- src/font/shaper/coretext.zig | 13 +------------ 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 7e305f968..affe7878f 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -396,7 +396,6 @@ pub const Face = struct { const offset_y: i32 = offset_y: { // Our Y coordinate in 3D is (0, 0) bottom left, +y is UP. // We need to calculate our baseline from the bottom of a cell. - //const baseline_from_bottom: f64 = @floatFromInt(self.metrics.cell_baseline); const baseline_from_bottom: f64 = @floatFromInt(metrics.cell_baseline); // Next we offset our baseline by the bearing in the font. We @@ -425,18 +424,6 @@ pub const Face = struct { var advances: [glyphs.len]macos.graphics.Size = undefined; _ = self.font.getAdvancesForGlyphs(.horizontal, &glyphs, &advances); - // std.log.warn("renderGlyph rect={} width={} height={} render_x={} render_y={} offset_y={} ascent={} cell_height={} cell_baseline={}", .{ - // rect, - // width, - // height, - // render_x, - // render_y, - // offset_y, - // glyph_ascent, - // self.metrics.cell_height, - // self.metrics.cell_baseline, - // }); - return .{ .width = width, .height = height, @@ -538,9 +525,6 @@ pub const Face = struct { .strikethrough_thickness = @intFromFloat(strikethrough_thickness), }; - // std.log.warn("font size size={d}", .{ct_font.getSize()}); - // std.log.warn("font metrics={}", .{result}); - return result; } }; diff --git a/src/font/shaper/coretext.zig b/src/font/shaper/coretext.zig index 76d0cdb9a..c83d07533 100644 --- a/src/font/shaper/coretext.zig +++ b/src/font/shaper/coretext.zig @@ -304,19 +304,16 @@ pub const Shaper = struct { // Get our glyphs and positions const glyphs = try ctrun.getGlyphs(alloc); - const positions = try ctrun.getPositions(alloc); const advances = try ctrun.getAdvances(alloc); const indices = try ctrun.getStringIndices(alloc); - assert(glyphs.len == positions.len); assert(glyphs.len == advances.len); assert(glyphs.len == indices.len); for ( glyphs, - positions, advances, indices, - ) |glyph, pos, advance, index| { + ) |glyph, advance, index| { try self.cell_buf.ensureUnusedCapacity( self.alloc, glyphs.len, @@ -351,15 +348,7 @@ pub const Shaper = struct { // Advances apply to the NEXT cell. cell_offset.x += advance.width; cell_offset.y += advance.height; - - _ = pos; - // const i = self.cell_buf.items.len - 1; - // log.warn( - // "i={} codepoint={} glyph={} pos={} advance={} index={} cluster={}", - // .{ i, self.codepoints.items[index].codepoint, glyph, pos, advance, index, cluster }, - // ); } - //log.warn("-------------------------------", .{}); } // If our last cell doesn't match our last cluster then we have From e564454ff1574a5b3c6bd22c0245c8629e2ae4db Mon Sep 17 00:00:00 2001 From: Gordon Cassie Date: Thu, 25 Apr 2024 15:40:48 -0700 Subject: [PATCH 3/4] More log statements. --- src/font/shaper/coretext.zig | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/font/shaper/coretext.zig b/src/font/shaper/coretext.zig index c83d07533..1e599475b 100644 --- a/src/font/shaper/coretext.zig +++ b/src/font/shaper/coretext.zig @@ -379,7 +379,6 @@ pub const Shaper = struct { pub fn prepare(self: *RunIteratorHook) !void { try self.shaper.run_state.reset(); - // log.warn("----------- run reset -------------", .{}); } pub fn addCodepoint(self: RunIteratorHook, cp: u32, cluster: u32) !void { @@ -398,7 +397,6 @@ pub const Shaper = struct { .codepoint = cp, .cluster = cluster, }); - // log.warn("run cp={X}", .{cp}); // If the UTF-16 codepoint is a pair then we need to insert // a dummy entry so that the CTRunGetStringIndices() function From e77f9962a82947957e280e50e065ba5f45b8519f Mon Sep 17 00:00:00 2001 From: Gordon Cassie Date: Thu, 25 Apr 2024 19:27:51 -0700 Subject: [PATCH 4/4] revert on comment removal --- src/font/face/coretext.zig | 15 +++++++++++++++ src/font/shaper/coretext.zig | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index affe7878f..3178a8132 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -424,6 +424,18 @@ pub const Face = struct { var advances: [glyphs.len]macos.graphics.Size = undefined; _ = self.font.getAdvancesForGlyphs(.horizontal, &glyphs, &advances); + // std.log.warn("renderGlyph rect={} width={} height={} render_x={} render_y={} offset_y={} ascent={} cell_height={} cell_baseline={}", .{ + // rect, + // width, + // height, + // render_x, + // render_y, + // offset_y, + // glyph_ascent, + // self.metrics.cell_height, + // self.metrics.cell_baseline, + // }); + return .{ .width = width, .height = height, @@ -525,6 +537,9 @@ pub const Face = struct { .strikethrough_thickness = @intFromFloat(strikethrough_thickness), }; + // std.log.warn("font size size={d}", .{ct_font.getSize()}); + // std.log.warn("font metrics={}", .{result}); + return result; } }; diff --git a/src/font/shaper/coretext.zig b/src/font/shaper/coretext.zig index 1e599475b..c83d07533 100644 --- a/src/font/shaper/coretext.zig +++ b/src/font/shaper/coretext.zig @@ -379,6 +379,7 @@ pub const Shaper = struct { pub fn prepare(self: *RunIteratorHook) !void { try self.shaper.run_state.reset(); + // log.warn("----------- run reset -------------", .{}); } pub fn addCodepoint(self: RunIteratorHook, cp: u32, cluster: u32) !void { @@ -397,6 +398,7 @@ pub const Shaper = struct { .codepoint = cp, .cluster = cluster, }); + // log.warn("run cp={X}", .{cp}); // If the UTF-16 codepoint is a pair then we need to insert // a dummy entry so that the CTRunGetStringIndices() function