[cairo] help with cairo_scale
Andrea Cimitan
andrea.cimitan at gmail.com
Thu Dec 16 15:29:18 PST 2010
On Thu, Dec 16, 2010 at 11:49 PM, Andrea Cimitan
<andrea.cimitan at gmail.com> wrote:
> On Thu, Dec 16, 2010 at 9:45 PM, Andrea Canciani <ranma42 at gmail.com> wrote:
>> 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
>>
> Already tried before, the problem is that it's like it's no applied,
> because of the save & restore?
>
>
> --
> Andrea Cimitan - http://www.cimitan.com
>
Just for the records, the problem is that the line_width is scaled as
well, and of course you can't use set_source and stroke after the
restore, because after the restore the previous set_source is restored
as well (so it ignores the call inside save/restore).
To play only with a similar scale like this, you can get the matrix
and set_matrix after the scale (it preserves the line width), or, if
you know your previous code was running the identify matrix, just use
cairo_identity_matrix without the need to get the matrix as well!
--
Andrea Cimitan - http://www.cimitan.com
More information about the cairo
mailing list