Class TextUtils

java.lang.Object
org.jfree.chart.util.TextUtils

public class TextUtils extends Object
Text utility functions.
Since:
1.0.18
  • Constructor Details

    • TextUtils

      public TextUtils()
  • Method Details

    • drawAlignedString

      public static Rectangle2D drawAlignedString(String text, Graphics2D g2, float x, float y, org.jfree.ui.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.
      x - the x coordinate (Java 2D).
      y - the y coordinate (Java 2D).
      anchor - the anchor location.
      Returns:
      The text bounds (adjusted for the text position).
    • calcAlignedStringBounds

      public static Rectangle2D calcAlignedStringBounds(String text, Graphics2D g2, float x, float y, org.jfree.ui.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 that will be aligned to (x, y) (null not permitted).
      Returns:
      The text bounds (never null).
      Since:
      1.3
    • deriveTextBoundsAnchorOffsets

      private static float[] deriveTextBoundsAnchorOffsets(Graphics2D g2, String text, org.jfree.ui.TextAnchor anchor)
      A utility method that calculates the anchor offsets for a string. Normally, the (x, y) coordinate for drawing text is a point on the baseline at the left of the text string. If you add these offsets to (x, y) and draw the string, then the anchor point should coincide with the (x, y) point.
      Parameters:
      g2 - the graphics device (not null).
      text - the text.
      anchor - the anchor point.
      Returns:
      The offsets.
    • deriveTextBoundsAnchorOffsets

      private static float[] deriveTextBoundsAnchorOffsets(Graphics2D g2, String text, org.jfree.ui.TextAnchor anchor, Rectangle2D textBounds)
      A utility method that calculates the anchor offsets for a string. Normally, the (x, y) coordinate for drawing text is a point on the baseline at the left of the text string. If you add these offsets to (x, y) and draw the string, then the anchor point should coincide with the (x, y) point.
      Parameters:
      g2 - the graphics device (not null).
      text - the text.
      anchor - the anchor point.
      textBounds - the text bounds (if not null, this object will be updated by this method to match the string bounds).
      Returns:
      The offsets.
    • getTextBounds

      public static Rectangle2D getTextBounds(String text, 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 Rectangle2D getTextBounds(String text, double x, double y, 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).