[cairo] Re: Scaling/rotating a pattern

David Reveman c99drn at cs.umu.se
Wed Apr 14 13:30:24 PDT 2004


On Wed, 2004-04-14 at 06:58 -0600, Ravindra Kumar wrote:

> Hi there,
> Thanks for great work you guys are doing!
> 
> I want to scale/rotate a pattern that I create. For example, I create
> a
> pattern that has an image and its reflection. I was trying out
> different
> ways to scale/rotate this pattern when I do stroke/fill. But,
> unfortunately, I could not do that and hence this mail.
> 
> I think following approach that did not work should have worked for me
> ;-(
> 
> cairo_t *cr = cairo_create ();
> cairo_pattern_t *pat;
> cairo_matrix_t *m; // matrix holding transformations to be applied to
> 
> cairo_save (cr);
> // I create a pattern pat using cairo_show_surface
> cairo_restore (cr);
> 
> cairo_set_matrix (cr, m);
> cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
> cairo_set_pattern (cr, pat);
> 
> cairo_set_line_width (cr, 100);
> cairo_move_to (cr, x1, y1);
> cairo_line_to (cr, x2, y2);
> cairo_stroke (cr);
> 
> The problems with this approach are, it scales just the pattern
> keeping the pattern size constant. Therefore, I get only half of the
> pattern scaled and tiled, when I do cairo_matrix_scale (m, 2, 1).
> If I rotate the pattern then I find the corners of the pattern missing
> since the corners that go out of pattern size due to rotation become
> invisible.

I'm not sure I really understanding what you're trying to do. I do know
this: 
Glitz is not very good at handling both rotation and transformation at
the same time. I think Xrender and pixman have the same problem. You can
always handle this in your application by first repeating the pattern to
an intermediate surface and then transforming this intermediate pattern
onto the destination. 

Maybe we should handle this in cairo. It could be done in a similar way
to how pattern opacity is handled right now.

> 
> Please let me know if this is not the right way to do this. I'm very
> eager to know the way to scale/rotate a pattern and stoke/fill it
> without losing any part of the pattern.

Could you please send a full source code example, makes it much easier
to understand exactly what you are trying to do.

- David

-- 
David Reveman <c99drn at cs.umu.se>





More information about the cairo mailing list