OpenWindows Server Programmer's Guide
只搜寻这本书
以 PDF 格式下载本书

Font Support

5

The OpenWindows server provides robust font support in both the X11 server and the Display PostScript (DPS) extension. Font formats from numerous vendors can be used to display text in English or foreign languages, including Asian languages. Symbol fonts can be used to display mathematical equations. The OpenWindows environment provides 55 Latin fonts for European text and two symbol fonts. You can add other fonts to the system if you want.

Font Formats

Fonts from different vendors come in different formats. Table 5-1 lists the various font formats, their vendors, and the associated file types supported by the OpenWindows environment.
Table 5-1
Font FormatVendorFile Types
F3 (Type 7)SunSoft.f3b
Type1 (ASCII)Adobe and various foundries.pfa
Type1 (binary)Adobe and various foundries.pfb
Type 3Adobe and various foundries.ps
SpeedoBitstream.spd
Portable Compiled FormatMIT.pcf
Bitmap Distribution FormatAdobe.bdf
Table 5-1
Font FormatVendorFile Types
Big Endian Prebuilt FormatAdobe.bepf
Little Endian Prebuilt FormatAdobe (for x86 only).lepf
Server Natural FormatMIT.snf
Old OpenWindows BitmapSunSoft.fb
The fonts provided by the OpenWindows server are located in the /usr/openwin/lib/X11/fonts directory. For more information on the directory structure see "Font Directory Structure" on page 38.

Outline and Bitmap Fonts

OpenWindows supports two types of font representation: outline fonts and bitmap fonts. In the X11 server, outline fonts can be scaled to any desired size; in Display PostScript (DPS) they can also be rotated and skewed. To display a letter from an outline font, the server scales and rotates only the outline of the character. This repositioned outline is then rendered into pixel form (bitmap) for display on the screen. This rendered bitmap is also stored in the glyph cache for reuse.
Because certain font sizes occur very frequently, they are also kept in separate files in pre-rendered bitmap form. This saves the server from having to scale and render them. However, the resulting bitmap fonts can only be displayed in one size and orientation. Some of these fonts have also been hand-tuned to look better and be more readable. As they are encountered, these bitmaps are also placed in the glyph cache.
The recommended bitmap format is the portable compiled format (.pcf).
The /usr/openwin/bin directory contains the following tools to convert between outline and bitmap fonts, as well as between various bitmap formats. See the corresponding man pages for more detailed information.
  • makebdf Creates Bitmap Distribution Format files (.bdf) from outline font files (.f3b)
  • bdftopcf Converts font from .bdf format to Portable Compiled Format (.pcf)
  • bdftosnf Converts .bdf files to Server Natural Format (.snf) files
As illustrated in Table 5-2, many bitmap font file formats are architecture-dependent binary files. They cannot be shared between machines of different architectures (for example, between SPARC and x86).
Table 5-2
Font FormatFile ExtensionBinaryArchitecture-specific
Bitmap Distribution.bdfNoNo
Portable Compiled.pcfYesNo
Server Natural Format.snfYesYes
Old OpenWindows Bitmap.fbYesYes
Little Endian Prebuilt Format.lepfYesYes (x86)
Big Endian Prebuilt Format.bepfYesYes (SPARC)
The OpenWindows environment contains compressed .pcf files (files with .pcf.Z extensions). You can uncompress these if you want. If you add fonts to your system, you can either compress the files or not. Use uncompressed files if you want the fonts to display somewhat faster.

Replacing Outline Fonts with Bitmap Fonts

The OpenWindows environment automatically replaces some outline fonts by bitmap fonts when the size is appropriate. This improves performance, and in some cases improves the aesthetics and readability of the text. There may be several sizes at which replacement occurs for a given outline font.

When Replacement Occurs

Currently in DPS, the .pcf bitmap format is substituted for F3 outline fonts and the .bepf (or .lepf) is substituted for Type1 fonts. Substitution occurs when there is no rotation, the requested pixel size is within one half of a pixel of the .pcf font size, and the .pcf font is an F3BitMap resource in a .upr (PostScript resource) file.

Using F3 Fonts in DPS

