Package org.docx4j.fonts.fop.fonts
Class FontLoader
java.lang.Object
org.docx4j.fonts.fop.fonts.FontLoader
- Direct Known Subclasses:
TTFFontLoader,Type1FontLoader
public abstract class FontLoader
extends java.lang.Object
Base class for font loaders.
-
Field Summary
Fields Modifier and Type Field Description protected booleanembeddedtrue if the font will be embedded, false if it will be referenced only.protected java.lang.StringfontFileURIURI representing the font fileprotected booleanloadedtrue if the font has been loadedprotected static org.slf4j.Loggerloglogging instanceprotected FontResolverresolverthe FontResolver to use for font URI resolutionprotected CustomFontreturnFontthe loaded fontprotected booleanuseKerningtrue if kerning information shall be loaded if available. -
Constructor Summary
Constructors Constructor Description FontLoader(java.lang.String fontFileURI, boolean embedded, boolean useKerning, FontResolver resolver)Default constructor. -
Method Summary
Modifier and Type Method Description CustomFontgetFont()Returns the custom font that was read using this instance of FontLoader.static CustomFontloadFont(java.io.File fontFile, java.lang.String subFontName, boolean embedded, EncodingMode encodingMode, FontResolver resolver)Loads a custom font from a File.static CustomFontloadFont(java.lang.String fontFileURI, java.lang.String subFontName, boolean embedded, EncodingMode encodingMode, boolean useKerning, FontResolver resolver)Loads a custom font from a URI.static CustomFontloadFont(java.net.URL fontUrl, java.lang.String subFontName, boolean embedded, EncodingMode encodingMode, FontResolver resolver)Loads a custom font from an URL.static java.io.InputStreamopenFontUri(FontResolver resolver, java.lang.String uri)Opens a font URI and returns an input stream.protected abstract voidread()Reads/parses the font data.
-
Field Details
-
log
protected static org.slf4j.Logger loglogging instance -
fontFileURI
protected java.lang.String fontFileURIURI representing the font file -
resolver
the FontResolver to use for font URI resolution -
returnFont
the loaded font -
loaded
protected boolean loadedtrue if the font has been loaded -
embedded
protected boolean embeddedtrue if the font will be embedded, false if it will be referenced only. -
useKerning
protected boolean useKerningtrue if kerning information shall be loaded if available.
-
-
Constructor Details
-
FontLoader
public FontLoader(java.lang.String fontFileURI, boolean embedded, boolean useKerning, FontResolver resolver)Default constructor.- Parameters:
fontFileURI- the URI to the PFB file of a Type 1 fontembedded- indicates whether the font is embedded or referenceduseKerning- indicates whether kerning information shall be loaded if availableresolver- the font resolver used to resolve URIs
-
-
Method Details
-
loadFont
public static CustomFont loadFont(java.io.File fontFile, java.lang.String subFontName, boolean embedded, EncodingMode encodingMode, FontResolver resolver) throws java.io.IOExceptionLoads a custom font from a File. In the case of Type 1 fonts, the PFB file must be specified.- Parameters:
fontFile- the File representation of the fontsubFontName- the sub-fontname of a font (for TrueType Collections, null otherwise)embedded- indicates whether the font is embedded or referencedencodingMode- the requested encoding moderesolver- the font resolver to use when resolving URIs- Returns:
- the newly loaded font
- Throws:
java.io.IOException- In case of an I/O error
-
loadFont
public static CustomFont loadFont(java.net.URL fontUrl, java.lang.String subFontName, boolean embedded, EncodingMode encodingMode, FontResolver resolver) throws java.io.IOExceptionLoads a custom font from an URL. In the case of Type 1 fonts, the PFB file must be specified.- Parameters:
fontUrl- the URL representation of the fontsubFontName- the sub-fontname of a font (for TrueType Collections, null otherwise)embedded- indicates whether the font is embedded or referencedencodingMode- the requested encoding moderesolver- the font resolver to use when resolving URIs- Returns:
- the newly loaded font
- Throws:
java.io.IOException- In case of an I/O error
-
loadFont
public static CustomFont loadFont(java.lang.String fontFileURI, java.lang.String subFontName, boolean embedded, EncodingMode encodingMode, boolean useKerning, FontResolver resolver) throws java.io.IOExceptionLoads a custom font from a URI. In the case of Type 1 fonts, the PFB file must be specified.- Parameters:
fontFileURI- the URI to the fontsubFontName- the sub-fontname of a font (for TrueType Collections, null otherwise)embedded- indicates whether the font is embedded or referencedencodingMode- the requested encoding modeuseKerning- indicates whether kerning information should be loaded if availableresolver- the font resolver to use when resolving URIs- Returns:
- the newly loaded font
- Throws:
java.io.IOException- In case of an I/O error
-
openFontUri
public static java.io.InputStream openFontUri(FontResolver resolver, java.lang.String uri) throws java.io.IOException, java.net.MalformedURLExceptionOpens a font URI and returns an input stream.- Parameters:
resolver- the FontResolver to use for font URI resolutionuri- the URI representing the font- Returns:
- the InputStream to read the font from.
- Throws:
java.io.IOException- In case of an I/O errorjava.net.MalformedURLException- If an invalid URL is built
-
read
protected abstract void read() throws java.io.IOExceptionReads/parses the font data.- Throws:
java.io.IOException- In case of an I/O error
-
getFont
Returns the custom font that was read using this instance of FontLoader.- Returns:
- the newly loaded font
- Throws:
java.io.IOException- if an I/O error occurs
-