|
|
||
Ben Galbraith's BlogJanuary 2008 ArchivesOf Fonts and Java2DPosted by javaben on January 25, 2008 at 08:08 AM | Permalink | Comments (29)The other day I googled for information on nice-looking fonts for Java2D and found nothing; this entry is largely to help future googlers. A poorly-rendered typeface can really ruin my day. I'm passionate about creating beautiful software. Well, for the sake of those who've seen my code, I should clarify: beautiful user interfaces. Generally, I'm satisfied that when my attempts fall short of my ideals, I'm the weak link in the process. After all, I control every pixel on the screen, so whether they look purty or not is my problem. Except for the fonts. Ah, the fonts. Translating typefaces into pixels is a complex problem I'm all too happy to leave to others to solve. But of course, that's the double-edged sword; I'm stuck with other people's solutions, be they good, bad, or somewhere in-between. I often find myself building user interfaces in Java Swing. Interestingly, Swing typically renders its own fonts--it doesn't rely on the underlying operating system. (Apple's JRE lets developers choose between having the OS or Java2D do the font rendering, but in the future, it appears this choice will go away in favor of Java2D). This could be a really good thing, if Java2D rendered better than the OS. Unfortunately, when compared to Windows and OS X, it doesn't. (It might render better than Linux, but I've never cared about that OS.) This characteristic of Java GUIs is still arguably a good thing, because Java applications render consistently across differently platforms; consistently subpar rendering to many is better than inconsistent rendering behavior, which could lead to all kinds of problems when the bounds of strings are different on different operating systems. The Problems with Java2D Fonts I've been blabbing about how Java2D font rendering is worse than that of Windows and OS X. In what way is it worse? Back in 2004, I identified and documented what I judged to be the four most serious problems. I'll summarize these issues here:
A Problem of Spacing To get a feel for the problem of spacing, check out how both OS X and Java2D (Java 1.6, Windows XP) rendering the same text with Lucida Grande Bold (11 points, Java2D text attributes set to PLAIN):
It's pretty amazing how gorgeous OS X's rendering of the text is; it's as though a magazine climbed into my LCD. The Java rendering looks pretty rough, due to both the glyph quality and their spacing. Check out the difference in character spacing in the word "quick" versus the word "brown" or how the "ps" in "jumps" is floating a bit too far to the right; also, note how Java renders the 'e', 'q', and 'w' compared to the Mac. It's pretty hard to argue that one could prefer the Java rendering, though the increased intensity of the pure white hue is a potential benefit. Am I Crazy? I know there are a large swath of folks who are just happy if they can get their app to do something and view my rambling on about fonts as silliness. I have no problem with such. My point here is that when you want to create gorgeous applications, these things really do matter, and they matter quite a bit. If you disagree with this assertion, well, we'll just have to disagree. (I'm reminded of a recent Wall Street Journal column by Lee Gomes in which he said audiophiles are divided into two camps: the crazy and the totally insane.) What To Do? I've had the opportunity to meet Phil Race, the font guru on the Java2D team, and I'm satisfied that he's smarter than I'll ever be, that he knows about these problems, and that he'd fix them if Sun's priorities and resources permitted such to happen. And who knows but that such fixes are already in the pipeline? (Well, I guess Phil knows.) That doesn't relate to my problem: I've got an app that I need to make gorgeous today. So, what do I do? I don't have time to render fonts myself. That's Hard Stuff. But, I could lay out the individual glyphs myself and do a better job than the Sun folks. But, having met Phil, I assume if that problem were non-trivial, he'd have improved it himself by now. However, by only caring how fonts look in my applications, as opposed to the entire world's set of Swing apps, perhaps I can get some results in this area. Finding the Best Fonts for Java2D In a past life, I did lay out glyphs myself, but that code no longer belongs to me, and I'm not in the mood to write it again. So the easiest solution is simply to check how Java2D renders fonts at different sizes and see which ones look best. I created a simple program and rendered some test output for Java2D using sub-pixel anti-aliasing (HRGB) with all of the fonts available to the JRE in a default Windows XP installation (along with Lucida Grande Bold), split into three large images. My favorites are:
Your Favorites? I was surprised at just how good some of these fonts look. Thanks Phil! Did I miss some other good ones? Are there other fonts that you've used with good results in Java2D? What are your "go to" fonts for beautiful type at large sizes? Update: Whoops. I put together this blog entry in a bit of a hurry whilst flying from Point A to Point B and I included some faulty images (due to a bug I introduced in the program I wrote to display the fonts; the last 2/3 of the fonts weren't sub-pixel AA'd):
The observations that drove me to write this blog entry were with properly sub-pixel anti-aliased type; so the content stands. Sorry for the goof-up. | ||
|
|