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

Bug 362999

Summary: SWTGraphics#scale is broken when used with Printer on Eclipse 3.7 / GTK
Product: [Eclipse Project] Platform Reporter: Peter Severin <peter>
Component: SWTAssignee: Silenio Quarti <Silenio_Quarti>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: carolynmacleod4, cedric.brun, nyssen, pwebster
Version: 4.2   
Target Milestone: 4.2 M4   
Hardware: All   
OS: Linux-GTK   
Whiteboard:
Bug Depends on: 150870    
Bug Blocks:    
Attachments:
Description Flags
SWT-only test case none

Description Peter Severin CLA 2011-11-06 12:57:15 EST
Build Identifier: M20110909-1335

Due to a fix in Printer made in Eclipse 3.7 as part of Bug 150870 the scaling of SWTGraphics is now broken. This is due to the fact that now some pre-scaling is being done in Printer#internal_new_GC:

Cairo.cairo_translate(cairo, printX, printY);
Cairo.cairo_scale(cairo, screenDPI.x / (float)dpi.x, screenDPI.y / (float)dpi.y);

Doing SWTGraphics#scale will initialize a new Transform which is not multiplied with the one already set in the above method. So for example doing SWTGraphics#scale(1) changes the scale although the method should have no effect.

There also a translate that I am sure is being lost too.

I don't know if the fix should be in SWT for Draw2d but I though you should know about this issue.

Currently I am doing transform multiplication manually to fix the bug in Eclipse 3.7.

Reproducible: Always
Comment 1 Alexander Nyßen CLA 2011-11-06 14:15:44 EST
Added dependency to #150870.
Comment 2 Alexander Nyßen CLA 2011-11-06 14:25:33 EST
How can SWTGraphics be affected by changes to Printer? I suppose you mean ScaledGraphics?
Comment 3 Peter Severin CLA 2011-11-06 22:32:15 EST
Alexander, I am using SWTGraphics with Printer for native scaling which gets better results. I use code that looks something like this:

printer.startPage();
GC gc = new GC(printer);
Graphics graphics = new SWTGraphics(gc);

Actually I have a PrinterGraphics subclass, similar to one based on ScaledGraphics, that does some device resource handling.
Comment 4 Peter Severin CLA 2011-11-06 22:35:06 EST
But the bug is not specific to scaling as it can be triggered by anything that sets a new Transform on GC: a non-integer translation or a rotation. So it should be also present in PrinterGraphics found in Draw2d.
Comment 5 Carolyn MacLeod CLA 2011-11-07 09:50:41 EST
Hi, Peter. Would you be able to provide an SWT-only test case? It would save us some time looking at the problem and testing what we think might be a possible fix. Thanks!
Comment 6 Peter Severin CLA 2011-11-07 10:01:45 EST
Created attachment 206526 [details]
SWT-only test case

I adapted on of the SWT snippets to show the bug. Normally this code should print two identical lines one below the other. However on Eclipse 3.7 the second line will be much bigger, depending on the Printer DPI / 72.0f ratio.
Comment 7 Carolyn MacLeod CLA 2011-11-07 11:03:02 EST
Thank-you, Peter!
Reassigning to SWT.
Comment 9 Peter Severin CLA 2011-11-07 11:11:48 EST
Great, Carolyn! Will it be backported to 3.7/3.8 versions? I don't need it but just want to know from which version I can disable my workaround.
Comment 10 Carolyn MacLeod CLA 2011-11-07 12:18:18 EST
Backported to 3.7:
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?h=R3_7_maintenance&id=da1f7fdabbd2b4b4a76e6e27218cef07f95be1ce

It is already in 3.8 because (most of) the SWT source for 3.8 and 4.2 are the same.