Ever wanted to install a particular font on your XServer but only could find the font you are after in True Type Format?
Ever asked comp.fontsi for a True Type to Type 1 converter and got a List of Commercial software that doesn't run on your Operating System?
Well, this program should be the answer. This program is written in C (so it should be portable) and therefore should run on any OS. The only limitation is that the program requires some method of converting Big endian integers into local host integers so the network functions ntohs and ntohl are used. These can be replaced by macros if your platform doesn't have them. Of course the target platform requires a C compiler and command line ability.
The version 3.0 got rather extensive post-processing algorithm that brings the converted fonts to the requirements of the Type1 standard, tries to correct the rounding errors introduced during conversions and some simple kinds of bugs that are typical for the public domain TTF fonts. It also generates the hints that enable much better rendering of fonts in small sizes that are typical for the computer displays. But everything has its price, and some of the optimizations may not work well for certain fonts. That's why the options were added to the converter, to control the performed optimizations.
The converter is simple to run, just:
ttf2pt1 [-options] ttffont.ttf Fontnameor
ttf2pt1 [-options] ttffont.ttf -
The first variant creates the file Fontname.pfa (or Fontname.pfb if the option "-b" was used) with the converted font and Fontname.afm with the font metrics, the second one prints the font or the font metrics (if the option "-A" was used) on the standard output from where it can be immediately piped through some filter.
Most of the time no options are neccessary (with a possible exception of `-e'). But if there are some troubles with the resulting font, they may be used to control the conversion. The options are:
-e - Assemble the resulting font to produce a ready .pfa file. [ S.B.: Personally I don't think that this option is particularly useful. The same result may be achieved by piping the unassembled data through t1asm, the Type 1 assembler. And, anyways, it's good to have the t1utils package handy. But Mark and many users think that this functionality is good and it took not much time to add this option. ]
-b - Encode the resulting font to produce a ready .pfb file.
-A - Print the font metrics (.afm file) instead of the font on STDOUT
-o - Disable the optimization of the outlines' code. This kind of optimization never hurts, and the only usage of this option is for comparison of the generated fonts with the fonts generated by the previous versions of converter.
-s - Disable the smoothing of outlines. If the font is broken in some way (even the ones that are not easily noticeable), such smoothing may break it further. So this option is the first thing to be tried if some font looks odd. But with smoothing off the hint generation algorithms may not work properly too.
-t - Disable auto-scaling to the 1000x1000 Type1 standard matrix. The TTF fonts are described in terms of an arbitrary matrix up to 4000x4000. The converted fonts must be scaled to conform to the Type1 standard. But the scaling introduces additional rounding errors, so it may be curious sometimes to look at the font in its original scale.
-h - Disable the autogeneration of hints. The really complex outlines may confuse the algorithm, so theoretically it may be useful sometimes to disable them. Although up to now it seems that even bad hints are better than no hints at all.
-f - Don't try to guess the ForceBold parameter. This parameter helps the Type1 engine to rasterize the bold fonts properly at small sizes. But the algorithm used to guess the proper value of this flag makes that guess based solely on the font name. In some cases that may cause the errors, so you may want to disable this guessing.
-l language - extract the fonts for the specified language from the
multi-language Unicode font. If this option is not used the converter
tries to guess the language by the values of the shell variable LANG.
If it is not able to guess the language by LANG it tries all the
languages in the order they are listed.
As of now the following languages are supported:
latin1 - for all the languages using the Latin-1 encoding
latin2 - for the Central European languages
latin4 - for the Baltic languages
latin5 - for the Turkish language
bulgarian - for the Bulgarian language
russian - for the Russian language
NOTE: You may notice that the language names are not uniform: some are the names of particular languages and some are names of encodings. This is because of the different approaches. The original idea was to implement a conversion from Unicode to the appropriate Windows encoding for a given language. And then use the translation tables to generate the fonts in whatever final encodings are needed. This would allow to pile together the Unicode fonts and the non-Unicode Windows fonts for that language and let the program to sort them out automatically. And then generate fonts in all the possible encodings for that language. An example of this approach is the Russian language support. But if there is no multiplicity of encodings used for some languages and if the non-Unicode fonts are not considered important by the users, another way would be simpler to implement: just provide only one table for extraction of the target encoding from Unicode and don't bother with the translation tables. The latin* "languages" are examples of this approach. If somebody feels that he needs the Type1 fonts both in Latin-* and Windows encodings he or she is absolutely welcome to submit the code to implement it.
-w - Try to correct the glyph widths. This option is designed to be used on broken fonts which specify too narrow widths for the letters. You can tell that a font can benefit from this option if you see that the characters are smashed together without any white space between them. This option causes the converter to set the character widths to the actual width of this character plus the width of a typical vertical stem. But on the other hand the well-designed fonts may have characters that look better if their widths are set slightly narrower. Such well-designed fonts will benefit from not using this option. You may want to convert a font with and without this option, compare the results and select the better one. This option is ignored for the fixed-width fonts.
-v size - Re-scale the font to get the size of a typical uppercase letter somewhere around the specified size. Actually, it re-scales the whole font to get the size of one language-dependent letter to be at least of the specified size. Now this letter is "A" in all the supported languages. The size is specified in the points of the Type 1 coordinate grids, the maximal value is 1000. This is an experimental option and should be used with caution. It tries to increase the visible font size for a given point size and thus make the font more readable. But if overused it may cause the fonts to look out of scale. As of now the interesting values of size for this option seem to be located mostly between 600 and 850. This re-scaling may be quite useful but needs more experience to understand the balance of its effects.
-a - Prints out the absolute coordinates of dots in outlines. Such a font can not be used by any program (that's why this option is incompatible with `-e') but it has proven to be a valuable debuging information.
-r - Do not reverse the direction of outlines. The TTF fonts have the standard direction of outlines opposite to the Type1 fonts. So they should be reversed during proper conversion. This option may be used for debugging or to handle a TTF font with wrong direction of outlines (possibly, converted in a broken way from a Type1 font). The first signs of the wrong direction are the letters like "P" or "B" without the unpainted "holes" inside.
Obsolete option:
The algorithm that implemented the forced fixed width had major
flaws, so it was disabled. The code is still in the program and
some day it will be refined and returned back. Meanwhile the
option name "-f" was reused for another option. The old version was:
-f - Don't try to force the fixed width of font. Normally the converter
considers the fonts in which the glyph width deviates by not more
than 5% as buggy fixed width fonts and forces them to have really
fixed width. If this is undesirable, it can be disabled by this option.
The .pfa font format supposes that the description of the characters is binary encoded and encrypted. This converter does not encode or encrypt the data by default, you have to specify the option `-e' or use the `t1asm' program to assemble (that means, encode and encrypt) the font program. The `t1asm' program that is included with the converter is actually a part of the `t1utils' package, rather old version of which may be obtained from
http://www.netspace.net.au/~mheath/ttf2pt1/t1utils.tar.gz
For a newer version of t1utils please look at
http://www.lcdf.org/~eddietwo/type/
So, the following command lines:
ttf2pt1 -e ttffont.ttf t1font
ttf2pt1 ttffont.ttf - | t1asm >t1font.pfa
represent two ways to get a working font. The benefit of the second form is that other filters may be applied to the font between the converter and assembler.
But running the converter manually becomes somewhat boring if it has to be applied to a few hundreds of fonts and then you have to generate the fonts.scale and/or Fontmap files. The INSTALL file describes how to use the supplied scripts to handle such cases easily. The installation scripts use the `t1utils' package and won't work without it.
Another small and interesting program and its README file is located in the `others' subdirectory.
http://quadrant.netspace.net.au/ttf2pt1/
The main page of the project but it is not always available.
http://members.xoom.com/sab123/ttf2pt1/
The page by Sergey Babkin, may contain his latest experimental
patches. This page is going to contain the mirror of the main
page but not yet.
http://www.lcdf.org/~eddietwo/type/
The home page of the Type 1 utilities package.
http://www.rightbrain.com/pages/books.html
The first book about PostScript on the Web, "Thinking in PostScript".
http://search.adobe.com/cgi-bin/query?mss=simple&pg=q&what=web&fmt=.&where=main&superq=PostScript+language+reference+manual&rd=all&q=PostScript+language+reference+manual
The search page on the Adobe site that finds the on-line PostScript
reference manual.
http://fonts.apple.com/TTRefMan/index.html
The True Type reference manual.
http://www.adobe.com/supportservice/devrelations/PDFS/TN/T1_SPEC.PDF
The specification of the Type 1 font format.
http://www.adobe.com/supportservice/devrelations/PDFS/TN/5004.AFM_Spec.pdf
The specification of the Adobe font metrics file format.
http://www.cs.wpi.edu/~matt/courses/cs563/talks/surface/bez_surf.html
http://www.cs.wpi.edu/~matt/courses/cs563/talks/curves.html
Information about the Bezier curves.
mheath@netspace.net.au
Mark Heath
A.Weeks@mcc.ac.uk
Andrew Weeks
babkin@bellatlantic.net (preferred)
sab123@hotmail.com
Sergey Babkin
Run it like this:
ttf2pfa fontfile.ttf fontname
The first parameter is the truetype filename, the second is a stem for the output file names. The program will create a fontname.pfa containing the Postscript font and a fontname.afm containing the metrics.
The motivation behind this is that in Linux if you do not have a Postscript printer, but only some other printer, you can only print Postscript by using Ghostscript. But the fonts that come with Ghostscript are very poor (they are converted from bitmaps and look rather lumpy). This is rather frustrating as the PC running Linux probably has MS-Windows as well and will therefore have truetype fonts, but which are quite useless with Linux, X or Ghostscript.
The program has been tested on over a hundred different TrueType fonts from various sources, and seems to work fairly well. The converted characters look OK, and the program doesn't seem to crash any more. I'm not sure about the AFM files though, as I have no means to test them.
The fonts generated will not work with X, as the font rasterizer that comes with X only copes with Type 1 fonts. If I have the time I may modify ttf2pfa to generate Type 1s.
Copyright on fonts, however, is a difficult legal question. Any copyright statements found in a font will be preserved in the output. Whether you are entitled to translate them at all I don't know.
If you have a license to run a software package, like say MS-Windows, on your PC, then you probably have a right to use any part of it, including fonts, on that PC, even if not using that package for its intended purpose.
I am not a lawyer, however, so this is not a legal opinion, and may be garbage.
There shouldn't be a any problem with public domain fonts.
The TrueType format was originally developed by Apple for the MAC, which has opposite endianness to the PC, so to ensure compatibility 16 and 32 bit fields are the wrong way round from the PC's point of view. This is the reason for all the 'ntohs' and 'ntohl' calls. Doing it this way means the program will also work on big-endian machines like Suns.
I doubt whether it will work on a DOS-based PC though.
The program produces what technically are Type 3 rather than Type 1 fonts. They are not compressed or encrypted and are plain text. This is so I (and you) can see what's going on, and (if you're a Postscript guru and really want to) can alter the outlines.
I only translate the outlines, not the 'instructions' that come with them. This latter task is probably virtually impossible anyway. TrueType outlines are B-splines rather than the Bezier curves that Postscript uses. I believe that my conversion algorithm is reasonably correct, if nothing else because the characters look right.
Then there are buggy fonts (yes, a font can have bugs). I try to deal with these in as sane a manner as possible, but it's not always possible.
TrueType fonts are organised differently. As well as the glyph descriptions there are a number of tables. One of these is a mapping from a character set into the glyph array, and another is a mapping from the glyph array into a set of Postscript character names. The problems are:
1) Microsoft uses Unicode, a 16-bit system, to encode the font.
2) that more than one glyph is given the same Postscript name.
I deal with (1) by assuming a Latin1 encoding. The MS-Windows and Unicode character sets are both supersets of ISO-8859-1. This usually means that most characters will be properly encoded, but you should be warned that some software may assume that fonts have an Adobe encoding. Symbol, or Dingbat, fonts are in fact less of a problem, as they have private encodings starting at 0xF000. It is easy to just lose the top byte.
Postscript fonts can be re-encoded, either manually, or by software. Groff, for example, generates postscript that re-encodes fonts with the Adobe encoding. The problem here is that not all characters in the Adobe set are in the MS-Windows set. In particular there are no fi and fl ligatures. This means that conversions of the versions of Times-New-Roman and Arial that come with MS-Windows cannot be used blindly as replacements for Adobe Times-Roman and Helvetica. You can get expanded versions of MS fonts from Microsoft's web site which do contain these ligatures (and a lot else besides).
I deal with (2) by creating new character names. This can be error-prone because I do not know which of them is the correct glyph to give the name to. Some (buggy) fonts have large numbers of blank glyphs, all with the same name.
(almost every TrueType font has three glyphs called .notdef, one of them is usually an empty square shape, one has no outline and has zero width, and one has no outline and a positive width. This example is not really a problem with well formed fonts since the .notdef characters are only used for unprintable characters, which shouldn't occur in your documents anyway).