Class FontLoader


  • public final class FontLoader
    extends java.lang.Object
    Looks at the input and creates Font objects from it.
    • Constructor Detail

      • FontLoader

        public FontLoader()
    • Method Detail

      • getPSNameResolverInstance

        public static PSNameResolver getPSNameResolverInstance()
        Create a new empty PSNameResolver.

        Concurrency

        The instance implementing the PSNameResolver interface that is returned from this method offers some tighter thread safety guarantees than that guaranteed by the PSNameResolver interface. It is safe to use the PSNameResolver object for font resolution from multiple threads at one time as long as the methods which change the state of the PSNameResolver object are not called at any time that it may be being used for font resolution. There is no mechanism within PSNameResolver or FontLoader to guarantee that this doesn't occur. A client program can guarantee this by modifying the PSNameResolver object fully before giving it to one or more threads. A client program could also use some synchronization constructs of its own to guarantee this. This means that the addFont() and setResolutionPriority() methods can not be called while there is any chance that the PSNameResolver object may be being used for font resolution. It is also safe to copy this PSNameResolver object except when it is possible that it may be being modified. It is again the responsibility of the client to ensure that this doesn't happen.
        Returns:
        A new empty PSNameResolver
      • getPSNameResolverInstance

        public static PSNameResolver getPSNameResolverInstance​(FamilyNameNormalizer normalizer)
        Create a new empty PSNameResolver. This method allows a client to specify a FamilyNameNormalizer object that is used to modify the font family name of every Font object added to the PSNameResolver. It is also used to modify the font names inside of any search request.

        Concurrency

        The instance implementing the PSNameResolver interface that is returned from this method offers some tighter thread safety guarantees than that guaranteed by the PSNameResolver interface. It is safe to use the PSNameResolver object for font resolution from multiple threads at one time as long as the methods which change the state of the PSNameResolver object are not called at any time that it may be being used for font resolution. There is no mechanism within PSNameResolver or FontLoader to guarantee that this doesn't occur. A client program can guarantee this by modifying the PSNameResolver object fully before giving it to one or more threads. A client program could also use some synchronization constructs of its own to guarantee this. This means that the addFont() and setResolutionPriority() methods can not be called while there is any chance that the PSNameResolver object may be being used for font resolution. It is also safe to copy this PSNameResolver object except when it is possible that it may be being modified. It is again the responsibility of the client to ensure that this doesn't happen.
        Parameters:
        normalizer - A FamilyNameNormalizer used for adjusting font family names.
        Returns:
        A new empty PSNameResolver
      • getPSNameResolverInstance

        public static PSNameResolver getPSNameResolverInstance​(PSNameResolver original)
        Create a copy of a PSNameResolver.

        Concurrency

        The instance implementing the PSNameResolver interface that is returned from this method offers some tighter thread safety guarantees than that guaranteed by the PSNameResolver interface. It is safe to use the PSNameResolver object for font resolution from multiple threads at one time as long as the methods which change the state of the PSNameResolver object are not called at any time that it may be being used for font resolution. There is no mechanism within PSNameResolver or FontLoader to guarantee that this doesn't occur. A client program can guarantee this by modifying the PSNameResolver object fully before giving it to one or more threads. A client program could also use some synchronization constructs of its own to guarantee this. This means that the addFont() and setResolutionPriority() methods can not be called while there is any chance that the PSNameResolver object may be being used for font resolution. It is also safe to copy this PSNameResolver object except when it is possible that it may be being modified. It is again the responsibility of the client to ensure that this doesn't happen.
        Parameters:
        original - the PSNameResolver to copy
        Returns:
        A new empty PSNameResolver
      • getPlatformFontResolverInstance

        public static PlatformFontResolver getPlatformFontResolverInstance()
        Create a new empty PlatformNameResolver.

        Concurrency

        The instance implementing the PSNameResolver interface that is returned from this method offers some tighter thread safety guarantees than that guaranteed by the PSNameResolver interface. It is safe to use the PSNameResolver object for font resolution from multiple threads at one time as long as the methods which change the state of the PSNameResolver object are not called at any time that it may be being used for font resolution. There is no mechanism within PSNameResolver or FontLoader to guarantee that this doesn't occur. A client program can guarantee this by modifying the PSNameResolver object fully before giving it to one or more threads. A client program could also use some synchronization constructs of its own to guarantee this. This means that the addFont() and setResolutionPriority() methods can not be called while there is any chance that the PSNameResolver object may be being used for font resolution. It is also safe to copy this PSNameResolver object except when it is possible that it may be being modified. It is again the responsibility of the client to ensure that this doesn't happen.
        Returns:
        A new empty PlatformFontResolver
      • getPlatformFontResolverInstance

        public static PlatformFontResolver getPlatformFontResolverInstance​(PlatformFontResolver original)
        Create a copy of a PlatformNameResolver.

        Concurrency

        The instance implementing the PSNameResolver interface that is returned from this method offers some tighter thread safety guarantees than that guaranteed by the PSNameResolver interface. It is safe to use the PSNameResolver object for font resolution from multiple threads at one time as long as the methods which change the state of the PSNameResolver object are not called at any time that it may be being used for font resolution. There is no mechanism within PSNameResolver or FontLoader to guarantee that this doesn't occur. A client program can guarantee this by modifying the PSNameResolver object fully before giving it to one or more threads. A client program could also use some synchronization constructs of its own to guarantee this. This means that the addFont() and setResolutionPriority() methods can not be called while there is any chance that the PSNameResolver object may be being used for font resolution. It is also safe to copy this PSNameResolver object except when it is possible that it may be being modified. It is again the responsibility of the client to ensure that this doesn't happen.
        Parameters:
        original - the PlatformFontResolver to copy
        Returns:
        A new empty PlatformFontResolver
      • getPlatformFontResolverInstance

        public static PlatformFontResolver getPlatformFontResolverInstance​(FamilyNameNormalizer normalizer)
        Create a new empty PlatformNameResolver.

        Concurrency

        The instance implementing the PSNameResolver interface that is returned from this method offers some tighter thread safety guarantees than that guaranteed by the PSNameResolver interface. It is safe to use the PSNameResolver object for font resolution from multiple threads at one time as long as the methods which change the state of the PSNameResolver object are not called at any time that it may be being used for font resolution. There is no mechanism within PSNameResolver or FontLoader to guarantee that this doesn't occur. A client program can guarantee this by modifying the PSNameResolver object fully before giving it to one or more threads. A client program could also use some synchronization constructs of its own to guarantee this. This means that the addFont() and setResolutionPriority() methods can not be called while there is any chance that the PSNameResolver object may be being used for font resolution. It is also safe to copy this PSNameResolver object except when it is possible that it may be being modified. It is again the responsibility of the client to ensure that this doesn't happen.
        Parameters:
        normalizer - A FamilyNameNormalizer used for adjusting platform font family names.
        Returns:
        A new empty PlatformFontResolver
      • getFXGFontResolverInstance

        public static FXGFontResolver getFXGFontResolverInstance()
        Create a new empty FXGNameResolver.

        Concurrency

        The instance implementing the PSNameResolver interface that is returned from this method offers some tighter thread safety guarantees than that guaranteed by the PSNameResolver interface. It is safe to use the PSNameResolver object for font resolution from multiple threads at one time as long as the methods which change the state of the PSNameResolver object are not called at any time that it may be being used for font resolution. There is no mechanism within PSNameResolver or FontLoader to guarantee that this doesn't occur. A client program can guarantee this by modifying the PSNameResolver object fully before giving it to one or more threads. A client program could also use some synchronization constructs of its own to guarantee this. This means that the addFont() and setResolutionPriority() methods can not be called while there is any chance that the PSNameResolver object may be being used for font resolution. It is also safe to copy this PSNameResolver object except when it is possible that it may be being modified. It is again the responsibility of the client to ensure that this doesn't happen.
        Returns:
        A new empty PSNameResolver
      • getFXGFontResolverInstance

        public static FXGFontResolver getFXGFontResolverInstance​(FXGFontResolver original)
        Create a copy of a FXGNameResolver.

        Concurrency

        The instance implementing the PSNameResolver interface that is returned from this method offers some tighter thread safety guarantees than that guaranteed by the PSNameResolver interface. It is safe to use the PSNameResolver object for font resolution from multiple threads at one time as long as the methods which change the state of the PSNameResolver object are not called at any time that it may be being used for font resolution. There is no mechanism within PSNameResolver or FontLoader to guarantee that this doesn't occur. A client program can guarantee this by modifying the PSNameResolver object fully before giving it to one or more threads. A client program could also use some synchronization constructs of its own to guarantee this. This means that the addFont() and setResolutionPriority() methods can not be called while there is any chance that the PSNameResolver object may be being used for font resolution. It is also safe to copy this PSNameResolver object except when it is possible that it may be being modified. It is again the responsibility of the client to ensure that this doesn't happen.
        Parameters:
        original - the PSNameResolver to copy
        Returns:
        A new empty PSNameResolver
      • load

        public Font[] load​(java.net.URL url)
                    throws FontLoadingException,
                           InvalidFontException,
                           UnsupportedFontException
        Creates Font objects from a URL. Note that fonts may be parsed at this point.
        Parameters:
        url - The url of the font data. OpenType, TrueType, and Type1 fonts are the only acceptable input. In order to have predictible behavior, url must be available and must point to the same data for the lifetime of the returned Fonts. If the Font is added to a FontSet that is to be serialized, the urls must remain unchanged for as long as the serialized data is to be used.
        Returns:
        An array of Fonts representing the font data. An empty array if the font data does not represent a font that can be handled
        Throws:
        FontLoadingException - thrown if the font data cannot be accessed
        InvalidFontException - thrown if the font data appears to represent a font, but there is something about the data that cannot be understood and cannot be ignored
        UnsupportedFontException - thrown if the font contains data that indicates that AFE cannot support that category of fonts.
      • load

        public Font[] load​(java.net.URL[] url,
                           java.util.List exceptions)
        Creates Font objects from an array of URL. Note that fonts are parsed at this point.
        Parameters:
        url - The url of the font data. OpenType, TrueType and Type1 fonts and metric files associated with the type1 fonts are the only acceptable input. In order to have predictible behavior, url must be available and must point to the same data for the lifetime of the returned Fonts. If the Font is added to a FontSet that is to be serialized, the urls must remain unchanged for as long as the serialized data is to be used.
        exceptions - Any exceptions that are encountered during the loading process will added to the provided List. This can be a null if the caller doesn't want to know about the exceptions that occured.
        Returns:
        An array of Fonts representing the font data. An empty array if the font data does not represent a font that can be handled
      • load

        public Font[] load​(java.net.URL[] url,
                           java.util.List exceptions,
                           java.util.List badUrls)
        Creates Font objects from an array of URL. Note that fonts are parsed at this point.
        Parameters:
        url - The url of the font data. OpenType, TrueType and Type1 fonts and metric files associated with the type1 fonts are the only acceptable input. In order to have predictible behavior, url must be available and must point to the same data for the lifetime of the returned Fonts. If the Font is added to a FontSet that is to be serialized, the urls must remain unchanged for as long as the serialized data is to be used.
        exceptions - Any exceptions that are encountered during the loading process will added to the provided List. This can be a null if the caller doesn't want to know about the exceptions that occured.
        badUrls - The URLs causing any exception are recorded here. These are in 1 to 1 alignment with the exceptions returned. This can be a null if the caller doesn't want to know about the bad URLs that occured.
        Returns:
        An array of Fonts representing the font data. An empty array if the font data does not represent a font that can be handled
      • load

        public Font load​(java.io.InputStream inputStream,
                         int length,
                         boolean wasEmbedded)
                  throws FontLoadingException
        Creates a Font object from an InputStream and data describing the font. The returned Font cannot be serialized. Thus, it must not be added to a CSS or PS fontset that is intended to be serialized.
        Parameters:
        inputStream - The input stream containing the font data. This stream will be read from to create the Font. After returning from this method the stream will not be accessed again and it is the responsibilty of the caller to close this stream.
        length - The number of bytes in the InputStream.
        wasEmbedded - true iff this font is embedded in a document. This affects the way this font can be used. See Technote 5147 "Font Embedding Guidelines for Adobe Third-party Developers" for more information.
        Returns:
        A Font representing the font.
        Throws:
        FontLoadingException
      • load

        public Font[] load​(java.io.File f,
                           boolean recurseDirectories,
                           java.util.List exceptions)
        Creates Font objects for all fonts in a file or directory represented by f. Fonts are parsed at this point. AFE does not track changes in the file system dynamically. If fonts are added or deleted, the directory must be reloaded to see those changes. Note that this function does NOT resolve windows shortcuts.
        Parameters:
        f - The root directory or file to be read in. Only host font formats (OpenType, TrueType, or Type1) will be processed by this api. In order to have predictible behavior, the files pointed to by f must be available and must point to the same data for the lifetime of the returned Font.If these fonts become part of serialized font sets, f (and its subdirectories, if they are recursively searched) must be accessible from all servers sharing the serialized data. Likewise, the contents of f must not change for as long as the serialized data is to be used.
        recurseDirectories - if f is a directory, recurseDirectories specifies whether load should recursively walk all subdirectories. If true, the recursion happens. It does not if recurseDirectories is false. This parameter is ignored if f is not a directory.
        exceptions - Any exceptions that are encountered during the loading process will added to the provided List. This can be a null if the caller doesn't want to know about the exceptions that occured.
        Returns:
        An array of Fonts representing the fonts found. An empty array if no fonts are found.
      • load

        public Font[] load​(java.io.File f,
                           boolean recurseDirectories,
                           java.util.List exceptions,
                           java.util.List badUrls)
        Creates Font objects for all fonts in a file or directory represented by f. Fonts are parsed at this point. AFE does not track changes in the file system dynamically. If fonts are added or deleted, the directory must be reloaded to see those changes. Note that this function does NOT resolve windows shortcuts.
        Parameters:
        f - The root directory or file to be read in. Only host font formats (OpenType, TrueType, or Type1) will be processed by this api. In order to have predictible behavior, the files pointed to by f must be available and must point to the same data for the lifetime of the returned Font.If these fonts become part of serialized font sets, f (and its subdirectories, if they are recursively searched) must be accessible from all servers sharing the serialized data. Likewise, the contents of f must not change for as long as the serialized data is to be used.
        recurseDirectories - if f is a directory, recurseDirectories specifies whether load should recursively walk all subdirectories. If true, the recursion happens. It does not if recurseDirectories is false. This parameter is ignored if f is not a directory.
        exceptions - Any exceptions that are encountered during the loading process will added to the provided List. This can be a null if the caller doesn't want to know about the exceptions that occured.
        badUrls - If any exceptions are encountered during the loading process then the URL which casued the exception is recorded in this List. It is in 1 to 1 correlation with the exceptions returned in the exceptions List. This can be a null if the caller doesn't want to know about the bad URLs that occured.
        Returns:
        An array of Fonts representing the fonts found. An empty array if no fonts are found.
      • load

        public Font[] load​(java.io.File f,
                           boolean recurseDirectories,
                           java.util.List exceptions,
                           java.util.List badUrls,
                           java.io.File cacheFile)
        The new font cache support code starts here, although some supporting changes have also been made in code above here. The first is the specialized "load" API for use with the font cache. It is similar to the other load APIs except that it takes an additional argument to pass in the serialized cache file against which this load operation is to take place. It is synchronized so that two load operations can not occur in parallel against the same FontLoader object.
      • saveAllCaches

        public void saveAllCaches​(boolean clean)
                           throws java.io.IOException
        The cache files MUST be explictly save by the client. They are never saved automatically. It might be possible to use "finalize" for this in some environments but on servers where nothing ever terminates until the server crashes this won't work. It could also be hooked up to some daemon, but that is the client's job, not AFEs. The "clean" boolean throws away entries that were never loaded against before saving. This gets rid of "stale" entries for fonts that may have been deleted since the previous cycle of operation.
        Throws:
        java.io.IOException
      • saveCache

        public boolean saveCache​(java.io.File cacheFile,
                                 boolean clean)
                          throws java.io.IOException
        The inner loop, publically available, that saves just one cache file
        Throws:
        java.io.IOException
      • decommissionCachedFont

        public boolean decommissionCachedFont​(java.io.File fontFile)
                                       throws java.io.IOException
        This removes a single font file from all caches. This is the API clients would use if they have some list of specific fonts that they want to delete or replace.
        Throws:
        java.io.IOException
      • decommissionAllCaches

        public void decommissionAllCaches()
        This provides clients a way to remove caches from service. It is orthogonal to saving but if you also save you need to do the saving first. It simply clears all the caches and then reloads the builtin fonts to get a clean, initialized state.
      • decommissionCache

        public boolean decommissionCache​(java.io.File cacheFile)
        This allows a single cache to be separately decomissioned. It throws away the local cache referred to and removes all corresponding entries in the global cache. It may be quite slow in order to maintain consistency in other local caches. Use decommissionAllCaches() when possible.