Swing/CreateFont のバックアップの現在との差分(No.7)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/CreateFont へ行く。
- 1 (2005-03-07 (月) 02:07:13)
- 2 (2005-03-07 (月) 05:00:49)
- 3 (2005-03-07 (月) 10:59:12)
- 4 (2005-04-28 (木) 04:32:52)
- 5 (2005-06-20 (月) 02:30:05)
- 6 (2005-10-23 (日) 14:23:33)
- 7 (2006-02-27 (月) 15:36:10)
- 8 (2006-04-12 (水) 19:39:16)
- 9 (2006-05-25 (木) 23:34:18)
- 10 (2007-03-03 (土) 03:56:33)
- 11 (2007-03-28 (水) 19:36:28)
- 12 (2008-11-23 (日) 21:40:20)
- 13 (2013-03-30 (土) 21:26:22)
- 14 (2013-09-06 (金) 15:32:54)
- 15 (2014-02-04 (火) 14:55:12)
- 16 (2014-11-01 (土) 00:46:09)
- 17 (2014-11-25 (火) 03:03:31)
- 18 (2014-12-20 (土) 13:14:32)
- 19 (2015-03-24 (火) 16:06:39)
- 20 (2016-06-04 (土) 19:23:48)
- 21 (2017-09-15 (金) 16:45:34)
- 22 (2017-11-02 (木) 15:34:40)
- 23 (2019-03-20 (水) 16:09:50)
- 24 (2020-12-25 (金) 14:54:48)
- 25 (2022-08-20 (土) 22:15:25)
- 26 (2023-06-16 (金) 08:17:14)
- 追加された行はこの色です。
- 削除された行はこの色です。
#navi(../) *Fontをファイルから取得 [#o126bcf5] >編集者:[[Terai Atsuhiro>terai]]~ 作成日:2005-03-07~ 更新日:&lastmod; --- category: swing folder: CreateFont title: Fontをファイルから取得 tags: [Font, JTextArea] author: aterai pubdate: 2005-03-07T02:07:13+09:00 description: TrueTypeフォントをファイルから読み込み、ASCII artを表示します。 image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTKOUJYB7I/AAAAAAAAAVo/K2rl3dXD4ic/s800/CreateFont.png --- * 概要 [#summary] `TrueType`フォントをファイルから読み込み、`ASCII art`を表示します。 #contents **概要 [#sb13909f] 独自フォント(mona.ttf)をファイルから読み込み、ASCII artを表示します。 #download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTKOUJYB7I/AAAAAAAAAVo/K2rl3dXD4ic/s800/CreateFont.png) http://terai.xrea.jp/swing/createfont/screenshot.png * サンプルコード [#sourcecode] #code(link){{ Font makeFont(URL url) { Font font = null; try (InputStream is = url.openStream()) { font = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(12f); } catch (IOException | FontFormatException ex) { ex.printStackTrace(); } return font; } // Font makeFont(URL url) { // Font font = null; // InputStream is = null; // try { // is = url.openStream(); // font = (Font.createFont(Font.TRUETYPE_FONT, is)).deriveFont(12f); // 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; // } }} **サンプルコード [#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; } * 解説 [#explanation] 上記のサンプルでは、`Font.createFont(...)`メソッドで`.ttf`ファイルからフォントを作成しています。 -[[サンプルを起動>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()でフォントを作成しています。 * 参考リンク [#reference] - [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/Font.html#createFont-int-java.io.File- Font (Java Platform SE 8)] - [http://monafont.sourceforge.net/index.html モナーフォント] - [https://community.oracle.com/thread/1483177 Swing (Archive) - Loading TYPE1 fonts with JRE 1.5.0] 上記のサンプルで使用しているフォントは[[モナーフォント>http://monafont.sourceforge.net/index.html]]を、ASCIIアートは2chから引用しています。 * コメント [#comment] #comment - `JDK 1.5.0_01`でずれる? -- &user(aterai); &new{2005-03-07 11:19:11 (月)}; -- 応急処置済み -- &user(aterai); &new{2005-03-07 11:32:44 (月)}; - メモ: [https://bugs.openjdk.org/browse/JDK-6313541 Bug ID: 6313541 Fonts loaded with createFont cannot be converted into FontUIResource] -- &user(aterai); &new{2006-05-25 (木) 23:34:18}; **参考リンク [#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