org.apache.fop.fonts

Class Font


public class Font
extends java.lang.Object

This class holds font state information and provides access to the font metrics.

Field Summary

static FontTriplet
DEFAULT_FONT
Default fallback key
static String
STYLE_ITALIC
Italic font style
static String
STYLE_NORMAL
Normal font style
static int
WEIGHT_BOLD
Bold font weight
static int
WEIGHT_NORMAL
Normal font weight

Constructor Summary

Font(String key, FontTriplet triplet, FontMetrics met, int fontSize)
Main constructor

Method Summary

int
getAscender()
Returns the font's ascender.
int
getCapHeight()
Returns the font's CapHeight.
int
getCharWidth(char c)
Helper method for getting the width of a unicode char from the current fontstate.
int
getDescender()
Returns the font's Descender.
String
getFontName()
Returns the font's name.
int
getFontSize()
Returns the font size
FontTriplet
getFontTriplet()
int
getKernValue(char ch1, char ch2)
Returns the amount of kerning between two characters.
Map
getKerning()
Returns the font's kerning table
int
getWidth(int charnum)
Returns the width of a character
int
getWordWidth(String word)
Calculates the word width.
int
getXHeight()
Returns the XHeight
boolean
hasChar(char c)
Determines whether this font contains a particular character/glyph.
boolean
hasKerning()
char
mapChar(char c)
Map a java character (unicode) to a font character.
String
toString()

Field Details

DEFAULT_FONT

public static final FontTriplet DEFAULT_FONT
Default fallback key

STYLE_ITALIC

public static final String STYLE_ITALIC
Italic font style

STYLE_NORMAL

public static final String STYLE_NORMAL
Normal font style

WEIGHT_BOLD

public static final int WEIGHT_BOLD
Bold font weight
Field Value:
700

WEIGHT_NORMAL

public static final int WEIGHT_NORMAL
Normal font weight
Field Value:
400

Constructor Details

Font

public Font(String key,
            FontTriplet triplet,
            FontMetrics met,
            int fontSize)
Main constructor
Parameters:
key - key of the font
triplet - the font triplet that was used to lookup this font (may be null)
met - font metrics
fontSize - font size

Method Details

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

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

getDescender

public int getDescender()
Returns the font's Descender.
Returns:
the descender

getFontName

public String getFontName()
Returns the font's name.
Returns:
the font name

getFontSize

public int getFontSize()
Returns the font size
Returns:
the font size

getFontTriplet

public FontTriplet getFontTriplet()
Returns:
the font triplet that selected this font

getKernValue

public int getKernValue(char ch1,
                        char ch2)
Returns the amount of kerning between two characters.
Parameters:
ch1 - first character
ch2 - second character
Returns:
the distance to adjust for kerning, 0 if there's no kerning

getKerning

public Map getKerning()
Returns the font's kerning table
Returns:
the kerning table

getWidth

public int getWidth(int charnum)
Returns the width of a character
Parameters:
charnum - character to look up
Returns:
width of the character

getWordWidth

public int getWordWidth(String word)
Calculates the word width.
Parameters:
word - text to get width for
Returns:
the width of the text

getXHeight

public int getXHeight()
Returns the XHeight
Returns:
the XHeight

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

hasKerning

public boolean hasKerning()
Returns:
true if the font has kerning info

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

toString

public String toString()
See Also:
java.lang.Object.toString()

Copyright 1999-2007 The Apache Software Foundation. All Rights Reserved.