#navi(../)
*Fontをファイルから取得 [#o126bcf5]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2005-03-07~
更新日:&lastmod;

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

http://terai.xrea.jp/swing/createfont/screenshot.png

**サンプルコード [#ibfdaff0]
 private static Font makeFont(String resourcePath) {
   Font font = null;
   InputStream is = null;
   try {
     is = MainPanel.class.getResourceAsStream(resourcePath);
     font = (Font.createFont(Font.TRUETYPE_FONT, is)).deriveFont(12.0f);
     is.close();
   }catch(IOException ioe) {
     ioe.printStackTrace();
     throw new InternalError(ioe.getMessage());
   }catch(FontFormatException ffe) {
     ffe.printStackTrace();
     throw new InternalError(ffe.getMessage());
   }finally{
     if(is!=null) {
       try{
         is.close();
       }catch(IOException ioex) {
         ioex.printStackTrace();
         throw new InternalError(ioex.getMessage());
       }
     }
   }
   return font;
 }

-[[サンプルを起動>http://terai.xrea.jp/swing/createfont/sample.jnlp]]
-[[jarファイル>http://terai.xrea.jp/swing/createfont/sample.jar]]
-[[ソース>http://terai.xrea.jp/swing/createfont/src.zip]]
**解説 [#v308e626]
Font.createFont()でフォントを作成しています。

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

**参考リンク [#cbcb57f0]
-[[モナーフォント>http://monafont.sourceforge.net/index.html]]
-[[Java Forums - Loading TYPE1 fonts with JRE 1.5.0>http://forum.java.sun.com/thread.jspa?forumID=57&threadID=518768]]
**コメント [#d9deff49]
-1.5.0_01でずれる? -- [[terai]] &new{2005-03-07 11:19:11 (月)};
-応急処置済み -- [[terai]] &new{2005-03-07 11:32:44 (月)};

#comment