private void writeTextAreaElement(IXMLElement parent, SVGTextAreaFigure f) throws IOException { IXMLElement elem = parent.createElement("AREA"); Rectangle2D.Double rect = f.getBounds(); double grow = getPerpendicularHitGrowth(f); rect.x -= grow; rect.y -= grow; rect.width += grow; rect.height += grow; if (writeRectAttributes(elem, f, rect)) { parent.addChild(elem); } }
@Override public void draw(Graphics2D g) { double opacity = get(OPACITY); opacity = Math.min(Math.max(0d, opacity), 1d); if (opacity != 0d) { if (opacity != 1d) { Rectangle2D.Double drawingArea = getDrawingArea(); Rectangle2D clipBounds = g.getClipBounds(); if (clipBounds != null) { Rectangle2D.intersect(drawingArea, clipBounds, drawingArea); } if (!drawingArea.isEmpty()) { BufferedImage buf = new BufferedImage( (int) ((2 + drawingArea.width) * g.getTransform().getScaleX()), (int) ((2 + drawingArea.height) * g.getTransform().getScaleY()), BufferedImage.TYPE_INT_ARGB); Graphics2D gr = buf.createGraphics(); gr.scale(g.getTransform().getScaleX(), g.getTransform().getScaleY()); gr.translate((int) -drawingArea.x, (int) -drawingArea.y); gr.setRenderingHints(g.getRenderingHints()); drawFigure(gr); gr.dispose(); Composite savedComposite = g.getComposite(); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) opacity)); g.drawImage( buf, (int) drawingArea.x, (int) drawingArea.y, 2 + (int) drawingArea.width, 2 + (int) drawingArea.height, null); g.setComposite(savedComposite); } } else { drawFigure(g); } } }
private void writeRectElement(IXMLElement parent, SVGRectFigure f) throws IOException { IXMLElement elem = parent.createElement("AREA"); boolean isContained; if (f.getArcHeight() == 0 && f.getArcWidth() == 0) { Rectangle2D.Double rect = f.getBounds(); double grow = getPerpendicularHitGrowth(f); rect.x -= grow; rect.y -= grow; rect.width += grow; rect.height += grow; isContained = writeRectAttributes(elem, f, rect); } else { isContained = writePolyAttributes(elem, f, new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f)). createStrokedShape(new RoundRectangle2D.Double( f.getX(), f.getY(), f.getWidth(), f.getHeight(), f.getArcWidth(), f.getArcHeight() ))); } if (isContained) { parent.addChild(elem); } }
/** * All other write methods delegate their work to here. */ public void write(OutputStream out, java.util.List<Figure> figures) throws IOException { Rectangle2D.Double drawingRect = null; for (Figure f : figures) { if (drawingRect == null) { drawingRect = f.getBounds(); } else { drawingRect.add(f.getBounds()); } } AffineTransform drawingTransform = new AffineTransform(); drawingTransform.translate( -Math.min(0, drawingRect.x), -Math.min(0, drawingRect.y) ); write(out, figures, drawingTransform, new Dimension( (int) (Math.abs(drawingRect.x) + drawingRect.width), (int) (Math.abs(drawingRect.y) + drawingRect.height)) ); }