Skip to content

Commit d77cbb7

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
1 parent a71bea9 commit d77cbb7

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-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+
public 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: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,10 +809,20 @@ 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;
820+
if (imageProvider.supportComplexZoom()) {
821+
zoomContext = new ZoomContext(targetZoom, nativeZoom);
822+
} else {
823+
zoomContext = new ZoomContext(targetZoom);
824+
}
825+
return getImageMetadata(zoomContext).handle;
816826
}
817827

818828
/**
@@ -1752,6 +1762,7 @@ private long configureGC(GCData data, ZoomContext zoomContext) {
17521762
}
17531763
data.device = device;
17541764
data.nativeZoom = zoomContext.nativeZoom();
1765+
data.imageZoom = zoomContext.targetZoom();
17551766
data.image = this;
17561767
data.font = SWTFontProvider.getSystemFont(device, zoomContext.nativeZoom());
17571768
}
@@ -1913,6 +1924,10 @@ private abstract class AbstractImageProviderWrapper {
19131924

19141925
protected abstract Rectangle getBounds(int zoom);
19151926

1927+
protected boolean supportComplexZoom() {
1928+
return false;
1929+
}
1930+
19161931
protected long configureGCData(GCData data) {
19171932
return configureGC(data, new ZoomContext(100));
19181933
}
@@ -2138,14 +2153,19 @@ private class PlainImageProviderWrapper extends AbstractImageProviderWrapper {
21382153
type = SWT.BITMAP;
21392154
}
21402155

2156+
@Override
2157+
protected boolean supportComplexZoom() {
2158+
return memGC != null;
2159+
}
2160+
21412161
@Override
21422162
public Collection<Integer> getPreservedZoomLevels() {
21432163
return Collections.singleton(baseZoom);
21442164
}
21452165

21462166
@Override
21472167
protected long configureGCData(GCData data) {
2148-
return configureGC(data, new ZoomContext(DPIUtil.getDeviceZoom()));
2168+
return configureGC(data, new ZoomContext(DPIUtil.getDeviceZoom(), DPIUtil.getNativeDeviceZoom()));
21492169
}
21502170

21512171
@Override
@@ -2577,6 +2597,11 @@ private class ImageGcDrawerWrapper extends DynamicImageProviderWrapper {
25772597
this.height = height;
25782598
}
25792599

2600+
@Override
2601+
protected boolean supportComplexZoom() {
2602+
return true;
2603+
}
2604+
25802605
@Override
25812606
protected Rectangle getBounds(int zoom) {
25822607
Rectangle rectangle = new Rectangle(0, 0, width, height);

0 commit comments

Comments
 (0)