32 lines
714 B
Markdown
32 lines
714 B
Markdown
# Font
|
|
|
|
```java
|
|
Font font = Font.createFont(Font.TRUETYPE_FONT, new File("Abc.ttf"));
|
|
return font.deriveFont(12.f);
|
|
```
|
|
|
|
* `getFamily()`
|
|
* `getFontName()`
|
|
* `getAttributes()`
|
|
|
|
* `graphics2D.getFont()` / `graphics2D.setFont(Font)`
|
|
* `Font.createFont(int,InputStream)`
|
|
|
|
* `deriveFont()`
|
|
|
|
* `graphicsEnvironment.getAvailableFontFamilyNames()`
|
|
* `graphicsEnvironment.getAllFonts()`
|
|
|
|
```java
|
|
HashMap<TextAttribute,Object> map = new HashMap<>();
|
|
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
|
font = font.deriveFont(map);
|
|
```
|
|
|
|
## FontMetrics
|
|
```java
|
|
FontMetrics fontMetrics = graphics2D.getFontMetrics(font);
|
|
int textHeight = fontMetrics.getHeight();
|
|
int textWidth = fontMetrics.stringWidth("Hello");
|
|
```
|