Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2025 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1520,8 +1520,19 @@ private void initUsingImageDataProvider(ImageDataProvider imageDataProvider) {
private static ImageDataProvider createImageDataProvider(InputStream stream) throws IOException {
byte[] streamData = stream.readAllBytes();
if (ImageDataLoader.isDynamicallySizable(new ByteArrayInputStream(streamData))) {
ImageDataAtSizeProvider imageDataAtSizeProvider = (width, height) -> 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);
}
};
return imageDataAtSizeProvider;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2025 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -811,8 +811,19 @@ private void initFromImageDataProvider(int zoom) {
private static ImageDataProvider createImageDataProvider(InputStream stream) throws IOException {
byte[] streamData = stream.readAllBytes();
if (ImageDataLoader.isDynamicallySizable(new ByteArrayInputStream(streamData))) {
ImageDataAtSizeProvider imageDataAtSizeProvider = (width, height) -> 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);
}
};
return imageDataAtSizeProvider;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2025 Vector Informatik GmbH and others.
* Copyright (c) 2025, 2026 Vector Informatik GmbH and others.
*
* This program and the accompanying materials are made available under the terms of the Eclipse
* Public License 2.0 which accompanies this distribution, and is available at
Expand All @@ -13,8 +13,11 @@
package org.eclipse.swt.tests.junit;

import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;

import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -42,10 +45,31 @@ private static String getPath(String fileName) {
return SwtTestUtil.getPath(fileName, tempFolder).toString();
}

@Test
public void test_ConstructorLorg_eclipse_swt_graphics_Device_InputStream() throws IOException {
Image image = null;
try (InputStream is = getClass().getResourceAsStream("collapseall.svg")) {
image = new Image(Display.getDefault(), is);
}
ImageData imageData = image.getImageData();
assertEquals(16, imageData.width);
assertEquals(16, imageData.height);
image.dispose();

try (InputStream is = getClass().getResourceAsStream("corrupt.svg")) {
SWTException e = assertThrows(SWTException.class,
() -> new Image(Display.getDefault(), is));
assertSWTProblem("Incorrect exception thrown for provider with corrupt images", SWT.ERROR_INVALID_IMAGE, e);
}
}

@Test
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvider() {
ImageFileNameProvider validImageFileNameProvider = zoom -> getPath("collapseall.svg");
Image image = new Image(Display.getDefault(), validImageFileNameProvider);
ImageData imageData = image.getImageData();
assertEquals(16, imageData.width);
assertEquals(16, imageData.height);
image.dispose();

ImageFileNameProvider corruptImageFileNameProvider = zoom -> getPath("corrupt.svg");
Expand All @@ -58,6 +82,9 @@ public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvid
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider() {
ImageDataProvider validImageDataProvider = zoom -> (zoom == 100) ? new ImageData(getPath("collapseall.svg")) : null;
Image image = new Image(Display.getDefault(), validImageDataProvider);
ImageData imageData = image.getImageData();
assertEquals(16, imageData.width);
assertEquals(16, imageData.height);
image.dispose();

ImageDataProvider corruptImageDataProvider = zoom -> (zoom == 100) ? new ImageData(getPath("corrupt.svg")) : null;
Expand Down
Loading