Class FontUtil


  • public final class FontUtil
    extends java.lang.Object
    Font utilities.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String[] BOLD_WORDS
      font constituent names which identify a font as being of "bold" weight
      private static java.lang.String[] DEMI_WORDS
      font constituent names which identify a font as being of "demi/semi" weight
      private static java.lang.String[] EXTRA_BOLD_WORDS
      font constituent names which identify a font as being of "extra bold" weight
      private static java.lang.String[] ITALIC_WORDS
      font constituent names which identify a font as being of "italic" style
      private static java.lang.String[] LIGHT_WORDS
      font constituent names which identify a font as being of "light" weight
      private static java.lang.String[] MEDIUM_WORDS
      font constituent names which identify a font as being of "medium" weight
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FontUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String guessStyle​(java.lang.String fontName)
      Guesses the font style of a font using its name.
      static int guessWeight​(java.lang.String fontName)
      Guesses the font weight of a font using its name.
      static int parseCSS2FontWeight​(java.lang.String text)
      Parses an CSS2 (SVG and XSL-FO) font weight (normal, bold, 100-900) to an integer.
      static java.lang.String stripWhiteSpace​(java.lang.String str)
      Removes all white space from a string (used primarily for font names)
      • Methods inherited from class java.lang.Object

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

      • ITALIC_WORDS

        private static final java.lang.String[] ITALIC_WORDS
        font constituent names which identify a font as being of "italic" style
      • LIGHT_WORDS

        private static final java.lang.String[] LIGHT_WORDS
        font constituent names which identify a font as being of "light" weight
      • MEDIUM_WORDS

        private static final java.lang.String[] MEDIUM_WORDS
        font constituent names which identify a font as being of "medium" weight
      • DEMI_WORDS

        private static final java.lang.String[] DEMI_WORDS
        font constituent names which identify a font as being of "demi/semi" weight
      • BOLD_WORDS

        private static final java.lang.String[] BOLD_WORDS
        font constituent names which identify a font as being of "bold" weight
      • EXTRA_BOLD_WORDS

        private static final java.lang.String[] EXTRA_BOLD_WORDS
        font constituent names which identify a font as being of "extra bold" weight
    • Constructor Detail

      • FontUtil

        private FontUtil()
    • Method Detail

      • parseCSS2FontWeight

        public static int parseCSS2FontWeight​(java.lang.String text)
        Parses an CSS2 (SVG and XSL-FO) font weight (normal, bold, 100-900) to an integer. See http://www.w3.org/TR/REC-CSS2/fonts.html#propdef-font-weight TODO: Implement "lighter" and "bolder".
        Parameters:
        text - the font weight to parse
        Returns:
        an integer between 100 and 900 (100, 200, 300...)
      • stripWhiteSpace

        public static java.lang.String stripWhiteSpace​(java.lang.String str)
        Removes all white space from a string (used primarily for font names)
        Parameters:
        str - the string
        Returns:
        the processed result
      • guessStyle

        public static java.lang.String guessStyle​(java.lang.String fontName)
        Guesses the font style of a font using its name.
        Parameters:
        fontName - the font name
        Returns:
        "normal" or "italic"
      • guessWeight

        public static int guessWeight​(java.lang.String fontName)
        Guesses the font weight of a font using its name.
        Parameters:
        fontName - the font name
        Returns:
        an integer between 100 and 900