Skip to content
Draft
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
Expand Up @@ -214,6 +214,8 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra
data.setPixel(9, 9, 0x30);
final Image imageFromImageData = new Image(display, data);
try {
int originalDeviceZoom = DPIUtil.getDeviceZoom();
DPIUtil.setDeviceZoom(100);
ImageGcDrawer gcDrawer = (gc, width, height) -> {
gc.drawImage(imageFromImageData, 0, 0);
};
Expand All @@ -224,6 +226,7 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra
assertEquals(getRealRGB(display.getSystemColor(SWT.COLOR_RED)), gcImageData.palette.getRGB(redPixel));
} finally {
gcImage.dispose();
DPIUtil.setDeviceZoom(originalDeviceZoom);
}
image.dispose();
} finally {
Expand Down Expand Up @@ -269,6 +272,8 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra
gc.fillRectangle(0, 0, 10, 10);
gc.drawImage(image2, 0, 0);
};
int originalDeviceZoom = DPIUtil.getDeviceZoom();
DPIUtil.setDeviceZoom(100);
Image gcImage = new Image(display, gcDrawer, 10, 10);
try {
ImageData gcImageData = gcImage.getImageData();
Expand All @@ -278,6 +283,7 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra
assertEquals(getRealRGB(backgroundColor), gcImageData.palette.getRGB(bluePixel));
} finally {
gcImage.dispose();
DPIUtil.setDeviceZoom(originalDeviceZoom);
}
image.dispose();
image2.dispose();
Expand Down Expand Up @@ -643,6 +649,7 @@ public void test_getBounds() {
@Test
public void test_getBoundsInPixels() {
Rectangle initialBounds = new Rectangle(0, 0, 10, 20);
Rectangle scaledInitialBounds = scaleBounds(initialBounds, DPIUtil.getDeviceZoom(), 100);
Image image1 = new Image(display, initialBounds.width, initialBounds.height);
image1.dispose();
SWTException e = assertThrows(SWTException.class, () -> image1.getBoundsInPixels());
Expand All @@ -655,7 +662,7 @@ public void test_getBoundsInPixels() {
Rectangle bounds = image.getBounds();
image.dispose();
assertEquals(initialBounds, bounds);
assertEquals(initialBounds, boundsInPixels);
assertEquals(scaledInitialBounds, boundsInPixels);

// create icon image
ImageData imageData = new ImageData(initialBounds.width, initialBounds.height, 1, new PaletteData(new RGB[] {new RGB(0, 0, 0)}));
Expand All @@ -664,29 +671,29 @@ public void test_getBoundsInPixels() {
bounds = image.getBounds();
image.dispose();
assertEquals(initialBounds, bounds);
assertEquals(initialBounds, boundsInPixels);
assertEquals(scaledInitialBounds, boundsInPixels);

// create image with FileNameProvider
image = new Image(display, imageFileNameProvider);
boundsInPixels = image.getBoundsInPixels();
bounds = image.getBounds();
image.dispose();
assertEquals(bounds, boundsInPixels);
assertEquals(scaleBounds(bounds, DPIUtil.getDeviceZoom(), 100), boundsInPixels);

// create image with ImageDataProvider
image = new Image(display, imageDataProvider);
boundsInPixels = image.getBoundsInPixels();
bounds = image.getBounds();
image.dispose();
assertEquals(bounds, boundsInPixels);
assertEquals(scaleBounds(bounds, DPIUtil.getDeviceZoom(), 100), boundsInPixels);

// create image with ImageGcDrawer
image = new Image(display, imageGcDrawer, initialBounds.width, initialBounds.height);
boundsInPixels = image.getBoundsInPixels();
bounds = image.getBounds();
image.dispose();
assertEquals(initialBounds, bounds);
assertEquals(initialBounds, boundsInPixels);
assertEquals(scaledInitialBounds, boundsInPixels);
}

@SuppressWarnings("removal")
Expand All @@ -704,31 +711,31 @@ public void test_getImageDataCurrentZoom() {
ImageData imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom();
image.dispose();
Rectangle boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height);
assertEquals(boundsAtCurrentZoom, bounds);
assertEquals(boundsAtCurrentZoom, scaleBounds(bounds, DPIUtil.getDeviceZoom(), 100));

// create icon image and compare size of imageData
ImageData imageData = new ImageData(bounds.width, bounds.height, 1, new PaletteData(new RGB[] {new RGB(0, 0, 0)}));
image = new Image(display, imageData);
imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom();
image.dispose();
boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height);
assertEquals(boundsAtCurrentZoom, bounds);
assertEquals(boundsAtCurrentZoom, scaleBounds(bounds, DPIUtil.getDeviceZoom(), 100));

// create image with FileNameProvider
image = new Image(display, imageFileNameProvider);
imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom();
boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height);
bounds = image.getBounds();
image.dispose();
assertEquals(boundsAtCurrentZoom, bounds);
assertEquals(boundsAtCurrentZoom, scaleBounds(bounds, DPIUtil.getDeviceZoom(), 100));

// create image with ImageDataProvider
image = new Image(display, imageDataProvider);
imageDataAtCurrentZoom = image.getImageDataAtCurrentZoom();
boundsAtCurrentZoom = new Rectangle(0, 0, imageDataAtCurrentZoom.width, imageDataAtCurrentZoom.height);
bounds = image.getBounds();
image.dispose();
assertEquals(boundsAtCurrentZoom, bounds);
assertEquals(boundsAtCurrentZoom, scaleBounds(bounds, DPIUtil.getDeviceZoom(), 100));
}

@Test
Expand Down
Loading