Beispiel #1
0
  public FileHandle getTTFSafely(String fontName) throws IOException {
    FontManager fontManager = facade.retrieveProxy(FontManager.NAME);

    ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
    String expectedPath = projectManager.getFreeTypeFontPath() + File.separator + fontName + ".ttf";
    FileHandle expectedFile = Gdx.files.internal(expectedPath);
    if (!expectedFile.exists()) {
      // let's check if system fonts fot it
      HashMap<String, String> fonts = fontManager.getFontsMap();
      if (fonts.containsKey(fontName)) {
        File source = new File(fonts.get(fontName));
        FileUtils.copyFile(source, expectedFile.file());
        expectedFile = Gdx.files.internal(expectedPath);
      } else {
        throw new FileNotFoundException();
      }
    }

    return expectedFile;
  }