Class PhysicalFonts

java.lang.Object
org.docx4j.fonts.PhysicalFonts

public class PhysicalFonts extends Object
The fonts which are physically installed on the system. They can be discovered automatically, or you can just add specific fonts. Since 11.5.8 you can discover fonts in jars on your classpath using method discoverJarFonts Do NOT add fonts embedded in a docx to physicalFontMap!
Author:
jharrop
  • Field Details

    • log

      protected static org.slf4j.Logger log
    • fontCache

      protected static FontCache fontCache
  • Constructor Details

    • PhysicalFonts

      public PhysicalFonts()
  • Method Details

    • getPhysicalFonts

      @Deprecated public static Map<String,PhysicalFont> getPhysicalFonts()
      Deprecated.
    • get

      public static PhysicalFont get(String key)
      Get a PhysicalFont by case-insensitive name. (Although Word always uses Title Case for font names, it is actually case insensitive; the spec is silent on this.)
      Parameters:
      key -
      Returns:
    • put

      public static void put(String key, PhysicalFont pf)
      Put a PhysicalFont by case-insensitive name. (Although Word always uses Title Case for font names, it is actually case insensitive; the spec is silent on this.)
      Parameters:
      key -
      pf -
    • getRegex

      public static String getRegex()
    • setRegex

      public static void setRegex(String regex)
      Set a regex to limit to the common fonts in order to lower memory use. eg on Mac regex=".*(Courier New|Arial|Times New Roman|Comic Sans|Georgia|Impact|Lucida Console|Lucida Sans Unicode|Palatino Linotype|Tahoma|Trebuchet|Verdana|Symbol|Webdings|Wingdings|MS Sans Serif|MS Serif).*"; on Windows: regex=".*(calibri|cour|arial|times|comic|georgia|impact|LSANS|pala|tahoma|trebuc|verdana|symbol|webdings|wingding).*"; If you want to use this, set it before instantiating a Mapper.
      Since:
      2.8.1
    • discoverPhysicalFonts

      public static final void discoverPhysicalFonts() throws Exception
      Autodetect fonts available on the system.
      Throws:
      Exception
    • addPhysicalFont

      public static void addPhysicalFont(URI fontUrl)
      Add a physical font's EmbedFontInfo object. Not to be used for embedded fonts.
      Parameters:
      fontUrl - eg new java.net.URL("file:" + path)
    • addPhysicalFonts

      public static void addPhysicalFonts(String nameAsInFontTablePart, URI fontUrl)
      Add a physical font's EmbedFontInfo object. Not to be used for embedded fonts.
      Parameters:
      fontUrl - eg new java.net.URL("file:" + path)
    • putPhysicalFonts

      public static void putPhysicalFonts(String nameAsInFontTablePart, List<PhysicalFont> physicalFonts)
      Parameters:
      nameAsInFontTablePart -
      physicalFonts -
      Since:
      11.5.8
    • getPhysicalFont

      public static List<PhysicalFont> getPhysicalFont(String nameAsInFontTablePart, URI fontUrl)
      Get a physical font's EmbedFontInfo object.
      Parameters:
      fontUrl - eg new java.net.URL("file:" + path)
    • getPhysicalFont

      public static List<PhysicalFont> getPhysicalFont(String nameAsInFontTablePart, URI fontUrl, InternalResourceResolver fontResolver)
      Get a physical font's EmbedFontInfo object.
      Parameters:
      fontUrl - eg new java.net.URL("file:" + path)
      Since:
      11.5.8
    • getBoldForm

      public static PhysicalFont getBoldForm(PhysicalFont pf)
    • getBoldItalicForm

      public static PhysicalFont getBoldItalicForm(PhysicalFont pf)
    • getItalicForm

      public static PhysicalFont getItalicForm(PhysicalFont pf)
    • getPhysicalFont

      public static String getPhysicalFont(OpcPackage wmlPackage, String fontName)
    • getWDingsFont

      public static PhysicalFont getWDingsFont()
      For XSL FO output of Webdings and the Wingdings fonts, substitute a font known to contain the appropriate glyphs (if font is present).
      Returns:
    • getWDingsFont2

      public static PhysicalFont getWDingsFont2()
      For XSL FO output of Webdings and the Wingdings fonts, most are in Noto Sans Symbols 2 Regular, but some ranges are not. This returns the font containing the remainder.
      Returns:
    • getSymbolFont

      public static PhysicalFont getSymbolFont()
      For XSL FO output of Symbol font, substitute a font known to contain the appropriate glyphs (if font is present).
      Returns:
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception
    • discoverJarFonts

      public static final int discoverJarFonts() throws URISyntaxException, IOException, FOPException
      Detect fonts available in jars on classpath. You need to invoke this specifically if you want to do this.
      Throws:
      FOPException
      URISyntaxException
      IOException
      Since:
      11.5.8
    • discoverJarFonts

      public static final int discoverJarFonts(String pathPrefix) throws URISyntaxException, FOPException
      Detect fonts available in jars on classpath. You need to invoke this specifically if you want to do this.
      Throws:
      FOPException
      URISyntaxException
      Since:
      11.5.8