I use FontAwesome to generate icons in my app. The font is temporarily installed during each runtime. I tried drawing Font awesome glyphs onto a canvas, but didn’t work (didn’t give it much time). Works like a charm for text properties of labels.
Has anyone else worked with custom fonts (Font Awesome for example) and managed to load the glyphs onto a canvas?
I use several custom-made custom fonts and I do not have any problem applying them to labels, canvases or whatever (but not manuItems). Search for ‘custom fonts’ on this forum and you will find ways to “install” them on Mac, Windows and Linus. For instance, on Mac, I put my fonts in a folder named “FontsforMac”, and to be able to use them in a project I need only this entry in the plist:
ATSApplicationFontsPath
FontsForMac/
In one of posts (Two ways to install, dated 2022) you may find also a post with a .zip file showing how to deal for Mac, Windows and Linus.
I’ve worked with Font Awesome in Xojo too. Make sure the font name is correct in your code, as even a small mistake can cause issues. Also, check if you’re using the right Unicode point for the icon when drawing on the canvas.
I have no problem installing them via runtime, as stated above. They also work like a charm on labels, I have not spent any proper time drawing custom fonts on a canvas, will try tonight and see how it goes
So again, the issue is not with installing the fonts or using fontawesome, just didn’t get it to work on a canvas… but will try again, will pay attention to the right unicode / textfont property / drawtext… highly appreciate the feedback ya all
Turned out to be straightforward, for anyone planning to use a custom font with the canvas:
Sub Paint(g As Graphics, areas() As Rect) Handles Paint
#PRAGMA unused areas
Const kMargin = 20
Var wrapCheck as Boolean = true // Wrap the text or not
g.ClearRect(0, 0, g.Width, g.Height)
// Set font and font properties
g.FontName = "Font Awesome 6 Pro Light"
g.FontSize = 20
g.DrawingColor = Color.TextColor
g.Bold = true
g.Underline = false
g.Italic = false
// draw the string
Var wrapValue As Integer
If wrapCheck Then
wrapValue = Me.Width - kMargin
Else
wrapValue = 0
End If
g.DrawText("thumbs-up", kMargin, kMargin, wrapValue)
End Sub
And here is a great example how to define custom App fonts :