[cairo] Coordinates

Bill Spitzak spitzak at d2.com
Thu Dec 1 11:47:27 PST 2005



Mirza wrote:
> Would it make sense to create "compatibility option" for how coordinates 
> are interpreted? Most of legacy graphic code I saw assumes that integer 
> coordinates, like (0, 0) are placed in the middle of the pixel, not 
> between pixels. Such global setting (non-default) would make life easier 
> for people switching to Cairo from something else IMO.

Just doing that translation will make all the edges of filled rectangles 
fuzzy with antialiasing, and will blur all images even if drawn at 
exactly the size the are, so I doubt that is what is wanted.

I believe what is wanted is a special line mode, which I call 
linewidth=0 (due to the fact that EVERY implementation of this I have 
ever seen uses the same call as setting line width to turn on this 
mode). All this does is make narrow lines that look "nice", while 
leaving the coordinates at the corners of pixels, which makes everything 
else look nice.

This has been argued about here quite a bit before, and it does not look 
like it is going to happen, even though I believe it is pretty vital to 
get Cairo accepted. Without it people's initial attempts at drawing with 
Cairo look like crap. Worse, they will tend to "fix" it in ways that 
make Cairo's output look worse, by translating by .5 and/or turning off 
antialiasing.

Here is the proposal once again:

1. Setting the linewidth to 0 makes the Cairo "stroke" command draw in a 
special, different mode.

(Normal lines thinner than this value can still be achieved by setting 
the linewidth to very small, but non-zero values. As the interface is 
floating-point it is possible to get invisibly-thin on any conceivalbe 
raster device. Setting the linewidth to a negative value should act the 
same as the absolute value, except possibly to flip any assymettric line 
caps. The reason for using linewidth for this control is two-fold: first 
it is what virtually every other graphics API I have seen does, making 
emulation easier, and second it removes any need to define this for 
anything thicker than very thin lines, avoiding line-join and cap questions)

2. In this mode the lines are 1/180 of an inch thick, rounded *up* to 
the nearest device pixel.

3. Lines that are parallel with the raster are moved in a perpendicular 
direction to a location where they do not produce antialiasing. The 
location chosen is such that it covers any antialiasing drawn on a 
filled edge drawn with the same coordinates. The result is that a 
raster-parallel rectangle at any coordinates, including fractions, that 
is filled and then stroked never produces any visible antialiasing.

4. Lines that are not parallel *are* antialiased. However all ends are 
moved so that they will join neatly with lines that are drawn parallel 
with the raster.

5. linewidth = 0 mode is the default when a new Cairo context is created.


More information about the cairo mailing list