Package org.docx4j.fonts.fop.fonts
Class FontCache
java.lang.Object
org.docx4j.fonts.fop.fonts.FontCache
- All Implemented Interfaces:
java.io.Serializable
public final class FontCache
extends java.lang.Object
implements java.io.Serializable
Fop cache (currently only used for font info caching)
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description FontCache()Default constructor -
Method Summary
Modifier and Type Method Description voidaddFont(EmbedFontInfo fontInfo)Adds a font info to cachevoidclear()Clears font cachebooleancontainsFont(java.lang.String embedUrl)is this font in the cache?booleancontainsFont(EmbedFontInfo fontInfo)is this font info in the cache?protected static java.lang.StringgetCacheKey(EmbedFontInfo fontInfo)creates a key given a font info for the font mappingstatic java.io.FilegetDefaultCacheFile(boolean forWriting)Returns the default font cache file.static java.io.FilegetFileFromUrls(java.lang.String[] urls)Tries to identify a File instance from an array of URLs.org.docx4j.fonts.fop.fonts.FontCache.CachedFontFilegetFontFile(java.lang.String embedUrl)Returns a font from the cache.EmbedFontInfo[]getFontInfos(java.lang.String embedUrl, long lastModified)Returns the EmbedFontInfo instances belonging to a font file.static longgetLastModified(java.net.URL url)Retrieve the last modified date/time of a URL.booleanhasChanged()cache has been updated since it was readbooleanisFailedFont(java.lang.String embedUrl, long lastModified)has this font previously failed to load?static FontCacheload()Reads the default font cache file and returns its contents.static FontCacheloadFrom(java.io.File cacheFile)Reads a font cache file and returns its contents.voidregisterFailedFont(java.lang.String embedUrl, long lastModified)Registers a failed font with the cachevoidremoveFont(java.lang.String embedUrl)removes font from cachevoidsave()Writes the font cache to disk.voidsaveTo(java.io.File cacheFile)Writes the font cache to disk.
-
Constructor Details
-
FontCache
public FontCache()Default constructor
-
-
Method Details
-
getDefaultCacheFile
public static java.io.File getDefaultCacheFile(boolean forWriting)Returns the default font cache file.- Parameters:
forWriting- true if the user directory should be created- Returns:
- the default font cache file
-
load
Reads the default font cache file and returns its contents.- Returns:
- the font cache deserialized from the file (or null if no cache file exists or if it could not be read)
-
loadFrom
Reads a font cache file and returns its contents.- Parameters:
cacheFile- the cache file- Returns:
- the font cache deserialized from the file (or null if no cache file exists or if it could not be read)
-
save
Writes the font cache to disk.- Throws:
FOPException- fop exception
-
saveTo
Writes the font cache to disk.- Parameters:
cacheFile- the file to write to- Throws:
FOPException- fop exception
-
getCacheKey
creates a key given a font info for the font mapping- Parameters:
fontInfo- font info- Returns:
- font cache key
-
hasChanged
public boolean hasChanged()cache has been updated since it was read- Returns:
- if this cache has changed
-
containsFont
public boolean containsFont(java.lang.String embedUrl)is this font in the cache?- Parameters:
embedUrl- font info- Returns:
- boolean
-
containsFont
is this font info in the cache?- Parameters:
fontInfo- font info- Returns:
- font
-
getFileFromUrls
public static java.io.File getFileFromUrls(java.lang.String[] urls)Tries to identify a File instance from an array of URLs. If there's no file URL in the array, the method returns null.- Parameters:
urls- array of possible font urls- Returns:
- file font file
-
addFont
Adds a font info to cache- Parameters:
fontInfo- font info
-
getFontFile
public org.docx4j.fonts.fop.fonts.FontCache.CachedFontFile getFontFile(java.lang.String embedUrl)Returns a font from the cache.- Parameters:
embedUrl- font info- Returns:
- CachedFontFile object
-
getFontInfos
Returns the EmbedFontInfo instances belonging to a font file. If the font file was modified since it was cached the entry is removed and null is returned.- Parameters:
embedUrl- the font URLlastModified- the last modified date/time of the font file- Returns:
- the EmbedFontInfo instances or null if there's no cached entry or if it is outdated
-
removeFont
public void removeFont(java.lang.String embedUrl)removes font from cache- Parameters:
embedUrl- embed url
-
isFailedFont
public boolean isFailedFont(java.lang.String embedUrl, long lastModified)has this font previously failed to load?- Parameters:
embedUrl- embed urllastModified- last modified- Returns:
- whether this is a failed font
-
registerFailedFont
public void registerFailedFont(java.lang.String embedUrl, long lastModified)Registers a failed font with the cache- Parameters:
embedUrl- embed urllastModified- time last modified
-
clear
public void clear()Clears font cache -
getLastModified
public static long getLastModified(java.net.URL url)Retrieve the last modified date/time of a URL.- Parameters:
url- the URL- Returns:
- the last modified date/time
-