Fix font weight reporting on macOS
authorPo Lu <luangruo@yahoo.com>
Thu, 5 May 2022 09:01:53 +0000 (17:01 +0800)
committerPo Lu <luangruo@yahoo.com>
Thu, 5 May 2022 09:01:53 +0000 (17:01 +0800)
* 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
src/nsterm.m

index 35648df06c6f05de3dfc51cb3c0db3d621dcbad8..4dd55e77469f82f91328ca71a0d041456e8e8e44 100644 (file)
@@ -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}},
index 8e8d5c969be7d26385ac6530b2bcb8283276aec6..fef7f0dc6c8ebc44a9ac1f1cb1bf343547007624 100644 (file)
@@ -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);