Android Question [SOLVED] How to tell if font doesn't support character?

Computersmith64

Well-Known Member
Licensed User
Longtime User
I'm trying to add support for different currency symbols to an app. I can get the relevant symbol from the locale (using the AHLocale library), but some users have asked for the ability to select a different symbol.

I have a list of unicode currency symbols & can load them into a listview using Chr(unicode) or use CSBuilder to create them, however some of them aren't supported by the various fonts I've tried. What ends up happening is that I either end up with a blank item or a rectangular character in the listview.

So how do I tell if the font I'm using can support the unicode char I'm trying to use? I've tried testing for null & for "", but I still end up with them in the listview. If I could tell that the char isn't supported, then I could simply not load it into the listview...

- Colin.
 

udg

Expert
Licensed User
Longtime User
I know this doesn't reply to your question, but maybe it could be of some help.
Read about ISO 4217 coding.
As reported here, it seems that currency symbols in Unicode are just a few and they may differ from font to font.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Thanks udg - you're right, that wasn't a lot of help! :p However I did manage to solve it using this inline Java function:

B4X:
public boolean isPrintable(String c) {
    import android.graphics.Paint;
    import android.graphics.Rect;
   
    Paint paint = new Paint();
    Rect rtt = new Rect();
    paint.getTextBounds(c, 0, 1, rtt );
    if (rtt.width() == 0) {
        return false;
    }
    return true;
}

There are other ways of doing it using Java, but this function will work with APIs older than 23.

- Colin.
 
  • Like
Reactions: udg
Upvote 0
Top