Right now my goal is to have anti-aliased text on my Labels. If my research was correct, SWT Labels do not natively support anti-aliasing on text, so my current workaround attempt is to create an image, turn text anti-aliasing on, draw my text to that image, then give that image to the Label.
My current image drawing code is as follows:
Image image = new Image(Display.getDefault(), width, height);
GC gc = new GC(image);
gc.setAntialias(SWT.ON);
gc.setTextAntialias(SWT.ON);
gc.setBackground(background);
gc.fillRectangle(0, 0, width, height);
gc.setFont(font);
gc.setForeground(foreground);
int yPos = offset.y;
for (String rawLine : lines)
{
String line = rawLine.trim();
Point lineSize = gc.textExtent(line);
int xPos = offset.x;
switch (alignment)
{
case SWT.RIGHT:
xPos += width - lineSize.x;
break;
case SWT.CENTER:
xPos += width / 2 - lineSize.x / 2;
break;
case SWT.LEFT:
default:
xPos += 0;
}
gc.drawText(line, xPos, yPos, true);
yPos += lineSize.y;
}
gc.dispose();
return image;
I have had inconsistent results on two different computers: At work, the text in the resulting images appears as choppy as ever- as if text anti-aliasing wasn't even on. But at home, connected to my work computer via remote desktop, I saw exactly the results I wanted.
Obviously I'd like things to work correctly on both computers, but I am currently stumped as to why they aren't. Each computer is running Windows 7, Eclipse v3.6.
What could be the problem that is causing this inconsistency? And if my workaround is just absurd and I am completely missing an easier way, what is that way? Thank you for any help!