Community
Participate
Working Groups
Linux HiDPI GC.fillGradientRectangle sets device scale permanently Linux Ubuntu 20.04 Hi-res display (200% scaling) I am creating an SWT Image to a GC instance usng fillGradientRectangle() and drawing text to the same GC instance. However, any GC methods used after calling fillGradientRectangle() draw at double-scale. - Run the attached snippet and look at the generated image - drawText() is called first and draws correctly - fillGradientRectangle() is then called - drawText() is then called again, but this time scaling is at 2x and so the text is double size - If fillGradientRectangle() is commented out, then drawing is at the correct scale It seems that once GC#fillGradientRectangle() is called any drawing after that is at double scale. Note these lines in GC#fillGradientRectangleInPixels() : if (DPIUtil.useCairoAutoScale() ) { ... Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor); Perhaps the scale should be set back to its original setting after drawing the gradient?
Created attachment 284776 [details] Snippet that shows the problem Here's the snippet that shows the problem.
Do you see from which Eclipse version the regression is coming? Do you want to provide a gerrit patch?
(In reply to Andrey Loskutov from comment #2) > Do you see from which Eclipse version the regression is coming? I think it has been like this for some time. > Do you want to provide a gerrit patch? Normally I would try, but this is beyond my programming skills as it is in the C language (I think).
(In reply to Phil Beauvoir from comment #3) > (In reply to Andrey Loskutov from comment #2) > > Do you see from which Eclipse version the regression is coming? > > I think it has been like this for some time. > > > Do you want to provide a gerrit patch? > > Normally I would try, but this is beyond my programming skills as it is in > the C language (I think). I meant to say that the code calls some C functions. I would not say this was a recent regression, this has been like this since 2018 or so.
Setting scaleFactor to 1.0 in this block fixes the issue: if (DPIUtil.useCairoAutoScale() ) { /* * Here the co-ordinates passed are in points for GTK3. * That means the user is expecting surface to be at * device scale equal to current scale factor. So need * to set the device scale to current scale factor */ long surface = Cairo.cairo_get_target(cairo); if (surface != 0) { float scaleFactor = DPIUtil.getDeviceZoom() / 100f; Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor); } } Is this block of code needed?