-
Notifications
You must be signed in to change notification settings - Fork 191
Fix improper ImageData size when loading SVG from InputStream #3011 #3012
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
Test Results 176 files 176 suites 28m 12s ⏱️ Results for commit 5058445. ♻️ This comment has been updated with latest results. |
| Point defaultSize = new Point(imageData.width, imageData.height); | ||
| ImageDataAtSizeProvider imageDataAtSizeProvider = new ImageDataAtSizeProvider() { | ||
| @Override | ||
| public Point getDefaultSize() { | ||
| return defaultSize; | ||
| } | ||
|
|
||
| @Override | ||
| public ImageData getImageData(int width, int height) { | ||
| if (width == defaultSize.x && height == defaultSize.y) { | ||
| return imageData; | ||
| } | ||
| return ImageDataLoader.loadBySize(new ByteArrayInputStream(streamData), width, height); | ||
| } | ||
| }; |
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 should work, still I would propose to just implement the getImageData(zoom) method instead of the getDefaultSize() method because of two reasons:
- You avoid loading the 100% image data even though you potentially do not need the data (but just the size)
- In general, the advice is to overwrite
getImageData(zoom)in case the provider (the file) specifies the default 100% size andgetDefaultSize()in case the consumer does it. In this case, you want to have the provider (the file) specify the 100% size, which is why simply loading the file in the existing by-zoom way is most appropriate. In the current proposa, the provider specifies the size, stillgetDefaultSize()is overwritten, which makes this workaround of loading the data at 100% to extract the provider size which is then passed by the consumer again necessary.
| Point defaultSize = new Point(imageData.width, imageData.height); | |
| ImageDataAtSizeProvider imageDataAtSizeProvider = new ImageDataAtSizeProvider() { | |
| @Override | |
| public Point getDefaultSize() { | |
| return defaultSize; | |
| } | |
| @Override | |
| public ImageData getImageData(int width, int height) { | |
| if (width == defaultSize.x && height == defaultSize.y) { | |
| return imageData; | |
| } | |
| return ImageDataLoader.loadBySize(new ByteArrayInputStream(streamData), width, height); | |
| } | |
| }; | |
| ImageDataAtSizeProvider imageDataAtSizeProvider = new ImageDataAtSizeProvider() { | |
| @Override | |
| public ImageData getImageData(int zoom) { | |
| return ImageDataLoader.loadByZoom(new ByteArrayInputStream(streamData), FileFormat.DEFAULT_ZOOM, zoom).element(); | |
| } | |
| @Override | |
| public ImageData getImageData(int width, int height) { | |
| return ImageDataLoader.loadBySize(new ByteArrayInputStream(streamData), width, height); | |
| } | |
| }; |
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 wasn't really sure which of the default methods to override, but that makes sense, of course. The call to getDefaultSize() no longer returns a meaningful size, but that's probably not releveant for an instance that is only used internally.
7d7de55 to
9ec8bcc
Compare
…-platform#3011 On Linux and MacOS, loading an `Image` from an `InputStream` is internally handled via an `ImageDataAtSizeProvider`. When loading `ImageData` by zoom, this interface requires a proper implementation of the `getDefaultSize()` or `getImageData(int)` method. Otherwise an `ImageData` of size 1x1 is returned at 100% zoom, otherwise `null`. The tests have been updated to test the loading of an `Image` from an `InputStream` and to also check the size of the `ImageData` at 100% zoom. Closes eclipse-platform#3011
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.
Thank you, @ptziegler!
The fix is sound and works fine on both MacOS and Linux.
On Linux, loading an
Imagefrom anInputStreamis internally handled via anImageDataAtSizeProvider.When loading
ImageDataby zoom, this interface requires a proper implementation of thegetDefaultSize()method, which in return requires theImageDatabe loaded at 100% zoom, even when the source data is dynamically sizable. To avoid loading the same resource twice, this data is then used when requesting theImageDatawith default size.The tests have been updated to test the loading of an
Imagefrom anInputStreamand to also check the size of theImageDataat 100% zoom.Closes #3011