Bug 351038 - SWTGraphics.rotate should use GC data state mask to avoid rotate problems
Summary: SWTGraphics.rotate should use GC data state mask to avoid rotate problems
Status: NEW
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy Draw2d (show other bugs)
Version: 3.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: gef-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 253670
Blocks:
  Show dependency tree
 
Reported: 2011-07-03 22:25 EDT by Colin Sharples CLA
Modified: 2012-05-01 14:42 EDT (History)
1 user (show)

See Also:


Attachments
Demonstrates rotate problem with paintFill (4.12 KB, text/x-java)
2012-04-30 17:31 EDT, Colin Sharples CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Colin Sharples CLA 2011-07-03 22:25:17 EDT
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°.
Comment 1 Alexander Nyßen CLA 2011-10-17 17:03:38 EDT
I think we should rather urge the SWT guys to get their problem fixed...
Comment 2 Alexander Nyßen CLA 2011-10-17 17:16:58 EDT
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.
Comment 3 Colin Sharples CLA 2011-10-17 17:46:12 EDT
Okay, provided the SWT bug gets fixed. If there is no fix for that in the 3.7 timeline, would you add the workaround?
Comment 4 Colin Sharples CLA 2012-04-30 17:31:49 EDT
Created attachment 214839 [details]
Demonstrates rotate problem with paintFill
Comment 5 Colin Sharples CLA 2012-04-30 17:34:44 EDT
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()?
Comment 6 Alexander Nyßen CLA 2012-05-01 14:09:24 EDT
(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.
Comment 7 Colin Sharples CLA 2012-05-01 14:42:22 EDT
(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.