Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 199710

Summary: Figure Ellipse clipping problem
Product: [Tools] GEF Reporter: Levente Mészáros <melevy>
Component: GEF-Legacy GEF (MVC)Assignee: gef-inbox <gef-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: hudsonr, nyssen
Version: 3.4   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Incorrect rendering see top and left edge none

Description Levente Mészáros CLA 2007-08-13 06:21:52 EDT
Created attachment 75949 [details]
Incorrect rendering see top and left edge

Build ID: I20070621-1340

Steps To Reproduce:


More information:
Figure Ellipse with even line width incorrectly clips the oval's left and top side when anti alias is turned on

I guess this could fix the problem: 

Ellipse:
    protected void outlineShape(Graphics graphics) {
    	Rectangle r = Rectangle.SINGLETON;
    	r.setBounds(getBounds());
    	r.width--;
    	r.height--;
    	int t = lineWidth / 2;
    	r.translate(t, t);
    	int s = (lineWidth - 1) / 2;
    	r.resize(-t - s, -t -s);
    	graphics.drawOval(r);
    }
Comment 1 Randy Hudson CLA 2007-08-13 09:54:55 EDT
We are translating by whole numbers even though we divide by 2 to compensate for the fact that:

drawLine (0,0,100,0) puts pixels at row 0 for width=1
but puts pixels at rows 0&1 for width=2.

Try this in pure SWT:

gc.setBackground(gray);
gc.setLineWidth(2);
gc.fillRect(10,10,10,10);
gc.drawOval(11,11,8,8); // (I'm guessing here)

Then try it with antialias on. If the oval is not inside the box for both cases, it sounds like an SWT problem. First, get the oval exactly inside without AA on.
Comment 2 Levente Mészáros CLA 2007-08-14 08:04:55 EDT
If you look at the attached picture it becomes clear that this is a problem. Whether it is a GEF problem or an SWT problem I don't know and don't have time to figure it out. I guess I did what I should, I have reported a problem.

Sorry for not having time to help more than this.

levy
Comment 3 Alexander Nyßen CLA 2011-03-30 13:08:31 EDT
I used the following snippet and tried to reproduce the problem on Windows XP and Mac Cocoa. However, I was not able to find a combination of lineWidth and bounds that reproduce the described problem.

package swt.bugs;

/*******************************************************************************
 * Copyright (c) 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Bug199710 {

	public static void main(String[] args) {
		Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setText("Bug199710");

		final Ellipse ellipse = new Ellipse();
		ellipse.setForegroundColor(ColorConstants.black);
		ellipse.setBackgroundColor(ColorConstants.white);
		ellipse.setLineWidth(2);
		ellipse.setAntialias(SWT.ON);
		ellipse.setBounds(new Rectangle(50, 50, 60, 60));

		shell.addPaintListener(new PaintListener() {

			public void paintControl(PaintEvent e) {
				Graphics g = new SWTGraphics(e.gc);
				ellipse.paint(g);
			}
		});

		shell.addKeyListener(new KeyListener() {

			public void keyReleased(KeyEvent e) {
			}

			public void keyPressed(KeyEvent e) {
				if (e.character == 'a') {
					ellipse.setBounds(ellipse.getBounds().getShrinked(1, 1));
					shell.redraw();
				}
				if (e.character == 's') {
					ellipse.setBounds(ellipse.getBounds().getExpanded(1, 1));
					shell.redraw();
				}
				if (e.character == 'd') {
					ellipse.setBounds(ellipse.getBounds().getTranslated(1, 1));
					shell.redraw();
				}
				if (e.character == 'f') {
					ellipse.setBounds(ellipse.getBounds().getTranslated(-1, -1));
					shell.redraw();
				}
				if (e.character == 'g') {
					ellipse.setLineWidth(Math.min(10,
							ellipse.getLineWidth() + 1));
					shell.redraw();
				}
				if (e.character == 'h') {
					ellipse.setLineWidth(Math.max(ellipse.getLineWidth() - 1, 1));
					shell.redraw();
				}
			}
		});

		shell.setSize(500, 380);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

Resolving as WORKSFORME, as reporter is unwilling to provide additional information and reproduction is not possible with what is given. Please re-open and provide additional information in case this can be reproduced somewhere.