Class FontSet

java.lang.Object
com.itextpdf.layout.font.FontSet

public final class FontSet extends Object
Reusable font set for FontProgram related data. Add and search fonts.

A FontSet instance could be shared for multiple threads. However FontSet filling is not thread safe operation.

See Also:
  • Constructor Details

    • FontSet

      public FontSet()
      Creates a new instance of FontSet.
  • Method Details

    • addDirectory

      public int addDirectory (String dir, boolean scanSubdirectories)
      Add all the fonts in a directory and possibly its subdirectories.
      Parameters:
      dir - path to directory.
      scanSubdirectories - recursively scan subdirectories if true.
      Returns:
      number of added fonts.
    • addDirectory

      public int addDirectory (String dir)
      Add all the fonts in a directory.
      Parameters:
      dir - path to directory.
      Returns:
      number of added fonts.
    • addFont

      public boolean addFont (FontProgram fontProgram, String encoding, String alias, Range unicodeRange)
      Add not supported for auto creating FontPrograms.

      Note, FontInfo.getAlias() do not taken into account in FontInfo.equals(java.lang.Object). The same font with different alias will not be replaced. Alias will replace original font family in font selector algorithm.

      Parameters:
      fontProgram - FontProgram
      encoding - FontEncoding for creating PdfFont
      alias - font alias.
      unicodeRange - sets the specific range of characters to be used from the font
      Returns:
      true, if font was successfully added, otherwise false.
    • addFont

      public boolean addFont (FontProgram fontProgram, String encoding, String alias)
      Add not supported for auto creating FontPrograms.

      Note, FontInfo.getAlias() do not taken into account in FontInfo.equals(java.lang.Object). The same font with different alias will not be replaced. Alias will replace original font family in font selector algorithm.

      Parameters:
      fontProgram - FontProgram
      encoding - FontEncoding for creating PdfFont
      alias - font alias.
      Returns:
      true, if font was successfully added, otherwise false.
    • addFont

      public boolean addFont (FontProgram fontProgram, String encoding)
      Add not supported for auto creating FontPrograms.
      Parameters:
      fontProgram - FontProgram
      encoding - FontEncoding for creating PdfFont.
      Returns:
      true, if font was successfully added, otherwise false.
    • addFont

      public boolean addFont (String fontPath, String encoding, String alias, Range unicodeRange)
      Creates FontInfo, fetches FontProgramDescriptor and adds just created FontInfo to FontSet.

      Note, FontInfo.getAlias() do not taken into account in FontInfo.equals(java.lang.Object). The same font with different alias will not be replaced. Alias will replace original font family in font selector algorithm.

      Parameters:
      fontPath - path to font data.
      encoding - preferred font encoding.
      alias - font alias, will replace original font family.
      unicodeRange - sets the specific range of characters to be used from the font
      Returns:
      true, if font was successfully added, otherwise false.
      See Also:
    • addFont

      public boolean addFont (String fontPath, String encoding, String alias)
      Creates FontInfo, fetches FontProgramDescriptor and adds just created FontInfo to FontSet.

      Note, FontInfo.getAlias() do not taken into account in FontInfo.equals(java.lang.Object). The same font with different alias will not be replaced. Alias will replace original font family in font selector algorithm.

      Parameters:
      fontPath - path to font data.
      encoding - preferred font encoding.
      alias - font alias.
      Returns:
      true, if font was successfully added, otherwise false.
      See Also:
    • addFont

      public boolean addFont (String fontPath, String encoding)
      Creates FontInfo, fetches FontProgramDescriptor and adds just created FontInfo to FontSet.
      Parameters:
      fontPath - path to font data.
      encoding - preferred font encoding.
      Returns:
      true, if font was successfully added, otherwise false.
      See Also:
    • addFont

      public boolean addFont (byte[] fontData, String encoding, String alias, Range unicodeRange)
      Creates FontInfo, fetches FontProgramDescriptor and adds just created FontInfo to FontSet.

      Note, FontInfo.getAlias() do not taken into account in FontInfo.equals(java.lang.Object). The same font with different alias will not be replaced. Alias will replace original font family in font selector algorithm.

      Parameters:
      fontData - font data.
      encoding - preferred font encoding.
      alias - font alias.
      unicodeRange - sets the specific range of characters to be used from the font
      Returns:
      true, if font was successfully added, otherwise false.
      See Also:
    • addFont

      public boolean addFont (byte[] fontData, String encoding, String alias)
      Creates FontInfo, fetches FontProgramDescriptor and adds just created FontInfo to FontSet.

      Note, FontInfo.getAlias() do not taken into account in FontInfo.equals(java.lang.Object). The same font with different alias will not be replaced. Alias will replace original font family in font selector algorithm.

      Parameters:
      fontData - font data.
      encoding - preferred font encoding.
      alias - font alias.
      Returns:
      true, if font was successfully added, otherwise false.
      See Also:
    • addFont

      public boolean addFont (byte[] fontData, String encoding)
      Creates FontInfo, fetches FontProgramDescriptor and adds just created FontInfo to FontSet.
      Parameters:
      fontData - font data.
      encoding - preferred font encoding.
      Returns:
      true, if font was successfully added, otherwise false.
      See Also:
    • addFont

      public boolean addFont (String fontPath)
      Creates FontInfo, fetches FontProgramDescriptor and adds just created FontInfo to FontSet. FontProvider.getDefaultEncoding(FontProgram) will be used to determine encoding.
      Parameters:
      fontPath - path to font data.
      Returns:
      true, if font was successfully added, otherwise false.
    • addFont

      public boolean addFont (byte[] fontData)
      Creates FontInfo, fetches FontProgramDescriptor and adds just created FontInfo to FontSet. FontProvider.getDefaultEncoding(FontProgram) will be used to determine encoding.
      Parameters:
      fontData - font data.
      Returns:
      true, if font was successfully added, otherwise false.
    • addFont

      public boolean addFont (FontInfo fontInfo, String alias, Range unicodeRange)
      Adds FontInfo with alias. Could be used to fill temporary font set.

      Note, FontInfo.getAlias() do not taken into account in FontInfo.equals(java.lang.Object). The same font with different alias will not be replaced. Alias will replace original font family in font selector algorithm.

      Parameters:
      fontInfo - font info.
      alias - font alias.
      unicodeRange - sets the specific range of characters to be used from the font
      Returns:
      true, if font was successfully added, otherwise false.
    • addFont

      public boolean addFont (FontInfo fontInfo, String alias)
      Adds FontInfo with alias. Could be used to fill temporary font set.

      Note, FontInfo.getAlias() do not taken into account in FontInfo.equals(java.lang.Object). The same font with different alias will not be replaced. Alias will replace original font family in font selector algorithm.

      Parameters:
      fontInfo - font info.
      alias - font alias.
      Returns:
      true, if font was successfully added, otherwise false.
    • addFont

      public final boolean addFont (FontInfo fontInfo)
      Adds FontInfo. Could be used to fill temporary font set.

      Note, FontInfo.getAlias() do not taken into account in FontInfo.equals(java.lang.Object). The same font with different alias will not be replaced.

      Parameters:
      fontInfo - font info.
      Returns:
      true, if font was successfully added, otherwise false.
    • contains

      public boolean contains (String fontName)
      Search in existed fonts for PostScript name or full font name.

      Note, this method has O(n) complexity.

      Parameters:
      fontName - PostScript or full name.
      Returns:
      true, if FontSet contains font with given name.
    • get

      public Collection<FontInfo> get (String fontName)
      Search in existed fonts for PostScript name or full font name.

      Note, this method has O(n) complexity.

      Parameters:
      fontName - PostScript or full name.
      Returns:
      Collection of FontInfo from set of fonts with given PostScript or full name.
    • getFonts

      public Collection<FontInfo> getFonts()
      Gets available fonts.

      Note, the collection is unmodifiable.

      Returns:
      set of all available fonts
    • getFonts

      public Collection<FontInfo> getFonts (FontSet additionalFonts)
      Gets union of available and temporary fonts.

      Note, the collection is unmodifiable.

      Parameters:
      additionalFonts - set of temporary fonts
      Returns:
      set of all available and temporary fonts
    • isEmpty

      public boolean isEmpty()
      Returns true if this set contains no elements.
      Returns:
      true if this set contains no elements
    • size

      public int size()
      Returns the number of elements in this set.
      Returns:
      the number of elements in this set