Bug 175760 - gc.drawString() draws incorrectly with ClearType fonts
Summary: gc.drawString() draws incorrectly with ClearType fonts
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-27 17:59 EST by Curtis d'Entremont CLA
Modified: 2019-09-06 16:12 EDT (History)
6 users (show)

See Also:


Attachments
screenshot showing the problem (13.09 KB, image/png)
2007-02-27 18:00 EST, Curtis d'Entremont CLA
no flags Details
Screenshot showing correct rendering (4.00 KB, image/png)
2008-04-11 09:27 EDT, André Kischkel CLA
no flags Details
Screenshot showing errorneous rendering (5.59 KB, image/png)
2008-04-11 09:28 EDT, André Kischkel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Curtis d'Entremont CLA 2007-02-27 17:59:36 EST
I20070227-0800

Enable ClearType fonts:

- Right click on Desktop, select Properties
- Go to Appearance
- Click Effects..
- Select ClearType in the second drop down

I also installed the Clear Type Tuning tool (http://www.microsoft.com/typography/ClearTypePowerToy.mspx) but I'm not sure if this matters.

If I enable this, gc.drawString starts drawing before the x coordinate I give it.

Here's a snippet:


public static void main(String[] args) {
	final Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	
	Canvas canvas = new Canvas(shell, SWT.NONE);
	canvas.addPaintListener(new PaintListener() {
		public void paintControl(PaintEvent e) {
			GC gc = e.gc;
			gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
							
			// draw the string
			gc.drawString("abc", 20, 20, false);
			
			// show the expected bounds
			Point extent = gc.textExtent("abc");
			gc.drawRectangle(20, 20, extent.x, extent.y);
		}
	});
	
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}

I will attach a comparison screenshot, with and withough ClearType.

Note: gc.drawText does not have this problem.
Comment 1 Curtis d'Entremont CLA 2007-02-27 18:00:29 EST
Created attachment 59927 [details]
screenshot showing the problem
Comment 2 André Kischkel CLA 2008-04-11 09:27:07 EDT
The ClearType bug also messed up FormText rendering. Pixels from inline images get cut off (see screenshot).
Comment 3 André Kischkel CLA 2008-04-11 09:27:47 EDT
Created attachment 95673 [details]
Screenshot showing correct rendering
Comment 4 André Kischkel CLA 2008-04-11 09:28:53 EDT
Created attachment 95674 [details]
Screenshot showing errorneous rendering
Comment 5 Steve Northover CLA 2008-04-11 11:49:18 EDT
Not sure we can work around this bug in Windows.
Comment 6 Adam Archer CLA 2008-05-21 11:38:06 EDT
*** Bug 194443 has been marked as a duplicate of this bug. ***
Comment 7 Adam Archer CLA 2008-05-21 11:41:06 EDT
(In reply to comment #5)
> Not sure we can work around this bug in Windows.

ClearType is the default setting in Windows XP and this bug causes lots of glitches in FormText. If it can't be fixed than that makes me sad.

Has a valiant effort been made? Is the problem that SWT cannot know if windows is using ClearType or not?
Comment 8 Silenio Quarti CLA 2008-05-21 13:02:30 EDT
ExtTextOut() has a bug when ClearType is used and the string drawing is not transparent. There are a couple of solutions here:

1) SWT detects that ClearType is enabled, calculate and fill the background rect itself and then draw the string transparent.

   This solution would make every string drawing operation slower. It is also kind of late to change GC.drawString() for 3.4.

2) If the background is not required, the app code draws the string transparent (drawString("string", 0, 0, true)).

   It is not clear in the test code that the background drawing is necessary, but it seems it is not needed in the real eclipse screenshots. Is this an option for you?
Comment 9 Silenio Quarti CLA 2008-05-21 13:07:05 EDT
It is worth to mention that the testcase is also wrong. If it draws with drawString(), it must measure with stringExtent() (not textExtent()).
Comment 10 Adam Archer CLA 2008-05-21 13:44:32 EDT
Thanks for the quick response. I understand your hesitation to change GC.drawString() so late in 3.4 (particularly with a performance degradation involved). I tried out your suggested fix to draw the strings transparently and it does appear to fix the problem. In Forms we are actually drawing background colors ourselves anyway, so passing false was actually resulting in extra work being done for every rendered string.
Comment 11 Eclipse Webmaster CLA 2019-09-06 16:12:07 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.