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

Bug 130400

Summary: ScaledGraphics should not nest another ScaledGraphics
Product: [Tools] GEF Reporter: Chris Lee <eclipse>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: nyssen
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Chris Lee CLA 2006-03-03 16:58:49 EST
The problem is when we have a scaled layer containing (eventually) another scaled layer.  The first one applies a scale of 15, the next one applies a scale of 1/15.  When drawing almost anything, this dual transform renders things like..well..crap.

Rather than maintaining a nesting of ScaledGraphics within another ScaledGraphics, it should use the Graphics inside the passed in ScaledGraphics (normally an SWTGraphics), and just initialize its scale to the passed in scale.

I think something like this would solve the problem:

public ScaledGraphics (Graphics g) {
  if (g instanceof ScaledGraphics) {
    sG = (ScaledGraphics)g;
    graphics = sG.graphics;
    setScale (sG.zoom);
    localFont = sG.localFont;
    localLineWidth = sG.localLineWidth;
  } else {
    graphics = g;
    localFont = g.getFont ();
    localLineWidth = g.getLineWidth ();
  }
}
Comment 1 Randy Hudson CLA 2006-03-03 17:37:01 EST
That's an interesting idea and I think it involves a few more checks on the state of the ScaledGraphics that is passed in.

We would have to create a static factory method instead of changing the behavior of the existing constructor.

Of course, clients could always check if a Graphics is a ScaledGraphics already, and avoid constructing the new one.
Comment 2 Chris Lee CLA 2006-03-03 18:49:29 EST
That's our current workaround, except it involves doing this any place where a ScaledGraphics would be constructed - quite a bit cumbersome.
Comment 3 Randy Hudson CLA 2006-03-03 18:56:45 EST
If you are doing that test more than once, just create a utility that does it for you:

public static ScaledGraphics ScaledGraphicsFactory.create(Graphics g) {
...
}
Comment 4 Alexander Nyßen CLA 2014-08-08 10:32:02 EDT
As Draw2d is only maintained and there is a documented workaround for this (clients can make sure to not pass in a ScaledGraphics to the ScaledGraphics constructor, resolving this as WONTFIX.