Tuesday, March 20, 2012

Fonts of Wisdom

Previous versions of Solitaire Till Dawn have always used carefully-drawn bitmap images to display the indices (the rank and suit of the card, shown in the upper-left corner). I did this because in the old days (you know, when we all used steam-powered computers), pixels were large and screen space was limited. I needed to know exactly where each numeral or letter would be placed, how tall it would be, how wide it would be, and how it aligned vertically and horizontally. I couldn't leave that to the vagaries of a computerized typesetter; if I did, all kinds of things wouldn't be right. The 10's would be absurdly wide; the suit symbols wouldn't line up vertically in columns; the letterforms wouldn't be thick and black enough for instant recognition; the fonts wouldn't look good at tiny sizes... you get the picture.

But it's a new age, people. I may be slow in realizing it, but I get there eventually. Bitmap images are a bad idea these days, precisely because they don't scale well as screens get larger and pixels get smaller. Using the system's text-display features takes care of that. And it turns out that the Mac's (and for future reference, iOS's) font tools are really flexible. This evening I finished substituting genuine font-drawn letters and numbers for my old bitmap images, and they look great.

To get the pixel-perfection I demand, I had to do some strange things. These included building tables that yielded the exact font size and baseline height needed for each separate card size; calculating string widths carefully for precise horizontal positioning and then adding offset adjustments for certain characters; and squeezing or widening some characters so their widths wouldn't differ so much. I even played with kerning to adjust the distance between the 1 and the 0 in "10", though in the end I found that I didn't need to do that.

I'm pleased with the results. The new letters and numbers almost precisely fill the space of the old ones, and are much better-looking. I think you'll like them.

I haven't done the suits yet. That comes next.