|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jfig.gui.FontCache
singleton class to manage text fonts and font metrics.
FontCache: a helper class to maintain information about Fonts and FontMetrics (for different zoom factors). This is a singleton class. Use getFontCache() to retrieve a reference to the global FontCache.
The main purpose of this class is to provide a fast mapping from FIG font index values to Java Font and FontMetrics objects. Internally, the FIG font index is first mapped to equivalent Java Font names (like "ItcBookman Light") and styles (like Font.ITALIC). These values are then used to create Java Font objects via the corresponding Font constructor.
For performance reasons, especially for Java 1.1 VMs, this class caches the Font and FontMetrics objects in hashtables indexed via (fig_font_index, font_size_in_pt) integer pairs. This currently incurs an Integer object allocation per get() request, which should be optimized away by using custom hashtables instead of java.util.Hashtable.
For portable Math/Symbol rendering, we try to load the Bakoma Truetype version of the Computer Modern fonts directly from the classpath, i.e. JAR-resources like "/jfig/fonts/cmsy10.ttf". This works only on JDK 1.3+ virtual machines.
Nested Class Summary | |
(package private) class |
FontCache.ComputerModernFontsManager
|
Field Summary | |
static java.lang.String[] |
cmFontNames
|
static java.lang.String[][] |
defaultFontMapping
an array with the original FIG Postscript font names, without spaces, and the default (JDK 1.1 compatible) mapping to Java font names. |
static float[] |
postscriptFontMetrics
this array contains the measured length in centimeters of the string "The quick brown fox jumps over the lazy dog." when printed at 12pt size at 100% magnification for each of the FIG format fonts. |
static java.lang.String[] |
postscriptFontNames
|
static java.lang.String[] |
texFontNames
|
Method Summary | |
void |
dumpFontDescriptions()
|
void |
flushFontCache()
|
java.awt.Font |
getFont(int fig_font,
int size)
get a Java Font object for the requested font. |
static FontCache |
getFontCache()
get a reference to the FontCache singleton instance. |
int |
getFontIndex(java.lang.String fontName)
find the FIG font index from a font name. |
java.awt.FontMetrics |
getFontMetrics(java.awt.Font font)
return the FontMetrics for the given Font. |
java.awt.FontMetrics |
getFontMetrics(int fig_font,
int size)
get the FontMetrics for the requested font. |
void |
initializeFontDescriptions()
initialize the font description strings for all 34 FIG fonts. |
void |
loadComputerModernFonts()
|
static void |
main(java.lang.String[] argv)
main: simple FontCache selftest, properties in /jfig/jfig.cnf |
void |
parseFontDescriptions()
parse all font description strings and extract both the Font names (like "Times" or "ItcBookman Light") and the Font styles (like Font.PLAIN or Font.BOLDITALIC). |
void |
put(java.lang.Object key,
int fig_font,
int size)
add a new Font with index fig_font and point size into our fontTable and fontMetricsTable hashtables, under the given key. |
void |
set_debug(boolean v)
enable/disable debug output from this FontCache |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String[] postscriptFontNames
public static final java.lang.String[] cmFontNames
public static final float[] postscriptFontMetrics
public static final java.lang.String[] texFontNames
public static java.lang.String[][] defaultFontMapping
Method Detail |
public static FontCache getFontCache()
public void flushFontCache()
public void set_debug(boolean v)
v
- whether to use debug (true) or not (false)public void initializeFontDescriptions()
public void dumpFontDescriptions()
public void parseFontDescriptions()
This method expects a font description of the form "Font Family Name,Style" with a comma-separated pair of strings. Style may be either "plain", "italic", "bold", or "bolditalic". Invalid strings will be substituted by "Courier,plain".
public int getFontIndex(java.lang.String fontName)
public void put(java.lang.Object key, int fig_font, int size)
public java.awt.FontMetrics getFontMetrics(int fig_font, int size)
fig_font
- the FIG index of the font (0=Times .. 33=ZapfChancery)size
- the font size in point.public java.awt.FontMetrics getFontMetrics(java.awt.Font font)
public java.awt.Font getFont(int fig_font, int size)
fig_font
- the FIG index of the font (0=Times .. 33=ZapfChancery)size
- the font size in point.public void loadComputerModernFonts()
public static void main(java.lang.String[] argv)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |