Package net.codecrete.qrbill.canvas
Class FontMetrics
- java.lang.Object
-
- net.codecrete.qrbill.canvas.FontMetrics
-
public class FontMetrics extends java.lang.ObjectSimple 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
Constructors Constructor Description FontMetrics(java.lang.String fontFamilyList)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetAscender(int fontSize)Distance between baseline and top of highest letter.doublegetDescender(int fontSize)Distance between baseline and bottom of letter extending the farthest below the baseline.java.lang.StringgetFirstFontFamily()Gets the first font family (from the font family list).java.lang.StringgetFontFamilyList()Gets the font family list.doublegetLineHeight(int fontSize)Distance between the baselines of two consecutive text lines.doublegetTextWidth(java.lang.CharSequence text, int fontSize, boolean isBold)Returns the width of the specified text for the specified font sizejava.lang.String[]splitLines(java.lang.String text, double maxLength, int fontSize)Splits the text into lines.
-
-
-
Method Detail
-
getFontFamilyList
public java.lang.String getFontFamilyList()
Gets the font family list.- Returns:
- font family list (comma separated)
-
getFirstFontFamily
public java.lang.String 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 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
public java.lang.String[] splitLines(java.lang.String text, double maxLength, int fontSize)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
public double getTextWidth(java.lang.CharSequence text, int fontSize, boolean isBold)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)
-
-