use of org.apache.hop.core.svg.SvgCacheEntry in project hop by apache.
the class SvgGc method drawImage.
@Override
public void drawImage(SvgFile svgFile, int x, int y, int desiredWidth, int desiredHeight, float magnification, double angle) throws HopException {
//
try {
// Let's not hammer the file system all the time, keep the SVGDocument in memory
//
SvgCacheEntry cacheEntry = SvgCache.loadSvg(svgFile);
SVGDocument svgDocument = cacheEntry.getSvgDocument();
// How much more do we need to scale the image.
// If the width of the icon is 500px and we desire 50px then we need to scale to 10% times the
// magnification
//
float xScaleFactor = magnification * desiredWidth / cacheEntry.getWidth();
float yScaleFactor = magnification * desiredHeight / cacheEntry.getHeight();
// We want to scale evenly so what's the lowest magnification?
//
xScaleFactor = Math.min(xScaleFactor, yScaleFactor);
yScaleFactor = Math.min(xScaleFactor, yScaleFactor);
gc.embedSvg(svgDocument.getRootElement(), svgFile.getFilename(), x - cacheEntry.getX(), y - cacheEntry.getY(), cacheEntry.getWidth(), cacheEntry.getHeight(), xScaleFactor, yScaleFactor, Math.toDegrees(angle));
} catch (Exception e) {
throw new HopException("Unable to load SVG file '" + svgFile.getFilename() + "'", e);
}
}
use of org.apache.hop.core.svg.SvgCacheEntry 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.svg.SvgCacheEntry 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.svg.SvgCacheEntry 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