org.apache.fop.fonts

Class FontInfo


public class FontInfo
extends java.lang.Object

The FontInfo for the layout and rendering of a fo document. This stores the list of available fonts that are setup by the renderer. The font name can be retrieved for the family style and weight.
Currently font supported font-variant small-caps is not implemented.

Field Summary

protected static Log
log
logging instance

Constructor Summary

FontInfo()
Main constructor

Method Summary

void
addFontProperties(String name, String family, String style, int weight)
Adds a new font triplet.
void
addFontProperties(String name, FontTriplet triplet)
Adds a new font triplet.
void
addMetrics(String name, FontMetrics metrics)
Adds font metrics for a specific font.
static FontTriplet
createFontKey(String family, String style, int weight)
Creates a key from the given strings.
FontTriplet
findAdjustWeight(String family, String style, int weight)
Find a font with a given family and style by trying different font weights according to the spec.
FontTriplet
fontLookup(String family, String style, int weight)
Lookup a font.
FontTriplet
fontLookup(String[] family, String style, int weight)
Lookup a font.
Font
getFontInstance(FontTriplet triplet, int fontSize)
Retrieves a (possibly cached) Font instance based on a FontTriplet and a font size.
String
getFontStyleFor(String fontName)
Returns the font style for a particular font.
int
getFontWeightFor(String fontName)
Returns the font weight for a particular font.
Map
getFonts()
Gets a Map of all registred fonts.
String
getInternalFontKey(FontTriplet triplet)
Returns the internal font key (F1, F2, F3 etc.) for a given triplet.
FontMetrics
getMetricsFor(String fontName)
Returns the FontMetrics for a particular font
FontTriplet
getTripletFor(String fontName)
Returns the first triplet matching the given font name.
Map
getUsedFonts()
This is used by the renderers to retrieve all the fonts used in the document.
boolean
hasFont(String family, String style, int weight)
Determines if a particular font is available.
boolean
isSetupValid()
Checks if the font setup is valid (At least the ultimate fallback font must be registered.)
void
useFont(String internalName)
Tells this class that the font with the given internal name has been used.

Field Details

log

protected static Log log
logging instance

Constructor Details

FontInfo

public FontInfo()
Main constructor

Method Details

addFontProperties

public void addFontProperties(String name,
                              String family,
                              String style,
                              int weight)
Adds a new font triplet.
Parameters:
name - internal key
family - font family name
style - font style (normal, italic, oblique...)
weight - font weight

addFontProperties

public void addFontProperties(String name,
                              FontTriplet triplet)
Adds a new font triplet.
Parameters:
name - internal key
triplet - the font triplet to associate with the internal key

addMetrics

public void addMetrics(String name,
                       FontMetrics metrics)
Adds font metrics for a specific font.
Parameters:
name - internal key
metrics - metrics to register

createFontKey

public static FontTriplet createFontKey(String family,
                                        String style,
                                        int weight)
Creates a key from the given strings.
Parameters:
family - font family
style - font style
weight - font weight
Returns:
internal key

findAdjustWeight

public FontTriplet findAdjustWeight(String family,
                                    String style,
                                    int weight)
Find a font with a given family and style by trying different font weights according to the spec.
Parameters:
family - font family
style - font style
weight - font weight
Returns:
internal key

fontLookup

public FontTriplet fontLookup(String family,
                              String style,
                              int weight)
Lookup a font.
Locate the font name for a given family, style and weight. The font name can then be used as a key as it is unique for the associated document. This also adds the font to the list of used fonts.
Parameters:
family - font family
style - font style
weight - font weight
Returns:
the font triplet of the font chosen

fontLookup

public FontTriplet fontLookup(String[] family,
                              String style,
                              int weight)
Lookup a font.
Locate the font name for a given family, style and weight. The font name can then be used as a key as it is unique for the associated document. This also adds the font to the list of used fonts.
Parameters:
family - font family (priority list)
style - font style
weight - font weight
Returns:
font triplet of the font chosen

getFontInstance

public Font getFontInstance(FontTriplet triplet,
                            int fontSize)
Retrieves a (possibly cached) Font instance based on a FontTriplet and a font size.
Parameters:
triplet - the font triplet designating the requested font
fontSize - the font size
Returns:
the requested Font instance

getFontStyleFor

public String getFontStyleFor(String fontName)
Returns the font style for a particular font. There may be multiple font styles matching this font. Only the first found is returned. Searching is done on a sorted list to guarantee consistent results.
Parameters:
fontName - internal key
Returns:
font style

getFontWeightFor

public int getFontWeightFor(String fontName)
Returns the font weight for a particular font. There may be multiple font weights matching this font. Only the first found is returned. Searching is done on a sorted list to guarantee consistent results.
Parameters:
fontName - internal key
Returns:
font weight

getFonts

public Map getFonts()
Gets a Map of all registred fonts.
Returns:
a read-only Map with font key/FontMetrics pairs

getInternalFontKey

public String getInternalFontKey(FontTriplet triplet)
Returns the internal font key (F1, F2, F3 etc.) for a given triplet.
Parameters:
triplet - the font triplet
Returns:
the associated internal key or null, if not found

getMetricsFor

public FontMetrics getMetricsFor(String fontName)
Returns the FontMetrics for a particular font
Parameters:
fontName - internal key
Returns:
font metrics

getTripletFor

public FontTriplet getTripletFor(String fontName)
Returns the first triplet matching the given font name. As there may be multiple triplets matching the font name the result set is sorted first to guarantee consistent results.
Parameters:
fontName - The font name we are looking for
Returns:
The first triplet for the given font name

getUsedFonts

public Map getUsedFonts()
This is used by the renderers to retrieve all the fonts used in the document. This is for embedded font or creating a list of used fonts.
Returns:
a read-only Map with font key/FontMetrics pairs

hasFont

public boolean hasFont(String family,
                       String style,
                       int weight)
Determines if a particular font is available.
Parameters:
family - font family
style - font style
weight - font weight
Returns:
True if available

isSetupValid

public boolean isSetupValid()
Checks if the font setup is valid (At least the ultimate fallback font must be registered.)
Returns:
True if valid

useFont

public void useFont(String internalName)
Tells this class that the font with the given internal name has been used.
Parameters:
internalName - the internal font name (F1, F2 etc.)

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