Class FontMetrics


  • public class FontMetrics
    extends java.lang.Object
    Simple font metrics class, independent of graphics subsystems and installed fonts.

    It supports Helvetica, Arial, Frutiger, Liberation Sans. Kerning and ligatures 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
      double getAscender​(int fontSize)
      Distance between baseline and top of highest letter.
      double getDescender​(int fontSize)
      Distance between baseline and bottom of letter extending the farest below the baseline.
      java.lang.String getFirstFontFamily()
      Gets the first font family (from the font family list).
      java.lang.String getFontFamilyList()
      Gets the font family list.
      double getLineHeight​(int fontSize)
      Distance between the baselines of two consecutive text lines.
      double getTextWidth​(java.lang.CharSequence text, int fontSize, boolean isBold)
      Returns the width of the specified text for the specified font size
      java.lang.String[] splitLines​(java.lang.String text, double maxLength, int fontSize)
      Splits the text into lines.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FontMetrics

        public FontMetrics​(java.lang.String fontFamilyList)
    • 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 farest 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 text
        maxLength - 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 - text
        fontSize - font size (in pt)
        isBold - indicates if the text is in bold or regular weight
        Returns:
        width (in mm)