use of org.eclipse.swt.graphics.ImageDataProvider in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider.
@Test
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider() {
// Null provider
ImageDataProvider provider = null;
try {
Image image = new Image(display, provider);
image.dispose();
fail("No exception thrown for file name == null");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for provider == null", SWT.ERROR_NULL_ARGUMENT, e);
}
// Invalid provider
provider = zoom -> null;
try {
Image image = new Image(display, provider);
image.dispose();
fail("No exception thrown for non-existent file name");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for provider == null", SWT.ERROR_INVALID_ARGUMENT, e);
}
// Valid provider
Image image = new Image(display, imageDataProvider);
image.dispose();
// Corrupt Image provider
provider = zoom -> {
String fileName;
switch(zoom) {
case 100:
fileName = "corrupt.png";
break;
case 150:
fileName = "corrupt.png";
break;
case 200:
fileName = "corrupt.png";
break;
default:
return null;
}
return new ImageData(getPath(fileName));
};
try {
image = new Image(display, provider);
image.dispose();
fail("No exception thrown for corrupt image file.");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for provider with corrupt images", SWT.ERROR_INVALID_IMAGE, e);
}
// Valid provider only 100% zoom
provider = zoom -> {
String fileName;
switch(zoom) {
case 100:
fileName = "collapseall.png";
break;
case 150:
case 200:
default:
return null;
}
return new ImageData(getPath(fileName));
};
image = new Image(display, provider);
image.dispose();
}
use of org.eclipse.swt.graphics.ImageDataProvider in project eclipse.platform.text by eclipse.
the class LineNumberRulerColumn method doubleBufferPaint.
/**
* Double buffer drawing.
*
* @param dest the GC to draw into
*/
private void doubleBufferPaint(GC dest) {
Point size = fCanvas.getSize();
if (size.x <= 0 || size.y <= 0)
return;
if (fBuffer != null) {
Rectangle r = fBuffer.getBounds();
if (r.width != size.x || r.height != size.y) {
fBuffer.dispose();
fBuffer = null;
}
}
ILineRange visibleLines = JFaceTextUtil.getVisibleModelLines(fCachedTextViewer);
if (visibleLines == null)
return;
if (IS_MAC_BUG_516293) {
/* FIXME: Workaround (bug 516293):
* Relies on SWT implementation detail that GC drawing on macOS only draws at 100% zoom level.
* For higher zoom levels (200%), we manually scale the font and drawing coordinates,
* and then use getImageData(100) to extract the high-resolution image data. */
fBuffer = new Image(fCanvas.getDisplay(), (ImageDataProvider) zoom -> {
fZoom = zoom;
internalSetZoom(zoom);
int width = size.x * zoom / 100;
int height = size.y * zoom / 100;
Image gcImage = new Image(fCanvas.getDisplay(), width, height);
GC gc = new GC(gcImage);
Font font = fCanvas.getFont();
if (zoom != 100) {
if (fLastFont != null && font == fLastFont.get()) {
font = fLastZoomedFont;
} else {
fLastFont = new WeakReference<>(font);
FontData fontData = font.getFontData()[0];
fontData.setHeight(fontData.getHeight() * zoom / 100);
font = new Font(font.getDevice(), fontData);
fLastZoomedFont = font;
}
}
gc.setFont(font);
if (fForeground != null)
gc.setForeground(fForeground);
try {
gc.setBackground(getBackground(fCanvas.getDisplay()));
gc.fillRectangle(0, 0, width, height);
doPaint(gc, visibleLines);
} finally {
gc.dispose();
fZoom = 100;
}
ImageData imageData = gcImage.getImageData(100);
gcImage.dispose();
return imageData;
});
} else {
if (fBuffer == null)
fBuffer = new Image(fCanvas.getDisplay(), size.x, size.y);
GC gc = new GC(fBuffer);
gc.setFont(fCanvas.getFont());
if (fForeground != null)
gc.setForeground(fForeground);
try {
gc.setBackground(getBackground(fCanvas.getDisplay()));
gc.fillRectangle(0, 0, size.x, size.y);
doPaint(gc, visibleLines);
} finally {
gc.dispose();
}
}
dest.drawImage(fBuffer, 0, 0);
}
Aggregations