[XRender] Howto draw a hairline-trapezoid?
Carl Worth
cworth at cworth.org
Mon Jun 2 08:54:26 PDT 2008
On Mon, 2 Jun 2008 17:30:28 +0200, "Clemens Eisserer" wrote:
> Yes, I was using a zero line width, after setting it to 1 I get the
> same results as with XRender, it seems the Intel-Driver was
> responsible for th nice lines and not XDrawLine.
Right. With any width other than 0 you'll see this problem with X
lines. They are actually specified in such a way as to guarantee this
very unpleasant result, (one reason wide X lines have never been
popular).
> Is there any way for getting "nice lines" with XRender, without
> emmiting many many small trapezoids?
Yes.
The problem of inconsistent appearance of line width when stroking a
path with a circular pen was treated by John Hobby as his
Ph.D. thesis[*]. It's extraordinarily dense, (and a 29.6MB PDF file).
Fortunately, he followed up with a much shorter paper that provides
everything you would need to understand the problem and implement a
solution:
http://cm.bell-labs.com/who/hobby/87_2-04.pdf
John D. Hobby, Rasterizing Curves of Constant Width, JACM 36(2),
1989.
To summarize his result. All you have to do is approximate the
circular pen with a very carefully-constructed polygon, (what he terms
a "pen polygon"), and then use that polygon to stroke the path.
Cairo is already constructing a polygonal approximation of the
circular pen in its stroking algorithm, but simply generating a
regular polygon rather than a Hobby "pen polygon". So if you wanted to
get a more pleasing result with cairo+Xrender all it should take is a
modification of the _cairo_pen_init function to return a "pen polygon"
rather than a regular polygon.
Hobby provides an algorithm for generating pen polygons, but it
wouldn't even be necessary to implement that. Instead, one could
simply drop in several pre-generated pen polygons, (provided in the
paper), for the first several integer widths, (1 to 10, say), and that
should solve the problem for most interesting cases.
As may be evident from this mail, we've known about this issue for
quite some time. Basically, many of us just don't care about
non-antialiased rendering quality enough to step up and do this last
little bit of work. But I'd be quite happy to accept a patch for cairo
from someone that does.
Meanwhile, I know you're trying to implement your own non-cairo
solution on top of XRender. So, for that case, just get a Hobby pen
polygon, and then do what cairo does and you should be fine.
Have fun!
-Carl
[*] http://cm.bell-labs.com/who/hobby/thesis.pdf
John D. Hobby, Digitized Brush Trajectories, Ph.D. thesis,
Stanford University, 1985. (Also Stanford CS-TR-85-1070)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg/attachments/20080602/234a0ad9/attachment.pgp>
More information about the xorg
mailing list