Class TextRenderer

java.lang.Object
de.gurkenlabs.litiengine.graphics.TextRenderer

public final class TextRenderer extends Object
This class provides static methods for rendering text with various options such as alignment, scaling, rotation, and anti-aliasing. It cannot be instantiated.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Enables text anti-aliasing on the provided Graphics2D object.
    Retrieve the bounds of some text if it was to be drawn on the specified Graphics2D
    static double
    Retrieve the height of some text if it was to be drawn on the specified Graphics2D
    static double
    Retrieve the width of some text if it was to be drawn on the specified Graphics2D
    static void
    render(Graphics2D g, String text, double x, double y)
    Draw text at the given coordinates.
    static void
    render(Graphics2D g, String text, double x, double y, boolean antiAliasing)
    Draw text at the given coordinates.
    static void
    render(Graphics2D g, String text, Align align, Valign valign, double offsetX, double offsetY)
    Draws text with the specified alignment.
    static void
    render(Graphics2D g, String text, Point2D location)
    Renders the specified String to the given Graphics2D object at the specified location.
    static void
    render(Graphics2D g, String text, Point2D location, boolean antiAliasing)
    Renders the specified String to the given Graphics2D object at the specified location with optional anti-aliasing.
    static void
    render(Graphics2D g, String text, Rectangle2D bounds, Align alignment, Valign verticalAlignment, boolean scaleFont)
    Renders the specified String to the given Graphics2D object within the specified bounds using the specified alignment and scaling options.
    static void
    render(Graphics2D g, String text, Rectangle2D bounds, Align align, Valign valign, double offsetX, double offsetY, boolean scaleFont)
    Draws text within the given boundaries using the specified alignment and scales the font size, if desired.
    static void
    renderRotated(Graphics2D g, String text, double x, double y, double angle)
    Renders the specified String to the given Graphics2D object at the specified coordinates with rotation.
    static void
    renderRotated(Graphics2D g, String text, double x, double y, double angle, boolean antiAliasing)
    Renders the specified String to the given Graphics2D object at the specified coordinates with rotation and optional anti-aliasing.
    static void
    renderRotated(Graphics2D g, String text, Point2D location, double angle)
    Renders the specified String to the given Graphics2D object at the specified location with rotation.
    static void
    renderRotated(Graphics2D g, String text, Point2D location, double angle, boolean antiAliasing)
    Renders the specified String to the given Graphics2D object at the specified location with rotation and optional anti-aliasing.
    static void
    renderWithLinebreaks(Graphics2D g, String text, double x, double y, double lineWidth)
    Draw text at the given coordinates with a maximum line width for automatic line breaks.
    static void
    renderWithLinebreaks(Graphics2D g, String text, double x, double y, double lineWidth, boolean antiAliasing)
    Draw text at the given coordinates with a maximum line width for automatic line breaks and a provided Anti-Aliasing parameter.
    static void
    renderWithLinebreaks(Graphics2D g, String text, Align align, Valign valign, double x, double y, double width, double height, boolean antiAliasing)
    Draw text at the given coordinates with a maximum line width for automatic line breaks and a provided Anti-Aliasing parameter.
    static void
    renderWithLinebreaks(Graphics2D g, String text, Point2D location, double lineWidth)
    Draw text at the given coordinates with a maximum line width for automatic line breaks.
    static void
    renderWithLinebreaks(Graphics2D g, String text, Point2D location, double lineWidth, boolean antiAliasing)
    Draw text at the given coordinates with a maximum line width for automatic line breaks and a provided Anti-Aliasing parameter.
    static void
    renderWithOutline(Graphics2D g, String text, double x, double y, double width, double height, Color outlineColor, float stroke, Align align, Valign valign, boolean antiAliasing)
    Draw text at the given coordinates with an outline in the provided color and a provided Anti-Aliasing parameter.
    static void
    renderWithOutline(Graphics2D g, String text, double x, double y, Color outlineColor)
    Draw text at the given coordinates with an outline in the provided color.
    static void
    renderWithOutline(Graphics2D g, String text, double x, double y, Color outlineColor, boolean antiAliasing)
     
    static void
    renderWithOutline(Graphics2D g, String text, double x, double y, Color outlineColor, float stroke, boolean antiAliasing)
    Draw text at the given coordinates with an outline in the provided color and a provided Anti-Aliasing parameter.
    static void
    renderWithOutline(Graphics2D g, String text, Point2D location, Color outlineColor)
    Draw text at the given coordinates with an outline in the provided color.
    static void
    renderWithOutline(Graphics2D g, String text, Point2D location, Color outlineColor, boolean antiAliasing)
    Draw text at the given coordinates with an outline in the provided color and a provided Anti-Aliasing parameter.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • render

      public static void render(Graphics2D g, String text, double x, double y)
      Draw text at the given coordinates. This variant of drawText() uses RenderingHints.VALUE_TEXT_ANTIALIAS_OFF as Anti-Aliasing method by standard. For other Anti-Aliasing options, please use the drawText()-variant with five parameters.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      x - the min x coordinate
      y - the min y coordinate
    • render

      public static void render(Graphics2D g, String text, Point2D location)
      Renders the specified String to the given Graphics2D object at the specified location.
      Parameters:
      g - The graphics object to draw on.
      text - The text to be drawn.
      location - The location where the text will be drawn.
    • render

      public static void render(Graphics2D g, String text, Align align, Valign valign, double offsetX, double offsetY)
      Draws text with the specified alignment.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      align - The horizontal alignment.
      valign - The vertical alignment.
      offsetX - The horizontal offset that is added to the alignment.
      offsetY - The vertical offset that is added to the alignment.
    • render

      public static void render(Graphics2D g, String text, Rectangle2D bounds, Align alignment, Valign verticalAlignment, boolean scaleFont)
      Renders the specified String to the given Graphics2D object within the specified bounds using the specified alignment and scaling options.
      Parameters:
      g - The graphics object to draw on.
      text - The text to be drawn.
      bounds - The rectangle defining the boundaries used for alignment and scaling.
      alignment - The horizontal alignment.
      verticalAlignment - The vertical alignment.
      scaleFont - If true, scale the font so that the text will fit inside the given rectangle. If not, use the Graphics context's previous font size.
    • render

      public static void render(Graphics2D g, String text, Rectangle2D bounds, Align align, Valign valign, double offsetX, double offsetY, boolean scaleFont)
      Draws text within the given boundaries using the specified alignment and scales the font size, if desired.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      bounds - the Rectangle defining the boundaries used for alignment and scaling.
      align - The horizontal alignment.
      valign - The vertical alignment.
      offsetX - The horizontal offset that is added to the alignment.
      offsetY - The vertical offset that is added to the alignment.
      scaleFont - if true, scale the font so that the text will fit inside the given rectangle. If not, use the Graphics context's previous font size.
    • render

      public static void render(Graphics2D g, String text, double x, double y, boolean antiAliasing)
      Draw text at the given coordinates. This variant of drawText() uses a provided AntiAliasing parameter.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      x - the min x coordinate
      y - the min y coordinate
      antiAliasing - Configure whether or not to render the text with antialiasing.
      See Also:
    • render

      public static void render(Graphics2D g, String text, Point2D location, boolean antiAliasing)
      Renders the specified String to the given Graphics2D object at the specified location with optional anti-aliasing.
      Parameters:
      g - The graphics object to draw on.
      text - The text to be drawn.
      location - The location where the text will be drawn.
      antiAliasing - Configure whether or not to render the text with antialiasing.
    • renderRotated

      public static void renderRotated(Graphics2D g, String text, double x, double y, double angle, boolean antiAliasing)
      Renders the specified String to the given Graphics2D object at the specified coordinates with rotation and optional anti-aliasing.
      Parameters:
      g - The graphics object to draw on.
      text - The text to be drawn.
      x - The x-coordinate of the text.
      y - The y-coordinate of the text.
      angle - The angle by which the text will be rotated.
      antiAliasing - Configure whether or not to render the text with antialiasing.
    • renderRotated

      public static void renderRotated(Graphics2D g, String text, double x, double y, double angle)
      Renders the specified String to the given Graphics2D object at the specified coordinates with rotation.
      Parameters:
      g - The graphics object to draw on.
      text - The text to be drawn.
      x - The x-coordinate of the text.
      y - The y-coordinate of the text.
      angle - The angle by which the text will be rotated.
    • renderRotated

      public static void renderRotated(Graphics2D g, String text, Point2D location, double angle)
      Renders the specified String to the given Graphics2D object at the specified location with rotation.
      Parameters:
      g - The graphics object to draw on.
      text - The text to be drawn.
      location - The location where the text will be drawn.
      angle - The angle by which the text will be rotated.
    • renderRotated

      public static void renderRotated(Graphics2D g, String text, Point2D location, double angle, boolean antiAliasing)
      Renders the specified String to the given Graphics2D object at the specified location with rotation and optional anti-aliasing.
      Parameters:
      g - The graphics object to draw on.
      text - The text to be drawn.
      location - The location where the text will be drawn.
      angle - The angle by which the text will be rotated.
      antiAliasing - Configure whether or not to render the text with antialiasing.
    • renderWithLinebreaks

      public static void renderWithLinebreaks(Graphics2D g, String text, double x, double y, double lineWidth)
      Draw text at the given coordinates with a maximum line width for automatic line breaks. This variant of drawTextWithAutomaticLinebreaks() uses RenderingHints.VALUE_TEXT_ANTIALIAS_OFF as Anti-Aliasing method by standard. For other Anti-Aliasing options, please use the drawTextWithAutomaticLinebreaks()-variant with six parameters.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      x - the min x coordinate
      y - the min y coordinate
      lineWidth - the max line width
    • renderWithLinebreaks

      public static void renderWithLinebreaks(Graphics2D g, String text, Point2D location, double lineWidth)
      Draw text at the given coordinates with a maximum line width for automatic line breaks.
      Parameters:
      g - The Graphics2D object to draw on.
      text - The String to be distributed over all generated lines.
      location - The location where the text will be drawn.
      lineWidth - The max line width.
    • renderWithLinebreaks

      public static void renderWithLinebreaks(Graphics2D g, String text, double x, double y, double lineWidth, boolean antiAliasing)
      Draw text at the given coordinates with a maximum line width for automatic line breaks and a provided Anti-Aliasing parameter.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      x - the min x coordinate
      y - the min y coordinate
      lineWidth - the max line width
      antiAliasing - Configure whether or not to render the text with antialiasing.
      See Also:
    • renderWithLinebreaks

      public static void renderWithLinebreaks(Graphics2D g, String text, Align align, Valign valign, double x, double y, double width, double height, boolean antiAliasing)
      Draw text at the given coordinates with a maximum line width for automatic line breaks and a provided Anti-Aliasing parameter.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      align - The horizontal alignment.
      valign - The vertical alignment.
      x - the min x coordinate
      y - the min y coordinate
      width - the line width
      height - the line height.
      antiAliasing - Configure whether or not to render the text with antialiasing.
      See Also:
    • renderWithLinebreaks

      public static void renderWithLinebreaks(Graphics2D g, String text, Point2D location, double lineWidth, boolean antiAliasing)
      Draw text at the given coordinates with a maximum line width for automatic line breaks and a provided Anti-Aliasing parameter.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      location - The location where the text will be drawn.
      lineWidth - the max line width
      antiAliasing - Configure whether or not to render the text with antialiasing.
      See Also:
    • renderWithOutline

      public static void renderWithOutline(Graphics2D g, String text, double x, double y, Color outlineColor)
      Draw text at the given coordinates with an outline in the provided color. This variant of drawTextWithShadow() doesn't use Anti-Aliasing. For other Anti-Aliasing options, please specify the boolean value that controls it.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      x - the min x coordinate
      y - the min y coordinate
      outlineColor - the outline color
    • renderWithOutline

      public static void renderWithOutline(Graphics2D g, String text, Point2D location, Color outlineColor)
      Draw text at the given coordinates with an outline in the provided color.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      location - The location where the text will be drawn.
      outlineColor - the outline color
    • renderWithOutline

      public static void renderWithOutline(Graphics2D g, String text, double x, double y, Color outlineColor, boolean antiAliasing)
    • renderWithOutline

      public static void renderWithOutline(Graphics2D g, String text, double x, double y, Color outlineColor, float stroke, boolean antiAliasing)
      Draw text at the given coordinates with an outline in the provided color and a provided Anti-Aliasing parameter.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      x - the min x coordinate
      y - the min y coordinate
      outlineColor - the outline color
      stroke - the width of the outline
      antiAliasing - the Anti-Aliasing object (e.g. RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
      See Also:
    • renderWithOutline

      public static void renderWithOutline(Graphics2D g, String text, double x, double y, double width, double height, Color outlineColor, float stroke, Align align, Valign valign, boolean antiAliasing)
      Draw text at the given coordinates with an outline in the provided color and a provided Anti-Aliasing parameter.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      x - the min x coordinate
      y - the min y coordinate
      width - the width of the bounding box in which the text will be aligned
      height - the height of the bounding box in which the text will be aligned
      outlineColor - the outline color
      stroke - the thickness of the outline
      align - The horizontal alignment.
      valign - The vertical alignment.
      antiAliasing - Configure whether or not to render the text with antialiasing.
      See Also:
    • renderWithOutline

      public static void renderWithOutline(Graphics2D g, String text, Point2D location, Color outlineColor, boolean antiAliasing)
      Draw text at the given coordinates with an outline in the provided color and a provided Anti-Aliasing parameter.
      Parameters:
      g - the Graphics2D object to draw on
      text - the String to be distributed over all generated lines
      location - The location where the text will be drawn.
      outlineColor - the outline color
      antiAliasing - Configure whether or not to render the text with antialiasing.
      See Also:
    • getBounds

      public static Rectangle2D getBounds(Graphics2D g, String text)
      Retrieve the bounds of some text if it was to be drawn on the specified Graphics2D
      Parameters:
      g - The Graphics2D object to be drawn on
      text - The string to calculate the bounds of
      Returns:
      The bounds of the specified String in the specified Graphics context.
      See Also:
    • getWidth

      public static double getWidth(Graphics2D g, String text)
      Retrieve the width of some text if it was to be drawn on the specified Graphics2D
      Parameters:
      g - The Graphics2D object to be drawn on
      text - The string to retrieve the width of
      Returns:
      The width of the specified text
    • getHeight

      public static double getHeight(Graphics2D g, String text)
      Retrieve the height of some text if it was to be drawn on the specified Graphics2D
      Parameters:
      g - The Graphics2D object to be drawn on
      text - The string to retrieve the height of
      Returns:
      The height of the specified text
    • enableTextAntiAliasing

      public static void enableTextAntiAliasing(Graphics2D g)
      Enables text anti-aliasing on the provided Graphics2D object.
      Parameters:
      g - The Graphics2D object on which to enable text anti-aliasing.