coretext: the size needs to be in pixels! (see comment)

This commit is contained in:
Mitchell Hashimoto
2023-06-30 14:13:40 -07:00
parent 4d7a2c9f05
commit 079fe7bc94

View File

@ -41,8 +41,10 @@ pub const Face = struct {
/// because the font is loaded at a default size during discovery, and then /// because the font is loaded at a default size during discovery, and then
/// adjusted to the final size for final load. /// adjusted to the final size for final load.
pub fn initFontCopy(base: *macos.text.Font, size: font.face.DesiredSize) !Face { pub fn initFontCopy(base: *macos.text.Font, size: font.face.DesiredSize) !Face {
// Create a copy // Create a copy. The copyWithAttributes docs say the size is in points,
const ct_font = try base.copyWithAttributes(@floatFromInt(size.points), null); // but we need to scale the points by the DPI and to do that we use our
// function called "pixels".
const ct_font = try base.copyWithAttributes(@floatFromInt(size.pixels()), null);
errdefer ct_font.release(); errdefer ct_font.release();
var hb_font = try harfbuzz.coretext.createFont(ct_font); var hb_font = try harfbuzz.coretext.createFont(ct_font);