Class FontMetrics


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

    Only supports Helvetica font.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double getAscender​(int fontSize)
      Distance between baseline and top of highest letter.
      static double getDescender​(int fontSize)
      Distance between baseline and bottom of letter extending the farest below the baseline.
      static double getLineHeight​(int fontSize)
      Distance between the baselines of two consecutive text lines.
      static 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
    • Method Detail

      • getAscender

        public static 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 static 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 static 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 static 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