Android Question Embedding Typeface file in library

thedesolatesoul

Expert
Licensed User
Longtime 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.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime 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

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:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime 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?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…