macoscocoafontscore-textnsfont

What are the canonical font weights in Core Text?


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

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


Solution

  • 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?