java.awt.font
Font font = new Font("Arial", Font.PLAIN, 12);
System.out.println("Font name: " + font.getName());
System.out.println("Font style: " + font.getStyle());
System.out.println("Font size: " + font.getSize());Map<TextAttribute, ?> attrs = new HashMap<>();
attrs.put(TextAttribute.FAMILY, "Arial");
attrs.put(TextAttribute.SIZE, 12.0f);
attrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
Font font = new Font(attrs);FontMetrics metrics = font.getFontMetrics();
System.out.println("Ascent: " + metrics.getAscent());
System.out.println("Descent: " + metrics.getDescent());
System.out.println("Leading: " + metrics.getLeading());String text = "Hello, world!";
FontMetrics metrics = font.getFontMetrics();
int width = metrics.stringWidth(text);