Android Question BCTextEngine Using Custom Fonts

bocker77

Active Member
Licensed User
Longtime User
I am trying to use a custom font with BCTextEngine but I am unable to get it to use it.

B4X:
    ' Font to use for Header
    tfOutline = Typeface.LoadFromAssets("MyFont.ttf")
'    TextEngine.CustomFonts.Put("dearest", xui.CreateFont(Typeface.LoadFromAssets("MyFont.ttf"), 10))
'    TextEngine.CustomFonts.Put("dearest",xui.CreateFont(tfOutline, 10))
    TextEngine.CustomFonts.Put("dearest",xui.CreateFont(Typeface.CreateNew(tfOutline, Typeface.STYLE_BOLD), 10))
    BBCodeView1.Text = _
$"[Alignment=Center][font=dearest size=18][b]My Header[/b][/Font][/Alignment]"$

Is this even possible and if so how do I get it to work?

BTW I am converting my monospace font "About" info in my app with this since it has Justified Alignment and other nice features. Pretty cool stuff!
 

bocker77

Active Member
Licensed User
Longtime User
Sorry I didn't make this clear but because of Justified alignment means that I can use any font that I want. So the monospace font is replaced with serif. My original problem is that I cannot get a custom font to be used. A font that I downloaded from the web.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
?
B4X:
    Dim MyFont As B4XFont
    #If B4A
    MyFont = xui.CreateFont(Typeface.LoadFromAssets("audiowide.regular.ttf"),62)
    #Else If B4J
    Dim fx As JFX
    MyFont = xui.CreateFont(fx.LoadFont(File.DirAssets,"audiowide.regular.ttf",62),62)
    #Else
    MyFont = xui.CreateFont(Font.CreateNew2("audiowide.regular.ttf",62),62)
    #End If

    TextEngine.CustomFonts.Put("MyFont", MyFont)
    BBCodeView1.TextEngine = TextEngine
    BBCodeView1.Text = $"[Alignment=Center][TextSize=30][b][Font=MyFont] My Header [/Font][/b][/TextSize][/Alignment]"$

Demo:
1657794567683.png


Example:
B4X:
    BBCodeView1.Text = _
$"[Alignment=Center][TextSize=30][b][u][Font=MyFont Size=50]This is the title [/Font][FontAwesome=0xF034/] [FontAwesome=0xF035/][/u][/b][/TextSize][/Alignment]
Emoji made of multiple "characters": 👨‍💻 and a flag: [TextSize=30][e=🇺🇳/][/TextSize]
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc fermentum elit vitae nisi faucibus, vitae lacinia turpis mattis.
....
....

1657795351816.png
 
Last edited:
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Thank you Omar my good man. That worked but I also needed to delete the bold statements around my text. I'll need to look into that as I use this font in other places in my app and am able to use bold.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Thank you Omar my good man. That worked but I also needed to delete the bold statements around my text. I'll need to look into that as I use this font in other places in my app and am able to use bold.
ok,
I leave an example in which I was studying BCToast and BCTextEngine/BBCodeView
1657824280884.png
 

Attachments

  • TEST-BCToast.zip
    35.4 KB · Views: 98
Upvote 0
Top