Class PhysicalFonts

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

public class PhysicalFonts
extends java.lang.Object
The fonts which are physically installed on the system. They can be discovered automatically, or you can just add specific fonts. Do NOT add fonts embedded in a docx to physicalFontMap!
Author:
dev
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected static FontCache fontCache  
    protected static org.slf4j.Logger log  
  • Constructor Summary

    Constructors 
    Constructor Description
    PhysicalFonts()  
  • Method Summary

    Modifier and Type Method Description
    static void addPhysicalFont​(java.net.URL fontUrl)
    Add a physical font's EmbedFontInfo object.
    static void addPhysicalFonts​(java.lang.String nameAsInFontTablePart, java.net.URL fontUrl)
    Add a physical font's EmbedFontInfo object.
    static void discoverPhysicalFonts()
    Autodetect fonts available on the system.
    static PhysicalFont get​(java.lang.String key)
    Get a PhysicalFont by case-insensitive name.
    static PhysicalFont getBoldForm​(PhysicalFont pf)  
    static PhysicalFont getBoldItalicForm​(PhysicalFont pf)  
    static PhysicalFont getItalicForm​(PhysicalFont pf)  
    static java.util.List<PhysicalFont> getPhysicalFont​(java.lang.String nameAsInFontTablePart, java.net.URL fontUrl)
    Get a physical font's EmbedFontInfo object.
    static java.lang.String getPhysicalFont​(OpcPackage wmlPackage, java.lang.String fontName)  
    static java.util.Map<java.lang.String,​PhysicalFont> getPhysicalFonts()
    Deprecated.
    static java.lang.String getRegex()  
    static void main​(java.lang.String[] args)  
    static void put​(java.lang.String key, PhysicalFont pf)
    Put a PhysicalFont by case-insensitive name.
    static void setRegex​(java.lang.String regex)
    Set a regex to limit to the common fonts in order to lower memory use.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • getPhysicalFonts

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

      public static PhysicalFont get​(java.lang.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​(java.lang.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 java.lang.String getRegex()
    • setRegex

      public static void setRegex​(java.lang.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 java.lang.Exception
      Autodetect fonts available on the system.
      Throws:
      java.lang.Exception
    • addPhysicalFont

      public static void addPhysicalFont​(java.net.URL 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​(java.lang.String nameAsInFontTablePart, java.net.URL fontUrl)
      Add a physical font's EmbedFontInfo object. Not to be used for embedded fonts.
      Parameters:
      fontUrl - eg new java.net.URL("file:" + path)
    • getPhysicalFont

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

      public static PhysicalFont getBoldForm​(PhysicalFont pf)
    • getBoldItalicForm

      public static PhysicalFont getBoldItalicForm​(PhysicalFont pf)
    • getItalicForm

      public static PhysicalFont getItalicForm​(PhysicalFont pf)
    • getPhysicalFont

      public static java.lang.String getPhysicalFont​(OpcPackage wmlPackage, java.lang.String fontName)
    • main

      public static void main​(java.lang.String[] args) throws java.lang.Exception
      Throws:
      java.lang.Exception