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.

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   8m 2s ⏱️ +38s
4 513 tests ±0  4 270 ✅ ±0  243 💤 ±0  0 ❌ ±0 
  104 runs  ±0    104 ✅ ±0    0 💤 ±0  0 ❌ ±0 

Results for commit a99e984. ± Comparison against base commit 383ed2a.

♻️ 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 25s ⏱️ -7s
4 557 tests ±0  4 337 ✅ ±0  220 💤 ±0  0 ❌ ±0 
  211 runs  ±0    208 ✅ ±0    3 💤 ±0  0 ❌ ±0 

Results for commit a99e984. ± Comparison against base commit 383ed2a.

♻️ 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

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.
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sharp rendering of SVGs passed as filename to Image constructor when drawing at arbitrary size

4 participants