Posted by terai at 2005-03-07
Fontをファイルから取得
独自フォント(mona.ttf)をファイルから読み込み、ASCII artを表示します。
サンプルコード
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;
}
解説
Font.createFontメソッドでフォントを作成しています。
上記のサンプルでは、モナーフォントを使用しています。
参考リンク
コメント
- 1.5.0_01でずれる? -- terai 2005-03-07 11:19:11 (月)
- 応急処置済み -- terai 2005-03-07 11:32:44 (月)
- メモ:Bug ID: 6313541 Fonts loaded with createFont cannot be converted into FontUIResource -- terai 2006-05-25 (木) 23:34:18