diff --git a/pkg/macos/text/line.zig b/pkg/macos/text/line.zig index e6a506de9..d392643e4 100644 --- a/pkg/macos/text/line.zig +++ b/pkg/macos/text/line.zig @@ -30,30 +30,12 @@ pub const Line = opaque { self: *Line, opts: LineBoundsOptions, ) graphics.Rect { - // return @bitCast(c.CGRect, c.CTLineGetBoundsWithOptions( - // @ptrCast(c.CTLineRef, self), - // opts.cval(), - // )); - - // We have to use a custom C wrapper here because there is some - // C ABI issue happening. - var result: graphics.Rect = undefined; - zig_cabi_CTLineGetBoundsWithOptions( + return @bitCast(c.CTLineGetBoundsWithOptions( @ptrCast(self), opts.cval(), - @ptrCast(&result), - ); - - return result; + )); } - // See getBoundsWithOptions - extern "c" fn zig_cabi_CTLineGetBoundsWithOptions( - c.CTLineRef, - c.CTLineBoundsOptions, - *c.CGRect, - ) void; - pub fn getTypographicBounds( self: *Line, ascent: ?*f64, diff --git a/src/font/Group.zig b/src/font/Group.zig index 804438c44..f7f9e271f 100644 --- a/src/font/Group.zig +++ b/src/font/Group.zig @@ -282,7 +282,9 @@ pub fn renderGlyph( const face = &self.faces.get(index.style).items[@intCast(index.idx)]; try face.load(self.lib, self.size); - return try face.face.?.renderGlyph(alloc, atlas, glyph_index, max_height); + const glyph = try face.face.?.renderGlyph(alloc, atlas, glyph_index, max_height); + // log.warn("GLYPH={}", .{glyph}); + return glyph; } /// The wasm-compatible API. diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 308ac3344..b04e35d07 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -545,16 +545,22 @@ pub const Face = struct { // NOTE(mitchellh): For some reason, CTLineGetBoundsWithOptions // returns garbage and I can't figure out why... so we use the // raw ascender. + const bounds = line.getBoundsWithOptions(.{ .exclude_leading = true }); + const bounds_ascent = bounds.size.height + bounds.origin.y; + const baseline = @floor(bounds_ascent + 0.5); - var ascent: f64 = 0; - var descent: f64 = 0; - var leading: f64 = 0; - _ = line.getTypographicBounds(&ascent, &descent, &leading); + // This is an alternate approach to the above to calculate the + // baseline by simply using the ascender. Using this approach led + // to less accurate results, but I'm leaving it here for reference. + // var ascent: f64 = 0; + // var descent: f64 = 0; + // var leading: f64 = 0; + // _ = line.getTypographicBounds(&ascent, &descent, &leading); //std.log.warn("ascent={} descent={} leading={}", .{ ascent, descent, leading }); break :metrics .{ .height = @floatCast(points[0].y - points[1].y), - .ascent = @floatCast(ascent), + .ascent = @floatCast(baseline), }; };