Add font fallback capability and use system UI font fallback by default

The current JUCE font system seems to have no font fallback support.

I was trying to edit the juce_Fonts_mac.mm file to let it support Chinese character display:

However, it doesn’t support customized font fallback, either.

PingFang SC is the shared font on current macOS and iOS which can display the most Chinese characters, plus displaying Japanese Kana. However, its latin glyphs rendered in JUCE are too small.

Hiragino Sans GB is not available on iOS unless manually downloaded.

If possible, please just use NSFont.systemFont(ofSize: CGFloat) in this context.

I believe that fixing this is one of the big things planned for JUCE 8, though that still might be a while away.

This thread is a collection of all the times it has been discussed previously, and it also offers a few solutions:

If you draw fonts with AttributedString on macOS or Windows, it should allow font fallback.

If you want a solution where it will also work on Linux, and it will also work with default JUCE components without modifications, you might want to check out the solution I propose here, in the last post: Unicode text rendering & editing in 2022 - #25 by timothyschoen.

If you create a font that contains all unicode characters in it, you can reliably draw non-latin text anywhere you want, at the cost of more memory usage and slightly worse startup time.

3 Likes