Search in sources :

Example 1 with SvgCacheEntry

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);
    }
}
Also used : HopException(org.apache.hop.core.exception.HopException) SvgCacheEntry(org.apache.hop.core.svg.SvgCacheEntry) SVGDocument(org.w3c.dom.svg.SVGDocument) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopException(org.apache.hop.core.exception.HopException)

Example 2 with SvgCacheEntry

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();
        }
    });
}
Also used : IHopFileType(org.apache.hop.ui.hopgui.file.IHopFileType) SvgCacheEntry(org.apache.hop.core.svg.SvgCacheEntry) SwtUniversalImageSvg(org.apache.hop.core.SwtUniversalImageSvg) SvgImage(org.apache.hop.core.svg.SvgImage) SvgImage(org.apache.hop.core.svg.SvgImage) Image(org.eclipse.swt.graphics.Image) SvgFile(org.apache.hop.core.svg.SvgFile) HopGuiExtensionPoint(org.apache.hop.ui.hopgui.HopGuiExtensionPoint) HopException(org.apache.hop.core.exception.HopException)

Example 3 with SvgCacheEntry

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);
    }
}
Also used : SvgCacheEntry(org.apache.hop.core.svg.SvgCacheEntry) SwtUniversalImageSvg(org.apache.hop.core.SwtUniversalImageSvg) SvgImage(org.apache.hop.core.svg.SvgImage) SwtUniversalImage(org.apache.hop.core.SwtUniversalImage) SvgImage(org.apache.hop.core.svg.SvgImage) Point(org.apache.hop.core.gui.Point)

Example 4 with SvgCacheEntry

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);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) SvgCacheEntry(org.apache.hop.core.svg.SvgCacheEntry) SwtUniversalImageSvg(org.apache.hop.core.SwtUniversalImageSvg) SvgImage(org.apache.hop.core.svg.SvgImage) Image(org.eclipse.swt.graphics.Image) SvgImage(org.apache.hop.core.svg.SvgImage) SvgFile(org.apache.hop.core.svg.SvgFile)

Aggregations

SvgCacheEntry (org.apache.hop.core.svg.SvgCacheEntry)4 SwtUniversalImageSvg (org.apache.hop.core.SwtUniversalImageSvg)3 SvgImage (org.apache.hop.core.svg.SvgImage)3 HopException (org.apache.hop.core.exception.HopException)2 SvgFile (org.apache.hop.core.svg.SvgFile)2 Image (org.eclipse.swt.graphics.Image)2 SwtUniversalImage (org.apache.hop.core.SwtUniversalImage)1 HopPluginException (org.apache.hop.core.exception.HopPluginException)1 Point (org.apache.hop.core.gui.Point)1 HopGuiExtensionPoint (org.apache.hop.ui.hopgui.HopGuiExtensionPoint)1 IHopFileType (org.apache.hop.ui.hopgui.file.IHopFileType)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 SVGDocument (org.w3c.dom.svg.SVGDocument)1