Font lookupFont(char text[], int start, int limit, int style) {
        /* Try using an already known base font; the first font in usedFonts list is the one set with setDefaultFont() */
        Iterator<Font> iterator = usedFonts.iterator();
        while (iterator.hasNext()) {
            /* Only use the font if it can layout at least the first character of the requested string range */
            Font font = iterator.next();
            if (font.canDisplayUpTo(text, start, limit) != start) {
                /* Return a font instance of the proper point size and style; usedFonts has only 1pt sized plain style fonts */
                return font.deriveFont(style, fontSize);
            }
        }

        /* If still not found, try searching through all fonts installed on the system for the first that can layout this string */
        iterator = allFonts.iterator();
        while (iterator.hasNext()) {
            /* Only use the font if it can layout at least the first character of the requested string range */
            Font font = iterator.next();
            if (font.canDisplayUpTo(text, start, limit) != start) {
                /* If found, add this font to the usedFonts list so it can be looked up faster next time */
                System.out.println("BetterFonts loading font \"" + font.getFontName() + "\"");
                usedFonts.add(font);

                /* Return a font instance of the proper point size and style; allFonts has only 1pt sized plain style fonts */
                return font.deriveFont(style, fontSize);
            }
        }

        /* If no supported fonts found, use the default one (first in usedFonts) so it can draw its unknown character glyphs */
        Font font = usedFonts.get(0);

        /* Return a font instance of the proper point size and style; usedFonts only 1pt sized plain style fonts */
        return font.deriveFont(style, fontSize);
    }