Platforms to show: All Mac Windows Linux Cross-Platform
/MacCG/CoreText/CoreText Font Change Notification
Required plugins for this example: MBS MacCF Plugin, MBS MacCG Plugin, MBS Main Plugin, MBS MacBase Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/CoreText/CoreText Font Change Notification
This example is the version from Wed, 18th Jan 2022.
Project "CoreText Font Change Notification.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
//-------------------------------------------------
// NSNotificationObserver
// "ATS_DB_Chenged"
//-------------------------------------------------
DefaultObserver = new MyNSNotificationObserverMBS
//NSDistributedNotificationCenterMBS.defaultCenter.addObserver(DefaultObserver) // listen for all
NSDistributedNotificationCenterMBS.defaultCenter.addObserver(DefaultObserver, "ATS_DB_Changed", nil) // listen for our sender
myFontDic = New Dictionary
End EventHandler
Property defaultObserver As MyNSNotificationObserverMBS
Property myFontDic As Dictionary
End Class
Class Window1 Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub ExpandRow(row As Integer)
dim d as Dictionary = me.CellTag(row,0)
if d<>Nil then
for each key as Variant in d.keys
dim value as Variant = d.Value(key)
me.AddRow key.StringValue +" -> "+value.StringValue
next
end if
End EventHandler
End Control
EventHandler Sub Open()
//-------------------------------------------------
// Display For now
//-------------------------------------------------
GetFontList()
ListBoxUpdate()
End EventHandler
Sub GetFontList()
//-------------------------------------------------
// Get Fonts --> to Dictionary
//-------------------------------------------------
App.myFontDic.Clear
Dim availablePostScriptNames() as string = CoreTextMBS.AvailablePostScriptNames
For Each name As String In availablePostScriptNames
Dim ctFont As CTFontMBS = CTFontMBS.CreateWithName(name)
App.myFontDic.Value(ctFont.DisplayName) = ctFont.PostScriptName
Next
End Sub
Sub ListBoxUpdate()
window1.List.RemoveAllRows
For Each key As String in App.myFontDic.Keys
window1.List.AddRow(key, App.myFontDic.Value(key))
next
End Sub
Property DefaultObserver As MyNSNotificationObserverMBS
End Class
Class MyNSNotificationObserverMBS Inherits NSNotificationObserverMBS
EventHandler Sub GotNotification(notification as NSNotificationMBS)
Window1.GetFontList()
Window1.ListBoxUpdate()
End EventHandler
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project
See also:
The items on this page are in the following plugins: MBS MacCG Plugin.