Package net.codecrete.qrbill.canvas
Class FontMetrics
java.lang.Object
net.codecrete.qrbill.canvas.FontMetrics
Simple font metrics class, independent of graphics subsystems and
installed fonts.
It supports Helvetica, Arial, Frutiger, Liberation Sans. Kerning and ligatures are not supported.
-
Constructor Summary
ConstructorDescriptionFontMetrics
(String fontFamilyList) Creates a new instance for the first supported font in the specified list. -
Method Summary
Modifier and TypeMethodDescriptiondouble
getAscender
(int fontSize) Distance between baseline and top of the highest letter.double
getDescender
(int fontSize) Distance between baseline and bottom of letter extending the farthest below the baseline.Gets the first font family (from the font family list).Gets the font family list.double
getLineHeight
(int fontSize) Distance between the baselines of two consecutive text lines.double
getTextWidth
(CharSequence text, int fontSize, boolean isBold) Returns the width of the specified text for the specified font sizeString[]
splitLines
(String text, double maxLength, int fontSize) Splits the text into lines.
-
Constructor Details
-
FontMetrics
Creates a new instance for the first supported font in the specified list.- Parameters:
fontFamilyList
- list of font families
-
-
Method Details
-
getFontFamilyList
Gets the font family list.- Returns:
- font family list (comma separated)
-
getFirstFontFamily
Gets the first font family (from the font family list).- Returns:
- first font family
-
getAscender
public double getAscender(int fontSize) Distance between baseline and top of the highest letter.- Parameters:
fontSize
- the font size (in pt)- Returns:
- the distance (in mm)
-
getDescender
public double getDescender(int fontSize) Distance between baseline and bottom of letter extending the farthest below the baseline.- Parameters:
fontSize
- the font size (in pt)- Returns:
- the distance (in mm)
-
getLineHeight
public double getLineHeight(int fontSize) Distance between the baselines of two consecutive text lines.- Parameters:
fontSize
- the font size (in pt)- Returns:
- the distance (in mm)
-
splitLines
Splits the text into lines.If a line would exceed the specified maximum length, line breaks are inserted. Newlines are treated as fixed line breaks.
- Parameters:
text
- the textmaxLength
- the maximum line length (in pt)fontSize
- the font size (in pt)- Returns:
- an array of text lines
-
getTextWidth
Returns the width of the specified text for the specified font size- Parameters:
text
- textfontSize
- font size (in pt)isBold
- indicates if the text is in bold or regular weight- Returns:
- width (in mm)
-