### Set Font Awesome Character

Example of using the Font Awesome character set.
References:
http://fontawesome.io
http://fontawesome.io/cheatsheet/
Option 1 for B4J versions enabling to set the font to FontAweSome in the B4J Visual Designer
Example setting the anchor as logo for a Label.
Dim LabelLogo as Label
LabelLogo.Text = Chr(0xF13D)
For use as properties in a form:
`Public Sub setLabelLogo(Value As String)
Label_Logo.Text = Value
End Sub`
`Public Sub getLabelLogo As String
Return Label_Logo.Text
End Sub`
Option 2 for older B4J versions which do not support settin the font to FontAweSome in the B4J Visual Designer
• Get the fontawesome font library file (FontAwesome.otf) and copy to the file project files folder (dir.assets).
• Add the fontawesome otf file to the B4J IDE Files Manager.
B4J Code Snippet
`Sub Process_Globals
Private Button1 As Button
'Create a global font
Private fontawesome As Font
End Sub`
`Sub SetFont
'Load the font
fontawesome = fx.LoadFont(File.DirAssets, "FontAwesome.otf", 20)
'Assign the fontawesome font to a button
Button1.Font = fontawesome
'Set the fontawesome character
'Option 1
'Set the font as text by selecting the icon and copy & paste from http://fontawesome.io/cheatsheet/
'Example Battery Half = fa-battery-half []
'Button1.Text = ""
'Option 2 using unicode - requires sub UnescapeUnicode
Button1.Text = UnescapeUnicode("\uf242")
End Sub`
`Sub UnescapeUnicode(s As String) As String
Dim sb As StringBuilder
sb.Initialize
Dim i As Int
Do While i < s.Length
Dim c As Char = s.CharAt(i)
If c = "\" And i < s.Length - 1 And s.CharAt(i + 1) = "u" Then
Dim unicode As StringBuilder
unicode.Initialize
i = i + 2
Do While i < s.Length
Dim cc As String = s.CharAt(i)
Dim n As Int = Asc(cc.ToLowerCase)
If (n >= Asc("0") And n <= Asc("9")) Or (n >= Asc("a") And n <= Asc("z")) Then
unicode.Append(s.CharAt(i))
Else
i = i - 1
Exit
End If
i = i + 1
Loop
sb.Append(Chr(Bit.ParseInt(unicode.ToString, 16)))
Else
sb.Append(c)
End If
i = i + 1
Loop
Return sb.ToString
End Sub`

Changed: 2018-05-02 15:32, Category: Fonts, File: T6C194M1404.htm, ID: 1404