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
- has a URI source (file, JAR, even network) -- so can recreated by the system when gc'ed
- 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:
- Database of fonts in list of directories (as specified in constructor).
Fonts from a JAR or non-standard paths or dynamically discovered can be {link #map(String,String,int,int,URL,int,boolean) mapped} for general purpose use.
A font, which need not exist, can be
replaced
in all uses with another font;
this capability is used to optionally make available the free URW fonts
under standard names.
Likewise, Macintosh and Windows
font families can be mapped to one another.
The database can report all font names
and all families
.
An instance of this class initialized with the standard system font paths is available via getFontManager.
- Tenacious
family matching
,
which returns a good substitute if the exact font is not available.
- Font creation and cacheing.
Fonts can be created based on
The cache is subject to garbage collection, and uses the source URL to recreate fonts if necessary.
- Low-level communication among NFont subclasses,
in the sharing of a few open file descriptors among the possibly many fonts that need them.
Version: $Revision: 1.9 $ $Date: 2003/12/30 04:13:36 $
Method Summary |
static NFont | createFont(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. |
String | getAvailableFamily(String family, int flags)
Returns font family that best matches passed family and flags.
|
String[] | getAvailableNames() Returns sorted list of font names. |
NFont | getInstance(String name)
Finds font with exact PostScript font name, which looks like Times-Italic .
|
NFont | getInstance(String family, int weight, int flags)
Returns font best matching family and flags.
|
static String | guessFamily(String name)
Guess the family from the font name.
|
static int | guessWeight(String name) |
boolean | isAvailableFamily(String family) |
boolean | isAvailableName(String name) |
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.
|
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).
|
void | mapJavaLogical() |
void | mapMacDoze()
Maps missing Macintosh fonts to use Windows equivalents, and vice-versa.
|
void | mapURW()
Maps missing common fonts to use URW equivalents, if available. |
void | update(Observable obs, Object arg) For internal use only. |
public NFontManager(File log, String[] paths)
public static
NFont createFont(URL source)
Creates font fron source, using the file suffix to determine font type.
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.
public String getAvailableFamily(String family, int flags)
Returns font family that best matches passed
family and
flags.
Sequence to choose font:
- (if exact font name is known, use getInstance)
- family exactly
- family normalized: removing spaces ("Times New Roman" ⇒ "TimesNewRoman") and all lowercase
- fixed set of remappings (CJKV to OS X built-in)
- strip trailing caps, which are usually foundary abbreviation ("ArialMT" ⇒ "Arial") or foundary/company ("Apple Chancery" ⇒ "Chancery")
- strip foundary from start of name
- strip "Pro" ("Helvetica" matches "Helvetica Pro");
- partial match
- family with similar properties to flags
public String[] getAvailableNames()
Returns sorted list of font names.
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
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.
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
.
public static int guessWeight(String name)
public boolean isAvailableFamily(String family)
public boolean isAvailableName(String name)
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.
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.
public void mapJavaLogical()
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.
public void mapURW()
Maps missing common fonts to use URW equivalents, if available.
public void update(Observable obs, Object arg)
For internal use only.