[cairo] How to prevent disappear of lines when scaling?

Hakki Dogusan dogusanh at tr.net
Fri Nov 7 15:04:11 PST 2008


Carl Worth wrote:
> On Fri, 2008-11-07 at 13:03 +0200, Hakki Dogusan wrote:
>> I found Carl's line-width-scale.c code about subject. It uses following 
>> method:
> ...
>> But I need different line widths in my do-drawings step. Is there a 
>> solution for that usage?
> Hello there,
> I'm not exactly sure what your question is, so I'll try a couple of
> different answers at the same time. :-)
> If you are about to stroke a line and you want a line width of "width"
> user-space units (that is, the width is modified by the current
> transformation so it may be a different number of pixels), then do:

No, I'm trying to prevent this.

> 	cairo_set_line_width (cr, width);
> 	cairo_stroke (cr);
> If you are about to stroke a line and you want a line width of "width"
> device-space units (in other words, "width" pixels, independent of the
> current transformation), then do:

Yes, I want that one :)

> 	cairo_save (cr);
> 	cairo_identity_matrix (cr);
> 	cairo_set_line_width (cr, width);
> 	cairo_stroke (cr);
> 	cairo_restore (cr);
> In other words, cairo_set_line_width *always* accepts a value in
> user-space units, but you can arrange for user space to be identical to
> device space with cairo_identity_matrix as desired.

If you need some fun, look at my newbie solution:

double scale = 1/100.0;
double linewidth = 2;

cairo_scale(cr, scale, scale);
cairo_move_to(cr, 0, 8000);
cairo_line_to(cr, 5000, 10500);
// cairo_set_line_width(cr, linewidth);
cairo_set_line_width(cr, linewidth/scale);


> Now, if you actually want something different than either of the above,
> then please try asking again with more details, because I didn't catch
> the question the first time.

Sorry about my wording. And, thanks for reply. It was very helpful.

> Thanks,
> -Carl

Hakki Dogusan

More information about the cairo mailing list