Hey guys!
I had an issue lately in a Scrabble game I’ve been making and after 2 days I still haven’t found the answer to it.
I basically need to load a Font from file and then transform it into a TrueTypeFont thanks to slick-util so I can use it in my OpenGL context. The issue is that actually creating the java.awt.Font itself takes about 5(!) seconds to be completed which is obviously very frustrating when debugging/developing the game.
Here is the relevant excerpt:
try(InputStream in = getClass().getResourceAsStream(FONT_DIR + fontName + FONT_EXT))
{
long startTime = System.nanoTime();
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, in); //<-- This operation takes about 5 seconds
System.out.println("Operation took: " + (System.nanoTime() - startTime) / 1000000);
awtFont = awtFont.deriveFont(fontSize);
result = new TrueTypeFont(awtFont, antiAlias);
}
Do you guys know any alternative to my approach? Is there a faster way to load a Font from file or am I doing something terribly wrong?
Thanks for your time!
Alex