コード例 #1
0
ファイル: ResourceManager.java プロジェクト: kulgan/overlap2d
  public void prepareEmbeddingFont(String fontfamily, int fontSize) {
    flushAllUnusedFonts();

    if (isFontLoaded(fontfamily, fontSize)) {
      return;
    }

    FontManager fontManager = facade.retrieveProxy(FontManager.NAME);

    FreeTypeFontGenerator.FreeTypeFontParameter parameter =
        new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = fontSize;

    FreeTypeFontGenerator generator =
        new FreeTypeFontGenerator(fontManager.getTTFByName(fontfamily));
    BitmapFont font = generator.generateFont(parameter);

    addBitmapFont(fontfamily, parameter.size, font);
  }
コード例 #2
0
ファイル: ResourceManager.java プロジェクト: kulgan/overlap2d
  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;
  }