public class FontCalculator extends Object
Modifier and Type | Method and Description |
---|---|
Font |
fontToFitRectangle(Rectangle2D rectangle,
double scaleFactor,
String text,
String fontName,
int fontStyle)
Returns a font object that has the correct height to draw the specified text in the specified rectangle using
no minimal font height.
|
Font |
fontToFitRectangle(Rectangle2D rectangle,
double scaleFactor,
String text,
String fontName,
int fontStyle,
int minHeight)
Returns a font object that has the correct height to draw the specified text in the specified rectangle.
|
float |
getAscent(Font font) |
float |
getAscentToHeight(String fontName,
int fontStyle,
float height) |
float |
getAspectRatio(Font font,
String text)
Returns the width of the given text divided by the height.
|
float |
getDescent(Font font) |
float |
getDescentToHeight(String fontName,
int fontStyle,
float height) |
float |
getHeight(Font font) |
static FontCalculator |
getInstance() |
float |
getWidth(Font font,
String text) |
float |
getWidthToHeigth(String fontName,
int fontStyle,
String text,
float height) |
public static FontCalculator getInstance()
public float getDescent(Font font)
public float getAspectRatio(Font font, String text)
The value is identical with getWidth() / getHeight()
but is calculated more efficiently.
public float getWidthToHeigth(String fontName, int fontStyle, String text, float height)
public float getDescentToHeight(String fontName, int fontStyle, float height)
public float getAscentToHeight(String fontName, int fontStyle, float height)
public Font fontToFitRectangle(Rectangle2D rectangle, double scaleFactor, String text, String fontName, int fontStyle)
rectangle
- the rectangle to fit the text intoscaleFactor
- the factor by which the font height should be scaled (If 1.0 is provided here, the text will
will the width or the height of the rectangle completely. Note that due to possible rounding imprecision
a value below 1.0 is recommended so that the text fits completely into the rectangle.)text
- the text to be drawnfontName
- the name of the font to be usedfontStyle
- the style of the font to be usedGraphicsUtils.drawStringInRectangle(Graphics2D, Rectangle2D, String)
public Font fontToFitRectangle(Rectangle2D rectangle, double scaleFactor, String text, String fontName, int fontStyle, int minHeight)
rectangle
- the rectangle to fit the text intoscaleFactor
- the factor by which the font height should be scaled (If 1.0 is provided here, the text will
will the width or the height of the rectangle completely. Note that due to possible rounding imprecision
a value below 1.0 is recommended so that the text fits completely into the rectangle.)text
- the text to be drawnfontName
- the name of the font to be usedfontStyle
- the style of the font to be usedminHeight
- the minimal font height the text should havenull
if the font would have to be smaller than the specified minimal heightGraphicsUtils.drawStringInRectangle(Graphics2D, Rectangle2D, String)