Class Java2DFontResolver

  • All Implemented Interfaces:
    FontResolver

    public class Java2DFontResolver
    extends java.lang.Object
    implements FontResolver
    REsolves an AWT font instance from a list of CSS font families and characteristics.
    • Field Detail

      • instanceHash

        private final java.util.HashMap<java.lang.String,​java.awt.Font> instanceHash
        Map of concrete instances of fonts including size, weight, etc.
      • availableFontsHash

        private final java.util.HashMap<java.lang.String,​java.awt.Font> availableFontsHash
        Map of base fonts, from which we can derive a concrete instance at the correct size, weight, etc. Note: The value is initially null until we need the given base font.
    • Constructor Detail

      • Java2DFontResolver

        public Java2DFontResolver​(SharedContext sharedCtx,
                                  boolean useEnvironmentFonts)
    • Method Detail

      • init

        private void init()
      • flushCache

        @Deprecated
        public void flushCache()
        Deprecated.
      • importFontFaces

        public void importFontFaces​(java.util.List<FontFaceRule> fontFaces)
      • addInputStreamFont

        public void addInputStreamFont​(FSSupplier<java.io.InputStream> fontSupplier,
                                       java.lang.String fontFamilyNameOverride,
                                       java.lang.Integer fontWeightOverride,
                                       IdentValue fontStyleOverride)
      • addFontFaceFont

        private void addFontFaceFont​(java.lang.String fontFamilyNameOverride,
                                     IdentValue fontWeightOverride,
                                     IdentValue fontStyleOverride,
                                     java.lang.String uri)
      • addFontFile

        public void addFontFile​(java.io.File fontFile,
                                java.lang.String fontFamilyNameOverride,
                                java.lang.Integer fontWeightOverride,
                                IdentValue fontStyleOverride)
        Add a font using a existing file. Does not handle true type collections.
      • normalizeFontFamily

        private java.lang.String normalizeFontFamily​(java.lang.String fontFamily)
      • resolveFontFaceBaseFont

        private java.awt.Font resolveFontFaceBaseFont​(java.lang.String normalizedFontFamily,
                                                      float size,
                                                      IdentValue weight,
                                                      IdentValue style)
      • resolveFont

        public FSFont resolveFont​(SharedContext ctx,
                                  java.lang.String[] families,
                                  float size,
                                  IdentValue weight,
                                  IdentValue style,
                                  IdentValue variant)
        Resolves a list of font families. Search order for each family is: 1. Concrete fonts with correct size that have already been used. 2. Font face fonts. 3. System fonts.
      • setFontMapping

        public void setFontMapping​(java.lang.String name,
                                   java.awt.Font font)
        Sets the fontMapping attribute of the FontResolver object
        Parameters:
        name - The new fontMapping value
        font - The new fontMapping value
      • createFont

        protected static java.awt.Font createFont​(SharedContext ctx,
                                                  java.awt.Font rootFont,
                                                  float size,
                                                  IdentValue weight,
                                                  IdentValue style,
                                                  IdentValue variant)
        Creates a concrete instance of a font at specified size, weight, style and variant.
      • getFontInstanceHashName

        protected static java.lang.String getFontInstanceHashName​(SharedContext ctx,
                                                                  java.lang.String name,
                                                                  float size,
                                                                  IdentValue weight,
                                                                  IdentValue style,
                                                                  IdentValue variant)
        Gets the hash key for a concrete instance of a font. This incorporates size, weight, etc.