java.awt.Font issue

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

Why is 5 seconds such a big deal? Hopefully you’re only doing this once at the very beginning, and not more than once…

Indeed it is not a big deal, I was just wondering if anyone knew a way to avoid this delay especially when
with often building and running the project these 5 seconds tend to be an annoyance. Of course I could just
load a default font when debugging and just add the final font later. That is what I’ll do if it turns out there is
no other way around this :slight_smile: