Class DefaultFontFactory


  • @ThreadSafe
    public class DefaultFontFactory
    extends FontFactory
    Concrete FontFactory implementation that does simple caching of Fonts loaded via Font.createFont(int, File) APIs.
    Version:
    $Revision: 2907029e5fad $
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Font getFont​(java.lang.String name, int style, float size)
      Create a font object with specified properties.
      java.awt.Font getFont​(java.util.List<java.lang.String> preferredFonts, int codepoint, int style, float size)
      Create a font object which is able to display the requested code point.
      java.util.Set<java.lang.String> listFontNames()
      Retrieve a list of all fonts registered with this fontFactory.
      java.awt.Font registerFont​(int format, java.io.File fontFile)
      Load an external font from a file and 'register' (aka 'cache') it for future use.
      java.awt.Font registerFont​(int format, java.io.InputStream fontStream)
      Load an external font from a stream and 'register' (aka 'cache') it for future use.
      • Methods inherited from class java.lang.Object

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

      • getFont

        public java.awt.Font getFont​(java.lang.String name,
                                     int style,
                                     float size)
        Create a font object with specified properties. Font name may refer to either 'built-in' or loaded externally and 'cached' font.
        Specified by:
        getFont in class FontFactory
        Parameters:
        name - font name or font family name
        style - font style
        size - font size
        Returns:
        Font instance
        See Also:
        Font(String, int, int)
      • getFont

        public java.awt.Font getFont​(java.util.List<java.lang.String> preferredFonts,
                                     int codepoint,
                                     int style,
                                     float size)
        Create a font object which is able to display the requested code point. Uses one of the list of preferred fonts is possible. If no matching font is found null is returned.
        Specified by:
        getFont in class FontFactory
        Parameters:
        preferredFonts - List of preferred fonts
        codepoint - code point which must be displayable
        style - font style
        size - font size
        Returns:
        a valid Font instance or null if no font could be found.
      • registerFont

        public java.awt.Font registerFont​(int format,
                                          java.io.File fontFile)
                                   throws java.io.IOException,
                                          java.awt.FontFormatException
        Load an external font from a file and 'register' (aka 'cache') it for future use.
        Specified by:
        registerFont in class FontFactory
        Parameters:
        format - font format (TTF or TYPE_1 currently supported by the platform)
        fontFile - file which contains the font
        Returns:
        The newly created Font instance
        Throws:
        java.awt.FontFormatException - if font contained in the file doesn't match the specified format
        java.io.IOException - in case of problem while reading the file
        See Also:
        Font.createFont(int, File)
      • registerFont

        public java.awt.Font registerFont​(int format,
                                          java.io.InputStream fontStream)
                                   throws java.io.IOException,
                                          java.awt.FontFormatException
        Load an external font from a stream and 'register' (aka 'cache') it for future use.
        Specified by:
        registerFont in class FontFactory
        Parameters:
        format - font format (TTF or TYPE_1 currently supported by the platform)
        fontStream - file which contains the font
        Returns:
        The newly created Font instance
        Throws:
        java.awt.FontFormatException - if font contained in the stream doesn't match the specified format
        java.io.IOException - in case of problem while reading the stream
        See Also:
        Font.createFont(int, InputStream)
      • listFontNames

        public java.util.Set<java.lang.String> listFontNames()
        Retrieve a list of all fonts registered with this fontFactory.
        Specified by:
        listFontNames in class FontFactory
        Returns:
        A set of recognized font names