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");
    }

}

