Class TextSizingUtility
- java.lang.Object
-
- ch.sahits.game.openpatrician.javafx.control.TextSizingUtility
-
- All Implemented Interfaces:
ITextSizing
public class TextSizingUtility extends java.lang.Object implements ITextSizing
Utility class to define the dimensions of texts used with a certain font.- Author:
- Andi Hotz, (c) Sahits GmbH, 2013 Created on Aug 4, 2013
-
-
Constructor Summary
Constructors Constructor Description TextSizingUtility()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javafx.geometry.Dimension2D
calculate(int size, javafx.scene.text.Font font)
Calculate the dimensions of a string using the font with the number of characters.javafx.geometry.Dimension2D
calculate(java.lang.String text, javafx.scene.text.Font font)
Calculate the dimensions of a string using the font with the characters in the string.(package private) double
computeTextHeight(javafx.scene.text.Font font, java.lang.String text, double wrappingWidth)
(package private) double
computeTextHeight(javafx.scene.text.Font font, java.lang.String text, double wrappingWidth, double lineSpacing)
(package private) double
computeTextWidth(javafx.scene.text.Font font, java.lang.String text, double wrappingWidth)
int
guessNumberOfCharacters(double destWidth, javafx.scene.text.Font font)
Guess the number of characters that can be displayed indestWidth
.
-
-
-
Method Detail
-
computeTextWidth
double computeTextWidth(javafx.scene.text.Font font, java.lang.String text, double wrappingWidth)
-
computeTextHeight
double computeTextHeight(javafx.scene.text.Font font, java.lang.String text, double wrappingWidth)
-
computeTextHeight
double computeTextHeight(javafx.scene.text.Font font, java.lang.String text, double wrappingWidth, double lineSpacing)
-
calculate
public javafx.geometry.Dimension2D calculate(int size, javafx.scene.text.Font font)
Calculate the dimensions of a string using the font with the number of characters. The height and width are the maximum value, the width of a character is an average value.- Specified by:
calculate
in interfaceITextSizing
- Parameters:
size
- number of carachters for wich to calculate the dimensionsfont
- to be used- Returns:
- dimensions of a String containing Tg to calculate the heigth and n for the width calculation.
-
guessNumberOfCharacters
public int guessNumberOfCharacters(double destWidth, javafx.scene.text.Font font)
Guess the number of characters that can be displayed indestWidth
. The number is guessed as an arbitrary width per character for the font is assumed.- Parameters:
destWidth
- destination withfont
- to used for the text- Returns:
- number of characters that should match into
destWidth
-
calculate
public javafx.geometry.Dimension2D calculate(java.lang.String text, javafx.scene.text.Font font)
Calculate the dimensions of a string using the font with the characters in the string. The height and width are the maximum value. The text will not be wrapped.- Specified by:
calculate
in interfaceITextSizing
- Parameters:
text
- for which to calculate the dimensionsfont
- to be used for the calculation- Returns:
- Bounding box for the text using font.
-
-