Community
Participate
Working Groups
Build Identifier: 20110615-0604 Bug #253670 describes a problem with SWT GC where rotation causes drawXxx and fillXxx to be misaligned at certain angles (45, 135, 225, 315). In SWT you can work around this by setting the GC data state mask to DRAW_OFFSET. This does not work in Draw2D, as you don't have access to the GC, only to the Draw2D SWTGraphics. Draw2D should implement support for this workaround. Reproducible: Always Steps to Reproduce: 1. Create a Shape that fills and draws a rotated rectangle, and set the rotation angle to 45°.
I think we should rather urge the SWT guys to get their problem fixed...
I actually don't wont to add any direct workaround for this, but I will leave this one open as a reminder for now. Added a dependency on bug #253670 to keep track about what happens to the underlying issue.
Okay, provided the SWT bug gets fixed. If there is no fix for that in the 3.7 timeline, would you add the workaround?
Created attachment 214839 [details] Demonstrates rotate problem with paintFill
I have found something interesting. It appears that this is only a problem when you are using Shape.fillShape(). If you do all the drawing of the Shape in outlineShape(), then the problem doesn't happen. I am attaching some sample code to illustrate this. This shows two figures that you can rotate around. The good one on the left will draw correctly, using outlineShape, whereas the bad one on the right will have the problem at 45°, 135°, 225°, 315°. I then imported the Draw2D plugin into my workspace, and modified SWTGraphics.rotate(), to add the following line after it sets the transform: gc.getGCData().state |= 1 << 9; // DRAW_OFFSET Running the program again shows both figures rotating correctly. Looking at Shape.paintFill() and Shape.paintOutline(), the only difference between them is that paintOutline() is setting the line attributes on the graphics. Is there a reason that the line attributes are not set in paintFill()? I'm not sure what effect setting the line attributes has on the graphics, but presumably it has having some similar effect to setting the state with the DRAW_OFFSET mask. It would still be nice if the underlying graphics problem were fixed, but might another approach be to set the line attributes in paintFill()?
(In reply to comment #5) > I have found something interesting. It appears that this is only a problem when > you are using Shape.fillShape(). If you do all the drawing of the Shape in > outlineShape(), then the problem doesn't happen. I am attaching some sample > code to illustrate this. This shows two figures that you can rotate around. The > good one on the left will draw correctly, using outlineShape, whereas the bad > one on the right will have the problem at 45°, 135°, 225°, 315°. > > I then imported the Draw2D plugin into my workspace, and modified > SWTGraphics.rotate(), to add the following line after it sets the transform: > > gc.getGCData().state |= 1 << 9; // DRAW_OFFSET > > Running the program again shows both figures rotating correctly. > > Looking at Shape.paintFill() and Shape.paintOutline(), the only difference > between them is that paintOutline() is setting the line attributes on the > graphics. Is there a reason that the line attributes are not set in > paintFill()? Hmm, filling a shape actually does not rely on the line attributes, as no outline is painted. As such, this really looks like a workaround for me. > > I'm not sure what effect setting the line attributes has on the graphics, but > presumably it has having some similar effect to setting the state with the > DRAW_OFFSET mask. > > It would still be nice if the underlying graphics problem were fixed, but might > another approach be to set the line attributes in paintFill()? I think we should rather try to find out what side-effect of the setting of line attributes actually has the respective impact. You have already reported this on bug #253670 as I have seen, so maybe we try to urge the SWT team for an investigation before building in any workarounds into Draw2d.
(In reply to comment #6) > Hmm, filling a shape actually does not rely on the line attributes, as no > outline is painted. As such, this really looks like a workaround for me. I have some shapes where the "fill" does involve drawing, but I can manually set the line attributes in fillShape(), so there's no need for a change in Draw2D code. > I think we should rather try to find out what side-effect of the setting of > line attributes actually has the respective impact. You have already reported > this on bug #253670 as I have seen, so maybe we try to urge the SWT team for an > investigation before building in any workarounds into Draw2d. I'm not holding my breath. That bug was raised in 2008, with no sign that it has ever even been looked at by the SWT team.