Skip to content

Commit e97143c

Browse files
HeikoKlareakoch-yatta
authored andcommitted
[Win32] Consider transformation scale in GC.drawImage(image, x, y) #2919
The GC.drawImage(image, x, y) does not consider a potential transformation applied to the GC when retrieving the best-fitting image handle. The other GC.drawImage() methods are already updated accordingly. The GC.drawImage(image, x, y) method has a special use case of drawing an image that is currently being rendered by another GC (like used in double-buffering scenarios for rulers), which also requires potentially different native and autoscale zooms to be used be applied when retrieving a handle. For that reason, this change only delegates a call for GC.drawImage(image, x, y) to the existing scaling GC.drawImage() method in case the transformation currently applied to the GC is not the identity, as that's not the use case for rendering an image currently generated by another GC. Fixes #2919
1 parent 057b24c commit e97143c

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -522,19 +522,6 @@ void disposeAll() {
522522
super.disposeAll();
523523
}
524524

525-
protected float calculateTransformationScale() {
526-
Transform current = new Transform(device);
527-
getTransform(current);
528-
float[] m = new float[6];
529-
current.getElements(m);
530-
// this calculates the effective length in x and y
531-
// direction without being affected by the rotation
532-
// of the transformation
533-
float scaleWidth = (float) Math.hypot(m[0], m[2]);
534-
float scaleHeight = (float) Math.hypot(m[1], m[3]);
535-
current.dispose();
536-
return Math.max(scaleWidth, scaleHeight);
537-
}
538525
}
539526

540527
private class CopyAreaToImageOperation extends ImageOperation {
@@ -1055,7 +1042,32 @@ public void drawImage (Image image, int x, int y) {
10551042
checkNonDisposed();
10561043
if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
10571044
if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
1058-
storeAndApplyOperationForExistingHandle(new DrawImageOperation(image, new Point(x, y)));
1045+
Transform transform = new Transform(device);
1046+
try {
1047+
getTransform(transform);
1048+
if (transform.isIdentity()) {
1049+
storeAndApplyOperationForExistingHandle(new DrawImageOperation(image, new Point(x, y)));
1050+
} else {
1051+
Rectangle imageBounds = image.getBounds();
1052+
drawImage(image, x, y, imageBounds.width, imageBounds.height);
1053+
}
1054+
} finally {
1055+
transform.dispose();
1056+
}
1057+
}
1058+
1059+
private float calculateTransformationScale() {
1060+
Transform current = new Transform(device);
1061+
getTransform(current);
1062+
float[] m = new float[6];
1063+
current.getElements(m);
1064+
// this calculates the effective length in x and y
1065+
// direction without being affected by the rotation
1066+
// of the transformation
1067+
float scaleWidth = (float) Math.hypot(m[0], m[2]);
1068+
float scaleHeight = (float) Math.hypot(m[1], m[3]);
1069+
current.dispose();
1070+
return Math.max(scaleWidth, scaleHeight);
10591071
}
10601072

10611073
private class DrawImageOperation extends ImageOperation {

0 commit comments

Comments
 (0)