*
* @return Font The Font object
*/
static public Font loadfont(String fontname) {
Font font = new Font();
Properties fontprops = new Properties();
// FileInputStream in;
InputStream in;
in = FontUtils.class.getResourceAsStream("/fonts/" + fontname + "/font.txt");
if (in == null) {
return null;
}
try {
fontprops.load(in);
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
finally {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
font.setMaxwidth(Integer.parseInt(fontprops.getProperty("maxwidth")));
font.setMaxheight(Integer.parseInt(fontprops.getProperty("maxheight")));
font.setX(Integer.parseInt(fontprops.getProperty("x")));
font.setY(Integer.parseInt(fontprops.getProperty("y")));
font.setOldfont(Integer.parseInt(fontprops.getProperty("oldfont")));
font.setFcols(Integer.parseInt(fontprops.getProperty("fcols")));
font.setFrows(Integer.parseInt(fontprops.getProperty("frows")));
for (int i = 0; i < 256; i++) {
in = FontUtils.class.getResourceAsStream("/fonts/" + fontname + "/glyph." + i);
if (in == null) {
font.addGlyph(null);
continue;
}
Properties gprops = new Properties();
try {
gprops.load(in);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
try {
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
continue;
}
Glyph g = new Glyph();
g.setWidth(Integer.parseInt(gprops.getProperty("width")));
g.setHeight(Integer.parseInt(gprops.getProperty("height")));
g.setX(Integer.parseInt(gprops.getProperty("x")));
g.setY(Integer.parseInt(gprops.getProperty("y")));
g.setXadd(Integer.parseInt(gprops.getProperty("xadd")));
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
InputStream is = FontUtils.class.getResourceAsStream("/fonts/" + fontname + "/glyph_bmap." + i);
g.setBmap(getBytesFromInputStream(is, g.getWidth() * g.getHeight()));
// g.setBmap(getBytesFromFile(new File("fonts/" + fontname + "/glyph_bmap." + i)));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
font.addGlyph(g);
}
return font;
}