Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Aug 1996 18:41:28 -0500
From:      Dave Bodenstab <imdave@synet.net>
To:        doc@freebsd.org
Subject:   Font cookbook possible addition to FAQ/handbook
Message-ID:  <199608052341.SAA22093@base486.synet.net>

next in thread | raw e-mail | index | archive | help

Hi,

Recently, I wanted to figure out how to use some additional fonts that
I had accumulated.  I finally figured out *how to do it* from the various
man pages and documentation.  Since it might be of use to other users,
and I didn't see any reference to this topic in the FAQ or handbook, I
thought I'd try my hand at a simple cookbook tutorial addressing the
use of fonts.  I have included my unanswered questions at the end of
the document.

BTW, I looked at sgmlfmt(1) and that told me how to convert a sgml
document once I had one.  The man page referred me to
/usr/share/sgml/FreeBSD/dtd/linuxdoc so I looked... it doesn't seem
to be a reference guide.  So, how does one go about creating a sgml
document?  Where is the reference guide for sgml?  What is the format
of a sgml file?

Anyway, here's what I put together.  This is my present understanding of
fonts and how to use them with FreeBSD.  I am sure that there are errors or
misunderstandings, but it contains enough valid information to allow the
use of additional fonts with Ghostscript, X11 and Groff.  This is my first
attempt to write anything along the lines of a tutorial/FAQ, so I am sure
it is pretty raw.  There are probably better ways to do some of this stuff,
and I would welcome being corrected.

Feel free to incorporate this into the handbook/FAQ as you see fit.  If
I can be of further assistance, let me know.

Dave Bodenstab
imdave@synet.net



-----------

Fonts and how to use them with FreeBSD

1. Basic terminology

There are many different font formats and associated font file suffixes.
A few that will be addressed here are:

	.pfa .pfb   - Postscript type 1 fonts.  The .pfa is the *A*scii form
		      and .pfb the *B*inary form.
	.afm	    - The font metrics associated with a type 1 font.
	.pfm	    - The printer font metrics associated with a type 1 font.
	.ttf	    - A TrueType font
	.fot	    - An indirect reference to a TrueType font (not an actual
		      font)
	.fon	    - A bitmapped screen font
	.fnt	    - A bitmapped screen font

2. What font formats can I use?

Which font type is useful depends on the application being used.  FreeBSD
by itself uses no fonts.  Application programs and/or drivers may make use
of the font files.  Here is a small cross reference of application/driver
to the font type suffixes:

      Driver
	syscons     - .fnt

      Application
	Ghostscript - .pfa .pfb .ttf
	X11         - .pfa .pfb
	Groff       - .pfa .afm
	Povray      - .ttf


3. Setting a virtual console to 80x60 line mode

First, a 8x8 font must be loaded.  /etc/sysconfig should contain the lines:
   
  # Choose font 8x8 from /usr/share/syscons/fonts/* (or NO for default)
  font8x8=/usr/share/syscons/fonts/cp437-8x8.fnt

Various screen orientated programs, such as vi, must be able to determine
the current screen dimensions.  These can be set with stty:

  bash$ stty crt rows 60 columns 80

References: stty(1), vidcontrol(1)


4. Using type 1 fonts with X11

The X11 fonts are located in various subdirectories under
/usr/X11R6/lib/X11/fonts.  There is already a directory named "Type1".
The most straight forward way to add a new font is to put it into this
directory.  A better way is to keep all new fonts in a separate directory and
use a symbolic link to the additional font.  This allows one to more easily
keep track of ones fonts without confusing them with the fonts that were
originally provided.  For example:

	# Create a directory to contain the font files
	bash$ mkdir -p /usr/local/share/fonts/type1
	bash$ cd /usr/local/share/fonts/type1

	# Place the .pfa, .pfb and .afm files here
	# You might want to keep readme files, and other documentation
	# for the fonts here also
	cp /cdrom/fonts/atm/showboat/showboat.pfb .
	cp /cdrom/fonts/atm/showboat/showboat.afm .

	# Maintain an index to cross reference the fonts
	bash$ echo showboat - InfoMagic CICA, Dec 1994, \
		/fonts/atm/showboat >>INDEX


Now, to use a new font with X11, one must make the font file available and
update the font name files.  The X11 font names look like:

  -bitstream-charter-medium-r-normal-xxx-0-0-0-0-p-0-iso8859-1
       \        \      \    |   \     |  | | | | | |    \    \ 
        \        \      \    \   \     \  \ \ \ \ \ \    +----- character set
         \        \      \    \   \     \  \ \ \ \ \ +- average width
          \        \      \    \   \     \  \ \ \ \ +- spacing
           \        \      \    \   \     \  \ \ \ +- vertical res.
            \        \      \    \   \     \  \ \ +- horiz. res.
             \        \      \    \   \     \  \ +- points
              \        \      \    \   \     \  +- pixels
               \        \      \    \   \     +- additionall style
                \        \      \    \   +- width
                 \        \      \    +- slant
                  \        \      +- weight
                   \        +- family
                    +- foundry

