Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.awt.font letter spacing

Is it possible to increase letter spacing when using java.awt.font ? Something like this:

Font font = new Font("serif", Font.PLAIN, 21);
//Increase the spacing - perhaps with deriveFont()?

BufferedImage image = new BufferedImage(400, 600, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics();
graphics.setFont(font);
graphics.drawString("testing",0,0);
like image 694
user1031054 Avatar asked Nov 05 '12 09:11

user1031054


People also ask

What fonts are in Java awt font?

Logical Fonts Java defines five logical font families that are Serif, SansSerif, Monospaced, Dialog, and DialogInput. It must be supported by the JRE. Note that JRE maps the logical font names to physical font because these are not the actual font libraries.

What is standard letter spacing?

The spacing between the characters is normal. letter-spacing: 2px; You can use pixel values.

Is the spacing between characters pairs?

Kerning is the spacing between individual letters or characters. Unlike tracking, which adjusts the amount of space between the letters of an entire word in equal increments, kerning is focused on how type looks — creating readable text that's visually pleasing.

What is the importance of spacing in lettering?

The main purpose of letter-spacing is to improve the legibility and readability of the text. Words act differently depending on their size, color, and the background they are on.


1 Answers

You can derive a new font, with an updated tracking attribute:

Map<TextAttribute, Object> attributes = new HashMap<TextAttribute, Object>();
attributes.put(TextAttribute.TRACKING, 0.5);
Font font2 = font.deriveFont(attributes);
gr.setFont(font2);
gr.drawString("testing",0,20);
like image 132
Gijs Overvliet Avatar answered Sep 29 '22 05:09

Gijs Overvliet