Package org.docx4j.fonts.fop.fonts
Class Font
java.lang.Object
org.docx4j.fonts.fop.fonts.Font
public class Font
extends java.lang.Object
This class holds font state information and provides access to the font
metrics.
-
Field Summary
Fields Modifier and Type Field Description static FontTripletDEFAULT_FONTDefault fallback keystatic intPRIORITY_DEFAULTDefault selection prioritystatic java.lang.StringSTYLE_INCLINEDInclined font stylestatic java.lang.StringSTYLE_ITALICItalic font stylestatic java.lang.StringSTYLE_NORMALNormal font stylestatic java.lang.StringSTYLE_OBLIQUEOblique font stylestatic intWEIGHT_BOLDBold font weightstatic intWEIGHT_EXTRA_BOLDExtra Bold font weightstatic intWEIGHT_LIGHTLight font weightstatic intWEIGHT_NORMALNormal font weight -
Constructor Summary
Constructors Constructor Description Font(java.lang.String key, FontTriplet triplet, FontMetrics met, int fontSize)Main constructor -
Method Summary
Modifier and Type Method Description intgetAscender()Returns the font's ascender.intgetCapHeight()Returns the font's CapHeight.intgetCharWidth(char c)Helper method for getting the width of a unicode char from the current fontstate.intgetDescender()Returns the font's Descender.FontMetricsgetFontMetrics()Returns the associated font metrics object.java.lang.StringgetFontName()Returns the font's name.intgetFontSize()Returns the font sizeFontTripletgetFontTriplet()java.util.MapgetKerning()Returns the font's kerning tableintgetKernValue(char ch1, char ch2)Returns the amount of kerning between two characters.intgetWidth(int charnum)Returns the width of a characterintgetWordWidth(java.lang.String word)Calculates the word width.intgetXHeight()Returns the XHeightbooleanhasChar(char c)Determines whether this font contains a particular character/glyph.booleanhasKerning()charmapChar(char c)Map a java character (unicode) to a font character.java.lang.StringtoString()
-
Field Details
-
WEIGHT_EXTRA_BOLD
public static final int WEIGHT_EXTRA_BOLDExtra Bold font weight- See Also:
- Constant Field Values
-
WEIGHT_BOLD
public static final int WEIGHT_BOLDBold font weight- See Also:
- Constant Field Values
-
WEIGHT_NORMAL
public static final int WEIGHT_NORMALNormal font weight- See Also:
- Constant Field Values
-
WEIGHT_LIGHT
public static final int WEIGHT_LIGHTLight font weight- See Also:
- Constant Field Values
-
STYLE_NORMAL
public static final java.lang.String STYLE_NORMALNormal font style- See Also:
- Constant Field Values
-
STYLE_ITALIC
public static final java.lang.String STYLE_ITALICItalic font style- See Also:
- Constant Field Values
-
STYLE_OBLIQUE
public static final java.lang.String STYLE_OBLIQUEOblique font style- See Also:
- Constant Field Values
-
STYLE_INCLINED
public static final java.lang.String STYLE_INCLINEDInclined font style- See Also:
- Constant Field Values
-
PRIORITY_DEFAULT
public static final int PRIORITY_DEFAULTDefault selection priority- See Also:
- Constant Field Values
-
DEFAULT_FONT
Default fallback key
-
-
Constructor Details
-
Font
Main constructor- Parameters:
key- key of the fonttriplet- the font triplet that was used to lookup this font (may be null)met- font metricsfontSize- font size
-
-
Method Details
-
getFontMetrics
Returns the associated font metrics object.- Returns:
- the font metrics
-
getAscender
public int getAscender()Returns the font's ascender.- Returns:
- the ascender
-
getCapHeight
public int getCapHeight()Returns the font's CapHeight.- Returns:
- the capital height
-
getDescender
public int getDescender()Returns the font's Descender.- Returns:
- the descender
-
getFontName
public java.lang.String getFontName()Returns the font's name.- Returns:
- the font name
-
getFontTriplet
- Returns:
- the font triplet that selected this font
-
getFontSize
public int getFontSize()Returns the font size- Returns:
- the font size
-
getXHeight
public int getXHeight()Returns the XHeight- Returns:
- the XHeight
-
hasKerning
public boolean hasKerning()- Returns:
- true if the font has kerning info
-
getKerning
public java.util.Map getKerning()Returns the font's kerning table- Returns:
- the kerning table
-
getKernValue
public int getKernValue(char ch1, char ch2)Returns the amount of kerning between two characters.- Parameters:
ch1- first characterch2- second character- Returns:
- the distance to adjust for kerning, 0 if there's no kerning
-
getWidth
public int getWidth(int charnum)Returns the width of a character- Parameters:
charnum- character to look up- Returns:
- width of the character
-
mapChar
public char mapChar(char c)Map a java character (unicode) to a font character. Default uses CodePointMapping.- Parameters:
c- character to map- Returns:
- the mapped character
-
hasChar
public boolean hasChar(char c)Determines whether this font contains a particular character/glyph.- Parameters:
c- character to check- Returns:
- True if the character is supported, Falso otherwise
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
getCharWidth
public int getCharWidth(char c)Helper method for getting the width of a unicode char from the current fontstate. This also performs some guessing on widths on various versions of space that might not exists in the font.- Parameters:
c- character to inspect- Returns:
- the width of the character
-
getWordWidth
public int getWordWidth(java.lang.String word)Calculates the word width.- Parameters:
word- text to get width for- Returns:
- the width of the text
-