2024-06-12
This commit is contained in:
31
Writerside2/topics/Font.md
Normal file
31
Writerside2/topics/Font.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# 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");
|
||||
```
|
||||
Reference in New Issue
Block a user