Class TextRenderer
java.lang.Object
de.gurkenlabs.litiengine.graphics.TextRenderer
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 TypeMethodDescriptionstatic voidEnables text anti-aliasing on the providedGraphics2Dobject.static Rectangle2DgetBounds(Graphics2D g, String text) Retrieve the bounds of some text if it was to be drawn on the specified Graphics2Dstatic doublegetHeight(Graphics2D g, String text) Retrieve the height of some text if it was to be drawn on the specified Graphics2Dstatic doublegetWidth(Graphics2D g, String text) Retrieve the width of some text if it was to be drawn on the specified Graphics2Dstatic voidrender(Graphics2D g, String text, double x, double y) Draw text at the given coordinates.static voidrender(Graphics2D g, String text, double x, double y, boolean antiAliasing) Draw text at the given coordinates.static voidrender(Graphics2D g, String text, Align align, Valign valign, double offsetX, double offsetY) Draws text with the specified alignment.static voidrender(Graphics2D g, String text, Point2D location) Renders the specifiedStringto the givenGraphics2Dobject at the specified location.static voidrender(Graphics2D g, String text, Point2D location, boolean antiAliasing) Renders the specifiedStringto the givenGraphics2Dobject at the specified location with optional anti-aliasing.static voidrender(Graphics2D g, String text, Rectangle2D bounds, Align alignment, Valign verticalAlignment, boolean scaleFont) Renders the specifiedStringto the givenGraphics2Dobject within the specified bounds using the specified alignment and scaling options.static voidrender(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 voidrenderRotated(Graphics2D g, String text, double x, double y, double angle) Renders the specifiedStringto the givenGraphics2Dobject at the specified coordinates with rotation.static voidrenderRotated(Graphics2D g, String text, double x, double y, double angle, boolean antiAliasing) Renders the specifiedStringto the givenGraphics2Dobject at the specified coordinates with rotation and optional anti-aliasing.static voidrenderRotated(Graphics2D g, String text, Point2D location, double angle) Renders the specifiedStringto the givenGraphics2Dobject at the specified location with rotation.static voidrenderRotated(Graphics2D g, String text, Point2D location, double angle, boolean antiAliasing) Renders the specifiedStringto the givenGraphics2Dobject at the specified location with rotation and optional anti-aliasing.static voidrenderWithLinebreaks(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 voidrenderWithLinebreaks(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 voidrenderWithLinebreaks(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 voidrenderWithLinebreaks(Graphics2D g, String text, Point2D location, double lineWidth) Draw text at the given coordinates with a maximum line width for automatic line breaks.static voidrenderWithLinebreaks(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 voidrenderWithOutline(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 voidrenderWithOutline(Graphics2D g, String text, double x, double y, Color outlineColor) Draw text at the given coordinates with an outline in the provided color.static voidrenderWithOutline(Graphics2D g, String text, double x, double y, Color outlineColor, boolean antiAliasing) static voidrenderWithOutline(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 voidrenderWithOutline(Graphics2D g, String text, Point2D location, Color outlineColor) Draw text at the given coordinates with an outline in the provided color.static voidrenderWithOutline(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.
-
Method Details
-
render
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
Renders the specifiedStringto the givenGraphics2Dobject 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 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
public static void render(Graphics2D g, String text, Rectangle2D bounds, Align alignment, Valign verticalAlignment, boolean scaleFont) Renders the specifiedStringto the givenGraphics2Dobject 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 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
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:
-
render
Renders the specifiedStringto the givenGraphics2Dobject 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 specifiedStringto the givenGraphics2Dobject 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
Renders the specifiedStringto the givenGraphics2Dobject 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
Renders the specifiedStringto the givenGraphics2Dobject 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 specifiedStringto the givenGraphics2Dobject 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 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(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 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:
-
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 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 coordinatewidth- the line widthheight- 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 ontext- the String to be distributed over all generated lineslocation- The location where the text will be drawn.lineWidth- the max line widthantiAliasing- 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 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(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 ontext- the String to be distributed over all generated lineslocation- 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 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:
-
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 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:
-
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 ontext- the String to be distributed over all generated lineslocation- The location where the text will be drawn.outlineColor- the outline colorantiAliasing- Configure whether or not to render the text with antialiasing.- See Also:
-
getBounds
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:
-
getWidth
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
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
Enables text anti-aliasing on the providedGraphics2Dobject.- Parameters:
g- The Graphics2D object on which to enable text anti-aliasing.
-