A new name needs to be created for each new font.  If you have some information
from the documentation that accompanied the font, that would serve as the basis
for creating the name.  If there is no information, then you can get some idea
by using strings(1) on the font file.  For example:

	strings showboat.pfb | more
	%!FontType1-1.0: Showboat 001.001
	%%CreationDate: 1/15/91 5:16:03 PM
	%%VMusage: 1024 45747
	% Generated by Fontographer 3.1
	% Showboat
	 1991 by David Rakowski.  Alle Rechte Vorbehalten.
	FontDirectory/Showboat known{/Showboat findfont dup/UniqueID known{dup
	/UniqueID get 4962377 eq exch/FontType get 1 eq and}{pop false}ifelse
	{save true}{false}ifelse}{false}ifelse
	12 dict begin
	/FontInfo 9 dict dup begin
	 /version (001.001) readonly def
	 /FullName (Showboat) readonly def
	 /FamilyName (Showboat) readonly def
	 /Weight (Medium) readonly def
	 /ItalicAngle 0 def
	 /isFixedPitch false def
	 /UnderlinePosition -106 def
	 /UnderlineThickness 16 def
	 /Notice (Showboat
	 1991 by David Rakowski.  Alle Rechte Vorbehalten.) readonly def
	end readonly def
	/FontName /Showboat def
	--stdin--

Using this information, a possible name might be:

  -type1-Showboat-medium-r-normal-decorative-0-0-0-0-p-0-iso8859-1

  Foundry - lets just name all the new fonts "type1"
  Family - the name of the font
  Weight - normal, bold, medium, semibold, etc.
  Slant - roman, italic, oblique, etc.
  Width - normal, wide, condensed, extended, etc.
  Additional style - usually omitted, but this font contains decorative
  		capital letters so lets indicate that
  Spacing - proportional or monospaced

All of these names are arbitrary, but one should strive to be compatible
with the existing conventions.  A font is referenced by name with possible
wild cards by an X11 program, so the names chosen should make some sense.
You might begin by simply using ...-normal-r-normal-...-p-... as the name,
and then use xfontsel(1) to examine it and adjust the name after you see
what it looks like.

So, to complete our example:

	# Make the font accessible to X11
	bash$ cd /usr/X11R6/lib/X11/fonts/Type1
	bash$ ln -s /usr/local/share/fonts/type1/showboat.pfb .

	# Edit fonts.dir and fonts.scale, adding the line:
	# -type1-showboat-medium-r-normal-decorative-0-0-0-0-p-0-iso8859-1
	# and incrementing the number of fonts in the first line.
	bash$ ed fonts.dir
	1p
	25
	1c
	26
	.
	$a
	showboat.pfb -type1-showboat-medium-r-normal-decorative-0-0-0-0-p-0-iso8859-1
	.
	w
	q

	# fonts.scale seems to be identical to fonts.dir...
	bash$ cp fonts.dir fonts.scale

	# Tell X11 that things have changed
	bash$ xset fp rehash

	# Examine the new font
	bash$ xfontsel -pattern -type1-*


References: xfontsel(1)


5. Using type 1 fonts with Ghostscript

Ghostscript references a font via its Fontmap file.  This must be modified
in a similar way to the X11 fonts.dir file.  Using the font from the previous
example, here is how to use it with Ghostscript:

	# Put the font in Ghostscript's font directory
	bash$ cd /usr/local/share/ghostscript/fonts
	bash$ ln -s /usr/local/share/fonts/type1/showboat.pfb .

	# Edit Fontmap so Ghostscript knows about the font
	bash$ cd /usr/local/share/ghostscript/4.01
	bash$ ed Fontmap
	$a
	/Showboat        (showboat.pfb) ; % From CICA /fonts/atm/showboat
	.
	w
	q

	# Use Ghostscript to examine the font
	bash$ gs prfont.ps
	Aladdin Ghostscript 4.01 (1996-7-10)
	Copyright (C) 1996 Aladdin Enterprises, Menlo Park, CA.  All rights
	reserved.
	This software comes with NO WARRANTY: see the file PUBLIC for details.
	Loading Times-Roman font from /usr/local/share/ghostscript/fonts/tir_____.pfb...
	 /1899520 581354 1300084 13826 0 done.
	GS>Showboat DoFont
	Loading Showboat font from /usr/local/share/ghostscript/fonts/showboat.pfb...
	 1939688 565415 1300084 16901 0 done.
	>>showpage, press <return> to continue<<
	>>showpage, press <return> to continue<<
	>>showpage, press <return> to continue<<
	GS>quit


References: fonts.txt in the Ghostscript distribution


5. Using type 1 fonts with Groff

