3

My current project uses some symbols which are absent in many fonts. So far I've found some iOS renders as a box so I'm expecting sooner or later to find one that Android can't render too, though so far it's done better than iOS in this regard.

Is there a way to programatically check that a given Unicode codepoint will display correctly on the screen and not as an empty square box etc?

If I can detect a symbol can't be rendered I can implement a workaround for it rather than display an ugly box.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
  • what symbols are being used and missing in the fonts? – Siyamed Sep 05 '17 at 05:34
  • So far I haven't found a missing one on Android but I found the new Armenian currency symbol ֏ was missing on iOS so I'm assuming that's not a one-off. – hippietrail Sep 05 '17 at 06:10
  • My co-developer has found that earlier versions of Android that I can't test does not have some of the Unicode national flag Emoijis. – hippietrail Sep 28 '17 at 04:03

2 Answers2

3

For general unicode characters you can use PaintCompat.hasGlyph.

You should still use EmojiCompat that is mentioned in ianhanniballake's answer to be able to properly render emojis.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Siyamed
  • 495
  • 2
  • 11
2

With Emoji Compat, all current Unicode characters are supported back to API 19. It can be used with Downloadable Fonts, ensuring that as additional Unicode characters become standardized, your app automatically supports them.

You can confirm if a specific character is supported by Emoji Compat with hasEmojiGlyph():

EmojiCompat.get().hasEmojiGlyph(charSequence);

Note: you must have initialized Emoji Compat before calling this.

The EmojiCompat DevByte video shows a minimal set of steps to get things working.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • The characters I'm concerned with are not Emoji. Does this still apply? – hippietrail Sep 02 '17 at 02:05
  • 1
    I added a note on the `hasEmojiGlyph()` method, which should tell you exactly what will render as boxes (if it returns false) vs rich characters. – ianhanniballake Sep 02 '17 at 02:10
  • 2
    For general unicode characters you can use PaintCompat.hasGlyph. https://developer.android.com/reference/android/support/v4/graphics/PaintCompat.html – Siyamed Sep 05 '17 at 05:32