Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GETAFM - print in PostScript fonts you never knew you had.

20 views
Skip to first unread message

gree...@swatsun.uucp

unread,
Apr 13, 1987, 12:39:04 AM4/13/87
to

Dear PostScriptFolk,

The situation may arise where your PostScript device knows about fonts
that your host computer is not familiar with. The popular TranScript
package from Adobe, for example, contains two important programs,
namely enscript(1) and pscat(1) (the guts of ptroff(1)), that demand
font metrics information in the Adobe Font Metric (AFM) format. (In the
case of pscat, the program pscatmap(8) must be run on the AFM files to
produce troff width files before use.) Adobe, however, only supplies
AFM files for fonts known to the old Apple LaserWriter. Many sites now
use the LaserWriter Plus, which has more fonts which are not supported
with AFM files. This program gets the AFM files from the LaserWriter
Plus or any other PostScript device, thereby enabling enscript, pscat,
ptroff, or any other programs demanding access to AFM files to print in
any font supported by the PostScript device.

Peter "PostScript" Greenberg
Swarthmore College
Swarthmore, PA 19081
(215) 328-8384 or 8610
UUCP: ...{seismo!bpa | sun!liberty}!swatsun!greenber


-------------------------SNIP SNIP SNIP-------------------------------------


#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# getafm
# getafm.man
# This archive created: Mon Apr 13 00:26:15 1987
export PATH; PATH=/bin:$PATH
if test -f 'getafm'
then
echo shar: will not over-write existing file "'getafm'"
else
cat << \SHAR_EOF > 'getafm'
#!/bin/sh
# Getafm by Peter Greenberg at Swarthmore College. February 13, 1987.
# This program gets Adobe Font Metric (AFM) files from a PostScript device.
# Enables enscript and other programs to know about every font on your
# PostScript device. See afm(7) and other Adobe docs for more info.
#
# copyright 1987 by Peter Greenberg. May be used and copied without charge so
# long as credit is given to the author and this message is retained.
# PostScript and LaserWriter are trademarks of Adobe Systems Inc. and Apple
# Computer, Inc. respectively.
#
# SEE THE MANUAL PAGE FOR GETAFM FOR FULL INSTRUCTIONS ON HOW TO
# USE THIS PROGRAM.
#
# bugs? questions? contact
# Peter Greenberg, Swarthmore College, Swarthmore, PA 19081
# Tel. (215) 328-8384
# UUCP: ...!seismo!bpa!swatsun!greenber
#
# HOW TO WORK THIS THING
#
# This file is a hybrid between a PostScript and a Bourne shell program.
# It takes an arbitrary number of command line arguments giving names of
# PostScript fonts. It spools a PostScript program that extracts font metric
# information from the PostScript fonts. The PostScript program sends this
# information in the format of a standard Adobe Font Metric file to its idea
# of standard output, which is definitely NOT its raster device. On the Apple
# LaserWriter, standard output is the same serial line on which it gets data
# from the host. This program was developed on a net of Sun3's, one of which
# is hooked up to an Apple LaserWriter Plus. We ran this program with lpr set
# as the spooler and extracted the resultant afm files from the log file kept
# by the lpd program. This file contains all messages sent back from the
# printer over the tty, so the afm file may be buried amongst other stuff.
# They are easy to find, however, since they are between distinctive GETAFM
# banner lines. Extract these files, getting rid of the ctrl-M characters. Our
# log file is /usr/spool/laser/laser-log. Install these extracted files (without
# banner lines) in the directory /usr/local/lib/lw, or wherever your software
# looks for afm files. Naming is important; call them [fullfontname].afm.

# NOTE: The Bourne shell part of this program does little other than spool the
# PostScript program, so it won't know if any of the fonts you give it are
# not recognized by your PostScript device. The PostScript program will indicate
# the error by writing an appropriate message instead of the table to its
# standard output.

# CHANGE THIS LINE IF YOUR SPOOLER IS OTHER THAN LPR.
spooler=/usr/ucb/lpr

#CHANGE THIS LINE IF YOUR PRINTER IS OTHER THAN POSTSCRIPT.
spoolopts=-PPostScript

emit_header () {
echo '%!'
echo "/Font /$1 def"
}

