Class FontCache
java.lang.Object
org.apache.fop.fonts.FontCache
- All Implemented Interfaces:
Serializable
Fop cache (currently only used for font info caching)
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanhas this cache been changed since it was last read?private final boolean[]change lockprivate static final Stringfont cache file pathmapping of font url -> file modified date (for all fonts that have failed to load)private Map<String, FontCache.CachedFontFile> master mapping of font url -> font info.private static final StringFOP's user directory nameprivate static org.apache.commons.logging.Loglogging instanceprivate static final longSerialization Version UID. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFont(EmbedFontInfo fontInfo, InternalResourceResolver resourceResolver) Adds a font info to cachevoidclear()Clears font cachebooleancontainsFont(String embedUrl) is this font in the cache?booleancontainsFont(EmbedFontInfo fontInfo) is this font info in the cache?protected static StringgetCacheKey(EmbedFontInfo fontInfo) creates a key given a font info for the font mappingstatic FilegetDefaultCacheFile(boolean forWriting) Returns the default font cache file.static FilegetFileFromUrls(String[] urls) Tries to identify a File instance from an array of URLs.getFontFile(String embedUrl) Returns a font from the cache.private Map<String, FontCache.CachedFontFile> getFontInfos(String embedUrl, long lastModified) Returns the EmbedFontInfo instances belonging to a font file.static longgetLastModified(URI uri) Retrieve the last modified date/time of a URI.private static Fileprivate static Filebooleancache has been updated since it was readbooleanisFailedFont(String embedUrl, long lastModified) has this font previously failed to load?static FontCacheload()Deprecated.static FontCacheReads a font cache file and returns its contents.private voidvoidregisterFailedFont(String embedUrl, long lastModified) Registers a failed font with the cachevoidremoveFont(String embedUrl) removes font from cachevoidsave()Deprecated.usesaveTo(File)insteadvoidWrites the font cache to disk.private static FiletoDirectory(String path)
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization Version UID. Change this value if you want to make sure the user's cache file is purged after an update.- See Also:
-
log
private static org.apache.commons.logging.Log loglogging instance -
FOP_USER_DIR
-
DEFAULT_CACHE_FILENAME
-
changed
private transient boolean changedhas this cache been changed since it was last read? -
changeLock
private final boolean[] changeLockchange lock -
fontfileMap
master mapping of font url -> font info. This needs to be a list, since a TTC file may contain more than 1 font. -
failedFontMap
-
-
Constructor Details
-
FontCache
public FontCache()
-
-
Method Details
-
readObject
- Throws:
ClassNotFoundExceptionIOException
-
getUserHome
-
getTempDirectory
-
toDirectory
-
getDefaultCacheFile
Returns the default font cache file.- Parameters:
forWriting- true if the user directory should be created- Returns:
- the default font cache file
-
load
Deprecated.useloadFrom(File)insteadReads 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
-
save
Deprecated.usesaveTo(File)insteadWrites 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
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
-
getFontFileMap
-
addFont
Adds a font info to cache- Parameters:
fontInfo- font info
-
getFontFile
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
-
isFailedFont
has this font previously failed to load?- Parameters:
embedUrl- embed urllastModified- last modified- Returns:
- whether this is a failed font
-
registerFailedFont
Registers a failed font with the cache- Parameters:
embedUrl- embed urllastModified- time last modified
-
getFailedFontMap
-
clear
public void clear()Clears font cache -
getLastModified
Retrieve the last modified date/time of a URI.- Parameters:
uri- the URI- Returns:
- the last modified date/time
-
loadFrom(File)instead