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 :

http://www.developerfeed.com/how-list-all-fonts-available-ios-platform

[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 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIFont_Class/ 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
[/code]

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.

Enjoy:
https://www.dropbox.com/s/nzhzde8i0zeprao/GetAvailableFonts%20.xojo_binary_project?dl=0

[quote=162201:@Jason King]Enjoy:
https://www.dropbox.com/s/nzhzde8i0zeprao/GetAvailableFonts%20.xojo_binary_project?dl=0[/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.