Java Question Fonts & Typeface.createFromAsset

tchart

Well-Known Member
Licensed User
Longtime User
All, another question about wrapping libraries with resources. This one has to do with fonts.

The library Im trying to wrap has the following code in it;

B4X:
Typeface t = Typeface.createFromAsset(c.getAssets(), String.format("fonts/%s.ttf", name));

I get an error stating that it cant find the font file. The problem from what I can see is that the library Java code is expecting the font to be in the "fonts" sub-folder. I've tried altering the code to look in the root resources folder but that didnt work either.

In the end I altered the code to be this, which works;

B4X:
Typeface t = Typeface.createFromAsset(BA.applicationContext.getAssets(), String.format("%s.ttf", name).toLowerCase(BA.cul));

This relies on B4A to create the font which is fine but I would like to remove the need for me to alter any code from the original library source code.

Is there a trick I need to know about loading the font correctly?
 

tchart

Well-Known Member
Licensed User
Longtime User
Thanks Erel, yes I tried that too. I think maybe the context under which it tries to load the fonts must be different or something.
 

tchart

Well-Known Member
Licensed User
Longtime User
Manfred, you are a legend.

Added fonts to ..\files\fonts folder and altered code to lowercase the font name.

Typeface t = Typeface.createFromAsset(c.getAssets(), String.format("fonts/%s.ttf", name).toLowerCase());
 

DonManfred

Expert
Licensed User
Longtime User
What i meant to say was that you should copy only lowercased filenames into the assets (and it´s subfolders) instead of
doing a
B4X:
.toLowerCase()
as it is not needed to change the code if folder and filenames are lowercase. Your goal was to suppress the needs to change the original code or not?
 

tchart

Well-Known Member
Licensed User
Longtime User
DonManfred b4a lower cases the font file names. The problem is actually that library developer has hard coded the font names in mixed case. So I have to lower case them in his helper function. I've asked him if he can lower case the font names but he said no.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…