PDF documents in Chrome for the Mac

Chrome for the Mac is finally out of beta. It feels subjectively faster than the current version of Safari (4.0.5), it looks nice and polished, it syncs your bookmarks via your Google account, and the extension system is pretty powerful.

And yet, I simply cannot use it as my main Web browser on the Mac. When you click on a PDF link, the default behavior is to download the file and open it in Preview. Since I often have to read PDF documents that I do not need to keep, this is inconvenient: after reading the file, I must open the Downloads folder and trash it manually. This is not a problem on Windows: I use the Foxit PDF reader, which is fast and comes with a plugin that Chrome apparently likes.

On the Mac, the only alternative to downloading files is to use the Google Docs PDF/ Powerpoint viewer extension. As the name suggests, whenever you click on a PDF, .doc or .ppt link, this extension opens up the Google Docs viewer, which displays the document and provides navigation controls. This is exactly the same behavior you get in Gmail when you receive an attachment and click on its View link.

This is very convenient, and does avoid downloading the file. Unfortunately, the quality of the PDF rendering is abysmal. Furthermore, it brings back memories of my Linux days. But, before I start reminiscing, let me explain the problem. The following is a small excerpt from a paper of mine, typeset using the default LaTeX font, Computer Modern, and viewed using the Mac’s default Preview.app (sorry for the largish picture, but it is important for me to show you the original, uncompressed text):

Document as shown in Preview

Now, here’s the same document as shown by the Google Docs viewer:

Document as shown in Google Docs

I tried to match the size of the previews as best I could. The Preview.app rendering has a uniform, pleasantly dark “color,” and even subscripts are very readable. The Google Docs rendering, on the other hand, is spindly and washed out; the real numbers sign is hard to distinguish from a poorly drawn capital R; the “belongs to” sign (∈) is squashed against the letter q; and in general several letters are drawn with dark and light strokes that are unpleasant to the eye and, after a while, hard to read.

Linux veterans probably know what is going on here. While I have no inside knowledge, I am 99.99999% sure that Google Docs uses the open-source Poppler PDF renderer. This is an excellent library, used in many Linux PDF viewers, as well as in the TeXworks cross-platform LaTeX IDE. In turn, Poppler draws TrueType and Type 1 fonts using the FreeType library, which is also excellent. The problem is that FreeType is often configured to use (fairly aggressive) font hinting with these fonts. Roughly speaking (see the forelinked Wikipedia article for details), this means that each character, which is originally represented in vector-graphics format, is modified (“deformed”) so as to fit a particular character size.

The main problem is that, at least for the fonts used by LaTeX, these hints are meant to display text that is not anti-aliased. Poppler, and all other PDF rendering libraries I know of, do use antialiasing. The result is the mess you get in the above picture. Just to show you that Poppler is indeed quite capable of displaying top-quality text, here’s the same passage as shown by TeXworks, which uses antialiasing but not font hinting:

Document as shown in TeXworks

This is not quite at the level of Preview.app, because the Mac also uses subpixel rendering (like Windows and the Adobe Reader). However, characters are drawn more faithfully, font color is uniform, and in general the text is more readable.

All it takes to fix this problem is to change one configuration setting, or alternatively comment out a few lines: see e.g. this Poppler bug report, with attendant patch (this might be against an old version of poppler, but the idea is still valid). I used to apply this modification and recompile Poppler whenever my Linux distro “helpfully” configured FreeType to always use hinting. I never thought I’d have to deal with this problem again… but apparently, what was old is new again!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s