Skip to content

Commit d4c3036

Browse files
committed
[win32] Foward native zoom to draw bitmap in GC
This commit adapts the logic when a bitmap or icon is drawn with the GC in the windows implementation. As of now, the autoscale zoom was used to identify the image handle to use. If the image is itself drawn with a ImageGCDrawer, information about the original native zoom was lost, which led to inconsistencies in fonts depending on the auto scale mode. This commit fowards the native zoom in this case to enable the Image to initialize the GC accordingly. fixes #2385 fixes #2311
1 parent a71bea9 commit d4c3036

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ private void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int src
12531253
}
12541254
return;
12551255
}
1256-
long imageHandle = Image.win32_getHandle(srcImage, imageZoom);
1256+
long imageHandle = srcImage.getHandle(imageZoom, data.nativeZoom);
12571257
switch (srcImage.type) {
12581258
case SWT.BITMAP:
12591259
drawBitmap(srcImage, imageHandle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
@@ -4384,7 +4384,7 @@ private void init(Drawable drawable, GCData data, long hDC) {
43844384
}
43854385
Image image = data.image;
43864386
if (image != null) {
4387-
data.hNullBitmap = OS.SelectObject(hDC, Image.win32_getHandle(image, data.nativeZoom));
4387+
data.hNullBitmap = OS.SelectObject(hDC, image.getHandle(data.imageZoom, data.nativeZoom));
43884388
image.memGC = this;
43894389
}
43904390
int layout = data.layout;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public final class GCData {
4848
public float lineMiterLimit = 10;
4949
public int alpha = 0xFF;
5050
public int nativeZoom;
51+
int imageZoom;
5152

5253
public Image image;
5354
public PAINTSTRUCT ps;
@@ -67,6 +68,7 @@ void copyTo(GCData originalData) {
6768
originalData.font = font;
6869
originalData.nativeZoom = nativeZoom;
6970
originalData.image = image;
71+
originalData.imageZoom = imageZoom;
7072
originalData.ps = ps;
7173
originalData.layout = layout;
7274
originalData.hwnd = hwnd;

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,10 +809,15 @@ private ImageHandle getImageMetadata(ZoomContext zoomContext) {
809809
* @noreference This method is not intended to be referenced by clients.
810810
*/
811811
public static long win32_getHandle (Image image, int zoom) {
812-
if (image.isDisposed()) {
812+
return image.getHandle(zoom, zoom);
813+
}
814+
815+
long getHandle (int targetZoom, int nativeZoom) {
816+
if (isDisposed()) {
813817
return 0L;
814818
}
815-
return image.getImageMetadata(new ZoomContext(zoom)).handle;
819+
ZoomContext zoomContext = imageProvider.getFittingZoomContext(targetZoom, nativeZoom);
820+
return getImageMetadata(zoomContext).handle;
816821
}
817822

818823
/**
@@ -1752,6 +1757,7 @@ private long configureGC(GCData data, ZoomContext zoomContext) {
17521757
}
17531758
data.device = device;
17541759
data.nativeZoom = zoomContext.nativeZoom();
1760+
data.imageZoom = zoomContext.targetZoom();
17551761
data.image = this;
17561762
data.font = SWTFontProvider.getSystemFont(device, zoomContext.nativeZoom());
17571763
}
@@ -1913,6 +1919,10 @@ private abstract class AbstractImageProviderWrapper {
19131919

19141920
protected abstract Rectangle getBounds(int zoom);
19151921

1922+
protected ZoomContext getFittingZoomContext(int targetZoom, int nativeZoom) {
1923+
return new ZoomContext(targetZoom);
1924+
}
1925+
19161926
protected long configureGCData(GCData data) {
19171927
return configureGC(data, new ZoomContext(100));
19181928
}
@@ -2138,14 +2148,22 @@ private class PlainImageProviderWrapper extends AbstractImageProviderWrapper {
21382148
type = SWT.BITMAP;
21392149
}
21402150

2151+
@Override
2152+
protected ZoomContext getFittingZoomContext(int targetZoom, int nativeZoom) {
2153+
if (memGC != null) {
2154+
return new ZoomContext(targetZoom, nativeZoom);
2155+
}
2156+
return super.getFittingZoomContext(targetZoom, nativeZoom);
2157+
}
2158+
21412159
@Override
21422160
public Collection<Integer> getPreservedZoomLevels() {
21432161
return Collections.singleton(baseZoom);
21442162
}
21452163

21462164
@Override
21472165
protected long configureGCData(GCData data) {
2148-
return configureGC(data, new ZoomContext(DPIUtil.getDeviceZoom()));
2166+
return configureGC(data, new ZoomContext(DPIUtil.getDeviceZoom(), DPIUtil.getNativeDeviceZoom()));
21492167
}
21502168

21512169
@Override
@@ -2577,6 +2595,11 @@ private class ImageGcDrawerWrapper extends DynamicImageProviderWrapper {
25772595
this.height = height;
25782596
}
25792597

2598+
@Override
2599+
protected ZoomContext getFittingZoomContext(int targetZoom, int nativeZoom) {
2600+
return new ZoomContext(targetZoom, nativeZoom);
2601+
}
2602+
25802603
@Override
25812604
protected Rectangle getBounds(int zoom) {
25822605
Rectangle rectangle = new Rectangle(0, 0, width, height);

0 commit comments

Comments
 (0)