diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java index 8d619bd4eb..cce24a1107 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java @@ -281,6 +281,19 @@ static int checkStyle (int style) { return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); } +private float calculateTransformationScale() { + if (data.transform == null) { + return 1.0f; + } + // this calculates the effective length in x and y + // direction without being affected by the rotation + // of the transformation + NSAffineTransformStruct struct = data.transform.transformStruct(); + float scaleWidth = (float) Math.hypot(struct.m11, struct.m21); + float scaleHeight = (float) Math.hypot(struct.m12, struct.m22); + return Math.max(scaleWidth, scaleHeight); +} + /** * Invokes platform specific functionality to allocate a new graphics context. *

@@ -1143,7 +1156,12 @@ public void drawImage(Image image, int x, int y) { if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true); + if (data.transform != null) { + Rectangle imageBounds = image.getBounds(); + drawImage(image, x, y, imageBounds.width, imageBounds.height); + } else { + drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true); + } } /** @@ -1238,9 +1256,12 @@ public void drawImage(Image image, int destX, int destY, int destWidth, int dest if (image.isDisposed()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } + float transformationScale = calculateTransformationScale(); + int scaledWidth = Math.round(destWidth * transformationScale); + int scaledHeight = Math.round(destHeight * transformationScale); image.executeOnImageAtSizeBestFittingSize(imageAtSize -> { drawImage(imageAtSize, 0, 0, imageAtSize.width, imageAtSize.height, destX, destY, destWidth, destHeight, false); - }, destWidth, destHeight); + }, scaledWidth, scaledHeight); } void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java index e2760ab9d0..cafb4f9146 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java @@ -58,8 +58,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -395,7 +393,6 @@ public void test_drawImageLorg_eclipse_swt_graphics_ImageIIII() { } @Test -@DisabledOnOs(OS.MAC) public void test_drawImageLorg_eclipse_swt_graphics_ImageIIII_withTransform() throws IOException { Image image = null; try (InputStream is = getClass().getResourceAsStream("collapseall.svg")) {