[cairo] line width questions
spitzak at thefoundry.co.uk
Mon Aug 18 15:49:29 PDT 2008
Ian Britten wrote:
> Simon Budig wrote:
>> Ian Britten (britten at caris.com) wrote:
>>> Just a couple of quick questions about set_line_width()
>>> [ Disclaimer - Yes, I read the FAQ. Those aren't my questions ]
>>> First, is there a quick/easy way to draw a line "as thin as possible"?
>> Well, how would you define "as thin as possible" when lines with a
>> width smaller than 1 device pixel are allowed and get rendered nicely?
> Beats me, which is why I asked! :)
> Seriously though, as I originally described, most graphics systems
> have an idiom to draw a line as thin as they possibly can, while still
> actually drawing the line. This is often done by setting the the
> thickness to zero (eg: PS behaves this way, and with X, a thickness
> of zero draws a 1-pixel wide line).
Also OpenGL, Windows GDI, GDI+, PDF, AGG, SVG, DirectX, SilverLight, and
a whole lot of others use "zero line width" to mean a special line
drawing algorithim. In fact it has been in *every single graphics api* I
have ever seen that has an ability to set the line width, except for Cairo.
I have said this quite a few times on this mailing list but there seems
to be no interest in replicating it in Cairo, and have pretty much given
up as I don't want to make myself too much of an a**hole about it.
The best definition of zero line width is that you get the smallest
integer number of device pixels that is larger than a fixed distance,
such as 1/300 of an inch (this would match what PostScript did on the
first printers that used it).
In addition the line ends are adjusted so that horizontal and vertical
lines are aligned with pixel boundaries so that the line thickness looks
the same no matter where it is drawn.
There is no problem with scaling in Cairo since it can simply remember
whether the passed argument was non-zero as an additional flag. If a
calling program is scaling the graphics itself it may want to make sure
that the scale is not so tiny that when they multiply a non-zero line
width they get zero, but that is really tiny due to the denormaized
format of floating point numbers.
It is true that this should not be used for presentation graphics.
However it is incredibly useful for drawing layout lines. Also it makes
drawing user interface graphics a lot easier.
The PDF output should just pass the zero through and let whoever is
interpreting the PDF decide how thick to make it.
Bill Spitzak, Senior Software Engineer
The Foundry, 618 Hampton Drive, Venice, CA, 90291, USA
Tel: +1 310 399-4555 * Fax: +1 310 450-4516 * Web: www.thefoundry.co.uk
The Foundry Visionmongers Ltd * Registered in England and Wales No: 4642027
More information about the cairo