Class FontSet
- java.lang.Object
-
- com.itextpdf.layout.font.FontSet
-
public final class FontSet extends java.lang.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:
FontProvider
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<FontInfo,FontProgram>
fontPrograms
private java.util.Set<FontInfo>
fonts
private long
id
private static java.util.concurrent.atomic.AtomicLong
lastId
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addDirectory(java.lang.String dir)
Add all the fonts in a directory.int
addDirectory(java.lang.String dir, boolean scanSubdirectories)
Add all the fonts in a directory and possibly its subdirectories.boolean
addFont(byte[] fontData)
boolean
addFont(byte[] fontData, java.lang.String encoding)
boolean
addFont(byte[] fontData, java.lang.String encoding, java.lang.String alias)
boolean
addFont(byte[] fontData, java.lang.String encoding, java.lang.String alias, Range unicodeRange)
boolean
addFont(FontProgram fontProgram, java.lang.String encoding)
Add not supported for auto creating FontPrograms.boolean
addFont(FontProgram fontProgram, java.lang.String encoding, java.lang.String alias)
Add not supported for auto creating FontPrograms.boolean
addFont(FontProgram fontProgram, java.lang.String encoding, java.lang.String alias, Range unicodeRange)
Add not supported for auto creating FontPrograms.boolean
addFont(FontInfo fontInfo)
AddsFontInfo
.boolean
addFont(FontInfo fontInfo, java.lang.String alias)
AddsFontInfo
with alias.boolean
addFont(FontInfo fontInfo, java.lang.String alias, Range unicodeRange)
AddsFontInfo
with alias.boolean
addFont(java.lang.String fontPath)
boolean
addFont(java.lang.String fontPath, java.lang.String encoding)
boolean
addFont(java.lang.String fontPath, java.lang.String encoding, java.lang.String alias)
boolean
addFont(java.lang.String fontPath, java.lang.String encoding, java.lang.String alias, Range unicodeRange)
boolean
contains(java.lang.String fontName)
Search in existed fonts for PostScript name or full font name.java.util.Collection<FontInfo>
get(java.lang.String fontName)
Search in existed fonts for PostScript name or full font name.(package private) FontProgram
getFontProgram(FontInfo fontInfo)
java.util.Collection<FontInfo>
getFonts()
Gets available fonts.java.util.Collection<FontInfo>
getFonts(FontSet additionalFonts)
Gets union of available and temporary fonts.(package private) long
getId()
boolean
isEmpty()
Returnstrue
if this set contains no elements.int
size()
Returns the number of elements in this set.
-
-
-
Field Detail
-
lastId
private static final java.util.concurrent.atomic.AtomicLong lastId
-
fonts
private final java.util.Set<FontInfo> fonts
-
fontPrograms
private final java.util.Map<FontInfo,FontProgram> fontPrograms
-
id
private final long id
-
-
Constructor Detail
-
FontSet
public FontSet()
Creates a new instance ofFontSet
.
-
-
Method Detail
-
addDirectory
public int addDirectory(java.lang.String dir, boolean scanSubdirectories)
Add all the fonts in a directory and possibly its subdirectories.- Parameters:
dir
- path to directory.scanSubdirectories
- recursively scan subdirectories iftrue
.- Returns:
- number of added fonts.
-
addDirectory
public int addDirectory(java.lang.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, java.lang.String encoding, java.lang.String alias, Range unicodeRange)
Add not supported for auto creating FontPrograms.Note,
FontInfo.getAlias()
do not taken into account inFontInfo.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 creatingPdfFont
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, java.lang.String encoding, java.lang.String alias)
Add not supported for auto creating FontPrograms.Note,
FontInfo.getAlias()
do not taken into account inFontInfo.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 creatingPdfFont
alias
- font alias.- Returns:
- true, if font was successfully added, otherwise false.
-
addFont
public boolean addFont(FontProgram fontProgram, java.lang.String encoding)
Add not supported for auto creating FontPrograms.- Parameters:
fontProgram
-FontProgram
encoding
- FontEncoding for creatingPdfFont
.- Returns:
- true, if font was successfully added, otherwise false.
-
addFont
public boolean addFont(java.lang.String fontPath, java.lang.String encoding, java.lang.String alias, Range unicodeRange)
CreatesFontInfo
, fetchesFontProgramDescriptor
and adds just createdFontInfo
toFontSet
.Note,
FontInfo.getAlias()
do not taken into account inFontInfo.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:
PdfEncodings
-
addFont
public boolean addFont(java.lang.String fontPath, java.lang.String encoding, java.lang.String alias)
CreatesFontInfo
, fetchesFontProgramDescriptor
and adds just createdFontInfo
toFontSet
.Note,
FontInfo.getAlias()
do not taken into account inFontInfo.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:
PdfEncodings
-
addFont
public boolean addFont(java.lang.String fontPath, java.lang.String encoding)
- Parameters:
fontPath
- path to font data.encoding
- preferred font encoding.- Returns:
- true, if font was successfully added, otherwise false.
- See Also:
PdfEncodings
-
addFont
public boolean addFont(byte[] fontData, java.lang.String encoding, java.lang.String alias, Range unicodeRange)
CreatesFontInfo
, fetchesFontProgramDescriptor
and adds just createdFontInfo
toFontSet
.Note,
FontInfo.getAlias()
do not taken into account inFontInfo.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:
PdfEncodings
-
addFont
public boolean addFont(byte[] fontData, java.lang.String encoding, java.lang.String alias)
CreatesFontInfo
, fetchesFontProgramDescriptor
and adds just createdFontInfo
toFontSet
.Note,
FontInfo.getAlias()
do not taken into account inFontInfo.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:
PdfEncodings
-
addFont
public boolean addFont(byte[] fontData, java.lang.String encoding)
- Parameters:
fontData
- font data.encoding
- preferred font encoding.- Returns:
- true, if font was successfully added, otherwise false.
- See Also:
PdfEncodings
-
addFont
public boolean addFont(java.lang.String fontPath)
CreatesFontInfo
, fetchesFontProgramDescriptor
and adds just createdFontInfo
toFontSet
.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)
CreatesFontInfo
, fetchesFontProgramDescriptor
and adds just createdFontInfo
toFontSet
.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, java.lang.String alias, Range unicodeRange)
AddsFontInfo
with alias. Could be used to fill temporary font set.Note,
FontInfo.getAlias()
do not taken into account inFontInfo.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, java.lang.String alias)
AddsFontInfo
with alias. Could be used to fill temporary font set.Note,
FontInfo.getAlias()
do not taken into account inFontInfo.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)
AddsFontInfo
. Could be used to fill temporary font set.Note,
FontInfo.getAlias()
do not taken into account inFontInfo.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(java.lang.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 java.util.Collection<FontInfo> get(java.lang.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 java.util.Collection<FontInfo> getFonts()
Gets available fonts.Note, the collection is unmodifiable.
- Returns:
- set of all available fonts
-
getFonts
public java.util.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()
Returnstrue
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
-
getId
long getId()
-
getFontProgram
FontProgram getFontProgram(FontInfo fontInfo)
-
-