emit_rest () {
cat <<End-Of-PostScript-Code
% This is the PostScript code that extracts font metric info from font
% dictionaries known to PostScript.
/output { print flush } def %change this routine for raster output, etc.
/PrintByName
{
dup
80 string cvs output ( ) output
currentdict exch 2 copy known
{get 255 string cvs output (\n) output}
{ pop pop } %if name is not in currentdict, do nothing
ifelse
} def
/Chr 1 string def
/DoIt {
FontDirectory Font 2 copy known not
{pop pop (GETAFM: Font not found -- aborting!\n) output}
{get dup setfont begin
currentdict /FontInfo 2 copy known {
get begin % stuff in FontInfo
/Notice PrintByName
/FullName PrintByName
/FamilyName PrintByName
/Weight PrintByName
/version PrintByName
/isFixedPitch PrintByName
/UnderlinePosition PrintByName
/UnderlineThickness PrintByName
/ItalicAngle PrintByName
end
}
{ pop pop } %FontInfo not there
ifelse
%stuff in toplevel of font dictionary. All this stuff *must* be there
%by PostScript convention or standard.
/FontName PrintByName
(FontBBox ) output
currentdict /FontBBox get dup dup dup
0 1 3 { get 10 string cvs output ( ) output } for
(\n) output
newpath 0 0 moveto
% CapHeight: top of capital H.
(CapHeight ) output
(H) false charpath flattenpath pathbbox 1000 mul round cvi
20 string cvs output pop pop pop
(\n) output closepath newpath 0 0 moveto
%XHeight: top of lowercase x.
(XHeight ) output
(x) false charpath flattenpath pathbbox 1000 mul round cvi
20 string cvs output pop pop pop
(\n) output closepath newpath 0 0 moveto
%Ascender: top of lowercase d.
(Ascender ) output
(d) false charpath flattenpath pathbbox 1000 mul round cvi
20 string cvs output pop pop pop
(\n) output closepath newpath 0 0 moveto
%Descender: Bottom of lowercase p.
(Descender ) output
(p) false charpath flattenpath pathbbox pop pop 1000 mul round cvi
20 string cvs output pop
(\n) output closepath newpath 0 0 moveto
%FontMetrics Stuff
(StartCharMetrics\n) output
32 1 255 {
(C ) output
dup dup 5 string cvs output
( ; WX ) output
Chr exch 0 exch put
Chr stringwidth pop 1000 mul round cvi 5 string cvs output
( ; N ) output
currentdict /Encoding get % 256 elt. array
exch get %now the PS name of the char is on op stack
40 string cvs output
( ; B ) output
newpath 0 0 moveto
[ Chr false charpath flattenpath pathbbox ] dup dup dup
closepath
0 get 1000 mul round cvi 5 string cvs output ( ) output
1 get 1000 mul round cvi 5 string cvs output ( ) output
2 get 1000 mul round cvi 5 string cvs output ( ) output
3 get 1000 mul round cvi 5 string cvs output ( ) output
(; \n) output
} for
(EndCharMetrics\n) output
end
(EndFontMetrics\n) output
} ifelse
} def % end of DoIt
(=====================GETAFM OUTPUT BEGIN========================\n) output
(StartFontMetrics 1.0\n) output
(Comment Adobe Font Metric table for font ) output Font 255 string cvs output
(\n) output
(Comment Font metric table computed from PostScript device\n) output
(Comment by getafm program.\n) output
DoIt
(====================GETAFM OUTPUT END===========================\n) output

End-Of-PostScript-Code
} # end of emit_rest shell subroutine
# Back in Bourne shell.

