Community
Participate
Working Groups
Created attachment 181809 [details] image revealing the mentioned gap This bug was observed in a Graphiti based diagram. As of the discussion following http://www.eclipse.org/forums/index.php?t=msg&th=198956&start=0&S=75d2be8d91fb1185adf47d502a7bda94 Tim Kaiser from Graphiti could reproduce it and tracked it back to a problem in the underlying GEF/draw2d layer. In attached figure the inner GA is a filled ellipse: Ellipse inset = gaService.createEllipse(invisibleRectangle); inset.setForeground(manageColor(fill)); inset.setBackground(manageColor(fill)); inset.setLineWidth(LINE_WIDTH); gaService.setLocationAndSize(inset, 3*size/4, 3*size/4, size/2, size/2); The rendering leaves a little gap of background color on the upper left part. setting the ellipse filled inset.setFilled(true); doesn't change the behavior.
Some additional information: I'm using Eclipse 3.6, Build id: I20100608-0911 (the 32bit version running on a 64bit Windows 7) Graphiti 0.7.0 GEF 3.6.1 Debug output: Pictogram Model Tree() *PE* ContainerShapeImpl (active) (visible) RectangleImpl (360, 0, 80, 80) RectangleImpl (20, 20, 40, 40) EllipseImpl (30, 30, 20, 20) *PE* ShapeImpl (inactive) (visible) TextImpl (0, 0, 80, 20) *PE* ChopboxAnchorImpl (inactive) (invisible) Edit Part Tree() ContainerShapeEditPart (RectangleImpl) Figure Tree GFRectangleFigure (Rectangle(400, 40, 80, 80)) GFRectangleFigure (Rectangle(420, 60, 40, 40)) GFEllipse (Rectangle(430, 70, 20, 20)) GFText (text: fcn) (Rectangle(400, 40, 80, 20))
Created attachment 181810 [details] some code that may help to reproduce
Henrik, is it possible to come up with a "Draw2d-only" snippet to reproduce the problem? In the thread you are referring to, it is mentioned that Tim had a respective snippet to reproduce the problem.
(In reply to comment #3) > Henrik, is it possible to come up with a "Draw2d-only" snippet to reproduce the > problem? In the thread you are referring to, it is mentioned that Tim had a > respective snippet to reproduce the problem. Hi Alexander, I'm afraid that I can't provide a pure draw2d code. How can I support you tracking down the problem? I could offer to make a debug session in my code using some kind of desktop sharing (skype?). -Henrik
As a starting point, could you provide the complete source code of the class that contains the snippet?
Created attachment 192438 [details] pure SWT/draw2d example looks good Java code trying to resemble the wrong behavior with pure SWT/draw2d code. But renders as should be. Where is the difference?
Tim, I've brought up this issue in the Graphiti newsgroup. In http://www.eclipse.org/forums/index.php?t=tree&goto=634573&S=50b455834c39d76107613a5737e28180#page_top you mentioned that you could reproduce the issue with plain draw2d, but we couldn't (cf. attachment 3 [details]). Can you provide this code?
the 3rd is actually attachment 192438 [details]
Hi, this is still a thing. This happens because the outline of the Ellipse is drawn using the scaled rectangle returned by zoomRect while the inner circle is drawn using the rectangle returned by zoomFillrect and those rectangle centers are not aligned. I believe the bug is in zoomFillRect as it doesn't compensate the (x, y) coordinates. If I had the proper dev environment I would try to update zoomFillRect from: private Rectangle zoomFillRect(int x, int y, int w, int h) { tempRECT.x = (int) (Math.floor((x * zoom + fractionalX))); tempRECT.y = (int) (Math.floor((y * zoom + fractionalY))); tempRECT.width = (int) (Math.floor(((x + w - 1) * zoom + fractionalX))) - tempRECT.x + 1; tempRECT.height = (int) (Math.floor(((y + h - 1) * zoom + fractionalY))) - tempRECT.y + 1; return tempRECT; } to: private Rectangle zoomFillRect(int x, int y, int w, int h) { tempRECT.x = (int) (Math.floor(((x + 1) * zoom + fractionalX))); tempRECT.y = (int) (Math.floor(((y + 1) * zoom + fractionalY))); tempRECT.width = (int) (Math.floor(((x + w - 2) * zoom + fractionalX))) - tempRECT.x + 1; tempRECT.height = (int) (Math.floor(((y + h - 2) * zoom + fractionalY))) - tempRECT.y + 1; return tempRECT; } Sorry, that's how close to a proper patch as I will ever get :) Regards Seb
The compensation you refer to within ScaledGraphics is there because of different behavior for draw and fill within SWT (see http://www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html). I do not think its causing the issue reported here.
Fix proposition at: https://github.com/eclipse/gef/pull/2
(In reply to Jules CLERO from comment #11) > Fix proposition at: https://github.com/eclipse/gef/pull/2 I am sorry, but as already indicated, neither this fix nor the one you proposed in comment #9 are correct. The compensation within ScaledGraphics#zoomFillRect() is there because fillRect and drawRect behave differently in SWT (and thus also Draw2d). The problem reported here IMHO is related to scaling effects in combination with integer-based precision (and some inappropriate compensations within Draw2d shapes). Consider the following snippet that renders the same rectangle with GC (SWT), Graphics (Draw2d), and ScaledGraphics (Draw2d), using the same width and height in all three cases. With the original code base, all three rectangles look the same. Both of your proposed fixes will break the rendering of the last rectangle. package swt.bugs; import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.Graphics; import org.eclipse.draw2d.SWTGraphics; import org.eclipse.draw2d.ScaledGraphics; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class Bug328801 { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(); 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(ColorConstants.red); gc.drawRectangle(50, 50, 50, 50); gc.fillRectangle(50, 50, 50, 50); Graphics graphics = new SWTGraphics(gc); graphics.setBackgroundColor(ColorConstants.red); graphics.drawRectangle(150, 50, 50, 50); graphics.fillRectangle(150, 50, 50, 50); ScaledGraphics scaledGraphics = new ScaledGraphics(graphics); scaledGraphics.setBackgroundColor(ColorConstants.red); scaledGraphics.drawRectangle(250, 50, 50, 50); scaledGraphics.fillRectangle(250, 50, 50, 50); } }); shell.setSize(400, 200); shell.open(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); } }