Package com.itextpdf.awt
Class DefaultFontMapper
- java.lang.Object
-
- com.itextpdf.awt.DefaultFontMapper
-
- All Implemented Interfaces:
FontMapper
- Direct Known Subclasses:
AsianFontMapper
public class DefaultFontMapper extends java.lang.Object implements FontMapper
Default class to map awt fonts to BaseFont.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultFontMapper.BaseFontParameters
A representation of BaseFont parameters.
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.lang.String,java.lang.String>
aliases
Maps aliases to names.private java.util.HashMap<java.lang.String,DefaultFontMapper.BaseFontParameters>
mapper
Maps names to BaseFont parameters.
-
Constructor Summary
Constructors Constructor Description DefaultFontMapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BaseFont
awtToPdf(java.awt.Font font)
Returns a BaseFont which can be used to represent the given AWT Fontjava.util.HashMap<java.lang.String,java.lang.String>
getAliases()
DefaultFontMapper.BaseFontParameters
getBaseFontParameters(java.lang.String name)
Looks for a BaseFont parameter associated with a name.java.util.HashMap<java.lang.String,DefaultFontMapper.BaseFontParameters>
getMapper()
int
insertDirectory(java.lang.String dir)
Inserts all the fonts recognized by iText in thedirectory
into the map.int
insertFile(java.io.File file)
Inserts one font file into the map.void
insertNames(java.lang.Object[] allNames, java.lang.String path)
Inserts the names in this map.java.awt.Font
pdfToAwt(BaseFont font, int size)
Returns an AWT Font which can be used to represent the given BaseFontvoid
putAlias(java.lang.String alias, java.lang.String awtName)
Maps an alias to a name.void
putName(java.lang.String awtName, DefaultFontMapper.BaseFontParameters parameters)
Maps a name to a BaseFont parameter.
-
-
-
Field Detail
-
aliases
private java.util.HashMap<java.lang.String,java.lang.String> aliases
Maps aliases to names.
-
mapper
private java.util.HashMap<java.lang.String,DefaultFontMapper.BaseFontParameters> mapper
Maps names to BaseFont parameters.
-
-
Method Detail
-
awtToPdf
public BaseFont awtToPdf(java.awt.Font font)
Returns a BaseFont which can be used to represent the given AWT Font- Specified by:
awtToPdf
in interfaceFontMapper
- Parameters:
font
- the font to be converted- Returns:
- a BaseFont which has similar properties to the provided Font
-
pdfToAwt
public java.awt.Font pdfToAwt(BaseFont font, int size)
Returns an AWT Font which can be used to represent the given BaseFont- Specified by:
pdfToAwt
in interfaceFontMapper
- Parameters:
font
- the font to be convertedsize
- the desired point size of the resulting font- Returns:
- a Font which has similar properties to the provided BaseFont
-
putName
public void putName(java.lang.String awtName, DefaultFontMapper.BaseFontParameters parameters)
Maps a name to a BaseFont parameter.- Parameters:
awtName
- the nameparameters
- the BaseFont parameter
-
putAlias
public void putAlias(java.lang.String alias, java.lang.String awtName)
Maps an alias to a name.- Parameters:
alias
- the aliasawtName
- the name
-
getBaseFontParameters
public DefaultFontMapper.BaseFontParameters getBaseFontParameters(java.lang.String name)
Looks for a BaseFont parameter associated with a name.- Parameters:
name
- the name- Returns:
- the BaseFont parameter or
null
if not found.
-
insertNames
public void insertNames(java.lang.Object[] allNames, java.lang.String path)
Inserts the names in this map.- Parameters:
allNames
- the returned value of callingBaseFont.getAllFontNames(String, String, byte[])
path
- the full path to the font
-
insertFile
public int insertFile(java.io.File file)
Inserts one font file into the map. The encoding will beBaseFont.CP1252
but can be changed later.- Parameters:
file
- the file to insert- Returns:
- the number of files inserted
- Since:
- 5.0.5
-
insertDirectory
public int insertDirectory(java.lang.String dir)
Inserts all the fonts recognized by iText in thedirectory
into the map. The encoding will beBaseFont.CP1252
but can be changed later.- Parameters:
dir
- the directory to scan- Returns:
- the number of files processed
-
getMapper
public java.util.HashMap<java.lang.String,DefaultFontMapper.BaseFontParameters> getMapper()
-
getAliases
public java.util.HashMap<java.lang.String,java.lang.String> getAliases()
-
-