-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -554,11 +554,17 @@ public Image(Device device, ImageData source, ImageData mask) { | |||||||||||||||||||||
| */ | ||||||||||||||||||||||
| public Image(Device device, InputStream stream) { | ||||||||||||||||||||||
| super(device); | ||||||||||||||||||||||
| currentDeviceZoom = DPIUtil.getDeviceZoom(); | ||||||||||||||||||||||
| ElementAtZoom<ImageData> image = ImageDataLoader.loadByZoom(stream, FileFormat.DEFAULT_ZOOM, currentDeviceZoom); | ||||||||||||||||||||||
| ImageData data = DPIUtil.scaleImageData(device, image, currentDeviceZoom); | ||||||||||||||||||||||
| init(data); | ||||||||||||||||||||||
| init(); | ||||||||||||||||||||||
| if (stream == null) { | ||||||||||||||||||||||
| SWT.error(SWT.ERROR_NULL_ARGUMENT); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| currentDeviceZoom = DPIUtil.getDeviceZoom(); | ||||||||||||||||||||||
| this.imageDataProvider = createImageDataProvider(stream); | ||||||||||||||||||||||
| initFromImageDataProvider(currentDeviceZoom); | ||||||||||||||||||||||
| init(); | ||||||||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||||||||
| SWT.error(SWT.ERROR_IO, e); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
|
|
@@ -802,6 +808,20 @@ private void initFromImageDataProvider(int zoom) { | |||||||||||||||||||||
| init(resizedData); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private static ImageDataProvider createImageDataProvider(InputStream stream) throws IOException { | ||||||||||||||||||||||
| byte[] streamData = stream.readAllBytes(); | ||||||||||||||||||||||
| if (ImageDataLoader.isDynamicallySizable(new ByteArrayInputStream(streamData))) { | ||||||||||||||||||||||
| ImageDataAtSizeProvider imageDataAtSizeProvider = (width, height) -> ImageDataLoader | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work when loading the Lines 46 to 55 in c6ec34e
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||||||||||||||||||||||
| .loadBySize(new ByteArrayInputStream(streamData), width, height); | ||||||||||||||||||||||
| return imageDataAtSizeProvider; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ImageData imageData = ImageDataLoader | ||||||||||||||||||||||
| .loadByZoom(new ByteArrayInputStream(streamData), FileFormat.DEFAULT_ZOOM, 100) | ||||||||||||||||||||||
| .element(); | ||||||||||||||||||||||
| return zoom -> zoom == 100 ? imageData : null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| void createFromPixbuf(int type, long pixbuf) { | ||||||||||||||||||||||
| this.type = type; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.