Package net.sourceforge.jeuclid.font
Class FontFactory
- java.lang.Object
-
- net.sourceforge.jeuclid.font.FontFactory
-
- Direct Known Subclasses:
DefaultFontFactory
public abstract class FontFactory extends java.lang.ObjectAbstract 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.StringSANSSERIFName 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.FontgetFont(java.lang.String name, int style, float size)Create a font object with specified properties.abstract java.awt.FontgetFont(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 FontFactorygetInstance()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.FontregisterFont(int format, java.io.File fontFile)Load an external font from a file and 'register' (aka 'cache') it for future use.abstract java.awt.FontregisterFont(int format, java.io.InputStream fontStream)Load an external font from a stream and 'register' (aka 'cache') it for future use.
-
-
-
Field Detail
-
SANSSERIF
public static final java.lang.String SANSSERIF
Name for the default (sans serif) font.- See Also:
- Constant Field Values
-
-
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 namestyle- font stylesize- 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 fontscodepoint- code point which must be displayablestyle- font stylesize- 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.FontFormatExceptionLoad 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 formatjava.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.FontFormatExceptionLoad 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 formatjava.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
-
-