0

If I want to embed custom fonts in my application I have to protect them at least in some way because the license requires this. So I cannot do something like

Typeface.createFromAsset(getAssets(),"fonts/myAwesomeFont.ttf");

On iOS is used this approach that decrypts a font on the fly and makes it available in the application. Is there a similar approach possible on Android?

My hunch is using a singleton class that handles the decryption of the raw resource file and returns the typeface on demand as I set it in code on the views. Are there better approaches out there that I missed? *Is this even possible?*

Erik
  • 834
  • 8
  • 17

2 Answers2

1

Is there a similar approach possible on Android?

Not really.

My hunch is using a singleton class that handles the decryption of the raw resource file and returns the typeface on demand as I set it in code on the views

That is not possible, as there is no way for you to create a Typeface from some byte array or stream.

You are welcome to decrypt the font file and store it locally unencrypted, then use that. Whether this is sufficient for your license terms is a question for your attorney.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So the only way to access a font is by embedding it plainly in the apk? – Erik Dec 04 '13 at 13:23
  • @Erikmitk: No. You are welcome to decrypt the font file and store it locally unencrypted, then use that. It would be encrypted in the APK, but decrypted on internal storage. Internal storage is inaccessible to normal users, though users with rooted devices could get at it. – CommonsWare Dec 04 '13 at 13:35
  • Ah, okay. Now I get what you mean. I have to make sure, but I believe that’ll do. Thanks. – Erik Dec 04 '13 at 13:44
0

you can do one thing...

encrypt your original font file using File I/O streams and save encrypted file in Assets. and when your App is installed,
then get the encrypted file using

getAssets().open(fileName);

and decrypt stream and store decrypted file (original font file) in your Appication private path for first time . and use this file for creating Typeface every time where ever you need... using

Typeface.createFromFile(File);

so your APK will contain encrypted file...

Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43