Home > database >  What are the ranges for each font weight in Cocoa?
What are the ranges for each font weight in Cocoa?

Time:12-02

The documentation for NSFontWeight only shows a few values, but doesn't say what is the range for each font weight.

Using the following values,

NSFontWeightUltraLight  NSFontWeight(rawValue: -0.800000011920929)
NSFontWeightThin        NSFontWeight(rawValue: -0.6000000238418579)
NSFontWeightLight       NSFontWeight(rawValue: -0.4000000059604645)
NSFontWeightRegular     NSFontWeight(rawValue: 0.0)
NSFontWeightMedium      NSFontWeight(rawValue: 0.23000000417232513)
NSFontWeightSemibold    NSFontWeight(rawValue: 0.30000001192092896)
NSFontWeightBold        NSFontWeight(rawValue: 0.4000000059604645)
NSFontWeightHeavy       NSFontWeight(rawValue: 0.5600000023841858)
NSFontWeightBlack       NSFontWeight(rawValue: 0.6200000047683716)

Which font weight would, for example, -0.17 be? Should I interpret it as normal, or light?

CodePudding user response:

There is no range. Those are the values for the named weights in NSFont (other font systems use different scales). -0.17 is between regular and light. If you want to snap the value to one of the named weights, you'll need to decide your rule for doing that. The most obvious would be to pick the closest (Regular in this case), but this could change the weight slightly. There is no objective measure of font weights. Regular is generally designed to appear "heavier" than light. Bold is generally designed to appear "heavier" than regular. But what "heavier" means is up to the font designer, and may not be consistent or compatible between fonts, particularly fonts from different designers.

  • Related