No updates lately. I have been so wrapped up in learning new stuff that it just hasn't occurred to me to write about it. My recent flash of interest in chess led to me thinking about porting some of my old Java Swing code to OS X. The old code used the WinBoard bitmaps which look pretty bad at high resolution and I had been thinking about making vector version of the pieces for years. I tinkered with that a little, and then decided to use it as an excuse to play with Quartz's PDF generation. After a couple of days of typing and recompiling verbose Core Graphics code, I started dabbling with Chicken Scheme's low-level C interface, learned how to move data back and forth across the Scheme/C border, and started writing a Scheme wrapper/interpreter for Quartz. Along the way, I re-learned how to use Lisp macros because Chicken does not support syntax-rules() by default, but it does supply a non-hygienic system which was more than adequate for my needs. After two weeks, I had a pretty good knowledge of Scheme (except for continuations) and a program that could take a chess position string in FEN format and generate a beautiful, scalable PDF diagram. (And my knights are prettier. I render the mane as delicate lines with the endpoints placed along two slowly diverging BeziƩr curves. I can't ever seem to get the eyes right, though. No matter how I do it, the perspective seems a little off.)
Then I tackled text layout. This was harder than I expected. First, Quartz's text-handling facilities are fairly limited. Instead, Apple has a separate software layer, Apple Type Services for Unicode Imaging (ATSUI), which provides a procedural API with extensive support for sophisticated typography concepts that most of us will never need. So I spent a few days learning how to use that from C, then I had to spend a few days experimenting with Chicken's C interface to improve buffer handling and figure out how to break down Scheme structures in C code, and then I had to design a Scheme API that gave me 90% of the power of ATS for common cases without me having to keep the rest of the huge ATS API in my head. I have completed the basic design now and can layout block paragraphs with simple Scheme code. With a little more work, this could become a general typesetting system. (Mmmm, don't give up your LaTeX books yet.)
I like this. A Scheme wrapper over Quartz/ATSUI gives me the power of PostScript without its limitations. Where PostScript enforces an opaque paint model, Quartz supports alpha channels and compositing effects. Where PostScript's byte-string model requires the programmer to construct 256-entry windows into a font's glyph table, ATS supports 16-bit characters and Unicode encoding. Finally, Quartz's ability to generate PDF and/or render that PDF immediately to PNG makes the output widely available.
A little project came up at work where I needed to generate a map of the eastern USA with some colored overlays. I found an EPS file on the web generated from the old CIA vector data, converted it to my new Scheme syntax, and used it to create a compact 35K PDF. I also ran into some limits in Chicken's implementation. If you try to concatenate too many S-expressions (126 or 127) in certain situations, the system breaks down. It's easy to fix, though: just group them inside (begin...) clauses. By the way, Alaska has too many islands: the vector outlines on Alaska are almost as big as the rest of the USA combined!
Of course, with all this programming, I haven't even looked at a chess book. That's typical for me. I spend so much time wandering the side streets, I forget the original reason I started out. Serendipity is my modus operandi?