public static Rectangle2D calcAlignedStringBounds(String text,Graphics2D g2,float x,float y,TextAnchor anchor){
  Rectangle2D textBounds=new Rectangle2D.Double();
  float[] adjust=deriveTextBoundsAnchorOffsets(g2,text,anchor,textBounds);
  textBounds.setRect(x + adjust[0],y + adjust[1] + adjust[2],textBounds.getWidth(),textBounds.getHeight());
  return textBounds;
}

public static Rectangle2D calcAlignedStringBounds ( String text , Graphics2D g2 , float x , float y , TextAnchor anchor ) { Rectangle2D textBounds = new Rectangle2D . Double ( ) ; float [ ] adjust = deriveTextBoundsAnchorOffsets ( g2 , text , anchor , textBounds ) ; textBounds . setRect ( x + adjust [ 0 ] , y + adjust [ 1 ] + adjust [ 2 ] , textBounds . getWidth ( ) , textBounds . getHeight ( ) ) ; return textBounds ; }
returns the bounds of an aligned string .
