tags:

views:

181

answers:

1

In SWT, how can I create a bold/italic variant of a font and how can I scale a font? I tried

int fontStyle = SWT.BOLD;
int height = 1200;

FontData[] fds = font.getFontData ();
for (FontData fd: fds)
{
    fd.setStyle (fontStyle);
    fd.setHeight ((fd.getHeight () * height + 500) / 1000);
}
newFont = new Font(font.getDevice (), fds);

but that doesn't work for "Andale Mono", for example.

A: 

Not all fonts support Italic or Bold. You can set size of the font when creating it:

Font font = new Font(fontFamilyName, fontStyle, fontSize);

Smilediver
But why does it work when I use `new Font(device, "Andale Mono", SWT.BOLD)`? It just fails when I use the FontData API directly. I also can't see a difference when I call `fd.toString()`. Everything looks ok, I get different font handles but they look wrong on the screen.
Aaron Digulla