I can think of two ways, but neither gives exactly the same semantics as +[NSFont systemFontOfSize:weight:]
.
One is to use -[NSFontManager convertWeight:ofFont:]
. That just allows you to go up or down in weight, not select a specific target weight. However, if it provides a new font, you can query -[NSFontManager weightOfFont:]
to get its weight, where a value of 3 is "light" (see the table at -convertWeight:ofFont:
). By repeating the process, you may be able to get the weight you want, although the method could fail or overshoot.
The other is to go from font to font descriptor to new font descriptor with the desired weight to a new font:
NSFontDescriptor* origDescriptor = origFont.fontDescriptor;
NSFontDescriptor* newDescriptor = [origDescriptor fontDescriptorByAddingAttributes:@{ NSFontTraitsAttribute: @{ NSFontWeightTrait: @(-0.2) } }];
NSFont* newFont = [NSFont fontWithDescriptor:newDescriptor size:origFont.pointSize];
Here I just chose -0.2 arbitrarily. The problem with this approach is that it takes weights as values from -1.0 to 1.0, with 0 as "normal". It's not clear how to map that scale to "light weight". I suppose you can query some light weight fonts you acquire by name to see what their weights are.