net.sourceforge.jeuclid.font
Class FontFactory

java.lang.Object
  extended by net.sourceforge.jeuclid.font.FontFactory
Direct Known Subclasses:
DefaultFontFactory

public abstract class FontFactory
extends 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
static String SANSSERIF
          Name for the default (sans serif) font.
 
Constructor Summary
FontFactory()
           
 
Method Summary
abstract  Font getFont(List<String> preferredFonts, int codepoint, int style, float size)
          Create a font object which is able to display the requested code point.
abstract  Font getFont(String name, int style, float size)
          Create a font object with specified properties.
static FontFactory getInstance()
          Return an instance of the currently configured concrete FontFactory.
abstract  Set<String> listFontNames()
          Retrieve a list of all fonts registered with this fontFactory.
abstract  Font registerFont(int format, File fontFile)
          Load an external font from a file and 'register' (aka 'cache') it for future use.
abstract  Font registerFont(int format, 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 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 Font getFont(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.Font(String, int, int)

getFont

public abstract Font getFont(List<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 Font registerFont(int format,
                                  File fontFile)
                           throws IOException,
                                  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:
FontFormatException - if font contained in the file doesn't match the specified format
IOException - in case of problem while reading the file
See Also:
Font.createFont(int, File)

registerFont

public abstract Font registerFont(int format,
                                  InputStream fontStream)
                           throws IOException,
                                  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:
FontFormatException - if font contained in the stream doesn't match the specified format
IOException - in case of problem while reading the stream
See Also:
Font.createFont(int, InputStream)

listFontNames

public abstract Set<String> listFontNames()
Retrieve a list of all fonts registered with this fontFactory.

Returns:
A set of recognized font names


Copyright © 2002-2010 The JEuclid project. All Rights Reserved.