Class FontUtils


  • public class FontUtils
    extends java.lang.Object
    This is a global class to keep a record of Font so that we can improve the performance and memory usage in various scenarios like StyledLabel.

    In this class, we have a global map of font and derived font. It probably could be huge after running a long time. In that case, you need explicitly clear the font cache in this class by using clearDerivedFontCache() .

    • Constructor Summary

      Constructors 
      Constructor Description
      FontUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clearDerivedFontCache()
      Clear cache whenever needed.
      static java.awt.Font getCachedDerivedFont​(java.awt.Font font, int style, int size)
      Get derived font by font, style and size.
      static int getDerivedFontCacheSize()
      Gets the derived font cache size.
      • Methods inherited from class java.lang.Object

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

      • FontUtils

        public FontUtils()
    • Method Detail

      • getDerivedFontCacheSize

        public static int getDerivedFontCacheSize()
        Gets the derived font cache size.
        Returns:
        the derived font cache size.
      • clearDerivedFontCache

        public static void clearDerivedFontCache()
        Clear cache whenever needed.
      • getCachedDerivedFont

        public static java.awt.Font getCachedDerivedFont​(java.awt.Font font,
                                                         int style,
                                                         int size)
        Get derived font by font, style and size. At first it will get the derived font from cache. If it cannot hit the derived font, it will invoke font.deriveFont to derive a font.
        Parameters:
        font - the original font
        style - the font style
        size - the font size
        Returns:
        the derived font.