F3 fonts behave exactly like Type1 fonts, except /FontType returns 7 instead of 1. For example, the following PostScript code works the same regardless of the kind of font.
/Helvetica findfont 50 scalefont setfont 10 10 moveto (ABC) show
But the following code yields 7 for an F3 font and 1 for a Type1 font.
currentfont /FontType get ==
The kind of font returned depends on the current DPS internal resource path. See "Changing the Resource Path in DPS" on page 40 for details.)

Locating Fonts

By default, the OpenWindows server looks for fonts in directories under the /usr/openwin/lib/X11/fonts directory. See Table 5-3 for the complete font directory structure.

Font Directory Structure

The directories below are preceded by /usr/openwin/lib/X11/fonts.
Table 5-3
DirectorySubdirectoryFile SuffixesContents
/100dpi
.pcfBitmap fonts
/75dpi
.pcfBitmap fonts
/F3
.f3bF3 format outline fonts
/map.mapF3 character set specifications
/F3bitmaps.pcfBitmap fonts
/Speedo.spdBitstream Speedo format outline fonts
Table 5-3
DirectorySubdirectoryFile SuffixesContents
/Type1
.pfa, .pfbType1 outline fonts
/afm.afmAdobe font metrics
/outline.pfa, .pfbType1 outline fonts
/prebuilt.bepf, .lepfBitmaps for SPARC Solaris and x86
/Xt+.pcfBitmap fonts
/Type3.psPostScript Outline fonts
/encodings.encEncodings
/misc.pcfBitmap fonts

Changing the Default Font Path in X11

In X11, the default font path is:
/usr/openwin/lib/X11/fonts/F3,
/usr/openwin/lib/X11/fonts/F3bitmaps,
/usr/openwin/lib/X11/fonts/Type1,
/usr/openwin/lib/X11/fonts/Speedo,
/usr/openwin/lib/X11/fonts/misc,
/usr/openwin/lib/X11/fonts/75dpi,
/usr/openwin/lib/X11/fonts/100dpi,
/usr/openwin/lib/X11/fonts/Xt+

You can change this default either at start up or after the server has been started.
At start up, use:

  example% openwin -fp /<user-defined-directory-list>  

where the user-defined directory list is a comma separated list of directories for the server to search. Note that the directory paths must be absolute.
After the server has started, you can use either the xset command or XSetFontPath. For xset, use only one of the following:

  example% xset +fp /user-defined-directory-list  
  example% xset fp+ /user-defined-directory-list  
  example% xset fp- /user-defined-directory-list  


Note - Since xset dynamically changes the font path, you do not need to restart the server to change the default font path.

For more information on xset, see the xset man page; for XSetFontPath, see the Xlib Reference Manual.

Changing the Resource Path in DPS

In DPS, fonts are considered resources in the font category. Their associated files are specified by resource (.upr) files. DPS resource files reside in directories specified by the resource (font) path. This path is a list of directories maintained internally by DPS. DPS uses the default resource path specified by the PSRESOURCEPATH environment variable to initialize itself. If PSRESOURCEPATH is not defined, DPS uses /usr/openwin/lib/X11. (See Programming the Display PostScript System with X for further information on resource database files.)

Warning - Because DPS maintains so many internal font caches, you cannot remove a path from the DPS resource path. DPS appends all paths subsequent to the default path to the resource path, regardless of where they end up in the X11 font path. Thus fonts available in X windows might be different from those available in DPS. However, the DPS resource path is dynamic. Fonts should be accessible after the xset command completes. Any change to the X font path is passed to DPS. If there are .upr files present, DPS appends the font files to its internal resource path.The examples in the remainder of this section illustrate some of the DPS and X11 font path behavior.

The xset command:

  example% xset +fp /dir1/dir2/fonts  

prepends /dir1/dir2/fonts to the X11 font path. (Use fp+ to append /dir1/dir2/fonts to the font path.) If there are any .upr files present, the xset command (with either fp+ or +fp) also appends /dir1/dir2/fonts to the DPS resource path.
The command:

  example% xset fp- /dir1/dir2/fonts  

removes /dir1/dir2/fonts from the X11 font path, but does not alter the DPS resource path.
The following openwin command:

  example% openwin -fp /dir1/dir2/fonts  

