| Can character be displayed in Java |
|
|
|
| Written by Charles | |||||
| Tuesday, 16 March 2010 13:54 | |||||
|
Sometimes you need to determine if you have Java font support for a particular character in Unicode. This is what I use when I need to find out. The source code is HERE import java.awt.*;
public class CanDisplay { static String currentFontName = ""; public static void main(String[] args){ if(args.length < 1){ System.out.println("Usage: java CanDisplay <Unicode character, e.g. 0044>"); System.exit(-1); } char c = (char)Integer.parseInt(args[0],16); System.out.println("Checking on character " + c); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = ge.getAllFonts(); for(int i = 0;i < fonts.length ;i++){ String fontName = fonts[i].getFontName(); /** * Assume that if a glyph is contained in a certain typeface, * then its first font will be able to display it. Otherwise * this iteration can take a long time. */ if (fontName.equals(currentFontName)){ continue; } else { currentFontName = fontName; } if (fonts[i].canDisplay(c)){ System.out.println(fonts[i]); // Just take the first one as this iteration can take a long time! System.exit(0); } } System.out.println("Font not found"); } }
Only registered users can write comments!
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |
|||||
| Last Updated ( Tuesday, 16 March 2010 14:00 ) |



