[cairo] help with cairo_scale

Andrea Canciani ranma42 at gmail.com
Thu Dec 16 12:45:39 PST 2010


On Thu, Dec 16, 2010 at 8:11 PM, Andrea Cimitan
<andrea.cimitan at gmail.com> wrote:
> Hi guys, I'm playing with the new gtk-style-context code for a new
> theming engine.
> I'm trying to grab a cairo_pattern_t, which is given to me in a 1x1
> format, so I need to scale it to my context and paint it.
> I'm encountering some difficulties, even if it seems simple (might be
> late for my brain :))
>
> so, with cairo_t* cr the context, cairo_pattern_t* pat as the pattern,
> x, y, width, height the dimensions, I was doing
>
> cairo_rectangle (cr,  x, y, width, height);
>
> cairo_save (cr);
>
> cairo_scale (cr, width, height);
> cairo_set_source (cr, pat);
> cairo_stroke (cr);
>
> cairo_restore (cr);
>
> but the line width is all messed up, because it's scaled as well :(
>
> what am I doing wrong?

You probably want to do:
cairo_rectangle (cr,  x, y, width, height);

cairo_save (cr);
cairo_scale (cr, width, height);
cairo_set_source (cr, pat);
cairo_restore (cr);

cairo_stroke (cr);


See http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-set-line-width
for an explanatio of what is happening to your line width.

Andrea


More information about the cairo mailing list