[cairo] Scene-level snapping (was: Cairo developers conference call...)

Keith Packard keithp at keithp.com
Fri Oct 15 16:58:08 PDT 2004

Around 15 o'clock on Oct 15, Carl Worth wrote:

> Do you have "before" picture to help us see how much the snapping is
> helping?

Heh.  That would be nice, but I'm afraid I don't.  I do have other sample 
pictures in that directory to look at, but the samples without snapping 
have disappeared.  Regenerating them is possible, but non-trivial at this 

> Right. Adjustments lead to spacing errors between objects, and a smart
> layout tool will try to reduce those errors when performing adjustments
> on neighboring objects. So that sounds like a simple cairo_set_snapping
> won't be anywhere sufficient. Hmmm...

In fact, what I learned was that you really only want to snap points 
involved in horizontal and vertical edges and lines.  Without that, other 
shapes are quite distorted as you can see in this sample:


This is somewhat exagerated as the letters in that sample are built from 
straight segments without any splines, but still, it's clear that 
simplistic snapping isn't satisfactory.

Those samples also snap the line width, and adjust line centers to 
half-pixel coordinates for odd line-widths.

In some more detail, the algorithm used is to identify horizontal and 
vertical edges and mark the Y and X coordinates respectively.  Compute the
snapped location of each of these edges.  Now take every coordinate in the 
scene and 'adjust' it by an amount proportional to the movement of the
neighboring snapped coordinates.  I'm using a simple linear average, which 
works surprisingly well (note how few 'm' instances appear assymetrical).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20041015/2449f160/attachment.pgp

More information about the cairo mailing list