package de.gurkenlabs.litiengine.resources;

import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

import de.gurkenlabs.litiengine.util.io.FileUtilities;

public final class Fonts extends ResourcesContainer<Font> {
  private static final Logger log = Logger.getLogger(Fonts.class.getName());

  Fonts() {
  }

  /***
   * Loads a custom font with the specified name from game's resources and registers it on the <code>GraphicsEnvironment</code>.
   * As a fallback, when no font could be found by the specified <code>fontName</code>, it tries to get the font from the environment by calling.
   *
   * @param resourceName
   *          The name of the font
   * @return The loaded font.
   * 
   * @see GraphicsEnvironment#registerFont(Font)
   * @see Font#createFont(int, java.io.File)
   * @see Font#getFont(String)
   */
  @Override
  protected Font load(String resourceName) {
    try {
      final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

      final InputStream fontStream = FileUtilities.getGameResource(resourceName);
      if (fontStream == null) {
        log.log(Level.SEVERE, "font {0} could not be loaded", resourceName);
        return null;
      }

      final Font font = Font.createFont(Font.TRUETYPE_FONT, fontStream);
      ge.registerFont(font);
      return font;
    } catch (final FontFormatException | IOException e) {
      log.log(Level.SEVERE, e.getMessage(), e);
    }

    return Font.getFont(resourceName);
  }
}

@@ -101,45 +101,8 @@
 on;%0A
-import java.awt.GraphicsEnvironment;%0A
 impo
@@ -117,32 +117,32 @@
 io.IOException;%0A
+
 import java.io.I
@@ -511,65 +511,8 @@
 rces
- and registers it on the %3Ccode%3EGraphicsEnvironment%3C/code%3E
 .%0A  
@@ -760,57 +760,8 @@
  * %0A
-   * @see GraphicsEnvironment#registerFont(Font)%0A
    *
@@ -909,97 +909,8 @@
 y %7B%0A
-      final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();%0A%0A
     
@@ -1136,25 +1136,14 @@
     
-final Font font =
+return
  Fon
@@ -1192,56 +1192,8 @@
 m);%0A
-      ge.registerFont(font);%0A      return font;%0A
     

Improve font loading performance