appends /dir1/dir2/fonts to the DPS resource path.
Use the following xset command to set the X11 font path to /dir1/dir2/fonts and to append /dir1/dir2/fonts to the existing DPS resource path:

  example% xset fp= /dir1/dir2/fonts  


Note - A server reset clears both the X11 font path and the DPS resource path.

Font File Suffixes

The OpenWindows environment is configured so that most X11 fonts are also available in DPS (see Table 5-4 below). DPS supports a slightly different set of fonts than those supported by X11.
Table 5-4
Font DescriptionFont File SuffixAvailable in X11 Available in DPS
Type1 outline fonts.pfa (scaled)
YesYes
Type1 outline fonts.pfb (scaled)
NoYes
Big Endian Prebuilt Format.bepf
NoYes
Little Endian Prebuilt Format.lepf
NoYes
F3 (Type 7).f3b (scaled)
YesYes
Old OpenWindows Bitmap.fb
YesNo
Speedo.spd (scaled)
YesNo
Type 3.ps (scaled)
NoYes
Portable compiled.pcf
YesYes
Bitmap Distribution.bdf
YesNo
Server Natural Format.snf
YesNo

Associated Files

The OpenWindows environment provides files with these extensions. They are not intended to be edited.
  • .afm Adobe Font Metrics files read by client for kerning information
  • .map F3 files read by X11 and DPS for encoding purposes
  • .trans F3 files read by DPS for composite font construction
  • .ps..PostScript Files for composite font and PostScript resource construction
  • .enc Encoding files used by X11 and DPS
  • .upr Display PostScript resource files

Adding New Fonts

To add new bitmap and outline fonts to the OpenWindows Server, follow the steps outlined in the following sections. These instructions apply to eight-bit fonts. Multibyte fonts might require additional files from the font supplier.
  1. Create a directory for the new fonts.

    Do not add fonts to existing font directories--you might corrupt files in those directories, and you also must be superuser.

    For this example, /newfonts is the directory name.


  example% mkdir /newfonts  

  1. Copy or move all fonts to the /newfonts directory.

If you are installing bitmap fonts (pcf, snf, bdf, or fb), see additional steps in "Adding Bitmap Fonts." If you are installing outline fonts (f3b, pfa, pfb, or spd formats), see "Adding Outline Fonts" on page 44.

Adding Bitmap Fonts

Follow these steps if you are installing any of the bitmap font formats (pcf, snf, bdf, or fb).
  1. Use mkfontdir to create the fonts.dir file.


  example% cd /newfonts  
  example% /usr/openwin/bin/mkfontdir  

See the mkfontdir(1) man page for further details.
  1. If you want to define font "aliases," create a fonts.alias file. Use this to map the long internal XLFD font names to shorter names that are easier to enter on a command line.

    Here is a sample fonts.alias file:


  courier "-adobe-courier-medium-r-normal--0-0-0-0-m-0-iso8859-1"  
  courier-italic "-adobe-courier-medium-i-normal--0-0-0-0-m-0-iso8859-1  
  courier-bold "-adobe-courier-bold-r-normal--0-0-0-0-m-0-iso8859-1  
  courier-bolditalic "-adobe-courier-bold-i-normal--0-0-0-0-m-0-iso8859-1  

See the mkfontdir(1) man page for further details.
  1. Use xset to add the /newfonts directory to the server font path.


  example% xset fp+ /newfonts  

See the xset(1) man page for more information.
  1. Use xlsfonts to check to see if the server recognizes your new fonts. xlsfonts lists all the names of all fonts that are accessible to the window server.

Adding Outline Fonts

