[cairo] line width questions

Simon Budig simon at budig.de
Mon Aug 18 08:51:02 PDT 2008


... sorry, this should have gone to the list as well...

Ian Britten (britten at caris.com) 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).

I know and it perfectly makes sense if you draw non-antialiased lines
where a linewidth of zero indicates a straight-bresenham-style line.

My point is, that in an antialiased rendering context this definition no
longer makes sense. It would be desastrous for your API, if you e.g.
specify a line width of 0.005 px (which might get rendered nicely
although basically invisible), then you do some transformations on top
of your code and due to rounding errors you end up with a linewidth of
zero and suddenly you get a fat 1px line in your output, which is not
what you expect from scaling down your drawing code with a
transformation (this argument might be bogus, since the linewidth in
the drawing context probably does not get affected by transformations
directly, but you get the idea).

Also, if you think in the context of a PDF - if a zero linewidth
specifies the "thinnest possible" linewidth and you cannot possibly know
what to write to the PDF, since you have no idea about the actual output
device. A line might show up nicely on the imagesetter in your print
shop, but a same width line might just be invisible on your offices'
laser printer.

Just specifying the actual width - which in certain conditions might add
the "complexity" of doing an additional cairo_device_to_user_distance ()
to get real 1px lines on your image surface - is way easier than having
a magical guessing machine in cairo that does the wrong thing in a
critical situation.

> Since a thickness of zero seems to draw no line with Cairo, how
> am I to know what the thinnest possible line can be (Esp. when
> accounting for different surface types!).

If you don't know, how should cairo know? As written above, the
effective resolution of a printer is not known at the time of the PDF
output.

> My main problem is that "1 device unit" is unacceptably thick in PDF
> (Can anyone tell me what the PDF device units are?  Points maybe?).
> So how small can I specify the thickness? 0.5? 0.01? 0.000000001?
> And how am I supposed to know this, short of experimenting?

AFAIK the device units for postscript/pdf are postscript points, i.e.
1/72 inches or 0.353mm.

Bye,
        Simon
-- 
              simon at budig.de              http://simon.budig.de/


More information about the cairo mailing list