public static Font makeFont(String name) {
try {
if (resources.containsKey(name)) {
Object obj = resources.get(name);
if (!(obj instanceof Font)) {
throw new ChunkyException("Reference for " + name + " ended up with a bad value, " +
"suggested=" + Font.class.getName() + "; got=" + obj.getClass().getName());
} else {
return (Font) obj;
}
} else {
if (isSystemFont(name)) {
Font f = new Font(name, Font.PLAIN, 0);
resources.put(name, f);
return f;
} else {
URL url = System.class.getResource("/assets/font/" + name + ".ttf");
if (url == null) {
throw new NullPointerException("Cannot find font " + name);
} else {
Font f = Font.createFont(Font.TRUETYPE_FONT, url.openStream());
resources.put(name, f);
return f;
}
}
}
} catch (Exception ex) {
throw new ChunkyException(ex);
}
}