Netscape Navigator 4.x and fonts ================================ I had problems with fonts in Netscape for quite a while. Exactly, since I downloaded Netscape for the first time. As time went on some things got fixed some things got broken but one thing stayed broken very consistently: printing. Printing of documents with non-Latin letters just didn't work for me. Of course, lack or deficiences of the fonts containing the Russian letters was a big problem. But even printing of documents which used pure ASCII worked awfully: the sections printed in bold or italic would jump somewhere out of their proper place in the line and overlap with some other text. That was because I printed through Ghostscript and although Ghostscript provides reasonable substitutes for the original Adobe fonts, these substitutes are slightly different from the originals. And even when I got some Russian PostScript fonts the result with them had the same problem but much worse: the sizes of the letters differed even more from the Adobe originals. Not even speaking that the fonts converted from TTF by Fontographer were awful and the process of conversion was extremely slow and painful. On some lucky day I discovered ttf2pt1, a font converter from the TTF format to the Adobe Type1 format. It worked better than Fontographer and had source code ! In result I quickly got many Postscript fonts which I could use. (Well, their quality was still an itch, so I scratched it intensively by contributing code to the project). So one half of the problem was solved and that made the other half, in Netscape, yet more annoying. But I did not feel particularly enthusiastic about reverse engineering all that stuff of monstrous size to find the font metrics tables. For some time I entertained with the idea of processing the PostScript files generated by Netscape. But it did not bring aby useful result. Fortunately, another important event happened: Netscape had opened the code of its browser. So I was able to look at it, find out how it works, and patch the Netscape binary to include the metrics for my favorite fonts. And finally get it printing ! Mozilla seems to have an easier way of configuring the font metrics. Hopefully it will be included in Netscape 6 and will work properly, so this hack will not be needed any more. But in meantime it's a quite useful thing. Patching the binary looked a bit labor-intensive, and I did not want to repeat this procedure on each architecture and version of Netscape that I happen to get. So I wrote an auto-patching program (which was quite a fun by itself). This led to writing some other supplemental scripts. And I had a few other small scripts which I used to work around the Netscape bugs. So I packaged all that stuff together. The program is included in the distribution of ttf2pt1. Its WWW home page is located at http://ttf2pt1.sourceforge.net. Download any version starting from 3.2. The earlier versions are smaller, so for those interested only in making Netscape print the best choice would be 3.2. But the later versions do better font conversion, so people interested in that should get the latest version. In ttf2pt1 the Netscape-related things are located in subdirectory app/netscape. Let's look at them more closely. The collection of supplements is for Netscape 4.x on Unix. Probably they will also work with Netscape 3.x, possilby with minor modifications. They are discussed in groups by their Makefile nsfix.c psfonts.cf This is a program that allows to substitute the font metrics of any PostScript font in Netscape. It allows to replace the width tables inside the Netscape executable with the tables for any given font. The only problem is that Netscape 4 can hold only one set of tables at once. So to print with different fonts (say, for different languages or encodings) it would be neccessary to make multiple copies of the executable, tune each of them for its font and then run them separately. I tried to make the program as machine-independent as possible. But because it patches the binary files it still has the dependencies on hardware. The default version as supplied was designed for Intel x86 machines but it should work OK on any machine with 32-bit CPU and 4Kbyte (or less) page size. If it can't find the tables matching the font names on some other architecture the first thing to try would be reduce the `PAGEBITS' definition in the source code. On the machines with non-page-aligned structure of executables it won't work at all. But probably there are no such mahcines any more anyway. Or if there are any then Netscape don't run on them. I don't know whether would it work on the 64-bit machines. This may depend on whether the Netscape executable was compiled in 32-bit or 64-bit mode. For the 64-bit executables it may be neccessary to change the definition of the type `tptr' to an 8-byte integer type (probably `long' or `long long'). Also it must be re-compiled for patching of the Netscape binary for each particular machine architecture because it assumes the byte order of the current machine. It might be possible to create a program that would patch a running Netscape binary on the fly, that would allow changing the printing fonts as neccessary when Netscape is running. But this would be even more platform-dependent, so I don't feel any enthusiasm about doing that. I have successfully tested the program on the Intel machines, Netscape 4.08 and 4.7, OS FreeBSD (both a.out and ELF formats of the Netscape binary) and UnixWare. After all these scary issues are resolved the compiling is easy: just run `make'. To command to patch the Netscape is: ./nsfix Please make a copy of the original Netscape binary before patching in case anything goes wrong. Patch the copy, test that it works OK and only then install it. The configuration file describes the fonts that will be used. An example is provided in the file psfonts.cf. Each line in the configuration file consists of 4 columns: For example, the following line from my configuration file: Courier /usr/lib/X11/fonts/ttf/cokoi8n.koi8-r .afm .pfa says that the font `Courier' will be replaced with the font taken from the file `/usr/lib/X11/fonts/ttf/cokoi8n.koi8-r.pfa' and the metrics for that font will be taken from the file `/usr/lib/X11/fonts/ttf/cokoi8n.koi8-r.afm' . Netscape prints all the variable-width fonts as typeface Times and all the fixed-width fonts as typeface Courier. The example of configuration file lists all the styles of these fonts that should be defined because they are expected by Netscape. One more caveat: the new font must have a proper encoding table. Some fonts contain characters for multiple encodings hoping that the program wil re-encode them as neccessary. This won't work in this case, only the primary encoding table of the font will be used. Changing the metrics is not the end of the story. This will provide proper placement of the characters but not the characters themselves. There are a few ways to provide the characters: First, if GhostScript is used for printing then proper font aliases may be configured in the GhostScript configuration file. We will consider this variant trivial and won't discuss it furter except for two caveats: First, Netscape tries to re-encode the fonts per the ISO Latin-1 encoding. If the primary encoding of the font is different this would cause unexpected effects. Second, that would mean that these customized fonts will always be used instead of the standard fonts. And that may be not good. So this case may not be the best one even if it's feasible. Second, load the fonts right into the printer to substitute the standard fonts. This is very much like configuring GhostScript. Third, do printing from netscape using the provided filters: nsfilter nsprint psfonts.cf The script `nsfilter' reads the output of Netscape on its standard input and puts the result to its standard output. It uses the same configuration file `psfonts.cf' as `nsfix'. First it looks for the configuration file in the user's home directory ($HOME/.netscape/psfonts.cf) and if the file it not there then the second guess is the system-wide configuration file /usr/local/etc/psfonts.cf. The script inserts the fonts into the output and also removes the Netscape's experiments with the encodings. `nsfilter' is generally intended to be run by user, not by the printing subsystem. The reason is that the user may have changed fonts in his Netscape and the printing subsystem would have no way to access user's configuration file. But if all the users are using the same fonts then it may be incorporated into the printing subsystem and use the system-wide configuration file. The script `nsprint' is purely for convenience, to type it as a printing command in the Netscape printing window. It just pipelines the data through `nsfilter' to the printing program which also gets all the arguments. Please note that the SystemV-style and BSD-style systems use different printing programs (although they commonly provide compatibility with the other style too). The script tries to guess the type of system and use its native print program, `lp' or `lpr'. In case it guesses wrong the right choice may be hardcoded into the script. Also if the printer does not support PostScript directly this script may be a good place to insert a call to GhostScript. So when I print from Netscape I enter the following Print Command into the print dialog window: nsprint -Plp5m This takes care of printing but alas printing is not the only thing broken in Netscape 4 (and I wonder how Netscape 6 looks in this respect). So here is one more fix: notscape fontsz.cf Netscape 4 on Unix has a very annoying "feature", it does not remember the desired base size of the scalable screen fonts and always resets it to 12.0 points. Even if the size is changed manually in its preferences file, Netscape forgets it after it exits. So my solution was to write a program which would change the size to my favorite one every time right before starting Netscape. `notscape' is exactly such a program, it sets the font sizes an then transparently executes netscape. It takes the font sizes from the file `$HOME/.netscape/fontsz.cf' . An example of such file is provided. The format of the file is quite self-explanatory, for example the lines fixed-koi8-r 140 prop-koi8-r 150 mean "set the size of the fixed-width screen font in the encoding koi8-r to 14.0 points; set the size of the proportional (variable-width) font in the encoding koi8-r to 15.0 points". I also found that the script `notscape' is a convenient place to erase the cookies file. This seems to be quite a good idea to reduce the amount of information the advertisers like DoubleClick may collect about the browsing habits. Or at least make it more difficult for them. But because some people may find this inconvenient this removal is not included into the distribution. It may be easily added with a line: rm -f $HOME/.netscape/cookies added before starting Netscape.