Class FontCache


  • public class FontCache
    extends Object
    Lookup and caches font definitions for faster retrieval
    Author:
    Andrea Aime - TOPP
    • Constructor Summary

      Constructors 
      Constructor Description
      FontCache()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      List<String> getAlternatives​(String name)
      Given a font name, returns alternatives for other scripts, based on the assumption they start with the same base name, e.g., "Noto Sans" also has a number of alternative fonts dedicated to specific scripts, like "Noti Sans Urdu", "Noto Sans Arabic", "Noto Sans Javanese" and so on.
      Set<String> getAvailableFonts()
      Returns the set of font families and font faces available in the system and those manually loaded into the cache
      static FontCache getDefaultInstance()
      Returns the default, system wide font cache
      Font getFont​(String requestedFont)  
      static Font loadFromUrl​(String fontUrl)
      Tries to load the specified font name as a URL.
      void registerFont​(Font f)
      Adds the specified font in the font cache.
      void resetCache()
      Resets the font loading cache.
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FontCache

        public FontCache()
    • Method Detail

      • getDefaultInstance

        public static FontCache getDefaultInstance()
        Returns the default, system wide font cache
        Since:
        2.6
      • getFont

        public Font getFont​(String requestedFont)
      • loadFromUrl

        public static Font loadFromUrl​(String fontUrl)
        Tries to load the specified font name as a URL. Does not cache the result.
      • registerFont

        public void registerFont​(Font f)
        Adds the specified font in the font cache. Useful if you want to load fonts that are not installed in the Operating System and cannot provide a full path to fonts either.
      • resetCache

        public void resetCache()
        Resets the font loading cache. If any font was manually registered, it will have to be registered again
      • getAvailableFonts

        public Set<String> getAvailableFonts()
        Returns the set of font families and font faces available in the system and those manually loaded into the cache
      • getAlternatives

        public List<String> getAlternatives​(String name)
        Given a font name, returns alternatives for other scripts, based on the assumption they start with the same base name, e.g., "Noto Sans" also has a number of alternative fonts dedicated to specific scripts, like "Noti Sans Urdu", "Noto Sans Arabic", "Noto Sans Javanese" and so on. The code will not return style alterations like "Noto Sans Bold" or "Noto Sans Bold Italic" thought (strips all font names containing "bold" and "italic", case insesitive).
        Returns:
        A list of font names with the same base name