-
Notifications
You must be signed in to change notification settings - Fork 191
Sharp rendering of SVGs passed as InputStream #2935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@ShahzaibIbrahim please provide a consistent PR description and at best show before/after screenshot. |
Hi @laeubi, This PR is not ready and hence it's currently drafted. |
I appreciate that it's marked as a draft, but even draft PRs should contain a clear title and meaningful description explaining what you're working on and what the expected outcome is. This helps maintainers understand the context and provide better guidance early in the process. The SWT repository should have draft PRs that clearly communicate:
If you need to run CI checks while developing, you can do that on your fork as well. Please update the PR description before continuing, so we can provide better feedback. Thanks! |
9d99069 to
3f0b54c
Compare
I have updated the PR description with all the sufficient information I currently have. |
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
|
Some early feedback on Mac for this one... Here's a screenshot running this Snippet of the changes in this PR and #2924
@ShahzaibIbrahim Thank-you for your work on this and #2924 |
25abe2b to
e4cd2a2
Compare
|
@HeikoKlare I think tests are fixed. Can you please test my snippet on multiple zoom level on mac to mark this PR ready for review? |
e4cd2a2 to
4cdd05f
Compare
HeikoKlare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up on the comment of @laeubi, wouldn't it be cleaner to wrap the input stream handling in an ImageDataProvider to not further mess up the Image implementation with mutual exclusive providers?
It might work as follows (starting from the InputStream constructor):
- Read stream data from stream
- Check if stream data belong to a dynamically sizable image, in that case create an
ImageDataAtSizeProviderotherwise create anImageDataProvider.- The
ImageDataAtSizeProviderwill store the stream data and return accordingly loaded image data in itsgetImageData(width, height)andgetImageData(zoom)methods - The
ImageDataProviderwill only return according image data at 100% and none for the other zoom, so it does not need to store the stream data
- The
Nothing needs to be changed for the loadImageDataAtExactSize then, as it reuses the ImageDataAtSizeProvider functionality.
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/SVGImageTests.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
d8ac328 to
df2bf7a
Compare
I have adapted the changes as per your recommendation. It looks good in GTK but some tests are failing in cocoa but I can't figure why. Can you please test for me in mac? @HeikoKlare |
HeikoKlare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have adapted the changes as per your recommendation. It looks good in GTK but some tests are failing in cocoa but I can't figure why. Can you please test for me in mac?
This change uncovered a bug in the image copy implementation for MacOS. I have created a PR to fix it:
When rebasing your PR on top of that fix, the tests should succeed. Meanwhile, I left some comments for further improvement of the PR.
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
b3701bb to
f7b36dc
Compare
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
e095d5c to
c71c599
Compare
c71c599 to
58a7a2a
Compare
HeikoKlare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested on MacOS again and it works like expected. Code is also fine now.
58a7a2a to
8aaf426
Compare
Wrapping the input stream handling in an ImageDataProvider. In case stream data belong to a dynamically sizable image we create a provider with ImageDataAtSizeProvider else we use ImageDataProvider. - The ImageDataAtSizeProvider will store the stream data and return accordingly loaded image data in its getImageData(width, height) and getImageData(zoom) methods. - The ImageDataProvider will only return according image data at 100% and none for the other zoom, so it does not need to store the stream data. Contributes to: eclipse-platform#2917
8aaf426 to
8e281f9
Compare
| private static ImageDataProvider createImageDataProvider(InputStream stream) throws IOException { | ||
| byte[] streamData = stream.readAllBytes(); | ||
| if (ImageDataLoader.isDynamicallySizable(new ByteArrayInputStream(streamData))) { | ||
| ImageDataAtSizeProvider imageDataAtSizeProvider = (width, height) -> ImageDataLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work when loading the ImageData of an Image by zoom. Because the getDefaultSize() method is not overridden, a 1x1 ImageData is returned at 100% zoom, otherwise null.
Lines 46 to 55 in c6ec34e
| default ImageData getImageData(int zoom) { | |
| Point defaultSize = getDefaultSize(); | |
| if (new Point(-1, -1).equals(defaultSize)) { | |
| if (zoom == 100) { | |
| return new ImageData(1, 1, 32, new PaletteData(0xFF0000, 0xFF00, 0xFF)); | |
| } | |
| return null; | |
| } | |
| return getImageData(DPIUtil.pointToPixel(defaultSize.x, zoom), DPIUtil.pointToPixel(defaultSize.y, zoom)); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, I even though about that case when reviewing the PR and somehow didn't follow-up on it. Too bad that there was not even a test for it. Thank you for fixing that with #3012!


Wrapping the input stream handling in an ImageDataProvider. In case stream data belong to a dynamically sizable image we create a provider with ImageDataAtSizeProvider else we use ImageDataProvider.
Contributes to: #2917
How to Test
Results
Without this PR:

After Changes:
GTK:
Cocoa: