From 30caeb789659441f8feb76b24f3d0b1f60125085 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Thu, 5 May 2022 17:01:53 +0800 Subject: [PATCH] Fix font weight reporting on macOS * src/macfont.m (macfont_store_descriptor_attributes): Fix numeric values for the addition of `medium'. * src/nsterm.m (ns_font_desc_to_font_spec): Adjust accordingly. (ns_create_font_panel_buttons): Try to fix button width. --- src/macfont.m | 2 +- src/nsterm.m | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/macfont.m b/src/macfont.m index 35648df06c6..4dd55e77469 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -847,7 +847,7 @@ macfont_store_descriptor_attributes (CTFontDescriptorRef desc, {{FONT_WEIGHT_INDEX, kCTFontWeightTrait, {{-0.4, 50}, /* light */ {-0.24, 87.5}, /* (semi-light + normal) / 2 */ - {0, 100}, /* normal */ + {0, 80}, /* normal */ {0.24, 140}, /* (semi-bold + normal) / 2 */ {0.4, 200}, /* bold */ {CGFLOAT_MAX, CGFLOAT_MAX}}, diff --git a/src/nsterm.m b/src/nsterm.m index 8e8d5c969be..fef7f0dc6c8 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -6092,10 +6092,26 @@ ns_font_desc_to_font_spec (NSFontDescriptor *desc, NSFont *font) tem = [dict objectForKey: NSFontWeightTrait]; +#ifdef NS_IMPL_GNUSTEP if (tem != nil) lweight = ([tem floatValue] > 0 ? Qbold : ([tem floatValue] < -0.4f ? Qlight : Qnormal)); +#else + if (tem != nil) + { + if ([tem floatValue] >= 0.4) + lweight = Qbold; + else if ([tem floatValue] >= 0.24) + lweight = Qmedium; + else if ([tem floatValue] >= 0) + lweight = Qnormal; + else if ([tem floatValue] >= -0.24) + lweight = Qsemi_light; + else + lweight = Qlight; + } +#endif tem = [dict objectForKey: NSFontWidthTrait]; @@ -6127,6 +6143,7 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) prototype = [[NSButtonCell alloc] init]; [prototype setBezelStyle: NSBezelStyleRounded]; + [prototype setTitle: @"Cancel"]; cell_size = [prototype cellSize]; frame = NSMakeRect (0, 0, cell_size.width * 2, cell_size.height); -- 2.39.5