code: static TextOutline generateAnnotation(Point2d basePoint, String label, Vector2d direction, double distance,
              double scale, Font font, AtomSymbol symbol) {
  
          boolean italicHint = label.startsWith(ITALIC_DISPLAY_PREFIX);
  
          label = italicHint ? label.substring(ITALIC_DISPLAY_PREFIX.length()) : label;
  
          Font annFont = italicHint ? font.deriveFont(Font.ITALIC) : font;
  
          final TextOutline annOutline = new TextOutline(label, annFont).resize(scale, -scale);
  
          // align to the first or last character of the annotation depending on the direction
          final Point2D center = direction.x > 0.3 ? annOutline.getFirstGlyphCenter() : direction.x < -0.3 ? annOutline
                  .getLastGlyphCenter() : annOutline.getCenter();
  
          // Avoid atom symbol
          if (symbol != null) {
              Point2D intersect = symbol.getConvexHull().intersect(VecmathUtil.toAwtPoint(basePoint),
                      VecmathUtil.toAwtPoint(new Point2d(VecmathUtil.sum(basePoint, direction))));
              // intersect should never be null be check against this
              if (intersect != null) basePoint = VecmathUtil.toVecmathPoint(intersect);
          }
  
          direction.scale(distance);
          direction.add(basePoint);
  
          // move to position
          return annOutline.translate(direction.x - center.getX(), direction.y - center.getY());
      }
docs: Generate an annotation 'label' for an atom (located at 'basePoint'). The label is offset from
  the basePoint by the provided 'distance' and 'direction'.
  
  @param basePoint the relative (0,0) reference
  @param label     the annotation text
  @param direction the direction along which the label is laid out
  @param distance  the distance along the direct to travel
  @param scale     the font scale of the label
  @param font      the font to use
  @param symbol    the atom symbol to avoid overlap with
  @return the position text outline for the annotation