com.orsoncharts.util

## Class TextUtils

- java.lang.Object
- - com.orsoncharts.util.TextUtils

-     public class TextUtils
      extends java.lang.Object

  Utility methods for working with text.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.awt.geom.Rectangle2D` | `calcAlignedStringBounds(java.lang.String text, java.awt.Graphics2D g2, float x, float y, TextAnchor anchor)` Returns the bounds of an aligned string.
    `static java.awt.geom.Rectangle2D` | `drawAlignedString(java.lang.String text, java.awt.Graphics2D g2, float x, float y, TextAnchor anchor)` Draws a string such that the specified anchor point is aligned to the given `(x, y)` location, and returns a bounding rectangle for the text.
    `static java.awt.Shape` | `drawRotatedString(java.text.AttributedString text, java.awt.Graphics2D g2, double angle, float x, float y)` Draws the attributed string at `(x, y)`, rotated by the specified angle about `(x, y)`.
    `static java.awt.Shape` | `drawRotatedString(java.text.AttributedString text, java.awt.Graphics2D g2, float textX, float textY, double angle, float rotateX, float rotateY)` Draws the attributed string at `(textX, textY)`, rotated by the specified angle about `(rotateX, rotateY)`.
    `static java.awt.Shape` | `drawRotatedString(java.text.AttributedString text, java.awt.Graphics2D g2, float x, float y, TextAnchor textAnchor, double angle, TextAnchor rotationAnchor, java.awt.geom.Rectangle2D nonRotatedBounds)` Draws the attributed string aligned to the point `(x, y)`, rotated by the specified angle about `rotationAnchor`.
    `static java.awt.Shape` | `drawRotatedString(java.lang.String text, java.awt.Graphics2D g2, double angle, float x, float y)` A utility method for drawing rotated text.
    `static java.awt.Shape` | `drawRotatedString(java.lang.String text, java.awt.Graphics2D g2, float textX, float textY, double angle, float rotateX, float rotateY)` A utility method for drawing rotated text.
    `static java.awt.Shape` | `drawRotatedString(java.lang.String text, java.awt.Graphics2D g2, float x, float y, TextAnchor textAnchor, double angle, float rotationX, float rotationY)` Draws a string that is aligned by one anchor point and rotated about another anchor point.
    `static java.awt.Shape` | `drawRotatedString(java.lang.String text, java.awt.Graphics2D g2, float x, float y, TextAnchor textAnchor, double angle, TextAnchor rotationAnchor)` Draws a string that is aligned by one anchor point and rotated about another anchor point, and returns a bounding shape for the text.
    `static java.awt.geom.Rectangle2D` | `getTextBounds(java.lang.String text, double x, double y, java.awt.FontMetrics fm)` Returns the bounds for the specified text when it is drawn with the left-baseline aligned to the point `(x, y)`.
    `static java.awt.geom.Rectangle2D` | `getTextBounds(java.lang.String text, java.awt.FontMetrics fm)` Returns the bounds for the specified text.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### drawAlignedString

          public static java.awt.geom.Rectangle2D drawAlignedString(java.lang.String text,
                                                                    java.awt.Graphics2D g2,
                                                                    float x,
                                                                    float y,
                                                                    TextAnchor anchor)

      Draws a string such that the specified anchor point is aligned to the given `(x, y)` location, and returns a bounding rectangle for the text.
      Parameters:
        `text` - the text.
        `g2` - the graphics device (`null` not permitted).
        `x` - the x coordinate (Java 2D).
        `y` - the y coordinate (Java 2D).
        `anchor` - the anchor location (`null` not permitted).
      Returns:
        The text bounds (adjusted for the text position).

    - #### calcAlignedStringBounds

          public static java.awt.geom.Rectangle2D calcAlignedStringBounds(java.lang.String text,
                                                                          java.awt.Graphics2D g2,
                                                                          float x,
                                                                          float y,
                                                                          TextAnchor anchor)

      Returns the bounds of an aligned string.
      Parameters:
        `text` - the string (`null` not permitted).
        `g2` - the graphics target (`null` not permitted).
        `x` - the x-coordinate.
        `y` - the y-coordinate.
        `anchor` - the anchor point on the text that will be aligned to `(x, y)` (`null` not permitted).
      Returns:
        The text bounds (never `null`).
      Since:
        1.3

    - #### getTextBounds

          public static java.awt.geom.Rectangle2D getTextBounds(java.lang.String text,
                                                                java.awt.FontMetrics fm)

      Returns the bounds for the specified text. The supplied text is assumed to be on a single line (no carriage return or newline characters).
      Parameters:
        `text` - the text (`null` not permitted).
        `fm` - the font metrics (`null` not permitted).
      Returns:
        The text bounds.

    - #### getTextBounds

          public static java.awt.geom.Rectangle2D getTextBounds(java.lang.String text,
                                                                double x,
                                                                double y,
                                                                java.awt.FontMetrics fm)

      Returns the bounds for the specified text when it is drawn with the left-baseline aligned to the point `(x, y)`.
      Parameters:
        `text` - the text (`null` not permitted).
        `x` - the x-coordinate.
        `y` - the y-coordinate.
        `fm` - the font metrics (`null` not permitted).
      Returns:
        The bounding rectangle (never `null`).

    - #### drawRotatedString

          public static java.awt.Shape drawRotatedString(java.lang.String text,
                                                         java.awt.Graphics2D g2,
                                                         float x,
                                                         float y,
                                                         TextAnchor textAnchor,
                                                         double angle,
                                                         float rotationX,
                                                         float rotationY)

      Draws a string that is aligned by one anchor point and rotated about another anchor point.
      Parameters:
        `text` - the text (`null` not permitted).
        `g2` - the graphics target (`null` not permitted).
        `x` - the x-coordinate for positioning the text.
        `y` - the y-coordinate for positioning the text.
        `textAnchor` - the text anchor (`null` not permitted).
        `angle` - the rotation angle.
        `rotationX` - the x-coordinate for the rotation anchor point.
        `rotationY` - the y-coordinate for the rotation anchor point.
      Returns:
        The text bounds (never `null`).

    - #### drawRotatedString

          public static java.awt.Shape drawRotatedString(java.lang.String text,
                                                         java.awt.Graphics2D g2,
                                                         float x,
                                                         float y,
                                                         TextAnchor textAnchor,
                                                         double angle,
                                                         TextAnchor rotationAnchor)

      Draws a string that is aligned by one anchor point and rotated about another anchor point, and returns a bounding shape for the text.
      Parameters:
        `text` - the text (`null` not permitted).
        `g2` - the graphics device (`null` not permitted).
        `x` - the x-coordinate for positioning the text.
        `y` - the y-coordinate for positioning the text.
        `textAnchor` - the text anchor (`null` not permitted).
        `angle` - the rotation angle (in radians).
        `rotationAnchor` - the rotation anchor (`null` not permitted).
      Returns:
        A bounding shape for the text.

    - #### drawRotatedString

          public static java.awt.Shape drawRotatedString(java.lang.String text,
                                                         java.awt.Graphics2D g2,
                                                         double angle,
                                                         float x,
                                                         float y)

      A utility method for drawing rotated text.

      A common rotation is `-Math.PI/2` which draws text 'vertically' (with the top of the characters on the left).

      Parameters:
        `text` - the text (`null` not permitted)
        `g2` - the graphics target (`null` not permitted).
        `angle` - the angle of the (clockwise) rotation (in radians).
        `x` - the x-coordinate.
        `y` - the y-coordinate.
      Returns:
        The text bounds.

    - #### drawRotatedString

          public static java.awt.Shape drawRotatedString(java.lang.String text,
                                                         java.awt.Graphics2D g2,
                                                         float textX,
                                                         float textY,
                                                         double angle,
                                                         float rotateX,
                                                         float rotateY)

      A utility method for drawing rotated text.

      A common rotation is `-Math.PI/2` which draws text 'vertically' (with the top of the characters on the left).

      Parameters:
        `text` - the text (`null` not permitted).
        `g2` - the graphics device (`null` not permitted).
        `textX` - the x-coordinate for the text (before rotation).
        `textY` - the y-coordinate for the text (before rotation).
        `angle` - the angle of the (clockwise) rotation (in radians).
        `rotateX` - the point about which the text is rotated.
        `rotateY` - the point about which the text is rotated.
      Returns:
        The bounds for the rotated text (never `null`).

    - #### drawRotatedString

          public static java.awt.Shape drawRotatedString(java.text.AttributedString text,
                                                         java.awt.Graphics2D g2,
                                                         double angle,
                                                         float x,
                                                         float y)

      Draws the attributed string at `(x, y)`, rotated by the specified angle about `(x, y)`.
      Parameters:
        `text` - the attributed string (`null` not permitted).
        `g2` - the graphics output target (`null` not permitted).
        `angle` - the angle.
        `x` - the x-coordinate.
        `y` - the y-coordinate.
      Returns:
        The text bounds (never `null`).
      Since:
        1.2

    - #### drawRotatedString

          public static java.awt.Shape drawRotatedString(java.text.AttributedString text,
                                                         java.awt.Graphics2D g2,
                                                         float textX,
                                                         float textY,
                                                         double angle,
                                                         float rotateX,
                                                         float rotateY)

      Draws the attributed string at `(textX, textY)`, rotated by the specified angle about `(rotateX, rotateY)`.
      Parameters:
        `text` - the attributed string (`null` not permitted).
        `g2` - the graphics output target (`null` not permitted).
        `textX` - the x-coordinate for the text alignment point.
        `textY` - the y-coordinate for the text alignment point.
        `angle` - the rotation angle (in radians).
        `rotateX` - the x-coordinate for the rotation point.
        `rotateY` - the y-coordinate for the rotation point.
      Returns:
        The text bounds (never `null`).
      Since:
        1.2

    - #### drawRotatedString

          public static java.awt.Shape drawRotatedString(java.text.AttributedString text,
                                                         java.awt.Graphics2D g2,
                                                         float x,
                                                         float y,
                                                         TextAnchor textAnchor,
                                                         double angle,
                                                         TextAnchor rotationAnchor,
                                                         java.awt.geom.Rectangle2D nonRotatedBounds)

      Draws the attributed string aligned to the point `(x, y)`, rotated by the specified angle about `rotationAnchor`.
      Parameters:
        `text` - the attributed string (`null` not permitted).
        `g2` - the graphics target (`null` not permitted).
        `x` - the x-coordinate.
        `y` - the y-coordinate.
        `textAnchor` - the text anchor (`null` not permitted).
        `angle` - the rotation angle (in radians).
        `rotationAnchor` - the rotation anchor (`null` not permitted).
        `nonRotatedBounds` - if not `null` this rectangle will be updated with the non-rotated bounds of the text for the caller to use.
      Returns:
        The text bounds (never `null`).
      Since:
        1.2