Package net.sourceforge.jeuclid.font
Class FontFactory
java.lang.Object
net.sourceforge.jeuclid.font.FontFactory
- Direct Known Subclasses:
DefaultFontFactory
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract FontCreate a font object with specified properties.abstract FontCreate a font object which is able to display the requested code point.static FontFactoryReturn an instance of the currently configured concrete FontFactory.Retrieve a list of all fonts registered with this fontFactory.abstract FontregisterFont(int format, File fontFile) Load an external font from a file and 'register' (aka 'cache') it for future use.abstract FontregisterFont(int format, InputStream fontStream) Load an external font from a stream and 'register' (aka 'cache') it for future use.
-
Field Details
-
SANSSERIF
Name for the default (sans serif) font.- See Also:
-
-
Constructor Details
-
FontFactory
public FontFactory()
-
-
Method Details
-
getInstance
Return an instance of the currently configured concrete FontFactory.- Returns:
- an instance of FontFactory
-
getFont
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:
-
getFont
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 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 formatIOException- in case of problem while reading the file- See Also:
-
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 formatIOException- in case of problem while reading the stream- See Also:
-
listFontNames
Retrieve a list of all fonts registered with this fontFactory.- Returns:
- A set of recognized font names
-