Feb 22 2007

The Ugly Chronicles of Postcript and PDF

Levi and I tried to figure out the age-old question of how to get not-ugly PDFs out of troublesome PS files. This question used to be primarily “how do I get legible PDFs out of LaTeX?” That question has been answered and answered well, and in most setups of LaTeX it just works these days (in my experience). Here is a good page on that subject.

The question now has become, how do I get legible PDFs out of PostScript files for which I do not have the .dvi or source files? The web is fairly silent on this point.

First, let’s talk about the problem. The problem is bitmapped fonts. The beautiful Computer Modern fonts are (were) not vectorized fonts, but bitmapped fonts. That means, in a nutshell, they only look right at certain resolutions. When ps2pdf or its kin converts such a PostScript file to PDF, it generates a PDF file with Type 3 fonts. I believe Type 3 fonts can be either vector or raster, but we’re interested in the raster case.

Many many programs do a fantastically terrible job of rendering Type 3 fonts. This includes Adobe Acrobat (rumor has it newer versions are improved), OS X Preview, gv, and a whole slew of others. So what you get is a PDF that is fairly illegible on-screen but that prints fine. Some nice screenshots here.

This inability to cope with Type 3 fonts seems to be a matter of utter incompetence. If you know anything about image processing, you know that it would be hard not to do a better job of downsampling. There do seem to be programs capable of displaying PDFs with Type 3 fonts in at least an acceptable manner. On linux, xpdf and whatever GNOME’s PDF viewer is called manage well enough. gv does not handle a PDF with Type 3 fonts well, however it handles the original PostScript file very well. On OS X, Preview fails miserably. You should be able to get xpdf from MacPorts, which is a valid option. Another option is to enhance the generated PDF to the point of moderate legibility:

ps2pdf -dPDFSETTINGS=/screen -dGrayDownsampleType=2 foo.ps

That says downsample to screen resolution not printer resolution, and use
bicubic resampling instead of the fast and worthless default. Levi reports MacGhostView ($20 shareware) works well too, but I can’t get it to extract out of the sitx file for some reason. I tried PStill ($70) and got an absolutely pitiful output (and the UI sucks too). Probably the best option is to use gv in X11 to view the original PostScript file, if you don’t mind the interface (I actually am kind of fond of gv’s interface). However my initial attempt at this with MacPorts doesn’t seem to work – I get no fonts at all.

Hopefully this helps somebody. If you know anyone that is responsible for the abysmal state of things, whack him upside the head for me. If you ever generate a PostScript or PDF file from LaTeX with bitmapped fonts instead of vector fonts, whack yourself upside the head for me.


Feb 18 2007

gvim on OS X

In spite of being the author of one of the more (in)famous vim color schemes,
desert.vim, I have been
vimming primarily in the console for quite some time now. The primary reason is
that gvim on OS X sucks.

Still, it’s nice to have gvim working for various reasons. One of the more
important reasons is dragging stuff to the Vim icon on the dock.

As a follow-up to my post on unicode in the terminal, I decided to install the latest Vim.app from macvim.org and see how it handled unicode. It didn’t handle it very well, but it’s only a few settings away.

First, there’s the issue of font. I don’t like Monaco very much. I use
Anonymous for the terminal
and I think it is an excellent font. In fact, I find myself likeing Anonymous
just as much as Terminus, but it
has the added advantage of being TrueType and looking great with antialiasing.
Unfortunately, in Vim at least it looks terrible without antialiasing. So I
got the pseudo-TrueType Terminus
font
by Eric Cheng. It took
some fiddling, because of various Bad Things™ happening with Vim and OS X
dealing with a TrueType-wrapped bitmap font, but I found the following settings
work great (put them in ~/.gvimrc):

set enc=utf-8
set macatsui noanti gfn=Terminus:h12

It’s not antialiased, but it is Terminus and it handles Unicode just fine (as
far as the Terminus font itself does, which is pretty good).

You can use antialiased fonts, e.g. Anonymous, with the following .gvimrc:

set enc=utf-8
set nomacatsui anti termencoding=macroman gfn=Anonymous:h10

but Bad Things™ happen when you use Unicode, so I’m sticking with the Terminus setup.