public class FontProvider extends Object
FontSet
and collection of PdfFont
s. FontProvider depends on PdfDocument
due to PdfFont
, so it cannot be reused for different documents unless reset with reset()
or recreated with getFontSet()
. In the former case the FontSelectorCache
is reused and in the latter it's reinitialised. FontProvider the only end point for creating PdfFont
.
It is allowed to use only one FontProvider
per document. If additional fonts per element needed, another instance of FontSet
can be used. For more details see Property.FONT_SET
, getPdfFont(FontInfo, FontSet)
, getStrategy(String, List, FontCharacteristics, FontSet)
.
Note, FontProvider does not close created FontProgram
s, because of possible conflicts with FontCache
.
Modifier and Type | Field and Description |
---|---|
protected String |
defaultFontFamily
The default font-family is used by FontSelector if it's impossible to select a font for all other set font-families
|
protected Map<FontInfo,PdfFont> |
pdfFonts |
Constructor and Description |
---|
FontProvider()
Creates a new instance of FontProvider.
|
FontProvider(FontSet fontSet)
Creates a new instance of FontProvider.
|
FontProvider(FontSet fontSet, String defaultFontFamily)
Creates a new instance of FontProvider.
|
FontProvider(String defaultFontFamily)
Creates a new instance of FontProvider.
|
Modifier and Type | Method and Description |
---|---|
int |
addDirectory(String dir)
Add all the fonts from a directory.
|
boolean |
addFont(byte[] fontData)
Add font to FontSet cache.
|
boolean |
addFont(byte[] fontData, String encoding)
Add font to FontSet cache.
|
boolean |
addFont(byte[] fontData, String encoding, Range unicodeRange)
Add font to FontSet cache.
|
boolean |
addFont(FontProgram fontProgram)
Add font to FontSet cache.
|
boolean |
addFont(FontProgram fontProgram, String encoding)
Add font to FontSet cache.
|
boolean |
addFont(FontProgram fontProgram, String encoding, Range unicodeRange)
Add font to FontSet cache.
|
boolean |
addFont(String fontPath)
Add font to FontSet cache.
|
boolean |
addFont(String fontPath, String encoding)
Add font to FontSet cache.
|
boolean |
addFont(String fontPath, String encoding, Range unicodeRange)
Add font to FontSet cache.
|
int |
addStandardPdfFonts()
Add standard fonts to FontSet cache.
|
int |
addSystemFonts()
Add all fonts from system directories to FontSet cache.
|
protected FontSelector |
createFontSelector(Collection<FontInfo> fonts, List<String> fontFamilies, FontCharacteristics fc)
Create a new instance of FontSelector .
|
boolean |
getDefaultCacheFlag()
The method is used to determine whether the font should be cached or not by default.
|
boolean |
getDefaultEmbeddingFlag()
The method is used to determine whether the font should be embedded or not by default.
|
String |
getDefaultEncoding(FontProgram fontProgram)
Gets the default encoding for specific font.
|
String |
getDefaultFontFamily()
Gets the default font-family.
|
FontSelector |
getFontSelector(List<String> fontFamilies, FontCharacteristics fc)
Create FontSelector or get from cache.
|
FontSelector |
getFontSelector(List<String> fontFamilies, FontCharacteristics fc, FontSet additionalFonts)
Create FontSelector or get from cache.
|
FontSet |
getFontSet()
Gets FontSet .
|
PdfFont |
getPdfFont(FontInfo fontInfo)
Get from cache or create a new instance of PdfFont .
|
PdfFont |
getPdfFont(FontInfo fontInfo, FontSet additionalFonts)
Get from cache or create a new instance of PdfFont .
|
FontSelectorStrategy |
getStrategy(String text, List<String> fontFamilies)
Gets the FontSelectorStrategy to split specified text into sequences of glyphs, already tied to the fonts which contain them.
|
FontSelectorStrategy |
getStrategy(String text, List<String> fontFamilies, FontCharacteristics fc)
Gets the FontSelectorStrategy to split specified text into sequences of glyphs, already tied to the fonts which contain them.
|
FontSelectorStrategy |
getStrategy(String text, List<String> fontFamilies, FontCharacteristics fc, FontSet additionalFonts)
Gets the FontSelectorStrategy to split specified text into sequences of glyphs, already tied to the fonts which contain them.
|
void |
reset()
Resets PdfFont cache .
|
protected final String defaultFontFamily
FontSelector
if it's impossible to select a font for all other set font-families
public FontProvider(FontSet fontSet)
fontSet
- predefined set of fonts, could be null.
public FontProvider()
public FontProvider(String defaultFontFamily)
defaultFontFamily
- default font family.
public boolean addFont(FontProgram fontProgram, String encoding, Range unicodeRange)
FontSet
cache.
fontProgram
- the font file which will be added to font cache. The FontProgram
instances are normally created via FontProgramFactory
.
encoding
- font encoding to create PdfFont
. Possible values for this argument are the same as for PdfFontFactory.createFont()
family of methods.
unicodeRange
- sets the specific range of characters to be used from the font.
public boolean addFont(FontProgram fontProgram, String encoding)
FontSet
cache.
fontProgram
- the font file which will be added to font cache. The FontProgram
instances are normally created via FontProgramFactory
.
encoding
- font encoding to create PdfFont
. Possible values for this argument are the same as for PdfFontFactory.createFont()
family of methods.
public boolean addFont(FontProgram fontProgram)
FontSet
cache.
fontProgram
- the font file which will be added to font cache. The FontProgram
instances are normally created via FontProgramFactory
.
public boolean addFont(String fontPath, String encoding, Range unicodeRange)
FontSet
cache.
fontPath
- path to the font file to add. Can be a path to file or font name, see FontProgramFactory.createFont(String)
.
encoding
- font encoding to create PdfFont
. Possible values for this argument are the same as for PdfFontFactory.createFont()
family of methods.
unicodeRange
- sets the specific range of characters to be used from the font.
public boolean addFont(String fontPath, String encoding)
FontSet
cache.
fontPath
- path to the font file to add. Can be a path to file or font name, see FontProgramFactory.createFont(String)
.
encoding
- font encoding to create PdfFont
. Possible values for this argument are the same as for PdfFontFactory.createFont()
family of methods.
public boolean addFont(String fontPath)
FontSet
cache.
fontPath
- path to the font file to add. Can be a path to file or font name, see FontProgramFactory.createFont(String)
.
public boolean addFont(byte[] fontData, String encoding, Range unicodeRange)
FontSet
cache.
fontData
- byte content of the font program file.
encoding
- font encoding to create PdfFont
. Possible values for this argument are the same as for PdfFontFactory.createFont()
family of methods.
unicodeRange
- sets the specific range of characters to be used from the font.
public boolean addFont(byte[] fontData, String encoding)
FontSet
cache.
fontData
- byte content of the font program file.
encoding
- font encoding to create PdfFont
. Possible values for this argument are the same as for PdfFontFactory.createFont()
family of methods.
public boolean addFont(byte[] fontData)
FontSet
cache.
fontData
- byte content of the font program file.
public int addDirectory(String dir)
dir
- path to directory.
public int addSystemFonts()
FontSet
cache.
public int addStandardPdfFonts()
FontSet
cache.
StandardFonts
public String getDefaultFontFamily()
public String getDefaultEncoding(FontProgram fontProgram)
fontProgram
- to get default encoding
PdfEncodings
public boolean getDefaultCacheFlag()
NOTE: This method can be overridden to customize behaviour.
public boolean getDefaultEmbeddingFlag()
NOTE: This method can be overridden to customize behaviour.
public FontSelectorStrategy getStrategy(String text, List<String> fontFamilies, FontCharacteristics fc, FontSet additionalFonts)
FontSelectorStrategy
to split specified text into sequences of glyphs, already tied to the fonts which contain them. The fonts can be taken from the added fonts to the font provider and are chosen based on font-families list and desired font characteristics.
text
- for splitting into sequences of glyphs.
fontFamilies
- target font families to create FontSelector
for sequences of glyphs.
fc
- instance of FontCharacteristics
to create FontSelector
for sequences of glyphs.
additionalFonts
- set which provides fonts additionally to the fonts added to font provider. Combined set of font provider fonts and additional fonts is used when choosing a single font for a sequence of glyphs. Additional fonts will only be used for the given font selector strategy instance and will not be otherwise preserved in font provider.
FontSelectorStrategy
instance.
public FontSelectorStrategy getStrategy(String text, List<String> fontFamilies, FontCharacteristics fc)
FontSelectorStrategy
to split specified text into sequences of glyphs, already tied to the fonts which contain them. The fonts can be taken from the added fonts to the font provider and are chosen based on font-families list and desired font characteristics.
text
- for splitting into sequences of glyphs.
fontFamilies
- target font families to create FontSelector
for sequences of glyphs.
fc
- instance of FontCharacteristics
to create FontSelector
for sequences of glyphs.
FontSelectorStrategy
instance.
public FontSelectorStrategy getStrategy(String text, List<String> fontFamilies)
FontSelectorStrategy
to split specified text into sequences of glyphs, already tied to the fonts which contain them. The fonts can be taken from the added fonts to the font provider and are chosen based on font-families list and desired font characteristics.
text
- for splitting into sequences of glyphs.
fontFamilies
- target font families to create FontSelector
for sequences of glyphs.
FontSelectorStrategy
instance.
public final FontSelector getFontSelector(List<String> fontFamilies, FontCharacteristics fc)
FontSelector
or get from cache.
fontFamilies
- target font families.
fc
- instance of FontCharacteristics
.
FontSelector
.
createFontSelector(Collection, List, FontCharacteristics)
, getFontSelector(List, FontCharacteristics, FontSet)
public final FontSelector getFontSelector(List<String> fontFamilies, FontCharacteristics fc, FontSet additionalFonts)
FontSelector
or get from cache.
fontFamilies
- target font families.
fc
- instance of FontCharacteristics
.
additionalFonts
- set which provides fonts additionally to the fonts added to font provider. Combined set of font provider fonts and additional fonts is used when choosing a single font for FontSelector
. Additional fonts will only be used for the given font selector strategy instance and will not be otherwise preserved in font provider.
FontSelector
.
}
protected FontSelector createFontSelector(Collection<FontInfo> fonts, List<String> fontFamilies, FontCharacteristics fc)
FontSelector
. While caching is main responsibility of getFontSelector(List, FontCharacteristics, FontSet)
. This method just create a new instance of FontSelector
.
fonts
- Set of all available fonts in current context.
fontFamilies
- target font families.
fc
- instance of FontCharacteristics
.
FontSelector
.
public PdfFont getPdfFont(FontInfo fontInfo)
PdfFont
.
fontInfo
- font info, to create FontProgram
and PdfFont
.
PdfFont
.
public PdfFont getPdfFont(FontInfo fontInfo, FontSet additionalFonts)
PdfFont
.
fontInfo
- font info, to create FontProgram
and PdfFont
.
additionalFonts
- set of additional fonts to consider.
PdfFont
.
public void reset()
Copyright © 1998–2021 iText Group NV. All rights reserved.