Package org.apache.pdfbox.pdmodel.font
Class Standard14Fonts
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.font.Standard14Fonts
-
public final class Standard14Fonts extends java.lang.ObjectThe "Standard 14" PDF fonts, also known as the "base 14" fonts. There are 14 font files, but Acrobat uses additional names for compatibility, e.g. Arial.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStandard14Fonts.FontNameEnum for the names of the 14 standard fonts.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,Standard14Fonts.FontName>ALIASESContains all base names and alias names for the known fonts.private static java.util.Map<Standard14Fonts.FontName,FontMetrics>FONTSContains the font metrics for the standard 14 fonts.private static java.util.Map<Standard14Fonts.FontName,FontBoxFont>GENERIC_FONTSContains the mapped fonts for the standard 14 fonts.
-
Constructor Summary
Constructors Modifier Constructor Description privateStandard14Fonts()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontainsName(java.lang.String fontName)Returns true if the given font name is one of the known names, including alias.static FontMetricsgetAFM(java.lang.String fontName)Returns the metrics for font specified by fontName.private static GlyphListgetGlyphList(Standard14Fonts.FontName baseName)static java.awt.geom.GeneralPathgetGlyphPath(Standard14Fonts.FontName baseName, java.lang.String glyphName)Returns the path for the character with the given name for the specified Standard 14 font.private static FontBoxFontgetMappedFont(Standard14Fonts.FontName baseName)Returns the mapped font for the specified Standard 14 font.static Standard14Fonts.FontNamegetMappedFontName(java.lang.String fontName)Returns the base name of the font which the given font name maps to.static java.util.Set<java.lang.String>getNames()Returns the set of known font names, including aliases.private static voidloadMetrics(Standard14Fonts.FontName fontName)Loads the metrics for the base font specified by name.private static voidmapName(java.lang.String alias, Standard14Fonts.FontName baseName)Adds an alias name for a standard font to the map of known aliases to the map of aliases (alias as key, standard name as value).private static voidmapName(Standard14Fonts.FontName baseName)Adds a standard font name to the map of known aliases, to simplify the logic of finding font metrics by name.
-
-
-
Field Detail
-
ALIASES
private static final java.util.Map<java.lang.String,Standard14Fonts.FontName> ALIASES
Contains all base names and alias names for the known fonts. For base fonts both the key and the value will be the base name. For aliases, the key is an alias, and the value is a FontName. We want a single lookup in the map to find the font both by a base name or an alias.
-
FONTS
private static final java.util.Map<Standard14Fonts.FontName,FontMetrics> FONTS
Contains the font metrics for the standard 14 fonts. The key is the font name, value is a FontMetrics instance. Metrics are loaded into this map on demand, only if needed.- See Also:
getAFM(java.lang.String)
-
GENERIC_FONTS
private static final java.util.Map<Standard14Fonts.FontName,FontBoxFont> GENERIC_FONTS
Contains the mapped fonts for the standard 14 fonts. The key is the font name, value is a FontBoxFont instance. FontBoxFont are loaded into this map on demand, only if needed.
-
-
Method Detail
-
loadMetrics
private static void loadMetrics(Standard14Fonts.FontName fontName) throws java.io.IOException
Loads the metrics for the base font specified by name. Metric file must exist in the pdfbox jar under /org/apache/pdfbox/resources/afm/- Parameters:
fontName- one of the standard 14 font names for which to load the metrics.- Throws:
java.io.IOException- if no metrics exist for that font.
-
mapName
private static void mapName(Standard14Fonts.FontName baseName)
Adds a standard font name to the map of known aliases, to simplify the logic of finding font metrics by name. We want a single lookup in the map to find the font both by a base name or an alias.- Parameters:
baseName- the font name of the Standard 14 font- See Also:
getAFM(java.lang.String)
-
mapName
private static void mapName(java.lang.String alias, Standard14Fonts.FontName baseName)Adds an alias name for a standard font to the map of known aliases to the map of aliases (alias as key, standard name as value). We want a single lookup in tbaseNamehe map to find the font both by a base name or an alias.- Parameters:
alias- an alias for the fontbaseName- the font name of the Standard 14 font
-
getAFM
public static FontMetrics getAFM(java.lang.String fontName)
Returns the metrics for font specified by fontName. Loads the font metrics if not already loaded.- Parameters:
fontName- name of font; either a base name or alias- Returns:
- the font metrics or null if the name is not one of the known names
- Throws:
java.lang.IllegalArgumentException- if no metrics exist for that font.
-
containsName
public static boolean containsName(java.lang.String fontName)
Returns true if the given font name is one of the known names, including alias.- Parameters:
fontName- the name of font, either a base name or alias- Returns:
- true if the name is one of the known names
-
getNames
public static java.util.Set<java.lang.String> getNames()
Returns the set of known font names, including aliases.- Returns:
- the set of known font names
-
getMappedFontName
public static Standard14Fonts.FontName getMappedFontName(java.lang.String fontName)
Returns the base name of the font which the given font name maps to.- Parameters:
fontName- name of font, either a base name or an alias- Returns:
- the base name or null if this is not one of the known names
-
getMappedFont
private static FontBoxFont getMappedFont(Standard14Fonts.FontName baseName)
Returns the mapped font for the specified Standard 14 font. The mapped font is cached.- Parameters:
baseName- name of the standard 14 font- Returns:
- the mapped font
-
getGlyphPath
public static java.awt.geom.GeneralPath getGlyphPath(Standard14Fonts.FontName baseName, java.lang.String glyphName) throws java.io.IOException
Returns the path for the character with the given name for the specified Standard 14 font. The mapped font is cached. The path may differ in different environments as it depends on the mapped font.- Parameters:
baseName- name of the standard 14 fontglyphName- name of glyph- Returns:
- the mapped font
- Throws:
java.io.IOException- if the data could not be read
-
getGlyphList
private static GlyphList getGlyphList(Standard14Fonts.FontName baseName)
-
-