android - how to detect which language fonts are supported by device? -


say, want display list of 10 languages in native scripts, , if phone doesn't support font fall english script. there way can detect fonts supported particular device? in other words, want check whether, say, "punjabi" can displayed "ਪੰਜਾਬੀ"

to on safe side, use both english , native name (and did). please take pity on poor guy seeing these فارسی 贛語 ગુજરાતી Հայերեն हिन्दी বিষ্ণুপ্রিয়া মণিপুরী עברית ಕನ್ನಡ ქართული ລາວ مصرى नेपाल भाषा Олык марий ភាសាខ្មែរ Српски தமிழ் 文言 ייִדיש 中文 in native scripts only!

you can try draw text bitmap , check whether or not resulting bitmap blank. e.g. http://www.skoumal.net/en/android-how-draw-text-bitmap , how check if bitmap empty (blank) on android (of course, assuming unsupported letters not shown black diamonds or that).

class util {     private static final int width_px = 200;     private static final int height_px = 80;      public static boolean issupported(context context, string text) {         int w = width_px, h = height_px;         resources resources = context.getresources();         float scale = resources.getdisplaymetrics().density;         bitmap.config conf = bitmap.config.argb_8888;         bitmap bitmap = bitmap.createbitmap(w, h, conf); // creates mutable bitmap         bitmap orig = bitmap.copy(conf, false);         canvas canvas = new canvas(bitmap);         paint paint = new paint(paint.anti_alias_flag);         paint.setcolor(color.rgb(0, 0, 0));         paint.settextsize((int) (14 * scale));          // draw text canvas center         rect bounds = new rect();         paint.gettextbounds(text, 0, text.length(), bounds);         int x = (bitmap.getwidth() - bounds.width()) / 2;         int y = (bitmap.getheight() + bounds.height()) / 2;          canvas.drawtext(text, x, y, paint);         boolean res = !orig.sameas(bitmap);         orig.recycle();         bitmap.recycle();         return res;     } } 

testing code:

    string s;     s="";log.d("~~~","=="+s+"=="+util.issupported(this, s));     s="中文";log.d("~~~","=="+s+"=="+util.issupported(this, s));     s="ਪੰਜਾਬੀ";log.d("~~~","=="+s+"=="+util.issupported(this, s));     s="Հայերեն";log.d("~~~","=="+s+"=="+util.issupported(this, s)); 

output:

 ====false  ==中文==true  ==ਪੰਜਾਬੀ==false  ==Հայերեն==true 

ps if want show both english , native name in same string, can either check native name may displayed before composing string both names, or remove latin characters:

public static string striplatin(string s) {     string res = "";     (int = 0; < s.length(); i++) {         if (s.charat(i) > 127) {             res += s.charat(i);         }     }     return res; } 

testing code:

s="punjabi(ਪੰਜਾਬੀ)";log.d("~~~","=="+s+"=="+util.issupported(this, util.striplatin(s))); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -