use of org.apache.hop.core.SwtUniversalImageSvg in project hop by apache.
the class ExplorerPerspective method loadTypeImages.
private void loadTypeImages(Composite parentComposite) {
typeImageMap = new HashMap<>();
int iconSize = (int) (PropsUi.getInstance().getZoomFactor() * 16);
for (IHopFileType fileType : fileTypes) {
String imageFilename = fileType.getFileTypeImage();
if (imageFilename != null) {
try {
SvgCacheEntry svgCacheEntry = SvgCache.loadSvg(new SvgFile(imageFilename, fileType.getClass().getClassLoader()));
SwtUniversalImageSvg imageSvg = new SwtUniversalImageSvg(new SvgImage(svgCacheEntry.getSvgDocument()));
Image image = imageSvg.getAsBitmapForSize(hopGui.getDisplay(), iconSize, iconSize);
typeImageMap.put(fileType.getName(), image);
} catch (Exception e) {
hopGui.getLog().logError("Error loading image : '" + imageFilename + "' for type '" + fileType.getName() + "'", e);
}
}
}
// Properly dispose images when done...
//
parentComposite.addListener(SWT.Dispose, e -> {
for (Image image : typeImageMap.values()) {
image.dispose();
}
});
}
use of org.apache.hop.core.SwtUniversalImageSvg in project hop by apache.
the class SwtGc method drawImage.
@Override
public void drawImage(SvgFile svgFile, int x, int y, int desiredWidth, int desiredHeight, float magnification, double angle) throws HopException {
//
SvgCacheEntry cacheEntry = SvgCache.loadSvg(svgFile);
SwtUniversalImageSvg imageSvg = new SwtUniversalImageSvg(new SvgImage(cacheEntry.getSvgDocument()));
int magnifiedWidth = Math.round(desiredWidth * magnification);
int magnifiedHeight = Math.round(desiredHeight * magnification);
if (angle != 0) {
// A rotated image is blown up to twice its size to allow it to be rendered completely in the
// center
//
Image img = imageSvg.getAsBitmapForSize(gc.getDevice(), magnifiedWidth, magnifiedHeight, angle);
Rectangle bounds = img.getBounds();
int hx = Math.round(bounds.width / magnification);
int hy = Math.round(bounds.height / magnification);
gc.drawImage(img, 0, 0, bounds.width, bounds.height, x - hx / 2, y - hy / 2, hx, hy);
} else {
// Without rotation we simply draw the image with the desired width
//
Image img = imageSvg.getAsBitmapForSize(gc.getDevice(), magnifiedWidth, magnifiedHeight);
Rectangle bounds = img.getBounds();
gc.drawImage(img, 0, 0, bounds.width, bounds.height, x, y, desiredWidth, desiredHeight);
}
}
use of org.apache.hop.core.SwtUniversalImageSvg in project hop by apache.
the class SvgExplorerFileTypeHandler method paintControl.
private static void paintControl(PaintEvent event, ExplorerFile explorerFile, Canvas canvas) {
// Render the SVG file...
//
Rectangle area = canvas.getBounds();
try {
SvgCacheEntry entry = SvgCache.loadSvg(new SvgFile(explorerFile.getFilename(), SvgExplorerFileType.class.getClassLoader()));
SwtUniversalImageSvg svg = new SwtUniversalImageSvg(new SvgImage(entry.getSvgDocument()), true);
float factorX = (float) area.width / entry.getWidth();
float factorY = (float) area.height / entry.getHeight();
float minFactor = Math.min(factorX, factorY);
int imageWidth = (int) (entry.getWidth() * minFactor);
int imageHeight = (int) (entry.getHeight() * minFactor);
Image image = svg.getAsBitmapForSize(canvas.getDisplay(), imageWidth, imageHeight);
event.gc.drawImage(image, 0, 0);
} catch (Exception e) {
LogChannel.GENERAL.logError("Error rendering SVG", e);
}
}
Aggregations