Class FontUtil


  • public class FontUtil
    extends Object

    Created by Jeff Gaynor
    on 6/27/24 at 7:08 AM

    • Constructor Detail

      • FontUtil

        public FontUtil()
    • Method Detail

      • fontReport

        protected String fontReport​(Font font)
      • getStyle

        public static String getStyle​(Font font)
        Convert the Swing constant for the font style into the QDL name.
        Parameters:
        font -
        Returns:
      • getStyle

        public static int getStyle​(String styleName)
        Convert the QDL names for font styles into the constant that Swing understands.

        Caveat any unknown font style is rendered as the default, which is Font.BOLD
        Parameters:
        styleName -
        Returns:
      • findQDLFonts

        public static List<String> findQDLFonts()
                                         throws Throwable
        A utility that runs through all of the fons on your system and finds those that are able to output all of the QDL character set.

        The issue

        The issue is that Swing is restricted to TrueType fonts and very few of those have all the unicode characters in them. Really only the built-in Java is reliable. This checks by using the QDLConstants.UNICODE_CHARS and checks how much of it is printable. Any result from that greater than -1 flags which character Swing fails at.

        This is compounded by the fact that other font formats might include more. For instance "Ubuntu Mono" as an Open Type font has everything, but several characters as missing in the True Type version. Applications may be clever too and auto switch to replace a missing character from another font or member of a family of fonts. Can't do that in Swing either on a per character basis.

        Common failures are the APL symbols for the apply and floor operator, or the alternate Greek letters for rho, theta, etc. Math symbol sets had the latter, only APL character sets reliably have the first, but usually don't have any Math symbols.

        Returns:
        Throws:
        Throwable
      • checkSingleFont

        public static boolean checkSingleFont​(String name,
                                              int type,
                                              int size)
      • findUnsupportedCharacters

        public static String findUnsupportedCharacters​(Font font,
                                                       String x)
        A font utility to check the support for a font. This returns the string of characters that this font cannot display.
        Parameters:
        font -
        x -
        Returns:
      • findUnsupportedCharacters

        public static String findUnsupportedCharacters​(Font font,
                                                       char[] y)