Now that the new font can be used by both X11 and Ghostscript, how can one
use the new font with groff?  First of all, since we are dealing with type 1
postscript fonts, the groff device that is applicable is the `ps' device.
A font file must be created for each font that groff can use.  A groff font
name is just a file in /usr/share/groff_font/devps.  With our example, the
font file could be /usr/share/groff_font/devps/SHOWBOAT.  The file must be
created using tools provided by groff.

The first tool is `afmtodit'.  This is not normally installed, so it must be
retrieved from the source distribution.  I found I had to change the first
line of the file, so I did:

	bash$ cp /usr/src/gnu/usr.bin/groff/afmtodit/afmtodit.pl /tmp
	bash$ ed /tmp/afmtodit.pl
	1c
	#!/usr/bin/perl -P-
	.
	w
	q

This tool will create the groff font file from the metrics file (.afm suffix)
Continuing with our example:

	# Many .afm files are in Mac format... ^M delimited lines
	# We need to convert them to unix style ^J delimited lines
	bash$ cd /tmp
	bash$ cat /usr/local/share/fonts/type1/showboat.afm |
		tr '\015' '\012' >showboat.afm
	# Now create the groff font file
	bash$ cd /usr/share/groff_font/devps
	bash$ /tmp/afmtodit -d DESC -e text.enc /tmp/showboat.afm \
		generate/textmap SHOWBOAT

The font can now be referenced with the name SHOWBOAT.

If ghostscript is used to drive the printers on the system, then nothing
more needs to be done.  However, if true postscript printers are used, then
the font must be down loaded to the printer in order for the font to be used
(unless the printer happens to have the showboat font built in or on an
accessible font disk.) The final step is to create a down loadable font.
The pfbtops tool is used to create the .pfa format of the font, and the
`download' file is modified to reference the new font.  The `download' file
must reference the postscript name of the font.  This can easily be determined
from the .pfa file as illustrated:

	# Create the .pfa font file
	bash$ pfbtops /usr/local/share/fonts/type1/showboat.pfb >showboat.pfa

Of course, if the .pfa file is already available, just use a symbolic link
to reference it.

	# Get the postscript font name
	bash$ fgrep /FullName showboat.pfa
	 /FullName (Showboat) readonly def

	# Tell groff that the font must be down loaded
	bash$ ed download
	$a
	/Showboat      showboat.pfa
	.
	w
	q


To test the font:

	cat >example.t
	.sp 5
	.ps 16
	This is an example of the Showboat font:
	.br
	.ps 48
	.vs (\n(.s+2)p
	.sp
	.ft SHOWBOAT
	ABCDEFGHI
	.br
	JKLMNOPQR
	.br
	STUVWXYZ
	.sp
	.ps 16
	.vs (\n(.s+2)p
	.fp 5 SHOWBOAT
	.ft R
	To use it for the first letter of a paragraph, it will look like:
	.sp 50p
	\s(48\f5H\s0\fRere is the first sentence of a paragraph that uses the
	showboat font as its first letter.
	Additional vertical space must be used to allow room for the larger
	letter.
	^D
	bash$ groff -Tps example.t >example.ps

	# To use ghostscript/ghostview
	bash$ ghostview example.ps

	# To print it
	bash$ lpr -Ppostscript example.ps


6. Can TrueType fonts be used?

Ghostscript v4.1 has the ability to use TrueType fonts.  However, the
documentation mentions that the result will be fairly poor due to
deficiencies in ghostscript itself.  So, if one write postscript
files directly, one could reference a TrueType font.

However, groff would need a font description file, and I know of no tools
to construct the metrics from a TrueType font.  In addition, the font would
have to be down loaded to postscript printers in the appropriate format,
and again, groff cannot handle TrueType fonts in this fashion.

X11 has no support for TrueType fonts that I am aware of.

The only program that I know of that has the ability to use TrueType fonts
is POVRAY version 3.


7. Where can additional fonts be obtained?

Many fonts are available over the Internet.  They are either entirely
free, or are share-ware.  In addition, there are many inexpensive CDROMs
available that contain many fonts.  Some Internet locations (as of August
1996) are:

  ftp://ftp.winsite.com		(Formerly CICA)
  http://www.simtel.net/simcgi-bin/dosfind.cgi
  ftp://ftp.coast.net/
  http://af-pc-plloyd.ecel.uwa.edu.au/fonts/index.html
  http://www.esselte.com/letraset/index.html
  http://www.inil.com/users/elfring/esf.htm


8. Additional questions

   What use are the .pfm files?
   Can one generate the .afm file from a .pfa or .pfb?
   How to generate the groff character mapping files for postscript
   	fonts with non-standard character names?
   Can xditview and devX?? devices be setup to access all the new
   	fonts?
   It might be good to have examples of using TrueType fonts with
   	povray and ghostscript.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608052341.SAA22093>