Class FontFactory

  • Direct Known Subclasses:
    DefaultFontFactory

    public abstract class FontFactory
    extends java.lang.Object
    Abstract factory to be used to create instances of java.awt.Font. The rationale behind this approach is that out-of-the box there is no way in java platform to load and register and internal font. In other words, Font.createFont and Font's constructor are not aware of each other.

    The abstract FontFactory just provides a centralized access and extension point, delegating the actual functionality to subclasses.

    How a concrete subclass of FontFactory is identified is subject to change in the future versions.

    Version:
    $Revision: e6bd6c2d9bf4 $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SANSSERIF
      Name for the default (sans serif) font.
    • Constructor Summary

      Constructors 
      Constructor Description
      FontFactory()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract java.awt.Font getFont​(java.lang.String name, int style, float size)
      Create a font object with specified properties.
      abstract 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.
      static FontFactory getInstance()
      Return an instance of the currently configured concrete FontFactory.
      abstract java.util.Set<java.lang.String> listFontNames()
      Retrieve a list of all fonts registered with this fontFactory.
      abstract 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.
      abstract 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
    • Field Detail

      • SANSSERIF

        public static final java.lang.String SANSSERIF
        Name for the default (sans serif) font.
        See Also:
        Constant Field Values
    • Constructor Detail

      • FontFactory

        public FontFactory()
    • Method Detail

      • getInstance

        public static FontFactory getInstance()
        Return an instance of the currently configured concrete FontFactory.
        Returns:
        an instance of FontFactory
      • getFont

        public abstract 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.
        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 abstract 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.
        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 abstract 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.
        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 abstract 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.
        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 abstract java.util.Set<java.lang.String> listFontNames()
        Retrieve a list of all fonts registered with this fontFactory.
        Returns:
        A set of recognized font names