TITLE:Fontをファイルから取得

Posted by at 2005-03-07

Fontをファイルから取得

独自フォント(`mona.ttf)をファイルから読み込み、ASCII art`を表示します。

  • &jnlp;
  • &jar;
  • &zip;
CreateFont.png

サンプルコード

Font makeFont(URL url) {
  Font font = null;
  InputStream is = null;
  try {
    is = url.openStream();
    font = (Font.createFont(Font.TRUETYPE_FONT, is)).deriveFont(12.0f);
    is.close();
  }catch(IOException ioe) {
    ioe.printStackTrace();
  }catch(FontFormatException ffe) {
    ffe.printStackTrace();
  }finally{
    if(is!=null) {
      try{
        is.close();
      }catch(IOException ioex) {
        ioex.printStackTrace();
      }
    }
  }
  return font;
}
View in GitHub: Java, Kotlin

解説

`Font.createFont`メソッドでフォントを作成しています。

上記のサンプルでは、モナーフォントを使用しています。

参考リンク

コメント