public class FontUtil extends Object
Constructor and Description |
---|
FontUtil() |
Modifier and Type | Method and Description |
---|---|
static Font |
createFont()
创建默认字体
|
static Font |
createFont(File fontFile)
|
static Font |
createFont(InputStream fontStream)
|
static Font |
createFont(String name,
int size)
创建指定名称的字体
|
static Font |
createSansSerifFont(int size)
创建SansSerif字体
|
static Font[] |
getAllFonts()
获得系统中支持的所有字体
|
static Dimension |
getDimension(FontMetrics metrics,
String str)
获得字体对应字符串的长宽信息
|
static Rectangle2D |
getRectangle(String str,
Font font)
获取font的样式应用在str上的整个矩形
|
static void |
registerFont(Font font)
注册字体到系统
此方法用于将字体文件注册到系统,之后即可在字体名称列表中看到此字体 |
public static Font[] getAllFonts()
public static void registerFont(Font font)
font
- 字体public static Font createFont()
public static Font createSansSerifFont(int size)
size
- 字体大小public static Font createFont(String name, int size)
name
- 字体名称size
- 字体大小public static Font createFont(InputStream fontStream)
fontStream
- 字体流Font
public static Dimension getDimension(FontMetrics metrics, String str)
metrics
- FontMetrics
str
- 字符串public static Rectangle2D getRectangle(String str, Font font)
str
- 字符串,必须非空font
- 字体,必须非空Rectangle2D
Copyright © 2025. All rights reserved.