Listing font families and associated styles

Using Font as described in http://documentation.xojo.com/index.php/Font I can get all the font families available in the system. But I would like to be able to list all the styles for each family, such as bold, italic, oblique, bolditalic, thin, ultra bold, and so on.

I looked at NSFont but it is unclear if and how this can be obtained.

Will appreciate any suggestions.

In my Fonts folder styles seem to be separate files. Are they ever bundled into one file or would it be reasonable to expect them to be separate? If you’re not sandboxed you should be able to read both the system and user Fonts folders.

I’m not so good with the declares business, but you might find this of interest:
https://developer.apple.com/library/prerelease/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSFontDescriptor_Class/index.html#//apple_ref/doc/uid/20002041-SW20

It’s a dictionary of attributes for the font.
It reminds me that I really need to learn Swift >_<

Good idea Tim. I was not on the right page. Thank you.

I see that apparently Christian has a plugin to access it : NSFontDescriptorMBS. I will investigate.

In the meantime, though, I had found a way to verify if a particular style is available :

[code] dim p as new picture(1,1)
dim g as graphics = p.graphics

g.TextFont = “Helvetica ThisStyleDoesNotExist”
system.DebugLog "DoesNotExist : "+str(g.stringwidth(“yadayadayadayada”))

g.TextFont = “Helvetica”
system.DebugLog "Regular : "+str(g.stringwidth(“yadayadayadayada”))

g.TextFont = “Helvetica Bold”
system.DebugLog "Bold : "+str(g.stringwidth(“yadayadayadayada”))

g.TextFont = “Helvetica Italic”
system.DebugLog "Italic : "+str(g.stringwidth(“yadayadayadayada”))

g.TextFont = “Helvetica Oblique”
system.DebugLog "Oblique : "+str(g.stringwidth(“yadayadayadayada”))

g.TextFont = “Helvetica Bold Oblique”
system.DebugLog "Bold Oblique : "+str(g.stringwidth(“yadayadayadayada”))

g.TextFont = “Helvetica BoldItalic”
system.DebugLog "BoldItalic : "+str(g.stringwidth(“yadayadayadayada”))

g.TextFont = “Helvetica ExtraBold”
system.DebugLog "ExtraBold : "+str(g.stringwidth(“yadayadayadayada”))[/code]

Result :

DoesNotExist : 106.875
Regular : 104.0859
Bold : 109.4062
Italic : 106.875
Oblique : 104.0859
Bold Oblique : 109.4062
BoldItalic : 106.875
ExtraBold : 106.875

The styles that do not exist give a width of 106.875. Existing styles have different values.

OK. As usual, Christian had the solution in his huge bag of tricks. The difficult part was to find it :

http://www.monkeybreadsoftware.net/example-cocoabase-nsfontfonts.shtml

It is much easier to buy MBS Plugins complete than to learn Objective-C :slight_smile:

https://forum.xojo.com/26247-use-the-light-version-of-a-font/p1#p217218

Thank you Axel. I used the MBS plugin, but that can be of use for people who do not like plugins.