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 ); } }
public void paint(Graphics2D g, int width, int height, int x, int y) { // saves the old transform; AffineTransform oldTransform = g.getTransform(); try { if (oldTransform == null) oldTransform = new AffineTransform(); AffineTransform transform = new AffineTransform(oldTransform); // adds scaling to the transform so that we respect the declared size transform.translate(x, y); transform.scale(width / bounds.getWidth(), height / bounds.getHeight()); g.setTransform(transform); node.paint(g); } finally { g.setTransform(oldTransform); } } }
@Override public void render(Graphics2D graphics2D) { /* * Do the real paint */ PDFTranscoder.this.root.paint(graphics2D); } });
/** * Paints this node without applying Filter, Mask, Composite and clip. * * @param g2d the Graphics2D to use */ public void primitivePaint(Graphics2D g2d) { if (source != null) { source.paint(g2d); } }
public void primitivePaint(Graphics2D g2d) { pcn.paint(g2d); } public Rectangle2D getPrimitiveBounds() {
/** * Paints this node without applying Filter, Mask, Composite and clip. * * @param g2d the Graphics2D to use */ public void primitivePaint(Graphics2D g2d) { if (source != null) { source.paint(g2d); } }
/** * Paints this node without applying Filter, Mask, Composite and clip. * * @param g2d the Graphics2D to use */ public void primitivePaint(Graphics2D g2d) { if (source != null) { source.paint(g2d); } }
public void primitivePaint(Graphics2D g2d) { pcn.paint(g2d); } public Rectangle2D getPrimitiveBounds() {
public void primitivePaint(Graphics2D g2d) { pcn.paint(g2d); } public Rectangle2D getPrimitiveBounds() {
/** {@inheritDoc} */ public void paint(Graphics2D g2d, Rectangle2D area) { prepare(g2d, area); root.paint(g2d); }
public void paint(Graphics2D g, int width, int height, int x, int y) { // saves the old transform; AffineTransform oldTransform = g.getTransform(); try { if (oldTransform == null) oldTransform = new AffineTransform(); AffineTransform transform = new AffineTransform(oldTransform); // adds scaling to the transform so that we respect the declared size transform.translate(x, y); transform.scale(width / bounds.getWidth(), height / bounds.getHeight()); g.setTransform(transform); node.paint(g); } finally { g.setTransform(oldTransform); } } }
/** * Paints this node without applying Filter, Mask, Composite, and clip. * * @param g2d the Graphics2D to use */ public void primitivePaint(Graphics2D g2d) { if (count == 0) { return; } // Thread.currentThread() is potentially expensive, so reuse my instance in hasBeenHalted() Thread currentThread = Thread.currentThread(); // Paint children for (int i=0; i < count; ++i) { if (HaltingThread.hasBeenHalted( currentThread )) return; GraphicsNode node = children[i]; if (node == null) { continue; } node.paint(g2d); } }
/** * Draws the object. * * @param g the graphics device. * @param area the area inside which the object should be drawn. */ public void draw( final Graphics2D g, final Rectangle2D area ) { if ( width == 0 || height == 0 ) { return; } final Graphics2D g2 = (Graphics2D) g.create(); try { g2.translate( -area.getX(), -area.getY() ); final double sx = area.getWidth() / width; final double sy = area.getHeight() / height; final double sm = Math.min( sx, sy ); g2.scale( sm, sm ); rootNode.paint( g2 ); } finally { g2.dispose(); } } }
/** * Paints this node without applying Filter, Mask, Composite, and clip. * * @param g2d the Graphics2D to use */ public void primitivePaint(Graphics2D g2d) { if (count == 0) { return; } // Thread.currentThread() is potentially expensive, so reuse my instance in hasBeenHalted() Thread currentThread = Thread.currentThread(); // Paint children for (int i=0; i < count; ++i) { if (HaltingThread.hasBeenHalted( currentThread )) return; GraphicsNode node = children[i]; if (node == null) { continue; } node.paint(g2d); } }
/** * Paints this node without applying Filter, Mask, Composite, and clip. * * @param g2d the Graphics2D to use */ public void primitivePaint(Graphics2D g2d) { if (count == 0) { return; } // Thread.currentThread() is potentially expensive, so reuse my instance in hasBeenHalted() Thread currentThread = Thread.currentThread(); // Paint children for (int i=0; i < count; ++i) { if (HaltingThread.hasBeenHalted( currentThread )) return; GraphicsNode node = children[i]; if (node == null) { continue; } node.paint(g2d); } }
public void render(Graphics2D grx, Rectangle2D rectangle) throws JRException { ensureSvg(); AffineTransform transform = ViewBox.getPreserveAspectRatioTransform( new float[]{0, 0, (float) documentSize.getWidth(), (float) documentSize.getHeight()}, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE, true, (float) rectangle.getWidth(), (float) rectangle.getHeight()); Graphics2D graphics = (Graphics2D) grx.create(); graphics.translate(rectangle.getX(), rectangle.getY()); graphics.transform(transform); // CompositeGraphicsNode not thread safe synchronized (rootNode) { rootNode.paint(graphics); } }
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName()); UserAgent userAgent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(userAgent); BridgeContext ctx = new BridgeContext(userAgent, loader); ctx.setDynamicState(BridgeContext.DYNAMIC); GVTBuilder builder = new GVTBuilder(); SVGDocument svgDoc = factory.createSVGDocument(rootPath, new StringReader(svg)); PdfTemplate svgTempl = PdfTemplate.createTemplate(writer, Float.parseFloat(svgDoc.getDocumentElement().getAttribute("width")), Float.parseFloat(svgDoc.getDocumentElement().getAttribute("height"))); Graphics2D g2d = new PdfGraphics2D(svgTempl, svgTempl.getWidth(), svgTempl.getHeight()); GraphicsNode chartGfx = builder.build(ctx, svgDoc); chartGfx.paint(g2d); g2d.dispose(); Image svgImg = new ImgTemplate(svgTempl); svgImg.setAlignment(Image.ALIGN_CENTER); //svgImg.setBorder(Image.BOX); //svgImg.setBorderColor(new BaseColor(0xff, 0x00, 0x00)); //svgImg.setBorderWidth(1); document.add(svgImg);
/** * Reads an SVG Image file into an com.itextpdf.text.Image instance to embed it into a PDF * @param svgPath SVG filepath * @param writer PdfWriter instance * @return Instance of com.itextpdf.text.Image holding the SVG file * @throws IOException * @throws BadElementException */ private static Image getSVGImage(String svgPath, PdfWriter writer) throws IOException, BadElementException { SVGDocument svgDoc = new SAXSVGDocumentFactory(null).createSVGDocument(null, new FileReader(svgPath)); // Try to read embedded height and width float svgWidth = Float.parseFloat(svgDoc.getDocumentElement().getAttribute("width").replaceAll("[^0-9.,]","")); float svgHeight = Float.parseFloat(svgDoc.getDocumentElement().getAttribute("height").replaceAll("[^0-9.,]","")); PdfTemplate svgTempl = PdfTemplate.createTemplate(writer, svgWidth, svgHeight); Graphics2D g2d = new PdfGraphics2D(svgTempl, svgTempl.getWidth(), svgTempl.getHeight()); GraphicsNode chartGfx = (new GVTBuilder()).build(new BridgeContext(new UserAgentAdapter()), svgDoc); chartGfx.paint(g2d); g2d.dispose(); return new ImgTemplate(svgTempl); }
public void genRect(WritableRaster wr) { // System.out.println(" Rect: " + wr.getBounds()); BufferedImage offScreen = new BufferedImage(cm, wr.createWritableTranslatedChild(0,0), cm.isAlphaPremultiplied(), null); Graphics2D g = GraphicsUtil.createGraphics(offScreen, hints); g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, wr.getWidth(), wr.getHeight()); g.setComposite(AlphaComposite.SrcOver); g.translate(-wr.getMinX(), -wr.getMinY()); // Set transform g.transform(node2dev); // Invoke primitive paint. if (usePrimitivePaint) { node.primitivePaint(g); } else { node.paint (g); } g.dispose(); }
public void genRect(WritableRaster wr) { // System.out.println(" Rect: " + wr.getBounds()); BufferedImage offScreen = new BufferedImage(cm, wr.createWritableTranslatedChild(0,0), cm.isAlphaPremultiplied(), null); Graphics2D g = GraphicsUtil.createGraphics(offScreen, hints); g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, wr.getWidth(), wr.getHeight()); g.setComposite(AlphaComposite.SrcOver); g.translate(-wr.getMinX(), -wr.getMinY()); // Set transform g.transform(node2dev); // Invoke primitive paint. if (usePrimitivePaint) { node.primitivePaint(g); } else { node.paint (g); } g.dispose(); }