Skip to content

Commit b6a3721

Browse files
Delegating Image(Display, String) to ImageFileNameProvider to init Image
In GTK and Cocoa, an image based on an SVG passed as filename to Image(Device, String) will be drawn now sharply with this change.
1 parent 1bc596e commit b6a3721

File tree

2 files changed

+13
-16
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT

2 files changed

+13
-16
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -736,19 +736,11 @@ public Image(Device device, InputStream stream) {
736736
*/
737737
public Image(Device device, String filename) {
738738
super(device);
739-
NSAutoreleasePool pool = null;
740-
if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
741-
try {
742-
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
743-
initNative(filename);
744-
if (this.handle == null) {
745-
initWithSupplier(zoom -> ImageDataLoader.canLoadAtZoom(filename, FileFormat.DEFAULT_ZOOM, zoom),
746-
zoom -> ImageDataLoader.loadByZoom(filename, FileFormat.DEFAULT_ZOOM, zoom).element());
747-
}
748-
init();
749-
} finally {
750-
if (pool != null) pool.release();
751-
}
739+
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
740+
ImageFileNameProvider imageFileNameProvider = (ImageFileNameProvider) zoom -> {
741+
return zoom == 100 ? filename.toString() : null;
742+
};
743+
initUsingFileNameProvider(imageFileNameProvider);
752744
}
753745

754746
/**
@@ -783,6 +775,10 @@ public Image(Device device, String filename) {
783775
public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
784776
super(device);
785777
if (imageFileNameProvider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
778+
initUsingFileNameProvider(imageFileNameProvider);
779+
}
780+
781+
private void initUsingFileNameProvider(ImageFileNameProvider imageFileNameProvider) {
786782
this.imageFileNameProvider = imageFileNameProvider;
787783
String filename = imageFileNameProvider.getImagePath(100);
788784
if (filename == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,10 @@ public Image(Device device, String filename) {
597597
super(device);
598598
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
599599
currentDeviceZoom = DPIUtil.getDeviceZoom();
600-
ElementAtZoom<ImageData> image = ImageDataLoader.loadByZoom(filename, FileFormat.DEFAULT_ZOOM, currentDeviceZoom);
601-
ImageData data = DPIUtil.scaleImageData(device, image, currentDeviceZoom);
602-
init(data);
600+
this.imageFileNameProvider = (ImageFileNameProvider) zoom -> {
601+
return zoom == 100 ? filename.toString() : null;
602+
};
603+
initFromFileNameProvider(currentDeviceZoom);
603604
init();
604605
}
605606

0 commit comments

Comments
 (0)