Class TextRenderer

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

public final class TextRenderer
extends java.lang.Object
  • Method Summary

    Modifier and TypeMethodDescription
    static voidenableTextAntiAliasing​(java.awt.Graphics2D g) 
    static java.awt.geom.Rectangle2DgetBounds​(java.awt.Graphics2D g, java.lang.String text)
    Retrieve the bounds of some text if it was to be drawn on the specified Graphics2D
    static doublegetHeight​(java.awt.Graphics2D g, java.lang.String text)
    Retrieve the height of some text if it was to be drawn on the specified Graphics2D
    static doublegetWidth​(java.awt.Graphics2D g, java.lang.String text)
    Retrieve the width of some text if it was to be drawn on the specified Graphics2D
    static voidrender​(java.awt.Graphics2D g, java.lang.String text, double x, double y)
    Draw text at the given coordinates.
    static voidrender​(java.awt.Graphics2D g, java.lang.String text, double x, double y, boolean antiAliasing)
    Draw text at the given coordinates.
    static voidrender​(java.awt.Graphics2D g, java.lang.String text, Align align, Valign valign, double offsetX, double offsetY)
    Draws text with the specified alignment.
    static voidrender​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location) 
    static voidrender​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, boolean antiAliasing) 
    static voidrender​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Rectangle2D bounds, Align alignment, Valign verticalAlignment, boolean scaleFont) 
    static voidrender​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.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 voidrenderRotated​(java.awt.Graphics2D g, java.lang.String text, double x, double y, double angle) 
    static voidrenderRotated​(java.awt.Graphics2D g, java.lang.String text, double x, double y, double angle, boolean antiAliasing) 
    static voidrenderRotated​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double angle) 
    static voidrenderRotated​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double angle, boolean antiAliasing) 
    static voidrenderWithLinebreaks​(java.awt.Graphics2D g, java.lang.String text, double x, double y, double lineWidth)
    Draw text at the given coordinates with a maximum line width for automatic line breaks.
    static voidrenderWithLinebreaks​(java.awt.Graphics2D g, java.lang.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 voidrenderWithLinebreaks​(java.awt.Graphics2D g, java.lang.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 voidrenderWithLinebreaks​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double lineWidth) 
    static voidrenderWithLinebreaks​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double lineWidth, boolean antiAliasing) 
    static voidrenderWithOutline​(java.awt.Graphics2D g, java.lang.String text, double x, double y, double width, double height, java.awt.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 voidrenderWithOutline​(java.awt.Graphics2D g, java.lang.String text, double x, double y, java.awt.Color outlineColor)
    Draw text at the given coordinates with an outline in the provided color.
    static voidrenderWithOutline​(java.awt.Graphics2D g, java.lang.String text, double x, double y, java.awt.Color outlineColor, boolean antiAliasing) 
    static voidrenderWithOutline​(java.awt.Graphics2D g, java.lang.String text, double x, double y, java.awt.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 voidrenderWithOutline​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, java.awt.Color outlineColor) 
    static voidrenderWithOutline​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, java.awt.Color outlineColor, boolean antiAliasing) 

    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​(java.awt.Graphics2D g, java.lang.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​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location)
    • render

      public static void render​(java.awt.Graphics2D g, java.lang.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​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Rectangle2D bounds, Align alignment, Valign verticalAlignment, boolean scaleFont)
    • render

      public static void render​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.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​(java.awt.Graphics2D g, java.lang.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:
      RenderingHints
    • render

      public static void render​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, boolean antiAliasing)
    • renderRotated

      public static void renderRotated​(java.awt.Graphics2D g, java.lang.String text, double x, double y, double angle, boolean antiAliasing)
    • renderRotated

      public static void renderRotated​(java.awt.Graphics2D g, java.lang.String text, double x, double y, double angle)
    • renderRotated

      public static void renderRotated​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double angle)
    • renderRotated

      public static void renderRotated​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double angle, boolean antiAliasing)
    • renderWithLinebreaks

      public static void renderWithLinebreaks​(java.awt.Graphics2D g, java.lang.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​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double lineWidth)
    • renderWithLinebreaks

      public static void renderWithLinebreaks​(java.awt.Graphics2D g, java.lang.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:
      RenderingHints
    • renderWithLinebreaks

      public static void renderWithLinebreaks​(java.awt.Graphics2D g, java.lang.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
      height - the line height.
      width - the line width
      antiAliasing - Configure whether or not to render the text with antialiasing.
      See Also:
      RenderingHints
    • renderWithLinebreaks

      public static void renderWithLinebreaks​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double lineWidth, boolean antiAliasing)
    • renderWithOutline

      public static void renderWithOutline​(java.awt.Graphics2D g, java.lang.String text, double x, double y, java.awt.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​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, java.awt.Color outlineColor)
    • renderWithOutline

      public static void renderWithOutline​(java.awt.Graphics2D g, java.lang.String text, double x, double y, java.awt.Color outlineColor, boolean antiAliasing)
    • renderWithOutline

      public static void renderWithOutline​(java.awt.Graphics2D g, java.lang.String text, double x, double y, java.awt.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:
      RenderingHints
    • renderWithOutline

      public static void renderWithOutline​(java.awt.Graphics2D g, java.lang.String text, double x, double y, double width, double height, java.awt.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:
      RenderingHints
    • renderWithOutline

      public static void renderWithOutline​(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, java.awt.Color outlineColor, boolean antiAliasing)
    • getBounds

      public static java.awt.geom.Rectangle2D getBounds​(java.awt.Graphics2D g, java.lang.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:
      FontMetrics.getStringBounds(String str, Graphics context)
    • getWidth

      public static double getWidth​(java.awt.Graphics2D g, java.lang.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​(java.awt.Graphics2D g, java.lang.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​(java.awt.Graphics2D g)