@@ -247,6 +247,55 @@ public void test_dispose() {
247247 gc .dispose ();
248248}
249249
250+
251+ @ Test
252+ public void test_drawImage_nonAutoScalableGC_bug_2504 () {
253+ Shell shell = new Shell (display );
254+ float targetScale = 2f ;
255+ int srcSize = 50 ;
256+ Image image = new Image (display , srcSize , srcSize );
257+ GC gcSrc = new GC (image );
258+ gcSrc .setBackground (display .getSystemColor (SWT .COLOR_BLACK ));
259+ gcSrc .fillRectangle (0 , 0 , srcSize , srcSize );
260+ gcSrc .setBackground (display .getSystemColor (SWT .COLOR_WHITE ));
261+ gcSrc .fillRectangle (2 , 2 , srcSize - 4 , srcSize - 4 );
262+ gcSrc .dispose ();
263+
264+ Rectangle bounds = image .getBounds ();
265+
266+ Canvas canvas = new Canvas (shell , SWT .NONE ) {
267+ @ Override
268+ public boolean isAutoScalable () {
269+ return false ;
270+ }
271+ };
272+
273+ int canvasWidth = Math .round (bounds .width * targetScale );
274+ int canvasHeight = Math .round (bounds .height * targetScale );
275+ canvas .setSize (canvasWidth , canvasHeight );
276+ canvas .addPaintListener (e -> {
277+ e .gc .drawImage (image , 0 , 0 , bounds .width , bounds .height ,
278+ 0 , 0 , canvasWidth , canvasHeight );
279+ });
280+
281+ shell .open ();
282+ Image target = new Image (display , canvasWidth , canvasHeight );
283+ GC gcCopy = new GC (canvas );
284+ gcCopy .copyArea (target , 0 , 0 );
285+ gcCopy .dispose ();
286+
287+ ImageData data = target .getImageData ();
288+
289+ int bottomRightX = canvasWidth - 1 ;
290+ int bottomRightY = canvasHeight - 1 ;
291+ RGB bottomRight = data .palette .getRGB (data .getPixel (bottomRightX , bottomRightY ));
292+ RGB black = new RGB (0 , 0 , 0 );
293+ assertEquals ( black , bottomRight , "Bottom-right pixel is not black! when source GC is not autoScalable" );
294+ shell .dispose ();
295+ target .dispose ();
296+ image .dispose ();
297+ }
298+
250299@ Test
251300public void test_drawArcIIIIII () {
252301 gc .drawArc (10 , 20 , 50 , 25 , 90 , 90 );
0 commit comments