TITLE:Fontをファイルから取得
#navi(../)
*Fontをファイルから取得 [#o126bcf5]
Posted by [[terai]] at 2005-03-07

#contents

**概要 [#sb13909f]
独自フォント(mona.ttf)をファイルから読み込み、ASCII artを表示します。

-&jnlp;
-&jar;
-&zip;

#screenshot

**サンプルコード [#ibfdaff0]
#code{{
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;
}
}}

**解説 [#v308e626]
Font.createFontメソッドでフォントを作成しています。

上記のサンプルで使用しているフォントは[[モナーフォント>http://monafont.sourceforge.net/index.html]]を、ASCIIアートは2chから引用しています。

**参考リンク [#cbcb57f0]
-[[モナーフォント>http://monafont.sourceforge.net/index.html]]
-[[Swing [Archive] - Loading TYPE1 fonts with JRE 1.5.0>http://forums.sun.com/thread.jspa?threadID=518768]]

**コメント [#d9deff49]
-1.5.0_01でずれる? -- [[terai]] &new{2005-03-07 11:19:11 (月)};
-応急処置済み -- [[terai]] &new{2005-03-07 11:32:44 (月)};
- メモ:[[Bug ID: 6313541 Fonts loaded with createFont cannot be converted into FontUIResource>http://bugs.sun.com/view_bug.do?bug_id=6313541]] -- [[terai]] &new{2006-05-25 (木) 23:34:18};

#comment