private static float[] deriveRotationAnchorOffsets(Graphics2D g2,AttributedString text,TextAnchor anchor){
  float[] result=new float[2];
  TextLayout layout=new TextLayout(text.getIterator(),g2.getFontRenderContext());
  Rectangle2D bounds=layout.getBounds();
  float ascent=layout.getAscent();
  float halfAscent=ascent / 2.0f;
  float descent=layout.getDescent();
  float leading=layout.getLeading();
  float xAdj=0.0f;
  float yAdj=0.0f;
  if (isHorizontalLeft(anchor)) {
    xAdj=0.0f;
  }
 else   if (isHorizontalCenter(anchor)) {
    xAdj=(float)bounds.getWidth() / 2.0f;
  }
 else   if (isHorizontalRight(anchor)) {
    xAdj=(float)bounds.getWidth();
  }
  if (isTop(anchor)) {
    yAdj=descent + leading - (float)bounds.getHeight();
  }
 else   if (isHalfHeight(anchor)) {
    yAdj=descent + leading - (float)(bounds.getHeight() / 2.0);
  }
 else   if (isHalfAscent(anchor)) {
    yAdj=-halfAscent;
  }
 else   if (isBaseline(anchor)) {
    yAdj=0.0f;
  }
 else   if (isBottom(anchor)) {
    yAdj=descent + leading;
  }
  result[0]=xAdj;
  result[1]=yAdj;
  return result;
}

private static float [ ] deriveRotationAnchorOffsets ( Graphics2D g2 , AttributedString text , TextAnchor anchor ) { float [ ] result = new float [ 2 ] ; TextLayout layout = new TextLayout ( text . getIterator ( ) , g2 . getFontRenderContext ( ) ) ; Rectangle2D bounds = layout . getBounds ( ) ; float ascent = layout . getAscent ( ) ; float halfAscent = ascent / 2.0f ; float descent = layout . getDescent ( ) ; float leading = layout . getLeading ( ) ; float xAdj = 0.0f ; float yAdj = 0.0f ; if ( isHorizontalLeft ( anchor ) ) { xAdj = 0.0f ; } else if ( isHorizontalCenter ( anchor ) ) { xAdj = ( float ) bounds . getWidth ( ) / 2.0f ; } else if ( isHorizontalRight ( anchor ) ) { xAdj = ( float ) bounds . getWidth ( ) ; } if ( isTop ( anchor ) ) { yAdj = descent + leading - ( float ) bounds . getHeight ( ) ; } else if ( isHalfHeight ( anchor ) ) { yAdj = descent + leading - ( float ) ( bounds . getHeight ( ) / 2.0 ) ; } else if ( isHalfAscent ( anchor ) ) { yAdj = - halfAscent ; } else if ( isBaseline ( anchor ) ) { yAdj = 0.0f ; } else if ( isBottom ( anchor ) ) { yAdj = descent + leading ; } result [ 0 ] = xAdj ; result [ 1 ] = yAdj ; return result ; }
a utility method that calculates the rotation anchor offsets for a string . these offsets are relative to the text starting coordinate ( baseline_left ) .
