Get a list of installed fonts on the device

I am trying to get a list of all the fonts installed on a device. This list is not fixed. It varies according to the system version, and also, fonts can be installed.

I have found this in Objective-C :

[code]// array
NSMutableArray *fontNames = [[NSMutableArray alloc] init];

// get font family
NSArray *fontFamilyNames = [UIFont familyNames];

// loop
for (NSString *familyName in fontFamilyNames)
NSLog(@“Font Family Name = %@”, familyName);

// font names under family
NSArray *names = [UIFont fontNamesForFamilyName:familyName];

NSLog(@“Font Names = %@”, fontNames);

// add to array
[fontNames addObjectsFromArray:names];

[fontNames release];[/code]

If I read this correctly, the method first reads all the font families, then for each family all the font names (Times Bold, Times Italic and so on I guess).

I looked at the UIFont class reference at and used Jason King’s Declare Maker to create the necessary declares.

Now I have picked up the methods from what the

[code] Shared Function FamilyNames() As NSArray
declare function familyNames_ lib UIKitLib selector “familyNames” (clsRef as ptr) as ptr
Return new NSArray(familyNames_(ClassRef))
End Function

Shared Function FontNamesForFamilyName(familyName as CFStringRef) As NSArray
declare function fontNamesForFamilyName_ lib UIKitLib selector “fontNamesForFamilyName:” (clsRef as ptr, familyName as CFStringRef) as ptr
Return new NSArray(fontNamesForFamilyName_(ClassRef, familyName))
End Function

Now I am lost.

Any help will be greatly appreciated.

If you check the class generated by Declare Maker is should have a shared method ClassRef which is simply contains:

return NSClassFromString("UIFont")[/code]
I added that feature because then you don't need to add a call to NSClassFromString for every shared/class method, you can simply use ClassRef.

(if you don't have NSClassFromString added to your project already then you will need to add:
[code]declare function NSClassFromString lib "Foundation" (clsName as CFStringRef) as ptr

If you give me a minute I should be able convert that code for you though.


[quote=162201:@Jason King]Enjoy:[/quote]

Now I see the declare for FamilyNames works the same as the Swift one in :

dim familyNamesArray as ptr = FamilyNames

Your project is a great study for me

That is wonderful, Jason. Thank you so much.

You’re welcome.