Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if custom font can display character

I have a custom font which is displaying the box character. The font I am using does not support all languages apparently. I want to check if the String I am about to display can be displayed by my custom font. If it cannot then I want to use the standard Android font (which I know can display the characters). I can't find a method to check if my Typeface can display a particular String though. I am sure I have seen a method around that does this somewhere. Anyone know?

like image 778
timothyjc Avatar asked Aug 05 '12 09:08

timothyjc


1 Answers

As of Android version 23, You can test it like this:

Typeface typeface;
//initialize the custom font here

//enter the character to test
String charToTest="\u0978";
Paint paint=new Paint();
paint.setTypeface(typeface);
boolean hasGlyph=paint.hasGlyph(charToTest);
like image 149
Orson Baines Avatar answered Oct 30 '22 03:10

Orson Baines