face: coretext zero the bitmap before render

This commit is contained in:
Mitchell Hashimoto
2022-10-18 12:52:37 -07:00
parent 58c107dceb
commit 4669032e56

View File

@ -107,6 +107,8 @@ pub const Face = struct {
_ = glyph_height; _ = glyph_height;
const width = @floatToInt(u32, self.metrics.cell_width); const width = @floatToInt(u32, self.metrics.cell_width);
const height = @floatToInt(u32, self.metrics.cell_height); const height = @floatToInt(u32, self.metrics.cell_height);
// const width = glyph_width;
// const height = glyph_height;
// This bitmap is blank. I've seen it happen in a font, I don't know why. // This bitmap is blank. I've seen it happen in a font, I don't know why.
// If it is empty, we just return a valid glyph struct that does nothing. // If it is empty, we just return a valid glyph struct that does nothing.
@ -131,6 +133,7 @@ pub const Face = struct {
// TODO(mitchellh): color is going to require a depth here // TODO(mitchellh): color is going to require a depth here
var buf = try alloc.alloc(u8, width * height); var buf = try alloc.alloc(u8, width * height);
defer alloc.free(buf); defer alloc.free(buf);
std.mem.set(u8, buf, 0);
const space = try macos.graphics.ColorSpace.createDeviceGray(); const space = try macos.graphics.ColorSpace.createDeviceGray();
defer space.release(); defer space.release();
@ -155,6 +158,7 @@ pub const Face = struct {
ctx.setTextDrawingMode(.fill_stroke); ctx.setTextDrawingMode(.fill_stroke);
ctx.setTextMatrix(macos.graphics.AffineTransform.identity()); ctx.setTextMatrix(macos.graphics.AffineTransform.identity());
ctx.setTextPosition(0, @intToFloat(f32, height) - self.metrics.cell_baseline); ctx.setTextPosition(0, @intToFloat(f32, height) - self.metrics.cell_baseline);
//ctx.setTextPosition(0, 0);
var pos = [_]macos.graphics.Point{.{ .x = 0, .y = 0 }}; var pos = [_]macos.graphics.Point{.{ .x = 0, .y = 0 }};
self.font.drawGlyphs(&glyphs, &pos, ctx); self.font.drawGlyphs(&glyphs, &pos, ctx);