Improving Fonts on Android


The state of fonts is pretty bad on Android. The usual APIs seem to be simply non-existent. After five years of Android development, there is still no way to iterate through an Android Graphics Path (hence your use of Edge Tables). You also can’t enumerate fonts though I guess they consider that a non-issue since there are usually only 3 fonts installed by default and no way to add fonts OS-wide without rooting.

The only option I see to get some decent font support is bypass it completely by using FreeType. I plan on rewriting juce_android_Fonts.cpp to do this. You already wrote almost all of the code in juce_linux_Fonts.cpp so this shouldn’t be too hard.

I was wondering if you would be willing to put such changes into the tip? This would add a dependency on FreeType, though that is not unprecendented the Linux code has always depended on that. Maybe a compromise would be having both (current android code + freetype android code) sets of code with ifdefs?


Yes, it’s odd how some basic things like this seem to still be missing on android!

You’re right that FT is probably the only way to do a better job of it. My main reasons for avoiding going down that route were to avoid bloating the binary, and because I’d have to look into the licensing issues.


Implementing this turned out to be quite easy and clean thanks to existing code. It was just a matter of combining TheVinn’s FreeTypeAmalgamation with your code in juce_linux_Fonts.cpp.

As for bloat, here are the source code numbers:
FreeTypeAmalgam.h - 586.998 kb
FreeTypeAmalgam.c - 5564.115 kb

Not small but I still think it is worth it.

As for licensing:

Doesn’t really get much better than that (well other than public domain).

So would you be willing at least to at least have both code paths (current Android native code path + new FreeType android code path) in juce_android_Fonts.cpp? If yes, I can send you my changes.


Yes - I’d certainly be interested in having it as an option (sorry, I think my reply sounded more negative than I intended!)


Bringing in the FreeType sources (using my amalgamation or otherwise) is probably not such a hot idea, since Android already has the FreeType shared library built in unless I am mistaken?

It should be possible to use the FreeType library built in to Android.

As far as licensing or dependency issues, there are none. Android/Linux builds already have a pile of deps, one more won’t break the bank.


Great! I’ll send a diff over.

Android does have FreeType but it is not developer accessible and could change between Android versions. Bringing in FreeType is the only option.

“If you need FreeType (a library to render fonts), you’ll need to cross-compile it. The Android system uses FreeType but internally it doesn’t expose it to native apps.” -
"The library isn’t exposed by the NDK (and wasn’t even exposed by the system last time I looked, it is statically linked into another library, without exported symbols), so instead link a custom version to your app." -!topic/android-ndk/ASe_nISofzU


I'd like to get my chosen fonts working on Android.

Has anyone got any code examples for using FreeType like this, either cross-compiling FreeType or using the FreeTypeAmalgamation library?


EDIT: OK I found JUCE_USE_FREETYPE, looks like everything is now in JUCE ...  I guess I need to be using TrueType fonts.