[cairo] line width questions

Simon Budig simon at budig.de
Mon Aug 18 14:40:10 PDT 2008

Ian Britten (britten at caris.com) wrote:
> Simon Budig wrote:
> At least for now, I'd like to keep this focused on PDF (and maybe the
> other vector output formats: PS, SVG, etc), where the output is most
> definitely not anti-aliased.
> [ Or, I'm assuming they aren't.  If Cairo is doing some sort of AA for
> PDF, etc, then that would open up a whole different discussion ]

Yeah, sorry, I did not realize that PDF and PS have this width 0 special
case for lines (Note that the PDF specification specifically
discourages the use of this feature though).

> >> 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.
> So you're saying that Cairo is going to prevent me from using this
> valid PS/PDF feature? Namely, using a lineweight of zero and
> automatically getting a "as thin as possible" line?
> I just printed some (PS) lines with a lineweight of zero.  Admittedly,
> it was only to a 1200dpi laser printer, and my optical measuring tools
> aren't super-advanced, but the resulting lines are around 0.03mm
> thick - Far smaller than one point.

Frankly, I don't get what is the big deal about this. Nothing prevents
you from specifying linewidths smaller than one point. If a 0.03mm line
meets your requirements (and you don't use transformations) specify a
line width of 0.086 and you're fine (0.086 * 25.4mm / 72 = 0.03mm)
(note that the device coordinates for a PDF surface are kind of
specified in the docs for cairo_pdf_surface_create()).

For Screen renderings I usually do something like this:
  double w1, w2;
  w1 = w2 = 1.0;
  cairo_device_to_user_distance (cr, &w1, &w2);
  cairo_set_line_width (cr, MAX (w1, w2));

and any further drawing yields neat 1px lines (on screen), but nothing
prevents you to use w1 = w2 = 0.086; to get consistent 0.03mm lines (in
your PDF). Or set up a transformation matrix where you can specify the
linewidths and coordinates in mm directly:

  cairo_scale (cr, 72.0 / 25.4, 72.0 / 25.4);
  cairo_set_line_width (cr, 0.03);

or whatever. I don't get what is the benefit of "as thin as possible"
over "0.03mm", especially when you're ready to accept that the printout
quality might vary drastically depending on your output device.


              simon at budig.de              http://simon.budig.de/

More information about the cairo mailing list