简体   繁体   中英

What are the ranges for each font weight in Cocoa?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM