Package com.openhtmltopdf.swing
Class AWTFontResolver
- java.lang.Object
-
- com.openhtmltopdf.swing.AWTFontResolver
-
- All Implemented Interfaces:
FontResolver
public class AWTFontResolver extends java.lang.Object implements FontResolver
REsolves an AWT font instance from a list of CSS font families and characteristics.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.awt.Font>
availableFontsHash
Map of base fonts, from which we can derive a concrete instance at the correct size, weight, etc.private java.util.Map<java.lang.String,java.awt.Font>
instanceHash
Map of concrete instances of fonts including size, weight, etc.
-
Constructor Summary
Constructors Constructor Description AWTFontResolver()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static java.awt.Font
createFont(SharedContext ctx, java.awt.Font rootFont, float size, IdentValue weight, IdentValue style, IdentValue variant)
Creates a concrete instance of a font at specified size, weight, style and variant.void
flushCache()
protected static java.lang.String
getFontInstanceHashName(SharedContext ctx, java.lang.String name, float size, IdentValue weight, IdentValue style, IdentValue variant)
Gets the hash key for a concrete instance of a font.private void
init()
FSFont
resolveFont(SharedContext renderingContext, FontSpecification spec)
FSFont
resolveFont(SharedContext ctx, java.lang.String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant)
Resolves a list of font families.protected java.awt.Font
resolveFont(SharedContext ctx, java.lang.String font, float size, IdentValue weight, IdentValue style, IdentValue variant)
Resolves a single font name.void
setFontMapping(java.lang.String name, java.awt.Font font)
Sets the fontMapping attribute of the FontResolver object
-
-
-
Field Detail
-
instanceHash
private final java.util.Map<java.lang.String,java.awt.Font> instanceHash
Map of concrete instances of fonts including size, weight, etc.
-
availableFontsHash
private final java.util.Map<java.lang.String,java.awt.Font> availableFontsHash
Map of base fonts, from which we can derive a concrete instance at the correct size, weight, etc. Note: The value is initially null until we need the given base font.
-
-
Method Detail
-
init
private void init()
-
flushCache
public void flushCache()
-
resolveFont
public FSFont resolveFont(SharedContext ctx, java.lang.String[] families, float size, IdentValue weight, IdentValue style, IdentValue variant)
Resolves a list of font families.
-
setFontMapping
public void setFontMapping(java.lang.String name, java.awt.Font font)
Sets the fontMapping attribute of the FontResolver object- Parameters:
name
- The new fontMapping valuefont
- The new fontMapping value
-
createFont
protected static java.awt.Font createFont(SharedContext ctx, java.awt.Font rootFont, float size, IdentValue weight, IdentValue style, IdentValue variant)
Creates a concrete instance of a font at specified size, weight, style and variant.
-
resolveFont
protected java.awt.Font resolveFont(SharedContext ctx, java.lang.String font, float size, IdentValue weight, IdentValue style, IdentValue variant)
Resolves a single font name. TODO: Make case insensitive.
-
getFontInstanceHashName
protected static java.lang.String getFontInstanceHashName(SharedContext ctx, java.lang.String name, float size, IdentValue weight, IdentValue style, IdentValue variant)
Gets the hash key for a concrete instance of a font. This incorporates size, weight, etc.
-
resolveFont
public FSFont resolveFont(SharedContext renderingContext, FontSpecification spec)
- Specified by:
resolveFont
in interfaceFontResolver
-
-