From 004719a3512b931c7c7962fbba4beaa365d1bd0e Mon Sep 17 00:00:00 2001 From: Andreas Koch Date: Tue, 6 May 2025 13:17:01 +0200 Subject: [PATCH] [win32] Improve GC init for ImageGcDrawer This commits wraps the GC initialization for the ImageGcDrawer to directly pass the zoom from the wrapper when the GC is initialized. In all other cases the GC will be initialized with 100 zoom. --- .../win32/org/eclipse/swt/graphics/Image.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index 7263a283a15..05c3fe8fd89 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -1719,6 +1719,10 @@ private ImageHandle init(ImageData i, int zoom) { */ @Override public long internal_new_GC (GCData data) { + return configureGC(data, 100); +} + +private long configureGC(GCData data, int zoom) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); /* * Create a new GC that can draw into the image. @@ -1743,9 +1747,9 @@ public long internal_new_GC (GCData data) { data.style |= SWT.LEFT_TO_RIGHT; } data.device = device; - data.nativeZoom = initialNativeZoom; + data.nativeZoom = zoom; data.image = this; - data.font = SWTFontProvider.getSystemFont(device, initialNativeZoom); + data.font = SWTFontProvider.getSystemFont(device, zoom); } return imageDC; } @@ -2530,7 +2534,7 @@ protected ImageHandle newImageHandle(int zoom) { } else { image = new Image(device, width, height, zoom); } - GC gc = new GC(image, gcStyle); + GC gc = new GC(new DrawableWrapper(image, zoom), gcStyle); try { gc.data.nativeZoom = zoom; drawer.drawOn(gc, width, height); @@ -2544,6 +2548,26 @@ protected ImageHandle newImageHandle(int zoom) { } } + private class DrawableWrapper implements Drawable { + private final Image image; + private final int zoom; + + public DrawableWrapper(Image image, int zoom) { + this.image = image; + this.zoom = zoom; + } + + @Override + public long internal_new_GC(GCData data) { + return this.image.configureGC(data, zoom); + } + + @Override + public void internal_dispose_GC(long handle, GCData data) { + this.image.internal_dispose_GC(handle, data); + } + } + @Override Object getProvider() { return drawer;