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.Font;
import java.awt.GraphicsEnvironment;
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);
}
int codePoint = Integer.parseInt(args[0], 16);
System.out.printf("Checking on character %s ...%n", Character.toString(codePoint));
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(codePoint)) {
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");
}
}
import java.awt.GraphicsEnvironment;
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);
}
int codePoint = Integer.parseInt(args[0], 16);
System.out.printf("Checking on character %s ...%n", Character.toString(codePoint));
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(codePoint)) {
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");
}
}