A PostScript Type 1 Font Downloader
Vector 14:2, page 110
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 110
What is a Type 1 PostScript Font?¶
A Type 1 PostScript font is a special case of a PostScript language program, which tells a printer how to make each character of the font. The program uses characters from the lower half of the ASCII character set, but in order to save space on disks containing fonts, the part of the font that is encrypted into hexadecimal characters is compressed by a factor of 2.
Why do we need a Downloader?¶
A download program is required to undo this compression and send the font to the output device for use by other PostScript programs. The output device is usually a PostScript printer, but it could be a file if the output is not to be printed immediately.
In Microsoft Windows with Adobe Type Manager, the printer driver will sort out all the nuts and bolts of sending installed fonts to the printer for you. But what do you do if the font is not installed (there is a limit to the number of fonts you can install), or if you are not using Windows, or any other software which handles printing for you? When I started home computing I used an Atari ST, and this did not have any way of sending fonts to a PostScript printer, so, I had to find a way of downloading fonts myself. The information is not generally available, although the books published by Adobe Systems themselves[1] do contain some useful information.
Gallia est omnis divisa in partes tres¶
So said Julius Caesar[2], but he might equally well have been referring to a PostScript font! The middle part of the font, called the "eexec encryption" is surrounded by two parts in plain ASCII. Each of these parts starts with a two-byte delimiter and a four-byte length, and the whole font file ends with another two-byte delimiter. The task of the downloader is to split the file into the three parts, uncompress the middle one, and put it all together for sending to the printer.
The Downloader¶
The downloader is written for Dyalog APL but it should be easy to convert to any other APL (as mentioned above, it started life as APL.68000 for the Atari ST, so it has been converted once already). It takes the raw font file as its argument and returns the downloadable font. No I/O is performed in this function because that is for the programmer to sort out in the application. All I/O should be performed with no translation, which is why line 1 of then function looks odd (it should end up on the printer as serverdict begin 0 exitserver). This version assumes that the lengths of each part of the font file are stored in Intel format: my PostScript fonts were bought for DOS/Windows, and fonts for other platforms may have the lengths stored differently. If this is the case with your fonts, make the appropriate changes to variable c.
This function does not check that the input is a font file because it assumes that that has been done already. The index origin must be 0.
∇ z←fontload x;a;b;c
[1] z←⎕AV[4],'…',⎕AV[13] ⍝ [string of 29 ⎕AV characters; see N.B.]
[2] z←z,x[6+⍳a←II x[c←5 4 3 2]]
[3] z←z,'0123456789ABCDEF'[,⍉0 16⊤⎕AV⍳x[12+a+⍳b←II x[a+6+c]]]
[4] z←z,x[18+a+b+⍳II x[a+b+12+c]]
[5] z←z,⎕AV[4]
∇
∇ z←II x
[1] z←⍉⌊(256⊥x)-(256*''⍴(⍴x),1)×128≤(1↑⍴x)⍴x←⍉⎕AV⍳x
∇
References¶
- Adobe Systems Inc., Type 1 Font Format, Addison-Wesley Publishing Co., Inc, 1990.
- C Julius Caesar (died 44 B.C.E.), De Bello Gallico, I.i.
Finally¶
Before downloading any fonts to your printer, please make sure that you have the legal right to do so.
N.B. (Production Ed) … Line-1 may also be entered as: