Bug 243618 - Can't fill and outline the same shape with GDI+
Summary: Can't fill and outline the same shape with GDI+
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-08 14:23 EDT by Randy Hudson CLA
Modified: 2022-02-18 08:12 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Randy Hudson CLA 2008-08-08 14:23:07 EDT
The problem seems to be that 1/2 pixel is being added for draw operations (but not for fills) when the line width is an odd number, which is why even the 100% case is not working.

Here's a modified version of the snippet that applies the same 1/2-pixel shift for fillOval, which gives the expected results:

public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setText("Shell");
	shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
	final Color YELLOW = display.getSystemColor(SWT.COLOR_YELLOW);
	shell.addPaintListener(new PaintListener() {
		public void paintControl(PaintEvent e) {
			GC gc = e.gc;
//			gc.setAntialias(SWT.ON);
			gc.setLineWidth(1);
			Transform t = new Transform(null);
			gc.setTransform(t);
			gc.setBackground(YELLOW);
			paintOval(gc, t, 0.5f);
			t.scale(3f, 3f);
			gc.setTransform(t);
			paintOval(gc, t, 0.5f/3);
			t.dispose();
		}

		private void paintOval(GC gc, Transform t, float correction) {
			t.translate(correction, correction); //Apply the missing 1/2-pixel shift when filling
			gc.setTransform(t);
			gc.fillOval(10, 10, 20, 20);
			t.translate(-correction, -correction);
			gc.setTransform(t);
			gc.drawOval(10, 10, 20, 20);
		}
	});
	
	shell.setSize(200, 200);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
Comment 1 Randy Hudson CLA 2008-08-08 15:03:28 EDT
To see same problem for Paths, "apply" this "patch":

	final Color YELLOW = display.getSystemColor(SWT.COLOR_YELLOW);
+	final Path path = new Path(display);
+	path.moveTo(40, 15);
+	path.lineTo(60, 5);
+	path.lineTo(80, 15);
+	path.lineTo(60, 25);
+	path.close();

and
		gc.setTransform(t);
		gc.fillOval(10, 10, 20, 20);
+		gc.fillPath(path);
		t.translate(-correction, -correction);
		gc.setTransform(t);
		gc.drawOval(10, 10, 20, 20);
+		gc.drawPath(path);
Comment 2 Randy Hudson CLA 2008-08-08 17:10:03 EDT
See related bug 242280.  Because of it, the problem shown here disappears for scale factor 2.0.
Comment 3 Randy Hudson CLA 2008-08-13 11:13:01 EDT

*** This bug has been marked as a duplicate of bug 146179 ***
Comment 4 Randy Hudson CLA 2008-08-14 10:33:07 EDT
Sorry, I meant to resolve another GEF bug as duplicate, not this one.  Reopened.
Comment 5 Eclipse Webmaster CLA 2019-09-06 15:33:16 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.
Comment 6 Eclipse Genie CLA 2022-02-18 08:12:04 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.

--
The automated Eclipse Genie.