There's been a flurry of work on the CairoGraphics package found in the Open Repository of late. A bunch of small stuff and fixes. And then there's one truly new feature.
We've added (need to stop to give credit here, Michael Lucas-Smith started this effort, he had the idea to try it, and did a lot of the ground work, so thanks go to him) the ability to use Cairo to draw on VisualWorks Image objects.
This is kind of cool. Historically to "draw" on a VisualWorks Image object, you had to convert it to a Pixmap, which allows one to instantiate a GraphicsContext to draw with, and then finally convert back. Now you can draw directly on the bits of the Image.
There are some pretty severe caveats though. Like other VW objects, you use the newCairoContextWhile: message to draw with it. Unless two conditions are met though, it will raise an error.
The first is pretty easy. The bits have to be allocated as a FixedSpace object. There is a useFixedSpaceBits method added to Image which you can use to move its bits into FixedSpace. This can be done on just about any image without negative side affects.
The second is that the palette has to be such that the bits of the Image are in a format that Cairo is happy with. There is a message which provides the transformation, becomeCairoCompatible (which should possibly be better named). This uses the convertToPalette:... message to create a new copy of the image, and then become:'s with the copy. So your image changes in place.
As it currently stands, you should send these two messages to an Image before using the newCairoContextWhile: message. I'm of two minds on this. The one is that these preparatory conversions should be explicit. On the sly, warping side affects, shouldn't happen out the open to surprise the programmer at a later point. The flip position, is that it's a pain to have to do this all the time, and it'd just be easier to have the newCairoContextWhile: automatically promote the Image to work with Cairo.
I'm curious what others think. Should an Image that is hit with Cairo methods automatically be coerced to something that Cairo is happy with? Or should that action be left to the programmer?