phelps.awt.font

Class NFontManager

public class NFontManager extends Object implements Observer

Advanced management of general purpose fonts -- ordinarily use NFont instead. A font is a general purpose font iff it
  1. has a URI source (file, JAR, even network) -- so can recreated by the system when gc'ed
  2. can be accessed by name via NFont or getInstance.
TeX fonts aren't general purpose because they have weird encodings. Fonts embedded in PDF aren't general purpose because they are usually subsetted, and thus aren't suitable for uses that expect a full character set.

Services:

Version: $Revision: 1.9 $ $Date: 2003/12/30 04:13:36 $

Constructor Summary
NFontManager(File log, String[] paths)
Method Summary
static NFontcreateFont(URL source)
Creates font fron source, using the file suffix to determine font type.
String[]getAvailableFamilies()
Returns sorted list of family names, which is generally shorter than the font name list because fonts can be in the same families.
StringgetAvailableFamily(String family, int flags)
Returns font family that best matches passed family and flags.
String[]getAvailableNames()
Returns sorted list of font names.
NFontgetInstance(String name)
Finds font with exact PostScript font name, which looks like Times-Italic.
NFontgetInstance(String family, int weight, int flags)
Returns font best matching family and flags.
static StringguessFamily(String name)
Guess the family from the font name.
static intguessWeight(String name)
booleanisAvailableFamily(String family)
booleanisAvailableName(String name)
booleanmap(String name, String family, int weight, int flags, URL source, int num, boolean override)
Add a mapping from a font name and family to a font file.
booleanmap(String fromname, String fromfamily, String toname, boolean override)
Map requests for one font (which may or may not already exist) to another (that must exist).
voidmapJavaLogical()
voidmapMacDoze()
Maps missing Macintosh fonts to use Windows equivalents, and vice-versa.
voidmapURW()
Maps missing common fonts to use URW equivalents, if available.
voidupdate(Observable obs, Object arg)
For internal use only.

Constructor Detail

NFontManager

public NFontManager(File log, String[] paths)

Method Detail

createFont

public static NFont createFont(URL source)
Creates font fron source, using the file suffix to determine font type.

getAvailableFamilies

public String[] getAvailableFamilies()
Returns sorted list of family names, which is generally shorter than the font name list because fonts can be in the same families.

getAvailableFamily

public String getAvailableFamily(String family, int flags)
Returns font family that best matches passed family and flags.

Sequence to choose font:

  1. (if exact font name is known, use getInstance)
  2. family exactly
  3. family normalized: removing spaces ("Times New Roman" ⇒ "TimesNewRoman") and all lowercase
  4. fixed set of remappings (CJKV to OS X built-in)
  5. strip trailing caps, which are usually foundary abbreviation ("ArialMT" ⇒ "Arial") or foundary/company ("Apple Chancery" ⇒ "Chancery")
  6. strip foundary from start of name
  7. strip "Pro" ("Helvetica" matches "Helvetica Pro");
  8. partial match
  9. family with similar properties to flags

getAvailableNames

public String[] getAvailableNames()
Returns sorted list of font names.

getInstance

public NFont getInstance(String name)
Finds font with exact PostScript font name, which looks like Times-Italic. Caches.

Returns: font or null of it doesn't exist

getInstance

public NFont getInstance(String family, int weight, int flags)
Returns font best matching family and flags. Tries to use a font from database as found by NFontManager, but OSes have fonts not available as ordinary font files, so if database match is not close, tries OS through java.awt.Font.

guessFamily

public static String guessFamily(String name)
Guess the family from the font name. It excludes style properties, corporate prefixes, and subsetting prefixes. For example Times,BoldItalic returns Times, and Adobe-Times-Bold returns Times.

guessWeight

public static int guessWeight(String name)

isAvailableFamily

public boolean isAvailableFamily(String family)

isAvailableName

public boolean isAvailableName(String name)

map

public boolean map(String name, String family, int weight, int flags, URL source, int num, boolean override)
Add a mapping from a font name and family to a font file. If the font name already exists, then the passed setting can override or be ignored. Otherwise the mapping is added. If the font name (or family) is null, then the font will be created and queried for this information, at some cost in performance. If the source is null, then that font is deleted.

With this mechanism, new fonts can be added for general use (such as a font from a JAR or from an application like FrameMaker or OpenOffice), and existing fonts can be remapped (such as mapping "Times" to the URW version, only if there is no existing "Times"), and existing fonts can be deleted,

Returns: true iff passed mapping was modified the database, added/deleted/overrode.

map

public boolean map(String fromname, String fromfamily, String toname, boolean override)
Map requests for one font (which may or may not already exist) to another (that must exist). If toname does not exist, or fromname exists and override is false, then the mapping is ignored. The font toname continues to be accesible under its pre-existing name and family.

mapJavaLogical

public void mapJavaLogical()

mapMacDoze

public void mapMacDoze()
Maps missing Macintosh fonts to use Windows equivalents, and vice-versa. For instance, the font called "Palatino" on the Mac is called "Book Antiqua" on Windows.

mapURW

public void mapURW()
Maps missing common fonts to use URW equivalents, if available.

update

public void update(Observable obs, Object arg)
For internal use only.