1

Both GDI and Pango have a list of canonical font weights that go in the range "thin, extra light, light, normal, medium, semibold, bold, extra bold, heavy". It appears CSS does too.

However, I don't see such a font list for Core Text (or even NSFont/NSFontDescriptor) on OS X. Instead, what I see is

  • kCTFontWeightTrait, which is documented as going from -1.0 to 1.0 with 0.0 being "regular or medium" (so both normal and medium or just medium?), and
  • -[NSFontManager fontWithFamily:traits:weight:size:], whose weight parameter is documented as going from 0 to 15 with 5 being normal/book (which I assume is between light and normal, if not normal) and 9 and higher all being bold

So what are the equivalents of the above canonical weight names? Thanks.

1 Answer 1

3

The canonical names are given in the headers:

APPKIT_EXTERN const CGFloat NSFontWeightUltraLight NS_AVAILABLE_MAC(10_11);
APPKIT_EXTERN const CGFloat NSFontWeightThin NS_AVAILABLE_MAC(10_11);
APPKIT_EXTERN const CGFloat NSFontWeightLight NS_AVAILABLE_MAC(10_11);
APPKIT_EXTERN const CGFloat NSFontWeightRegular NS_AVAILABLE_MAC(10_11);
APPKIT_EXTERN const CGFloat NSFontWeightMedium NS_AVAILABLE_MAC(10_11);
APPKIT_EXTERN const CGFloat NSFontWeightSemibold NS_AVAILABLE_MAC(10_11);
APPKIT_EXTERN const CGFloat NSFontWeightBold NS_AVAILABLE_MAC(10_11);
APPKIT_EXTERN const CGFloat NSFontWeightHeavy NS_AVAILABLE_MAC(10_11);
APPKIT_EXTERN const CGFloat NSFontWeightBlack NS_AVAILABLE_MAC(10_11);

To learn their values, just log each one in turn.

NSLog(@"%f", NSFontWeightUltraLight);
NSLog(@"%f", NSFontWeightThin);
// ... need I go on?
4
  • Oh neat. Which header is this? I completely missed it when I looked earlier today >////>
    – andlabs
    Commented Sep 14, 2015 at 18:22
  • Oh wait I just realized why I missed it: I only have the 10.10 headers :/ Surprised they were only added now...
    – andlabs
    Commented Sep 14, 2015 at 18:24
  • There were no canonical weights until now, I think.
    – matt
    Commented Sep 14, 2015 at 18:34
  • Yep, this confirms it. Thanks! Since I need to run on 10.7 and higher I'll just get the values of the constants out of a 10.11 box and switch to using the constants directly if my requirements ever change.
    – andlabs
    Commented Sep 14, 2015 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.