Would be nice to have a set a functions to get all fonts available on the system.
Pretty sure there's an easy way to do it on Windows (probably on Mac too!), feel free to show some code if you have some

Polo wrote:Looking for a Mac solution now, seems CTFontCollectionCreateFromAvailableFonts should be used though I have no idea how
Code: Select all
EnableExplicit
ImportC ""
CFArrayGetCount(CFArrayRef.L)
CFArrayGetValueAtIndex(CFArrayRef.L, Index.L)
CFRelease(CFTypeRef.L)
CFStringGetCString(CFStringRef.L, *StringBuffer, BufferSize.L, CFStringEncoding.L)
CTFontCollectionCreateFromAvailableFonts(RemoveDuplicates.L)
CTFontCollectionCreateMatchingFontDescriptors(FontCollectionRef.L)
CTFontDescriptorCopyAttribute(FontDescriptorRef.L, AttributeStringRef.L)
EndImport
Procedure.S ConvertCFStringIntoString(CFStringRef.L)
Protected String.S = Space(256)
CFStringGetCString(CFStringRef, @String, Len(String), 0)
ProcedureReturn Trim(String)
EndProcedure
NewList FontName.S()
Define FontCollectionRef.L
Define FontCount.L
Define FontDescriptorArrayRef.L
Define FontDescriptorRef.L
Define FontDictionaryRef.L
Define FontNameRef.L
Define i.L
Define NSFontNameAttribute.L = CFStringCreateWithCString_(0, @"NSFontNameAttribute", 0)
FontCollectionRef = CTFontCollectionCreateFromAvailableFonts(0)
If FontCollectionRef
FontDescriptorArrayRef = CTFontCollectionCreateMatchingFontDescriptors(FontCollectionRef)
If FontDescriptorArrayRef
FontCount = CFArrayGetCount(FontDescriptorArrayRef)
Debug "Fonts available: " + Str(FontCount)
For i = 0 To FontCount - 1
FontDescriptorRef = CFArrayGetValueAtIndex(FontDescriptorArrayRef, i)
If FontDescriptorRef
FontNameRef = CTFontDescriptorCopyAttribute(FontDescriptorRef, NSFontNameAttribute)
If FontNameRef
AddElement(FontName())
FontName() = ConvertCFStringIntoString(FontNameRef)
CFRelease(FontNameRef)
EndIf
CFRelease(FontDescriptorRef)
EndIf
Next i
CFRelease(FontDescriptorArrayRef)
EndIf
EndIf
If FontCount > 0
OpenWindow(0, 270, 100, 280, 400, "Available fonts: " + Str(FontCount), #PB_Window_SystemMenu | #PB_Window_Invisible)
ListViewGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
SortList(FontName(), #PB_Sort_Ascending)
ForEach FontName()
AddGadgetItem(0, -1, FontName())
Next
HideWindow(0, #False)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf