Android Question Embedding Typeface file in library

NJDude

Expert
Licensed User
Based on THIS, how do you embed a Typeface file (.ttf) in a library?

Thanks.
 
Last edited:

thedesolatesoul

Expert
Licensed User
Why should it? Erel is talking about code in JAVA. In java you can use Typeface.createFromFile
I see, I didnt realize that.
I'm probably confused but I believe NJDude is talking about creating a library from B4A class, compile to jar, then adding the ttf file to it.
Then you need to take the input stream from LoadFileFileFromJar(in the class mentioned by NJDude) and copy it.
Then you further need to use JO or Reflection to load it.
Also, Typeface.createFromFile should definitely be added to the B4A Typeface class as well.
 

DonManfred

Expert
Licensed User
I'm probably confused but I believe NJDude is talking about creating a library from B4A class, compile to jar, then adding the ttf file to it.
Then he forgot to mention that :D

I did not checked the linked thread. Now i have... But honestly i must say i did not get it... I never thought that this is the issue
 
Last edited:

Erel

Administrator
Staff member
Licensed User
You can use this sub to load a typeface from a file:
B4X:
Sub LoadTypefaceFromFile(Dir As String, FileName As String) As Typeface
   Dim jo As JavaObject
   jo.InitializeStatic("android.graphics.Typeface")
   Return jo.RunMethod("createFromFile", Array(File.Combine(Dir, FileName)))
End Sub
'usage example
Dim tf As Typeface = LoadTypefaceFromFile(File.DirRootExternal, "papercuts-2.ttf")
Label1.Typeface = tf
 

Cableguy

Expert
Licensed User
If i understand correctly, the only diference between create type face from file and typeface.load from assets is the ability to access outside folders, right?
 

NJDude

Expert
Licensed User
Thanks Erel, but, how would I copy the ttf file embedded in the lib to the device?
 
Top