Skip to content

Conversation

@ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Jan 2, 2026

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.

resolves: #2917

How to Test

Run this Snippet on Windows, Mac and Linux and compare the results:

import java.nio.file.Path;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageFileNameProvider;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class SVGImageTests {
    
    public static void main(String[] args) throws Exception {
        final Display display = new Display();

        final Shell shell = new Shell(display);
        shell.setText("SVG Image Test");
        shell.setLayout(new FillLayout());
        shell.setBounds(250, 50, 1000, 400);
        shell.setBackground(new Color(255, 255, 255));
        
        String imgPath = "image.svg";
        Path fullPath = Path.of(SVGImageTests.class.getResource(imgPath).toURI());

        // Image loaded in file path
        Image image2 = new Image(display, fullPath.toString());
        
        // Image loaded in ImageFileNameProvider
        Image image3 = new Image(display, (ImageFileNameProvider) zoom -> {
            return zoom == 100 ? fullPath.toString() : null;
        });
        
        shell.addPaintListener(e -> {            
            e.gc.drawImage(image2, 340, 10, 300, 300);
            e.gc.drawText("Image(Display, String)", 420, 300);
            
            e.gc.drawImage(image3, 660, 10, 300, 300);
            e.gc.drawText("Image(Display, ImageFileNameProvider)", 700, 300);
        });
        
        shell.open();

        while(!shell.isDisposed()) {
            if(!display.readAndDispatch()) {
                display.sleep();
            }
        }

        display.dispose();
    }
}

Use this SVG image for the Snippet:

image

Here's the outputs...

On Windows all Image methods result in sharp output:

image

On Mac only using ImageFileNameProvider is sharp:

image

On Linux only using ImageFileNameProvider is sharp:

image

After Fix

Image use for testing:
eclipse16

GTK:

image

Cocoa:

image

@fedejeanne
Copy link
Member

On Mac it looks like this

grafik

@ShahzaibIbrahim
Copy link
Contributor Author

On Mac it looks like this

Thank you @fedejeanne for testing on Mac. I will be using your screenshot for my PR description.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Test Results (macos)

   54 files  ±0     54 suites  ±0   7m 32s ⏱️ +43s
4 513 tests ±0  4 270 ✅ ±0  243 💤 ±0  0 ❌ ±0 
  104 runs  ±0    104 ✅ ±0    0 💤 ±0  0 ❌ ±0 

Results for commit 3896684. ± Comparison against base commit 892be33.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Test Results (linux)

   88 files  ±0     88 suites  ±0   14m 13s ⏱️ -25s
4 557 tests ±0  4 337 ✅ ±0  220 💤 ±0  0 ❌ ±0 
  211 runs  ±0    208 ✅ ±0    3 💤 ±0  0 ❌ ±0 

Results for commit 7099e36. ± Comparison against base commit 892be33.

♻️ This comment has been updated with latest results.

@Phillipus
Copy link
Contributor

I tested my original Snippet on Mac and the quality is as good as ImageFileNameProvider:

Screenshot 2026-01-02 at 15 29 07

@Phillipus
Copy link
Contributor

And on Linux it also looks good:

Screenshot from 2026-01-02 15-45-28

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the master-566 branch 2 times, most recently from 0a7d45c to a99e984 Compare January 2, 2026 16:21
Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR currently seems to lack a reference to the original issue (#2917). Would be nice to have it referenced in the commit and PR message.

I think it would also be great to add that snippet or a comparable one to the SWT snippets (may be done in a separate PR). If I am not mistaken, we have no snippet for testing SVG behavior yet, which is also why the snippets do not contain any SVG test image, so everytime you want to try something you have to copy one over. @Phillipus as you provided an extended version of the snippet in the reported issue, maybe you want to contribute it to the snippets project?

@Phillipus
Copy link
Contributor

Phillipus commented Jan 3, 2026

@Phillipus as you provided an extended version of the snippet in the reported issue, maybe you want to contribute it to the snippets project?

#2926

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the master-566 branch 2 times, most recently from ce8f5ac to 2a142e4 Compare January 5, 2026 09:11
@ShahzaibIbrahim
Copy link
Contributor Author

This PR currently seems to lack a reference to the original issue (#2917). Would be nice to have it referenced in the commit and PR message.

Adapted the commit message to reference original issue.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks fine and straightforward. I have a minor comment regarding the kind of refactoring (consistency with existing code structure) in the Cocoa implementation.

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the master-566 branch 2 times, most recently from 74ee641 to 7099e36 Compare January 5, 2026 13:42
Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation still looks good and works as expected on MacOS as well. I only have minor comments left.

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.

Resolves: eclipse-platform#2917
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants