Java Utililty Methods Font Text Bounds

List of utility methods to do Font Text Bounds

Description

The list of methods to do Font Text Bounds are organized into topic(s).

Method

Rectangle2DgetStringBounds(Graphics2D g, Font font, String s)
get String Bounds
return g.getFontMetrics(font).getStringBounds(s, g);
DimensiongetStringBounds(Graphics2D g2, String s)
Returns the @Rectangle2D surrounding a piece of text
if (isStringEmpty(s))
    return new Dimension();
TextLayout layout = new TextLayout(s, g2.getFont(), g2.getFontRenderContext());
Rectangle2D bounds = layout.getBounds();
return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight());
RectanglegetStringBounds(Graphics2D g2, String str, float x, float y)
get String Bounds
FontRenderContext frc = g2.getFontRenderContext();
GlyphVector gv = g2.getFont().createGlyphVector(frc, str);
return gv.getPixelBounds(null, x, y);
Rectangle2DgetStringBounds(Graphics2D g2d, String text, int x, int y)
Calculates the string bounds for the given text.
Rectangle2D bounds = g2d.getFontMetrics().getStringBounds(text, g2d);
return setLocation(bounds, x, y);
Rectangle2DgetStringBounds(String s, Graphics g)
Compute the width and height of given string given the current font context in the Graphics object
FontMetrics fm = g.getFontMetrics();
return fm.getStringBounds(s, 0, s.length(), g);
Rectangle2DgetStringBounds(String str, java.awt.Font font)
Get the string bounds for a particular string given the font.
return font.getStringBounds(str, 0, str.length(), new FontRenderContext(new AffineTransform(), true, true));
Rectangle2DgetTextBounds(AttributedString text, Graphics2D g2)
Returns the bounds for the attributed string.
TextLayout tl = new TextLayout(text.getIterator(), g2.getFontRenderContext());
return tl.getBounds();
Rectangle2DgetTextBounds(final Graphics2D graphics, final String text, final Font font)
get Text Bounds
final FontRenderContext frc = graphics.getFontRenderContext();
final GlyphVector gv = font.createGlyphVector(frc, text);
return gv.getVisualBounds();
RectanglegetTextBounds(final String text, final Graphics g, final Font font)
Determines real text size
return getTextBounds(text, (Graphics2D) g, font);
RectanglegetTextBounds(Graphics g, Font font, String text, int x, int y, int halign, int valign)
get Text Bounds
if (g == null)
    return new Rectangle(x, y, 0, 0);
Font oldfont = g.getFont();
if (font != null)
    g.setFont(font);
Rectangle ret = getTextBounds(g, text, x, y, halign, valign);
if (font != null)
    g.setFont(oldfont);
...