Follow the steps included in this section to install outline fonts. The OpenWindows environment supports Type1 (pfa), Speedo (spd), and F3 (f3b) outline fonts.
Multibyte fonts might require additional files from the font supplier. For F3 format fonts, you need the .map and .trans files. The server also uses the .map file. It provides a mapping between the character name and its F3 code. The DPS extension uses the .trans file to support multiple byte encodings. It contains the definitions of these encodings.
  1. If you are installing Type1 (pfa or pfb) fonts run makepsres in the /newfonts directory.

    This creates a PSres.upr file. The system requires this file if you want to use these fonts within the DPS extension.

  1. If you are installing F3 fonts, create a .upr file. Use the template below for the .upr file. Replace the example values given below with values that reflect the fonts you want to add. Follow the syntax used in the example. Include the // before the directory name you want to install into. Use the = in the lines where you include the map file and font file names.

    If the .map file included with your font is not in /usr/openwin/lib/X11/F3/map, then include it in the .upr file.)


  PS-Resources-1.0          #mandatory  
  F3MapFile                 #put this in if you are adding map files  
  FontOutline               #put this in if you are installing F3 fonts  
  .                         #mandatory  
  //home/newfonts           #name of directory to install fonts in:  
                             #// required (this is an example)  
  F3MapFile                 #put this in if you are adding map files  
  latin=map/latin.map       #name of the map file and where it is  
                              located (this is an example)  
  .                         #put this in if you are adding map files  
  FontOutline               #put this in if you are installing F3 fonts  
  Helvetica=Helvetica.f3b        #put the font file name here (this is  
                                 an example)  
  Times-Roman=Times-Roman.f3b#put in as many font files as you want  
  .                         #mandatory  

  1. If you are installing Type1 (pfa or pfb) or Speedo (spd) fonts, create a fonts.scale file.

    The fonts.scale file contains the mapping of an internal X11 font name to an easily understood font name. The fonts.scale file will be copied to the fonts.dir file automatically. Do not edit the fonts.dir file. Any changes you make are overwritten when you run mkfontdir.

    For example, here is a fonts.scale file for a directory containing four Type1 fonts:


  cour.pfa -adobe-courier-medium-r-normal--0-0-0-0-m-0-iso8859-1  
  couri.pfa -adobe-courier-medium-i-normal--0-0-0-0-m-0-iso8859-1  
  courb.pfa -adobe-courier-bold-r-normal--0-0-0-0-m-0-iso8859-1  
  courbi.pfa -adobe-courier-bold-i-normal--0-0-0-0-m-0-iso8859-1  


Note - X11 names must follow the standard XLFD font naming convention, using 0's in appropriate fields to indicate outline fonts.

See the X Protocol Reference Manual for additional information on the XLFD font naming convention.
See the mkfontdir(1) man page for more information on the fonts.scale file.
  1. Use mkfontdir to create the fonts.dir file. If you are installing Type1 or Speedo fonts, your fonts.scale file is copied to fonts.dir at this point.


  example% cd /newfonts  
  example% /usr/openwin/bin/mkfontdir  

See the mkfontdir(1) man page for further details.
  1. If you want to define font "aliases," create a fonts.alias file. Use this to map the long internal XLFD font names to shorter names which are easier to enter on the command line.

    Here is an example fonts.alias file:


  courier "-adobe-courier-medium-r-normal--0-0-0-0-m-0-iso8859-1"  
  courier-italic "-adobe-courier-medium-i-normal--0-0-0-0-m-0-iso8859-1"  
  courier-bold "-adobe-courier-bold-r-normal--0-0-0-0-m-0-iso8859-1"  
  courier-bolditalic "-adobe-courier-bold-i-normal--0-0-0-0-m-0-iso8859-1"  

See the mkfontdir(1) man page for further details.
If you are installing an F3 font and the character set supported by this font is not one of the following, the font supplier must provide an encoding file (.enc file).
  • iso8859-1
  • iso8859-2
  • symbol
  • jisx0201.1976-0
  • jisx0208.1983-0
  1. Copy the .enc file described in Step 5 (if you have one) to /usr/openwin/lib/X11/fonts/encodings, and add an entry for it in the encodings.dir file in the same directory.

  2. Use xset to add the /newfonts directory to your font path.


  example% xset fp+ /newfonts  

See the xset(1) man page for more information.
  1. Use xlsfonts to check if the server recognizes your new fonts. xlsfonts lists all the names of all fonts that are accessible to the window server.

You can now use the fonts in the /newfonts directory in your applications. In X11, you do not need to restart the OpenWindows server since xset dynamically changes the font path. See "Changing the Default Font Path in X11" on page 39 for more information.

Using OPEN LOOK Fonts on X Terminals

The /usr/openwin/share/src/fonts directory contains OPEN LOOK fonts in bdf format. Follow the instructions from your vendor on how to install the fonts.