Java Code Examples for org.apache.batik.gvt.GraphicsNode#setTransform()
The following examples show how to use
org.apache.batik.gvt.GraphicsNode#setTransform() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingUniversalImageSvg.java From hop with Apache License 2.0 | 6 votes |
public static void render( Graphics2D gc, GraphicsNode svgGraphicsNode, Dimension2D svgGraphicsSize, int centerX, int centerY, int width, int height, double angleRadians ) { double scaleX = width / svgGraphicsSize.getWidth(); double scaleY = height / svgGraphicsSize.getHeight(); AffineTransform affineTransform = new AffineTransform(); if ( centerX != 0 || centerY != 0 ) { affineTransform.translate( centerX, centerY ); } affineTransform.scale( scaleX, scaleY ); if ( angleRadians != 0 ) { affineTransform.rotate( angleRadians ); } affineTransform.translate( -svgGraphicsSize.getWidth() / 2, -svgGraphicsSize.getHeight() / 2 ); svgGraphicsNode.setTransform( affineTransform ); svgGraphicsNode.paint( gc ); }
Example 2
Source File: SwingUniversalImageSvg.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public static void render( Graphics2D gc, GraphicsNode svgGraphicsNode, Dimension2D svgGraphicsSize, int centerX, int centerY, int width, int height, double angleRadians ) { double scaleX = width / svgGraphicsSize.getWidth(); double scaleY = height / svgGraphicsSize.getHeight(); AffineTransform affineTransform = new AffineTransform(); if ( centerX != 0 || centerY != 0 ) { affineTransform.translate( centerX, centerY ); } affineTransform.scale( scaleX, scaleY ); if ( angleRadians != 0 ) { affineTransform.rotate( angleRadians ); } affineTransform.translate( -svgGraphicsSize.getWidth() / 2, -svgGraphicsSize.getHeight() / 2 ); svgGraphicsNode.setTransform( affineTransform ); svgGraphicsNode.paint( gc ); }
Example 3
Source File: VehicleMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Creates a buffered image from a SVG graphics node. * @param svg the SVG graphics node. * @param width the width of the produced image. * @param length the length of the produced image. * @return the created buffered image. */ private BufferedImage createBufferedImage(GraphicsNode svg, double width, double length) { int imageWidth = (int) (width * scale); if (imageWidth <= 0) { imageWidth = 1; } int imageLength = (int) (length * scale); if (imageLength <= 0) { imageLength = 1; } BufferedImage bufferedImage = new BufferedImage( imageWidth, imageLength, BufferedImage.TYPE_INT_ARGB ); // Determine bounds. Rectangle2D bounds = svg.getBounds(); // Determine transform information. double scalingWidth = width / bounds.getWidth() * scale; double scalingLength = length / bounds.getHeight() * scale; // Draw the SVG image on the buffered image. Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); svg.setTransform(AffineTransform.getScaleInstance(scalingWidth, scalingLength)); svg.paint(g2d); // Cleanup and return image g2d.dispose(); return bufferedImage; }
Example 4
Source File: WappalyzerJsonParser.java From zap-extensions with Apache License 2.0 | 5 votes |
private static ImageIcon createSvgIcon(URL url) throws Exception { if (url == null) { return null; } String xmlParser = XMLResourceDescriptor.getXMLParserClassName(); SAXSVGDocumentFactory df = new SAXSVGDocumentFactory(xmlParser); SVGDocument doc = null; GraphicsNode svgIcon = null; try { doc = df.createSVGDocument(url.toString()); } catch (RuntimeException re) { // v1 SVGs are unsupported return null; } doc.getRootElement().setAttribute("width", String.valueOf(SIZE)); doc.getRootElement().setAttribute("height", String.valueOf(SIZE)); UserAgent userAgent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(userAgent); GVTBuilder builder = new GVTBuilder(); try { svgIcon = builder.build(new BridgeContext(userAgent, loader), doc); } catch (BridgeException | StringIndexOutOfBoundsException ex) { logger.debug("Failed to parse SVG. " + ex.getMessage()); return null; } AffineTransform transform = new AffineTransform(1, 0.0, 0.0, 1, 0, 0); BufferedImage image = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = addRenderingHints(image); svgIcon.setTransform(transform); svgIcon.paint(g2d); g2d.dispose(); return new ImageIcon(image); }
Example 5
Source File: StructureMapLayer.java From mars-sim with GNU General Public License v3.0 | 4 votes |
/** * Creates a buffered image from a SVG graphics node. * @param svg the SVG graphics node. * @param width the structure width (meters). * @param length the structure length (meters). * @param patternSVG the pattern SVG graphics node (null if no pattern). * @return the created buffered image. */ private BufferedImage createBufferedImage(GraphicsNode svg, double width, double length, GraphicsNode patternSVG) { int imageWidth = (int) (width * scale); if (imageWidth <= 0) { imageWidth = 1; } int imageLength = (int) (length * scale); if (imageLength <= 0) { imageLength = 1; } BufferedImage bufferedImage = new BufferedImage( imageWidth, imageLength, BufferedImage.TYPE_INT_ARGB ); // Determine bounds. Rectangle2D bounds = svg.getBounds(); // Determine transform information. double scalingWidth = width / bounds.getWidth() * scale; double scalingLength = length / bounds.getHeight() * scale; // Draw the SVG image on the buffered image. Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); svg.setTransform(AffineTransform.getScaleInstance(scalingWidth, scalingLength)); svg.paint(g2d); // Draw repeating pattern SVG image on the buffered image. if (patternSVG != null) { double patternScaling = 0D; double patternWidth = 0D; double patternLength = 0D; double originalProportions = bounds.getWidth() / bounds.getHeight(); double finalProportions = width / length; Rectangle2D patternBounds = patternSVG.getBounds(); if ((finalProportions / originalProportions) >= 1D) { patternScaling = scalingLength; patternLength = length * (patternBounds.getHeight() / bounds.getHeight()); patternWidth = patternLength * (patternBounds.getWidth() / patternBounds.getHeight()); } else { patternScaling = scalingWidth; patternWidth = width * (patternBounds.getWidth() / bounds.getWidth()); patternLength = patternWidth * (patternBounds.getHeight() / patternBounds.getWidth()); } AffineTransform patternTransform = new AffineTransform(); patternTransform.scale(patternScaling, patternScaling); for (double x = 0D; x < length; x += patternLength) { patternTransform.translate(0D, x * bounds.getHeight()); double y = 0D; for (; y < width; y += patternWidth) { patternTransform.translate(y * bounds.getWidth(), 0D); patternSVG.setTransform(patternTransform); patternSVG.paint(g2d); patternTransform.translate(y * bounds.getWidth() * -1D, 0D); } patternTransform.translate(0D, x * bounds.getHeight() * -1D); } } // Cleanup and return image g2d.dispose(); return bufferedImage; }