Class FontRegisterProvider


  • class FontRegisterProvider
    extends java.lang.Object
    If you are using True Type fonts, you can declare the paths of the different ttf- and ttc-files to this class first and then create fonts in your code using one of the getFont method without having to enter a path as parameter.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.util.List<java.lang.String>> fontFamilies
      This is a map of fontfamilies.
      private java.util.Map<java.lang.String,​java.lang.String> fontNames
      This is a map of postscriptfontnames of fonts and the path of their font file.
      private static org.slf4j.Logger LOGGER  
    • Constructor Summary

      Constructors 
      Constructor Description
      FontRegisterProvider()
      Creates new FontRegisterProvider
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearRegisteredFontFamilies()  
      void clearRegisteredFonts()  
      (package private) FontProgram getFont​(java.lang.String fontName, int style)
      Constructs a Font-object.
      (package private) FontProgram getFont​(java.lang.String fontName, int style, boolean cached)
      Constructs a Font-object.
      protected FontProgram getFontProgram​(java.lang.String fontName, boolean cached)  
      (package private) java.util.Set<java.lang.String> getRegisteredFontFamilies()
      Gets a set of registered font names.
      (package private) java.util.Set<java.lang.String> getRegisteredFonts()
      Gets a set of registered font names.
      (package private) boolean isRegisteredFont​(java.lang.String fontname)
      Checks if a certain font is registered.
      (package private) void registerFont​(java.lang.String path)
      Register a font file, either .ttf or .otf, .afm or a font from TrueType Collection.
      (package private) void registerFont​(java.lang.String path, java.lang.String alias)
      Register a font file and use an alias for the font contained in it.
      (package private) int registerFontDirectory​(java.lang.String dir)
      Register all the fonts in a directory.
      (package private) int registerFontDirectory​(java.lang.String dir, boolean scanSubdirectories)
      Register all the fonts in a directory and possibly its subdirectories.
      (package private) void registerFontFamily​(java.lang.String familyName, java.lang.String fullName, java.lang.String path)
      Register a font by giving explicitly the font family and name.
      protected void registerStandardFontFamilies()  
      protected void registerStandardFonts()  
      (package private) int registerSystemFontDirectories()
      Register fonts in some probable directories.
      (package private) boolean saveCopyOfRegularFont​(java.lang.String regularFontName, java.lang.String path)  
      • Methods inherited from class java.lang.Object

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

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • fontNames

        private final java.util.Map<java.lang.String,​java.lang.String> fontNames
        This is a map of postscriptfontnames of fonts and the path of their font file.
      • fontFamilies

        private final java.util.Map<java.lang.String,​java.util.List<java.lang.String>> fontFamilies
        This is a map of fontfamilies.
    • Constructor Detail

      • FontRegisterProvider

        FontRegisterProvider()
        Creates new FontRegisterProvider
    • Method Detail

      • getFont

        FontProgram getFont​(java.lang.String fontName,
                            int style)
                     throws java.io.IOException
        Constructs a Font-object.
        Parameters:
        fontName - the name of the font
        style - the style of this font
        Returns:
        the Font constructed based on the parameters
        Throws:
        java.io.IOException
      • getFont

        FontProgram getFont​(java.lang.String fontName,
                            int style,
                            boolean cached)
                     throws java.io.IOException
        Constructs a Font-object.
        Parameters:
        fontName - the name of the font
        style - the style of this font
        cached - true if the font comes from the cache or is added to the cache if new, false if the font is always created new
        Returns:
        the Font constructed based on the parameters
        Throws:
        java.io.IOException
      • registerStandardFonts

        protected void registerStandardFonts()
      • registerStandardFontFamilies

        protected void registerStandardFontFamilies()
      • getFontProgram

        protected FontProgram getFontProgram​(java.lang.String fontName,
                                             boolean cached)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • registerFontFamily

        void registerFontFamily​(java.lang.String familyName,
                                java.lang.String fullName,
                                java.lang.String path)
        Register a font by giving explicitly the font family and name.
        Parameters:
        familyName - the font family
        fullName - the font name
        path - the font path
      • registerFont

        void registerFont​(java.lang.String path)
        Register a font file, either .ttf or .otf, .afm or a font from TrueType Collection. If a TrueType Collection is registered, an additional index of the font program can be specified
        Parameters:
        path - the path to a ttf- or ttc-file
      • registerFont

        void registerFont​(java.lang.String path,
                          java.lang.String alias)
        Register a font file and use an alias for the font contained in it.
        Parameters:
        path - the path to a font file
        alias - the alias you want to use for the font
      • saveCopyOfRegularFont

        boolean saveCopyOfRegularFont​(java.lang.String regularFontName,
                                      java.lang.String path)
      • registerFontDirectory

        int registerFontDirectory​(java.lang.String dir)
        Register all the fonts in a directory.
        Parameters:
        dir - the directory
        Returns:
        the number of fonts registered
      • registerFontDirectory

        int registerFontDirectory​(java.lang.String dir,
                                  boolean scanSubdirectories)
        Register all the fonts in a directory and possibly its subdirectories.
        Parameters:
        dir - the directory
        scanSubdirectories - recursively scan subdirectories if true
        Returns:
        the number of fonts registered
      • registerSystemFontDirectories

        int registerSystemFontDirectories()
        Register fonts in some probable directories. It usually works in Windows, Linux and Solaris.
        Returns:
        the number of fonts registered
      • getRegisteredFonts

        java.util.Set<java.lang.String> getRegisteredFonts()
        Gets a set of registered font names.
        Returns:
        a set of registered fonts
      • getRegisteredFontFamilies

        java.util.Set<java.lang.String> getRegisteredFontFamilies()
        Gets a set of registered font names.
        Returns:
        a set of registered font families
      • isRegisteredFont

        boolean isRegisteredFont​(java.lang.String fontname)
        Checks if a certain font is registered.
        Parameters:
        fontname - the name of the font that has to be checked.
        Returns:
        true if the font is found
      • clearRegisteredFonts

        public void clearRegisteredFonts()
      • clearRegisteredFontFamilies

        public void clearRegisteredFontFamilies()