if [ $# = 0 ]
then
echo "$0: usage: $0 fontname ..."
exit 1
fi

for font in $@
do
(emit_header $font ; emit_rest ) | $spooler $spoolopts
done
exit 0
SHAR_EOF
chmod +x 'getafm'
fi # end of overwriting check
if test -f 'getafm.man'
then
echo shar: will not over-write existing file "'getafm.man'"
else
cat << \SHAR_EOF > 'getafm.man'
.TH GETAFM 8 "12 April 1987"
.SH NAME
getafm \- have your PostScript device send you an Adobe Font Metrics file for
PostScript fonts.
.SH SYNOPSIS
.B getafm
.I fontname [...]
.SH RATIONALE
The situation may arise where your PostScript device knows about fonts that
your host computer is not familiar with. The popular TranScript package
from Adobe, for example, contains two
important programs, namely \fIenscript(1)\fR and \fIpscat(1)\fR
(the guts of \fIptroff(1)\fR),
that demand font metrics
information in the Adobe Font Metric (AFM) format. (In the case of \fIpscat,\fR
the program \fIpscatmap(8)\fR must be run on the AFM files to produce troff
width files before use.)
Adobe, however,
only supplies AFM
files for fonts known to the old Apple LaserWriter. Many sites now use the
LaserWriter Plus, which has more fonts which are not supported with AFM files.
This program gets the AFM files from the LaserWriter Plus or any other
PostScript device, thereby enabling \fIenscript, pscat, ptroff,\fR or any
other programs demanding access to AFM files to print in any font supported
by the PostScript device.
.SH DESCRIPTION
Each \fIfontname\fR is the full PostScript name of a font for which font
metrics information is desired.
\fIgetafm\fR spools a program written in PostScript to a PostScript device.
This PostScript code has the device write a file in Adobe Font Metric
(AFM) format (see \fIafm(7)\fR) for each \fIfontname\fR indicated on the
command line to its idea
of standard output, which is certainly NOT the PostScript virtual page, and is
almost definitely the communications line connecting the device to the host.
This information may be read directly off the line, but on most systems data
comming back from a PostScript device is stored in a log file for that device.
If you have a UNIX-type system running TranScript, this will probably be
/usr/spool/laser/laser-log. The AFM output will come sandwiched between
appropriate banner lines. The AFM files for each \fIfontname\fR will be sent
sepreately.
.LP
The system administrator should clip these files out (dropping the banner
lines) and install them where
software needing them will see them. TranScript programs on UNIX-type systems
will look in the directory given by environment variable PSLIBDIR, or
/usr/local/lib/lw by default. An AFM file for a given font should be named
\fIfontname\fR.afm. CAUTION: The control-M characters should
be removed from AFM files before use.
.LP
\fIgetafm\fR is a Bourne shell script which currently makes use of \fIlpr(1)\fR
to spool the PostScript code, but can be modified easily to use any spooler.
.SH DIAGNOSTICS
Exits with non-zero return code if no fonts are specified on the command
line. Since \fIgetafm\fR makes no
assumptions about the PostScript device it is working with, all other error
checking is done in PostScript. If PostScript cannot find the font requested
it prints an appropriate message in between the banner lines in lieu of an
AFM file.
.SH FILES
.TP 2.2i
/usr/local/lib/lw/*.afm
font metrics files.
.TP
/usr/spool/laser/laser-log
probable location of log file where \fIgetafm\fR output will be found.
.SH "SEE ALSO"
enscript(1), pscat(1), ptroff(1), troff(1), afm(7), pscatmap(8).
.br
4.2bsd: lpr(1).
.br
System V: lp(1).
.SH CAVEATS
\fIgetafm\fR output has been used by \fIenscript\fR and \fIpscat\fR
(through the prior application of \fIpscatmap\fR) to produce
excellent looking documents in all the fonts supplied with the Apple
LaserWriter Plus. There are differences, however, between AFM files produced
by \fIgetafm\fR for the original LaserWriter fonts and the AFM files supplied
by Adobe. These differences are confined to character bounding box information,
on which point there is never agreement between the two files, although the
numbers are always in the same ballpark. The PostScript code spooled by
\fIgetafm\fR uses empirical methods to determine this information, and it
does so using a technique described in Adobe PostScript documentation.
Nevertheless, it seems that \fIenscript\fR and \fIpscat\fR are interested
only in character
width information, about with there is never a discrepancy, so \fIgetafm\fR
is guaranteed to work beautifully with these programs. If other problems are
detected, they should be brought to the attention of the author.
.SH AUTHORS
.nf
Peter Greenberg
Swarthmore College
Swarthmore, PA 19081
(215) 328-8384 or 8610
UUCP: ...{seismo!bpa | sun!liberty}!swatsun!greenber
.fi
.RE
.SH NOTICES
PostScript and TranScript are trademarks of Adobe Systems Inc. UNIX and
System V are a trademarks of AT&T-Bell Labs. LaserWriter is a trademark of
Apple Computer Inc.
.LP
Special thanks to Scott Schwartz for helping with the Bourne shell side of
\fIgetafm.\fR
SHAR_EOF
fi # end of overwriting check
# End of shell archive
exit 0

fa...@sun.uucp

unread,
Apr 15, 1987, 1:12:40 AM4/15/87
to
In article <10...@byzantium.UUCP>, greenber@swatsun (Peter Greenberg) writes:
>
>
> Dear PostScriptFolk,
>
> The situation may arise where your PostScript device knows about fonts
> that your host computer is not familiar with....


In a similar vein, here's a little toy I wrote when I was learning postscript.

It goes through the printer's internal memory and gives an example of
every font the printer has. For some reason it takes a while to run; probably
because the printer has to scale all of its fonts.

Simply print this on your postscript printer...

=====================cut here==========================
%! PostScript!
%

/Times-Roman findfont 10 scalefont setfont

/inch { 72 mul } def

/LM 1.0 inch def
/RM 7 inch def
/BM .5 inch def
/TM 10 inch def
/tmpstr 80 string def

/xpos LM def
/ypos TM def
xpos ypos moveto
/dy 18 def

/crlf
{
/xpos LM def
/ypos ypos dy sub def
ypos BM lt
{ showpage /ypos TM def } if
ypos xpos exch moveto
} def

/c-crlf { stringwidth pop currentpoint pop add RM gt { crlf } if } def

/c-show { dup c-crlf show } def

/putnum { tmpstr cvs c-show ( ) show } def

/puttype { type tmpstr cvs c-show ( ) show } def

/showfont
{
crlf
dup findfont 15 scalefont setfont
tmpstr cvs show (: ) show
(ABCDEFGHIJKLMNOPQRSTUVWXYZ ) c-show
(abcdefghijklmnopqrstuvwxyz ) c-show
(0123456789 ) c-show
(!"#$%&' ) c-show (\(\)*+,-./ ) c-show
(:;<=>?@ ) c-show ([\\]^_` ) c-show
({|}~ ) c-show
( ) tmpstr copy
0 1 31 { tmpstr exch dup 8#240 add put } for tmpstr c-show
0 1 31 { tmpstr exch dup 8#300 add put } for tmpstr c-show
0 1 31 { tmpstr exch dup 8#340 add put } for tmpstr c-show
crlf
} def


FontDirectory length (length = ) show putnum crlf crlf

FontDirectory
{pop showfont} forall


showpage


=====================cut here==========================

--
-ed falk, sun microsystems, fa...@sun.com
terrorist, cryptography, DES, drugs, cipher, secret, decode, NSA, CIA, NRO.

gree...@swatsun.uucp

unread,
Apr 22, 1987, 8:08:25 PM4/22/87
to

PostScriptFolk,
I recently posted getafm, a PostScript program wrapped in a Bourne shell
script. The PostScript part works fine, but I used function definitions in the
Bourne shell part, and now I find that many Bourne shell implementations do not
support this. If you got getafm, and it works, you are golden. But if you get
shell errors, then you have to apply this patch.

---------------------------------SNIP-SNIP-SNIP--------------------------------
52,56c52,55


< if [ $# = 0 ]
< then
< echo "$0: usage: $0 fontname ..."
< exit 1
< fi

---


> emit_header () {
> echo '%!'
> echo "/Font /$1 def"
> }

58,61c57,58
< while test $# -gt 0 ; do
< $spooler $spoolopts <<End-Of-PostScript
< %!
< /Font /$1 def
---
> emit_rest () {
> cat <<End-Of-PostScript-Code
157,159c154,165
< End-Of-PostScript
< # Back in Bourne Shell
< shift
---


> End-Of-PostScript-Code
> } # end of emit_rest shell subroutine
> # Back in Bourne shell.
>

> emit_header () {
> echo '%!'
> echo "/Font /$1 def"
> }
>

> for font in $@
> do
> (emit_header $font ; emit_rest ) | $spooler $spoolopts

---------------------------SNIP-SNIP-SNIP---------------------------------------
--

Peter Greenberg, Swarthmore College, Swarthmore, PA 19081

AT&T:(215) 328-8384 or 8610
UUCP: ...{{seismo | inhp4}!bpa | {sun | rutgers}!liberty}!swatsun!greenber
ARPA: swatsun!gree...@bpa.BELL-ATL.COM

0 new messages