Issue
I'm using a JTextPane
to display a kind of bus ticket that uses a monospaced font. I am using StyleConstants
and SimpleAttributeSet
to set bold and italic text, but I would like to also use double width and height characters. I don't want to make a double-sized font, by double I mean that a character 'A' which I want to be double-width, would get stretched in width, but not in height, and vice versa for double-height, like in this image I found here.
I really don't know any method to do so and googling didn't give me an answer. Maybe a way to adjust the size of a font horizontally and vertically?
Solution
To adjust the size of a font to double width:
// Input: an existing Font object called 'font'.
final int style = Font.PLAIN;
AffineTransform transform = new AffineTransform();
transform.setToScale(2.0, 1.0);
Font doubleWidthFont = font.deriveFont(style, transform);
I haven't tried this code, so please let me know if it doesn't work exactly as written.
Answered By - user1324109