Android Question Embedding Typeface file in library

Discussion in 'Android Questions' started by NJDude, May 17, 2015.

  1. NJDude

    NJDude Expert Licensed User

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

    Thanks.
     
    Last edited: May 17, 2015
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Good question. Currently they are only able to be loaded from assets.
    I would like to know this too.
     
    NJDude likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    You will need to copy the file to File.DirInternal (you can do it in the library) and then call Typeface.createFromFile.
     
  4. thedesolatesoul

    thedesolatesoul Expert Licensed User

  5. DonManfred

    DonManfred Expert Licensed User

    Why should it? Erel is talking about code in JAVA. In java you can use Typeface.createFromFile
     
  6. thedesolatesoul

    thedesolatesoul Expert Licensed User

    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 likes this.
  7. NJDude

    NJDude Expert Licensed User

    TDS is correct, I'm referring to a B4A class compile to a library.
     
    Cableguy likes this.
  8. DonManfred

    DonManfred Expert Licensed User

    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: May 18, 2015
  9. Erel

    Erel Administrator Staff Member Licensed User

    You can use this sub to load a typeface from a file:
    Code:
    Sub LoadTypefaceFromFile(Dir As String, FileName As StringAs 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, NJDude and inakigarm like this.
  10. Cableguy

    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?
     
  11. NJDude

    NJDude Expert Licensed User

    Thanks Erel, but, how would I copy the ttf file embedded in the lib to the device?
     
  12. DonManfred

    DonManfred Expert Licensed User

    to access them from folders different to file.DirAssets, yes.
     
    Cableguy likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice