Search in sources :

Example 1 with SVGUniverse

use of com.kitfox.svg.SVGUniverse in project pivot by apache.

the class SVGDiagramSerializer method readObject.

@Override
public SVGDiagram readObject(InputStream inputStream) throws IOException {
    SVGUniverse universe = SVGCache.getSVGUniverse();
    URI location = universe.loadSVG(inputStream, NAME_PREFIX + (index++));
    return universe.getDiagram(location, true);
}
Also used : SVGUniverse(com.kitfox.svg.SVGUniverse) URI(java.net.URI)

Example 2 with SVGUniverse

use of com.kitfox.svg.SVGUniverse in project JWildfire by thargor6.

the class SvgFilePreview method createThumbnail.

public void createThumbnail() {
    if (currFile == null) {
        currThumbnail = null;
        return;
    }
    try {
        if (currFile.exists()) {
            SVGUniverse svgUniverse = new SVGUniverse();
            String svg = Tools.readUTF8Textfile(currFile.getAbsolutePath());
            StringReader reader = new StringReader(svg);
            SVGDiagram diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(reader, "svgImage"));
            int imgWidth = this.getPreferredSize().width;
            int imgHeight = this.getPreferredSize().height - BUTTON_HEIGHT;
            SimpleImage imgMap = new SimpleImage(imgWidth, imgHeight);
            Graphics2D g = imgMap.getBufferedImg().createGraphics();
            double sclX = (double) imgWidth / diagram.getWidth();
            double sclY = (double) imgHeight / diagram.getHeight();
            double scl = sclX < sclY ? sclX : sclY;
            g.scale(scl, scl);
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            diagram.render(g);
            currThumbnail = new ImageIcon(imgMap.getBufferedImg());
        }
    } catch (Exception ex) {
        currThumbnail = null;
        if (ex.getCause() != null) {
            ex.getCause().printStackTrace();
        } else {
            ex.printStackTrace();
        }
    }
}
Also used : SVGUniverse(com.kitfox.svg.SVGUniverse) ImageIcon(javax.swing.ImageIcon) SVGDiagram(com.kitfox.svg.SVGDiagram) SimpleImage(org.jwildfire.image.SimpleImage) StringReader(java.io.StringReader) Graphics2D(java.awt.Graphics2D)

Example 3 with SVGUniverse

use of com.kitfox.svg.SVGUniverse in project JWildfire by thargor6.

the class SVGWFFunc method getPoints.

@SuppressWarnings("unchecked")
private List<Point> getPoints() {
    if (_points == null) {
        String key = makeRessourceKey();
        _points = (List<Point>) RessourceManager.getRessource(key);
        if (_points == null) {
            try {
                SVGUniverse svgUniverse = new SVGUniverse();
                StringReader reader = new StringReader(svg);
                SVGDiagram diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(reader, "svgImage"));
                int imgWidth = Tools.FTOI(diagram.getWidth() * resolution_multiplier);
                int imgHeight = Tools.FTOI(diagram.getHeight() * resolution_multiplier);
                // SVGRoot root = diagram.getRoot();
                // root.setAttribute("width", AnimationElement.AT_XML, Integer.toString(imgWidth));
                // root.setAttribute("height", AnimationElement.AT_XML, Integer.toString(imgHeight));
                // root.build();
                SimpleImage imgMap = new SimpleImage(imgWidth, imgHeight);
                Graphics2D g = imgMap.getBufferedImg().createGraphics();
                g.scale(resolution_multiplier, resolution_multiplier);
                if (pre_antialias != 0) {
                    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                } else {
                    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
                    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                }
                diagram.render(g);
                Pixel pixel = new Pixel();
                _points = new ArrayList<Point>();
                int xMin = imgMap.getImageWidth() - 1, xMax = 0;
                int yMin = imgMap.getImageHeight() - 1, yMax = 0;
                for (int i = 0; i < imgMap.getImageHeight(); i++) {
                    for (int j = 0; j < imgMap.getImageWidth(); j++) {
                        int argb = imgMap.getARGBValue(j, i);
                        if (argb != 0) {
                            if (j < xMin) {
                                xMin = j;
                            } else if (j > xMax) {
                                xMax = j;
                            }
                            if (i < yMin) {
                                yMin = i;
                            } else if (i > yMax) {
                                yMax = i;
                            }
                        }
                    }
                }
                int xSize = xMax - xMin;
                int ySize = yMax - yMin;
                int maxSize = xSize > ySize ? xSize : ySize;
                if (maxSize > 0) {
                    for (int i = 0; i < imgMap.getImageHeight(); i++) {
                        for (int j = 0; j < imgMap.getImageWidth(); j++) {
                            int argb = imgMap.getARGBValue(j, i);
                            if (argb != 0) {
                                double x = ((j - xMin) - xSize / 2.0) / (double) maxSize;
                                double y = ((i - yMin) - ySize / 2.0) / (double) maxSize;
                                pixel.setARGBValue(argb);
                                _points.add(new Point(x, y, pixel.r, pixel.g, pixel.b));
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                _points = new ArrayList<Point>();
            }
            RessourceManager.putRessource(key, _points);
        }
    }
    return _points;
}
Also used : ArrayList(java.util.ArrayList) XYZPoint(org.jwildfire.create.tina.base.XYZPoint) XYZPoint(org.jwildfire.create.tina.base.XYZPoint) Graphics2D(java.awt.Graphics2D) SVGUniverse(com.kitfox.svg.SVGUniverse) SVGDiagram(com.kitfox.svg.SVGDiagram) SimpleImage(org.jwildfire.image.SimpleImage) StringReader(java.io.StringReader) Pixel(org.jwildfire.image.Pixel)

Aggregations

SVGUniverse (com.kitfox.svg.SVGUniverse)3 SVGDiagram (com.kitfox.svg.SVGDiagram)2 Graphics2D (java.awt.Graphics2D)2 StringReader (java.io.StringReader)2 SimpleImage (org.jwildfire.image.SimpleImage)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ImageIcon (javax.swing.ImageIcon)1 XYZPoint (org.jwildfire.create.tina.base.XYZPoint)1 Pixel (org.jwildfire.image.Pixel)1