Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't text anti-aliasing working, while using a SWT GC to draw text?

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!

like image 954
Dylan Avatar asked Jan 13 '11 20:01

Dylan


1 Answers

Check if Anti-Aliased text support is configured differently on both machines in the Control Panel. In XP, you'd be looking to make sure ClearType was enabled.

http://www.microsoft.com/typography/cleartype/tuner/step1.aspx

You might also look at this article. It could be playing a role.

http://www.ytechie.com/2008/12/cleartype-in-remote-desktop-with-xp.html

like image 51
James Branigan Avatar answered Oct 01 '22 02:10

James Branigan