use of org.pentaho.di.core.SwtUniversalImageSvg in project pentaho-kettle by pentaho.
the class KettleXulLoader method getResourceAsStream.
@Override
public InputStream getResourceAsStream(String resource) {
int height = iconHeight;
int width = iconWidth;
if (resource.contains(":")) {
// we have height/width overrides
width = Integer.parseInt(resource.substring(resource.indexOf(":") + 1, resource.indexOf("#")));
height = Integer.parseInt(resource.substring(resource.indexOf("#") + 1, resource.indexOf(".")));
resource = resource.substring(0, resource.indexOf(":")) + resource.substring(resource.indexOf("."));
}
if (SvgSupport.isSvgEnabled() && (SvgSupport.isSvgName(resource) || SvgSupport.isPngName(resource))) {
InputStream in = null;
try {
in = super.getResourceAsStream(SvgSupport.toSvgName(resource));
// load SVG
SvgImage svg = SvgSupport.loadSvgImage(in);
SwtUniversalImage image = new SwtUniversalImageSvg(svg);
Display d = Display.getCurrent() != null ? Display.getCurrent() : Display.getDefault();
// write to png
Image result = image.getAsBitmapForSize(d, width, height);
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { result.getImageData() };
ByteArrayOutputStream out = new ByteArrayOutputStream();
loader.save(out, SWT.IMAGE_PNG);
image.dispose();
return new ByteArrayInputStream(out.toByteArray());
} catch (Throwable ignored) {
// any exception will result in falling back to PNG
} finally {
IOUtils.closeQuietly(in);
}
resource = SvgSupport.toPngName(resource);
}
return super.getResourceAsStream(resource);
}
use of org.pentaho.di.core.SwtUniversalImageSvg in project pentaho-kettle by pentaho.
the class KettleImageUtil method loadImages.
/**
* Load multiple images from svg, or just png file.
*/
public static Image[] loadImages(XulDomContainer container, Shell shell, String resource) {
Display d = shell.getDisplay();
if (d == null) {
d = Display.getCurrent() != null ? Display.getCurrent() : Display.getDefault();
}
if (SvgSupport.isSvgEnabled() && (SvgSupport.isSvgName(resource) || SvgSupport.isPngName(resource))) {
InputStream in = null;
try {
in = getResourceInputStream(resource, container);
// getResourceInputStream( SvgSupport.toSvgName( resource ) );
// load SVG
SvgImage svg = SvgSupport.loadSvgImage(in);
SwtUniversalImage image = new SwtUniversalImageSvg(svg);
Image[] result = new Image[IMAGE_SIZES.length];
for (int i = 0; i < IMAGE_SIZES.length; i++) {
result[i] = image.getAsBitmapForSize(d, IMAGE_SIZES[i], IMAGE_SIZES[i]);
}
return result;
} catch (Throwable ignored) {
// any exception will result in falling back to PNG
ignored.printStackTrace();
} finally {
IOUtils.closeQuietly(in);
}
resource = SvgSupport.toPngName(resource);
}
InputStream in = null;
try {
in = getResourceInputStream(resource, container);
return new Image[] { new Image(d, in) };
} catch (Throwable ignored) {
// any exception will result in falling back to PNG
} finally {
IOUtils.closeQuietly(in);
}
return null;
}
Aggregations