Awt-font
AWTフォントクラス
前書き
Fontクラスは、目に見える方法でテキストをレンダリングするために使用されるフォントを記述します。
クラス宣言
以下は、 java.awt.Font クラスの宣言です。
public class Font
extends Object
implements Serializable
フィールド
*java.awt.geom.Arc2D* クラスのフィールドは次のとおりです。
- static int BOLD -太字スタイルの定数。
- static int CENTER_BASELINE -テキストをレイアウトするときに中国語、日本語、韓国語などの表意文字スクリプトで使用されるベースライン。
- static String DIALOG -論理フォント「Dialog」の標準ファミリ名の文字列定数。
- static String DIALOG_INPUT -論理フォント「DialogInput」の標準ファミリ名の文字列定数。
- static int HANGING_BASELINE -テキストをレイアウトするときにDevanigiriおよび同様のスクリプトで使用されるベースライン。
- static int ITALIC -イタリック体のスタイル定数。
- static int LAYOUT_LEFT_TO_RIGHT -テキストが左から右にBidi分析で決定されたことを示すlayoutGlyphVectorへのフラグ。
- static int LAYOUT_NO_LIMIT_CONTEXT -指定された制限の後のchar配列のテキストを検査しないことを示すlayoutGlyphVectorのフラグ。
- static int LAYOUT_NO_START_CONTEXT -指定された開始前のchar配列内のテキストを検査しないことを示すlayoutGlyphVectorへのフラグ。
- static int LAYOUT_RIGHT_TO_LEFT -BIDI分析で決定されたテキストが右から左であることを示すlayoutGlyphVectorへのフラグ。
- static String MONOSPACED -論理フォント「Monospaced」の標準ファミリ名の文字列定数。
- protected String name -コンストラクターに渡される、このFontの論理名。
- static int PLAIN -プレーンスタイルの定数。
- protected float pointSize -このFontのポイントサイズ(float)。
- static int ROMAN_BASELINE -テキストをレイアウトするときにほとんどのローマ字スクリプトで使用されるベースライン。
- static String SANS_SERIF -論理フォント「SansSerif」の標準的なファミリ名の文字列定数。
- static String SERIF -論理フォント「Serif」の標準的なファミリ名の文字列定数。
- protected int size -整数値に丸められたこのFontのポイントサイズ。
- protected int style -コンストラクターに渡されるこのFontのスタイル。
- static int TRUETYPE_FONT -タイプTRUETYPEのフォントリソースを識別します。
- static int TYPE1_FONT -タイプTYPE1のフォントリソースを識別します。
クラスコンストラクター
S.N. | Constructor & Description |
---|---|
1 |
protected Font() () 指定されたフォントから新しいフォントを作成します。 |
2 |
Font(Map<? extends AttributedCharacterIterator.Attribute,?> attributes) 指定されたフォントから新しいフォントを作成します。 |
3 |
Font(String name, int style, int size) 指定されたフォントから新しいフォントを作成します。 |
クラスメソッド
S.N. | Method & Description |
---|---|
1 |
boolean canDisplay(char c) このFontに指定された文字のグリフがあるかどうかを確認します。 |
2 |
boolean canDisplay(int codePoint) このFontに指定された文字のグリフがあるかどうかを確認します。 |
3 |
int canDisplayUpTo(char[] text, int start, int limit) このFontが指定されたテキストの文字をstartで始まりlimitで終わるように表示できるかどうかを示します。 |
4 |
int canDisplayUpTo(CharacterIterator iter, int start, int limit) このFontがstartで始まりlimitで終わるiterによって指定されたテキストを表示できるかどうかを示します。 |
5 |
int canDisplayUpTo(String str) このFontが指定された文字列を表示できるかどうかを示します。 |
6 |
static Font createFont(int fontFormat, File fontFile) 指定されたフォントタイプと指定されたフォントファイルを使用して新しいフォントを返します。 |
7 |
static Font createFont(int fontFormat, InputStream fontStream) 指定されたフォントタイプと入力データを使用して新しいフォントを返します。 |
8 |
GlyphVector createGlyphVector(FontRenderContext frc, char[] chars) このFontのUnicode cmapに基づいて文字を1対1のグリフにマッピングすることにより、GlyphVectorを作成します。 |
9 |
GlyphVector createGlyphVector(FontRenderContext frc, CharacterIterator ci) このFontのUnicode cmapに基づいて、指定された文字をグリフに1対1でマッピングすることにより、GlyphVectorを作成します。 |
10 |
GlyphVector createGlyphVector(FontRenderContext frc, int[] glyphCodes) このFontのUnicode cmapに基づいて文字を1対1のグリフにマッピングすることにより、GlyphVectorを作成します。 |
11 |
GlyphVector createGlyphVector(FontRenderContext frc, String str) このFontのUnicode cmapに基づいて文字を1対1のグリフにマッピングすることにより、GlyphVectorを作成します。 |
12 |
static Font decode(String str) str引数が記述するFontを返します。 |
13 |
Font deriveFont(AffineTransform trans) 現在のFontオブジェクトを複製して新しい変換を適用することにより、新しいFontオブジェクトを作成します。 |
14 |
Font deriveFont(float size) 現在のFontオブジェクトを複製して新しいサイズを適用することにより、新しいFontオブジェクトを作成します。 |
15 |
Font deriveFont(int style) 現在のFontオブジェクトを複製して新しいスタイルを適用することにより、新しいFontオブジェクトを作成します。 |
16 |
Font deriveFont(int style, AffineTransform trans) このFontオブジェクトを複製し、新しいスタイルと変換を適用することにより、新しいFontオブジェクトを作成します。 |
17 |
Font deriveFont(int style, float size) このFontオブジェクトを複製し、新しいスタイルとサイズを適用することにより、新しいFontオブジェクトを作成します。 |
18 |
Font deriveFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes) 現在のFontオブジェクトを複製し、新しいフォント属性のセットを適用することにより、新しいFontオブジェクトを作成します。 |
19 |
boolean equals(Object obj) このFontオブジェクトを指定されたObjectと比較します。 |
20 |
protected void finalize() ネイティブのFontオブジェクトを破棄します。 |
21 |
Map<TextAttribute,?> getAttributes() このFontで利用可能なフォント属性のマップを返します。 |
22 |
AttributedCharacterIterator.Attribute[] getAvailableAttributes() このFontがサポートするすべての属性のキーを返します。 |
23 |
byte getBaselineFor(char c) このキャラクターの表示に適したベースラインを返します。 |
24 |
String getFamily() このFontのファミリ名を返します。 |
25 |
String getFamily(Locale l) 指定されたロケールにローカライズされた、このFontのファミリ名を返します。 |
26 |
static Font getFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes) 属性に適したフォントを返します。 |
27 |
static Font getFont(String nm) システムプロパティリストからFontオブジェクトを返します。 |
28 |
static Font getFont(String nm, Font font) システムプロパティリストから指定されたフォントを取得します。 |
29 |
String getFontName() このFontのフォントフェイス名を返します。 |
30 |
String getFontName(Locale l) 指定されたロケールにローカライズされた、フォントのフォントフェイス名を返します。 |
31 |
float getItalicAngle() このFontの斜体の角度を返します。 |
32 |
LineMetrics getLineMetrics(char[] chars, int beginIndex, int limit, FontRenderContext frc) 指定された引数で作成されたLineMetricsオブジェクトを返します。 |
33 |
LineMetrics getLineMetrics(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc) 指定された引数で作成されたLineMetricsオブジェクトを返します。 |
34 |
LineMetrics getLineMetrics(String str, FontRenderContext frc) 指定されたStringおよびFontRenderContextで作成されたLineMetricsオブジェクトを返します。 |
35 |
LineMetrics getLineMetrics(String str, int beginIndex, int limit, FontRenderContext frc) 指定された引数で作成されたLineMetricsオブジェクトを返します。 |
36 |
Rectangle2D getMaxCharBounds(FontRenderContext frc) 指定されたFontRenderContextで定義されている最大境界を持つ文字の境界を返します。 |
37 |
int getMissingGlyphCode() このFontに指定されたUnicodeコードポイントのグリフがない場合に使用されるglyphCodeを返します。 |
38 |
String getName() このFontの論理名を返します。 |
39 |
int getNumGlyphs() このFontのグリフの数を返します。 |
40 |
java.awt.peer.FontPeer getPeer() 廃止予定です。 フォントのレンダリングはプラットフォームに依存しなくなりました。 |
41 |
String getPSName() このFontのポストスクリプト名を返します。 |
42 |
int getSize() 整数に丸められた、このFontのポイントサイズを返します。 |
43 |
float getSize2D() このFontのポイントサイズをfloat値で返します。 |
44 |
Rectangle2D getStringBounds(char[] chars, int beginIndex, int limit, FontRenderContext frc) 指定されたFontRenderContextの指定された文字配列の論理境界を返します。 |
45 |
Rectangle2D getStringBounds(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc) 指定されたFontRenderContextの指定されたCharacterIteratorでインデックス付けされた文字の論理境界を返します。 |
46 |
Rectangle2D getStringBounds(String str, FontRenderContext frc) 指定されたFontRenderContextの指定された文字列の論理境界を返します。 |
47 |
Rectangle2D getStringBounds(String str, int beginIndex, int limit, FontRenderContext frc) 指定されたFontRenderContextの指定された文字列の論理境界を返します。 |
48 |
int getStyle() このFontのスタイルを返します。 |
49 |
AffineTransform getTransform() このFontに関連付けられた変換のコピーを返します。 |
50 |
int hashCode() このフォントのハッシュコードを返します。 |
51 |
boolean hasLayoutAttributes() このFontに追加のレイアウト処理を必要とする属性が含まれる場合、trueを返します。 |
52 |
boolean hasUniformLineMetrics() このFontに均一な行メトリックがあるかどうかを確認します。 |
53 |
boolean isBold() このFontオブジェクトのスタイルが太字かどうかを示します。 |
54 |
boolean isItalic() このFontオブジェクトのスタイルがITALICかどうかを示します。 |
55 |
boolean isPlain() このFontオブジェクトのスタイルがPLAINかどうかを示します。 |
56 |
boolean isTransformed() このFontオブジェクトに、Size属性に加えてそのサイズに影響する変換があるかどうかを示します。 |
57 |
GlyphVector layoutGlyphVector(FontRenderContext frc, char[] text, int start, int limit, int flags) 新しいGlyphVectorオブジェクトを返し、可能であればテキストの完全なレイアウトを実行します。 |
58 |
String toString() このFontオブジェクトをString表現に変換します。 |
継承されたメソッド
このクラスは、次のクラスからメソッドを継承します。
- java.lang.Object
フォントの例
たとえば、 D:/> AWT> com> finddevguides> gui> の任意のエディターを使用して、次のJavaプログラムを作成します。
AWTGraphicsDemo.java
package com.finddevguides.gui;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class AWTGraphicsDemo extends Frame {
public AWTGraphicsDemo(){
super("Java AWT Examples");
prepareGUI();
}
public static void main(String[] args){
AWTGraphicsDemo awtGraphicsDemo = new AWTGraphicsDemo();
awtGraphicsDemo.setVisible(true);
}
private void prepareGUI(){
setSize(400,400);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
}
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
Font plainFont = new Font("Serif", Font.PLAIN, 24);
g2.setFont(plainFont);
g2.drawString("Welcome to finddevguides", 50, 70);
Font italicFont = new Font("Serif", Font.ITALIC, 24);
g2.setFont(italicFont);
g2.drawString("Welcome to finddevguides", 50, 120);
Font boldFont = new Font("Serif", Font.BOLD, 24);
g2.setFont(boldFont);
g2.drawString("Welcome to finddevguides", 50, 170);
Font boldItalicFont = new Font("Serif", Font.BOLD+Font.ITALIC, 24);
g2.setFont(boldItalicFont);
g2.drawString("Welcome to finddevguides", 50, 220);
}
}
コマンドプロンプトを使用してプログラムをコンパイルします。 D:/> AWT に移動し、次のコマンドを入力します。
D:\AWT>javac com\finddevguides\gui\AWTGraphicsDemo.java
エラーが発生しない場合は、コンパイルが成功したことを意味します。 次のコマンドを使用してプログラムを実行します。
D:\AWT>java com.finddevguides.gui.AWTGraphicsDemo
次の出力を確認します