public static BufferedImage getResourceBitmap(InputStream inputStream, String name, float scaleFactor, float defaultSize, int width, int height, int percent) throws IOException { try { URI uri = SVGCache.getSVGUniverse().loadSVG(inputStream, name); SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); double scale = scaleFactor / Math.sqrt((diagram.getHeight() * diagram.getWidth()) / defaultSize); float[] bmpSize = GraphicUtils.imageSize(diagram.getWidth(), diagram.getHeight(), (float) scale, width, height, percent); SVGIcon icon = new SVGIcon(); icon.setAntiAlias(true); icon.setAutosize(SVGIcon.AUTOSIZE_STRETCH); icon.setPreferredSize(new Dimension((int) bmpSize[0], (int) bmpSize[1])); icon.setSvgURI(uri); BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(null, bufferedImage.createGraphics(), 0, 0); return bufferedImage; } catch (Exception e) { throw new IOException(e); } }
@Override public int getHeight() { return (int)Math.ceil(diagram.getHeight()); }
@Override public int getHeight() { return (int)Math.ceil(diagram.getHeight()); }
private boolean isAutoSizeBestFitUseFixedHeight(final int iconWidthIgnoreAutosize, final int iconHeightIgnoreAutosize, final SVGDiagram diagram) { return iconHeightIgnoreAutosize/diagram.getHeight() < iconWidthIgnoreAutosize/diagram.getWidth(); }
/** * @return height of this icon */ public int getIconHeight() { if (scaleToFit && preferredSize != null) { return preferredSize.height; } SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram == null) return 0; return (int)diagram.getHeight(); }
private boolean isAutoSizeBestFitUseFixedHeight(final int iconWidthIgnoreAutosize, final int iconHeightIgnoreAutosize, final SVGDiagram diagram) { return iconHeightIgnoreAutosize/diagram.getHeight() < iconWidthIgnoreAutosize/diagram.getWidth(); }
/** * @return height of this icon */ public int getIconHeight() { if (scaleToFit && preferredSize != null) { return preferredSize.height; } SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram == null) { return 0; } return (int)diagram.getHeight(); }
/** * @return height of this icon */ public int getIconHeightIgnoreAutosize() { if (preferredSize != null && (autosize == AUTOSIZE_VERT || autosize == AUTOSIZE_STRETCH || autosize == AUTOSIZE_BESTFIT)) { return preferredSize.height; } SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram == null) { return 0; } return (int)diagram.getHeight(); }
/** * @return height of this icon */ public int getIconHeightIgnoreAutosize() { if (preferredSize != null && (autosize == AUTOSIZE_VERT || autosize == AUTOSIZE_STRETCH || autosize == AUTOSIZE_BESTFIT)) { return preferredSize.height; } SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram == null) { return 0; } return (int)diagram.getHeight(); }
public int getSVGHeight() { if (scaleToFit) return getPreferredSize().height; SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram == null) return 0; return (int)diagram.getHeight(); }
public Dimension getPreferredSize() { if (preferredSize == null) { SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram != null) { //preferredSize = new Dimension((int)diagram.getWidth(), (int)diagram.getHeight()); setPreferredSize(new Dimension((int)diagram.getWidth(), (int)diagram.getHeight())); } } return new Dimension(preferredSize); }
public int getSVGHeight() { if (scaleToFit) { return getPreferredSize().height; } SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram == null) { return 0; } return (int)diagram.getHeight(); }
public Dimension getPreferredSize() { if (preferredSize == null) { SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram != null) { //preferredSize = new Dimension((int)diagram.getWidth(), (int)diagram.getHeight()); setPreferredSize(new Dimension((int)diagram.getWidth(), (int)diagram.getHeight())); } } return new Dimension(preferredSize); }
public Dimension getPreferredSize() { if (preferredSize == null) { SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram != null) { //preferredSize = new Dimension((int)diagram.getWidth(), (int)diagram.getHeight()); setPreferredSize(new Dimension((int)diagram.getWidth(), (int)diagram.getHeight())); } } return new Dimension(preferredSize); }
public Dimension getPreferredSize() { if (preferredSize == null) { SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram != null) { //preferredSize = new Dimension((int)diagram.getWidth(), (int)diagram.getHeight()); setPreferredSize(new Dimension((int)diagram.getWidth(), (int)diagram.getHeight())); } } return new Dimension(preferredSize); }
public int getSVGHeight() { if (autosize == AUTOSIZE_VERT || autosize == AUTOSIZE_STRETCH || autosize == AUTOSIZE_BESTFIT) { return getPreferredSize().height; } SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram == null) { return 0; } return (int)diagram.getHeight(); }
public int getSVGHeight() { if (autosize == AUTOSIZE_VERT || autosize == AUTOSIZE_STRETCH || autosize == AUTOSIZE_BESTFIT) { return getPreferredSize().height; } SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram == null) { return 0; } return (int)diagram.getHeight(); }
@Override public int getIconWidth() { final int iconWidthIgnoreAutosize = getIconWidthIgnoreAutosize(); final int iconHeightIgnoreAutosize = getIconHeightIgnoreAutosize(); final SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (preferredSize != null && (autosize == AUTOSIZE_VERT || (autosize == AUTOSIZE_BESTFIT && isAutoSizeBestFitUseFixedHeight(iconWidthIgnoreAutosize, iconHeightIgnoreAutosize, diagram)))) { final double aspectRatio = diagram.getHeight()/diagram.getWidth(); return (int)(iconHeightIgnoreAutosize / aspectRatio); } else { return iconWidthIgnoreAutosize; } }
@Override public int getIconHeight() { final int iconWidthIgnoreAutosize = getIconWidthIgnoreAutosize(); final int iconHeightIgnoreAutosize = getIconHeightIgnoreAutosize(); final SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (preferredSize != null && (autosize == AUTOSIZE_HORIZ || (autosize == AUTOSIZE_BESTFIT && !isAutoSizeBestFitUseFixedHeight(iconWidthIgnoreAutosize, iconHeightIgnoreAutosize, diagram)))) { final double aspectRatio = diagram.getHeight()/diagram.getWidth(); return (int)(iconWidthIgnoreAutosize * aspectRatio); } else { return iconHeightIgnoreAutosize; } }
@Override public int getIconWidth() { final int iconWidthIgnoreAutosize = getIconWidthIgnoreAutosize(); final int iconHeightIgnoreAutosize = getIconHeightIgnoreAutosize(); final SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (preferredSize != null && (autosize == AUTOSIZE_VERT || (autosize == AUTOSIZE_BESTFIT && isAutoSizeBestFitUseFixedHeight(iconWidthIgnoreAutosize, iconHeightIgnoreAutosize, diagram)))) { final double aspectRatio = diagram.getHeight()/diagram.getWidth(); return (int)(iconHeightIgnoreAutosize / aspectRatio); } else { return iconWidthIgnoreAutosize; } }