Class TextRenderer
java.lang.Object
de.gurkenlabs.litiengine.graphics.TextRenderer
public final class TextRenderer
extends java.lang.Object
Method Summary
Modifier and Type Method Description static void
enableTextAntiAliasing(java.awt.Graphics2D g)
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 Graphics2Dstatic 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 Graphics2Dstatic 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 Graphics2Dstatic void
render(java.awt.Graphics2D g, java.lang.String text, double x, double y)
Draw text at the given coordinates.static void
render(java.awt.Graphics2D g, java.lang.String text, double x, double y, boolean antiAliasing)
Draw text at the given coordinates.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.static void
render(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location)
static void
render(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, boolean antiAliasing)
static void
render(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Rectangle2D bounds, Align alignment, Valign verticalAlignment, boolean scaleFont)
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.static void
renderRotated(java.awt.Graphics2D g, java.lang.String text, double x, double y, double angle)
static void
renderRotated(java.awt.Graphics2D g, java.lang.String text, double x, double y, double angle, boolean antiAliasing)
static void
renderRotated(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double angle)
static void
renderRotated(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double angle, boolean antiAliasing)
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.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.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.static void
renderWithLinebreaks(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double lineWidth)
static void
renderWithLinebreaks(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, double lineWidth, boolean antiAliasing)
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.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.static void
renderWithOutline(java.awt.Graphics2D g, java.lang.String text, double x, double y, java.awt.Color outlineColor, boolean antiAliasing)
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.static void
renderWithOutline(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, java.awt.Color outlineColor)
static void
renderWithOutline(java.awt.Graphics2D g, java.lang.String text, java.awt.geom.Point2D location, java.awt.Color outlineColor, boolean antiAliasing)
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 ontext
- the String to be distributed over all generated linesx
- the min x coordinatey
- 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 ontext
- the String to be distributed over all generated linesalign
- 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
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 ontext
- the String to be distributed over all generated linesbounds
- 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 ontext
- the String to be distributed over all generated linesx
- the min x coordinatey
- the min y coordinateantiAliasing
- 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 ontext
- the String to be distributed over all generated linesx
- the min x coordinatey
- the min y coordinatelineWidth
- 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 ontext
- the String to be distributed over all generated linesx
- the min x coordinatey
- the min y coordinatelineWidth
- the max line widthantiAliasing
- 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 ontext
- the String to be distributed over all generated linesalign
- The horizontal alignment.valign
- The vertical alignment.x
- the min x coordinatey
- the min y coordinateheight
- the line height.width
- the line widthantiAliasing
- 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 ontext
- the String to be distributed over all generated linesx
- the min x coordinatey
- the min y coordinateoutlineColor
- 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 ontext
- the String to be distributed over all generated linesx
- the min x coordinatey
- the min y coordinateoutlineColor
- the outline colorstroke
- the width of the outlineantiAliasing
- 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 ontext
- the String to be distributed over all generated linesx
- the min x coordinatey
- the min y coordinatewidth
- the width of the bounding box in which the text will be alignedheight
- the height of the bounding box in which the text will be alignedoutlineColor
- the outline colorstroke
- the thickness of the outlinealign
- 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 ontext
- 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 ontext
- 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 ontext
- The string to retrieve the height of- Returns:
- The height of the specified text
enableTextAntiAliasing
public static void enableTextAntiAliasing(java.awt.Graphics2D g)