Class Java2DFontResolver

java.lang.Object
com.openhtmltopdf.java2d.Java2DFontResolver
All Implemented Interfaces:
FontResolver

public class Java2DFontResolver extends Object implements FontResolver
REsolves an AWT font instance from a list of CSS font families and characteristics.
Author:
Joshua Marinacci
  • Constructor Details

    • Java2DFontResolver

      public Java2DFontResolver(SharedContext sharedCtx, boolean useEnvironmentFonts)
  • Method Details

    • flushCache

      @Deprecated public void flushCache()
      Deprecated.
    • importFontFaces

      public void importFontFaces(List<FontFaceRule> fontFaces)
    • addInputStreamFont

      public void addInputStreamFont(FSSupplier<InputStream> fontSupplier, String fontFamilyNameOverride, Integer fontWeightOverride, IdentValue fontStyleOverride)
    • addFontFile

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

      public FSFont resolveFont(SharedContext ctx, 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(String name, Font font)
      Sets the fontMapping attribute of the FontResolver object
      Parameters:
      name - The new fontMapping value
      font - The new fontMapping value
    • createFont

      protected static Font createFont(SharedContext ctx, 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 String getFontInstanceHashName(SharedContext ctx, 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.
    • resolveFont

      public FSFont resolveFont(SharedContext renderingContext, FontSpecification spec)
      Specified by:
      resolveFont in interface FontResolver