public Rectangle2D.Double getBounds() {
   if (cachedBounds == null) {
     cachedBounds = new Rectangle2D.Double();
     cachedBounds.setRect(getTextShape().getBounds2D());
   }
   return (Rectangle2D.Double) cachedBounds.clone();
 }
 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 Rectangle2D.Double getDrawingArea() {
   if (cachedDrawingArea == null) {
     Rectangle2D rx = getBounds();
     Rectangle2D.Double r =
         (rx instanceof Rectangle2D.Double)
             ? (Rectangle2D.Double) rx
             : new Rectangle2D.Double(rx.getX(), rx.getY(), rx.getWidth(), rx.getHeight());
     double g = SVGAttributeKeys.getPerpendicularHitGrowth(this);
     Geom.grow(r, g, g);
     if (TRANSFORM.get(this) == null) {
       cachedDrawingArea = r;
     } else {
       cachedDrawingArea = new Rectangle2D.Double();
       cachedDrawingArea.setRect(TRANSFORM.get(this).createTransformedShape(r).getBounds2D());
     }
   }
   return (Rectangle2D.Double) cachedDrawingArea.clone();
 }
 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))
             );
 }