Android Question B4X BCTextengine custom font

james_sgp

Active Member
Licensed User
Longtime User
Hi,
I`m using BCtextengine on a B4X app, all is working well in B4A, but I`m getting an error in B4i "Object was not initialized (UIFont)"

The font file is in the Special directory, I`m using the fonts name without spaces as shown in the attached picture.

Appreciate any advice as this is killing my B4i apps release šŸ˜­

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #ATSEnabled: True
    #MinVersion: 8
    
    #AppFont: ocfont1-regular.ttf
        
#End Region


#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region40

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    
    Public TE As BCTextEngine
    Private BBCodeView1 As BBCodeView

End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")

    TE.CustomFonts.Put("MyFont", xui.CreateFont(Font.CreateNew2("OCFont1", 40), 40))

    '[font=MyFont size=30]e[/font]
    BBCodeView1.Text = $"[indent=-1][Alignment=Left][TextSize=14][list]
[*][Color=#e1e3e7][b]Don't take[/b] anything that belongs in the ocean[/color]
[*][Color=#e1e3e7][b]Leave all[/b] marine life in the ocean, where they belong[/color]
[*][Color=#e1e3e7]Say [b]NO[/b] to single-use plastics[/color]"$

End Sub
 

Attachments

  • Screenshot 2023-02-04 082903.jpg
    Screenshot 2023-02-04 082903.jpg
    23.3 KB · Views: 75

mcqueccu

Well-Known Member
Licensed User
Longtime User
I use to have that problem when I pick the names from the font file until I came across this subroutine that checks for the actual name of the font.

Check post #6,

 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Thanks for the suggestion, i have tried that and it shows my "OC Font1" has "OCFont1-Regular" in it...
Using that in my code, still gives the same error as post #1

B4X:
    TE.CustomFonts.Put("MyFont", xui.CreateFont(Font.CreateNew2("OCFont1-Regular", 40), 40))

In case it makes a difference, I am running it on a local builder.
 

Attachments

  • Screenshot 2023-02-04 134351.jpg
    Screenshot 2023-02-04 134351.jpg
    8.3 KB · Views: 80
Upvote 0

MicroDrie

Well-Known Member
Licensed User
In case it makes a difference, I am running it on a local builder.
The font file is in the Special directory, I`m using the fonts name without spaces as shown in the attached picture.
I can't find a TTF font with the name of ocfont1, so i think that the is renamed with a short name. If your font is used with a css file, you will find a css line with a reference to the font location like something like this code:
TTF source location:
src: url("../../special/ocfont1-regular.ttf") format("truetype");
Especially when you talk about a 'special' directory, it is important that in that case you build up the CSS and the special font directories in such a way that they can be reached via a relative reference and not an absolute reference if your use a css file.
Another possibility is that your builder breaks this relationship by moving files in a particular order.

update: Do you use the obfuscated option in release mode or not?
 
Last edited:
Upvote 0
Top