Carl Worth and I have started building a postscript-like API for drawing using the Render extension (or a client-side Render emulator). Interested parties are welcome to take a look at the current state of the API in CVS at keithp.com (http://keithp.com has a pointer), the two modules are called 'Xr' (the "rendering part") and 'Xc' (the "compositing part", which is a layer on top of Render which will eventually grow a client-side Render emulator).
We chatted with Lyle Ramshaw a couple of weeks ago and he suggested that we implement only cubic Bezier splines and leave other kinds of splines out of this library. Certainly that matches what Postscript does, and cubic Bezier's have the nice property of being trivial to decompose into line segments. Filling figures bounded by a Bezier is quite easy; split the curve into line segments and fill the resulting polygon. Stroking these curves is somewhat more difficult. We knew that circular pens were a bad idea; in Sharp mode, they generate lumpy lines while even in AA mode they're computationally intractable to compute precisely. For Sharp mode, the fix for the lumps is pretty easy -- use one of John Hobby's pen polygons and you get a nice even stroke width along the spline. What I hadn't realized before now is that polygonal pens solve the computational problem as well -- instead of generating a new n-th order polynomial describing the track of the edge of the figure, a polygonal pen stitches translated pieces of the original path together to form the boundary. We know how to compute points along the spline, and certainly translating them is easy enough, the only hard part is selecting which pieces of the spline are glued together to form the final edges. That part turned out to be confusing, but actually quite simple -- you move counter-clockwise along the polygon when the counter-clockwise polygon edge is clockwise from the spline and clockwise along the polygon when the clockwise polygon edge is clockwise from the spline. Another realization is that Hobby's pen polygons aren't interesting in the anti-aliased case -- pen polygons are designed to generate the same number of lit pixels on each scanline (and column) so that non-AA lines don't appear lumpy, but in the AA case, we don't want to round the widths to the nearest whole pixel like that. So, for AA splines, we just use a symmetrical polygon with enough points to keep things looking smooth. The final trick was to add the four points forming the start and end of each edge of the stroke to the polygon. This preserves the precise width of the face so that a cap or join can be applied smoothly. Carl wrote a prototype of this algorithm, a sample of it's output can be seen at http://keithp.com/~keithp/download/spline.png The code for this is in the 'spline' CVS module at keithp.com and is written in nickle with a C helper to do the actual drawing with Xr. The sample uses colors to show the transition from one polygon vertex to the next; there are 20 vertices forming a regular polygon along with the four additional vertices from the spline ends. The colors of the polygon progress counter clockwise through black, red, green, blue, yellow, cyan, magenta and gray, as seen in the little sample polygon drawn at the start of the spline. Keith Packard XFree86 Core Team HP Cambridge Research Lab _______________________________________________ Render mailing list [EMAIL PROTECTED] http://XFree86.Org/mailman/listinfo/render
